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
222,600
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.index
public function index() { // SECURITY: // if view_table_permission is false, abort if (isset($this->crud['view_table_permission']) && !$this->crud['view_table_permission']) { abort(403, 'Not allowed.'); } // get all results for that entity $model = $this->crud['model']; if (property_exists($model, 'translatable')) { $this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get(); } else { $this->data['entries'] = $model::all(); } // add the fake fields for each entry foreach ($this->data['entries'] as $key => $entry) { $entry->addFakes($this->getFakeColumnsAsArray()); } $this->prepareColumns(); $this->data['crud'] = $this->crud; // load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package return $this->firstViewThatExists('vendor.dick.crud.list', 'crud::list', $this->data); }
php
public function index() { // SECURITY: // if view_table_permission is false, abort if (isset($this->crud['view_table_permission']) && !$this->crud['view_table_permission']) { abort(403, 'Not allowed.'); } // get all results for that entity $model = $this->crud['model']; if (property_exists($model, 'translatable')) { $this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get(); } else { $this->data['entries'] = $model::all(); } // add the fake fields for each entry foreach ($this->data['entries'] as $key => $entry) { $entry->addFakes($this->getFakeColumnsAsArray()); } $this->prepareColumns(); $this->data['crud'] = $this->crud; // load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package return $this->firstViewThatExists('vendor.dick.crud.list', 'crud::list', $this->data); }
[ "public", "function", "index", "(", ")", "{", "// SECURITY:", "// if view_table_permission is false, abort", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'view_table_permission'", "]", ")", "&&", "!", "$", "this", "->", "crud", "[", "'view_table_permission'", "]", ")", "{", "abort", "(", "403", ",", "'Not allowed.'", ")", ";", "}", "// get all results for that entity", "$", "model", "=", "$", "this", "->", "crud", "[", "'model'", "]", ";", "if", "(", "property_exists", "(", "$", "model", ",", "'translatable'", ")", ")", "{", "$", "this", "->", "data", "[", "'entries'", "]", "=", "$", "model", "::", "where", "(", "'translation_lang'", ",", "\\", "Lang", "::", "locale", "(", ")", ")", "->", "get", "(", ")", ";", "}", "else", "{", "$", "this", "->", "data", "[", "'entries'", "]", "=", "$", "model", "::", "all", "(", ")", ";", "}", "// add the fake fields for each entry", "foreach", "(", "$", "this", "->", "data", "[", "'entries'", "]", "as", "$", "key", "=>", "$", "entry", ")", "{", "$", "entry", "->", "addFakes", "(", "$", "this", "->", "getFakeColumnsAsArray", "(", ")", ")", ";", "}", "$", "this", "->", "prepareColumns", "(", ")", ";", "$", "this", "->", "data", "[", "'crud'", "]", "=", "$", "this", "->", "crud", ";", "// load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package", "return", "$", "this", "->", "firstViewThatExists", "(", "'vendor.dick.crud.list'", ",", "'crud::list'", ",", "$", "this", "->", "data", ")", ";", "}" ]
Display all rows in the database for this entity. @return Response
[ "Display", "all", "rows", "in", "the", "database", "for", "this", "entity", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L46-L75
222,601
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.create
public function create() { // SECURITY: // if add_permission is false, abort if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { abort(403, 'Not allowed.'); } // get the fields you need to show if (isset($this->data['crud']['create_fields'])) { $this->crud['fields'] = $this->data['crud']['create_fields']; } // prepare the fields you need to show $this->prepareFields(); $this->data['crud'] = $this->crud; // load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package return $this->firstViewThatExists('vendor.dick.crud.create', 'crud::create', $this->data); }
php
public function create() { // SECURITY: // if add_permission is false, abort if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { abort(403, 'Not allowed.'); } // get the fields you need to show if (isset($this->data['crud']['create_fields'])) { $this->crud['fields'] = $this->data['crud']['create_fields']; } // prepare the fields you need to show $this->prepareFields(); $this->data['crud'] = $this->crud; // load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package return $this->firstViewThatExists('vendor.dick.crud.create', 'crud::create', $this->data); }
[ "public", "function", "create", "(", ")", "{", "// SECURITY:", "// if add_permission is false, abort", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'add_permission'", "]", ")", "&&", "!", "$", "this", "->", "crud", "[", "'add_permission'", "]", ")", "{", "abort", "(", "403", ",", "'Not allowed.'", ")", ";", "}", "// get the fields you need to show", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "'crud'", "]", "[", "'create_fields'", "]", ")", ")", "{", "$", "this", "->", "crud", "[", "'fields'", "]", "=", "$", "this", "->", "data", "[", "'crud'", "]", "[", "'create_fields'", "]", ";", "}", "// prepare the fields you need to show", "$", "this", "->", "prepareFields", "(", ")", ";", "$", "this", "->", "data", "[", "'crud'", "]", "=", "$", "this", "->", "crud", ";", "// load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package", "return", "$", "this", "->", "firstViewThatExists", "(", "'vendor.dick.crud.create'", ",", "'crud::create'", ",", "$", "this", "->", "data", ")", ";", "}" ]
Show the form for creating inserting a new row. @return Response
[ "Show", "the", "form", "for", "creating", "inserting", "a", "new", "row", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L83-L103
222,602
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.storeCrud
public function storeCrud(StoreRequest $request = null) { // SECURITY: // if add_permission is false, abort if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { abort(403, 'Not allowed.'); } // compress the fake fields into one field $model = $this->crud['model']; $values_to_store = $this->compactFakeFields(\Request::all()); $item = $model::create($values_to_store); // if it's a relationship with a pivot table, also sync that $this->prepareFields(); foreach ($this->crud['fields'] as $k => $field) { if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name'])) { $model::find($item->id)->$field['name']()->attach(\Request::input($field['name'])); } } // show a success message \Alert::success(trans('crud.insert_success'))->flash(); // redirect the user where he chose to be redirected switch (\Request::input('redirect_after_save')) { case 'current_item_edit': return \Redirect::to($this->crud['route'].'/'.$item->id.'/edit'); break; default: return \Redirect::to(\Request::input('redirect_after_save')); break; } }
php
public function storeCrud(StoreRequest $request = null) { // SECURITY: // if add_permission is false, abort if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { abort(403, 'Not allowed.'); } // compress the fake fields into one field $model = $this->crud['model']; $values_to_store = $this->compactFakeFields(\Request::all()); $item = $model::create($values_to_store); // if it's a relationship with a pivot table, also sync that $this->prepareFields(); foreach ($this->crud['fields'] as $k => $field) { if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name'])) { $model::find($item->id)->$field['name']()->attach(\Request::input($field['name'])); } } // show a success message \Alert::success(trans('crud.insert_success'))->flash(); // redirect the user where he chose to be redirected switch (\Request::input('redirect_after_save')) { case 'current_item_edit': return \Redirect::to($this->crud['route'].'/'.$item->id.'/edit'); break; default: return \Redirect::to(\Request::input('redirect_after_save')); break; } }
[ "public", "function", "storeCrud", "(", "StoreRequest", "$", "request", "=", "null", ")", "{", "// SECURITY:", "// if add_permission is false, abort", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'add_permission'", "]", ")", "&&", "!", "$", "this", "->", "crud", "[", "'add_permission'", "]", ")", "{", "abort", "(", "403", ",", "'Not allowed.'", ")", ";", "}", "// compress the fake fields into one field", "$", "model", "=", "$", "this", "->", "crud", "[", "'model'", "]", ";", "$", "values_to_store", "=", "$", "this", "->", "compactFakeFields", "(", "\\", "Request", "::", "all", "(", ")", ")", ";", "$", "item", "=", "$", "model", "::", "create", "(", "$", "values_to_store", ")", ";", "// if it's a relationship with a pivot table, also sync that", "$", "this", "->", "prepareFields", "(", ")", ";", "foreach", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "as", "$", "k", "=>", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "[", "'pivot'", "]", ")", "&&", "$", "field", "[", "'pivot'", "]", "==", "true", "&&", "\\", "Request", "::", "has", "(", "$", "field", "[", "'name'", "]", ")", ")", "{", "$", "model", "::", "find", "(", "$", "item", "->", "id", ")", "->", "$", "field", "[", "'name'", "]", "(", ")", "->", "attach", "(", "\\", "Request", "::", "input", "(", "$", "field", "[", "'name'", "]", ")", ")", ";", "}", "}", "// show a success message", "\\", "Alert", "::", "success", "(", "trans", "(", "'crud.insert_success'", ")", ")", "->", "flash", "(", ")", ";", "// redirect the user where he chose to be redirected", "switch", "(", "\\", "Request", "::", "input", "(", "'redirect_after_save'", ")", ")", "{", "case", "'current_item_edit'", ":", "return", "\\", "Redirect", "::", "to", "(", "$", "this", "->", "crud", "[", "'route'", "]", ".", "'/'", ".", "$", "item", "->", "id", ".", "'/edit'", ")", ";", "break", ";", "default", ":", "return", "\\", "Redirect", "::", "to", "(", "\\", "Request", "::", "input", "(", "'redirect_after_save'", ")", ")", ";", "break", ";", "}", "}" ]
Store a newly created resource in the database. @return Response
[ "Store", "a", "newly", "created", "resource", "in", "the", "database", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L111-L146
222,603
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.updateCrud
public function updateCrud(UpdateRequest $request = null) { // if edit_permission is false, abort if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) { abort(403, 'Not allowed.'); } $model = $this->crud['model']; $this->prepareFields($model::find(\Request::input('id'))); $item = $model::find(\Request::input('id')) ->update($this->compactFakeFields(\Request::all())); // if it's a relationship with a pivot table, also sync that foreach ($this->crud['fields'] as $k => $field) { if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name'])) { $model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name'])); } } // show a success message \Alert::success(trans('crud.update_success'))->flash(); return \Redirect::to($this->crud['route']); }
php
public function updateCrud(UpdateRequest $request = null) { // if edit_permission is false, abort if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) { abort(403, 'Not allowed.'); } $model = $this->crud['model']; $this->prepareFields($model::find(\Request::input('id'))); $item = $model::find(\Request::input('id')) ->update($this->compactFakeFields(\Request::all())); // if it's a relationship with a pivot table, also sync that foreach ($this->crud['fields'] as $k => $field) { if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name'])) { $model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name'])); } } // show a success message \Alert::success(trans('crud.update_success'))->flash(); return \Redirect::to($this->crud['route']); }
[ "public", "function", "updateCrud", "(", "UpdateRequest", "$", "request", "=", "null", ")", "{", "// if edit_permission is false, abort", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'edit_permission'", "]", ")", "&&", "!", "$", "this", "->", "crud", "[", "'edit_permission'", "]", ")", "{", "abort", "(", "403", ",", "'Not allowed.'", ")", ";", "}", "$", "model", "=", "$", "this", "->", "crud", "[", "'model'", "]", ";", "$", "this", "->", "prepareFields", "(", "$", "model", "::", "find", "(", "\\", "Request", "::", "input", "(", "'id'", ")", ")", ")", ";", "$", "item", "=", "$", "model", "::", "find", "(", "\\", "Request", "::", "input", "(", "'id'", ")", ")", "->", "update", "(", "$", "this", "->", "compactFakeFields", "(", "\\", "Request", "::", "all", "(", ")", ")", ")", ";", "// if it's a relationship with a pivot table, also sync that", "foreach", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "as", "$", "k", "=>", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "[", "'pivot'", "]", ")", "&&", "$", "field", "[", "'pivot'", "]", "==", "true", "&&", "\\", "Request", "::", "has", "(", "$", "field", "[", "'name'", "]", ")", ")", "{", "$", "model", "::", "find", "(", "\\", "Request", "::", "input", "(", "'id'", ")", ")", "->", "$", "field", "[", "'name'", "]", "(", ")", "->", "sync", "(", "\\", "Request", "::", "input", "(", "$", "field", "[", "'name'", "]", ")", ")", ";", "}", "}", "// show a success message", "\\", "Alert", "::", "success", "(", "trans", "(", "'crud.update_success'", ")", ")", "->", "flash", "(", ")", ";", "return", "\\", "Redirect", "::", "to", "(", "$", "this", "->", "crud", "[", "'route'", "]", ")", ";", "}" ]
Update the specified resource in the database. @param int $id @return Response
[ "Update", "the", "specified", "resource", "in", "the", "database", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L188-L213
222,604
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.reorder
public function reorder($lang = false) { // if reorder_table_permission is false, abort if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { abort(403, 'Not allowed.'); } if ($lang == false) { $lang = \Lang::locale(); } // get all results for that entity $model = $this->crud['model']; if (property_exists($model, 'translatable')) { $this->data['entries'] = $model::where('translation_lang', $lang)->get(); $this->data['languages'] = \Dick\TranslationManager\Models\Language::all(); $this->data['active_language'] = $lang; } else { $this->data['entries'] = $model::all(); } $this->data['crud'] = $this->crud; // load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package return $this->firstViewThatExists('vendor.dick.crud.reorder', 'crud::reorder', $this->data); }
php
public function reorder($lang = false) { // if reorder_table_permission is false, abort if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { abort(403, 'Not allowed.'); } if ($lang == false) { $lang = \Lang::locale(); } // get all results for that entity $model = $this->crud['model']; if (property_exists($model, 'translatable')) { $this->data['entries'] = $model::where('translation_lang', $lang)->get(); $this->data['languages'] = \Dick\TranslationManager\Models\Language::all(); $this->data['active_language'] = $lang; } else { $this->data['entries'] = $model::all(); } $this->data['crud'] = $this->crud; // load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package return $this->firstViewThatExists('vendor.dick.crud.reorder', 'crud::reorder', $this->data); }
[ "public", "function", "reorder", "(", "$", "lang", "=", "false", ")", "{", "// if reorder_table_permission is false, abort", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'reorder_permission'", "]", ")", "&&", "!", "$", "this", "->", "crud", "[", "'reorder_permission'", "]", ")", "{", "abort", "(", "403", ",", "'Not allowed.'", ")", ";", "}", "if", "(", "$", "lang", "==", "false", ")", "{", "$", "lang", "=", "\\", "Lang", "::", "locale", "(", ")", ";", "}", "// get all results for that entity", "$", "model", "=", "$", "this", "->", "crud", "[", "'model'", "]", ";", "if", "(", "property_exists", "(", "$", "model", ",", "'translatable'", ")", ")", "{", "$", "this", "->", "data", "[", "'entries'", "]", "=", "$", "model", "::", "where", "(", "'translation_lang'", ",", "$", "lang", ")", "->", "get", "(", ")", ";", "$", "this", "->", "data", "[", "'languages'", "]", "=", "\\", "Dick", "\\", "TranslationManager", "\\", "Models", "\\", "Language", "::", "all", "(", ")", ";", "$", "this", "->", "data", "[", "'active_language'", "]", "=", "$", "lang", ";", "}", "else", "{", "$", "this", "->", "data", "[", "'entries'", "]", "=", "$", "model", "::", "all", "(", ")", ";", "}", "$", "this", "->", "data", "[", "'crud'", "]", "=", "$", "this", "->", "crud", ";", "// load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package", "return", "$", "this", "->", "firstViewThatExists", "(", "'vendor.dick.crud.reorder'", ",", "'crud::reorder'", ",", "$", "this", "->", "data", ")", ";", "}" ]
Reorder the items in the database using the Nested Set pattern. Database columns needed: id, parent_id, lft, rgt, depth, name/title @return Response
[ "Reorder", "the", "items", "in", "the", "database", "using", "the", "Nested", "Set", "pattern", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L264-L292
222,605
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.saveReorder
public function saveReorder() { // if reorder_table_permission is false, abort if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { abort(403, 'Not allowed.'); } $model = $this->crud['model']; $count = 0; $all_entries = \Request::input('tree'); if (count($all_entries)) { foreach ($all_entries as $key => $entry) { if ($entry['item_id'] != "" && $entry['item_id'] != null) { $item = $model::find($entry['item_id']); $item->parent_id = $entry['parent_id']; $item->depth = $entry['depth']; $item->lft = $entry['left']; $item->rgt = $entry['right']; $item->save(); $count++; } } } else { return false; } return 'success for '.$count." items"; }
php
public function saveReorder() { // if reorder_table_permission is false, abort if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { abort(403, 'Not allowed.'); } $model = $this->crud['model']; $count = 0; $all_entries = \Request::input('tree'); if (count($all_entries)) { foreach ($all_entries as $key => $entry) { if ($entry['item_id'] != "" && $entry['item_id'] != null) { $item = $model::find($entry['item_id']); $item->parent_id = $entry['parent_id']; $item->depth = $entry['depth']; $item->lft = $entry['left']; $item->rgt = $entry['right']; $item->save(); $count++; } } } else { return false; } return 'success for '.$count." items"; }
[ "public", "function", "saveReorder", "(", ")", "{", "// if reorder_table_permission is false, abort", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'reorder_permission'", "]", ")", "&&", "!", "$", "this", "->", "crud", "[", "'reorder_permission'", "]", ")", "{", "abort", "(", "403", ",", "'Not allowed.'", ")", ";", "}", "$", "model", "=", "$", "this", "->", "crud", "[", "'model'", "]", ";", "$", "count", "=", "0", ";", "$", "all_entries", "=", "\\", "Request", "::", "input", "(", "'tree'", ")", ";", "if", "(", "count", "(", "$", "all_entries", ")", ")", "{", "foreach", "(", "$", "all_entries", "as", "$", "key", "=>", "$", "entry", ")", "{", "if", "(", "$", "entry", "[", "'item_id'", "]", "!=", "\"\"", "&&", "$", "entry", "[", "'item_id'", "]", "!=", "null", ")", "{", "$", "item", "=", "$", "model", "::", "find", "(", "$", "entry", "[", "'item_id'", "]", ")", ";", "$", "item", "->", "parent_id", "=", "$", "entry", "[", "'parent_id'", "]", ";", "$", "item", "->", "depth", "=", "$", "entry", "[", "'depth'", "]", ";", "$", "item", "->", "lft", "=", "$", "entry", "[", "'left'", "]", ";", "$", "item", "->", "rgt", "=", "$", "entry", "[", "'right'", "]", ";", "$", "item", "->", "save", "(", ")", ";", "$", "count", "++", ";", "}", "}", "}", "else", "{", "return", "false", ";", "}", "return", "'success for '", ".", "$", "count", ".", "\" items\"", ";", "}" ]
Save the new order, using the Nested Set pattern. Database columns needed: id, parent_id, lft, rgt, depth, name/title @return
[ "Save", "the", "new", "order", "using", "the", "Nested", "Set", "pattern", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L302-L333
222,606
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.translateItem
public function translateItem($id, $lang) { $model = $this->crud['model']; $this->data['entry'] = $model::find($id); // check if there isn't a translation already $existing_translation = $this->data['entry']->translation($lang); if ($existing_translation) { $new_entry = $existing_translation; } else { // get the info for that entry $new_entry_attributes = $this->data['entry']->getAttributes(); $new_entry_attributes['translation_lang'] = $lang; $new_entry_attributes['translation_of'] = $id; $new_entry_attributes = array_except($new_entry_attributes, 'id'); $new_entry = $model::create($new_entry_attributes); } // redirect to the edit form for that translation return redirect(str_replace($id, $new_entry->id, str_replace('translate/'.$lang, 'edit', \Request::url()))); }
php
public function translateItem($id, $lang) { $model = $this->crud['model']; $this->data['entry'] = $model::find($id); // check if there isn't a translation already $existing_translation = $this->data['entry']->translation($lang); if ($existing_translation) { $new_entry = $existing_translation; } else { // get the info for that entry $new_entry_attributes = $this->data['entry']->getAttributes(); $new_entry_attributes['translation_lang'] = $lang; $new_entry_attributes['translation_of'] = $id; $new_entry_attributes = array_except($new_entry_attributes, 'id'); $new_entry = $model::create($new_entry_attributes); } // redirect to the edit form for that translation return redirect(str_replace($id, $new_entry->id, str_replace('translate/'.$lang, 'edit', \Request::url()))); }
[ "public", "function", "translateItem", "(", "$", "id", ",", "$", "lang", ")", "{", "$", "model", "=", "$", "this", "->", "crud", "[", "'model'", "]", ";", "$", "this", "->", "data", "[", "'entry'", "]", "=", "$", "model", "::", "find", "(", "$", "id", ")", ";", "// check if there isn't a translation already", "$", "existing_translation", "=", "$", "this", "->", "data", "[", "'entry'", "]", "->", "translation", "(", "$", "lang", ")", ";", "if", "(", "$", "existing_translation", ")", "{", "$", "new_entry", "=", "$", "existing_translation", ";", "}", "else", "{", "// get the info for that entry", "$", "new_entry_attributes", "=", "$", "this", "->", "data", "[", "'entry'", "]", "->", "getAttributes", "(", ")", ";", "$", "new_entry_attributes", "[", "'translation_lang'", "]", "=", "$", "lang", ";", "$", "new_entry_attributes", "[", "'translation_of'", "]", "=", "$", "id", ";", "$", "new_entry_attributes", "=", "array_except", "(", "$", "new_entry_attributes", ",", "'id'", ")", ";", "$", "new_entry", "=", "$", "model", "::", "create", "(", "$", "new_entry_attributes", ")", ";", "}", "// redirect to the edit form for that translation", "return", "redirect", "(", "str_replace", "(", "$", "id", ",", "$", "new_entry", "->", "id", ",", "str_replace", "(", "'translate/'", ".", "$", "lang", ",", "'edit'", ",", "\\", "Request", "::", "url", "(", ")", ")", ")", ")", ";", "}" ]
Duplicate an existing item into another language and open it for editing.
[ "Duplicate", "an", "existing", "item", "into", "another", "language", "and", "open", "it", "for", "editing", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L374-L398
222,607
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.compactFakeFields
protected function compactFakeFields($request) { $this->prepareFields(); $fake_field_columns_to_encode = []; // go through each defined field foreach ($this->crud['fields'] as $k => $field) { // if it's a fake field if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) { // add it to the request in its appropriate variable - the one defined, if defined if (isset($this->crud['fields'][$k]['store_in'])) { $request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){ array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']); } } else //otherwise in the one defined in the $crud variable { $request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); if(!in_array('extras', $fake_field_columns_to_encode, true)){ array_push($fake_field_columns_to_encode, 'extras'); } } } } // json_encode all fake_value columns in the database, so they can be properly stored and interpreted if (count($fake_field_columns_to_encode)) { foreach ($fake_field_columns_to_encode as $key => $value) { $request[$value] = json_encode($request[$value]); } } // if there are no fake fields defined, this will just return the original Request in full // since no modifications or additions have been made to $request return $request; }
php
protected function compactFakeFields($request) { $this->prepareFields(); $fake_field_columns_to_encode = []; // go through each defined field foreach ($this->crud['fields'] as $k => $field) { // if it's a fake field if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) { // add it to the request in its appropriate variable - the one defined, if defined if (isset($this->crud['fields'][$k]['store_in'])) { $request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){ array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']); } } else //otherwise in the one defined in the $crud variable { $request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); if(!in_array('extras', $fake_field_columns_to_encode, true)){ array_push($fake_field_columns_to_encode, 'extras'); } } } } // json_encode all fake_value columns in the database, so they can be properly stored and interpreted if (count($fake_field_columns_to_encode)) { foreach ($fake_field_columns_to_encode as $key => $value) { $request[$value] = json_encode($request[$value]); } } // if there are no fake fields defined, this will just return the original Request in full // since no modifications or additions have been made to $request return $request; }
[ "protected", "function", "compactFakeFields", "(", "$", "request", ")", "{", "$", "this", "->", "prepareFields", "(", ")", ";", "$", "fake_field_columns_to_encode", "=", "[", "]", ";", "// go through each defined field", "foreach", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "as", "$", "k", "=>", "$", "field", ")", "{", "// if it's a fake field", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'fake'", "]", ")", "&&", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'fake'", "]", "==", "true", ")", "{", "// add it to the request in its appropriate variable - the one defined, if defined", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'store_in'", "]", ")", ")", "{", "$", "request", "[", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'store_in'", "]", "]", "[", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'name'", "]", "]", "=", "$", "request", "[", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'name'", "]", "]", ";", "$", "remove_fake_field", "=", "array_pull", "(", "$", "request", ",", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'name'", "]", ")", ";", "if", "(", "!", "in_array", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'store_in'", "]", ",", "$", "fake_field_columns_to_encode", ",", "true", ")", ")", "{", "array_push", "(", "$", "fake_field_columns_to_encode", ",", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'store_in'", "]", ")", ";", "}", "}", "else", "//otherwise in the one defined in the $crud variable", "{", "$", "request", "[", "'extras'", "]", "[", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'name'", "]", "]", "=", "$", "request", "[", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'name'", "]", "]", ";", "$", "remove_fake_field", "=", "array_pull", "(", "$", "request", ",", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'name'", "]", ")", ";", "if", "(", "!", "in_array", "(", "'extras'", ",", "$", "fake_field_columns_to_encode", ",", "true", ")", ")", "{", "array_push", "(", "$", "fake_field_columns_to_encode", ",", "'extras'", ")", ";", "}", "}", "}", "}", "// json_encode all fake_value columns in the database, so they can be properly stored and interpreted", "if", "(", "count", "(", "$", "fake_field_columns_to_encode", ")", ")", "{", "foreach", "(", "$", "fake_field_columns_to_encode", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "request", "[", "$", "value", "]", "=", "json_encode", "(", "$", "request", "[", "$", "value", "]", ")", ";", "}", "}", "// if there are no fake fields defined, this will just return the original Request in full", "// since no modifications or additions have been made to $request", "return", "$", "request", ";", "}" ]
Refactor the request array to something that can be passed to the model's create or update function. The resulting array will only include the fields that are stored in the database and their values, plus the '_token' and 'redirect_after_save' variables. @param Request $request - everything that was sent from the form, usually \Request::all() @return array
[ "Refactor", "the", "request", "array", "to", "something", "that", "can", "be", "passed", "to", "the", "model", "s", "create", "or", "update", "function", ".", "The", "resulting", "array", "will", "only", "include", "the", "fields", "that", "are", "stored", "in", "the", "database", "and", "their", "values", "plus", "the", "_token", "and", "redirect_after_save", "variables", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L437-L478
222,608
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.prepareColumns
protected function prepareColumns() { // if the columns aren't set, we can't show this page // TODO: instead of dying, show the columns defined as visible on the model if (!isset($this->crud['columns'])) { abort(500, "CRUD columns are not defined."); } // if the columns are defined as a string, transform it to a proper array if (!is_array($this->crud['columns'])) { $current_columns_array = explode(",", $this->crud['columns']); $proper_columns_array = array(); foreach ($current_columns_array as $key => $col) { $proper_columns_array[] = [ 'name' => $col, 'label' => ucfirst($col) //TODO: also replace _ with space ]; } $this->crud['columns'] = $proper_columns_array; } }
php
protected function prepareColumns() { // if the columns aren't set, we can't show this page // TODO: instead of dying, show the columns defined as visible on the model if (!isset($this->crud['columns'])) { abort(500, "CRUD columns are not defined."); } // if the columns are defined as a string, transform it to a proper array if (!is_array($this->crud['columns'])) { $current_columns_array = explode(",", $this->crud['columns']); $proper_columns_array = array(); foreach ($current_columns_array as $key => $col) { $proper_columns_array[] = [ 'name' => $col, 'label' => ucfirst($col) //TODO: also replace _ with space ]; } $this->crud['columns'] = $proper_columns_array; } }
[ "protected", "function", "prepareColumns", "(", ")", "{", "// if the columns aren't set, we can't show this page", "// TODO: instead of dying, show the columns defined as visible on the model", "if", "(", "!", "isset", "(", "$", "this", "->", "crud", "[", "'columns'", "]", ")", ")", "{", "abort", "(", "500", ",", "\"CRUD columns are not defined.\"", ")", ";", "}", "// if the columns are defined as a string, transform it to a proper array", "if", "(", "!", "is_array", "(", "$", "this", "->", "crud", "[", "'columns'", "]", ")", ")", "{", "$", "current_columns_array", "=", "explode", "(", "\",\"", ",", "$", "this", "->", "crud", "[", "'columns'", "]", ")", ";", "$", "proper_columns_array", "=", "array", "(", ")", ";", "foreach", "(", "$", "current_columns_array", "as", "$", "key", "=>", "$", "col", ")", "{", "$", "proper_columns_array", "[", "]", "=", "[", "'name'", "=>", "$", "col", ",", "'label'", "=>", "ucfirst", "(", "$", "col", ")", "//TODO: also replace _ with space", "]", ";", "}", "$", "this", "->", "crud", "[", "'columns'", "]", "=", "$", "proper_columns_array", ";", "}", "}" ]
If it's not an array of array and it's a simple array, create a proper array of arrays for it
[ "If", "it", "s", "not", "an", "array", "of", "array", "and", "it", "s", "a", "simple", "array", "create", "a", "proper", "array", "of", "arrays", "for", "it" ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L519-L543
222,609
tabacitu/crud
src/Http/Controllers/CrudController.php
CrudController.prepareFields
protected function prepareFields($entry = false) { // if the fields have been defined separately for create and update, use that if (!isset($this->crud['fields'])) { if (isset($this->crud['create_fields'])) { $this->crud['fields'] = $this->crud['create_fields']; } elseif (isset($this->crud['update_fields'])) { $this->crud['fields'] = $this->crud['update_fields']; } } // PREREQUISITES CHECK: // if the fields aren't set, trigger error if (!isset($this->crud['fields'])) { abort(500, "The CRUD fields are not defined."); } // if the fields are defined as a string, transform it to a proper array if (!is_array($this->crud['fields'])) { $current_fields_array = explode(",", $this->crud['fields']); $proper_fields_array = array(); foreach ($current_fields_array as $key => $field) { $proper_fields_array[] = [ 'name' => $field, 'label' => ucfirst($field), // TODO: also replace _ with space 'type' => 'text' // TODO: choose different types of fields depending on the MySQL column type ]; } $this->crud['fields'] = $proper_fields_array; } // if no field type is defined, assume the "text" field type foreach ($this->crud['fields'] as $k => $field) { if (!isset($this->crud['fields'][$k]['type'])) $this->crud['fields'][$k]['type'] = 'text'; } // if an entry was passed, we're preparing for the update form, not create if ($entry) { // put the values in the same 'fields' variable $fields = $this->crud['fields']; foreach ($fields as $k => $field) { // set the value if (!isset($this->crud['fields'][$k]['value'])) { $this->crud['fields'][$k]['value'] = $entry->$field['name']; } } // always have a hidden input for the entry id $this->crud['fields'][] = array( 'name' => 'id', 'value' => $entry->id, 'type' => 'hidden' ); } }
php
protected function prepareFields($entry = false) { // if the fields have been defined separately for create and update, use that if (!isset($this->crud['fields'])) { if (isset($this->crud['create_fields'])) { $this->crud['fields'] = $this->crud['create_fields']; } elseif (isset($this->crud['update_fields'])) { $this->crud['fields'] = $this->crud['update_fields']; } } // PREREQUISITES CHECK: // if the fields aren't set, trigger error if (!isset($this->crud['fields'])) { abort(500, "The CRUD fields are not defined."); } // if the fields are defined as a string, transform it to a proper array if (!is_array($this->crud['fields'])) { $current_fields_array = explode(",", $this->crud['fields']); $proper_fields_array = array(); foreach ($current_fields_array as $key => $field) { $proper_fields_array[] = [ 'name' => $field, 'label' => ucfirst($field), // TODO: also replace _ with space 'type' => 'text' // TODO: choose different types of fields depending on the MySQL column type ]; } $this->crud['fields'] = $proper_fields_array; } // if no field type is defined, assume the "text" field type foreach ($this->crud['fields'] as $k => $field) { if (!isset($this->crud['fields'][$k]['type'])) $this->crud['fields'][$k]['type'] = 'text'; } // if an entry was passed, we're preparing for the update form, not create if ($entry) { // put the values in the same 'fields' variable $fields = $this->crud['fields']; foreach ($fields as $k => $field) { // set the value if (!isset($this->crud['fields'][$k]['value'])) { $this->crud['fields'][$k]['value'] = $entry->$field['name']; } } // always have a hidden input for the entry id $this->crud['fields'][] = array( 'name' => 'id', 'value' => $entry->id, 'type' => 'hidden' ); } }
[ "protected", "function", "prepareFields", "(", "$", "entry", "=", "false", ")", "{", "// if the fields have been defined separately for create and update, use that", "if", "(", "!", "isset", "(", "$", "this", "->", "crud", "[", "'fields'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "crud", "[", "'create_fields'", "]", ")", ")", "{", "$", "this", "->", "crud", "[", "'fields'", "]", "=", "$", "this", "->", "crud", "[", "'create_fields'", "]", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "crud", "[", "'update_fields'", "]", ")", ")", "{", "$", "this", "->", "crud", "[", "'fields'", "]", "=", "$", "this", "->", "crud", "[", "'update_fields'", "]", ";", "}", "}", "// PREREQUISITES CHECK:", "// if the fields aren't set, trigger error", "if", "(", "!", "isset", "(", "$", "this", "->", "crud", "[", "'fields'", "]", ")", ")", "{", "abort", "(", "500", ",", "\"The CRUD fields are not defined.\"", ")", ";", "}", "// if the fields are defined as a string, transform it to a proper array", "if", "(", "!", "is_array", "(", "$", "this", "->", "crud", "[", "'fields'", "]", ")", ")", "{", "$", "current_fields_array", "=", "explode", "(", "\",\"", ",", "$", "this", "->", "crud", "[", "'fields'", "]", ")", ";", "$", "proper_fields_array", "=", "array", "(", ")", ";", "foreach", "(", "$", "current_fields_array", "as", "$", "key", "=>", "$", "field", ")", "{", "$", "proper_fields_array", "[", "]", "=", "[", "'name'", "=>", "$", "field", ",", "'label'", "=>", "ucfirst", "(", "$", "field", ")", ",", "// TODO: also replace _ with space", "'type'", "=>", "'text'", "// TODO: choose different types of fields depending on the MySQL column type", "]", ";", "}", "$", "this", "->", "crud", "[", "'fields'", "]", "=", "$", "proper_fields_array", ";", "}", "// if no field type is defined, assume the \"text\" field type", "foreach", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "as", "$", "k", "=>", "$", "field", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'type'", "]", ")", ")", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'type'", "]", "=", "'text'", ";", "}", "// if an entry was passed, we're preparing for the update form, not create", "if", "(", "$", "entry", ")", "{", "// put the values in the same 'fields' variable", "$", "fields", "=", "$", "this", "->", "crud", "[", "'fields'", "]", ";", "foreach", "(", "$", "fields", "as", "$", "k", "=>", "$", "field", ")", "{", "// set the value", "if", "(", "!", "isset", "(", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'value'", "]", ")", ")", "{", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "$", "k", "]", "[", "'value'", "]", "=", "$", "entry", "->", "$", "field", "[", "'name'", "]", ";", "}", "}", "// always have a hidden input for the entry id", "$", "this", "->", "crud", "[", "'fields'", "]", "[", "]", "=", "array", "(", "'name'", "=>", "'id'", ",", "'value'", "=>", "$", "entry", "->", "id", ",", "'type'", "=>", "'hidden'", ")", ";", "}", "}" ]
Prepare the fields to be shown, stored, updated or created. Makes sure $this->crud['fields'] is in the proper format (array of arrays); Makes sure $this->crud['fields'] also contains the id of the current item; Makes sure $this->crud['fields'] also contains the values for each field;
[ "Prepare", "the", "fields", "to", "be", "shown", "stored", "updated", "or", "created", "." ]
1236e1a51e75b86d48967272064b0f90c62568ad
https://github.com/tabacitu/crud/blob/1236e1a51e75b86d48967272064b0f90c62568ad/src/Http/Controllers/CrudController.php#L553-L618
222,610
dmmlabo/dmm-php-sdk
src/Dmm/HttpClients/CurlHttpClient.php
CurlHttpClient.getHeaderSize
private function getHeaderSize() { $headerSize = $this->dmmCurl->getinfo(CURLINFO_HEADER_SIZE); // This corrects a Curl bug where header size does not account // for additional Proxy headers. if ($this->needsCurlProxyFix()) { // Additional way to calculate the request body size. if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { $headerSize = mb_strlen($this->rawResponse) - $m[1]; } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); } } return $headerSize; }
php
private function getHeaderSize() { $headerSize = $this->dmmCurl->getinfo(CURLINFO_HEADER_SIZE); // This corrects a Curl bug where header size does not account // for additional Proxy headers. if ($this->needsCurlProxyFix()) { // Additional way to calculate the request body size. if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { $headerSize = mb_strlen($this->rawResponse) - $m[1]; } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); } } return $headerSize; }
[ "private", "function", "getHeaderSize", "(", ")", "{", "$", "headerSize", "=", "$", "this", "->", "dmmCurl", "->", "getinfo", "(", "CURLINFO_HEADER_SIZE", ")", ";", "// This corrects a Curl bug where header size does not account", "// for additional Proxy headers.", "if", "(", "$", "this", "->", "needsCurlProxyFix", "(", ")", ")", "{", "// Additional way to calculate the request body size.", "if", "(", "preg_match", "(", "'/Content-Length: (\\d+)/'", ",", "$", "this", "->", "rawResponse", ",", "$", "m", ")", ")", "{", "$", "headerSize", "=", "mb_strlen", "(", "$", "this", "->", "rawResponse", ")", "-", "$", "m", "[", "1", "]", ";", "}", "elseif", "(", "stripos", "(", "$", "this", "->", "rawResponse", ",", "self", "::", "CONNECTION_ESTABLISHED", ")", "!==", "false", ")", "{", "$", "headerSize", "+=", "mb_strlen", "(", "self", "::", "CONNECTION_ESTABLISHED", ")", ";", "}", "}", "return", "$", "headerSize", ";", "}" ]
Return proper header size @return integer
[ "Return", "proper", "header", "size" ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/HttpClients/CurlHttpClient.php#L157-L172
222,611
dmmlabo/dmm-php-sdk
src/Dmm/HttpClients/CurlHttpClient.php
CurlHttpClient.needsCurlProxyFix
private function needsCurlProxyFix() { $ver = $this->dmmCurl->version(); $version = $ver['version_number']; return $version < self::CURL_PROXY_QUIRK_VER; }
php
private function needsCurlProxyFix() { $ver = $this->dmmCurl->version(); $version = $ver['version_number']; return $version < self::CURL_PROXY_QUIRK_VER; }
[ "private", "function", "needsCurlProxyFix", "(", ")", "{", "$", "ver", "=", "$", "this", "->", "dmmCurl", "->", "version", "(", ")", ";", "$", "version", "=", "$", "ver", "[", "'version_number'", "]", ";", "return", "$", "version", "<", "self", "::", "CURL_PROXY_QUIRK_VER", ";", "}" ]
Detect versions of Curl which report incorrect header lengths when using Proxies. @return boolean
[ "Detect", "versions", "of", "Curl", "which", "report", "incorrect", "header", "lengths", "when", "using", "Proxies", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/HttpClients/CurlHttpClient.php#L180-L186
222,612
zackslash/PHP-Web-Article-Extractor
src/Filters/EndBlockFilter.php
EndBlockFilter.stringStartsWithResourceEntry
private static function stringStartsWithResourceEntry($blockText,$resource) { foreach ($resource->resourceContent as $resourceEntry) { if(EndBlockFilter::stringStartsWith($blockText,$resourceEntry)) { return true; } } return false; }
php
private static function stringStartsWithResourceEntry($blockText,$resource) { foreach ($resource->resourceContent as $resourceEntry) { if(EndBlockFilter::stringStartsWith($blockText,$resourceEntry)) { return true; } } return false; }
[ "private", "static", "function", "stringStartsWithResourceEntry", "(", "$", "blockText", ",", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "resourceContent", "as", "$", "resourceEntry", ")", "{", "if", "(", "EndBlockFilter", "::", "stringStartsWith", "(", "$", "blockText", ",", "$", "resourceEntry", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks all resources entries against block text for a 'starts with' qualifier
[ "Checks", "all", "resources", "entries", "against", "block", "text", "for", "a", "starts", "with", "qualifier" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/Filters/EndBlockFilter.php#L102-L112
222,613
zackslash/PHP-Web-Article-Extractor
src/Filters/EndBlockFilter.php
EndBlockFilter.stringContainsResourceEntry
private static function stringContainsResourceEntry($blockText,$resource) { foreach ($resource->resourceContent as $resourceEntry) { if(EndBlockFilter::stringContains($blockText,$resourceEntry)) { return true; } } return false; }
php
private static function stringContainsResourceEntry($blockText,$resource) { foreach ($resource->resourceContent as $resourceEntry) { if(EndBlockFilter::stringContains($blockText,$resourceEntry)) { return true; } } return false; }
[ "private", "static", "function", "stringContainsResourceEntry", "(", "$", "blockText", ",", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "resourceContent", "as", "$", "resourceEntry", ")", "{", "if", "(", "EndBlockFilter", "::", "stringContains", "(", "$", "blockText", ",", "$", "resourceEntry", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks all resource entries against block text for a 'contains' qualifier
[ "Checks", "all", "resource", "entries", "against", "block", "text", "for", "a", "contains", "qualifier" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/Filters/EndBlockFilter.php#L115-L125
222,614
zackslash/PHP-Web-Article-Extractor
src/Filters/EndBlockFilter.php
EndBlockFilter.stringMatchesResourceEntry
private static function stringMatchesResourceEntry($blockText,$resource) { foreach ($resource->resourceContent as $resourceEntry) { if($blockText === $resourceEntry) { return true; } } return false; }
php
private static function stringMatchesResourceEntry($blockText,$resource) { foreach ($resource->resourceContent as $resourceEntry) { if($blockText === $resourceEntry) { return true; } } return false; }
[ "private", "static", "function", "stringMatchesResourceEntry", "(", "$", "blockText", ",", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "resourceContent", "as", "$", "resourceEntry", ")", "{", "if", "(", "$", "blockText", "===", "$", "resourceEntry", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks all resource entries against block text for a complete match
[ "Checks", "all", "resource", "entries", "against", "block", "text", "for", "a", "complete", "match" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/Filters/EndBlockFilter.php#L128-L138
222,615
zackslash/PHP-Web-Article-Extractor
src/Filters/EndBlockFilter.php
EndBlockFilter.stringStartsWithNumberFollowedByResource
private static function stringStartsWithNumberFollowedByResource($inString,$resource) { $followingTextArray = $resource->resourceContent; $count = 0; foreach (str_split($inString) as $character) { if(EndBlockFilter::characterIsDigit($character)) { $count++; } else { break; } } if($count > 0) { foreach ($followingTextArray as $followingEntry) { $formStr = sprintf('%s %s',$count,$followingEntry); if (0 === strpos($inString, $formStr)) { return true; } } } return false; }
php
private static function stringStartsWithNumberFollowedByResource($inString,$resource) { $followingTextArray = $resource->resourceContent; $count = 0; foreach (str_split($inString) as $character) { if(EndBlockFilter::characterIsDigit($character)) { $count++; } else { break; } } if($count > 0) { foreach ($followingTextArray as $followingEntry) { $formStr = sprintf('%s %s',$count,$followingEntry); if (0 === strpos($inString, $formStr)) { return true; } } } return false; }
[ "private", "static", "function", "stringStartsWithNumberFollowedByResource", "(", "$", "inString", ",", "$", "resource", ")", "{", "$", "followingTextArray", "=", "$", "resource", "->", "resourceContent", ";", "$", "count", "=", "0", ";", "foreach", "(", "str_split", "(", "$", "inString", ")", "as", "$", "character", ")", "{", "if", "(", "EndBlockFilter", "::", "characterIsDigit", "(", "$", "character", ")", ")", "{", "$", "count", "++", ";", "}", "else", "{", "break", ";", "}", "}", "if", "(", "$", "count", ">", "0", ")", "{", "foreach", "(", "$", "followingTextArray", "as", "$", "followingEntry", ")", "{", "$", "formStr", "=", "sprintf", "(", "'%s %s'", ",", "$", "count", ",", "$", "followingEntry", ")", ";", "if", "(", "0", "===", "strpos", "(", "$", "inString", ",", "$", "formStr", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Checks if text matches a specific format i.e '23 comments'
[ "Checks", "if", "text", "matches", "a", "specific", "format", "i", ".", "e", "23", "comments" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/Filters/EndBlockFilter.php#L141-L171
222,616
zackslash/PHP-Web-Article-Extractor
src/ResourceProvider.php
ResourceProvider.loadResource
public function loadResource($resourceName) { $resourceLocation = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."res".DIRECTORY_SEPARATOR.$resourceName; $this->resourceContent = $this->readResourceToArray($resourceLocation); }
php
public function loadResource($resourceName) { $resourceLocation = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."res".DIRECTORY_SEPARATOR.$resourceName; $this->resourceContent = $this->readResourceToArray($resourceLocation); }
[ "public", "function", "loadResource", "(", "$", "resourceName", ")", "{", "$", "resourceLocation", "=", "dirname", "(", "__FILE__", ")", ".", "DIRECTORY_SEPARATOR", ".", "\"..\"", ".", "DIRECTORY_SEPARATOR", ".", "\"res\"", ".", "DIRECTORY_SEPARATOR", ".", "$", "resourceName", ";", "$", "this", "->", "resourceContent", "=", "$", "this", "->", "readResourceToArray", "(", "$", "resourceLocation", ")", ";", "}" ]
Loads resource into memory by name only into this instance's resourceContent @param string $resourceName name of the resource to load.
[ "Loads", "resource", "into", "memory", "by", "name", "only", "into", "this", "instance", "s", "resourceContent" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/ResourceProvider.php#L74-L78
222,617
zackslash/PHP-Web-Article-Extractor
src/ResourceProvider.php
ResourceProvider.loadResourceDirectory
public function loadResourceDirectory($directoryName) { $resourceLocation = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."res".DIRECTORY_SEPARATOR.$directoryName; $results = array(); foreach (scandir($resourceLocation) as $file) { //Only load file if it has a .lst extention (list) if((($temp = strlen($file) - strlen(".lst")) >= 0 && strpos($file, ".lst", $temp) !== FALSE)) { $fileEntry = array(); $fileKey = str_replace(".lst","",$file); $fileEntry[0] = $fileKey; $fileEntry[1] = $this->readResourceToArray($resourceLocation.DIRECTORY_SEPARATOR.$file); $results[] = $fileEntry; } } $this->resourceContent = $results; }
php
public function loadResourceDirectory($directoryName) { $resourceLocation = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."res".DIRECTORY_SEPARATOR.$directoryName; $results = array(); foreach (scandir($resourceLocation) as $file) { //Only load file if it has a .lst extention (list) if((($temp = strlen($file) - strlen(".lst")) >= 0 && strpos($file, ".lst", $temp) !== FALSE)) { $fileEntry = array(); $fileKey = str_replace(".lst","",$file); $fileEntry[0] = $fileKey; $fileEntry[1] = $this->readResourceToArray($resourceLocation.DIRECTORY_SEPARATOR.$file); $results[] = $fileEntry; } } $this->resourceContent = $results; }
[ "public", "function", "loadResourceDirectory", "(", "$", "directoryName", ")", "{", "$", "resourceLocation", "=", "dirname", "(", "__FILE__", ")", ".", "DIRECTORY_SEPARATOR", ".", "\"..\"", ".", "DIRECTORY_SEPARATOR", ".", "\"res\"", ".", "DIRECTORY_SEPARATOR", ".", "$", "directoryName", ";", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "scandir", "(", "$", "resourceLocation", ")", "as", "$", "file", ")", "{", "//Only load file if it has a .lst extention (list)", "if", "(", "(", "(", "$", "temp", "=", "strlen", "(", "$", "file", ")", "-", "strlen", "(", "\".lst\"", ")", ")", ">=", "0", "&&", "strpos", "(", "$", "file", ",", "\".lst\"", ",", "$", "temp", ")", "!==", "FALSE", ")", ")", "{", "$", "fileEntry", "=", "array", "(", ")", ";", "$", "fileKey", "=", "str_replace", "(", "\".lst\"", ",", "\"\"", ",", "$", "file", ")", ";", "$", "fileEntry", "[", "0", "]", "=", "$", "fileKey", ";", "$", "fileEntry", "[", "1", "]", "=", "$", "this", "->", "readResourceToArray", "(", "$", "resourceLocation", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ")", ";", "$", "results", "[", "]", "=", "$", "fileEntry", ";", "}", "}", "$", "this", "->", "resourceContent", "=", "$", "results", ";", "}" ]
Loads all resources found in a directory into memory by name only into this instance's resourceContent @param string $resourceName name of the directory to load
[ "Loads", "all", "resources", "found", "in", "a", "directory", "into", "memory", "by", "name", "only", "into", "this", "instance", "s", "resourceContent" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/ResourceProvider.php#L85-L103
222,618
joomla-framework/form
src/Field/ListField.php
ListField.getInput
protected function getInput() { $html = array(); $attr = ''; $select = new HtmlSelect; // Try to inject the text object into the field try { $select->setText($this->getText()); } catch (\RuntimeException $exception) { // A Text object was not set, ignore the error and try to continue processing } // Initialize some field attributes. $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; // To avoid user's confusion, readonly="true" should imply disabled="true". if ((string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true') { $attr .= ' disabled="disabled"'; } $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $attr .= $this->multiple ? ' multiple="multiple"' : ''; // Initialize JavaScript field attributes. $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; // Get the field options. $options = (array) $this->getOptions(); // Create a read-only list (no name) with a hidden input to store the value. if ((string) $this->element['readonly'] == 'true') { $html[] = $select->genericlist($options, '', trim($attr), 'value', 'text', $this->value, $this->id); $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>'; } else // Create a regular list. { $html[] = $select->genericlist($options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id); } return implode($html); }
php
protected function getInput() { $html = array(); $attr = ''; $select = new HtmlSelect; // Try to inject the text object into the field try { $select->setText($this->getText()); } catch (\RuntimeException $exception) { // A Text object was not set, ignore the error and try to continue processing } // Initialize some field attributes. $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; // To avoid user's confusion, readonly="true" should imply disabled="true". if ((string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true') { $attr .= ' disabled="disabled"'; } $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $attr .= $this->multiple ? ' multiple="multiple"' : ''; // Initialize JavaScript field attributes. $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; // Get the field options. $options = (array) $this->getOptions(); // Create a read-only list (no name) with a hidden input to store the value. if ((string) $this->element['readonly'] == 'true') { $html[] = $select->genericlist($options, '', trim($attr), 'value', 'text', $this->value, $this->id); $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>'; } else // Create a regular list. { $html[] = $select->genericlist($options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id); } return implode($html); }
[ "protected", "function", "getInput", "(", ")", "{", "$", "html", "=", "array", "(", ")", ";", "$", "attr", "=", "''", ";", "$", "select", "=", "new", "HtmlSelect", ";", "// Try to inject the text object into the field", "try", "{", "$", "select", "->", "setText", "(", "$", "this", "->", "getText", "(", ")", ")", ";", "}", "catch", "(", "\\", "RuntimeException", "$", "exception", ")", "{", "// A Text object was not set, ignore the error and try to continue processing", "}", "// Initialize some field attributes.", "$", "attr", ".=", "$", "this", "->", "element", "[", "'class'", "]", "?", "' class=\"'", ".", "(", "string", ")", "$", "this", "->", "element", "[", "'class'", "]", ".", "'\"'", ":", "''", ";", "// To avoid user's confusion, readonly=\"true\" should imply disabled=\"true\".", "if", "(", "(", "string", ")", "$", "this", "->", "element", "[", "'readonly'", "]", "==", "'true'", "||", "(", "string", ")", "$", "this", "->", "element", "[", "'disabled'", "]", "==", "'true'", ")", "{", "$", "attr", ".=", "' disabled=\"disabled\"'", ";", "}", "$", "attr", ".=", "$", "this", "->", "element", "[", "'size'", "]", "?", "' size=\"'", ".", "(", "int", ")", "$", "this", "->", "element", "[", "'size'", "]", ".", "'\"'", ":", "''", ";", "$", "attr", ".=", "$", "this", "->", "multiple", "?", "' multiple=\"multiple\"'", ":", "''", ";", "// Initialize JavaScript field attributes.", "$", "attr", ".=", "$", "this", "->", "element", "[", "'onchange'", "]", "?", "' onchange=\"'", ".", "(", "string", ")", "$", "this", "->", "element", "[", "'onchange'", "]", ".", "'\"'", ":", "''", ";", "// Get the field options.", "$", "options", "=", "(", "array", ")", "$", "this", "->", "getOptions", "(", ")", ";", "// Create a read-only list (no name) with a hidden input to store the value.", "if", "(", "(", "string", ")", "$", "this", "->", "element", "[", "'readonly'", "]", "==", "'true'", ")", "{", "$", "html", "[", "]", "=", "$", "select", "->", "genericlist", "(", "$", "options", ",", "''", ",", "trim", "(", "$", "attr", ")", ",", "'value'", ",", "'text'", ",", "$", "this", "->", "value", ",", "$", "this", "->", "id", ")", ";", "$", "html", "[", "]", "=", "'<input type=\"hidden\" name=\"'", ".", "$", "this", "->", "name", ".", "'\" value=\"'", ".", "$", "this", "->", "value", ".", "'\"/>'", ";", "}", "else", "// Create a regular list.", "{", "$", "html", "[", "]", "=", "$", "select", "->", "genericlist", "(", "$", "options", ",", "$", "this", "->", "name", ",", "trim", "(", "$", "attr", ")", ",", "'value'", ",", "'text'", ",", "$", "this", "->", "value", ",", "$", "this", "->", "id", ")", ";", "}", "return", "implode", "(", "$", "html", ")", ";", "}" ]
Method to get the field input markup for a generic list. Use the multiple attribute to enable multiselect. @return string The field input markup. @since 1.0
[ "Method", "to", "get", "the", "field", "input", "markup", "for", "a", "generic", "list", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Field/ListField.php#L40-L88
222,619
enygma/yubikey
src/Yubikey/Validate.php
Validate.getApiKey
public function getApiKey($decoded = false) { return ($decoded === false) ? $this->apiKey : base64_decode($this->apiKey); }
php
public function getApiKey($decoded = false) { return ($decoded === false) ? $this->apiKey : base64_decode($this->apiKey); }
[ "public", "function", "getApiKey", "(", "$", "decoded", "=", "false", ")", "{", "return", "(", "$", "decoded", "===", "false", ")", "?", "$", "this", "->", "apiKey", ":", "base64_decode", "(", "$", "this", "->", "apiKey", ")", ";", "}" ]
Get the currently set API key @return string API key
[ "Get", "the", "currently", "set", "API", "key" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Validate.php#L86-L89
222,620
enygma/yubikey
src/Yubikey/Validate.php
Validate.setApiKey
public function setApiKey($apiKey) { $key = base64_decode($apiKey, true); if ($key === false) { throw new \InvalidArgumentException('Invalid API key'); } $this->apiKey = $key; return $this; }
php
public function setApiKey($apiKey) { $key = base64_decode($apiKey, true); if ($key === false) { throw new \InvalidArgumentException('Invalid API key'); } $this->apiKey = $key; return $this; }
[ "public", "function", "setApiKey", "(", "$", "apiKey", ")", "{", "$", "key", "=", "base64_decode", "(", "$", "apiKey", ",", "true", ")", ";", "if", "(", "$", "key", "===", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid API key'", ")", ";", "}", "$", "this", "->", "apiKey", "=", "$", "key", ";", "return", "$", "this", ";", "}" ]
Set the API key @param string $apiKey API request key
[ "Set", "the", "API", "key" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Validate.php#L96-L105
222,621
enygma/yubikey
src/Yubikey/Validate.php
Validate.getHost
public function getHost() { if ($this->host === null) { // pick a "random" host $host = $this->hosts[mt_rand(0,count($this->hosts)-1)]; $this->setHost($host); return $host; } else { return $this->host; } }
php
public function getHost() { if ($this->host === null) { // pick a "random" host $host = $this->hosts[mt_rand(0,count($this->hosts)-1)]; $this->setHost($host); return $host; } else { return $this->host; } }
[ "public", "function", "getHost", "(", ")", "{", "if", "(", "$", "this", "->", "host", "===", "null", ")", "{", "// pick a \"random\" host", "$", "host", "=", "$", "this", "->", "hosts", "[", "mt_rand", "(", "0", ",", "count", "(", "$", "this", "->", "hosts", ")", "-", "1", ")", "]", ";", "$", "this", "->", "setHost", "(", "$", "host", ")", ";", "return", "$", "host", ";", "}", "else", "{", "return", "$", "this", "->", "host", ";", "}", "}" ]
Get the host for the request If one is not set, it returns a random one from the host set @return string Hostname string
[ "Get", "the", "host", "for", "the", "request", "If", "one", "is", "not", "set", "it", "returns", "a", "random", "one", "from", "the", "host", "set" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Validate.php#L180-L190
222,622
enygma/yubikey
src/Yubikey/Validate.php
Validate.generateSignature
public function generateSignature($data, $key = null) { if ($key === null) { $key = $this->getApiKey(); if ($key === null || empty($key)) { throw new \InvalidArgumentException('Invalid API key!'); } } $query = http_build_query($data); $query = utf8_encode(str_replace('%3A', ':', $query)); $hash = preg_replace( '/\+/', '%2B', // base64_encode(hash_hmac('sha1', http_build_query($data), $key, true)) base64_encode(hash_hmac('sha1', $query, $key, true)) ); return $hash; }
php
public function generateSignature($data, $key = null) { if ($key === null) { $key = $this->getApiKey(); if ($key === null || empty($key)) { throw new \InvalidArgumentException('Invalid API key!'); } } $query = http_build_query($data); $query = utf8_encode(str_replace('%3A', ':', $query)); $hash = preg_replace( '/\+/', '%2B', // base64_encode(hash_hmac('sha1', http_build_query($data), $key, true)) base64_encode(hash_hmac('sha1', $query, $key, true)) ); return $hash; }
[ "public", "function", "generateSignature", "(", "$", "data", ",", "$", "key", "=", "null", ")", "{", "if", "(", "$", "key", "===", "null", ")", "{", "$", "key", "=", "$", "this", "->", "getApiKey", "(", ")", ";", "if", "(", "$", "key", "===", "null", "||", "empty", "(", "$", "key", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid API key!'", ")", ";", "}", "}", "$", "query", "=", "http_build_query", "(", "$", "data", ")", ";", "$", "query", "=", "utf8_encode", "(", "str_replace", "(", "'%3A'", ",", "':'", ",", "$", "query", ")", ")", ";", "$", "hash", "=", "preg_replace", "(", "'/\\+/'", ",", "'%2B'", ",", "// base64_encode(hash_hmac('sha1', http_build_query($data), $key, true))", "base64_encode", "(", "hash_hmac", "(", "'sha1'", ",", "$", "query", ",", "$", "key", ",", "true", ")", ")", ")", ";", "return", "$", "hash", ";", "}" ]
Geenrate the signature for the request values @param array $data Data for request @throws \InvalidArgumentException when API key is invalid @return Hashed request signature (string)
[ "Geenrate", "the", "signature", "for", "the", "request", "values" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Validate.php#L241-L259
222,623
enygma/yubikey
src/Yubikey/Validate.php
Validate.check
public function check($otp, $multi = false) { $otp = trim($otp); if (strlen($otp) < 32 || strlen($otp) > 48) { throw new \InvalidArgumentException('Invalid OTP length'); } $this->setOtp($otp); $this->setYubikeyId(); $clientId = $this->getClientId(); if ($clientId === null) { throw new \InvalidArgumentException('Client ID cannot be null'); } $nonce = $this->generateNonce(); $params = array( 'id' => $clientId, 'otp' => $otp, 'nonce' => $nonce, 'timestamp' => '1' ); ksort($params); $url = '/wsapi/2.0/verify?'.http_build_query($params).'&h='.$this->generateSignature($params); $hosts = ($multi === false) ? array(array_shift($this->hosts)) : $this->hosts; return $this->request($url, $hosts, $otp, $nonce); }
php
public function check($otp, $multi = false) { $otp = trim($otp); if (strlen($otp) < 32 || strlen($otp) > 48) { throw new \InvalidArgumentException('Invalid OTP length'); } $this->setOtp($otp); $this->setYubikeyId(); $clientId = $this->getClientId(); if ($clientId === null) { throw new \InvalidArgumentException('Client ID cannot be null'); } $nonce = $this->generateNonce(); $params = array( 'id' => $clientId, 'otp' => $otp, 'nonce' => $nonce, 'timestamp' => '1' ); ksort($params); $url = '/wsapi/2.0/verify?'.http_build_query($params).'&h='.$this->generateSignature($params); $hosts = ($multi === false) ? array(array_shift($this->hosts)) : $this->hosts; return $this->request($url, $hosts, $otp, $nonce); }
[ "public", "function", "check", "(", "$", "otp", ",", "$", "multi", "=", "false", ")", "{", "$", "otp", "=", "trim", "(", "$", "otp", ")", ";", "if", "(", "strlen", "(", "$", "otp", ")", "<", "32", "||", "strlen", "(", "$", "otp", ")", ">", "48", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid OTP length'", ")", ";", "}", "$", "this", "->", "setOtp", "(", "$", "otp", ")", ";", "$", "this", "->", "setYubikeyId", "(", ")", ";", "$", "clientId", "=", "$", "this", "->", "getClientId", "(", ")", ";", "if", "(", "$", "clientId", "===", "null", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Client ID cannot be null'", ")", ";", "}", "$", "nonce", "=", "$", "this", "->", "generateNonce", "(", ")", ";", "$", "params", "=", "array", "(", "'id'", "=>", "$", "clientId", ",", "'otp'", "=>", "$", "otp", ",", "'nonce'", "=>", "$", "nonce", ",", "'timestamp'", "=>", "'1'", ")", ";", "ksort", "(", "$", "params", ")", ";", "$", "url", "=", "'/wsapi/2.0/verify?'", ".", "http_build_query", "(", "$", "params", ")", ".", "'&h='", ".", "$", "this", "->", "generateSignature", "(", "$", "params", ")", ";", "$", "hosts", "=", "(", "$", "multi", "===", "false", ")", "?", "array", "(", "array_shift", "(", "$", "this", "->", "hosts", ")", ")", ":", "$", "this", "->", "hosts", ";", "return", "$", "this", "->", "request", "(", "$", "url", ",", "$", "hosts", ",", "$", "otp", ",", "$", "nonce", ")", ";", "}" ]
Check the One-time Password with API request @param string $otp One-time password @param integer $clientId Client ID for API @throws \InvalidArgumentException when OTP length is invalid @return \Yubikey\Response object
[ "Check", "the", "One", "-", "time", "Password", "with", "API", "request" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Validate.php#L269-L297
222,624
enygma/yubikey
src/Yubikey/Validate.php
Validate.generateNonce
public function generateNonce() { if (function_exists('openssl_random_pseudo_bytes') === true) { $hash = md5(openssl_random_pseudo_bytes(32)); } else { $hash = md5(uniqid(mt_rand())); } return $hash; }
php
public function generateNonce() { if (function_exists('openssl_random_pseudo_bytes') === true) { $hash = md5(openssl_random_pseudo_bytes(32)); } else { $hash = md5(uniqid(mt_rand())); } return $hash; }
[ "public", "function", "generateNonce", "(", ")", "{", "if", "(", "function_exists", "(", "'openssl_random_pseudo_bytes'", ")", "===", "true", ")", "{", "$", "hash", "=", "md5", "(", "openssl_random_pseudo_bytes", "(", "32", ")", ")", ";", "}", "else", "{", "$", "hash", "=", "md5", "(", "uniqid", "(", "mt_rand", "(", ")", ")", ")", ";", "}", "return", "$", "hash", ";", "}" ]
Generate a good nonce for the request @return string Generated hash
[ "Generate", "a", "good", "nonce", "for", "the", "request" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Validate.php#L304-L312
222,625
enygma/yubikey
src/Yubikey/Validate.php
Validate.validateResponseSignature
public function validateResponseSignature(\Yubikey\Response $response) { $params = array(); foreach ($response->getProperties() as $property) { $value = $response->$property; if ($value !== null) { $params[$property] = $value; } } ksort($params); $signature = $this->generateSignature($params); return $this->hash_equals($signature, $response->getHash(true)); }
php
public function validateResponseSignature(\Yubikey\Response $response) { $params = array(); foreach ($response->getProperties() as $property) { $value = $response->$property; if ($value !== null) { $params[$property] = $value; } } ksort($params); $signature = $this->generateSignature($params); return $this->hash_equals($signature, $response->getHash(true)); }
[ "public", "function", "validateResponseSignature", "(", "\\", "Yubikey", "\\", "Response", "$", "response", ")", "{", "$", "params", "=", "array", "(", ")", ";", "foreach", "(", "$", "response", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "$", "value", "=", "$", "response", "->", "$", "property", ";", "if", "(", "$", "value", "!==", "null", ")", "{", "$", "params", "[", "$", "property", "]", "=", "$", "value", ";", "}", "}", "ksort", "(", "$", "params", ")", ";", "$", "signature", "=", "$", "this", "->", "generateSignature", "(", "$", "params", ")", ";", "return", "$", "this", "->", "hash_equals", "(", "$", "signature", ",", "$", "response", "->", "getHash", "(", "true", ")", ")", ";", "}" ]
Validate the signature on the response @param \Yubikey\Response $response Response instance @return boolean Pass/fail status of signature validation
[ "Validate", "the", "signature", "on", "the", "response" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Validate.php#L354-L367
222,626
mickgeek/yii2-actionbar
Widget.php
Widget.initDefaultElements
protected function initDefaultElements() { if (!isset($this->elements['bulk-actions'])) { if ($this->bulkActionsPrompt === null) { $this->bulkActionsPrompt = $this->t('widget', 'Bulk Actions'); } if (empty($this->bulkActionsItems)) { $this->bulkActionsItems = [ $this->t('widget', 'General') => [ 'general-delete' => $this->t('widget', 'Delete'), ], ]; } if (isset($this->bulkActionsOptions['id'])) { $this->_bulkActionsId = $this->bulkActionsOptions['id']; } if (!isset($this->bulkActionsOptions['options'])) { $this->bulkActionsOptions = ArrayHelper::merge($this->bulkActionsOptions, [ 'options' => [ 'general-delete' => [ 'url' => Url::toRoute('delete-multiple'), 'data-confirm' => $this->t('widget', 'Are you sure you want to delete these items?'), ], ], ]); } $this->elements['bulk-actions'] = Html::dropDownList('bulkactions', null, $this->bulkActionsItems, ArrayHelper::merge([ 'prompt' => $this->bulkActionsPrompt, 'id' => $this->_bulkActionsId, 'disabled' => $this->grid === null, ], $this->bulkActionsOptions) ); } if (!isset($this->elements['create'])) { $this->elements['create'] = Html::a( '<span class="glyphicon glyphicon-plus-sign"></span> ' . $this->t('widget', 'Create New'), Url::toRoute('create'), ['class' => 'btn btn-default'] ); } }
php
protected function initDefaultElements() { if (!isset($this->elements['bulk-actions'])) { if ($this->bulkActionsPrompt === null) { $this->bulkActionsPrompt = $this->t('widget', 'Bulk Actions'); } if (empty($this->bulkActionsItems)) { $this->bulkActionsItems = [ $this->t('widget', 'General') => [ 'general-delete' => $this->t('widget', 'Delete'), ], ]; } if (isset($this->bulkActionsOptions['id'])) { $this->_bulkActionsId = $this->bulkActionsOptions['id']; } if (!isset($this->bulkActionsOptions['options'])) { $this->bulkActionsOptions = ArrayHelper::merge($this->bulkActionsOptions, [ 'options' => [ 'general-delete' => [ 'url' => Url::toRoute('delete-multiple'), 'data-confirm' => $this->t('widget', 'Are you sure you want to delete these items?'), ], ], ]); } $this->elements['bulk-actions'] = Html::dropDownList('bulkactions', null, $this->bulkActionsItems, ArrayHelper::merge([ 'prompt' => $this->bulkActionsPrompt, 'id' => $this->_bulkActionsId, 'disabled' => $this->grid === null, ], $this->bulkActionsOptions) ); } if (!isset($this->elements['create'])) { $this->elements['create'] = Html::a( '<span class="glyphicon glyphicon-plus-sign"></span> ' . $this->t('widget', 'Create New'), Url::toRoute('create'), ['class' => 'btn btn-default'] ); } }
[ "protected", "function", "initDefaultElements", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "elements", "[", "'bulk-actions'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "bulkActionsPrompt", "===", "null", ")", "{", "$", "this", "->", "bulkActionsPrompt", "=", "$", "this", "->", "t", "(", "'widget'", ",", "'Bulk Actions'", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "bulkActionsItems", ")", ")", "{", "$", "this", "->", "bulkActionsItems", "=", "[", "$", "this", "->", "t", "(", "'widget'", ",", "'General'", ")", "=>", "[", "'general-delete'", "=>", "$", "this", "->", "t", "(", "'widget'", ",", "'Delete'", ")", ",", "]", ",", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "bulkActionsOptions", "[", "'id'", "]", ")", ")", "{", "$", "this", "->", "_bulkActionsId", "=", "$", "this", "->", "bulkActionsOptions", "[", "'id'", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "bulkActionsOptions", "[", "'options'", "]", ")", ")", "{", "$", "this", "->", "bulkActionsOptions", "=", "ArrayHelper", "::", "merge", "(", "$", "this", "->", "bulkActionsOptions", ",", "[", "'options'", "=>", "[", "'general-delete'", "=>", "[", "'url'", "=>", "Url", "::", "toRoute", "(", "'delete-multiple'", ")", ",", "'data-confirm'", "=>", "$", "this", "->", "t", "(", "'widget'", ",", "'Are you sure you want to delete these items?'", ")", ",", "]", ",", "]", ",", "]", ")", ";", "}", "$", "this", "->", "elements", "[", "'bulk-actions'", "]", "=", "Html", "::", "dropDownList", "(", "'bulkactions'", ",", "null", ",", "$", "this", "->", "bulkActionsItems", ",", "ArrayHelper", "::", "merge", "(", "[", "'prompt'", "=>", "$", "this", "->", "bulkActionsPrompt", ",", "'id'", "=>", "$", "this", "->", "_bulkActionsId", ",", "'disabled'", "=>", "$", "this", "->", "grid", "===", "null", ",", "]", ",", "$", "this", "->", "bulkActionsOptions", ")", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "elements", "[", "'create'", "]", ")", ")", "{", "$", "this", "->", "elements", "[", "'create'", "]", "=", "Html", "::", "a", "(", "'<span class=\"glyphicon glyphicon-plus-sign\"></span> '", ".", "$", "this", "->", "t", "(", "'widget'", ",", "'Create New'", ")", ",", "Url", "::", "toRoute", "(", "'create'", ")", ",", "[", "'class'", "=>", "'btn btn-default'", "]", ")", ";", "}", "}" ]
Initializes the default elements.
[ "Initializes", "the", "default", "elements", "." ]
028f38229bfee69ced4748f2cb869c5d4a630436
https://github.com/mickgeek/yii2-actionbar/blob/028f38229bfee69ced4748f2cb869c5d4a630436/Widget.php#L133-L175
222,627
mickgeek/yii2-actionbar
Widget.php
Widget.renderElements
protected function renderElements($template) { return preg_replace_callback('/\\{([\w\-\/]+)\\}/', function ($matches) { $name = $matches[1]; if (isset($this->elements[$name])) { if ($name === 'bulk-actions' && $this->grid !== null) { $id = $this->options['id']; $this->view->registerJs("$('#{$id} #{$this->_bulkActionsId}').change(function() { if (this.value) { var ids = $('#{$this->grid}').yiiGridView('getSelectedRows'), options = this.options[this.selectedIndex], dataConfirm = options.getAttribute('data-confirm'), url = options.getAttribute('url'); if (!ids.length) { alert('" . $this->t('widget', 'Please select one or more items from the list.') . "'); this.value = ''; } else if (dataConfirm && !confirm(dataConfirm)) { this.value = ''; return; } else if (url) { var form = $('<form action=' + url + ' method=\"POST\"></form>'), csrfParam = $('meta[name=csrf-param]').prop('content'), csrfToken = $('meta[name=csrf-token]').prop('content'); if (csrfParam) { form.append('<input type=\"hidden\" name=' + csrfParam + ' value=' + csrfToken + ' />'); } $.each(ids, function(index, id) { form.append('<input type=\"hidden\" name=\"' + (options.getAttribute('name') ? options.getAttribute('name') : 'ids') + '[]\" value=' + id + ' />'); }); form.appendTo('body').submit(); } } });"); } return $this->elements[$name]; } else { return ''; } }, $template); }
php
protected function renderElements($template) { return preg_replace_callback('/\\{([\w\-\/]+)\\}/', function ($matches) { $name = $matches[1]; if (isset($this->elements[$name])) { if ($name === 'bulk-actions' && $this->grid !== null) { $id = $this->options['id']; $this->view->registerJs("$('#{$id} #{$this->_bulkActionsId}').change(function() { if (this.value) { var ids = $('#{$this->grid}').yiiGridView('getSelectedRows'), options = this.options[this.selectedIndex], dataConfirm = options.getAttribute('data-confirm'), url = options.getAttribute('url'); if (!ids.length) { alert('" . $this->t('widget', 'Please select one or more items from the list.') . "'); this.value = ''; } else if (dataConfirm && !confirm(dataConfirm)) { this.value = ''; return; } else if (url) { var form = $('<form action=' + url + ' method=\"POST\"></form>'), csrfParam = $('meta[name=csrf-param]').prop('content'), csrfToken = $('meta[name=csrf-token]').prop('content'); if (csrfParam) { form.append('<input type=\"hidden\" name=' + csrfParam + ' value=' + csrfToken + ' />'); } $.each(ids, function(index, id) { form.append('<input type=\"hidden\" name=\"' + (options.getAttribute('name') ? options.getAttribute('name') : 'ids') + '[]\" value=' + id + ' />'); }); form.appendTo('body').submit(); } } });"); } return $this->elements[$name]; } else { return ''; } }, $template); }
[ "protected", "function", "renderElements", "(", "$", "template", ")", "{", "return", "preg_replace_callback", "(", "'/\\\\{([\\w\\-\\/]+)\\\\}/'", ",", "function", "(", "$", "matches", ")", "{", "$", "name", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "elements", "[", "$", "name", "]", ")", ")", "{", "if", "(", "$", "name", "===", "'bulk-actions'", "&&", "$", "this", "->", "grid", "!==", "null", ")", "{", "$", "id", "=", "$", "this", "->", "options", "[", "'id'", "]", ";", "$", "this", "->", "view", "->", "registerJs", "(", "\"$('#{$id} #{$this->_bulkActionsId}').change(function() {\n if (this.value) {\n var ids = $('#{$this->grid}').yiiGridView('getSelectedRows'),\n options = this.options[this.selectedIndex],\n dataConfirm = options.getAttribute('data-confirm'),\n url = options.getAttribute('url');\n\n if (!ids.length) {\n alert('\"", ".", "$", "this", "->", "t", "(", "'widget'", ",", "'Please select one or more items from the list.'", ")", ".", "\"');\n this.value = '';\n } else if (dataConfirm && !confirm(dataConfirm)) {\n this.value = '';\n return;\n } else if (url) {\n var form = $('<form action=' + url + ' method=\\\"POST\\\"></form>'),\n csrfParam = $('meta[name=csrf-param]').prop('content'),\n csrfToken = $('meta[name=csrf-token]').prop('content');\n\n if (csrfParam) {\n form.append('<input type=\\\"hidden\\\" name=' + csrfParam + ' value=' + csrfToken + ' />');\n }\n $.each(ids, function(index, id) {\n form.append('<input type=\\\"hidden\\\" name=\\\"' + (options.getAttribute('name') ? options.getAttribute('name') : 'ids') + '[]\\\" value=' + id + ' />');\n });\n form.appendTo('body').submit();\n }\n }\n });\"", ")", ";", "}", "return", "$", "this", "->", "elements", "[", "$", "name", "]", ";", "}", "else", "{", "return", "''", ";", "}", "}", ",", "$", "template", ")", ";", "}" ]
Renders elements. @param string $template the elements template. @return string the rendering result.
[ "Renders", "elements", "." ]
028f38229bfee69ced4748f2cb869c5d4a630436
https://github.com/mickgeek/yii2-actionbar/blob/028f38229bfee69ced4748f2cb869c5d4a630436/Widget.php#L207-L249
222,628
enygma/yubikey
src/Yubikey/Request.php
Request.setUrl
public function setUrl($url) { if (filter_var($url, FILTER_VALIDATE_URL) !== $url) { throw new \Exception('Invalid URL: '.$url); } $this->url = $url; }
php
public function setUrl($url) { if (filter_var($url, FILTER_VALIDATE_URL) !== $url) { throw new \Exception('Invalid URL: '.$url); } $this->url = $url; }
[ "public", "function", "setUrl", "(", "$", "url", ")", "{", "if", "(", "filter_var", "(", "$", "url", ",", "FILTER_VALIDATE_URL", ")", "!==", "$", "url", ")", "{", "throw", "new", "\\", "Exception", "(", "'Invalid URL: '", ".", "$", "url", ")", ";", "}", "$", "this", "->", "url", "=", "$", "url", ";", "}" ]
Set the URL location for the request @param string $url URL location
[ "Set", "the", "URL", "location", "for", "the", "request" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Request.php#L66-L72
222,629
dmmlabo/dmm-php-sdk
src/Dmm/HttpClients/GuzzleHttpClient.php
GuzzleHttpClient.getHeadersAsString
public function getHeadersAsString(ResponseInterface $response) { $headers = $response->getHeaders(); $rawHeaders = []; foreach ($headers as $name => $values) { $rawHeaders[] = $name . ": " . implode(", ", $values); } return implode("\r\n", $rawHeaders); }
php
public function getHeadersAsString(ResponseInterface $response) { $headers = $response->getHeaders(); $rawHeaders = []; foreach ($headers as $name => $values) { $rawHeaders[] = $name . ": " . implode(", ", $values); } return implode("\r\n", $rawHeaders); }
[ "public", "function", "getHeadersAsString", "(", "ResponseInterface", "$", "response", ")", "{", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "$", "rawHeaders", "=", "[", "]", ";", "foreach", "(", "$", "headers", "as", "$", "name", "=>", "$", "values", ")", "{", "$", "rawHeaders", "[", "]", "=", "$", "name", ".", "\": \"", ".", "implode", "(", "\", \"", ",", "$", "values", ")", ";", "}", "return", "implode", "(", "\"\\r\\n\"", ",", "$", "rawHeaders", ")", ";", "}" ]
Returns the Guzzle array of headers as a string. @param ResponseInterface $response The Guzzle response. @return string
[ "Returns", "the", "Guzzle", "array", "of", "headers", "as", "a", "string", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/HttpClients/GuzzleHttpClient.php#L67-L76
222,630
apioo/psx-schema
src/SchemaTraverser.php
SchemaTraverser.traverse
public function traverse($data, SchemaInterface $schema, VisitorInterface $visitor = null) { $this->pathStack = []; $this->recCount = -1; if ($visitor === null) { $visitor = new NullVisitor(); } return $this->recTraverse($data, $schema->getDefinition(), $visitor); }
php
public function traverse($data, SchemaInterface $schema, VisitorInterface $visitor = null) { $this->pathStack = []; $this->recCount = -1; if ($visitor === null) { $visitor = new NullVisitor(); } return $this->recTraverse($data, $schema->getDefinition(), $visitor); }
[ "public", "function", "traverse", "(", "$", "data", ",", "SchemaInterface", "$", "schema", ",", "VisitorInterface", "$", "visitor", "=", "null", ")", "{", "$", "this", "->", "pathStack", "=", "[", "]", ";", "$", "this", "->", "recCount", "=", "-", "1", ";", "if", "(", "$", "visitor", "===", "null", ")", "{", "$", "visitor", "=", "new", "NullVisitor", "(", ")", ";", "}", "return", "$", "this", "->", "recTraverse", "(", "$", "data", ",", "$", "schema", "->", "getDefinition", "(", ")", ",", "$", "visitor", ")", ";", "}" ]
Traverses through the data and validates it according to the provided schema. Calls also the visitor methods for each type @param mixed $data @param \PSX\Schema\SchemaInterface $schema @param \PSX\Schema\VisitorInterface $visitor @return mixed
[ "Traverses", "through", "the", "data", "and", "validates", "it", "according", "to", "the", "provided", "schema", ".", "Calls", "also", "the", "visitor", "methods", "for", "each", "type" ]
b06eebe847364c4b57e2447cd04be8eb75044947
https://github.com/apioo/psx-schema/blob/b06eebe847364c4b57e2447cd04be8eb75044947/src/SchemaTraverser.php#L54-L64
222,631
zackslash/PHP-Web-Article-Extractor
src/TextBlock.php
TextBlock.calculateDensities
public function calculateDensities() { if ($this->numWordsInWrappedLines == 0) { $this->numWordsInWrappedLines = $this->numWords; $this->numWrappedLines = 1; } $this->textDensity = $this->numWordsInWrappedLines / $this->numWrappedLines; $this->linkDensity = $this->numWords == 0 ? 0 : $this->numWordsInAnchorText / $this->numWords; // Set full text words only if this block is past the threshold if($this->textDensity >= self::TEXT_DENSITY_THRESHOLD) { $this->numFullTextWords = $this->numWords; } }
php
public function calculateDensities() { if ($this->numWordsInWrappedLines == 0) { $this->numWordsInWrappedLines = $this->numWords; $this->numWrappedLines = 1; } $this->textDensity = $this->numWordsInWrappedLines / $this->numWrappedLines; $this->linkDensity = $this->numWords == 0 ? 0 : $this->numWordsInAnchorText / $this->numWords; // Set full text words only if this block is past the threshold if($this->textDensity >= self::TEXT_DENSITY_THRESHOLD) { $this->numFullTextWords = $this->numWords; } }
[ "public", "function", "calculateDensities", "(", ")", "{", "if", "(", "$", "this", "->", "numWordsInWrappedLines", "==", "0", ")", "{", "$", "this", "->", "numWordsInWrappedLines", "=", "$", "this", "->", "numWords", ";", "$", "this", "->", "numWrappedLines", "=", "1", ";", "}", "$", "this", "->", "textDensity", "=", "$", "this", "->", "numWordsInWrappedLines", "/", "$", "this", "->", "numWrappedLines", ";", "$", "this", "->", "linkDensity", "=", "$", "this", "->", "numWords", "==", "0", "?", "0", ":", "$", "this", "->", "numWordsInAnchorText", "/", "$", "this", "->", "numWords", ";", "// Set full text words only if this block is past the threshold", "if", "(", "$", "this", "->", "textDensity", ">=", "self", "::", "TEXT_DENSITY_THRESHOLD", ")", "{", "$", "this", "->", "numFullTextWords", "=", "$", "this", "->", "numWords", ";", "}", "}" ]
Calculates the text and link densities for this block
[ "Calculates", "the", "text", "and", "link", "densities", "for", "this", "block" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/TextBlock.php#L38-L53
222,632
sheadawson/silverstripe-blocks
src/forms/GridfieldConfigBlockManager.php
GridFieldConfigBlockManager.addExisting
public function addExisting() { $classes = $this->blockManager->getBlockClasses(); $this->addComponent($add = new GridFieldAddExistingSearchButton()); $add->setSearchList(Block::get()->filter(array( 'ClassName' => array_keys($classes), ))); return $this; }
php
public function addExisting() { $classes = $this->blockManager->getBlockClasses(); $this->addComponent($add = new GridFieldAddExistingSearchButton()); $add->setSearchList(Block::get()->filter(array( 'ClassName' => array_keys($classes), ))); return $this; }
[ "public", "function", "addExisting", "(", ")", "{", "$", "classes", "=", "$", "this", "->", "blockManager", "->", "getBlockClasses", "(", ")", ";", "$", "this", "->", "addComponent", "(", "$", "add", "=", "new", "GridFieldAddExistingSearchButton", "(", ")", ")", ";", "$", "add", "->", "setSearchList", "(", "Block", "::", "get", "(", ")", "->", "filter", "(", "array", "(", "'ClassName'", "=>", "array_keys", "(", "$", "classes", ")", ",", ")", ")", ")", ";", "return", "$", "this", ";", "}" ]
Add the GridFieldAddExistingSearchButton component to this grid config. @return $this
[ "Add", "the", "GridFieldAddExistingSearchButton", "component", "to", "this", "grid", "config", "." ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/forms/GridfieldConfigBlockManager.php#L129-L139
222,633
sheadawson/silverstripe-blocks
src/BlockManager.php
BlockManager.getAreas
public function getAreas($keyAsValue = true) { $areas = $this->config()->get('areas'); $areas = $keyAsValue ? ArrayLib::valuekey(array_keys($areas)) : $areas; if (count($areas)) { foreach ($areas as $k => $v) { $areas[$k] = $keyAsValue ? FormField::name_to_label($k) : $v; } } return $areas; }
php
public function getAreas($keyAsValue = true) { $areas = $this->config()->get('areas'); $areas = $keyAsValue ? ArrayLib::valuekey(array_keys($areas)) : $areas; if (count($areas)) { foreach ($areas as $k => $v) { $areas[$k] = $keyAsValue ? FormField::name_to_label($k) : $v; } } return $areas; }
[ "public", "function", "getAreas", "(", "$", "keyAsValue", "=", "true", ")", "{", "$", "areas", "=", "$", "this", "->", "config", "(", ")", "->", "get", "(", "'areas'", ")", ";", "$", "areas", "=", "$", "keyAsValue", "?", "ArrayLib", "::", "valuekey", "(", "array_keys", "(", "$", "areas", ")", ")", ":", "$", "areas", ";", "if", "(", "count", "(", "$", "areas", ")", ")", "{", "foreach", "(", "$", "areas", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "areas", "[", "$", "k", "]", "=", "$", "keyAsValue", "?", "FormField", "::", "name_to_label", "(", "$", "k", ")", ":", "$", "v", ";", "}", "}", "return", "$", "areas", ";", "}" ]
Gets an array of all areas defined for blocks. @param bool $keyAsValue @return array $areas
[ "Gets", "an", "array", "of", "all", "areas", "defined", "for", "blocks", "." ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/BlockManager.php#L46-L58
222,634
dmmlabo/dmm-php-sdk
src/Dmm/HttpClients/StreamHttpClient.php
StreamHttpClient.compileHeader
public function compileHeader(array $headers) { $header = []; foreach ($headers as $k => $v) { $header[] = $k . ': ' . $v; } return implode("\r\n", $header); }
php
public function compileHeader(array $headers) { $header = []; foreach ($headers as $k => $v) { $header[] = $k . ': ' . $v; } return implode("\r\n", $header); }
[ "public", "function", "compileHeader", "(", "array", "$", "headers", ")", "{", "$", "header", "=", "[", "]", ";", "foreach", "(", "$", "headers", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "header", "[", "]", "=", "$", "k", ".", "': '", ".", "$", "v", ";", "}", "return", "implode", "(", "\"\\r\\n\"", ",", "$", "header", ")", ";", "}" ]
Formats the headers for use in the stream wrapper. @param array $headers The request headers. @return string
[ "Formats", "the", "headers", "for", "use", "in", "the", "stream", "wrapper", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/HttpClients/StreamHttpClient.php#L65-L73
222,635
fedemotta/yii2-cronjob
models/CronJob.php
CronJob.execution_time
private static function execution_time(){ if (self::$execution_time === 0){ self::$execution_time = -microtime(true); }else{ self::$execution_time += microtime(true); } return self::$execution_time; }
php
private static function execution_time(){ if (self::$execution_time === 0){ self::$execution_time = -microtime(true); }else{ self::$execution_time += microtime(true); } return self::$execution_time; }
[ "private", "static", "function", "execution_time", "(", ")", "{", "if", "(", "self", "::", "$", "execution_time", "===", "0", ")", "{", "self", "::", "$", "execution_time", "=", "-", "microtime", "(", "true", ")", ";", "}", "else", "{", "self", "::", "$", "execution_time", "+=", "microtime", "(", "true", ")", ";", "}", "return", "self", "::", "$", "execution_time", ";", "}" ]
Get and set execution time @return int The execution time
[ "Get", "and", "set", "execution", "time" ]
01f99a808f7ff0ad7faa52711b0b49ed1a0e9992
https://github.com/fedemotta/yii2-cronjob/blob/01f99a808f7ff0ad7faa52711b0b49ed1a0e9992/models/CronJob.php#L39-L46
222,636
fedemotta/yii2-cronjob
models/CronJob.php
CronJob.initDatesInRange
public static function initDatesInRange($start_date, $end_date, $daysDifference = 1){ $dates_in_range = []; $begin = new DateTime($start_date); $end = new DateTime($end_date); $endModify = $end->modify( '+'.$daysDifference.' day' ); $interval = new DateInterval('P'.$daysDifference.'D'); $daterange = new DatePeriod($begin, $interval ,$endModify); foreach($daterange as $date){ $dates_in_range[$date->getTimestamp()] = $date->format("Y-m-d"); } return $dates_in_range; }
php
public static function initDatesInRange($start_date, $end_date, $daysDifference = 1){ $dates_in_range = []; $begin = new DateTime($start_date); $end = new DateTime($end_date); $endModify = $end->modify( '+'.$daysDifference.' day' ); $interval = new DateInterval('P'.$daysDifference.'D'); $daterange = new DatePeriod($begin, $interval ,$endModify); foreach($daterange as $date){ $dates_in_range[$date->getTimestamp()] = $date->format("Y-m-d"); } return $dates_in_range; }
[ "public", "static", "function", "initDatesInRange", "(", "$", "start_date", ",", "$", "end_date", ",", "$", "daysDifference", "=", "1", ")", "{", "$", "dates_in_range", "=", "[", "]", ";", "$", "begin", "=", "new", "DateTime", "(", "$", "start_date", ")", ";", "$", "end", "=", "new", "DateTime", "(", "$", "end_date", ")", ";", "$", "endModify", "=", "$", "end", "->", "modify", "(", "'+'", ".", "$", "daysDifference", ".", "' day'", ")", ";", "$", "interval", "=", "new", "DateInterval", "(", "'P'", ".", "$", "daysDifference", ".", "'D'", ")", ";", "$", "daterange", "=", "new", "DatePeriod", "(", "$", "begin", ",", "$", "interval", ",", "$", "endModify", ")", ";", "foreach", "(", "$", "daterange", "as", "$", "date", ")", "{", "$", "dates_in_range", "[", "$", "date", "->", "getTimestamp", "(", ")", "]", "=", "$", "date", "->", "format", "(", "\"Y-m-d\"", ")", ";", "}", "return", "$", "dates_in_range", ";", "}" ]
Generate dates in range @param type $start_date @param type $end_date @param type $daysDifference @return array of dates
[ "Generate", "dates", "in", "range" ]
01f99a808f7ff0ad7faa52711b0b49ed1a0e9992
https://github.com/fedemotta/yii2-cronjob/blob/01f99a808f7ff0ad7faa52711b0b49ed1a0e9992/models/CronJob.php#L55-L68
222,637
fedemotta/yii2-cronjob
models/CronJob.php
CronJob.initDatetimesInRange
public static function initDatetimesInRange($start_datetime, $end_datetime, $hoursDifference = 1){ $dates_in_range = []; $begin = new DateTime($start_datetime); $end = new DateTime($end_datetime); $endModify = $end->modify( '+'.$hoursDifference.' hour' ); $interval = new DateInterval('PT'.$hoursDifference.'H'); $daterange = new DatePeriod($begin, $interval ,$endModify); foreach($daterange as $date){ $dates_in_range[$date->getTimestamp()] = $date->format("Y-m-d H:i:s"); } return $dates_in_range; }
php
public static function initDatetimesInRange($start_datetime, $end_datetime, $hoursDifference = 1){ $dates_in_range = []; $begin = new DateTime($start_datetime); $end = new DateTime($end_datetime); $endModify = $end->modify( '+'.$hoursDifference.' hour' ); $interval = new DateInterval('PT'.$hoursDifference.'H'); $daterange = new DatePeriod($begin, $interval ,$endModify); foreach($daterange as $date){ $dates_in_range[$date->getTimestamp()] = $date->format("Y-m-d H:i:s"); } return $dates_in_range; }
[ "public", "static", "function", "initDatetimesInRange", "(", "$", "start_datetime", ",", "$", "end_datetime", ",", "$", "hoursDifference", "=", "1", ")", "{", "$", "dates_in_range", "=", "[", "]", ";", "$", "begin", "=", "new", "DateTime", "(", "$", "start_datetime", ")", ";", "$", "end", "=", "new", "DateTime", "(", "$", "end_datetime", ")", ";", "$", "endModify", "=", "$", "end", "->", "modify", "(", "'+'", ".", "$", "hoursDifference", ".", "' hour'", ")", ";", "$", "interval", "=", "new", "DateInterval", "(", "'PT'", ".", "$", "hoursDifference", ".", "'H'", ")", ";", "$", "daterange", "=", "new", "DatePeriod", "(", "$", "begin", ",", "$", "interval", ",", "$", "endModify", ")", ";", "foreach", "(", "$", "daterange", "as", "$", "date", ")", "{", "$", "dates_in_range", "[", "$", "date", "->", "getTimestamp", "(", ")", "]", "=", "$", "date", "->", "format", "(", "\"Y-m-d H:i:s\"", ")", ";", "}", "return", "$", "dates_in_range", ";", "}" ]
Generate datetimes in range @param type $start_datetime @param type $end_datetime @param type $hoursDifference @return array of datetimes
[ "Generate", "datetimes", "in", "range" ]
01f99a808f7ff0ad7faa52711b0b49ed1a0e9992
https://github.com/fedemotta/yii2-cronjob/blob/01f99a808f7ff0ad7faa52711b0b49ed1a0e9992/models/CronJob.php#L89-L102
222,638
fedemotta/yii2-cronjob
models/CronJob.php
CronJob.get_cron
public static function get_cron($controller,$action){ $cron = self::find()->where(['controller'=>$controller,'action'=>$action, 'success' => 0])->orderBy('id_cron_job DESC')->one(); if (is_null($cron)){ $cron = new CronJob(); $cron->controller = $controller; $cron->action = $action; } return $cron; }
php
public static function get_cron($controller,$action){ $cron = self::find()->where(['controller'=>$controller,'action'=>$action, 'success' => 0])->orderBy('id_cron_job DESC')->one(); if (is_null($cron)){ $cron = new CronJob(); $cron->controller = $controller; $cron->action = $action; } return $cron; }
[ "public", "static", "function", "get_cron", "(", "$", "controller", ",", "$", "action", ")", "{", "$", "cron", "=", "self", "::", "find", "(", ")", "->", "where", "(", "[", "'controller'", "=>", "$", "controller", ",", "'action'", "=>", "$", "action", ",", "'success'", "=>", "0", "]", ")", "->", "orderBy", "(", "'id_cron_job DESC'", ")", "->", "one", "(", ")", ";", "if", "(", "is_null", "(", "$", "cron", ")", ")", "{", "$", "cron", "=", "new", "CronJob", "(", ")", ";", "$", "cron", "->", "controller", "=", "$", "controller", ";", "$", "cron", "->", "action", "=", "$", "action", ";", "}", "return", "$", "cron", ";", "}" ]
Get a cron or generates a new one @param type $controller @param type $action @return CronJob The cronjob
[ "Get", "a", "cron", "or", "generates", "a", "new", "one" ]
01f99a808f7ff0ad7faa52711b0b49ed1a0e9992
https://github.com/fedemotta/yii2-cronjob/blob/01f99a808f7ff0ad7faa52711b0b49ed1a0e9992/models/CronJob.php#L131-L139
222,639
fedemotta/yii2-cronjob
models/CronJob.php
CronJob.get_previous_cron
public static function get_previous_cron($controller,$action){ return self::find()->where(['controller'=>$controller,'action'=>$action, 'success' => 1])->orderBy('id_cron_job DESC')->one(); }
php
public static function get_previous_cron($controller,$action){ return self::find()->where(['controller'=>$controller,'action'=>$action, 'success' => 1])->orderBy('id_cron_job DESC')->one(); }
[ "public", "static", "function", "get_previous_cron", "(", "$", "controller", ",", "$", "action", ")", "{", "return", "self", "::", "find", "(", ")", "->", "where", "(", "[", "'controller'", "=>", "$", "controller", ",", "'action'", "=>", "$", "action", ",", "'success'", "=>", "1", "]", ")", "->", "orderBy", "(", "'id_cron_job DESC'", ")", "->", "one", "(", ")", ";", "}" ]
Get previous successful ran cron @param type $controller @param type $action @return CronJob The cron job
[ "Get", "previous", "successful", "ran", "cron" ]
01f99a808f7ff0ad7faa52711b0b49ed1a0e9992
https://github.com/fedemotta/yii2-cronjob/blob/01f99a808f7ff0ad7faa52711b0b49ed1a0e9992/models/CronJob.php#L146-L148
222,640
fedemotta/yii2-cronjob
models/CronJob.php
CronJob.run
public static function run($controller, $action, $limit, $max){ $current = self::get_cron($controller, $action); $current::execution_time(); $current->limit = $limit; $current->running = 1; $current->success = 0; //get previous cron to set offset $previous = self::get_previous_cron($controller, $action); if (is_null($previous)){ $current->offset = 0; }else{ if (($previous->offset + $limit) >= $max){ $current->offset = 0; }else{ $current->offset = $previous->offset + $previous->limit; } } if ($current->save()){ Console::stdout(Console::ansiFormat("*** running ".$current->controller."/".$current->action."\n", [Console::FG_YELLOW])); return $current; }else{ Console::stdout(Console::ansiFormat("*** failed to run ".$current->controller."/".$current->action."\n", [Console::FG_RED])); return false; } }
php
public static function run($controller, $action, $limit, $max){ $current = self::get_cron($controller, $action); $current::execution_time(); $current->limit = $limit; $current->running = 1; $current->success = 0; //get previous cron to set offset $previous = self::get_previous_cron($controller, $action); if (is_null($previous)){ $current->offset = 0; }else{ if (($previous->offset + $limit) >= $max){ $current->offset = 0; }else{ $current->offset = $previous->offset + $previous->limit; } } if ($current->save()){ Console::stdout(Console::ansiFormat("*** running ".$current->controller."/".$current->action."\n", [Console::FG_YELLOW])); return $current; }else{ Console::stdout(Console::ansiFormat("*** failed to run ".$current->controller."/".$current->action."\n", [Console::FG_RED])); return false; } }
[ "public", "static", "function", "run", "(", "$", "controller", ",", "$", "action", ",", "$", "limit", ",", "$", "max", ")", "{", "$", "current", "=", "self", "::", "get_cron", "(", "$", "controller", ",", "$", "action", ")", ";", "$", "current", "::", "execution_time", "(", ")", ";", "$", "current", "->", "limit", "=", "$", "limit", ";", "$", "current", "->", "running", "=", "1", ";", "$", "current", "->", "success", "=", "0", ";", "//get previous cron to set offset", "$", "previous", "=", "self", "::", "get_previous_cron", "(", "$", "controller", ",", "$", "action", ")", ";", "if", "(", "is_null", "(", "$", "previous", ")", ")", "{", "$", "current", "->", "offset", "=", "0", ";", "}", "else", "{", "if", "(", "(", "$", "previous", "->", "offset", "+", "$", "limit", ")", ">=", "$", "max", ")", "{", "$", "current", "->", "offset", "=", "0", ";", "}", "else", "{", "$", "current", "->", "offset", "=", "$", "previous", "->", "offset", "+", "$", "previous", "->", "limit", ";", "}", "}", "if", "(", "$", "current", "->", "save", "(", ")", ")", "{", "Console", "::", "stdout", "(", "Console", "::", "ansiFormat", "(", "\"*** running \"", ".", "$", "current", "->", "controller", ".", "\"/\"", ".", "$", "current", "->", "action", ".", "\"\\n\"", ",", "[", "Console", "::", "FG_YELLOW", "]", ")", ")", ";", "return", "$", "current", ";", "}", "else", "{", "Console", "::", "stdout", "(", "Console", "::", "ansiFormat", "(", "\"*** failed to run \"", ".", "$", "current", "->", "controller", ".", "\"/\"", ".", "$", "current", "->", "action", ".", "\"\\n\"", ",", "[", "Console", "::", "FG_RED", "]", ")", ")", ";", "return", "false", ";", "}", "}" ]
Starts a cron job @param type $controller @param type $action @param type $limit @param type $max @return boolean Success
[ "Starts", "a", "cron", "job" ]
01f99a808f7ff0ad7faa52711b0b49ed1a0e9992
https://github.com/fedemotta/yii2-cronjob/blob/01f99a808f7ff0ad7faa52711b0b49ed1a0e9992/models/CronJob.php#L158-L185
222,641
fedemotta/yii2-cronjob
models/CronJob.php
CronJob.finish
public function finish(){ $this->running = 0; $this->success = 1; $this->last_execution_time = self::execution_time(); if ($this->save()){ Console::stdout(Console::ansiFormat("*** finished ".$this->controller."/".$this->action." (time: " . sprintf("%.3f", $this->last_execution_time) . "s)\n\n", [Console::FG_GREEN])); return true; }else{ Console::stdout(Console::ansiFormat("*** failed to finish ".$this->controller."/".$this->action." (time: " . sprintf("%.3f", $this->last_execution_time) . "s)\n\n", [Console::FG_RED])); return false; } }
php
public function finish(){ $this->running = 0; $this->success = 1; $this->last_execution_time = self::execution_time(); if ($this->save()){ Console::stdout(Console::ansiFormat("*** finished ".$this->controller."/".$this->action." (time: " . sprintf("%.3f", $this->last_execution_time) . "s)\n\n", [Console::FG_GREEN])); return true; }else{ Console::stdout(Console::ansiFormat("*** failed to finish ".$this->controller."/".$this->action." (time: " . sprintf("%.3f", $this->last_execution_time) . "s)\n\n", [Console::FG_RED])); return false; } }
[ "public", "function", "finish", "(", ")", "{", "$", "this", "->", "running", "=", "0", ";", "$", "this", "->", "success", "=", "1", ";", "$", "this", "->", "last_execution_time", "=", "self", "::", "execution_time", "(", ")", ";", "if", "(", "$", "this", "->", "save", "(", ")", ")", "{", "Console", "::", "stdout", "(", "Console", "::", "ansiFormat", "(", "\"*** finished \"", ".", "$", "this", "->", "controller", ".", "\"/\"", ".", "$", "this", "->", "action", ".", "\" (time: \"", ".", "sprintf", "(", "\"%.3f\"", ",", "$", "this", "->", "last_execution_time", ")", ".", "\"s)\\n\\n\"", ",", "[", "Console", "::", "FG_GREEN", "]", ")", ")", ";", "return", "true", ";", "}", "else", "{", "Console", "::", "stdout", "(", "Console", "::", "ansiFormat", "(", "\"*** failed to finish \"", ".", "$", "this", "->", "controller", ".", "\"/\"", ".", "$", "this", "->", "action", ".", "\" (time: \"", ".", "sprintf", "(", "\"%.3f\"", ",", "$", "this", "->", "last_execution_time", ")", ".", "\"s)\\n\\n\"", ",", "[", "Console", "::", "FG_RED", "]", ")", ")", ";", "return", "false", ";", "}", "}" ]
Ends a cron job @return boolean Success
[ "Ends", "a", "cron", "job" ]
01f99a808f7ff0ad7faa52711b0b49ed1a0e9992
https://github.com/fedemotta/yii2-cronjob/blob/01f99a808f7ff0ad7faa52711b0b49ed1a0e9992/models/CronJob.php#L190-L202
222,642
dmmlabo/dmm-php-sdk
src/Dmm/Http/RawResponse.php
RawResponse.setHeadersFromString
protected function setHeadersFromString($rawHeaders) { // Normalize line breaks $rawHeaders = str_replace("\r\n", "\n", $rawHeaders); // There will be multiple headers if a 301 was followed // or a proxy was followed, etc $headerCollection = explode("\n\n", trim($rawHeaders)); // We just want the last response (at the end) $rawHeader = array_pop($headerCollection); $headerComponents = explode("\n", $rawHeader); foreach ($headerComponents as $line) { if (strpos($line, ': ') === false) { $this->setHttpResponseCodeFromHeader($line); } else { list($key, $value) = explode(': ', $line); $this->headers[$key] = $value; } } }
php
protected function setHeadersFromString($rawHeaders) { // Normalize line breaks $rawHeaders = str_replace("\r\n", "\n", $rawHeaders); // There will be multiple headers if a 301 was followed // or a proxy was followed, etc $headerCollection = explode("\n\n", trim($rawHeaders)); // We just want the last response (at the end) $rawHeader = array_pop($headerCollection); $headerComponents = explode("\n", $rawHeader); foreach ($headerComponents as $line) { if (strpos($line, ': ') === false) { $this->setHttpResponseCodeFromHeader($line); } else { list($key, $value) = explode(': ', $line); $this->headers[$key] = $value; } } }
[ "protected", "function", "setHeadersFromString", "(", "$", "rawHeaders", ")", "{", "// Normalize line breaks", "$", "rawHeaders", "=", "str_replace", "(", "\"\\r\\n\"", ",", "\"\\n\"", ",", "$", "rawHeaders", ")", ";", "// There will be multiple headers if a 301 was followed", "// or a proxy was followed, etc", "$", "headerCollection", "=", "explode", "(", "\"\\n\\n\"", ",", "trim", "(", "$", "rawHeaders", ")", ")", ";", "// We just want the last response (at the end)", "$", "rawHeader", "=", "array_pop", "(", "$", "headerCollection", ")", ";", "$", "headerComponents", "=", "explode", "(", "\"\\n\"", ",", "$", "rawHeader", ")", ";", "foreach", "(", "$", "headerComponents", "as", "$", "line", ")", "{", "if", "(", "strpos", "(", "$", "line", ",", "': '", ")", "===", "false", ")", "{", "$", "this", "->", "setHttpResponseCodeFromHeader", "(", "$", "line", ")", ";", "}", "else", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "explode", "(", "': '", ",", "$", "line", ")", ";", "$", "this", "->", "headers", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}" ]
Parse the raw headers and set as an array. @param string $rawHeaders The raw headers from the response.
[ "Parse", "the", "raw", "headers", "and", "set", "as", "an", "array", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/Http/RawResponse.php#L94-L114
222,643
Telerivet/telerivet-php-client
lib/entity.php
Telerivet_Entity.save
function save() { $dirty_props = $this->_dirty; if ($this->_vars) { $dirty_vars = $this->_vars->getDirtyVariables(); if ($dirty_vars) { $dirty_props['vars'] = $dirty_vars; } } $this->_api->doRequest('POST', $this->getBaseApiPath(), $dirty_props); $this->_dirty = array(); if ($this->_vars) { $this->_vars->clearDirtyVariables(); } }
php
function save() { $dirty_props = $this->_dirty; if ($this->_vars) { $dirty_vars = $this->_vars->getDirtyVariables(); if ($dirty_vars) { $dirty_props['vars'] = $dirty_vars; } } $this->_api->doRequest('POST', $this->getBaseApiPath(), $dirty_props); $this->_dirty = array(); if ($this->_vars) { $this->_vars->clearDirtyVariables(); } }
[ "function", "save", "(", ")", "{", "$", "dirty_props", "=", "$", "this", "->", "_dirty", ";", "if", "(", "$", "this", "->", "_vars", ")", "{", "$", "dirty_vars", "=", "$", "this", "->", "_vars", "->", "getDirtyVariables", "(", ")", ";", "if", "(", "$", "dirty_vars", ")", "{", "$", "dirty_props", "[", "'vars'", "]", "=", "$", "dirty_vars", ";", "}", "}", "$", "this", "->", "_api", "->", "doRequest", "(", "'POST'", ",", "$", "this", "->", "getBaseApiPath", "(", ")", ",", "$", "dirty_props", ")", ";", "$", "this", "->", "_dirty", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "_vars", ")", "{", "$", "this", "->", "_vars", "->", "clearDirtyVariables", "(", ")", ";", "}", "}" ]
Saves any updated properties to Telerivet.
[ "Saves", "any", "updated", "properties", "to", "Telerivet", "." ]
c0b04a5974b25e13047c3e86bd16530fd5feec04
https://github.com/Telerivet/telerivet-php-client/blob/c0b04a5974b25e13047c3e86bd16530fd5feec04/lib/entity.php#L84-L104
222,644
zackslash/PHP-Web-Article-Extractor
src/Mergers/CloseBlockMerger.php
CloseBlockMerger.merge
public static function merge(&$article) { if(sizeof($article->textBlocks) < 2) { return; } $previousBlock = null; foreach ($article->textBlocks as $key => $textBlock) { if(!isset($previousBlock)) { $previousBlock = $textBlock; continue; } if(!$textBlock->isContent) { $previousBlock = $textBlock; continue; } $blockDiff = $textBlock->offsetBlocksStart - $previousBlock->offsetBlocksEnd - 1; if($blockDiff <= SELF::BLOCK_DISTANCE) { // Merge of this block into the previous block $previousBlock->text .= "\r\n\r\n"; $previousBlock->text .= $textBlock->text; $previousBlock->numWords += $textBlock->numWords; $previousBlock->numWordsInAnchorText += $textBlock->numWordsInAnchorText; $previousBlock->numWordsInWrappedLines += $textBlock->numWordsInWrappedLines; $previousBlock->numFullTextWords += $textBlock->numFullTextWords; $previousBlock->offsetBlocksStart = min($previousBlock->offsetBlocksStart,$textBlock->offsetBlocksStart); $previousBlock->offsetBlocksEnd = max($previousBlock->offsetBlocksEnd,$textBlock->offsetBlocksEnd); $previousBlock->tagLevel = min($previousBlock->tagLevel,$textBlock->tagLevel); $previousBlock->isContent = ($previousBlock->isContent || $textBlock->isContent); $previousBlock->currentContainedTextElements = array_merge($previousBlock->currentContainedTextElements,$textBlock->currentContainedTextElements); $previousBlock->labels = array_merge($previousBlock->labels,$textBlock->labels); $previousBlock->calculateDensities(); unset($article->textBlocks[$key]); // Safe as per PHP 'foreach' specification } else { $previousBlock = $textBlock; } } $article->textBlocks = array_values($article->textBlocks); }
php
public static function merge(&$article) { if(sizeof($article->textBlocks) < 2) { return; } $previousBlock = null; foreach ($article->textBlocks as $key => $textBlock) { if(!isset($previousBlock)) { $previousBlock = $textBlock; continue; } if(!$textBlock->isContent) { $previousBlock = $textBlock; continue; } $blockDiff = $textBlock->offsetBlocksStart - $previousBlock->offsetBlocksEnd - 1; if($blockDiff <= SELF::BLOCK_DISTANCE) { // Merge of this block into the previous block $previousBlock->text .= "\r\n\r\n"; $previousBlock->text .= $textBlock->text; $previousBlock->numWords += $textBlock->numWords; $previousBlock->numWordsInAnchorText += $textBlock->numWordsInAnchorText; $previousBlock->numWordsInWrappedLines += $textBlock->numWordsInWrappedLines; $previousBlock->numFullTextWords += $textBlock->numFullTextWords; $previousBlock->offsetBlocksStart = min($previousBlock->offsetBlocksStart,$textBlock->offsetBlocksStart); $previousBlock->offsetBlocksEnd = max($previousBlock->offsetBlocksEnd,$textBlock->offsetBlocksEnd); $previousBlock->tagLevel = min($previousBlock->tagLevel,$textBlock->tagLevel); $previousBlock->isContent = ($previousBlock->isContent || $textBlock->isContent); $previousBlock->currentContainedTextElements = array_merge($previousBlock->currentContainedTextElements,$textBlock->currentContainedTextElements); $previousBlock->labels = array_merge($previousBlock->labels,$textBlock->labels); $previousBlock->calculateDensities(); unset($article->textBlocks[$key]); // Safe as per PHP 'foreach' specification } else { $previousBlock = $textBlock; } } $article->textBlocks = array_values($article->textBlocks); }
[ "public", "static", "function", "merge", "(", "&", "$", "article", ")", "{", "if", "(", "sizeof", "(", "$", "article", "->", "textBlocks", ")", "<", "2", ")", "{", "return", ";", "}", "$", "previousBlock", "=", "null", ";", "foreach", "(", "$", "article", "->", "textBlocks", "as", "$", "key", "=>", "$", "textBlock", ")", "{", "if", "(", "!", "isset", "(", "$", "previousBlock", ")", ")", "{", "$", "previousBlock", "=", "$", "textBlock", ";", "continue", ";", "}", "if", "(", "!", "$", "textBlock", "->", "isContent", ")", "{", "$", "previousBlock", "=", "$", "textBlock", ";", "continue", ";", "}", "$", "blockDiff", "=", "$", "textBlock", "->", "offsetBlocksStart", "-", "$", "previousBlock", "->", "offsetBlocksEnd", "-", "1", ";", "if", "(", "$", "blockDiff", "<=", "SELF", "::", "BLOCK_DISTANCE", ")", "{", "// Merge of this block into the previous block", "$", "previousBlock", "->", "text", ".=", "\"\\r\\n\\r\\n\"", ";", "$", "previousBlock", "->", "text", ".=", "$", "textBlock", "->", "text", ";", "$", "previousBlock", "->", "numWords", "+=", "$", "textBlock", "->", "numWords", ";", "$", "previousBlock", "->", "numWordsInAnchorText", "+=", "$", "textBlock", "->", "numWordsInAnchorText", ";", "$", "previousBlock", "->", "numWordsInWrappedLines", "+=", "$", "textBlock", "->", "numWordsInWrappedLines", ";", "$", "previousBlock", "->", "numFullTextWords", "+=", "$", "textBlock", "->", "numFullTextWords", ";", "$", "previousBlock", "->", "offsetBlocksStart", "=", "min", "(", "$", "previousBlock", "->", "offsetBlocksStart", ",", "$", "textBlock", "->", "offsetBlocksStart", ")", ";", "$", "previousBlock", "->", "offsetBlocksEnd", "=", "max", "(", "$", "previousBlock", "->", "offsetBlocksEnd", ",", "$", "textBlock", "->", "offsetBlocksEnd", ")", ";", "$", "previousBlock", "->", "tagLevel", "=", "min", "(", "$", "previousBlock", "->", "tagLevel", ",", "$", "textBlock", "->", "tagLevel", ")", ";", "$", "previousBlock", "->", "isContent", "=", "(", "$", "previousBlock", "->", "isContent", "||", "$", "textBlock", "->", "isContent", ")", ";", "$", "previousBlock", "->", "currentContainedTextElements", "=", "array_merge", "(", "$", "previousBlock", "->", "currentContainedTextElements", ",", "$", "textBlock", "->", "currentContainedTextElements", ")", ";", "$", "previousBlock", "->", "labels", "=", "array_merge", "(", "$", "previousBlock", "->", "labels", ",", "$", "textBlock", "->", "labels", ")", ";", "$", "previousBlock", "->", "calculateDensities", "(", ")", ";", "unset", "(", "$", "article", "->", "textBlocks", "[", "$", "key", "]", ")", ";", "// Safe as per PHP 'foreach' specification", "}", "else", "{", "$", "previousBlock", "=", "$", "textBlock", ";", "}", "}", "$", "article", "->", "textBlocks", "=", "array_values", "(", "$", "article", "->", "textBlocks", ")", ";", "}" ]
Executes this merger @param article $article reference directly to the article object to merge
[ "Executes", "this", "merger" ]
f93d25d588dc0f8ddc4572429288edddb69386f6
https://github.com/zackslash/PHP-Web-Article-Extractor/blob/f93d25d588dc0f8ddc4572429288edddb69386f6/src/Mergers/CloseBlockMerger.php#L27-L75
222,645
joomla-framework/form
src/Form.php
Form.getFieldset
public function getFieldset($set = null) { $fields = array(); // Get all of the field elements in the fieldset. if ($set) { $elements = $this->findFieldsByFieldset($set); } else // Get all fields. { $elements = $this->findFieldsByGroup(); } // If no field elements were found return empty. if (empty($elements)) { return $fields; } // Build the result array from the found field elements. /** @var \SimpleXMLElement $element */ foreach ($elements as $element) { // Get the field groups for the element. $attrs = $element->xpath('ancestor::fields[@name]/@name'); $groups = array_map('strval', $attrs ? $attrs : array()); $group = implode('.', $groups); // If the field is successfully loaded add it to the result array. if ($field = $this->loadField($element, $group)) { $fields[$field->id] = $field; } } return $fields; }
php
public function getFieldset($set = null) { $fields = array(); // Get all of the field elements in the fieldset. if ($set) { $elements = $this->findFieldsByFieldset($set); } else // Get all fields. { $elements = $this->findFieldsByGroup(); } // If no field elements were found return empty. if (empty($elements)) { return $fields; } // Build the result array from the found field elements. /** @var \SimpleXMLElement $element */ foreach ($elements as $element) { // Get the field groups for the element. $attrs = $element->xpath('ancestor::fields[@name]/@name'); $groups = array_map('strval', $attrs ? $attrs : array()); $group = implode('.', $groups); // If the field is successfully loaded add it to the result array. if ($field = $this->loadField($element, $group)) { $fields[$field->id] = $field; } } return $fields; }
[ "public", "function", "getFieldset", "(", "$", "set", "=", "null", ")", "{", "$", "fields", "=", "array", "(", ")", ";", "// Get all of the field elements in the fieldset.", "if", "(", "$", "set", ")", "{", "$", "elements", "=", "$", "this", "->", "findFieldsByFieldset", "(", "$", "set", ")", ";", "}", "else", "// Get all fields.", "{", "$", "elements", "=", "$", "this", "->", "findFieldsByGroup", "(", ")", ";", "}", "// If no field elements were found return empty.", "if", "(", "empty", "(", "$", "elements", ")", ")", "{", "return", "$", "fields", ";", "}", "// Build the result array from the found field elements.", "/** @var \\SimpleXMLElement $element */", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "// Get the field groups for the element.", "$", "attrs", "=", "$", "element", "->", "xpath", "(", "'ancestor::fields[@name]/@name'", ")", ";", "$", "groups", "=", "array_map", "(", "'strval'", ",", "$", "attrs", "?", "$", "attrs", ":", "array", "(", ")", ")", ";", "$", "group", "=", "implode", "(", "'.'", ",", "$", "groups", ")", ";", "// If the field is successfully loaded add it to the result array.", "if", "(", "$", "field", "=", "$", "this", "->", "loadField", "(", "$", "element", ",", "$", "group", ")", ")", "{", "$", "fields", "[", "$", "field", "->", "id", "]", "=", "$", "field", ";", "}", "}", "return", "$", "fields", ";", "}" ]
Method to get an array of Field objects in a given fieldset by name. If no name is given then all fields are returned. @param string $set The optional name of the fieldset. @return Field[] An array of Field objects in the fieldset. @since 1.0
[ "Method", "to", "get", "an", "array", "of", "Field", "objects", "in", "a", "given", "fieldset", "by", "name", ".", "If", "no", "name", "is", "given", "then", "all", "fields", "are", "returned", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Form.php#L341-L379
222,646
joomla-framework/form
src/Form.php
Form.setField
public function setField(\SimpleXMLElement $element, $group = null, $replace = true) { // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { throw new \UnexpectedValueException(sprintf('%s::setField `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $old = $this->findField((string) $element['name'], $group); // If an existing field is found and replace flag is false do nothing and return true. if (!$replace && !empty($old)) { return true; } // If an existing field is found and replace flag is true remove the old field. if ($replace && !empty($old) && ($old instanceof \SimpleXMLElement)) { $dom = dom_import_simplexml($old); $dom->parentNode->removeChild($dom); } // If no existing field is found find a group element and add the field as a child of it. if ($group) { // Get the fields elements for a given group. $fields = &$this->findGroup($group); // If an appropriate fields element was found for the group, add the element. if (isset($fields[0]) && ($fields[0] instanceof \SimpleXMLElement)) { static::addNode($fields[0], $element); } } else { // Set the new field to the form. static::addNode($this->xml, $element); } // Synchronize any paths found in the load. $this->syncPaths(); return true; }
php
public function setField(\SimpleXMLElement $element, $group = null, $replace = true) { // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { throw new \UnexpectedValueException(sprintf('%s::setField `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $old = $this->findField((string) $element['name'], $group); // If an existing field is found and replace flag is false do nothing and return true. if (!$replace && !empty($old)) { return true; } // If an existing field is found and replace flag is true remove the old field. if ($replace && !empty($old) && ($old instanceof \SimpleXMLElement)) { $dom = dom_import_simplexml($old); $dom->parentNode->removeChild($dom); } // If no existing field is found find a group element and add the field as a child of it. if ($group) { // Get the fields elements for a given group. $fields = &$this->findGroup($group); // If an appropriate fields element was found for the group, add the element. if (isset($fields[0]) && ($fields[0] instanceof \SimpleXMLElement)) { static::addNode($fields[0], $element); } } else { // Set the new field to the form. static::addNode($this->xml, $element); } // Synchronize any paths found in the load. $this->syncPaths(); return true; }
[ "public", "function", "setField", "(", "\\", "SimpleXMLElement", "$", "element", ",", "$", "group", "=", "null", ",", "$", "replace", "=", "true", ")", "{", "// Make sure there is a valid Form XML document.", "if", "(", "!", "(", "$", "this", "->", "xml", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "sprintf", "(", "'%s::setField `xml` is not an instance of SimpleXMLElement'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "// Find the form field element from the definition.", "$", "old", "=", "$", "this", "->", "findField", "(", "(", "string", ")", "$", "element", "[", "'name'", "]", ",", "$", "group", ")", ";", "// If an existing field is found and replace flag is false do nothing and return true.", "if", "(", "!", "$", "replace", "&&", "!", "empty", "(", "$", "old", ")", ")", "{", "return", "true", ";", "}", "// If an existing field is found and replace flag is true remove the old field.", "if", "(", "$", "replace", "&&", "!", "empty", "(", "$", "old", ")", "&&", "(", "$", "old", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "$", "dom", "=", "dom_import_simplexml", "(", "$", "old", ")", ";", "$", "dom", "->", "parentNode", "->", "removeChild", "(", "$", "dom", ")", ";", "}", "// If no existing field is found find a group element and add the field as a child of it.", "if", "(", "$", "group", ")", "{", "// Get the fields elements for a given group.", "$", "fields", "=", "&", "$", "this", "->", "findGroup", "(", "$", "group", ")", ";", "// If an appropriate fields element was found for the group, add the element.", "if", "(", "isset", "(", "$", "fields", "[", "0", "]", ")", "&&", "(", "$", "fields", "[", "0", "]", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "static", "::", "addNode", "(", "$", "fields", "[", "0", "]", ",", "$", "element", ")", ";", "}", "}", "else", "{", "// Set the new field to the form.", "static", "::", "addNode", "(", "$", "this", "->", "xml", ",", "$", "element", ")", ";", "}", "// Synchronize any paths found in the load.", "$", "this", "->", "syncPaths", "(", ")", ";", "return", "true", ";", "}" ]
Method to set a field XML element to the form definition. If the replace flag is set then the field will be set whether it already exists or not. If it isn't set, then the field will not be replaced if it already exists. @param \SimpleXMLElement $element The XML element object representation of the form field. @param string $group The optional dot-separated form group path on which to set the field. @param boolean $replace True to replace an existing field if one already exists. @return boolean True on success. @since 1.0 @throws \UnexpectedValueException
[ "Method", "to", "set", "a", "field", "XML", "element", "to", "the", "form", "definition", ".", "If", "the", "replace", "flag", "is", "set", "then", "the", "field", "will", "be", "set", "whether", "it", "already", "exists", "or", "not", ".", "If", "it", "isn", "t", "set", "then", "the", "field", "will", "not", "be", "replaced", "if", "it", "already", "exists", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Form.php#L933-L979
222,647
joomla-framework/form
src/Form.php
Form.setFieldAttribute
public function setFieldAttribute($name, $attribute, $value, $group = null) { // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { throw new \UnexpectedValueException(sprintf('%s::setFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $element = $this->findField($name, $group); // If the element doesn't exist return false. if (!($element instanceof \SimpleXMLElement)) { return false; } else // Otherwise set the attribute and return true. { $element[$attribute] = $value; // Synchronize any paths found in the load. $this->syncPaths(); return true; } }
php
public function setFieldAttribute($name, $attribute, $value, $group = null) { // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { throw new \UnexpectedValueException(sprintf('%s::setFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $element = $this->findField($name, $group); // If the element doesn't exist return false. if (!($element instanceof \SimpleXMLElement)) { return false; } else // Otherwise set the attribute and return true. { $element[$attribute] = $value; // Synchronize any paths found in the load. $this->syncPaths(); return true; } }
[ "public", "function", "setFieldAttribute", "(", "$", "name", ",", "$", "attribute", ",", "$", "value", ",", "$", "group", "=", "null", ")", "{", "// Make sure there is a valid Form XML document.", "if", "(", "!", "(", "$", "this", "->", "xml", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "sprintf", "(", "'%s::setFieldAttribute `xml` is not an instance of SimpleXMLElement'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "// Find the form field element from the definition.", "$", "element", "=", "$", "this", "->", "findField", "(", "$", "name", ",", "$", "group", ")", ";", "// If the element doesn't exist return false.", "if", "(", "!", "(", "$", "element", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "return", "false", ";", "}", "else", "// Otherwise set the attribute and return true.", "{", "$", "element", "[", "$", "attribute", "]", "=", "$", "value", ";", "// Synchronize any paths found in the load.", "$", "this", "->", "syncPaths", "(", ")", ";", "return", "true", ";", "}", "}" ]
Method to set an attribute value for a field XML element. @param string $name The name of the form field for which to set the attribute value. @param string $attribute The name of the attribute for which to set a value. @param mixed $value The value to set for the attribute. @param string $group The optional dot-separated form group path on which to find the field. @return boolean True on success. @since 1.0 @throws \UnexpectedValueException
[ "Method", "to", "set", "an", "attribute", "value", "for", "a", "field", "XML", "element", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Form.php#L994-L1020
222,648
joomla-framework/form
src/Form.php
Form.validate
public function validate($data, $group = null) { // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { return false; } $return = true; // Create an input registry object from the data to validate. $input = new Registry($data); // Get the fields for which to validate the data. $fields = $this->findFieldsByGroup($group); if (!$fields) { // PANIC! return false; } // Validate the fields. foreach ($fields as $field) { $value = null; $name = (string) $field['name']; if (!$input->exists($name)) { continue; } // Get the group names as strings for ancestor fields elements. $attrs = $field->xpath('ancestor::fields[@name]/@name'); $groups = array_map('strval', $attrs ? $attrs : array()); $group = implode('.', $groups); // Get the value from the input data. if ($group) { $value = $input->get($group . '.' . $name); } else { $value = $input->get($name); } // Validate the field. $valid = $this->validateField($field, $group, $value, $input); // Check for an error. if ($valid instanceof \Exception) { array_push($this->errors, $valid); $return = false; } } return $return; }
php
public function validate($data, $group = null) { // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { return false; } $return = true; // Create an input registry object from the data to validate. $input = new Registry($data); // Get the fields for which to validate the data. $fields = $this->findFieldsByGroup($group); if (!$fields) { // PANIC! return false; } // Validate the fields. foreach ($fields as $field) { $value = null; $name = (string) $field['name']; if (!$input->exists($name)) { continue; } // Get the group names as strings for ancestor fields elements. $attrs = $field->xpath('ancestor::fields[@name]/@name'); $groups = array_map('strval', $attrs ? $attrs : array()); $group = implode('.', $groups); // Get the value from the input data. if ($group) { $value = $input->get($group . '.' . $name); } else { $value = $input->get($name); } // Validate the field. $valid = $this->validateField($field, $group, $value, $input); // Check for an error. if ($valid instanceof \Exception) { array_push($this->errors, $valid); $return = false; } } return $return; }
[ "public", "function", "validate", "(", "$", "data", ",", "$", "group", "=", "null", ")", "{", "// Make sure there is a valid Form XML document.", "if", "(", "!", "(", "$", "this", "->", "xml", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "return", "false", ";", "}", "$", "return", "=", "true", ";", "// Create an input registry object from the data to validate.", "$", "input", "=", "new", "Registry", "(", "$", "data", ")", ";", "// Get the fields for which to validate the data.", "$", "fields", "=", "$", "this", "->", "findFieldsByGroup", "(", "$", "group", ")", ";", "if", "(", "!", "$", "fields", ")", "{", "// PANIC!", "return", "false", ";", "}", "// Validate the fields.", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "value", "=", "null", ";", "$", "name", "=", "(", "string", ")", "$", "field", "[", "'name'", "]", ";", "if", "(", "!", "$", "input", "->", "exists", "(", "$", "name", ")", ")", "{", "continue", ";", "}", "// Get the group names as strings for ancestor fields elements.", "$", "attrs", "=", "$", "field", "->", "xpath", "(", "'ancestor::fields[@name]/@name'", ")", ";", "$", "groups", "=", "array_map", "(", "'strval'", ",", "$", "attrs", "?", "$", "attrs", ":", "array", "(", ")", ")", ";", "$", "group", "=", "implode", "(", "'.'", ",", "$", "groups", ")", ";", "// Get the value from the input data.", "if", "(", "$", "group", ")", "{", "$", "value", "=", "$", "input", "->", "get", "(", "$", "group", ".", "'.'", ".", "$", "name", ")", ";", "}", "else", "{", "$", "value", "=", "$", "input", "->", "get", "(", "$", "name", ")", ";", "}", "// Validate the field.", "$", "valid", "=", "$", "this", "->", "validateField", "(", "$", "field", ",", "$", "group", ",", "$", "value", ",", "$", "input", ")", ";", "// Check for an error.", "if", "(", "$", "valid", "instanceof", "\\", "Exception", ")", "{", "array_push", "(", "$", "this", "->", "errors", ",", "$", "valid", ")", ";", "$", "return", "=", "false", ";", "}", "}", "return", "$", "return", ";", "}" ]
Method to validate form data. Validation warnings will be pushed into Form::errors and should be retrieved with Form::getErrors() when validate returns boolean false. @param array $data An array of field values to validate. @param string $group The optional dot-separated form group path on which to filter the fields to be validated. @return mixed True on success. @since 1.0
[ "Method", "to", "validate", "form", "data", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Form.php#L1134-L1194
222,649
joomla-framework/form
src/Form.php
Form.findField
protected function findField($name, $group = null) { $element = false; $fields = array(); // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { return false; } // Let's get the appropriate field element based on the method arguments. if ($group) { // Get the fields elements for a given group. $elements = &$this->findGroup($group); // Get all of the field elements with the correct name for the fields elements. /** @var \SimpleXMLElement $element */ foreach ($elements as $element) { // If there are matching field elements add them to the fields array. if ($tmp = $element->xpath('descendant::field[@name="' . $name . '"]')) { $fields = array_merge($fields, $tmp); } } // Make sure something was found. if (empty($fields)) { return false; } // Use the first correct match in the given group. $groupNames = explode('.', $group); /** @var \SimpleXMLElement $field */ foreach ($fields as &$field) { // Get the group names as strings for ancestor fields elements. $attrs = $field->xpath('ancestor::fields[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the field is in the exact group use it and break out of the loop. if ($names == (array) $groupNames) { $element = &$field; break; } } } else { // Get an array of fields with the correct name. $fields = $this->xml->xpath('//field[@name="' . $name . '"]'); // Make sure something was found. if (empty($fields)) { return false; } // Search through the fields for the right one. foreach ($fields as &$field) { // If we find an ancestor fields element with a group name then it isn't what we want. if ($field->xpath('ancestor::fields[@name]')) { continue; } else // Found it! { $element = &$field; break; } } } return $element; }
php
protected function findField($name, $group = null) { $element = false; $fields = array(); // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { return false; } // Let's get the appropriate field element based on the method arguments. if ($group) { // Get the fields elements for a given group. $elements = &$this->findGroup($group); // Get all of the field elements with the correct name for the fields elements. /** @var \SimpleXMLElement $element */ foreach ($elements as $element) { // If there are matching field elements add them to the fields array. if ($tmp = $element->xpath('descendant::field[@name="' . $name . '"]')) { $fields = array_merge($fields, $tmp); } } // Make sure something was found. if (empty($fields)) { return false; } // Use the first correct match in the given group. $groupNames = explode('.', $group); /** @var \SimpleXMLElement $field */ foreach ($fields as &$field) { // Get the group names as strings for ancestor fields elements. $attrs = $field->xpath('ancestor::fields[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the field is in the exact group use it and break out of the loop. if ($names == (array) $groupNames) { $element = &$field; break; } } } else { // Get an array of fields with the correct name. $fields = $this->xml->xpath('//field[@name="' . $name . '"]'); // Make sure something was found. if (empty($fields)) { return false; } // Search through the fields for the right one. foreach ($fields as &$field) { // If we find an ancestor fields element with a group name then it isn't what we want. if ($field->xpath('ancestor::fields[@name]')) { continue; } else // Found it! { $element = &$field; break; } } } return $element; }
[ "protected", "function", "findField", "(", "$", "name", ",", "$", "group", "=", "null", ")", "{", "$", "element", "=", "false", ";", "$", "fields", "=", "array", "(", ")", ";", "// Make sure there is a valid Form XML document.", "if", "(", "!", "(", "$", "this", "->", "xml", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "return", "false", ";", "}", "// Let's get the appropriate field element based on the method arguments.", "if", "(", "$", "group", ")", "{", "// Get the fields elements for a given group.", "$", "elements", "=", "&", "$", "this", "->", "findGroup", "(", "$", "group", ")", ";", "// Get all of the field elements with the correct name for the fields elements.", "/** @var \\SimpleXMLElement $element */", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "// If there are matching field elements add them to the fields array.", "if", "(", "$", "tmp", "=", "$", "element", "->", "xpath", "(", "'descendant::field[@name=\"'", ".", "$", "name", ".", "'\"]'", ")", ")", "{", "$", "fields", "=", "array_merge", "(", "$", "fields", ",", "$", "tmp", ")", ";", "}", "}", "// Make sure something was found.", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "return", "false", ";", "}", "// Use the first correct match in the given group.", "$", "groupNames", "=", "explode", "(", "'.'", ",", "$", "group", ")", ";", "/** @var \\SimpleXMLElement $field */", "foreach", "(", "$", "fields", "as", "&", "$", "field", ")", "{", "// Get the group names as strings for ancestor fields elements.", "$", "attrs", "=", "$", "field", "->", "xpath", "(", "'ancestor::fields[@name]/@name'", ")", ";", "$", "names", "=", "array_map", "(", "'strval'", ",", "$", "attrs", "?", "$", "attrs", ":", "array", "(", ")", ")", ";", "// If the field is in the exact group use it and break out of the loop.", "if", "(", "$", "names", "==", "(", "array", ")", "$", "groupNames", ")", "{", "$", "element", "=", "&", "$", "field", ";", "break", ";", "}", "}", "}", "else", "{", "// Get an array of fields with the correct name.", "$", "fields", "=", "$", "this", "->", "xml", "->", "xpath", "(", "'//field[@name=\"'", ".", "$", "name", ".", "'\"]'", ")", ";", "// Make sure something was found.", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "return", "false", ";", "}", "// Search through the fields for the right one.", "foreach", "(", "$", "fields", "as", "&", "$", "field", ")", "{", "// If we find an ancestor fields element with a group name then it isn't what we want.", "if", "(", "$", "field", "->", "xpath", "(", "'ancestor::fields[@name]'", ")", ")", "{", "continue", ";", "}", "else", "// Found it!", "{", "$", "element", "=", "&", "$", "field", ";", "break", ";", "}", "}", "}", "return", "$", "element", ";", "}" ]
Method to get a form field represented as an XML element object. @param string $name The name of the form field. @param string $group The optional dot-separated form group path on which to find the field. @return \SimpleXMLElement|boolean Boolean false on error or a SimpleXMLElement object. @since 1.0
[ "Method", "to", "get", "a", "form", "field", "represented", "as", "an", "XML", "element", "object", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Form.php#L1410-L1491
222,650
joomla-framework/form
src/Form.php
Form.&
protected function &findGroup($group) { $false = false; $groups = array(); $tmp = array(); // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { return $false; } // Make sure there is actually a group to find. $group = explode('.', $group); if (!empty($group)) { // Get any fields elements with the correct group name. $elements = $this->xml->xpath('//fields[@name="' . (string) $group[0] . '"]'); // Check to make sure that there are no parent groups for each element. foreach ($elements as $element) { if (!$element->xpath('ancestor::fields[@name]')) { $tmp[] = $element; } } // Iterate through the nested groups to find any matching form field groups. for ($i = 1, $n = count($group); $i < $n; $i++) { // Initialise some loop variables. $validNames = array_slice($group, 0, $i + 1); $current = $tmp; $tmp = array(); // Check to make sure that there are no parent groups for each element. /** @var \SimpleXMLElement $element */ foreach ($current as $element) { // Get any fields elements with the correct group name. $children = $element->xpath('descendant::fields[@name="' . (string) $group[$i] . '"]'); // For the found fields elements validate that they are in the correct groups. foreach ($children as $fields) { // Get the group names as strings for ancestor fields elements. $attrs = $fields->xpath('ancestor-or-self::fields[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the group names for the fields element match the valid names at this // level add the fields element. if ($validNames == $names) { $tmp[] = $fields; } } } } // Only include valid XML objects. foreach ($tmp as $element) { if ($element instanceof \SimpleXMLElement) { $groups[] = $element; } } } return $groups; }
php
protected function &findGroup($group) { $false = false; $groups = array(); $tmp = array(); // Make sure there is a valid Form XML document. if (!($this->xml instanceof \SimpleXMLElement)) { return $false; } // Make sure there is actually a group to find. $group = explode('.', $group); if (!empty($group)) { // Get any fields elements with the correct group name. $elements = $this->xml->xpath('//fields[@name="' . (string) $group[0] . '"]'); // Check to make sure that there are no parent groups for each element. foreach ($elements as $element) { if (!$element->xpath('ancestor::fields[@name]')) { $tmp[] = $element; } } // Iterate through the nested groups to find any matching form field groups. for ($i = 1, $n = count($group); $i < $n; $i++) { // Initialise some loop variables. $validNames = array_slice($group, 0, $i + 1); $current = $tmp; $tmp = array(); // Check to make sure that there are no parent groups for each element. /** @var \SimpleXMLElement $element */ foreach ($current as $element) { // Get any fields elements with the correct group name. $children = $element->xpath('descendant::fields[@name="' . (string) $group[$i] . '"]'); // For the found fields elements validate that they are in the correct groups. foreach ($children as $fields) { // Get the group names as strings for ancestor fields elements. $attrs = $fields->xpath('ancestor-or-self::fields[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the group names for the fields element match the valid names at this // level add the fields element. if ($validNames == $names) { $tmp[] = $fields; } } } } // Only include valid XML objects. foreach ($tmp as $element) { if ($element instanceof \SimpleXMLElement) { $groups[] = $element; } } } return $groups; }
[ "protected", "function", "&", "findGroup", "(", "$", "group", ")", "{", "$", "false", "=", "false", ";", "$", "groups", "=", "array", "(", ")", ";", "$", "tmp", "=", "array", "(", ")", ";", "// Make sure there is a valid Form XML document.", "if", "(", "!", "(", "$", "this", "->", "xml", "instanceof", "\\", "SimpleXMLElement", ")", ")", "{", "return", "$", "false", ";", "}", "// Make sure there is actually a group to find.", "$", "group", "=", "explode", "(", "'.'", ",", "$", "group", ")", ";", "if", "(", "!", "empty", "(", "$", "group", ")", ")", "{", "// Get any fields elements with the correct group name.", "$", "elements", "=", "$", "this", "->", "xml", "->", "xpath", "(", "'//fields[@name=\"'", ".", "(", "string", ")", "$", "group", "[", "0", "]", ".", "'\"]'", ")", ";", "// Check to make sure that there are no parent groups for each element.", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "if", "(", "!", "$", "element", "->", "xpath", "(", "'ancestor::fields[@name]'", ")", ")", "{", "$", "tmp", "[", "]", "=", "$", "element", ";", "}", "}", "// Iterate through the nested groups to find any matching form field groups.", "for", "(", "$", "i", "=", "1", ",", "$", "n", "=", "count", "(", "$", "group", ")", ";", "$", "i", "<", "$", "n", ";", "$", "i", "++", ")", "{", "// Initialise some loop variables.", "$", "validNames", "=", "array_slice", "(", "$", "group", ",", "0", ",", "$", "i", "+", "1", ")", ";", "$", "current", "=", "$", "tmp", ";", "$", "tmp", "=", "array", "(", ")", ";", "// Check to make sure that there are no parent groups for each element.", "/** @var \\SimpleXMLElement $element */", "foreach", "(", "$", "current", "as", "$", "element", ")", "{", "// Get any fields elements with the correct group name.", "$", "children", "=", "$", "element", "->", "xpath", "(", "'descendant::fields[@name=\"'", ".", "(", "string", ")", "$", "group", "[", "$", "i", "]", ".", "'\"]'", ")", ";", "// For the found fields elements validate that they are in the correct groups.", "foreach", "(", "$", "children", "as", "$", "fields", ")", "{", "// Get the group names as strings for ancestor fields elements.", "$", "attrs", "=", "$", "fields", "->", "xpath", "(", "'ancestor-or-self::fields[@name]/@name'", ")", ";", "$", "names", "=", "array_map", "(", "'strval'", ",", "$", "attrs", "?", "$", "attrs", ":", "array", "(", ")", ")", ";", "// If the group names for the fields element match the valid names at this", "// level add the fields element.", "if", "(", "$", "validNames", "==", "$", "names", ")", "{", "$", "tmp", "[", "]", "=", "$", "fields", ";", "}", "}", "}", "}", "// Only include valid XML objects.", "foreach", "(", "$", "tmp", "as", "$", "element", ")", "{", "if", "(", "$", "element", "instanceof", "\\", "SimpleXMLElement", ")", "{", "$", "groups", "[", "]", "=", "$", "element", ";", "}", "}", "}", "return", "$", "groups", ";", "}" ]
Method to get a form field group represented as an XML element object. @param string $group The dot-separated form group path on which to find the group. @return \SimpleXMLElement[]|boolean Boolean false on error or array of SimpleXMLElement objects. @since 1.0
[ "Method", "to", "get", "a", "form", "field", "group", "represented", "as", "an", "XML", "element", "object", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Form.php#L1610-L1682
222,651
sheadawson/silverstripe-blocks
src/extensions/BlocksSiteTreeExtension.php
BlocksSiteTreeExtension.showBlocksFields
public function showBlocksFields() { $whiteList = $this->blockManager->getWhiteListedPageTypes(); $blackList = $this->blockManager->getBlackListedPageTypes(); if (in_array($this->owner->ClassName, $blackList)) { return false; } if (count($whiteList) && !in_array($this->owner->ClassName, $whiteList)) { return false; } if (!Permission::check('BLOCK_EDIT')) { return false; } return true; }
php
public function showBlocksFields() { $whiteList = $this->blockManager->getWhiteListedPageTypes(); $blackList = $this->blockManager->getBlackListedPageTypes(); if (in_array($this->owner->ClassName, $blackList)) { return false; } if (count($whiteList) && !in_array($this->owner->ClassName, $whiteList)) { return false; } if (!Permission::check('BLOCK_EDIT')) { return false; } return true; }
[ "public", "function", "showBlocksFields", "(", ")", "{", "$", "whiteList", "=", "$", "this", "->", "blockManager", "->", "getWhiteListedPageTypes", "(", ")", ";", "$", "blackList", "=", "$", "this", "->", "blockManager", "->", "getBlackListedPageTypes", "(", ")", ";", "if", "(", "in_array", "(", "$", "this", "->", "owner", "->", "ClassName", ",", "$", "blackList", ")", ")", "{", "return", "false", ";", "}", "if", "(", "count", "(", "$", "whiteList", ")", "&&", "!", "in_array", "(", "$", "this", "->", "owner", "->", "ClassName", ",", "$", "whiteList", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "Permission", "::", "check", "(", "'BLOCK_EDIT'", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check if the Blocks CMSFields should be displayed for this Page @return boolean
[ "Check", "if", "the", "Blocks", "CMSFields", "should", "be", "displayed", "for", "this", "Page" ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/extensions/BlocksSiteTreeExtension.php#L62-L80
222,652
sheadawson/silverstripe-blocks
src/extensions/BlocksSiteTreeExtension.php
BlocksSiteTreeExtension.updateCMSFields
public function updateCMSFields(FieldList $fields) { if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) { return; } $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName); if ($areas && count($areas)) { $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks'))); if (BlockManager::config()->get('block_area_preview')) { $fields->addFieldToTab('Root.Blocks', LiteralField::create('PreviewLink', $this->areasPreviewButton())); } // Blocks related directly to this Page $gridConfig = GridFieldConfigBlockManager::create(true, true, true, true) ->addExisting($this->owner->class) //->addBulkEditing() // ->addComponent(new GridFieldOrderableRows()) // Comment until below TODO is complete. ; // TODO it seems this sort is not being applied... $gridSource = $this->owner->Blocks(); // ->sort(array( // "FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '', // 'SiteTree_Blocks.Sort' => 'ASC', // 'Name' => 'ASC' // )); $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig)); // Blocks inherited from BlockSets if ($this->blockManager->getUseBlockSets()) { $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true); if ($inheritedBlocks->count()) { $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false); if ($activeInherited->count()) { $fields->addFieldsToTab('Root.Blocks', [ GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited, GridFieldConfigBlockManager::create(false, false, false)), LiteralField::create('InheritedBlockListTip', "<p class='message'>"._t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', ['link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>']).'<p>'), ]); } $fields->addFieldToTab('Root.Blocks', ListboxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), $inheritedBlocks->map('ID', 'Title'), null, null, true) ->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.')) ); } else { $fields->addFieldToTab('Root.Blocks', ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.'))); } $fields->addFieldToTab('Root.Blocks', CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets'))); } } }
php
public function updateCMSFields(FieldList $fields) { if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) { return; } $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName); if ($areas && count($areas)) { $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks'))); if (BlockManager::config()->get('block_area_preview')) { $fields->addFieldToTab('Root.Blocks', LiteralField::create('PreviewLink', $this->areasPreviewButton())); } // Blocks related directly to this Page $gridConfig = GridFieldConfigBlockManager::create(true, true, true, true) ->addExisting($this->owner->class) //->addBulkEditing() // ->addComponent(new GridFieldOrderableRows()) // Comment until below TODO is complete. ; // TODO it seems this sort is not being applied... $gridSource = $this->owner->Blocks(); // ->sort(array( // "FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '', // 'SiteTree_Blocks.Sort' => 'ASC', // 'Name' => 'ASC' // )); $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig)); // Blocks inherited from BlockSets if ($this->blockManager->getUseBlockSets()) { $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true); if ($inheritedBlocks->count()) { $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false); if ($activeInherited->count()) { $fields->addFieldsToTab('Root.Blocks', [ GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited, GridFieldConfigBlockManager::create(false, false, false)), LiteralField::create('InheritedBlockListTip', "<p class='message'>"._t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', ['link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>']).'<p>'), ]); } $fields->addFieldToTab('Root.Blocks', ListboxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), $inheritedBlocks->map('ID', 'Title'), null, null, true) ->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.')) ); } else { $fields->addFieldToTab('Root.Blocks', ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.'))); } $fields->addFieldToTab('Root.Blocks', CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets'))); } } }
[ "public", "function", "updateCMSFields", "(", "FieldList", "$", "fields", ")", "{", "if", "(", "$", "fields", "->", "fieldByName", "(", "'Root.Blocks'", ")", "||", "!", "$", "this", "->", "showBlocksFields", "(", ")", ")", "{", "return", ";", "}", "$", "areas", "=", "$", "this", "->", "blockManager", "->", "getAreasForPageType", "(", "$", "this", "->", "owner", "->", "ClassName", ")", ";", "if", "(", "$", "areas", "&&", "count", "(", "$", "areas", ")", ")", "{", "$", "fields", "->", "addFieldToTab", "(", "'Root'", ",", "new", "Tab", "(", "'Blocks'", ",", "_t", "(", "'Block.PLURALNAME'", ",", "'Blocks'", ")", ")", ")", ";", "if", "(", "BlockManager", "::", "config", "(", ")", "->", "get", "(", "'block_area_preview'", ")", ")", "{", "$", "fields", "->", "addFieldToTab", "(", "'Root.Blocks'", ",", "LiteralField", "::", "create", "(", "'PreviewLink'", ",", "$", "this", "->", "areasPreviewButton", "(", ")", ")", ")", ";", "}", "// Blocks related directly to this Page", "$", "gridConfig", "=", "GridFieldConfigBlockManager", "::", "create", "(", "true", ",", "true", ",", "true", ",", "true", ")", "->", "addExisting", "(", "$", "this", "->", "owner", "->", "class", ")", "//->addBulkEditing()", "// ->addComponent(new GridFieldOrderableRows()) // Comment until below TODO is complete.", ";", "// TODO it seems this sort is not being applied...", "$", "gridSource", "=", "$", "this", "->", "owner", "->", "Blocks", "(", ")", ";", "// ->sort(array(", "// \t\"FIELD(SiteTree_Blocks.BlockArea, '\" . implode(\"','\", array_keys($areas)) . \"')\" => '',", "// \t'SiteTree_Blocks.Sort' => 'ASC',", "// \t'Name' => 'ASC'", "// ));", "$", "fields", "->", "addFieldToTab", "(", "'Root.Blocks'", ",", "GridField", "::", "create", "(", "'Blocks'", ",", "_t", "(", "'Block.PLURALNAME'", ",", "'Blocks'", ")", ",", "$", "gridSource", ",", "$", "gridConfig", ")", ")", ";", "// Blocks inherited from BlockSets", "if", "(", "$", "this", "->", "blockManager", "->", "getUseBlockSets", "(", ")", ")", "{", "$", "inheritedBlocks", "=", "$", "this", "->", "getBlocksFromAppliedBlockSets", "(", "null", ",", "true", ")", ";", "if", "(", "$", "inheritedBlocks", "->", "count", "(", ")", ")", "{", "$", "activeInherited", "=", "$", "this", "->", "getBlocksFromAppliedBlockSets", "(", "null", ",", "false", ")", ";", "if", "(", "$", "activeInherited", "->", "count", "(", ")", ")", "{", "$", "fields", "->", "addFieldsToTab", "(", "'Root.Blocks'", ",", "[", "GridField", "::", "create", "(", "'InheritedBlockList'", ",", "_t", "(", "'BlocksSiteTreeExtension.BlocksInheritedFromBlockSets'", ",", "'Blocks Inherited from Block Sets'", ")", ",", "$", "activeInherited", ",", "GridFieldConfigBlockManager", "::", "create", "(", "false", ",", "false", ",", "false", ")", ")", ",", "LiteralField", "::", "create", "(", "'InheritedBlockListTip'", ",", "\"<p class='message'>\"", ".", "_t", "(", "'BlocksSiteTreeExtension.InheritedBlocksEditLink'", ",", "'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}'", ",", "''", ",", "[", "'link_start'", "=>", "'<a href=\"admin/block-admin\">'", ",", "'link_end'", "=>", "'</a>'", "]", ")", ".", "'<p>'", ")", ",", "]", ")", ";", "}", "$", "fields", "->", "addFieldToTab", "(", "'Root.Blocks'", ",", "ListboxField", "::", "create", "(", "'DisabledBlocks'", ",", "_t", "(", "'BlocksSiteTreeExtension.DisableInheritedBlocks'", ",", "'Disable Inherited Blocks'", ")", ",", "$", "inheritedBlocks", "->", "map", "(", "'ID'", ",", "'Title'", ")", ",", "null", ",", "null", ",", "true", ")", "->", "setDescription", "(", "_t", "(", "'BlocksSiteTreeExtension.DisableInheritedBlocksDescription'", ",", "'Select any inherited blocks that you would not like displayed on this page.'", ")", ")", ")", ";", "}", "else", "{", "$", "fields", "->", "addFieldToTab", "(", "'Root.Blocks'", ",", "ReadonlyField", "::", "create", "(", "'DisabledBlocksReadOnly'", ",", "_t", "(", "'BlocksSiteTreeExtension.DisableInheritedBlocks'", ",", "'Disable Inherited Blocks'", ")", ",", "_t", "(", "'BlocksSiteTreeExtension.NoInheritedBlocksToDisable'", ",", "'This page has no inherited blocks to disable.'", ")", ")", ")", ";", "}", "$", "fields", "->", "addFieldToTab", "(", "'Root.Blocks'", ",", "CheckboxField", "::", "create", "(", "'InheritBlockSets'", ",", "_t", "(", "'BlocksSiteTreeExtension.InheritBlocksFromBlockSets'", ",", "'Inherit Blocks from Block Sets'", ")", ")", ")", ";", "}", "}", "}" ]
Block manager for Pages.
[ "Block", "manager", "for", "Pages", "." ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/extensions/BlocksSiteTreeExtension.php#L85-L149
222,653
sheadawson/silverstripe-blocks
src/extensions/BlocksSiteTreeExtension.php
BlocksSiteTreeExtension.BlockArea
public function BlockArea($area, $limit = null) { if ($this->owner->ID <= 0) { return; } // blocks break on fake pages ie Security/login $list = $this->getBlockList($area); foreach ($list as $block) { if (!$block->canView()) { $list->remove($block); } } if ($limit !== null) { $list = $list->limit($limit); } $data = []; $data['HasBlockArea'] = ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) || $list->Count() > 0; $data['BlockArea'] = $list; $data['AreaID'] = $area; $data = $this->owner->customise($data); $template = ['BlockArea_'.$area]; if (SSViewer::hasTemplate($template)) { return $data->renderWith($template); } else { return $data->renderWith('BlockArea'); } }
php
public function BlockArea($area, $limit = null) { if ($this->owner->ID <= 0) { return; } // blocks break on fake pages ie Security/login $list = $this->getBlockList($area); foreach ($list as $block) { if (!$block->canView()) { $list->remove($block); } } if ($limit !== null) { $list = $list->limit($limit); } $data = []; $data['HasBlockArea'] = ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) || $list->Count() > 0; $data['BlockArea'] = $list; $data['AreaID'] = $area; $data = $this->owner->customise($data); $template = ['BlockArea_'.$area]; if (SSViewer::hasTemplate($template)) { return $data->renderWith($template); } else { return $data->renderWith('BlockArea'); } }
[ "public", "function", "BlockArea", "(", "$", "area", ",", "$", "limit", "=", "null", ")", "{", "if", "(", "$", "this", "->", "owner", "->", "ID", "<=", "0", ")", "{", "return", ";", "}", "// blocks break on fake pages ie Security/login", "$", "list", "=", "$", "this", "->", "getBlockList", "(", "$", "area", ")", ";", "foreach", "(", "$", "list", "as", "$", "block", ")", "{", "if", "(", "!", "$", "block", "->", "canView", "(", ")", ")", "{", "$", "list", "->", "remove", "(", "$", "block", ")", ";", "}", "}", "if", "(", "$", "limit", "!==", "null", ")", "{", "$", "list", "=", "$", "list", "->", "limit", "(", "$", "limit", ")", ";", "}", "$", "data", "=", "[", "]", ";", "$", "data", "[", "'HasBlockArea'", "]", "=", "(", "$", "this", "->", "owner", "->", "canEdit", "(", ")", "&&", "isset", "(", "$", "_REQUEST", "[", "'block_preview'", "]", ")", "&&", "$", "_REQUEST", "[", "'block_preview'", "]", ")", "||", "$", "list", "->", "Count", "(", ")", ">", "0", ";", "$", "data", "[", "'BlockArea'", "]", "=", "$", "list", ";", "$", "data", "[", "'AreaID'", "]", "=", "$", "area", ";", "$", "data", "=", "$", "this", "->", "owner", "->", "customise", "(", "$", "data", ")", ";", "$", "template", "=", "[", "'BlockArea_'", ".", "$", "area", "]", ";", "if", "(", "SSViewer", "::", "hasTemplate", "(", "$", "template", ")", ")", "{", "return", "$", "data", "->", "renderWith", "(", "$", "template", ")", ";", "}", "else", "{", "return", "$", "data", "->", "renderWith", "(", "'BlockArea'", ")", ";", "}", "}" ]
Called from templates to get rendered blocks for the given area. @param string $area @param int $limit Limit the items to this number, or null for no limit
[ "Called", "from", "templates", "to", "get", "rendered", "blocks", "for", "the", "given", "area", "." ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/extensions/BlocksSiteTreeExtension.php#L157-L189
222,654
sheadawson/silverstripe-blocks
src/extensions/BlocksSiteTreeExtension.php
BlocksSiteTreeExtension.getBlockList
public function getBlockList($area = null, $includeDisabled = false) { $includeSets = $this->blockManager->getUseBlockSets() && $this->owner->InheritBlockSets; $blocks = ArrayList::create(); // get blocks directly linked to this page $nativeBlocks = $this->owner->Blocks()->sort('Sort'); if ($area) { $nativeBlocks = $nativeBlocks->filter('BlockArea', $area); } if ($nativeBlocks->count()) { foreach ($nativeBlocks as $block) { $blocks->add($block); } } // get blocks from BlockSets if ($includeSets) { $blocksFromSets = $this->getBlocksFromAppliedBlockSets($area, $includeDisabled); if ($blocksFromSets->count()) { // merge set sources foreach ($blocksFromSets as $block) { if (!$blocks->find('ID', $block->ID)) { if ($block->AboveOrBelow == 'Above') { $blocks->unshift($block); } else { $blocks->push($block); } } } } } return $blocks; }
php
public function getBlockList($area = null, $includeDisabled = false) { $includeSets = $this->blockManager->getUseBlockSets() && $this->owner->InheritBlockSets; $blocks = ArrayList::create(); // get blocks directly linked to this page $nativeBlocks = $this->owner->Blocks()->sort('Sort'); if ($area) { $nativeBlocks = $nativeBlocks->filter('BlockArea', $area); } if ($nativeBlocks->count()) { foreach ($nativeBlocks as $block) { $blocks->add($block); } } // get blocks from BlockSets if ($includeSets) { $blocksFromSets = $this->getBlocksFromAppliedBlockSets($area, $includeDisabled); if ($blocksFromSets->count()) { // merge set sources foreach ($blocksFromSets as $block) { if (!$blocks->find('ID', $block->ID)) { if ($block->AboveOrBelow == 'Above') { $blocks->unshift($block); } else { $blocks->push($block); } } } } } return $blocks; }
[ "public", "function", "getBlockList", "(", "$", "area", "=", "null", ",", "$", "includeDisabled", "=", "false", ")", "{", "$", "includeSets", "=", "$", "this", "->", "blockManager", "->", "getUseBlockSets", "(", ")", "&&", "$", "this", "->", "owner", "->", "InheritBlockSets", ";", "$", "blocks", "=", "ArrayList", "::", "create", "(", ")", ";", "// get blocks directly linked to this page", "$", "nativeBlocks", "=", "$", "this", "->", "owner", "->", "Blocks", "(", ")", "->", "sort", "(", "'Sort'", ")", ";", "if", "(", "$", "area", ")", "{", "$", "nativeBlocks", "=", "$", "nativeBlocks", "->", "filter", "(", "'BlockArea'", ",", "$", "area", ")", ";", "}", "if", "(", "$", "nativeBlocks", "->", "count", "(", ")", ")", "{", "foreach", "(", "$", "nativeBlocks", "as", "$", "block", ")", "{", "$", "blocks", "->", "add", "(", "$", "block", ")", ";", "}", "}", "// get blocks from BlockSets", "if", "(", "$", "includeSets", ")", "{", "$", "blocksFromSets", "=", "$", "this", "->", "getBlocksFromAppliedBlockSets", "(", "$", "area", ",", "$", "includeDisabled", ")", ";", "if", "(", "$", "blocksFromSets", "->", "count", "(", ")", ")", "{", "// merge set sources", "foreach", "(", "$", "blocksFromSets", "as", "$", "block", ")", "{", "if", "(", "!", "$", "blocks", "->", "find", "(", "'ID'", ",", "$", "block", "->", "ID", ")", ")", "{", "if", "(", "$", "block", "->", "AboveOrBelow", "==", "'Above'", ")", "{", "$", "blocks", "->", "unshift", "(", "$", "block", ")", ";", "}", "else", "{", "$", "blocks", "->", "push", "(", "$", "block", ")", ";", "}", "}", "}", "}", "}", "return", "$", "blocks", ";", "}" ]
Get a merged list of all blocks on this page and ones inherited from BlockSets. @param string|null $area filter by block area @param bool $includeDisabled Include blocks that have been explicitly excluded from this page i.e. blocks from block sets added to the "disable inherited blocks" list @return ArrayList
[ "Get", "a", "merged", "list", "of", "all", "blocks", "on", "this", "page", "and", "ones", "inherited", "from", "BlockSets", "." ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/extensions/BlocksSiteTreeExtension.php#L217-L252
222,655
sheadawson/silverstripe-blocks
src/extensions/BlocksSiteTreeExtension.php
BlocksSiteTreeExtension.getAppliedSets
public function getAppliedSets() { $list = ArrayList::create(); if (!$this->owner->InheritBlockSets) { return $list; } $sets = BlockSet::get()->where("(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\"{$this->owner->ClassName}%')"); $ancestors = $this->owner->getAncestors()->column('ID'); foreach ($sets as $set) { $restrictedToParerentIDs = $set->PageParents()->column('ID'); if (count($restrictedToParerentIDs)) { // check whether the set should include selected parent, in which case check whether // it was in the restricted parents list. If it's not, or if include parentpage // wasn't selected, we check the ancestors of this page. if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) { $list->add($set); } else { if (count($ancestors)) { foreach ($ancestors as $ancestor) { if (in_array($ancestor, $restrictedToParerentIDs)) { $list->add($set); continue; } } } } } else { $list->add($set); } } return $list; }
php
public function getAppliedSets() { $list = ArrayList::create(); if (!$this->owner->InheritBlockSets) { return $list; } $sets = BlockSet::get()->where("(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\"{$this->owner->ClassName}%')"); $ancestors = $this->owner->getAncestors()->column('ID'); foreach ($sets as $set) { $restrictedToParerentIDs = $set->PageParents()->column('ID'); if (count($restrictedToParerentIDs)) { // check whether the set should include selected parent, in which case check whether // it was in the restricted parents list. If it's not, or if include parentpage // wasn't selected, we check the ancestors of this page. if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) { $list->add($set); } else { if (count($ancestors)) { foreach ($ancestors as $ancestor) { if (in_array($ancestor, $restrictedToParerentIDs)) { $list->add($set); continue; } } } } } else { $list->add($set); } } return $list; }
[ "public", "function", "getAppliedSets", "(", ")", "{", "$", "list", "=", "ArrayList", "::", "create", "(", ")", ";", "if", "(", "!", "$", "this", "->", "owner", "->", "InheritBlockSets", ")", "{", "return", "$", "list", ";", "}", "$", "sets", "=", "BlockSet", "::", "get", "(", ")", "->", "where", "(", "\"(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\\\"{$this->owner->ClassName}%')\"", ")", ";", "$", "ancestors", "=", "$", "this", "->", "owner", "->", "getAncestors", "(", ")", "->", "column", "(", "'ID'", ")", ";", "foreach", "(", "$", "sets", "as", "$", "set", ")", "{", "$", "restrictedToParerentIDs", "=", "$", "set", "->", "PageParents", "(", ")", "->", "column", "(", "'ID'", ")", ";", "if", "(", "count", "(", "$", "restrictedToParerentIDs", ")", ")", "{", "// check whether the set should include selected parent, in which case check whether", "// it was in the restricted parents list. If it's not, or if include parentpage", "// wasn't selected, we check the ancestors of this page.", "if", "(", "$", "set", "->", "IncludePageParent", "&&", "in_array", "(", "$", "this", "->", "owner", "->", "ID", ",", "$", "restrictedToParerentIDs", ")", ")", "{", "$", "list", "->", "add", "(", "$", "set", ")", ";", "}", "else", "{", "if", "(", "count", "(", "$", "ancestors", ")", ")", "{", "foreach", "(", "$", "ancestors", "as", "$", "ancestor", ")", "{", "if", "(", "in_array", "(", "$", "ancestor", ",", "$", "restrictedToParerentIDs", ")", ")", "{", "$", "list", "->", "add", "(", "$", "set", ")", ";", "continue", ";", "}", "}", "}", "}", "}", "else", "{", "$", "list", "->", "add", "(", "$", "set", ")", ";", "}", "}", "return", "$", "list", ";", "}" ]
Get Any BlockSets that apply to this page. @return ArrayList
[ "Get", "Any", "BlockSets", "that", "apply", "to", "this", "page", "." ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/extensions/BlocksSiteTreeExtension.php#L259-L293
222,656
sheadawson/silverstripe-blocks
src/extensions/BlocksSiteTreeExtension.php
BlocksSiteTreeExtension.getBlocksFromAppliedBlockSets
public function getBlocksFromAppliedBlockSets($area = null, $includeDisabled = false) { $blocks = ArrayList::create(); $sets = $this->getAppliedSets(); if (!$sets->count()) { return $blocks; } foreach ($sets as $set) { $setBlocks = $set->Blocks()->sort('Sort DESC'); if (!$includeDisabled) { $setBlocks = $setBlocks->exclude('ID', $this->owner->DisabledBlocks()->column('ID')); } if ($area) { $setBlocks = $setBlocks->filter('BlockArea', $area); } $blocks->merge($setBlocks); } $blocks->removeDuplicates(); return $blocks; }
php
public function getBlocksFromAppliedBlockSets($area = null, $includeDisabled = false) { $blocks = ArrayList::create(); $sets = $this->getAppliedSets(); if (!$sets->count()) { return $blocks; } foreach ($sets as $set) { $setBlocks = $set->Blocks()->sort('Sort DESC'); if (!$includeDisabled) { $setBlocks = $setBlocks->exclude('ID', $this->owner->DisabledBlocks()->column('ID')); } if ($area) { $setBlocks = $setBlocks->filter('BlockArea', $area); } $blocks->merge($setBlocks); } $blocks->removeDuplicates(); return $blocks; }
[ "public", "function", "getBlocksFromAppliedBlockSets", "(", "$", "area", "=", "null", ",", "$", "includeDisabled", "=", "false", ")", "{", "$", "blocks", "=", "ArrayList", "::", "create", "(", ")", ";", "$", "sets", "=", "$", "this", "->", "getAppliedSets", "(", ")", ";", "if", "(", "!", "$", "sets", "->", "count", "(", ")", ")", "{", "return", "$", "blocks", ";", "}", "foreach", "(", "$", "sets", "as", "$", "set", ")", "{", "$", "setBlocks", "=", "$", "set", "->", "Blocks", "(", ")", "->", "sort", "(", "'Sort DESC'", ")", ";", "if", "(", "!", "$", "includeDisabled", ")", "{", "$", "setBlocks", "=", "$", "setBlocks", "->", "exclude", "(", "'ID'", ",", "$", "this", "->", "owner", "->", "DisabledBlocks", "(", ")", "->", "column", "(", "'ID'", ")", ")", ";", "}", "if", "(", "$", "area", ")", "{", "$", "setBlocks", "=", "$", "setBlocks", "->", "filter", "(", "'BlockArea'", ",", "$", "area", ")", ";", "}", "$", "blocks", "->", "merge", "(", "$", "setBlocks", ")", ";", "}", "$", "blocks", "->", "removeDuplicates", "(", ")", ";", "return", "$", "blocks", ";", "}" ]
Get all Blocks from BlockSets that apply to this page. @return ArrayList
[ "Get", "all", "Blocks", "from", "BlockSets", "that", "apply", "to", "this", "page", "." ]
07b00124ea617f95f436fb98b09d304daf6334e1
https://github.com/sheadawson/silverstripe-blocks/blob/07b00124ea617f95f436fb98b09d304daf6334e1/src/extensions/BlocksSiteTreeExtension.php#L300-L326
222,657
dmmlabo/dmm-php-sdk
src/Dmm/Dmm.php
Dmm.request
public function request($method, $endpoint, array $params = []) { return new DmmRequest( $this->credential, $method, $endpoint, $params ); }
php
public function request($method, $endpoint, array $params = []) { return new DmmRequest( $this->credential, $method, $endpoint, $params ); }
[ "public", "function", "request", "(", "$", "method", ",", "$", "endpoint", ",", "array", "$", "params", "=", "[", "]", ")", "{", "return", "new", "DmmRequest", "(", "$", "this", "->", "credential", ",", "$", "method", ",", "$", "endpoint", ",", "$", "params", ")", ";", "}" ]
Instantiates a new DmmRequest entity. @param string $method @param string $endpoint @param array $params @return DmmRequest @throws DmmSDKException
[ "Instantiates", "a", "new", "DmmRequest", "entity", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/Dmm.php#L151-L159
222,658
dmmlabo/dmm-php-sdk
src/Dmm/Dmm.php
Dmm.api
public function api($name) { switch ($name) { case 'actress': $api = new Apis\Actress($this->client, $this->credential); break; case 'author': $api = new Apis\Author($this->client, $this->credential); break; case 'floor': $api = new Apis\Floor($this->client, $this->credential); break; case 'genre': $api = new Apis\Genre($this->client, $this->credential); break; case 'maker': $api = new Apis\Maker($this->client, $this->credential); break; case 'product': $api = new Apis\Product($this->client, $this->credential); break; case 'series': $api = new Apis\Series($this->client, $this->credential); break; default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); break; } return $api; }
php
public function api($name) { switch ($name) { case 'actress': $api = new Apis\Actress($this->client, $this->credential); break; case 'author': $api = new Apis\Author($this->client, $this->credential); break; case 'floor': $api = new Apis\Floor($this->client, $this->credential); break; case 'genre': $api = new Apis\Genre($this->client, $this->credential); break; case 'maker': $api = new Apis\Maker($this->client, $this->credential); break; case 'product': $api = new Apis\Product($this->client, $this->credential); break; case 'series': $api = new Apis\Series($this->client, $this->credential); break; default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); break; } return $api; }
[ "public", "function", "api", "(", "$", "name", ")", "{", "switch", "(", "$", "name", ")", "{", "case", "'actress'", ":", "$", "api", "=", "new", "Apis", "\\", "Actress", "(", "$", "this", "->", "client", ",", "$", "this", "->", "credential", ")", ";", "break", ";", "case", "'author'", ":", "$", "api", "=", "new", "Apis", "\\", "Author", "(", "$", "this", "->", "client", ",", "$", "this", "->", "credential", ")", ";", "break", ";", "case", "'floor'", ":", "$", "api", "=", "new", "Apis", "\\", "Floor", "(", "$", "this", "->", "client", ",", "$", "this", "->", "credential", ")", ";", "break", ";", "case", "'genre'", ":", "$", "api", "=", "new", "Apis", "\\", "Genre", "(", "$", "this", "->", "client", ",", "$", "this", "->", "credential", ")", ";", "break", ";", "case", "'maker'", ":", "$", "api", "=", "new", "Apis", "\\", "Maker", "(", "$", "this", "->", "client", ",", "$", "this", "->", "credential", ")", ";", "break", ";", "case", "'product'", ":", "$", "api", "=", "new", "Apis", "\\", "Product", "(", "$", "this", "->", "client", ",", "$", "this", "->", "credential", ")", ";", "break", ";", "case", "'series'", ":", "$", "api", "=", "new", "Apis", "\\", "Series", "(", "$", "this", "->", "client", ",", "$", "this", "->", "credential", ")", ";", "break", ";", "default", ":", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Undefined api instance called: \"%s\"'", ",", "$", "name", ")", ")", ";", "break", ";", "}", "return", "$", "api", ";", "}" ]
Get API interface @param string $name @return ApiInterface @throws InvalidArgumentException
[ "Get", "API", "interface" ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/Dmm.php#L170-L199
222,659
enygma/yubikey
src/Yubikey/Response.php
Response.parse
public function parse($data) { $result = array(); $parts = explode("\n", $data); foreach($parts as $index => $part) { $kv = explode("=", $part); if (!empty($kv[1])) { $result[$kv[0]] = $kv[1]; } } $this->load($result); }
php
public function parse($data) { $result = array(); $parts = explode("\n", $data); foreach($parts as $index => $part) { $kv = explode("=", $part); if (!empty($kv[1])) { $result[$kv[0]] = $kv[1]; } } $this->load($result); }
[ "public", "function", "parse", "(", "$", "data", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "parts", "=", "explode", "(", "\"\\n\"", ",", "$", "data", ")", ";", "foreach", "(", "$", "parts", "as", "$", "index", "=>", "$", "part", ")", "{", "$", "kv", "=", "explode", "(", "\"=\"", ",", "$", "part", ")", ";", "if", "(", "!", "empty", "(", "$", "kv", "[", "1", "]", ")", ")", "{", "$", "result", "[", "$", "kv", "[", "0", "]", "]", "=", "$", "kv", "[", "1", "]", ";", "}", "}", "$", "this", "->", "load", "(", "$", "result", ")", ";", "}" ]
Parse the return data from the request and load it into the object properties @param string $data API return data
[ "Parse", "the", "return", "data", "from", "the", "request", "and", "load", "it", "into", "the", "object", "properties" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Response.php#L133-L146
222,660
enygma/yubikey
src/Yubikey/Response.php
Response.getHash
public function getHash($encode = false) { $hash = $this->h; if (substr($hash, -1) !== '=') { $hash .= '='; } if ($encode === true) { $hash = str_replace('+', '%2B', $hash); } return $hash; }
php
public function getHash($encode = false) { $hash = $this->h; if (substr($hash, -1) !== '=') { $hash .= '='; } if ($encode === true) { $hash = str_replace('+', '%2B', $hash); } return $hash; }
[ "public", "function", "getHash", "(", "$", "encode", "=", "false", ")", "{", "$", "hash", "=", "$", "this", "->", "h", ";", "if", "(", "substr", "(", "$", "hash", ",", "-", "1", ")", "!==", "'='", ")", "{", "$", "hash", ".=", "'='", ";", "}", "if", "(", "$", "encode", "===", "true", ")", "{", "$", "hash", "=", "str_replace", "(", "'+'", ",", "'%2B'", ",", "$", "hash", ")", ";", "}", "return", "$", "hash", ";", "}" ]
Get the hash from the response @param boolean $encode "Encode" the data (replace + with %2B) @return string Hash value
[ "Get", "the", "hash", "from", "the", "response" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Response.php#L231-L241
222,661
joomla-framework/form
src/Field.php
Field.__isset
public function __isset($name) { // These properties aren't directly accessible, so always return true if ($name == 'input' || $name == 'label') { return true; } // Check if a property has an assigned value if ($this->$name !== null) { return true; } return false; }
php
public function __isset($name) { // These properties aren't directly accessible, so always return true if ($name == 'input' || $name == 'label') { return true; } // Check if a property has an assigned value if ($this->$name !== null) { return true; } return false; }
[ "public", "function", "__isset", "(", "$", "name", ")", "{", "// These properties aren't directly accessible, so always return true", "if", "(", "$", "name", "==", "'input'", "||", "$", "name", "==", "'label'", ")", "{", "return", "true", ";", "}", "// Check if a property has an assigned value", "if", "(", "$", "this", "->", "$", "name", "!==", "null", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Method to checks whether the value of certain inaccessible properties has been set or is it null. @param string $name The property name. @return boolean True if the value is set, false otherwise. @since __DEPLOY_VERSION__
[ "Method", "to", "checks", "whether", "the", "value", "of", "certain", "inaccessible", "properties", "has", "been", "set", "or", "is", "it", "null", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Field.php#L333-L348
222,662
dmmlabo/dmm-php-sdk
src/Dmm/HttpClients/DmmStream.php
DmmStream.fileGetContents
public function fileGetContents($url) { $rawResponse = file_get_contents($url, false, $this->stream); $this->responseHeaders = $http_response_header ?: []; return $rawResponse; }
php
public function fileGetContents($url) { $rawResponse = file_get_contents($url, false, $this->stream); $this->responseHeaders = $http_response_header ?: []; return $rawResponse; }
[ "public", "function", "fileGetContents", "(", "$", "url", ")", "{", "$", "rawResponse", "=", "file_get_contents", "(", "$", "url", ",", "false", ",", "$", "this", "->", "stream", ")", ";", "$", "this", "->", "responseHeaders", "=", "$", "http_response_header", "?", ":", "[", "]", ";", "return", "$", "rawResponse", ";", "}" ]
Send a stream wrapped request @param string $url @return mixed
[ "Send", "a", "stream", "wrapped", "request" ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/HttpClients/DmmStream.php#L51-L57
222,663
dmmlabo/dmm-php-sdk
src/Dmm/Url/DmmUrlManipulator.php
DmmUrlManipulator.removeParamsFromUrl
public static function removeParamsFromUrl($url, array $paramsToFilter) { $parts = parse_url($url); $query = ''; if (isset($parts['query'])) { $params = []; parse_str($parts['query'], $params); // Remove query params foreach ($paramsToFilter as $paramName) { unset($params[$paramName]); } if (count($params) > 0) { $query = '?' . http_build_query($params, null, '&'); } } $scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : ''; $host = isset($parts['host']) ? $parts['host'] : ''; $port = isset($parts['port']) ? ':' . $parts['port'] : ''; $path = isset($parts['path']) ? $parts['path'] : ''; $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : ''; return $scheme . $host . $port . $path . $query . $fragment; }
php
public static function removeParamsFromUrl($url, array $paramsToFilter) { $parts = parse_url($url); $query = ''; if (isset($parts['query'])) { $params = []; parse_str($parts['query'], $params); // Remove query params foreach ($paramsToFilter as $paramName) { unset($params[$paramName]); } if (count($params) > 0) { $query = '?' . http_build_query($params, null, '&'); } } $scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : ''; $host = isset($parts['host']) ? $parts['host'] : ''; $port = isset($parts['port']) ? ':' . $parts['port'] : ''; $path = isset($parts['path']) ? $parts['path'] : ''; $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : ''; return $scheme . $host . $port . $path . $query . $fragment; }
[ "public", "static", "function", "removeParamsFromUrl", "(", "$", "url", ",", "array", "$", "paramsToFilter", ")", "{", "$", "parts", "=", "parse_url", "(", "$", "url", ")", ";", "$", "query", "=", "''", ";", "if", "(", "isset", "(", "$", "parts", "[", "'query'", "]", ")", ")", "{", "$", "params", "=", "[", "]", ";", "parse_str", "(", "$", "parts", "[", "'query'", "]", ",", "$", "params", ")", ";", "// Remove query params", "foreach", "(", "$", "paramsToFilter", "as", "$", "paramName", ")", "{", "unset", "(", "$", "params", "[", "$", "paramName", "]", ")", ";", "}", "if", "(", "count", "(", "$", "params", ")", ">", "0", ")", "{", "$", "query", "=", "'?'", ".", "http_build_query", "(", "$", "params", ",", "null", ",", "'&'", ")", ";", "}", "}", "$", "scheme", "=", "isset", "(", "$", "parts", "[", "'scheme'", "]", ")", "?", "$", "parts", "[", "'scheme'", "]", ".", "'://'", ":", "''", ";", "$", "host", "=", "isset", "(", "$", "parts", "[", "'host'", "]", ")", "?", "$", "parts", "[", "'host'", "]", ":", "''", ";", "$", "port", "=", "isset", "(", "$", "parts", "[", "'port'", "]", ")", "?", "':'", ".", "$", "parts", "[", "'port'", "]", ":", "''", ";", "$", "path", "=", "isset", "(", "$", "parts", "[", "'path'", "]", ")", "?", "$", "parts", "[", "'path'", "]", ":", "''", ";", "$", "fragment", "=", "isset", "(", "$", "parts", "[", "'fragment'", "]", ")", "?", "'#'", ".", "$", "parts", "[", "'fragment'", "]", ":", "''", ";", "return", "$", "scheme", ".", "$", "host", ".", "$", "port", ".", "$", "path", ".", "$", "query", ".", "$", "fragment", ";", "}" ]
Remove params from a URL. @param string $url The URL to filter. @param array $paramsToFilter The params to filter from the URL. @return string The URL with the params removed.
[ "Remove", "params", "from", "a", "URL", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/Url/DmmUrlManipulator.php#L19-L45
222,664
dmmlabo/dmm-php-sdk
src/Dmm/Url/DmmUrlManipulator.php
DmmUrlManipulator.getParamsAsArray
public static function getParamsAsArray($url) { $query = parse_url($url, PHP_URL_QUERY); if (!$query) { return []; } $params = []; parse_str($query, $params); return $params; }
php
public static function getParamsAsArray($url) { $query = parse_url($url, PHP_URL_QUERY); if (!$query) { return []; } $params = []; parse_str($query, $params); return $params; }
[ "public", "static", "function", "getParamsAsArray", "(", "$", "url", ")", "{", "$", "query", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_QUERY", ")", ";", "if", "(", "!", "$", "query", ")", "{", "return", "[", "]", ";", "}", "$", "params", "=", "[", "]", ";", "parse_str", "(", "$", "query", ",", "$", "params", ")", ";", "return", "$", "params", ";", "}" ]
Returns the params from a URL in the form of an array. @param string $url The URL to parse the params from. @return array
[ "Returns", "the", "params", "from", "a", "URL", "in", "the", "form", "of", "an", "array", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/Url/DmmUrlManipulator.php#L85-L95
222,665
enygma/yubikey
src/Yubikey/Client.php
Client.request
public function request(\Yubikey\RequestCollection $requests) { $responses = new \Yubikey\ResponseCollection(); $startTime = microtime(true); $multi = curl_multi_init(); $curls = array(); foreach ($requests as $index => $request) { $curls[$index] = curl_init(); curl_setopt_array($curls[$index], array( CURLOPT_URL => $request->getUrl(), CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1 )); curl_multi_add_handle($multi, $curls[$index]); } do { while ((curl_multi_exec($multi, $active)) == CURLM_CALL_MULTI_PERFORM); while ($info = curl_multi_info_read($multi)) { if ($info['result'] == CURLE_OK) { $return = curl_multi_getcontent($info['handle']); $cinfo = curl_getinfo($info['handle']); $url = parse_url($cinfo['url']); $response = new \Yubikey\Response(array( 'host' => $url['host'], 'mt' => (microtime(true)-$startTime) )); $response->parse($return); $responses->add($response); } } } while ($active); return $responses; }
php
public function request(\Yubikey\RequestCollection $requests) { $responses = new \Yubikey\ResponseCollection(); $startTime = microtime(true); $multi = curl_multi_init(); $curls = array(); foreach ($requests as $index => $request) { $curls[$index] = curl_init(); curl_setopt_array($curls[$index], array( CURLOPT_URL => $request->getUrl(), CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1 )); curl_multi_add_handle($multi, $curls[$index]); } do { while ((curl_multi_exec($multi, $active)) == CURLM_CALL_MULTI_PERFORM); while ($info = curl_multi_info_read($multi)) { if ($info['result'] == CURLE_OK) { $return = curl_multi_getcontent($info['handle']); $cinfo = curl_getinfo($info['handle']); $url = parse_url($cinfo['url']); $response = new \Yubikey\Response(array( 'host' => $url['host'], 'mt' => (microtime(true)-$startTime) )); $response->parse($return); $responses->add($response); } } } while ($active); return $responses; }
[ "public", "function", "request", "(", "\\", "Yubikey", "\\", "RequestCollection", "$", "requests", ")", "{", "$", "responses", "=", "new", "\\", "Yubikey", "\\", "ResponseCollection", "(", ")", ";", "$", "startTime", "=", "microtime", "(", "true", ")", ";", "$", "multi", "=", "curl_multi_init", "(", ")", ";", "$", "curls", "=", "array", "(", ")", ";", "foreach", "(", "$", "requests", "as", "$", "index", "=>", "$", "request", ")", "{", "$", "curls", "[", "$", "index", "]", "=", "curl_init", "(", ")", ";", "curl_setopt_array", "(", "$", "curls", "[", "$", "index", "]", ",", "array", "(", "CURLOPT_URL", "=>", "$", "request", "->", "getUrl", "(", ")", ",", "CURLOPT_HEADER", "=>", "0", ",", "CURLOPT_RETURNTRANSFER", "=>", "1", ")", ")", ";", "curl_multi_add_handle", "(", "$", "multi", ",", "$", "curls", "[", "$", "index", "]", ")", ";", "}", "do", "{", "while", "(", "(", "curl_multi_exec", "(", "$", "multi", ",", "$", "active", ")", ")", "==", "CURLM_CALL_MULTI_PERFORM", ")", ";", "while", "(", "$", "info", "=", "curl_multi_info_read", "(", "$", "multi", ")", ")", "{", "if", "(", "$", "info", "[", "'result'", "]", "==", "CURLE_OK", ")", "{", "$", "return", "=", "curl_multi_getcontent", "(", "$", "info", "[", "'handle'", "]", ")", ";", "$", "cinfo", "=", "curl_getinfo", "(", "$", "info", "[", "'handle'", "]", ")", ";", "$", "url", "=", "parse_url", "(", "$", "cinfo", "[", "'url'", "]", ")", ";", "$", "response", "=", "new", "\\", "Yubikey", "\\", "Response", "(", "array", "(", "'host'", "=>", "$", "url", "[", "'host'", "]", ",", "'mt'", "=>", "(", "microtime", "(", "true", ")", "-", "$", "startTime", ")", ")", ")", ";", "$", "response", "->", "parse", "(", "$", "return", ")", ";", "$", "responses", "->", "add", "(", "$", "response", ")", ";", "}", "}", "}", "while", "(", "$", "active", ")", ";", "return", "$", "responses", ";", "}" ]
Make the request given the Request set and content @param \Yubikey\RequestCollection $requests Request collection @return \Yubikey\ResponseCollection instance
[ "Make", "the", "request", "given", "the", "Request", "set", "and", "content" ]
d8487c4c28ee6ae75d10077c97795e8b64fa8ff4
https://github.com/enygma/yubikey/blob/d8487c4c28ee6ae75d10077c97795e8b64fa8ff4/src/Yubikey/Client.php#L28-L64
222,666
joomla-framework/form
src/Field/CheckboxesField.php
CheckboxesField.getInput
protected function getInput() { $html = array(); // Initialize some field attributes. $class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"'; $checkedOptions = explode(',', (string) $this->element['checked']); // Start the checkbox field output. $html[] = '<fieldset id="' . $this->id . '"' . $class . '>'; // Get the field options. $options = $this->getOptions(); // Build the checkbox field output. $html[] = '<ul>'; foreach ($options as $i => $option) { // Initialize some option attributes. if (!isset($this->value) || empty($this->value)) { $checked = (in_array((string) $option->value, (array) $checkedOptions) ? ' checked="checked"' : ''); } else { $value = !is_array($this->value) ? explode(',', $this->value) : $this->value; $checked = (in_array((string) $option->value, $value) ? ' checked="checked"' : ''); } $class = !empty($option->class) ? ' class="' . $option->class . '"' : ''; $disabled = !empty($option->disable) ? ' disabled="disabled"' : ''; // Initialize some JavaScript option attributes. $onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : ''; $label = $this->translateLabel ? $this->getText()->translate($option->text) : $option->text; $html[] = '<li>'; $html[] = '<input type="checkbox" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="' . htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>'; $html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . $label . '</label>'; $html[] = '</li>'; } $html[] = '</ul>'; // End the checkbox field output. $html[] = '</fieldset>'; return implode($html); }
php
protected function getInput() { $html = array(); // Initialize some field attributes. $class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"'; $checkedOptions = explode(',', (string) $this->element['checked']); // Start the checkbox field output. $html[] = '<fieldset id="' . $this->id . '"' . $class . '>'; // Get the field options. $options = $this->getOptions(); // Build the checkbox field output. $html[] = '<ul>'; foreach ($options as $i => $option) { // Initialize some option attributes. if (!isset($this->value) || empty($this->value)) { $checked = (in_array((string) $option->value, (array) $checkedOptions) ? ' checked="checked"' : ''); } else { $value = !is_array($this->value) ? explode(',', $this->value) : $this->value; $checked = (in_array((string) $option->value, $value) ? ' checked="checked"' : ''); } $class = !empty($option->class) ? ' class="' . $option->class . '"' : ''; $disabled = !empty($option->disable) ? ' disabled="disabled"' : ''; // Initialize some JavaScript option attributes. $onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : ''; $label = $this->translateLabel ? $this->getText()->translate($option->text) : $option->text; $html[] = '<li>'; $html[] = '<input type="checkbox" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="' . htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>'; $html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . $label . '</label>'; $html[] = '</li>'; } $html[] = '</ul>'; // End the checkbox field output. $html[] = '</fieldset>'; return implode($html); }
[ "protected", "function", "getInput", "(", ")", "{", "$", "html", "=", "array", "(", ")", ";", "// Initialize some field attributes.", "$", "class", "=", "$", "this", "->", "element", "[", "'class'", "]", "?", "' class=\"checkboxes '", ".", "(", "string", ")", "$", "this", "->", "element", "[", "'class'", "]", ".", "'\"'", ":", "' class=\"checkboxes\"'", ";", "$", "checkedOptions", "=", "explode", "(", "','", ",", "(", "string", ")", "$", "this", "->", "element", "[", "'checked'", "]", ")", ";", "// Start the checkbox field output.", "$", "html", "[", "]", "=", "'<fieldset id=\"'", ".", "$", "this", "->", "id", ".", "'\"'", ".", "$", "class", ".", "'>'", ";", "// Get the field options.", "$", "options", "=", "$", "this", "->", "getOptions", "(", ")", ";", "// Build the checkbox field output.", "$", "html", "[", "]", "=", "'<ul>'", ";", "foreach", "(", "$", "options", "as", "$", "i", "=>", "$", "option", ")", "{", "// Initialize some option attributes.", "if", "(", "!", "isset", "(", "$", "this", "->", "value", ")", "||", "empty", "(", "$", "this", "->", "value", ")", ")", "{", "$", "checked", "=", "(", "in_array", "(", "(", "string", ")", "$", "option", "->", "value", ",", "(", "array", ")", "$", "checkedOptions", ")", "?", "' checked=\"checked\"'", ":", "''", ")", ";", "}", "else", "{", "$", "value", "=", "!", "is_array", "(", "$", "this", "->", "value", ")", "?", "explode", "(", "','", ",", "$", "this", "->", "value", ")", ":", "$", "this", "->", "value", ";", "$", "checked", "=", "(", "in_array", "(", "(", "string", ")", "$", "option", "->", "value", ",", "$", "value", ")", "?", "' checked=\"checked\"'", ":", "''", ")", ";", "}", "$", "class", "=", "!", "empty", "(", "$", "option", "->", "class", ")", "?", "' class=\"'", ".", "$", "option", "->", "class", ".", "'\"'", ":", "''", ";", "$", "disabled", "=", "!", "empty", "(", "$", "option", "->", "disable", ")", "?", "' disabled=\"disabled\"'", ":", "''", ";", "// Initialize some JavaScript option attributes.", "$", "onclick", "=", "!", "empty", "(", "$", "option", "->", "onclick", ")", "?", "' onclick=\"'", ".", "$", "option", "->", "onclick", ".", "'\"'", ":", "''", ";", "$", "label", "=", "$", "this", "->", "translateLabel", "?", "$", "this", "->", "getText", "(", ")", "->", "translate", "(", "$", "option", "->", "text", ")", ":", "$", "option", "->", "text", ";", "$", "html", "[", "]", "=", "'<li>'", ";", "$", "html", "[", "]", "=", "'<input type=\"checkbox\" id=\"'", ".", "$", "this", "->", "id", ".", "$", "i", ".", "'\" name=\"'", ".", "$", "this", "->", "name", ".", "'\"'", ".", "' value=\"'", ".", "htmlspecialchars", "(", "$", "option", "->", "value", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ".", "'\"'", ".", "$", "checked", ".", "$", "class", ".", "$", "onclick", ".", "$", "disabled", ".", "'/>'", ";", "$", "html", "[", "]", "=", "'<label for=\"'", ".", "$", "this", "->", "id", ".", "$", "i", ".", "'\"'", ".", "$", "class", ".", "'>'", ".", "$", "label", ".", "'</label>'", ";", "$", "html", "[", "]", "=", "'</li>'", ";", "}", "$", "html", "[", "]", "=", "'</ul>'", ";", "// End the checkbox field output.", "$", "html", "[", "]", "=", "'</fieldset>'", ";", "return", "implode", "(", "$", "html", ")", ";", "}" ]
Method to get the field input markup for check boxes. @return string The field input markup. @since 1.0
[ "Method", "to", "get", "the", "field", "input", "markup", "for", "check", "boxes", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Field/CheckboxesField.php#L45-L96
222,667
joomla-framework/form
src/Field/PasswordField.php
PasswordField.getInput
protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; $auto = ((string) $this->element['autocomplete'] == 'off') ? ' autocomplete="off"' : ''; $readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : ''; $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : ''; // Temporary workaround to make sure the placeholder can be set without coupling to joomla/language $placeholder = ''; if ($this->element['placeholder']) { try { $placeholder = ' placeholder="' . $this->getText()->translate((string) $this->element['placeholder']) . '"'; } catch (\RuntimeException $e) { $placeholder = ' placeholder="' . (string) $this->element['placeholder'] . '"'; } } return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $auto . $class . $readonly . $disabled . $size . $maxLength . $placeholder . '/>'; }
php
protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; $auto = ((string) $this->element['autocomplete'] == 'off') ? ' autocomplete="off"' : ''; $readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : ''; $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : ''; // Temporary workaround to make sure the placeholder can be set without coupling to joomla/language $placeholder = ''; if ($this->element['placeholder']) { try { $placeholder = ' placeholder="' . $this->getText()->translate((string) $this->element['placeholder']) . '"'; } catch (\RuntimeException $e) { $placeholder = ' placeholder="' . (string) $this->element['placeholder'] . '"'; } } return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $auto . $class . $readonly . $disabled . $size . $maxLength . $placeholder . '/>'; }
[ "protected", "function", "getInput", "(", ")", "{", "// Initialize some field attributes.", "$", "size", "=", "$", "this", "->", "element", "[", "'size'", "]", "?", "' size=\"'", ".", "(", "int", ")", "$", "this", "->", "element", "[", "'size'", "]", ".", "'\"'", ":", "''", ";", "$", "maxLength", "=", "$", "this", "->", "element", "[", "'maxlength'", "]", "?", "' maxlength=\"'", ".", "(", "int", ")", "$", "this", "->", "element", "[", "'maxlength'", "]", ".", "'\"'", ":", "''", ";", "$", "class", "=", "$", "this", "->", "element", "[", "'class'", "]", "?", "' class=\"'", ".", "(", "string", ")", "$", "this", "->", "element", "[", "'class'", "]", ".", "'\"'", ":", "''", ";", "$", "auto", "=", "(", "(", "string", ")", "$", "this", "->", "element", "[", "'autocomplete'", "]", "==", "'off'", ")", "?", "' autocomplete=\"off\"'", ":", "''", ";", "$", "readonly", "=", "(", "(", "string", ")", "$", "this", "->", "element", "[", "'readonly'", "]", "==", "'true'", ")", "?", "' readonly=\"readonly\"'", ":", "''", ";", "$", "disabled", "=", "(", "(", "string", ")", "$", "this", "->", "element", "[", "'disabled'", "]", "==", "'true'", ")", "?", "' disabled=\"disabled\"'", ":", "''", ";", "// Temporary workaround to make sure the placeholder can be set without coupling to joomla/language", "$", "placeholder", "=", "''", ";", "if", "(", "$", "this", "->", "element", "[", "'placeholder'", "]", ")", "{", "try", "{", "$", "placeholder", "=", "' placeholder=\"'", ".", "$", "this", "->", "getText", "(", ")", "->", "translate", "(", "(", "string", ")", "$", "this", "->", "element", "[", "'placeholder'", "]", ")", ".", "'\"'", ";", "}", "catch", "(", "\\", "RuntimeException", "$", "e", ")", "{", "$", "placeholder", "=", "' placeholder=\"'", ".", "(", "string", ")", "$", "this", "->", "element", "[", "'placeholder'", "]", ".", "'\"'", ";", "}", "}", "return", "'<input type=\"password\" name=\"'", ".", "$", "this", "->", "name", ".", "'\" id=\"'", ".", "$", "this", "->", "id", ".", "'\"'", ".", "' value=\"'", ".", "htmlspecialchars", "(", "$", "this", "->", "value", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ".", "'\"'", ".", "$", "auto", ".", "$", "class", ".", "$", "readonly", ".", "$", "disabled", ".", "$", "size", ".", "$", "maxLength", ".", "$", "placeholder", ".", "'/>'", ";", "}" ]
Method to get the field input markup for password. @return string The field input markup. @since 1.0
[ "Method", "to", "get", "the", "field", "input", "markup", "for", "password", "." ]
3bc5e3bc3c5c8ba5374623785483f7a677bfb012
https://github.com/joomla-framework/form/blob/3bc5e3bc3c5c8ba5374623785483f7a677bfb012/src/Field/PasswordField.php#L38-L66
222,668
dmmlabo/dmm-php-sdk
src/Dmm/Exceptions/DmmResponseException.php
DmmResponseException.create
public static function create(DmmResponse $response) { $data = $response->getDecodedBody(); $code = isset($data['status']) ? $data['status'] : null; $message = isset($data['message']) ? $data['message'] : 'Unknown error from API.'; // All others return new static($response, new DmmOtherException($message, $code)); }
php
public static function create(DmmResponse $response) { $data = $response->getDecodedBody(); $code = isset($data['status']) ? $data['status'] : null; $message = isset($data['message']) ? $data['message'] : 'Unknown error from API.'; // All others return new static($response, new DmmOtherException($message, $code)); }
[ "public", "static", "function", "create", "(", "DmmResponse", "$", "response", ")", "{", "$", "data", "=", "$", "response", "->", "getDecodedBody", "(", ")", ";", "$", "code", "=", "isset", "(", "$", "data", "[", "'status'", "]", ")", "?", "$", "data", "[", "'status'", "]", ":", "null", ";", "$", "message", "=", "isset", "(", "$", "data", "[", "'message'", "]", ")", "?", "$", "data", "[", "'message'", "]", ":", "'Unknown error from API.'", ";", "// All others", "return", "new", "static", "(", "$", "response", ",", "new", "DmmOtherException", "(", "$", "message", ",", "$", "code", ")", ")", ";", "}" ]
A factory for creating the appropriate exception based on the response from API. @param DmmResponse $response The response that threw the exception. @return DmmResponseException
[ "A", "factory", "for", "creating", "the", "appropriate", "exception", "based", "on", "the", "response", "from", "API", "." ]
027fbe8fbf07178460e449ede116f9eae91061eb
https://github.com/dmmlabo/dmm-php-sdk/blob/027fbe8fbf07178460e449ede116f9eae91061eb/src/Dmm/Exceptions/DmmResponseException.php#L47-L56
222,669
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Config/Clone.php
EcomDev_Varnish_Model_Config_Clone.getPrefixes
public function getPrefixes() { $prefixes = array(); foreach (Mage::helper('ecomdev_varnish')->getAllowedPages() as $name => $label) { $prefixes[] = array( 'field' => $name.'_', 'label' => $label ); } return $prefixes; }
php
public function getPrefixes() { $prefixes = array(); foreach (Mage::helper('ecomdev_varnish')->getAllowedPages() as $name => $label) { $prefixes[] = array( 'field' => $name.'_', 'label' => $label ); } return $prefixes; }
[ "public", "function", "getPrefixes", "(", ")", "{", "$", "prefixes", "=", "array", "(", ")", ";", "foreach", "(", "Mage", "::", "helper", "(", "'ecomdev_varnish'", ")", "->", "getAllowedPages", "(", ")", "as", "$", "name", "=>", "$", "label", ")", "{", "$", "prefixes", "[", "]", "=", "array", "(", "'field'", "=>", "$", "name", ".", "'_'", ",", "'label'", "=>", "$", "label", ")", ";", "}", "return", "$", "prefixes", ";", "}" ]
Get field prefixes for generating translation config nodes @return array
[ "Get", "field", "prefixes", "for", "generating", "translation", "config", "nodes" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Config/Clone.php#L31-L42
222,670
TerbiumLibs/dbConfig
src/Terbium/DbConfig/DbConfig.php
DbConfig.store
public function store($key, $value) { // save key => value into DB $this->dbProvider->store($key, $value); //set value to config $this->origConfig->set($key, $value); }
php
public function store($key, $value) { // save key => value into DB $this->dbProvider->store($key, $value); //set value to config $this->origConfig->set($key, $value); }
[ "public", "function", "store", "(", "$", "key", ",", "$", "value", ")", "{", "// save key => value into DB", "$", "this", "->", "dbProvider", "->", "store", "(", "$", "key", ",", "$", "value", ")", ";", "//set value to config", "$", "this", "->", "origConfig", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "}" ]
Save item into database and set to current config @param string $key @param mixed $value @return void @throws Exceptions\SaveException
[ "Save", "item", "into", "database", "and", "set", "to", "current", "config" ]
c418de91cf13af8bce107e9da6226abc9a0167c6
https://github.com/TerbiumLibs/dbConfig/blob/c418de91cf13af8bce107e9da6226abc9a0167c6/src/Terbium/DbConfig/DbConfig.php#L68-L78
222,671
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Catalogrule/Observer.php
EcomDev_Varnish_Model_Catalogrule_Observer.retrieveAppliedProducts
public function retrieveAppliedProducts(Varien_Event_Observer $observer) { $this->_productIds = $this->_getResource()->getAffectedProductIds( $observer->getEvent()->getProductCondition() ); }
php
public function retrieveAppliedProducts(Varien_Event_Observer $observer) { $this->_productIds = $this->_getResource()->getAffectedProductIds( $observer->getEvent()->getProductCondition() ); }
[ "public", "function", "retrieveAppliedProducts", "(", "Varien_Event_Observer", "$", "observer", ")", "{", "$", "this", "->", "_productIds", "=", "$", "this", "->", "_getResource", "(", ")", "->", "getAffectedProductIds", "(", "$", "observer", "->", "getEvent", "(", ")", "->", "getProductCondition", "(", ")", ")", ";", "}" ]
Collects affected products by price rules @param Varien_Event_Observer $observer
[ "Collects", "affected", "products", "by", "price", "rules" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Catalogrule/Observer.php#L37-L42
222,672
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Catalogrule/Observer.php
EcomDev_Varnish_Model_Catalogrule_Observer.postApply
public function postApply(Varien_Event_Observer $observer) { $productIds = array(); foreach ($this->_productIds as $productId) { $productIds[] = EcomDev_Varnish_Model_Processor_Product::TAG_PREFIX . $productId; } // Run cleaning process separately if amount of stored tags too large $chunks = array_chunk( $productIds, 500 ); foreach ($chunks as $tags) { Mage::getSingleton('ecomdev_varnish/connector')->banTags($tags); } $this->_productIds = array(); }
php
public function postApply(Varien_Event_Observer $observer) { $productIds = array(); foreach ($this->_productIds as $productId) { $productIds[] = EcomDev_Varnish_Model_Processor_Product::TAG_PREFIX . $productId; } // Run cleaning process separately if amount of stored tags too large $chunks = array_chunk( $productIds, 500 ); foreach ($chunks as $tags) { Mage::getSingleton('ecomdev_varnish/connector')->banTags($tags); } $this->_productIds = array(); }
[ "public", "function", "postApply", "(", "Varien_Event_Observer", "$", "observer", ")", "{", "$", "productIds", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_productIds", "as", "$", "productId", ")", "{", "$", "productIds", "[", "]", "=", "EcomDev_Varnish_Model_Processor_Product", "::", "TAG_PREFIX", ".", "$", "productId", ";", "}", "// Run cleaning process separately if amount of stored tags too large", "$", "chunks", "=", "array_chunk", "(", "$", "productIds", ",", "500", ")", ";", "foreach", "(", "$", "chunks", "as", "$", "tags", ")", "{", "Mage", "::", "getSingleton", "(", "'ecomdev_varnish/connector'", ")", "->", "banTags", "(", "$", "tags", ")", ";", "}", "$", "this", "->", "_productIds", "=", "array", "(", ")", ";", "}" ]
Clears cache after applying the price rules @param Varien_Event_Observer $observer
[ "Clears", "cache", "after", "applying", "the", "price", "rules" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Catalogrule/Observer.php#L49-L67
222,673
gordalina/easypay-php
src/Gordalina/Easypay/Payment/RecurringPayment.php
RecurringPayment.getAllowedPaymentFrequencies
protected function getAllowedPaymentFrequencies() { return array( static::DAILY, static::WEEKLY, static::SEMIMONTHLY, static::MONTHLY, static::BIMONTHLY, static::QUATERLY, static::EVERY_4_MONTHS, static::SEMIANNUAL, static::ANNUAL, ); }
php
protected function getAllowedPaymentFrequencies() { return array( static::DAILY, static::WEEKLY, static::SEMIMONTHLY, static::MONTHLY, static::BIMONTHLY, static::QUATERLY, static::EVERY_4_MONTHS, static::SEMIANNUAL, static::ANNUAL, ); }
[ "protected", "function", "getAllowedPaymentFrequencies", "(", ")", "{", "return", "array", "(", "static", "::", "DAILY", ",", "static", "::", "WEEKLY", ",", "static", "::", "SEMIMONTHLY", ",", "static", "::", "MONTHLY", ",", "static", "::", "BIMONTHLY", ",", "static", "::", "QUATERLY", ",", "static", "::", "EVERY_4_MONTHS", ",", "static", "::", "SEMIANNUAL", ",", "static", "::", "ANNUAL", ",", ")", ";", "}" ]
Returns an array of valid payment frequencies @return array
[ "Returns", "an", "array", "of", "valid", "payment", "frequencies" ]
23e8d462f33834233cad4e9fbe9fc57267c1e573
https://github.com/gordalina/easypay-php/blob/23e8d462f33834233cad4e9fbe9fc57267c1e573/src/Gordalina/Easypay/Payment/RecurringPayment.php#L78-L91
222,674
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php
EcomDev_Varnish_Model_AbstractFacade.add
public function add($item) { foreach ($this->_requiredInterfaces as $interface) { if (!$item instanceof $interface) { throw new RuntimeException( sprintf('Item "%s" should implement "%s" interface', get_class($item), $interface) ); } } $this->_items[spl_object_hash($item)] = $item; return $this; }
php
public function add($item) { foreach ($this->_requiredInterfaces as $interface) { if (!$item instanceof $interface) { throw new RuntimeException( sprintf('Item "%s" should implement "%s" interface', get_class($item), $interface) ); } } $this->_items[spl_object_hash($item)] = $item; return $this; }
[ "public", "function", "add", "(", "$", "item", ")", "{", "foreach", "(", "$", "this", "->", "_requiredInterfaces", "as", "$", "interface", ")", "{", "if", "(", "!", "$", "item", "instanceof", "$", "interface", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Item \"%s\" should implement \"%s\" interface'", ",", "get_class", "(", "$", "item", ")", ",", "$", "interface", ")", ")", ";", "}", "}", "$", "this", "->", "_items", "[", "spl_object_hash", "(", "$", "item", ")", "]", "=", "$", "item", ";", "return", "$", "this", ";", "}" ]
Adds an item to facade @param EcomDev_Varnish_Model_ApplicableInterface $item @return $this @throws RuntimeException
[ "Adds", "an", "item", "to", "facade" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php#L51-L63
222,675
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php
EcomDev_Varnish_Model_AbstractFacade.remove
public function remove($item) { $hash = spl_object_hash($item); if (isset($this->_items[$hash])) { unset($this->_items[$hash]); } return $this; }
php
public function remove($item) { $hash = spl_object_hash($item); if (isset($this->_items[$hash])) { unset($this->_items[$hash]); } return $this; }
[ "public", "function", "remove", "(", "$", "item", ")", "{", "$", "hash", "=", "spl_object_hash", "(", "$", "item", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_items", "[", "$", "hash", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "_items", "[", "$", "hash", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Removes items from facade @param EcomDev_Varnish_Model_ApplicableInterface $item @return $this
[ "Removes", "items", "from", "facade" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php#L71-L79
222,676
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php
EcomDev_Varnish_Model_AbstractFacade._initItems
protected function _initItems() { if (!$this->_itemsXmlPath) { throw new RuntimeException('XML Path for facade items is not specified'); } $config = Mage::getConfig()->getNode($this->_itemsXmlPath)->children(); foreach ($config as $class) { $this->add(Mage::getModel($class)); } return $this; }
php
protected function _initItems() { if (!$this->_itemsXmlPath) { throw new RuntimeException('XML Path for facade items is not specified'); } $config = Mage::getConfig()->getNode($this->_itemsXmlPath)->children(); foreach ($config as $class) { $this->add(Mage::getModel($class)); } return $this; }
[ "protected", "function", "_initItems", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_itemsXmlPath", ")", "{", "throw", "new", "RuntimeException", "(", "'XML Path for facade items is not specified'", ")", ";", "}", "$", "config", "=", "Mage", "::", "getConfig", "(", ")", "->", "getNode", "(", "$", "this", "->", "_itemsXmlPath", ")", "->", "children", "(", ")", ";", "foreach", "(", "$", "config", "as", "$", "class", ")", "{", "$", "this", "->", "add", "(", "Mage", "::", "getModel", "(", "$", "class", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Initializes default facade items @return $this @throws RuntimeException
[ "Initializes", "default", "facade", "items" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php#L87-L100
222,677
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php
EcomDev_Varnish_Model_AbstractFacade.items
public function items($object = null) { if (!$this->_items) { $this->_initItems(); } $items = array(); foreach ($this->_items as $item) { if ($object !== null && !$item->isApplicable($object)) { continue; } $items[] = $item; } return $items; }
php
public function items($object = null) { if (!$this->_items) { $this->_initItems(); } $items = array(); foreach ($this->_items as $item) { if ($object !== null && !$item->isApplicable($object)) { continue; } $items[] = $item; } return $items; }
[ "public", "function", "items", "(", "$", "object", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "_items", ")", "{", "$", "this", "->", "_initItems", "(", ")", ";", "}", "$", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_items", "as", "$", "item", ")", "{", "if", "(", "$", "object", "!==", "null", "&&", "!", "$", "item", "->", "isApplicable", "(", "$", "object", ")", ")", "{", "continue", ";", "}", "$", "items", "[", "]", "=", "$", "item", ";", "}", "return", "$", "items", ";", "}" ]
Retrieves facade items If object is specified, it will filter out items by isApplicable interface @param null|object $object @return EcomDev_Varnish_Model_ApplicableInterface[]
[ "Retrieves", "facade", "items", "If", "object", "is", "specified", "it", "will", "filter", "out", "items", "by", "isApplicable", "interface" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php#L109-L126
222,678
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php
EcomDev_Varnish_Model_AbstractFacade.walk
public function walk($method, $arg = null, $object = null) { $result = array(); foreach ($this->items($object) as $item) { $itemResult = $item->$method($arg); if ($itemResult === $item) { continue; } if (!is_array($itemResult)) { $result[] = $itemResult; } elseif (isset($itemResult[0])) { array_splice($result, count($result), 0, $itemResult); } elseif (count($itemResult)) { $result += $itemResult; } } return $result; }
php
public function walk($method, $arg = null, $object = null) { $result = array(); foreach ($this->items($object) as $item) { $itemResult = $item->$method($arg); if ($itemResult === $item) { continue; } if (!is_array($itemResult)) { $result[] = $itemResult; } elseif (isset($itemResult[0])) { array_splice($result, count($result), 0, $itemResult); } elseif (count($itemResult)) { $result += $itemResult; } } return $result; }
[ "public", "function", "walk", "(", "$", "method", ",", "$", "arg", "=", "null", ",", "$", "object", "=", "null", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "items", "(", "$", "object", ")", "as", "$", "item", ")", "{", "$", "itemResult", "=", "$", "item", "->", "$", "method", "(", "$", "arg", ")", ";", "if", "(", "$", "itemResult", "===", "$", "item", ")", "{", "continue", ";", "}", "if", "(", "!", "is_array", "(", "$", "itemResult", ")", ")", "{", "$", "result", "[", "]", "=", "$", "itemResult", ";", "}", "elseif", "(", "isset", "(", "$", "itemResult", "[", "0", "]", ")", ")", "{", "array_splice", "(", "$", "result", ",", "count", "(", "$", "result", ")", ",", "0", ",", "$", "itemResult", ")", ";", "}", "elseif", "(", "count", "(", "$", "itemResult", ")", ")", "{", "$", "result", "+=", "$", "itemResult", ";", "}", "}", "return", "$", "result", ";", "}" ]
Invokes method on each facade item with specified arguments @param string $method @param null|mixed $arg @param null|object $object @return array
[ "Invokes", "method", "on", "each", "facade", "item", "with", "specified", "arguments" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/AbstractFacade.php#L137-L155
222,679
univicosa/laravel-openid-client
Services/Api.php
Api.initialize
private static function initialize() { if (self::$initialized) return; self::$client = \OpenId::getClient(); self::$version = config('openid.api-version'); self::$initialized = TRUE; }
php
private static function initialize() { if (self::$initialized) return; self::$client = \OpenId::getClient(); self::$version = config('openid.api-version'); self::$initialized = TRUE; }
[ "private", "static", "function", "initialize", "(", ")", "{", "if", "(", "self", "::", "$", "initialized", ")", "return", ";", "self", "::", "$", "client", "=", "\\", "OpenId", "::", "getClient", "(", ")", ";", "self", "::", "$", "version", "=", "config", "(", "'openid.api-version'", ")", ";", "self", "::", "$", "initialized", "=", "TRUE", ";", "}" ]
Static class constructor
[ "Static", "class", "constructor" ]
42ac511de250b597ba12ef0216f1d493fd7a2def
https://github.com/univicosa/laravel-openid-client/blob/42ac511de250b597ba12ef0216f1d493fd7a2def/Services/Api.php#L28-L35
222,680
xcaliber-tech/omnipay-skrill
src/Omnipay/Skrill/Message/StatusCallback.php
StatusCallback.isCancelled
public function isCancelled() { if (!$this->testMdSignatures()) { return false; } return in_array($this->getStatus(), [self::STATUS_CHARGEBACK, self::STATUS_FAILED, self::STATUS_CANCELLED]); }
php
public function isCancelled() { if (!$this->testMdSignatures()) { return false; } return in_array($this->getStatus(), [self::STATUS_CHARGEBACK, self::STATUS_FAILED, self::STATUS_CANCELLED]); }
[ "public", "function", "isCancelled", "(", ")", "{", "if", "(", "!", "$", "this", "->", "testMdSignatures", "(", ")", ")", "{", "return", "false", ";", "}", "return", "in_array", "(", "$", "this", "->", "getStatus", "(", ")", ",", "[", "self", "::", "STATUS_CHARGEBACK", ",", "self", "::", "STATUS_FAILED", ",", "self", "::", "STATUS_CANCELLED", "]", ")", ";", "}" ]
Was the payment cancelled? @return bool
[ "Was", "the", "payment", "cancelled?" ]
f90a185b5e26fb5b4150d664f01ad8048b460bcf
https://github.com/xcaliber-tech/omnipay-skrill/blob/f90a185b5e26fb5b4150d664f01ad8048b460bcf/src/Omnipay/Skrill/Message/StatusCallback.php#L87-L94
222,681
xcaliber-tech/omnipay-skrill
src/Omnipay/Skrill/Message/StatusCallback.php
StatusCallback.validateSignatures
protected function validateSignatures() { if (!$this->testMdSignatures()) { return false; } if ($this->getSha2Signature() !== null) { return $this->getSha2Signature() === $this->calculateSha2Signature(); } return true; }
php
protected function validateSignatures() { if (!$this->testMdSignatures()) { return false; } if ($this->getSha2Signature() !== null) { return $this->getSha2Signature() === $this->calculateSha2Signature(); } return true; }
[ "protected", "function", "validateSignatures", "(", ")", "{", "if", "(", "!", "$", "this", "->", "testMdSignatures", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "getSha2Signature", "(", ")", "!==", "null", ")", "{", "return", "$", "this", "->", "getSha2Signature", "(", ")", "===", "$", "this", "->", "calculateSha2Signature", "(", ")", ";", "}", "return", "true", ";", "}" ]
Validates the MD5 signature and, if enabled, the SHA2 signature. @return bool
[ "Validates", "the", "MD5", "signature", "and", "if", "enabled", "the", "SHA2", "signature", "." ]
f90a185b5e26fb5b4150d664f01ad8048b460bcf
https://github.com/xcaliber-tech/omnipay-skrill/blob/f90a185b5e26fb5b4150d664f01ad8048b460bcf/src/Omnipay/Skrill/Message/StatusCallback.php#L101-L112
222,682
xcaliber-tech/omnipay-skrill
src/Omnipay/Skrill/Message/StatusCallback.php
StatusCallback.getSkrillAmount
public function getSkrillAmount($stringFormat = false) { $amount = (double)$this->data['mb_amount']; if ($stringFormat) { $amount = number_format($amount, 2, '.', ''); } return $amount; }
php
public function getSkrillAmount($stringFormat = false) { $amount = (double)$this->data['mb_amount']; if ($stringFormat) { $amount = number_format($amount, 2, '.', ''); } return $amount; }
[ "public", "function", "getSkrillAmount", "(", "$", "stringFormat", "=", "false", ")", "{", "$", "amount", "=", "(", "double", ")", "$", "this", "->", "data", "[", "'mb_amount'", "]", ";", "if", "(", "$", "stringFormat", ")", "{", "$", "amount", "=", "number_format", "(", "$", "amount", ",", "2", ",", "'.'", ",", "''", ")", ";", "}", "return", "$", "amount", ";", "}" ]
Get the total amount of the payment in merchant's currency. @param $stringFormat @return float|string amount
[ "Get", "the", "total", "amount", "of", "the", "payment", "in", "merchant", "s", "currency", "." ]
f90a185b5e26fb5b4150d664f01ad8048b460bcf
https://github.com/xcaliber-tech/omnipay-skrill/blob/f90a185b5e26fb5b4150d664f01ad8048b460bcf/src/Omnipay/Skrill/Message/StatusCallback.php#L212-L221
222,683
xcaliber-tech/omnipay-skrill
src/Omnipay/Skrill/Message/StatusCallback.php
StatusCallback.getMerchantFields
public function getMerchantFields(array $keys) { $fields = []; foreach ($keys as $key) { $fields[$key] = $this->data[$key]; } return $fields; }
php
public function getMerchantFields(array $keys) { $fields = []; foreach ($keys as $key) { $fields[$key] = $this->data[$key]; } return $fields; }
[ "public", "function", "getMerchantFields", "(", "array", "$", "keys", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "fields", "[", "$", "key", "]", "=", "$", "this", "->", "data", "[", "$", "key", "]", ";", "}", "return", "$", "fields", ";", "}" ]
Get the fields that the merchant chose to submit in the merchant_fields parameter. @param array $keys keys for the fields @return array merchant fields
[ "Get", "the", "fields", "that", "the", "merchant", "chose", "to", "submit", "in", "the", "merchant_fields", "parameter", "." ]
f90a185b5e26fb5b4150d664f01ad8048b460bcf
https://github.com/xcaliber-tech/omnipay-skrill/blob/f90a185b5e26fb5b4150d664f01ad8048b460bcf/src/Omnipay/Skrill/Message/StatusCallback.php#L318-L326
222,684
xcaliber-tech/omnipay-skrill
src/Omnipay/Skrill/Message/StatusCallback.php
StatusCallback.calculateMd5Signature
public function calculateMd5Signature() { return strtoupper(md5( $this->getMerchantId() . $this->getTransactionReference() . $this->getSecretWordForMd5Signature() . $this->getSkrillAmount(true) . $this->getSkrillCurrency() . $this->getStatus() )); }
php
public function calculateMd5Signature() { return strtoupper(md5( $this->getMerchantId() . $this->getTransactionReference() . $this->getSecretWordForMd5Signature() . $this->getSkrillAmount(true) . $this->getSkrillCurrency() . $this->getStatus() )); }
[ "public", "function", "calculateMd5Signature", "(", ")", "{", "return", "strtoupper", "(", "md5", "(", "$", "this", "->", "getMerchantId", "(", ")", ".", "$", "this", "->", "getTransactionReference", "(", ")", ".", "$", "this", "->", "getSecretWordForMd5Signature", "(", ")", ".", "$", "this", "->", "getSkrillAmount", "(", "true", ")", ".", "$", "this", "->", "getSkrillCurrency", "(", ")", ".", "$", "this", "->", "getStatus", "(", ")", ")", ")", ";", "}" ]
Calculate the 128 bit message digest, expressed as a string of thirty-two hexadecimal digits in UPPERCASE. The md5sig is constructed by performing a MD5 calculation on a string built up by concatenating the other fields returned to the status url. @return string md5 signature
[ "Calculate", "the", "128", "bit", "message", "digest", "expressed", "as", "a", "string", "of", "thirty", "-", "two", "hexadecimal", "digits", "in", "UPPERCASE", "." ]
f90a185b5e26fb5b4150d664f01ad8048b460bcf
https://github.com/xcaliber-tech/omnipay-skrill/blob/f90a185b5e26fb5b4150d664f01ad8048b460bcf/src/Omnipay/Skrill/Message/StatusCallback.php#L337-L347
222,685
xcaliber-tech/omnipay-skrill
src/Omnipay/Skrill/Message/StatusCallback.php
StatusCallback.calculateSha2Signature
public function calculateSha2Signature() { return hash('sha256', $this->getMerchantId() . $this->getTransactionReference() . $this->getSecretWordForMd5Signature() . $this->getSkrillAmount() . $this->getSkrillCurrency() . $this->getStatus() ); }
php
public function calculateSha2Signature() { return hash('sha256', $this->getMerchantId() . $this->getTransactionReference() . $this->getSecretWordForMd5Signature() . $this->getSkrillAmount() . $this->getSkrillCurrency() . $this->getStatus() ); }
[ "public", "function", "calculateSha2Signature", "(", ")", "{", "return", "hash", "(", "'sha256'", ",", "$", "this", "->", "getMerchantId", "(", ")", ".", "$", "this", "->", "getTransactionReference", "(", ")", ".", "$", "this", "->", "getSecretWordForMd5Signature", "(", ")", ".", "$", "this", "->", "getSkrillAmount", "(", ")", ".", "$", "this", "->", "getSkrillCurrency", "(", ")", ".", "$", "this", "->", "getStatus", "(", ")", ")", ";", "}" ]
Calculate the 256 bit message digest, expressed as a string of sixty-four hexadecimal digits in lowercase. The sha2sig is constructed by performing a SHA256 calculation on a string built up by concatenating the other fields returned to the status url. @return string sha2 signature
[ "Calculate", "the", "256", "bit", "message", "digest", "expressed", "as", "a", "string", "of", "sixty", "-", "four", "hexadecimal", "digits", "in", "lowercase", "." ]
f90a185b5e26fb5b4150d664f01ad8048b460bcf
https://github.com/xcaliber-tech/omnipay-skrill/blob/f90a185b5e26fb5b4150d664f01ad8048b460bcf/src/Omnipay/Skrill/Message/StatusCallback.php#L358-L368
222,686
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Block/Esi/Tag.php
EcomDev_Varnish_Block_Esi_Tag._beforeToHtml
protected function _beforeToHtml() { Mage::helper('ecomdev_varnish')->setIsEsiUsed(true); $handles = implode(',', $this->_handles); $params = array( 'handles' => $handles, 'package' => Mage::getSingleton('core/design_package')->getPackageName(), 'theme' => Mage::getSingleton('core/design_package')->getTheme('default') ?: 'default', 'store' => Mage::app()->getStore()->getCode(), 'block' => $this->getBlockName() ); if ($this->getTtl()) { $params['ttl'] = (string)$this->getTtl(); } if ($this->hasData('referrer') && !$this->getData('referrer')) { $params['filter_referrer'] = '1'; } if ($this->hasData('cookies') && !$this->getData('cookies')) { $params['filter_cookies'] = '1'; } $params['checksum'] = Mage::helper('ecomdev_varnish')->getChecksum($params); $params['_secure'] = Mage::app()->getStore()->isCurrentlySecure(); $url = $this->getUrl('varnish/esi/handle', $params); // Replace http with https, // So varnish can process ESI requests correctly and take domain name into account if (strpos($url, 'https://') === 0) { $url = 'http:' . substr($url, 6); } $this->setBlockUrl($url); $this->setHtmlId($this->getBlockAlias() . '-placeholder'); return parent::_beforeToHtml(); }
php
protected function _beforeToHtml() { Mage::helper('ecomdev_varnish')->setIsEsiUsed(true); $handles = implode(',', $this->_handles); $params = array( 'handles' => $handles, 'package' => Mage::getSingleton('core/design_package')->getPackageName(), 'theme' => Mage::getSingleton('core/design_package')->getTheme('default') ?: 'default', 'store' => Mage::app()->getStore()->getCode(), 'block' => $this->getBlockName() ); if ($this->getTtl()) { $params['ttl'] = (string)$this->getTtl(); } if ($this->hasData('referrer') && !$this->getData('referrer')) { $params['filter_referrer'] = '1'; } if ($this->hasData('cookies') && !$this->getData('cookies')) { $params['filter_cookies'] = '1'; } $params['checksum'] = Mage::helper('ecomdev_varnish')->getChecksum($params); $params['_secure'] = Mage::app()->getStore()->isCurrentlySecure(); $url = $this->getUrl('varnish/esi/handle', $params); // Replace http with https, // So varnish can process ESI requests correctly and take domain name into account if (strpos($url, 'https://') === 0) { $url = 'http:' . substr($url, 6); } $this->setBlockUrl($url); $this->setHtmlId($this->getBlockAlias() . '-placeholder'); return parent::_beforeToHtml(); }
[ "protected", "function", "_beforeToHtml", "(", ")", "{", "Mage", "::", "helper", "(", "'ecomdev_varnish'", ")", "->", "setIsEsiUsed", "(", "true", ")", ";", "$", "handles", "=", "implode", "(", "','", ",", "$", "this", "->", "_handles", ")", ";", "$", "params", "=", "array", "(", "'handles'", "=>", "$", "handles", ",", "'package'", "=>", "Mage", "::", "getSingleton", "(", "'core/design_package'", ")", "->", "getPackageName", "(", ")", ",", "'theme'", "=>", "Mage", "::", "getSingleton", "(", "'core/design_package'", ")", "->", "getTheme", "(", "'default'", ")", "?", ":", "'default'", ",", "'store'", "=>", "Mage", "::", "app", "(", ")", "->", "getStore", "(", ")", "->", "getCode", "(", ")", ",", "'block'", "=>", "$", "this", "->", "getBlockName", "(", ")", ")", ";", "if", "(", "$", "this", "->", "getTtl", "(", ")", ")", "{", "$", "params", "[", "'ttl'", "]", "=", "(", "string", ")", "$", "this", "->", "getTtl", "(", ")", ";", "}", "if", "(", "$", "this", "->", "hasData", "(", "'referrer'", ")", "&&", "!", "$", "this", "->", "getData", "(", "'referrer'", ")", ")", "{", "$", "params", "[", "'filter_referrer'", "]", "=", "'1'", ";", "}", "if", "(", "$", "this", "->", "hasData", "(", "'cookies'", ")", "&&", "!", "$", "this", "->", "getData", "(", "'cookies'", ")", ")", "{", "$", "params", "[", "'filter_cookies'", "]", "=", "'1'", ";", "}", "$", "params", "[", "'checksum'", "]", "=", "Mage", "::", "helper", "(", "'ecomdev_varnish'", ")", "->", "getChecksum", "(", "$", "params", ")", ";", "$", "params", "[", "'_secure'", "]", "=", "Mage", "::", "app", "(", ")", "->", "getStore", "(", ")", "->", "isCurrentlySecure", "(", ")", ";", "$", "url", "=", "$", "this", "->", "getUrl", "(", "'varnish/esi/handle'", ",", "$", "params", ")", ";", "// Replace http with https,", "// So varnish can process ESI requests correctly and take domain name into account", "if", "(", "strpos", "(", "$", "url", ",", "'https://'", ")", "===", "0", ")", "{", "$", "url", "=", "'http:'", ".", "substr", "(", "$", "url", ",", "6", ")", ";", "}", "$", "this", "->", "setBlockUrl", "(", "$", "url", ")", ";", "$", "this", "->", "setHtmlId", "(", "$", "this", "->", "getBlockAlias", "(", ")", ".", "'-placeholder'", ")", ";", "return", "parent", "::", "_beforeToHtml", "(", ")", ";", "}" ]
Outputs ESI tag @return string
[ "Outputs", "ESI", "tag" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Block/Esi/Tag.php#L69-L108
222,687
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Block/Esi/Tag.php
EcomDev_Varnish_Block_Esi_Tag.getBlockJson
public function getBlockJson() { $result = array( 'htmlId' => $this->getHtmlId(), 'url' => $this->getBlockUrl() ); return $this->helper('core')->jsonEncode($result); }
php
public function getBlockJson() { $result = array( 'htmlId' => $this->getHtmlId(), 'url' => $this->getBlockUrl() ); return $this->helper('core')->jsonEncode($result); }
[ "public", "function", "getBlockJson", "(", ")", "{", "$", "result", "=", "array", "(", "'htmlId'", "=>", "$", "this", "->", "getHtmlId", "(", ")", ",", "'url'", "=>", "$", "this", "->", "getBlockUrl", "(", ")", ")", ";", "return", "$", "this", "->", "helper", "(", "'core'", ")", "->", "jsonEncode", "(", "$", "result", ")", ";", "}" ]
Returns block json @return string[]
[ "Returns", "block", "json" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Block/Esi/Tag.php#L115-L123
222,688
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Message.php
EcomDev_Varnish_Model_Message.getMessageTypes
public function getMessageTypes() { if ($this->messageTypes === null) { $this->messageTypes = array(); $messageTypes = Mage::getConfig()->getNode(self::XML_PATH_MESSAGE_TYPES); if ($messageTypes) { foreach ($messageTypes->children() as $typeCode => $classAlias) { $this->messageTypes[$typeCode] = (string)$classAlias; } } } return $this->messageTypes; }
php
public function getMessageTypes() { if ($this->messageTypes === null) { $this->messageTypes = array(); $messageTypes = Mage::getConfig()->getNode(self::XML_PATH_MESSAGE_TYPES); if ($messageTypes) { foreach ($messageTypes->children() as $typeCode => $classAlias) { $this->messageTypes[$typeCode] = (string)$classAlias; } } } return $this->messageTypes; }
[ "public", "function", "getMessageTypes", "(", ")", "{", "if", "(", "$", "this", "->", "messageTypes", "===", "null", ")", "{", "$", "this", "->", "messageTypes", "=", "array", "(", ")", ";", "$", "messageTypes", "=", "Mage", "::", "getConfig", "(", ")", "->", "getNode", "(", "self", "::", "XML_PATH_MESSAGE_TYPES", ")", ";", "if", "(", "$", "messageTypes", ")", "{", "foreach", "(", "$", "messageTypes", "->", "children", "(", ")", "as", "$", "typeCode", "=>", "$", "classAlias", ")", "{", "$", "this", "->", "messageTypes", "[", "$", "typeCode", "]", "=", "(", "string", ")", "$", "classAlias", ";", "}", "}", "}", "return", "$", "this", "->", "messageTypes", ";", "}" ]
Returns message types for varnish cache @return string[]
[ "Returns", "message", "types", "for", "varnish", "cache" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Message.php#L41-L54
222,689
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Message.php
EcomDev_Varnish_Model_Message.getMessageTypeByStorage
public function getMessageTypeByStorage($storageType) { if ($this->messageTypeByStorageType === null) { $types = $this->getMessageTypes(); if ($types) { $this->messageTypeByStorageType = array_combine( array_values($types), array_keys($types) ); } else { $this->messageTypeByStorageType = array(); } } if (isset($this->messageTypeByStorageType[$storageType])) { return $this->messageTypeByStorageType[$storageType]; } return false; }
php
public function getMessageTypeByStorage($storageType) { if ($this->messageTypeByStorageType === null) { $types = $this->getMessageTypes(); if ($types) { $this->messageTypeByStorageType = array_combine( array_values($types), array_keys($types) ); } else { $this->messageTypeByStorageType = array(); } } if (isset($this->messageTypeByStorageType[$storageType])) { return $this->messageTypeByStorageType[$storageType]; } return false; }
[ "public", "function", "getMessageTypeByStorage", "(", "$", "storageType", ")", "{", "if", "(", "$", "this", "->", "messageTypeByStorageType", "===", "null", ")", "{", "$", "types", "=", "$", "this", "->", "getMessageTypes", "(", ")", ";", "if", "(", "$", "types", ")", "{", "$", "this", "->", "messageTypeByStorageType", "=", "array_combine", "(", "array_values", "(", "$", "types", ")", ",", "array_keys", "(", "$", "types", ")", ")", ";", "}", "else", "{", "$", "this", "->", "messageTypeByStorageType", "=", "array", "(", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "messageTypeByStorageType", "[", "$", "storageType", "]", ")", ")", "{", "return", "$", "this", "->", "messageTypeByStorageType", "[", "$", "storageType", "]", ";", "}", "return", "false", ";", "}" ]
Returns message type by storage @param string $storageType @return string|bool
[ "Returns", "message", "type", "by", "storage" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Message.php#L62-L81
222,690
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Message.php
EcomDev_Varnish_Model_Message.getStorageByMessageType
public function getStorageByMessageType($messageType) { if ($this->messageTypes === null) { $this->getMessageTypes(); } if (!isset($this->messageTypes[$messageType])) { return false; } return Mage::getSingleton($this->messageTypes[$messageType]); }
php
public function getStorageByMessageType($messageType) { if ($this->messageTypes === null) { $this->getMessageTypes(); } if (!isset($this->messageTypes[$messageType])) { return false; } return Mage::getSingleton($this->messageTypes[$messageType]); }
[ "public", "function", "getStorageByMessageType", "(", "$", "messageType", ")", "{", "if", "(", "$", "this", "->", "messageTypes", "===", "null", ")", "{", "$", "this", "->", "getMessageTypes", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "messageTypes", "[", "$", "messageType", "]", ")", ")", "{", "return", "false", ";", "}", "return", "Mage", "::", "getSingleton", "(", "$", "this", "->", "messageTypes", "[", "$", "messageType", "]", ")", ";", "}" ]
Returns storage by message type @param string $messageType @return Mage_Core_Model_Session_Abstract|bool
[ "Returns", "storage", "by", "message", "type" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Message.php#L89-L100
222,691
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Message.php
EcomDev_Varnish_Model_Message.addMessages
public function addMessages($messages, $storageType) { if ($messages instanceof Mage_Core_Model_Message_Collection) { $messages = $messages->getItems(); } $this->scheduledMessages[$storageType] = $messages; return $this; }
php
public function addMessages($messages, $storageType) { if ($messages instanceof Mage_Core_Model_Message_Collection) { $messages = $messages->getItems(); } $this->scheduledMessages[$storageType] = $messages; return $this; }
[ "public", "function", "addMessages", "(", "$", "messages", ",", "$", "storageType", ")", "{", "if", "(", "$", "messages", "instanceof", "Mage_Core_Model_Message_Collection", ")", "{", "$", "messages", "=", "$", "messages", "->", "getItems", "(", ")", ";", "}", "$", "this", "->", "scheduledMessages", "[", "$", "storageType", "]", "=", "$", "messages", ";", "return", "$", "this", ";", "}" ]
Adds messages for a later use @param Mage_Core_Model_Message_Collection|Mage_Core_Model_Message_Abstract[] $messages @param string $storageType @return $this
[ "Adds", "messages", "for", "a", "later", "use" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Message.php#L121-L129
222,692
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Message.php
EcomDev_Varnish_Model_Message.getMessages
public function getMessages($types) { $result = array(); foreach ($types as $type) { $storage = $this->getStorageByMessageType($type); if ($storage) { $result[] = $storage->getMessages(true); } } return $result; }
php
public function getMessages($types) { $result = array(); foreach ($types as $type) { $storage = $this->getStorageByMessageType($type); if ($storage) { $result[] = $storage->getMessages(true); } } return $result; }
[ "public", "function", "getMessages", "(", "$", "types", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "storage", "=", "$", "this", "->", "getStorageByMessageType", "(", "$", "type", ")", ";", "if", "(", "$", "storage", ")", "{", "$", "result", "[", "]", "=", "$", "storage", "->", "getMessages", "(", "true", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns all messages from types passed in argument @return Mage_Core_Model_Message_Collection[]
[ "Returns", "all", "messages", "from", "types", "passed", "in", "argument" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Message.php#L136-L148
222,693
EcomDev/EcomDev_Varnish
src/app/code/community/EcomDev/Varnish/Model/Message.php
EcomDev_Varnish_Model_Message.apply
public function apply() { if (!isset($_SESSION) || empty($_SESSION)) { return $this; } foreach ($this->messageBlocks as $messageBlock) { foreach ($messageBlock->getMessagesByStorage() as $storageType => $messages) { $this->addMessagesByStorageType($storageType, $messages); } } foreach ($this->scheduledMessages as $storageType => $messages) { $this->addMessagesByStorageType($storageType, $messages); } $types = array_keys($this->getMessageTypes()); $updatedStorages = []; foreach ($types as $type) { $storage = $this->getStorageByMessageType($type); if ($storage && $storage->getMessages(false)->getItems()) { $updatedStorages[] = $type; } } if ($updatedStorages) { Mage::getSingleton('ecomdev_varnish/cookie')->set( self::COOKIE_NAME, implode(',', $updatedStorages) ); } return $this; }
php
public function apply() { if (!isset($_SESSION) || empty($_SESSION)) { return $this; } foreach ($this->messageBlocks as $messageBlock) { foreach ($messageBlock->getMessagesByStorage() as $storageType => $messages) { $this->addMessagesByStorageType($storageType, $messages); } } foreach ($this->scheduledMessages as $storageType => $messages) { $this->addMessagesByStorageType($storageType, $messages); } $types = array_keys($this->getMessageTypes()); $updatedStorages = []; foreach ($types as $type) { $storage = $this->getStorageByMessageType($type); if ($storage && $storage->getMessages(false)->getItems()) { $updatedStorages[] = $type; } } if ($updatedStorages) { Mage::getSingleton('ecomdev_varnish/cookie')->set( self::COOKIE_NAME, implode(',', $updatedStorages) ); } return $this; }
[ "public", "function", "apply", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "_SESSION", ")", "||", "empty", "(", "$", "_SESSION", ")", ")", "{", "return", "$", "this", ";", "}", "foreach", "(", "$", "this", "->", "messageBlocks", "as", "$", "messageBlock", ")", "{", "foreach", "(", "$", "messageBlock", "->", "getMessagesByStorage", "(", ")", "as", "$", "storageType", "=>", "$", "messages", ")", "{", "$", "this", "->", "addMessagesByStorageType", "(", "$", "storageType", ",", "$", "messages", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "scheduledMessages", "as", "$", "storageType", "=>", "$", "messages", ")", "{", "$", "this", "->", "addMessagesByStorageType", "(", "$", "storageType", ",", "$", "messages", ")", ";", "}", "$", "types", "=", "array_keys", "(", "$", "this", "->", "getMessageTypes", "(", ")", ")", ";", "$", "updatedStorages", "=", "[", "]", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "storage", "=", "$", "this", "->", "getStorageByMessageType", "(", "$", "type", ")", ";", "if", "(", "$", "storage", "&&", "$", "storage", "->", "getMessages", "(", "false", ")", "->", "getItems", "(", ")", ")", "{", "$", "updatedStorages", "[", "]", "=", "$", "type", ";", "}", "}", "if", "(", "$", "updatedStorages", ")", "{", "Mage", "::", "getSingleton", "(", "'ecomdev_varnish/cookie'", ")", "->", "set", "(", "self", "::", "COOKIE_NAME", ",", "implode", "(", "','", ",", "$", "updatedStorages", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Applies changes values stored in message block into session instances @return $this
[ "Applies", "changes", "values", "stored", "in", "message", "block", "into", "session", "instances" ]
228b7b1bdaae15c1895f2533667fffa515447915
https://github.com/EcomDev/EcomDev_Varnish/blob/228b7b1bdaae15c1895f2533667fffa515447915/src/app/code/community/EcomDev/Varnish/Model/Message.php#L155-L190
222,694
basarevych/dynamic-table
php/DynamicTable/Table.php
Table.setSortColumn
public function setSortColumn($column) { $this->sortColumn = null; $found = false; foreach ($this->getColumns() as $id => $params) { if ($id == $column) { $found = ($params['sortable'] === true); break; } } if ($found) $this->sortColumn = $column; return $this; }
php
public function setSortColumn($column) { $this->sortColumn = null; $found = false; foreach ($this->getColumns() as $id => $params) { if ($id == $column) { $found = ($params['sortable'] === true); break; } } if ($found) $this->sortColumn = $column; return $this; }
[ "public", "function", "setSortColumn", "(", "$", "column", ")", "{", "$", "this", "->", "sortColumn", "=", "null", ";", "$", "found", "=", "false", ";", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", "as", "$", "id", "=>", "$", "params", ")", "{", "if", "(", "$", "id", "==", "$", "column", ")", "{", "$", "found", "=", "(", "$", "params", "[", "'sortable'", "]", "===", "true", ")", ";", "break", ";", "}", "}", "if", "(", "$", "found", ")", "$", "this", "->", "sortColumn", "=", "$", "column", ";", "return", "$", "this", ";", "}" ]
Sort column setter @param string $column @return Table
[ "Sort", "column", "setter" ]
227eafab0d4dafabe0d2ceaa881ab3befe994d9c
https://github.com/basarevych/dynamic-table/blob/227eafab0d4dafabe0d2ceaa881ab3befe994d9c/php/DynamicTable/Table.php#L294-L310
222,695
basarevych/dynamic-table
php/DynamicTable/Table.php
Table.setSortDir
public function setSortDir($dir) { if (in_array($dir, [ self::DIR_ASC, self::DIR_DESC ])) $this->sortDir = $dir; else $this->sortDir = self::DIR_ASC; return $this; }
php
public function setSortDir($dir) { if (in_array($dir, [ self::DIR_ASC, self::DIR_DESC ])) $this->sortDir = $dir; else $this->sortDir = self::DIR_ASC; return $this; }
[ "public", "function", "setSortDir", "(", "$", "dir", ")", "{", "if", "(", "in_array", "(", "$", "dir", ",", "[", "self", "::", "DIR_ASC", ",", "self", "::", "DIR_DESC", "]", ")", ")", "$", "this", "->", "sortDir", "=", "$", "dir", ";", "else", "$", "this", "->", "sortDir", "=", "self", "::", "DIR_ASC", ";", "return", "$", "this", ";", "}" ]
Sort direction setter @param string $dir @return Table
[ "Sort", "direction", "setter" ]
227eafab0d4dafabe0d2ceaa881ab3befe994d9c
https://github.com/basarevych/dynamic-table/blob/227eafab0d4dafabe0d2ceaa881ab3befe994d9c/php/DynamicTable/Table.php#L328-L336
222,696
basarevych/dynamic-table
php/DynamicTable/Table.php
Table.setPageNumber
public function setPageNumber($number) { $this->pageNumber = ($number === null ? 1 : (int)$number); if ($this->pageNumber < 1) $this->pageNumber = 1; return $this; }
php
public function setPageNumber($number) { $this->pageNumber = ($number === null ? 1 : (int)$number); if ($this->pageNumber < 1) $this->pageNumber = 1; return $this; }
[ "public", "function", "setPageNumber", "(", "$", "number", ")", "{", "$", "this", "->", "pageNumber", "=", "(", "$", "number", "===", "null", "?", "1", ":", "(", "int", ")", "$", "number", ")", ";", "if", "(", "$", "this", "->", "pageNumber", "<", "1", ")", "$", "this", "->", "pageNumber", "=", "1", ";", "return", "$", "this", ";", "}" ]
Page number setter @param integer $number @return Table
[ "Page", "number", "setter" ]
227eafab0d4dafabe0d2ceaa881ab3befe994d9c
https://github.com/basarevych/dynamic-table/blob/227eafab0d4dafabe0d2ceaa881ab3befe994d9c/php/DynamicTable/Table.php#L354-L361
222,697
basarevych/dynamic-table
php/DynamicTable/Table.php
Table.setPageSize
public function setPageSize($size) { $this->pageSize = ($size === null ? self::PAGE_SIZE : (int)$size); if ($this->pageSize < 0) $this->pageSize = self::PAGE_SIZE; return $this; }
php
public function setPageSize($size) { $this->pageSize = ($size === null ? self::PAGE_SIZE : (int)$size); if ($this->pageSize < 0) $this->pageSize = self::PAGE_SIZE; return $this; }
[ "public", "function", "setPageSize", "(", "$", "size", ")", "{", "$", "this", "->", "pageSize", "=", "(", "$", "size", "===", "null", "?", "self", "::", "PAGE_SIZE", ":", "(", "int", ")", "$", "size", ")", ";", "if", "(", "$", "this", "->", "pageSize", "<", "0", ")", "$", "this", "->", "pageSize", "=", "self", "::", "PAGE_SIZE", ";", "return", "$", "this", ";", "}" ]
Page size setter @param integer $size @return Table
[ "Page", "size", "setter" ]
227eafab0d4dafabe0d2ceaa881ab3befe994d9c
https://github.com/basarevych/dynamic-table/blob/227eafab0d4dafabe0d2ceaa881ab3befe994d9c/php/DynamicTable/Table.php#L379-L386
222,698
basarevych/dynamic-table
php/DynamicTable/Table.php
Table.setPageParams
public function setPageParams($params) { $this->setFilters(json_decode(@$params['filters'], true)); $this->setSortColumn(json_decode(@$params['sort_column'], true)); $this->setSortDir(json_decode(@$params['sort_dir'], true)); $this->setPageNumber(json_decode(@$params['page_number'], true)); $this->setPageSize(json_decode(@$params['page_size'], true)); return $this; }
php
public function setPageParams($params) { $this->setFilters(json_decode(@$params['filters'], true)); $this->setSortColumn(json_decode(@$params['sort_column'], true)); $this->setSortDir(json_decode(@$params['sort_dir'], true)); $this->setPageNumber(json_decode(@$params['page_number'], true)); $this->setPageSize(json_decode(@$params['page_size'], true)); return $this; }
[ "public", "function", "setPageParams", "(", "$", "params", ")", "{", "$", "this", "->", "setFilters", "(", "json_decode", "(", "@", "$", "params", "[", "'filters'", "]", ",", "true", ")", ")", ";", "$", "this", "->", "setSortColumn", "(", "json_decode", "(", "@", "$", "params", "[", "'sort_column'", "]", ",", "true", ")", ")", ";", "$", "this", "->", "setSortDir", "(", "json_decode", "(", "@", "$", "params", "[", "'sort_dir'", "]", ",", "true", ")", ")", ";", "$", "this", "->", "setPageNumber", "(", "json_decode", "(", "@", "$", "params", "[", "'page_number'", "]", ",", "true", ")", ")", ";", "$", "this", "->", "setPageSize", "(", "json_decode", "(", "@", "$", "params", "[", "'page_size'", "]", ",", "true", ")", ")", ";", "return", "$", "this", ";", "}" ]
Sets sort, filter and pagination options @param array $params @return Table
[ "Sets", "sort", "filter", "and", "pagination", "options" ]
227eafab0d4dafabe0d2ceaa881ab3befe994d9c
https://github.com/basarevych/dynamic-table/blob/227eafab0d4dafabe0d2ceaa881ab3befe994d9c/php/DynamicTable/Table.php#L414-L423
222,699
basarevych/dynamic-table
php/DynamicTable/Table.php
Table.describe
public function describe() { $columns = []; foreach ($this->columns as $id => $params) { $columns[$id] = [ 'title' => $params['title'], 'type' => $params['type'], 'filters' => $params['filters'], 'sortable' => $params['sortable'], 'visible' => $params['visible'], ]; } return [ 'columns' => $columns, ]; }
php
public function describe() { $columns = []; foreach ($this->columns as $id => $params) { $columns[$id] = [ 'title' => $params['title'], 'type' => $params['type'], 'filters' => $params['filters'], 'sortable' => $params['sortable'], 'visible' => $params['visible'], ]; } return [ 'columns' => $columns, ]; }
[ "public", "function", "describe", "(", ")", "{", "$", "columns", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "id", "=>", "$", "params", ")", "{", "$", "columns", "[", "$", "id", "]", "=", "[", "'title'", "=>", "$", "params", "[", "'title'", "]", ",", "'type'", "=>", "$", "params", "[", "'type'", "]", ",", "'filters'", "=>", "$", "params", "[", "'filters'", "]", ",", "'sortable'", "=>", "$", "params", "[", "'sortable'", "]", ",", "'visible'", "=>", "$", "params", "[", "'visible'", "]", ",", "]", ";", "}", "return", "[", "'columns'", "=>", "$", "columns", ",", "]", ";", "}" ]
Return table description @return array
[ "Return", "table", "description" ]
227eafab0d4dafabe0d2ceaa881ab3befe994d9c
https://github.com/basarevych/dynamic-table/blob/227eafab0d4dafabe0d2ceaa881ab3befe994d9c/php/DynamicTable/Table.php#L449-L465