repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
nabab/bbn
src/bbn/appui/mapper.php
mapper.get_default_field_config
public function get_default_field_config($table, $column){ // Looks in the db for columns corresponding to the given table if ( $this->db && bbn\str::check_name($column) && ($table_cfg = $this->db->modelize($table)) && isset($table_cfg['fields'][$column]) ){ $col = $table_cfg['fields'][$column]; $full_name = explode(".", $this->db->table_full_name($table))[1].'.'.$column; $cfg = [ 'attr' => [ 'name' => $full_name, ], 'null' => $col['null'] ? 1 : false ]; if ( strpos($col['type'], 'enum') === 0 ){ preg_match_all("/'((?:[^']|\\\\.)*)'/", $col['extra'], $m); if ( isset($m[1]) ){ $cfg['field'] = 'dropdown'; $cfg['data'] = $m[1]; } } else{ $ref = false; if ( isset($col['keys']) ){ foreach ( $col['keys'] as $k ){ $key = $table_cfg['keys'][$k]; if ( bbn\str::check_name($key['ref_db'], $key['ref_table'], $key['ref_column']) ){ $ref = [ 'db' => $key['ref_db'], 'table' => $key['ref_table'], 'column' => $key['ref_column'] ]; break; } } } if ( \is_array($ref) && $ref_table_cfg = $this->db->modelize($ref['table']) ){ // Arguments for select $cols = [$ref['column']]; foreach ( $ref_table_cfg['fields'] as $name => $def ){ if ( ($def['type'] === 'varchar') || ($def['type'] === 'text') ){ $cols = [ "value" => $ref['column'], "text" => $name ]; break; } } $cfg['data']['sql'] = $this->db->get_full_select($ref['table'], $cols); $cfg['data']['db'] = $this->db; $cfg['field'] = 'dropdown'; } else if ( strpos($col['type'], 'char') !== false ){ $cfg['field'] = 'text'; } else if ( strpos($col['type'], 'float') !== false ){ $cfg['field'] = 'numeric'; $dec = explode(",", $col['maxlength']); if ( isset($dec[0], $dec[1]) ){ $cfg['widget']['options']['decimals'] = (int)$dec[1]; } $cfg['attr']['maxlength'] = isset($cfg['widget']['options']['decimals']) ? (int)($col['maxlength'] + 1) : (int)$col['maxlength']; $cfg['widget']['options']['format'] = empty($cfg['widget']['options']['decimals']) ? 'n0' : 'n2'; $cfg['attr']['type'] = 'number'; $cfg['widget']['options']['step'] = 10/pow(10, $cfg['widget']['options']['decimals']+1); $max = ''; $max_length = $cfg['attr']['maxlength']; if ( isset($cfg['options']['decimals']) ){ $max_length -= $cfg['options']['decimals']; } for ( $i = 0; $i < $max_length; $i++ ){ $max .= '9'; } $max = (int)$max; $cfg['widget']['options']['max'] = ( (float)$max > (int)$max ) ? (float)$max : (int)$max; $cfg['widget']['options']['min'] = $col['signed'] ? - $cfg['widget']['options']['max'] : 0; } else if ( strpos($col['type'], 'text') !== false ){ $cfg['field'] = 'editor'; } else if ( $col['type'] === 'datetime' ){ $cfg['field'] = 'datetime'; } else if ( $col['type'] === 'date' ){ $cfg['field'] = 'date'; } else if ( $col['type'] === 'time' ){ $cfg['field'] = 'time'; } else if ( $col['type'] === 'timestamp' ){ $cfg['field'] = 'datetime'; } else if ( strpos($col['type'], 'int') !== false ){ if ( $col['maxlength'] == 1 ){ $cfg['field'] = 'checkbox'; } else if ( !isset($cfg['field']) ){ if ( strpos($col['type'], 'unsigned') ){ $cfg['widget']['options']['min'] = 0; } else{ $cfg['widget']['options']['min'] = false; } $cfg['field'] = 'numeric'; $cfg['widget']['options']['decimals'] = 0; $cfg['widget']['options']['format'] = 'd'; $cfg['attr']['type'] = 'number'; } } } return $cfg; } }
php
public function get_default_field_config($table, $column){ // Looks in the db for columns corresponding to the given table if ( $this->db && bbn\str::check_name($column) && ($table_cfg = $this->db->modelize($table)) && isset($table_cfg['fields'][$column]) ){ $col = $table_cfg['fields'][$column]; $full_name = explode(".", $this->db->table_full_name($table))[1].'.'.$column; $cfg = [ 'attr' => [ 'name' => $full_name, ], 'null' => $col['null'] ? 1 : false ]; if ( strpos($col['type'], 'enum') === 0 ){ preg_match_all("/'((?:[^']|\\\\.)*)'/", $col['extra'], $m); if ( isset($m[1]) ){ $cfg['field'] = 'dropdown'; $cfg['data'] = $m[1]; } } else{ $ref = false; if ( isset($col['keys']) ){ foreach ( $col['keys'] as $k ){ $key = $table_cfg['keys'][$k]; if ( bbn\str::check_name($key['ref_db'], $key['ref_table'], $key['ref_column']) ){ $ref = [ 'db' => $key['ref_db'], 'table' => $key['ref_table'], 'column' => $key['ref_column'] ]; break; } } } if ( \is_array($ref) && $ref_table_cfg = $this->db->modelize($ref['table']) ){ // Arguments for select $cols = [$ref['column']]; foreach ( $ref_table_cfg['fields'] as $name => $def ){ if ( ($def['type'] === 'varchar') || ($def['type'] === 'text') ){ $cols = [ "value" => $ref['column'], "text" => $name ]; break; } } $cfg['data']['sql'] = $this->db->get_full_select($ref['table'], $cols); $cfg['data']['db'] = $this->db; $cfg['field'] = 'dropdown'; } else if ( strpos($col['type'], 'char') !== false ){ $cfg['field'] = 'text'; } else if ( strpos($col['type'], 'float') !== false ){ $cfg['field'] = 'numeric'; $dec = explode(",", $col['maxlength']); if ( isset($dec[0], $dec[1]) ){ $cfg['widget']['options']['decimals'] = (int)$dec[1]; } $cfg['attr']['maxlength'] = isset($cfg['widget']['options']['decimals']) ? (int)($col['maxlength'] + 1) : (int)$col['maxlength']; $cfg['widget']['options']['format'] = empty($cfg['widget']['options']['decimals']) ? 'n0' : 'n2'; $cfg['attr']['type'] = 'number'; $cfg['widget']['options']['step'] = 10/pow(10, $cfg['widget']['options']['decimals']+1); $max = ''; $max_length = $cfg['attr']['maxlength']; if ( isset($cfg['options']['decimals']) ){ $max_length -= $cfg['options']['decimals']; } for ( $i = 0; $i < $max_length; $i++ ){ $max .= '9'; } $max = (int)$max; $cfg['widget']['options']['max'] = ( (float)$max > (int)$max ) ? (float)$max : (int)$max; $cfg['widget']['options']['min'] = $col['signed'] ? - $cfg['widget']['options']['max'] : 0; } else if ( strpos($col['type'], 'text') !== false ){ $cfg['field'] = 'editor'; } else if ( $col['type'] === 'datetime' ){ $cfg['field'] = 'datetime'; } else if ( $col['type'] === 'date' ){ $cfg['field'] = 'date'; } else if ( $col['type'] === 'time' ){ $cfg['field'] = 'time'; } else if ( $col['type'] === 'timestamp' ){ $cfg['field'] = 'datetime'; } else if ( strpos($col['type'], 'int') !== false ){ if ( $col['maxlength'] == 1 ){ $cfg['field'] = 'checkbox'; } else if ( !isset($cfg['field']) ){ if ( strpos($col['type'], 'unsigned') ){ $cfg['widget']['options']['min'] = 0; } else{ $cfg['widget']['options']['min'] = false; } $cfg['field'] = 'numeric'; $cfg['widget']['options']['decimals'] = 0; $cfg['widget']['options']['format'] = 'd'; $cfg['attr']['type'] = 'number'; } } } return $cfg; } }
[ "public", "function", "get_default_field_config", "(", "$", "table", ",", "$", "column", ")", "{", "// Looks in the db for columns corresponding to the given table", "if", "(", "$", "this", "->", "db", "&&", "bbn", "\\", "str", "::", "check_name", "(", "$", "column", ")", "&&", "(", "$", "table_cfg", "=", "$", "this", "->", "db", "->", "modelize", "(", "$", "table", ")", ")", "&&", "isset", "(", "$", "table_cfg", "[", "'fields'", "]", "[", "$", "column", "]", ")", ")", "{", "$", "col", "=", "$", "table_cfg", "[", "'fields'", "]", "[", "$", "column", "]", ";", "$", "full_name", "=", "explode", "(", "\".\"", ",", "$", "this", "->", "db", "->", "table_full_name", "(", "$", "table", ")", ")", "[", "1", "]", ".", "'.'", ".", "$", "column", ";", "$", "cfg", "=", "[", "'attr'", "=>", "[", "'name'", "=>", "$", "full_name", ",", "]", ",", "'null'", "=>", "$", "col", "[", "'null'", "]", "?", "1", ":", "false", "]", ";", "if", "(", "strpos", "(", "$", "col", "[", "'type'", "]", ",", "'enum'", ")", "===", "0", ")", "{", "preg_match_all", "(", "\"/'((?:[^']|\\\\\\\\.)*)'/\"", ",", "$", "col", "[", "'extra'", "]", ",", "$", "m", ")", ";", "if", "(", "isset", "(", "$", "m", "[", "1", "]", ")", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'dropdown'", ";", "$", "cfg", "[", "'data'", "]", "=", "$", "m", "[", "1", "]", ";", "}", "}", "else", "{", "$", "ref", "=", "false", ";", "if", "(", "isset", "(", "$", "col", "[", "'keys'", "]", ")", ")", "{", "foreach", "(", "$", "col", "[", "'keys'", "]", "as", "$", "k", ")", "{", "$", "key", "=", "$", "table_cfg", "[", "'keys'", "]", "[", "$", "k", "]", ";", "if", "(", "bbn", "\\", "str", "::", "check_name", "(", "$", "key", "[", "'ref_db'", "]", ",", "$", "key", "[", "'ref_table'", "]", ",", "$", "key", "[", "'ref_column'", "]", ")", ")", "{", "$", "ref", "=", "[", "'db'", "=>", "$", "key", "[", "'ref_db'", "]", ",", "'table'", "=>", "$", "key", "[", "'ref_table'", "]", ",", "'column'", "=>", "$", "key", "[", "'ref_column'", "]", "]", ";", "break", ";", "}", "}", "}", "if", "(", "\\", "is_array", "(", "$", "ref", ")", "&&", "$", "ref_table_cfg", "=", "$", "this", "->", "db", "->", "modelize", "(", "$", "ref", "[", "'table'", "]", ")", ")", "{", "// Arguments for select", "$", "cols", "=", "[", "$", "ref", "[", "'column'", "]", "]", ";", "foreach", "(", "$", "ref_table_cfg", "[", "'fields'", "]", "as", "$", "name", "=>", "$", "def", ")", "{", "if", "(", "(", "$", "def", "[", "'type'", "]", "===", "'varchar'", ")", "||", "(", "$", "def", "[", "'type'", "]", "===", "'text'", ")", ")", "{", "$", "cols", "=", "[", "\"value\"", "=>", "$", "ref", "[", "'column'", "]", ",", "\"text\"", "=>", "$", "name", "]", ";", "break", ";", "}", "}", "$", "cfg", "[", "'data'", "]", "[", "'sql'", "]", "=", "$", "this", "->", "db", "->", "get_full_select", "(", "$", "ref", "[", "'table'", "]", ",", "$", "cols", ")", ";", "$", "cfg", "[", "'data'", "]", "[", "'db'", "]", "=", "$", "this", "->", "db", ";", "$", "cfg", "[", "'field'", "]", "=", "'dropdown'", ";", "}", "else", "if", "(", "strpos", "(", "$", "col", "[", "'type'", "]", ",", "'char'", ")", "!==", "false", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'text'", ";", "}", "else", "if", "(", "strpos", "(", "$", "col", "[", "'type'", "]", ",", "'float'", ")", "!==", "false", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'numeric'", ";", "$", "dec", "=", "explode", "(", "\",\"", ",", "$", "col", "[", "'maxlength'", "]", ")", ";", "if", "(", "isset", "(", "$", "dec", "[", "0", "]", ",", "$", "dec", "[", "1", "]", ")", ")", "{", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'decimals'", "]", "=", "(", "int", ")", "$", "dec", "[", "1", "]", ";", "}", "$", "cfg", "[", "'attr'", "]", "[", "'maxlength'", "]", "=", "isset", "(", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'decimals'", "]", ")", "?", "(", "int", ")", "(", "$", "col", "[", "'maxlength'", "]", "+", "1", ")", ":", "(", "int", ")", "$", "col", "[", "'maxlength'", "]", ";", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'format'", "]", "=", "empty", "(", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'decimals'", "]", ")", "?", "'n0'", ":", "'n2'", ";", "$", "cfg", "[", "'attr'", "]", "[", "'type'", "]", "=", "'number'", ";", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'step'", "]", "=", "10", "/", "pow", "(", "10", ",", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'decimals'", "]", "+", "1", ")", ";", "$", "max", "=", "''", ";", "$", "max_length", "=", "$", "cfg", "[", "'attr'", "]", "[", "'maxlength'", "]", ";", "if", "(", "isset", "(", "$", "cfg", "[", "'options'", "]", "[", "'decimals'", "]", ")", ")", "{", "$", "max_length", "-=", "$", "cfg", "[", "'options'", "]", "[", "'decimals'", "]", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "max_length", ";", "$", "i", "++", ")", "{", "$", "max", ".=", "'9'", ";", "}", "$", "max", "=", "(", "int", ")", "$", "max", ";", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'max'", "]", "=", "(", "(", "float", ")", "$", "max", ">", "(", "int", ")", "$", "max", ")", "?", "(", "float", ")", "$", "max", ":", "(", "int", ")", "$", "max", ";", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'min'", "]", "=", "$", "col", "[", "'signed'", "]", "?", "-", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'max'", "]", ":", "0", ";", "}", "else", "if", "(", "strpos", "(", "$", "col", "[", "'type'", "]", ",", "'text'", ")", "!==", "false", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'editor'", ";", "}", "else", "if", "(", "$", "col", "[", "'type'", "]", "===", "'datetime'", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'datetime'", ";", "}", "else", "if", "(", "$", "col", "[", "'type'", "]", "===", "'date'", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'date'", ";", "}", "else", "if", "(", "$", "col", "[", "'type'", "]", "===", "'time'", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'time'", ";", "}", "else", "if", "(", "$", "col", "[", "'type'", "]", "===", "'timestamp'", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'datetime'", ";", "}", "else", "if", "(", "strpos", "(", "$", "col", "[", "'type'", "]", ",", "'int'", ")", "!==", "false", ")", "{", "if", "(", "$", "col", "[", "'maxlength'", "]", "==", "1", ")", "{", "$", "cfg", "[", "'field'", "]", "=", "'checkbox'", ";", "}", "else", "if", "(", "!", "isset", "(", "$", "cfg", "[", "'field'", "]", ")", ")", "{", "if", "(", "strpos", "(", "$", "col", "[", "'type'", "]", ",", "'unsigned'", ")", ")", "{", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'min'", "]", "=", "0", ";", "}", "else", "{", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'min'", "]", "=", "false", ";", "}", "$", "cfg", "[", "'field'", "]", "=", "'numeric'", ";", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'decimals'", "]", "=", "0", ";", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'format'", "]", "=", "'d'", ";", "$", "cfg", "[", "'attr'", "]", "[", "'type'", "]", "=", "'number'", ";", "}", "}", "}", "return", "$", "cfg", ";", "}", "}" ]
Creates an array for configuring an instance of input for a given field in a given table @param string $table The database's table @param string $column The table's column @return array $cfg a configuration array for bbn\html\input
[ "Creates", "an", "array", "for", "configuring", "an", "instance", "of", "input", "for", "a", "given", "field", "in", "a", "given", "table" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mapper.php#L610-L723
nabab/bbn
src/bbn/appui/mapper.php
mapper.update
public function update($db=''){ if ( empty($db) ){ $db = $this->db->current; } if ( bbn\str::check_name($db) ){ $this->db->clear_all_cache(); $change = $this->db->current === $db ? false : $this->db->current; if ( $change ){ $this->db->change($db); } $schema = $this->db->modelize(); if ( $change ){ $this->db->change($change); } /* $projects = []; $r1 = $this->db->query("SELECT * FROM `{$this->admin_db}`.`{$this->prefix}projects` WHERE `db` LIKE '$db'"); while ( $d1 = $r1->get_row() ){ $projects[$d1['id']] = $d1; $projects[$d1['id']]['forms'] = []; $r2 = $this->db->query(" SELECT id FROM `{$this->admin_db}`.`{$this->prefix}forms` WHERE `id_project` = ?", $d1['id']); while ( $d2 = $r2->get_row() ){ $projects[$d1['id']]['forms'][$d2['id']] = $this->get_form_config(); } } */ $this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'dbs',[ 'id' => $db, 'db' => $db, 'host' => $this->db->host ]); $tab_history = false; if ( bbn\appui\history::$is_used && isset($schema[bbn\appui\history::$htable]) ){ $tab_history = 1; } if ( !\is_array($schema) ){ die(var_dump("THIS IS NOT AN ARRAY", $schema)); } foreach ( $schema as $t => $vars ){ $col_history = $tab_history; if ( isset($vars['fields']) ){ $tmp = explode(".", $t); $db = $tmp[0]; $table = $tmp[1]; $this->db->insert_update($this->admin_db.'.'.$this->prefix.'tables',[ 'id' => $t, 'db' => $db, 'table' => $table ]); if ( $col_history && !array_key_exists(bbn\appui\history::$hcol, $vars['fields']) ){ $col_history = false; } foreach ( $vars['fields'] as $col => $f ){ $config = new \stdClass(); if ( $col_history && ($col !== bbn\appui\history::$hcol) ){ $config->history = 1; } if ( !empty($f['extra']) ){ $config->extra = $f['extra']; } if ( isset($f['signed']) && $f['signed'] == 1 ){ $config->signed = 1; } if ( isset($f['null']) && $f['null'] == '1' ){ $config->null = 1; } if ( isset($f['maxlength']) && $f['maxlength'] > 0 ){ $config->maxlength = (int)$f['maxlength']; } if ( isset($f['keys']) ){ $config->keys = []; foreach ( $f['keys'] as $key ){ $config->keys[$key] = $vars['keys'][$key]; } } $this->db->insert_update($this->admin_db.'.'.$this->prefix.'columns',[ 'id' => $t.'.'.$col, 'table' => $t, 'column' => $col, 'position' => $f['position'], 'type' => $f['type'], 'null' => $f['null'], 'key' => $f['key'], 'default' => $f['default'], 'config' => json_encode($config) ]); } } } foreach ( $schema as $t => $vars ){ if ( isset($vars['keys']) && \is_array($vars['keys']) ){ foreach ( $vars['keys'] as $k => $arr ){ $pos = 1; foreach ( $arr['columns'] as $c ){ $this->db->insert_update($this->admin_db.'.'.$this->prefix.'keys', [ 'id' => $t.'.'.$k, 'key' => $k, 'table' => $t, 'column' => $t.'.'.$c, 'position' => $pos, 'ref_column' => \is_null($arr['ref_column']) ? null : $arr['ref_db'].'.'.$arr['ref_table'].'.'.$arr['ref_column'], 'unique' => $arr['unique'] ]); $pos++; } } } } /* foreach ( $projects as $i => $p ){ $this->db->insert($this->admin_db.'.'.$this->prefix.'projects',[ 'id' => $i, 'id_client' => $p['id_client'], 'db' => $p['db'], 'name' => $p['name'], 'config' => $p['config']]); foreach ( $p['forms'] as $j => $form ){ $this->db->insert($this->admin_db.'.'.$this->prefix.'forms',[ 'id' => $j, 'id_project' => $i ]); foreach ( $form as $field ){ $this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'fields',[ 'id' => $field['id'], 'id_form' => $j, 'column' => $field['column'], 'title' => $field['title'], 'position' => $field['position'], 'configuration' => json_encode($field['configuration']) ]); } } } * */ $this->db->enable_keys(); } }
php
public function update($db=''){ if ( empty($db) ){ $db = $this->db->current; } if ( bbn\str::check_name($db) ){ $this->db->clear_all_cache(); $change = $this->db->current === $db ? false : $this->db->current; if ( $change ){ $this->db->change($db); } $schema = $this->db->modelize(); if ( $change ){ $this->db->change($change); } /* $projects = []; $r1 = $this->db->query("SELECT * FROM `{$this->admin_db}`.`{$this->prefix}projects` WHERE `db` LIKE '$db'"); while ( $d1 = $r1->get_row() ){ $projects[$d1['id']] = $d1; $projects[$d1['id']]['forms'] = []; $r2 = $this->db->query(" SELECT id FROM `{$this->admin_db}`.`{$this->prefix}forms` WHERE `id_project` = ?", $d1['id']); while ( $d2 = $r2->get_row() ){ $projects[$d1['id']]['forms'][$d2['id']] = $this->get_form_config(); } } */ $this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'dbs',[ 'id' => $db, 'db' => $db, 'host' => $this->db->host ]); $tab_history = false; if ( bbn\appui\history::$is_used && isset($schema[bbn\appui\history::$htable]) ){ $tab_history = 1; } if ( !\is_array($schema) ){ die(var_dump("THIS IS NOT AN ARRAY", $schema)); } foreach ( $schema as $t => $vars ){ $col_history = $tab_history; if ( isset($vars['fields']) ){ $tmp = explode(".", $t); $db = $tmp[0]; $table = $tmp[1]; $this->db->insert_update($this->admin_db.'.'.$this->prefix.'tables',[ 'id' => $t, 'db' => $db, 'table' => $table ]); if ( $col_history && !array_key_exists(bbn\appui\history::$hcol, $vars['fields']) ){ $col_history = false; } foreach ( $vars['fields'] as $col => $f ){ $config = new \stdClass(); if ( $col_history && ($col !== bbn\appui\history::$hcol) ){ $config->history = 1; } if ( !empty($f['extra']) ){ $config->extra = $f['extra']; } if ( isset($f['signed']) && $f['signed'] == 1 ){ $config->signed = 1; } if ( isset($f['null']) && $f['null'] == '1' ){ $config->null = 1; } if ( isset($f['maxlength']) && $f['maxlength'] > 0 ){ $config->maxlength = (int)$f['maxlength']; } if ( isset($f['keys']) ){ $config->keys = []; foreach ( $f['keys'] as $key ){ $config->keys[$key] = $vars['keys'][$key]; } } $this->db->insert_update($this->admin_db.'.'.$this->prefix.'columns',[ 'id' => $t.'.'.$col, 'table' => $t, 'column' => $col, 'position' => $f['position'], 'type' => $f['type'], 'null' => $f['null'], 'key' => $f['key'], 'default' => $f['default'], 'config' => json_encode($config) ]); } } } foreach ( $schema as $t => $vars ){ if ( isset($vars['keys']) && \is_array($vars['keys']) ){ foreach ( $vars['keys'] as $k => $arr ){ $pos = 1; foreach ( $arr['columns'] as $c ){ $this->db->insert_update($this->admin_db.'.'.$this->prefix.'keys', [ 'id' => $t.'.'.$k, 'key' => $k, 'table' => $t, 'column' => $t.'.'.$c, 'position' => $pos, 'ref_column' => \is_null($arr['ref_column']) ? null : $arr['ref_db'].'.'.$arr['ref_table'].'.'.$arr['ref_column'], 'unique' => $arr['unique'] ]); $pos++; } } } } /* foreach ( $projects as $i => $p ){ $this->db->insert($this->admin_db.'.'.$this->prefix.'projects',[ 'id' => $i, 'id_client' => $p['id_client'], 'db' => $p['db'], 'name' => $p['name'], 'config' => $p['config']]); foreach ( $p['forms'] as $j => $form ){ $this->db->insert($this->admin_db.'.'.$this->prefix.'forms',[ 'id' => $j, 'id_project' => $i ]); foreach ( $form as $field ){ $this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'fields',[ 'id' => $field['id'], 'id_form' => $j, 'column' => $field['column'], 'title' => $field['title'], 'position' => $field['position'], 'configuration' => json_encode($field['configuration']) ]); } } } * */ $this->db->enable_keys(); } }
[ "public", "function", "update", "(", "$", "db", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "db", ")", ")", "{", "$", "db", "=", "$", "this", "->", "db", "->", "current", ";", "}", "if", "(", "bbn", "\\", "str", "::", "check_name", "(", "$", "db", ")", ")", "{", "$", "this", "->", "db", "->", "clear_all_cache", "(", ")", ";", "$", "change", "=", "$", "this", "->", "db", "->", "current", "===", "$", "db", "?", "false", ":", "$", "this", "->", "db", "->", "current", ";", "if", "(", "$", "change", ")", "{", "$", "this", "->", "db", "->", "change", "(", "$", "db", ")", ";", "}", "$", "schema", "=", "$", "this", "->", "db", "->", "modelize", "(", ")", ";", "if", "(", "$", "change", ")", "{", "$", "this", "->", "db", "->", "change", "(", "$", "change", ")", ";", "}", "/*\n\t\t\t$projects = [];\n\t\t\t$r1 = $this->db->query(\"SELECT *\n\t\t\tFROM `{$this->admin_db}`.`{$this->prefix}projects`\n\t\t\tWHERE `db` LIKE '$db'\");\n\t\t\twhile ( $d1 = $r1->get_row() ){\n\t\t\t\t$projects[$d1['id']] = $d1;\n\t\t\t\t$projects[$d1['id']]['forms'] = [];\n\t\t\t\t$r2 = $this->db->query(\"\n\t\t\t\t\tSELECT id\n\t\t\t\t\tFROM `{$this->admin_db}`.`{$this->prefix}forms`\n\t\t\t\t\tWHERE `id_project` = ?\",\n\t\t\t\t\t$d1['id']);\n\t\t\t\twhile ( $d2 = $r2->get_row() ){\n\t\t\t\t\t$projects[$d1['id']]['forms'][$d2['id']] = $this->get_form_config();\n\t\t\t\t}\n\t\t\t}\n\t\t\t*/", "$", "this", "->", "db", "->", "insert_ignore", "(", "$", "this", "->", "admin_db", ".", "'.'", ".", "$", "this", "->", "prefix", ".", "'dbs'", ",", "[", "'id'", "=>", "$", "db", ",", "'db'", "=>", "$", "db", ",", "'host'", "=>", "$", "this", "->", "db", "->", "host", "]", ")", ";", "$", "tab_history", "=", "false", ";", "if", "(", "bbn", "\\", "appui", "\\", "history", "::", "$", "is_used", "&&", "isset", "(", "$", "schema", "[", "bbn", "\\", "appui", "\\", "history", "::", "$", "htable", "]", ")", ")", "{", "$", "tab_history", "=", "1", ";", "}", "if", "(", "!", "\\", "is_array", "(", "$", "schema", ")", ")", "{", "die", "(", "var_dump", "(", "\"THIS IS NOT AN ARRAY\"", ",", "$", "schema", ")", ")", ";", "}", "foreach", "(", "$", "schema", "as", "$", "t", "=>", "$", "vars", ")", "{", "$", "col_history", "=", "$", "tab_history", ";", "if", "(", "isset", "(", "$", "vars", "[", "'fields'", "]", ")", ")", "{", "$", "tmp", "=", "explode", "(", "\".\"", ",", "$", "t", ")", ";", "$", "db", "=", "$", "tmp", "[", "0", "]", ";", "$", "table", "=", "$", "tmp", "[", "1", "]", ";", "$", "this", "->", "db", "->", "insert_update", "(", "$", "this", "->", "admin_db", ".", "'.'", ".", "$", "this", "->", "prefix", ".", "'tables'", ",", "[", "'id'", "=>", "$", "t", ",", "'db'", "=>", "$", "db", ",", "'table'", "=>", "$", "table", "]", ")", ";", "if", "(", "$", "col_history", "&&", "!", "array_key_exists", "(", "bbn", "\\", "appui", "\\", "history", "::", "$", "hcol", ",", "$", "vars", "[", "'fields'", "]", ")", ")", "{", "$", "col_history", "=", "false", ";", "}", "foreach", "(", "$", "vars", "[", "'fields'", "]", "as", "$", "col", "=>", "$", "f", ")", "{", "$", "config", "=", "new", "\\", "stdClass", "(", ")", ";", "if", "(", "$", "col_history", "&&", "(", "$", "col", "!==", "bbn", "\\", "appui", "\\", "history", "::", "$", "hcol", ")", ")", "{", "$", "config", "->", "history", "=", "1", ";", "}", "if", "(", "!", "empty", "(", "$", "f", "[", "'extra'", "]", ")", ")", "{", "$", "config", "->", "extra", "=", "$", "f", "[", "'extra'", "]", ";", "}", "if", "(", "isset", "(", "$", "f", "[", "'signed'", "]", ")", "&&", "$", "f", "[", "'signed'", "]", "==", "1", ")", "{", "$", "config", "->", "signed", "=", "1", ";", "}", "if", "(", "isset", "(", "$", "f", "[", "'null'", "]", ")", "&&", "$", "f", "[", "'null'", "]", "==", "'1'", ")", "{", "$", "config", "->", "null", "=", "1", ";", "}", "if", "(", "isset", "(", "$", "f", "[", "'maxlength'", "]", ")", "&&", "$", "f", "[", "'maxlength'", "]", ">", "0", ")", "{", "$", "config", "->", "maxlength", "=", "(", "int", ")", "$", "f", "[", "'maxlength'", "]", ";", "}", "if", "(", "isset", "(", "$", "f", "[", "'keys'", "]", ")", ")", "{", "$", "config", "->", "keys", "=", "[", "]", ";", "foreach", "(", "$", "f", "[", "'keys'", "]", "as", "$", "key", ")", "{", "$", "config", "->", "keys", "[", "$", "key", "]", "=", "$", "vars", "[", "'keys'", "]", "[", "$", "key", "]", ";", "}", "}", "$", "this", "->", "db", "->", "insert_update", "(", "$", "this", "->", "admin_db", ".", "'.'", ".", "$", "this", "->", "prefix", ".", "'columns'", ",", "[", "'id'", "=>", "$", "t", ".", "'.'", ".", "$", "col", ",", "'table'", "=>", "$", "t", ",", "'column'", "=>", "$", "col", ",", "'position'", "=>", "$", "f", "[", "'position'", "]", ",", "'type'", "=>", "$", "f", "[", "'type'", "]", ",", "'null'", "=>", "$", "f", "[", "'null'", "]", ",", "'key'", "=>", "$", "f", "[", "'key'", "]", ",", "'default'", "=>", "$", "f", "[", "'default'", "]", ",", "'config'", "=>", "json_encode", "(", "$", "config", ")", "]", ")", ";", "}", "}", "}", "foreach", "(", "$", "schema", "as", "$", "t", "=>", "$", "vars", ")", "{", "if", "(", "isset", "(", "$", "vars", "[", "'keys'", "]", ")", "&&", "\\", "is_array", "(", "$", "vars", "[", "'keys'", "]", ")", ")", "{", "foreach", "(", "$", "vars", "[", "'keys'", "]", "as", "$", "k", "=>", "$", "arr", ")", "{", "$", "pos", "=", "1", ";", "foreach", "(", "$", "arr", "[", "'columns'", "]", "as", "$", "c", ")", "{", "$", "this", "->", "db", "->", "insert_update", "(", "$", "this", "->", "admin_db", ".", "'.'", ".", "$", "this", "->", "prefix", ".", "'keys'", ",", "[", "'id'", "=>", "$", "t", ".", "'.'", ".", "$", "k", ",", "'key'", "=>", "$", "k", ",", "'table'", "=>", "$", "t", ",", "'column'", "=>", "$", "t", ".", "'.'", ".", "$", "c", ",", "'position'", "=>", "$", "pos", ",", "'ref_column'", "=>", "\\", "is_null", "(", "$", "arr", "[", "'ref_column'", "]", ")", "?", "null", ":", "$", "arr", "[", "'ref_db'", "]", ".", "'.'", ".", "$", "arr", "[", "'ref_table'", "]", ".", "'.'", ".", "$", "arr", "[", "'ref_column'", "]", ",", "'unique'", "=>", "$", "arr", "[", "'unique'", "]", "]", ")", ";", "$", "pos", "++", ";", "}", "}", "}", "}", "/*\n\t\t\tforeach ( $projects as $i => $p ){\n\t\t\t\t$this->db->insert($this->admin_db.'.'.$this->prefix.'projects',[\n\t\t\t\t\t'id' => $i,\n\t\t\t\t\t'id_client' => $p['id_client'],\n\t\t\t\t\t'db' => $p['db'],\n\t\t\t\t\t'name' => $p['name'],\n\t\t\t\t\t'config' => $p['config']]);\n\t\t\t\tforeach ( $p['forms'] as $j => $form ){\n\t\t\t\t\t$this->db->insert($this->admin_db.'.'.$this->prefix.'forms',[\n\t\t\t\t\t\t'id' => $j,\n\t\t\t\t\t\t'id_project' => $i\n\t\t\t\t\t]);\n\t\t\t\t\tforeach ( $form as $field ){\n\t\t\t\t\t\t$this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'fields',[\n\t\t\t\t\t\t\t'id' => $field['id'],\n\t\t\t\t\t\t\t'id_form' => $j,\n\t\t\t\t\t\t\t'column' => $field['column'],\n\t\t\t\t\t\t\t'title' => $field['title'],\n\t\t\t\t\t\t\t'position' => $field['position'],\n\t\t\t\t\t\t\t'configuration' => json_encode($field['configuration'])\n\t\t\t\t\t\t]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n * \n */", "$", "this", "->", "db", "->", "enable_keys", "(", ")", ";", "}", "}" ]
Empties the structure tables for a given database and refill them with the current structure @param string $db @return void
[ "Empties", "the", "structure", "tables", "for", "a", "given", "database", "and", "refill", "them", "with", "the", "current", "structure" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mapper.php#L731-L878
wenbinye/PhalconX
src/Validation/ValidatorFactory.php
ValidatorFactory.create
public function create($options, Context $context = null) { $validators = []; if (!empty($options['required'])) { $validators[] = new PresenceOf(); } $type = ArrayHelper::fetch($options, 'type'); if (isset($type)) { if ($type == 'datetime') { $validators[] = new Datetime([ 'pattern' => ArrayHelper::fetch($options, 'pattern') ]); } elseif (isset(self::$TYPES[$type])) { $validators[] = (new self::$TYPES[$type]([]))->getValidator($this->form); } elseif ($type == 'array') { $validators[] = (new IsArray([ 'element' => ArrayHelper::fetch($options, 'element') ], $context))->getValidator($this->form); } else { if ($context) { $type = (new ClassResolver($this->form->getCache())) ->resolve($type, $context->getDeclaringClass()); } if (class_exists($type)) { if (is_subclass_of($type, ValidatorInterface::class)) { $validators[] = new $type($options); } else { $validators[] = new IsA($this->form, ['class' => $type]); } } else { if ($this->logger) { $this->logger->warning("unknown validator type {$type}"); } } } } if (isset($options['min']) || isset($options['max'])) { $validators[] = new Range([ 'min' => ArrayHelper::fetch($options, 'min'), 'max' => ArrayHelper::fetch($options, 'max'), 'exclusiveMinimum' => ArrayHelper::fetch($options, 'exclusiveMinimum'), 'exclusiveMaximum' => ArrayHelper::fetch($options, 'exclusiveMaximum') ]); } if (isset($options['minLength']) || isset($options['maxLength'])) { $validators[] = new StringLength([ 'min' => ArrayHelper::fetch($options, 'minLength'), 'max' => ArrayHelper::fetch($options, 'maxLength') ]); } if (isset($options['enum'])) { if (is_array($options['enum'])) { $validators[] = new InclusionIn(['domain' => $options['enum']]); } else { $validators[] = (new Enum([ 'model' => $options['enum'], 'attribute' => ArrayHelper::fetch($options, 'attribute'), ], $context))->getValidator($this->form); } } if (isset($options['pattern']) && $type != 'datetime') { $validators[] = new Regex([ 'pattern' => $options['pattern'] ]); } return $validators; }
php
public function create($options, Context $context = null) { $validators = []; if (!empty($options['required'])) { $validators[] = new PresenceOf(); } $type = ArrayHelper::fetch($options, 'type'); if (isset($type)) { if ($type == 'datetime') { $validators[] = new Datetime([ 'pattern' => ArrayHelper::fetch($options, 'pattern') ]); } elseif (isset(self::$TYPES[$type])) { $validators[] = (new self::$TYPES[$type]([]))->getValidator($this->form); } elseif ($type == 'array') { $validators[] = (new IsArray([ 'element' => ArrayHelper::fetch($options, 'element') ], $context))->getValidator($this->form); } else { if ($context) { $type = (new ClassResolver($this->form->getCache())) ->resolve($type, $context->getDeclaringClass()); } if (class_exists($type)) { if (is_subclass_of($type, ValidatorInterface::class)) { $validators[] = new $type($options); } else { $validators[] = new IsA($this->form, ['class' => $type]); } } else { if ($this->logger) { $this->logger->warning("unknown validator type {$type}"); } } } } if (isset($options['min']) || isset($options['max'])) { $validators[] = new Range([ 'min' => ArrayHelper::fetch($options, 'min'), 'max' => ArrayHelper::fetch($options, 'max'), 'exclusiveMinimum' => ArrayHelper::fetch($options, 'exclusiveMinimum'), 'exclusiveMaximum' => ArrayHelper::fetch($options, 'exclusiveMaximum') ]); } if (isset($options['minLength']) || isset($options['maxLength'])) { $validators[] = new StringLength([ 'min' => ArrayHelper::fetch($options, 'minLength'), 'max' => ArrayHelper::fetch($options, 'maxLength') ]); } if (isset($options['enum'])) { if (is_array($options['enum'])) { $validators[] = new InclusionIn(['domain' => $options['enum']]); } else { $validators[] = (new Enum([ 'model' => $options['enum'], 'attribute' => ArrayHelper::fetch($options, 'attribute'), ], $context))->getValidator($this->form); } } if (isset($options['pattern']) && $type != 'datetime') { $validators[] = new Regex([ 'pattern' => $options['pattern'] ]); } return $validators; }
[ "public", "function", "create", "(", "$", "options", ",", "Context", "$", "context", "=", "null", ")", "{", "$", "validators", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'required'", "]", ")", ")", "{", "$", "validators", "[", "]", "=", "new", "PresenceOf", "(", ")", ";", "}", "$", "type", "=", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'type'", ")", ";", "if", "(", "isset", "(", "$", "type", ")", ")", "{", "if", "(", "$", "type", "==", "'datetime'", ")", "{", "$", "validators", "[", "]", "=", "new", "Datetime", "(", "[", "'pattern'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'pattern'", ")", "]", ")", ";", "}", "elseif", "(", "isset", "(", "self", "::", "$", "TYPES", "[", "$", "type", "]", ")", ")", "{", "$", "validators", "[", "]", "=", "(", "new", "self", "::", "$", "TYPES", "[", "$", "type", "]", "(", "[", "]", ")", ")", "->", "getValidator", "(", "$", "this", "->", "form", ")", ";", "}", "elseif", "(", "$", "type", "==", "'array'", ")", "{", "$", "validators", "[", "]", "=", "(", "new", "IsArray", "(", "[", "'element'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'element'", ")", "]", ",", "$", "context", ")", ")", "->", "getValidator", "(", "$", "this", "->", "form", ")", ";", "}", "else", "{", "if", "(", "$", "context", ")", "{", "$", "type", "=", "(", "new", "ClassResolver", "(", "$", "this", "->", "form", "->", "getCache", "(", ")", ")", ")", "->", "resolve", "(", "$", "type", ",", "$", "context", "->", "getDeclaringClass", "(", ")", ")", ";", "}", "if", "(", "class_exists", "(", "$", "type", ")", ")", "{", "if", "(", "is_subclass_of", "(", "$", "type", ",", "ValidatorInterface", "::", "class", ")", ")", "{", "$", "validators", "[", "]", "=", "new", "$", "type", "(", "$", "options", ")", ";", "}", "else", "{", "$", "validators", "[", "]", "=", "new", "IsA", "(", "$", "this", "->", "form", ",", "[", "'class'", "=>", "$", "type", "]", ")", ";", "}", "}", "else", "{", "if", "(", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "warning", "(", "\"unknown validator type {$type}\"", ")", ";", "}", "}", "}", "}", "if", "(", "isset", "(", "$", "options", "[", "'min'", "]", ")", "||", "isset", "(", "$", "options", "[", "'max'", "]", ")", ")", "{", "$", "validators", "[", "]", "=", "new", "Range", "(", "[", "'min'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'min'", ")", ",", "'max'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'max'", ")", ",", "'exclusiveMinimum'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'exclusiveMinimum'", ")", ",", "'exclusiveMaximum'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'exclusiveMaximum'", ")", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'minLength'", "]", ")", "||", "isset", "(", "$", "options", "[", "'maxLength'", "]", ")", ")", "{", "$", "validators", "[", "]", "=", "new", "StringLength", "(", "[", "'min'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'minLength'", ")", ",", "'max'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'maxLength'", ")", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'enum'", "]", ")", ")", "{", "if", "(", "is_array", "(", "$", "options", "[", "'enum'", "]", ")", ")", "{", "$", "validators", "[", "]", "=", "new", "InclusionIn", "(", "[", "'domain'", "=>", "$", "options", "[", "'enum'", "]", "]", ")", ";", "}", "else", "{", "$", "validators", "[", "]", "=", "(", "new", "Enum", "(", "[", "'model'", "=>", "$", "options", "[", "'enum'", "]", ",", "'attribute'", "=>", "ArrayHelper", "::", "fetch", "(", "$", "options", ",", "'attribute'", ")", ",", "]", ",", "$", "context", ")", ")", "->", "getValidator", "(", "$", "this", "->", "form", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "options", "[", "'pattern'", "]", ")", "&&", "$", "type", "!=", "'datetime'", ")", "{", "$", "validators", "[", "]", "=", "new", "Regex", "(", "[", "'pattern'", "=>", "$", "options", "[", "'pattern'", "]", "]", ")", ";", "}", "return", "$", "validators", ";", "}" ]
options 可指定以下选项: - required - type - pattern - element - min - max - exclusiveMinimum - exclusiveMaximum - maxLength - minLength - enum - attribute
[ "options", "可指定以下选项:", "-", "required", "-", "type", "-", "pattern", "-", "element", "-", "min", "-", "max", "-", "exclusiveMinimum", "-", "exclusiveMaximum", "-", "maxLength", "-", "minLength", "-", "enum", "-", "attribute" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Validation/ValidatorFactory.php#L57-L121
rhosocial/yii2-user
widgets/UserListWidget.php
UserListWidget.init
public function init() { if (empty($this->dataProvider)) { throw new ServerErrorHttpException('Invalid User Provider.'); } if (is_string($this->actionColumn) && strtolower($this->actionColumn) == self::ACTION_COLUMN_DEFAULT) { $this->actionColumn = [ 'class' => ActionColumn::class, 'header' => Yii::t('user', 'Action'), 'useIcon' => false, 'urlCreator' => function ($action, $model, $key, $index, ActionColumn $column) { /* @var $model User */ if ($action == 'view') { return Url::to(['view', 'id' => $model->id]); } elseif ($action == 'update') { return Url::to(['update', 'id' => $model->id]); } elseif ($action == 'delete') { return Url::to(['deregister', 'id' => $model->id]); } return '#'; }, 'visibleButtons' => [ 'view' => Yii::$app->user->can('viewUser'), 'update' => Yii::$app->user->can('updateUser'), 'delete' => Yii::$app->user->can('deleteUser'), ], ]; } parent::init(); }
php
public function init() { if (empty($this->dataProvider)) { throw new ServerErrorHttpException('Invalid User Provider.'); } if (is_string($this->actionColumn) && strtolower($this->actionColumn) == self::ACTION_COLUMN_DEFAULT) { $this->actionColumn = [ 'class' => ActionColumn::class, 'header' => Yii::t('user', 'Action'), 'useIcon' => false, 'urlCreator' => function ($action, $model, $key, $index, ActionColumn $column) { /* @var $model User */ if ($action == 'view') { return Url::to(['view', 'id' => $model->id]); } elseif ($action == 'update') { return Url::to(['update', 'id' => $model->id]); } elseif ($action == 'delete') { return Url::to(['deregister', 'id' => $model->id]); } return '#'; }, 'visibleButtons' => [ 'view' => Yii::$app->user->can('viewUser'), 'update' => Yii::$app->user->can('updateUser'), 'delete' => Yii::$app->user->can('deleteUser'), ], ]; } parent::init(); }
[ "public", "function", "init", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "dataProvider", ")", ")", "{", "throw", "new", "ServerErrorHttpException", "(", "'Invalid User Provider.'", ")", ";", "}", "if", "(", "is_string", "(", "$", "this", "->", "actionColumn", ")", "&&", "strtolower", "(", "$", "this", "->", "actionColumn", ")", "==", "self", "::", "ACTION_COLUMN_DEFAULT", ")", "{", "$", "this", "->", "actionColumn", "=", "[", "'class'", "=>", "ActionColumn", "::", "class", ",", "'header'", "=>", "Yii", "::", "t", "(", "'user'", ",", "'Action'", ")", ",", "'useIcon'", "=>", "false", ",", "'urlCreator'", "=>", "function", "(", "$", "action", ",", "$", "model", ",", "$", "key", ",", "$", "index", ",", "ActionColumn", "$", "column", ")", "{", "/* @var $model User */", "if", "(", "$", "action", "==", "'view'", ")", "{", "return", "Url", "::", "to", "(", "[", "'view'", ",", "'id'", "=>", "$", "model", "->", "id", "]", ")", ";", "}", "elseif", "(", "$", "action", "==", "'update'", ")", "{", "return", "Url", "::", "to", "(", "[", "'update'", ",", "'id'", "=>", "$", "model", "->", "id", "]", ")", ";", "}", "elseif", "(", "$", "action", "==", "'delete'", ")", "{", "return", "Url", "::", "to", "(", "[", "'deregister'", ",", "'id'", "=>", "$", "model", "->", "id", "]", ")", ";", "}", "return", "'#'", ";", "}", ",", "'visibleButtons'", "=>", "[", "'view'", "=>", "Yii", "::", "$", "app", "->", "user", "->", "can", "(", "'viewUser'", ")", ",", "'update'", "=>", "Yii", "::", "$", "app", "->", "user", "->", "can", "(", "'updateUser'", ")", ",", "'delete'", "=>", "Yii", "::", "$", "app", "->", "user", "->", "can", "(", "'deleteUser'", ")", ",", "]", ",", "]", ";", "}", "parent", "::", "init", "(", ")", ";", "}" ]
Initialize attributes.
[ "Initialize", "attributes", "." ]
train
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/widgets/UserListWidget.php#L63-L92
rhosocial/yii2-user
widgets/UserListWidget.php
UserListWidget.run
public function run() { return $this->render('user-list', [ 'dataProvider' => $this->dataProvider, 'additionalColumns' => $this->additionalColumns, 'actionColumn' => $this->actionColumn, 'visible' => $this->visible, 'tips' => $this->tips, ]); }
php
public function run() { return $this->render('user-list', [ 'dataProvider' => $this->dataProvider, 'additionalColumns' => $this->additionalColumns, 'actionColumn' => $this->actionColumn, 'visible' => $this->visible, 'tips' => $this->tips, ]); }
[ "public", "function", "run", "(", ")", "{", "return", "$", "this", "->", "render", "(", "'user-list'", ",", "[", "'dataProvider'", "=>", "$", "this", "->", "dataProvider", ",", "'additionalColumns'", "=>", "$", "this", "->", "additionalColumns", ",", "'actionColumn'", "=>", "$", "this", "->", "actionColumn", ",", "'visible'", "=>", "$", "this", "->", "visible", ",", "'tips'", "=>", "$", "this", "->", "tips", ",", "]", ")", ";", "}" ]
Run action. @return string
[ "Run", "action", "." ]
train
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/widgets/UserListWidget.php#L98-L107
tylernathanreed/flash
src/Flash.php
Flash.flash
private function flash($type, $message) { // Determine the Current Session Flash Type $flash = Session::has($type) ? Session::get($type) : array(); // Prevent Duplicate Messages from Appearing if(!in_array($message, $flash)) $flash[] = $message; // Add the Message to the Flashes // Flash the Message Session::flash($type, $flash); }
php
private function flash($type, $message) { // Determine the Current Session Flash Type $flash = Session::has($type) ? Session::get($type) : array(); // Prevent Duplicate Messages from Appearing if(!in_array($message, $flash)) $flash[] = $message; // Add the Message to the Flashes // Flash the Message Session::flash($type, $flash); }
[ "private", "function", "flash", "(", "$", "type", ",", "$", "message", ")", "{", "// Determine the Current Session Flash Type", "$", "flash", "=", "Session", "::", "has", "(", "$", "type", ")", "?", "Session", "::", "get", "(", "$", "type", ")", ":", "array", "(", ")", ";", "// Prevent Duplicate Messages from Appearing", "if", "(", "!", "in_array", "(", "$", "message", ",", "$", "flash", ")", ")", "$", "flash", "[", "]", "=", "$", "message", ";", "// Add the Message to the Flashes", "// Flash the Message", "Session", "::", "flash", "(", "$", "type", ",", "$", "flash", ")", ";", "}" ]
Flashes a Message to the Session. @param string $type The Type of Message to Flash. @param string $message The Message to Flash. @return void
[ "Flashes", "a", "Message", "to", "the", "Session", "." ]
train
https://github.com/tylernathanreed/flash/blob/6ca4b361493e7e48e3c3cf6b1ed95f8a1b2b724c/src/Flash.php#L82-L93
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.list_subscribed
private function list_subscribed($dir){ if ( $this->is_connected() ){ return imap_lsub($this->stream, $this->mbParam, $dir); } return false; }
php
private function list_subscribed($dir){ if ( $this->is_connected() ){ return imap_lsub($this->stream, $this->mbParam, $dir); } return false; }
[ "private", "function", "list_subscribed", "(", "$", "dir", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_lsub", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ",", "$", "dir", ")", ";", "}", "return", "false", ";", "}" ]
Returns an array containing the names of the mailboxes that you have subscribed. (Test: ok) @param string $dir Mailbox directory @return bool|array
[ "Returns", "an", "array", "containing", "the", "names", "of", "the", "mailboxes", "that", "you", "have", "subscribed", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L31-L36
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.list_mboxes
private function list_mboxes($dir){ if ( $this->is_connected() ){ return imap_list($this->stream, $this->mbParam, $dir); } return false; }
php
private function list_mboxes($dir){ if ( $this->is_connected() ){ return imap_list($this->stream, $this->mbParam, $dir); } return false; }
[ "private", "function", "list_mboxes", "(", "$", "dir", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_list", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ",", "$", "dir", ")", ";", "}", "return", "false", ";", "}" ]
Returns an array containing the full names of the mailboxes. (Test: ok) @param string $dir Mailbox directory @return bool|array
[ "Returns", "an", "array", "containing", "the", "full", "names", "of", "the", "mailboxes", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L44-L49
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.get_mboxes
private function get_mboxes($dir){ if ( $this->is_connected() ){ return imap_getmailboxes($this->stream, $this->mbParam, $dir); } return false; }
php
private function get_mboxes($dir){ if ( $this->is_connected() ){ return imap_getmailboxes($this->stream, $this->mbParam, $dir); } return false; }
[ "private", "function", "get_mboxes", "(", "$", "dir", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_getmailboxes", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ",", "$", "dir", ")", ";", "}", "return", "false", ";", "}" ]
Returns an array of objects containing detailed mailboxes information. (Test: ok) @param string $dir Mailbox directory @return array|bool
[ "Returns", "an", "array", "of", "objects", "containing", "detailed", "mailboxes", "information", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L57-L62
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.get_names_mboxes
private function get_names_mboxes($dir){ if ( $mboxes = $this->get_mboxes($dir) ){ $i = 0; $ret = []; while( list($key, $val) = each($mboxes) ){ $name = imap_utf7_decode($val->name); $name_arr = explode('}', $name); $j = \count($name_arr) - 1; $mbox_name = $name_arr[$j]; if( $mbox_name == "" ){ continue; // the DIRECTORY itself } $ret[$i++] = $mbox_name; } sort($ret); return $ret; } return false; }
php
private function get_names_mboxes($dir){ if ( $mboxes = $this->get_mboxes($dir) ){ $i = 0; $ret = []; while( list($key, $val) = each($mboxes) ){ $name = imap_utf7_decode($val->name); $name_arr = explode('}', $name); $j = \count($name_arr) - 1; $mbox_name = $name_arr[$j]; if( $mbox_name == "" ){ continue; // the DIRECTORY itself } $ret[$i++] = $mbox_name; } sort($ret); return $ret; } return false; }
[ "private", "function", "get_names_mboxes", "(", "$", "dir", ")", "{", "if", "(", "$", "mboxes", "=", "$", "this", "->", "get_mboxes", "(", "$", "dir", ")", ")", "{", "$", "i", "=", "0", ";", "$", "ret", "=", "[", "]", ";", "while", "(", "list", "(", "$", "key", ",", "$", "val", ")", "=", "each", "(", "$", "mboxes", ")", ")", "{", "$", "name", "=", "imap_utf7_decode", "(", "$", "val", "->", "name", ")", ";", "$", "name_arr", "=", "explode", "(", "'}'", ",", "$", "name", ")", ";", "$", "j", "=", "\\", "count", "(", "$", "name_arr", ")", "-", "1", ";", "$", "mbox_name", "=", "$", "name_arr", "[", "$", "j", "]", ";", "if", "(", "$", "mbox_name", "==", "\"\"", ")", "{", "continue", ";", "// the DIRECTORY itself", "}", "$", "ret", "[", "$", "i", "++", "]", "=", "$", "mbox_name", ";", "}", "sort", "(", "$", "ret", ")", ";", "return", "$", "ret", ";", "}", "return", "false", ";", "}" ]
Returns a sorted array containing the simple names of the mailboxes. (Test: ok) @param string $dir Mailbox directory @return array
[ "Returns", "a", "sorted", "array", "containing", "the", "simple", "names", "of", "the", "mailboxes", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L70-L88
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.get_decode_value
private function get_decode_value($message, $coding){ if ( $coding === 0 ){ $message = imap_8bit($message); } else if ( $coding === 1 ){ $message = imap_8bit($message); } else if ( $coding === 2 ){ $message = imap_binary($message); } else if ( $coding === 3 ){ $message=imap_base64($message); } else if ( $coding === 4 ){ $message = imap_qprint($message); } else if ( $coding === 5 ){ $message = imap_base64($message); } return $message; }
php
private function get_decode_value($message, $coding){ if ( $coding === 0 ){ $message = imap_8bit($message); } else if ( $coding === 1 ){ $message = imap_8bit($message); } else if ( $coding === 2 ){ $message = imap_binary($message); } else if ( $coding === 3 ){ $message=imap_base64($message); } else if ( $coding === 4 ){ $message = imap_qprint($message); } else if ( $coding === 5 ){ $message = imap_base64($message); } return $message; }
[ "private", "function", "get_decode_value", "(", "$", "message", ",", "$", "coding", ")", "{", "if", "(", "$", "coding", "===", "0", ")", "{", "$", "message", "=", "imap_8bit", "(", "$", "message", ")", ";", "}", "else", "if", "(", "$", "coding", "===", "1", ")", "{", "$", "message", "=", "imap_8bit", "(", "$", "message", ")", ";", "}", "else", "if", "(", "$", "coding", "===", "2", ")", "{", "$", "message", "=", "imap_binary", "(", "$", "message", ")", ";", "}", "else", "if", "(", "$", "coding", "===", "3", ")", "{", "$", "message", "=", "imap_base64", "(", "$", "message", ")", ";", "}", "else", "if", "(", "$", "coding", "===", "4", ")", "{", "$", "message", "=", "imap_qprint", "(", "$", "message", ")", ";", "}", "else", "if", "(", "$", "coding", "===", "5", ")", "{", "$", "message", "=", "imap_base64", "(", "$", "message", ")", ";", "}", "return", "$", "message", ";", "}" ]
Decodes message. (Test: ok) @param string $message Messate to decode @param int $coding Type of encoding @return string
[ "Decodes", "message", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L97-L117
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.get_imap
public function get_imap(){ if ( $this->imap = imap_check($this->stream) ){ if ( $this->imap->Nmsgs > 0 ){ $this->last_uid = $this->get_msg_uid($this->imap->Nmsgs); $this->num_msg = $this->imap->Nmsgs; } else { $this->last_uid = 0; $this->num_msg = 0; } return $this->imap; } return false; }
php
public function get_imap(){ if ( $this->imap = imap_check($this->stream) ){ if ( $this->imap->Nmsgs > 0 ){ $this->last_uid = $this->get_msg_uid($this->imap->Nmsgs); $this->num_msg = $this->imap->Nmsgs; } else { $this->last_uid = 0; $this->num_msg = 0; } return $this->imap; } return false; }
[ "public", "function", "get_imap", "(", ")", "{", "if", "(", "$", "this", "->", "imap", "=", "imap_check", "(", "$", "this", "->", "stream", ")", ")", "{", "if", "(", "$", "this", "->", "imap", "->", "Nmsgs", ">", "0", ")", "{", "$", "this", "->", "last_uid", "=", "$", "this", "->", "get_msg_uid", "(", "$", "this", "->", "imap", "->", "Nmsgs", ")", ";", "$", "this", "->", "num_msg", "=", "$", "this", "->", "imap", "->", "Nmsgs", ";", "}", "else", "{", "$", "this", "->", "last_uid", "=", "0", ";", "$", "this", "->", "num_msg", "=", "0", ";", "}", "return", "$", "this", "->", "imap", ";", "}", "return", "false", ";", "}" ]
Gets IMAP essential info (Test: ok) @return object|bool
[ "Gets", "IMAP", "essential", "info", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L283-L296
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.create_mbox
public function create_mbox($mbox){ if ( $this->is_connected() ){ return imap_createmailbox($this->stream, $this->mbParam. $mbox); } return false; }
php
public function create_mbox($mbox){ if ( $this->is_connected() ){ return imap_createmailbox($this->stream, $this->mbParam. $mbox); } return false; }
[ "public", "function", "create_mbox", "(", "$", "mbox", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_createmailbox", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ".", "$", "mbox", ")", ";", "}", "return", "false", ";", "}" ]
Creates a mailbox (Test: ok) @param string $mbox Mailbox name @return bool
[ "Creates", "a", "mailbox", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L314-L319
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.delete_mbox
public function delete_mbox($mbox){ if ( $this->is_connected() ){ return imap_deletemailbox($this->stream, $this->mbParam . $mbox); } return false; }
php
public function delete_mbox($mbox){ if ( $this->is_connected() ){ return imap_deletemailbox($this->stream, $this->mbParam . $mbox); } return false; }
[ "public", "function", "delete_mbox", "(", "$", "mbox", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_deletemailbox", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ".", "$", "mbox", ")", ";", "}", "return", "false", ";", "}" ]
Deletes a mailbox (Test: ok) @param string $mbox Mailbox @return bool
[ "Deletes", "a", "mailbox", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L327-L332
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.rename_mbox
public function rename_mbox($old, $new){ if ( $this->is_connected() ){ return imap_renamemailbox($this->stream, $this->mbParam. $old, $this->mbParam. $new); } return false; }
php
public function rename_mbox($old, $new){ if ( $this->is_connected() ){ return imap_renamemailbox($this->stream, $this->mbParam. $old, $this->mbParam. $new); } return false; }
[ "public", "function", "rename_mbox", "(", "$", "old", ",", "$", "new", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_renamemailbox", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ".", "$", "old", ",", "$", "this", "->", "mbParam", ".", "$", "new", ")", ";", "}", "return", "false", ";", "}" ]
Renames a mailbox (Test: ok) @param string $old Old mailbox name @param string $new New mailbox name @return bool
[ "Renames", "a", "mailbox", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L341-L346
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.reopen_mbox
public function reopen_mbox($mbox){ if ( $this->is_connected() ){ if ( \in_array($mbox, $this->get_all_names_mboxes()) ){ return imap_reopen($this->stream, $this->mbParam . $mbox); } else { return imap_reopen($this->stream, $mbox); } } return false; }
php
public function reopen_mbox($mbox){ if ( $this->is_connected() ){ if ( \in_array($mbox, $this->get_all_names_mboxes()) ){ return imap_reopen($this->stream, $this->mbParam . $mbox); } else { return imap_reopen($this->stream, $mbox); } } return false; }
[ "public", "function", "reopen_mbox", "(", "$", "mbox", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "if", "(", "\\", "in_array", "(", "$", "mbox", ",", "$", "this", "->", "get_all_names_mboxes", "(", ")", ")", ")", "{", "return", "imap_reopen", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ".", "$", "mbox", ")", ";", "}", "else", "{", "return", "imap_reopen", "(", "$", "this", "->", "stream", ",", "$", "mbox", ")", ";", "}", "}", "return", "false", ";", "}" ]
Reopens the desired mailbox (you can give it the simple name or the full name). (Test: ok) If the given name is not existing it opens the default inbox. @param string $mbox Simple/full mailbox name @return bool
[ "Reopens", "the", "desired", "mailbox", "(", "you", "can", "give", "it", "the", "simple", "name", "or", "the", "full", "name", ")", ".", "(", "Test", ":", "ok", ")", "If", "the", "given", "name", "is", "not", "existing", "it", "opens", "the", "default", "inbox", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L431-L441
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.sort_mbox
public function sort_mbox($criteria, $reverse = 0){ if ( $this->is_connected() && !empty($criteria) ){ return imap_sort($this->stream, constant(strtoupper($criteria)), $reverse, SE_NOPREFETCH); } return false; }
php
public function sort_mbox($criteria, $reverse = 0){ if ( $this->is_connected() && !empty($criteria) ){ return imap_sort($this->stream, constant(strtoupper($criteria)), $reverse, SE_NOPREFETCH); } return false; }
[ "public", "function", "sort_mbox", "(", "$", "criteria", ",", "$", "reverse", "=", "0", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", "&&", "!", "empty", "(", "$", "criteria", ")", ")", "{", "return", "imap_sort", "(", "$", "this", "->", "stream", ",", "constant", "(", "strtoupper", "(", "$", "criteria", ")", ")", ",", "$", "reverse", ",", "SE_NOPREFETCH", ")", ";", "}", "return", "false", ";", "}" ]
Sorts the mailbox. (Test: ok) Criteria can be one (and only one) of the following: SORTDATE - message Date SORTARRIVAL - arrival date SORTFROM - mailbox in first From address SORTSUBJECT - message subject SORTTO - mailbox in first To address SORTCC - mailbox in first cc address SORTSIZE - size of message in octets @param string $criteria Pass it without quote or double quote @param string $reverse Set this to 1 for reverse sorting @return array|bool
[ "Sorts", "the", "mailbox", ".", "(", "Test", ":", "ok", ")", "Criteria", "can", "be", "one", "(", "and", "only", "one", ")", "of", "the", "following", ":", "SORTDATE", "-", "message", "Date", "SORTARRIVAL", "-", "arrival", "date", "SORTFROM", "-", "mailbox", "in", "first", "From", "address", "SORTSUBJECT", "-", "message", "subject", "SORTTO", "-", "mailbox", "in", "first", "To", "address", "SORTCC", "-", "mailbox", "in", "first", "cc", "address", "SORTSIZE", "-", "size", "of", "message", "in", "octets" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L470-L475
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.get_msg_header
public function get_msg_header($msgnum, $uid = false){ if ( $this->is_connected() ){ if ( $uid ){ return imap_fetchheader($this->stream, $msgnum, FT_UID); } return imap_fetchheader($this->stream, $msgnum); } return false; }
php
public function get_msg_header($msgnum, $uid = false){ if ( $this->is_connected() ){ if ( $uid ){ return imap_fetchheader($this->stream, $msgnum, FT_UID); } return imap_fetchheader($this->stream, $msgnum); } return false; }
[ "public", "function", "get_msg_header", "(", "$", "msgnum", ",", "$", "uid", "=", "false", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "if", "(", "$", "uid", ")", "{", "return", "imap_fetchheader", "(", "$", "this", "->", "stream", ",", "$", "msgnum", ",", "FT_UID", ")", ";", "}", "return", "imap_fetchheader", "(", "$", "this", "->", "stream", ",", "$", "msgnum", ")", ";", "}", "return", "false", ";", "}" ]
Fetches the header of the message. (Test: ok) @param int $msgnum No of the message @param int|bool $uid Set true f the msgnum is a UID @return bool|string
[ "Fetches", "the", "header", "of", "the", "message", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L536-L544
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.delete_msg
public function delete_msg($uid){ if ( $this->is_connected() ){ return imap_delete($this->stream, $this->get_msg_no($uid)); } return false; }
php
public function delete_msg($uid){ if ( $this->is_connected() ){ return imap_delete($this->stream, $this->get_msg_no($uid)); } return false; }
[ "public", "function", "delete_msg", "(", "$", "uid", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_delete", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "get_msg_no", "(", "$", "uid", ")", ")", ";", "}", "return", "false", ";", "}" ]
Mark the specified message for deletion from current mailbox. (Text: ok) @param int $uid UID of the message @return bool
[ "Mark", "the", "specified", "message", "for", "deletion", "from", "current", "mailbox", ".", "(", "Text", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L552-L557
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.move_msg
public function move_msg($uid, $tombox){ if ( $this->is_connected() ){ return imap_mail_move($this->stream, $uid, $tombox, CP_UID); } return false; }
php
public function move_msg($uid, $tombox){ if ( $this->is_connected() ){ return imap_mail_move($this->stream, $uid, $tombox, CP_UID); } return false; }
[ "public", "function", "move_msg", "(", "$", "uid", ",", "$", "tombox", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_mail_move", "(", "$", "this", "->", "stream", ",", "$", "uid", ",", "$", "tombox", ",", "CP_UID", ")", ";", "}", "return", "false", ";", "}" ]
Move the specified message to specified mailbox. (Test: ok) @param int $uid UID of the message @param string $tombox Destination mailbox name @return bool
[ "Move", "the", "specified", "message", "to", "specified", "mailbox", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L566-L571
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.get_msg_body
public function get_msg_body($msgno, $part){ if ( $this->is_connected() ){ if ( empty($part) ){ return imap_body($this->stream, $msgno); } return imap_fetchbody($this->stream, $msgno, $part); } return false; }
php
public function get_msg_body($msgno, $part){ if ( $this->is_connected() ){ if ( empty($part) ){ return imap_body($this->stream, $msgno); } return imap_fetchbody($this->stream, $msgno, $part); } return false; }
[ "public", "function", "get_msg_body", "(", "$", "msgno", ",", "$", "part", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "part", ")", ")", "{", "return", "imap_body", "(", "$", "this", "->", "stream", ",", "$", "msgno", ")", ";", "}", "return", "imap_fetchbody", "(", "$", "this", "->", "stream", ",", "$", "msgno", ",", "$", "part", ")", ";", "}", "return", "false", ";", "}" ]
Fetches the body of the message. (Test: ok) @param int $msgno No of the message @param string|false $part The part number @return bool|string
[ "Fetches", "the", "body", "of", "the", "message", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L592-L600
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.set_msg_flag
public function set_msg_flag($seq, $flg, $remove=false){ if ( $this->is_connected() ){ return $remove ? imap_clearflag_full($this->stream, $seq, $flg) : imap_setflag_full($this->stream, $seq, $flg); } return false; }
php
public function set_msg_flag($seq, $flg, $remove=false){ if ( $this->is_connected() ){ return $remove ? imap_clearflag_full($this->stream, $seq, $flg) : imap_setflag_full($this->stream, $seq, $flg); } return false; }
[ "public", "function", "set_msg_flag", "(", "$", "seq", ",", "$", "flg", ",", "$", "remove", "=", "false", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "$", "remove", "?", "imap_clearflag_full", "(", "$", "this", "->", "stream", ",", "$", "seq", ",", "$", "flg", ")", ":", "imap_setflag_full", "(", "$", "this", "->", "stream", ",", "$", "seq", ",", "$", "flg", ")", ";", "}", "return", "false", ";", "}" ]
Sets or removes flag/s on message/s. (Test: ok) The flags which you can set are \\Seen, \\Answered, \\Flagged, \\Deleted, and \\Draft. (Test: ok) @param string $seq A sequence of message numbers. Ex. "2,5,6" or "2:5:6" @param string $flg The flag/s. Ex. "\\Seen \\Flagged" @param bool $remove Set this to true to remove flag/s @return bool
[ "Sets", "or", "removes", "flag", "/", "s", "on", "message", "/", "s", ".", "(", "Test", ":", "ok", ")", "The", "flags", "which", "you", "can", "set", "are", "\\\\", "Seen", "\\\\", "Answered", "\\\\", "Flagged", "\\\\", "Deleted", "and", "\\\\", "Draft", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L611-L616
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.search
public function search($criteria){ if ( $this->is_connected() ){ return imap_search($this->stream, $criteria, SE_UID); } return false; }
php
public function search($criteria){ if ( $this->is_connected() ){ return imap_search($this->stream, $criteria, SE_UID); } return false; }
[ "public", "function", "search", "(", "$", "criteria", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "imap_search", "(", "$", "this", "->", "stream", ",", "$", "criteria", ",", "SE_UID", ")", ";", "}", "return", "false", ";", "}" ]
Search messages. (Test: ok) Returns an array of UIDs. Arguments: ALL - return all messages matching the rest of the criteria ANSWERED - match messages with the \\ANSWERED flag set BCC "string" - match messages with "string" in the Bcc: field BEFORE "date" - match messages with Date: before "date" BODY "string" - match messages with "string" in the body of the message CC "string" - match messages with "string" in the Cc: field DELETED - match deleted messages FLAGGED - match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set FROM "string" - match messages with "string" in the From: field KEYWORD "string" - match messages with "string" as a keyword NEW - match new messages OLD - match old messages ON "date" - match messages with Date: matching "date" RECENT - match messages with the \\RECENT flag set SEEN - match messages that have been read (the \\SEEN flag is set) SINCE "date" - match messages with Date: after "date" SUBJECT "string" - match messages with "string" in the Subject: TEXT "string" - match messages with text "string" TO "string" - match messages with "string" in the To: UNANSWERED - match messages that have not been answered UNDELETED - match messages that are not deleted UNFLAGGED - match messages that are not flagged UNKEYWORD "string" - match messages that do not have the keyword "string" UNSEEN - match messages which have not been read yet @param string $criteria @return array|bool
[ "Search", "messages", ".", "(", "Test", ":", "ok", ")", "Returns", "an", "array", "of", "UIDs", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L651-L656
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.append
public function append($mbox, $msg){ if ( $this->is_connected() ){ return @imap_append($this->stream, $this->mbParam. $mbox, $msg); } return false; }
php
public function append($mbox, $msg){ if ( $this->is_connected() ){ return @imap_append($this->stream, $this->mbParam. $mbox, $msg); } return false; }
[ "public", "function", "append", "(", "$", "mbox", ",", "$", "msg", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", ")", "{", "return", "@", "imap_append", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "mbParam", ".", "$", "mbox", ",", "$", "msg", ")", ";", "}", "return", "false", ";", "}" ]
Appends a string message to a specified mailbox. (Test: ok) @param string $mbox Destination mailbox name @param string $msg Message @return bool
[ "Appends", "a", "string", "message", "to", "a", "specified", "mailbox", ".", "(", "Test", ":", "ok", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L665-L670
nabab/bbn
src/bbn/appui/mailbox.php
mailbox.mbox_exists
public function mbox_exists($name){ if ( $this->is_connected() && !empty($name) ){ $names = $this->get_all_names_mboxes(); if ( !empty($names) && \in_array($name, $names) ){ return true; } } return false; }
php
public function mbox_exists($name){ if ( $this->is_connected() && !empty($name) ){ $names = $this->get_all_names_mboxes(); if ( !empty($names) && \in_array($name, $names) ){ return true; } } return false; }
[ "public", "function", "mbox_exists", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "is_connected", "(", ")", "&&", "!", "empty", "(", "$", "name", ")", ")", "{", "$", "names", "=", "$", "this", "->", "get_all_names_mboxes", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "names", ")", "&&", "\\", "in_array", "(", "$", "name", ",", "$", "names", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if a mailbox exists @param string $name The mailbox name @return bool
[ "Check", "if", "a", "mailbox", "exists" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mailbox.php#L710-L718
surebert/surebert-framework
src/sb/Gitlab/Project.php
Project.issueCreate
public function issueCreate($title, $description, $assignee_email, $labels='') { $post = [ 'id' => $this->id, 'title' => $title, 'description' => $description ]; if($assignee_email){ $user = new \sb\Gitlab\User($assignee_email, $this->_client); $post['assignee_id']= $user->id; } $response = $this->_client->get('/projects/'.$this->id.'/issues',$post); if($response){ return \sb\Gitlab\Issue::fromObject($response); } }
php
public function issueCreate($title, $description, $assignee_email, $labels='') { $post = [ 'id' => $this->id, 'title' => $title, 'description' => $description ]; if($assignee_email){ $user = new \sb\Gitlab\User($assignee_email, $this->_client); $post['assignee_id']= $user->id; } $response = $this->_client->get('/projects/'.$this->id.'/issues',$post); if($response){ return \sb\Gitlab\Issue::fromObject($response); } }
[ "public", "function", "issueCreate", "(", "$", "title", ",", "$", "description", ",", "$", "assignee_email", ",", "$", "labels", "=", "''", ")", "{", "$", "post", "=", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'title'", "=>", "$", "title", ",", "'description'", "=>", "$", "description", "]", ";", "if", "(", "$", "assignee_email", ")", "{", "$", "user", "=", "new", "\\", "sb", "\\", "Gitlab", "\\", "User", "(", "$", "assignee_email", ",", "$", "this", "->", "_client", ")", ";", "$", "post", "[", "'assignee_id'", "]", "=", "$", "user", "->", "id", ";", "}", "$", "response", "=", "$", "this", "->", "_client", "->", "get", "(", "'/projects/'", ".", "$", "this", "->", "id", ".", "'/issues'", ",", "$", "post", ")", ";", "if", "(", "$", "response", ")", "{", "return", "\\", "sb", "\\", "Gitlab", "\\", "Issue", "::", "fromObject", "(", "$", "response", ")", ";", "}", "}" ]
Adds an issue to a git repository @param string $title @param string $description @param string $assignee_email @return \Gitlab\Model\Issue @throws \Exception
[ "Adds", "an", "issue", "to", "a", "git", "repository" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Gitlab/Project.php#L183-L200
surebert/surebert-framework
src/sb/Gitlab/Project.php
Project.issueClose
public function issueClose(\sb\Gitlab\Issue $issue){ $response = $this->_client->get("/projects/".$this->id."/issues/".$issue->id, [ 'state_event' => 'close' ], 'PUT'); if(is_object($response) && isset($response->message)){ throw new \Exception("Could not close issue ".$issue->id." on project ".$this->id.": ".json_encode($response)); } return $response; }
php
public function issueClose(\sb\Gitlab\Issue $issue){ $response = $this->_client->get("/projects/".$this->id."/issues/".$issue->id, [ 'state_event' => 'close' ], 'PUT'); if(is_object($response) && isset($response->message)){ throw new \Exception("Could not close issue ".$issue->id." on project ".$this->id.": ".json_encode($response)); } return $response; }
[ "public", "function", "issueClose", "(", "\\", "sb", "\\", "Gitlab", "\\", "Issue", "$", "issue", ")", "{", "$", "response", "=", "$", "this", "->", "_client", "->", "get", "(", "\"/projects/\"", ".", "$", "this", "->", "id", ".", "\"/issues/\"", ".", "$", "issue", "->", "id", ",", "[", "'state_event'", "=>", "'close'", "]", ",", "'PUT'", ")", ";", "if", "(", "is_object", "(", "$", "response", ")", "&&", "isset", "(", "$", "response", "->", "message", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Could not close issue \"", ".", "$", "issue", "->", "id", ".", "\" on project \"", ".", "$", "this", "->", "id", ".", "\": \"", ".", "json_encode", "(", "$", "response", ")", ")", ";", "}", "return", "$", "response", ";", "}" ]
Closes an issue by id within the project @param int $issue_id @return type
[ "Closes", "an", "issue", "by", "id", "within", "the", "project" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Gitlab/Project.php#L207-L217
surebert/surebert-framework
src/sb/Gitlab/Project.php
Project.getByName
protected function getByName($project_name) { if (!strstr($project_name, ":")) { throw (new \Exception("You must search for project with namespace: prefix")); } $parts = explode(':', $project_name); $projects = $this->_client->get('/projects/search/' . urlencode($parts[1])); $found_project = false; foreach ($projects as $project) { if (preg_match("~^" . $parts[0] . "$~", $project->namespace->name)) { return $project; } } if (!$found_project) { return false; } }
php
protected function getByName($project_name) { if (!strstr($project_name, ":")) { throw (new \Exception("You must search for project with namespace: prefix")); } $parts = explode(':', $project_name); $projects = $this->_client->get('/projects/search/' . urlencode($parts[1])); $found_project = false; foreach ($projects as $project) { if (preg_match("~^" . $parts[0] . "$~", $project->namespace->name)) { return $project; } } if (!$found_project) { return false; } }
[ "protected", "function", "getByName", "(", "$", "project_name", ")", "{", "if", "(", "!", "strstr", "(", "$", "project_name", ",", "\":\"", ")", ")", "{", "throw", "(", "new", "\\", "Exception", "(", "\"You must search for project with namespace: prefix\"", ")", ")", ";", "}", "$", "parts", "=", "explode", "(", "':'", ",", "$", "project_name", ")", ";", "$", "projects", "=", "$", "this", "->", "_client", "->", "get", "(", "'/projects/search/'", ".", "urlencode", "(", "$", "parts", "[", "1", "]", ")", ")", ";", "$", "found_project", "=", "false", ";", "foreach", "(", "$", "projects", "as", "$", "project", ")", "{", "if", "(", "preg_match", "(", "\"~^\"", ".", "$", "parts", "[", "0", "]", ".", "\"$~\"", ",", "$", "project", "->", "namespace", "->", "name", ")", ")", "{", "return", "$", "project", ";", "}", "}", "if", "(", "!", "$", "found_project", ")", "{", "return", "false", ";", "}", "}" ]
Loads project data by namespace:name @param string $project_name namespace:name @return \stdClass @throws \Exception
[ "Loads", "project", "data", "by", "namespace", ":", "name" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Gitlab/Project.php#L242-L261
surebert/surebert-framework
src/sb/Gitlab/Project.php
Project.fromObject
public static function fromObject($object){ $issue = new \sb\Gitlab\P(); foreach(get_object_vars($object) as $k=>$v){ switch($k){ case 'assignee': case 'author': if(!is_object($v)){ $issue->{$k} = $v; break; } $user = new \sb\Gitlab\User(); foreach(get_object_vars($v) as $uk=>$uv){ $user->{$uk} = $uv; } $issue->{$k} = $user; break; default: $issue->{$k} = $v; } } return $issue; }
php
public static function fromObject($object){ $issue = new \sb\Gitlab\P(); foreach(get_object_vars($object) as $k=>$v){ switch($k){ case 'assignee': case 'author': if(!is_object($v)){ $issue->{$k} = $v; break; } $user = new \sb\Gitlab\User(); foreach(get_object_vars($v) as $uk=>$uv){ $user->{$uk} = $uv; } $issue->{$k} = $user; break; default: $issue->{$k} = $v; } } return $issue; }
[ "public", "static", "function", "fromObject", "(", "$", "object", ")", "{", "$", "issue", "=", "new", "\\", "sb", "\\", "Gitlab", "\\", "P", "(", ")", ";", "foreach", "(", "get_object_vars", "(", "$", "object", ")", "as", "$", "k", "=>", "$", "v", ")", "{", "switch", "(", "$", "k", ")", "{", "case", "'assignee'", ":", "case", "'author'", ":", "if", "(", "!", "is_object", "(", "$", "v", ")", ")", "{", "$", "issue", "->", "{", "$", "k", "}", "=", "$", "v", ";", "break", ";", "}", "$", "user", "=", "new", "\\", "sb", "\\", "Gitlab", "\\", "User", "(", ")", ";", "foreach", "(", "get_object_vars", "(", "$", "v", ")", "as", "$", "uk", "=>", "$", "uv", ")", "{", "$", "user", "->", "{", "$", "uk", "}", "=", "$", "uv", ";", "}", "$", "issue", "->", "{", "$", "k", "}", "=", "$", "user", ";", "break", ";", "default", ":", "$", "issue", "->", "{", "$", "k", "}", "=", "$", "v", ";", "}", "}", "return", "$", "issue", ";", "}" ]
Convert stdClass Object to actual \sb\Gitlab\Issue @param \stdClass $object @return \sb\Gitlab\Issue
[ "Convert", "stdClass", "Object", "to", "actual", "\\", "sb", "\\", "Gitlab", "\\", "Issue" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Gitlab/Project.php#L277-L302
weew/http
src/Weew/Http/ReceivedHeadersParser.php
ReceivedHeadersParser.parseHeaders
public function parseHeaders(array $server, array $specialHeaders = []) { $specialHeaders = $this->getSpecialHeaders($specialHeaders); $headers = new HttpHeaders(); $this->extractPrefixedHeaders($headers, $server); $this->extractSpecialHeaders($headers, $server, $specialHeaders); $this->extractAuthHeaders($headers, $server); return $headers; }
php
public function parseHeaders(array $server, array $specialHeaders = []) { $specialHeaders = $this->getSpecialHeaders($specialHeaders); $headers = new HttpHeaders(); $this->extractPrefixedHeaders($headers, $server); $this->extractSpecialHeaders($headers, $server, $specialHeaders); $this->extractAuthHeaders($headers, $server); return $headers; }
[ "public", "function", "parseHeaders", "(", "array", "$", "server", ",", "array", "$", "specialHeaders", "=", "[", "]", ")", "{", "$", "specialHeaders", "=", "$", "this", "->", "getSpecialHeaders", "(", "$", "specialHeaders", ")", ";", "$", "headers", "=", "new", "HttpHeaders", "(", ")", ";", "$", "this", "->", "extractPrefixedHeaders", "(", "$", "headers", ",", "$", "server", ")", ";", "$", "this", "->", "extractSpecialHeaders", "(", "$", "headers", ",", "$", "server", ",", "$", "specialHeaders", ")", ";", "$", "this", "->", "extractAuthHeaders", "(", "$", "headers", ",", "$", "server", ")", ";", "return", "$", "headers", ";", "}" ]
@param array $server @param array $specialHeaders @return HttpHeaders
[ "@param", "array", "$server", "@param", "array", "$specialHeaders" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/ReceivedHeadersParser.php#L12-L21
weew/http
src/Weew/Http/ReceivedHeadersParser.php
ReceivedHeadersParser.formatHeaderAndRemovePrefix
public function formatHeaderAndRemovePrefix($header, $prefix = 'HTTP_') { if (str_starts_with($header, $prefix)) { $header = substr($header, strlen($prefix)); } return $this->formatHeader($header); }
php
public function formatHeaderAndRemovePrefix($header, $prefix = 'HTTP_') { if (str_starts_with($header, $prefix)) { $header = substr($header, strlen($prefix)); } return $this->formatHeader($header); }
[ "public", "function", "formatHeaderAndRemovePrefix", "(", "$", "header", ",", "$", "prefix", "=", "'HTTP_'", ")", "{", "if", "(", "str_starts_with", "(", "$", "header", ",", "$", "prefix", ")", ")", "{", "$", "header", "=", "substr", "(", "$", "header", ",", "strlen", "(", "$", "prefix", ")", ")", ";", "}", "return", "$", "this", "->", "formatHeader", "(", "$", "header", ")", ";", "}" ]
@param string $header @param string $prefix @return string
[ "@param", "string", "$header", "@param", "string", "$prefix" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/ReceivedHeadersParser.php#L111-L117
weew/http
src/Weew/Http/ReceivedHeadersParser.php
ReceivedHeadersParser.findAuthHeader
protected function findAuthHeader(array $server) { if (array_has($server, 'HTTP_AUTHORIZATION')) { return array_get($server, 'HTTP_AUTHORIZATION'); } else if (array_has($server, 'REDIRECT_HTTP_AUTHORIZATION')) { return array_get($server, 'REDIRECT_HTTP_AUTHORIZATION'); } return null; }
php
protected function findAuthHeader(array $server) { if (array_has($server, 'HTTP_AUTHORIZATION')) { return array_get($server, 'HTTP_AUTHORIZATION'); } else if (array_has($server, 'REDIRECT_HTTP_AUTHORIZATION')) { return array_get($server, 'REDIRECT_HTTP_AUTHORIZATION'); } return null; }
[ "protected", "function", "findAuthHeader", "(", "array", "$", "server", ")", "{", "if", "(", "array_has", "(", "$", "server", ",", "'HTTP_AUTHORIZATION'", ")", ")", "{", "return", "array_get", "(", "$", "server", ",", "'HTTP_AUTHORIZATION'", ")", ";", "}", "else", "if", "(", "array_has", "(", "$", "server", ",", "'REDIRECT_HTTP_AUTHORIZATION'", ")", ")", "{", "return", "array_get", "(", "$", "server", ",", "'REDIRECT_HTTP_AUTHORIZATION'", ")", ";", "}", "return", "null", ";", "}" ]
@param array $server @return string|null
[ "@param", "array", "$server" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/ReceivedHeadersParser.php#L136-L144
DevFactoryCH/api
src/Provider/RequestProvider.php
RequestProvider.put
public function put($url, $params = null) { $this->params = $params; $this->method = 'PUT'; $this->url = $url; return $this->request(); }
php
public function put($url, $params = null) { $this->params = $params; $this->method = 'PUT'; $this->url = $url; return $this->request(); }
[ "public", "function", "put", "(", "$", "url", ",", "$", "params", "=", "null", ")", "{", "$", "this", "->", "params", "=", "$", "params", ";", "$", "this", "->", "method", "=", "'PUT'", ";", "$", "this", "->", "url", "=", "$", "url", ";", "return", "$", "this", "->", "request", "(", ")", ";", "}" ]
Make a PUT query @param data @return
[ "Make", "a", "PUT", "query" ]
train
https://github.com/DevFactoryCH/api/blob/ed239aac6e15cba23ae527b1d175c478d2b7d6ae/src/Provider/RequestProvider.php#L27-L33
DevFactoryCH/api
src/Provider/RequestProvider.php
RequestProvider.post
public function post($url, $params = null) { $this->params = $params; $this->method = 'POST'; $this->url = $url; return $this->request(); }
php
public function post($url, $params = null) { $this->params = $params; $this->method = 'POST'; $this->url = $url; return $this->request(); }
[ "public", "function", "post", "(", "$", "url", ",", "$", "params", "=", "null", ")", "{", "$", "this", "->", "params", "=", "$", "params", ";", "$", "this", "->", "method", "=", "'POST'", ";", "$", "this", "->", "url", "=", "$", "url", ";", "return", "$", "this", "->", "request", "(", ")", ";", "}" ]
Make a POST query @param data @return
[ "Make", "a", "POST", "query" ]
train
https://github.com/DevFactoryCH/api/blob/ed239aac6e15cba23ae527b1d175c478d2b7d6ae/src/Provider/RequestProvider.php#L42-L48
DevFactoryCH/api
src/Provider/RequestProvider.php
RequestProvider.get
public function get($url, $params = null) { $this->params = $params; $this->method = 'GET'; $this->url = $url; return $this->request(); }
php
public function get($url, $params = null) { $this->params = $params; $this->method = 'GET'; $this->url = $url; return $this->request(); }
[ "public", "function", "get", "(", "$", "url", ",", "$", "params", "=", "null", ")", "{", "$", "this", "->", "params", "=", "$", "params", ";", "$", "this", "->", "method", "=", "'GET'", ";", "$", "this", "->", "url", "=", "$", "url", ";", "return", "$", "this", "->", "request", "(", ")", ";", "}" ]
Make a GET query @param data @return
[ "Make", "a", "GET", "query" ]
train
https://github.com/DevFactoryCH/api/blob/ed239aac6e15cba23ae527b1d175c478d2b7d6ae/src/Provider/RequestProvider.php#L57-L63
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.index
public function index() { $this->authorize('readList', Block::class); $input = $this->validator->validate('list'); $params = $this->processor->process($input)->getProcessedFields(); $results = $this->repository->getBlocks( $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new BlockTransformer); }
php
public function index() { $this->authorize('readList', Block::class); $input = $this->validator->validate('list'); $params = $this->processor->process($input)->getProcessedFields(); $results = $this->repository->getBlocks( $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new BlockTransformer); }
[ "public", "function", "index", "(", ")", "{", "$", "this", "->", "authorize", "(", "'readList'", ",", "Block", "::", "class", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'list'", ")", ";", "$", "params", "=", "$", "this", "->", "processor", "->", "process", "(", "$", "input", ")", "->", "getProcessedFields", "(", ")", ";", "$", "results", "=", "$", "this", "->", "repository", "->", "getBlocks", "(", "$", "params", "[", "'filter'", "]", ",", "$", "params", "[", "'orderBy'", "]", ",", "$", "params", "[", "'page'", "]", ",", "$", "params", "[", "'perPage'", "]", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "results", ",", "new", "BlockTransformer", ")", ";", "}" ]
Display a listing of the resource. @return \Illuminate\Http\JsonResponse
[ "Display", "a", "listing", "of", "the", "resource", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L89-L101
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.indexOfDeleted
public function indexOfDeleted() { $this->authorize('readList', Block::class); $input = $this->validator->validate('list'); $params = $this->processor->process($input)->getProcessedFields(); $results = $this->repository->getDeletedBlocks( $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new BlockTransformer); }
php
public function indexOfDeleted() { $this->authorize('readList', Block::class); $input = $this->validator->validate('list'); $params = $this->processor->process($input)->getProcessedFields(); $results = $this->repository->getDeletedBlocks( $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new BlockTransformer); }
[ "public", "function", "indexOfDeleted", "(", ")", "{", "$", "this", "->", "authorize", "(", "'readList'", ",", "Block", "::", "class", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'list'", ")", ";", "$", "params", "=", "$", "this", "->", "processor", "->", "process", "(", "$", "input", ")", "->", "getProcessedFields", "(", ")", ";", "$", "results", "=", "$", "this", "->", "repository", "->", "getDeletedBlocks", "(", "$", "params", "[", "'filter'", "]", ",", "$", "params", "[", "'orderBy'", "]", ",", "$", "params", "[", "'page'", "]", ",", "$", "params", "[", "'perPage'", "]", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "results", ",", "new", "BlockTransformer", ")", ";", "}" ]
Display list of soft deleted blocks @return \Illuminate\Http\JsonResponse
[ "Display", "list", "of", "soft", "deleted", "blocks" ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L108-L120
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.indexForSpecificContent
public function indexForSpecificContent($contentId) { $this->authorize('readList', Block::class); $onlyPublic = false; $content = $this->contentRepository->getById($contentId); if ($content) { $input = $this->validator->validate('listContent'); $params = $this->processor->process($input)->getProcessedFields(); $blockIds = $this->finder->getBlocksIds($content->path, $params, $onlyPublic); $results = $this->repository->getVisibleBlocks($blockIds, $onlyPublic); return $this->respondWithSuccess($results, new BlockTransformer); } return $this->respondNotFound(); }
php
public function indexForSpecificContent($contentId) { $this->authorize('readList', Block::class); $onlyPublic = false; $content = $this->contentRepository->getById($contentId); if ($content) { $input = $this->validator->validate('listContent'); $params = $this->processor->process($input)->getProcessedFields(); $blockIds = $this->finder->getBlocksIds($content->path, $params, $onlyPublic); $results = $this->repository->getVisibleBlocks($blockIds, $onlyPublic); return $this->respondWithSuccess($results, new BlockTransformer); } return $this->respondNotFound(); }
[ "public", "function", "indexForSpecificContent", "(", "$", "contentId", ")", "{", "$", "this", "->", "authorize", "(", "'readList'", ",", "Block", "::", "class", ")", ";", "$", "onlyPublic", "=", "false", ";", "$", "content", "=", "$", "this", "->", "contentRepository", "->", "getById", "(", "$", "contentId", ")", ";", "if", "(", "$", "content", ")", "{", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'listContent'", ")", ";", "$", "params", "=", "$", "this", "->", "processor", "->", "process", "(", "$", "input", ")", "->", "getProcessedFields", "(", ")", ";", "$", "blockIds", "=", "$", "this", "->", "finder", "->", "getBlocksIds", "(", "$", "content", "->", "path", ",", "$", "params", ",", "$", "onlyPublic", ")", ";", "$", "results", "=", "$", "this", "->", "repository", "->", "getVisibleBlocks", "(", "$", "blockIds", ",", "$", "onlyPublic", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "results", ",", "new", "BlockTransformer", ")", ";", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Display a listing of the resource. @param int $contentId Id of the resource @return \Illuminate\Http\JsonResponse @throws \Gzero\Validator\ValidationException
[ "Display", "a", "listing", "of", "the", "resource", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L130-L143
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.indexOfFiles
public function indexOfFiles($blockId) { $this->authorize('readList', File::class); $input = $this->validator->validate('files'); $params = $this->processor->process($input)->getProcessedFields(); $block = $this->repository->getById($blockId); if (empty($block)) { return $this->respondNotFound(); } $results = $this->fileRepository->getEntityFiles( $block, $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new FileTransformer); }
php
public function indexOfFiles($blockId) { $this->authorize('readList', File::class); $input = $this->validator->validate('files'); $params = $this->processor->process($input)->getProcessedFields(); $block = $this->repository->getById($blockId); if (empty($block)) { return $this->respondNotFound(); } $results = $this->fileRepository->getEntityFiles( $block, $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new FileTransformer); }
[ "public", "function", "indexOfFiles", "(", "$", "blockId", ")", "{", "$", "this", "->", "authorize", "(", "'readList'", ",", "File", "::", "class", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'files'", ")", ";", "$", "params", "=", "$", "this", "->", "processor", "->", "process", "(", "$", "input", ")", "->", "getProcessedFields", "(", ")", ";", "$", "block", "=", "$", "this", "->", "repository", "->", "getById", "(", "$", "blockId", ")", ";", "if", "(", "empty", "(", "$", "block", ")", ")", "{", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}", "$", "results", "=", "$", "this", "->", "fileRepository", "->", "getEntityFiles", "(", "$", "block", ",", "$", "params", "[", "'filter'", "]", ",", "$", "params", "[", "'orderBy'", "]", ",", "$", "params", "[", "'page'", "]", ",", "$", "params", "[", "'perPage'", "]", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "results", ",", "new", "FileTransformer", ")", ";", "}" ]
Display a listing of the resource. @param int|null $blockId Block id for which we are displaying files @return \Illuminate\Http\JsonResponse
[ "Display", "a", "listing", "of", "the", "resource", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L152-L169
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.show
public function show($id) { $block = $this->repository->getById($id); if (!empty($block)) { $this->authorize('read', $block); return $this->respondWithSuccess($block, new BlockTransformer); } return $this->respondNotFound(); }
php
public function show($id) { $block = $this->repository->getById($id); if (!empty($block)) { $this->authorize('read', $block); return $this->respondWithSuccess($block, new BlockTransformer); } return $this->respondNotFound(); }
[ "public", "function", "show", "(", "$", "id", ")", "{", "$", "block", "=", "$", "this", "->", "repository", "->", "getById", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "block", ")", ")", "{", "$", "this", "->", "authorize", "(", "'read'", ",", "$", "block", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "block", ",", "new", "BlockTransformer", ")", ";", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Display a specified resource. @param int $id Id of the resource @return \Illuminate\Http\JsonResponse
[ "Display", "a", "specified", "resource", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L178-L186
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.store
public function store() { $this->authorize('create', Block::class); $input = $this->validator->validate('create'); try { $block = $this->repository->create($input, auth()->user()); return $this->respondWithSuccess($block, new BlockTransformer); } catch (RepositoryValidationException $e) { return $this->respondWithError($e->getMessage()); } }
php
public function store() { $this->authorize('create', Block::class); $input = $this->validator->validate('create'); try { $block = $this->repository->create($input, auth()->user()); return $this->respondWithSuccess($block, new BlockTransformer); } catch (RepositoryValidationException $e) { return $this->respondWithError($e->getMessage()); } }
[ "public", "function", "store", "(", ")", "{", "$", "this", "->", "authorize", "(", "'create'", ",", "Block", "::", "class", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'create'", ")", ";", "try", "{", "$", "block", "=", "$", "this", "->", "repository", "->", "create", "(", "$", "input", ",", "auth", "(", ")", "->", "user", "(", ")", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "block", ",", "new", "BlockTransformer", ")", ";", "}", "catch", "(", "RepositoryValidationException", "$", "e", ")", "{", "return", "$", "this", "->", "respondWithError", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Stores newly created block in database. @return \Illuminate\Http\JsonResponse
[ "Stores", "newly", "created", "block", "in", "database", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L193-L203
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.update
public function update($id) { $block = $this->repository->getById($id); if (!empty($block)) { $this->authorize('update', $block); $input = $this->validator->validate('update'); $block = $this->repository->update($block, $input, auth()->user()); return $this->respondWithSuccess($block, new BlockTransformer); } return $this->respondNotFound(); }
php
public function update($id) { $block = $this->repository->getById($id); if (!empty($block)) { $this->authorize('update', $block); $input = $this->validator->validate('update'); $block = $this->repository->update($block, $input, auth()->user()); return $this->respondWithSuccess($block, new BlockTransformer); } return $this->respondNotFound(); }
[ "public", "function", "update", "(", "$", "id", ")", "{", "$", "block", "=", "$", "this", "->", "repository", "->", "getById", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "block", ")", ")", "{", "$", "this", "->", "authorize", "(", "'update'", ",", "$", "block", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'update'", ")", ";", "$", "block", "=", "$", "this", "->", "repository", "->", "update", "(", "$", "block", ",", "$", "input", ",", "auth", "(", ")", "->", "user", "(", ")", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "block", ",", "new", "BlockTransformer", ")", ";", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Updates the specified resource in the database. @param int $id Block id @return \Illuminate\Http\JsonResponse
[ "Updates", "the", "specified", "resource", "in", "the", "database", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L212-L222
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.destroy
public function destroy(Request $request, $id) { $forceDelete = $request->get('force', false); $block = $this->repository->getByIdWithTrashed($id); if (!empty($block)) { $this->authorize('delete', $block); if ($forceDelete) { $this->repository->forceDelete($block); } else { $this->repository->delete($block); } return $this->respondWithSimpleSuccess(['success' => true]); } return $this->respondNotFound(); }
php
public function destroy(Request $request, $id) { $forceDelete = $request->get('force', false); $block = $this->repository->getByIdWithTrashed($id); if (!empty($block)) { $this->authorize('delete', $block); if ($forceDelete) { $this->repository->forceDelete($block); } else { $this->repository->delete($block); } return $this->respondWithSimpleSuccess(['success' => true]); } return $this->respondNotFound(); }
[ "public", "function", "destroy", "(", "Request", "$", "request", ",", "$", "id", ")", "{", "$", "forceDelete", "=", "$", "request", "->", "get", "(", "'force'", ",", "false", ")", ";", "$", "block", "=", "$", "this", "->", "repository", "->", "getByIdWithTrashed", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "block", ")", ")", "{", "$", "this", "->", "authorize", "(", "'delete'", ",", "$", "block", ")", ";", "if", "(", "$", "forceDelete", ")", "{", "$", "this", "->", "repository", "->", "forceDelete", "(", "$", "block", ")", ";", "}", "else", "{", "$", "this", "->", "repository", "->", "delete", "(", "$", "block", ")", ";", "}", "return", "$", "this", "->", "respondWithSimpleSuccess", "(", "[", "'success'", "=>", "true", "]", ")", ";", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Removes the specified resource from database. @param Request $request Request object @param int $id Block id @return \Illuminate\Http\JsonResponse
[ "Removes", "the", "specified", "resource", "from", "database", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L232-L248
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.restore
public function restore($id) { $block = $this->repository->getDeletedById($id); if (!empty($block)) { $this->authorize('update', $block); $block->restore(); return $this->respondWithSimpleSuccess(['success' => true]); } return $this->respondNotFound(); }
php
public function restore($id) { $block = $this->repository->getDeletedById($id); if (!empty($block)) { $this->authorize('update', $block); $block->restore(); return $this->respondWithSimpleSuccess(['success' => true]); } return $this->respondNotFound(); }
[ "public", "function", "restore", "(", "$", "id", ")", "{", "$", "block", "=", "$", "this", "->", "repository", "->", "getDeletedById", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "block", ")", ")", "{", "$", "this", "->", "authorize", "(", "'update'", ",", "$", "block", ")", ";", "$", "block", "->", "restore", "(", ")", ";", "return", "$", "this", "->", "respondWithSimpleSuccess", "(", "[", "'success'", "=>", "true", "]", ")", ";", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Restore soft deleted block @param int $id Block id @return mixed
[ "Restore", "soft", "deleted", "block" ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L257-L266
GrupaZero/api
src/Gzero/Api/Controller/Admin/BlockController.php
BlockController.syncFiles
public function syncFiles($contentId) { $block = $this->repository->getById($contentId); if (empty($block)) { return $this->respondNotFound(); } $this->authorize('update', $block); $input = $this->validator->validate('syncFiles'); $block = $this->fileRepository->syncWith($block, $this->buildSyncData($input)); return $this->respondWithSuccess($block); }
php
public function syncFiles($contentId) { $block = $this->repository->getById($contentId); if (empty($block)) { return $this->respondNotFound(); } $this->authorize('update', $block); $input = $this->validator->validate('syncFiles'); $block = $this->fileRepository->syncWith($block, $this->buildSyncData($input)); return $this->respondWithSuccess($block); }
[ "public", "function", "syncFiles", "(", "$", "contentId", ")", "{", "$", "block", "=", "$", "this", "->", "repository", "->", "getById", "(", "$", "contentId", ")", ";", "if", "(", "empty", "(", "$", "block", ")", ")", "{", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}", "$", "this", "->", "authorize", "(", "'update'", ",", "$", "block", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'syncFiles'", ")", ";", "$", "block", "=", "$", "this", "->", "fileRepository", "->", "syncWith", "(", "$", "block", ",", "$", "this", "->", "buildSyncData", "(", "$", "input", ")", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "block", ")", ";", "}" ]
Sync files with specific content @param int $contentId Content id @return mixed
[ "Sync", "files", "with", "specific", "content" ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/BlockController.php#L275-L285
99designs/ergo-http
src/Client.php
Client.addHeader
public function addHeader($header) { if (is_string($header)) { $header = HeaderField::fromString($header); } $this->headers[] = $header; return $this; }
php
public function addHeader($header) { if (is_string($header)) { $header = HeaderField::fromString($header); } $this->headers[] = $header; return $this; }
[ "public", "function", "addHeader", "(", "$", "header", ")", "{", "if", "(", "is_string", "(", "$", "header", ")", ")", "{", "$", "header", "=", "HeaderField", "::", "fromString", "(", "$", "header", ")", ";", "}", "$", "this", "->", "headers", "[", "]", "=", "$", "header", ";", "return", "$", "this", ";", "}" ]
Adds an HTTP header to all requests @param mixed either a string or a HeaderField @return $this
[ "Adds", "an", "HTTP", "header", "to", "all", "requests" ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/Client.php#L65-L72
99designs/ergo-http
src/Client.php
Client.post
function post($path, $body, $contentType = null) { return $this->dispatchRequest( $this->buildRequest('POST', $path, $body, $contentType) ); }
php
function post($path, $body, $contentType = null) { return $this->dispatchRequest( $this->buildRequest('POST', $path, $body, $contentType) ); }
[ "function", "post", "(", "$", "path", ",", "$", "body", ",", "$", "contentType", "=", "null", ")", "{", "return", "$", "this", "->", "dispatchRequest", "(", "$", "this", "->", "buildRequest", "(", "'POST'", ",", "$", "path", ",", "$", "body", ",", "$", "contentType", ")", ")", ";", "}" ]
Sends a POST request @return Response
[ "Sends", "a", "POST", "request" ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/Client.php#L134-L139
99designs/ergo-http
src/Client.php
Client.put
function put($path, $body, $contentType = null) { return $this->dispatchRequest( $this->buildRequest('PUT', $path, $body, $contentType) ); }
php
function put($path, $body, $contentType = null) { return $this->dispatchRequest( $this->buildRequest('PUT', $path, $body, $contentType) ); }
[ "function", "put", "(", "$", "path", ",", "$", "body", ",", "$", "contentType", "=", "null", ")", "{", "return", "$", "this", "->", "dispatchRequest", "(", "$", "this", "->", "buildRequest", "(", "'PUT'", ",", "$", "path", ",", "$", "body", ",", "$", "contentType", ")", ")", ";", "}" ]
Sends a PUT request @return Response
[ "Sends", "a", "PUT", "request" ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/Client.php#L145-L150
99designs/ergo-http
src/Client.php
Client.buildRequest
private function buildRequest($method, $path, $body = null, $contentType = null) { // copy default headers $headers = $this->headers; // add Content-Type header if provided if ($contentType) $headers [] = new HeaderField('Content-Type', $contentType); $request = new Request( $method, $this->url->getUrlForRelativePath($path), $headers, $body ); // pass the request through the filter chain foreach ($this->filters as $filter) { $request = $filter->request($request); } return $request; }
php
private function buildRequest($method, $path, $body = null, $contentType = null) { // copy default headers $headers = $this->headers; // add Content-Type header if provided if ($contentType) $headers [] = new HeaderField('Content-Type', $contentType); $request = new Request( $method, $this->url->getUrlForRelativePath($path), $headers, $body ); // pass the request through the filter chain foreach ($this->filters as $filter) { $request = $filter->request($request); } return $request; }
[ "private", "function", "buildRequest", "(", "$", "method", ",", "$", "path", ",", "$", "body", "=", "null", ",", "$", "contentType", "=", "null", ")", "{", "// copy default headers", "$", "headers", "=", "$", "this", "->", "headers", ";", "// add Content-Type header if provided", "if", "(", "$", "contentType", ")", "$", "headers", "[", "]", "=", "new", "HeaderField", "(", "'Content-Type'", ",", "$", "contentType", ")", ";", "$", "request", "=", "new", "Request", "(", "$", "method", ",", "$", "this", "->", "url", "->", "getUrlForRelativePath", "(", "$", "path", ")", ",", "$", "headers", ",", "$", "body", ")", ";", "// pass the request through the filter chain", "foreach", "(", "$", "this", "->", "filters", "as", "$", "filter", ")", "{", "$", "request", "=", "$", "filter", "->", "request", "(", "$", "request", ")", ";", "}", "return", "$", "request", ";", "}" ]
Builds an Request object
[ "Builds", "an", "Request", "object" ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/Client.php#L177-L199
99designs/ergo-http
src/Client.php
Client.dispatchRequest
private function dispatchRequest($request) { // track the number of requests across instances self::$requestCount++; $timestart = microtime(true); $response = self::transport()->send($request); // pass the response through the filter chain foreach ($this->filters as $filter) { $response = $filter->response($response); } $httpCode = $response->getStatus()->getCode(); $location = $response->getHeaders()->value('Location'); $body = $response->getBody(); // track the time taken across instances self::$requestTime += microtime(true) - $timestart; // process a redirect if needed if ($httpCode < 400 && $location) { return $this->redirect($location); } else { $this->redirects = 0; } // translate error code to a typed exception if ($httpCode == 500) { throw new Error\InternalServerError($body); } elseif ($httpCode == 400) { throw new Error\BadRequest($body); } elseif ($httpCode == 401) { throw new Error\Unauthorized($body); } elseif ($httpCode == 404) { throw new Error\NotFound($body); } elseif ($httpCode >= 300) { throw new Error($body, $httpCode); } return $response; }
php
private function dispatchRequest($request) { // track the number of requests across instances self::$requestCount++; $timestart = microtime(true); $response = self::transport()->send($request); // pass the response through the filter chain foreach ($this->filters as $filter) { $response = $filter->response($response); } $httpCode = $response->getStatus()->getCode(); $location = $response->getHeaders()->value('Location'); $body = $response->getBody(); // track the time taken across instances self::$requestTime += microtime(true) - $timestart; // process a redirect if needed if ($httpCode < 400 && $location) { return $this->redirect($location); } else { $this->redirects = 0; } // translate error code to a typed exception if ($httpCode == 500) { throw new Error\InternalServerError($body); } elseif ($httpCode == 400) { throw new Error\BadRequest($body); } elseif ($httpCode == 401) { throw new Error\Unauthorized($body); } elseif ($httpCode == 404) { throw new Error\NotFound($body); } elseif ($httpCode >= 300) { throw new Error($body, $httpCode); } return $response; }
[ "private", "function", "dispatchRequest", "(", "$", "request", ")", "{", "// track the number of requests across instances", "self", "::", "$", "requestCount", "++", ";", "$", "timestart", "=", "microtime", "(", "true", ")", ";", "$", "response", "=", "self", "::", "transport", "(", ")", "->", "send", "(", "$", "request", ")", ";", "// pass the response through the filter chain", "foreach", "(", "$", "this", "->", "filters", "as", "$", "filter", ")", "{", "$", "response", "=", "$", "filter", "->", "response", "(", "$", "response", ")", ";", "}", "$", "httpCode", "=", "$", "response", "->", "getStatus", "(", ")", "->", "getCode", "(", ")", ";", "$", "location", "=", "$", "response", "->", "getHeaders", "(", ")", "->", "value", "(", "'Location'", ")", ";", "$", "body", "=", "$", "response", "->", "getBody", "(", ")", ";", "// track the time taken across instances", "self", "::", "$", "requestTime", "+=", "microtime", "(", "true", ")", "-", "$", "timestart", ";", "// process a redirect if needed", "if", "(", "$", "httpCode", "<", "400", "&&", "$", "location", ")", "{", "return", "$", "this", "->", "redirect", "(", "$", "location", ")", ";", "}", "else", "{", "$", "this", "->", "redirects", "=", "0", ";", "}", "// translate error code to a typed exception", "if", "(", "$", "httpCode", "==", "500", ")", "{", "throw", "new", "Error", "\\", "InternalServerError", "(", "$", "body", ")", ";", "}", "elseif", "(", "$", "httpCode", "==", "400", ")", "{", "throw", "new", "Error", "\\", "BadRequest", "(", "$", "body", ")", ";", "}", "elseif", "(", "$", "httpCode", "==", "401", ")", "{", "throw", "new", "Error", "\\", "Unauthorized", "(", "$", "body", ")", ";", "}", "elseif", "(", "$", "httpCode", "==", "404", ")", "{", "throw", "new", "Error", "\\", "NotFound", "(", "$", "body", ")", ";", "}", "elseif", "(", "$", "httpCode", ">=", "300", ")", "{", "throw", "new", "Error", "(", "$", "body", ",", "$", "httpCode", ")", ";", "}", "return", "$", "response", ";", "}" ]
Dispatches a request via CURL
[ "Dispatches", "a", "request", "via", "CURL" ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/Client.php#L204-L245
99designs/ergo-http
src/Client.php
Client.redirect
private function redirect($location) { $locationUrl = new Url($location); // if the location header was relative (bleh) add the host if (!$locationUrl->hasHost()) { $locationUrl = $this->url->getUrlForPath($location); } if ($this->redirects > self::MAXredirects) { throw new Error\BadRequest("Exceeded maximum redirects"); } $this->redirects++; return $this->dispatchRequest( new Request('GET', $locationUrl, $this->headers) ); }
php
private function redirect($location) { $locationUrl = new Url($location); // if the location header was relative (bleh) add the host if (!$locationUrl->hasHost()) { $locationUrl = $this->url->getUrlForPath($location); } if ($this->redirects > self::MAXredirects) { throw new Error\BadRequest("Exceeded maximum redirects"); } $this->redirects++; return $this->dispatchRequest( new Request('GET', $locationUrl, $this->headers) ); }
[ "private", "function", "redirect", "(", "$", "location", ")", "{", "$", "locationUrl", "=", "new", "Url", "(", "$", "location", ")", ";", "// if the location header was relative (bleh) add the host", "if", "(", "!", "$", "locationUrl", "->", "hasHost", "(", ")", ")", "{", "$", "locationUrl", "=", "$", "this", "->", "url", "->", "getUrlForPath", "(", "$", "location", ")", ";", "}", "if", "(", "$", "this", "->", "redirects", ">", "self", "::", "MAXredirects", ")", "{", "throw", "new", "Error", "\\", "BadRequest", "(", "\"Exceeded maximum redirects\"", ")", ";", "}", "$", "this", "->", "redirects", "++", ";", "return", "$", "this", "->", "dispatchRequest", "(", "new", "Request", "(", "'GET'", ",", "$", "locationUrl", ",", "$", "this", "->", "headers", ")", ")", ";", "}" ]
Redirect to a new url
[ "Redirect", "to", "a", "new", "url" ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/Client.php#L250-L268
rafalkot/yii2-settings
SettingsTrait.php
SettingsTrait.getSetting
public function getSetting($key = null, $default = null) { return $this->getSettingsComponent()->get($this->getSettingsCategory(), $key, $default); }
php
public function getSetting($key = null, $default = null) { return $this->getSettingsComponent()->get($this->getSettingsCategory(), $key, $default); }
[ "public", "function", "getSetting", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "return", "$", "this", "->", "getSettingsComponent", "(", ")", "->", "get", "(", "$", "this", "->", "getSettingsCategory", "(", ")", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
Returns settings from current category. @param string|array $key Single or multiple keys in array @param mixed $default Default value when setting does not exist @return mixed Setting value @throws Exception
[ "Returns", "settings", "from", "current", "category", "." ]
train
https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/SettingsTrait.php#L39-L42
rafalkot/yii2-settings
SettingsTrait.php
SettingsTrait.setSetting
public function setSetting($key, $value = null) { $this->getSettingsComponent()->set($this->getSettingsCategory(), $key, $value); }
php
public function setSetting($key, $value = null) { $this->getSettingsComponent()->set($this->getSettingsCategory(), $key, $value); }
[ "public", "function", "setSetting", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "$", "this", "->", "getSettingsComponent", "(", ")", "->", "set", "(", "$", "this", "->", "getSettingsCategory", "(", ")", ",", "$", "key", ",", "$", "value", ")", ";", "}" ]
Saves setting @param mixed $key Setting key or array of settings ie.: ['key' => value'', 'key2' => 'value2'] @param mixed $value Setting value @throws Exception
[ "Saves", "setting" ]
train
https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/SettingsTrait.php#L51-L54
vaibhavpandeyvpz/sandesh
src/ServerRequest.php
ServerRequest.getParsedBody
public function getParsedBody() { if ($this->parsedBody || !$this->body) { return $this->parsedBody; } $type = $this->getHeaderLine('Content-Type'); if ($type) { list($type) = explode(';', $type, 2); } $body = (string)$this->getBody(); switch ($type) { case 'application/json': $this->parsedBody = json_decode($body, true); break; case 'application/x-www-form-urlencoded': parse_str($body, $data); $this->parsedBody = $data; break; case 'text/xml': $disabled = libxml_disable_entity_loader(true); $xml = simplexml_load_string($body); libxml_disable_entity_loader($disabled); $this->parsedBody = $xml; break; default: break; } return $this->parsedBody; }
php
public function getParsedBody() { if ($this->parsedBody || !$this->body) { return $this->parsedBody; } $type = $this->getHeaderLine('Content-Type'); if ($type) { list($type) = explode(';', $type, 2); } $body = (string)$this->getBody(); switch ($type) { case 'application/json': $this->parsedBody = json_decode($body, true); break; case 'application/x-www-form-urlencoded': parse_str($body, $data); $this->parsedBody = $data; break; case 'text/xml': $disabled = libxml_disable_entity_loader(true); $xml = simplexml_load_string($body); libxml_disable_entity_loader($disabled); $this->parsedBody = $xml; break; default: break; } return $this->parsedBody; }
[ "public", "function", "getParsedBody", "(", ")", "{", "if", "(", "$", "this", "->", "parsedBody", "||", "!", "$", "this", "->", "body", ")", "{", "return", "$", "this", "->", "parsedBody", ";", "}", "$", "type", "=", "$", "this", "->", "getHeaderLine", "(", "'Content-Type'", ")", ";", "if", "(", "$", "type", ")", "{", "list", "(", "$", "type", ")", "=", "explode", "(", "';'", ",", "$", "type", ",", "2", ")", ";", "}", "$", "body", "=", "(", "string", ")", "$", "this", "->", "getBody", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "'application/json'", ":", "$", "this", "->", "parsedBody", "=", "json_decode", "(", "$", "body", ",", "true", ")", ";", "break", ";", "case", "'application/x-www-form-urlencoded'", ":", "parse_str", "(", "$", "body", ",", "$", "data", ")", ";", "$", "this", "->", "parsedBody", "=", "$", "data", ";", "break", ";", "case", "'text/xml'", ":", "$", "disabled", "=", "libxml_disable_entity_loader", "(", "true", ")", ";", "$", "xml", "=", "simplexml_load_string", "(", "$", "body", ")", ";", "libxml_disable_entity_loader", "(", "$", "disabled", ")", ";", "$", "this", "->", "parsedBody", "=", "$", "xml", ";", "break", ";", "default", ":", "break", ";", "}", "return", "$", "this", "->", "parsedBody", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/ServerRequest.php#L80-L108
inhere/php-librarys
src/DI/Container.php
Container.set
public function set(string $id, $definition, array $opts = []) { $id = $this->_checkServiceId($id); // 已锁定的服务,不能更改 if ($this->isLocked($id)) { throw new \InvalidArgumentException(sprintf('Cannot override frozen service "%s".', $id)); } $args = $props = []; $opts = array_merge([ 'aliases' => null, 'shared' => true, 'locked' => false, 'active' => false, ], $opts); // 已经是个服务实例 object 不是闭包 closure if (\is_object($definition)) { $this->services[$id] = new Service($definition, $args, $opts['shared'], $opts['locked']); return $this; } // a string; is target if (\is_string($definition) || \is_callable($definition)) { $callback = $this->createCallback($definition); // a Array 详细设置服务信息 } elseif (\is_array($definition)) { if (empty($definition['target'])) { throw new \InvalidArgumentException("Configuration errors, the 'target' is must be defined! ID: $id"); } $target = $definition['target']; // 在配置中 设置一些信息 if (isset($definition['_options'])) { $opts = array_merge($opts, $definition['_options']); $this->alias($opts['aliases'], $id); unset($definition['_options']); } // 收集方法参数 if (isset($definition['_args'])) { $args = $definition['_args']; unset($definition['_args']); } // 收集对象属性 if (isset($definition['_props'])) { $props = $definition['_props']; } else { unset($definition['target']); $props = $definition; } $callback = $this->createCallback($target, $args, $props); } else { throw new \InvalidArgumentException('Invalid parameter!'); } $this->services[$id] = new Service($callback, $args, $opts['shared'], $opts['locked']); // active service if ($opts['active']) { $this->get($id); } return $this; }
php
public function set(string $id, $definition, array $opts = []) { $id = $this->_checkServiceId($id); // 已锁定的服务,不能更改 if ($this->isLocked($id)) { throw new \InvalidArgumentException(sprintf('Cannot override frozen service "%s".', $id)); } $args = $props = []; $opts = array_merge([ 'aliases' => null, 'shared' => true, 'locked' => false, 'active' => false, ], $opts); // 已经是个服务实例 object 不是闭包 closure if (\is_object($definition)) { $this->services[$id] = new Service($definition, $args, $opts['shared'], $opts['locked']); return $this; } // a string; is target if (\is_string($definition) || \is_callable($definition)) { $callback = $this->createCallback($definition); // a Array 详细设置服务信息 } elseif (\is_array($definition)) { if (empty($definition['target'])) { throw new \InvalidArgumentException("Configuration errors, the 'target' is must be defined! ID: $id"); } $target = $definition['target']; // 在配置中 设置一些信息 if (isset($definition['_options'])) { $opts = array_merge($opts, $definition['_options']); $this->alias($opts['aliases'], $id); unset($definition['_options']); } // 收集方法参数 if (isset($definition['_args'])) { $args = $definition['_args']; unset($definition['_args']); } // 收集对象属性 if (isset($definition['_props'])) { $props = $definition['_props']; } else { unset($definition['target']); $props = $definition; } $callback = $this->createCallback($target, $args, $props); } else { throw new \InvalidArgumentException('Invalid parameter!'); } $this->services[$id] = new Service($callback, $args, $opts['shared'], $opts['locked']); // active service if ($opts['active']) { $this->get($id); } return $this; }
[ "public", "function", "set", "(", "string", "$", "id", ",", "$", "definition", ",", "array", "$", "opts", "=", "[", "]", ")", "{", "$", "id", "=", "$", "this", "->", "_checkServiceId", "(", "$", "id", ")", ";", "// 已锁定的服务,不能更改", "if", "(", "$", "this", "->", "isLocked", "(", "$", "id", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Cannot override frozen service \"%s\".'", ",", "$", "id", ")", ")", ";", "}", "$", "args", "=", "$", "props", "=", "[", "]", ";", "$", "opts", "=", "array_merge", "(", "[", "'aliases'", "=>", "null", ",", "'shared'", "=>", "true", ",", "'locked'", "=>", "false", ",", "'active'", "=>", "false", ",", "]", ",", "$", "opts", ")", ";", "// 已经是个服务实例 object 不是闭包 closure", "if", "(", "\\", "is_object", "(", "$", "definition", ")", ")", "{", "$", "this", "->", "services", "[", "$", "id", "]", "=", "new", "Service", "(", "$", "definition", ",", "$", "args", ",", "$", "opts", "[", "'shared'", "]", ",", "$", "opts", "[", "'locked'", "]", ")", ";", "return", "$", "this", ";", "}", "// a string; is target", "if", "(", "\\", "is_string", "(", "$", "definition", ")", "||", "\\", "is_callable", "(", "$", "definition", ")", ")", "{", "$", "callback", "=", "$", "this", "->", "createCallback", "(", "$", "definition", ")", ";", "// a Array 详细设置服务信息", "}", "elseif", "(", "\\", "is_array", "(", "$", "definition", ")", ")", "{", "if", "(", "empty", "(", "$", "definition", "[", "'target'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Configuration errors, the 'target' is must be defined! ID: $id\"", ")", ";", "}", "$", "target", "=", "$", "definition", "[", "'target'", "]", ";", "// 在配置中 设置一些信息", "if", "(", "isset", "(", "$", "definition", "[", "'_options'", "]", ")", ")", "{", "$", "opts", "=", "array_merge", "(", "$", "opts", ",", "$", "definition", "[", "'_options'", "]", ")", ";", "$", "this", "->", "alias", "(", "$", "opts", "[", "'aliases'", "]", ",", "$", "id", ")", ";", "unset", "(", "$", "definition", "[", "'_options'", "]", ")", ";", "}", "// 收集方法参数", "if", "(", "isset", "(", "$", "definition", "[", "'_args'", "]", ")", ")", "{", "$", "args", "=", "$", "definition", "[", "'_args'", "]", ";", "unset", "(", "$", "definition", "[", "'_args'", "]", ")", ";", "}", "// 收集对象属性", "if", "(", "isset", "(", "$", "definition", "[", "'_props'", "]", ")", ")", "{", "$", "props", "=", "$", "definition", "[", "'_props'", "]", ";", "}", "else", "{", "unset", "(", "$", "definition", "[", "'target'", "]", ")", ";", "$", "props", "=", "$", "definition", ";", "}", "$", "callback", "=", "$", "this", "->", "createCallback", "(", "$", "target", ",", "$", "args", ",", "$", "props", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid parameter!'", ")", ";", "}", "$", "this", "->", "services", "[", "$", "id", "]", "=", "new", "Service", "(", "$", "callback", ",", "$", "args", ",", "$", "opts", "[", "'shared'", "]", ",", "$", "opts", "[", "'locked'", "]", ")", ";", "// active service", "if", "(", "$", "opts", "[", "'active'", "]", ")", "{", "$", "this", "->", "get", "(", "$", "id", ")", ";", "}", "return", "$", "this", ";", "}" ]
在容器注册服务 @param string $id 服务组件注册id @param mixed (string|array|object|callback) $definition 服务实例对象 | 服务信息定义 string: $definition = className array: $definition = [ // 1. 仅类名 $definition['_args']则传入对应构造方法 'target' => 'className', // 2. 类的静态方法, $definition['_args']则传入对应方法 className::staticMethod(_args...) 'target' => 'className::staticMethod', // 3. 类的动态方法, $definition['_args']则传入对应方法 (new className)->method(_args...) 'target' => 'className->method', '_options' => [...] 一些服务设置(别名,是否共享) // 设置参数方式 '_args' => [ arg1,arg2,arg3,... ] // 设置属性方式1 '_props' => [ arg1,arg2,arg3,... ] // 设置属性方式2, // prop1 prop2 prop3 将会被收集 到 _props[], 组成 方式1 的形式 prop1 => arg1, prop2 => arg2, ... ... ] object: $definition = new xxClass(); closure: $definition = function($di){ return xxx;}; @param array $opts [ 'shared' => (bool), 是否共享 'locked' => (bool), 是否锁定服务 'aliases' => (array), 别名 'active' => (bool), 立即激活 ] @return $this @internal param bool $shared 是否共享 @internal param bool $locked 是否锁定服务 @throws \Inhere\Exceptions\DependencyResolutionException @throws \InvalidArgumentException
[ "在容器注册服务", "@param", "string", "$id", "服务组件注册id", "@param", "mixed", "(", "string|array|object|callback", ")", "$definition", "服务实例对象", "|", "服务信息定义", "string", ":", "$definition", "=", "className", "array", ":", "$definition", "=", "[", "//", "1", ".", "仅类名", "$definition", "[", "_args", "]", "则传入对应构造方法", "target", "=", ">", "className", "//", "2", ".", "类的静态方法", "$definition", "[", "_args", "]", "则传入对应方法", "className", "::", "staticMethod", "(", "_args", "...", ")", "target", "=", ">", "className", "::", "staticMethod", "//", "3", ".", "类的动态方法", "$definition", "[", "_args", "]", "则传入对应方法", "(", "new", "className", ")", "-", ">", "method", "(", "_args", "...", ")", "target", "=", ">", "className", "-", ">", "method" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L131-L201
inhere/php-librarys
src/DI/Container.php
Container.sets
public function sets(array $services) { $IServiceProvider = ServiceProviderInterface::class; foreach ($services as $id => $definition) { if (!$id || !$definition) { continue; } // string. is a Service Provider class name if (\is_string($definition) && is_subclass_of($definition, $IServiceProvider)) { $this->registerServiceProvider(new $definition); continue; } // set service $this->set($id, $definition); } return $this; }
php
public function sets(array $services) { $IServiceProvider = ServiceProviderInterface::class; foreach ($services as $id => $definition) { if (!$id || !$definition) { continue; } // string. is a Service Provider class name if (\is_string($definition) && is_subclass_of($definition, $IServiceProvider)) { $this->registerServiceProvider(new $definition); continue; } // set service $this->set($id, $definition); } return $this; }
[ "public", "function", "sets", "(", "array", "$", "services", ")", "{", "$", "IServiceProvider", "=", "ServiceProviderInterface", "::", "class", ";", "foreach", "(", "$", "services", "as", "$", "id", "=>", "$", "definition", ")", "{", "if", "(", "!", "$", "id", "||", "!", "$", "definition", ")", "{", "continue", ";", "}", "// string. is a Service Provider class name", "if", "(", "\\", "is_string", "(", "$", "definition", ")", "&&", "is_subclass_of", "(", "$", "definition", ",", "$", "IServiceProvider", ")", ")", "{", "$", "this", "->", "registerServiceProvider", "(", "new", "$", "definition", ")", ";", "continue", ";", "}", "// set service", "$", "this", "->", "set", "(", "$", "id", ",", "$", "definition", ")", ";", "}", "return", "$", "this", ";", "}" ]
通过设置配置的多维数组 注册多个服务. 服务详细设置请看{@see self::set()} @param array $services @example $services = [ 'service1 id' => 'xx\yy\className', 'service2 id' => ... , 'service3 id' => ... ] @return $this @throws \InvalidArgumentException @throws \Inhere\Exceptions\DependencyResolutionException
[ "通过设置配置的多维数组", "注册多个服务", ".", "服务详细设置请看", "{" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L216-L237
inhere/php-librarys
src/DI/Container.php
Container.protect
public function protect(string $id, $definition, $share = false) { return $this->lock($id, $definition, $share); }
php
public function protect(string $id, $definition, $share = false) { return $this->lock($id, $definition, $share); }
[ "public", "function", "protect", "(", "string", "$", "id", ",", "$", "definition", ",", "$", "share", "=", "false", ")", "{", "return", "$", "this", "->", "lock", "(", "$", "id", ",", "$", "definition", ",", "$", "share", ")", ";", "}" ]
注册受保护的服务 like class::lock() @param string $id [description] @param $definition @param $share @return $this @throws \InvalidArgumentException @throws \Inhere\Exceptions\DependencyResolutionException
[ "注册受保护的服务", "like", "class", "::", "lock", "()" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L248-L251
inhere/php-librarys
src/DI/Container.php
Container.lock
public function lock(string $id, $definition, $share = false) { return $this->set($id, $definition, [ 'shared' => $share, 'locked' => true, ]); }
php
public function lock(string $id, $definition, $share = false) { return $this->set($id, $definition, [ 'shared' => $share, 'locked' => true, ]); }
[ "public", "function", "lock", "(", "string", "$", "id", ",", "$", "definition", ",", "$", "share", "=", "false", ")", "{", "return", "$", "this", "->", "set", "(", "$", "id", ",", "$", "definition", ",", "[", "'shared'", "=>", "$", "share", ",", "'locked'", "=>", "true", ",", "]", ")", ";", "}" ]
(注册)锁定的服务,也可在注册后锁定,防止 getNew() 强制重载 @param string $id description @param $definition @param $share @return $this @throws \Inhere\Exceptions\DependencyResolutionException @throws \InvalidArgumentException
[ "(", "注册", ")", "锁定的服务,也可在注册后锁定", "防止", "getNew", "()", "强制重载" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L262-L268
inhere/php-librarys
src/DI/Container.php
Container.createCallback
public function createCallback($target, array $arguments = [], array $props = []): callable { // a Closure OR a callable Object if (\is_object($target) && method_exists($target, '__invoke')) { return $target; } $arguments = array_values($arguments); /** @see $this->set() $definition is array */ $target = trim($target); if (($pos = strpos($target, '::')) !== false) { $callback = function (self $self) use ($target, $arguments) { if ($arguments) { return $target(...$arguments); } return $target($self); }; } elseif (($pos = strpos($target, '->')) !== false) { $class = substr($target, 0, $pos); $method = substr($target, $pos + 2); $callback = function (self $self) use ($class, $method, $arguments, $props) { $object = new $class; Obj::init($object, $props); if ($arguments) { return $object->$method(...$arguments); } return $object->$method($self); }; } else { // 仅是个 class name $class = $target; try { $reflection = new \ReflectionClass($class); } catch (\Exception $e) { throw new \InvalidArgumentException($e->getMessage()); } /** @var \ReflectionMethod */ $reflectionMethod = $reflection->getConstructor(); // If there are no parameters, just return a new object. if (null === $reflectionMethod) { $callback = function () use ($class, $props) { return Obj::init(new $class, $props); }; } else { $arguments = $arguments ?: Obj::getMethodArgs($reflectionMethod); // Create a callable $callback = function () use ($reflection, $arguments, $props) { $object = $reflection->newInstanceArgs($arguments); return Obj::init($object, $props); }; } unset($reflection, $reflectionMethod); } return $callback; }
php
public function createCallback($target, array $arguments = [], array $props = []): callable { // a Closure OR a callable Object if (\is_object($target) && method_exists($target, '__invoke')) { return $target; } $arguments = array_values($arguments); /** @see $this->set() $definition is array */ $target = trim($target); if (($pos = strpos($target, '::')) !== false) { $callback = function (self $self) use ($target, $arguments) { if ($arguments) { return $target(...$arguments); } return $target($self); }; } elseif (($pos = strpos($target, '->')) !== false) { $class = substr($target, 0, $pos); $method = substr($target, $pos + 2); $callback = function (self $self) use ($class, $method, $arguments, $props) { $object = new $class; Obj::init($object, $props); if ($arguments) { return $object->$method(...$arguments); } return $object->$method($self); }; } else { // 仅是个 class name $class = $target; try { $reflection = new \ReflectionClass($class); } catch (\Exception $e) { throw new \InvalidArgumentException($e->getMessage()); } /** @var \ReflectionMethod */ $reflectionMethod = $reflection->getConstructor(); // If there are no parameters, just return a new object. if (null === $reflectionMethod) { $callback = function () use ($class, $props) { return Obj::init(new $class, $props); }; } else { $arguments = $arguments ?: Obj::getMethodArgs($reflectionMethod); // Create a callable $callback = function () use ($reflection, $arguments, $props) { $object = $reflection->newInstanceArgs($arguments); return Obj::init($object, $props); }; } unset($reflection, $reflectionMethod); } return $callback; }
[ "public", "function", "createCallback", "(", "$", "target", ",", "array", "$", "arguments", "=", "[", "]", ",", "array", "$", "props", "=", "[", "]", ")", ":", "callable", "{", "// a Closure OR a callable Object", "if", "(", "\\", "is_object", "(", "$", "target", ")", "&&", "method_exists", "(", "$", "target", ",", "'__invoke'", ")", ")", "{", "return", "$", "target", ";", "}", "$", "arguments", "=", "array_values", "(", "$", "arguments", ")", ";", "/** @see $this->set() $definition is array */", "$", "target", "=", "trim", "(", "$", "target", ")", ";", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "target", ",", "'::'", ")", ")", "!==", "false", ")", "{", "$", "callback", "=", "function", "(", "self", "$", "self", ")", "use", "(", "$", "target", ",", "$", "arguments", ")", "{", "if", "(", "$", "arguments", ")", "{", "return", "$", "target", "(", "...", "$", "arguments", ")", ";", "}", "return", "$", "target", "(", "$", "self", ")", ";", "}", ";", "}", "elseif", "(", "(", "$", "pos", "=", "strpos", "(", "$", "target", ",", "'->'", ")", ")", "!==", "false", ")", "{", "$", "class", "=", "substr", "(", "$", "target", ",", "0", ",", "$", "pos", ")", ";", "$", "method", "=", "substr", "(", "$", "target", ",", "$", "pos", "+", "2", ")", ";", "$", "callback", "=", "function", "(", "self", "$", "self", ")", "use", "(", "$", "class", ",", "$", "method", ",", "$", "arguments", ",", "$", "props", ")", "{", "$", "object", "=", "new", "$", "class", ";", "Obj", "::", "init", "(", "$", "object", ",", "$", "props", ")", ";", "if", "(", "$", "arguments", ")", "{", "return", "$", "object", "->", "$", "method", "(", "...", "$", "arguments", ")", ";", "}", "return", "$", "object", "->", "$", "method", "(", "$", "self", ")", ";", "}", ";", "}", "else", "{", "// 仅是个 class name", "$", "class", "=", "$", "target", ";", "try", "{", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "/** @var \\ReflectionMethod */", "$", "reflectionMethod", "=", "$", "reflection", "->", "getConstructor", "(", ")", ";", "// If there are no parameters, just return a new object.", "if", "(", "null", "===", "$", "reflectionMethod", ")", "{", "$", "callback", "=", "function", "(", ")", "use", "(", "$", "class", ",", "$", "props", ")", "{", "return", "Obj", "::", "init", "(", "new", "$", "class", ",", "$", "props", ")", ";", "}", ";", "}", "else", "{", "$", "arguments", "=", "$", "arguments", "?", ":", "Obj", "::", "getMethodArgs", "(", "$", "reflectionMethod", ")", ";", "// Create a callable", "$", "callback", "=", "function", "(", ")", "use", "(", "$", "reflection", ",", "$", "arguments", ",", "$", "props", ")", "{", "$", "object", "=", "$", "reflection", "->", "newInstanceArgs", "(", "$", "arguments", ")", ";", "return", "Obj", "::", "init", "(", "$", "object", ",", "$", "props", ")", ";", "}", ";", "}", "unset", "(", "$", "reflection", ",", "$", "reflectionMethod", ")", ";", "}", "return", "$", "callback", ";", "}" ]
创建(类实例/类的方法)回调 @param mixed $target @param array $arguments @param array $props @return callable @throws \InvalidArgumentException @throws \Inhere\Exceptions\DependencyResolutionException
[ "创建", "(", "类实例", "/", "类的方法", ")", "回调" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L305-L372
inhere/php-librarys
src/DI/Container.php
Container.get
public function get($id) { if (!$this->has($id)) { // a class name. if (strpos($id, '\\') && class_exists($id)) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $this->set($id, $id); } else { throw new \InvalidArgumentException("The service '$id' was not found, has not been registered!"); } } return $this->getInstance($id); }
php
public function get($id) { if (!$this->has($id)) { // a class name. if (strpos($id, '\\') && class_exists($id)) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $this->set($id, $id); } else { throw new \InvalidArgumentException("The service '$id' was not found, has not been registered!"); } } return $this->getInstance($id); }
[ "public", "function", "get", "(", "$", "id", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "id", ")", ")", "{", "// a class name.", "if", "(", "strpos", "(", "$", "id", ",", "'\\\\'", ")", "&&", "class_exists", "(", "$", "id", ")", ")", "{", "/** @noinspection ExceptionsAnnotatingAndHandlingInspection */", "$", "this", "->", "set", "(", "$", "id", ",", "$", "id", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The service '$id' was not found, has not been registered!\"", ")", ";", "}", "}", "return", "$", "this", "->", "getInstance", "(", "$", "id", ")", ";", "}" ]
get 获取已注册的服务组件实例 - 共享服务总是获取已存储的实例 - 其他的则总是返回新的实例 @param string $id 要获取的服务组件id @return mixed @throws \InvalidArgumentException
[ "get", "获取已注册的服务组件实例", "-", "共享服务总是获取已存储的实例", "-", "其他的则总是返回新的实例" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L386-L399
inhere/php-librarys
src/DI/Container.php
Container.del
public function del(string $id) { $id = $this->resolveAlias($id); if (isset($this->services[$id])) { unset($this->services[$id]); } }
php
public function del(string $id) { $id = $this->resolveAlias($id); if (isset($this->services[$id])) { unset($this->services[$id]); } }
[ "public", "function", "del", "(", "string", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "resolveAlias", "(", "$", "id", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ";", "}", "}" ]
删除服务 @param $id
[ "删除服务" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L453-L460
inhere/php-librarys
src/DI/Container.php
Container.getInstance
public function getInstance(string $id, $thrErr = true, $forceNew = false) { if (!$id) { throw new \InvalidArgumentException(sprintf( 'The first parameter must be a non-empty string, %s given', \gettype($id) )); } $id = $this->resolveAlias($id); if ($service = $this->getService($id, $thrErr)) { return $service->get($this, $forceNew); } return null; }
php
public function getInstance(string $id, $thrErr = true, $forceNew = false) { if (!$id) { throw new \InvalidArgumentException(sprintf( 'The first parameter must be a non-empty string, %s given', \gettype($id) )); } $id = $this->resolveAlias($id); if ($service = $this->getService($id, $thrErr)) { return $service->get($this, $forceNew); } return null; }
[ "public", "function", "getInstance", "(", "string", "$", "id", ",", "$", "thrErr", "=", "true", ",", "$", "forceNew", "=", "false", ")", "{", "if", "(", "!", "$", "id", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'The first parameter must be a non-empty string, %s given'", ",", "\\", "gettype", "(", "$", "id", ")", ")", ")", ";", "}", "$", "id", "=", "$", "this", "->", "resolveAlias", "(", "$", "id", ")", ";", "if", "(", "$", "service", "=", "$", "this", "->", "getService", "(", "$", "id", ",", "$", "thrErr", ")", ")", "{", "return", "$", "service", "->", "get", "(", "$", "this", ",", "$", "forceNew", ")", ";", "}", "return", "null", ";", "}" ]
get 获取已注册的服务组件实例 @param $id @param bool $thrErr @param bool $forceNew 强制获取服务的新实例 @return mixed|null @throws \InvalidArgumentException
[ "get", "获取已注册的服务组件实例" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L483-L499
inhere/php-librarys
src/DI/Container.php
Container.getService
public function getService(string $id, $thrErr = false) { $id = $this->resolveAlias($id); if (isset($this->services[$id])) { return $this->services[$id]; } if ($thrErr) { throw new \InvalidArgumentException("The service '$id' was not found, has not been registered!"); } return null; }
php
public function getService(string $id, $thrErr = false) { $id = $this->resolveAlias($id); if (isset($this->services[$id])) { return $this->services[$id]; } if ($thrErr) { throw new \InvalidArgumentException("The service '$id' was not found, has not been registered!"); } return null; }
[ "public", "function", "getService", "(", "string", "$", "id", ",", "$", "thrErr", "=", "false", ")", "{", "$", "id", "=", "$", "this", "->", "resolveAlias", "(", "$", "id", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ")", "{", "return", "$", "this", "->", "services", "[", "$", "id", "]", ";", "}", "if", "(", "$", "thrErr", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The service '$id' was not found, has not been registered!\"", ")", ";", "}", "return", "null", ";", "}" ]
获取某一个服务的信息 @param $id @param bool $thrErr @return Service|null @throws \InvalidArgumentException
[ "获取某一个服务的信息" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L508-L521
inhere/php-librarys
src/DI/Container.php
Container.getIds
public function getIds($toArray = true): array { $ids = array_keys($this->services); return $toArray ? $ids : implode(', ', $ids); }
php
public function getIds($toArray = true): array { $ids = array_keys($this->services); return $toArray ? $ids : implode(', ', $ids); }
[ "public", "function", "getIds", "(", "$", "toArray", "=", "true", ")", ":", "array", "{", "$", "ids", "=", "array_keys", "(", "$", "this", "->", "services", ")", ";", "return", "$", "toArray", "?", "$", "ids", ":", "implode", "(", "', '", ",", "$", "ids", ")", ";", "}" ]
获取全部服务id @param bool $toArray @return array
[ "获取全部服务id" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/DI/Container.php#L576-L581
oroinc/OroLayoutComponent
StringOptionValueBuilder.php
StringOptionValueBuilder.add
public function add($value) { if (!is_string($value)) { throw new UnexpectedTypeException($value, 'string', 'value'); } if (empty($value)) { return; } if ($this->allowTokenize) { $this->values = array_merge($this->values, explode($this->delimiter, $value)); } else { $this->values[] = $value; } }
php
public function add($value) { if (!is_string($value)) { throw new UnexpectedTypeException($value, 'string', 'value'); } if (empty($value)) { return; } if ($this->allowTokenize) { $this->values = array_merge($this->values, explode($this->delimiter, $value)); } else { $this->values[] = $value; } }
[ "public", "function", "add", "(", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "throw", "new", "UnexpectedTypeException", "(", "$", "value", ",", "'string'", ",", "'value'", ")", ";", "}", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "allowTokenize", ")", "{", "$", "this", "->", "values", "=", "array_merge", "(", "$", "this", "->", "values", ",", "explode", "(", "$", "this", "->", "delimiter", ",", "$", "value", ")", ")", ";", "}", "else", "{", "$", "this", "->", "values", "[", "]", "=", "$", "value", ";", "}", "}" ]
Requests to add new value @param string $value
[ "Requests", "to", "add", "new", "value" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/StringOptionValueBuilder.php#L38-L52
oroinc/OroLayoutComponent
StringOptionValueBuilder.php
StringOptionValueBuilder.remove
public function remove($value) { if (!is_string($value)) { throw new UnexpectedTypeException($value, 'string', 'value'); } if (empty($value)) { return; } if ($this->allowTokenize) { $this->values = array_diff($this->values, explode($this->delimiter, $value)); } else { $this->values = array_diff($this->values, [$value]); } }
php
public function remove($value) { if (!is_string($value)) { throw new UnexpectedTypeException($value, 'string', 'value'); } if (empty($value)) { return; } if ($this->allowTokenize) { $this->values = array_diff($this->values, explode($this->delimiter, $value)); } else { $this->values = array_diff($this->values, [$value]); } }
[ "public", "function", "remove", "(", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "throw", "new", "UnexpectedTypeException", "(", "$", "value", ",", "'string'", ",", "'value'", ")", ";", "}", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "allowTokenize", ")", "{", "$", "this", "->", "values", "=", "array_diff", "(", "$", "this", "->", "values", ",", "explode", "(", "$", "this", "->", "delimiter", ",", "$", "value", ")", ")", ";", "}", "else", "{", "$", "this", "->", "values", "=", "array_diff", "(", "$", "this", "->", "values", ",", "[", "$", "value", "]", ")", ";", "}", "}" ]
Requests to remove existing value @param string $value
[ "Requests", "to", "remove", "existing", "value" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/StringOptionValueBuilder.php#L59-L73
oroinc/OroLayoutComponent
StringOptionValueBuilder.php
StringOptionValueBuilder.replace
public function replace($oldValue, $newValue) { if (!is_string($oldValue)) { throw new UnexpectedTypeException($oldValue, 'string', 'oldValue'); } if (empty($oldValue)) { return; } if (!is_string($newValue) && null !== $newValue) { throw new UnexpectedTypeException($newValue, 'string or null', 'newValue'); } $key = array_search($oldValue, $this->values, true); if (false !== $key) { if (empty($newValue)) { unset($this->values[$key]); } else { $this->values[$key] = $newValue; } } }
php
public function replace($oldValue, $newValue) { if (!is_string($oldValue)) { throw new UnexpectedTypeException($oldValue, 'string', 'oldValue'); } if (empty($oldValue)) { return; } if (!is_string($newValue) && null !== $newValue) { throw new UnexpectedTypeException($newValue, 'string or null', 'newValue'); } $key = array_search($oldValue, $this->values, true); if (false !== $key) { if (empty($newValue)) { unset($this->values[$key]); } else { $this->values[$key] = $newValue; } } }
[ "public", "function", "replace", "(", "$", "oldValue", ",", "$", "newValue", ")", "{", "if", "(", "!", "is_string", "(", "$", "oldValue", ")", ")", "{", "throw", "new", "UnexpectedTypeException", "(", "$", "oldValue", ",", "'string'", ",", "'oldValue'", ")", ";", "}", "if", "(", "empty", "(", "$", "oldValue", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_string", "(", "$", "newValue", ")", "&&", "null", "!==", "$", "newValue", ")", "{", "throw", "new", "UnexpectedTypeException", "(", "$", "newValue", ",", "'string or null'", ",", "'newValue'", ")", ";", "}", "$", "key", "=", "array_search", "(", "$", "oldValue", ",", "$", "this", "->", "values", ",", "true", ")", ";", "if", "(", "false", "!==", "$", "key", ")", "{", "if", "(", "empty", "(", "$", "newValue", ")", ")", "{", "unset", "(", "$", "this", "->", "values", "[", "$", "key", "]", ")", ";", "}", "else", "{", "$", "this", "->", "values", "[", "$", "key", "]", "=", "$", "newValue", ";", "}", "}", "}" ]
Requests to replace one value with another value @param string $oldValue @param string|null $newValue
[ "Requests", "to", "replace", "one", "value", "with", "another", "value" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/StringOptionValueBuilder.php#L81-L101
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_sqlite.php
ezcQueryExpressionSqlite.dateExtract
public function dateExtract( $column, $type ) { switch ( $type ) { case 'SECOND': $type = '%S'; break; case 'MINUTE': $type = '%M'; break; case 'HOUR': $type = '%H'; break; case 'DAY': $type = '%d'; break; case 'MONTH': $type = '%m'; break; case 'YEAR': $type = '%Y'; break; } if ( $column == 'NOW()' ) { $column = "'now'"; } $column = $this->getIdentifier( $column ); return " strftime( '{$type}', {$column} ) "; }
php
public function dateExtract( $column, $type ) { switch ( $type ) { case 'SECOND': $type = '%S'; break; case 'MINUTE': $type = '%M'; break; case 'HOUR': $type = '%H'; break; case 'DAY': $type = '%d'; break; case 'MONTH': $type = '%m'; break; case 'YEAR': $type = '%Y'; break; } if ( $column == 'NOW()' ) { $column = "'now'"; } $column = $this->getIdentifier( $column ); return " strftime( '{$type}', {$column} ) "; }
[ "public", "function", "dateExtract", "(", "$", "column", ",", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'SECOND'", ":", "$", "type", "=", "'%S'", ";", "break", ";", "case", "'MINUTE'", ":", "$", "type", "=", "'%M'", ";", "break", ";", "case", "'HOUR'", ":", "$", "type", "=", "'%H'", ";", "break", ";", "case", "'DAY'", ":", "$", "type", "=", "'%d'", ";", "break", ";", "case", "'MONTH'", ":", "$", "type", "=", "'%m'", ";", "break", ";", "case", "'YEAR'", ":", "$", "type", "=", "'%Y'", ";", "break", ";", "}", "if", "(", "$", "column", "==", "'NOW()'", ")", "{", "$", "column", "=", "\"'now'\"", ";", "}", "$", "column", "=", "$", "this", "->", "getIdentifier", "(", "$", "column", ")", ";", "return", "\" strftime( '{$type}', {$column} ) \"", ";", "}" ]
Returns the SQL that extracts parts from a timestamp value. @param string $column @param string $type one of SECOND, MINUTE, HOUR, DAY, MONTH, or YEAR @return string
[ "Returns", "the", "SQL", "that", "extracts", "parts", "from", "a", "timestamp", "value", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_sqlite.php#L146-L177
ekuiter/feature-php
FeaturePhp/File/StoredFileContent.php
StoredFileContent.copy
public function copy($target) { if (!parent::copy($target)) return false; return copy($this->fileSource, $target); }
php
public function copy($target) { if (!parent::copy($target)) return false; return copy($this->fileSource, $target); }
[ "public", "function", "copy", "(", "$", "target", ")", "{", "if", "(", "!", "parent", "::", "copy", "(", "$", "target", ")", ")", "return", "false", ";", "return", "copy", "(", "$", "this", "->", "fileSource", ",", "$", "target", ")", ";", "}" ]
Copies the stored file's content to the local filesystem. @param string $target the file target in the filesystem
[ "Copies", "the", "stored", "file", "s", "content", "to", "the", "local", "filesystem", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/StoredFileContent.php#L59-L63
blast-project/BaseEntitiesBundle
src/Search/SearchHandler.php
SearchHandler.batchUpdate
public function batchUpdate() { if ($this->_entityName === null) { throw new \Exception('Please call « handleEntity(ClassMetadata $class) » before using this handler'); } if (!$this->truncateTable()) { throw new \Exception('Could not truncate table ' . $this->getSearchIndexTable()); } $em = $this->_em; $indexClass = $this->getSearchIndexClass(); $batchSize = 100; $offset = 0; $query = $this->_em->createQueryBuilder() ->select('o') ->from($this->_entityName, 'o') ->setMaxResults($batchSize); do { $query->setFirstResult($offset); $entities = $query->getQuery()->execute(); foreach ($entities as $entity) { $fields = $this->searchIndexes[$this->_class->getName()]['fields']; foreach ($fields as $field) { $keywords = $entity->analyseField($field); foreach ($keywords as $keyword) { $index = new $indexClass(); $index->setObject($entity); $index->setField($field); $index->setKeyword($keyword); $em->persist($index); } } } $em->flush(); $offset += $batchSize; } while (count($entities) > 0); }
php
public function batchUpdate() { if ($this->_entityName === null) { throw new \Exception('Please call « handleEntity(ClassMetadata $class) » before using this handler'); } if (!$this->truncateTable()) { throw new \Exception('Could not truncate table ' . $this->getSearchIndexTable()); } $em = $this->_em; $indexClass = $this->getSearchIndexClass(); $batchSize = 100; $offset = 0; $query = $this->_em->createQueryBuilder() ->select('o') ->from($this->_entityName, 'o') ->setMaxResults($batchSize); do { $query->setFirstResult($offset); $entities = $query->getQuery()->execute(); foreach ($entities as $entity) { $fields = $this->searchIndexes[$this->_class->getName()]['fields']; foreach ($fields as $field) { $keywords = $entity->analyseField($field); foreach ($keywords as $keyword) { $index = new $indexClass(); $index->setObject($entity); $index->setField($field); $index->setKeyword($keyword); $em->persist($index); } } } $em->flush(); $offset += $batchSize; } while (count($entities) > 0); }
[ "public", "function", "batchUpdate", "(", ")", "{", "if", "(", "$", "this", "->", "_entityName", "===", "null", ")", "{", "throw", "new", "\\", "Exception", "(", "'Please call « handleEntity(ClassMetadata $class) » before using this handler');", "", "", "}", "if", "(", "!", "$", "this", "->", "truncateTable", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Could not truncate table '", ".", "$", "this", "->", "getSearchIndexTable", "(", ")", ")", ";", "}", "$", "em", "=", "$", "this", "->", "_em", ";", "$", "indexClass", "=", "$", "this", "->", "getSearchIndexClass", "(", ")", ";", "$", "batchSize", "=", "100", ";", "$", "offset", "=", "0", ";", "$", "query", "=", "$", "this", "->", "_em", "->", "createQueryBuilder", "(", ")", "->", "select", "(", "'o'", ")", "->", "from", "(", "$", "this", "->", "_entityName", ",", "'o'", ")", "->", "setMaxResults", "(", "$", "batchSize", ")", ";", "do", "{", "$", "query", "->", "setFirstResult", "(", "$", "offset", ")", ";", "$", "entities", "=", "$", "query", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "fields", "=", "$", "this", "->", "searchIndexes", "[", "$", "this", "->", "_class", "->", "getName", "(", ")", "]", "[", "'fields'", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "keywords", "=", "$", "entity", "->", "analyseField", "(", "$", "field", ")", ";", "foreach", "(", "$", "keywords", "as", "$", "keyword", ")", "{", "$", "index", "=", "new", "$", "indexClass", "(", ")", ";", "$", "index", "->", "setObject", "(", "$", "entity", ")", ";", "$", "index", "->", "setField", "(", "$", "field", ")", ";", "$", "index", "->", "setKeyword", "(", "$", "keyword", ")", ";", "$", "em", "->", "persist", "(", "$", "index", ")", ";", "}", "}", "}", "$", "em", "->", "flush", "(", ")", ";", "$", "offset", "+=", "$", "batchSize", ";", "}", "while", "(", "count", "(", "$", "entities", ")", ">", "0", ")", ";", "}" ]
Does a batch update of the whole search index table.
[ "Does", "a", "batch", "update", "of", "the", "whole", "search", "index", "table", "." ]
train
https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Search/SearchHandler.php#L65-L103
blast-project/BaseEntitiesBundle
src/Search/SearchHandler.php
SearchHandler.indexSearch
public function indexSearch($searchText, $maxResults) { // split the phrase into words $words = SearchAnalyser::analyse($searchText); if (!$words) { return []; } $query = $this->_em->createQueryBuilder() ->select('o') ->from($this->_entityName, 'o') ->setMaxResults($maxResults); $parameters = []; foreach ($words as $k => $word) { $subquery = $this->_em->createQueryBuilder() ->select("i$k.keyword") ->from($this->getSearchIndexClass(), "i$k") ->where("i$k.object = o") ->andWhere("i$k.keyword ILIKE :search$k"); $query->andWhere($query->expr()->exists($subquery->getDql())); $parameters["search$k"] = '%' . $word . '%'; } $query->setParameters($parameters); $results = $query->getQuery()->execute(); return $results; }
php
public function indexSearch($searchText, $maxResults) { // split the phrase into words $words = SearchAnalyser::analyse($searchText); if (!$words) { return []; } $query = $this->_em->createQueryBuilder() ->select('o') ->from($this->_entityName, 'o') ->setMaxResults($maxResults); $parameters = []; foreach ($words as $k => $word) { $subquery = $this->_em->createQueryBuilder() ->select("i$k.keyword") ->from($this->getSearchIndexClass(), "i$k") ->where("i$k.object = o") ->andWhere("i$k.keyword ILIKE :search$k"); $query->andWhere($query->expr()->exists($subquery->getDql())); $parameters["search$k"] = '%' . $word . '%'; } $query->setParameters($parameters); $results = $query->getQuery()->execute(); return $results; }
[ "public", "function", "indexSearch", "(", "$", "searchText", ",", "$", "maxResults", ")", "{", "// split the phrase into words", "$", "words", "=", "SearchAnalyser", "::", "analyse", "(", "$", "searchText", ")", ";", "if", "(", "!", "$", "words", ")", "{", "return", "[", "]", ";", "}", "$", "query", "=", "$", "this", "->", "_em", "->", "createQueryBuilder", "(", ")", "->", "select", "(", "'o'", ")", "->", "from", "(", "$", "this", "->", "_entityName", ",", "'o'", ")", "->", "setMaxResults", "(", "$", "maxResults", ")", ";", "$", "parameters", "=", "[", "]", ";", "foreach", "(", "$", "words", "as", "$", "k", "=>", "$", "word", ")", "{", "$", "subquery", "=", "$", "this", "->", "_em", "->", "createQueryBuilder", "(", ")", "->", "select", "(", "\"i$k.keyword\"", ")", "->", "from", "(", "$", "this", "->", "getSearchIndexClass", "(", ")", ",", "\"i$k\"", ")", "->", "where", "(", "\"i$k.object = o\"", ")", "->", "andWhere", "(", "\"i$k.keyword ILIKE :search$k\"", ")", ";", "$", "query", "->", "andWhere", "(", "$", "query", "->", "expr", "(", ")", "->", "exists", "(", "$", "subquery", "->", "getDql", "(", ")", ")", ")", ";", "$", "parameters", "[", "\"search$k\"", "]", "=", "'%'", ".", "$", "word", ".", "'%'", ";", "}", "$", "query", "->", "setParameters", "(", "$", "parameters", ")", ";", "$", "results", "=", "$", "query", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "return", "$", "results", ";", "}" ]
Find the entities that have the appropriate keywords in their searchIndex. @param string $searchText @param int $maxResults @return Collection found entities
[ "Find", "the", "entities", "that", "have", "the", "appropriate", "keywords", "in", "their", "searchIndex", "." ]
train
https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Search/SearchHandler.php#L113-L141
blast-project/BaseEntitiesBundle
src/Search/SearchHandler.php
SearchHandler.truncateTable
public function truncateTable() { $connection = $this->_em->getConnection(); $dbPlatform = $connection->getDatabasePlatform(); $connection->beginTransaction(); try { $q = $dbPlatform->getTruncateTableSql($this->getSearchIndexTable()); $connection->executeUpdate($q); $connection->commit(); return true; } catch (\Exception $e) { $connection->rollback(); return false; } }
php
public function truncateTable() { $connection = $this->_em->getConnection(); $dbPlatform = $connection->getDatabasePlatform(); $connection->beginTransaction(); try { $q = $dbPlatform->getTruncateTableSql($this->getSearchIndexTable()); $connection->executeUpdate($q); $connection->commit(); return true; } catch (\Exception $e) { $connection->rollback(); return false; } }
[ "public", "function", "truncateTable", "(", ")", "{", "$", "connection", "=", "$", "this", "->", "_em", "->", "getConnection", "(", ")", ";", "$", "dbPlatform", "=", "$", "connection", "->", "getDatabasePlatform", "(", ")", ";", "$", "connection", "->", "beginTransaction", "(", ")", ";", "try", "{", "$", "q", "=", "$", "dbPlatform", "->", "getTruncateTableSql", "(", "$", "this", "->", "getSearchIndexTable", "(", ")", ")", ";", "$", "connection", "->", "executeUpdate", "(", "$", "q", ")", ";", "$", "connection", "->", "commit", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "connection", "->", "rollback", "(", ")", ";", "return", "false", ";", "}", "}" ]
Truncates the search index table. @return bool true if success
[ "Truncates", "the", "search", "index", "table", "." ]
train
https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Search/SearchHandler.php#L148-L164
php-lug/lug
src/Bundle/GridBundle/Form/Type/GridSortingType.php
GridSortingType.configureOptions
public function configureOptions(OptionsResolver $resolver) { $resolver ->setDefaults([ 'constraints' => function (Options $options) { return new GridSortingConstraint(['grid' => $options['grid']]); }, 'error_bubbling' => function (Options $options) { return !$this->parameterResolver->resolveApi(); }, ]) ->setRequired('grid') ->setAllowedTypes('grid', GridInterface::class); }
php
public function configureOptions(OptionsResolver $resolver) { $resolver ->setDefaults([ 'constraints' => function (Options $options) { return new GridSortingConstraint(['grid' => $options['grid']]); }, 'error_bubbling' => function (Options $options) { return !$this->parameterResolver->resolveApi(); }, ]) ->setRequired('grid') ->setAllowedTypes('grid', GridInterface::class); }
[ "public", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", "{", "$", "resolver", "->", "setDefaults", "(", "[", "'constraints'", "=>", "function", "(", "Options", "$", "options", ")", "{", "return", "new", "GridSortingConstraint", "(", "[", "'grid'", "=>", "$", "options", "[", "'grid'", "]", "]", ")", ";", "}", ",", "'error_bubbling'", "=>", "function", "(", "Options", "$", "options", ")", "{", "return", "!", "$", "this", "->", "parameterResolver", "->", "resolveApi", "(", ")", ";", "}", ",", "]", ")", "->", "setRequired", "(", "'grid'", ")", "->", "setAllowedTypes", "(", "'grid'", ",", "GridInterface", "::", "class", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Form/Type/GridSortingType.php#L62-L75
gordalina/mangopay-php
src/Gordalina/Mangopay/Client.php
Client.createHttpClient
protected function createHttpClient() { $this->client = new GuzzleHttpClient($this->getEndpoint()); $this->client->addSubscriber(new SignerPlugin($this->signer)); }
php
protected function createHttpClient() { $this->client = new GuzzleHttpClient($this->getEndpoint()); $this->client->addSubscriber(new SignerPlugin($this->signer)); }
[ "protected", "function", "createHttpClient", "(", ")", "{", "$", "this", "->", "client", "=", "new", "GuzzleHttpClient", "(", "$", "this", "->", "getEndpoint", "(", ")", ")", ";", "$", "this", "->", "client", "->", "addSubscriber", "(", "new", "SignerPlugin", "(", "$", "this", "->", "signer", ")", ")", ";", "}" ]
Initializes client @return null
[ "Initializes", "client" ]
train
https://github.com/gordalina/mangopay-php/blob/6807992416d964e25670d961b66dbccd7a46ef62/src/Gordalina/Mangopay/Client.php#L127-L131
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.setAttribute
public function setAttribute($key, $value) { if ($value instanceof BaseModel || $value instanceof Collection) $this->setRelationship($value, $key); elseif ( !is_array($value)) $this->attributes[$key] = $value; else $this->setRelationship($value, $key); }
php
public function setAttribute($key, $value) { if ($value instanceof BaseModel || $value instanceof Collection) $this->setRelationship($value, $key); elseif ( !is_array($value)) $this->attributes[$key] = $value; else $this->setRelationship($value, $key); }
[ "public", "function", "setAttribute", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "BaseModel", "||", "$", "value", "instanceof", "Collection", ")", "$", "this", "->", "setRelationship", "(", "$", "value", ",", "$", "key", ")", ";", "elseif", "(", "!", "is_array", "(", "$", "value", ")", ")", "$", "this", "->", "attributes", "[", "$", "key", "]", "=", "$", "value", ";", "else", "$", "this", "->", "setRelationship", "(", "$", "value", ",", "$", "key", ")", ";", "}" ]
Sets the attributes for this model @param mixed $key @param mixed $value
[ "Sets", "the", "attributes", "for", "this", "model" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L115-L123
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.setRelationship
public function setRelationship($value, $key = '') { if (is_array($value)) { $class = __NAMESPACE__ . '\\' . str_singular($key); if (class_exists($class)) { // Check to see if the key value is plural or singular // if it is plural then we create a collection // otherwise we instantiate the class and add a single item to the relationship if (str_singular($key) == $key) { $this->addRelationship(new $class($value)); } else { $collection = $class::newCollection($value); $this->addRelationship($collection); } } } elseif ($value instanceof Collection) { $this->addRelationship($value); } elseif ($value instanceof BaseModel) { $this->addRelationship($value); } }
php
public function setRelationship($value, $key = '') { if (is_array($value)) { $class = __NAMESPACE__ . '\\' . str_singular($key); if (class_exists($class)) { // Check to see if the key value is plural or singular // if it is plural then we create a collection // otherwise we instantiate the class and add a single item to the relationship if (str_singular($key) == $key) { $this->addRelationship(new $class($value)); } else { $collection = $class::newCollection($value); $this->addRelationship($collection); } } } elseif ($value instanceof Collection) { $this->addRelationship($value); } elseif ($value instanceof BaseModel) { $this->addRelationship($value); } }
[ "public", "function", "setRelationship", "(", "$", "value", ",", "$", "key", "=", "''", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "class", "=", "__NAMESPACE__", ".", "'\\\\'", ".", "str_singular", "(", "$", "key", ")", ";", "if", "(", "class_exists", "(", "$", "class", ")", ")", "{", "// Check to see if the key value is plural or singular", "// if it is plural then we create a collection", "// otherwise we instantiate the class and add a single item to the relationship", "if", "(", "str_singular", "(", "$", "key", ")", "==", "$", "key", ")", "{", "$", "this", "->", "addRelationship", "(", "new", "$", "class", "(", "$", "value", ")", ")", ";", "}", "else", "{", "$", "collection", "=", "$", "class", "::", "newCollection", "(", "$", "value", ")", ";", "$", "this", "->", "addRelationship", "(", "$", "collection", ")", ";", "}", "}", "}", "elseif", "(", "$", "value", "instanceof", "Collection", ")", "{", "$", "this", "->", "addRelationship", "(", "$", "value", ")", ";", "}", "elseif", "(", "$", "value", "instanceof", "BaseModel", ")", "{", "$", "this", "->", "addRelationship", "(", "$", "value", ")", ";", "}", "}" ]
Sets the relationships on this model, which in fact are collections of other models @param string $key @param array $value
[ "Sets", "the", "relationships", "on", "this", "model", "which", "in", "fact", "are", "collections", "of", "other", "models" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L132-L158
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.getAttribute
public function getAttribute($key) { if (isset($this->attributes[$key])) return $this->attributes[$key]; if (isset($this->relationships[$key])) return $this->relationships[$key]; return null; }
php
public function getAttribute($key) { if (isset($this->attributes[$key])) return $this->attributes[$key]; if (isset($this->relationships[$key])) return $this->relationships[$key]; return null; }
[ "public", "function", "getAttribute", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "$", "key", "]", ")", ")", "return", "$", "this", "->", "attributes", "[", "$", "key", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "relationships", "[", "$", "key", "]", ")", ")", "return", "$", "this", "->", "relationships", "[", "$", "key", "]", ";", "return", "null", ";", "}" ]
Get an attribute from the model. @param string $key @return mixed
[ "Get", "an", "attribute", "from", "the", "model", "." ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L166-L175
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.setAttributes
public function setAttributes(array $data) { $data = $this->stripResponseData($data); foreach ($data as $key => $value) { $this->setAttribute($key, $value); } return $this->getAttributes(); }
php
public function setAttributes(array $data) { $data = $this->stripResponseData($data); foreach ($data as $key => $value) { $this->setAttribute($key, $value); } return $this->getAttributes(); }
[ "public", "function", "setAttributes", "(", "array", "$", "data", ")", "{", "$", "data", "=", "$", "this", "->", "stripResponseData", "(", "$", "data", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "setAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", "->", "getAttributes", "(", ")", ";", "}" ]
Set all the attributes from an array. @param array $data
[ "Set", "all", "the", "attributes", "from", "an", "array", "." ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L192-L201
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.getSingularEntityName
public static function getSingularEntityName() { if ( isset(self::$entity_singular) && ! empty(self::$entity_singular)) return self::$entity_singular; return str_singular(self::getEntityName()); }
php
public static function getSingularEntityName() { if ( isset(self::$entity_singular) && ! empty(self::$entity_singular)) return self::$entity_singular; return str_singular(self::getEntityName()); }
[ "public", "static", "function", "getSingularEntityName", "(", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "entity_singular", ")", "&&", "!", "empty", "(", "self", "::", "$", "entity_singular", ")", ")", "return", "self", "::", "$", "entity_singular", ";", "return", "str_singular", "(", "self", "::", "getEntityName", "(", ")", ")", ";", "}" ]
Retrieves the singular name of the entity we are querying. @return string
[ "Retrieves", "the", "singular", "name", "of", "the", "entity", "we", "are", "querying", "." ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L285-L291
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.request
public function request($method, $url, $params = array(), $xml = "", $format = "") { if ( !$format) $format = $this->format; $response = $this->api->request($method, $url, $params, $xml, $format); return $this->parseResponse($response); }
php
public function request($method, $url, $params = array(), $xml = "", $format = "") { if ( !$format) $format = $this->format; $response = $this->api->request($method, $url, $params, $xml, $format); return $this->parseResponse($response); }
[ "public", "function", "request", "(", "$", "method", ",", "$", "url", ",", "$", "params", "=", "array", "(", ")", ",", "$", "xml", "=", "\"\"", ",", "$", "format", "=", "\"\"", ")", "{", "if", "(", "!", "$", "format", ")", "$", "format", "=", "$", "this", "->", "format", ";", "$", "response", "=", "$", "this", "->", "api", "->", "request", "(", "$", "method", ",", "$", "url", ",", "$", "params", ",", "$", "xml", ",", "$", "format", ")", ";", "return", "$", "this", "->", "parseResponse", "(", "$", "response", ")", ";", "}" ]
A high level request method used from static methods. @param string $method @param string $url @param array $params @param string $xml @param string $format @return Daursu\Xero\BaseModel
[ "A", "high", "level", "request", "method", "used", "from", "static", "methods", "." ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L303-L309
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.get
public static function get($params = array()) { $object = new static; $data = $object->request('GET', $object->getUrl(), $params); $data = $object->stripResponseData($data); // Initialise a collection $collection = self::newCollection(); if (isset($data[0]) && is_array($data[0])) { // This should be a collection $collection->setItems($data); } return $collection; }
php
public static function get($params = array()) { $object = new static; $data = $object->request('GET', $object->getUrl(), $params); $data = $object->stripResponseData($data); // Initialise a collection $collection = self::newCollection(); if (isset($data[0]) && is_array($data[0])) { // This should be a collection $collection->setItems($data); } return $collection; }
[ "public", "static", "function", "get", "(", "$", "params", "=", "array", "(", ")", ")", "{", "$", "object", "=", "new", "static", ";", "$", "data", "=", "$", "object", "->", "request", "(", "'GET'", ",", "$", "object", "->", "getUrl", "(", ")", ",", "$", "params", ")", ";", "$", "data", "=", "$", "object", "->", "stripResponseData", "(", "$", "data", ")", ";", "// Initialise a collection", "$", "collection", "=", "self", "::", "newCollection", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "0", "]", ")", "&&", "is_array", "(", "$", "data", "[", "0", "]", ")", ")", "{", "// This should be a collection", "$", "collection", "->", "setItems", "(", "$", "data", ")", ";", "}", "return", "$", "collection", ";", "}" ]
Get a collection of items @param array $params @return Daursu\Xero\BaseModel
[ "Get", "a", "collection", "of", "items" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L317-L332
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.find
public static function find($id) { $object = new static; $response = $object->request('GET', sprintf('%s/%s', $object->getUrl(), $id)); return $response ? $object : false; }
php
public static function find($id) { $object = new static; $response = $object->request('GET', sprintf('%s/%s', $object->getUrl(), $id)); return $response ? $object : false; }
[ "public", "static", "function", "find", "(", "$", "id", ")", "{", "$", "object", "=", "new", "static", ";", "$", "response", "=", "$", "object", "->", "request", "(", "'GET'", ",", "sprintf", "(", "'%s/%s'", ",", "$", "object", "->", "getUrl", "(", ")", ",", "$", "id", ")", ")", ";", "return", "$", "response", "?", "$", "object", ":", "false", ";", "}" ]
Find a single element by its ID @param mixed $id @return Daursu\Xero\BaseModel
[ "Find", "a", "single", "element", "by", "its", "ID" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L340-L346
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.create
public function create($params = array()) { $response = $this->api->request('PUT', $this->getUrl(), $params, $this->toXML(), $this->format); return $this->parseResponse($response) ? true : false; }
php
public function create($params = array()) { $response = $this->api->request('PUT', $this->getUrl(), $params, $this->toXML(), $this->format); return $this->parseResponse($response) ? true : false; }
[ "public", "function", "create", "(", "$", "params", "=", "array", "(", ")", ")", "{", "$", "response", "=", "$", "this", "->", "api", "->", "request", "(", "'PUT'", ",", "$", "this", "->", "getUrl", "(", ")", ",", "$", "params", ",", "$", "this", "->", "toXML", "(", ")", ",", "$", "this", "->", "format", ")", ";", "return", "$", "this", "->", "parseResponse", "(", "$", "response", ")", "?", "true", ":", "false", ";", "}" ]
Creates a new entity in Xero @param array $data @return boolean
[ "Creates", "a", "new", "entity", "in", "Xero" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L365-L369
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.save
public function save($params = array()) { if ( isset($this->attributes[$this->primary_column])) { return $this->update($params); } else { return $this->create($params); } }
php
public function save($params = array()) { if ( isset($this->attributes[$this->primary_column])) { return $this->update($params); } else { return $this->create($params); } }
[ "public", "function", "save", "(", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "$", "this", "->", "primary_column", "]", ")", ")", "{", "return", "$", "this", "->", "update", "(", "$", "params", ")", ";", "}", "else", "{", "return", "$", "this", "->", "create", "(", "$", "params", ")", ";", "}", "}" ]
Save an entity. If it doesn't have the primary key set then it will create it, otherwise it will update it. @param array $params @return boolean
[ "Save", "an", "entity", ".", "If", "it", "doesn", "t", "have", "the", "primary", "key", "set", "then", "it", "will", "create", "it", "otherwise", "it", "will", "update", "it", "." ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L391-L399
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.delete
public function delete() { if ( !isset($this->attributes[$this->primary_column])) throw new XeroGeneralException(sprintf("The %s attribute is required.", $this->primary_column)); $this->setAttribute($this->status_field, 'DELETED'); $response = $this->api->request('POST', $this->getUrl(), array(), $this->toXML(), $this->format); return $this->parseResponse($response) ? true : false; }
php
public function delete() { if ( !isset($this->attributes[$this->primary_column])) throw new XeroGeneralException(sprintf("The %s attribute is required.", $this->primary_column)); $this->setAttribute($this->status_field, 'DELETED'); $response = $this->api->request('POST', $this->getUrl(), array(), $this->toXML(), $this->format); return $this->parseResponse($response) ? true : false; }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attributes", "[", "$", "this", "->", "primary_column", "]", ")", ")", "throw", "new", "XeroGeneralException", "(", "sprintf", "(", "\"The %s attribute is required.\"", ",", "$", "this", "->", "primary_column", ")", ")", ";", "$", "this", "->", "setAttribute", "(", "$", "this", "->", "status_field", ",", "'DELETED'", ")", ";", "$", "response", "=", "$", "this", "->", "api", "->", "request", "(", "'POST'", ",", "$", "this", "->", "getUrl", "(", ")", ",", "array", "(", ")", ",", "$", "this", "->", "toXML", "(", ")", ",", "$", "this", "->", "format", ")", ";", "return", "$", "this", "->", "parseResponse", "(", "$", "response", ")", "?", "true", ":", "false", ";", "}" ]
Delete an existing entity @param mixed $id @return array
[ "Delete", "an", "existing", "entity" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L407-L416
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.toArray
public function toArray() { $output = $this->getAttributes(); foreach ($this->relationships as $key => $value) { if ($value instanceof BaseModel) { $value = array($value->getSingularEntityName() => $value->toArray()); } else { $value = $value->toArray(); } $output = array_merge($output, $value); } return $output; }
php
public function toArray() { $output = $this->getAttributes(); foreach ($this->relationships as $key => $value) { if ($value instanceof BaseModel) { $value = array($value->getSingularEntityName() => $value->toArray()); } else { $value = $value->toArray(); } $output = array_merge($output, $value); } return $output; }
[ "public", "function", "toArray", "(", ")", "{", "$", "output", "=", "$", "this", "->", "getAttributes", "(", ")", ";", "foreach", "(", "$", "this", "->", "relationships", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "BaseModel", ")", "{", "$", "value", "=", "array", "(", "$", "value", "->", "getSingularEntityName", "(", ")", "=>", "$", "value", "->", "toArray", "(", ")", ")", ";", "}", "else", "{", "$", "value", "=", "$", "value", "->", "toArray", "(", ")", ";", "}", "$", "output", "=", "array_merge", "(", "$", "output", ",", "$", "value", ")", ";", "}", "return", "$", "output", ";", "}" ]
Convert the model to an array @return array
[ "Convert", "the", "model", "to", "an", "array" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L433-L450
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.toXML
public function toXML($singular = false) { $root = ($singular) ? self::getSingularEntityName() : self::getEntityName(); $output = new SimpleXMLElement( sprintf('<%s></%s>', $root, $root) ); if ( ! $singular) { $node = $output->addChild(self::getSingularEntityName()); self::array_to_xml($this->toArray(), $node); } else { self::array_to_xml($this->toArray(), $output); } return $output->asXML(); }
php
public function toXML($singular = false) { $root = ($singular) ? self::getSingularEntityName() : self::getEntityName(); $output = new SimpleXMLElement( sprintf('<%s></%s>', $root, $root) ); if ( ! $singular) { $node = $output->addChild(self::getSingularEntityName()); self::array_to_xml($this->toArray(), $node); } else { self::array_to_xml($this->toArray(), $output); } return $output->asXML(); }
[ "public", "function", "toXML", "(", "$", "singular", "=", "false", ")", "{", "$", "root", "=", "(", "$", "singular", ")", "?", "self", "::", "getSingularEntityName", "(", ")", ":", "self", "::", "getEntityName", "(", ")", ";", "$", "output", "=", "new", "SimpleXMLElement", "(", "sprintf", "(", "'<%s></%s>'", ",", "$", "root", ",", "$", "root", ")", ")", ";", "if", "(", "!", "$", "singular", ")", "{", "$", "node", "=", "$", "output", "->", "addChild", "(", "self", "::", "getSingularEntityName", "(", ")", ")", ";", "self", "::", "array_to_xml", "(", "$", "this", "->", "toArray", "(", ")", ",", "$", "node", ")", ";", "}", "else", "{", "self", "::", "array_to_xml", "(", "$", "this", "->", "toArray", "(", ")", ",", "$", "output", ")", ";", "}", "return", "$", "output", "->", "asXML", "(", ")", ";", "}" ]
Converts the model to XML @return string
[ "Converts", "the", "model", "to", "XML" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L468-L485
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.array_to_xml
public static function array_to_xml($array, &$xml) { foreach($array as $key => $value) { if(is_array($value)) { if(!is_numeric($key)){ $subnode = $xml->addChild("$key"); self::array_to_xml($value, $subnode); } elseif ($key == 0) { self::array_to_xml($value, $xml); } else { $name = $xml->getName(); $subnode = $xml->xpath("..")[0]->addChild("$name"); self::array_to_xml($value, $subnode); } } else { $xml->addChild("$key","$value"); } } }
php
public static function array_to_xml($array, &$xml) { foreach($array as $key => $value) { if(is_array($value)) { if(!is_numeric($key)){ $subnode = $xml->addChild("$key"); self::array_to_xml($value, $subnode); } elseif ($key == 0) { self::array_to_xml($value, $xml); } else { $name = $xml->getName(); $subnode = $xml->xpath("..")[0]->addChild("$name"); self::array_to_xml($value, $subnode); } } else { $xml->addChild("$key","$value"); } } }
[ "public", "static", "function", "array_to_xml", "(", "$", "array", ",", "&", "$", "xml", ")", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "subnode", "=", "$", "xml", "->", "addChild", "(", "\"$key\"", ")", ";", "self", "::", "array_to_xml", "(", "$", "value", ",", "$", "subnode", ")", ";", "}", "elseif", "(", "$", "key", "==", "0", ")", "{", "self", "::", "array_to_xml", "(", "$", "value", ",", "$", "xml", ")", ";", "}", "else", "{", "$", "name", "=", "$", "xml", "->", "getName", "(", ")", ";", "$", "subnode", "=", "$", "xml", "->", "xpath", "(", "\"..\"", ")", "[", "0", "]", "->", "addChild", "(", "\"$name\"", ")", ";", "self", "::", "array_to_xml", "(", "$", "value", ",", "$", "subnode", ")", ";", "}", "}", "else", "{", "$", "xml", "->", "addChild", "(", "\"$key\"", ",", "\"$value\"", ")", ";", "}", "}", "}" ]
Helper function to convert an array to XML @param array $array @param SimpleXMLElement $xml @return string
[ "Helper", "function", "to", "convert", "an", "array", "to", "XML" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L504-L522
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.stripResponseData
public function stripResponseData(array $data) { if (isset($data[self::getEntityName()]) && is_array($data[self::getEntityName()])) $data = $data[self::getEntityName()]; if (isset($data[self::getSingularEntityName()]) && is_array($data[self::getSingularEntityName()])) $data = $data[self::getSingularEntityName()]; return $data; }
php
public function stripResponseData(array $data) { if (isset($data[self::getEntityName()]) && is_array($data[self::getEntityName()])) $data = $data[self::getEntityName()]; if (isset($data[self::getSingularEntityName()]) && is_array($data[self::getSingularEntityName()])) $data = $data[self::getSingularEntityName()]; return $data; }
[ "public", "function", "stripResponseData", "(", "array", "$", "data", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "self", "::", "getEntityName", "(", ")", "]", ")", "&&", "is_array", "(", "$", "data", "[", "self", "::", "getEntityName", "(", ")", "]", ")", ")", "$", "data", "=", "$", "data", "[", "self", "::", "getEntityName", "(", ")", "]", ";", "if", "(", "isset", "(", "$", "data", "[", "self", "::", "getSingularEntityName", "(", ")", "]", ")", "&&", "is_array", "(", "$", "data", "[", "self", "::", "getSingularEntityName", "(", ")", "]", ")", ")", "$", "data", "=", "$", "data", "[", "self", "::", "getSingularEntityName", "(", ")", "]", ";", "return", "$", "data", ";", "}" ]
This function removes all the unecessary data from a response and leaves us with what we need when trying to populate objects or collections with data @param array $data @return array
[ "This", "function", "removes", "all", "the", "unecessary", "data", "from", "a", "response", "and", "leaves", "us", "with", "what", "we", "need", "when", "trying", "to", "populate", "objects", "or", "collections", "with", "data" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L532-L541
Daursu/xero
src/Daursu/Xero/models/BaseModel.php
BaseModel.parseResponse
protected function parseResponse($response, $setAttributes = true) { if ($response['code'] == 200) { $data = $this->api->parseResponse($response['response'], $response['format']); if ($response['format'] == 'xml') { $data = json_encode($data); $data = json_decode($data, true); } // print_r($data); if ($setAttributes && is_array($data)) $this->setAttributes($data); return $data; } elseif ($response['code'] == 404) { return false; } else { throw new XeroGeneralException('Error from Xero: ' . $response['response']); } }
php
protected function parseResponse($response, $setAttributes = true) { if ($response['code'] == 200) { $data = $this->api->parseResponse($response['response'], $response['format']); if ($response['format'] == 'xml') { $data = json_encode($data); $data = json_decode($data, true); } // print_r($data); if ($setAttributes && is_array($data)) $this->setAttributes($data); return $data; } elseif ($response['code'] == 404) { return false; } else { throw new XeroGeneralException('Error from Xero: ' . $response['response']); } }
[ "protected", "function", "parseResponse", "(", "$", "response", ",", "$", "setAttributes", "=", "true", ")", "{", "if", "(", "$", "response", "[", "'code'", "]", "==", "200", ")", "{", "$", "data", "=", "$", "this", "->", "api", "->", "parseResponse", "(", "$", "response", "[", "'response'", "]", ",", "$", "response", "[", "'format'", "]", ")", ";", "if", "(", "$", "response", "[", "'format'", "]", "==", "'xml'", ")", "{", "$", "data", "=", "json_encode", "(", "$", "data", ")", ";", "$", "data", "=", "json_decode", "(", "$", "data", ",", "true", ")", ";", "}", "// print_r($data);", "if", "(", "$", "setAttributes", "&&", "is_array", "(", "$", "data", ")", ")", "$", "this", "->", "setAttributes", "(", "$", "data", ")", ";", "return", "$", "data", ";", "}", "elseif", "(", "$", "response", "[", "'code'", "]", "==", "404", ")", "{", "return", "false", ";", "}", "else", "{", "throw", "new", "XeroGeneralException", "(", "'Error from Xero: '", ".", "$", "response", "[", "'response'", "]", ")", ";", "}", "}" ]
Parses the response retrieved from Xero, or throws an exception if it fails. @param array $response @return array
[ "Parses", "the", "response", "retrieved", "from", "Xero", "or", "throws", "an", "exception", "if", "it", "fails", "." ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/BaseModel.php#L550-L576
phergie/phergie-irc-plugin-react-nickserv
src/Plugin.php
Plugin.handleNotice
public function handleNotice(UserEvent $event, Queue $queue) { // Ignore notices that aren't from the NickServ agent if (strcasecmp($event->getNick(), $this->botNick) !== 0) { return; } $connection = $event->getConnection(); $params = $event->getParams(); $message = $params['text']; // Authenticate the bot's identity for authentication requests if (preg_match($this->identifyPattern, $message)) { return $queue->ircPrivmsg($this->botNick, 'IDENTIFY ' . $this->password); } // Emit an event on successful authentication if (preg_match($this->loginPattern, $message)) { return $this->getEventEmitter()->emit('nickserv.identified', [$connection, $queue]); } // Reclaim primary nick on ghost confirmation if ($this->ghostNick !== null && preg_match($this->ghostPattern, $message)) { $queue->ircNick($this->ghostNick); $this->ghostNick = null; return; } }
php
public function handleNotice(UserEvent $event, Queue $queue) { // Ignore notices that aren't from the NickServ agent if (strcasecmp($event->getNick(), $this->botNick) !== 0) { return; } $connection = $event->getConnection(); $params = $event->getParams(); $message = $params['text']; // Authenticate the bot's identity for authentication requests if (preg_match($this->identifyPattern, $message)) { return $queue->ircPrivmsg($this->botNick, 'IDENTIFY ' . $this->password); } // Emit an event on successful authentication if (preg_match($this->loginPattern, $message)) { return $this->getEventEmitter()->emit('nickserv.identified', [$connection, $queue]); } // Reclaim primary nick on ghost confirmation if ($this->ghostNick !== null && preg_match($this->ghostPattern, $message)) { $queue->ircNick($this->ghostNick); $this->ghostNick = null; return; } }
[ "public", "function", "handleNotice", "(", "UserEvent", "$", "event", ",", "Queue", "$", "queue", ")", "{", "// Ignore notices that aren't from the NickServ agent", "if", "(", "strcasecmp", "(", "$", "event", "->", "getNick", "(", ")", ",", "$", "this", "->", "botNick", ")", "!==", "0", ")", "{", "return", ";", "}", "$", "connection", "=", "$", "event", "->", "getConnection", "(", ")", ";", "$", "params", "=", "$", "event", "->", "getParams", "(", ")", ";", "$", "message", "=", "$", "params", "[", "'text'", "]", ";", "// Authenticate the bot's identity for authentication requests", "if", "(", "preg_match", "(", "$", "this", "->", "identifyPattern", ",", "$", "message", ")", ")", "{", "return", "$", "queue", "->", "ircPrivmsg", "(", "$", "this", "->", "botNick", ",", "'IDENTIFY '", ".", "$", "this", "->", "password", ")", ";", "}", "// Emit an event on successful authentication", "if", "(", "preg_match", "(", "$", "this", "->", "loginPattern", ",", "$", "message", ")", ")", "{", "return", "$", "this", "->", "getEventEmitter", "(", ")", "->", "emit", "(", "'nickserv.identified'", ",", "[", "$", "connection", ",", "$", "queue", "]", ")", ";", "}", "// Reclaim primary nick on ghost confirmation", "if", "(", "$", "this", "->", "ghostNick", "!==", "null", "&&", "preg_match", "(", "$", "this", "->", "ghostPattern", ",", "$", "message", ")", ")", "{", "$", "queue", "->", "ircNick", "(", "$", "this", "->", "ghostNick", ")", ";", "$", "this", "->", "ghostNick", "=", "null", ";", "return", ";", "}", "}" ]
Responds to authentication requests and notifications of ghost connections being killed from NickServ. @param \Phergie\Irc\Event\UserEventInterface $event @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
[ "Responds", "to", "authentication", "requests", "and", "notifications", "of", "ghost", "connections", "being", "killed", "from", "NickServ", "." ]
train
https://github.com/phergie/phergie-irc-plugin-react-nickserv/blob/0319c79314029bd1ebab0de04a67ff20705e36da/src/Plugin.php#L146-L173
phergie/phergie-irc-plugin-react-nickserv
src/Plugin.php
Plugin.handleNick
public function handleNick(UserEvent $event, Queue $queue) { $connection = $event->getConnection(); if (strcasecmp($event->getNick(), $connection->getNickname()) === 0) { $params = $event->getParams(); $connection->setNickname($params['nickname']); } }
php
public function handleNick(UserEvent $event, Queue $queue) { $connection = $event->getConnection(); if (strcasecmp($event->getNick(), $connection->getNickname()) === 0) { $params = $event->getParams(); $connection->setNickname($params['nickname']); } }
[ "public", "function", "handleNick", "(", "UserEvent", "$", "event", ",", "Queue", "$", "queue", ")", "{", "$", "connection", "=", "$", "event", "->", "getConnection", "(", ")", ";", "if", "(", "strcasecmp", "(", "$", "event", "->", "getNick", "(", ")", ",", "$", "connection", "->", "getNickname", "(", ")", ")", "===", "0", ")", "{", "$", "params", "=", "$", "event", "->", "getParams", "(", ")", ";", "$", "connection", "->", "setNickname", "(", "$", "params", "[", "'nickname'", "]", ")", ";", "}", "}" ]
Changes the nick associated with the bot in local memory when a change to it is successfully registered with the server. @param \Phergie\Irc\Event\UserEventInterface $event @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
[ "Changes", "the", "nick", "associated", "with", "the", "bot", "in", "local", "memory", "when", "a", "change", "to", "it", "is", "successfully", "registered", "with", "the", "server", "." ]
train
https://github.com/phergie/phergie-irc-plugin-react-nickserv/blob/0319c79314029bd1ebab0de04a67ff20705e36da/src/Plugin.php#L182-L189
phergie/phergie-irc-plugin-react-nickserv
src/Plugin.php
Plugin.handleNicknameInUse
public function handleNicknameInUse(ServerEvent $event, Queue $queue) { // Don't listen if ghost isn't enabled, or this isn't the first nickname-in-use error if (!$this->ghostEnabled || $this->ghostNick !== null) { return; } // Save the nick, so that we can send a ghost request once registration is complete $params = $event->getParams(); $this->ghostNick = $params[1]; }
php
public function handleNicknameInUse(ServerEvent $event, Queue $queue) { // Don't listen if ghost isn't enabled, or this isn't the first nickname-in-use error if (!$this->ghostEnabled || $this->ghostNick !== null) { return; } // Save the nick, so that we can send a ghost request once registration is complete $params = $event->getParams(); $this->ghostNick = $params[1]; }
[ "public", "function", "handleNicknameInUse", "(", "ServerEvent", "$", "event", ",", "Queue", "$", "queue", ")", "{", "// Don't listen if ghost isn't enabled, or this isn't the first nickname-in-use error", "if", "(", "!", "$", "this", "->", "ghostEnabled", "||", "$", "this", "->", "ghostNick", "!==", "null", ")", "{", "return", ";", "}", "// Save the nick, so that we can send a ghost request once registration is complete", "$", "params", "=", "$", "event", "->", "getParams", "(", ")", ";", "$", "this", "->", "ghostNick", "=", "$", "params", "[", "1", "]", ";", "}" ]
Kick-starts the ghost process. @param \Phergie\Irc\Event\ServerEventInterface $event @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
[ "Kick", "-", "starts", "the", "ghost", "process", "." ]
train
https://github.com/phergie/phergie-irc-plugin-react-nickserv/blob/0319c79314029bd1ebab0de04a67ff20705e36da/src/Plugin.php#L197-L207
phergie/phergie-irc-plugin-react-nickserv
src/Plugin.php
Plugin.handleGhost
public function handleGhost(ServerEvent $event, Queue $queue) { if ($this->ghostNick === null) { return; } // Attempt to kill the ghost connection $queue->ircPrivmsg($this->botNick, 'GHOST ' . $this->ghostNick . ' ' . $this->password); }
php
public function handleGhost(ServerEvent $event, Queue $queue) { if ($this->ghostNick === null) { return; } // Attempt to kill the ghost connection $queue->ircPrivmsg($this->botNick, 'GHOST ' . $this->ghostNick . ' ' . $this->password); }
[ "public", "function", "handleGhost", "(", "ServerEvent", "$", "event", ",", "Queue", "$", "queue", ")", "{", "if", "(", "$", "this", "->", "ghostNick", "===", "null", ")", "{", "return", ";", "}", "// Attempt to kill the ghost connection", "$", "queue", "->", "ircPrivmsg", "(", "$", "this", "->", "botNick", ",", "'GHOST '", ".", "$", "this", "->", "ghostNick", ".", "' '", ".", "$", "this", "->", "password", ")", ";", "}" ]
Completes the ghost process. @param \Phergie\Irc\Event\ServerEventInterface $event @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
[ "Completes", "the", "ghost", "process", "." ]
train
https://github.com/phergie/phergie-irc-plugin-react-nickserv/blob/0319c79314029bd1ebab0de04a67ff20705e36da/src/Plugin.php#L215-L223
phergie/phergie-irc-plugin-react-nickserv
src/Plugin.php
Plugin.getConfigOption
protected function getConfigOption(array $config, $key) { if (empty($config[$key]) || !is_string($config[$key])) { throw new \DomainException( "$key must be a non-empty string" ); } return $config[$key]; }
php
protected function getConfigOption(array $config, $key) { if (empty($config[$key]) || !is_string($config[$key])) { throw new \DomainException( "$key must be a non-empty string" ); } return $config[$key]; }
[ "protected", "function", "getConfigOption", "(", "array", "$", "config", ",", "$", "key", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "$", "key", "]", ")", "||", "!", "is_string", "(", "$", "config", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "\\", "DomainException", "(", "\"$key must be a non-empty string\"", ")", ";", "}", "return", "$", "config", "[", "$", "key", "]", ";", "}" ]
Extracts a string from the config options map. @param array $config @param string $key @return string @throws \DomainException if password is unspecified or not a string
[ "Extracts", "a", "string", "from", "the", "config", "options", "map", "." ]
train
https://github.com/phergie/phergie-irc-plugin-react-nickserv/blob/0319c79314029bd1ebab0de04a67ff20705e36da/src/Plugin.php#L233-L241
maestroprog/saw-php
src/Command/AbstractCommand.php
AbstractCommand.dispatchResult
public function dispatchResult($result, int $code) { $this->accomplishedResult = $result; $this->accomplished = true; $this->successful = CommandDispatcher::CODE_SUCCESS === $code; switch ($code) { case CommandDispatcher::CODE_SUCCESS: if (is_callable($this->onSuccess)) { call_user_func($this->onSuccess, $this); } break; case CommandDispatcher::CODE_ERROR: if (is_callable($this->onError)) { call_user_func($this->onError, $this); } break; default: throw new \RuntimeException('Why is not success and is not error?'); } }
php
public function dispatchResult($result, int $code) { $this->accomplishedResult = $result; $this->accomplished = true; $this->successful = CommandDispatcher::CODE_SUCCESS === $code; switch ($code) { case CommandDispatcher::CODE_SUCCESS: if (is_callable($this->onSuccess)) { call_user_func($this->onSuccess, $this); } break; case CommandDispatcher::CODE_ERROR: if (is_callable($this->onError)) { call_user_func($this->onError, $this); } break; default: throw new \RuntimeException('Why is not success and is not error?'); } }
[ "public", "function", "dispatchResult", "(", "$", "result", ",", "int", "$", "code", ")", "{", "$", "this", "->", "accomplishedResult", "=", "$", "result", ";", "$", "this", "->", "accomplished", "=", "true", ";", "$", "this", "->", "successful", "=", "CommandDispatcher", "::", "CODE_SUCCESS", "===", "$", "code", ";", "switch", "(", "$", "code", ")", "{", "case", "CommandDispatcher", "::", "CODE_SUCCESS", ":", "if", "(", "is_callable", "(", "$", "this", "->", "onSuccess", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "onSuccess", ",", "$", "this", ")", ";", "}", "break", ";", "case", "CommandDispatcher", "::", "CODE_ERROR", ":", "if", "(", "is_callable", "(", "$", "this", "->", "onError", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "onError", ",", "$", "this", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "\\", "RuntimeException", "(", "'Why is not success and is not error?'", ")", ";", "}", "}" ]
Метод вызывается диспетчером команд, и он реализует механизм вызова колбэков, назначаемых в @see CommandCode::onSuccess() и @see CommandCode::onError(). @param mixed $result @param int $code @return void @throws \RuntimeException Исключение бросается в случае получения неизвестного статуса выполнения команды
[ "Метод", "вызывается", "диспетчером", "команд", "и", "он", "реализует", "механизм", "вызова", "колбэков", "назначаемых", "в", "@see", "CommandCode", "::", "onSuccess", "()", "и", "@see", "CommandCode", "::", "onError", "()", "." ]
train
https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Command/AbstractCommand.php#L90-L109
willishq/laravel5-flash
src/Flash.php
Flash.message
protected function message($message, $title = '', $type = 'info') { $this->message = $message; $this->title = $title; $this->type = $type; $this->session->flash($this->namespace, (array) $this); }
php
protected function message($message, $title = '', $type = 'info') { $this->message = $message; $this->title = $title; $this->type = $type; $this->session->flash($this->namespace, (array) $this); }
[ "protected", "function", "message", "(", "$", "message", ",", "$", "title", "=", "''", ",", "$", "type", "=", "'info'", ")", "{", "$", "this", "->", "message", "=", "$", "message", ";", "$", "this", "->", "title", "=", "$", "title", ";", "$", "this", "->", "type", "=", "$", "type", ";", "$", "this", "->", "session", "->", "flash", "(", "$", "this", "->", "namespace", ",", "(", "array", ")", "$", "this", ")", ";", "}" ]
Setup the flash messsage data. @param string $message @param string $title @param string $level
[ "Setup", "the", "flash", "messsage", "data", "." ]
train
https://github.com/willishq/laravel5-flash/blob/47f436b30e5a2f5b06a742e8ed9d49251eac5589/src/Flash.php#L68-L74
FrenzelGmbH/cm-address
controllers/AddressController.php
AddressController.actionDelete
public function actionDelete($id) { $date = new DateTime('now'); $model = $this->findModel($id); $model->deleted_at = $date->format("U"); $model->save(); return $this->redirect(['index']); }
php
public function actionDelete($id) { $date = new DateTime('now'); $model = $this->findModel($id); $model->deleted_at = $date->format("U"); $model->save(); return $this->redirect(['index']); }
[ "public", "function", "actionDelete", "(", "$", "id", ")", "{", "$", "date", "=", "new", "DateTime", "(", "'now'", ")", ";", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "$", "model", "->", "deleted_at", "=", "$", "date", "->", "format", "(", "\"U\"", ")", ";", "$", "model", "->", "save", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}" ]
Deletes an existing Address model. If deletion is successful, the browser will be redirected to the 'index' page. @param integer $id @return mixed
[ "Deletes", "an", "existing", "Address", "model", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "index", "page", "." ]
train
https://github.com/FrenzelGmbH/cm-address/blob/4295671dc603beed4bea6c5a7f77dac9846127f3/controllers/AddressController.php#L101-L109
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/ServiceProvider.php
ServiceProvider.register
public function register(Application $app) { $this->registerTranslationMessages($app); $this->registerWriters($app); $this->registerDependenciesOnXsltExtension($app); $app->register(new \phpDocumentor\Plugin\Graphs\ServiceProvider()); $app->register(new \phpDocumentor\Plugin\Twig\ServiceProvider()); }
php
public function register(Application $app) { $this->registerTranslationMessages($app); $this->registerWriters($app); $this->registerDependenciesOnXsltExtension($app); $app->register(new \phpDocumentor\Plugin\Graphs\ServiceProvider()); $app->register(new \phpDocumentor\Plugin\Twig\ServiceProvider()); }
[ "public", "function", "register", "(", "Application", "$", "app", ")", "{", "$", "this", "->", "registerTranslationMessages", "(", "$", "app", ")", ";", "$", "this", "->", "registerWriters", "(", "$", "app", ")", ";", "$", "this", "->", "registerDependenciesOnXsltExtension", "(", "$", "app", ")", ";", "$", "app", "->", "register", "(", "new", "\\", "phpDocumentor", "\\", "Plugin", "\\", "Graphs", "\\", "ServiceProvider", "(", ")", ")", ";", "$", "app", "->", "register", "(", "new", "\\", "phpDocumentor", "\\", "Plugin", "\\", "Twig", "\\", "ServiceProvider", "(", ")", ")", ";", "}" ]
Registers services on the given app. @param Application $app An Application instance. @return void
[ "Registers", "services", "on", "the", "given", "app", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/ServiceProvider.php#L36-L44
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/ServiceProvider.php
ServiceProvider.registerWriters
private function registerWriters(Application $app) { $writerCollection = $this->getWriterCollection($app); $writerCollection['FileIo'] = new Writer\FileIo(); $writerCollection['checkstyle'] = new Writer\Checkstyle(); $writerCollection['sourcecode'] = new Writer\Sourcecode(); $writerCollection['statistics'] = new Writer\Statistics(); $writerCollection['xml'] = new Writer\Xml($app['transformer.routing.standard']); $writerCollection['xsl'] = new Writer\Xsl($app['monolog']); $writerCollection['checkstyle']->setTranslator($this->getTranslator($app)); $writerCollection['xml']->setTranslator($this->getTranslator($app)); }
php
private function registerWriters(Application $app) { $writerCollection = $this->getWriterCollection($app); $writerCollection['FileIo'] = new Writer\FileIo(); $writerCollection['checkstyle'] = new Writer\Checkstyle(); $writerCollection['sourcecode'] = new Writer\Sourcecode(); $writerCollection['statistics'] = new Writer\Statistics(); $writerCollection['xml'] = new Writer\Xml($app['transformer.routing.standard']); $writerCollection['xsl'] = new Writer\Xsl($app['monolog']); $writerCollection['checkstyle']->setTranslator($this->getTranslator($app)); $writerCollection['xml']->setTranslator($this->getTranslator($app)); }
[ "private", "function", "registerWriters", "(", "Application", "$", "app", ")", "{", "$", "writerCollection", "=", "$", "this", "->", "getWriterCollection", "(", "$", "app", ")", ";", "$", "writerCollection", "[", "'FileIo'", "]", "=", "new", "Writer", "\\", "FileIo", "(", ")", ";", "$", "writerCollection", "[", "'checkstyle'", "]", "=", "new", "Writer", "\\", "Checkstyle", "(", ")", ";", "$", "writerCollection", "[", "'sourcecode'", "]", "=", "new", "Writer", "\\", "Sourcecode", "(", ")", ";", "$", "writerCollection", "[", "'statistics'", "]", "=", "new", "Writer", "\\", "Statistics", "(", ")", ";", "$", "writerCollection", "[", "'xml'", "]", "=", "new", "Writer", "\\", "Xml", "(", "$", "app", "[", "'transformer.routing.standard'", "]", ")", ";", "$", "writerCollection", "[", "'xsl'", "]", "=", "new", "Writer", "\\", "Xsl", "(", "$", "app", "[", "'monolog'", "]", ")", ";", "$", "writerCollection", "[", "'checkstyle'", "]", "->", "setTranslator", "(", "$", "this", "->", "getTranslator", "(", "$", "app", ")", ")", ";", "$", "writerCollection", "[", "'xml'", "]", "->", "setTranslator", "(", "$", "this", "->", "getTranslator", "(", "$", "app", ")", ")", ";", "}" ]
Creates all writers for this plugin and adds them to the WriterCollection object. This action will enable transformations in templates to make use of these writers. @param Application $app @return void
[ "Creates", "all", "writers", "for", "this", "plugin", "and", "adds", "them", "to", "the", "WriterCollection", "object", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/ServiceProvider.php#L55-L68