id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
16,600 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.createDropdown | public static function createDropdown($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
} | php | public static function createDropdown($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
} | [
"public",
"static",
"function",
"createDropdown",
"(",
"$",
"label",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"(",
")",
";",
"$",
"dropdown",
"->",
"setLabel",
"(",
"$",
"label",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"dropdown",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
]
| Create dropdown button.
@param string $label Dropdown button.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown | [
"Create",
"dropdown",
"button",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L143-L151 |
16,601 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.createDropdownHeader | public static function createDropdownHeader($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Header();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
} | php | public static function createDropdownHeader($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Header();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
} | [
"public",
"static",
"function",
"createDropdownHeader",
"(",
"$",
"label",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"\\",
"Header",
"(",
")",
";",
"$",
"dropdown",
"->",
"setLabel",
"(",
"$",
"label",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"dropdown",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
]
| Create dropdown header.
@param string $label Dropdown button.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown\Header | [
"Create",
"dropdown",
"header",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L162-L170 |
16,602 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.createDropdownDivider | public static function createDropdownDivider(array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Divider();
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
} | php | public static function createDropdownDivider(array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Divider();
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
} | [
"public",
"static",
"function",
"createDropdownDivider",
"(",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"\\",
"Divider",
"(",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"dropdown",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
]
| Create dropdown divider.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown\Divider | [
"Create",
"dropdown",
"divider",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L180-L186 |
16,603 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.createDropdownItem | public static function createDropdownItem($label, $url, array $attributes = array(), $fromFieldset = false)
{
$button = static::createButton($label, $url, $attributes, $fromFieldset);
$button->setAttribute('role', 'menuitem');
$dropdown = new Dropdown\Item($button);
return $dropdown;
} | php | public static function createDropdownItem($label, $url, array $attributes = array(), $fromFieldset = false)
{
$button = static::createButton($label, $url, $attributes, $fromFieldset);
$button->setAttribute('role', 'menuitem');
$dropdown = new Dropdown\Item($button);
return $dropdown;
} | [
"public",
"static",
"function",
"createDropdownItem",
"(",
"$",
"label",
",",
"$",
"url",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"button",
"=",
"static",
"::",
"createButton",
"(",
"$",
"label",
",",
"$",
"url",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"$",
"button",
"->",
"setAttribute",
"(",
"'role'",
",",
"'menuitem'",
")",
";",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"\\",
"Item",
"(",
"$",
"button",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
]
| Create dropdown item.
@param string $label Dropdown label.
@param string $url Dropdown url.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown\Item | [
"Create",
"dropdown",
"item",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L198-L205 |
16,604 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.applyAttributes | protected static function applyAttributes(Attributes $node, array $attributes, $fromFieldset = false)
{
if (empty($attributes)) {
return;
}
if ($fromFieldset) {
foreach ($attributes as $attribute) {
if ($attribute['name']) {
if ($attribute['name'] == 'class') {
if (!$attribute['value']) {
return;
}
$attribute['value'] = explode(' ', $attribute['value']);
}
$node->setAttribute($attribute['name'], $attribute['value']);
}
}
} else {
foreach ($attributes as $name => $value) {
if ($name) {
$node->setAttribute($name, $value);
}
}
}
} | php | protected static function applyAttributes(Attributes $node, array $attributes, $fromFieldset = false)
{
if (empty($attributes)) {
return;
}
if ($fromFieldset) {
foreach ($attributes as $attribute) {
if ($attribute['name']) {
if ($attribute['name'] == 'class') {
if (!$attribute['value']) {
return;
}
$attribute['value'] = explode(' ', $attribute['value']);
}
$node->setAttribute($attribute['name'], $attribute['value']);
}
}
} else {
foreach ($attributes as $name => $value) {
if ($name) {
$node->setAttribute($name, $value);
}
}
}
} | [
"protected",
"static",
"function",
"applyAttributes",
"(",
"Attributes",
"$",
"node",
",",
"array",
"$",
"attributes",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"fromFieldset",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"attribute",
"[",
"'name'",
"]",
")",
"{",
"if",
"(",
"$",
"attribute",
"[",
"'name'",
"]",
"==",
"'class'",
")",
"{",
"if",
"(",
"!",
"$",
"attribute",
"[",
"'value'",
"]",
")",
"{",
"return",
";",
"}",
"$",
"attribute",
"[",
"'value'",
"]",
"=",
"explode",
"(",
"' '",
",",
"$",
"attribute",
"[",
"'value'",
"]",
")",
";",
"}",
"$",
"node",
"->",
"setAttribute",
"(",
"$",
"attribute",
"[",
"'name'",
"]",
",",
"$",
"attribute",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"name",
")",
"{",
"$",
"node",
"->",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}"
]
| Apply attributes.
@param Attributes $node Attrbiutes alement.
@param array $attributes Html attributes which being applied.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return void | [
"Apply",
"attributes",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L216-L242 |
16,605 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.enableToolbar | protected static function enableToolbar($root)
{
if (!$root instanceof Toolbar) {
$group = $root;
$root = static::createToolbar(array(), true);
if ($group instanceof Group && $group->getChildren()) {
$root->addChild($group);
}
}
return $root;
} | php | protected static function enableToolbar($root)
{
if (!$root instanceof Toolbar) {
$group = $root;
$root = static::createToolbar(array(), true);
if ($group instanceof Group && $group->getChildren()) {
$root->addChild($group);
}
}
return $root;
} | [
"protected",
"static",
"function",
"enableToolbar",
"(",
"$",
"root",
")",
"{",
"if",
"(",
"!",
"$",
"root",
"instanceof",
"Toolbar",
")",
"{",
"$",
"group",
"=",
"$",
"root",
";",
"$",
"root",
"=",
"static",
"::",
"createToolbar",
"(",
"array",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"group",
"instanceof",
"Group",
"&&",
"$",
"group",
"->",
"getChildren",
"(",
")",
")",
"{",
"$",
"root",
"->",
"addChild",
"(",
"$",
"group",
")",
";",
"}",
"}",
"return",
"$",
"root",
";",
"}"
]
| Enable the toolbar.
@param mixed $root Current root element.
@return Toolbar | [
"Enable",
"the",
"toolbar",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L251-L263 |
16,606 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.parseDropdownChild | private static function parseDropdownChild($dropdown, $button)
{
if ($dropdown === false || !$dropdown instanceof Dropdown) {
// @codingStandardsIgnoreStart
// TODO throw exception?
// @codingStandardsIgnoreEnd
return;
}
if ($button['type'] == 'child') {
$child = static::createDropdownItem($button['label'], $button['url'], $button['attributes'], true);
} else {
if ($dropdown->getChildren()) {
$child = static::createDropdownDivider();
$dropdown->addChild($child);
}
$child = static::createDropdownHeader($button['label'], $button['attributes'], true);
}
$dropdown->addChild($child);
} | php | private static function parseDropdownChild($dropdown, $button)
{
if ($dropdown === false || !$dropdown instanceof Dropdown) {
// @codingStandardsIgnoreStart
// TODO throw exception?
// @codingStandardsIgnoreEnd
return;
}
if ($button['type'] == 'child') {
$child = static::createDropdownItem($button['label'], $button['url'], $button['attributes'], true);
} else {
if ($dropdown->getChildren()) {
$child = static::createDropdownDivider();
$dropdown->addChild($child);
}
$child = static::createDropdownHeader($button['label'], $button['attributes'], true);
}
$dropdown->addChild($child);
} | [
"private",
"static",
"function",
"parseDropdownChild",
"(",
"$",
"dropdown",
",",
"$",
"button",
")",
"{",
"if",
"(",
"$",
"dropdown",
"===",
"false",
"||",
"!",
"$",
"dropdown",
"instanceof",
"Dropdown",
")",
"{",
"// @codingStandardsIgnoreStart",
"// TODO throw exception?",
"// @codingStandardsIgnoreEnd",
"return",
";",
"}",
"if",
"(",
"$",
"button",
"[",
"'type'",
"]",
"==",
"'child'",
")",
"{",
"$",
"child",
"=",
"static",
"::",
"createDropdownItem",
"(",
"$",
"button",
"[",
"'label'",
"]",
",",
"$",
"button",
"[",
"'url'",
"]",
",",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"dropdown",
"->",
"getChildren",
"(",
")",
")",
"{",
"$",
"child",
"=",
"static",
"::",
"createDropdownDivider",
"(",
")",
";",
"$",
"dropdown",
"->",
"addChild",
"(",
"$",
"child",
")",
";",
"}",
"$",
"child",
"=",
"static",
"::",
"createDropdownHeader",
"(",
"$",
"button",
"[",
"'label'",
"]",
",",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
")",
";",
"}",
"$",
"dropdown",
"->",
"addChild",
"(",
"$",
"child",
")",
";",
"}"
]
| Parse dropdown child.
@param Dropdown|bool $dropdown Current dropdown element.
@param array $button Button definition.
@return void | [
"Parse",
"dropdown",
"child",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L273-L294 |
16,607 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.parseDefinition | protected static function parseDefinition($definition)
{
if (!is_array($definition)) {
$definition = deserialize($definition, true);
return $definition;
}
return $definition;
} | php | protected static function parseDefinition($definition)
{
if (!is_array($definition)) {
$definition = deserialize($definition, true);
return $definition;
}
return $definition;
} | [
"protected",
"static",
"function",
"parseDefinition",
"(",
"$",
"definition",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"definition",
")",
")",
"{",
"$",
"definition",
"=",
"deserialize",
"(",
"$",
"definition",
",",
"true",
")",
";",
"return",
"$",
"definition",
";",
"}",
"return",
"$",
"definition",
";",
"}"
]
| Parse button definition.
@param string|array $definition Button definition.
@return array | [
"Parse",
"button",
"definition",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L303-L312 |
16,608 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.encodeValue | protected static function encodeValue($button)
{
if (isset($button['button']) && $button['button'] == 'link') {
if (substr($button['value'], 0, 7) == 'mailto:') {
if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
$button['value'] = \StringUtil::encodeEmail($button['value']);
} else {
$button['value'] = \String::encodeEmail($button['value']);
}
} else {
$button['value'] = ampersand($button['value']);
}
}
return $button;
} | php | protected static function encodeValue($button)
{
if (isset($button['button']) && $button['button'] == 'link') {
if (substr($button['value'], 0, 7) == 'mailto:') {
if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
$button['value'] = \StringUtil::encodeEmail($button['value']);
} else {
$button['value'] = \String::encodeEmail($button['value']);
}
} else {
$button['value'] = ampersand($button['value']);
}
}
return $button;
} | [
"protected",
"static",
"function",
"encodeValue",
"(",
"$",
"button",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"button",
"[",
"'button'",
"]",
")",
"&&",
"$",
"button",
"[",
"'button'",
"]",
"==",
"'link'",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"button",
"[",
"'value'",
"]",
",",
"0",
",",
"7",
")",
"==",
"'mailto:'",
")",
"{",
"if",
"(",
"version_compare",
"(",
"VERSION",
".",
"'.'",
".",
"BUILD",
",",
"'3.5.5'",
",",
"'>='",
")",
")",
"{",
"$",
"button",
"[",
"'value'",
"]",
"=",
"\\",
"StringUtil",
"::",
"encodeEmail",
"(",
"$",
"button",
"[",
"'value'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"button",
"[",
"'value'",
"]",
"=",
"\\",
"String",
"::",
"encodeEmail",
"(",
"$",
"button",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"button",
"[",
"'value'",
"]",
"=",
"ampersand",
"(",
"$",
"button",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"button",
";",
"}"
]
| Encode button value.
@param array $button Button definition.
@return array | [
"Encode",
"button",
"value",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L333-L348 |
16,609 | contao-bootstrap/buttons | src/Netzmacht/Bootstrap/Buttons/Factory.php | Factory.createNewGroup | protected static function createNewGroup(&$root, $button, &$dropdown, $addToRoot = true)
{
if ($addToRoot) {
$root = self::enableToolbar($root);
}
if ($dropdown !== false) {
$dropdown = false;
}
$group = static::createGroup($button['attributes'], true, ($button['type'] === 'vgroup'));
if ($addToRoot) {
$root->addChild($group);
} else {
$root = $group;
}
return $group;
} | php | protected static function createNewGroup(&$root, $button, &$dropdown, $addToRoot = true)
{
if ($addToRoot) {
$root = self::enableToolbar($root);
}
if ($dropdown !== false) {
$dropdown = false;
}
$group = static::createGroup($button['attributes'], true, ($button['type'] === 'vgroup'));
if ($addToRoot) {
$root->addChild($group);
} else {
$root = $group;
}
return $group;
} | [
"protected",
"static",
"function",
"createNewGroup",
"(",
"&",
"$",
"root",
",",
"$",
"button",
",",
"&",
"$",
"dropdown",
",",
"$",
"addToRoot",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"addToRoot",
")",
"{",
"$",
"root",
"=",
"self",
"::",
"enableToolbar",
"(",
"$",
"root",
")",
";",
"}",
"if",
"(",
"$",
"dropdown",
"!==",
"false",
")",
"{",
"$",
"dropdown",
"=",
"false",
";",
"}",
"$",
"group",
"=",
"static",
"::",
"createGroup",
"(",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
",",
"(",
"$",
"button",
"[",
"'type'",
"]",
"===",
"'vgroup'",
")",
")",
";",
"if",
"(",
"$",
"addToRoot",
")",
"{",
"$",
"root",
"->",
"addChild",
"(",
"$",
"group",
")",
";",
"}",
"else",
"{",
"$",
"root",
"=",
"$",
"group",
";",
"}",
"return",
"$",
"group",
";",
"}"
]
| Create a new group element.
@param mixed $root Current root.
@param array $button Button definition.
@param Dropdown|bool $dropdown Dropdown element.
@param bool $addToRoot If rue the created group is added to the root.
@return Group | [
"Create",
"a",
"new",
"group",
"element",
"."
]
| f573a24c19ec059aae528a12ba46dfc993844201 | https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L360-L379 |
16,610 | jan-dolata/crude-crud | src/Engine/CrudeInstance.php | CrudeInstance.get | public static function get($name)
{
$namespaces = config('crude.namespace');
if (! is_array($namespaces)) {
$fullName = $namespaces . $name;
return class_exists($fullName)
? new $fullName()
: null;
}
foreach ($namespaces as $namespace) {
$fullName = $namespace . $name;
if (class_exists($fullName))
return new $fullName();
}
return null;
} | php | public static function get($name)
{
$namespaces = config('crude.namespace');
if (! is_array($namespaces)) {
$fullName = $namespaces . $name;
return class_exists($fullName)
? new $fullName()
: null;
}
foreach ($namespaces as $namespace) {
$fullName = $namespace . $name;
if (class_exists($fullName))
return new $fullName();
}
return null;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"$",
"namespaces",
"=",
"config",
"(",
"'crude.namespace'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"namespaces",
")",
")",
"{",
"$",
"fullName",
"=",
"$",
"namespaces",
".",
"$",
"name",
";",
"return",
"class_exists",
"(",
"$",
"fullName",
")",
"?",
"new",
"$",
"fullName",
"(",
")",
":",
"null",
";",
"}",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"$",
"fullName",
"=",
"$",
"namespace",
".",
"$",
"name",
";",
"if",
"(",
"class_exists",
"(",
"$",
"fullName",
")",
")",
"return",
"new",
"$",
"fullName",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Create crude instance
@param string $name
@return Model|null | [
"Create",
"crude",
"instance"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/CrudeInstance.php#L13-L32 |
16,611 | blast-project/CoreBundle | src/Admin/Traits/PreEvents.php | PreEvents.prePersistOrUpdate | protected function prePersistOrUpdate($object, $method)
{
$analyzer = new ClassAnalyzer();
foreach ($analyzer->getTraits($this) as $traitname) {
$rc = new \ReflectionClass($traitname);
if (method_exists($this, $exec = $method . $rc->getShortName())) {
$this->$exec($object);
} // executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method
}
return $this;
} | php | protected function prePersistOrUpdate($object, $method)
{
$analyzer = new ClassAnalyzer();
foreach ($analyzer->getTraits($this) as $traitname) {
$rc = new \ReflectionClass($traitname);
if (method_exists($this, $exec = $method . $rc->getShortName())) {
$this->$exec($object);
} // executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method
}
return $this;
} | [
"protected",
"function",
"prePersistOrUpdate",
"(",
"$",
"object",
",",
"$",
"method",
")",
"{",
"$",
"analyzer",
"=",
"new",
"ClassAnalyzer",
"(",
")",
";",
"foreach",
"(",
"$",
"analyzer",
"->",
"getTraits",
"(",
"$",
"this",
")",
"as",
"$",
"traitname",
")",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"traitname",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"exec",
"=",
"$",
"method",
".",
"$",
"rc",
"->",
"getShortName",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"$",
"exec",
"(",
"$",
"object",
")",
";",
"}",
"// executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method",
"}",
"return",
"$",
"this",
";",
"}"
]
| function prePersistOrUpdate.
Searches in every trait (as if they were kind of Doctrine Behaviors) some logical to be
executed during the self::prePersist() or self::preUpdate() calls
The logical is stored in the self::prePersist{TraitName}() method
@param object $object (Entity)
@param string $method (the current called method, eg. 'preUpdate' or 'prePersist')
@return CoreAdmin $this | [
"function",
"prePersistOrUpdate",
"."
]
| 7a0832758ca14e5bc5d65515532c1220df3930ae | https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Admin/Traits/PreEvents.php#L51-L62 |
16,612 | comelyio/comely | src/Comely/IO/Yaml/Compiler.php | Compiler.setIndent | public function setIndent(int $indent = 2): self
{
if (!Number::Range($indent, 2, 8)) {
throw new CompilerException(sprintf('"%d" is an invalid indent value', $indent));
}
return $this;
} | php | public function setIndent(int $indent = 2): self
{
if (!Number::Range($indent, 2, 8)) {
throw new CompilerException(sprintf('"%d" is an invalid indent value', $indent));
}
return $this;
} | [
"public",
"function",
"setIndent",
"(",
"int",
"$",
"indent",
"=",
"2",
")",
":",
"self",
"{",
"if",
"(",
"!",
"Number",
"::",
"Range",
"(",
"$",
"indent",
",",
"2",
",",
"8",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"'\"%d\" is an invalid indent value'",
",",
"$",
"indent",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set indent spacer
@param int $indent
@return Compiler
@throws CompilerException | [
"Set",
"indent",
"spacer"
]
| 561ea7aef36fea347a1a79d3ee5597d4057ddf82 | https://github.com/comelyio/comely/blob/561ea7aef36fea347a1a79d3ee5597d4057ddf82/src/Comely/IO/Yaml/Compiler.php#L66-L73 |
16,613 | axelitus/php-base | src/Comparison/IntComparer.php | IntComparer.setCallback | public function setCallback(Closure $callback = null)
{
if ($this->callback !== null || $callback === null) {
throw new \RuntimeException("Cannot redeclare this comparer callback.");
}
$this->callback = Closure::bind($callback, $this, get_called_class());
} | php | public function setCallback(Closure $callback = null)
{
if ($this->callback !== null || $callback === null) {
throw new \RuntimeException("Cannot redeclare this comparer callback.");
}
$this->callback = Closure::bind($callback, $this, get_called_class());
} | [
"public",
"function",
"setCallback",
"(",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"callback",
"!==",
"null",
"||",
"$",
"callback",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Cannot redeclare this comparer callback.\"",
")",
";",
"}",
"$",
"this",
"->",
"callback",
"=",
"Closure",
"::",
"bind",
"(",
"$",
"callback",
",",
"$",
"this",
",",
"get_called_class",
"(",
")",
")",
";",
"}"
]
| This comparer does not allow to set the callback outside this class.
@param Closure $callback The new callback.
@throws \RuntimeException | [
"This",
"comparer",
"does",
"not",
"allow",
"to",
"set",
"the",
"callback",
"outside",
"this",
"class",
"."
]
| c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075 | https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Comparison/IntComparer.php#L52-L59 |
16,614 | ekyna/GlsUniBox | Api/AbstractData.php | AbstractData.get | protected function get($tag)
{
if (isset($this->data[$tag])) {
return $this->data[$tag];
}
return null;
} | php | protected function get($tag)
{
if (isset($this->data[$tag])) {
return $this->data[$tag];
}
return null;
} | [
"protected",
"function",
"get",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"tag",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Returns the value for the given tag.
@param string $tag
@return string|null | [
"Returns",
"the",
"value",
"for",
"the",
"given",
"tag",
"."
]
| b474271ba355c3917074422306dc64abf09584d0 | https://github.com/ekyna/GlsUniBox/blob/b474271ba355c3917074422306dc64abf09584d0/Api/AbstractData.php#L54-L61 |
16,615 | ekyna/GlsUniBox | Api/AbstractData.php | AbstractData.clean | public function clean()
{
foreach ($this->data as $key => $data) {
if (empty($data)) {
unset($this->data[$key]);
}
}
return $this;
} | php | public function clean()
{
foreach ($this->data as $key => $data) {
if (empty($data)) {
unset($this->data[$key]);
}
}
return $this;
} | [
"public",
"function",
"clean",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Removes keys with empty value.
@return $this | [
"Removes",
"keys",
"with",
"empty",
"value",
"."
]
| b474271ba355c3917074422306dc64abf09584d0 | https://github.com/ekyna/GlsUniBox/blob/b474271ba355c3917074422306dc64abf09584d0/Api/AbstractData.php#L68-L77 |
16,616 | ray-di/Ray.WebFormModule | src/AbstractForm.php | AbstractForm.apply | public function apply(array $data)
{
if ($this->antiCsrf && ! $this->antiCsrf->isValid($data)) {
throw new CsrfViolationException;
}
$this->fill($data);
return $this->filter->apply($data);
} | php | public function apply(array $data)
{
if ($this->antiCsrf && ! $this->antiCsrf->isValid($data)) {
throw new CsrfViolationException;
}
$this->fill($data);
return $this->filter->apply($data);
} | [
"public",
"function",
"apply",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"antiCsrf",
"&&",
"!",
"$",
"this",
"->",
"antiCsrf",
"->",
"isValid",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"CsrfViolationException",
";",
"}",
"$",
"this",
"->",
"fill",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"filter",
"->",
"apply",
"(",
"$",
"data",
")",
";",
"}"
]
| Applies the filter to a subject.
@param array $data
@throws CsrfViolationException
@return bool | [
"Applies",
"the",
"filter",
"to",
"a",
"subject",
"."
]
| 4b6d33adb4a5c285278a068f3e7a5afdc4e680d9 | https://github.com/ray-di/Ray.WebFormModule/blob/4b6d33adb4a5c285278a068f3e7a5afdc4e680d9/src/AbstractForm.php#L158-L166 |
16,617 | andyvenus/form | src/EntityProcessor/GetterSetterEntityProcessor.php | GetterSetterEntityProcessor.getFromEntity | public function getFromEntity($entity, array $formParameters, $limitFields = null)
{
$extracted_data = array();
foreach($formParameters as $field) {
$getter_name = "get".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $getter_name) && ($value = $entity->$getter_name()) !== null) {
$extracted_data[$field] = $value;
}
}
return $extracted_data;
} | php | public function getFromEntity($entity, array $formParameters, $limitFields = null)
{
$extracted_data = array();
foreach($formParameters as $field) {
$getter_name = "get".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $getter_name) && ($value = $entity->$getter_name()) !== null) {
$extracted_data[$field] = $value;
}
}
return $extracted_data;
} | [
"public",
"function",
"getFromEntity",
"(",
"$",
"entity",
",",
"array",
"$",
"formParameters",
",",
"$",
"limitFields",
"=",
"null",
")",
"{",
"$",
"extracted_data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"formParameters",
"as",
"$",
"field",
")",
"{",
"$",
"getter_name",
"=",
"\"get\"",
".",
"$",
"this",
"->",
"dashesToCamelCase",
"(",
"$",
"field",
")",
";",
"if",
"(",
"(",
"$",
"limitFields",
"===",
"null",
"||",
"in_array",
"(",
"$",
"field",
",",
"$",
"limitFields",
")",
")",
"&&",
"method_exists",
"(",
"$",
"entity",
",",
"$",
"getter_name",
")",
"&&",
"(",
"$",
"value",
"=",
"$",
"entity",
"->",
"$",
"getter_name",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"extracted_data",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"extracted_data",
";",
"}"
]
| Get data from an entity using getter methods
@param $entity
@param array $formParameters
@param null $limitFields
@return array | [
"Get",
"data",
"from",
"an",
"entity",
"using",
"getter",
"methods"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/EntityProcessor/GetterSetterEntityProcessor.php#L25-L38 |
16,618 | andyvenus/form | src/EntityProcessor/GetterSetterEntityProcessor.php | GetterSetterEntityProcessor.saveToEntity | public function saveToEntity($entity, $formData, $limitFields = null)
{
foreach($formData as $field => $value) {
$setter_name = "set".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $setter_name)) {
$entity->$setter_name($value);
}
}
} | php | public function saveToEntity($entity, $formData, $limitFields = null)
{
foreach($formData as $field => $value) {
$setter_name = "set".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $setter_name)) {
$entity->$setter_name($value);
}
}
} | [
"public",
"function",
"saveToEntity",
"(",
"$",
"entity",
",",
"$",
"formData",
",",
"$",
"limitFields",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"formData",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"setter_name",
"=",
"\"set\"",
".",
"$",
"this",
"->",
"dashesToCamelCase",
"(",
"$",
"field",
")",
";",
"if",
"(",
"(",
"$",
"limitFields",
"===",
"null",
"||",
"in_array",
"(",
"$",
"field",
",",
"$",
"limitFields",
")",
")",
"&&",
"method_exists",
"(",
"$",
"entity",
",",
"$",
"setter_name",
")",
")",
"{",
"$",
"entity",
"->",
"$",
"setter_name",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}"
]
| Save data to an entity using setter methods
@param $entity
@param $formData
@param null $limitFields
@return void | [
"Save",
"data",
"to",
"an",
"entity",
"using",
"setter",
"methods"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/EntityProcessor/GetterSetterEntityProcessor.php#L48-L57 |
16,619 | foothing/laravel-repository | src/Foothing/Repository/Eloquent/EloquentRepository.php | EloquentRepository.setModel | public function setModel(\Illuminate\Database\Eloquent\Model $model) {
$this->model = $model;
if ($this->model instanceof ResourceInterface) {
$this->enableAutoEagerLoading = true;
}
} | php | public function setModel(\Illuminate\Database\Eloquent\Model $model) {
$this->model = $model;
if ($this->model instanceof ResourceInterface) {
$this->enableAutoEagerLoading = true;
}
} | [
"public",
"function",
"setModel",
"(",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Model",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"model",
";",
"if",
"(",
"$",
"this",
"->",
"model",
"instanceof",
"ResourceInterface",
")",
"{",
"$",
"this",
"->",
"enableAutoEagerLoading",
"=",
"true",
";",
"}",
"}"
]
| Set the repository model.
@param \Illuminate\Database\Eloquent\Model $model | [
"Set",
"the",
"repository",
"model",
"."
]
| a2e329acb26a08d9f260c66534b0d4f42e2adff5 | https://github.com/foothing/laravel-repository/blob/a2e329acb26a08d9f260c66534b0d4f42e2adff5/src/Foothing/Repository/Eloquent/EloquentRepository.php#L60-L65 |
16,620 | foothing/laravel-repository | src/Foothing/Repository/Eloquent/EloquentRepository.php | EloquentRepository.finalize | protected function finalize($result) {
$this->eagerLoad = [];
$this->criteria->reset();
$this->scope = null;
return $result;
} | php | protected function finalize($result) {
$this->eagerLoad = [];
$this->criteria->reset();
$this->scope = null;
return $result;
} | [
"protected",
"function",
"finalize",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"eagerLoad",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"criteria",
"->",
"reset",
"(",
")",
";",
"$",
"this",
"->",
"scope",
"=",
"null",
";",
"return",
"$",
"result",
";",
"}"
]
| Utility method for flags reset. Always use this to return results.
@param $result
The result we want to return
@return mixed | [
"Utility",
"method",
"for",
"flags",
"reset",
".",
"Always",
"use",
"this",
"to",
"return",
"results",
"."
]
| a2e329acb26a08d9f260c66534b0d4f42e2adff5 | https://github.com/foothing/laravel-repository/blob/a2e329acb26a08d9f260c66534b0d4f42e2adff5/src/Foothing/Repository/Eloquent/EloquentRepository.php#L75-L80 |
16,621 | foothing/laravel-repository | src/Foothing/Repository/Eloquent/EloquentRepository.php | EloquentRepository.applyAutoEagerLoading | protected function applyAutoEagerLoading($fetch = 'unit') {
if (! empty($this->eagerLoad)) {
return;
}
if ($this->enableAutoEagerLoading && $fetch == 'unit') {
$this->eagerLoad = $this->model->unitRelations();
}
elseif ($this->enableAutoEagerLoading && $fetch == 'list') {
$this->eagerLoad = $this->model->listRelations();
}
} | php | protected function applyAutoEagerLoading($fetch = 'unit') {
if (! empty($this->eagerLoad)) {
return;
}
if ($this->enableAutoEagerLoading && $fetch == 'unit') {
$this->eagerLoad = $this->model->unitRelations();
}
elseif ($this->enableAutoEagerLoading && $fetch == 'list') {
$this->eagerLoad = $this->model->listRelations();
}
} | [
"protected",
"function",
"applyAutoEagerLoading",
"(",
"$",
"fetch",
"=",
"'unit'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"eagerLoad",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"enableAutoEagerLoading",
"&&",
"$",
"fetch",
"==",
"'unit'",
")",
"{",
"$",
"this",
"->",
"eagerLoad",
"=",
"$",
"this",
"->",
"model",
"->",
"unitRelations",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"enableAutoEagerLoading",
"&&",
"$",
"fetch",
"==",
"'list'",
")",
"{",
"$",
"this",
"->",
"eagerLoad",
"=",
"$",
"this",
"->",
"model",
"->",
"listRelations",
"(",
")",
";",
"}",
"}"
]
| Check whether the autoEagerLoading feature has to be applied.
@param string $fetch | [
"Check",
"whether",
"the",
"autoEagerLoading",
"feature",
"has",
"to",
"be",
"applied",
"."
]
| a2e329acb26a08d9f260c66534b0d4f42e2adff5 | https://github.com/foothing/laravel-repository/blob/a2e329acb26a08d9f260c66534b0d4f42e2adff5/src/Foothing/Repository/Eloquent/EloquentRepository.php#L87-L99 |
16,622 | heyday/heystack | src/DependencyInjection/SilverStripe/SilverStripeServiceTrait.php | SilverStripeServiceTrait.getInjector | protected function getInjector()
{
if ($this->injector === null) {
$this->injector = \Injector::inst();
}
return $this->injector;
} | php | protected function getInjector()
{
if ($this->injector === null) {
$this->injector = \Injector::inst();
}
return $this->injector;
} | [
"protected",
"function",
"getInjector",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"injector",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"injector",
"=",
"\\",
"Injector",
"::",
"inst",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"injector",
";",
"}"
]
| Retrieves the Injector instance
@return \Injector | [
"Retrieves",
"the",
"Injector",
"instance"
]
| 2c051933f8c532d0a9a23be6ee1ff5c619e47dfe | https://github.com/heyday/heystack/blob/2c051933f8c532d0a9a23be6ee1ff5c619e47dfe/src/DependencyInjection/SilverStripe/SilverStripeServiceTrait.php#L34-L41 |
16,623 | activecollab/databasestructure | src/Builder/TriggersBuilder.php | TriggersBuilder.triggerExists | private function triggerExists($trigger_name)
{
if ($triggers = $this->getConnection()->execute('SHOW TRIGGERS', $trigger_name)) {
foreach ($triggers as $trigger) {
if ($trigger['Trigger'] == $trigger_name) {
return true;
}
}
}
return false;
} | php | private function triggerExists($trigger_name)
{
if ($triggers = $this->getConnection()->execute('SHOW TRIGGERS', $trigger_name)) {
foreach ($triggers as $trigger) {
if ($trigger['Trigger'] == $trigger_name) {
return true;
}
}
}
return false;
} | [
"private",
"function",
"triggerExists",
"(",
"$",
"trigger_name",
")",
"{",
"if",
"(",
"$",
"triggers",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"execute",
"(",
"'SHOW TRIGGERS'",
",",
"$",
"trigger_name",
")",
")",
"{",
"foreach",
"(",
"$",
"triggers",
"as",
"$",
"trigger",
")",
"{",
"if",
"(",
"$",
"trigger",
"[",
"'Trigger'",
"]",
"==",
"$",
"trigger_name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check if trigger exists.
@param string $trigger_name
@return bool | [
"Check",
"if",
"trigger",
"exists",
"."
]
| 4b2353c4422186bcfce63b3212da3e70e63eb5df | https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/TriggersBuilder.php#L134-L145 |
16,624 | jan-dolata/crude-crud | src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php | StoreUpdateDeleteTrait.store | public function store($attributes)
{
$attributes = $this->formatStoreAttributes($attributes);
$model = $this->model->create($this->mapAttributesWithScope($attributes));
if ($this->canOrder()) {
if ($this->storeInLastPlace) {
$attr = $this->crudeSetup->getOrderAttribute();
$model->$attr = $model->id;
$model->save();
}
$this->resetOrder();
}
$apiModel = $this->getById($model->id);
$this->afterStore($apiModel, $attributes);
return $apiModel;
} | php | public function store($attributes)
{
$attributes = $this->formatStoreAttributes($attributes);
$model = $this->model->create($this->mapAttributesWithScope($attributes));
if ($this->canOrder()) {
if ($this->storeInLastPlace) {
$attr = $this->crudeSetup->getOrderAttribute();
$model->$attr = $model->id;
$model->save();
}
$this->resetOrder();
}
$apiModel = $this->getById($model->id);
$this->afterStore($apiModel, $attributes);
return $apiModel;
} | [
"public",
"function",
"store",
"(",
"$",
"attributes",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"formatStoreAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"create",
"(",
"$",
"this",
"->",
"mapAttributesWithScope",
"(",
"$",
"attributes",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"canOrder",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"storeInLastPlace",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"crudeSetup",
"->",
"getOrderAttribute",
"(",
")",
";",
"$",
"model",
"->",
"$",
"attr",
"=",
"$",
"model",
"->",
"id",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"}",
"$",
"this",
"->",
"resetOrder",
"(",
")",
";",
"}",
"$",
"apiModel",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"model",
"->",
"id",
")",
";",
"$",
"this",
"->",
"afterStore",
"(",
"$",
"apiModel",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"apiModel",
";",
"}"
]
| Store new model
@param array $attributes
@return Model | [
"Store",
"new",
"model"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php#L47-L67 |
16,625 | jan-dolata/crude-crud | src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php | StoreUpdateDeleteTrait.updateById | public function updateById($id, $attributes)
{
$attributes = $this->formatUpdateAttributes($attributes);
$model = $this->model->find($id);
if (empty($model))
return $this;
$model->update($this->mapAttributesWithScope($attributes));
$apiModel = $this->getById($model->id);
$this->afterUpdate($apiModel, $attributes);
return $apiModel;
} | php | public function updateById($id, $attributes)
{
$attributes = $this->formatUpdateAttributes($attributes);
$model = $this->model->find($id);
if (empty($model))
return $this;
$model->update($this->mapAttributesWithScope($attributes));
$apiModel = $this->getById($model->id);
$this->afterUpdate($apiModel, $attributes);
return $apiModel;
} | [
"public",
"function",
"updateById",
"(",
"$",
"id",
",",
"$",
"attributes",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"formatUpdateAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"model",
")",
")",
"return",
"$",
"this",
";",
"$",
"model",
"->",
"update",
"(",
"$",
"this",
"->",
"mapAttributesWithScope",
"(",
"$",
"attributes",
")",
")",
";",
"$",
"apiModel",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"model",
"->",
"id",
")",
";",
"$",
"this",
"->",
"afterUpdate",
"(",
"$",
"apiModel",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"apiModel",
";",
"}"
]
| Update by id
@param integer $id
@param array $attributes
@return Model | [
"Update",
"by",
"id"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php#L75-L89 |
16,626 | jan-dolata/crude-crud | src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php | StoreUpdateDeleteTrait.deleteById | public function deleteById($id)
{
$model = $this->getById($id);
if (empty($model))
return $this;
if ($this instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithFileInterface) {
$fileAttrName = $this->fileAttrName;
$modelFiles = $model->$fileAttrName;
foreach ($modelFiles as $file)
$this->deleteFileByData($model->id, $file['file_log_id']);
}
$model->delete();
if ($this->canOrder())
$this->resetOrder();
return $this;
} | php | public function deleteById($id)
{
$model = $this->getById($id);
if (empty($model))
return $this;
if ($this instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithFileInterface) {
$fileAttrName = $this->fileAttrName;
$modelFiles = $model->$fileAttrName;
foreach ($modelFiles as $file)
$this->deleteFileByData($model->id, $file['file_log_id']);
}
$model->delete();
if ($this->canOrder())
$this->resetOrder();
return $this;
} | [
"public",
"function",
"deleteById",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"model",
")",
")",
"return",
"$",
"this",
";",
"if",
"(",
"$",
"this",
"instanceof",
"\\",
"JanDolata",
"\\",
"CrudeCRUD",
"\\",
"Engine",
"\\",
"Interfaces",
"\\",
"WithFileInterface",
")",
"{",
"$",
"fileAttrName",
"=",
"$",
"this",
"->",
"fileAttrName",
";",
"$",
"modelFiles",
"=",
"$",
"model",
"->",
"$",
"fileAttrName",
";",
"foreach",
"(",
"$",
"modelFiles",
"as",
"$",
"file",
")",
"$",
"this",
"->",
"deleteFileByData",
"(",
"$",
"model",
"->",
"id",
",",
"$",
"file",
"[",
"'file_log_id'",
"]",
")",
";",
"}",
"$",
"model",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"canOrder",
"(",
")",
")",
"$",
"this",
"->",
"resetOrder",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Delete by id
@param integer $id
@return self | [
"Delete",
"by",
"id"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php#L124-L145 |
16,627 | JoffreyPoreeCoding/MongoDB-ODM | src/Hydrator.php | Hydrator.recursiveConvertInArray | public function recursiveConvertInArray($array)
{
$newArray = [];
foreach ($array as $key => $value) {
if ($value instanceof \MongoDB\Model\BSONDocument || $value instanceof \MongoDB\Model\BSONArray) {
$value = (array) $value;
}
if (is_array($value)) {
$value = $this->recursiveConvertInArray($value);
}
$newArray[$key] = $value;
}
return $newArray;
} | php | public function recursiveConvertInArray($array)
{
$newArray = [];
foreach ($array as $key => $value) {
if ($value instanceof \MongoDB\Model\BSONDocument || $value instanceof \MongoDB\Model\BSONArray) {
$value = (array) $value;
}
if (is_array($value)) {
$value = $this->recursiveConvertInArray($value);
}
$newArray[$key] = $value;
}
return $newArray;
} | [
"public",
"function",
"recursiveConvertInArray",
"(",
"$",
"array",
")",
"{",
"$",
"newArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONDocument",
"||",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONArray",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"recursiveConvertInArray",
"(",
"$",
"value",
")",
";",
"}",
"$",
"newArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newArray",
";",
"}"
]
| Convert BSONDocument and BSONArray to array recursively
@param array $array Array to convert
@return array | [
"Convert",
"BSONDocument",
"and",
"BSONArray",
"to",
"array",
"recursively"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Hydrator.php#L302-L318 |
16,628 | JoffreyPoreeCoding/MongoDB-ODM | src/Hydrator.php | Hydrator.getHydrator | public function getHydrator($class)
{
$metadata = $this->classMetadataFactory->getMetadataForClass($class);
return new Hydrator($this->classMetadataFactory, $metadata, $this->documentManager, $this->repositoryFactory);
} | php | public function getHydrator($class)
{
$metadata = $this->classMetadataFactory->getMetadataForClass($class);
return new Hydrator($this->classMetadataFactory, $metadata, $this->documentManager, $this->repositoryFactory);
} | [
"public",
"function",
"getHydrator",
"(",
"$",
"class",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"classMetadataFactory",
"->",
"getMetadataForClass",
"(",
"$",
"class",
")",
";",
"return",
"new",
"Hydrator",
"(",
"$",
"this",
"->",
"classMetadataFactory",
",",
"$",
"metadata",
",",
"$",
"this",
"->",
"documentManager",
",",
"$",
"this",
"->",
"repositoryFactory",
")",
";",
"}"
]
| Get hydrator for specified class
@param string $class Class which you will get hydrator
@return Hydrator Hydrator corresponding to specified class | [
"Get",
"hydrator",
"for",
"specified",
"class"
]
| 56fd7ab28c22f276573a89d56bb93c8d74ad7f74 | https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Hydrator.php#L326-L330 |
16,629 | WebDevTmas/date-repetition | src/DateRepetition/DateRepetitionCalculator.php | DateRepetitionCalculator.getNextOccurence | public function getNextOccurence(DateRepetition $dateRepetition, DateTime $datetime = null)
{
if(null === $datetime) {
$datetime = $this->timeProvider->now();
}
switch(true) {
case $dateRepetition instanceof WeeklyDateRepetition:
return $this->getNextOccurenceForWeeklyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof DailyDateRepetition:
return $this->getNextOccurenceForDailyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof HourlyDateRepetition:
return $this->getNextOccurenceForHourlyDateRepetition($dateRepetition, $datetime);
}
return new \Exception('Not yet implemented');
} | php | public function getNextOccurence(DateRepetition $dateRepetition, DateTime $datetime = null)
{
if(null === $datetime) {
$datetime = $this->timeProvider->now();
}
switch(true) {
case $dateRepetition instanceof WeeklyDateRepetition:
return $this->getNextOccurenceForWeeklyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof DailyDateRepetition:
return $this->getNextOccurenceForDailyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof HourlyDateRepetition:
return $this->getNextOccurenceForHourlyDateRepetition($dateRepetition, $datetime);
}
return new \Exception('Not yet implemented');
} | [
"public",
"function",
"getNextOccurence",
"(",
"DateRepetition",
"$",
"dateRepetition",
",",
"DateTime",
"$",
"datetime",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"datetime",
")",
"{",
"$",
"datetime",
"=",
"$",
"this",
"->",
"timeProvider",
"->",
"now",
"(",
")",
";",
"}",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"dateRepetition",
"instanceof",
"WeeklyDateRepetition",
":",
"return",
"$",
"this",
"->",
"getNextOccurenceForWeeklyDateRepetition",
"(",
"$",
"dateRepetition",
",",
"$",
"datetime",
")",
";",
"case",
"$",
"dateRepetition",
"instanceof",
"DailyDateRepetition",
":",
"return",
"$",
"this",
"->",
"getNextOccurenceForDailyDateRepetition",
"(",
"$",
"dateRepetition",
",",
"$",
"datetime",
")",
";",
"case",
"$",
"dateRepetition",
"instanceof",
"HourlyDateRepetition",
":",
"return",
"$",
"this",
"->",
"getNextOccurenceForHourlyDateRepetition",
"(",
"$",
"dateRepetition",
",",
"$",
"datetime",
")",
";",
"}",
"return",
"new",
"\\",
"Exception",
"(",
"'Not yet implemented'",
")",
";",
"}"
]
| Find next occurence of date repetition
@param DateRepetition
@param DateTime next occurence from this date (null == now)
@return DateTime date/time of next occurence | [
"Find",
"next",
"occurence",
"of",
"date",
"repetition"
]
| 3ebd59f4ab3aab4b7497ebd767a57fad08277c6d | https://github.com/WebDevTmas/date-repetition/blob/3ebd59f4ab3aab4b7497ebd767a57fad08277c6d/src/DateRepetition/DateRepetitionCalculator.php#L33-L49 |
16,630 | tonicospinelli/class-generation | src/ClassGeneration/MethodCollection.php | MethodCollection.add | public function add($method)
{
if (!$method instanceof MethodInterface) {
throw new \InvalidArgumentException('This Method must be a instance of \ClassGeneration\MethodInterface');
}
if ($method->getName() === null) {
$method->setName('method' . ($this->count() + 1));
}
parent::set($method->getName(), $method);
return true;
} | php | public function add($method)
{
if (!$method instanceof MethodInterface) {
throw new \InvalidArgumentException('This Method must be a instance of \ClassGeneration\MethodInterface');
}
if ($method->getName() === null) {
$method->setName('method' . ($this->count() + 1));
}
parent::set($method->getName(), $method);
return true;
} | [
"public",
"function",
"add",
"(",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"$",
"method",
"instanceof",
"MethodInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'This Method must be a instance of \\ClassGeneration\\MethodInterface'",
")",
";",
"}",
"if",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
"===",
"null",
")",
"{",
"$",
"method",
"->",
"setName",
"(",
"'method'",
".",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"1",
")",
")",
";",
"}",
"parent",
"::",
"set",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"$",
"method",
")",
";",
"return",
"true",
";",
"}"
]
| Adds a new Method on collection.
@param MethodInterface $method
@return bool
@throws \InvalidArgumentException | [
"Adds",
"a",
"new",
"Method",
"on",
"collection",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/MethodCollection.php#L32-L43 |
16,631 | tonicospinelli/class-generation | src/ClassGeneration/MethodCollection.php | MethodCollection.toString | public function toString()
{
$string = '';
$methods = $this->getIterator();
foreach ($methods as $method) {
$string .= $method->toString();
}
return $string;
} | php | public function toString()
{
$string = '';
$methods = $this->getIterator();
foreach ($methods as $method) {
$string .= $method->toString();
}
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"methods",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"string",
".=",
"$",
"method",
"->",
"toString",
"(",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
]
| Parse the Method Collection to string.
@return string | [
"Parse",
"the",
"Method",
"Collection",
"to",
"string",
"."
]
| eee63bdb68c066b25b885b57b23656e809381a76 | https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/MethodCollection.php#L58-L67 |
16,632 | withfatpanda/illuminate-wordpress | src/Support/Concerns/Retriable.php | Retriable.fail | function fail($callback)
{
if (is_null($this->state)) {
$this->onError[] = $callback;
} else if (!$this->state) {
$callback($this->result);
}
return $this;
} | php | function fail($callback)
{
if (is_null($this->state)) {
$this->onError[] = $callback;
} else if (!$this->state) {
$callback($this->result);
}
return $this;
} | [
"function",
"fail",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"state",
")",
")",
"{",
"$",
"this",
"->",
"onError",
"[",
"]",
"=",
"$",
"callback",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"this",
"->",
"state",
")",
"{",
"$",
"callback",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| If the wrapped operation ultimately fails on all attempts,
invoke the given function. Many functions can be
added to the stack. If the attempted execution
of the wrapped operation has already failed, the the function
given here will be invoked instantly.
@param function
@return self | [
"If",
"the",
"wrapped",
"operation",
"ultimately",
"fails",
"on",
"all",
"attempts",
"invoke",
"the",
"given",
"function",
".",
"Many",
"functions",
"can",
"be",
"added",
"to",
"the",
"stack",
".",
"If",
"the",
"attempted",
"execution",
"of",
"the",
"wrapped",
"operation",
"has",
"already",
"failed",
"the",
"the",
"function",
"given",
"here",
"will",
"be",
"invoked",
"instantly",
"."
]
| b426ca81a55367459430c974932ee5a941d759d8 | https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/Support/Concerns/Retriable.php#L143-L151 |
16,633 | withfatpanda/illuminate-wordpress | src/Support/Concerns/Retriable.php | Retriable.until | function until($limit)
{
$until = function() use ($limit) {
if (is_int($limit)) {
if ($this->attempts < $limit) {
return true;
} else {
return false;
}
} else {
if ($limit($this->lastException, $this->attempts)) {
return true;
} else {
return false;
}
}
};
$defaultResult = function() {
if (is_callable($this->defaultResult)) {
return call_user_func_array($this->defaultResult, [ $this->lastException, $this->attempts ]);
} else {
return $this->defaultResult;
}
};
do {
$this->attempts++;
if ($this->attempts > 1) {
if ($timeout = $this->handleWait($this->lastException)) {
// DEBUG: echo "sleep($timeout)\n";
sleep($timeout);
}
}
try {
// try to execute the wrapped process
$result = call_user_func_array($this->operation, [ $this->attempts ]);
// this might throw an Exception too:
$this->handleSuccess($result);
// it didn't throw an exception, so we're done!
return $result;
} catch (\Exception $e) {
$this->lastException = $e;
// let's filter the exception:
if (!$this->handleException($e)) {
// filtering the exception resulted in false, so we're done:
$this->handleError($e);
// just return the default result
return $defaultResult();
}
}
} while ($until());
// we fell through to here, so we invoke handleError
// DEBUG: echo "Fell through at: ".time()."\n";
$this->handleError($this->lastException, $this->attempts);
// and we just return whatever the default value of result was
return $defaultResult();
} | php | function until($limit)
{
$until = function() use ($limit) {
if (is_int($limit)) {
if ($this->attempts < $limit) {
return true;
} else {
return false;
}
} else {
if ($limit($this->lastException, $this->attempts)) {
return true;
} else {
return false;
}
}
};
$defaultResult = function() {
if (is_callable($this->defaultResult)) {
return call_user_func_array($this->defaultResult, [ $this->lastException, $this->attempts ]);
} else {
return $this->defaultResult;
}
};
do {
$this->attempts++;
if ($this->attempts > 1) {
if ($timeout = $this->handleWait($this->lastException)) {
// DEBUG: echo "sleep($timeout)\n";
sleep($timeout);
}
}
try {
// try to execute the wrapped process
$result = call_user_func_array($this->operation, [ $this->attempts ]);
// this might throw an Exception too:
$this->handleSuccess($result);
// it didn't throw an exception, so we're done!
return $result;
} catch (\Exception $e) {
$this->lastException = $e;
// let's filter the exception:
if (!$this->handleException($e)) {
// filtering the exception resulted in false, so we're done:
$this->handleError($e);
// just return the default result
return $defaultResult();
}
}
} while ($until());
// we fell through to here, so we invoke handleError
// DEBUG: echo "Fell through at: ".time()."\n";
$this->handleError($this->lastException, $this->attempts);
// and we just return whatever the default value of result was
return $defaultResult();
} | [
"function",
"until",
"(",
"$",
"limit",
")",
"{",
"$",
"until",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"limit",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attempts",
"<",
"$",
"limit",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"limit",
"(",
"$",
"this",
"->",
"lastException",
",",
"$",
"this",
"->",
"attempts",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"}",
";",
"$",
"defaultResult",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"defaultResult",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"defaultResult",
",",
"[",
"$",
"this",
"->",
"lastException",
",",
"$",
"this",
"->",
"attempts",
"]",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"defaultResult",
";",
"}",
"}",
";",
"do",
"{",
"$",
"this",
"->",
"attempts",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"attempts",
">",
"1",
")",
"{",
"if",
"(",
"$",
"timeout",
"=",
"$",
"this",
"->",
"handleWait",
"(",
"$",
"this",
"->",
"lastException",
")",
")",
"{",
"// DEBUG: echo \"sleep($timeout)\\n\";",
"sleep",
"(",
"$",
"timeout",
")",
";",
"}",
"}",
"try",
"{",
"// try to execute the wrapped process",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"operation",
",",
"[",
"$",
"this",
"->",
"attempts",
"]",
")",
";",
"// this might throw an Exception too:",
"$",
"this",
"->",
"handleSuccess",
"(",
"$",
"result",
")",
";",
"// it didn't throw an exception, so we're done!",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"lastException",
"=",
"$",
"e",
";",
"// let's filter the exception:",
"if",
"(",
"!",
"$",
"this",
"->",
"handleException",
"(",
"$",
"e",
")",
")",
"{",
"// filtering the exception resulted in false, so we're done:",
"$",
"this",
"->",
"handleError",
"(",
"$",
"e",
")",
";",
"// just return the default result",
"return",
"$",
"defaultResult",
"(",
")",
";",
"}",
"}",
"}",
"while",
"(",
"$",
"until",
"(",
")",
")",
";",
"// we fell through to here, so we invoke handleError",
"// DEBUG: echo \"Fell through at: \".time().\"\\n\";",
"$",
"this",
"->",
"handleError",
"(",
"$",
"this",
"->",
"lastException",
",",
"$",
"this",
"->",
"attempts",
")",
";",
"// and we just return whatever the default value of result was",
"return",
"$",
"defaultResult",
"(",
")",
";",
"}"
]
| Start the loop with the given limit
@param mixed Can be an integer or a function of
the signature function(\Exception $e, $attempt),
where $e is the last Exception thrown and $attempt
is the count of attempts made to execute the wrapped
operation
@return The return result of the wrapped operation,
if and when it completes successfully.
@throws Exception If there are no functions in the
fail stack, the final exception thrown by the
wrapped operation will be rethrown by this function | [
"Start",
"the",
"loop",
"with",
"the",
"given",
"limit"
]
| b426ca81a55367459430c974932ee5a941d759d8 | https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/Support/Concerns/Retriable.php#L237-L302 |
16,634 | EcomDev/phpspec-magento-di-adapter | src/ParameterValidator.php | ParameterValidator.generator | public function generator($className)
{
foreach ($this->generators as $generator) {
if ($generator->supports($className)) {
return $generator->createGenerator($className);
}
}
return false;
} | php | public function generator($className)
{
foreach ($this->generators as $generator) {
if ($generator->supports($className)) {
return $generator->createGenerator($className);
}
}
return false;
} | [
"public",
"function",
"generator",
"(",
"$",
"className",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"generators",
"as",
"$",
"generator",
")",
"{",
"if",
"(",
"$",
"generator",
"->",
"supports",
"(",
"$",
"className",
")",
")",
"{",
"return",
"$",
"generator",
"->",
"createGenerator",
"(",
"$",
"className",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Generates a generator from class name rules
@param string $className
@return bool|\Magento\Framework\Code\Generator\EntityAbstract | [
"Generates",
"a",
"generator",
"from",
"class",
"name",
"rules"
]
| b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37 | https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L78-L87 |
16,635 | EcomDev/phpspec-magento-di-adapter | src/ParameterValidator.php | ParameterValidator.createGeneratorFactory | private function createGeneratorFactory($generatorClass, \Closure $factory = null)
{
return function ($sourceClass, $prefixClass) use ($factory, $generatorClass) {
if ($factory) {
return $factory($sourceClass, $prefixClass, $this->generationIo, $this->definedClasses, $generatorClass);
}
return new $generatorClass($sourceClass, $prefixClass, $this->generationIo, null, $this->definedClasses);
};
} | php | private function createGeneratorFactory($generatorClass, \Closure $factory = null)
{
return function ($sourceClass, $prefixClass) use ($factory, $generatorClass) {
if ($factory) {
return $factory($sourceClass, $prefixClass, $this->generationIo, $this->definedClasses, $generatorClass);
}
return new $generatorClass($sourceClass, $prefixClass, $this->generationIo, null, $this->definedClasses);
};
} | [
"private",
"function",
"createGeneratorFactory",
"(",
"$",
"generatorClass",
",",
"\\",
"Closure",
"$",
"factory",
"=",
"null",
")",
"{",
"return",
"function",
"(",
"$",
"sourceClass",
",",
"$",
"prefixClass",
")",
"use",
"(",
"$",
"factory",
",",
"$",
"generatorClass",
")",
"{",
"if",
"(",
"$",
"factory",
")",
"{",
"return",
"$",
"factory",
"(",
"$",
"sourceClass",
",",
"$",
"prefixClass",
",",
"$",
"this",
"->",
"generationIo",
",",
"$",
"this",
"->",
"definedClasses",
",",
"$",
"generatorClass",
")",
";",
"}",
"return",
"new",
"$",
"generatorClass",
"(",
"$",
"sourceClass",
",",
"$",
"prefixClass",
",",
"$",
"this",
"->",
"generationIo",
",",
"null",
",",
"$",
"this",
"->",
"definedClasses",
")",
";",
"}",
";",
"}"
]
| Returns generator factory
@param string $generatorClass
@param \Closure|null $factory
@return \Closure | [
"Returns",
"generator",
"factory"
]
| b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37 | https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L97-L106 |
16,636 | EcomDev/phpspec-magento-di-adapter | src/ParameterValidator.php | ParameterValidator.validate | public function validate(\ReflectionFunctionAbstract $reflectionFunction)
{
foreach ($reflectionFunction->getParameters() as $parameter) {
$this->validateParameter($parameter);
}
return $this;
} | php | public function validate(\ReflectionFunctionAbstract $reflectionFunction)
{
foreach ($reflectionFunction->getParameters() as $parameter) {
$this->validateParameter($parameter);
}
return $this;
} | [
"public",
"function",
"validate",
"(",
"\\",
"ReflectionFunctionAbstract",
"$",
"reflectionFunction",
")",
"{",
"foreach",
"(",
"$",
"reflectionFunction",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"$",
"this",
"->",
"validateParameter",
"(",
"$",
"parameter",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Validates method signature and tries to generate missing classes
@param \ReflectionFunctionAbstract $reflectionFunction
@return $this | [
"Validates",
"method",
"signature",
"and",
"tries",
"to",
"generate",
"missing",
"classes"
]
| b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37 | https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L115-L122 |
16,637 | phramework/jsonapi | src/Controller/GETById.php | GETById.handleGETById | protected static function handleGETById(
$parameters,
$id,
$modelClass,
$primaryDataParameters = [],
$relationshipParameters = []
) {
$filterValidationModel = $modelClass::getFilterValidationModel();
$idAttribute = $modelClass::getIdAttribute();
//Filter id attribute value
if (!empty($filterValidationModel) && isset($filterValidationModel->{$idAttribute})) {
$id = $filterValidationModel->{$idAttribute}->parse($id);
}
$fields = $modelClass::parseFields($parameters);
$requestInclude = static::getRequestInclude($parameters, $modelClass);
$data = $modelClass::getById(
$id,
$fields,
...$primaryDataParameters
);
//Check if resource exists
static::exists($data);
$includedData = $modelClass::getIncludedData(
$data,
$requestInclude,
$fields,
$relationshipParameters
);
return static::viewData(
$data,
(object) [
'self' => $modelClass::getSelfLink($id)
],
null,
(empty($requestInclude) ? null : $includedData)
);
} | php | protected static function handleGETById(
$parameters,
$id,
$modelClass,
$primaryDataParameters = [],
$relationshipParameters = []
) {
$filterValidationModel = $modelClass::getFilterValidationModel();
$idAttribute = $modelClass::getIdAttribute();
//Filter id attribute value
if (!empty($filterValidationModel) && isset($filterValidationModel->{$idAttribute})) {
$id = $filterValidationModel->{$idAttribute}->parse($id);
}
$fields = $modelClass::parseFields($parameters);
$requestInclude = static::getRequestInclude($parameters, $modelClass);
$data = $modelClass::getById(
$id,
$fields,
...$primaryDataParameters
);
//Check if resource exists
static::exists($data);
$includedData = $modelClass::getIncludedData(
$data,
$requestInclude,
$fields,
$relationshipParameters
);
return static::viewData(
$data,
(object) [
'self' => $modelClass::getSelfLink($id)
],
null,
(empty($requestInclude) ? null : $includedData)
);
} | [
"protected",
"static",
"function",
"handleGETById",
"(",
"$",
"parameters",
",",
"$",
"id",
",",
"$",
"modelClass",
",",
"$",
"primaryDataParameters",
"=",
"[",
"]",
",",
"$",
"relationshipParameters",
"=",
"[",
"]",
")",
"{",
"$",
"filterValidationModel",
"=",
"$",
"modelClass",
"::",
"getFilterValidationModel",
"(",
")",
";",
"$",
"idAttribute",
"=",
"$",
"modelClass",
"::",
"getIdAttribute",
"(",
")",
";",
"//Filter id attribute value",
"if",
"(",
"!",
"empty",
"(",
"$",
"filterValidationModel",
")",
"&&",
"isset",
"(",
"$",
"filterValidationModel",
"->",
"{",
"$",
"idAttribute",
"}",
")",
")",
"{",
"$",
"id",
"=",
"$",
"filterValidationModel",
"->",
"{",
"$",
"idAttribute",
"}",
"->",
"parse",
"(",
"$",
"id",
")",
";",
"}",
"$",
"fields",
"=",
"$",
"modelClass",
"::",
"parseFields",
"(",
"$",
"parameters",
")",
";",
"$",
"requestInclude",
"=",
"static",
"::",
"getRequestInclude",
"(",
"$",
"parameters",
",",
"$",
"modelClass",
")",
";",
"$",
"data",
"=",
"$",
"modelClass",
"::",
"getById",
"(",
"$",
"id",
",",
"$",
"fields",
",",
"...",
"$",
"primaryDataParameters",
")",
";",
"//Check if resource exists",
"static",
"::",
"exists",
"(",
"$",
"data",
")",
";",
"$",
"includedData",
"=",
"$",
"modelClass",
"::",
"getIncludedData",
"(",
"$",
"data",
",",
"$",
"requestInclude",
",",
"$",
"fields",
",",
"$",
"relationshipParameters",
")",
";",
"return",
"static",
"::",
"viewData",
"(",
"$",
"data",
",",
"(",
"object",
")",
"[",
"'self'",
"=>",
"$",
"modelClass",
"::",
"getSelfLink",
"(",
"$",
"id",
")",
"]",
",",
"null",
",",
"(",
"empty",
"(",
"$",
"requestInclude",
")",
"?",
"null",
":",
"$",
"includedData",
")",
")",
";",
"}"
]
| handles GETById requests
@param object $parameters Request parameters
@param integer|string $id Requested resource's id
@param string $modelClass Resource's primary model
to be used
@param array $primaryDataParameters [Optional] Array with any
additional arguments that the primary data is requiring
@param array $relationshipParameters [Optional] Array with any
additional argument primary data's relationships are requiring
@uses model's `getById` method to fetch resource
@return boolean
@todo Force parsing of relationship data when included | [
"handles",
"GETById",
"requests"
]
| af20882a8b6f6e5be9c8e09e5b87f6c23a4b0726 | https://github.com/phramework/jsonapi/blob/af20882a8b6f6e5be9c8e09e5b87f6c23a4b0726/src/Controller/GETById.php#L46-L90 |
16,638 | phpalchemy/cerberus | src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php | RolePermissionTableMap.doInsert | public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RolePermissionTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from RolePermission object
}
// Set the correct dbName
$query = RolePermissionQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
} | php | public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RolePermissionTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from RolePermission object
}
// Set the correct dbName
$query = RolePermissionQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
} | [
"public",
"static",
"function",
"doInsert",
"(",
"$",
"criteria",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"RolePermissionTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"if",
"(",
"$",
"criteria",
"instanceof",
"Criteria",
")",
"{",
"$",
"criteria",
"=",
"clone",
"$",
"criteria",
";",
"// rename for clarity",
"}",
"else",
"{",
"$",
"criteria",
"=",
"$",
"criteria",
"->",
"buildCriteria",
"(",
")",
";",
"// build Criteria from RolePermission object",
"}",
"// Set the correct dbName",
"$",
"query",
"=",
"RolePermissionQuery",
"::",
"create",
"(",
")",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"// use transaction because $criteria could contain info",
"// for more than one table (I guess, conceivably)",
"return",
"$",
"con",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"con",
",",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"doInsert",
"(",
"$",
"con",
")",
";",
"}",
")",
";",
"}"
]
| Performs an INSERT on the database, given a RolePermission or Criteria object.
@param mixed $criteria Criteria or RolePermission object containing data that is used to create the INSERT statement.
@param ConnectionInterface $con the ConnectionInterface connection to use
@return mixed The new primary key.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException. | [
"Performs",
"an",
"INSERT",
"on",
"the",
"database",
"given",
"a",
"RolePermission",
"or",
"Criteria",
"object",
"."
]
| 3424a360c9bded71eb5b570bc114a7759cb23ec6 | https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php#L454-L475 |
16,639 | braincrafted/arrayquery | src/Braincrafted/ArrayQuery/Evaluation.php | Evaluation.evaluateFilter | protected function evaluateFilter($value, $filter)
{
$filter = explode(' ', $filter, 2);
if (1 === count($filter)) {
$args = [];
$filter = $filter[0];
} else {
$args = array_map('trim', explode(',', $filter[1]));
$filter = $filter[0];
}
if (false === isset($this->filters[$filter])) {
throw new UnkownFilterException(sprintf('The filter "%s" does not exist.', $filter));
}
return $this->filters[$filter]->evaluate($value, $args);
} | php | protected function evaluateFilter($value, $filter)
{
$filter = explode(' ', $filter, 2);
if (1 === count($filter)) {
$args = [];
$filter = $filter[0];
} else {
$args = array_map('trim', explode(',', $filter[1]));
$filter = $filter[0];
}
if (false === isset($this->filters[$filter])) {
throw new UnkownFilterException(sprintf('The filter "%s" does not exist.', $filter));
}
return $this->filters[$filter]->evaluate($value, $args);
} | [
"protected",
"function",
"evaluateFilter",
"(",
"$",
"value",
",",
"$",
"filter",
")",
"{",
"$",
"filter",
"=",
"explode",
"(",
"' '",
",",
"$",
"filter",
",",
"2",
")",
";",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"$",
"filter",
"=",
"$",
"filter",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"args",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"filter",
"[",
"1",
"]",
")",
")",
";",
"$",
"filter",
"=",
"$",
"filter",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"filter",
"]",
")",
")",
"{",
"throw",
"new",
"UnkownFilterException",
"(",
"sprintf",
"(",
"'The filter \"%s\" does not exist.'",
",",
"$",
"filter",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filters",
"[",
"$",
"filter",
"]",
"->",
"evaluate",
"(",
"$",
"value",
",",
"$",
"args",
")",
";",
"}"
]
| Evaluates the given value with the given filter.
@param mixed $value
@param string|array $filter
@return mixed
@throws Braincrafted\ArrayQuery\Exception\UnkownFilterException if a filter does not exist. | [
"Evaluates",
"the",
"given",
"value",
"with",
"the",
"given",
"filter",
"."
]
| 8b0c44ee76cea796589422f52e2f7130676b9bd1 | https://github.com/braincrafted/arrayquery/blob/8b0c44ee76cea796589422f52e2f7130676b9bd1/src/Braincrafted/ArrayQuery/Evaluation.php#L36-L52 |
16,640 | heyday/heystack | src/Processor/HandlerTrait.php | HandlerTrait.getProcessor | public function getProcessor($name)
{
return isset($this->processors[$name]) ? $this->processors[$name] : false;
} | php | public function getProcessor($name)
{
return isset($this->processors[$name]) ? $this->processors[$name] : false;
} | [
"public",
"function",
"getProcessor",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"processors",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"processors",
"[",
"$",
"name",
"]",
":",
"false",
";",
"}"
]
| Return a processor by an identifier if it exists
@param string $name The processor identifier
@return mixed The processor if it exists | [
"Return",
"a",
"processor",
"by",
"an",
"identifier",
"if",
"it",
"exists"
]
| 2c051933f8c532d0a9a23be6ee1ff5c619e47dfe | https://github.com/heyday/heystack/blob/2c051933f8c532d0a9a23be6ee1ff5c619e47dfe/src/Processor/HandlerTrait.php#L27-L30 |
16,641 | crossjoin/Css | src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php | DocumentRule.setUrl | public function setUrl($url)
{
if (is_string($url)) {
$this->url = $url;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($url) . "' for argument 'url' given. String expected."
);
}
} | php | public function setUrl($url)
{
if (is_string($url)) {
$this->url = $url;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($url) . "' for argument 'url' given. String expected."
);
}
} | [
"public",
"function",
"setUrl",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"url",
")",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"url",
")",
".",
"\"' for argument 'url' given. String expected.\"",
")",
";",
"}",
"}"
]
| Sets the document URL filter.
@param string $url | [
"Sets",
"the",
"document",
"URL",
"filter",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L52-L61 |
16,642 | crossjoin/Css | src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php | DocumentRule.setUrlPrefix | public function setUrlPrefix($urlPrefix)
{
if (is_string($urlPrefix)) {
$this->urlPrefix = $urlPrefix;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($urlPrefix) . "' for argument 'urlPrefix' given. String expected."
);
}
} | php | public function setUrlPrefix($urlPrefix)
{
if (is_string($urlPrefix)) {
$this->urlPrefix = $urlPrefix;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($urlPrefix) . "' for argument 'urlPrefix' given. String expected."
);
}
} | [
"public",
"function",
"setUrlPrefix",
"(",
"$",
"urlPrefix",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"urlPrefix",
")",
")",
"{",
"$",
"this",
"->",
"urlPrefix",
"=",
"$",
"urlPrefix",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"urlPrefix",
")",
".",
"\"' for argument 'urlPrefix' given. String expected.\"",
")",
";",
"}",
"}"
]
| Sets the document URL prefix filter.
@param string $urlPrefix | [
"Sets",
"the",
"document",
"URL",
"prefix",
"filter",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L78-L87 |
16,643 | crossjoin/Css | src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php | DocumentRule.setDomain | public function setDomain($domain)
{
if (is_string($domain)) {
$this->domain = $domain;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($domain) . "' for argument 'domain' given. String expected."
);
}
} | php | public function setDomain($domain)
{
if (is_string($domain)) {
$this->domain = $domain;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($domain) . "' for argument 'domain' given. String expected."
);
}
} | [
"public",
"function",
"setDomain",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"domain",
")",
")",
"{",
"$",
"this",
"->",
"domain",
"=",
"$",
"domain",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"domain",
")",
".",
"\"' for argument 'domain' given. String expected.\"",
")",
";",
"}",
"}"
]
| Sets the document domain filter.
@param string $domain | [
"Sets",
"the",
"document",
"domain",
"filter",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L104-L113 |
16,644 | crossjoin/Css | src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php | DocumentRule.setRegexp | public function setRegexp($regexp)
{
if (is_string($regexp)) {
$this->regexp = $regexp;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($regexp) . "' for argument 'regexp' given. String expected."
);
}
} | php | public function setRegexp($regexp)
{
if (is_string($regexp)) {
$this->regexp = $regexp;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($regexp) . "' for argument 'regexp' given. String expected."
);
}
} | [
"public",
"function",
"setRegexp",
"(",
"$",
"regexp",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"regexp",
")",
")",
"{",
"$",
"this",
"->",
"regexp",
"=",
"$",
"regexp",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"regexp",
")",
".",
"\"' for argument 'regexp' given. String expected.\"",
")",
";",
"}",
"}"
]
| Sets the document regular expression filter.
@param string $regexp | [
"Sets",
"the",
"document",
"regular",
"expression",
"filter",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L130-L139 |
16,645 | verschoof/bunq-api | src/Resource/UserResource.php | UserResource.getUser | public function getUser($id)
{
$response = $this->client->get($this->getResourceEndpoint() . '/' . (int)$id);
return $response['Response'][0]['UserCompany'];
} | php | public function getUser($id)
{
$response = $this->client->get($this->getResourceEndpoint() . '/' . (int)$id);
return $response['Response'][0]['UserCompany'];
} | [
"public",
"function",
"getUser",
"(",
"$",
"id",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
"$",
"this",
"->",
"getResourceEndpoint",
"(",
")",
".",
"'/'",
".",
"(",
"int",
")",
"$",
"id",
")",
";",
"return",
"$",
"response",
"[",
"'Response'",
"]",
"[",
"0",
"]",
"[",
"'UserCompany'",
"]",
";",
"}"
]
| Gets a user its information.
@param integer $id
@return array | [
"Gets",
"a",
"user",
"its",
"information",
"."
]
| df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd | https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Resource/UserResource.php#L39-L44 |
16,646 | andyvenus/form | src/FormView.php | FormView.getSectionFields | public function getSectionFields($section, $flatten = true)
{
if ($flatten === false) {
$fields = $this->fields;
} else {
$fields = $this->getFlattenedFields();
}
$matchedFields = array();
foreach ($fields as $fieldName => $field) {
if (isset($field['options']['section']) && $field['options']['section'] == $section) {
$matchedFields[$fieldName] = $field;
}
}
return $matchedFields;
} | php | public function getSectionFields($section, $flatten = true)
{
if ($flatten === false) {
$fields = $this->fields;
} else {
$fields = $this->getFlattenedFields();
}
$matchedFields = array();
foreach ($fields as $fieldName => $field) {
if (isset($field['options']['section']) && $field['options']['section'] == $section) {
$matchedFields[$fieldName] = $field;
}
}
return $matchedFields;
} | [
"public",
"function",
"getSectionFields",
"(",
"$",
"section",
",",
"$",
"flatten",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"flatten",
"===",
"false",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"fields",
";",
"}",
"else",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFlattenedFields",
"(",
")",
";",
"}",
"$",
"matchedFields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'options'",
"]",
"[",
"'section'",
"]",
")",
"&&",
"$",
"field",
"[",
"'options'",
"]",
"[",
"'section'",
"]",
"==",
"$",
"section",
")",
"{",
"$",
"matchedFields",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"return",
"$",
"matchedFields",
";",
"}"
]
| Get fields for a certain section
@param $section
@param bool $flatten
@return array | [
"Get",
"fields",
"for",
"a",
"certain",
"section"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L188-L204 |
16,647 | andyvenus/form | src/FormView.php | FormView.getFlattenedFields | public function getFlattenedFields()
{
if (!isset($this->flatFields)) {
$this->flatFields = [];
foreach ($this->fields as $field) {
if (isset($field['fields']) && is_array($field['fields'])) {
$this->flatFields += $this->flattenCollection($field);
} else {
$this->flatFields[$field['name']] = $field;
}
}
}
return $this->flatFields;
} | php | public function getFlattenedFields()
{
if (!isset($this->flatFields)) {
$this->flatFields = [];
foreach ($this->fields as $field) {
if (isset($field['fields']) && is_array($field['fields'])) {
$this->flatFields += $this->flattenCollection($field);
} else {
$this->flatFields[$field['name']] = $field;
}
}
}
return $this->flatFields;
} | [
"public",
"function",
"getFlattenedFields",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"flatFields",
")",
")",
"{",
"$",
"this",
"->",
"flatFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'fields'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"field",
"[",
"'fields'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"flatFields",
"+=",
"$",
"this",
"->",
"flattenCollection",
"(",
"$",
"field",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"flatFields",
"[",
"$",
"field",
"[",
"'name'",
"]",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"flatFields",
";",
"}"
]
| Flatten all fields by moving collections into the main array
@return array | [
"Flatten",
"all",
"fields",
"by",
"moving",
"collections",
"into",
"the",
"main",
"array"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L211-L226 |
16,648 | andyvenus/form | src/FormView.php | FormView.flattenCollection | protected function flattenCollection($field)
{
if (!isset($field['fields']) || !is_array($field['fields'])) {
return [];
}
$fields = [];
foreach ($field['fields'] as $field) {
if (isset($field['fields']) && is_array($field['fields'])) {
$fields += $this->flattenCollection($field);
} else {
$fields[$field['name']] = $field;
}
}
return $fields;
} | php | protected function flattenCollection($field)
{
if (!isset($field['fields']) || !is_array($field['fields'])) {
return [];
}
$fields = [];
foreach ($field['fields'] as $field) {
if (isset($field['fields']) && is_array($field['fields'])) {
$fields += $this->flattenCollection($field);
} else {
$fields[$field['name']] = $field;
}
}
return $fields;
} | [
"protected",
"function",
"flattenCollection",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"field",
"[",
"'fields'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"field",
"[",
"'fields'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"field",
"[",
"'fields'",
"]",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'fields'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"field",
"[",
"'fields'",
"]",
")",
")",
"{",
"$",
"fields",
"+=",
"$",
"this",
"->",
"flattenCollection",
"(",
"$",
"field",
")",
";",
"}",
"else",
"{",
"$",
"fields",
"[",
"$",
"field",
"[",
"'name'",
"]",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"return",
"$",
"fields",
";",
"}"
]
| Flatten the fields in a collection
@param $field
@return array | [
"Flatten",
"the",
"fields",
"in",
"a",
"collection"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L234-L251 |
16,649 | andyvenus/form | src/FormView.php | FormView.getFieldsWithoutSection | public function getFieldsWithoutSection()
{
$matchedFields = array();
foreach ($this->fields as $fieldName => $field) {
if (!isset($field['options']['section']) || $field['options']['section'] === null || $field['options']['section'] === '') {
$matchedFields[$fieldName] = $field;
}
}
return $matchedFields;
} | php | public function getFieldsWithoutSection()
{
$matchedFields = array();
foreach ($this->fields as $fieldName => $field) {
if (!isset($field['options']['section']) || $field['options']['section'] === null || $field['options']['section'] === '') {
$matchedFields[$fieldName] = $field;
}
}
return $matchedFields;
} | [
"public",
"function",
"getFieldsWithoutSection",
"(",
")",
"{",
"$",
"matchedFields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"field",
"[",
"'options'",
"]",
"[",
"'section'",
"]",
")",
"||",
"$",
"field",
"[",
"'options'",
"]",
"[",
"'section'",
"]",
"===",
"null",
"||",
"$",
"field",
"[",
"'options'",
"]",
"[",
"'section'",
"]",
"===",
"''",
")",
"{",
"$",
"matchedFields",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"return",
"$",
"matchedFields",
";",
"}"
]
| Get any fields that don't have a section set
@return array | [
"Get",
"any",
"fields",
"that",
"don",
"t",
"have",
"a",
"section",
"set"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L258-L268 |
16,650 | andyvenus/form | src/FormView.php | FormView.translate | protected function translate($str, $params = array())
{
if (isset($this->translator)) {
return $this->translator->trans($str, $params);
}
else {
$finalParams = array();
foreach ($params as $placeholder => $value) {
$finalParams['{'.$placeholder.'}'] = $value;
}
return strtr($str, $finalParams);
}
} | php | protected function translate($str, $params = array())
{
if (isset($this->translator)) {
return $this->translator->trans($str, $params);
}
else {
$finalParams = array();
foreach ($params as $placeholder => $value) {
$finalParams['{'.$placeholder.'}'] = $value;
}
return strtr($str, $finalParams);
}
} | [
"protected",
"function",
"translate",
"(",
"$",
"str",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"translator",
")",
")",
"{",
"return",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"str",
",",
"$",
"params",
")",
";",
"}",
"else",
"{",
"$",
"finalParams",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"placeholder",
"=>",
"$",
"value",
")",
"{",
"$",
"finalParams",
"[",
"'{'",
".",
"$",
"placeholder",
".",
"'}'",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"strtr",
"(",
"$",
"str",
",",
"$",
"finalParams",
")",
";",
"}",
"}"
]
| Translate a string if the translator has been injected
@param $str string The string that will be translated
@param array $params
@return string | [
"Translate",
"a",
"string",
"if",
"the",
"translator",
"has",
"been",
"injected"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L377-L389 |
16,651 | jelix/ldapdao-module | ldapdao/plugins/auth/ldapdao/ldapdao.auth.php | ldapdaoAuthDriver._getLinkId | protected function _getLinkId()
{
if ($connect = ldap_connect($this->_params['hostname'], $this->_params['port'])) {
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, $this->_params['protocolVersion']);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
return $connect;
}
return false;
} | php | protected function _getLinkId()
{
if ($connect = ldap_connect($this->_params['hostname'], $this->_params['port'])) {
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, $this->_params['protocolVersion']);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
return $connect;
}
return false;
} | [
"protected",
"function",
"_getLinkId",
"(",
")",
"{",
"if",
"(",
"$",
"connect",
"=",
"ldap_connect",
"(",
"$",
"this",
"->",
"_params",
"[",
"'hostname'",
"]",
",",
"$",
"this",
"->",
"_params",
"[",
"'port'",
"]",
")",
")",
"{",
"ldap_set_option",
"(",
"$",
"connect",
",",
"LDAP_OPT_PROTOCOL_VERSION",
",",
"$",
"this",
"->",
"_params",
"[",
"'protocolVersion'",
"]",
")",
";",
"ldap_set_option",
"(",
"$",
"connect",
",",
"LDAP_OPT_REFERRALS",
",",
"0",
")",
";",
"return",
"$",
"connect",
";",
"}",
"return",
"false",
";",
"}"
]
| open the connection to the ldap server | [
"open",
"the",
"connection",
"to",
"the",
"ldap",
"server"
]
| 8261aadf643e95c98fcb96f5d65fa007977418cd | https://github.com/jelix/ldapdao-module/blob/8261aadf643e95c98fcb96f5d65fa007977418cd/ldapdao/plugins/auth/ldapdao/ldapdao.auth.php#L467-L475 |
16,652 | jelix/ldapdao-module | ldapdao/plugins/auth/ldapdao/ldapdao.auth.php | ldapdaoAuthDriver._bindLdapAdminUser | protected function _bindLdapAdminUser()
{
$connect = $this->_getLinkId();
if (!$connect) {
jLog::log('ldapdao: impossible to connect to ldap', 'auth');
return false;
}
if ($this->_params['adminUserDn'] == '') {
$bind = ldap_bind($connect);
} else {
$bind = ldap_bind($connect, $this->_params['adminUserDn'], $this->_params['adminPassword']);
}
if (!$bind) {
if ($this->_params['adminUserDn'] == '') {
jLog::log('ldapdao: impossible to authenticate to ldap as anonymous admin user', 'auth');
} else {
jLog::log('ldapdao: impossible to authenticate to ldap with admin user '.$this->_params['adminUserDn'], 'auth');
}
ldap_close($connect);
return false;
}
return $connect;
} | php | protected function _bindLdapAdminUser()
{
$connect = $this->_getLinkId();
if (!$connect) {
jLog::log('ldapdao: impossible to connect to ldap', 'auth');
return false;
}
if ($this->_params['adminUserDn'] == '') {
$bind = ldap_bind($connect);
} else {
$bind = ldap_bind($connect, $this->_params['adminUserDn'], $this->_params['adminPassword']);
}
if (!$bind) {
if ($this->_params['adminUserDn'] == '') {
jLog::log('ldapdao: impossible to authenticate to ldap as anonymous admin user', 'auth');
} else {
jLog::log('ldapdao: impossible to authenticate to ldap with admin user '.$this->_params['adminUserDn'], 'auth');
}
ldap_close($connect);
return false;
}
return $connect;
} | [
"protected",
"function",
"_bindLdapAdminUser",
"(",
")",
"{",
"$",
"connect",
"=",
"$",
"this",
"->",
"_getLinkId",
"(",
")",
";",
"if",
"(",
"!",
"$",
"connect",
")",
"{",
"jLog",
"::",
"log",
"(",
"'ldapdao: impossible to connect to ldap'",
",",
"'auth'",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_params",
"[",
"'adminUserDn'",
"]",
"==",
"''",
")",
"{",
"$",
"bind",
"=",
"ldap_bind",
"(",
"$",
"connect",
")",
";",
"}",
"else",
"{",
"$",
"bind",
"=",
"ldap_bind",
"(",
"$",
"connect",
",",
"$",
"this",
"->",
"_params",
"[",
"'adminUserDn'",
"]",
",",
"$",
"this",
"->",
"_params",
"[",
"'adminPassword'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"bind",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_params",
"[",
"'adminUserDn'",
"]",
"==",
"''",
")",
"{",
"jLog",
"::",
"log",
"(",
"'ldapdao: impossible to authenticate to ldap as anonymous admin user'",
",",
"'auth'",
")",
";",
"}",
"else",
"{",
"jLog",
"::",
"log",
"(",
"'ldapdao: impossible to authenticate to ldap with admin user '",
".",
"$",
"this",
"->",
"_params",
"[",
"'adminUserDn'",
"]",
",",
"'auth'",
")",
";",
"}",
"ldap_close",
"(",
"$",
"connect",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"connect",
";",
"}"
]
| open the connection to the ldap server
and bind to the admin user
@return resource|false the ldap connection | [
"open",
"the",
"connection",
"to",
"the",
"ldap",
"server",
"and",
"bind",
"to",
"the",
"admin",
"user"
]
| 8261aadf643e95c98fcb96f5d65fa007977418cd | https://github.com/jelix/ldapdao-module/blob/8261aadf643e95c98fcb96f5d65fa007977418cd/ldapdao/plugins/auth/ldapdao/ldapdao.auth.php#L482-L505 |
16,653 | ftrrtf/FtrrtfRollbarBundle | Rollbar/Environment.php | Environment.getRequestData | public function getRequestData()
{
parent::getRequestData();
if ($this->getRequest() instanceof Request) {
if (in_array($this->getRequest()->getMethod(), array('PUT', 'DELETE'))) {
$this->requestData[$this->getRequest()->getMethod()] = $this->getRequest()->request->all();
}
}
return $this->requestData;
} | php | public function getRequestData()
{
parent::getRequestData();
if ($this->getRequest() instanceof Request) {
if (in_array($this->getRequest()->getMethod(), array('PUT', 'DELETE'))) {
$this->requestData[$this->getRequest()->getMethod()] = $this->getRequest()->request->all();
}
}
return $this->requestData;
} | [
"public",
"function",
"getRequestData",
"(",
")",
"{",
"parent",
"::",
"getRequestData",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"instanceof",
"Request",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getMethod",
"(",
")",
",",
"array",
"(",
"'PUT'",
",",
"'DELETE'",
")",
")",
")",
"{",
"$",
"this",
"->",
"requestData",
"[",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getMethod",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"request",
"->",
"all",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"requestData",
";",
"}"
]
| Cached values for request.
@return array|null | [
"Cached",
"values",
"for",
"request",
"."
]
| 64c75862b80a4a1ed9e98c0d217003e84df40dd7 | https://github.com/ftrrtf/FtrrtfRollbarBundle/blob/64c75862b80a4a1ed9e98c0d217003e84df40dd7/Rollbar/Environment.php#L25-L36 |
16,654 | puli/discovery | src/Api/Type/BindingType.php | BindingType.hasParameterValues | public function hasParameterValues()
{
foreach ($this->parameters as $name => $parameter) {
if (!$parameter->isRequired()) {
return true;
}
}
return false;
} | php | public function hasParameterValues()
{
foreach ($this->parameters as $name => $parameter) {
if (!$parameter->isRequired()) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasParameterValues",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"parameters",
"as",
"$",
"name",
"=>",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"$",
"parameter",
"->",
"isRequired",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Returns whether the type has parameters with default values.
@return bool Returns `true` if at least one parameter has a default value
and `false` otherwise. | [
"Returns",
"whether",
"the",
"type",
"has",
"parameters",
"with",
"default",
"values",
"."
]
| 975f5e099563f1096bfabc17fbe4d1816408ad98 | https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/Api/Type/BindingType.php#L199-L208 |
16,655 | puli/discovery | src/Api/Type/BindingType.php | BindingType.acceptsBinding | public function acceptsBinding($binding)
{
return $binding instanceof $this->acceptedBindingClass
|| $binding === $this->acceptedBindingClass
|| is_subclass_of($binding, $this->acceptedBindingClass);
} | php | public function acceptsBinding($binding)
{
return $binding instanceof $this->acceptedBindingClass
|| $binding === $this->acceptedBindingClass
|| is_subclass_of($binding, $this->acceptedBindingClass);
} | [
"public",
"function",
"acceptsBinding",
"(",
"$",
"binding",
")",
"{",
"return",
"$",
"binding",
"instanceof",
"$",
"this",
"->",
"acceptedBindingClass",
"||",
"$",
"binding",
"===",
"$",
"this",
"->",
"acceptedBindingClass",
"||",
"is_subclass_of",
"(",
"$",
"binding",
",",
"$",
"this",
"->",
"acceptedBindingClass",
")",
";",
"}"
]
| Returns whether the type accepts a binding class.
@param Binding|string $binding The binding or the fully-qualified name of
the binding class.
@return bool Returns `true` if the binding can be bound to this type and
`false` otherwise. | [
"Returns",
"whether",
"the",
"type",
"accepts",
"a",
"binding",
"class",
"."
]
| 975f5e099563f1096bfabc17fbe4d1816408ad98 | https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/Api/Type/BindingType.php#L248-L253 |
16,656 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.updateApiEntity | public function updateApiEntity(Order $apiOrder, $locale)
{
$items = $apiOrder->getItems();
// perform price calucaltion
$prices = $supplierItems = null;
$totalPrice = $this->priceCalculator->calculate($items, $prices, $supplierItems);
if ($supplierItems) {
$supplierItems = array_values($supplierItems);
// update media api entities
$this->createMediaForSupplierItems($supplierItems, $locale);
// set grouped items
$apiOrder->setSupplierItems($supplierItems);
}
$this->createMediaForItems($items, $locale);
// check if any price in cart has changed
$hasChangedPrices = false;
foreach ($items as $item) {
if ($item->getPriceChange()) {
$hasChangedPrices = true;
break;
}
}
$apiOrder->setHasChangedPrices($hasChangedPrices);
// set total price
$apiOrder->setTotalNetPrice($totalPrice);
} | php | public function updateApiEntity(Order $apiOrder, $locale)
{
$items = $apiOrder->getItems();
// perform price calucaltion
$prices = $supplierItems = null;
$totalPrice = $this->priceCalculator->calculate($items, $prices, $supplierItems);
if ($supplierItems) {
$supplierItems = array_values($supplierItems);
// update media api entities
$this->createMediaForSupplierItems($supplierItems, $locale);
// set grouped items
$apiOrder->setSupplierItems($supplierItems);
}
$this->createMediaForItems($items, $locale);
// check if any price in cart has changed
$hasChangedPrices = false;
foreach ($items as $item) {
if ($item->getPriceChange()) {
$hasChangedPrices = true;
break;
}
}
$apiOrder->setHasChangedPrices($hasChangedPrices);
// set total price
$apiOrder->setTotalNetPrice($totalPrice);
} | [
"public",
"function",
"updateApiEntity",
"(",
"Order",
"$",
"apiOrder",
",",
"$",
"locale",
")",
"{",
"$",
"items",
"=",
"$",
"apiOrder",
"->",
"getItems",
"(",
")",
";",
"// perform price calucaltion",
"$",
"prices",
"=",
"$",
"supplierItems",
"=",
"null",
";",
"$",
"totalPrice",
"=",
"$",
"this",
"->",
"priceCalculator",
"->",
"calculate",
"(",
"$",
"items",
",",
"$",
"prices",
",",
"$",
"supplierItems",
")",
";",
"if",
"(",
"$",
"supplierItems",
")",
"{",
"$",
"supplierItems",
"=",
"array_values",
"(",
"$",
"supplierItems",
")",
";",
"// update media api entities",
"$",
"this",
"->",
"createMediaForSupplierItems",
"(",
"$",
"supplierItems",
",",
"$",
"locale",
")",
";",
"// set grouped items",
"$",
"apiOrder",
"->",
"setSupplierItems",
"(",
"$",
"supplierItems",
")",
";",
"}",
"$",
"this",
"->",
"createMediaForItems",
"(",
"$",
"items",
",",
"$",
"locale",
")",
";",
"// check if any price in cart has changed",
"$",
"hasChangedPrices",
"=",
"false",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getPriceChange",
"(",
")",
")",
"{",
"$",
"hasChangedPrices",
"=",
"true",
";",
"break",
";",
"}",
"}",
"$",
"apiOrder",
"->",
"setHasChangedPrices",
"(",
"$",
"hasChangedPrices",
")",
";",
"// set total price",
"$",
"apiOrder",
"->",
"setTotalNetPrice",
"(",
"$",
"totalPrice",
")",
";",
"}"
]
| Function updates the api-entity, like price-calculations
@param Order $apiOrder | [
"Function",
"updates",
"the",
"api",
"-",
"entity",
"like",
"price",
"-",
"calculations"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L362-L392 |
16,657 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.getContactData | public function getContactData($addressData, $contact)
{
$result = array();
// if account is set, take account's name
if ($addressData && isset($addressData['firstName']) && isset($addressData['lastName'])) {
$result['firstName'] = $addressData['firstName'];
$result['lastName'] = $addressData['lastName'];
$result['fullName'] = $result['firstName'] . ' ' . $result['lastName'];
if (isset($addressData['title'])) {
$result['title'] = $addressData['title'];
}
if (isset($addressData['salutation'])) {
$result['salutation'] = $addressData['salutation'];
}
} else {
if ($contact) {
$result['firstName'] = $contact->getFirstName();
$result['lastName'] = $contact->getLastName();
$result['fullName'] = $contact->getFullName();
$result['salutation'] = $contact->getFormOfAddress();
if ($contact->getTitle() !== null) {
$result['title'] = $contact->getTitle()->getTitle();
}
} else {
throw new MissingOrderAttributeException('firstName, lastName or contact');
}
}
return $result;
} | php | public function getContactData($addressData, $contact)
{
$result = array();
// if account is set, take account's name
if ($addressData && isset($addressData['firstName']) && isset($addressData['lastName'])) {
$result['firstName'] = $addressData['firstName'];
$result['lastName'] = $addressData['lastName'];
$result['fullName'] = $result['firstName'] . ' ' . $result['lastName'];
if (isset($addressData['title'])) {
$result['title'] = $addressData['title'];
}
if (isset($addressData['salutation'])) {
$result['salutation'] = $addressData['salutation'];
}
} else {
if ($contact) {
$result['firstName'] = $contact->getFirstName();
$result['lastName'] = $contact->getLastName();
$result['fullName'] = $contact->getFullName();
$result['salutation'] = $contact->getFormOfAddress();
if ($contact->getTitle() !== null) {
$result['title'] = $contact->getTitle()->getTitle();
}
} else {
throw new MissingOrderAttributeException('firstName, lastName or contact');
}
}
return $result;
} | [
"public",
"function",
"getContactData",
"(",
"$",
"addressData",
",",
"$",
"contact",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"// if account is set, take account's name",
"if",
"(",
"$",
"addressData",
"&&",
"isset",
"(",
"$",
"addressData",
"[",
"'firstName'",
"]",
")",
"&&",
"isset",
"(",
"$",
"addressData",
"[",
"'lastName'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'firstName'",
"]",
"=",
"$",
"addressData",
"[",
"'firstName'",
"]",
";",
"$",
"result",
"[",
"'lastName'",
"]",
"=",
"$",
"addressData",
"[",
"'lastName'",
"]",
";",
"$",
"result",
"[",
"'fullName'",
"]",
"=",
"$",
"result",
"[",
"'firstName'",
"]",
".",
"' '",
".",
"$",
"result",
"[",
"'lastName'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"addressData",
"[",
"'title'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'title'",
"]",
"=",
"$",
"addressData",
"[",
"'title'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"addressData",
"[",
"'salutation'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'salutation'",
"]",
"=",
"$",
"addressData",
"[",
"'salutation'",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"contact",
")",
"{",
"$",
"result",
"[",
"'firstName'",
"]",
"=",
"$",
"contact",
"->",
"getFirstName",
"(",
")",
";",
"$",
"result",
"[",
"'lastName'",
"]",
"=",
"$",
"contact",
"->",
"getLastName",
"(",
")",
";",
"$",
"result",
"[",
"'fullName'",
"]",
"=",
"$",
"contact",
"->",
"getFullName",
"(",
")",
";",
"$",
"result",
"[",
"'salutation'",
"]",
"=",
"$",
"contact",
"->",
"getFormOfAddress",
"(",
")",
";",
"if",
"(",
"$",
"contact",
"->",
"getTitle",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"result",
"[",
"'title'",
"]",
"=",
"$",
"contact",
"->",
"getTitle",
"(",
")",
"->",
"getTitle",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"MissingOrderAttributeException",
"(",
"'firstName, lastName or contact'",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Returns contact data as an array. Either by provided address or contact
@param array $addressData
@param Contact $contact
@throws MissingOrderAttributeException
@return array | [
"Returns",
"contact",
"data",
"as",
"an",
"array",
".",
"Either",
"by",
"provided",
"address",
"or",
"contact"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L404-L433 |
16,658 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.convertStatus | public function convertStatus($order, $statusId, $flush = false, $persist = true)
{
if ($order instanceof Order) {
$order = $order->getEntity();
}
// get current status
$currentStatus = $order->getStatus();
if ($currentStatus) {
if ($currentStatus instanceof \Massive\Bundle\Purchase\OrderBundle\Api\OrderStatus) {
$currentStatus = $order->getStatus()->getEntity();
}
// if status has not changed, skip
if ($currentStatus->getId() === $statusId) {
return;
}
}
// get desired status
$statusEntity = $this->em
->getRepository(self::$orderStatusEntityName)
->find($statusId);
if (!$statusEntity) {
throw new EntityNotFoundException(self::$orderStatusEntityName, $statusId);
}
// ACTIVITY LOG
$orderActivity = new OrderActivityLog();
$orderActivity->setOrder($order);
if ($currentStatus) {
$orderActivity->setStatusFrom($currentStatus);
}
$orderActivity->setStatusTo($statusEntity);
$orderActivity->setCreated(new \DateTime());
if ($persist) {
$this->em->persist($orderActivity);
}
// BITMASK
$currentBitmaskStatus = $order->getBitmaskStatus();
// if desired status already is in bitmask, remove current state
// since this is a step back
if ($currentBitmaskStatus && $currentBitmaskStatus & $statusEntity->getId()) {
$order->setBitmaskStatus($currentBitmaskStatus & ~$currentStatus->getId());
} else {
// else increment bitmask status
$order->setBitmaskStatus($currentBitmaskStatus | $statusEntity->getId());
}
// check if status has changed
if ($statusId === OrderStatusEntity::STATUS_CREATED) {
// TODO: re-edit - do some business logic
}
$order->setStatus($statusEntity);
if ($flush === true) {
$this->em->flush();
}
} | php | public function convertStatus($order, $statusId, $flush = false, $persist = true)
{
if ($order instanceof Order) {
$order = $order->getEntity();
}
// get current status
$currentStatus = $order->getStatus();
if ($currentStatus) {
if ($currentStatus instanceof \Massive\Bundle\Purchase\OrderBundle\Api\OrderStatus) {
$currentStatus = $order->getStatus()->getEntity();
}
// if status has not changed, skip
if ($currentStatus->getId() === $statusId) {
return;
}
}
// get desired status
$statusEntity = $this->em
->getRepository(self::$orderStatusEntityName)
->find($statusId);
if (!$statusEntity) {
throw new EntityNotFoundException(self::$orderStatusEntityName, $statusId);
}
// ACTIVITY LOG
$orderActivity = new OrderActivityLog();
$orderActivity->setOrder($order);
if ($currentStatus) {
$orderActivity->setStatusFrom($currentStatus);
}
$orderActivity->setStatusTo($statusEntity);
$orderActivity->setCreated(new \DateTime());
if ($persist) {
$this->em->persist($orderActivity);
}
// BITMASK
$currentBitmaskStatus = $order->getBitmaskStatus();
// if desired status already is in bitmask, remove current state
// since this is a step back
if ($currentBitmaskStatus && $currentBitmaskStatus & $statusEntity->getId()) {
$order->setBitmaskStatus($currentBitmaskStatus & ~$currentStatus->getId());
} else {
// else increment bitmask status
$order->setBitmaskStatus($currentBitmaskStatus | $statusEntity->getId());
}
// check if status has changed
if ($statusId === OrderStatusEntity::STATUS_CREATED) {
// TODO: re-edit - do some business logic
}
$order->setStatus($statusEntity);
if ($flush === true) {
$this->em->flush();
}
} | [
"public",
"function",
"convertStatus",
"(",
"$",
"order",
",",
"$",
"statusId",
",",
"$",
"flush",
"=",
"false",
",",
"$",
"persist",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"order",
"instanceof",
"Order",
")",
"{",
"$",
"order",
"=",
"$",
"order",
"->",
"getEntity",
"(",
")",
";",
"}",
"// get current status",
"$",
"currentStatus",
"=",
"$",
"order",
"->",
"getStatus",
"(",
")",
";",
"if",
"(",
"$",
"currentStatus",
")",
"{",
"if",
"(",
"$",
"currentStatus",
"instanceof",
"\\",
"Massive",
"\\",
"Bundle",
"\\",
"Purchase",
"\\",
"OrderBundle",
"\\",
"Api",
"\\",
"OrderStatus",
")",
"{",
"$",
"currentStatus",
"=",
"$",
"order",
"->",
"getStatus",
"(",
")",
"->",
"getEntity",
"(",
")",
";",
"}",
"// if status has not changed, skip",
"if",
"(",
"$",
"currentStatus",
"->",
"getId",
"(",
")",
"===",
"$",
"statusId",
")",
"{",
"return",
";",
"}",
"}",
"// get desired status",
"$",
"statusEntity",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"orderStatusEntityName",
")",
"->",
"find",
"(",
"$",
"statusId",
")",
";",
"if",
"(",
"!",
"$",
"statusEntity",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"orderStatusEntityName",
",",
"$",
"statusId",
")",
";",
"}",
"// ACTIVITY LOG",
"$",
"orderActivity",
"=",
"new",
"OrderActivityLog",
"(",
")",
";",
"$",
"orderActivity",
"->",
"setOrder",
"(",
"$",
"order",
")",
";",
"if",
"(",
"$",
"currentStatus",
")",
"{",
"$",
"orderActivity",
"->",
"setStatusFrom",
"(",
"$",
"currentStatus",
")",
";",
"}",
"$",
"orderActivity",
"->",
"setStatusTo",
"(",
"$",
"statusEntity",
")",
";",
"$",
"orderActivity",
"->",
"setCreated",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"if",
"(",
"$",
"persist",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"orderActivity",
")",
";",
"}",
"// BITMASK",
"$",
"currentBitmaskStatus",
"=",
"$",
"order",
"->",
"getBitmaskStatus",
"(",
")",
";",
"// if desired status already is in bitmask, remove current state",
"// since this is a step back",
"if",
"(",
"$",
"currentBitmaskStatus",
"&&",
"$",
"currentBitmaskStatus",
"&",
"$",
"statusEntity",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"order",
"->",
"setBitmaskStatus",
"(",
"$",
"currentBitmaskStatus",
"&",
"~",
"$",
"currentStatus",
"->",
"getId",
"(",
")",
")",
";",
"}",
"else",
"{",
"// else increment bitmask status",
"$",
"order",
"->",
"setBitmaskStatus",
"(",
"$",
"currentBitmaskStatus",
"|",
"$",
"statusEntity",
"->",
"getId",
"(",
")",
")",
";",
"}",
"// check if status has changed",
"if",
"(",
"$",
"statusId",
"===",
"OrderStatusEntity",
"::",
"STATUS_CREATED",
")",
"{",
"// TODO: re-edit - do some business logic",
"}",
"$",
"order",
"->",
"setStatus",
"(",
"$",
"statusEntity",
")",
";",
"if",
"(",
"$",
"flush",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"}"
]
| Converts the status of an order
@param ApiOrderInterface|OrderInterface $order
@param int $statusId
@param bool $flush
@param bool $persist
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException | [
"Converts",
"the",
"status",
"of",
"an",
"order"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L485-L544 |
16,659 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.findOrderEntityById | public function findOrderEntityById($id)
{
try {
return $this->em
->getRepository(static::$orderEntityName)
->find($id);
} catch (NoResultException $nre) {
throw new EntityNotFoundException(static::$orderEntityName, $id);
}
} | php | public function findOrderEntityById($id)
{
try {
return $this->em
->getRepository(static::$orderEntityName)
->find($id);
} catch (NoResultException $nre) {
throw new EntityNotFoundException(static::$orderEntityName, $id);
}
} | [
"public",
"function",
"findOrderEntityById",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"orderEntityName",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"nre",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"static",
"::",
"$",
"orderEntityName",
",",
"$",
"id",
")",
";",
"}",
"}"
]
| Find order entity by id
@param $id
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return OrderInterface | [
"Find",
"order",
"entity",
"by",
"id"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L575-L584 |
16,660 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.findOrderEntityForItemWithId | public function findOrderEntityForItemWithId($id, $returnMultipleResults = false)
{
try {
return $this->em
->getRepository(static::$orderEntityName)
->findOrderForItemWithId($id, $returnMultipleResults);
} catch (NoResultException $nre) {
throw new EntityNotFoundException(static::$itemEntity, $id);
}
} | php | public function findOrderEntityForItemWithId($id, $returnMultipleResults = false)
{
try {
return $this->em
->getRepository(static::$orderEntityName)
->findOrderForItemWithId($id, $returnMultipleResults);
} catch (NoResultException $nre) {
throw new EntityNotFoundException(static::$itemEntity, $id);
}
} | [
"public",
"function",
"findOrderEntityForItemWithId",
"(",
"$",
"id",
",",
"$",
"returnMultipleResults",
"=",
"false",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"orderEntityName",
")",
"->",
"findOrderForItemWithId",
"(",
"$",
"id",
",",
"$",
"returnMultipleResults",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"nre",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"static",
"::",
"$",
"itemEntity",
",",
"$",
"id",
")",
";",
"}",
"}"
]
| Find order for item with id
@param int $id
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return OrderInterface | [
"Find",
"order",
"for",
"item",
"with",
"id"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L595-L604 |
16,661 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.createMediaForSupplierItems | protected function createMediaForSupplierItems($items, $locale)
{
foreach ($items as $item) {
if (isset($item['items']) && count($item['items'] > 0)) {
$this->createMediaForItems($item['items'], $locale);
}
}
} | php | protected function createMediaForSupplierItems($items, $locale)
{
foreach ($items as $item) {
if (isset($item['items']) && count($item['items'] > 0)) {
$this->createMediaForItems($item['items'], $locale);
}
}
} | [
"protected",
"function",
"createMediaForSupplierItems",
"(",
"$",
"items",
",",
"$",
"locale",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'items'",
"]",
")",
"&&",
"count",
"(",
"$",
"item",
"[",
"'items'",
"]",
">",
"0",
")",
")",
"{",
"$",
"this",
"->",
"createMediaForItems",
"(",
"$",
"item",
"[",
"'items'",
"]",
",",
"$",
"locale",
")",
";",
"}",
"}",
"}"
]
| Creates correct media-api for supplier-items array
@param array $items
@param string $locale | [
"Creates",
"correct",
"media",
"-",
"api",
"for",
"supplier",
"-",
"items",
"array"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L790-L797 |
16,662 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.createMediaForItems | protected function createMediaForItems($items, $locale)
{
foreach ($items as $item) {
$product = $item->getProduct();
if ($product) {
$this->productManager->createProductMedia($product, $locale);
}
// Set api product for returning media-urls
$item->setProduct($product);
}
} | php | protected function createMediaForItems($items, $locale)
{
foreach ($items as $item) {
$product = $item->getProduct();
if ($product) {
$this->productManager->createProductMedia($product, $locale);
}
// Set api product for returning media-urls
$item->setProduct($product);
}
} | [
"protected",
"function",
"createMediaForItems",
"(",
"$",
"items",
",",
"$",
"locale",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"product",
"=",
"$",
"item",
"->",
"getProduct",
"(",
")",
";",
"if",
"(",
"$",
"product",
")",
"{",
"$",
"this",
"->",
"productManager",
"->",
"createProductMedia",
"(",
"$",
"product",
",",
"$",
"locale",
")",
";",
"}",
"// Set api product for returning media-urls",
"$",
"item",
"->",
"setProduct",
"(",
"$",
"product",
")",
";",
"}",
"}"
]
| Creates correct media-api for items array
@param array $items
@param string $locale | [
"Creates",
"correct",
"media",
"-",
"api",
"for",
"items",
"array"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L805-L815 |
16,663 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.setOrderType | private function setOrderType($data, ApiOrderInterface $order, $patch = false)
{
// get OrderType
$type = $this->getProperty($data, 'type', $order->getType());
// set order type
if (isset($data['type'])) {
if (is_array($type) && isset($type['id'])) {
// if provided as array
$typeId = $type['id'];
} elseif (is_numeric($type)) {
// if is numeric
$typeId = $type;
} else {
throw new OrderException('No typeid given');
}
} elseif (!$patch) {
// default type is manual
$typeId = OrderType::MANUAL;
} else {
// keep current type
return;
}
// get entity
$orderType = $this->getOrderTypeEntityById($typeId);
if (!$orderType) {
throw new EntityNotFoundException(static::$orderTypeEntityName, $typeId);
}
// set order type
$order->setType($orderType);
} | php | private function setOrderType($data, ApiOrderInterface $order, $patch = false)
{
// get OrderType
$type = $this->getProperty($data, 'type', $order->getType());
// set order type
if (isset($data['type'])) {
if (is_array($type) && isset($type['id'])) {
// if provided as array
$typeId = $type['id'];
} elseif (is_numeric($type)) {
// if is numeric
$typeId = $type;
} else {
throw new OrderException('No typeid given');
}
} elseif (!$patch) {
// default type is manual
$typeId = OrderType::MANUAL;
} else {
// keep current type
return;
}
// get entity
$orderType = $this->getOrderTypeEntityById($typeId);
if (!$orderType) {
throw new EntityNotFoundException(static::$orderTypeEntityName, $typeId);
}
// set order type
$order->setType($orderType);
} | [
"private",
"function",
"setOrderType",
"(",
"$",
"data",
",",
"ApiOrderInterface",
"$",
"order",
",",
"$",
"patch",
"=",
"false",
")",
"{",
"// get OrderType",
"$",
"type",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'type'",
",",
"$",
"order",
"->",
"getType",
"(",
")",
")",
";",
"// set order type",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"type",
")",
"&&",
"isset",
"(",
"$",
"type",
"[",
"'id'",
"]",
")",
")",
"{",
"// if provided as array",
"$",
"typeId",
"=",
"$",
"type",
"[",
"'id'",
"]",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"type",
")",
")",
"{",
"// if is numeric",
"$",
"typeId",
"=",
"$",
"type",
";",
"}",
"else",
"{",
"throw",
"new",
"OrderException",
"(",
"'No typeid given'",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"$",
"patch",
")",
"{",
"// default type is manual",
"$",
"typeId",
"=",
"OrderType",
"::",
"MANUAL",
";",
"}",
"else",
"{",
"// keep current type",
"return",
";",
"}",
"// get entity",
"$",
"orderType",
"=",
"$",
"this",
"->",
"getOrderTypeEntityById",
"(",
"$",
"typeId",
")",
";",
"if",
"(",
"!",
"$",
"orderType",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"static",
"::",
"$",
"orderTypeEntityName",
",",
"$",
"typeId",
")",
";",
"}",
"// set order type",
"$",
"order",
"->",
"setType",
"(",
"$",
"orderType",
")",
";",
"}"
]
| Sets OrderType on an order
@param array $data
@param ApiOrderInterface $order
@throws EntityNotFoundException
@throws OrderException | [
"Sets",
"OrderType",
"on",
"an",
"order"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L888-L919 |
16,664 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.addContactRelation | private function addContactRelation(array $data, $key, $addCallback)
{
$contact = null;
if (array_key_exists($key, $data) &&
is_array($data[$key]) &&
array_key_exists('id', $data[$key])
) {
/** @var Contact $contact */
$contactId = $data[$key]['id'];
$contact = $this->em->getRepository(static::$contactEntityName)->find($contactId);
if (!$contact) {
throw new OrderDependencyNotFoundException(static::$contactEntityName, $contactId);
}
$addCallback($contact);
}
return $contact;
} | php | private function addContactRelation(array $data, $key, $addCallback)
{
$contact = null;
if (array_key_exists($key, $data) &&
is_array($data[$key]) &&
array_key_exists('id', $data[$key])
) {
/** @var Contact $contact */
$contactId = $data[$key]['id'];
$contact = $this->em->getRepository(static::$contactEntityName)->find($contactId);
if (!$contact) {
throw new OrderDependencyNotFoundException(static::$contactEntityName, $contactId);
}
$addCallback($contact);
}
return $contact;
} | [
"private",
"function",
"addContactRelation",
"(",
"array",
"$",
"data",
",",
"$",
"key",
",",
"$",
"addCallback",
")",
"{",
"$",
"contact",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
"&&",
"array_key_exists",
"(",
"'id'",
",",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"/** @var Contact $contact */",
"$",
"contactId",
"=",
"$",
"data",
"[",
"$",
"key",
"]",
"[",
"'id'",
"]",
";",
"$",
"contact",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"contactEntityName",
")",
"->",
"find",
"(",
"$",
"contactId",
")",
";",
"if",
"(",
"!",
"$",
"contact",
")",
"{",
"throw",
"new",
"OrderDependencyNotFoundException",
"(",
"static",
"::",
"$",
"contactEntityName",
",",
"$",
"contactId",
")",
";",
"}",
"$",
"addCallback",
"(",
"$",
"contact",
")",
";",
"}",
"return",
"$",
"contact",
";",
"}"
]
| Searches for contact in specified data and calls callback function
@param array $data
@param string $key
@param callable $addCallback
@throws Exception\MissingOrderAttributeException
@throws Exception\OrderDependencyNotFoundException
@return Contact|null | [
"Searches",
"for",
"contact",
"in",
"specified",
"data",
"and",
"calls",
"callback",
"function"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1145-L1162 |
16,665 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.setCustomerAccount | private function setCustomerAccount($data, Order $order, $patch = false)
{
$accountData = $this->getProperty($data, 'customerAccount');
if ($accountData) {
if (!array_key_exists('id', $accountData)) {
throw new MissingOrderAttributeException('account.id');
}
$account = $this->accountRepository->find($accountData['id']);
if (!$account) {
throw new OrderDependencyNotFoundException('Account', $accountData['id']);
}
$order->setCustomerAccount($account);
return $account;
} elseif (!$patch) {
$order->setCustomerAccount(null);
}
return null;
} | php | private function setCustomerAccount($data, Order $order, $patch = false)
{
$accountData = $this->getProperty($data, 'customerAccount');
if ($accountData) {
if (!array_key_exists('id', $accountData)) {
throw new MissingOrderAttributeException('account.id');
}
$account = $this->accountRepository->find($accountData['id']);
if (!$account) {
throw new OrderDependencyNotFoundException('Account', $accountData['id']);
}
$order->setCustomerAccount($account);
return $account;
} elseif (!$patch) {
$order->setCustomerAccount(null);
}
return null;
} | [
"private",
"function",
"setCustomerAccount",
"(",
"$",
"data",
",",
"Order",
"$",
"order",
",",
"$",
"patch",
"=",
"false",
")",
"{",
"$",
"accountData",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'customerAccount'",
")",
";",
"if",
"(",
"$",
"accountData",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'id'",
",",
"$",
"accountData",
")",
")",
"{",
"throw",
"new",
"MissingOrderAttributeException",
"(",
"'account.id'",
")",
";",
"}",
"$",
"account",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"find",
"(",
"$",
"accountData",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"account",
")",
"{",
"throw",
"new",
"OrderDependencyNotFoundException",
"(",
"'Account'",
",",
"$",
"accountData",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"order",
"->",
"setCustomerAccount",
"(",
"$",
"account",
")",
";",
"return",
"$",
"account",
";",
"}",
"elseif",
"(",
"!",
"$",
"patch",
")",
"{",
"$",
"order",
"->",
"setCustomerAccount",
"(",
"null",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Sets the customer account of an order
@param array $data
@param Order $order
@param bool $patch
@return null|object
@throws MissingOrderAttributeException
@throws OrderDependencyNotFoundException | [
"Sets",
"the",
"customer",
"account",
"of",
"an",
"order"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1259-L1278 |
16,666 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php | OrderManager.processItems | private function processItems($data, Order $order, $locale, $userId = null)
{
$result = true;
try {
if ($this->checkIfSet('items', $data)) {
// items has to be an array
if (!is_array($data['items'])) {
throw new MissingOrderAttributeException('items array');
}
$items = $data['items'];
$get = function ($item) {
return $item->getId();
};
$delete = function ($item) use ($order) {
$this->removeItem($item->getEntity(), $order->getEntity());
};
$update = function ($item, $matchedEntry) use ($locale, $userId, $order) {
$item = $item->getEntity();
$itemEntity = $this->updateItem($item, $matchedEntry, $locale, $userId);
return $itemEntity ? true : false;
};
$add = function ($itemData) use ($locale, $userId, $order) {
return $this->addItem($itemData, $locale, $userId, $order);
};
$result = $this->processSubEntities(
$order->getItems(),
$items,
$get,
$add,
$update,
$delete
);
}
} catch (\Exception $e) {
throw new OrderException('Error while creating items: ' . $e->getMessage());
}
return $result;
} | php | private function processItems($data, Order $order, $locale, $userId = null)
{
$result = true;
try {
if ($this->checkIfSet('items', $data)) {
// items has to be an array
if (!is_array($data['items'])) {
throw new MissingOrderAttributeException('items array');
}
$items = $data['items'];
$get = function ($item) {
return $item->getId();
};
$delete = function ($item) use ($order) {
$this->removeItem($item->getEntity(), $order->getEntity());
};
$update = function ($item, $matchedEntry) use ($locale, $userId, $order) {
$item = $item->getEntity();
$itemEntity = $this->updateItem($item, $matchedEntry, $locale, $userId);
return $itemEntity ? true : false;
};
$add = function ($itemData) use ($locale, $userId, $order) {
return $this->addItem($itemData, $locale, $userId, $order);
};
$result = $this->processSubEntities(
$order->getItems(),
$items,
$get,
$add,
$update,
$delete
);
}
} catch (\Exception $e) {
throw new OrderException('Error while creating items: ' . $e->getMessage());
}
return $result;
} | [
"private",
"function",
"processItems",
"(",
"$",
"data",
",",
"Order",
"$",
"order",
",",
"$",
"locale",
",",
"$",
"userId",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"true",
";",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"checkIfSet",
"(",
"'items'",
",",
"$",
"data",
")",
")",
"{",
"// items has to be an array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
"[",
"'items'",
"]",
")",
")",
"{",
"throw",
"new",
"MissingOrderAttributeException",
"(",
"'items array'",
")",
";",
"}",
"$",
"items",
"=",
"$",
"data",
"[",
"'items'",
"]",
";",
"$",
"get",
"=",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"order",
")",
"{",
"$",
"this",
"->",
"removeItem",
"(",
"$",
"item",
"->",
"getEntity",
"(",
")",
",",
"$",
"order",
"->",
"getEntity",
"(",
")",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"item",
",",
"$",
"matchedEntry",
")",
"use",
"(",
"$",
"locale",
",",
"$",
"userId",
",",
"$",
"order",
")",
"{",
"$",
"item",
"=",
"$",
"item",
"->",
"getEntity",
"(",
")",
";",
"$",
"itemEntity",
"=",
"$",
"this",
"->",
"updateItem",
"(",
"$",
"item",
",",
"$",
"matchedEntry",
",",
"$",
"locale",
",",
"$",
"userId",
")",
";",
"return",
"$",
"itemEntity",
"?",
"true",
":",
"false",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"itemData",
")",
"use",
"(",
"$",
"locale",
",",
"$",
"userId",
",",
"$",
"order",
")",
"{",
"return",
"$",
"this",
"->",
"addItem",
"(",
"$",
"itemData",
",",
"$",
"locale",
",",
"$",
"userId",
",",
"$",
"order",
")",
";",
"}",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"order",
"->",
"getItems",
"(",
")",
",",
"$",
"items",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"OrderException",
"(",
"'Error while creating items: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Processes items defined in an order and creates item entities
@param array $data
@param Order $order
@param string $locale
@param int $userId
@throws Exception\OrderException
@return bool | [
"Processes",
"items",
"defined",
"in",
"an",
"order",
"and",
"creates",
"item",
"entities"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1292-L1337 |
16,667 | phpthinktank/blast-facades | src/FacadeFactory.php | FacadeFactory.create | public static function create($accessor, $name, array $arguments = [])
{
$container = static::getContainer();
$object = $container->get($accessor);
return call_user_func_array([$object, $name], $arguments);
} | php | public static function create($accessor, $name, array $arguments = [])
{
$container = static::getContainer();
$object = $container->get($accessor);
return call_user_func_array([$object, $name], $arguments);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"accessor",
",",
"$",
"name",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"$",
"container",
"=",
"static",
"::",
"getContainer",
"(",
")",
";",
"$",
"object",
"=",
"$",
"container",
"->",
"get",
"(",
"$",
"accessor",
")",
";",
"return",
"call_user_func_array",
"(",
"[",
"$",
"object",
",",
"$",
"name",
"]",
",",
"$",
"arguments",
")",
";",
"}"
]
| Get provided accessor from container and call method
@param $accessor
@param $name
@param $arguments
@return mixed | [
"Get",
"provided",
"accessor",
"from",
"container",
"and",
"call",
"method"
]
| 859fd8352f63febf3e1189ea3142afa5d6d8b9af | https://github.com/phpthinktank/blast-facades/blob/859fd8352f63febf3e1189ea3142afa5d6d8b9af/src/FacadeFactory.php#L48-L54 |
16,668 | alanpich/slender | src/Core/Autoloader/ClassLoader.php | ClassLoader.registerNamespace | public function registerNamespace($namespace, $paths, $type = 'psr-0')
{
switch ($type) {
case 'psr-0':
parent::registerNamespace($namespace, $paths);
break;
case 'psr-4':
$this->psr4Loader->addNamespace($namespace,$paths);
break;
default:
throw new AutoloadException("$type is not a known autoloader format");
}
} | php | public function registerNamespace($namespace, $paths, $type = 'psr-0')
{
switch ($type) {
case 'psr-0':
parent::registerNamespace($namespace, $paths);
break;
case 'psr-4':
$this->psr4Loader->addNamespace($namespace,$paths);
break;
default:
throw new AutoloadException("$type is not a known autoloader format");
}
} | [
"public",
"function",
"registerNamespace",
"(",
"$",
"namespace",
",",
"$",
"paths",
",",
"$",
"type",
"=",
"'psr-0'",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'psr-0'",
":",
"parent",
"::",
"registerNamespace",
"(",
"$",
"namespace",
",",
"$",
"paths",
")",
";",
"break",
";",
"case",
"'psr-4'",
":",
"$",
"this",
"->",
"psr4Loader",
"->",
"addNamespace",
"(",
"$",
"namespace",
",",
"$",
"paths",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"AutoloadException",
"(",
"\"$type is not a known autoloader format\"",
")",
";",
"}",
"}"
]
| Overridden to allow injecting psr-4 into the mix.
Also opens up doors for alternative formats to be used
later. Either way, it's a mess here right now
@param string $namespace
@param array|string $paths
@param string $type Either 'psr-0' or 'psr-4'. Defaults to 'psr-0'
@throws \Slender\Exception\AutoloadException | [
"Overridden",
"to",
"allow",
"injecting",
"psr",
"-",
"4",
"into",
"the",
"mix",
".",
"Also",
"opens",
"up",
"doors",
"for",
"alternative",
"formats",
"to",
"be",
"used",
"later",
".",
"Either",
"way",
"it",
"s",
"a",
"mess",
"here",
"right",
"now"
]
| 247f5c08af20cda95b116eb5d9f6f623d61e8a8a | https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/Core/Autoloader/ClassLoader.php#L56-L68 |
16,669 | tigris-php/telegram-bot-api | src/Types/Message.php | Message.detectType | protected static function detectType(array $data)
{
foreach ([
self::TYPE_TEXT,
self::TYPE_AUDIO,
self::TYPE_DOCUMENT,
self::TYPE_GAME,
self::TYPE_PHOTO,
self::TYPE_STICKER,
self::TYPE_VIDEO,
self::TYPE_VOICE,
self::TYPE_CONTACT,
self::TYPE_LOCATION,
self::TYPE_VENUE,
self::TYPE_VIDEO_NOTE,
self::TYPE_NEW_CHAT_MEMBERS,
self::TYPE_LEFT_CHAT_MEMBER,
self::TYPE_NEW_CHAT_TITLE,
self::TYPE_NEW_CHAT_PHOTO,
self::TYPE_DELETE_CHAT_PHOTO,
self::TYPE_GROUP_CHAT_CREATED,
self::TYPE_SUPERGROUP_CHAT_CREATED,
self::TYPE_CHANNEL_CHAT_CREATED,
self::TYPE_MESSAGE_PINNED,
self::TYPE_INVOICE,
self::TYPE_SUCCESSFUL_PAYMENT,
] as $type) {
if (isset($data[$type])) {
return $type;
}
}
return static::TYPE_UNKNOWN;
} | php | protected static function detectType(array $data)
{
foreach ([
self::TYPE_TEXT,
self::TYPE_AUDIO,
self::TYPE_DOCUMENT,
self::TYPE_GAME,
self::TYPE_PHOTO,
self::TYPE_STICKER,
self::TYPE_VIDEO,
self::TYPE_VOICE,
self::TYPE_CONTACT,
self::TYPE_LOCATION,
self::TYPE_VENUE,
self::TYPE_VIDEO_NOTE,
self::TYPE_NEW_CHAT_MEMBERS,
self::TYPE_LEFT_CHAT_MEMBER,
self::TYPE_NEW_CHAT_TITLE,
self::TYPE_NEW_CHAT_PHOTO,
self::TYPE_DELETE_CHAT_PHOTO,
self::TYPE_GROUP_CHAT_CREATED,
self::TYPE_SUPERGROUP_CHAT_CREATED,
self::TYPE_CHANNEL_CHAT_CREATED,
self::TYPE_MESSAGE_PINNED,
self::TYPE_INVOICE,
self::TYPE_SUCCESSFUL_PAYMENT,
] as $type) {
if (isset($data[$type])) {
return $type;
}
}
return static::TYPE_UNKNOWN;
} | [
"protected",
"static",
"function",
"detectType",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"[",
"self",
"::",
"TYPE_TEXT",
",",
"self",
"::",
"TYPE_AUDIO",
",",
"self",
"::",
"TYPE_DOCUMENT",
",",
"self",
"::",
"TYPE_GAME",
",",
"self",
"::",
"TYPE_PHOTO",
",",
"self",
"::",
"TYPE_STICKER",
",",
"self",
"::",
"TYPE_VIDEO",
",",
"self",
"::",
"TYPE_VOICE",
",",
"self",
"::",
"TYPE_CONTACT",
",",
"self",
"::",
"TYPE_LOCATION",
",",
"self",
"::",
"TYPE_VENUE",
",",
"self",
"::",
"TYPE_VIDEO_NOTE",
",",
"self",
"::",
"TYPE_NEW_CHAT_MEMBERS",
",",
"self",
"::",
"TYPE_LEFT_CHAT_MEMBER",
",",
"self",
"::",
"TYPE_NEW_CHAT_TITLE",
",",
"self",
"::",
"TYPE_NEW_CHAT_PHOTO",
",",
"self",
"::",
"TYPE_DELETE_CHAT_PHOTO",
",",
"self",
"::",
"TYPE_GROUP_CHAT_CREATED",
",",
"self",
"::",
"TYPE_SUPERGROUP_CHAT_CREATED",
",",
"self",
"::",
"TYPE_CHANNEL_CHAT_CREATED",
",",
"self",
"::",
"TYPE_MESSAGE_PINNED",
",",
"self",
"::",
"TYPE_INVOICE",
",",
"self",
"::",
"TYPE_SUCCESSFUL_PAYMENT",
",",
"]",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"type",
";",
"}",
"}",
"return",
"static",
"::",
"TYPE_UNKNOWN",
";",
"}"
]
| Detects message type
@param $data
@return string | [
"Detects",
"message",
"type"
]
| 7350c81d571387005d58079d8c654ee44504cdcf | https://github.com/tigris-php/telegram-bot-api/blob/7350c81d571387005d58079d8c654ee44504cdcf/src/Types/Message.php#L114-L146 |
16,670 | tbreuss/pvc | src/Middleware/MiddlewarePipe.php | MiddlewarePipe.add | public function add(MiddlewareInterface $middleware): self
{
$pipe = clone $this;
array_push($pipe->middlewares, $middleware);
return $pipe;
} | php | public function add(MiddlewareInterface $middleware): self
{
$pipe = clone $this;
array_push($pipe->middlewares, $middleware);
return $pipe;
} | [
"public",
"function",
"add",
"(",
"MiddlewareInterface",
"$",
"middleware",
")",
":",
"self",
"{",
"$",
"pipe",
"=",
"clone",
"$",
"this",
";",
"array_push",
"(",
"$",
"pipe",
"->",
"middlewares",
",",
"$",
"middleware",
")",
";",
"return",
"$",
"pipe",
";",
"}"
]
| Creates a new pipe with the given middleware connected.
@param MiddlewareInterface $middleware
@return self | [
"Creates",
"a",
"new",
"pipe",
"with",
"the",
"given",
"middleware",
"connected",
"."
]
| ae100351010a8c9f645ccb918f70a26e167de7a7 | https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/Middleware/MiddlewarePipe.php#L56-L61 |
16,671 | yuncms/framework | src/helpers/NumberHelper.php | NumberHelper.word | public static function word(int $num): string
{
$numberWordMap = [
1 => Yii::t('yuncms', 'One'),
2 => Yii::t('yuncms', 'Two'),
3 => Yii::t('yuncms', 'Three'),
4 => Yii::t('yuncms', 'Four'),
5 => Yii::t('yuncms', 'Five'),
6 => Yii::t('yuncms', 'Six'),
7 => Yii::t('yuncms', 'Seven'),
8 => Yii::t('yuncms', 'Eight'),
9 => Yii::t('yuncms', 'Nine')
];
if (isset($numberWordMap[$num])) {
return $numberWordMap[$num];
}
return (string)$num;
} | php | public static function word(int $num): string
{
$numberWordMap = [
1 => Yii::t('yuncms', 'One'),
2 => Yii::t('yuncms', 'Two'),
3 => Yii::t('yuncms', 'Three'),
4 => Yii::t('yuncms', 'Four'),
5 => Yii::t('yuncms', 'Five'),
6 => Yii::t('yuncms', 'Six'),
7 => Yii::t('yuncms', 'Seven'),
8 => Yii::t('yuncms', 'Eight'),
9 => Yii::t('yuncms', 'Nine')
];
if (isset($numberWordMap[$num])) {
return $numberWordMap[$num];
}
return (string)$num;
} | [
"public",
"static",
"function",
"word",
"(",
"int",
"$",
"num",
")",
":",
"string",
"{",
"$",
"numberWordMap",
"=",
"[",
"1",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'One'",
")",
",",
"2",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Two'",
")",
",",
"3",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Three'",
")",
",",
"4",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Four'",
")",
",",
"5",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Five'",
")",
",",
"6",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Six'",
")",
",",
"7",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Seven'",
")",
",",
"8",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Eight'",
")",
",",
"9",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Nine'",
")",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"numberWordMap",
"[",
"$",
"num",
"]",
")",
")",
"{",
"return",
"$",
"numberWordMap",
"[",
"$",
"num",
"]",
";",
"}",
"return",
"(",
"string",
")",
"$",
"num",
";",
"}"
]
| Returns the "word" version of a number
@param int $num The number
@return string The number word, or the original number if it's >= 10 | [
"Returns",
"the",
"word",
"version",
"of",
"a",
"number"
]
| af42e28ea4ae15ab8eead3f6d119f93863b94154 | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/NumberHelper.php#L22-L41 |
16,672 | nodes-php/database | src/Eloquent/Repository.php | Repository.get | public function get($columns = ['*'])
{
$result = $this->getBuilder()->get($columns);
// Reset query builder
$this->resetBuilder();
return $result;
} | php | public function get($columns = ['*'])
{
$result = $this->getBuilder()->get($columns);
// Reset query builder
$this->resetBuilder();
return $result;
} | [
"public",
"function",
"get",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"get",
"(",
"$",
"columns",
")",
";",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Execute the query and retrieve result.
@author Morten Rugaard <[email protected]>
@param array $columns
@return \Illuminate\Database\Eloquent\Collection | [
"Execute",
"the",
"query",
"and",
"retrieve",
"result",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L220-L228 |
16,673 | nodes-php/database | src/Eloquent/Repository.php | Repository.count | public function count($columns = '*')
{
$result = $this->getBuilder()->count($columns);
// Reset query builder
$this->resetBuilder();
return (int) $result;
} | php | public function count($columns = '*')
{
$result = $this->getBuilder()->count($columns);
// Reset query builder
$this->resetBuilder();
return (int) $result;
} | [
"public",
"function",
"count",
"(",
"$",
"columns",
"=",
"'*'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"count",
"(",
"$",
"columns",
")",
";",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"(",
"int",
")",
"$",
"result",
";",
"}"
]
| Execute query as a count statement.
@author Morten Rugaard <[email protected]>
@param string $columns
@return int | [
"Execute",
"query",
"as",
"a",
"count",
"statement",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L425-L433 |
16,674 | nodes-php/database | src/Eloquent/Repository.php | Repository.max | public function max($column)
{
$result = $this->getBuilder()->max($column);
// Reset query builder
$this->resetBuilder();
return $result;
} | php | public function max($column)
{
$result = $this->getBuilder()->max($column);
// Reset query builder
$this->resetBuilder();
return $result;
} | [
"public",
"function",
"max",
"(",
"$",
"column",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"max",
"(",
"$",
"column",
")",
";",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Retrieve the maximum value of a given column.
@author Morten Rugaard <[email protected]>
@param string $column
@return float|int | [
"Retrieve",
"the",
"maximum",
"value",
"of",
"a",
"given",
"column",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L461-L469 |
16,675 | nodes-php/database | src/Eloquent/Repository.php | Repository.update | public function update(array $values)
{
$result = $this->getBuilder()->update($values);
// Reset query builder
$this->resetBuilder();
return (int) $result;
} | php | public function update(array $values)
{
$result = $this->getBuilder()->update($values);
// Reset query builder
$this->resetBuilder();
return (int) $result;
} | [
"public",
"function",
"update",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"update",
"(",
"$",
"values",
")",
";",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"(",
"int",
")",
"$",
"result",
";",
"}"
]
| Execute query as an update statement.
@author Morten Rugaard <[email protected]>
@param array $values
@return int | [
"Execute",
"query",
"as",
"an",
"update",
"statement",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L584-L592 |
16,676 | nodes-php/database | src/Eloquent/Repository.php | Repository.raw | public function raw($value)
{
$result = $this->getBuilder()->raw($value);
// Reset query builder
$this->resetBuilder();
return $result;
} | php | public function raw($value)
{
$result = $this->getBuilder()->raw($value);
// Reset query builder
$this->resetBuilder();
return $result;
} | [
"public",
"function",
"raw",
"(",
"$",
"value",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"raw",
"(",
"$",
"value",
")",
";",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Create a raw database expression.
@author Morten Rugaard <[email protected]>
@param mixed $value
@return \Illuminate\Database\Query\Expression | [
"Create",
"a",
"raw",
"database",
"expression",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L691-L699 |
16,677 | nodes-php/database | src/Eloquent/Repository.php | Repository.renderSql | public function renderSql()
{
$result = vsprintf(
$this->getBuilder()->getQuery()->toSql(),
$this->getBuilder()->getQuery()->getBindings()
);
// Reset query builder
$this->resetBuilder();
return $result;
} | php | public function renderSql()
{
$result = vsprintf(
$this->getBuilder()->getQuery()->toSql(),
$this->getBuilder()->getQuery()->getBindings()
);
// Reset query builder
$this->resetBuilder();
return $result;
} | [
"public",
"function",
"renderSql",
"(",
")",
"{",
"$",
"result",
"=",
"vsprintf",
"(",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"getQuery",
"(",
")",
"->",
"toSql",
"(",
")",
",",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"getQuery",
"(",
")",
"->",
"getBindings",
"(",
")",
")",
";",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Render repository's query SQL string.
@author Morten Rugaard <[email protected]>
@return string | [
"Render",
"repository",
"s",
"query",
"SQL",
"string",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L725-L736 |
16,678 | nodes-php/database | src/Eloquent/Repository.php | Repository.withTrashed | public function withTrashed()
{
// Validate model is soft deletable
if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
}
// Set repository builder to include soft deleted entries
$this->setBuilder($this->getModel()->withTrashed());
return $this;
} | php | public function withTrashed()
{
// Validate model is soft deletable
if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
}
// Set repository builder to include soft deleted entries
$this->setBuilder($this->getModel()->withTrashed());
return $this;
} | [
"public",
"function",
"withTrashed",
"(",
")",
"{",
"// Validate model is soft deletable",
"if",
"(",
"!",
"in_array",
"(",
"IlluminateEloquentSoftDeletes",
"::",
"class",
",",
"class_uses",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
")",
")",
"{",
"throw",
"new",
"ModelNotSoftDeletable",
"(",
"'Model [%s] is not using the Soft Delete trait'",
")",
";",
"}",
"// Set repository builder to include soft deleted entries",
"$",
"this",
"->",
"setBuilder",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"withTrashed",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Include soft deleted entries in query.
Note this will reset the build
@author Morten Rugaard <[email protected]>
@throws \Nodes\Database\Exceptions\ModelNotSoftDeletable | [
"Include",
"soft",
"deleted",
"entries",
"in",
"query",
".",
"Note",
"this",
"will",
"reset",
"the",
"build"
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L746-L757 |
16,679 | nodes-php/database | src/Eloquent/Repository.php | Repository.onlyTrashed | public function onlyTrashed()
{
// Validate model is soft deletable
if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
}
// Set repository builder to include soft deleted entries
$this->setBuilder($this->getModel()->onlyTrashed());
return $this;
} | php | public function onlyTrashed()
{
// Validate model is soft deletable
if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
}
// Set repository builder to include soft deleted entries
$this->setBuilder($this->getModel()->onlyTrashed());
return $this;
} | [
"public",
"function",
"onlyTrashed",
"(",
")",
"{",
"// Validate model is soft deletable",
"if",
"(",
"!",
"in_array",
"(",
"IlluminateEloquentSoftDeletes",
"::",
"class",
",",
"class_uses",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
")",
")",
"{",
"throw",
"new",
"ModelNotSoftDeletable",
"(",
"'Model [%s] is not using the Soft Delete trait'",
")",
";",
"}",
"// Set repository builder to include soft deleted entries",
"$",
"this",
"->",
"setBuilder",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"onlyTrashed",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Only include soft deleted entries in query.
Note this will reset the build
@author Morten Rugaard <[email protected]>
@return $this
@throws \Nodes\Database\Exceptions\ModelNotSoftDeletable | [
"Only",
"include",
"soft",
"deleted",
"entries",
"in",
"query",
".",
"Note",
"this",
"will",
"reset",
"the",
"build"
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L768-L779 |
16,680 | nodes-php/database | src/Eloquent/Repository.php | Repository.getByContinuously | public function getByContinuously($column, $value, array $columns = ['*'], $retries = 10, $delayMs = 100, $maxDelay = 2000, $maxRetries = 100)
{
// Hard limits
$maxDelay = ($maxDelay > 2000) ? 2000 : $maxDelay;
$maxRetries = ($maxRetries > 100) ? 100 : $maxRetries;
// Validate delay parameter
if ($delayMs > $maxDelay) {
throw new NodesException('Invalid input parameter. Maximum delay is '.$maxDelay.' milliseconds', 0, null, false);
}
// Validate retry parameter
if ($retries > $maxRetries) {
throw new NodesException('Invalid input parameter. Maximum retry amount is '.$maxRetries, 0, null, false);
}
// Retrieve entity continuously
for ($try = 0; $try < $retries; $try++) {
$entity = $this->getBy($column, $value, $columns);
if (! empty($entity)) {
return $entity;
}
// Delay next retry
usleep($delayMs * 1000);
}
return false;
} | php | public function getByContinuously($column, $value, array $columns = ['*'], $retries = 10, $delayMs = 100, $maxDelay = 2000, $maxRetries = 100)
{
// Hard limits
$maxDelay = ($maxDelay > 2000) ? 2000 : $maxDelay;
$maxRetries = ($maxRetries > 100) ? 100 : $maxRetries;
// Validate delay parameter
if ($delayMs > $maxDelay) {
throw new NodesException('Invalid input parameter. Maximum delay is '.$maxDelay.' milliseconds', 0, null, false);
}
// Validate retry parameter
if ($retries > $maxRetries) {
throw new NodesException('Invalid input parameter. Maximum retry amount is '.$maxRetries, 0, null, false);
}
// Retrieve entity continuously
for ($try = 0; $try < $retries; $try++) {
$entity = $this->getBy($column, $value, $columns);
if (! empty($entity)) {
return $entity;
}
// Delay next retry
usleep($delayMs * 1000);
}
return false;
} | [
"public",
"function",
"getByContinuously",
"(",
"$",
"column",
",",
"$",
"value",
",",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
",",
"$",
"retries",
"=",
"10",
",",
"$",
"delayMs",
"=",
"100",
",",
"$",
"maxDelay",
"=",
"2000",
",",
"$",
"maxRetries",
"=",
"100",
")",
"{",
"// Hard limits",
"$",
"maxDelay",
"=",
"(",
"$",
"maxDelay",
">",
"2000",
")",
"?",
"2000",
":",
"$",
"maxDelay",
";",
"$",
"maxRetries",
"=",
"(",
"$",
"maxRetries",
">",
"100",
")",
"?",
"100",
":",
"$",
"maxRetries",
";",
"// Validate delay parameter",
"if",
"(",
"$",
"delayMs",
">",
"$",
"maxDelay",
")",
"{",
"throw",
"new",
"NodesException",
"(",
"'Invalid input parameter. Maximum delay is '",
".",
"$",
"maxDelay",
".",
"' milliseconds'",
",",
"0",
",",
"null",
",",
"false",
")",
";",
"}",
"// Validate retry parameter",
"if",
"(",
"$",
"retries",
">",
"$",
"maxRetries",
")",
"{",
"throw",
"new",
"NodesException",
"(",
"'Invalid input parameter. Maximum retry amount is '",
".",
"$",
"maxRetries",
",",
"0",
",",
"null",
",",
"false",
")",
";",
"}",
"// Retrieve entity continuously",
"for",
"(",
"$",
"try",
"=",
"0",
";",
"$",
"try",
"<",
"$",
"retries",
";",
"$",
"try",
"++",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"getBy",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"columns",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"entity",
")",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"// Delay next retry",
"usleep",
"(",
"$",
"delayMs",
"*",
"1000",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Retrieve entity by a specific column and value. Will retry with a delay until found.
Should only be used in queues, where databases are in a cluster
and there's a chance it's not always in sync
@author Casper Rasmussen <[email protected]>
@param string $column
@param string $value
@param array $columns
@param int $retries
@param int $delayMs
@param int $maxDelay
@param int $maxRetries
@return \Illuminate\Database\Eloquent\Model
@throws \Nodes\Exceptions\Exception | [
"Retrieve",
"entity",
"by",
"a",
"specific",
"column",
"and",
"value",
".",
"Will",
"retry",
"with",
"a",
"delay",
"until",
"found",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L975-L1003 |
16,681 | nodes-php/database | src/Eloquent/Repository.php | Repository.getByIdContinuously | public function getByIdContinuously($id, array $columns = ['*'], $retries = 10, $delayMs = 100)
{
return $this->getByContinuously('id', $id, $columns, $retries, $delayMs);
} | php | public function getByIdContinuously($id, array $columns = ['*'], $retries = 10, $delayMs = 100)
{
return $this->getByContinuously('id', $id, $columns, $retries, $delayMs);
} | [
"public",
"function",
"getByIdContinuously",
"(",
"$",
"id",
",",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
",",
"$",
"retries",
"=",
"10",
",",
"$",
"delayMs",
"=",
"100",
")",
"{",
"return",
"$",
"this",
"->",
"getByContinuously",
"(",
"'id'",
",",
"$",
"id",
",",
"$",
"columns",
",",
"$",
"retries",
",",
"$",
"delayMs",
")",
";",
"}"
]
| Retrieve entity by ID. Will retry with a delay until found.
Should only be used in queues, where databases are in a cluster
and there's a chance it's not always in sync
@author Casper Rasmussen <[email protected]>
@param int $id
@param array $columns
@param int $retries
@param int $delayMs
@return \Illuminate\Database\Eloquent\Model
@throws \Nodes\Exceptions\Exception | [
"Retrieve",
"entity",
"by",
"ID",
".",
"Will",
"retry",
"with",
"a",
"delay",
"until",
"found",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1020-L1023 |
16,682 | nodes-php/database | src/Eloquent/Repository.php | Repository.getByIdContinuouslyOrFail | public function getByIdContinuouslyOrFail($id, array $columns = ['*'], $retries = 10, $delayMs = 100)
{
$result = $this->getByContinuously('id', $id, $columns, $retries, $delayMs);
if (empty($result)) {
throw new EntityNotFoundException(sprintf('%s not found continuously by Id with value [%s]',
get_class($this->getModel()), $id));
}
return $result;
} | php | public function getByIdContinuouslyOrFail($id, array $columns = ['*'], $retries = 10, $delayMs = 100)
{
$result = $this->getByContinuously('id', $id, $columns, $retries, $delayMs);
if (empty($result)) {
throw new EntityNotFoundException(sprintf('%s not found continuously by Id with value [%s]',
get_class($this->getModel()), $id));
}
return $result;
} | [
"public",
"function",
"getByIdContinuouslyOrFail",
"(",
"$",
"id",
",",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
",",
"$",
"retries",
"=",
"10",
",",
"$",
"delayMs",
"=",
"100",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getByContinuously",
"(",
"'id'",
",",
"$",
"id",
",",
"$",
"columns",
",",
"$",
"retries",
",",
"$",
"delayMs",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"sprintf",
"(",
"'%s not found continuously by Id with value [%s]'",
",",
"get_class",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
",",
"$",
"id",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Retrieve entity by ID. Will retry with a delay until found or throw an exception.
Should only be used in queues, where databases are in a cluster
and there's a chance it's not always in sync
@author Rasmus Ebbesen <[email protected]>
@param int $id
@param array $columns
@param int $retries
@param int $delayMs
@return \Illuminate\Database\Eloquent\Model
@throws \Nodes\Database\Exceptions\EntityNotFoundException | [
"Retrieve",
"entity",
"by",
"ID",
".",
"Will",
"retry",
"with",
"a",
"delay",
"until",
"found",
"or",
"throw",
"an",
"exception",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1040-L1049 |
16,683 | nodes-php/database | src/Eloquent/Repository.php | Repository.deleteMorphsByEntity | public function deleteMorphsByEntity(IlluminateEloquentModel $entity, $relationName, $forceDelete = false)
{
// Retrieve all records by entity type and entity ID
$entities = $this->getBuilder()
->select(['id'])
->where(function ($query) use ($entity, $relationName) {
$query->where($relationName.'_type', '=', get_class($entity))
->where($relationName.'_id', '=', (int) $entity->id);
})
->get();
// Delete count
$deleteCount = 0;
// Loop through each entity individually.
// This is required to soft delete all found entiries.
foreach ($entities as $e) {
$status = ($forceDelete) ? $e->forceDelete() : $e->delete();
if ((bool) $status) {
$deleteCount += 1;
}
}
// Reset query builder
$this->resetBuilder();
return $deleteCount;
} | php | public function deleteMorphsByEntity(IlluminateEloquentModel $entity, $relationName, $forceDelete = false)
{
// Retrieve all records by entity type and entity ID
$entities = $this->getBuilder()
->select(['id'])
->where(function ($query) use ($entity, $relationName) {
$query->where($relationName.'_type', '=', get_class($entity))
->where($relationName.'_id', '=', (int) $entity->id);
})
->get();
// Delete count
$deleteCount = 0;
// Loop through each entity individually.
// This is required to soft delete all found entiries.
foreach ($entities as $e) {
$status = ($forceDelete) ? $e->forceDelete() : $e->delete();
if ((bool) $status) {
$deleteCount += 1;
}
}
// Reset query builder
$this->resetBuilder();
return $deleteCount;
} | [
"public",
"function",
"deleteMorphsByEntity",
"(",
"IlluminateEloquentModel",
"$",
"entity",
",",
"$",
"relationName",
",",
"$",
"forceDelete",
"=",
"false",
")",
"{",
"// Retrieve all records by entity type and entity ID",
"$",
"entities",
"=",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"select",
"(",
"[",
"'id'",
"]",
")",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"entity",
",",
"$",
"relationName",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"relationName",
".",
"'_type'",
",",
"'='",
",",
"get_class",
"(",
"$",
"entity",
")",
")",
"->",
"where",
"(",
"$",
"relationName",
".",
"'_id'",
",",
"'='",
",",
"(",
"int",
")",
"$",
"entity",
"->",
"id",
")",
";",
"}",
")",
"->",
"get",
"(",
")",
";",
"// Delete count",
"$",
"deleteCount",
"=",
"0",
";",
"// Loop through each entity individually.",
"// This is required to soft delete all found entiries.",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"e",
")",
"{",
"$",
"status",
"=",
"(",
"$",
"forceDelete",
")",
"?",
"$",
"e",
"->",
"forceDelete",
"(",
")",
":",
"$",
"e",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"(",
"bool",
")",
"$",
"status",
")",
"{",
"$",
"deleteCount",
"+=",
"1",
";",
"}",
"}",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"$",
"deleteCount",
";",
"}"
]
| Delete morphed relations by entity.
Note: This should only be used with morphed relations
@author Morten Rugaard <[email protected]>
@param \Illuminate\Database\Eloquent\Model $entity
@param string $relationName
@param bool $forceDelete
@return int | [
"Delete",
"morphed",
"relations",
"by",
"entity",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1063-L1090 |
16,684 | nodes-php/database | src/Eloquent/Repository.php | Repository.restoreMorphsByEntity | public function restoreMorphsByEntity(IlluminateEloquentModel $entity, $relationName)
{
// Validate model is soft deletable
if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
}
// Retrieve all records by entity type and entity ID
$entities = $this->onlyTrashed()
->getBuilder()
->select(['id'])
->where(function ($query) use ($entity, $relationName) {
$query->where($relationName.'_type', '=', get_class($entity))
->where($relationName.'_id', '=', (int) $entity->id);
})
->get();
// Restore count
$restoreCount = 0;
// Loop through each entity individually.
// This is required to soft delete all found entiries.
foreach ($entities as $e) {
if ((bool) $e->restore()) {
$restoreCount += 1;
}
}
// Reset query builder
$this->resetBuilder();
return $restoreCount;
} | php | public function restoreMorphsByEntity(IlluminateEloquentModel $entity, $relationName)
{
// Validate model is soft deletable
if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
}
// Retrieve all records by entity type and entity ID
$entities = $this->onlyTrashed()
->getBuilder()
->select(['id'])
->where(function ($query) use ($entity, $relationName) {
$query->where($relationName.'_type', '=', get_class($entity))
->where($relationName.'_id', '=', (int) $entity->id);
})
->get();
// Restore count
$restoreCount = 0;
// Loop through each entity individually.
// This is required to soft delete all found entiries.
foreach ($entities as $e) {
if ((bool) $e->restore()) {
$restoreCount += 1;
}
}
// Reset query builder
$this->resetBuilder();
return $restoreCount;
} | [
"public",
"function",
"restoreMorphsByEntity",
"(",
"IlluminateEloquentModel",
"$",
"entity",
",",
"$",
"relationName",
")",
"{",
"// Validate model is soft deletable",
"if",
"(",
"!",
"in_array",
"(",
"IlluminateEloquentSoftDeletes",
"::",
"class",
",",
"class_uses",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
")",
")",
"{",
"throw",
"new",
"ModelNotSoftDeletable",
"(",
"'Model [%s] is not using the Soft Delete trait'",
")",
";",
"}",
"// Retrieve all records by entity type and entity ID",
"$",
"entities",
"=",
"$",
"this",
"->",
"onlyTrashed",
"(",
")",
"->",
"getBuilder",
"(",
")",
"->",
"select",
"(",
"[",
"'id'",
"]",
")",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"entity",
",",
"$",
"relationName",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"relationName",
".",
"'_type'",
",",
"'='",
",",
"get_class",
"(",
"$",
"entity",
")",
")",
"->",
"where",
"(",
"$",
"relationName",
".",
"'_id'",
",",
"'='",
",",
"(",
"int",
")",
"$",
"entity",
"->",
"id",
")",
";",
"}",
")",
"->",
"get",
"(",
")",
";",
"// Restore count",
"$",
"restoreCount",
"=",
"0",
";",
"// Loop through each entity individually.",
"// This is required to soft delete all found entiries.",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"(",
"bool",
")",
"$",
"e",
"->",
"restore",
"(",
")",
")",
"{",
"$",
"restoreCount",
"+=",
"1",
";",
"}",
"}",
"// Reset query builder",
"$",
"this",
"->",
"resetBuilder",
"(",
")",
";",
"return",
"$",
"restoreCount",
";",
"}"
]
| Restore morphed relations by entity.
Note: This should only be used with morphed relations
@author Morten Rugaard <[email protected]>
@param \Illuminate\Database\Eloquent\Model $entity
@param string $relationName
@return int
@throws \Nodes\Database\Exceptions\ModelNotSoftDeletable | [
"Restore",
"morphed",
"relations",
"by",
"entity",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1104-L1136 |
16,685 | nodes-php/database | src/Eloquent/Repository.php | Repository.setModel | public function setModel(IlluminateEloquentModel $model)
{
// Set repository model
$this->model = $model;
// Set repository builder from model
$this->setBuilder($model->newQuery());
return $this;
} | php | public function setModel(IlluminateEloquentModel $model)
{
// Set repository model
$this->model = $model;
// Set repository builder from model
$this->setBuilder($model->newQuery());
return $this;
} | [
"public",
"function",
"setModel",
"(",
"IlluminateEloquentModel",
"$",
"model",
")",
"{",
"// Set repository model",
"$",
"this",
"->",
"model",
"=",
"$",
"model",
";",
"// Set repository builder from model",
"$",
"this",
"->",
"setBuilder",
"(",
"$",
"model",
"->",
"newQuery",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set repository model.
@author Morten Rugaard <[email protected]>
@param \Illuminate\Database\Eloquent\Model $model
@return $this | [
"Set",
"repository",
"model",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1182-L1191 |
16,686 | nodes-php/database | src/Eloquent/Repository.php | Repository.setBuilder | public function setBuilder(IlluminateEloquentBuilder $builder = null)
{
// If no builder was provided,
// we'll use the one from this repositorys model
if (empty($builder)) {
$builder = $this->getModel()->newQuery();
}
// Set repository builder
$this->builder = $builder;
return $this;
} | php | public function setBuilder(IlluminateEloquentBuilder $builder = null)
{
// If no builder was provided,
// we'll use the one from this repositorys model
if (empty($builder)) {
$builder = $this->getModel()->newQuery();
}
// Set repository builder
$this->builder = $builder;
return $this;
} | [
"public",
"function",
"setBuilder",
"(",
"IlluminateEloquentBuilder",
"$",
"builder",
"=",
"null",
")",
"{",
"// If no builder was provided,",
"// we'll use the one from this repositorys model",
"if",
"(",
"empty",
"(",
"$",
"builder",
")",
")",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"newQuery",
"(",
")",
";",
"}",
"// Set repository builder",
"$",
"this",
"->",
"builder",
"=",
"$",
"builder",
";",
"return",
"$",
"this",
";",
"}"
]
| Set repository builder.
@author Morten Rugaard <[email protected]>
@acecss public
@param \Illuminate\Database\Eloquent\Builder $builder
@return $this | [
"Set",
"repository",
"builder",
"."
]
| ec58a01a2b966f89efeac58ac9ac633919c04a52 | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1214-L1226 |
16,687 | askupasoftware/amarkal | Assets/Script.php | Script.register | public function register()
{
wp_register_script(
$this->handle,
$this->url,
$this->dependencies,
$this->version,
$this->footer
);
// Localize the script as needed
if( !empty( $this->localize['data'] ) && !empty( $this->localize['data'] ) ) {
wp_localize_script(
$this->handle,
$this->localize['name'],
$this->localize['data']
);
}
$this->is_registered = true;
} | php | public function register()
{
wp_register_script(
$this->handle,
$this->url,
$this->dependencies,
$this->version,
$this->footer
);
// Localize the script as needed
if( !empty( $this->localize['data'] ) && !empty( $this->localize['data'] ) ) {
wp_localize_script(
$this->handle,
$this->localize['name'],
$this->localize['data']
);
}
$this->is_registered = true;
} | [
"public",
"function",
"register",
"(",
")",
"{",
"wp_register_script",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"dependencies",
",",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"footer",
")",
";",
"// Localize the script as needed",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"localize",
"[",
"'data'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"localize",
"[",
"'data'",
"]",
")",
")",
"{",
"wp_localize_script",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"this",
"->",
"localize",
"[",
"'name'",
"]",
",",
"$",
"this",
"->",
"localize",
"[",
"'data'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"is_registered",
"=",
"true",
";",
"}"
]
| Enqueue the script and localize the data as needed | [
"Enqueue",
"the",
"script",
"and",
"localize",
"the",
"data",
"as",
"needed"
]
| fe8283e2d6847ef697abec832da7ee741a85058c | https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Assets/Script.php#L39-L58 |
16,688 | comodojo/cookies | src/Comodojo/Cookies/AbstractCookie.php | AbstractCookie.erase | public static function erase($name) {
try {
$class = get_called_class();
$cookie = new $class($name);
return $cookie->delete();
} catch (CookieException $ce) {
throw $ce;
}
} | php | public static function erase($name) {
try {
$class = get_called_class();
$cookie = new $class($name);
return $cookie->delete();
} catch (CookieException $ce) {
throw $ce;
}
} | [
"public",
"static",
"function",
"erase",
"(",
"$",
"name",
")",
"{",
"try",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"$",
"cookie",
"=",
"new",
"$",
"class",
"(",
"$",
"name",
")",
";",
"return",
"$",
"cookie",
"->",
"delete",
"(",
")",
";",
"}",
"catch",
"(",
"CookieException",
"$",
"ce",
")",
"{",
"throw",
"$",
"ce",
";",
"}",
"}"
]
| Static method to quickly delete a cookie
@param string $name
The cookie name
@return boolean
@throws CookieException | [
"Static",
"method",
"to",
"quickly",
"delete",
"a",
"cookie"
]
| a81c7dff37d52c1a75462c0ad30db75d0c3b0081 | https://github.com/comodojo/cookies/blob/a81c7dff37d52c1a75462c0ad30db75d0c3b0081/src/Comodojo/Cookies/AbstractCookie.php#L275-L291 |
16,689 | ammarfaizi2/Brainly | src/Brainly.php | Brainly.isPerfectCache | private function isPerfectCache()
{
if ($this->cacheMap[$this->hash] + 0x93a80 > time()) {
$this->cacheData = json_decode(
file_get_contents(
$this->cacheFile
),
true
);
return is_array($this->cacheData);
}
return false;
} | php | private function isPerfectCache()
{
if ($this->cacheMap[$this->hash] + 0x93a80 > time()) {
$this->cacheData = json_decode(
file_get_contents(
$this->cacheFile
),
true
);
return is_array($this->cacheData);
}
return false;
} | [
"private",
"function",
"isPerfectCache",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheMap",
"[",
"$",
"this",
"->",
"hash",
"]",
"+",
"0x93a80",
">",
"time",
"(",
")",
")",
"{",
"$",
"this",
"->",
"cacheData",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"cacheFile",
")",
",",
"true",
")",
";",
"return",
"is_array",
"(",
"$",
"this",
"->",
"cacheData",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Check the current cache is perfect or not.
@return bool | [
"Check",
"the",
"current",
"cache",
"is",
"perfect",
"or",
"not",
"."
]
| fe543a58563ed4ff4294a6c8c21ff719dd487b89 | https://github.com/ammarfaizi2/Brainly/blob/fe543a58563ed4ff4294a6c8c21ff719dd487b89/src/Brainly.php#L107-L119 |
16,690 | ammarfaizi2/Brainly | src/Brainly.php | Brainly._exec | private function _exec()
{
if ($this->isCached() && $this->isPerfectCache()) {
return $this->getCache();
} else {
return $this->fixer(
$this->search(
$this->query,
$this->limit
)
);
}
} | php | private function _exec()
{
if ($this->isCached() && $this->isPerfectCache()) {
return $this->getCache();
} else {
return $this->fixer(
$this->search(
$this->query,
$this->limit
)
);
}
} | [
"private",
"function",
"_exec",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCached",
"(",
")",
"&&",
"$",
"this",
"->",
"isPerfectCache",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getCache",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"fixer",
"(",
"$",
"this",
"->",
"search",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"limit",
")",
")",
";",
"}",
"}"
]
| Search data. | [
"Search",
"data",
"."
]
| fe543a58563ed4ff4294a6c8c21ff719dd487b89 | https://github.com/ammarfaizi2/Brainly/blob/fe543a58563ed4ff4294a6c8c21ff719dd487b89/src/Brainly.php#L137-L149 |
16,691 | ammarfaizi2/Brainly | src/Brainly.php | Brainly.fixer | private function fixer($data, $noWrite = false)
{
if (
$noWrite or $this->writeCache($data)
) {
$data = $noWrite ? $data : json_decode($data, true);
if ($data['success'] === true) {
if (isset($data['data']['tasks']['items'])) {
$r = [];
foreach ($data['data']['tasks']['items'] as $k => $v) {
$responses = [];
foreach ($v['responses'] as $j => $q) {
$responses[] = [
"content" => $q['content']
];
}
$r[] = [
"content" => $v['task']['content'],
"responses" => $responses
];
}
return $r;
}
}
}
return false;
} | php | private function fixer($data, $noWrite = false)
{
if (
$noWrite or $this->writeCache($data)
) {
$data = $noWrite ? $data : json_decode($data, true);
if ($data['success'] === true) {
if (isset($data['data']['tasks']['items'])) {
$r = [];
foreach ($data['data']['tasks']['items'] as $k => $v) {
$responses = [];
foreach ($v['responses'] as $j => $q) {
$responses[] = [
"content" => $q['content']
];
}
$r[] = [
"content" => $v['task']['content'],
"responses" => $responses
];
}
return $r;
}
}
}
return false;
} | [
"private",
"function",
"fixer",
"(",
"$",
"data",
",",
"$",
"noWrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"noWrite",
"or",
"$",
"this",
"->",
"writeCache",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"$",
"noWrite",
"?",
"$",
"data",
":",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'success'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'data'",
"]",
"[",
"'tasks'",
"]",
"[",
"'items'",
"]",
")",
")",
"{",
"$",
"r",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'data'",
"]",
"[",
"'tasks'",
"]",
"[",
"'items'",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"responses",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"v",
"[",
"'responses'",
"]",
"as",
"$",
"j",
"=>",
"$",
"q",
")",
"{",
"$",
"responses",
"[",
"]",
"=",
"[",
"\"content\"",
"=>",
"$",
"q",
"[",
"'content'",
"]",
"]",
";",
"}",
"$",
"r",
"[",
"]",
"=",
"[",
"\"content\"",
"=>",
"$",
"v",
"[",
"'task'",
"]",
"[",
"'content'",
"]",
",",
"\"responses\"",
"=>",
"$",
"responses",
"]",
";",
"}",
"return",
"$",
"r",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Fix raw data.
@param string $data
@return array | [
"Fix",
"raw",
"data",
"."
]
| fe543a58563ed4ff4294a6c8c21ff719dd487b89 | https://github.com/ammarfaizi2/Brainly/blob/fe543a58563ed4ff4294a6c8c21ff719dd487b89/src/Brainly.php#L189-L215 |
16,692 | ammarfaizi2/Brainly | src/Brainly.php | Brainly.writeCache | private function writeCache($data)
{
$this->cacheMap[$this->hash] = time();
$handle = fopen($this->cacheMapFile, "w");
flock($handle, LOCK_EX);
$write1 = fwrite($handle,
json_encode(
$this->cacheMap,
JSON_UNESCAPED_SLASHES
)
);
fclose($handle);
$handle = fopen($this->cacheFile, "w");
flock($handle, LOCK_EX);
$write2 = fwrite($handle, $data);
fclose($handle);
return (
(bool) $write1 && (bool) $write2
);
} | php | private function writeCache($data)
{
$this->cacheMap[$this->hash] = time();
$handle = fopen($this->cacheMapFile, "w");
flock($handle, LOCK_EX);
$write1 = fwrite($handle,
json_encode(
$this->cacheMap,
JSON_UNESCAPED_SLASHES
)
);
fclose($handle);
$handle = fopen($this->cacheFile, "w");
flock($handle, LOCK_EX);
$write2 = fwrite($handle, $data);
fclose($handle);
return (
(bool) $write1 && (bool) $write2
);
} | [
"private",
"function",
"writeCache",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"cacheMap",
"[",
"$",
"this",
"->",
"hash",
"]",
"=",
"time",
"(",
")",
";",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"cacheMapFile",
",",
"\"w\"",
")",
";",
"flock",
"(",
"$",
"handle",
",",
"LOCK_EX",
")",
";",
"$",
"write1",
"=",
"fwrite",
"(",
"$",
"handle",
",",
"json_encode",
"(",
"$",
"this",
"->",
"cacheMap",
",",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"cacheFile",
",",
"\"w\"",
")",
";",
"flock",
"(",
"$",
"handle",
",",
"LOCK_EX",
")",
";",
"$",
"write2",
"=",
"fwrite",
"(",
"$",
"handle",
",",
"$",
"data",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"return",
"(",
"(",
"bool",
")",
"$",
"write1",
"&&",
"(",
"bool",
")",
"$",
"write2",
")",
";",
"}"
]
| Write cache.
@param string $data
@return bool | [
"Write",
"cache",
"."
]
| fe543a58563ed4ff4294a6c8c21ff719dd487b89 | https://github.com/ammarfaizi2/Brainly/blob/fe543a58563ed4ff4294a6c8c21ff719dd487b89/src/Brainly.php#L223-L242 |
16,693 | SAREhub/PHP_Commons | src/SAREhub/Commons/Zmq/RequestReply/RequestReceiver.php | RequestReceiver.unbind | public function unbind()
{
if ($this->isBinded()) {
$this->getSocket()->unbind($this->dsn);
$this->dsn = null;
}
return $this;
} | php | public function unbind()
{
if ($this->isBinded()) {
$this->getSocket()->unbind($this->dsn);
$this->dsn = null;
}
return $this;
} | [
"public",
"function",
"unbind",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBinded",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getSocket",
"(",
")",
"->",
"unbind",
"(",
"$",
"this",
"->",
"dsn",
")",
";",
"$",
"this",
"->",
"dsn",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Unbinds socket from current binded dsn
@return $this | [
"Unbinds",
"socket",
"from",
"current",
"binded",
"dsn"
]
| 4e1769ab6411a584112df1151dcc90e6b82fe2bb | https://github.com/SAREhub/PHP_Commons/blob/4e1769ab6411a584112df1151dcc90e6b82fe2bb/src/SAREhub/Commons/Zmq/RequestReply/RequestReceiver.php#L68-L76 |
16,694 | SAREhub/PHP_Commons | src/SAREhub/Commons/Zmq/RequestReply/RequestReceiver.php | RequestReceiver.receiveRequest | public function receiveRequest($wait = self::WAIT)
{
return $this->getSocket()->recv(($wait ? 0 : \ZMQ::MODE_DONTWAIT));
} | php | public function receiveRequest($wait = self::WAIT)
{
return $this->getSocket()->recv(($wait ? 0 : \ZMQ::MODE_DONTWAIT));
} | [
"public",
"function",
"receiveRequest",
"(",
"$",
"wait",
"=",
"self",
"::",
"WAIT",
")",
"{",
"return",
"$",
"this",
"->",
"getSocket",
"(",
")",
"->",
"recv",
"(",
"(",
"$",
"wait",
"?",
"0",
":",
"\\",
"ZMQ",
"::",
"MODE_DONTWAIT",
")",
")",
";",
"}"
]
| Getting next request from socket.
@param bool $wait If true call will waits for next request.
@return string
@throws \ZMQSocketException | [
"Getting",
"next",
"request",
"from",
"socket",
"."
]
| 4e1769ab6411a584112df1151dcc90e6b82fe2bb | https://github.com/SAREhub/PHP_Commons/blob/4e1769ab6411a584112df1151dcc90e6b82fe2bb/src/SAREhub/Commons/Zmq/RequestReply/RequestReceiver.php#L84-L87 |
16,695 | SAREhub/PHP_Commons | src/SAREhub/Commons/Zmq/RequestReply/RequestReceiver.php | RequestReceiver.sendReply | public function sendReply($reply, $wait = self::WAIT)
{
$this->getSocket()->send($reply, ($wait ? 0 : \ZMQ::MODE_DONTWAIT));
return $this;
} | php | public function sendReply($reply, $wait = self::WAIT)
{
$this->getSocket()->send($reply, ($wait ? 0 : \ZMQ::MODE_DONTWAIT));
return $this;
} | [
"public",
"function",
"sendReply",
"(",
"$",
"reply",
",",
"$",
"wait",
"=",
"self",
"::",
"WAIT",
")",
"{",
"$",
"this",
"->",
"getSocket",
"(",
")",
"->",
"send",
"(",
"$",
"reply",
",",
"(",
"$",
"wait",
"?",
"0",
":",
"\\",
"ZMQ",
"::",
"MODE_DONTWAIT",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Sending reply to ZMQ socket.
@param string $reply
@param bool $wait If true call will be waits for reply send done.
@return $this
@throws \ZMQSocketException | [
"Sending",
"reply",
"to",
"ZMQ",
"socket",
"."
]
| 4e1769ab6411a584112df1151dcc90e6b82fe2bb | https://github.com/SAREhub/PHP_Commons/blob/4e1769ab6411a584112df1151dcc90e6b82fe2bb/src/SAREhub/Commons/Zmq/RequestReply/RequestReceiver.php#L96-L100 |
16,696 | daithi-coombes/bluemix-personality-insights-php | lib/RestAPI.php | RestAPI.analyzeBlob | public function analyzeBlob($text)
{
$config = Config::getInstance();
$url = $config->getParams()['credentials']['url']
. '/v2/profile';
return $this->_worker->post(
$url,
array(
'body' => $text,
'headers' => array('Content-Type' => 'text/plain'),
)
);
} | php | public function analyzeBlob($text)
{
$config = Config::getInstance();
$url = $config->getParams()['credentials']['url']
. '/v2/profile';
return $this->_worker->post(
$url,
array(
'body' => $text,
'headers' => array('Content-Type' => 'text/plain'),
)
);
} | [
"public",
"function",
"analyzeBlob",
"(",
"$",
"text",
")",
"{",
"$",
"config",
"=",
"Config",
"::",
"getInstance",
"(",
")",
";",
"$",
"url",
"=",
"$",
"config",
"->",
"getParams",
"(",
")",
"[",
"'credentials'",
"]",
"[",
"'url'",
"]",
".",
"'/v2/profile'",
";",
"return",
"$",
"this",
"->",
"_worker",
"->",
"post",
"(",
"$",
"url",
",",
"array",
"(",
"'body'",
"=>",
"$",
"text",
",",
"'headers'",
"=>",
"array",
"(",
"'Content-Type'",
"=>",
"'text/plain'",
")",
",",
")",
")",
";",
"}"
]
| Analayze a blob of text.
@param string $text The text to analyze
@return object Returns the response object of the Client library used. | [
"Analayze",
"a",
"blob",
"of",
"text",
"."
]
| 171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a | https://github.com/daithi-coombes/bluemix-personality-insights-php/blob/171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a/lib/RestAPI.php#L42-L56 |
16,697 | daithi-coombes/bluemix-personality-insights-php | lib/RestAPI.php | RestAPI.getWorker | public function getWorker()
{
if ($this->_worker===null) {
$config = Config::getInstance();
$this->setupWorker($config);
}
return $this->_worker;
} | php | public function getWorker()
{
if ($this->_worker===null) {
$config = Config::getInstance();
$this->setupWorker($config);
}
return $this->_worker;
} | [
"public",
"function",
"getWorker",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_worker",
"===",
"null",
")",
"{",
"$",
"config",
"=",
"Config",
"::",
"getInstance",
"(",
")",
";",
"$",
"this",
"->",
"setupWorker",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_worker",
";",
"}"
]
| Get the current worker.
@return object | [
"Get",
"the",
"current",
"worker",
"."
]
| 171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a | https://github.com/daithi-coombes/bluemix-personality-insights-php/blob/171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a/lib/RestAPI.php#L62-L70 |
16,698 | daithi-coombes/bluemix-personality-insights-php | lib/RestAPI.php | RestAPI.setupWorker | public function setupWorker(Config $config)
{
$credentials = $config->getParams()['credentials'];
$this->_worker = new \GuzzleHttp\Client(array(
'defaults' => array(
'auth' => array($credentials['username'], $credentials['password']),
),
));
} | php | public function setupWorker(Config $config)
{
$credentials = $config->getParams()['credentials'];
$this->_worker = new \GuzzleHttp\Client(array(
'defaults' => array(
'auth' => array($credentials['username'], $credentials['password']),
),
));
} | [
"public",
"function",
"setupWorker",
"(",
"Config",
"$",
"config",
")",
"{",
"$",
"credentials",
"=",
"$",
"config",
"->",
"getParams",
"(",
")",
"[",
"'credentials'",
"]",
";",
"$",
"this",
"->",
"_worker",
"=",
"new",
"\\",
"GuzzleHttp",
"\\",
"Client",
"(",
"array",
"(",
"'defaults'",
"=>",
"array",
"(",
"'auth'",
"=>",
"array",
"(",
"$",
"credentials",
"[",
"'username'",
"]",
",",
"$",
"credentials",
"[",
"'password'",
"]",
")",
",",
")",
",",
")",
")",
";",
"}"
]
| Constructs the middleware REST client library.
@param Config $config The configuration singleton. | [
"Constructs",
"the",
"middleware",
"REST",
"client",
"library",
"."
]
| 171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a | https://github.com/daithi-coombes/bluemix-personality-insights-php/blob/171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a/lib/RestAPI.php#L76-L86 |
16,699 | helthe/Chronos | CronExpression.php | CronExpression.setExpression | public function setExpression($expression)
{
$definitions = array(
'@yearly' => '0 0 1 1 *',
'@annually' => '0 0 1 1 *',
'@monthly' => '0 0 1 * *',
'@weekly' => '0 0 * * 0',
'@daily' => '0 0 * * *',
'@hourly' => '0 * * * *'
);
if (isset($definitions[$expression])) {
$expression = $definitions[$expression];
}
$expressionParts = explode(' ', $expression);
if (count($expressionParts) < 5 || count($expressionParts) > 6) {
throw new \InvalidArgumentException(sprintf('%s is not a valid CRON expression.', $expression));
}
$this->expression = $expression;
$this->fields = array();
foreach ($expressionParts as $position => $value) {
$this->fields[$position] = $this->getField($position, $value);
}
} | php | public function setExpression($expression)
{
$definitions = array(
'@yearly' => '0 0 1 1 *',
'@annually' => '0 0 1 1 *',
'@monthly' => '0 0 1 * *',
'@weekly' => '0 0 * * 0',
'@daily' => '0 0 * * *',
'@hourly' => '0 * * * *'
);
if (isset($definitions[$expression])) {
$expression = $definitions[$expression];
}
$expressionParts = explode(' ', $expression);
if (count($expressionParts) < 5 || count($expressionParts) > 6) {
throw new \InvalidArgumentException(sprintf('%s is not a valid CRON expression.', $expression));
}
$this->expression = $expression;
$this->fields = array();
foreach ($expressionParts as $position => $value) {
$this->fields[$position] = $this->getField($position, $value);
}
} | [
"public",
"function",
"setExpression",
"(",
"$",
"expression",
")",
"{",
"$",
"definitions",
"=",
"array",
"(",
"'@yearly'",
"=>",
"'0 0 1 1 *'",
",",
"'@annually'",
"=>",
"'0 0 1 1 *'",
",",
"'@monthly'",
"=>",
"'0 0 1 * *'",
",",
"'@weekly'",
"=>",
"'0 0 * * 0'",
",",
"'@daily'",
"=>",
"'0 0 * * *'",
",",
"'@hourly'",
"=>",
"'0 * * * *'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"definitions",
"[",
"$",
"expression",
"]",
")",
")",
"{",
"$",
"expression",
"=",
"$",
"definitions",
"[",
"$",
"expression",
"]",
";",
"}",
"$",
"expressionParts",
"=",
"explode",
"(",
"' '",
",",
"$",
"expression",
")",
";",
"if",
"(",
"count",
"(",
"$",
"expressionParts",
")",
"<",
"5",
"||",
"count",
"(",
"$",
"expressionParts",
")",
">",
"6",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s is not a valid CRON expression.'",
",",
"$",
"expression",
")",
")",
";",
"}",
"$",
"this",
"->",
"expression",
"=",
"$",
"expression",
";",
"$",
"this",
"->",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"expressionParts",
"as",
"$",
"position",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"$",
"position",
"]",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"position",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Set CRON expression.
@param string $expression
@throws \InvalidArgumentException | [
"Set",
"CRON",
"expression",
"."
]
| 6c783c55c32b323550fc6f21cd644c2be82720b0 | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/CronExpression.php#L63-L90 |
Subsets and Splits