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
38,100
gizburdt/cuztom
src/Meta/Meta.php
Meta.build
public function build($fields) { $data = []; if (Cuztom::isArray($fields)) { foreach ($fields as $type => $args) { $args = Cuztom::merge($args, [ 'metaBox' => $this, 'metaType' => $this->metaType, 'object' => $this->object, 'parent' => $this->id, ]); $field = Field::create($args, $this->values); $data[$field->id] = $field; } } return $data; }
php
public function build($fields) { $data = []; if (Cuztom::isArray($fields)) { foreach ($fields as $type => $args) { $args = Cuztom::merge($args, [ 'metaBox' => $this, 'metaType' => $this->metaType, 'object' => $this->object, 'parent' => $this->id, ]); $field = Field::create($args, $this->values); $data[$field->id] = $field; } } return $data; }
[ "public", "function", "build", "(", "$", "fields", ")", "{", "$", "data", "=", "[", "]", ";", "if", "(", "Cuztom", "::", "isArray", "(", "$", "fields", ")", ")", "{", "foreach", "(", "$", "fields", "as", "$", "type", "=>", "$", "args", ")", "{", "$", "args", "=", "Cuztom", "::", "merge", "(", "$", "args", ",", "[", "'metaBox'", "=>", "$", "this", ",", "'metaType'", "=>", "$", "this", "->", "metaType", ",", "'object'", "=>", "$", "this", "->", "object", ",", "'parent'", "=>", "$", "this", "->", "id", ",", "]", ")", ";", "$", "field", "=", "Field", "::", "create", "(", "$", "args", ",", "$", "this", "->", "values", ")", ";", "$", "data", "[", "$", "field", "->", "id", "]", "=", "$", "field", ";", "}", "}", "return", "$", "data", ";", "}" ]
This method builds the complete array with the right key => value pairs. @param array $fields @return array
[ "This", "method", "builds", "the", "complete", "array", "with", "the", "right", "key", "=", ">", "value", "pairs", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Meta.php#L180-L200
38,101
gizburdt/cuztom
src/Support/Guard.php
Guard.verifyNonce
public static function verifyNonce($name, $value) { return isset($_POST[$name]) && wp_verify_nonce($_POST[$name], $value); }
php
public static function verifyNonce($name, $value) { return isset($_POST[$name]) && wp_verify_nonce($_POST[$name], $value); }
[ "public", "static", "function", "verifyNonce", "(", "$", "name", ",", "$", "value", ")", "{", "return", "isset", "(", "$", "_POST", "[", "$", "name", "]", ")", "&&", "wp_verify_nonce", "(", "$", "_POST", "[", "$", "name", "]", ",", "$", "value", ")", ";", "}" ]
Check nonce. @param string $name @param string $value @return bool
[ "Check", "nonce", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Support/Guard.php#L48-L51
38,102
gizburdt/cuztom
src/Fields/Traits/Selectable.php
Selectable.maybeShowOptionNone
public function maybeShowOptionNone() { if (isset($this->args['show_option_none']) && ! Cuztom::isEmpty($this->args['show_option_none'])) { return '<option value="-1" '.(Cuztom::isEmpty($this->value) ? 'selected="selected"' : '').'>'.$this->args['show_option_none'].'</option>'; } }
php
public function maybeShowOptionNone() { if (isset($this->args['show_option_none']) && ! Cuztom::isEmpty($this->args['show_option_none'])) { return '<option value="-1" '.(Cuztom::isEmpty($this->value) ? 'selected="selected"' : '').'>'.$this->args['show_option_none'].'</option>'; } }
[ "public", "function", "maybeShowOptionNone", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "args", "[", "'show_option_none'", "]", ")", "&&", "!", "Cuztom", "::", "isEmpty", "(", "$", "this", "->", "args", "[", "'show_option_none'", "]", ")", ")", "{", "return", "'<option value=\"-1\" '", ".", "(", "Cuztom", "::", "isEmpty", "(", "$", "this", "->", "value", ")", "?", "'selected=\"selected\"'", ":", "''", ")", ".", "'>'", ".", "$", "this", "->", "args", "[", "'show_option_none'", "]", ".", "'</option>'", ";", "}", "}" ]
Show option none? @return string
[ "Show", "option", "none?" ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/Traits/Selectable.php#L17-L22
38,103
gizburdt/cuztom
src/Fields/Traits/Checkables.php
Checkables.outputOption
public function outputOption($value = null, $default_value = null, $option = null) { return '<input type="'.$this->getInputType().'" name="'.$this->getName().'" id="'.$this->getId($option).'" class="'.$this->getCssClass().'" value="'.$option.'" '.$this->getDataAttributes().' '.$this->maybeChecked($value, $default_value, $option).'/>'; }
php
public function outputOption($value = null, $default_value = null, $option = null) { return '<input type="'.$this->getInputType().'" name="'.$this->getName().'" id="'.$this->getId($option).'" class="'.$this->getCssClass().'" value="'.$option.'" '.$this->getDataAttributes().' '.$this->maybeChecked($value, $default_value, $option).'/>'; }
[ "public", "function", "outputOption", "(", "$", "value", "=", "null", ",", "$", "default_value", "=", "null", ",", "$", "option", "=", "null", ")", "{", "return", "'<input\n type=\"'", ".", "$", "this", "->", "getInputType", "(", ")", ".", "'\"\n name=\"'", ".", "$", "this", "->", "getName", "(", ")", ".", "'\"\n id=\"'", ".", "$", "this", "->", "getId", "(", "$", "option", ")", ".", "'\"\n class=\"'", ".", "$", "this", "->", "getCssClass", "(", ")", ".", "'\"\n value=\"'", ".", "$", "option", ".", "'\"\n '", ".", "$", "this", "->", "getDataAttributes", "(", ")", ".", "'\n '", ".", "$", "this", "->", "maybeChecked", "(", "$", "value", ",", "$", "default_value", ",", "$", "option", ")", ".", "'/>'", ";", "}" ]
Output option. @param string $value @param string $default_value @param string $option @return string
[ "Output", "option", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/Traits/Checkables.php#L19-L29
38,104
gizburdt/cuztom
src/Fields/Bundle/Item.php
Item.getField
public function getField($field) { return isset($this->data[$field]) ? $this->data[$field] : null; }
php
public function getField($field) { return isset($this->data[$field]) ? $this->data[$field] : null; }
[ "public", "function", "getField", "(", "$", "field", ")", "{", "return", "isset", "(", "$", "this", "->", "data", "[", "$", "field", "]", ")", "?", "$", "this", "->", "data", "[", "$", "field", "]", ":", "null", ";", "}" ]
Return field from data. @param string $field @return object
[ "Return", "field", "from", "data", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/Bundle/Item.php#L66-L69
38,105
gizburdt/cuztom
src/Support/Ajax.php
Ajax.setupRepeatableList
public function setupRepeatableList() { if (! Guard::verifyAjaxNonce('cuztom', 'security')) { return; } $data = []; $field = self::getField(); if (Cuztom::isArray($field->value)) { foreach ($field->value as $value) { $data[] = $field->outputInput($value); } } echo (new Response(true, $data))->toJson(); // wp die(); }
php
public function setupRepeatableList() { if (! Guard::verifyAjaxNonce('cuztom', 'security')) { return; } $data = []; $field = self::getField(); if (Cuztom::isArray($field->value)) { foreach ($field->value as $value) { $data[] = $field->outputInput($value); } } echo (new Response(true, $data))->toJson(); // wp die(); }
[ "public", "function", "setupRepeatableList", "(", ")", "{", "if", "(", "!", "Guard", "::", "verifyAjaxNonce", "(", "'cuztom'", ",", "'security'", ")", ")", "{", "return", ";", "}", "$", "data", "=", "[", "]", ";", "$", "field", "=", "self", "::", "getField", "(", ")", ";", "if", "(", "Cuztom", "::", "isArray", "(", "$", "field", "->", "value", ")", ")", "{", "foreach", "(", "$", "field", "->", "value", "as", "$", "value", ")", "{", "$", "data", "[", "]", "=", "$", "field", "->", "outputInput", "(", "$", "value", ")", ";", "}", "}", "echo", "(", "new", "Response", "(", "true", ",", "$", "data", ")", ")", "->", "toJson", "(", ")", ";", "// wp", "die", "(", ")", ";", "}" ]
Setup repeatable list on init. @return mixed
[ "Setup", "repeatable", "list", "on", "init", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Support/Ajax.php#L54-L73
38,106
gizburdt/cuztom
src/Support/Ajax.php
Ajax.setupBundleList
public function setupBundleList() { if (! Guard::verifyAjaxNonce('cuztom', 'security')) { return; } $data = []; $bundle = self::getField(); if (Cuztom::isArray($bundle->data)) { foreach ($bundle->data as $item) { $data[] = $item->output(); } } echo (new Response(true, $data))->toJson(); // wp die(); }
php
public function setupBundleList() { if (! Guard::verifyAjaxNonce('cuztom', 'security')) { return; } $data = []; $bundle = self::getField(); if (Cuztom::isArray($bundle->data)) { foreach ($bundle->data as $item) { $data[] = $item->output(); } } echo (new Response(true, $data))->toJson(); // wp die(); }
[ "public", "function", "setupBundleList", "(", ")", "{", "if", "(", "!", "Guard", "::", "verifyAjaxNonce", "(", "'cuztom'", ",", "'security'", ")", ")", "{", "return", ";", "}", "$", "data", "=", "[", "]", ";", "$", "bundle", "=", "self", "::", "getField", "(", ")", ";", "if", "(", "Cuztom", "::", "isArray", "(", "$", "bundle", "->", "data", ")", ")", "{", "foreach", "(", "$", "bundle", "->", "data", "as", "$", "item", ")", "{", "$", "data", "[", "]", "=", "$", "item", "->", "output", "(", ")", ";", "}", "}", "echo", "(", "new", "Response", "(", "true", ",", "$", "data", ")", ")", "->", "toJson", "(", ")", ";", "// wp", "die", "(", ")", ";", "}" ]
Setup bundle list on init. @return mixed
[ "Setup", "bundle", "list", "on", "init", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Support/Ajax.php#L102-L121
38,107
gizburdt/cuztom
src/Fields/TermSelect.php
TermSelect.outputInput
public function outputInput($value = null, $view = null) { $this->args['class'] = (isset($this->args['class']) ? $this->args['class'] : '').' cuztom-input--select cuztom-input--term-select'; $this->args['echo'] = 0; $this->args['name'] = $this->getName(); $this->args['id'] = $this->getId(); $this->args['selected'] = ! Cuztom::isEmpty($value) ? $value : $this->default_value; return wp_dropdown_categories($this->args); }
php
public function outputInput($value = null, $view = null) { $this->args['class'] = (isset($this->args['class']) ? $this->args['class'] : '').' cuztom-input--select cuztom-input--term-select'; $this->args['echo'] = 0; $this->args['name'] = $this->getName(); $this->args['id'] = $this->getId(); $this->args['selected'] = ! Cuztom::isEmpty($value) ? $value : $this->default_value; return wp_dropdown_categories($this->args); }
[ "public", "function", "outputInput", "(", "$", "value", "=", "null", ",", "$", "view", "=", "null", ")", "{", "$", "this", "->", "args", "[", "'class'", "]", "=", "(", "isset", "(", "$", "this", "->", "args", "[", "'class'", "]", ")", "?", "$", "this", "->", "args", "[", "'class'", "]", ":", "''", ")", ".", "' cuztom-input--select cuztom-input--term-select'", ";", "$", "this", "->", "args", "[", "'echo'", "]", "=", "0", ";", "$", "this", "->", "args", "[", "'name'", "]", "=", "$", "this", "->", "getName", "(", ")", ";", "$", "this", "->", "args", "[", "'id'", "]", "=", "$", "this", "->", "getId", "(", ")", ";", "$", "this", "->", "args", "[", "'selected'", "]", "=", "!", "Cuztom", "::", "isEmpty", "(", "$", "value", ")", "?", "$", "value", ":", "$", "this", "->", "default_value", ";", "return", "wp_dropdown_categories", "(", "$", "this", "->", "args", ")", ";", "}" ]
Output input. @param string|array $value @return string
[ "Output", "input", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/TermSelect.php#L42-L52
38,108
gizburdt/cuztom
src/Entities/PostType.php
PostType.registerEntity
public function registerEntity() { parent::registerEntity(); // Args $args = apply_filters('cuztom_post_type_args', array_merge( [ 'label' => sprintf(__('%s', 'cuztom'), $this->plural), 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => sanitize_title($this->plural), 'labels' => [ 'name' => sprintf(_x('%s', 'post type general name', 'cuztom'), $this->plural), 'singular_name' => sprintf(_x('%s', 'post type singular title', 'cuztom'), $this->title), 'menu_name' => sprintf(__('%s', 'cuztom'), $this->plural), 'all_items' => sprintf(__('All %s', 'cuztom'), $this->plural), 'add_new' => sprintf(_x('Add New', '%s', 'cuztom'), $this->title), 'add_new_item' => sprintf(__('Add New %s', 'cuztom'), $this->title), 'edit_item' => sprintf(__('Edit %s', 'cuztom'), $this->title), 'new_item' => sprintf(__('New %s', 'cuztom'), $this->title), 'view_item' => sprintf(__('View %s', 'cuztom'), $this->title), 'items_archive' => sprintf(__('%s Archive', 'cuztom'), $this->title), 'search_items' => sprintf(__('Search %s', 'cuztom'), $this->plural), 'not_found' => sprintf(__('No %s found', 'cuztom'), $this->plural), 'not_found_in_trash' => sprintf(__('No %s found in trash', 'cuztom'), $this->plural), 'parent_item_colon' => sprintf(__('%s Parent', 'cuztom'), $this->title), ], ], $this->original ), $this); // Register the post type register_post_type($this->name, $args); }
php
public function registerEntity() { parent::registerEntity(); // Args $args = apply_filters('cuztom_post_type_args', array_merge( [ 'label' => sprintf(__('%s', 'cuztom'), $this->plural), 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => sanitize_title($this->plural), 'labels' => [ 'name' => sprintf(_x('%s', 'post type general name', 'cuztom'), $this->plural), 'singular_name' => sprintf(_x('%s', 'post type singular title', 'cuztom'), $this->title), 'menu_name' => sprintf(__('%s', 'cuztom'), $this->plural), 'all_items' => sprintf(__('All %s', 'cuztom'), $this->plural), 'add_new' => sprintf(_x('Add New', '%s', 'cuztom'), $this->title), 'add_new_item' => sprintf(__('Add New %s', 'cuztom'), $this->title), 'edit_item' => sprintf(__('Edit %s', 'cuztom'), $this->title), 'new_item' => sprintf(__('New %s', 'cuztom'), $this->title), 'view_item' => sprintf(__('View %s', 'cuztom'), $this->title), 'items_archive' => sprintf(__('%s Archive', 'cuztom'), $this->title), 'search_items' => sprintf(__('Search %s', 'cuztom'), $this->plural), 'not_found' => sprintf(__('No %s found', 'cuztom'), $this->plural), 'not_found_in_trash' => sprintf(__('No %s found in trash', 'cuztom'), $this->plural), 'parent_item_colon' => sprintf(__('%s Parent', 'cuztom'), $this->title), ], ], $this->original ), $this); // Register the post type register_post_type($this->name, $args); }
[ "public", "function", "registerEntity", "(", ")", "{", "parent", "::", "registerEntity", "(", ")", ";", "// Args", "$", "args", "=", "apply_filters", "(", "'cuztom_post_type_args'", ",", "array_merge", "(", "[", "'label'", "=>", "sprintf", "(", "__", "(", "'%s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'public'", "=>", "true", ",", "'supports'", "=>", "[", "'title'", ",", "'editor'", "]", ",", "'has_archive'", "=>", "sanitize_title", "(", "$", "this", "->", "plural", ")", ",", "'labels'", "=>", "[", "'name'", "=>", "sprintf", "(", "_x", "(", "'%s'", ",", "'post type general name'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'singular_name'", "=>", "sprintf", "(", "_x", "(", "'%s'", ",", "'post type singular title'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'menu_name'", "=>", "sprintf", "(", "__", "(", "'%s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'all_items'", "=>", "sprintf", "(", "__", "(", "'All %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'add_new'", "=>", "sprintf", "(", "_x", "(", "'Add New'", ",", "'%s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'add_new_item'", "=>", "sprintf", "(", "__", "(", "'Add New %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'edit_item'", "=>", "sprintf", "(", "__", "(", "'Edit %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'new_item'", "=>", "sprintf", "(", "__", "(", "'New %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'view_item'", "=>", "sprintf", "(", "__", "(", "'View %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'items_archive'", "=>", "sprintf", "(", "__", "(", "'%s Archive'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'search_items'", "=>", "sprintf", "(", "__", "(", "'Search %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'not_found'", "=>", "sprintf", "(", "__", "(", "'No %s found'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'not_found_in_trash'", "=>", "sprintf", "(", "__", "(", "'No %s found in trash'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'parent_item_colon'", "=>", "sprintf", "(", "__", "(", "'%s Parent'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "]", ",", "]", ",", "$", "this", "->", "original", ")", ",", "$", "this", ")", ";", "// Register the post type", "register_post_type", "(", "$", "this", "->", "name", ",", "$", "args", ")", ";", "}" ]
Register post Type. @return void
[ "Register", "post", "Type", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/PostType.php#L38-L71
38,109
gizburdt/cuztom
src/Entities/PostType.php
PostType.addTaxonomy
public function addTaxonomy($name, $args = []) { $taxonomy = new Taxonomy($name, $this->name, $args); return $this; }
php
public function addTaxonomy($name, $args = []) { $taxonomy = new Taxonomy($name, $this->name, $args); return $this; }
[ "public", "function", "addTaxonomy", "(", "$", "name", ",", "$", "args", "=", "[", "]", ")", "{", "$", "taxonomy", "=", "new", "Taxonomy", "(", "$", "name", ",", "$", "this", "->", "name", ",", "$", "args", ")", ";", "return", "$", "this", ";", "}" ]
Add a taxonomy to the Post Type. @param string|array $name @param array $args
[ "Add", "a", "taxonomy", "to", "the", "Post", "Type", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/PostType.php#L79-L84
38,110
gizburdt/cuztom
src/Entities/PostType.php
PostType.addMetaBox
public function addMetaBox($id, $args) { $box = new MetaBox($id, $this->name, $args); return $this; }
php
public function addMetaBox($id, $args) { $box = new MetaBox($id, $this->name, $args); return $this; }
[ "public", "function", "addMetaBox", "(", "$", "id", ",", "$", "args", ")", "{", "$", "box", "=", "new", "MetaBox", "(", "$", "id", ",", "$", "this", "->", "name", ",", "$", "args", ")", ";", "return", "$", "this", ";", "}" ]
Add Meta Box to the Post Type. @param string $id @param array $args
[ "Add", "Meta", "Box", "to", "the", "Post", "Type", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/PostType.php#L92-L97
38,111
gizburdt/cuztom
src/Entities/PostType.php
PostType.removePostTypeSupport
public function removePostTypeSupport($features) { foreach ((array) $features as $feature) { remove_post_type_support($this->name, $feature); } return $this; }
php
public function removePostTypeSupport($features) { foreach ((array) $features as $feature) { remove_post_type_support($this->name, $feature); } return $this; }
[ "public", "function", "removePostTypeSupport", "(", "$", "features", ")", "{", "foreach", "(", "(", "array", ")", "$", "features", "as", "$", "feature", ")", "{", "remove_post_type_support", "(", "$", "this", "->", "name", ",", "$", "feature", ")", ";", "}", "return", "$", "this", ";", "}" ]
Remove support from Post Type. @param string|array $feature @return object
[ "Remove", "support", "from", "Post", "Type", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/PostType.php#L118-L125
38,112
gizburdt/cuztom
src/Entities/Taxonomy.php
Taxonomy.registerEntity
public function registerEntity() { parent::registerEntity(); // Args $args = apply_filters('cuztom_taxonomy_args', array_merge( [ 'label' => sprintf(__('%s', 'cuztom'), $this->plural), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, '_builtin' => false, 'show_admin_column' => false, 'labels' => [ 'name' => sprintf(_x('%s', 'taxonomy general name', 'cuztom'), $this->plural), 'singular_name' => sprintf(_x('%s', 'taxonomy singular name', 'cuztom'), $this->title), 'search_items' => sprintf(__('Search %s', 'cuztom'), $this->plural), 'all_items' => sprintf(__('All %s', 'cuztom'), $this->plural), 'parent_item' => sprintf(__('Parent %s', 'cuztom'), $this->title), 'parent_item_colon' => sprintf(__('Parent %s:', 'cuztom'), $this->title), 'edit_item' => sprintf(__('Edit %s', 'cuztom'), $this->title), 'update_item' => sprintf(__('Update %s', 'cuztom'), $this->title), 'add_new_item' => sprintf(__('Add New %s', 'cuztom'), $this->title), 'new_item_name' => sprintf(__('New %s Name', 'cuztom'), $this->title), 'menu_name' => sprintf(__('%s', 'cuztom'), $this->plural), ], ], $this->original ), $this); register_taxonomy($this->name, $this->postType, $args); }
php
public function registerEntity() { parent::registerEntity(); // Args $args = apply_filters('cuztom_taxonomy_args', array_merge( [ 'label' => sprintf(__('%s', 'cuztom'), $this->plural), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, '_builtin' => false, 'show_admin_column' => false, 'labels' => [ 'name' => sprintf(_x('%s', 'taxonomy general name', 'cuztom'), $this->plural), 'singular_name' => sprintf(_x('%s', 'taxonomy singular name', 'cuztom'), $this->title), 'search_items' => sprintf(__('Search %s', 'cuztom'), $this->plural), 'all_items' => sprintf(__('All %s', 'cuztom'), $this->plural), 'parent_item' => sprintf(__('Parent %s', 'cuztom'), $this->title), 'parent_item_colon' => sprintf(__('Parent %s:', 'cuztom'), $this->title), 'edit_item' => sprintf(__('Edit %s', 'cuztom'), $this->title), 'update_item' => sprintf(__('Update %s', 'cuztom'), $this->title), 'add_new_item' => sprintf(__('Add New %s', 'cuztom'), $this->title), 'new_item_name' => sprintf(__('New %s Name', 'cuztom'), $this->title), 'menu_name' => sprintf(__('%s', 'cuztom'), $this->plural), ], ], $this->original ), $this); register_taxonomy($this->name, $this->postType, $args); }
[ "public", "function", "registerEntity", "(", ")", "{", "parent", "::", "registerEntity", "(", ")", ";", "// Args", "$", "args", "=", "apply_filters", "(", "'cuztom_taxonomy_args'", ",", "array_merge", "(", "[", "'label'", "=>", "sprintf", "(", "__", "(", "'%s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'hierarchical'", "=>", "true", ",", "'public'", "=>", "true", ",", "'show_ui'", "=>", "true", ",", "'show_in_nav_menus'", "=>", "true", ",", "'_builtin'", "=>", "false", ",", "'show_admin_column'", "=>", "false", ",", "'labels'", "=>", "[", "'name'", "=>", "sprintf", "(", "_x", "(", "'%s'", ",", "'taxonomy general name'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'singular_name'", "=>", "sprintf", "(", "_x", "(", "'%s'", ",", "'taxonomy singular name'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'search_items'", "=>", "sprintf", "(", "__", "(", "'Search %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'all_items'", "=>", "sprintf", "(", "__", "(", "'All %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'parent_item'", "=>", "sprintf", "(", "__", "(", "'Parent %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'parent_item_colon'", "=>", "sprintf", "(", "__", "(", "'Parent %s:'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'edit_item'", "=>", "sprintf", "(", "__", "(", "'Edit %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'update_item'", "=>", "sprintf", "(", "__", "(", "'Update %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'add_new_item'", "=>", "sprintf", "(", "__", "(", "'Add New %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'new_item_name'", "=>", "sprintf", "(", "__", "(", "'New %s Name'", ",", "'cuztom'", ")", ",", "$", "this", "->", "title", ")", ",", "'menu_name'", "=>", "sprintf", "(", "__", "(", "'%s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "]", ",", "]", ",", "$", "this", "->", "original", ")", ",", "$", "this", ")", ";", "register_taxonomy", "(", "$", "this", "->", "name", ",", "$", "this", "->", "postType", ",", "$", "args", ")", ";", "}" ]
Registers the custom Taxonomy with the given arguments. @return void
[ "Registers", "the", "custom", "Taxonomy", "with", "the", "given", "arguments", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/Taxonomy.php#L75-L107
38,113
gizburdt/cuztom
src/Entities/Taxonomy.php
Taxonomy.addTermMeta
public function addTermMeta($id, $data = [], $locations = ['add_form', 'edit_form']) { $meta = new TermMeta($id, $this->name, $data, $locations); return $this; }
php
public function addTermMeta($id, $data = [], $locations = ['add_form', 'edit_form']) { $meta = new TermMeta($id, $this->name, $data, $locations); return $this; }
[ "public", "function", "addTermMeta", "(", "$", "id", ",", "$", "data", "=", "[", "]", ",", "$", "locations", "=", "[", "'add_form'", ",", "'edit_form'", "]", ")", "{", "$", "meta", "=", "new", "TermMeta", "(", "$", "id", ",", "$", "this", "->", "name", ",", "$", "data", ",", "$", "locations", ")", ";", "return", "$", "this", ";", "}" ]
Add Term Meta to this Taxonomy. @param string $id @param array $data @param array $locations
[ "Add", "Term", "Meta", "to", "this", "Taxonomy", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/Taxonomy.php#L126-L131
38,114
gizburdt/cuztom
src/Entities/Taxonomy.php
Taxonomy.adminColumnFilter
public function adminColumnFilter() { global $typenow, $wp_query; if (in_array($typenow, $this->postType)) { wp_dropdown_categories([ 'show_option_all' => sprintf(__('Show all %s', 'cuztom'), $this->plural), 'taxonomy' => $this->name, 'name' => $this->name, 'orderby' => 'name', 'selected' => isset($wp_query->query[$this->name]) ? $wp_query->query[$this->name] : '', 'hierarchical' => true, 'show_count' => true, 'hide_empty' => true, ]); } }
php
public function adminColumnFilter() { global $typenow, $wp_query; if (in_array($typenow, $this->postType)) { wp_dropdown_categories([ 'show_option_all' => sprintf(__('Show all %s', 'cuztom'), $this->plural), 'taxonomy' => $this->name, 'name' => $this->name, 'orderby' => 'name', 'selected' => isset($wp_query->query[$this->name]) ? $wp_query->query[$this->name] : '', 'hierarchical' => true, 'show_count' => true, 'hide_empty' => true, ]); } }
[ "public", "function", "adminColumnFilter", "(", ")", "{", "global", "$", "typenow", ",", "$", "wp_query", ";", "if", "(", "in_array", "(", "$", "typenow", ",", "$", "this", "->", "postType", ")", ")", "{", "wp_dropdown_categories", "(", "[", "'show_option_all'", "=>", "sprintf", "(", "__", "(", "'Show all %s'", ",", "'cuztom'", ")", ",", "$", "this", "->", "plural", ")", ",", "'taxonomy'", "=>", "$", "this", "->", "name", ",", "'name'", "=>", "$", "this", "->", "name", ",", "'orderby'", "=>", "'name'", ",", "'selected'", "=>", "isset", "(", "$", "wp_query", "->", "query", "[", "$", "this", "->", "name", "]", ")", "?", "$", "wp_query", "->", "query", "[", "$", "this", "->", "name", "]", ":", "''", ",", "'hierarchical'", "=>", "true", ",", "'show_count'", "=>", "true", ",", "'hide_empty'", "=>", "true", ",", "]", ")", ";", "}", "}" ]
Adds a filter to the post table filters. @return void
[ "Adds", "a", "filter", "to", "the", "post", "table", "filters", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/Taxonomy.php#L150-L166
38,115
gizburdt/cuztom
src/Entities/Taxonomy.php
Taxonomy.postFilterQuery
public function postFilterQuery($query) { // @TODO: Is this still right? global $pagenow; $vars = &$query->query_vars; if ($pagenow == 'edit.php' && isset($vars[$this->name]) && is_numeric($vars[$this->name]) && $vars[$this->name]) { $term = get_term_by('id', $vars[$this->name], $this->name); $vars[$this->name] = $term->slug; } return $vars; }
php
public function postFilterQuery($query) { // @TODO: Is this still right? global $pagenow; $vars = &$query->query_vars; if ($pagenow == 'edit.php' && isset($vars[$this->name]) && is_numeric($vars[$this->name]) && $vars[$this->name]) { $term = get_term_by('id', $vars[$this->name], $this->name); $vars[$this->name] = $term->slug; } return $vars; }
[ "public", "function", "postFilterQuery", "(", "$", "query", ")", "{", "// @TODO: Is this still right?", "global", "$", "pagenow", ";", "$", "vars", "=", "&", "$", "query", "->", "query_vars", ";", "if", "(", "$", "pagenow", "==", "'edit.php'", "&&", "isset", "(", "$", "vars", "[", "$", "this", "->", "name", "]", ")", "&&", "is_numeric", "(", "$", "vars", "[", "$", "this", "->", "name", "]", ")", "&&", "$", "vars", "[", "$", "this", "->", "name", "]", ")", "{", "$", "term", "=", "get_term_by", "(", "'id'", ",", "$", "vars", "[", "$", "this", "->", "name", "]", ",", "$", "this", "->", "name", ")", ";", "$", "vars", "[", "$", "this", "->", "name", "]", "=", "$", "term", "->", "slug", ";", "}", "return", "$", "vars", ";", "}" ]
Applies the selected filter to the query. @param object $query @return array
[ "Applies", "the", "selected", "filter", "to", "the", "query", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Entities/Taxonomy.php#L174-L188
38,116
gizburdt/cuztom
src/Meta/Term.php
Term.addColumn
public function addColumn($columns) { foreach ($this->fields as $id => $field) { if (isset($field->show_admin_column) && $field->show_admin_column) { $columns[$id] = $field->label; } } return $columns; }
php
public function addColumn($columns) { foreach ($this->fields as $id => $field) { if (isset($field->show_admin_column) && $field->show_admin_column) { $columns[$id] = $field->label; } } return $columns; }
[ "public", "function", "addColumn", "(", "$", "columns", ")", "{", "foreach", "(", "$", "this", "->", "fields", "as", "$", "id", "=>", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "->", "show_admin_column", ")", "&&", "$", "field", "->", "show_admin_column", ")", "{", "$", "columns", "[", "$", "id", "]", "=", "$", "field", "->", "label", ";", "}", "}", "return", "$", "columns", ";", "}" ]
Used to add a column head to the Taxonomy's List Table. @param array $columns @return array
[ "Used", "to", "add", "a", "column", "head", "to", "the", "Taxonomy", "s", "List", "Table", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Term.php#L131-L140
38,117
gizburdt/cuztom
src/Fields/Bundle.php
Bundle.save
public function save($object, $values) { $values = isset($values[$this->id]) ? $values[$this->id] : null; $values = is_array($values) ? array_values($values) : []; // Filter $values = apply_filters('cuztom_bundle_save_values', $values, $this); // Do do_action('cuztom_bundle_save', $this); foreach ($values as $cell => $fields) { foreach ($fields as $id => $value) { $values[$this->id][$cell][$id] = $this->getFirstItem()->getField($id)->parseValue($value); } } parent::save($object, $values); }
php
public function save($object, $values) { $values = isset($values[$this->id]) ? $values[$this->id] : null; $values = is_array($values) ? array_values($values) : []; // Filter $values = apply_filters('cuztom_bundle_save_values', $values, $this); // Do do_action('cuztom_bundle_save', $this); foreach ($values as $cell => $fields) { foreach ($fields as $id => $value) { $values[$this->id][$cell][$id] = $this->getFirstItem()->getField($id)->parseValue($value); } } parent::save($object, $values); }
[ "public", "function", "save", "(", "$", "object", ",", "$", "values", ")", "{", "$", "values", "=", "isset", "(", "$", "values", "[", "$", "this", "->", "id", "]", ")", "?", "$", "values", "[", "$", "this", "->", "id", "]", ":", "null", ";", "$", "values", "=", "is_array", "(", "$", "values", ")", "?", "array_values", "(", "$", "values", ")", ":", "[", "]", ";", "// Filter", "$", "values", "=", "apply_filters", "(", "'cuztom_bundle_save_values'", ",", "$", "values", ",", "$", "this", ")", ";", "// Do", "do_action", "(", "'cuztom_bundle_save'", ",", "$", "this", ")", ";", "foreach", "(", "$", "values", "as", "$", "cell", "=>", "$", "fields", ")", "{", "foreach", "(", "$", "fields", "as", "$", "id", "=>", "$", "value", ")", "{", "$", "values", "[", "$", "this", "->", "id", "]", "[", "$", "cell", "]", "[", "$", "id", "]", "=", "$", "this", "->", "getFirstItem", "(", ")", "->", "getField", "(", "$", "id", ")", "->", "parseValue", "(", "$", "value", ")", ";", "}", "}", "parent", "::", "save", "(", "$", "object", ",", "$", "values", ")", ";", "}" ]
Save bundle meta. @param int $object @param array $values
[ "Save", "bundle", "meta", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/Bundle.php#L68-L91
38,118
gizburdt/cuztom
src/Fields/Bundle.php
Bundle.build
public function build($args) { $data = []; $args = Cuztom::merge($args, [ 'parent' => $this, 'metaType' => $this->metaType, 'object' => $this->object, ]); // Build with value if (Cuztom::isArray($this->value)) { $i = 0; foreach ($this->value as $value) { $args = Cuztom::merge($args, "index=>$i"); $data[] = new BundleItem($args, $value); $i++; } } // Without value else { $args = Cuztom::merge($args, 'index=>0'); $data[] = new BundleItem($args); } return $data; }
php
public function build($args) { $data = []; $args = Cuztom::merge($args, [ 'parent' => $this, 'metaType' => $this->metaType, 'object' => $this->object, ]); // Build with value if (Cuztom::isArray($this->value)) { $i = 0; foreach ($this->value as $value) { $args = Cuztom::merge($args, "index=>$i"); $data[] = new BundleItem($args, $value); $i++; } } // Without value else { $args = Cuztom::merge($args, 'index=>0'); $data[] = new BundleItem($args); } return $data; }
[ "public", "function", "build", "(", "$", "args", ")", "{", "$", "data", "=", "[", "]", ";", "$", "args", "=", "Cuztom", "::", "merge", "(", "$", "args", ",", "[", "'parent'", "=>", "$", "this", ",", "'metaType'", "=>", "$", "this", "->", "metaType", ",", "'object'", "=>", "$", "this", "->", "object", ",", "]", ")", ";", "// Build with value", "if", "(", "Cuztom", "::", "isArray", "(", "$", "this", "->", "value", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "this", "->", "value", "as", "$", "value", ")", "{", "$", "args", "=", "Cuztom", "::", "merge", "(", "$", "args", ",", "\"index=>$i\"", ")", ";", "$", "data", "[", "]", "=", "new", "BundleItem", "(", "$", "args", ",", "$", "value", ")", ";", "$", "i", "++", ";", "}", "}", "// Without value", "else", "{", "$", "args", "=", "Cuztom", "::", "merge", "(", "$", "args", ",", "'index=>0'", ")", ";", "$", "data", "[", "]", "=", "new", "BundleItem", "(", "$", "args", ")", ";", "}", "return", "$", "data", ";", "}" ]
This method builds the complete array for a bundle. @param array $data @param array $values
[ "This", "method", "builds", "the", "complete", "array", "for", "a", "bundle", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/Bundle.php#L120-L151
38,119
gizburdt/cuztom
src/Meta/Box.php
Box.addHooks
public function addHooks() { if (isset($this->callback[0]) && $this->callback[0] == $this) { foreach ($this->postTypes as $postType) { add_filter('manage_'.$postType.'_posts_columns', [$this, 'addColumn']); add_action('manage_'.$postType.'_posts_custom_column', [$this, 'addColumnContent'], 10, 2); add_action('manage_edit-'.$postType.'_sortable_columns', [$this, 'addSortableColumn'], 10, 2); } add_action('save_post', [$this, 'savePost']); add_action('post_edit_form_tag', [$this, 'editFormTag']); } // Add the meta box add_action('add_meta_boxes', [$this, 'addMetaBox']); // Do do_action('cuztom_box_hooks', $this); }
php
public function addHooks() { if (isset($this->callback[0]) && $this->callback[0] == $this) { foreach ($this->postTypes as $postType) { add_filter('manage_'.$postType.'_posts_columns', [$this, 'addColumn']); add_action('manage_'.$postType.'_posts_custom_column', [$this, 'addColumnContent'], 10, 2); add_action('manage_edit-'.$postType.'_sortable_columns', [$this, 'addSortableColumn'], 10, 2); } add_action('save_post', [$this, 'savePost']); add_action('post_edit_form_tag', [$this, 'editFormTag']); } // Add the meta box add_action('add_meta_boxes', [$this, 'addMetaBox']); // Do do_action('cuztom_box_hooks', $this); }
[ "public", "function", "addHooks", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "callback", "[", "0", "]", ")", "&&", "$", "this", "->", "callback", "[", "0", "]", "==", "$", "this", ")", "{", "foreach", "(", "$", "this", "->", "postTypes", "as", "$", "postType", ")", "{", "add_filter", "(", "'manage_'", ".", "$", "postType", ".", "'_posts_columns'", ",", "[", "$", "this", ",", "'addColumn'", "]", ")", ";", "add_action", "(", "'manage_'", ".", "$", "postType", ".", "'_posts_custom_column'", ",", "[", "$", "this", ",", "'addColumnContent'", "]", ",", "10", ",", "2", ")", ";", "add_action", "(", "'manage_edit-'", ".", "$", "postType", ".", "'_sortable_columns'", ",", "[", "$", "this", ",", "'addSortableColumn'", "]", ",", "10", ",", "2", ")", ";", "}", "add_action", "(", "'save_post'", ",", "[", "$", "this", ",", "'savePost'", "]", ")", ";", "add_action", "(", "'post_edit_form_tag'", ",", "[", "$", "this", ",", "'editFormTag'", "]", ")", ";", "}", "// Add the meta box", "add_action", "(", "'add_meta_boxes'", ",", "[", "$", "this", ",", "'addMetaBox'", "]", ")", ";", "// Do", "do_action", "(", "'cuztom_box_hooks'", ",", "$", "this", ")", ";", "}" ]
Add all hooks.
[ "Add", "all", "hooks", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Box.php#L62-L80
38,120
gizburdt/cuztom
src/Meta/Box.php
Box.addMetaBox
public function addMetaBox() { foreach ($this->postTypes as $postType) { add_meta_box( $this->id, $this->title, $this->callback, $postType, $this->context, $this->priority ); } }
php
public function addMetaBox() { foreach ($this->postTypes as $postType) { add_meta_box( $this->id, $this->title, $this->callback, $postType, $this->context, $this->priority ); } }
[ "public", "function", "addMetaBox", "(", ")", "{", "foreach", "(", "$", "this", "->", "postTypes", "as", "$", "postType", ")", "{", "add_meta_box", "(", "$", "this", "->", "id", ",", "$", "this", "->", "title", ",", "$", "this", "->", "callback", ",", "$", "postType", ",", "$", "this", "->", "context", ",", "$", "this", "->", "priority", ")", ";", "}", "}" ]
Method that calls the add_meta_box function.
[ "Method", "that", "calls", "the", "add_meta_box", "function", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Box.php#L85-L97
38,121
gizburdt/cuztom
src/Meta/Box.php
Box.savePost
public function savePost($id) { if ( Guard::doingAutosave() || Guard::doingAjax() || ! Guard::verifyNonce('cuztom_nonce', 'cuztom_meta') || ! Guard::isPostType($id, $this->postTypes) || ! Guard::userCanEdit($id) ) { return; } // Filter $values = apply_filters('cuztom_box_save_values', (new Request($_POST))->getAll(), $this); // Do do_action('cuztom_box_save', $this); parent::save($id, $values); }
php
public function savePost($id) { if ( Guard::doingAutosave() || Guard::doingAjax() || ! Guard::verifyNonce('cuztom_nonce', 'cuztom_meta') || ! Guard::isPostType($id, $this->postTypes) || ! Guard::userCanEdit($id) ) { return; } // Filter $values = apply_filters('cuztom_box_save_values', (new Request($_POST))->getAll(), $this); // Do do_action('cuztom_box_save', $this); parent::save($id, $values); }
[ "public", "function", "savePost", "(", "$", "id", ")", "{", "if", "(", "Guard", "::", "doingAutosave", "(", ")", "||", "Guard", "::", "doingAjax", "(", ")", "||", "!", "Guard", "::", "verifyNonce", "(", "'cuztom_nonce'", ",", "'cuztom_meta'", ")", "||", "!", "Guard", "::", "isPostType", "(", "$", "id", ",", "$", "this", "->", "postTypes", ")", "||", "!", "Guard", "::", "userCanEdit", "(", "$", "id", ")", ")", "{", "return", ";", "}", "// Filter", "$", "values", "=", "apply_filters", "(", "'cuztom_box_save_values'", ",", "(", "new", "Request", "(", "$", "_POST", ")", ")", "->", "getAll", "(", ")", ",", "$", "this", ")", ";", "// Do", "do_action", "(", "'cuztom_box_save'", ",", "$", "this", ")", ";", "parent", "::", "save", "(", "$", "id", ",", "$", "values", ")", ";", "}" ]
Hooks into the save hook for the newly registered Post Type. @param int $id
[ "Hooks", "into", "the", "save", "hook", "for", "the", "newly", "registered", "Post", "Type", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Box.php#L104-L123
38,122
gizburdt/cuztom
src/Meta/Box.php
Box.addColumn
public function addColumn($columns) { unset($columns['date']); foreach ($this->data as $id => $field) { if (isset($field->show_admin_column) && $field->show_admin_column) { $columns[$id] = $field->label; } } $columns['date'] = __('Date'); return $columns; }
php
public function addColumn($columns) { unset($columns['date']); foreach ($this->data as $id => $field) { if (isset($field->show_admin_column) && $field->show_admin_column) { $columns[$id] = $field->label; } } $columns['date'] = __('Date'); return $columns; }
[ "public", "function", "addColumn", "(", "$", "columns", ")", "{", "unset", "(", "$", "columns", "[", "'date'", "]", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "id", "=>", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "->", "show_admin_column", ")", "&&", "$", "field", "->", "show_admin_column", ")", "{", "$", "columns", "[", "$", "id", "]", "=", "$", "field", "->", "label", ";", "}", "}", "$", "columns", "[", "'date'", "]", "=", "__", "(", "'Date'", ")", ";", "return", "$", "columns", ";", "}" ]
Used to add a column head to the Post Type's List Table. @param array $columns @return array
[ "Used", "to", "add", "a", "column", "head", "to", "the", "Post", "Type", "s", "List", "Table", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Box.php#L131-L144
38,123
gizburdt/cuztom
src/Meta/Box.php
Box.addSortableColumn
public function addSortableColumn($columns) { if ($this->data) { foreach ($this->data as $id => $field) { if ($field->admin_column_sortable) { $columns[$id] = $field->label; } } } return $columns; }
php
public function addSortableColumn($columns) { if ($this->data) { foreach ($this->data as $id => $field) { if ($field->admin_column_sortable) { $columns[$id] = $field->label; } } } return $columns; }
[ "public", "function", "addSortableColumn", "(", "$", "columns", ")", "{", "if", "(", "$", "this", "->", "data", ")", "{", "foreach", "(", "$", "this", "->", "data", "as", "$", "id", "=>", "$", "field", ")", "{", "if", "(", "$", "field", "->", "admin_column_sortable", ")", "{", "$", "columns", "[", "$", "id", "]", "=", "$", "field", "->", "label", ";", "}", "}", "}", "return", "$", "columns", ";", "}" ]
Used to make all columns sortable. @param array $columns @return array
[ "Used", "to", "make", "all", "columns", "sortable", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Box.php#L167-L178
38,124
gizburdt/cuztom
src/Meta/Box.php
Box.determineObject
public function determineObject() { if (isset($_GET['post'])) { return $_GET['post']; } if (isset($_POST['post_ID'])) { return $_POST['post_ID']; } if (isset($_POST['cuztom']['object'])) { return $_POST['cuztom']['object']; } }
php
public function determineObject() { if (isset($_GET['post'])) { return $_GET['post']; } if (isset($_POST['post_ID'])) { return $_POST['post_ID']; } if (isset($_POST['cuztom']['object'])) { return $_POST['cuztom']['object']; } }
[ "public", "function", "determineObject", "(", ")", "{", "if", "(", "isset", "(", "$", "_GET", "[", "'post'", "]", ")", ")", "{", "return", "$", "_GET", "[", "'post'", "]", ";", "}", "if", "(", "isset", "(", "$", "_POST", "[", "'post_ID'", "]", ")", ")", "{", "return", "$", "_POST", "[", "'post_ID'", "]", ";", "}", "if", "(", "isset", "(", "$", "_POST", "[", "'cuztom'", "]", "[", "'object'", "]", ")", ")", "{", "return", "$", "_POST", "[", "'cuztom'", "]", "[", "'object'", "]", ";", "}", "}" ]
Get object ID. @return int|null
[ "Get", "object", "ID", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Meta/Box.php#L185-L198
38,125
gizburdt/cuztom
src/Fields/Text.php
Text.parseValue
public function parseValue($value) { if (is_array($value)) { array_walk_recursive($value, [$this, 'doHtmlspecialchars']); } else { $value = $this->doHtmlspecialchars($value); } return parent::parseValue($value); }
php
public function parseValue($value) { if (is_array($value)) { array_walk_recursive($value, [$this, 'doHtmlspecialchars']); } else { $value = $this->doHtmlspecialchars($value); } return parent::parseValue($value); }
[ "public", "function", "parseValue", "(", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "array_walk_recursive", "(", "$", "value", ",", "[", "$", "this", ",", "'doHtmlspecialchars'", "]", ")", ";", "}", "else", "{", "$", "value", "=", "$", "this", "->", "doHtmlspecialchars", "(", "$", "value", ")", ";", "}", "return", "parent", "::", "parseValue", "(", "$", "value", ")", ";", "}" ]
Parse value for HTML special chars. @param string $value @return string
[ "Parse", "value", "for", "HTML", "special", "chars", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/Text.php#L25-L34
38,126
gizburdt/cuztom
src/Fields/Image.php
Image.outputColumnContent
public function outputColumnContent($post_id) { $meta = get_post_meta($post_id, $this->id, true); echo wp_get_attachment_image($meta, [100, 100]); }
php
public function outputColumnContent($post_id) { $meta = get_post_meta($post_id, $this->id, true); echo wp_get_attachment_image($meta, [100, 100]); }
[ "public", "function", "outputColumnContent", "(", "$", "post_id", ")", "{", "$", "meta", "=", "get_post_meta", "(", "$", "post_id", ",", "$", "this", "->", "id", ",", "true", ")", ";", "echo", "wp_get_attachment_image", "(", "$", "meta", ",", "[", "100", ",", "100", "]", ")", ";", "}" ]
Output column content. @param string $post_id @return string
[ "Output", "column", "content", "." ]
440afc5b9b65302dab2138c97974883ede90fbce
https://github.com/gizburdt/cuztom/blob/440afc5b9b65302dab2138c97974883ede90fbce/src/Fields/Image.php#L71-L76
38,127
hellowearemito/yii2-sentry
src/Component.php
Component.setEnvironmentOptions
private function setEnvironmentOptions() { if (empty($this->environment)) { return; } if (is_object($this->client) && property_exists($this->client, 'environment')) { $this->client->environment = $this->environment; } $this->jsOptions['environment'] = $this->environment; }
php
private function setEnvironmentOptions() { if (empty($this->environment)) { return; } if (is_object($this->client) && property_exists($this->client, 'environment')) { $this->client->environment = $this->environment; } $this->jsOptions['environment'] = $this->environment; }
[ "private", "function", "setEnvironmentOptions", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "environment", ")", ")", "{", "return", ";", "}", "if", "(", "is_object", "(", "$", "this", "->", "client", ")", "&&", "property_exists", "(", "$", "this", "->", "client", ",", "'environment'", ")", ")", "{", "$", "this", "->", "client", "->", "environment", "=", "$", "this", "->", "environment", ";", "}", "$", "this", "->", "jsOptions", "[", "'environment'", "]", "=", "$", "this", "->", "environment", ";", "}" ]
Adds a tag to filter events by environment
[ "Adds", "a", "tag", "to", "filter", "events", "by", "environment" ]
a754ab1bf2f7262a6637341b534a4638a787dd6e
https://github.com/hellowearemito/yii2-sentry/blob/a754ab1bf2f7262a6637341b534a4638a787dd6e/src/Component.php#L88-L98
38,128
hellowearemito/yii2-sentry
src/Component.php
Component.registerAssets
private function registerAssets() { if ($this->jsNotifier === false) { return; } if (!Yii::$app instanceof \yii\web\Application) { return; } try { $view = Yii::$app->getView(); RavenAsset::register($view); $view->registerJs('Raven.config(' . Json::encode($this->publicDsn) . ', ' . Json::encode($this->jsOptions) . ').install();', View::POS_HEAD); } catch (Exception $e) { // initialize Sentry component even if unable to register the assets Yii::error($e->getMessage()); } }
php
private function registerAssets() { if ($this->jsNotifier === false) { return; } if (!Yii::$app instanceof \yii\web\Application) { return; } try { $view = Yii::$app->getView(); RavenAsset::register($view); $view->registerJs('Raven.config(' . Json::encode($this->publicDsn) . ', ' . Json::encode($this->jsOptions) . ').install();', View::POS_HEAD); } catch (Exception $e) { // initialize Sentry component even if unable to register the assets Yii::error($e->getMessage()); } }
[ "private", "function", "registerAssets", "(", ")", "{", "if", "(", "$", "this", "->", "jsNotifier", "===", "false", ")", "{", "return", ";", "}", "if", "(", "!", "Yii", "::", "$", "app", "instanceof", "\\", "yii", "\\", "web", "\\", "Application", ")", "{", "return", ";", "}", "try", "{", "$", "view", "=", "Yii", "::", "$", "app", "->", "getView", "(", ")", ";", "RavenAsset", "::", "register", "(", "$", "view", ")", ";", "$", "view", "->", "registerJs", "(", "'Raven.config('", ".", "Json", "::", "encode", "(", "$", "this", "->", "publicDsn", ")", ".", "', '", ".", "Json", "::", "encode", "(", "$", "this", "->", "jsOptions", ")", ".", "').install();'", ",", "View", "::", "POS_HEAD", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// initialize Sentry component even if unable to register the assets", "Yii", "::", "error", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Registers RavenJS if publicDsn exists
[ "Registers", "RavenJS", "if", "publicDsn", "exists" ]
a754ab1bf2f7262a6637341b534a4638a787dd6e
https://github.com/hellowearemito/yii2-sentry/blob/a754ab1bf2f7262a6637341b534a4638a787dd6e/src/Component.php#L118-L136
38,129
tgallice/fb-messenger-sdk
src/Messenger.php
Messenger.subscribe
public function subscribe() { $response = $this->client->post('/me/subscribed_apps'); $decoded = $this->decodeResponse($response); return $decoded['success']; }
php
public function subscribe() { $response = $this->client->post('/me/subscribed_apps'); $decoded = $this->decodeResponse($response); return $decoded['success']; }
[ "public", "function", "subscribe", "(", ")", "{", "$", "response", "=", "$", "this", "->", "client", "->", "post", "(", "'/me/subscribed_apps'", ")", ";", "$", "decoded", "=", "$", "this", "->", "decodeResponse", "(", "$", "response", ")", ";", "return", "$", "decoded", "[", "'success'", "]", ";", "}" ]
Subscribe the app to the page @return bool
[ "Subscribe", "the", "app", "to", "the", "page" ]
1904df1a6dadb0e57b06ab109c9ca4a7e351843c
https://github.com/tgallice/fb-messenger-sdk/blob/1904df1a6dadb0e57b06ab109c9ca4a7e351843c/src/Messenger.php#L94-L100
38,130
tgallice/fb-messenger-sdk
src/WebhookRequestHandler.php
WebhookRequestHandler.isValidVerifyTokenRequest
public function isValidVerifyTokenRequest() { if ($this->getRequest()->getMethod() !== 'GET') { return false; } $params = $this->getRequest()->getQueryParams(); if (!isset($params['hub_verify_token'])) { return false; } return $params['hub_verify_token'] === $this->verifyToken; }
php
public function isValidVerifyTokenRequest() { if ($this->getRequest()->getMethod() !== 'GET') { return false; } $params = $this->getRequest()->getQueryParams(); if (!isset($params['hub_verify_token'])) { return false; } return $params['hub_verify_token'] === $this->verifyToken; }
[ "public", "function", "isValidVerifyTokenRequest", "(", ")", "{", "if", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getMethod", "(", ")", "!==", "'GET'", ")", "{", "return", "false", ";", "}", "$", "params", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getQueryParams", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "params", "[", "'hub_verify_token'", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "params", "[", "'hub_verify_token'", "]", "===", "$", "this", "->", "verifyToken", ";", "}" ]
Check if the token match with the given verify token. This is useful in the webhook setup process. @return bool
[ "Check", "if", "the", "token", "match", "with", "the", "given", "verify", "token", ".", "This", "is", "useful", "in", "the", "webhook", "setup", "process", "." ]
1904df1a6dadb0e57b06ab109c9ca4a7e351843c
https://github.com/tgallice/fb-messenger-sdk/blob/1904df1a6dadb0e57b06ab109c9ca4a7e351843c/src/WebhookRequestHandler.php#L80-L93
38,131
tgallice/fb-messenger-sdk
src/WebhookRequestHandler.php
WebhookRequestHandler.isValidCallbackRequest
public function isValidCallbackRequest() { if (!$this->isValidHubSignature()) { return false; } $decoded = $this->getDecodedBody(); $object = isset($decoded['object']) ? $decoded['object'] : null; $entry = isset($decoded['entry']) ? $decoded['entry'] : null; return $object === 'page' && null !== $entry; }
php
public function isValidCallbackRequest() { if (!$this->isValidHubSignature()) { return false; } $decoded = $this->getDecodedBody(); $object = isset($decoded['object']) ? $decoded['object'] : null; $entry = isset($decoded['entry']) ? $decoded['entry'] : null; return $object === 'page' && null !== $entry; }
[ "public", "function", "isValidCallbackRequest", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isValidHubSignature", "(", ")", ")", "{", "return", "false", ";", "}", "$", "decoded", "=", "$", "this", "->", "getDecodedBody", "(", ")", ";", "$", "object", "=", "isset", "(", "$", "decoded", "[", "'object'", "]", ")", "?", "$", "decoded", "[", "'object'", "]", ":", "null", ";", "$", "entry", "=", "isset", "(", "$", "decoded", "[", "'entry'", "]", ")", "?", "$", "decoded", "[", "'entry'", "]", ":", "null", ";", "return", "$", "object", "===", "'page'", "&&", "null", "!==", "$", "entry", ";", "}" ]
Check if the request is a valid webhook request @return bool
[ "Check", "if", "the", "request", "is", "a", "valid", "webhook", "request" ]
1904df1a6dadb0e57b06ab109c9ca4a7e351843c
https://github.com/tgallice/fb-messenger-sdk/blob/1904df1a6dadb0e57b06ab109c9ca4a7e351843c/src/WebhookRequestHandler.php#L110-L122
38,132
tgallice/fb-messenger-sdk
src/WebhookRequestHandler.php
WebhookRequestHandler.dispatchCallbackEvents
public function dispatchCallbackEvents() { foreach ($this->getAllCallbackEvents() as $event) { $this->dispatcher->dispatch($event->getName(), $event); if ($event instanceof PostbackEvent) { // Dispatch postback payload $this->dispatcher->dispatch($event->getPostback()->getPayload(), $event); } if ($event instanceof MessageEvent && $event->isQuickReply()) { // Dispatch quick reply payload $this->dispatcher->dispatch($event->getQuickReplyPayload(), $event); } } }
php
public function dispatchCallbackEvents() { foreach ($this->getAllCallbackEvents() as $event) { $this->dispatcher->dispatch($event->getName(), $event); if ($event instanceof PostbackEvent) { // Dispatch postback payload $this->dispatcher->dispatch($event->getPostback()->getPayload(), $event); } if ($event instanceof MessageEvent && $event->isQuickReply()) { // Dispatch quick reply payload $this->dispatcher->dispatch($event->getQuickReplyPayload(), $event); } } }
[ "public", "function", "dispatchCallbackEvents", "(", ")", "{", "foreach", "(", "$", "this", "->", "getAllCallbackEvents", "(", ")", "as", "$", "event", ")", "{", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "$", "event", "->", "getName", "(", ")", ",", "$", "event", ")", ";", "if", "(", "$", "event", "instanceof", "PostbackEvent", ")", "{", "// Dispatch postback payload", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "$", "event", "->", "getPostback", "(", ")", "->", "getPayload", "(", ")", ",", "$", "event", ")", ";", "}", "if", "(", "$", "event", "instanceof", "MessageEvent", "&&", "$", "event", "->", "isQuickReply", "(", ")", ")", "{", "// Dispatch quick reply payload", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "$", "event", "->", "getQuickReplyPayload", "(", ")", ",", "$", "event", ")", ";", "}", "}", "}" ]
Dispatch events to listeners
[ "Dispatch", "events", "to", "listeners" ]
1904df1a6dadb0e57b06ab109c9ca4a7e351843c
https://github.com/tgallice/fb-messenger-sdk/blob/1904df1a6dadb0e57b06ab109c9ca4a7e351843c/src/WebhookRequestHandler.php#L187-L202
38,133
authbucket/oauth2-php
src/GrantType/PasswordGrantTypeHandler.php
PasswordGrantTypeHandler.checkUsername
private function checkUsername(Request $request) { // username must exist and in valid format. $username = $request->request->get('username'); $errors = $this->validator->validate($username, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Username(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // password must exist and in valid format. $password = $request->request->get('password'); $errors = $this->validator->validate($password, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Password(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // Validate credentials with authentication manager. try { $token = new UsernamePasswordToken($username, $password, 'oauth2'); $authenticationProvider = new DaoAuthenticationProvider( $this->userProvider, new UserChecker(), 'oauth2', $this->encoderFactory ); $authenticationProvider->authenticate($token); } catch (BadCredentialsException $e) { throw new InvalidGrantException([ 'error_description' => 'The provided resource owner credentials is invalid.', ]); } return $username; }
php
private function checkUsername(Request $request) { // username must exist and in valid format. $username = $request->request->get('username'); $errors = $this->validator->validate($username, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Username(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // password must exist and in valid format. $password = $request->request->get('password'); $errors = $this->validator->validate($password, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Password(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // Validate credentials with authentication manager. try { $token = new UsernamePasswordToken($username, $password, 'oauth2'); $authenticationProvider = new DaoAuthenticationProvider( $this->userProvider, new UserChecker(), 'oauth2', $this->encoderFactory ); $authenticationProvider->authenticate($token); } catch (BadCredentialsException $e) { throw new InvalidGrantException([ 'error_description' => 'The provided resource owner credentials is invalid.', ]); } return $username; }
[ "private", "function", "checkUsername", "(", "Request", "$", "request", ")", "{", "// username must exist and in valid format.", "$", "username", "=", "$", "request", "->", "request", "->", "get", "(", "'username'", ")", ";", "$", "errors", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "username", ",", "[", "new", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "NotBlank", "(", ")", ",", "new", "\\", "AuthBucket", "\\", "OAuth2", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "Username", "(", ")", ",", "]", ")", ";", "if", "(", "count", "(", "$", "errors", ")", ">", "0", ")", "{", "throw", "new", "InvalidRequestException", "(", "[", "'error_description'", "=>", "'The request includes an invalid parameter value.'", ",", "]", ")", ";", "}", "// password must exist and in valid format.", "$", "password", "=", "$", "request", "->", "request", "->", "get", "(", "'password'", ")", ";", "$", "errors", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "password", ",", "[", "new", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "NotBlank", "(", ")", ",", "new", "\\", "AuthBucket", "\\", "OAuth2", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "Password", "(", ")", ",", "]", ")", ";", "if", "(", "count", "(", "$", "errors", ")", ">", "0", ")", "{", "throw", "new", "InvalidRequestException", "(", "[", "'error_description'", "=>", "'The request includes an invalid parameter value.'", ",", "]", ")", ";", "}", "// Validate credentials with authentication manager.", "try", "{", "$", "token", "=", "new", "UsernamePasswordToken", "(", "$", "username", ",", "$", "password", ",", "'oauth2'", ")", ";", "$", "authenticationProvider", "=", "new", "DaoAuthenticationProvider", "(", "$", "this", "->", "userProvider", ",", "new", "UserChecker", "(", ")", ",", "'oauth2'", ",", "$", "this", "->", "encoderFactory", ")", ";", "$", "authenticationProvider", "->", "authenticate", "(", "$", "token", ")", ";", "}", "catch", "(", "BadCredentialsException", "$", "e", ")", "{", "throw", "new", "InvalidGrantException", "(", "[", "'error_description'", "=>", "'The provided resource owner credentials is invalid.'", ",", "]", ")", ";", "}", "return", "$", "username", ";", "}" ]
Fetch username from POST. @param Request $request Incoming request object @return string The supplied username @throw InvalidRequestException If username or password in invalid format. @throw InvalidGrantException If reported as bad credentials from authentication provider.
[ "Fetch", "username", "from", "POST", "." ]
d923b94de8c6c567cb22e8c57af48a16f71f0c56
https://github.com/authbucket/oauth2-php/blob/d923b94de8c6c567cb22e8c57af48a16f71f0c56/src/GrantType/PasswordGrantTypeHandler.php#L69-L112
38,134
authbucket/oauth2-php
src/GrantType/AuthorizationCodeGrantTypeHandler.php
AuthorizationCodeGrantTypeHandler.checkCode
private function checkCode( Request $request, $clientId ) { // code is required and must in valid format. $code = $request->request->get('code'); $errors = $this->validator->validate($code, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Code(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // Check code with database record. $codeManager = $this->modelManagerFactory->getModelManager('code'); $result = $codeManager->readModelOneBy([ 'code' => $code, ]); if ($result === null || $result->getClientId() !== $clientId) { throw new InvalidGrantException([ 'error_description' => 'The provided authorization grant is invalid.', ]); } elseif ($result->getExpires() < new \DateTime()) { throw new InvalidGrantException([ 'error_description' => 'The provided authorization grant is expired.', ]); } return [$result->getUsername(), $result->getScope()]; }
php
private function checkCode( Request $request, $clientId ) { // code is required and must in valid format. $code = $request->request->get('code'); $errors = $this->validator->validate($code, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Code(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // Check code with database record. $codeManager = $this->modelManagerFactory->getModelManager('code'); $result = $codeManager->readModelOneBy([ 'code' => $code, ]); if ($result === null || $result->getClientId() !== $clientId) { throw new InvalidGrantException([ 'error_description' => 'The provided authorization grant is invalid.', ]); } elseif ($result->getExpires() < new \DateTime()) { throw new InvalidGrantException([ 'error_description' => 'The provided authorization grant is expired.', ]); } return [$result->getUsername(), $result->getScope()]; }
[ "private", "function", "checkCode", "(", "Request", "$", "request", ",", "$", "clientId", ")", "{", "// code is required and must in valid format.", "$", "code", "=", "$", "request", "->", "request", "->", "get", "(", "'code'", ")", ";", "$", "errors", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "code", ",", "[", "new", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "NotBlank", "(", ")", ",", "new", "\\", "AuthBucket", "\\", "OAuth2", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "Code", "(", ")", ",", "]", ")", ";", "if", "(", "count", "(", "$", "errors", ")", ">", "0", ")", "{", "throw", "new", "InvalidRequestException", "(", "[", "'error_description'", "=>", "'The request includes an invalid parameter value.'", ",", "]", ")", ";", "}", "// Check code with database record.", "$", "codeManager", "=", "$", "this", "->", "modelManagerFactory", "->", "getModelManager", "(", "'code'", ")", ";", "$", "result", "=", "$", "codeManager", "->", "readModelOneBy", "(", "[", "'code'", "=>", "$", "code", ",", "]", ")", ";", "if", "(", "$", "result", "===", "null", "||", "$", "result", "->", "getClientId", "(", ")", "!==", "$", "clientId", ")", "{", "throw", "new", "InvalidGrantException", "(", "[", "'error_description'", "=>", "'The provided authorization grant is invalid.'", ",", "]", ")", ";", "}", "elseif", "(", "$", "result", "->", "getExpires", "(", ")", "<", "new", "\\", "DateTime", "(", ")", ")", "{", "throw", "new", "InvalidGrantException", "(", "[", "'error_description'", "=>", "'The provided authorization grant is expired.'", ",", "]", ")", ";", "}", "return", "[", "$", "result", "->", "getUsername", "(", ")", ",", "$", "result", "->", "getScope", "(", ")", "]", ";", "}" ]
Fetch code from POST. @param Request $request Incoming request object @param string $clientId Corresponding client_id that code should belongs to @return array A list with stored username and scope, originally grant in authorize endpoint @throw InvalidRequestException If code in invalid format. @throw InvalidGrantException If code provided is no longer valid.
[ "Fetch", "code", "from", "POST", "." ]
d923b94de8c6c567cb22e8c57af48a16f71f0c56
https://github.com/authbucket/oauth2-php/blob/d923b94de8c6c567cb22e8c57af48a16f71f0c56/src/GrantType/AuthorizationCodeGrantTypeHandler.php#L63-L95
38,135
authbucket/oauth2-php
src/GrantType/AuthorizationCodeGrantTypeHandler.php
AuthorizationCodeGrantTypeHandler.checkRedirectUri
private function checkRedirectUri( Request $request, $clientId ) { // redirect_uri may not exists. $redirectUri = $request->request->get('redirect_uri'); $errors = $this->validator->validate($redirectUri, [ new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\RedirectUri(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // redirect_uri is not required if already established via other channels, // check an existing redirect URI against the one supplied. $stored = null; $clientManager = $this->modelManagerFactory->getModelManager('client'); $result = $clientManager->readModelOneBy([ 'clientId' => $clientId, ]); if ($result !== null && $result->getRedirectUri()) { $stored = $result->getRedirectUri(); } // At least one of: existing redirect URI or input redirect URI must be // specified. if (!$stored && !$redirectUri) { throw new InvalidRequestException([ 'error_description' => 'The request is missing a required parameter.', ]); } // If there's an existing uri and one from input, verify that they match. if ($stored && $redirectUri) { // Ensure that the input uri starts with the stored uri. if (strcasecmp(substr($redirectUri, 0, strlen($stored)), $stored) !== 0) { throw new InvalidGrantException([ 'error_description' => 'The provided authorization grant does not match the redirection URI used in the authorization request.', ]); } } return $redirectUri ?: $stored; }
php
private function checkRedirectUri( Request $request, $clientId ) { // redirect_uri may not exists. $redirectUri = $request->request->get('redirect_uri'); $errors = $this->validator->validate($redirectUri, [ new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\RedirectUri(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // redirect_uri is not required if already established via other channels, // check an existing redirect URI against the one supplied. $stored = null; $clientManager = $this->modelManagerFactory->getModelManager('client'); $result = $clientManager->readModelOneBy([ 'clientId' => $clientId, ]); if ($result !== null && $result->getRedirectUri()) { $stored = $result->getRedirectUri(); } // At least one of: existing redirect URI or input redirect URI must be // specified. if (!$stored && !$redirectUri) { throw new InvalidRequestException([ 'error_description' => 'The request is missing a required parameter.', ]); } // If there's an existing uri and one from input, verify that they match. if ($stored && $redirectUri) { // Ensure that the input uri starts with the stored uri. if (strcasecmp(substr($redirectUri, 0, strlen($stored)), $stored) !== 0) { throw new InvalidGrantException([ 'error_description' => 'The provided authorization grant does not match the redirection URI used in the authorization request.', ]); } } return $redirectUri ?: $stored; }
[ "private", "function", "checkRedirectUri", "(", "Request", "$", "request", ",", "$", "clientId", ")", "{", "// redirect_uri may not exists.", "$", "redirectUri", "=", "$", "request", "->", "request", "->", "get", "(", "'redirect_uri'", ")", ";", "$", "errors", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "redirectUri", ",", "[", "new", "\\", "AuthBucket", "\\", "OAuth2", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "RedirectUri", "(", ")", ",", "]", ")", ";", "if", "(", "count", "(", "$", "errors", ")", ">", "0", ")", "{", "throw", "new", "InvalidRequestException", "(", "[", "'error_description'", "=>", "'The request includes an invalid parameter value.'", ",", "]", ")", ";", "}", "// redirect_uri is not required if already established via other channels,", "// check an existing redirect URI against the one supplied.", "$", "stored", "=", "null", ";", "$", "clientManager", "=", "$", "this", "->", "modelManagerFactory", "->", "getModelManager", "(", "'client'", ")", ";", "$", "result", "=", "$", "clientManager", "->", "readModelOneBy", "(", "[", "'clientId'", "=>", "$", "clientId", ",", "]", ")", ";", "if", "(", "$", "result", "!==", "null", "&&", "$", "result", "->", "getRedirectUri", "(", ")", ")", "{", "$", "stored", "=", "$", "result", "->", "getRedirectUri", "(", ")", ";", "}", "// At least one of: existing redirect URI or input redirect URI must be", "// specified.", "if", "(", "!", "$", "stored", "&&", "!", "$", "redirectUri", ")", "{", "throw", "new", "InvalidRequestException", "(", "[", "'error_description'", "=>", "'The request is missing a required parameter.'", ",", "]", ")", ";", "}", "// If there's an existing uri and one from input, verify that they match.", "if", "(", "$", "stored", "&&", "$", "redirectUri", ")", "{", "// Ensure that the input uri starts with the stored uri.", "if", "(", "strcasecmp", "(", "substr", "(", "$", "redirectUri", ",", "0", ",", "strlen", "(", "$", "stored", ")", ")", ",", "$", "stored", ")", "!==", "0", ")", "{", "throw", "new", "InvalidGrantException", "(", "[", "'error_description'", "=>", "'The provided authorization grant does not match the redirection URI used in the authorization request.'", ",", "]", ")", ";", "}", "}", "return", "$", "redirectUri", "?", ":", "$", "stored", ";", "}" ]
Fetch redirect_uri from POST, or stored record. @param Request $request Incoming request object @param string $clientId Corresponding client_id that code should belongs to @return string The supplied redirect_uri from incoming request, or from stored record @throw InvalidRequestException If redirect_uri not exists in both incoming request and database record, or supplied value not match with stord record.
[ "Fetch", "redirect_uri", "from", "POST", "or", "stored", "record", "." ]
d923b94de8c6c567cb22e8c57af48a16f71f0c56
https://github.com/authbucket/oauth2-php/blob/d923b94de8c6c567cb22e8c57af48a16f71f0c56/src/GrantType/AuthorizationCodeGrantTypeHandler.php#L107-L152
38,136
authbucket/oauth2-php
src/ResponseType/AbstractResponseTypeHandler.php
AbstractResponseTypeHandler.checkUsername
protected function checkUsername() { $token = $this->tokenStorage->getToken(); if (!$token instanceof RememberMeToken && !$token instanceof UsernamePasswordToken) { throw new ServerErrorException([ 'error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.', ]); } return $token->getUsername(); }
php
protected function checkUsername() { $token = $this->tokenStorage->getToken(); if (!$token instanceof RememberMeToken && !$token instanceof UsernamePasswordToken) { throw new ServerErrorException([ 'error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.', ]); } return $token->getUsername(); }
[ "protected", "function", "checkUsername", "(", ")", "{", "$", "token", "=", "$", "this", "->", "tokenStorage", "->", "getToken", "(", ")", ";", "if", "(", "!", "$", "token", "instanceof", "RememberMeToken", "&&", "!", "$", "token", "instanceof", "UsernamePasswordToken", ")", "{", "throw", "new", "ServerErrorException", "(", "[", "'error_description'", "=>", "'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.'", ",", "]", ")", ";", "}", "return", "$", "token", "->", "getUsername", "(", ")", ";", "}" ]
Fetch username from authenticated token. @return string Supplied username from authenticated token @throw ServerErrorException If supplied token is not a standard TokenInterface instance.
[ "Fetch", "username", "from", "authenticated", "token", "." ]
d923b94de8c6c567cb22e8c57af48a16f71f0c56
https://github.com/authbucket/oauth2-php/blob/d923b94de8c6c567cb22e8c57af48a16f71f0c56/src/ResponseType/AbstractResponseTypeHandler.php#L57-L67
38,137
authbucket/oauth2-php
src/ResponseType/AbstractResponseTypeHandler.php
AbstractResponseTypeHandler.checkClientId
protected function checkClientId(Request $request) { // client_id is required and in valid format. $clientId = $request->query->get('client_id'); $errors = $this->validator->validate($clientId, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\ClientId(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // Compare client_id with database record. $clientManager = $this->modelManagerFactory->getModelManager('client'); $result = $clientManager->readModelOneBy([ 'clientId' => $clientId, ]); if ($result === null) { throw new UnauthorizedClientException([ 'error_description' => 'The client is not authorized.', ]); } return $clientId; }
php
protected function checkClientId(Request $request) { // client_id is required and in valid format. $clientId = $request->query->get('client_id'); $errors = $this->validator->validate($clientId, [ new \Symfony\Component\Validator\Constraints\NotBlank(), new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\ClientId(), ]); if (count($errors) > 0) { throw new InvalidRequestException([ 'error_description' => 'The request includes an invalid parameter value.', ]); } // Compare client_id with database record. $clientManager = $this->modelManagerFactory->getModelManager('client'); $result = $clientManager->readModelOneBy([ 'clientId' => $clientId, ]); if ($result === null) { throw new UnauthorizedClientException([ 'error_description' => 'The client is not authorized.', ]); } return $clientId; }
[ "protected", "function", "checkClientId", "(", "Request", "$", "request", ")", "{", "// client_id is required and in valid format.", "$", "clientId", "=", "$", "request", "->", "query", "->", "get", "(", "'client_id'", ")", ";", "$", "errors", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "clientId", ",", "[", "new", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "NotBlank", "(", ")", ",", "new", "\\", "AuthBucket", "\\", "OAuth2", "\\", "Symfony", "\\", "Component", "\\", "Validator", "\\", "Constraints", "\\", "ClientId", "(", ")", ",", "]", ")", ";", "if", "(", "count", "(", "$", "errors", ")", ">", "0", ")", "{", "throw", "new", "InvalidRequestException", "(", "[", "'error_description'", "=>", "'The request includes an invalid parameter value.'", ",", "]", ")", ";", "}", "// Compare client_id with database record.", "$", "clientManager", "=", "$", "this", "->", "modelManagerFactory", "->", "getModelManager", "(", "'client'", ")", ";", "$", "result", "=", "$", "clientManager", "->", "readModelOneBy", "(", "[", "'clientId'", "=>", "$", "clientId", ",", "]", ")", ";", "if", "(", "$", "result", "===", "null", ")", "{", "throw", "new", "UnauthorizedClientException", "(", "[", "'error_description'", "=>", "'The client is not authorized.'", ",", "]", ")", ";", "}", "return", "$", "clientId", ";", "}" ]
Fetch cliend_id from GET. @param Request $request Incoming request object @return string Supplied client_id from incoming request @throw InvalidRequestException If supplied client_id in bad format. @throw UnauthorizedClientException If client_id not found from database record.
[ "Fetch", "cliend_id", "from", "GET", "." ]
d923b94de8c6c567cb22e8c57af48a16f71f0c56
https://github.com/authbucket/oauth2-php/blob/d923b94de8c6c567cb22e8c57af48a16f71f0c56/src/ResponseType/AbstractResponseTypeHandler.php#L79-L105
38,138
ProAI/laravel-handlebars
src/Compilers/HandlebarsCompiler.php
HandlebarsCompiler.getLanguageHelpers
protected function getLanguageHelpers() { return [ 'lang' => function ($args, $named) { return Lang::get($args[0], $named); }, 'choice' => function ($args, $named) { return Lang::choice($args[0], $args[1], $named); } ]; }
php
protected function getLanguageHelpers() { return [ 'lang' => function ($args, $named) { return Lang::get($args[0], $named); }, 'choice' => function ($args, $named) { return Lang::choice($args[0], $args[1], $named); } ]; }
[ "protected", "function", "getLanguageHelpers", "(", ")", "{", "return", "[", "'lang'", "=>", "function", "(", "$", "args", ",", "$", "named", ")", "{", "return", "Lang", "::", "get", "(", "$", "args", "[", "0", "]", ",", "$", "named", ")", ";", "}", ",", "'choice'", "=>", "function", "(", "$", "args", ",", "$", "named", ")", "{", "return", "Lang", "::", "choice", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "named", ")", ";", "}", "]", ";", "}" ]
Get language helper functions. @return array
[ "Get", "language", "helper", "functions", "." ]
c0e154d2df1dfa667c2226e19710f06b8acef94e
https://github.com/ProAI/laravel-handlebars/blob/c0e154d2df1dfa667c2226e19710f06b8acef94e/src/Compilers/HandlebarsCompiler.php#L166-L176
38,139
ProAI/laravel-handlebars
src/HandlebarsServiceProvider.php
HandlebarsServiceProvider.registerHandlebarsEngine
public function registerHandlebarsEngine($resolver) { $app = $this->app; // The Compiler engine requires an instance of the CompilerInterface, which in // this case will be the Handlebars compiler, so we'll first create the compiler // instance to pass into the engine so it can compile the views properly. $app->singleton('handlebars.lightncandy', function ($app) { return new LightnCandy; }); $app->singleton('handlebars.compiler', function ($app) { $cache = $app['config']['view.compiled']; return new HandlebarsCompiler($app['files'], $app['handlebars.lightncandy'], $cache); }); $resolver->register('handlebars', function () use ($app) { return new HandlebarsEngine($app['handlebars.compiler']); }); }
php
public function registerHandlebarsEngine($resolver) { $app = $this->app; // The Compiler engine requires an instance of the CompilerInterface, which in // this case will be the Handlebars compiler, so we'll first create the compiler // instance to pass into the engine so it can compile the views properly. $app->singleton('handlebars.lightncandy', function ($app) { return new LightnCandy; }); $app->singleton('handlebars.compiler', function ($app) { $cache = $app['config']['view.compiled']; return new HandlebarsCompiler($app['files'], $app['handlebars.lightncandy'], $cache); }); $resolver->register('handlebars', function () use ($app) { return new HandlebarsEngine($app['handlebars.compiler']); }); }
[ "public", "function", "registerHandlebarsEngine", "(", "$", "resolver", ")", "{", "$", "app", "=", "$", "this", "->", "app", ";", "// The Compiler engine requires an instance of the CompilerInterface, which in", "// this case will be the Handlebars compiler, so we'll first create the compiler", "// instance to pass into the engine so it can compile the views properly.", "$", "app", "->", "singleton", "(", "'handlebars.lightncandy'", ",", "function", "(", "$", "app", ")", "{", "return", "new", "LightnCandy", ";", "}", ")", ";", "$", "app", "->", "singleton", "(", "'handlebars.compiler'", ",", "function", "(", "$", "app", ")", "{", "$", "cache", "=", "$", "app", "[", "'config'", "]", "[", "'view.compiled'", "]", ";", "return", "new", "HandlebarsCompiler", "(", "$", "app", "[", "'files'", "]", ",", "$", "app", "[", "'handlebars.lightncandy'", "]", ",", "$", "cache", ")", ";", "}", ")", ";", "$", "resolver", "->", "register", "(", "'handlebars'", ",", "function", "(", ")", "use", "(", "$", "app", ")", "{", "return", "new", "HandlebarsEngine", "(", "$", "app", "[", "'handlebars.compiler'", "]", ")", ";", "}", ")", ";", "}" ]
Register the mustache engine implementation. @param \Illuminate\View\Engines\EngineResolver $resolver @return void
[ "Register", "the", "mustache", "engine", "implementation", "." ]
c0e154d2df1dfa667c2226e19710f06b8acef94e
https://github.com/ProAI/laravel-handlebars/blob/c0e154d2df1dfa667c2226e19710f06b8acef94e/src/HandlebarsServiceProvider.php#L82-L102
38,140
ProAI/laravel-handlebars
src/HandlebarsServiceProvider.php
HandlebarsServiceProvider.registerFileExtensions
protected function registerFileExtensions() { $this->app->extend('view', function ($env, $app) { $fileexts = $app['config']['handlebars.fileext']; foreach ($fileexts as $fileext) { $env->addExtension(trim($fileext, '.'), 'handlebars'); } return $env; }); }
php
protected function registerFileExtensions() { $this->app->extend('view', function ($env, $app) { $fileexts = $app['config']['handlebars.fileext']; foreach ($fileexts as $fileext) { $env->addExtension(trim($fileext, '.'), 'handlebars'); } return $env; }); }
[ "protected", "function", "registerFileExtensions", "(", ")", "{", "$", "this", "->", "app", "->", "extend", "(", "'view'", ",", "function", "(", "$", "env", ",", "$", "app", ")", "{", "$", "fileexts", "=", "$", "app", "[", "'config'", "]", "[", "'handlebars.fileext'", "]", ";", "foreach", "(", "$", "fileexts", "as", "$", "fileext", ")", "{", "$", "env", "->", "addExtension", "(", "trim", "(", "$", "fileext", ",", "'.'", ")", ",", "'handlebars'", ")", ";", "}", "return", "$", "env", ";", "}", ")", ";", "}" ]
Register the file extensions. @return void
[ "Register", "the", "file", "extensions", "." ]
c0e154d2df1dfa667c2226e19710f06b8acef94e
https://github.com/ProAI/laravel-handlebars/blob/c0e154d2df1dfa667c2226e19710f06b8acef94e/src/HandlebarsServiceProvider.php#L109-L120
38,141
ProAI/laravel-handlebars
src/Support/LightnCandy.php
LightnCandy.setupToken
protected static function setupToken(&$context, $left = '{{', $right = '}}') { parent::setupToken($context, $left, $right); if (self::$compileHelpersOnly) { $helperTokens = array(); foreach ($context['helpers'] as $helper => $value) { $helperTokens[] = $helper . '.*?'; } $helperTokens = implode('|', $helperTokens); $context['tokens']['search'] = "/^(.*?)(\\s*)($left)(~?)([\\^#\\/!&>]?)(" . $helperTokens . ")(~?)($right)(\\s*)(.*)\$/s"; } }
php
protected static function setupToken(&$context, $left = '{{', $right = '}}') { parent::setupToken($context, $left, $right); if (self::$compileHelpersOnly) { $helperTokens = array(); foreach ($context['helpers'] as $helper => $value) { $helperTokens[] = $helper . '.*?'; } $helperTokens = implode('|', $helperTokens); $context['tokens']['search'] = "/^(.*?)(\\s*)($left)(~?)([\\^#\\/!&>]?)(" . $helperTokens . ")(~?)($right)(\\s*)(.*)\$/s"; } }
[ "protected", "static", "function", "setupToken", "(", "&", "$", "context", ",", "$", "left", "=", "'{{'", ",", "$", "right", "=", "'}}'", ")", "{", "parent", "::", "setupToken", "(", "$", "context", ",", "$", "left", ",", "$", "right", ")", ";", "if", "(", "self", "::", "$", "compileHelpersOnly", ")", "{", "$", "helperTokens", "=", "array", "(", ")", ";", "foreach", "(", "$", "context", "[", "'helpers'", "]", "as", "$", "helper", "=>", "$", "value", ")", "{", "$", "helperTokens", "[", "]", "=", "$", "helper", ".", "'.*?'", ";", "}", "$", "helperTokens", "=", "implode", "(", "'|'", ",", "$", "helperTokens", ")", ";", "$", "context", "[", "'tokens'", "]", "[", "'search'", "]", "=", "\"/^(.*?)(\\\\s*)($left)(~?)([\\\\^#\\\\/!&>]?)(\"", ".", "$", "helperTokens", ".", "\")(~?)($right)(\\\\s*)(.*)\\$/s\"", ";", "}", "}" ]
Setup token delimiter by default or provided string @param array<string,array|string|integer> $context Current context @param string $left left string of a token @param string $right right string of a token
[ "Setup", "token", "delimiter", "by", "default", "or", "provided", "string" ]
c0e154d2df1dfa667c2226e19710f06b8acef94e
https://github.com/ProAI/laravel-handlebars/blob/c0e154d2df1dfa667c2226e19710f06b8acef94e/src/Support/LightnCandy.php#L32-L45
38,142
me-io/php-lodash
src/Traits/Strings.php
Strings.kebabCase
public static function kebabCase(string $input): string { $words = __::words(preg_replace("/['\x{2019}]/u", '', $input)); return array_reduce( $words, function ($result, $word) use ($words) { $isFirst = __::first($words) === $word; return $result . (!$isFirst ? '-' : '') . __::toLower($word); }, '' ); }
php
public static function kebabCase(string $input): string { $words = __::words(preg_replace("/['\x{2019}]/u", '', $input)); return array_reduce( $words, function ($result, $word) use ($words) { $isFirst = __::first($words) === $word; return $result . (!$isFirst ? '-' : '') . __::toLower($word); }, '' ); }
[ "public", "static", "function", "kebabCase", "(", "string", "$", "input", ")", ":", "string", "{", "$", "words", "=", "__", "::", "words", "(", "preg_replace", "(", "\"/['\\x{2019}]/u\"", ",", "''", ",", "$", "input", ")", ")", ";", "return", "array_reduce", "(", "$", "words", ",", "function", "(", "$", "result", ",", "$", "word", ")", "use", "(", "$", "words", ")", "{", "$", "isFirst", "=", "__", "::", "first", "(", "$", "words", ")", "===", "$", "word", ";", "return", "$", "result", ".", "(", "!", "$", "isFirst", "?", "'-'", ":", "''", ")", ".", "__", "::", "toLower", "(", "$", "word", ")", ";", "}", ",", "''", ")", ";", "}" ]
Converts string to kebab case. @link https://en.wikipedia.org/wiki/Letter_case#Special_case_styles kebab case @usage __::kebabCase('Foo Bar'); >> 'foo-bar' @param string $input @return string
[ "Converts", "string", "to", "kebab", "case", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Strings.php#L84-L97
38,143
me-io/php-lodash
src/Traits/Strings.php
Strings.startCase
public static function startCase(string $input): string { $words = __::words(preg_replace("/['\x{2019}]/u", '', $input)); return array_reduce( $words, function ($result, $word) use ($words) { $isFirst = __::first($words) === $word; return $result . (!$isFirst ? ' ' : '') . __::upperFirst($word); }, '' ); }
php
public static function startCase(string $input): string { $words = __::words(preg_replace("/['\x{2019}]/u", '', $input)); return array_reduce( $words, function ($result, $word) use ($words) { $isFirst = __::first($words) === $word; return $result . (!$isFirst ? ' ' : '') . __::upperFirst($word); }, '' ); }
[ "public", "static", "function", "startCase", "(", "string", "$", "input", ")", ":", "string", "{", "$", "words", "=", "__", "::", "words", "(", "preg_replace", "(", "\"/['\\x{2019}]/u\"", ",", "''", ",", "$", "input", ")", ")", ";", "return", "array_reduce", "(", "$", "words", ",", "function", "(", "$", "result", ",", "$", "word", ")", "use", "(", "$", "words", ")", "{", "$", "isFirst", "=", "__", "::", "first", "(", "$", "words", ")", "===", "$", "word", ";", "return", "$", "result", ".", "(", "!", "$", "isFirst", "?", "' '", ":", "''", ")", ".", "__", "::", "upperFirst", "(", "$", "word", ")", ";", "}", ",", "''", ")", ";", "}" ]
Converts string to start case. @link https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage start case @usage __::startCase('--foo-bar--'); >> 'Foo Bar' @param string $input @return string
[ "Converts", "string", "to", "start", "case", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Strings.php#L153-L166
38,144
me-io/php-lodash
src/Traits/Strings.php
Strings.upperCase
public static function upperCase(string $input): string { $words = __::words(preg_replace("/['\x{2019}]/u", '', $input)); return array_reduce( $words, function ($result, $word) use ($words) { $isFirst = __::first($words) === $word; return $result . (!$isFirst ? ' ' : '') . __::toUpper($word); }, '' ); }
php
public static function upperCase(string $input): string { $words = __::words(preg_replace("/['\x{2019}]/u", '', $input)); return array_reduce( $words, function ($result, $word) use ($words) { $isFirst = __::first($words) === $word; return $result . (!$isFirst ? ' ' : '') . __::toUpper($word); }, '' ); }
[ "public", "static", "function", "upperCase", "(", "string", "$", "input", ")", ":", "string", "{", "$", "words", "=", "__", "::", "words", "(", "preg_replace", "(", "\"/['\\x{2019}]/u\"", ",", "''", ",", "$", "input", ")", ")", ";", "return", "array_reduce", "(", "$", "words", ",", "function", "(", "$", "result", ",", "$", "word", ")", "use", "(", "$", "words", ")", "{", "$", "isFirst", "=", "__", "::", "first", "(", "$", "words", ")", "===", "$", "word", ";", "return", "$", "result", ".", "(", "!", "$", "isFirst", "?", "' '", ":", "''", ")", ".", "__", "::", "toUpper", "(", "$", "word", ")", ";", "}", ",", "''", ")", ";", "}" ]
Converts string, as space separated words, to upper case. @usage __::upperCase('--foo-bar'); >> 'FOO BAR' @param string $input @return string
[ "Converts", "string", "as", "space", "separated", "words", "to", "upper", "case", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Strings.php#L208-L221
38,145
me-io/php-lodash
src/Traits/Collections.php
Collections.filter
public static function filter(array $array = [], Closure $closure = null): array { if ($closure) { $result = []; foreach ($array as $key => $value) { if (call_user_func($closure, $value)) { $result[] = $value; } } return $result; } return __::compact($array); }
php
public static function filter(array $array = [], Closure $closure = null): array { if ($closure) { $result = []; foreach ($array as $key => $value) { if (call_user_func($closure, $value)) { $result[] = $value; } } return $result; } return __::compact($array); }
[ "public", "static", "function", "filter", "(", "array", "$", "array", "=", "[", "]", ",", "Closure", "$", "closure", "=", "null", ")", ":", "array", "{", "if", "(", "$", "closure", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "call_user_func", "(", "$", "closure", ",", "$", "value", ")", ")", "{", "$", "result", "[", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}", "return", "__", "::", "compact", "(", "$", "array", ")", ";", "}" ]
Returns the values in the collection that pass the truth test. @param array $array array to filter @param \Closure $closure closure to filter array based on @return array
[ "Returns", "the", "values", "in", "the", "collection", "that", "pass", "the", "truth", "test", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L20-L35
38,146
me-io/php-lodash
src/Traits/Collections.php
Collections.get
public static function get($collection = [], $key = null, $default = null) { if (__::isNull($key)) { return $collection; } if (!__::isObject($collection) && isset($collection[$key])) { return $collection[$key]; } foreach (explode('.', $key) as $segment) { if (__::isObject($collection)) { if (!isset($collection->{$segment})) { return $default instanceof Closure ? $default() : $default; } else { $collection = $collection->{$segment}; } } else { if (!isset($collection[$segment])) { return $default instanceof Closure ? $default() : $default; } else { $collection = $collection[$segment]; } } } return $collection; }
php
public static function get($collection = [], $key = null, $default = null) { if (__::isNull($key)) { return $collection; } if (!__::isObject($collection) && isset($collection[$key])) { return $collection[$key]; } foreach (explode('.', $key) as $segment) { if (__::isObject($collection)) { if (!isset($collection->{$segment})) { return $default instanceof Closure ? $default() : $default; } else { $collection = $collection->{$segment}; } } else { if (!isset($collection[$segment])) { return $default instanceof Closure ? $default() : $default; } else { $collection = $collection[$segment]; } } } return $collection; }
[ "public", "static", "function", "get", "(", "$", "collection", "=", "[", "]", ",", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "__", "::", "isNull", "(", "$", "key", ")", ")", "{", "return", "$", "collection", ";", "}", "if", "(", "!", "__", "::", "isObject", "(", "$", "collection", ")", "&&", "isset", "(", "$", "collection", "[", "$", "key", "]", ")", ")", "{", "return", "$", "collection", "[", "$", "key", "]", ";", "}", "foreach", "(", "explode", "(", "'.'", ",", "$", "key", ")", "as", "$", "segment", ")", "{", "if", "(", "__", "::", "isObject", "(", "$", "collection", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "collection", "->", "{", "$", "segment", "}", ")", ")", "{", "return", "$", "default", "instanceof", "Closure", "?", "$", "default", "(", ")", ":", "$", "default", ";", "}", "else", "{", "$", "collection", "=", "$", "collection", "->", "{", "$", "segment", "}", ";", "}", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "collection", "[", "$", "segment", "]", ")", ")", "{", "return", "$", "default", "instanceof", "Closure", "?", "$", "default", "(", ")", ":", "$", "default", ";", "}", "else", "{", "$", "collection", "=", "$", "collection", "[", "$", "segment", "]", ";", "}", "}", "}", "return", "$", "collection", ";", "}" ]
Get item of an array by index, accepting nested index @usage __::get(['foo' => ['bar' => 'ter']], 'foo.bar'); >> 'ter' @param array|object $collection array of values @param null|string $key key or index @param mixed $default default value to return if index not exist @return mixed
[ "Get", "item", "of", "an", "array", "by", "index", "accepting", "nested", "index" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L69-L96
38,147
me-io/php-lodash
src/Traits/Collections.php
Collections.pluck
public static function pluck($collection, string $property): array { $result = array_map(function ($value) use ($property) { if (is_array($value) && isset($value[$property])) { return $value[$property]; } elseif (is_object($value) && isset($value->{$property})) { return $value->{$property}; } foreach (__::split($property, '.') as $segment) { if (is_object($value)) { if (isset($value->{$segment})) { $value = $value->{$segment}; } else { return null; } } else { if (isset($value[$segment])) { $value = $value[$segment]; } else { return null; } } } return $value; }, (array)$collection); return array_values($result); }
php
public static function pluck($collection, string $property): array { $result = array_map(function ($value) use ($property) { if (is_array($value) && isset($value[$property])) { return $value[$property]; } elseif (is_object($value) && isset($value->{$property})) { return $value->{$property}; } foreach (__::split($property, '.') as $segment) { if (is_object($value)) { if (isset($value->{$segment})) { $value = $value->{$segment}; } else { return null; } } else { if (isset($value[$segment])) { $value = $value[$segment]; } else { return null; } } } return $value; }, (array)$collection); return array_values($result); }
[ "public", "static", "function", "pluck", "(", "$", "collection", ",", "string", "$", "property", ")", ":", "array", "{", "$", "result", "=", "array_map", "(", "function", "(", "$", "value", ")", "use", "(", "$", "property", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "&&", "isset", "(", "$", "value", "[", "$", "property", "]", ")", ")", "{", "return", "$", "value", "[", "$", "property", "]", ";", "}", "elseif", "(", "is_object", "(", "$", "value", ")", "&&", "isset", "(", "$", "value", "->", "{", "$", "property", "}", ")", ")", "{", "return", "$", "value", "->", "{", "$", "property", "}", ";", "}", "foreach", "(", "__", "::", "split", "(", "$", "property", ",", "'.'", ")", "as", "$", "segment", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "if", "(", "isset", "(", "$", "value", "->", "{", "$", "segment", "}", ")", ")", "{", "$", "value", "=", "$", "value", "->", "{", "$", "segment", "}", ";", "}", "else", "{", "return", "null", ";", "}", "}", "else", "{", "if", "(", "isset", "(", "$", "value", "[", "$", "segment", "]", ")", ")", "{", "$", "value", "=", "$", "value", "[", "$", "segment", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}", "}", "return", "$", "value", ";", "}", ",", "(", "array", ")", "$", "collection", ")", ";", "return", "array_values", "(", "$", "result", ")", ";", "}" ]
Returns an array of values belonging to a given property of each item in a collection. @usage $a = [ ['foo' => 'bar', 'bis' => 'ter' ], ['foo' => 'bar2', 'bis' => 'ter2'], ]; __::pluck($a, 'foo'); >> ['bar', 'bar2'] @param array|object $collection array or object that can be converted to array @param string $property property name @return array
[ "Returns", "an", "array", "of", "values", "belonging", "to", "a", "given", "property", "of", "each", "item", "in", "a", "collection", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L191-L219
38,148
me-io/php-lodash
src/Traits/Collections.php
Collections.where
public static function where(array $array = [], array $key = [], bool $keepKeys = false): array { $result = []; foreach ($array as $k => $v) { $not = false; foreach ($key as $j => $w) { if (__::isArray($w)) { $inKV = $v[$j] ?? []; if (count(array_intersect_assoc($w, $inKV)) == 0) { $not = true; break; } } else { if (!isset($v[$j]) || $v[$j] != $w) { $not = true; break; } } } if ($not == false) { if ($keepKeys) { $result[$k] = $v; } else { $result[] = $v; } } } return $result; }
php
public static function where(array $array = [], array $key = [], bool $keepKeys = false): array { $result = []; foreach ($array as $k => $v) { $not = false; foreach ($key as $j => $w) { if (__::isArray($w)) { $inKV = $v[$j] ?? []; if (count(array_intersect_assoc($w, $inKV)) == 0) { $not = true; break; } } else { if (!isset($v[$j]) || $v[$j] != $w) { $not = true; break; } } } if ($not == false) { if ($keepKeys) { $result[$k] = $v; } else { $result[] = $v; } } } return $result; }
[ "public", "static", "function", "where", "(", "array", "$", "array", "=", "[", "]", ",", "array", "$", "key", "=", "[", "]", ",", "bool", "$", "keepKeys", "=", "false", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "not", "=", "false", ";", "foreach", "(", "$", "key", "as", "$", "j", "=>", "$", "w", ")", "{", "if", "(", "__", "::", "isArray", "(", "$", "w", ")", ")", "{", "$", "inKV", "=", "$", "v", "[", "$", "j", "]", "??", "[", "]", ";", "if", "(", "count", "(", "array_intersect_assoc", "(", "$", "w", ",", "$", "inKV", ")", ")", "==", "0", ")", "{", "$", "not", "=", "true", ";", "break", ";", "}", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "v", "[", "$", "j", "]", ")", "||", "$", "v", "[", "$", "j", "]", "!=", "$", "w", ")", "{", "$", "not", "=", "true", ";", "break", ";", "}", "}", "}", "if", "(", "$", "not", "==", "false", ")", "{", "if", "(", "$", "keepKeys", ")", "{", "$", "result", "[", "$", "k", "]", "=", "$", "v", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "v", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Return data matching specific key value condition @usage __::where($a, ['age' => 16]); >> [['name' => 'maciej', 'age' => 16]] @param array $array array of values @param array $key condition in format of ['KEY'=>'VALUE'] @param bool $keepKeys keep original keys @return array
[ "Return", "data", "matching", "specific", "key", "value", "condition" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L234-L266
38,149
me-io/php-lodash
src/Traits/Collections.php
Collections.assign
public static function assign($collection1, $collection2) { return __::reduceRight(func_get_args(), function ($source, $result) { __::doForEach($source, function ($sourceValue, $key) use (&$result) { $result = __::set($result, $key, $sourceValue); }); return $result; }, []); }
php
public static function assign($collection1, $collection2) { return __::reduceRight(func_get_args(), function ($source, $result) { __::doForEach($source, function ($sourceValue, $key) use (&$result) { $result = __::set($result, $key, $sourceValue); }); return $result; }, []); }
[ "public", "static", "function", "assign", "(", "$", "collection1", ",", "$", "collection2", ")", "{", "return", "__", "::", "reduceRight", "(", "func_get_args", "(", ")", ",", "function", "(", "$", "source", ",", "$", "result", ")", "{", "__", "::", "doForEach", "(", "$", "source", ",", "function", "(", "$", "sourceValue", ",", "$", "key", ")", "use", "(", "&", "$", "result", ")", "{", "$", "result", "=", "__", "::", "set", "(", "$", "result", ",", "$", "key", ",", "$", "sourceValue", ")", ";", "}", ")", ";", "return", "$", "result", ";", "}", ",", "[", "]", ")", ";", "}" ]
Combines and merge collections provided with each others. If the collections have common keys, then the last passed keys override the previous. If numerical indexes are passed, then last passed indexes override the previous. For a recursive merge, see __::merge. @usage __::assign(['color' => ['favorite' => 'red', 5], 3], [10, 'color' => ['favorite' => 'green', 'blue']]); >> ['color' => ['favorite' => 'green', 'blue'], 10] @param array|object $collection1 Collection to assign to. @param array|object $collection2 Other collections to assign @return array|object Assigned collection.
[ "Combines", "and", "merge", "collections", "provided", "with", "each", "others", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L285-L294
38,150
me-io/php-lodash
src/Traits/Collections.php
Collections.doForEachRight
public static function doForEachRight($collection, Closure $iterateFn) { __::doForEach(__::iteratorReverse($collection), $iterateFn); return true; }
php
public static function doForEachRight($collection, Closure $iterateFn) { __::doForEach(__::iteratorReverse($collection), $iterateFn); return true; }
[ "public", "static", "function", "doForEachRight", "(", "$", "collection", ",", "Closure", "$", "iterateFn", ")", "{", "__", "::", "doForEach", "(", "__", "::", "iteratorReverse", "(", "$", "collection", ")", ",", "$", "iterateFn", ")", ";", "return", "true", ";", "}" ]
Iterate over elements of the collection, from right to left, and invokes iterate for each element. The iterate is invoked with three arguments: (value, index|key, collection). Iterate functions may exit iteration early by explicitly returning false. @usage __::doForEachRight([1, 2, 3], function ($value) { print_r($value) }); >> (Side effect: print 3, 2, 1) @param array|object $collection The collection to iterate over. @param \Closure $iterateFn The function to call for each value. @return boolean
[ "Iterate", "over", "elements", "of", "the", "collection", "from", "right", "to", "left", "and", "invokes", "iterate", "for", "each", "element", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L349-L353
38,151
me-io/php-lodash
src/Traits/Collections.php
Collections.doForEach
public static function doForEach($collection, Closure $iterateFn) { foreach ($collection as $key => $value) { if ($iterateFn($value, $key, $collection) === false) { break; } } return true; }
php
public static function doForEach($collection, Closure $iterateFn) { foreach ($collection as $key => $value) { if ($iterateFn($value, $key, $collection) === false) { break; } } return true; }
[ "public", "static", "function", "doForEach", "(", "$", "collection", ",", "Closure", "$", "iterateFn", ")", "{", "foreach", "(", "$", "collection", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "iterateFn", "(", "$", "value", ",", "$", "key", ",", "$", "collection", ")", "===", "false", ")", "{", "break", ";", "}", "}", "return", "true", ";", "}" ]
Iterate over elements of the collection and invokes iterate for each element. The iterate is invoked with three arguments: (value, index|key, collection). Iterate functions may exit iteration early by explicitly returning false. @usage __::doForEach([1, 2, 3], function ($value) { print_r($value) }); >> (Side effect: print 1, 2, 3) @param array|object $collection The collection to iterate over. @param \Closure $iterateFn The function to call for each value @return boolean
[ "Iterate", "over", "elements", "of", "the", "collection", "and", "invokes", "iterate", "for", "each", "element", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L369-L377
38,152
me-io/php-lodash
src/Traits/Collections.php
Collections.set
public static function set($collection, $path, $value = null) { if ($path === null) { return $collection; } $portions = __::split($path, '.', 2); $key = $portions[0]; if (count($portions) === 1) { return __::universalSet($collection, $key, $value); } // Here we manage the case where the portion of the path points to nothing, // or to a value that does not match the type of the source collection // (e.g. the path portion 'foo.bar' points to an integer value, while we // want to set a string at 'foo.bar.fun'. We first set an object or array // - following the current collection type - to 'for.bar' before setting // 'foo.bar.fun' to the specified value). if (!__::has($collection, $key) || (__::isObject($collection) && !__::isObject(__::get($collection, $key))) || (__::isArray($collection) && !__::isArray(__::get($collection, $key))) ) { $collection = __::universalSet($collection, $key, __::isObject($collection) ? new stdClass : []); } return __::universalSet($collection, $key, __::set(__::get($collection, $key), $portions[1], $value)); }
php
public static function set($collection, $path, $value = null) { if ($path === null) { return $collection; } $portions = __::split($path, '.', 2); $key = $portions[0]; if (count($portions) === 1) { return __::universalSet($collection, $key, $value); } // Here we manage the case where the portion of the path points to nothing, // or to a value that does not match the type of the source collection // (e.g. the path portion 'foo.bar' points to an integer value, while we // want to set a string at 'foo.bar.fun'. We first set an object or array // - following the current collection type - to 'for.bar' before setting // 'foo.bar.fun' to the specified value). if (!__::has($collection, $key) || (__::isObject($collection) && !__::isObject(__::get($collection, $key))) || (__::isArray($collection) && !__::isArray(__::get($collection, $key))) ) { $collection = __::universalSet($collection, $key, __::isObject($collection) ? new stdClass : []); } return __::universalSet($collection, $key, __::set(__::get($collection, $key), $portions[1], $value)); }
[ "public", "static", "function", "set", "(", "$", "collection", ",", "$", "path", ",", "$", "value", "=", "null", ")", "{", "if", "(", "$", "path", "===", "null", ")", "{", "return", "$", "collection", ";", "}", "$", "portions", "=", "__", "::", "split", "(", "$", "path", ",", "'.'", ",", "2", ")", ";", "$", "key", "=", "$", "portions", "[", "0", "]", ";", "if", "(", "count", "(", "$", "portions", ")", "===", "1", ")", "{", "return", "__", "::", "universalSet", "(", "$", "collection", ",", "$", "key", ",", "$", "value", ")", ";", "}", "// Here we manage the case where the portion of the path points to nothing,", "// or to a value that does not match the type of the source collection", "// (e.g. the path portion 'foo.bar' points to an integer value, while we", "// want to set a string at 'foo.bar.fun'. We first set an object or array", "// - following the current collection type - to 'for.bar' before setting", "// 'foo.bar.fun' to the specified value).", "if", "(", "!", "__", "::", "has", "(", "$", "collection", ",", "$", "key", ")", "||", "(", "__", "::", "isObject", "(", "$", "collection", ")", "&&", "!", "__", "::", "isObject", "(", "__", "::", "get", "(", "$", "collection", ",", "$", "key", ")", ")", ")", "||", "(", "__", "::", "isArray", "(", "$", "collection", ")", "&&", "!", "__", "::", "isArray", "(", "__", "::", "get", "(", "$", "collection", ",", "$", "key", ")", ")", ")", ")", "{", "$", "collection", "=", "__", "::", "universalSet", "(", "$", "collection", ",", "$", "key", ",", "__", "::", "isObject", "(", "$", "collection", ")", "?", "new", "stdClass", ":", "[", "]", ")", ";", "}", "return", "__", "::", "universalSet", "(", "$", "collection", ",", "$", "key", ",", "__", "::", "set", "(", "__", "::", "get", "(", "$", "collection", ",", "$", "key", ")", ",", "$", "portions", "[", "1", "]", ",", "$", "value", ")", ")", ";", "}" ]
Return a new collection with the item set at index to given value. Index can be a path of nested indexes. If a portion of path doesn't exist, it's created. Arrays are created for missing index in an array; objects are created for missing property in an object. @usage __::set(['foo' => ['bar' => 'ter']], 'foo.baz.ber', 'fer'); >> '['foo' => ['bar' => 'ter', 'baz' => ['ber' => 'fer']]]' @param array|object $collection collection of values @param string|int|null $path key or index @param mixed $value the value to set at position $key @throws \Exception if the path consists of a non collection and strict is set to false @return array|object the new collection with the item set
[ "Return", "a", "new", "collection", "with", "the", "item", "set", "at", "index", "to", "given", "value", ".", "Index", "can", "be", "a", "path", "of", "nested", "indexes", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L409-L433
38,153
me-io/php-lodash
src/Traits/Collections.php
Collections.concat
public static function concat($collection1, $collection2) { $isObject = __::isObject($collection1); $args = __::map(func_get_args(), function ($arg) { return (array)$arg; }); $merged = call_user_func_array('array_merge', $args); return $isObject ? (object)$merged : $merged; }
php
public static function concat($collection1, $collection2) { $isObject = __::isObject($collection1); $args = __::map(func_get_args(), function ($arg) { return (array)$arg; }); $merged = call_user_func_array('array_merge', $args); return $isObject ? (object)$merged : $merged; }
[ "public", "static", "function", "concat", "(", "$", "collection1", ",", "$", "collection2", ")", "{", "$", "isObject", "=", "__", "::", "isObject", "(", "$", "collection1", ")", ";", "$", "args", "=", "__", "::", "map", "(", "func_get_args", "(", ")", ",", "function", "(", "$", "arg", ")", "{", "return", "(", "array", ")", "$", "arg", ";", "}", ")", ";", "$", "merged", "=", "call_user_func_array", "(", "'array_merge'", ",", "$", "args", ")", ";", "return", "$", "isObject", "?", "(", "object", ")", "$", "merged", ":", "$", "merged", ";", "}" ]
Combines and concat collections provided with each others. If the collections have common keys, then the values are appended in an array. If numerical indexes are passed, then values are appended. For a recursive merge, see __::merge. @usage __::concat(['color' => ['favorite' => 'red', 5], 3], [10, 'color' => ['favorite' => 'green', 'blue']]); >> ['color' => ['favorite' => ['green'], 5, 'blue'], 3, 10] @param array|object $collection1 Collection to assign to. @param array|object $collection2 Other collections to assign. @return array|object Assigned collection.
[ "Combines", "and", "concat", "collections", "provided", "with", "each", "others", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L534-L545
38,154
me-io/php-lodash
src/Traits/Collections.php
Collections.concatDeep
public static function concatDeep($collection1, $collection2) { return __::reduceRight(func_get_args(), function ($source, $result) { __::doForEach($source, function ($sourceValue, $key) use (&$result) { if (!__::has($result, $key)) { $result = __::set($result, $key, $sourceValue); } else { if (is_numeric($key)) { $result = __::concat($result, [$sourceValue]); } else { $resultValue = __::get($result, $key); $result = __::set($result, $key, __::concatDeep( __::isCollection($resultValue) ? $resultValue : (array)$resultValue, __::isCollection($sourceValue) ? $sourceValue : (array)$sourceValue )); } } }); return $result; }, []); }
php
public static function concatDeep($collection1, $collection2) { return __::reduceRight(func_get_args(), function ($source, $result) { __::doForEach($source, function ($sourceValue, $key) use (&$result) { if (!__::has($result, $key)) { $result = __::set($result, $key, $sourceValue); } else { if (is_numeric($key)) { $result = __::concat($result, [$sourceValue]); } else { $resultValue = __::get($result, $key); $result = __::set($result, $key, __::concatDeep( __::isCollection($resultValue) ? $resultValue : (array)$resultValue, __::isCollection($sourceValue) ? $sourceValue : (array)$sourceValue )); } } }); return $result; }, []); }
[ "public", "static", "function", "concatDeep", "(", "$", "collection1", ",", "$", "collection2", ")", "{", "return", "__", "::", "reduceRight", "(", "func_get_args", "(", ")", ",", "function", "(", "$", "source", ",", "$", "result", ")", "{", "__", "::", "doForEach", "(", "$", "source", ",", "function", "(", "$", "sourceValue", ",", "$", "key", ")", "use", "(", "&", "$", "result", ")", "{", "if", "(", "!", "__", "::", "has", "(", "$", "result", ",", "$", "key", ")", ")", "{", "$", "result", "=", "__", "::", "set", "(", "$", "result", ",", "$", "key", ",", "$", "sourceValue", ")", ";", "}", "else", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "result", "=", "__", "::", "concat", "(", "$", "result", ",", "[", "$", "sourceValue", "]", ")", ";", "}", "else", "{", "$", "resultValue", "=", "__", "::", "get", "(", "$", "result", ",", "$", "key", ")", ";", "$", "result", "=", "__", "::", "set", "(", "$", "result", ",", "$", "key", ",", "__", "::", "concatDeep", "(", "__", "::", "isCollection", "(", "$", "resultValue", ")", "?", "$", "resultValue", ":", "(", "array", ")", "$", "resultValue", ",", "__", "::", "isCollection", "(", "$", "sourceValue", ")", "?", "$", "sourceValue", ":", "(", "array", ")", "$", "sourceValue", ")", ")", ";", "}", "}", "}", ")", ";", "return", "$", "result", ";", "}", ",", "[", "]", ")", ";", "}" ]
Recursively combines and concat collections provided with each others. If the collections have common keys, then the values are appended in an array. If numerical indexes are passed, then values are appended. For a non-recursive concat, see __::concat. @usage __::concatDeep(['color' => ['favorite' => 'red', 5], 3], [10, 'color' => ['favorite' => 'green', 'blue']]); >> ['color' => ['favorite' => ['red', 'green'], 5, 'blue'], 3, 10] @param array|object $collection1 First collection to concatDeep. @param array|object $collection2 other collections to concatDeep. @return array|object Concatenated collection.
[ "Recursively", "combines", "and", "concat", "collections", "provided", "with", "each", "others", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L564-L585
38,155
me-io/php-lodash
src/Traits/Collections.php
Collections.ease
public static function ease(array $collection, string $glue = '.'): array { $map = []; __::internalEase($map, $collection, $glue); return $map; }
php
public static function ease(array $collection, string $glue = '.'): array { $map = []; __::internalEase($map, $collection, $glue); return $map; }
[ "public", "static", "function", "ease", "(", "array", "$", "collection", ",", "string", "$", "glue", "=", "'.'", ")", ":", "array", "{", "$", "map", "=", "[", "]", ";", "__", "::", "internalEase", "(", "$", "map", ",", "$", "collection", ",", "$", "glue", ")", ";", "return", "$", "map", ";", "}" ]
Flattens a complex collection by mapping each ending leafs value to a key consisting of all previous indexes. @usage __::ease(['foo' => ['bar' => 'ter'], 'baz' => ['b', 'z']]); >> '['foo.bar' => 'ter', 'baz.0' => 'b', , 'baz.1' => 'z']' @param array $collection array of values @param string $glue glue between key path @return array flatten collection
[ "Flattens", "a", "complex", "collection", "by", "mapping", "each", "ending", "leafs", "value", "to", "a", "key", "consisting", "of", "all", "previous", "indexes", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L598-L604
38,156
me-io/php-lodash
src/Traits/Collections.php
Collections.every
public static function every($collection, Closure $iterateFn): bool { $truthy = true; __::doForEach( $collection, function ($value, $key, $collection) use (&$truthy, $iterateFn) { $truthy = $truthy && $iterateFn($value, $key, $collection); if (!$truthy) { return false; } } ); return $truthy; }
php
public static function every($collection, Closure $iterateFn): bool { $truthy = true; __::doForEach( $collection, function ($value, $key, $collection) use (&$truthy, $iterateFn) { $truthy = $truthy && $iterateFn($value, $key, $collection); if (!$truthy) { return false; } } ); return $truthy; }
[ "public", "static", "function", "every", "(", "$", "collection", ",", "Closure", "$", "iterateFn", ")", ":", "bool", "{", "$", "truthy", "=", "true", ";", "__", "::", "doForEach", "(", "$", "collection", ",", "function", "(", "$", "value", ",", "$", "key", ",", "$", "collection", ")", "use", "(", "&", "$", "truthy", ",", "$", "iterateFn", ")", "{", "$", "truthy", "=", "$", "truthy", "&&", "$", "iterateFn", "(", "$", "value", ",", "$", "key", ",", "$", "collection", ")", ";", "if", "(", "!", "$", "truthy", ")", "{", "return", "false", ";", "}", "}", ")", ";", "return", "$", "truthy", ";", "}" ]
Checks if predicate returns truthy for all elements of collection. Iteration is stopped once predicate returns falsey. The predicate is invoked with three arguments: (value, index|key, collection). @usage __::every([1, 3, 4], function ($v) { return is_int($v); }); >> true @param array|object $collection The collection to iterate over. @param \Closure $iterateFn The function to call for each value. @return bool
[ "Checks", "if", "predicate", "returns", "truthy", "for", "all", "elements", "of", "collection", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L639-L654
38,157
me-io/php-lodash
src/Traits/Collections.php
Collections.isEmpty
public static function isEmpty($value): bool { return (!__::isArray($value) && !__::isObject($value)) || count((array)$value) === 0; }
php
public static function isEmpty($value): bool { return (!__::isArray($value) && !__::isObject($value)) || count((array)$value) === 0; }
[ "public", "static", "function", "isEmpty", "(", "$", "value", ")", ":", "bool", "{", "return", "(", "!", "__", "::", "isArray", "(", "$", "value", ")", "&&", "!", "__", "::", "isObject", "(", "$", "value", ")", ")", "||", "count", "(", "(", "array", ")", "$", "value", ")", "===", "0", ";", "}" ]
Check if value is an empty array or object. We consider any non enumerable as empty. @usage __::isEmpty([]); >> true @param mixed $value The value to check for emptiness. @return bool
[ "Check", "if", "value", "is", "an", "empty", "array", "or", "object", ".", "We", "consider", "any", "non", "enumerable", "as", "empty", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L743-L746
38,158
me-io/php-lodash
src/Traits/Collections.php
Collections.mapKeys
public static function mapKeys(array $array, Closure $closure = null): array { if (is_null($closure)) { $closure = '__::identity'; } $resultArray = []; foreach ($array as $key => $value) { $newKey = call_user_func_array($closure, [$key, $value, $array]); // key must be a number or string if (!is_numeric($newKey) && !is_string($newKey)) { throw new Exception('closure must returns a number or string'); } $resultArray[$newKey] = $value; } return $resultArray; }
php
public static function mapKeys(array $array, Closure $closure = null): array { if (is_null($closure)) { $closure = '__::identity'; } $resultArray = []; foreach ($array as $key => $value) { $newKey = call_user_func_array($closure, [$key, $value, $array]); // key must be a number or string if (!is_numeric($newKey) && !is_string($newKey)) { throw new Exception('closure must returns a number or string'); } $resultArray[$newKey] = $value; } return $resultArray; }
[ "public", "static", "function", "mapKeys", "(", "array", "$", "array", ",", "Closure", "$", "closure", "=", "null", ")", ":", "array", "{", "if", "(", "is_null", "(", "$", "closure", ")", ")", "{", "$", "closure", "=", "'__::identity'", ";", "}", "$", "resultArray", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "newKey", "=", "call_user_func_array", "(", "$", "closure", ",", "[", "$", "key", ",", "$", "value", ",", "$", "array", "]", ")", ";", "// key must be a number or string", "if", "(", "!", "is_numeric", "(", "$", "newKey", ")", "&&", "!", "is_string", "(", "$", "newKey", ")", ")", "{", "throw", "new", "Exception", "(", "'closure must returns a number or string'", ")", ";", "}", "$", "resultArray", "[", "$", "newKey", "]", "=", "$", "value", ";", "}", "return", "$", "resultArray", ";", "}" ]
Transforms the keys in a collection by running each key through the iterator @param array $array array of values @param \Closure $closure closure to map the keys @throws \Exception if closure doesn't return a valid key that can be used in PHP array @return array
[ "Transforms", "the", "keys", "in", "a", "collection", "by", "running", "each", "key", "through", "the", "iterator" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L758-L774
38,159
me-io/php-lodash
src/Traits/Collections.php
Collections.mapValues
public static function mapValues(array $array, Closure $closure = null): array { if (is_null($closure)) { $closure = '__::identity'; } $resultArray = []; foreach ($array as $key => $value) { $resultArray[$key] = call_user_func_array($closure, [$value, $key, $array]); } return $resultArray; }
php
public static function mapValues(array $array, Closure $closure = null): array { if (is_null($closure)) { $closure = '__::identity'; } $resultArray = []; foreach ($array as $key => $value) { $resultArray[$key] = call_user_func_array($closure, [$value, $key, $array]); } return $resultArray; }
[ "public", "static", "function", "mapValues", "(", "array", "$", "array", ",", "Closure", "$", "closure", "=", "null", ")", ":", "array", "{", "if", "(", "is_null", "(", "$", "closure", ")", ")", "{", "$", "closure", "=", "'__::identity'", ";", "}", "$", "resultArray", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "resultArray", "[", "$", "key", "]", "=", "call_user_func_array", "(", "$", "closure", ",", "[", "$", "value", ",", "$", "key", ",", "$", "array", "]", ")", ";", "}", "return", "$", "resultArray", ";", "}" ]
Transforms the values in a collection by running each value through the iterator @param array $array array of values @param \Closure $closure closure to map the values @return array
[ "Transforms", "the", "values", "in", "a", "collection", "by", "running", "each", "value", "through", "the", "iterator" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L784-L795
38,160
me-io/php-lodash
src/Traits/Collections.php
Collections.merge
public static function merge($collection1, $collection2) { return __::reduceRight(func_get_args(), function ($source, $result) { __::doForEach($source, function ($sourceValue, $key) use (&$result) { $value = $sourceValue; if (__::isCollection($value)) { $value = __::merge(__::get($result, $key), $sourceValue); } $result = __::set($result, $key, $value); }); return $result; }, []); }
php
public static function merge($collection1, $collection2) { return __::reduceRight(func_get_args(), function ($source, $result) { __::doForEach($source, function ($sourceValue, $key) use (&$result) { $value = $sourceValue; if (__::isCollection($value)) { $value = __::merge(__::get($result, $key), $sourceValue); } $result = __::set($result, $key, $value); }); return $result; }, []); }
[ "public", "static", "function", "merge", "(", "$", "collection1", ",", "$", "collection2", ")", "{", "return", "__", "::", "reduceRight", "(", "func_get_args", "(", ")", ",", "function", "(", "$", "source", ",", "$", "result", ")", "{", "__", "::", "doForEach", "(", "$", "source", ",", "function", "(", "$", "sourceValue", ",", "$", "key", ")", "use", "(", "&", "$", "result", ")", "{", "$", "value", "=", "$", "sourceValue", ";", "if", "(", "__", "::", "isCollection", "(", "$", "value", ")", ")", "{", "$", "value", "=", "__", "::", "merge", "(", "__", "::", "get", "(", "$", "result", ",", "$", "key", ")", ",", "$", "sourceValue", ")", ";", "}", "$", "result", "=", "__", "::", "set", "(", "$", "result", ",", "$", "key", ",", "$", "value", ")", ";", "}", ")", ";", "return", "$", "result", ";", "}", ",", "[", "]", ")", ";", "}" ]
Recursively combines and merge collections provided with each others. If the collections have common keys, then the last passed keys override the previous. If numerical indexes are passed, then last passed indexes override the previous. For a non-recursive merge, see __::merge. @usage __::merge(['color' => ['favorite' => 'red', 'model' => 3, 5], 3], [10, 'color' => ['favorite' => 'green', 'blue']]); >> ['color' => ['favorite' => 'green', 'model' => 3, 'blue'], 10] @param array|object $collection1 First collection to merge. @param array|object $collection2 Other collections to merge. @return array|object Concatenated collection.
[ "Recursively", "combines", "and", "merge", "collections", "provided", "with", "each", "others", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L814-L827
38,161
me-io/php-lodash
src/Traits/Collections.php
Collections.pick
public static function pick($collection = [], array $paths = [], $default = null) { return __::reduce($paths, function ($results, $path) use ($collection, $default) { return __::set($results, $path, __::get($collection, $path, $default)); }, __::isObject($collection) ? new stdClass() : []); }
php
public static function pick($collection = [], array $paths = [], $default = null) { return __::reduce($paths, function ($results, $path) use ($collection, $default) { return __::set($results, $path, __::get($collection, $path, $default)); }, __::isObject($collection) ? new stdClass() : []); }
[ "public", "static", "function", "pick", "(", "$", "collection", "=", "[", "]", ",", "array", "$", "paths", "=", "[", "]", ",", "$", "default", "=", "null", ")", "{", "return", "__", "::", "reduce", "(", "$", "paths", ",", "function", "(", "$", "results", ",", "$", "path", ")", "use", "(", "$", "collection", ",", "$", "default", ")", "{", "return", "__", "::", "set", "(", "$", "results", ",", "$", "path", ",", "__", "::", "get", "(", "$", "collection", ",", "$", "path", ",", "$", "default", ")", ")", ";", "}", ",", "__", "::", "isObject", "(", "$", "collection", ")", "?", "new", "stdClass", "(", ")", ":", "[", "]", ")", ";", "}" ]
Returns an array having only keys present in the given path list. Values for missing keys values will be filled with provided default value. @usage __::pick(['a' => 1, 'b' => ['c' => 3, 'd' => 4]], ['a', 'b.d']); >> ['a' => 1, 'b' => ['d' => 4]] @param array|object $collection The collection to iterate over. @param array $paths array paths to pick @param null $default @return array|object
[ "Returns", "an", "array", "having", "only", "keys", "present", "in", "the", "given", "path", "list", ".", "Values", "for", "missing", "keys", "values", "will", "be", "filled", "with", "provided", "default", "value", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L842-L847
38,162
me-io/php-lodash
src/Traits/Collections.php
Collections.unease
public static function unease(array $collection, string $separator = '.'): array { $nonDefaultSeparator = $separator !== '.'; $map = []; foreach ($collection as $key => $value) { $map = __::set( $map, $nonDefaultSeparator ? str_replace($separator, '.', $key) : $key, $value ); } return $map; }
php
public static function unease(array $collection, string $separator = '.'): array { $nonDefaultSeparator = $separator !== '.'; $map = []; foreach ($collection as $key => $value) { $map = __::set( $map, $nonDefaultSeparator ? str_replace($separator, '.', $key) : $key, $value ); } return $map; }
[ "public", "static", "function", "unease", "(", "array", "$", "collection", ",", "string", "$", "separator", "=", "'.'", ")", ":", "array", "{", "$", "nonDefaultSeparator", "=", "$", "separator", "!==", "'.'", ";", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "collection", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "map", "=", "__", "::", "set", "(", "$", "map", ",", "$", "nonDefaultSeparator", "?", "str_replace", "(", "$", "separator", ",", "'.'", ",", "$", "key", ")", ":", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "map", ";", "}" ]
Builds a multidimensional collection out of a hash map using the key as indicator where to put the value. @usage __::unease(['foo.bar' => 'ter', 'baz.0' => 'b', , 'baz.1' => 'z']); >> '['foo' => ['bar' => 'ter'], 'baz' => ['b', 'z']]' @param array $collection hash map of values @param string $separator the glue used in the keys @return array @throws \Exception
[ "Builds", "a", "multidimensional", "collection", "out", "of", "a", "hash", "map", "using", "the", "key", "as", "indicator", "where", "to", "put", "the", "value", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Collections.php#L935-L949
38,163
me-io/php-lodash
src/Traits/Arrays.php
Arrays.patch
public static function patch(array $array, array $patches, string $parent = ''): array { foreach ($array as $key => $value) { $z = $parent . '/' . $key; if (isset($patches[$z])) { $array[$key] = $patches[$z]; unset($patches[$z]); if (!count($patches)) { break; } } if (is_array($value)) { $array[$key] = static::patch($value, $patches, $z); } } return $array; }
php
public static function patch(array $array, array $patches, string $parent = ''): array { foreach ($array as $key => $value) { $z = $parent . '/' . $key; if (isset($patches[$z])) { $array[$key] = $patches[$z]; unset($patches[$z]); if (!count($patches)) { break; } } if (is_array($value)) { $array[$key] = static::patch($value, $patches, $z); } } return $array; }
[ "public", "static", "function", "patch", "(", "array", "$", "array", ",", "array", "$", "patches", ",", "string", "$", "parent", "=", "''", ")", ":", "array", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "z", "=", "$", "parent", ".", "'/'", ".", "$", "key", ";", "if", "(", "isset", "(", "$", "patches", "[", "$", "z", "]", ")", ")", "{", "$", "array", "[", "$", "key", "]", "=", "$", "patches", "[", "$", "z", "]", ";", "unset", "(", "$", "patches", "[", "$", "z", "]", ")", ";", "if", "(", "!", "count", "(", "$", "patches", ")", ")", "{", "break", ";", "}", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "array", "[", "$", "key", "]", "=", "static", "::", "patch", "(", "$", "value", ",", "$", "patches", ",", "$", "z", ")", ";", "}", "}", "return", "$", "array", ";", "}" ]
Patches array by xpath. @usage __::patch( ['addr' => ['country' => 'US', 'zip' => 12345]], ['/addr/country' => 'CA','/addr/zip' => 54321] ); * >> ['addr' => ['country' => 'CA', 'zip' => 54321]] @param array $array The array to patch @param array $patches List of new xpath-value pairs @param string $parent @return array Returns patched array
[ "Patches", "array", "by", "xpath", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L122-L142
38,164
me-io/php-lodash
src/Traits/Arrays.php
Arrays.range
public static function range($start = null, $stop = null, int $step = 1): array { if ($stop == null && $start != null) { $stop = $start; $start = 1; } return range($start, $stop, $step); }
php
public static function range($start = null, $stop = null, int $step = 1): array { if ($stop == null && $start != null) { $stop = $start; $start = 1; } return range($start, $stop, $step); }
[ "public", "static", "function", "range", "(", "$", "start", "=", "null", ",", "$", "stop", "=", "null", ",", "int", "$", "step", "=", "1", ")", ":", "array", "{", "if", "(", "$", "stop", "==", "null", "&&", "$", "start", "!=", "null", ")", "{", "$", "stop", "=", "$", "start", ";", "$", "start", "=", "1", ";", "}", "return", "range", "(", "$", "start", ",", "$", "stop", ",", "$", "step", ")", ";", "}" ]
Generate range of values based on start , end and step @usage __::range(1, 10, 2); * >> [1, 3, 5, 7, 9] @param int|null $start range start @param int|null $stop range end @param int $step range step value @return array range of values
[ "Generate", "range", "of", "values", "based", "on", "start", "end", "and", "step" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L174-L182
38,165
me-io/php-lodash
src/Traits/Arrays.php
Arrays.repeat
public static function repeat($object = '', int $times = null): array { $times = abs($times); if ($times == null) { return []; } return array_fill(0, $times, $object); }
php
public static function repeat($object = '', int $times = null): array { $times = abs($times); if ($times == null) { return []; } return array_fill(0, $times, $object); }
[ "public", "static", "function", "repeat", "(", "$", "object", "=", "''", ",", "int", "$", "times", "=", "null", ")", ":", "array", "{", "$", "times", "=", "abs", "(", "$", "times", ")", ";", "if", "(", "$", "times", "==", "null", ")", "{", "return", "[", "]", ";", "}", "return", "array_fill", "(", "0", ",", "$", "times", ",", "$", "object", ")", ";", "}" ]
Generate array of repeated values @usage __::repeat('foo', 3); * >> ['foo', 'foo', 'foo'] @param string $object The object to repeat. @param int $times ow many times has to be repeated. @return array Returns a new array of filled values.
[ "Generate", "array", "of", "repeated", "values" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L196-L204
38,166
me-io/php-lodash
src/Traits/Arrays.php
Arrays.randomize
public static function randomize(array $array): array { for ($i = 0, $c = count($array); $i < $c - 1; $i++) { $j = rand($i + 1, $c - 1); list($array[$i], $array[$j]) = [$array[$j], $array[$i]]; } return $array; }
php
public static function randomize(array $array): array { for ($i = 0, $c = count($array); $i < $c - 1; $i++) { $j = rand($i + 1, $c - 1); list($array[$i], $array[$j]) = [$array[$j], $array[$i]]; } return $array; }
[ "public", "static", "function", "randomize", "(", "array", "$", "array", ")", ":", "array", "{", "for", "(", "$", "i", "=", "0", ",", "$", "c", "=", "count", "(", "$", "array", ")", ";", "$", "i", "<", "$", "c", "-", "1", ";", "$", "i", "++", ")", "{", "$", "j", "=", "rand", "(", "$", "i", "+", "1", ",", "$", "c", "-", "1", ")", ";", "list", "(", "$", "array", "[", "$", "i", "]", ",", "$", "array", "[", "$", "j", "]", ")", "=", "[", "$", "array", "[", "$", "j", "]", ",", "$", "array", "[", "$", "i", "]", "]", ";", "}", "return", "$", "array", ";", "}" ]
Shuffle an array ensuring no item remains in the same position. @usage __::randomize([1, 2, 3]); >> [2, 3, 1] @param array $array original array @return array
[ "Shuffle", "an", "array", "ensuring", "no", "item", "remains", "in", "the", "same", "position", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L251-L259
38,167
me-io/php-lodash
src/Traits/Arrays.php
Arrays.intersection
public static function intersection(array $a, array $b): array { $a = (array)$a; $b = (array)$b; return array_values(array_intersect($a, $b)); }
php
public static function intersection(array $a, array $b): array { $a = (array)$a; $b = (array)$b; return array_values(array_intersect($a, $b)); }
[ "public", "static", "function", "intersection", "(", "array", "$", "a", ",", "array", "$", "b", ")", ":", "array", "{", "$", "a", "=", "(", "array", ")", "$", "a", ";", "$", "b", "=", "(", "array", ")", "$", "b", ";", "return", "array_values", "(", "array_intersect", "(", "$", "a", ",", "$", "b", ")", ")", ";", "}" ]
Return an array with all elements found in both input arrays. @usage __::intersection(["green", "red", "blue"], ["green", "yellow", "red"]) >> ["green", "red"] @param array $a @param array $b @return array
[ "Return", "an", "array", "with", "all", "elements", "found", "in", "both", "input", "arrays", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L374-L380
38,168
me-io/php-lodash
src/Traits/Arrays.php
Arrays.intersects
public static function intersects(array $a, array $b): bool { $a = (array)$a; $b = (array)$b; return count(self::intersection($a, $b)) > 0; }
php
public static function intersects(array $a, array $b): bool { $a = (array)$a; $b = (array)$b; return count(self::intersection($a, $b)) > 0; }
[ "public", "static", "function", "intersects", "(", "array", "$", "a", ",", "array", "$", "b", ")", ":", "bool", "{", "$", "a", "=", "(", "array", ")", "$", "a", ";", "$", "b", "=", "(", "array", ")", "$", "b", ";", "return", "count", "(", "self", "::", "intersection", "(", "$", "a", ",", "$", "b", ")", ")", ">", "0", ";", "}" ]
Return a boolean flag which indicates whether the two input arrays have any common elements. @usage __::intersects(["green", "red", "blue"], ["green", "yellow", "red"]) >> true @param array $a @param array $b @return bool
[ "Return", "a", "boolean", "flag", "which", "indicates", "whether", "the", "two", "input", "arrays", "have", "any", "common", "elements", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L393-L399
38,169
me-io/php-lodash
src/Traits/Arrays.php
Arrays.sortKeys
public static function sortKeys(array $array, string $direction = 'ASC') { $direction = (strtolower($direction) === 'desc') ? SORT_DESC : SORT_ASC; if ($direction === SORT_ASC) { ksort($array); } else { krsort($array); } return $array; }
php
public static function sortKeys(array $array, string $direction = 'ASC') { $direction = (strtolower($direction) === 'desc') ? SORT_DESC : SORT_ASC; if ($direction === SORT_ASC) { ksort($array); } else { krsort($array); } return $array; }
[ "public", "static", "function", "sortKeys", "(", "array", "$", "array", ",", "string", "$", "direction", "=", "'ASC'", ")", "{", "$", "direction", "=", "(", "strtolower", "(", "$", "direction", ")", "===", "'desc'", ")", "?", "SORT_DESC", ":", "SORT_ASC", ";", "if", "(", "$", "direction", "===", "SORT_ASC", ")", "{", "ksort", "(", "$", "array", ")", ";", "}", "else", "{", "krsort", "(", "$", "array", ")", ";", "}", "return", "$", "array", ";", "}" ]
Sort an array by key. @usage __::sortKeys(['z' => 0, 'b' => 1, 'r' => 2]) >> ['b' => 1, 'r' => 2, 'z' => 0] @param array $array @param string $direction @return mixed
[ "Sort", "an", "array", "by", "key", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L446-L456
38,170
me-io/php-lodash
src/Traits/Arrays.php
Arrays.without
public static function without(array $array, $remove, $preserveKeys = false): array { $remove = !is_array($remove) ? [$remove] : $remove; $result = []; foreach ($array as $key => $value) { if (in_array($value, $remove)) { continue; } if ($preserveKeys) { $result[$key] = $value; } else { $result[] = $value; } } return $result; }
php
public static function without(array $array, $remove, $preserveKeys = false): array { $remove = !is_array($remove) ? [$remove] : $remove; $result = []; foreach ($array as $key => $value) { if (in_array($value, $remove)) { continue; } if ($preserveKeys) { $result[$key] = $value; } else { $result[] = $value; } } return $result; }
[ "public", "static", "function", "without", "(", "array", "$", "array", ",", "$", "remove", ",", "$", "preserveKeys", "=", "false", ")", ":", "array", "{", "$", "remove", "=", "!", "is_array", "(", "$", "remove", ")", "?", "[", "$", "remove", "]", ":", "$", "remove", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "value", ",", "$", "remove", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "preserveKeys", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}" ]
Remove unwanted values from array @param array $array @param array|string $remove @param bool $preserveKeys , set true if you want to preserve the keys. by default false @usage _::without([1,5=>3,2 => 4,5],2) @return array
[ "Remove", "unwanted", "values", "from", "array" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Arrays.php#L469-L486
38,171
me-io/php-lodash
src/Traits/Functions.php
Functions.urlify
public static function urlify(string $string) { /* Proposed by: * Søren Løvborg * http://stackoverflow.com/users/136796/soren-lovborg * http://stackoverflow.com/questions/17900004/turn-plain-text-urls-into-active-links-using-php/17900021#17900021 */ $rexProtocol = '(https?://)?'; $rexDomain = '((?:[-a-zA-Z0-9]{1,63}\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\.){3}[0-9]{1,3})'; $rexPort = '(:[0-9]{1,5})?'; $rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?'; $rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; return preg_replace_callback( "&\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))&", function ($match) { $completeUrl = $match[1] ? $match[0] : "http://{$match[0]}"; return '<a href="' . $completeUrl . '">' . $match[2] . $match[3] . $match[4] . '</a>'; }, htmlspecialchars($string) ); }
php
public static function urlify(string $string) { /* Proposed by: * Søren Løvborg * http://stackoverflow.com/users/136796/soren-lovborg * http://stackoverflow.com/questions/17900004/turn-plain-text-urls-into-active-links-using-php/17900021#17900021 */ $rexProtocol = '(https?://)?'; $rexDomain = '((?:[-a-zA-Z0-9]{1,63}\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\.){3}[0-9]{1,3})'; $rexPort = '(:[0-9]{1,5})?'; $rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?'; $rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; return preg_replace_callback( "&\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))&", function ($match) { $completeUrl = $match[1] ? $match[0] : "http://{$match[0]}"; return '<a href="' . $completeUrl . '">' . $match[2] . $match[3] . $match[4] . '</a>'; }, htmlspecialchars($string) ); }
[ "public", "static", "function", "urlify", "(", "string", "$", "string", ")", "{", "/* Proposed by:\n * Søren Løvborg\n * http://stackoverflow.com/users/136796/soren-lovborg\n * http://stackoverflow.com/questions/17900004/turn-plain-text-urls-into-active-links-using-php/17900021#17900021\n */", "$", "rexProtocol", "=", "'(https?://)?'", ";", "$", "rexDomain", "=", "'((?:[-a-zA-Z0-9]{1,63}\\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\\.){3}[0-9]{1,3})'", ";", "$", "rexPort", "=", "'(:[0-9]{1,5})?'", ";", "$", "rexPath", "=", "'(/[!$-/0-9:;=@_\\':;!a-zA-Z\\x7f-\\xff]*?)?'", ";", "$", "rexQuery", "=", "'(\\?[!$-/0-9:;=@_\\':;!a-zA-Z\\x7f-\\xff]+?)?'", ";", "$", "rexFragment", "=", "'(#[!$-/0-9:;=@_\\':;!a-zA-Z\\x7f-\\xff]+?)?'", ";", "return", "preg_replace_callback", "(", "\"&\\\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\\\"]?(\\s|$))&\"", ",", "function", "(", "$", "match", ")", "{", "$", "completeUrl", "=", "$", "match", "[", "1", "]", "?", "$", "match", "[", "0", "]", ":", "\"http://{$match[0]}\"", ";", "return", "'<a href=\"'", ".", "$", "completeUrl", ".", "'\">'", ".", "$", "match", "[", "2", "]", ".", "$", "match", "[", "3", "]", ".", "$", "match", "[", "4", "]", ".", "'</a>'", ";", "}", ",", "htmlspecialchars", "(", "$", "string", ")", ")", ";", "}" ]
Find the urls inside a string a put them inside anchor tags. @usage __::urlify("I love https://google.com"); >> 'I love <a href="https://google.com">google.com</a>' @param string $string @return string|mixed
[ "Find", "the", "urls", "inside", "a", "string", "a", "put", "them", "inside", "anchor", "tags", "." ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Functions.php#L372-L396
38,172
me-io/php-lodash
src/Traits/Functions.php
Functions.truncate
public static function truncate(string $text, int $limit = 40): string { if (str_word_count($text, 0) > $limit) { $words = (array)str_word_count($text, 2); $pos = array_keys($words); $text = mb_substr($text, 0, $pos[$limit], 'UTF-8') . '...'; } return $text; }
php
public static function truncate(string $text, int $limit = 40): string { if (str_word_count($text, 0) > $limit) { $words = (array)str_word_count($text, 2); $pos = array_keys($words); $text = mb_substr($text, 0, $pos[$limit], 'UTF-8') . '...'; } return $text; }
[ "public", "static", "function", "truncate", "(", "string", "$", "text", ",", "int", "$", "limit", "=", "40", ")", ":", "string", "{", "if", "(", "str_word_count", "(", "$", "text", ",", "0", ")", ">", "$", "limit", ")", "{", "$", "words", "=", "(", "array", ")", "str_word_count", "(", "$", "text", ",", "2", ")", ";", "$", "pos", "=", "array_keys", "(", "$", "words", ")", ";", "$", "text", "=", "mb_substr", "(", "$", "text", ",", "0", ",", "$", "pos", "[", "$", "limit", "]", ",", "'UTF-8'", ")", ".", "'...'", ";", "}", "return", "$", "text", ";", "}" ]
Truncate string based on count of words @usage $string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et mi orci.'; __::truncate($string); >> 'Lorem ipsum dolor sit amet, consectetur...' @param string $text text to truncate @param integer $limit limit of words @return string
[ "Truncate", "string", "based", "on", "count", "of", "words" ]
b91c31fe4a03f85d21923b56a8bb45bcd857fdda
https://github.com/me-io/php-lodash/blob/b91c31fe4a03f85d21923b56a8bb45bcd857fdda/src/Traits/Functions.php#L411-L420
38,173
cmpayments/iban
src/lib/IBAN.php
IBAN.validate
public function validate(&$error = null) { if (!$this->isCountryCodeValid()) { $error = 'IBAN country code not valid or not supported'; } elseif (!$this->isLengthValid()) { $error = 'IBAN length is invalid'; } elseif (!$this->isFormatValid()) { $error = 'IBAN format is invalid'; } elseif (!$this->isChecksumValid()) { $error = 'IBAN checksum is invalid'; } else { $error = ''; return true; } return false; }
php
public function validate(&$error = null) { if (!$this->isCountryCodeValid()) { $error = 'IBAN country code not valid or not supported'; } elseif (!$this->isLengthValid()) { $error = 'IBAN length is invalid'; } elseif (!$this->isFormatValid()) { $error = 'IBAN format is invalid'; } elseif (!$this->isChecksumValid()) { $error = 'IBAN checksum is invalid'; } else { $error = ''; return true; } return false; }
[ "public", "function", "validate", "(", "&", "$", "error", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "isCountryCodeValid", "(", ")", ")", "{", "$", "error", "=", "'IBAN country code not valid or not supported'", ";", "}", "elseif", "(", "!", "$", "this", "->", "isLengthValid", "(", ")", ")", "{", "$", "error", "=", "'IBAN length is invalid'", ";", "}", "elseif", "(", "!", "$", "this", "->", "isFormatValid", "(", ")", ")", "{", "$", "error", "=", "'IBAN format is invalid'", ";", "}", "elseif", "(", "!", "$", "this", "->", "isChecksumValid", "(", ")", ")", "{", "$", "error", "=", "'IBAN checksum is invalid'", ";", "}", "else", "{", "$", "error", "=", "''", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Validates the supplied IBAN and provides passthrough failure message when validation fails @param null $error passthrough variable @return bool
[ "Validates", "the", "supplied", "IBAN", "and", "provides", "passthrough", "failure", "message", "when", "validation", "fails" ]
f3666e58a00f166e43eafc46a9b502ad971ca954
https://github.com/cmpayments/iban/blob/f3666e58a00f166e43eafc46a9b502ad971ca954/src/lib/IBAN.php#L159-L175
38,174
cmpayments/iban
src/lib/IBAN.php
IBAN.format
public function format() { return sprintf( '%s %s %s', $this->getCountryCode() . $this->getChecksum(), substr($this->getInstituteIdentification(), 0, 4), implode(' ', str_split($this->getBankAccountNumber(), 4)) ); }
php
public function format() { return sprintf( '%s %s %s', $this->getCountryCode() . $this->getChecksum(), substr($this->getInstituteIdentification(), 0, 4), implode(' ', str_split($this->getBankAccountNumber(), 4)) ); }
[ "public", "function", "format", "(", ")", "{", "return", "sprintf", "(", "'%s %s %s'", ",", "$", "this", "->", "getCountryCode", "(", ")", ".", "$", "this", "->", "getChecksum", "(", ")", ",", "substr", "(", "$", "this", "->", "getInstituteIdentification", "(", ")", ",", "0", ",", "4", ")", ",", "implode", "(", "' '", ",", "str_split", "(", "$", "this", "->", "getBankAccountNumber", "(", ")", ",", "4", ")", ")", ")", ";", "}" ]
Pretty print IBAN @return string
[ "Pretty", "print", "IBAN" ]
f3666e58a00f166e43eafc46a9b502ad971ca954
https://github.com/cmpayments/iban/blob/f3666e58a00f166e43eafc46a9b502ad971ca954/src/lib/IBAN.php#L182-L190
38,175
cmpayments/iban
src/lib/IBAN.php
IBAN.getBankAccountNumber
public function getBankAccountNumber() { $countryCode = $this->getCountryCode(); $length = static::$ibanFormatMap[$countryCode][0] - static::INSTITUTE_IDENTIFICATION_LENGTH; return substr($this->iban, static::BANK_ACCOUNT_NUMBER_OFFSET, $length); }
php
public function getBankAccountNumber() { $countryCode = $this->getCountryCode(); $length = static::$ibanFormatMap[$countryCode][0] - static::INSTITUTE_IDENTIFICATION_LENGTH; return substr($this->iban, static::BANK_ACCOUNT_NUMBER_OFFSET, $length); }
[ "public", "function", "getBankAccountNumber", "(", ")", "{", "$", "countryCode", "=", "$", "this", "->", "getCountryCode", "(", ")", ";", "$", "length", "=", "static", "::", "$", "ibanFormatMap", "[", "$", "countryCode", "]", "[", "0", "]", "-", "static", "::", "INSTITUTE_IDENTIFICATION_LENGTH", ";", "return", "substr", "(", "$", "this", "->", "iban", ",", "static", "::", "BANK_ACCOUNT_NUMBER_OFFSET", ",", "$", "length", ")", ";", "}" ]
Extract Bank Account number from IBAN @return string
[ "Extract", "Bank", "Account", "number", "from", "IBAN" ]
f3666e58a00f166e43eafc46a9b502ad971ca954
https://github.com/cmpayments/iban/blob/f3666e58a00f166e43eafc46a9b502ad971ca954/src/lib/IBAN.php#L237-L242
38,176
cmpayments/iban
src/lib/IBAN.php
IBAN.isLengthValid
private function isLengthValid() { $countryCode = $this->getCountryCode(); $validLength = static::COUNTRY_CODE_LENGTH + static::CHECKSUM_LENGTH + static::$ibanFormatMap[$countryCode][0]; return strlen($this->iban) === $validLength; }
php
private function isLengthValid() { $countryCode = $this->getCountryCode(); $validLength = static::COUNTRY_CODE_LENGTH + static::CHECKSUM_LENGTH + static::$ibanFormatMap[$countryCode][0]; return strlen($this->iban) === $validLength; }
[ "private", "function", "isLengthValid", "(", ")", "{", "$", "countryCode", "=", "$", "this", "->", "getCountryCode", "(", ")", ";", "$", "validLength", "=", "static", "::", "COUNTRY_CODE_LENGTH", "+", "static", "::", "CHECKSUM_LENGTH", "+", "static", "::", "$", "ibanFormatMap", "[", "$", "countryCode", "]", "[", "0", "]", ";", "return", "strlen", "(", "$", "this", "->", "iban", ")", "===", "$", "validLength", ";", "}" ]
Validate IBAN length boundaries @return bool
[ "Validate", "IBAN", "length", "boundaries" ]
f3666e58a00f166e43eafc46a9b502ad971ca954
https://github.com/cmpayments/iban/blob/f3666e58a00f166e43eafc46a9b502ad971ca954/src/lib/IBAN.php#L249-L255
38,177
cmpayments/iban
src/lib/IBAN.php
IBAN.isFormatValid
private function isFormatValid() { $countryCode = $this->getCountryCode(); $accountIdentification = $this->getAccountIdentification(); return !(preg_match('/' . static::$ibanFormatMap[$countryCode][1] . '/', $accountIdentification) !== 1); }
php
private function isFormatValid() { $countryCode = $this->getCountryCode(); $accountIdentification = $this->getAccountIdentification(); return !(preg_match('/' . static::$ibanFormatMap[$countryCode][1] . '/', $accountIdentification) !== 1); }
[ "private", "function", "isFormatValid", "(", ")", "{", "$", "countryCode", "=", "$", "this", "->", "getCountryCode", "(", ")", ";", "$", "accountIdentification", "=", "$", "this", "->", "getAccountIdentification", "(", ")", ";", "return", "!", "(", "preg_match", "(", "'/'", ".", "static", "::", "$", "ibanFormatMap", "[", "$", "countryCode", "]", "[", "1", "]", ".", "'/'", ",", "$", "accountIdentification", ")", "!==", "1", ")", ";", "}" ]
Validate the IBAN format according to the country code @return bool
[ "Validate", "the", "IBAN", "format", "according", "to", "the", "country", "code" ]
f3666e58a00f166e43eafc46a9b502ad971ca954
https://github.com/cmpayments/iban/blob/f3666e58a00f166e43eafc46a9b502ad971ca954/src/lib/IBAN.php#L274-L280
38,178
cmpayments/iban
src/lib/IBAN.php
IBAN.isChecksumValid
private function isChecksumValid() { $countryCode = $this->getCountryCode(); $checksum = $this->getChecksum(); $accountIdentification = $this->getAccountIdentification(); $numericCountryCode = $this->getNumericCountryCode($countryCode); $numericAccountIdentification = $this->getNumericAccountIdentification($accountIdentification); $invertedIban = $numericAccountIdentification . $numericCountryCode . $checksum; return $this->bcmod($invertedIban, 97) === '1'; }
php
private function isChecksumValid() { $countryCode = $this->getCountryCode(); $checksum = $this->getChecksum(); $accountIdentification = $this->getAccountIdentification(); $numericCountryCode = $this->getNumericCountryCode($countryCode); $numericAccountIdentification = $this->getNumericAccountIdentification($accountIdentification); $invertedIban = $numericAccountIdentification . $numericCountryCode . $checksum; return $this->bcmod($invertedIban, 97) === '1'; }
[ "private", "function", "isChecksumValid", "(", ")", "{", "$", "countryCode", "=", "$", "this", "->", "getCountryCode", "(", ")", ";", "$", "checksum", "=", "$", "this", "->", "getChecksum", "(", ")", ";", "$", "accountIdentification", "=", "$", "this", "->", "getAccountIdentification", "(", ")", ";", "$", "numericCountryCode", "=", "$", "this", "->", "getNumericCountryCode", "(", "$", "countryCode", ")", ";", "$", "numericAccountIdentification", "=", "$", "this", "->", "getNumericAccountIdentification", "(", "$", "accountIdentification", ")", ";", "$", "invertedIban", "=", "$", "numericAccountIdentification", ".", "$", "numericCountryCode", ".", "$", "checksum", ";", "return", "$", "this", "->", "bcmod", "(", "$", "invertedIban", ",", "97", ")", "===", "'1'", ";", "}" ]
Validates if the checksum number is valid according to the IBAN @return bool
[ "Validates", "if", "the", "checksum", "number", "is", "valid", "according", "to", "the", "IBAN" ]
f3666e58a00f166e43eafc46a9b502ad971ca954
https://github.com/cmpayments/iban/blob/f3666e58a00f166e43eafc46a9b502ad971ca954/src/lib/IBAN.php#L287-L297
38,179
cmpayments/iban
src/lib/IBAN.php
IBAN.getNumericRepresentation
private function getNumericRepresentation($letterRepresentation) { $numericRepresentation = ''; foreach (str_split($letterRepresentation) as $char) { $ord = ord($char); if ($ord >= 65 && $ord <= 90) { $numericRepresentation .= (string) ($ord - 55); } elseif ($ord >= 48 && $ord <= 57) { $numericRepresentation .= (string) ($ord - 48); } } return $numericRepresentation; }
php
private function getNumericRepresentation($letterRepresentation) { $numericRepresentation = ''; foreach (str_split($letterRepresentation) as $char) { $ord = ord($char); if ($ord >= 65 && $ord <= 90) { $numericRepresentation .= (string) ($ord - 55); } elseif ($ord >= 48 && $ord <= 57) { $numericRepresentation .= (string) ($ord - 48); } } return $numericRepresentation; }
[ "private", "function", "getNumericRepresentation", "(", "$", "letterRepresentation", ")", "{", "$", "numericRepresentation", "=", "''", ";", "foreach", "(", "str_split", "(", "$", "letterRepresentation", ")", "as", "$", "char", ")", "{", "$", "ord", "=", "ord", "(", "$", "char", ")", ";", "if", "(", "$", "ord", ">=", "65", "&&", "$", "ord", "<=", "90", ")", "{", "$", "numericRepresentation", ".=", "(", "string", ")", "(", "$", "ord", "-", "55", ")", ";", "}", "elseif", "(", "$", "ord", ">=", "48", "&&", "$", "ord", "<=", "57", ")", "{", "$", "numericRepresentation", ".=", "(", "string", ")", "(", "$", "ord", "-", "48", ")", ";", "}", "}", "return", "$", "numericRepresentation", ";", "}" ]
Retrieve numeric presentation of a letter part of the IBAN @param $letterRepresentation @return string
[ "Retrieve", "numeric", "presentation", "of", "a", "letter", "part", "of", "the", "IBAN" ]
f3666e58a00f166e43eafc46a9b502ad971ca954
https://github.com/cmpayments/iban/blob/f3666e58a00f166e43eafc46a9b502ad971ca954/src/lib/IBAN.php#L330-L344
38,180
philiplb/CRUDlex
src/CRUDlex/FileHandler.php
FileHandler.getPath
protected function getPath($entityName, Entity $entity, $field) { return $this->entityDefinition->getField($field, 'path').'/'.$entityName.'/'.$entity->get('id').'/'.$field; }
php
protected function getPath($entityName, Entity $entity, $field) { return $this->entityDefinition->getField($field, 'path').'/'.$entityName.'/'.$entity->get('id').'/'.$field; }
[ "protected", "function", "getPath", "(", "$", "entityName", ",", "Entity", "$", "entity", ",", "$", "field", ")", "{", "return", "$", "this", "->", "entityDefinition", "->", "getField", "(", "$", "field", ",", "'path'", ")", ".", "'/'", ".", "$", "entityName", ".", "'/'", ".", "$", "entity", "->", "get", "(", "'id'", ")", ".", "'/'", ".", "$", "field", ";", "}" ]
Constructs a file system path for the given parameters for storing the file of the file field. @param string $entityName the entity name @param Entity $entity the entity @param string $field the file field in the entity @return string the constructed path for storing the file of the file field
[ "Constructs", "a", "file", "system", "path", "for", "the", "given", "parameters", "for", "storing", "the", "file", "of", "the", "file", "field", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/FileHandler.php#L50-L53
38,181
philiplb/CRUDlex
src/CRUDlex/FileHandler.php
FileHandler.performOnFiles
protected function performOnFiles(Entity $entity, $entityName, $function) { $fields = $this->entityDefinition->getEditableFieldNames(); foreach ($fields as $field) { if ($this->entityDefinition->getType($field) == 'file') { $function($entity, $entityName, $field); } } }
php
protected function performOnFiles(Entity $entity, $entityName, $function) { $fields = $this->entityDefinition->getEditableFieldNames(); foreach ($fields as $field) { if ($this->entityDefinition->getType($field) == 'file') { $function($entity, $entityName, $field); } } }
[ "protected", "function", "performOnFiles", "(", "Entity", "$", "entity", ",", "$", "entityName", ",", "$", "function", ")", "{", "$", "fields", "=", "$", "this", "->", "entityDefinition", "->", "getEditableFieldNames", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "$", "this", "->", "entityDefinition", "->", "getType", "(", "$", "field", ")", "==", "'file'", ")", "{", "$", "function", "(", "$", "entity", ",", "$", "entityName", ",", "$", "field", ")", ";", "}", "}", "}" ]
Executes a function for each file field of this entity. @param Entity $entity the just created entity @param string $entityName the name of the entity as this class here is not aware of it @param \Closure $function the function to perform, takes $entity, $entityName and $field as parameter
[ "Executes", "a", "function", "for", "each", "file", "field", "of", "this", "entity", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/FileHandler.php#L65-L73
38,182
philiplb/CRUDlex
src/CRUDlex/FileHandler.php
FileHandler.shouldWriteFile
protected function shouldWriteFile(AbstractData $data, Request $request, Entity $entity, $entityName, $action) { $result = $data->getEvents()->shouldExecute($entity, 'before', $action); if (!$result) { return false; } $filesystem = $this->filesystem; $this->performOnFiles($entity, $entityName, function($entity, $entityName, $field) use ($filesystem, $request) { $file = $request->files->get($field); if ($file !== null && $file->isValid()) { $path = $this->getPath($entityName, $entity, $field); $filename = $path.'/'.$file->getClientOriginalName(); if ($filesystem->has($filename)) { $filesystem->delete($filename); } $stream = fopen($file->getRealPath(), 'r+'); $filesystem->writeStream($filename, $stream); fclose($stream); } }); $data->getEvents()->shouldExecute($entity, 'after', $action); return true; }
php
protected function shouldWriteFile(AbstractData $data, Request $request, Entity $entity, $entityName, $action) { $result = $data->getEvents()->shouldExecute($entity, 'before', $action); if (!$result) { return false; } $filesystem = $this->filesystem; $this->performOnFiles($entity, $entityName, function($entity, $entityName, $field) use ($filesystem, $request) { $file = $request->files->get($field); if ($file !== null && $file->isValid()) { $path = $this->getPath($entityName, $entity, $field); $filename = $path.'/'.$file->getClientOriginalName(); if ($filesystem->has($filename)) { $filesystem->delete($filename); } $stream = fopen($file->getRealPath(), 'r+'); $filesystem->writeStream($filename, $stream); fclose($stream); } }); $data->getEvents()->shouldExecute($entity, 'after', $action); return true; }
[ "protected", "function", "shouldWriteFile", "(", "AbstractData", "$", "data", ",", "Request", "$", "request", ",", "Entity", "$", "entity", ",", "$", "entityName", ",", "$", "action", ")", "{", "$", "result", "=", "$", "data", "->", "getEvents", "(", ")", "->", "shouldExecute", "(", "$", "entity", ",", "'before'", ",", "$", "action", ")", ";", "if", "(", "!", "$", "result", ")", "{", "return", "false", ";", "}", "$", "filesystem", "=", "$", "this", "->", "filesystem", ";", "$", "this", "->", "performOnFiles", "(", "$", "entity", ",", "$", "entityName", ",", "function", "(", "$", "entity", ",", "$", "entityName", ",", "$", "field", ")", "use", "(", "$", "filesystem", ",", "$", "request", ")", "{", "$", "file", "=", "$", "request", "->", "files", "->", "get", "(", "$", "field", ")", ";", "if", "(", "$", "file", "!==", "null", "&&", "$", "file", "->", "isValid", "(", ")", ")", "{", "$", "path", "=", "$", "this", "->", "getPath", "(", "$", "entityName", ",", "$", "entity", ",", "$", "field", ")", ";", "$", "filename", "=", "$", "path", ".", "'/'", ".", "$", "file", "->", "getClientOriginalName", "(", ")", ";", "if", "(", "$", "filesystem", "->", "has", "(", "$", "filename", ")", ")", "{", "$", "filesystem", "->", "delete", "(", "$", "filename", ")", ";", "}", "$", "stream", "=", "fopen", "(", "$", "file", "->", "getRealPath", "(", ")", ",", "'r+'", ")", ";", "$", "filesystem", "->", "writeStream", "(", "$", "filename", ",", "$", "stream", ")", ";", "fclose", "(", "$", "stream", ")", ";", "}", "}", ")", ";", "$", "data", "->", "getEvents", "(", ")", "->", "shouldExecute", "(", "$", "entity", ",", "'after'", ",", "$", "action", ")", ";", "return", "true", ";", "}" ]
Writes the uploaded files. @param AbstractData $data the AbstractData instance who should receive the events @param Request $request the HTTP request containing the file data @param Entity $entity the just manipulated entity @param string $entityName the name of the entity as this class here is not aware of it @param string $action the name of the performed action @return boolean true if all before events passed
[ "Writes", "the", "uploaded", "files", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/FileHandler.php#L92-L114
38,183
philiplb/CRUDlex
src/CRUDlex/FileHandler.php
FileHandler.deleteFiles
public function deleteFiles(AbstractData $data, Entity $entity, $entityName) { $result = $data->getEvents()->shouldExecute($entity, 'before', 'deleteFiles'); if (!$result) { return false; } $this->performOnFiles($entity, $entityName, function($entity, $entityName, $field) { // For now, we are defensive and don't delete ever. As soon as soft deletion is optional, files will get deleted. }); $data->getEvents()->shouldExecute($entity, 'after', 'deleteFiles'); return true; }
php
public function deleteFiles(AbstractData $data, Entity $entity, $entityName) { $result = $data->getEvents()->shouldExecute($entity, 'before', 'deleteFiles'); if (!$result) { return false; } $this->performOnFiles($entity, $entityName, function($entity, $entityName, $field) { // For now, we are defensive and don't delete ever. As soon as soft deletion is optional, files will get deleted. }); $data->getEvents()->shouldExecute($entity, 'after', 'deleteFiles'); return true; }
[ "public", "function", "deleteFiles", "(", "AbstractData", "$", "data", ",", "Entity", "$", "entity", ",", "$", "entityName", ")", "{", "$", "result", "=", "$", "data", "->", "getEvents", "(", ")", "->", "shouldExecute", "(", "$", "entity", ",", "'before'", ",", "'deleteFiles'", ")", ";", "if", "(", "!", "$", "result", ")", "{", "return", "false", ";", "}", "$", "this", "->", "performOnFiles", "(", "$", "entity", ",", "$", "entityName", ",", "function", "(", "$", "entity", ",", "$", "entityName", ",", "$", "field", ")", "{", "// For now, we are defensive and don't delete ever. As soon as soft deletion is optional, files will get deleted.", "}", ")", ";", "$", "data", "->", "getEvents", "(", ")", "->", "shouldExecute", "(", "$", "entity", ",", "'after'", ",", "'deleteFiles'", ")", ";", "return", "true", ";", "}" ]
Deletes all files of an existing entity. @param AbstractData $data the AbstractData instance who should receive the events @param Entity $entity the entity to delete the files from @param string $entityName the name of the entity as this class here is not aware of it @return boolean true on successful deletion
[ "Deletes", "all", "files", "of", "an", "existing", "entity", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/FileHandler.php#L181-L192
38,184
philiplb/CRUDlex
src/CRUDlex/FileHandler.php
FileHandler.deleteFile
public function deleteFile(AbstractData $data, Entity $entity, $entityName, $field) { $result = $data->getEvents()->shouldExecute($entity, 'before', 'deleteFile'); if (!$result) { return false; } // For now, we are defensive and don't delete ever. As soon as soft deletion is optional, files will get deleted. $data->getEvents()->shouldExecute($entity, 'after', 'deleteFile'); return true; }
php
public function deleteFile(AbstractData $data, Entity $entity, $entityName, $field) { $result = $data->getEvents()->shouldExecute($entity, 'before', 'deleteFile'); if (!$result) { return false; } // For now, we are defensive and don't delete ever. As soon as soft deletion is optional, files will get deleted. $data->getEvents()->shouldExecute($entity, 'after', 'deleteFile'); return true; }
[ "public", "function", "deleteFile", "(", "AbstractData", "$", "data", ",", "Entity", "$", "entity", ",", "$", "entityName", ",", "$", "field", ")", "{", "$", "result", "=", "$", "data", "->", "getEvents", "(", ")", "->", "shouldExecute", "(", "$", "entity", ",", "'before'", ",", "'deleteFile'", ")", ";", "if", "(", "!", "$", "result", ")", "{", "return", "false", ";", "}", "// For now, we are defensive and don't delete ever. As soon as soft deletion is optional, files will get deleted.", "$", "data", "->", "getEvents", "(", ")", "->", "shouldExecute", "(", "$", "entity", ",", "'after'", ",", "'deleteFile'", ")", ";", "return", "true", ";", "}" ]
Deletes a specific file from an existing entity. @param AbstractData $data the AbstractData instance who should receive the events @param Entity $entity the entity to delete the file from @param string $entityName the name of the entity as this class here is not aware of it @param string $field the field of the entity containing the file to be deleted @return bool true on successful deletion true on successful deletion
[ "Deletes", "a", "specific", "file", "from", "an", "existing", "entity", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/FileHandler.php#L208-L217
38,185
philiplb/CRUDlex
src/CRUDlex/FileHandler.php
FileHandler.updateFiles
public function updateFiles(AbstractData $data, Request $request, Entity $entity, $entityName) { // With optional soft deletion, the file should be deleted first. return $this->shouldWriteFile($data, $request, $entity, $entityName, 'updateFiles'); }
php
public function updateFiles(AbstractData $data, Request $request, Entity $entity, $entityName) { // With optional soft deletion, the file should be deleted first. return $this->shouldWriteFile($data, $request, $entity, $entityName, 'updateFiles'); }
[ "public", "function", "updateFiles", "(", "AbstractData", "$", "data", ",", "Request", "$", "request", ",", "Entity", "$", "entity", ",", "$", "entityName", ")", "{", "// With optional soft deletion, the file should be deleted first.", "return", "$", "this", "->", "shouldWriteFile", "(", "$", "data", ",", "$", "request", ",", "$", "entity", ",", "$", "entityName", ",", "'updateFiles'", ")", ";", "}" ]
Updates the uploaded files of an updated entity. @param AbstractData $data the AbstractData instance who should receive the events @param Request $request the HTTP request containing the file data @param Entity $entity the updated entity @param string $entityName the name of the entity as this class here is not aware of it @return boolean true on successful update
[ "Updates", "the", "uploaded", "files", "of", "an", "updated", "entity", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/FileHandler.php#L254-L258
38,186
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.getLocales
public static function getLocales() { $localeDir = __DIR__.'/../locales'; $languageFiles = scandir($localeDir); $locales = []; foreach ($languageFiles as $languageFile) { if (in_array($languageFile, ['.', '..'])) { continue; } $extensionPos = strpos($languageFile, '.yml'); if ($extensionPos !== false) { $locale = substr($languageFile, 0, $extensionPos); $locales[] = $locale; } } sort($locales); return $locales; }
php
public static function getLocales() { $localeDir = __DIR__.'/../locales'; $languageFiles = scandir($localeDir); $locales = []; foreach ($languageFiles as $languageFile) { if (in_array($languageFile, ['.', '..'])) { continue; } $extensionPos = strpos($languageFile, '.yml'); if ($extensionPos !== false) { $locale = substr($languageFile, 0, $extensionPos); $locales[] = $locale; } } sort($locales); return $locales; }
[ "public", "static", "function", "getLocales", "(", ")", "{", "$", "localeDir", "=", "__DIR__", ".", "'/../locales'", ";", "$", "languageFiles", "=", "scandir", "(", "$", "localeDir", ")", ";", "$", "locales", "=", "[", "]", ";", "foreach", "(", "$", "languageFiles", "as", "$", "languageFile", ")", "{", "if", "(", "in_array", "(", "$", "languageFile", ",", "[", "'.'", ",", "'..'", "]", ")", ")", "{", "continue", ";", "}", "$", "extensionPos", "=", "strpos", "(", "$", "languageFile", ",", "'.yml'", ")", ";", "if", "(", "$", "extensionPos", "!==", "false", ")", "{", "$", "locale", "=", "substr", "(", "$", "languageFile", ",", "0", ",", "$", "extensionPos", ")", ";", "$", "locales", "[", "]", "=", "$", "locale", ";", "}", "}", "sort", "(", "$", "locales", ")", ";", "return", "$", "locales", ";", "}" ]
Gets the available locales. @return array the available locales
[ "Gets", "the", "available", "locales", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L57-L74
38,187
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.initChildren
protected function initChildren() { foreach ($this->datas as $name => $data) { $fields = $data->getDefinition()->getFieldNames(); foreach ($fields as $field) { if ($data->getDefinition()->getType($field) == 'reference') { $this->datas[$data->getDefinition()->getSubTypeField($field, 'reference', 'entity')]->getDefinition()->addChild($data->getDefinition()->getTable(), $field, $name); } } } }
php
protected function initChildren() { foreach ($this->datas as $name => $data) { $fields = $data->getDefinition()->getFieldNames(); foreach ($fields as $field) { if ($data->getDefinition()->getType($field) == 'reference') { $this->datas[$data->getDefinition()->getSubTypeField($field, 'reference', 'entity')]->getDefinition()->addChild($data->getDefinition()->getTable(), $field, $name); } } } }
[ "protected", "function", "initChildren", "(", ")", "{", "foreach", "(", "$", "this", "->", "datas", "as", "$", "name", "=>", "$", "data", ")", "{", "$", "fields", "=", "$", "data", "->", "getDefinition", "(", ")", "->", "getFieldNames", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "$", "data", "->", "getDefinition", "(", ")", "->", "getType", "(", "$", "field", ")", "==", "'reference'", ")", "{", "$", "this", "->", "datas", "[", "$", "data", "->", "getDefinition", "(", ")", "->", "getSubTypeField", "(", "$", "field", ",", "'reference'", ",", "'entity'", ")", "]", "->", "getDefinition", "(", ")", "->", "addChild", "(", "$", "data", "->", "getDefinition", "(", ")", "->", "getTable", "(", ")", ",", "$", "field", ",", "$", "name", ")", ";", "}", "}", "}", "}" ]
Initializes the children of the data entries.
[ "Initializes", "the", "children", "of", "the", "data", "entries", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L79-L89
38,188
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.getLocaleLabels
protected function getLocaleLabels(array $crud) { $locales = $this->getLocales(); $localeLabels = []; foreach ($locales as $locale) { if (array_key_exists('label_'.$locale, $crud)) { $localeLabels[$locale] = $crud['label_'.$locale]; } } return $localeLabels; }
php
protected function getLocaleLabels(array $crud) { $locales = $this->getLocales(); $localeLabels = []; foreach ($locales as $locale) { if (array_key_exists('label_'.$locale, $crud)) { $localeLabels[$locale] = $crud['label_'.$locale]; } } return $localeLabels; }
[ "protected", "function", "getLocaleLabels", "(", "array", "$", "crud", ")", "{", "$", "locales", "=", "$", "this", "->", "getLocales", "(", ")", ";", "$", "localeLabels", "=", "[", "]", ";", "foreach", "(", "$", "locales", "as", "$", "locale", ")", "{", "if", "(", "array_key_exists", "(", "'label_'", ".", "$", "locale", ",", "$", "crud", ")", ")", "{", "$", "localeLabels", "[", "$", "locale", "]", "=", "$", "crud", "[", "'label_'", ".", "$", "locale", "]", ";", "}", "}", "return", "$", "localeLabels", ";", "}" ]
Gets a map with localized entity labels from the CRUD YML. @param array $crud the CRUD entity map @return array the map with localized entity labels
[ "Gets", "a", "map", "with", "localized", "entity", "labels", "from", "the", "CRUD", "YML", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L100-L110
38,189
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.configureDefinition
protected function configureDefinition(EntityDefinition $definition, array $crud) { $toConfigure = [ 'deleteCascade', 'listFields', 'filter', 'childrenLabelFields', 'pageSize', 'initialSortField', 'initialSortAscending', 'navBarGroup', 'optimisticLocking', 'hardDeletion', ]; foreach ($toConfigure as $field) { if (array_key_exists($field, $crud)) { $function = 'set'.ucfirst($field); $definition->$function($crud[$field]); } } }
php
protected function configureDefinition(EntityDefinition $definition, array $crud) { $toConfigure = [ 'deleteCascade', 'listFields', 'filter', 'childrenLabelFields', 'pageSize', 'initialSortField', 'initialSortAscending', 'navBarGroup', 'optimisticLocking', 'hardDeletion', ]; foreach ($toConfigure as $field) { if (array_key_exists($field, $crud)) { $function = 'set'.ucfirst($field); $definition->$function($crud[$field]); } } }
[ "protected", "function", "configureDefinition", "(", "EntityDefinition", "$", "definition", ",", "array", "$", "crud", ")", "{", "$", "toConfigure", "=", "[", "'deleteCascade'", ",", "'listFields'", ",", "'filter'", ",", "'childrenLabelFields'", ",", "'pageSize'", ",", "'initialSortField'", ",", "'initialSortAscending'", ",", "'navBarGroup'", ",", "'optimisticLocking'", ",", "'hardDeletion'", ",", "]", ";", "foreach", "(", "$", "toConfigure", "as", "$", "field", ")", "{", "if", "(", "array_key_exists", "(", "$", "field", ",", "$", "crud", ")", ")", "{", "$", "function", "=", "'set'", ".", "ucfirst", "(", "$", "field", ")", ";", "$", "definition", "->", "$", "function", "(", "$", "crud", "[", "$", "field", "]", ")", ";", "}", "}", "}" ]
Configures the EntityDefinition according to the given CRUD entity map. @param EntityDefinition $definition the definition to configure @param array $crud the CRUD entity map
[ "Configures", "the", "EntityDefinition", "according", "to", "the", "given", "CRUD", "entity", "map", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L121-L141
38,190
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.createDefinition
protected function createDefinition(TranslatorInterface $translator, EntityDefinitionFactoryInterface $entityDefinitionFactory, array $crud, $name) { $label = array_key_exists('label', $crud) ? $crud['label'] : $name; $localeLabels = $this->getLocaleLabels($crud); $standardFieldLabels = [ 'id' => $translator->trans('crudlex.label.id'), 'created_at' => $translator->trans('crudlex.label.created_at'), 'updated_at' => $translator->trans('crudlex.label.updated_at') ]; $definition = $entityDefinitionFactory->createEntityDefinition( $crud['table'], $crud['fields'], $label, $localeLabels, $standardFieldLabels, $this ); $this->configureDefinition($definition, $crud); return $definition; }
php
protected function createDefinition(TranslatorInterface $translator, EntityDefinitionFactoryInterface $entityDefinitionFactory, array $crud, $name) { $label = array_key_exists('label', $crud) ? $crud['label'] : $name; $localeLabels = $this->getLocaleLabels($crud); $standardFieldLabels = [ 'id' => $translator->trans('crudlex.label.id'), 'created_at' => $translator->trans('crudlex.label.created_at'), 'updated_at' => $translator->trans('crudlex.label.updated_at') ]; $definition = $entityDefinitionFactory->createEntityDefinition( $crud['table'], $crud['fields'], $label, $localeLabels, $standardFieldLabels, $this ); $this->configureDefinition($definition, $crud); return $definition; }
[ "protected", "function", "createDefinition", "(", "TranslatorInterface", "$", "translator", ",", "EntityDefinitionFactoryInterface", "$", "entityDefinitionFactory", ",", "array", "$", "crud", ",", "$", "name", ")", "{", "$", "label", "=", "array_key_exists", "(", "'label'", ",", "$", "crud", ")", "?", "$", "crud", "[", "'label'", "]", ":", "$", "name", ";", "$", "localeLabels", "=", "$", "this", "->", "getLocaleLabels", "(", "$", "crud", ")", ";", "$", "standardFieldLabels", "=", "[", "'id'", "=>", "$", "translator", "->", "trans", "(", "'crudlex.label.id'", ")", ",", "'created_at'", "=>", "$", "translator", "->", "trans", "(", "'crudlex.label.created_at'", ")", ",", "'updated_at'", "=>", "$", "translator", "->", "trans", "(", "'crudlex.label.updated_at'", ")", "]", ";", "$", "definition", "=", "$", "entityDefinitionFactory", "->", "createEntityDefinition", "(", "$", "crud", "[", "'table'", "]", ",", "$", "crud", "[", "'fields'", "]", ",", "$", "label", ",", "$", "localeLabels", ",", "$", "standardFieldLabels", ",", "$", "this", ")", ";", "$", "this", "->", "configureDefinition", "(", "$", "definition", ",", "$", "crud", ")", ";", "return", "$", "definition", ";", "}" ]
Creates and setups an EntityDefinition instance. @param TranslatorInterface $translator the Translator to use for some standard field labels @param EntityDefinitionFactoryInterface $entityDefinitionFactory the EntityDefinitionFactory to use @param array $crud the parsed YAML of a CRUD entity @param string $name the name of the entity @return EntityDefinition the EntityDefinition good to go
[ "Creates", "and", "setups", "an", "EntityDefinition", "instance", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L158-L178
38,191
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.getData
public function getData($name) { if (!array_key_exists($name, $this->datas)) { return null; } return $this->datas[$name]; }
php
public function getData($name) { if (!array_key_exists($name, $this->datas)) { return null; } return $this->datas[$name]; }
[ "public", "function", "getData", "(", "$", "name", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "datas", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "datas", "[", "$", "name", "]", ";", "}" ]
Getter for the AbstractData instances. @param string $name the entity name of the desired Data instance @return AbstractData the AbstractData instance or null on invalid name
[ "Getter", "for", "the", "AbstractData", "instances", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L234-L240
38,192
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.getEntitiesNavBar
public function getEntitiesNavBar() { $result = []; foreach ($this->datas as $entity => $data) { $navBarGroup = $data->getDefinition()->getNavBarGroup(); if ($navBarGroup !== 'main') { $result[$navBarGroup][] = $entity; } else { $result[$entity] = 'main'; } } return $result; }
php
public function getEntitiesNavBar() { $result = []; foreach ($this->datas as $entity => $data) { $navBarGroup = $data->getDefinition()->getNavBarGroup(); if ($navBarGroup !== 'main') { $result[$navBarGroup][] = $entity; } else { $result[$entity] = 'main'; } } return $result; }
[ "public", "function", "getEntitiesNavBar", "(", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "datas", "as", "$", "entity", "=>", "$", "data", ")", "{", "$", "navBarGroup", "=", "$", "data", "->", "getDefinition", "(", ")", "->", "getNavBarGroup", "(", ")", ";", "if", "(", "$", "navBarGroup", "!==", "'main'", ")", "{", "$", "result", "[", "$", "navBarGroup", "]", "[", "]", "=", "$", "entity", ";", "}", "else", "{", "$", "result", "[", "$", "entity", "]", "=", "'main'", ";", "}", "}", "return", "$", "result", ";", "}" ]
Getter for the entities for the navigation bar. @return string[] a list of all available entity names with their group
[ "Getter", "for", "the", "entities", "for", "the", "navigation", "bar", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L259-L271
38,193
philiplb/CRUDlex
src/CRUDlex/Service.php
Service.setLocale
public function setLocale($locale) { foreach ($this->datas as $data) { $data->getDefinition()->setLocale($locale); } }
php
public function setLocale($locale) { foreach ($this->datas as $data) { $data->getDefinition()->setLocale($locale); } }
[ "public", "function", "setLocale", "(", "$", "locale", ")", "{", "foreach", "(", "$", "this", "->", "datas", "as", "$", "data", ")", "{", "$", "data", "->", "getDefinition", "(", ")", "->", "setLocale", "(", "$", "locale", ")", ";", "}", "}" ]
Sets the locale to be used. @param string $locale the locale to be used.
[ "Sets", "the", "locale", "to", "be", "used", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Service.php#L334-L339
38,194
philiplb/CRUDlex
src/CRUDlex/TwigExtensions.php
TwigExtensions.formatFloat
public function formatFloat($float) { if (!$float) { return $float; } $zeroFraction = $float - floor($float) == 0 ? '0' : ''; // We don't want values like 0.004 converted to 0.00400000000000000008 if ($float > 0.0001) { return $float.($zeroFraction === '0' ? '.'.$zeroFraction : ''); } // We don't want values like 0.00004 converted to its scientific notation 4.0E-5 return rtrim(sprintf('%.20F', $float), '0').$zeroFraction; }
php
public function formatFloat($float) { if (!$float) { return $float; } $zeroFraction = $float - floor($float) == 0 ? '0' : ''; // We don't want values like 0.004 converted to 0.00400000000000000008 if ($float > 0.0001) { return $float.($zeroFraction === '0' ? '.'.$zeroFraction : ''); } // We don't want values like 0.00004 converted to its scientific notation 4.0E-5 return rtrim(sprintf('%.20F', $float), '0').$zeroFraction; }
[ "public", "function", "formatFloat", "(", "$", "float", ")", "{", "if", "(", "!", "$", "float", ")", "{", "return", "$", "float", ";", "}", "$", "zeroFraction", "=", "$", "float", "-", "floor", "(", "$", "float", ")", "==", "0", "?", "'0'", ":", "''", ";", "// We don't want values like 0.004 converted to 0.00400000000000000008", "if", "(", "$", "float", ">", "0.0001", ")", "{", "return", "$", "float", ".", "(", "$", "zeroFraction", "===", "'0'", "?", "'.'", ".", "$", "zeroFraction", ":", "''", ")", ";", "}", "// We don't want values like 0.00004 converted to its scientific notation 4.0E-5", "return", "rtrim", "(", "sprintf", "(", "'%.20F'", ",", "$", "float", ")", ",", "'0'", ")", ".", "$", "zeroFraction", ";", "}" ]
Formats a float to not display in scientific notation. @param float $float the float to format @return double|string the formated float
[ "Formats", "a", "float", "to", "not", "display", "in", "scientific", "notation", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/TwigExtensions.php#L82-L98
38,195
philiplb/CRUDlex
src/CRUDlex/TwigExtensions.php
TwigExtensions.formatDate
public function formatDate($value, $isUTC) { $timezone = $isUTC ? 'UTC' : date_default_timezone_get(); return $this->formatTime($value, $timezone, 'Y-m-d'); }
php
public function formatDate($value, $isUTC) { $timezone = $isUTC ? 'UTC' : date_default_timezone_get(); return $this->formatTime($value, $timezone, 'Y-m-d'); }
[ "public", "function", "formatDate", "(", "$", "value", ",", "$", "isUTC", ")", "{", "$", "timezone", "=", "$", "isUTC", "?", "'UTC'", ":", "date_default_timezone_get", "(", ")", ";", "return", "$", "this", "->", "formatTime", "(", "$", "value", ",", "$", "timezone", ",", "'Y-m-d'", ")", ";", "}" ]
Formats the given value to a date of the format 'Y-m-d'. @param string $value the value, might be of the format 'Y-m-d H:i' or 'Y-m-d' @param boolean $isUTC whether the given value is in UTC @return string the formatted result or an empty string on null value
[ "Formats", "the", "given", "value", "to", "a", "date", "of", "the", "format", "Y", "-", "m", "-", "d", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/TwigExtensions.php#L111-L115
38,196
philiplb/CRUDlex
src/CRUDlex/EntityValidator.php
EntityValidator.fieldTypeToRules
protected function fieldTypeToRules($field, AbstractData $data, Validator $validator) { $setItems = $this->definition->getField($field, 'items', []); $rulesMapping = [ 'boolean' => ['boolean'], 'float' => ['floating'], 'integer' => ['integer'], 'date' => ['dateTime', 'Y-m-d'], 'datetime' => ['or', $validator, ['dateTime', 'Y-m-d H:i'], ['dateTime', 'Y-m-d H:i:s']], 'set' => array_merge(['inSet'], $setItems), 'reference' => ['reference', $data, $field], 'many' => ['many', $data, $field] ]; $type = $this->definition->getType($field); $rules = []; if (array_key_exists($type, $rulesMapping)) { $rules[] = $rulesMapping[$type]; } return $rules; }
php
protected function fieldTypeToRules($field, AbstractData $data, Validator $validator) { $setItems = $this->definition->getField($field, 'items', []); $rulesMapping = [ 'boolean' => ['boolean'], 'float' => ['floating'], 'integer' => ['integer'], 'date' => ['dateTime', 'Y-m-d'], 'datetime' => ['or', $validator, ['dateTime', 'Y-m-d H:i'], ['dateTime', 'Y-m-d H:i:s']], 'set' => array_merge(['inSet'], $setItems), 'reference' => ['reference', $data, $field], 'many' => ['many', $data, $field] ]; $type = $this->definition->getType($field); $rules = []; if (array_key_exists($type, $rulesMapping)) { $rules[] = $rulesMapping[$type]; } return $rules; }
[ "protected", "function", "fieldTypeToRules", "(", "$", "field", ",", "AbstractData", "$", "data", ",", "Validator", "$", "validator", ")", "{", "$", "setItems", "=", "$", "this", "->", "definition", "->", "getField", "(", "$", "field", ",", "'items'", ",", "[", "]", ")", ";", "$", "rulesMapping", "=", "[", "'boolean'", "=>", "[", "'boolean'", "]", ",", "'float'", "=>", "[", "'floating'", "]", ",", "'integer'", "=>", "[", "'integer'", "]", ",", "'date'", "=>", "[", "'dateTime'", ",", "'Y-m-d'", "]", ",", "'datetime'", "=>", "[", "'or'", ",", "$", "validator", ",", "[", "'dateTime'", ",", "'Y-m-d H:i'", "]", ",", "[", "'dateTime'", ",", "'Y-m-d H:i:s'", "]", "]", ",", "'set'", "=>", "array_merge", "(", "[", "'inSet'", "]", ",", "$", "setItems", ")", ",", "'reference'", "=>", "[", "'reference'", ",", "$", "data", ",", "$", "field", "]", ",", "'many'", "=>", "[", "'many'", ",", "$", "data", ",", "$", "field", "]", "]", ";", "$", "type", "=", "$", "this", "->", "definition", "->", "getType", "(", "$", "field", ")", ";", "$", "rules", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "$", "type", ",", "$", "rulesMapping", ")", ")", "{", "$", "rules", "[", "]", "=", "$", "rulesMapping", "[", "$", "type", "]", ";", "}", "return", "$", "rules", ";", "}" ]
Builds up the validation rules for a single field according to the entity definition type. @param string $field the field for the rules @param AbstractData $data the data instance to use for validation @param Validator $validator the validator to use @return array the validation rules for the field
[ "Builds", "up", "the", "validation", "rules", "for", "a", "single", "field", "according", "to", "the", "entity", "definition", "type", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityValidator.php#L50-L69
38,197
philiplb/CRUDlex
src/CRUDlex/EntityValidator.php
EntityValidator.fieldConstraintsToRules
protected function fieldConstraintsToRules($field, AbstractData $data) { $rules = []; if ($this->definition->getField($field, 'required', false)) { $rules[] = ['required']; } if ($this->definition->getField($field, 'unique', false)) { $rules[] = ['unique', $data, $this->entity, $field]; } return $rules; }
php
protected function fieldConstraintsToRules($field, AbstractData $data) { $rules = []; if ($this->definition->getField($field, 'required', false)) { $rules[] = ['required']; } if ($this->definition->getField($field, 'unique', false)) { $rules[] = ['unique', $data, $this->entity, $field]; } return $rules; }
[ "protected", "function", "fieldConstraintsToRules", "(", "$", "field", ",", "AbstractData", "$", "data", ")", "{", "$", "rules", "=", "[", "]", ";", "if", "(", "$", "this", "->", "definition", "->", "getField", "(", "$", "field", ",", "'required'", ",", "false", ")", ")", "{", "$", "rules", "[", "]", "=", "[", "'required'", "]", ";", "}", "if", "(", "$", "this", "->", "definition", "->", "getField", "(", "$", "field", ",", "'unique'", ",", "false", ")", ")", "{", "$", "rules", "[", "]", "=", "[", "'unique'", ",", "$", "data", ",", "$", "this", "->", "entity", ",", "$", "field", "]", ";", "}", "return", "$", "rules", ";", "}" ]
Builds up the validation rules for a single field according to the entity definition constraints. @param string $field the field for the rules @param AbstractData $data the data instance to use for validation @return array the validation rules for the field
[ "Builds", "up", "the", "validation", "rules", "for", "a", "single", "field", "according", "to", "the", "entity", "definition", "constraints", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityValidator.php#L84-L94
38,198
philiplb/CRUDlex
src/CRUDlex/EntityValidator.php
EntityValidator.buildUpData
protected function buildUpData() { $data = []; $fields = $this->definition->getEditableFieldNames(); foreach ($fields as $field) { $data[$field] = $this->entity->getRaw($field); $fixed = $this->definition->getField($field, 'value'); if ($fixed) { $data[$field] = $fixed; } } return $data; }
php
protected function buildUpData() { $data = []; $fields = $this->definition->getEditableFieldNames(); foreach ($fields as $field) { $data[$field] = $this->entity->getRaw($field); $fixed = $this->definition->getField($field, 'value'); if ($fixed) { $data[$field] = $fixed; } } return $data; }
[ "protected", "function", "buildUpData", "(", ")", "{", "$", "data", "=", "[", "]", ";", "$", "fields", "=", "$", "this", "->", "definition", "->", "getEditableFieldNames", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "data", "[", "$", "field", "]", "=", "$", "this", "->", "entity", "->", "getRaw", "(", "$", "field", ")", ";", "$", "fixed", "=", "$", "this", "->", "definition", "->", "getField", "(", "$", "field", ",", "'value'", ")", ";", "if", "(", "$", "fixed", ")", "{", "$", "data", "[", "$", "field", "]", "=", "$", "fixed", ";", "}", "}", "return", "$", "data", ";", "}" ]
Builds up the data to validate from the entity. @return array a map field to raw value
[ "Builds", "up", "the", "data", "to", "validate", "from", "the", "entity", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityValidator.php#L129-L141
38,199
philiplb/CRUDlex
src/CRUDlex/EntityValidator.php
EntityValidator.validate
public function validate(AbstractData $data, $expectedVersion) { $validator = new Validator(); $validator->addValidator('unique', new UniqueValidator()); $validator->addValidator('reference', new ReferenceValidator()); $validator->addValidator('many', new ManyValidator()); $rules = $this->buildUpRules($data, $validator); $toValidate = $this->buildUpData(); if ($this->definition->hasOptimisticLocking()) { $rules['version'] = [['value', $expectedVersion]]; $toValidate['version'] = $this->entity->get('version'); } $validation = $validator->isValid($rules, $toValidate); return $validation; }
php
public function validate(AbstractData $data, $expectedVersion) { $validator = new Validator(); $validator->addValidator('unique', new UniqueValidator()); $validator->addValidator('reference', new ReferenceValidator()); $validator->addValidator('many', new ManyValidator()); $rules = $this->buildUpRules($data, $validator); $toValidate = $this->buildUpData(); if ($this->definition->hasOptimisticLocking()) { $rules['version'] = [['value', $expectedVersion]]; $toValidate['version'] = $this->entity->get('version'); } $validation = $validator->isValid($rules, $toValidate); return $validation; }
[ "public", "function", "validate", "(", "AbstractData", "$", "data", ",", "$", "expectedVersion", ")", "{", "$", "validator", "=", "new", "Validator", "(", ")", ";", "$", "validator", "->", "addValidator", "(", "'unique'", ",", "new", "UniqueValidator", "(", ")", ")", ";", "$", "validator", "->", "addValidator", "(", "'reference'", ",", "new", "ReferenceValidator", "(", ")", ")", ";", "$", "validator", "->", "addValidator", "(", "'many'", ",", "new", "ManyValidator", "(", ")", ")", ";", "$", "rules", "=", "$", "this", "->", "buildUpRules", "(", "$", "data", ",", "$", "validator", ")", ";", "$", "toValidate", "=", "$", "this", "->", "buildUpData", "(", ")", ";", "if", "(", "$", "this", "->", "definition", "->", "hasOptimisticLocking", "(", ")", ")", "{", "$", "rules", "[", "'version'", "]", "=", "[", "[", "'value'", ",", "$", "expectedVersion", "]", "]", ";", "$", "toValidate", "[", "'version'", "]", "=", "$", "this", "->", "entity", "->", "get", "(", "'version'", ")", ";", "}", "$", "validation", "=", "$", "validator", "->", "isValid", "(", "$", "rules", ",", "$", "toValidate", ")", ";", "return", "$", "validation", ";", "}" ]
Validates the entity against the definition. @param AbstractData $data the data access instance used for counting things @param integer $expectedVersion the version to perform the optimistic locking check on @return array an array with the fields "valid" and "errors"; valid provides a quick check whether the given entity passes the validation and errors is an array with all errored fields as keys and arrays as values; this field arrays contains the actual errors on the field: "boolean", "floating", "integer", "dateTime" (for dates and datetime fields), "inSet", "reference", "required", "unique", "value" (only for the version field, set if the optimistic locking failed).
[ "Validates", "the", "entity", "against", "the", "definition", "." ]
6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc
https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityValidator.php#L174-L188