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
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
huasituo/hstcms
src/Libraries/Fields/FieldAbs.php
FieldAbs.insert_value
public function insert_value(Request $request, $field, $postData = []) { $fieldname = $field['fieldname']; $value = $request->get($fieldname); if($field['fieldtype'] == 'Date' || $field['fieldtype'] == 'DateTime') { $value = (int)hst_str2time($value); } if (strpos($field['setting']['option']['fieldtype'], 'INT') !== FALSE) { $postData[$field['relatedtable']][$fieldname] = (int)$value; } elseif ($field['setting']['option']['fieldtype'] == 'DECIMAL' || $field['setting']['option']['fieldtype'] == 'FLOAT') { $postData[$field['relatedtable']][$fieldname] = (double)$value; } else { $postData[$field['relatedtable']][$fieldname] = $value ? $value : ''; } return $postData; }
php
public function insert_value(Request $request, $field, $postData = []) { $fieldname = $field['fieldname']; $value = $request->get($fieldname); if($field['fieldtype'] == 'Date' || $field['fieldtype'] == 'DateTime') { $value = (int)hst_str2time($value); } if (strpos($field['setting']['option']['fieldtype'], 'INT') !== FALSE) { $postData[$field['relatedtable']][$fieldname] = (int)$value; } elseif ($field['setting']['option']['fieldtype'] == 'DECIMAL' || $field['setting']['option']['fieldtype'] == 'FLOAT') { $postData[$field['relatedtable']][$fieldname] = (double)$value; } else { $postData[$field['relatedtable']][$fieldname] = $value ? $value : ''; } return $postData; }
[ "public", "function", "insert_value", "(", "Request", "$", "request", ",", "$", "field", ",", "$", "postData", "=", "[", "]", ")", "{", "$", "fieldname", "=", "$", "field", "[", "'fieldname'", "]", ";", "$", "value", "=", "$", "request", "->", "get", "(", "$", "fieldname", ")", ";", "if", "(", "$", "field", "[", "'fieldtype'", "]", "==", "'Date'", "||", "$", "field", "[", "'fieldtype'", "]", "==", "'DateTime'", ")", "{", "$", "value", "=", "(", "int", ")", "hst_str2time", "(", "$", "value", ")", ";", "}", "if", "(", "strpos", "(", "$", "field", "[", "'setting'", "]", "[", "'option'", "]", "[", "'fieldtype'", "]", ",", "'INT'", ")", "!==", "FALSE", ")", "{", "$", "postData", "[", "$", "field", "[", "'relatedtable'", "]", "]", "[", "$", "fieldname", "]", "=", "(", "int", ")", "$", "value", ";", "}", "elseif", "(", "$", "field", "[", "'setting'", "]", "[", "'option'", "]", "[", "'fieldtype'", "]", "==", "'DECIMAL'", "||", "$", "field", "[", "'setting'", "]", "[", "'option'", "]", "[", "'fieldtype'", "]", "==", "'FLOAT'", ")", "{", "$", "postData", "[", "$", "field", "[", "'relatedtable'", "]", "]", "[", "$", "fieldname", "]", "=", "(", "double", ")", "$", "value", ";", "}", "else", "{", "$", "postData", "[", "$", "field", "[", "'relatedtable'", "]", "]", "[", "$", "fieldname", "]", "=", "$", "value", "?", "$", "value", ":", "''", ";", "}", "return", "$", "postData", ";", "}" ]
处理输入数据,提供给入库
[ "处理输入数据,提供给入库" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/FieldAbs.php#L112-L127
huasituo/hstcms
src/Libraries/Fields/FieldAbs.php
FieldAbs.field_type
public function field_type($name = NULL, $length = NULL, $fvalue = '') { if ($this->fieldtype === TRUE) { $select = '<option value="">-</option> <option value="INT" '.($name == 'INT' ? 'selected' : '').'>INT</option> <option value="TINYINT" '.($name == 'TINYINT' ? 'selected' : '').'>TINYINT</option> <option value="SMALLINT" '.($name == 'SMALLINT' ? 'selected' : '').'>SMALLINT</option> <option value="MEDIUMINT" '.($name == 'MEDIUMINT' ? 'selected' : '').'>MEDIUMINT</option> <option value="">-</option> <option value="DECIMAL" '.($name == 'DECIMAL' ? 'selected' : '').'>DECIMAL</option> <option value="FLOAT" '.($name == 'FLOAT' ? 'selected' : '').'>FLOAT</option> <option value="">-</option> <option value="CHAR" '.($name == 'CHAR' ? 'selected' : '').'>CHAR</option> <option value="VARCHAR" '.($name == 'VARCHAR' ? 'selected' : '').'>VARCHAR</option> <option value="TEXT" '.($name == 'TEXT' ? 'selected' : '').'>TEXT</option> <option value="MEDIUMTEXT" '.($name == 'MEDIUMTEXT' ? 'selected' : '').'>MEDIUMTEXT</option>'; } elseif (count($this->fieldtype) > 1) { $select = '<option value="">-</option>'; foreach ($this->fieldtype as $t) { $select = "<option value=\"{$t}\" ".($name == $t ? "selected" : "").">{$t}</option>"; } } else { return ' <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.default.value').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][fvalue]" value="'.$fvalue.'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::fields.default.value.tips').'">'.hst_lang('hstcms::fields.default.value.tips').'</div> </div> </div>'; } $str = ' <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::manage.fields.fieldtype').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <select class="hstui-input hstui-textarea" name="setting[option][fieldtype]" onChange="setlength()" id="type"> '.$select.' </select> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::manage.fields.fieldtype.tips').'">'.hst_lang('hstcms::manage.fields.fieldtype.tips').'</div> </div> </div> <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::manage.fields.length.value').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][fieldlength]" value="'.$length.'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::manage.fields.length.value.tips').'">'.hst_lang('hstcms::manage.fields.length.value.tips').'</div> </div> </div> <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.default.value').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][fvalue]" value="'.$fvalue.'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::fields.default.value.tips').'">'.hst_lang('hstcms::fields.default.value.tips').'</div> </div> </div>'; return $str; }
php
public function field_type($name = NULL, $length = NULL, $fvalue = '') { if ($this->fieldtype === TRUE) { $select = '<option value="">-</option> <option value="INT" '.($name == 'INT' ? 'selected' : '').'>INT</option> <option value="TINYINT" '.($name == 'TINYINT' ? 'selected' : '').'>TINYINT</option> <option value="SMALLINT" '.($name == 'SMALLINT' ? 'selected' : '').'>SMALLINT</option> <option value="MEDIUMINT" '.($name == 'MEDIUMINT' ? 'selected' : '').'>MEDIUMINT</option> <option value="">-</option> <option value="DECIMAL" '.($name == 'DECIMAL' ? 'selected' : '').'>DECIMAL</option> <option value="FLOAT" '.($name == 'FLOAT' ? 'selected' : '').'>FLOAT</option> <option value="">-</option> <option value="CHAR" '.($name == 'CHAR' ? 'selected' : '').'>CHAR</option> <option value="VARCHAR" '.($name == 'VARCHAR' ? 'selected' : '').'>VARCHAR</option> <option value="TEXT" '.($name == 'TEXT' ? 'selected' : '').'>TEXT</option> <option value="MEDIUMTEXT" '.($name == 'MEDIUMTEXT' ? 'selected' : '').'>MEDIUMTEXT</option>'; } elseif (count($this->fieldtype) > 1) { $select = '<option value="">-</option>'; foreach ($this->fieldtype as $t) { $select = "<option value=\"{$t}\" ".($name == $t ? "selected" : "").">{$t}</option>"; } } else { return ' <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.default.value').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][fvalue]" value="'.$fvalue.'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::fields.default.value.tips').'">'.hst_lang('hstcms::fields.default.value.tips').'</div> </div> </div>'; } $str = ' <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::manage.fields.fieldtype').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <select class="hstui-input hstui-textarea" name="setting[option][fieldtype]" onChange="setlength()" id="type"> '.$select.' </select> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::manage.fields.fieldtype.tips').'">'.hst_lang('hstcms::manage.fields.fieldtype.tips').'</div> </div> </div> <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::manage.fields.length.value').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][fieldlength]" value="'.$length.'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::manage.fields.length.value.tips').'">'.hst_lang('hstcms::manage.fields.length.value.tips').'</div> </div> </div> <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.default.value').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][fvalue]" value="'.$fvalue.'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::fields.default.value.tips').'">'.hst_lang('hstcms::fields.default.value.tips').'</div> </div> </div>'; return $str; }
[ "public", "function", "field_type", "(", "$", "name", "=", "NULL", ",", "$", "length", "=", "NULL", ",", "$", "fvalue", "=", "''", ")", "{", "if", "(", "$", "this", "->", "fieldtype", "===", "TRUE", ")", "{", "$", "select", "=", "'<option value=\"\">-</option>\n\t\t\t\t<option value=\"INT\" '", ".", "(", "$", "name", "==", "'INT'", "?", "'selected'", ":", "''", ")", ".", "'>INT</option>\n\t\t\t\t<option value=\"TINYINT\" '", ".", "(", "$", "name", "==", "'TINYINT'", "?", "'selected'", ":", "''", ")", ".", "'>TINYINT</option>\n\t\t\t\t<option value=\"SMALLINT\" '", ".", "(", "$", "name", "==", "'SMALLINT'", "?", "'selected'", ":", "''", ")", ".", "'>SMALLINT</option>\n\t\t\t\t<option value=\"MEDIUMINT\" '", ".", "(", "$", "name", "==", "'MEDIUMINT'", "?", "'selected'", ":", "''", ")", ".", "'>MEDIUMINT</option>\n\t\t\t\t<option value=\"\">-</option>\n\t\t\t\t<option value=\"DECIMAL\" '", ".", "(", "$", "name", "==", "'DECIMAL'", "?", "'selected'", ":", "''", ")", ".", "'>DECIMAL</option>\n\t\t\t\t<option value=\"FLOAT\" '", ".", "(", "$", "name", "==", "'FLOAT'", "?", "'selected'", ":", "''", ")", ".", "'>FLOAT</option>\n\t\t\t\t<option value=\"\">-</option>\n\t\t\t\t<option value=\"CHAR\" '", ".", "(", "$", "name", "==", "'CHAR'", "?", "'selected'", ":", "''", ")", ".", "'>CHAR</option>\n\t\t\t\t<option value=\"VARCHAR\" '", ".", "(", "$", "name", "==", "'VARCHAR'", "?", "'selected'", ":", "''", ")", ".", "'>VARCHAR</option>\n\t\t\t\t<option value=\"TEXT\" '", ".", "(", "$", "name", "==", "'TEXT'", "?", "'selected'", ":", "''", ")", ".", "'>TEXT</option>\n\t\t\t\t<option value=\"MEDIUMTEXT\" '", ".", "(", "$", "name", "==", "'MEDIUMTEXT'", "?", "'selected'", ":", "''", ")", ".", "'>MEDIUMTEXT</option>'", ";", "}", "elseif", "(", "count", "(", "$", "this", "->", "fieldtype", ")", ">", "1", ")", "{", "$", "select", "=", "'<option value=\"\">-</option>'", ";", "foreach", "(", "$", "this", "->", "fieldtype", "as", "$", "t", ")", "{", "$", "select", "=", "\"<option value=\\\"{$t}\\\" \"", ".", "(", "$", "name", "==", "$", "t", "?", "\"selected\"", ":", "\"\"", ")", ".", "\">{$t}</option>\"", ";", "}", "}", "else", "{", "return", "'\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'", ".", "hst_lang", "(", "'hstcms::fields.default.value'", ")", ".", "'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][fvalue]\" value=\"'", ".", "$", "fvalue", ".", "'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_name\" data-tips=\"'", ".", "hst_lang", "(", "'hstcms::fields.default.value.tips'", ")", ".", "'\">'", ".", "hst_lang", "(", "'hstcms::fields.default.value.tips'", ")", ".", "'</div>\n\t </div>\n\t </div>'", ";", "}", "$", "str", "=", "'\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'", ".", "hst_lang", "(", "'hstcms::manage.fields.fieldtype'", ")", ".", "'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t \t<select class=\"hstui-input hstui-textarea\" name=\"setting[option][fieldtype]\" onChange=\"setlength()\" id=\"type\">\n\t\t\t\t\t\t'", ".", "$", "select", ".", "'\n\t\t\t\t\t</select>\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_name\" data-tips=\"'", ".", "hst_lang", "(", "'hstcms::manage.fields.fieldtype.tips'", ")", ".", "'\">'", ".", "hst_lang", "(", "'hstcms::manage.fields.fieldtype.tips'", ")", ".", "'</div>\n\t </div>\n\t </div>\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'", ".", "hst_lang", "(", "'hstcms::manage.fields.length.value'", ")", ".", "'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][fieldlength]\" value=\"'", ".", "$", "length", ".", "'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_name\" data-tips=\"'", ".", "hst_lang", "(", "'hstcms::manage.fields.length.value.tips'", ")", ".", "'\">'", ".", "hst_lang", "(", "'hstcms::manage.fields.length.value.tips'", ")", ".", "'</div>\n\t </div>\n\t </div>\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'", ".", "hst_lang", "(", "'hstcms::fields.default.value'", ")", ".", "'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][fvalue]\" value=\"'", ".", "$", "fvalue", ".", "'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_name\" data-tips=\"'", ".", "hst_lang", "(", "'hstcms::fields.default.value.tips'", ")", ".", "'\">'", ".", "hst_lang", "(", "'hstcms::fields.default.value.tips'", ")", ".", "'</div>\n\t </div>\n\t </div>'", ";", "return", "$", "str", ";", "}" ]
字段类型选择 @param string $name @param string $length @return string
[ "字段类型选择" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/FieldAbs.php#L196-L252
huasituo/hstcms
src/Libraries/Fields/FieldAbs.php
FieldAbs.input_format
public function input_format($name, $text, $value, $tips, $formattr = '') { return str_replace(['{name}', '{text}', '{value}', '{tips}', '{formattr}'], [$name, $text, $value, $tips, $formattr], $this->format); }
php
public function input_format($name, $text, $value, $tips, $formattr = '') { return str_replace(['{name}', '{text}', '{value}', '{tips}', '{formattr}'], [$name, $text, $value, $tips, $formattr], $this->format); }
[ "public", "function", "input_format", "(", "$", "name", ",", "$", "text", ",", "$", "value", ",", "$", "tips", ",", "$", "formattr", "=", "''", ")", "{", "return", "str_replace", "(", "[", "'{name}'", ",", "'{text}'", ",", "'{value}'", ",", "'{tips}'", ",", "'{formattr}'", "]", ",", "[", "$", "name", ",", "$", "text", ",", "$", "value", ",", "$", "tips", ",", "$", "formattr", "]", ",", "$", "this", "->", "format", ")", ";", "}" ]
表单输入格式 @param string $name 字段名称 @param string $text 字段别名 @param string $value 表单输入内容 @return string
[ "表单输入格式" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/FieldAbs.php#L262-L265
baleen/cli
src/Config/Definition.php
Definition.addMigrationsNode
protected function addMigrationsNode() { $builder = new TreeBuilder(); $node = $builder->root('migrations'); $node->isRequired() ->children() ->scalarNode('directory')->defaultValue('migrations')->end() ->scalarNode('namespace')->defaultValue('Migrations')->end() ->end() ->end(); return $node; }
php
protected function addMigrationsNode() { $builder = new TreeBuilder(); $node = $builder->root('migrations'); $node->isRequired() ->children() ->scalarNode('directory')->defaultValue('migrations')->end() ->scalarNode('namespace')->defaultValue('Migrations')->end() ->end() ->end(); return $node; }
[ "protected", "function", "addMigrationsNode", "(", ")", "{", "$", "builder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "node", "=", "$", "builder", "->", "root", "(", "'migrations'", ")", ";", "$", "node", "->", "isRequired", "(", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'directory'", ")", "->", "defaultValue", "(", "'migrations'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'namespace'", ")", "->", "defaultValue", "(", "'Migrations'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", ";", "return", "$", "node", ";", "}" ]
addMigrationsNode. @return \Symfony\Component\Config\Definition\Builder\NodeDefinition
[ "addMigrationsNode", "." ]
train
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/Config/Definition.php#L64-L77
tequila/mongodb-php-lib
src/OptionsResolver/OptionsResolver.php
OptionsResolver.get
public static function get($resolverClass) { if (!is_string($resolverClass)) { throw new InvalidArgumentException('$resolverClass must be a string.'); } if (!array_key_exists($resolverClass, self::$cache)) { if (!class_exists($resolverClass)) { throw new InvalidArgumentException( sprintf('Resolver class "%s" is not found.', $resolverClass) ); } /** @var OptionsResolver $resolver */ $resolver = new $resolverClass(); if (!$resolver instanceof self) { throw new InvalidArgumentException( sprintf( 'Resolver class "%s" must extend "%s".', $resolverClass, self::class ) ); } $resolver->configureOptions(); self::$cache[$resolverClass] = $resolver; } return self::$cache[$resolverClass]; }
php
public static function get($resolverClass) { if (!is_string($resolverClass)) { throw new InvalidArgumentException('$resolverClass must be a string.'); } if (!array_key_exists($resolverClass, self::$cache)) { if (!class_exists($resolverClass)) { throw new InvalidArgumentException( sprintf('Resolver class "%s" is not found.', $resolverClass) ); } /** @var OptionsResolver $resolver */ $resolver = new $resolverClass(); if (!$resolver instanceof self) { throw new InvalidArgumentException( sprintf( 'Resolver class "%s" must extend "%s".', $resolverClass, self::class ) ); } $resolver->configureOptions(); self::$cache[$resolverClass] = $resolver; } return self::$cache[$resolverClass]; }
[ "public", "static", "function", "get", "(", "$", "resolverClass", ")", "{", "if", "(", "!", "is_string", "(", "$", "resolverClass", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'$resolverClass must be a string.'", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "resolverClass", ",", "self", "::", "$", "cache", ")", ")", "{", "if", "(", "!", "class_exists", "(", "$", "resolverClass", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Resolver class \"%s\" is not found.'", ",", "$", "resolverClass", ")", ")", ";", "}", "/** @var OptionsResolver $resolver */", "$", "resolver", "=", "new", "$", "resolverClass", "(", ")", ";", "if", "(", "!", "$", "resolver", "instanceof", "self", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Resolver class \"%s\" must extend \"%s\".'", ",", "$", "resolverClass", ",", "self", "::", "class", ")", ")", ";", "}", "$", "resolver", "->", "configureOptions", "(", ")", ";", "self", "::", "$", "cache", "[", "$", "resolverClass", "]", "=", "$", "resolver", ";", "}", "return", "self", "::", "$", "cache", "[", "$", "resolverClass", "]", ";", "}" ]
@param string $resolverClass fully-qualified class name of resolver @return OptionsResolver
[ "@param", "string", "$resolverClass", "fully", "-", "qualified", "class", "name", "of", "resolver" ]
train
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/OptionsResolver/OptionsResolver.php#L34-L65
czim/laravel-pxlcms
src/Generator/Writer/Model/Steps/StubReplaceSluggableData.php
StubReplaceSluggableData.getSluggableConfigReplace
protected function getSluggableConfigReplace() { $setup = $this->data->sluggable_setup; if ( ! $this->context->modelIsSluggable || ! $this->data->sluggable || empty($setup)) return ''; $replace = $this->tab() . "protected \$sluggable = [\n"; $rows = []; if (array_get($setup, 'source')) { $rows['build_from'] = "'" . $setup['source'] . "'"; } if (array_get($setup, 'target')) { $rows['save_to'] = "'" . $setup['target'] . "'"; } if (config('pxlcms.generator.models.slugs.resluggify_on_update')) { $rows['on_update'] = 'true'; } // for now we don't support the locale key, all translated // tables will have a language_id column in the old CMS. if (array_get($setup, 'translated') === true) { $rows['language_key'] = "'" . config('pxlcms.slugs.keys.language', 'language_id') . "'"; $rows['locale_key'] = 'null'; } $longestPropertyLength = $this->getLongestKey($rows); foreach ($rows as $property => $value) { $replace .= $this->tab(2) . "'" . str_pad($property . "'", $longestPropertyLength + 1) . " => {$value},\n"; } $replace .= $this->tab() . "];\n\n"; return $replace; }
php
protected function getSluggableConfigReplace() { $setup = $this->data->sluggable_setup; if ( ! $this->context->modelIsSluggable || ! $this->data->sluggable || empty($setup)) return ''; $replace = $this->tab() . "protected \$sluggable = [\n"; $rows = []; if (array_get($setup, 'source')) { $rows['build_from'] = "'" . $setup['source'] . "'"; } if (array_get($setup, 'target')) { $rows['save_to'] = "'" . $setup['target'] . "'"; } if (config('pxlcms.generator.models.slugs.resluggify_on_update')) { $rows['on_update'] = 'true'; } // for now we don't support the locale key, all translated // tables will have a language_id column in the old CMS. if (array_get($setup, 'translated') === true) { $rows['language_key'] = "'" . config('pxlcms.slugs.keys.language', 'language_id') . "'"; $rows['locale_key'] = 'null'; } $longestPropertyLength = $this->getLongestKey($rows); foreach ($rows as $property => $value) { $replace .= $this->tab(2) . "'" . str_pad($property . "'", $longestPropertyLength + 1) . " => {$value},\n"; } $replace .= $this->tab() . "];\n\n"; return $replace; }
[ "protected", "function", "getSluggableConfigReplace", "(", ")", "{", "$", "setup", "=", "$", "this", "->", "data", "->", "sluggable_setup", ";", "if", "(", "!", "$", "this", "->", "context", "->", "modelIsSluggable", "||", "!", "$", "this", "->", "data", "->", "sluggable", "||", "empty", "(", "$", "setup", ")", ")", "return", "''", ";", "$", "replace", "=", "$", "this", "->", "tab", "(", ")", ".", "\"protected \\$sluggable = [\\n\"", ";", "$", "rows", "=", "[", "]", ";", "if", "(", "array_get", "(", "$", "setup", ",", "'source'", ")", ")", "{", "$", "rows", "[", "'build_from'", "]", "=", "\"'\"", ".", "$", "setup", "[", "'source'", "]", ".", "\"'\"", ";", "}", "if", "(", "array_get", "(", "$", "setup", ",", "'target'", ")", ")", "{", "$", "rows", "[", "'save_to'", "]", "=", "\"'\"", ".", "$", "setup", "[", "'target'", "]", ".", "\"'\"", ";", "}", "if", "(", "config", "(", "'pxlcms.generator.models.slugs.resluggify_on_update'", ")", ")", "{", "$", "rows", "[", "'on_update'", "]", "=", "'true'", ";", "}", "// for now we don't support the locale key, all translated", "// tables will have a language_id column in the old CMS.", "if", "(", "array_get", "(", "$", "setup", ",", "'translated'", ")", "===", "true", ")", "{", "$", "rows", "[", "'language_key'", "]", "=", "\"'\"", ".", "config", "(", "'pxlcms.slugs.keys.language'", ",", "'language_id'", ")", ".", "\"'\"", ";", "$", "rows", "[", "'locale_key'", "]", "=", "'null'", ";", "}", "$", "longestPropertyLength", "=", "$", "this", "->", "getLongestKey", "(", "$", "rows", ")", ";", "foreach", "(", "$", "rows", "as", "$", "property", "=>", "$", "value", ")", "{", "$", "replace", ".=", "$", "this", "->", "tab", "(", "2", ")", ".", "\"'\"", ".", "str_pad", "(", "$", "property", ".", "\"'\"", ",", "$", "longestPropertyLength", "+", "1", ")", ".", "\" => {$value},\\n\"", ";", "}", "$", "replace", ".=", "$", "this", "->", "tab", "(", ")", ".", "\"];\\n\\n\"", ";", "return", "$", "replace", ";", "}" ]
Returns the replacement for the sluggable config placeholder @return string
[ "Returns", "the", "replacement", "for", "the", "sluggable", "config", "placeholder" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Writer/Model/Steps/StubReplaceSluggableData.php#L18-L60
alexpts/psr15-middlewares
src/ResponseTime.php
ResponseTime.process
public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface { $server = $request->getServerParams(); $startTime = $server['REQUEST_TIME_FLOAT'] ?? microtime(true); $response = $next->handle($request); $diff = $this->getDiff($startTime); return $response->withHeader(self::HEADER, sprintf('%2.3fms', $diff)); }
php
public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface { $server = $request->getServerParams(); $startTime = $server['REQUEST_TIME_FLOAT'] ?? microtime(true); $response = $next->handle($request); $diff = $this->getDiff($startTime); return $response->withHeader(self::HEADER, sprintf('%2.3fms', $diff)); }
[ "public", "function", "process", "(", "ServerRequestInterface", "$", "request", ",", "RequestHandlerInterface", "$", "next", ")", ":", "ResponseInterface", "{", "$", "server", "=", "$", "request", "->", "getServerParams", "(", ")", ";", "$", "startTime", "=", "$", "server", "[", "'REQUEST_TIME_FLOAT'", "]", "??", "microtime", "(", "true", ")", ";", "$", "response", "=", "$", "next", "->", "handle", "(", "$", "request", ")", ";", "$", "diff", "=", "$", "this", "->", "getDiff", "(", "$", "startTime", ")", ";", "return", "$", "response", "->", "withHeader", "(", "self", "::", "HEADER", ",", "sprintf", "(", "'%2.3fms'", ",", "$", "diff", ")", ")", ";", "}" ]
@param ServerRequestInterface $request @param RequestHandlerInterface $next @return ResponseInterface @throws \InvalidArgumentException
[ "@param", "ServerRequestInterface", "$request", "@param", "RequestHandlerInterface", "$next" ]
train
https://github.com/alexpts/psr15-middlewares/blob/bff2887d5af01c54d9288fd19c20f0f593b69358/src/ResponseTime.php#L28-L37
huasituo/hstcms
src/Console/Generators/MakeInstallCommand.php
MakeInstallCommand.stepOne
private function stepOne() { if (file_exists(base_path('hstcms.install.lck'))) { $this->info(hst_lang('hstcms::install.install.already').'HSTCMS'.config('hstcms.version').','.hst_lang('hstcms::install.install.one')); return true; } if (!$this->files->isFile(base_path('.env'))) { $this->files->copy(base_path('.env.example'), base_path('.env')); } $this->container['lang'] = $this->ask('Please enter the site url:', env('locale', 'zh-en')); //检查数据库信息是否配置 if(!hst_checkEnvIsNull('DB_HOST') || !hst_checkEnvIsNull('DB_DATABASE') || !hst_checkEnvIsNull('DB_USERNAME') || !hst_checkEnvIsNull('DB_PASSWORD') || $this->option('d') !== 'null' ) { $this->container['db_host'] = $this->ask('Please enter the db host:', 'localhost'); $this->container['db_username'] = $this->ask('Please enter the db database:', 'root'); $this->container['db_password'] = $this->ask('Please enter the db password:', ''); $this->container['db_database'] = $this->ask('Please enter db database:', ''); } $this->container['site_url'] = $this->ask('Please enter the site url:', $this->container['site_url']); $this->container['username'] = $this->ask('Please enter the admin username:', 'admin'); $this->container['password'] = $this->ask('Please enter the admin password:', 'admin888'); $this->comment('You have provided the following manifest information:'); if(!hst_checkEnvIsNull('DB_HOST') || !hst_checkEnvIsNull('DB_DATABASE') || !hst_checkEnvIsNull('DB_USERNAME') || !hst_checkEnvIsNull('DB_PASSWORD') || $this->option('d') !== 'null' ) { $this->comment('DbHost: '.$this->container['db_host']); $this->comment('DbUsername: '.$this->container['db_username']); $this->comment('DbPassword: '.$this->container['db_password']); $this->comment('DbDatabase: '.$this->container['db_database']); } $this->comment('SiteUrl: '.$this->container['site_url']); $this->comment('Username: '.$this->container['username']); $this->comment('Password: '.$this->container['password']); Config::set('locale', $this->container['lang']); if ($this->confirm('If the provided information is correct, type "yes" to generate.')) { $envData = []; if(isset($this->container['db_host']) && $this->container['db_host']) { $envData = [ 'DB_HOST'=> $this->container['db_host'], 'DB_USERNAME'=> $this->container['db_username'], 'DB_PASSWORD'=> $this->container['db_password'], 'DB_DATABASE'=> $this->container['db_database'], ]; Config::set('database.connections.mysql.host', $this->container['db_host']); Config::set('database.connections.mysql.database', $this->container['db_database']); Config::set('database.connections.mysql.username', $this->container['db_username']); Config::set('database.connections.mysql.password', $this->container['db_password']); } else { $this->container['db_host'] = env('DB_HOST'); $this->container['db_username'] = env('DB_USERNAME'); $this->container['db_password'] = env('DB_PASSWORD'); $this->container['db_database'] = env('DB_DATABASE'); } if($this->container['site_url'] !== 'null') { $envData['APP_URL'] = $this->container['site_url']; } else { $envData['APP_URL'] = ''; } hst_updateEnvInfo($envData); $link = mysqli_connect($this->container['db_host'], $this->container['db_username'], $this->container['db_password']); if (!$link) { $this->error('Database configuration information error'); return $this->stepOne(); } if ( !mysqli_select_db($link, $this->container['db_database'])) { $sql = "CREATE DATABASE `" . $this->container['db_database'] . "`"; mysqli_query($link, $sql) or mysqli_error($link); } if($this->option('a') !== 'null'){ $this->call('migrate', [ '--force' => true ]); } else { $this->call('migrate', [ '--path' => 'vendor/huasituo/hstcms/src/database/migrations', '--force' => true ]); } $this->call('hstcms:seed', [ '--force' => true ]); $status = DB::transaction(function() { hst_save_config('site', [ ['name'=>'url', 'value'=>$this->container['site_url'], 'issystem'=>1], ['name'=>'debug', 'value'=>1, 'issystem'=>1] ]); if($this->container['site_url'] === 'null') { hst_save_config('site', [ ['name'=>'url', 'value'=>'', 'issystem'=>1], ['name'=>'debug', 'value'=>1, 'issystem'=>1] ]); } $salt = hst_random(6); ManageUserModel::insert([ 'gid'=>99, 'status'=>0, 'username' => $this->container['username'], 'salt' => $salt, 'password' => hst_md5($this->container['password'], $salt) ]); }); if (!is_null($status)) { $this->error(hst_lang('hstcms::install.install.error')); return $this->stepOne(); } else { $this->call('key:generate'); $this->call('vendor:publish', [ '--tag'=>'config' ]); $this->call('vendor:publish', [ '--tag'=>'public' ]); $this->call('hstcms:cache'); // $this->call('migrate', [ // '--force'=>true // ]); File::put(base_path('hstcms.install.lck'), env('APP_KEY')); $this->info('---------Install Success---------'); if($this->container['site_url'] !== 'null') { $this->comment('Home: '.env('APP_URL')); $this->comment('Admin: '.env('APP_URL').'/manage'); } else { $this->comment('Home: http(https)://域名(ip)'); $this->comment('Admin: http(https)://域名(ip)/manage'); } } } return true; }
php
private function stepOne() { if (file_exists(base_path('hstcms.install.lck'))) { $this->info(hst_lang('hstcms::install.install.already').'HSTCMS'.config('hstcms.version').','.hst_lang('hstcms::install.install.one')); return true; } if (!$this->files->isFile(base_path('.env'))) { $this->files->copy(base_path('.env.example'), base_path('.env')); } $this->container['lang'] = $this->ask('Please enter the site url:', env('locale', 'zh-en')); //检查数据库信息是否配置 if(!hst_checkEnvIsNull('DB_HOST') || !hst_checkEnvIsNull('DB_DATABASE') || !hst_checkEnvIsNull('DB_USERNAME') || !hst_checkEnvIsNull('DB_PASSWORD') || $this->option('d') !== 'null' ) { $this->container['db_host'] = $this->ask('Please enter the db host:', 'localhost'); $this->container['db_username'] = $this->ask('Please enter the db database:', 'root'); $this->container['db_password'] = $this->ask('Please enter the db password:', ''); $this->container['db_database'] = $this->ask('Please enter db database:', ''); } $this->container['site_url'] = $this->ask('Please enter the site url:', $this->container['site_url']); $this->container['username'] = $this->ask('Please enter the admin username:', 'admin'); $this->container['password'] = $this->ask('Please enter the admin password:', 'admin888'); $this->comment('You have provided the following manifest information:'); if(!hst_checkEnvIsNull('DB_HOST') || !hst_checkEnvIsNull('DB_DATABASE') || !hst_checkEnvIsNull('DB_USERNAME') || !hst_checkEnvIsNull('DB_PASSWORD') || $this->option('d') !== 'null' ) { $this->comment('DbHost: '.$this->container['db_host']); $this->comment('DbUsername: '.$this->container['db_username']); $this->comment('DbPassword: '.$this->container['db_password']); $this->comment('DbDatabase: '.$this->container['db_database']); } $this->comment('SiteUrl: '.$this->container['site_url']); $this->comment('Username: '.$this->container['username']); $this->comment('Password: '.$this->container['password']); Config::set('locale', $this->container['lang']); if ($this->confirm('If the provided information is correct, type "yes" to generate.')) { $envData = []; if(isset($this->container['db_host']) && $this->container['db_host']) { $envData = [ 'DB_HOST'=> $this->container['db_host'], 'DB_USERNAME'=> $this->container['db_username'], 'DB_PASSWORD'=> $this->container['db_password'], 'DB_DATABASE'=> $this->container['db_database'], ]; Config::set('database.connections.mysql.host', $this->container['db_host']); Config::set('database.connections.mysql.database', $this->container['db_database']); Config::set('database.connections.mysql.username', $this->container['db_username']); Config::set('database.connections.mysql.password', $this->container['db_password']); } else { $this->container['db_host'] = env('DB_HOST'); $this->container['db_username'] = env('DB_USERNAME'); $this->container['db_password'] = env('DB_PASSWORD'); $this->container['db_database'] = env('DB_DATABASE'); } if($this->container['site_url'] !== 'null') { $envData['APP_URL'] = $this->container['site_url']; } else { $envData['APP_URL'] = ''; } hst_updateEnvInfo($envData); $link = mysqli_connect($this->container['db_host'], $this->container['db_username'], $this->container['db_password']); if (!$link) { $this->error('Database configuration information error'); return $this->stepOne(); } if ( !mysqli_select_db($link, $this->container['db_database'])) { $sql = "CREATE DATABASE `" . $this->container['db_database'] . "`"; mysqli_query($link, $sql) or mysqli_error($link); } if($this->option('a') !== 'null'){ $this->call('migrate', [ '--force' => true ]); } else { $this->call('migrate', [ '--path' => 'vendor/huasituo/hstcms/src/database/migrations', '--force' => true ]); } $this->call('hstcms:seed', [ '--force' => true ]); $status = DB::transaction(function() { hst_save_config('site', [ ['name'=>'url', 'value'=>$this->container['site_url'], 'issystem'=>1], ['name'=>'debug', 'value'=>1, 'issystem'=>1] ]); if($this->container['site_url'] === 'null') { hst_save_config('site', [ ['name'=>'url', 'value'=>'', 'issystem'=>1], ['name'=>'debug', 'value'=>1, 'issystem'=>1] ]); } $salt = hst_random(6); ManageUserModel::insert([ 'gid'=>99, 'status'=>0, 'username' => $this->container['username'], 'salt' => $salt, 'password' => hst_md5($this->container['password'], $salt) ]); }); if (!is_null($status)) { $this->error(hst_lang('hstcms::install.install.error')); return $this->stepOne(); } else { $this->call('key:generate'); $this->call('vendor:publish', [ '--tag'=>'config' ]); $this->call('vendor:publish', [ '--tag'=>'public' ]); $this->call('hstcms:cache'); // $this->call('migrate', [ // '--force'=>true // ]); File::put(base_path('hstcms.install.lck'), env('APP_KEY')); $this->info('---------Install Success---------'); if($this->container['site_url'] !== 'null') { $this->comment('Home: '.env('APP_URL')); $this->comment('Admin: '.env('APP_URL').'/manage'); } else { $this->comment('Home: http(https)://域名(ip)'); $this->comment('Admin: http(https)://域名(ip)/manage'); } } } return true; }
[ "private", "function", "stepOne", "(", ")", "{", "if", "(", "file_exists", "(", "base_path", "(", "'hstcms.install.lck'", ")", ")", ")", "{", "$", "this", "->", "info", "(", "hst_lang", "(", "'hstcms::install.install.already'", ")", ".", "'HSTCMS'", ".", "config", "(", "'hstcms.version'", ")", ".", "','.h", "s", "t_lang('", "h", "stcms::install.install.one'))", ";", "", "", "return", "true", ";", "}", "if", "(", "!", "$", "this", "->", "files", "->", "isFile", "(", "base_path", "(", "'.env'", ")", ")", ")", "{", "$", "this", "->", "files", "->", "copy", "(", "base_path", "(", "'.env.example'", ")", ",", "base_path", "(", "'.env'", ")", ")", ";", "}", "$", "this", "->", "container", "[", "'lang'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter the site url:'", ",", "env", "(", "'locale'", ",", "'zh-en'", ")", ")", ";", "//检查数据库信息是否配置", "if", "(", "!", "hst_checkEnvIsNull", "(", "'DB_HOST'", ")", "||", "!", "hst_checkEnvIsNull", "(", "'DB_DATABASE'", ")", "||", "!", "hst_checkEnvIsNull", "(", "'DB_USERNAME'", ")", "||", "!", "hst_checkEnvIsNull", "(", "'DB_PASSWORD'", ")", "||", "$", "this", "->", "option", "(", "'d'", ")", "!==", "'null'", ")", "{", "$", "this", "->", "container", "[", "'db_host'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter the db host:'", ",", "'localhost'", ")", ";", "$", "this", "->", "container", "[", "'db_username'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter the db database:'", ",", "'root'", ")", ";", "$", "this", "->", "container", "[", "'db_password'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter the db password:'", ",", "''", ")", ";", "$", "this", "->", "container", "[", "'db_database'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter db database:'", ",", "''", ")", ";", "}", "$", "this", "->", "container", "[", "'site_url'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter the site url:'", ",", "$", "this", "->", "container", "[", "'site_url'", "]", ")", ";", "$", "this", "->", "container", "[", "'username'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter the admin username:'", ",", "'admin'", ")", ";", "$", "this", "->", "container", "[", "'password'", "]", "=", "$", "this", "->", "ask", "(", "'Please enter the admin password:'", ",", "'admin888'", ")", ";", "$", "this", "->", "comment", "(", "'You have provided the following manifest information:'", ")", ";", "if", "(", "!", "hst_checkEnvIsNull", "(", "'DB_HOST'", ")", "||", "!", "hst_checkEnvIsNull", "(", "'DB_DATABASE'", ")", "||", "!", "hst_checkEnvIsNull", "(", "'DB_USERNAME'", ")", "||", "!", "hst_checkEnvIsNull", "(", "'DB_PASSWORD'", ")", "||", "$", "this", "->", "option", "(", "'d'", ")", "!==", "'null'", ")", "{", "$", "this", "->", "comment", "(", "'DbHost: '", ".", "$", "this", "->", "container", "[", "'db_host'", "]", ")", ";", "$", "this", "->", "comment", "(", "'DbUsername: '", ".", "$", "this", "->", "container", "[", "'db_username'", "]", ")", ";", "$", "this", "->", "comment", "(", "'DbPassword: '", ".", "$", "this", "->", "container", "[", "'db_password'", "]", ")", ";", "$", "this", "->", "comment", "(", "'DbDatabase: '", ".", "$", "this", "->", "container", "[", "'db_database'", "]", ")", ";", "}", "$", "this", "->", "comment", "(", "'SiteUrl: '", ".", "$", "this", "->", "container", "[", "'site_url'", "]", ")", ";", "$", "this", "->", "comment", "(", "'Username: '", ".", "$", "this", "->", "container", "[", "'username'", "]", ")", ";", "$", "this", "->", "comment", "(", "'Password: '", ".", "$", "this", "->", "container", "[", "'password'", "]", ")", ";", "Config", "::", "set", "(", "'locale'", ",", "$", "this", "->", "container", "[", "'lang'", "]", ")", ";", "if", "(", "$", "this", "->", "confirm", "(", "'If the provided information is correct, type \"yes\" to generate.'", ")", ")", "{", "$", "envData", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "container", "[", "'db_host'", "]", ")", "&&", "$", "this", "->", "container", "[", "'db_host'", "]", ")", "{", "$", "envData", "=", "[", "'DB_HOST'", "=>", "$", "this", "->", "container", "[", "'db_host'", "]", ",", "'DB_USERNAME'", "=>", "$", "this", "->", "container", "[", "'db_username'", "]", ",", "'DB_PASSWORD'", "=>", "$", "this", "->", "container", "[", "'db_password'", "]", ",", "'DB_DATABASE'", "=>", "$", "this", "->", "container", "[", "'db_database'", "]", ",", "]", ";", "Config", "::", "set", "(", "'database.connections.mysql.host'", ",", "$", "this", "->", "container", "[", "'db_host'", "]", ")", ";", "Config", "::", "set", "(", "'database.connections.mysql.database'", ",", "$", "this", "->", "container", "[", "'db_database'", "]", ")", ";", "Config", "::", "set", "(", "'database.connections.mysql.username'", ",", "$", "this", "->", "container", "[", "'db_username'", "]", ")", ";", "Config", "::", "set", "(", "'database.connections.mysql.password'", ",", "$", "this", "->", "container", "[", "'db_password'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "container", "[", "'db_host'", "]", "=", "env", "(", "'DB_HOST'", ")", ";", "$", "this", "->", "container", "[", "'db_username'", "]", "=", "env", "(", "'DB_USERNAME'", ")", ";", "$", "this", "->", "container", "[", "'db_password'", "]", "=", "env", "(", "'DB_PASSWORD'", ")", ";", "$", "this", "->", "container", "[", "'db_database'", "]", "=", "env", "(", "'DB_DATABASE'", ")", ";", "}", "if", "(", "$", "this", "->", "container", "[", "'site_url'", "]", "!==", "'null'", ")", "{", "$", "envData", "[", "'APP_URL'", "]", "=", "$", "this", "->", "container", "[", "'site_url'", "]", ";", "}", "else", "{", "$", "envData", "[", "'APP_URL'", "]", "=", "''", ";", "}", "hst_updateEnvInfo", "(", "$", "envData", ")", ";", "$", "link", "=", "mysqli_connect", "(", "$", "this", "->", "container", "[", "'db_host'", "]", ",", "$", "this", "->", "container", "[", "'db_username'", "]", ",", "$", "this", "->", "container", "[", "'db_password'", "]", ")", ";", "if", "(", "!", "$", "link", ")", "{", "$", "this", "->", "error", "(", "'Database configuration information error'", ")", ";", "return", "$", "this", "->", "stepOne", "(", ")", ";", "}", "if", "(", "!", "mysqli_select_db", "(", "$", "link", ",", "$", "this", "->", "container", "[", "'db_database'", "]", ")", ")", "{", "$", "sql", "=", "\"CREATE DATABASE `\"", ".", "$", "this", "->", "container", "[", "'db_database'", "]", ".", "\"`\"", ";", "mysqli_query", "(", "$", "link", ",", "$", "sql", ")", "or", "mysqli_error", "(", "$", "link", ")", ";", "}", "if", "(", "$", "this", "->", "option", "(", "'a'", ")", "!==", "'null'", ")", "{", "$", "this", "->", "call", "(", "'migrate'", ",", "[", "'--force'", "=>", "true", "]", ")", ";", "}", "else", "{", "$", "this", "->", "call", "(", "'migrate'", ",", "[", "'--path'", "=>", "'vendor/huasituo/hstcms/src/database/migrations'", ",", "'--force'", "=>", "true", "]", ")", ";", "}", "$", "this", "->", "call", "(", "'hstcms:seed'", ",", "[", "'--force'", "=>", "true", "]", ")", ";", "$", "status", "=", "DB", "::", "transaction", "(", "function", "(", ")", "{", "hst_save_config", "(", "'site'", ",", "[", "[", "'name'", "=>", "'url'", ",", "'value'", "=>", "$", "this", "->", "container", "[", "'site_url'", "]", ",", "'issystem'", "=>", "1", "]", ",", "[", "'name'", "=>", "'debug'", ",", "'value'", "=>", "1", ",", "'issystem'", "=>", "1", "]", "]", ")", ";", "if", "(", "$", "this", "->", "container", "[", "'site_url'", "]", "===", "'null'", ")", "{", "hst_save_config", "(", "'site'", ",", "[", "[", "'name'", "=>", "'url'", ",", "'value'", "=>", "''", ",", "'issystem'", "=>", "1", "]", ",", "[", "'name'", "=>", "'debug'", ",", "'value'", "=>", "1", ",", "'issystem'", "=>", "1", "]", "]", ")", ";", "}", "$", "salt", "=", "hst_random", "(", "6", ")", ";", "ManageUserModel", "::", "insert", "(", "[", "'gid'", "=>", "99", ",", "'status'", "=>", "0", ",", "'username'", "=>", "$", "this", "->", "container", "[", "'username'", "]", ",", "'salt'", "=>", "$", "salt", ",", "'password'", "=>", "hst_md5", "(", "$", "this", "->", "container", "[", "'password'", "]", ",", "$", "salt", ")", "]", ")", ";", "}", ")", ";", "if", "(", "!", "is_null", "(", "$", "status", ")", ")", "{", "$", "this", "->", "error", "(", "hst_lang", "(", "'hstcms::install.install.error'", ")", ")", ";", "return", "$", "this", "->", "stepOne", "(", ")", ";", "}", "else", "{", "$", "this", "->", "call", "(", "'key:generate'", ")", ";", "$", "this", "->", "call", "(", "'vendor:publish'", ",", "[", "'--tag'", "=>", "'config'", "]", ")", ";", "$", "this", "->", "call", "(", "'vendor:publish'", ",", "[", "'--tag'", "=>", "'public'", "]", ")", ";", "$", "this", "->", "call", "(", "'hstcms:cache'", ")", ";", "// $this->call('migrate', [", "// '--force'=>true", "// ]);", "File", "::", "put", "(", "base_path", "(", "'hstcms.install.lck'", ")", ",", "env", "(", "'APP_KEY'", ")", ")", ";", "$", "this", "->", "info", "(", "'---------Install Success---------'", ")", ";", "if", "(", "$", "this", "->", "container", "[", "'site_url'", "]", "!==", "'null'", ")", "{", "$", "this", "->", "comment", "(", "'Home: '", ".", "env", "(", "'APP_URL'", ")", ")", ";", "$", "this", "->", "comment", "(", "'Admin: '", ".", "env", "(", "'APP_URL'", ")", ".", "'/manage'", ")", ";", "}", "else", "{", "$", "this", "->", "comment", "(", "'Home: http(https)://域名(ip)');", "", "", "$", "this", "->", "comment", "(", "'Admin: http(https)://域名(ip)/manage');", "", "", "}", "}", "}", "return", "true", ";", "}" ]
Step 1: Configure module manifest. @return mixed
[ "Step", "1", ":", "Configure", "module", "manifest", "." ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Console/Generators/MakeInstallCommand.php#L86-L215
jkribeiro/composer-hydration
src/Composer/ComposerHydration.php
ComposerHydration.meatOnBones
public static function meatOnBones(Event $event) { $basePath = realpath("."); $handler = new ComposerHydrationHandler($event, $basePath); $handler->hydrate(); }
php
public static function meatOnBones(Event $event) { $basePath = realpath("."); $handler = new ComposerHydrationHandler($event, $basePath); $handler->hydrate(); }
[ "public", "static", "function", "meatOnBones", "(", "Event", "$", "event", ")", "{", "$", "basePath", "=", "realpath", "(", "\".\"", ")", ";", "$", "handler", "=", "new", "ComposerHydrationHandler", "(", "$", "event", ",", "$", "basePath", ")", ";", "$", "handler", "->", "hydrate", "(", ")", ";", "}" ]
Composer callback method for Hydration process. @param object $event Composer Event object.
[ "Composer", "callback", "method", "for", "Hydration", "process", "." ]
train
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydration.php#L24-L30
comelyio/comely
src/Comely/IO/Mailer/Messages/Message.php
Message.compile
public function compile(string $separator = ""): string { // Boundaries $uniqueId = md5(uniqid(sprintf("%s-%s", $this->subject, microtime(false)))); $boundaries[] = "--Comely_B1" . $uniqueId; $boundaries[] = "--Comely_B2" . $uniqueId; $boundaries[] = "--Comely_B3" . $uniqueId; // Headers $headers[] = $this->sender->name ? sprintf('From: %1$s <%2$s>', $this->sender->name, $this->sender->email) : sprintf('From:<%1$s>', $this->sender->email); $headers[] = sprintf('Subject: %1$s', $this->subject); $headers[] = "MIME-Version: 1.0"; $headers[] = sprintf('X-Mailer: Comely %1$s', Comely::VERSION); $headers[] = sprintf('Content-Type: multipart/mixed; boundary="%1$s"', substr($boundaries[0], 2)); foreach ($this->headers as $key => $value) { $headers[] = sprintf('%1$s: %2$s', $key, $value); } $headers[] = $separator; // Separator line between headers and body // Body $body[] = "This is a multi-part message in MIME format."; $body[] = $boundaries[0]; $body[] = sprintf('Content-Type: multipart/alternative; boundary="%1$s"', substr($boundaries[1], 2)); $body[] = ""; // Empty line // Body: text/plain if ($this->body->plain) { $encoding = $this->checkBodyEncoding($this->body->plain); $body[] = $boundaries[1]; $body[] = sprintf('Content-Type: text/plain; charset=%1$s', $encoding[0]); $body[] = sprintf('Content-Transfer-Encoding: %1$s', $encoding[1]); $body[] = ""; // Empty line $body[] = $this->body->plain; } // Body: text/html if ($this->body->html) { $encoding = $this->checkBodyEncoding($this->body->html); $body[] = $boundaries[1]; $body[] = sprintf('Content-Type: text/html; charset=%1$s', $encoding[0]); $body[] = sprintf('Content-Transfer-Encoding: %1$s', $encoding[1]); $body[] = ""; // Empty line $body[] = $this->body->html; } // Attachments foreach ($this->attachments as $attachment) { /** @var $attachment Attachment */ $body[] = $boundaries[0]; $body[] = implode($this->eol, $attachment->mime()); } // Compile $mime = array_merge($headers, $body); return implode($this->eol, $mime); }
php
public function compile(string $separator = ""): string { // Boundaries $uniqueId = md5(uniqid(sprintf("%s-%s", $this->subject, microtime(false)))); $boundaries[] = "--Comely_B1" . $uniqueId; $boundaries[] = "--Comely_B2" . $uniqueId; $boundaries[] = "--Comely_B3" . $uniqueId; // Headers $headers[] = $this->sender->name ? sprintf('From: %1$s <%2$s>', $this->sender->name, $this->sender->email) : sprintf('From:<%1$s>', $this->sender->email); $headers[] = sprintf('Subject: %1$s', $this->subject); $headers[] = "MIME-Version: 1.0"; $headers[] = sprintf('X-Mailer: Comely %1$s', Comely::VERSION); $headers[] = sprintf('Content-Type: multipart/mixed; boundary="%1$s"', substr($boundaries[0], 2)); foreach ($this->headers as $key => $value) { $headers[] = sprintf('%1$s: %2$s', $key, $value); } $headers[] = $separator; // Separator line between headers and body // Body $body[] = "This is a multi-part message in MIME format."; $body[] = $boundaries[0]; $body[] = sprintf('Content-Type: multipart/alternative; boundary="%1$s"', substr($boundaries[1], 2)); $body[] = ""; // Empty line // Body: text/plain if ($this->body->plain) { $encoding = $this->checkBodyEncoding($this->body->plain); $body[] = $boundaries[1]; $body[] = sprintf('Content-Type: text/plain; charset=%1$s', $encoding[0]); $body[] = sprintf('Content-Transfer-Encoding: %1$s', $encoding[1]); $body[] = ""; // Empty line $body[] = $this->body->plain; } // Body: text/html if ($this->body->html) { $encoding = $this->checkBodyEncoding($this->body->html); $body[] = $boundaries[1]; $body[] = sprintf('Content-Type: text/html; charset=%1$s', $encoding[0]); $body[] = sprintf('Content-Transfer-Encoding: %1$s', $encoding[1]); $body[] = ""; // Empty line $body[] = $this->body->html; } // Attachments foreach ($this->attachments as $attachment) { /** @var $attachment Attachment */ $body[] = $boundaries[0]; $body[] = implode($this->eol, $attachment->mime()); } // Compile $mime = array_merge($headers, $body); return implode($this->eol, $mime); }
[ "public", "function", "compile", "(", "string", "$", "separator", "=", "\"\"", ")", ":", "string", "{", "// Boundaries", "$", "uniqueId", "=", "md5", "(", "uniqid", "(", "sprintf", "(", "\"%s-%s\"", ",", "$", "this", "->", "subject", ",", "microtime", "(", "false", ")", ")", ")", ")", ";", "$", "boundaries", "[", "]", "=", "\"--Comely_B1\"", ".", "$", "uniqueId", ";", "$", "boundaries", "[", "]", "=", "\"--Comely_B2\"", ".", "$", "uniqueId", ";", "$", "boundaries", "[", "]", "=", "\"--Comely_B3\"", ".", "$", "uniqueId", ";", "// Headers", "$", "headers", "[", "]", "=", "$", "this", "->", "sender", "->", "name", "?", "sprintf", "(", "'From: %1$s <%2$s>'", ",", "$", "this", "->", "sender", "->", "name", ",", "$", "this", "->", "sender", "->", "email", ")", ":", "sprintf", "(", "'From:<%1$s>'", ",", "$", "this", "->", "sender", "->", "email", ")", ";", "$", "headers", "[", "]", "=", "sprintf", "(", "'Subject: %1$s'", ",", "$", "this", "->", "subject", ")", ";", "$", "headers", "[", "]", "=", "\"MIME-Version: 1.0\"", ";", "$", "headers", "[", "]", "=", "sprintf", "(", "'X-Mailer: Comely %1$s'", ",", "Comely", "::", "VERSION", ")", ";", "$", "headers", "[", "]", "=", "sprintf", "(", "'Content-Type: multipart/mixed; boundary=\"%1$s\"'", ",", "substr", "(", "$", "boundaries", "[", "0", "]", ",", "2", ")", ")", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "headers", "[", "]", "=", "sprintf", "(", "'%1$s: %2$s'", ",", "$", "key", ",", "$", "value", ")", ";", "}", "$", "headers", "[", "]", "=", "$", "separator", ";", "// Separator line between headers and body", "// Body", "$", "body", "[", "]", "=", "\"This is a multi-part message in MIME format.\"", ";", "$", "body", "[", "]", "=", "$", "boundaries", "[", "0", "]", ";", "$", "body", "[", "]", "=", "sprintf", "(", "'Content-Type: multipart/alternative; boundary=\"%1$s\"'", ",", "substr", "(", "$", "boundaries", "[", "1", "]", ",", "2", ")", ")", ";", "$", "body", "[", "]", "=", "\"\"", ";", "// Empty line", "// Body: text/plain", "if", "(", "$", "this", "->", "body", "->", "plain", ")", "{", "$", "encoding", "=", "$", "this", "->", "checkBodyEncoding", "(", "$", "this", "->", "body", "->", "plain", ")", ";", "$", "body", "[", "]", "=", "$", "boundaries", "[", "1", "]", ";", "$", "body", "[", "]", "=", "sprintf", "(", "'Content-Type: text/plain; charset=%1$s'", ",", "$", "encoding", "[", "0", "]", ")", ";", "$", "body", "[", "]", "=", "sprintf", "(", "'Content-Transfer-Encoding: %1$s'", ",", "$", "encoding", "[", "1", "]", ")", ";", "$", "body", "[", "]", "=", "\"\"", ";", "// Empty line", "$", "body", "[", "]", "=", "$", "this", "->", "body", "->", "plain", ";", "}", "// Body: text/html", "if", "(", "$", "this", "->", "body", "->", "html", ")", "{", "$", "encoding", "=", "$", "this", "->", "checkBodyEncoding", "(", "$", "this", "->", "body", "->", "html", ")", ";", "$", "body", "[", "]", "=", "$", "boundaries", "[", "1", "]", ";", "$", "body", "[", "]", "=", "sprintf", "(", "'Content-Type: text/html; charset=%1$s'", ",", "$", "encoding", "[", "0", "]", ")", ";", "$", "body", "[", "]", "=", "sprintf", "(", "'Content-Transfer-Encoding: %1$s'", ",", "$", "encoding", "[", "1", "]", ")", ";", "$", "body", "[", "]", "=", "\"\"", ";", "// Empty line", "$", "body", "[", "]", "=", "$", "this", "->", "body", "->", "html", ";", "}", "// Attachments", "foreach", "(", "$", "this", "->", "attachments", "as", "$", "attachment", ")", "{", "/** @var $attachment Attachment */", "$", "body", "[", "]", "=", "$", "boundaries", "[", "0", "]", ";", "$", "body", "[", "]", "=", "implode", "(", "$", "this", "->", "eol", ",", "$", "attachment", "->", "mime", "(", ")", ")", ";", "}", "// Compile", "$", "mime", "=", "array_merge", "(", "$", "headers", ",", "$", "body", ")", ";", "return", "implode", "(", "$", "this", "->", "eol", ",", "$", "mime", ")", ";", "}" ]
Get compiled email in MIME format @param string $separator @return string
[ "Get", "compiled", "email", "in", "MIME", "format" ]
train
https://github.com/comelyio/comely/blob/561ea7aef36fea347a1a79d3ee5597d4057ddf82/src/Comely/IO/Mailer/Messages/Message.php#L131-L189
crossjoin/Css
src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php
StyleRuleSet.setSelectors
public function setSelectors($selectors) { $this->selectors = []; if (!is_array($selectors)) { $selectors = [$selectors]; } foreach ($selectors as $selector) { $this->addSelector($selector); } return $this; }
php
public function setSelectors($selectors) { $this->selectors = []; if (!is_array($selectors)) { $selectors = [$selectors]; } foreach ($selectors as $selector) { $this->addSelector($selector); } return $this; }
[ "public", "function", "setSelectors", "(", "$", "selectors", ")", "{", "$", "this", "->", "selectors", "=", "[", "]", ";", "if", "(", "!", "is_array", "(", "$", "selectors", ")", ")", "{", "$", "selectors", "=", "[", "$", "selectors", "]", ";", "}", "foreach", "(", "$", "selectors", "as", "$", "selector", ")", "{", "$", "this", "->", "addSelector", "(", "$", "selector", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the selectors for the style rule. @param StyleSelector[]|StyleSelector $selectors @return $this
[ "Sets", "the", "selectors", "for", "the", "style", "rule", "." ]
train
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php#L43-L54
crossjoin/Css
src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php
StyleRuleSet.addDeclaration
public function addDeclaration(DeclarationAbstract $declaration) { if ($declaration instanceof StyleDeclaration) { $this->declarations[] = $declaration; } else { throw new \InvalidArgumentException( "Invalid declaration instance. Instance of 'StyleDeclaration' expected." ); } return $this; }
php
public function addDeclaration(DeclarationAbstract $declaration) { if ($declaration instanceof StyleDeclaration) { $this->declarations[] = $declaration; } else { throw new \InvalidArgumentException( "Invalid declaration instance. Instance of 'StyleDeclaration' expected." ); } return $this; }
[ "public", "function", "addDeclaration", "(", "DeclarationAbstract", "$", "declaration", ")", "{", "if", "(", "$", "declaration", "instanceof", "StyleDeclaration", ")", "{", "$", "this", "->", "declarations", "[", "]", "=", "$", "declaration", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Invalid declaration instance. Instance of 'StyleDeclaration' expected.\"", ")", ";", "}", "return", "$", "this", ";", "}" ]
Adds a declaration to the rule. @param StyleDeclaration $declaration @return $this
[ "Adds", "a", "declaration", "to", "the", "rule", "." ]
train
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php#L85-L96
crossjoin/Css
src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php
StyleRuleSet.parseRuleString
protected function parseRuleString($ruleString) { foreach ($this->getSelectorStrings($ruleString) as $selectorString) { // Check for invalid selector (e.g. if starting with a comma, like in this example from // the spec ",all { body { background:lime } }") if ($selectorString === "") { $this->setIsValid(false); $this->addValidationError("Invalid selector at '$ruleString'."); break; } $this->addSelector(new StyleSelector($selectorString, $this->getStyleSheet())); } }
php
protected function parseRuleString($ruleString) { foreach ($this->getSelectorStrings($ruleString) as $selectorString) { // Check for invalid selector (e.g. if starting with a comma, like in this example from // the spec ",all { body { background:lime } }") if ($selectorString === "") { $this->setIsValid(false); $this->addValidationError("Invalid selector at '$ruleString'."); break; } $this->addSelector(new StyleSelector($selectorString, $this->getStyleSheet())); } }
[ "protected", "function", "parseRuleString", "(", "$", "ruleString", ")", "{", "foreach", "(", "$", "this", "->", "getSelectorStrings", "(", "$", "ruleString", ")", "as", "$", "selectorString", ")", "{", "// Check for invalid selector (e.g. if starting with a comma, like in this example from", "// the spec \",all { body { background:lime } }\")", "if", "(", "$", "selectorString", "===", "\"\"", ")", "{", "$", "this", "->", "setIsValid", "(", "false", ")", ";", "$", "this", "->", "addValidationError", "(", "\"Invalid selector at '$ruleString'.\"", ")", ";", "break", ";", "}", "$", "this", "->", "addSelector", "(", "new", "StyleSelector", "(", "$", "selectorString", ",", "$", "this", "->", "getStyleSheet", "(", ")", ")", ")", ";", "}", "}" ]
Parses the selector rule. @param string $ruleString
[ "Parses", "the", "selector", "rule", "." ]
train
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php#L103-L117
crossjoin/Css
src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php
StyleRuleSet.getSelectorStrings
protected function getSelectorStrings($selectorList) { $charset = $this->getCharset(); $groupsOpened = 0; $ignoreGroupOpenCloseChar = false; $enclosedChar = null; $selectors = []; $subSelectorList = ""; $currentSelectors = [""]; $currentSelectorKeys = [0]; $lastChar = null; if (preg_match('/[^\x00-\x7f]/', $selectorList)) { $isAscii = false; $strLen = mb_strlen($selectorList, $charset); } else { $isAscii = true; $strLen = strlen($selectorList); } for ($i = 0, $j = $strLen; $i < $j; $i++) { if ($isAscii === true) { $char = $selectorList[$i]; } else { $char = mb_substr($selectorList, $i, 1, $charset); } if ($char === "(") { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { if ($ignoreGroupOpenCloseChar === false) { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } } $groupsOpened++; } else if ($char === ")") { $groupsOpened--; if ($groupsOpened > 0) { $subSelectorList .= $char; } else { if ($subSelectorList != "") { $subSelectors = $this->getSelectorStrings($subSelectorList); $newSelectors = []; foreach ($subSelectors as $subSelector) { foreach ($currentSelectors as $currentSelector) { $concat = $lastChar === "(" ? "" : " "; $newSelectors[] = $currentSelector . $concat . $subSelector; } } $currentSelectors = $newSelectors; $currentSelectorKeys = array_keys($currentSelectors); } if ($ignoreGroupOpenCloseChar === false) { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } else { $ignoreGroupOpenCloseChar = false; } $subSelectorList = ""; } } else if ($char === ",") { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { foreach ($currentSelectors as $currentSelector) { $selectors[] = trim($currentSelector, " \r\n\t\f"); } $currentSelectors = [""]; $currentSelectorKeys = [0]; } } else if ($char === ":") { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { if ($isAscii === true) { $nextChars = substr($selectorList, $i); } else { $nextChars = mb_substr($selectorList, $i, null, $charset); } $nextChars = strtolower(preg_replace('/^(\:[-a-z]+)[^-a-z]*.*/', '\\1', $nextChars)); if ($nextChars === ":matches") { $i += (9 - 2); $ignoreGroupOpenCloseChar = true; } elseif ($nextChars === ":has") { $i += (5 - 2); $ignoreGroupOpenCloseChar = true; } else { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } } } else { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } } // Save last char (to avoid costly mb_substr() call) $lastChar = $char; } foreach ($currentSelectors as $currentSelector) { $selectors[] = trim($currentSelector, " \r\n\t\f"); } return $selectors; }
php
protected function getSelectorStrings($selectorList) { $charset = $this->getCharset(); $groupsOpened = 0; $ignoreGroupOpenCloseChar = false; $enclosedChar = null; $selectors = []; $subSelectorList = ""; $currentSelectors = [""]; $currentSelectorKeys = [0]; $lastChar = null; if (preg_match('/[^\x00-\x7f]/', $selectorList)) { $isAscii = false; $strLen = mb_strlen($selectorList, $charset); } else { $isAscii = true; $strLen = strlen($selectorList); } for ($i = 0, $j = $strLen; $i < $j; $i++) { if ($isAscii === true) { $char = $selectorList[$i]; } else { $char = mb_substr($selectorList, $i, 1, $charset); } if ($char === "(") { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { if ($ignoreGroupOpenCloseChar === false) { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } } $groupsOpened++; } else if ($char === ")") { $groupsOpened--; if ($groupsOpened > 0) { $subSelectorList .= $char; } else { if ($subSelectorList != "") { $subSelectors = $this->getSelectorStrings($subSelectorList); $newSelectors = []; foreach ($subSelectors as $subSelector) { foreach ($currentSelectors as $currentSelector) { $concat = $lastChar === "(" ? "" : " "; $newSelectors[] = $currentSelector . $concat . $subSelector; } } $currentSelectors = $newSelectors; $currentSelectorKeys = array_keys($currentSelectors); } if ($ignoreGroupOpenCloseChar === false) { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } else { $ignoreGroupOpenCloseChar = false; } $subSelectorList = ""; } } else if ($char === ",") { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { foreach ($currentSelectors as $currentSelector) { $selectors[] = trim($currentSelector, " \r\n\t\f"); } $currentSelectors = [""]; $currentSelectorKeys = [0]; } } else if ($char === ":") { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { if ($isAscii === true) { $nextChars = substr($selectorList, $i); } else { $nextChars = mb_substr($selectorList, $i, null, $charset); } $nextChars = strtolower(preg_replace('/^(\:[-a-z]+)[^-a-z]*.*/', '\\1', $nextChars)); if ($nextChars === ":matches") { $i += (9 - 2); $ignoreGroupOpenCloseChar = true; } elseif ($nextChars === ":has") { $i += (5 - 2); $ignoreGroupOpenCloseChar = true; } else { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } } } else { if ($groupsOpened > 0) { $subSelectorList .= $char; } else { foreach ($currentSelectorKeys as $index) { $currentSelectors[$index] .= $char; } } } // Save last char (to avoid costly mb_substr() call) $lastChar = $char; } foreach ($currentSelectors as $currentSelector) { $selectors[] = trim($currentSelector, " \r\n\t\f"); } return $selectors; }
[ "protected", "function", "getSelectorStrings", "(", "$", "selectorList", ")", "{", "$", "charset", "=", "$", "this", "->", "getCharset", "(", ")", ";", "$", "groupsOpened", "=", "0", ";", "$", "ignoreGroupOpenCloseChar", "=", "false", ";", "$", "enclosedChar", "=", "null", ";", "$", "selectors", "=", "[", "]", ";", "$", "subSelectorList", "=", "\"\"", ";", "$", "currentSelectors", "=", "[", "\"\"", "]", ";", "$", "currentSelectorKeys", "=", "[", "0", "]", ";", "$", "lastChar", "=", "null", ";", "if", "(", "preg_match", "(", "'/[^\\x00-\\x7f]/'", ",", "$", "selectorList", ")", ")", "{", "$", "isAscii", "=", "false", ";", "$", "strLen", "=", "mb_strlen", "(", "$", "selectorList", ",", "$", "charset", ")", ";", "}", "else", "{", "$", "isAscii", "=", "true", ";", "$", "strLen", "=", "strlen", "(", "$", "selectorList", ")", ";", "}", "for", "(", "$", "i", "=", "0", ",", "$", "j", "=", "$", "strLen", ";", "$", "i", "<", "$", "j", ";", "$", "i", "++", ")", "{", "if", "(", "$", "isAscii", "===", "true", ")", "{", "$", "char", "=", "$", "selectorList", "[", "$", "i", "]", ";", "}", "else", "{", "$", "char", "=", "mb_substr", "(", "$", "selectorList", ",", "$", "i", ",", "1", ",", "$", "charset", ")", ";", "}", "if", "(", "$", "char", "===", "\"(\"", ")", "{", "if", "(", "$", "groupsOpened", ">", "0", ")", "{", "$", "subSelectorList", ".=", "$", "char", ";", "}", "else", "{", "if", "(", "$", "ignoreGroupOpenCloseChar", "===", "false", ")", "{", "foreach", "(", "$", "currentSelectorKeys", "as", "$", "index", ")", "{", "$", "currentSelectors", "[", "$", "index", "]", ".=", "$", "char", ";", "}", "}", "}", "$", "groupsOpened", "++", ";", "}", "else", "if", "(", "$", "char", "===", "\")\"", ")", "{", "$", "groupsOpened", "--", ";", "if", "(", "$", "groupsOpened", ">", "0", ")", "{", "$", "subSelectorList", ".=", "$", "char", ";", "}", "else", "{", "if", "(", "$", "subSelectorList", "!=", "\"\"", ")", "{", "$", "subSelectors", "=", "$", "this", "->", "getSelectorStrings", "(", "$", "subSelectorList", ")", ";", "$", "newSelectors", "=", "[", "]", ";", "foreach", "(", "$", "subSelectors", "as", "$", "subSelector", ")", "{", "foreach", "(", "$", "currentSelectors", "as", "$", "currentSelector", ")", "{", "$", "concat", "=", "$", "lastChar", "===", "\"(\"", "?", "\"\"", ":", "\" \"", ";", "$", "newSelectors", "[", "]", "=", "$", "currentSelector", ".", "$", "concat", ".", "$", "subSelector", ";", "}", "}", "$", "currentSelectors", "=", "$", "newSelectors", ";", "$", "currentSelectorKeys", "=", "array_keys", "(", "$", "currentSelectors", ")", ";", "}", "if", "(", "$", "ignoreGroupOpenCloseChar", "===", "false", ")", "{", "foreach", "(", "$", "currentSelectorKeys", "as", "$", "index", ")", "{", "$", "currentSelectors", "[", "$", "index", "]", ".=", "$", "char", ";", "}", "}", "else", "{", "$", "ignoreGroupOpenCloseChar", "=", "false", ";", "}", "$", "subSelectorList", "=", "\"\"", ";", "}", "}", "else", "if", "(", "$", "char", "===", "\",\"", ")", "{", "if", "(", "$", "groupsOpened", ">", "0", ")", "{", "$", "subSelectorList", ".=", "$", "char", ";", "}", "else", "{", "foreach", "(", "$", "currentSelectors", "as", "$", "currentSelector", ")", "{", "$", "selectors", "[", "]", "=", "trim", "(", "$", "currentSelector", ",", "\" \\r\\n\\t\\f\"", ")", ";", "}", "$", "currentSelectors", "=", "[", "\"\"", "]", ";", "$", "currentSelectorKeys", "=", "[", "0", "]", ";", "}", "}", "else", "if", "(", "$", "char", "===", "\":\"", ")", "{", "if", "(", "$", "groupsOpened", ">", "0", ")", "{", "$", "subSelectorList", ".=", "$", "char", ";", "}", "else", "{", "if", "(", "$", "isAscii", "===", "true", ")", "{", "$", "nextChars", "=", "substr", "(", "$", "selectorList", ",", "$", "i", ")", ";", "}", "else", "{", "$", "nextChars", "=", "mb_substr", "(", "$", "selectorList", ",", "$", "i", ",", "null", ",", "$", "charset", ")", ";", "}", "$", "nextChars", "=", "strtolower", "(", "preg_replace", "(", "'/^(\\:[-a-z]+)[^-a-z]*.*/'", ",", "'\\\\1'", ",", "$", "nextChars", ")", ")", ";", "if", "(", "$", "nextChars", "===", "\":matches\"", ")", "{", "$", "i", "+=", "(", "9", "-", "2", ")", ";", "$", "ignoreGroupOpenCloseChar", "=", "true", ";", "}", "elseif", "(", "$", "nextChars", "===", "\":has\"", ")", "{", "$", "i", "+=", "(", "5", "-", "2", ")", ";", "$", "ignoreGroupOpenCloseChar", "=", "true", ";", "}", "else", "{", "foreach", "(", "$", "currentSelectorKeys", "as", "$", "index", ")", "{", "$", "currentSelectors", "[", "$", "index", "]", ".=", "$", "char", ";", "}", "}", "}", "}", "else", "{", "if", "(", "$", "groupsOpened", ">", "0", ")", "{", "$", "subSelectorList", ".=", "$", "char", ";", "}", "else", "{", "foreach", "(", "$", "currentSelectorKeys", "as", "$", "index", ")", "{", "$", "currentSelectors", "[", "$", "index", "]", ".=", "$", "char", ";", "}", "}", "}", "// Save last char (to avoid costly mb_substr() call)", "$", "lastChar", "=", "$", "char", ";", "}", "foreach", "(", "$", "currentSelectors", "as", "$", "currentSelector", ")", "{", "$", "selectors", "[", "]", "=", "trim", "(", "$", "currentSelector", ",", "\" \\r\\n\\t\\f\"", ")", ";", "}", "return", "$", "selectors", ";", "}" ]
Helper method to parse the style rule. @param string $selectorList @return array
[ "Helper", "method", "to", "parse", "the", "style", "rule", "." ]
train
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/Style/StyleRuleSet.php#L125-L243
movoin/one-swoole
src/Event/OnceListener.php
OnceListener.handle
public function handle(Event $event) { $name = $event->getName(); $emitter = $event->getEmitter(); $emitter->removeListener($name, $this); unset($name, $emitter); call_user_func_array($this->handler, [$event]); }
php
public function handle(Event $event) { $name = $event->getName(); $emitter = $event->getEmitter(); $emitter->removeListener($name, $this); unset($name, $emitter); call_user_func_array($this->handler, [$event]); }
[ "public", "function", "handle", "(", "Event", "$", "event", ")", "{", "$", "name", "=", "$", "event", "->", "getName", "(", ")", ";", "$", "emitter", "=", "$", "event", "->", "getEmitter", "(", ")", ";", "$", "emitter", "->", "removeListener", "(", "$", "name", ",", "$", "this", ")", ";", "unset", "(", "$", "name", ",", "$", "emitter", ")", ";", "call_user_func_array", "(", "$", "this", "->", "handler", ",", "[", "$", "event", "]", ")", ";", "}" ]
处理事件 @param \One\Event\Event $event
[ "处理事件" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Event/OnceListener.php#L24-L33
movoin/one-swoole
src/Event/OnceListener.php
OnceListener.isListener
public function isListener($listener): bool { if (Assert::instanceOf($listener, '\\One\\Event\\OnceListener')) { $listener = $listener->getHandler(); } return $this->handler === $listener; }
php
public function isListener($listener): bool { if (Assert::instanceOf($listener, '\\One\\Event\\OnceListener')) { $listener = $listener->getHandler(); } return $this->handler === $listener; }
[ "public", "function", "isListener", "(", "$", "listener", ")", ":", "bool", "{", "if", "(", "Assert", "::", "instanceOf", "(", "$", "listener", ",", "'\\\\One\\\\Event\\\\OnceListener'", ")", ")", "{", "$", "listener", "=", "$", "listener", "->", "getHandler", "(", ")", ";", "}", "return", "$", "this", "->", "handler", "===", "$", "listener", ";", "}" ]
判断是否是自己 @param mixed $listener @return bool
[ "判断是否是自己" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Event/OnceListener.php#L42-L49
nick-jones/globby
lib/Globby/Builder/Regex.php
Regex.createFromTokens
public function createFromTokens(array $tokens) { $buffer = $this->delimiter . '^'; foreach ($tokens as $token) { $buffer .= $this->translateToken($token); } $buffer .= '$' . $this->delimiter . $this->modifiers; return $buffer; }
php
public function createFromTokens(array $tokens) { $buffer = $this->delimiter . '^'; foreach ($tokens as $token) { $buffer .= $this->translateToken($token); } $buffer .= '$' . $this->delimiter . $this->modifiers; return $buffer; }
[ "public", "function", "createFromTokens", "(", "array", "$", "tokens", ")", "{", "$", "buffer", "=", "$", "this", "->", "delimiter", ".", "'^'", ";", "foreach", "(", "$", "tokens", "as", "$", "token", ")", "{", "$", "buffer", ".=", "$", "this", "->", "translateToken", "(", "$", "token", ")", ";", "}", "$", "buffer", ".=", "'$'", ".", "$", "this", "->", "delimiter", ".", "$", "this", "->", "modifiers", ";", "return", "$", "buffer", ";", "}" ]
Creates a regular expression based on the supplied tokens. This return expression will be wrapped by the value of the 'delimiter' property, and the modifiers contained within the 'modifiers' property will be appended to the end. @param array $tokens @return string
[ "Creates", "a", "regular", "expression", "based", "on", "the", "supplied", "tokens", ".", "This", "return", "expression", "will", "be", "wrapped", "by", "the", "value", "of", "the", "delimiter", "property", "and", "the", "modifiers", "contained", "within", "the", "modifiers", "property", "will", "be", "appended", "to", "the", "end", "." ]
train
https://github.com/nick-jones/globby/blob/5bfc56fbeb0ff84d71f7144c10cc9215a34d9ea4/lib/Globby/Builder/Regex.php#L79-L90
nick-jones/globby
lib/Globby/Builder/Regex.php
Regex.translateToken
protected function translateToken(array $token) { $identifier = is_string($token[0]) ? null : $token[0]; $value = $token[2]; $result = $this->translateTokenFromIdentifier($identifier, $value); if ($result === null) { throw new BuildException(sprintf('No available translation for "%s"', $value)); } return $result; }
php
protected function translateToken(array $token) { $identifier = is_string($token[0]) ? null : $token[0]; $value = $token[2]; $result = $this->translateTokenFromIdentifier($identifier, $value); if ($result === null) { throw new BuildException(sprintf('No available translation for "%s"', $value)); } return $result; }
[ "protected", "function", "translateToken", "(", "array", "$", "token", ")", "{", "$", "identifier", "=", "is_string", "(", "$", "token", "[", "0", "]", ")", "?", "null", ":", "$", "token", "[", "0", "]", ";", "$", "value", "=", "$", "token", "[", "2", "]", ";", "$", "result", "=", "$", "this", "->", "translateTokenFromIdentifier", "(", "$", "identifier", ",", "$", "value", ")", ";", "if", "(", "$", "result", "===", "null", ")", "{", "throw", "new", "BuildException", "(", "sprintf", "(", "'No available translation for \"%s\"'", ",", "$", "value", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Translates a token into an appropriate regular expression construct. Various map directly to the same values; others require some massaging and escaping to make them valid within the constructed in the regular expression. @param array $token @return string @throws BuildException
[ "Translates", "a", "token", "into", "an", "appropriate", "regular", "expression", "construct", ".", "Various", "map", "directly", "to", "the", "same", "values", ";", "others", "require", "some", "massaging", "and", "escaping", "to", "make", "them", "valid", "within", "the", "constructed", "in", "the", "regular", "expression", "." ]
train
https://github.com/nick-jones/globby/blob/5bfc56fbeb0ff84d71f7144c10cc9215a34d9ea4/lib/Globby/Builder/Regex.php#L100-L112
nick-jones/globby
lib/Globby/Builder/Regex.php
Regex.translateTokenFromIdentifier
protected function translateTokenFromIdentifier($identifier, $value) { $result = null; if (array_key_exists($identifier, self::$tokenValueMap)) { $result = $this->translateTokenUsingMap($identifier); } elseif (array_key_exists($identifier, self::$tokenCallbackMap)) { $result = $this->translateTokenUsingCallback($identifier, $value); } return $result; }
php
protected function translateTokenFromIdentifier($identifier, $value) { $result = null; if (array_key_exists($identifier, self::$tokenValueMap)) { $result = $this->translateTokenUsingMap($identifier); } elseif (array_key_exists($identifier, self::$tokenCallbackMap)) { $result = $this->translateTokenUsingCallback($identifier, $value); } return $result; }
[ "protected", "function", "translateTokenFromIdentifier", "(", "$", "identifier", ",", "$", "value", ")", "{", "$", "result", "=", "null", ";", "if", "(", "array_key_exists", "(", "$", "identifier", ",", "self", "::", "$", "tokenValueMap", ")", ")", "{", "$", "result", "=", "$", "this", "->", "translateTokenUsingMap", "(", "$", "identifier", ")", ";", "}", "elseif", "(", "array_key_exists", "(", "$", "identifier", ",", "self", "::", "$", "tokenCallbackMap", ")", ")", "{", "$", "result", "=", "$", "this", "->", "translateTokenUsingCallback", "(", "$", "identifier", ",", "$", "value", ")", ";", "}", "return", "$", "result", ";", "}" ]
Translates a token based on the identifier flavour. @param int $identifier @param string $value @return string|null
[ "Translates", "a", "token", "based", "on", "the", "identifier", "flavour", "." ]
train
https://github.com/nick-jones/globby/blob/5bfc56fbeb0ff84d71f7144c10cc9215a34d9ea4/lib/Globby/Builder/Regex.php#L121-L132
nick-jones/globby
lib/Globby/Builder/Regex.php
Regex.translateTokenUsingCallback
protected function translateTokenUsingCallback($identifier, $value) { $method = self::$tokenCallbackMap[$identifier]; return call_user_func( [$this, $method], $value ); }
php
protected function translateTokenUsingCallback($identifier, $value) { $method = self::$tokenCallbackMap[$identifier]; return call_user_func( [$this, $method], $value ); }
[ "protected", "function", "translateTokenUsingCallback", "(", "$", "identifier", ",", "$", "value", ")", "{", "$", "method", "=", "self", "::", "$", "tokenCallbackMap", "[", "$", "identifier", "]", ";", "return", "call_user_func", "(", "[", "$", "this", ",", "$", "method", "]", ",", "$", "value", ")", ";", "}" ]
Calls an internal method to retrieve an appropriate value for use within the regex. @param int $identifier @param string $value @return string
[ "Calls", "an", "internal", "method", "to", "retrieve", "an", "appropriate", "value", "for", "use", "within", "the", "regex", "." ]
train
https://github.com/nick-jones/globby/blob/5bfc56fbeb0ff84d71f7144c10cc9215a34d9ea4/lib/Globby/Builder/Regex.php#L152-L160
iter8-au/builder
src/Builder/Builders/SpoutBuilder.php
SpoutBuilder.setActiveSheetIndex
public function setActiveSheetIndex(int $sheetIndex = 1) { $sheets = $this->writer->getSheets(); if (!isset($sheets[$sheetIndex])) { throw new SheetNotFoundException( sprintf( 'The given sheet "%d" does not exist in the workbook.', $sheetIndex ) ); } $this->writer->setCurrentSheet($sheets[$sheetIndex]); return $this; }
php
public function setActiveSheetIndex(int $sheetIndex = 1) { $sheets = $this->writer->getSheets(); if (!isset($sheets[$sheetIndex])) { throw new SheetNotFoundException( sprintf( 'The given sheet "%d" does not exist in the workbook.', $sheetIndex ) ); } $this->writer->setCurrentSheet($sheets[$sheetIndex]); return $this; }
[ "public", "function", "setActiveSheetIndex", "(", "int", "$", "sheetIndex", "=", "1", ")", "{", "$", "sheets", "=", "$", "this", "->", "writer", "->", "getSheets", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "sheets", "[", "$", "sheetIndex", "]", ")", ")", "{", "throw", "new", "SheetNotFoundException", "(", "sprintf", "(", "'The given sheet \"%d\" does not exist in the workbook.'", ",", "$", "sheetIndex", ")", ")", ";", "}", "$", "this", "->", "writer", "->", "setCurrentSheet", "(", "$", "sheets", "[", "$", "sheetIndex", "]", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builders/SpoutBuilder.php#L107-L123
iter8-au/builder
src/Builder/Builders/SpoutBuilder.php
SpoutBuilder.setSheetTitle
public function setSheetTitle(string $title) { if ($this->isNotInitialised()) { $this->initialise(); } $this->writer->getCurrentSheet()->setName($title); return $this; }
php
public function setSheetTitle(string $title) { if ($this->isNotInitialised()) { $this->initialise(); } $this->writer->getCurrentSheet()->setName($title); return $this; }
[ "public", "function", "setSheetTitle", "(", "string", "$", "title", ")", "{", "if", "(", "$", "this", "->", "isNotInitialised", "(", ")", ")", "{", "$", "this", "->", "initialise", "(", ")", ";", "}", "$", "this", "->", "writer", "->", "getCurrentSheet", "(", ")", "->", "setName", "(", "$", "title", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builders/SpoutBuilder.php#L128-L137
iter8-au/builder
src/Builder/Builders/SpoutBuilder.php
SpoutBuilder.buildRowStyle
public function buildRowStyle(array $style) { $finalStyle = new StyleBuilder(); // Spout doesn't offer support for changing column alignment. if (array_key_exists('font', $style)) { if (array_key_exists('color', $style['font'])) { $finalStyle->setFontColor( Color::toARGB($style['font']['color']['rgb']) ); } if (array_key_exists('bold', $style['font']) && ($style['font']['bold'] === true)) { $finalStyle->setFontBold(); } } return $finalStyle->build(); }
php
public function buildRowStyle(array $style) { $finalStyle = new StyleBuilder(); // Spout doesn't offer support for changing column alignment. if (array_key_exists('font', $style)) { if (array_key_exists('color', $style['font'])) { $finalStyle->setFontColor( Color::toARGB($style['font']['color']['rgb']) ); } if (array_key_exists('bold', $style['font']) && ($style['font']['bold'] === true)) { $finalStyle->setFontBold(); } } return $finalStyle->build(); }
[ "public", "function", "buildRowStyle", "(", "array", "$", "style", ")", "{", "$", "finalStyle", "=", "new", "StyleBuilder", "(", ")", ";", "// Spout doesn't offer support for changing column alignment.", "if", "(", "array_key_exists", "(", "'font'", ",", "$", "style", ")", ")", "{", "if", "(", "array_key_exists", "(", "'color'", ",", "$", "style", "[", "'font'", "]", ")", ")", "{", "$", "finalStyle", "->", "setFontColor", "(", "Color", "::", "toARGB", "(", "$", "style", "[", "'font'", "]", "[", "'color'", "]", "[", "'rgb'", "]", ")", ")", ";", "}", "if", "(", "array_key_exists", "(", "'bold'", ",", "$", "style", "[", "'font'", "]", ")", "&&", "(", "$", "style", "[", "'font'", "]", "[", "'bold'", "]", "===", "true", ")", ")", "{", "$", "finalStyle", "->", "setFontBold", "(", ")", ";", "}", "}", "return", "$", "finalStyle", "->", "build", "(", ")", ";", "}" ]
@param array $style @return Style
[ "@param", "array", "$style" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builders/SpoutBuilder.php#L152-L171
iter8-au/builder
src/Builder/Builders/SpoutBuilder.php
SpoutBuilder.buildHeaderRow
public function buildHeaderRow( array $columns, $style = null ): void { if ($this->isNotInitialised()) { $this->initialise(); } if ($style instanceof Style) { $this->writer->addRowWithStyle($columns, $style); } else { $this->writer->addRow($columns); } return; }
php
public function buildHeaderRow( array $columns, $style = null ): void { if ($this->isNotInitialised()) { $this->initialise(); } if ($style instanceof Style) { $this->writer->addRowWithStyle($columns, $style); } else { $this->writer->addRow($columns); } return; }
[ "public", "function", "buildHeaderRow", "(", "array", "$", "columns", ",", "$", "style", "=", "null", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isNotInitialised", "(", ")", ")", "{", "$", "this", "->", "initialise", "(", ")", ";", "}", "if", "(", "$", "style", "instanceof", "Style", ")", "{", "$", "this", "->", "writer", "->", "addRowWithStyle", "(", "$", "columns", ",", "$", "style", ")", ";", "}", "else", "{", "$", "this", "->", "writer", "->", "addRow", "(", "$", "columns", ")", ";", "}", "return", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builders/SpoutBuilder.php#L176-L191
iter8-au/builder
src/Builder/Builders/SpoutBuilder.php
SpoutBuilder.buildRow
public function buildRow( array $row, $style = null, $rowIndex = 1 ): void { if ($this->isNotInitialised()) { $this->initialise(); } if ($style instanceof Style) { $this->writer->addRowWithStyle($row, $style); } else { $this->writer->addRow($row); } return; }
php
public function buildRow( array $row, $style = null, $rowIndex = 1 ): void { if ($this->isNotInitialised()) { $this->initialise(); } if ($style instanceof Style) { $this->writer->addRowWithStyle($row, $style); } else { $this->writer->addRow($row); } return; }
[ "public", "function", "buildRow", "(", "array", "$", "row", ",", "$", "style", "=", "null", ",", "$", "rowIndex", "=", "1", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isNotInitialised", "(", ")", ")", "{", "$", "this", "->", "initialise", "(", ")", ";", "}", "if", "(", "$", "style", "instanceof", "Style", ")", "{", "$", "this", "->", "writer", "->", "addRowWithStyle", "(", "$", "row", ",", "$", "style", ")", ";", "}", "else", "{", "$", "this", "->", "writer", "->", "addRow", "(", "$", "row", ")", ";", "}", "return", ";", "}" ]
{@inheritdoc} Spout does not require the $rowIndex parameter.
[ "{", "@inheritdoc", "}" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builders/SpoutBuilder.php#L198-L214
iter8-au/builder
src/Builder/Builders/SpoutBuilder.php
SpoutBuilder.buildRows
public function buildRows( array $rows, $style = null ): void { if ($this->isNotInitialised()) { $this->initialise(); } if ($style instanceof Style) { $this->writer->addRowsWithStyle($rows, $style); } else { $this->writer->addRows($rows); } return; }
php
public function buildRows( array $rows, $style = null ): void { if ($this->isNotInitialised()) { $this->initialise(); } if ($style instanceof Style) { $this->writer->addRowsWithStyle($rows, $style); } else { $this->writer->addRows($rows); } return; }
[ "public", "function", "buildRows", "(", "array", "$", "rows", ",", "$", "style", "=", "null", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isNotInitialised", "(", ")", ")", "{", "$", "this", "->", "initialise", "(", ")", ";", "}", "if", "(", "$", "style", "instanceof", "Style", ")", "{", "$", "this", "->", "writer", "->", "addRowsWithStyle", "(", "$", "rows", ",", "$", "style", ")", ";", "}", "else", "{", "$", "this", "->", "writer", "->", "addRows", "(", "$", "rows", ")", ";", "}", "return", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builders/SpoutBuilder.php#L219-L234
alexpts/psr15-middlewares
src/ErrorToJsonResponse.php
ErrorToJsonResponse.closeOutputBuffers
protected function closeOutputBuffers(int $targetLevel = 0, bool $flush = false): void { $status = ob_get_status(true); $level = \count($status); while ($level-- > $targetLevel) { $flush ? ob_end_flush() : ob_end_clean(); } }
php
protected function closeOutputBuffers(int $targetLevel = 0, bool $flush = false): void { $status = ob_get_status(true); $level = \count($status); while ($level-- > $targetLevel) { $flush ? ob_end_flush() : ob_end_clean(); } }
[ "protected", "function", "closeOutputBuffers", "(", "int", "$", "targetLevel", "=", "0", ",", "bool", "$", "flush", "=", "false", ")", ":", "void", "{", "$", "status", "=", "ob_get_status", "(", "true", ")", ";", "$", "level", "=", "\\", "count", "(", "$", "status", ")", ";", "while", "(", "$", "level", "--", ">", "$", "targetLevel", ")", "{", "$", "flush", "?", "ob_end_flush", "(", ")", ":", "ob_end_clean", "(", ")", ";", "}", "}" ]
Cleans or flushes output buffers up to target level. Resulting level can be greater than target level if a non-removable buffer has been encountered. @param int $targetLevel @param bool $flush @see original Symfony Response::closeOutputBuffers
[ "Cleans", "or", "flushes", "output", "buffers", "up", "to", "target", "level", ".", "Resulting", "level", "can", "be", "greater", "than", "target", "level", "if", "a", "non", "-", "removable", "buffer", "has", "been", "encountered", "." ]
train
https://github.com/alexpts/psr15-middlewares/blob/bff2887d5af01c54d9288fd19c20f0f593b69358/src/ErrorToJsonResponse.php#L85-L93
withfatpanda/illuminate-wordpress
src/Support/Exceptions/Handler.php
Handler.report
public function report(Exception $e) { if ($this->shouldntReport($e)) { return; } try { if ($this->plugin->bound('bugsnag.multi')) { $logger = $this->plugin->make('bugsnag.multi'); } else { $logger = $this->plugin->make('Psr\Log\LoggerInterface'); } $logger->error($e); } catch (Exception $ex) { throw $e; // throw the original exception } finally { $this->renderException($e); } }
php
public function report(Exception $e) { if ($this->shouldntReport($e)) { return; } try { if ($this->plugin->bound('bugsnag.multi')) { $logger = $this->plugin->make('bugsnag.multi'); } else { $logger = $this->plugin->make('Psr\Log\LoggerInterface'); } $logger->error($e); } catch (Exception $ex) { throw $e; // throw the original exception } finally { $this->renderException($e); } }
[ "public", "function", "report", "(", "Exception", "$", "e", ")", "{", "if", "(", "$", "this", "->", "shouldntReport", "(", "$", "e", ")", ")", "{", "return", ";", "}", "try", "{", "if", "(", "$", "this", "->", "plugin", "->", "bound", "(", "'bugsnag.multi'", ")", ")", "{", "$", "logger", "=", "$", "this", "->", "plugin", "->", "make", "(", "'bugsnag.multi'", ")", ";", "}", "else", "{", "$", "logger", "=", "$", "this", "->", "plugin", "->", "make", "(", "'Psr\\Log\\LoggerInterface'", ")", ";", "}", "$", "logger", "->", "error", "(", "$", "e", ")", ";", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "throw", "$", "e", ";", "// throw the original exception", "}", "finally", "{", "$", "this", "->", "renderException", "(", "$", "e", ")", ";", "}", "}" ]
Report or log an exception. This is a great spot to send exceptions to Sentry, Bugsnag, etc. @param \Exception $e @return void
[ "Report", "or", "log", "an", "exception", "." ]
train
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/Support/Exceptions/Handler.php#L53-L72
drunomics/service-utils
src/Core/Render/RendererTrait.php
RendererTrait.getrenderer
public function getrenderer() { if (empty($this->renderer)) { $this->renderer = \Drupal::service('renderer'); } return $this->renderer; }
php
public function getrenderer() { if (empty($this->renderer)) { $this->renderer = \Drupal::service('renderer'); } return $this->renderer; }
[ "public", "function", "getrenderer", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "renderer", ")", ")", "{", "$", "this", "->", "renderer", "=", "\\", "Drupal", "::", "service", "(", "'renderer'", ")", ";", "}", "return", "$", "this", "->", "renderer", ";", "}" ]
Gets the renderer. @return \Drupal\Core\Render\RendererInterface The renderer.
[ "Gets", "the", "renderer", "." ]
train
https://github.com/drunomics/service-utils/blob/56761750043132365ef4ae5d9e0cf4263459328f/src/Core/Render/RendererTrait.php#L38-L43
verschoof/bunq-api
src/Token/Storage/FileTokenStorage.php
FileTokenStorage.loadToken
private function loadToken(TokenType $type) { // take from cache, filesystems are slow if (isset($this->cache[$type->toString()])) { return $this->cache[$type->toString()]; } $token = trim(file_get_contents($this->path . '/' . $type->toString())); if (!$token) { throw new TokenNotFoundException($type, $this->path); } // save the result in the cache $this->cache[$type->toString()] = $token; return $token; }
php
private function loadToken(TokenType $type) { // take from cache, filesystems are slow if (isset($this->cache[$type->toString()])) { return $this->cache[$type->toString()]; } $token = trim(file_get_contents($this->path . '/' . $type->toString())); if (!$token) { throw new TokenNotFoundException($type, $this->path); } // save the result in the cache $this->cache[$type->toString()] = $token; return $token; }
[ "private", "function", "loadToken", "(", "TokenType", "$", "type", ")", "{", "// take from cache, filesystems are slow", "if", "(", "isset", "(", "$", "this", "->", "cache", "[", "$", "type", "->", "toString", "(", ")", "]", ")", ")", "{", "return", "$", "this", "->", "cache", "[", "$", "type", "->", "toString", "(", ")", "]", ";", "}", "$", "token", "=", "trim", "(", "file_get_contents", "(", "$", "this", "->", "path", ".", "'/'", ".", "$", "type", "->", "toString", "(", ")", ")", ")", ";", "if", "(", "!", "$", "token", ")", "{", "throw", "new", "TokenNotFoundException", "(", "$", "type", ",", "$", "this", "->", "path", ")", ";", "}", "// save the result in the cache", "$", "this", "->", "cache", "[", "$", "type", "->", "toString", "(", ")", "]", "=", "$", "token", ";", "return", "$", "token", ";", "}" ]
@param TokenType $type @return string @throws TokenNotFoundException
[ "@param", "TokenType", "$type" ]
train
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Token/Storage/FileTokenStorage.php#L66-L83
model3/model3
src/Model3/Db/Table.php
Table.describe
protected function describe() { if(is_null($this->_tableName) == false) { $this->_query = 'DESCRIBE '.$this->_tableName; if($this->_db->execute($this->_query) !== false) { $res = $this->_db->getAllRows(); unset($this->_fields); unset($this->_primaryKey); $this->_fields = array(); foreach($res as $r) { $this->_fields[] = $r['Field']; if($r['Key'] == 'PRI') $this->_primaryKey = $r['Field']; } return true; } } return false; }
php
protected function describe() { if(is_null($this->_tableName) == false) { $this->_query = 'DESCRIBE '.$this->_tableName; if($this->_db->execute($this->_query) !== false) { $res = $this->_db->getAllRows(); unset($this->_fields); unset($this->_primaryKey); $this->_fields = array(); foreach($res as $r) { $this->_fields[] = $r['Field']; if($r['Key'] == 'PRI') $this->_primaryKey = $r['Field']; } return true; } } return false; }
[ "protected", "function", "describe", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_tableName", ")", "==", "false", ")", "{", "$", "this", "->", "_query", "=", "'DESCRIBE '", ".", "$", "this", "->", "_tableName", ";", "if", "(", "$", "this", "->", "_db", "->", "execute", "(", "$", "this", "->", "_query", ")", "!==", "false", ")", "{", "$", "res", "=", "$", "this", "->", "_db", "->", "getAllRows", "(", ")", ";", "unset", "(", "$", "this", "->", "_fields", ")", ";", "unset", "(", "$", "this", "->", "_primaryKey", ")", ";", "$", "this", "->", "_fields", "=", "array", "(", ")", ";", "foreach", "(", "$", "res", "as", "$", "r", ")", "{", "$", "this", "->", "_fields", "[", "]", "=", "$", "r", "[", "'Field'", "]", ";", "if", "(", "$", "r", "[", "'Key'", "]", "==", "'PRI'", ")", "$", "this", "->", "_primaryKey", "=", "$", "r", "[", "'Field'", "]", ";", "}", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
for now, this method is intended just for tables with one primary key
[ "for", "now", "this", "method", "is", "intended", "just", "for", "tables", "with", "one", "primary", "key" ]
train
https://github.com/model3/model3/blob/c62858013fce9bac597d47a2475c69aebe7d6209/src/Model3/Db/Table.php#L98-L119
model3/model3
src/Model3/Db/Table.php
Table.insert
public function insert($data) { //var_dump($data); unset($this->_error); if(is_array($data)) { $fields = ''; $values = ''; reset($data); for($counter = 0, $maxIndex = count($data), $valid = true; $counter < $maxIndex && $valid == true; $counter ++) { $elementKey = key($data); $elementKey = $this->_db->escape($elementKey); $valid = in_array($elementKey, $this->_fields); if($valid == true) { $element = $data[$elementKey]; $element = $this->_db->escape($element); if(is_object($element) == true) { $valid = false; $this->_error = 'field: '.$elementKey.'is an object (this method just accept strings)'; } else { if(is_numeric($element) == false) $values .= '\''.$element.'\''; else $values .= $element; $fields .= $elementKey; if(($counter + 1) < $maxIndex) { $fields .= ','; $values .= ','; } next($data); } } else { $this->_error = 'field: '.$elementKey.' is not defined in '.$this->_tableName; } } if($valid == true) { $this->_query = 'INSERT INTO '.$this->_tableName.'('.$fields.') VALUES('.$values.')'; if($this->_db->execute($this->_query) !== false) { return $this->_db->insertId(); } else { $this->_error = $this->_db->errorStr(); } } } return false; }
php
public function insert($data) { //var_dump($data); unset($this->_error); if(is_array($data)) { $fields = ''; $values = ''; reset($data); for($counter = 0, $maxIndex = count($data), $valid = true; $counter < $maxIndex && $valid == true; $counter ++) { $elementKey = key($data); $elementKey = $this->_db->escape($elementKey); $valid = in_array($elementKey, $this->_fields); if($valid == true) { $element = $data[$elementKey]; $element = $this->_db->escape($element); if(is_object($element) == true) { $valid = false; $this->_error = 'field: '.$elementKey.'is an object (this method just accept strings)'; } else { if(is_numeric($element) == false) $values .= '\''.$element.'\''; else $values .= $element; $fields .= $elementKey; if(($counter + 1) < $maxIndex) { $fields .= ','; $values .= ','; } next($data); } } else { $this->_error = 'field: '.$elementKey.' is not defined in '.$this->_tableName; } } if($valid == true) { $this->_query = 'INSERT INTO '.$this->_tableName.'('.$fields.') VALUES('.$values.')'; if($this->_db->execute($this->_query) !== false) { return $this->_db->insertId(); } else { $this->_error = $this->_db->errorStr(); } } } return false; }
[ "public", "function", "insert", "(", "$", "data", ")", "{", "//var_dump($data);", "unset", "(", "$", "this", "->", "_error", ")", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "fields", "=", "''", ";", "$", "values", "=", "''", ";", "reset", "(", "$", "data", ")", ";", "for", "(", "$", "counter", "=", "0", ",", "$", "maxIndex", "=", "count", "(", "$", "data", ")", ",", "$", "valid", "=", "true", ";", "$", "counter", "<", "$", "maxIndex", "&&", "$", "valid", "==", "true", ";", "$", "counter", "++", ")", "{", "$", "elementKey", "=", "key", "(", "$", "data", ")", ";", "$", "elementKey", "=", "$", "this", "->", "_db", "->", "escape", "(", "$", "elementKey", ")", ";", "$", "valid", "=", "in_array", "(", "$", "elementKey", ",", "$", "this", "->", "_fields", ")", ";", "if", "(", "$", "valid", "==", "true", ")", "{", "$", "element", "=", "$", "data", "[", "$", "elementKey", "]", ";", "$", "element", "=", "$", "this", "->", "_db", "->", "escape", "(", "$", "element", ")", ";", "if", "(", "is_object", "(", "$", "element", ")", "==", "true", ")", "{", "$", "valid", "=", "false", ";", "$", "this", "->", "_error", "=", "'field: '", ".", "$", "elementKey", ".", "'is an object (this method just accept strings)'", ";", "}", "else", "{", "if", "(", "is_numeric", "(", "$", "element", ")", "==", "false", ")", "$", "values", ".=", "'\\''", ".", "$", "element", ".", "'\\''", ";", "else", "$", "values", ".=", "$", "element", ";", "$", "fields", ".=", "$", "elementKey", ";", "if", "(", "(", "$", "counter", "+", "1", ")", "<", "$", "maxIndex", ")", "{", "$", "fields", ".=", "','", ";", "$", "values", ".=", "','", ";", "}", "next", "(", "$", "data", ")", ";", "}", "}", "else", "{", "$", "this", "->", "_error", "=", "'field: '", ".", "$", "elementKey", ".", "' is not defined in '", ".", "$", "this", "->", "_tableName", ";", "}", "}", "if", "(", "$", "valid", "==", "true", ")", "{", "$", "this", "->", "_query", "=", "'INSERT INTO '", ".", "$", "this", "->", "_tableName", ".", "'('", ".", "$", "fields", ".", "') VALUES('", ".", "$", "values", ".", "')'", ";", "if", "(", "$", "this", "->", "_db", "->", "execute", "(", "$", "this", "->", "_query", ")", "!==", "false", ")", "{", "return", "$", "this", "->", "_db", "->", "insertId", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_error", "=", "$", "this", "->", "_db", "->", "errorStr", "(", ")", ";", "}", "}", "}", "return", "false", ";", "}" ]
data is an associative array containing the name of the field and its value
[ "data", "is", "an", "associative", "array", "containing", "the", "name", "of", "the", "field", "and", "its", "value" ]
train
https://github.com/model3/model3/blob/c62858013fce9bac597d47a2475c69aebe7d6209/src/Model3/Db/Table.php#L122-L179
model3/model3
src/Model3/Db/Table.php
Table.composeQuery
protected function composeQuery($key, $values) { $query = ''; for($counter = 0, $maxIndex = count($values); $counter < $maxIndex; $counter ++) { if(is_numeric($values[$counter])) $query .= $key.' = '.$values[$counter]; else $query .= $key.' = \''.$values[$counter].'\''; if(($counter + 1) < $maxIndex) $query .= ' OR '; } return $query; }
php
protected function composeQuery($key, $values) { $query = ''; for($counter = 0, $maxIndex = count($values); $counter < $maxIndex; $counter ++) { if(is_numeric($values[$counter])) $query .= $key.' = '.$values[$counter]; else $query .= $key.' = \''.$values[$counter].'\''; if(($counter + 1) < $maxIndex) $query .= ' OR '; } return $query; }
[ "protected", "function", "composeQuery", "(", "$", "key", ",", "$", "values", ")", "{", "$", "query", "=", "''", ";", "for", "(", "$", "counter", "=", "0", ",", "$", "maxIndex", "=", "count", "(", "$", "values", ")", ";", "$", "counter", "<", "$", "maxIndex", ";", "$", "counter", "++", ")", "{", "if", "(", "is_numeric", "(", "$", "values", "[", "$", "counter", "]", ")", ")", "$", "query", ".=", "$", "key", ".", "' = '", ".", "$", "values", "[", "$", "counter", "]", ";", "else", "$", "query", ".=", "$", "key", ".", "' = \\''", ".", "$", "values", "[", "$", "counter", "]", ".", "'\\''", ";", "if", "(", "(", "$", "counter", "+", "1", ")", "<", "$", "maxIndex", ")", "$", "query", ".=", "' OR '", ";", "}", "return", "$", "query", ";", "}" ]
compose query
[ "compose", "query" ]
train
https://github.com/model3/model3/blob/c62858013fce9bac597d47a2475c69aebe7d6209/src/Model3/Db/Table.php#L231-L244
model3/model3
src/Model3/Db/Table.php
Table.find
public function find($key, $values, $order = null) { if(is_array($values) == false) $arrayOfValues = array($values); else $arrayOfValues = $values; $orderString = ''; if($this->basicCheck($key, $arrayOfValues) == true) { $orderChecked = strcasecmp('DESC', $order) == 0 ? 'DESC' : ''; $orderString = ' ORDER BY '.$key.' '.$orderChecked; $this->_query = 'SELECT * FROM '.$this->_tableName.' WHERE '.$this->composeQuery($key, $arrayOfValues).$orderString; return $this->findExecute(); } return false; }
php
public function find($key, $values, $order = null) { if(is_array($values) == false) $arrayOfValues = array($values); else $arrayOfValues = $values; $orderString = ''; if($this->basicCheck($key, $arrayOfValues) == true) { $orderChecked = strcasecmp('DESC', $order) == 0 ? 'DESC' : ''; $orderString = ' ORDER BY '.$key.' '.$orderChecked; $this->_query = 'SELECT * FROM '.$this->_tableName.' WHERE '.$this->composeQuery($key, $arrayOfValues).$orderString; return $this->findExecute(); } return false; }
[ "public", "function", "find", "(", "$", "key", ",", "$", "values", ",", "$", "order", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "values", ")", "==", "false", ")", "$", "arrayOfValues", "=", "array", "(", "$", "values", ")", ";", "else", "$", "arrayOfValues", "=", "$", "values", ";", "$", "orderString", "=", "''", ";", "if", "(", "$", "this", "->", "basicCheck", "(", "$", "key", ",", "$", "arrayOfValues", ")", "==", "true", ")", "{", "$", "orderChecked", "=", "strcasecmp", "(", "'DESC'", ",", "$", "order", ")", "==", "0", "?", "'DESC'", ":", "''", ";", "$", "orderString", "=", "' ORDER BY '", ".", "$", "key", ".", "' '", ".", "$", "orderChecked", ";", "$", "this", "->", "_query", "=", "'SELECT * FROM '", ".", "$", "this", "->", "_tableName", ".", "' WHERE '", ".", "$", "this", "->", "composeQuery", "(", "$", "key", ",", "$", "arrayOfValues", ")", ".", "$", "orderString", ";", "return", "$", "this", "->", "findExecute", "(", ")", ";", "}", "return", "false", ";", "}" ]
for now this method is just accepting a single key value (no arrays allowed)
[ "for", "now", "this", "method", "is", "just", "accepting", "a", "single", "key", "value", "(", "no", "arrays", "allowed", ")" ]
train
https://github.com/model3/model3/blob/c62858013fce9bac597d47a2475c69aebe7d6209/src/Model3/Db/Table.php#L288-L303
dragosprotung/stc-core
src/Workout/AbstractSportMapper.php
AbstractSportMapper.sportFromCode
public function sportFromCode($code) : string { $code = strtolower($code); $codes = array_flip(static::getMap()); return $codes[$code] ?? self::OTHER; }
php
public function sportFromCode($code) : string { $code = strtolower($code); $codes = array_flip(static::getMap()); return $codes[$code] ?? self::OTHER; }
[ "public", "function", "sportFromCode", "(", "$", "code", ")", ":", "string", "{", "$", "code", "=", "strtolower", "(", "$", "code", ")", ";", "$", "codes", "=", "array_flip", "(", "static", "::", "getMap", "(", ")", ")", ";", "return", "$", "codes", "[", "$", "code", "]", "??", "self", "::", "OTHER", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Workout/AbstractSportMapper.php#L24-L30
dragosprotung/stc-core
src/Workout/AbstractSportMapper.php
AbstractSportMapper.codeFromSport
public function codeFromSport($sport) : string { $sport = strtolower($sport); $codes = static::getMap(); if (array_key_exists($sport, $codes)) { return $codes[$sport]; } elseif (array_key_exists(self::OTHER, $codes)) { return $codes[self::OTHER]; } throw new \RuntimeException('Sport not mapped.'); }
php
public function codeFromSport($sport) : string { $sport = strtolower($sport); $codes = static::getMap(); if (array_key_exists($sport, $codes)) { return $codes[$sport]; } elseif (array_key_exists(self::OTHER, $codes)) { return $codes[self::OTHER]; } throw new \RuntimeException('Sport not mapped.'); }
[ "public", "function", "codeFromSport", "(", "$", "sport", ")", ":", "string", "{", "$", "sport", "=", "strtolower", "(", "$", "sport", ")", ";", "$", "codes", "=", "static", "::", "getMap", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "sport", ",", "$", "codes", ")", ")", "{", "return", "$", "codes", "[", "$", "sport", "]", ";", "}", "elseif", "(", "array_key_exists", "(", "self", "::", "OTHER", ",", "$", "codes", ")", ")", "{", "return", "$", "codes", "[", "self", "::", "OTHER", "]", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "'Sport not mapped.'", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Workout/AbstractSportMapper.php#L35-L47
ejsmont-artur/phpProxyBuilder
src/PhpProxyBuilder/Adapter/Intrumentor/SimpleArrayIntrumentor.php
SimpleArrayIntrumentor.incrementCounter
public function incrementCounter($name, $value = 1) { if (!isset($this->counters[$name])) { $this->counters[$name] = 0; } $this->counters[$name] += $value; }
php
public function incrementCounter($name, $value = 1) { if (!isset($this->counters[$name])) { $this->counters[$name] = 0; } $this->counters[$name] += $value; }
[ "public", "function", "incrementCounter", "(", "$", "name", ",", "$", "value", "=", "1", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "counters", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "counters", "[", "$", "name", "]", "=", "0", ";", "}", "$", "this", "->", "counters", "[", "$", "name", "]", "+=", "$", "value", ";", "}" ]
Increments named counter by $value @param string $name name of the counter @param int $value value to be added to the counter, default 1 @return InstrumentorInterface returns $this for chaining
[ "Increments", "named", "counter", "by", "$value" ]
train
https://github.com/ejsmont-artur/phpProxyBuilder/blob/ef7ec14e5d18eeba7a93e3617a0fdb5b146d6480/src/PhpProxyBuilder/Adapter/Intrumentor/SimpleArrayIntrumentor.php#L53-L58
ejsmont-artur/phpProxyBuilder
src/PhpProxyBuilder/Adapter/Intrumentor/SimpleArrayIntrumentor.php
SimpleArrayIntrumentor.incrementTimer
public function incrementTimer($name, $time) { if (!isset($this->timers[$name])) { $this->timers[$name] = 0; } $this->timers[$name] += $this->getTime() - $time; }
php
public function incrementTimer($name, $time) { if (!isset($this->timers[$name])) { $this->timers[$name] = 0; } $this->timers[$name] += $this->getTime() - $time; }
[ "public", "function", "incrementTimer", "(", "$", "name", ",", "$", "time", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "timers", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "timers", "[", "$", "name", "]", "=", "0", ";", "}", "$", "this", "->", "timers", "[", "$", "name", "]", "+=", "$", "this", "->", "getTime", "(", ")", "-", "$", "time", ";", "}" ]
Increments named timer. @param string $name name of the timer @param mixed $time time value acquired from getTime() method @return InstrumentorInterface returns $this for chaining
[ "Increments", "named", "timer", "." ]
train
https://github.com/ejsmont-artur/phpProxyBuilder/blob/ef7ec14e5d18eeba7a93e3617a0fdb5b146d6480/src/PhpProxyBuilder/Adapter/Intrumentor/SimpleArrayIntrumentor.php#L67-L72
movoin/one-swoole
src/Swoole/Traits/HasProtocol.php
HasProtocol.createProtocol
protected function createProtocol(string $protocol): self { $this->protocol = Factory::newProtocol($protocol); $this->protocol->setServer($this); return $this; }
php
protected function createProtocol(string $protocol): self { $this->protocol = Factory::newProtocol($protocol); $this->protocol->setServer($this); return $this; }
[ "protected", "function", "createProtocol", "(", "string", "$", "protocol", ")", ":", "self", "{", "$", "this", "->", "protocol", "=", "Factory", "::", "newProtocol", "(", "$", "protocol", ")", ";", "$", "this", "->", "protocol", "->", "setServer", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}" ]
创建协议 @param string $protocol @return self @throws \One\Protocol\Exceptions\ProtocolException
[ "创建协议" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Traits/HasProtocol.php#L45-L51
movoin/one-swoole
src/Swoole/Traits/HasProtocol.php
HasProtocol.callProtocolMethod
protected function callProtocolMethod(string $event, ...$parameters) { if (method_exists($this->protocol, $event)) { call_user_func_array([$this->protocol, $event], $parameters); } }
php
protected function callProtocolMethod(string $event, ...$parameters) { if (method_exists($this->protocol, $event)) { call_user_func_array([$this->protocol, $event], $parameters); } }
[ "protected", "function", "callProtocolMethod", "(", "string", "$", "event", ",", "...", "$", "parameters", ")", "{", "if", "(", "method_exists", "(", "$", "this", "->", "protocol", ",", "$", "event", ")", ")", "{", "call_user_func_array", "(", "[", "$", "this", "->", "protocol", ",", "$", "event", "]", ",", "$", "parameters", ")", ";", "}", "}" ]
调用协议方法 @param string $event @param array $parameters
[ "调用协议方法" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Traits/HasProtocol.php#L59-L64
puli/twig-extension
src/NodeVisitor/TemplatePathResolver.php
TemplatePathResolver.processNode
protected function processNode(Twig_Node $node) { if ($node instanceof Twig_Node_Module) { return $this->processModuleNode($node); } if ($node instanceof Twig_Node_Include) { return $this->processIncludeNode($node); } if ($node instanceof Twig_Node_Import) { return $this->processImportNode($node); } if ($node instanceof Twig_Node_Expression_Function && 'resource_url' === $node->getAttribute('name')) { return $this->processResourceUrlFunction($node); } return null; }
php
protected function processNode(Twig_Node $node) { if ($node instanceof Twig_Node_Module) { return $this->processModuleNode($node); } if ($node instanceof Twig_Node_Include) { return $this->processIncludeNode($node); } if ($node instanceof Twig_Node_Import) { return $this->processImportNode($node); } if ($node instanceof Twig_Node_Expression_Function && 'resource_url' === $node->getAttribute('name')) { return $this->processResourceUrlFunction($node); } return null; }
[ "protected", "function", "processNode", "(", "Twig_Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "Twig_Node_Module", ")", "{", "return", "$", "this", "->", "processModuleNode", "(", "$", "node", ")", ";", "}", "if", "(", "$", "node", "instanceof", "Twig_Node_Include", ")", "{", "return", "$", "this", "->", "processIncludeNode", "(", "$", "node", ")", ";", "}", "if", "(", "$", "node", "instanceof", "Twig_Node_Import", ")", "{", "return", "$", "this", "->", "processImportNode", "(", "$", "node", ")", ";", "}", "if", "(", "$", "node", "instanceof", "Twig_Node_Expression_Function", "&&", "'resource_url'", "===", "$", "node", "->", "getAttribute", "(", "'name'", ")", ")", "{", "return", "$", "this", "->", "processResourceUrlFunction", "(", "$", "node", ")", ";", "}", "return", "null", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/twig-extension/blob/b19fce610aa9fda5d86c73045ed5b9d378c47b93/src/NodeVisitor/TemplatePathResolver.php#L65-L84
crossjoin/Css
src/Crossjoin/Css/Format/Rule/TraitVendorPrefix.php
TraitVendorPrefix.setVendorPrefix
public function setVendorPrefix($vendorPrefix) { if (is_string($vendorPrefix)) { $this->vendorPrefix = $vendorPrefix; } else { throw new \InvalidArgumentException( "Invalid type '" . gettype($vendorPrefix). "' for argument 'vendorPrefix' given." ); } }
php
public function setVendorPrefix($vendorPrefix) { if (is_string($vendorPrefix)) { $this->vendorPrefix = $vendorPrefix; } else { throw new \InvalidArgumentException( "Invalid type '" . gettype($vendorPrefix). "' for argument 'vendorPrefix' given." ); } }
[ "public", "function", "setVendorPrefix", "(", "$", "vendorPrefix", ")", "{", "if", "(", "is_string", "(", "$", "vendorPrefix", ")", ")", "{", "$", "this", "->", "vendorPrefix", "=", "$", "vendorPrefix", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Invalid type '\"", ".", "gettype", "(", "$", "vendorPrefix", ")", ".", "\"' for argument 'vendorPrefix' given.\"", ")", ";", "}", "}" ]
Sets the vendor prefix. @param $vendorPrefix
[ "Sets", "the", "vendor", "prefix", "." ]
train
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/TraitVendorPrefix.php#L13-L22
crossjoin/Css
src/Crossjoin/Css/Format/Rule/TraitVendorPrefix.php
TraitVendorPrefix.getVendorPrefixRegExp
public static function getVendorPrefixRegExp($delimiter = null) { $vendorPrefixValues = self::getVendorPrefixValues(); foreach ($vendorPrefixValues as $vendorPrefixKey => $vendorPrefixValue) { $vendorPrefixValues[$vendorPrefixKey] = preg_quote($vendorPrefixValue, $delimiter); } return implode('|', $vendorPrefixValues); }
php
public static function getVendorPrefixRegExp($delimiter = null) { $vendorPrefixValues = self::getVendorPrefixValues(); foreach ($vendorPrefixValues as $vendorPrefixKey => $vendorPrefixValue) { $vendorPrefixValues[$vendorPrefixKey] = preg_quote($vendorPrefixValue, $delimiter); } return implode('|', $vendorPrefixValues); }
[ "public", "static", "function", "getVendorPrefixRegExp", "(", "$", "delimiter", "=", "null", ")", "{", "$", "vendorPrefixValues", "=", "self", "::", "getVendorPrefixValues", "(", ")", ";", "foreach", "(", "$", "vendorPrefixValues", "as", "$", "vendorPrefixKey", "=>", "$", "vendorPrefixValue", ")", "{", "$", "vendorPrefixValues", "[", "$", "vendorPrefixKey", "]", "=", "preg_quote", "(", "$", "vendorPrefixValue", ",", "$", "delimiter", ")", ";", "}", "return", "implode", "(", "'|'", ",", "$", "vendorPrefixValues", ")", ";", "}" ]
Returns a partial regular expression of known vendor prefixes. @param string|null $delimiter @return string
[ "Returns", "a", "partial", "regular", "expression", "of", "known", "vendor", "prefixes", "." ]
train
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/TraitVendorPrefix.php#L67-L74
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.count
public function count($filters = [], $options = []) { return $this->collection->count($this->castQuery($filters), $options); }
php
public function count($filters = [], $options = []) { return $this->collection->count($this->castQuery($filters), $options); }
[ "public", "function", "count", "(", "$", "filters", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "collection", "->", "count", "(", "$", "this", "->", "castQuery", "(", "$", "filters", ")", ",", "$", "options", ")", ";", "}" ]
Count corresponding documents for filters @param array $filters Object @param array $options Options for the query @return int Number of corresponding documents
[ "Count", "corresponding", "documents", "for", "filters" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L131-L134
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.distinct
public function distinct($fieldName, $filters = [], $options = []) { $field = $fieldName; $propInfos = $this->classMetadata->getPropertyInfoForField($fieldName); if (!$propInfos) { $propInfos = $this->classMetadata->getPropertyInfo($fieldName); } if (isset($propInfos)) { $field = $propInfos->getField(); if ($propInfos->getMetadata()) { $field = "metadata." . $field; } } $filters = $this->castQuery($filters); $result = $this->collection->distinct($field, $filters, $options); return $result; }
php
public function distinct($fieldName, $filters = [], $options = []) { $field = $fieldName; $propInfos = $this->classMetadata->getPropertyInfoForField($fieldName); if (!$propInfos) { $propInfos = $this->classMetadata->getPropertyInfo($fieldName); } if (isset($propInfos)) { $field = $propInfos->getField(); if ($propInfos->getMetadata()) { $field = "metadata." . $field; } } $filters = $this->castQuery($filters); $result = $this->collection->distinct($field, $filters, $options); return $result; }
[ "public", "function", "distinct", "(", "$", "fieldName", ",", "$", "filters", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "field", "=", "$", "fieldName", ";", "$", "propInfos", "=", "$", "this", "->", "classMetadata", "->", "getPropertyInfoForField", "(", "$", "fieldName", ")", ";", "if", "(", "!", "$", "propInfos", ")", "{", "$", "propInfos", "=", "$", "this", "->", "classMetadata", "->", "getPropertyInfo", "(", "$", "fieldName", ")", ";", "}", "if", "(", "isset", "(", "$", "propInfos", ")", ")", "{", "$", "field", "=", "$", "propInfos", "->", "getField", "(", ")", ";", "if", "(", "$", "propInfos", "->", "getMetadata", "(", ")", ")", "{", "$", "field", "=", "\"metadata.\"", ".", "$", "field", ";", "}", "}", "$", "filters", "=", "$", "this", "->", "castQuery", "(", "$", "filters", ")", ";", "$", "result", "=", "$", "this", "->", "collection", "->", "distinct", "(", "$", "field", ",", "$", "filters", ",", "$", "options", ")", ";", "return", "$", "result", ";", "}" ]
Get distinct value for a field @param string $fieldName Name of the field @param array $filters Filters of query @param array $options Options of query @return array List of distinct values
[ "Get", "distinct", "value", "for", "a", "field" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L144-L165
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.find
public function find($id, $projections = [], $options = []) { $options = $this->createOption($projections, null, $options); $result = $this->collection->findOne(["_id" => $id], $options); return $this->createObject($result, $options); }
php
public function find($id, $projections = [], $options = []) { $options = $this->createOption($projections, null, $options); $result = $this->collection->findOne(["_id" => $id], $options); return $this->createObject($result, $options); }
[ "public", "function", "find", "(", "$", "id", ",", "$", "projections", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "createOption", "(", "$", "projections", ",", "null", ",", "$", "options", ")", ";", "$", "result", "=", "$", "this", "->", "collection", "->", "findOne", "(", "[", "\"_id\"", "=>", "$", "id", "]", ",", "$", "options", ")", ";", "return", "$", "this", "->", "createObject", "(", "$", "result", ",", "$", "options", ")", ";", "}" ]
Find document by ID Options : * readOnly : boolean - When false, flush will not update object @see MongoDB\Operation\FindOne::__construct for more option @param mixed $id Id of the document @param array $projections Projection of the query @param array $options Options for the query @return object|null
[ "Find", "document", "by", "ID" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L179-L186
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.findAll
public function findAll($projections = [], $sorts = [], $options = []) { $options = $this->createOption($projections, $sorts, $options); $result = $this->collection->find([], $options); if (!isset($options['iterator']) || $options['iterator'] === false) { $objects = []; foreach ($result as $datas) { if (null != ($object = $this->createObject($datas, $options))) { $objects[] = $object; } } return $objects; } else { $iteratorClass = $options['iterator']; $iterator = $iteratorClass === true ? new DocumentIterator($result, $this->modelName, $this) : new $iteratorClass($result, $this->modelName, $this); if (isset($options['readOnly']) && $options['readOnly'] == true) { $iterator->readOnly(); } return $iterator; } }
php
public function findAll($projections = [], $sorts = [], $options = []) { $options = $this->createOption($projections, $sorts, $options); $result = $this->collection->find([], $options); if (!isset($options['iterator']) || $options['iterator'] === false) { $objects = []; foreach ($result as $datas) { if (null != ($object = $this->createObject($datas, $options))) { $objects[] = $object; } } return $objects; } else { $iteratorClass = $options['iterator']; $iterator = $iteratorClass === true ? new DocumentIterator($result, $this->modelName, $this) : new $iteratorClass($result, $this->modelName, $this); if (isset($options['readOnly']) && $options['readOnly'] == true) { $iterator->readOnly(); } return $iterator; } }
[ "public", "function", "findAll", "(", "$", "projections", "=", "[", "]", ",", "$", "sorts", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "createOption", "(", "$", "projections", ",", "$", "sorts", ",", "$", "options", ")", ";", "$", "result", "=", "$", "this", "->", "collection", "->", "find", "(", "[", "]", ",", "$", "options", ")", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'iterator'", "]", ")", "||", "$", "options", "[", "'iterator'", "]", "===", "false", ")", "{", "$", "objects", "=", "[", "]", ";", "foreach", "(", "$", "result", "as", "$", "datas", ")", "{", "if", "(", "null", "!=", "(", "$", "object", "=", "$", "this", "->", "createObject", "(", "$", "datas", ",", "$", "options", ")", ")", ")", "{", "$", "objects", "[", "]", "=", "$", "object", ";", "}", "}", "return", "$", "objects", ";", "}", "else", "{", "$", "iteratorClass", "=", "$", "options", "[", "'iterator'", "]", ";", "$", "iterator", "=", "$", "iteratorClass", "===", "true", "?", "new", "DocumentIterator", "(", "$", "result", ",", "$", "this", "->", "modelName", ",", "$", "this", ")", ":", "new", "$", "iteratorClass", "(", "$", "result", ",", "$", "this", "->", "modelName", ",", "$", "this", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'readOnly'", "]", ")", "&&", "$", "options", "[", "'readOnly'", "]", "==", "true", ")", "{", "$", "iterator", "->", "readOnly", "(", ")", ";", "}", "return", "$", "iterator", ";", "}", "}" ]
Find all document of the collection Options : * readOnly : boolean - When false, flush will not update object * iterator : boolean|string - Return DocumentIterator if true (or specified class if is string) @see MongoDB\Operation\Find::__construct for more option @param array $projections Projection of the query @param array $sorts Sort options @param array $options Options for the query @return array Array containing all the document of the collection
[ "Find", "all", "document", "of", "the", "collection" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L201-L223
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.findOneBy
public function findOneBy($filters = [], $projections = [], $sorts = [], $options = []) { $options = $this->createOption($projections, $sorts, $options); $filters = $this->castQuery($filters); $result = $this->collection->findOne($filters, $options); return $this->createObject($result, $options); }
php
public function findOneBy($filters = [], $projections = [], $sorts = [], $options = []) { $options = $this->createOption($projections, $sorts, $options); $filters = $this->castQuery($filters); $result = $this->collection->findOne($filters, $options); return $this->createObject($result, $options); }
[ "public", "function", "findOneBy", "(", "$", "filters", "=", "[", "]", ",", "$", "projections", "=", "[", "]", ",", "$", "sorts", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "createOption", "(", "$", "projections", ",", "$", "sorts", ",", "$", "options", ")", ";", "$", "filters", "=", "$", "this", "->", "castQuery", "(", "$", "filters", ")", ";", "$", "result", "=", "$", "this", "->", "collection", "->", "findOne", "(", "$", "filters", ",", "$", "options", ")", ";", "return", "$", "this", "->", "createObject", "(", "$", "result", ",", "$", "options", ")", ";", "}" ]
Get first document which match the query Options : * readOnly : boolean - When false, flush will not update object @see MongoDB\Operation\Find::__construct for more option @param array $filters Filters @param array $projections Projection of the query @param array $sorts Sorts specification @param array $options Options for the query @param array $options @return void
[ "Get", "first", "document", "which", "match", "the", "query" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L279-L288
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.findAndModifyOneBy
public function findAndModifyOneBy($filters = [], $update = [], $projections = [], $sorts = [], $options = []) { $options = $this->createOption($projections, $sorts, $options); $filters = $this->castQuery($filters); $update = $this->castQuery($update); $result = (array) $this->collection->findOneAndUpdate($filters, $update, $options); return $this->createObject($result, $options); }
php
public function findAndModifyOneBy($filters = [], $update = [], $projections = [], $sorts = [], $options = []) { $options = $this->createOption($projections, $sorts, $options); $filters = $this->castQuery($filters); $update = $this->castQuery($update); $result = (array) $this->collection->findOneAndUpdate($filters, $update, $options); return $this->createObject($result, $options); }
[ "public", "function", "findAndModifyOneBy", "(", "$", "filters", "=", "[", "]", ",", "$", "update", "=", "[", "]", ",", "$", "projections", "=", "[", "]", ",", "$", "sorts", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "createOption", "(", "$", "projections", ",", "$", "sorts", ",", "$", "options", ")", ";", "$", "filters", "=", "$", "this", "->", "castQuery", "(", "$", "filters", ")", ";", "$", "update", "=", "$", "this", "->", "castQuery", "(", "$", "update", ")", ";", "$", "result", "=", "(", "array", ")", "$", "this", "->", "collection", "->", "findOneAndUpdate", "(", "$", "filters", ",", "$", "update", ",", "$", "options", ")", ";", "return", "$", "this", "->", "createObject", "(", "$", "result", ",", "$", "options", ")", ";", "}" ]
Find a document and make specified update on it Options : * readOnly : boolean - When false, flush will not update object @see MongoDB\Operation\FindAndModify::__construct for more option @param array $filters Filters @param array $update Update to perform @param array $projections Projection of the query @param array $sorts Sorts specification @param array $options Options for the query @param array $options @return void
[ "Find", "a", "document", "and", "make", "specified", "update", "on", "it" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L305-L316
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.getTailableCursor
public function getTailableCursor($filters = [], $options = []) { $options['cursorType'] = \MongoDB\Operation\Find::TAILABLE_AWAIT; return $this->collection->find($this->castQuery($filters), $options); }
php
public function getTailableCursor($filters = [], $options = []) { $options['cursorType'] = \MongoDB\Operation\Find::TAILABLE_AWAIT; return $this->collection->find($this->castQuery($filters), $options); }
[ "public", "function", "getTailableCursor", "(", "$", "filters", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "options", "[", "'cursorType'", "]", "=", "\\", "MongoDB", "\\", "Operation", "\\", "Find", "::", "TAILABLE_AWAIT", ";", "return", "$", "this", "->", "collection", "->", "find", "(", "$", "this", "->", "castQuery", "(", "$", "filters", ")", ",", "$", "options", ")", ";", "}" ]
Get tailable cursor for query @param array $filters Filters of query @param array $options Option (Tailable setted as default) @return \MongoDB\Driver\TailableCursor A tailable cursor
[ "Get", "tailable", "cursor", "for", "query" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L325-L330
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.insertOne
public function insertOne($document, $options = []) { $query = new InsertOne($this->documentManager, $this, $document, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
php
public function insertOne($document, $options = []) { $query = new InsertOne($this->documentManager, $this, $document, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
[ "public", "function", "insertOne", "(", "$", "document", ",", "$", "options", "=", "[", "]", ")", "{", "$", "query", "=", "new", "InsertOne", "(", "$", "this", "->", "documentManager", ",", "$", "this", ",", "$", "document", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'getQuery'", "]", ")", "&&", "$", "options", "[", "'getQuery'", "]", ")", "{", "return", "$", "query", ";", "}", "else", "{", "return", "$", "query", "->", "execute", "(", ")", ";", "}", "}" ]
Insert a document in collection @param mixed $document Document to insert @param array $options Options @return void
[ "Insert", "a", "document", "in", "collection" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L339-L347
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.insertMany
public function insertMany($documents, $options = []) { $insertQuery = []; foreach ($documents as $document) { $this->classMetadata->getEventManager()->execute(EventManager::EVENT_PRE_INSERT, $document); $query = $this->hydrator->unhydrate($document); $idGen = $this->classMetadata->getIdGenerator(); if ($idGen !== null) { if (!class_exists($idGen) || !is_subclass_of($idGen, AbstractIdGenerator::class)) { throw new \Exception('Bad ID generator : class \'' . $idGen . '\' not exists or not extends JPC\MongoDB\ODM\Id\AbstractIdGenerator'); } $generator = new $idGen(); $query['_id'] = $generator->generate($this->documentManager, $document); } $insertQuery[] = $query; } $result = $this->collection->insertMany($insertQuery, $options); if ($result->isAcknowledged()) { foreach ($result->getInsertedIds() as $key => $id) { if ($id instanceof \stdClass) { $id = (array) $id; } $insertQuery[$key]["_id"] = $id; $this->hydrator->hydrate($documents[$key], $insertQuery[$key]); $this->classMetadata->getEventManager()->execute(EventManager::EVENT_POST_INSERT, $documents[$key]); $this->cacheObject($documents[$key]); } return true; } else { foreach ($documents as $document) { $this->cacheObject($document); // $this->documentManager->removeObject(); } return false; } }
php
public function insertMany($documents, $options = []) { $insertQuery = []; foreach ($documents as $document) { $this->classMetadata->getEventManager()->execute(EventManager::EVENT_PRE_INSERT, $document); $query = $this->hydrator->unhydrate($document); $idGen = $this->classMetadata->getIdGenerator(); if ($idGen !== null) { if (!class_exists($idGen) || !is_subclass_of($idGen, AbstractIdGenerator::class)) { throw new \Exception('Bad ID generator : class \'' . $idGen . '\' not exists or not extends JPC\MongoDB\ODM\Id\AbstractIdGenerator'); } $generator = new $idGen(); $query['_id'] = $generator->generate($this->documentManager, $document); } $insertQuery[] = $query; } $result = $this->collection->insertMany($insertQuery, $options); if ($result->isAcknowledged()) { foreach ($result->getInsertedIds() as $key => $id) { if ($id instanceof \stdClass) { $id = (array) $id; } $insertQuery[$key]["_id"] = $id; $this->hydrator->hydrate($documents[$key], $insertQuery[$key]); $this->classMetadata->getEventManager()->execute(EventManager::EVENT_POST_INSERT, $documents[$key]); $this->cacheObject($documents[$key]); } return true; } else { foreach ($documents as $document) { $this->cacheObject($document); // $this->documentManager->removeObject(); } return false; } }
[ "public", "function", "insertMany", "(", "$", "documents", ",", "$", "options", "=", "[", "]", ")", "{", "$", "insertQuery", "=", "[", "]", ";", "foreach", "(", "$", "documents", "as", "$", "document", ")", "{", "$", "this", "->", "classMetadata", "->", "getEventManager", "(", ")", "->", "execute", "(", "EventManager", "::", "EVENT_PRE_INSERT", ",", "$", "document", ")", ";", "$", "query", "=", "$", "this", "->", "hydrator", "->", "unhydrate", "(", "$", "document", ")", ";", "$", "idGen", "=", "$", "this", "->", "classMetadata", "->", "getIdGenerator", "(", ")", ";", "if", "(", "$", "idGen", "!==", "null", ")", "{", "if", "(", "!", "class_exists", "(", "$", "idGen", ")", "||", "!", "is_subclass_of", "(", "$", "idGen", ",", "AbstractIdGenerator", "::", "class", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Bad ID generator : class \\''", ".", "$", "idGen", ".", "'\\' not exists or not extends JPC\\MongoDB\\ODM\\Id\\AbstractIdGenerator'", ")", ";", "}", "$", "generator", "=", "new", "$", "idGen", "(", ")", ";", "$", "query", "[", "'_id'", "]", "=", "$", "generator", "->", "generate", "(", "$", "this", "->", "documentManager", ",", "$", "document", ")", ";", "}", "$", "insertQuery", "[", "]", "=", "$", "query", ";", "}", "$", "result", "=", "$", "this", "->", "collection", "->", "insertMany", "(", "$", "insertQuery", ",", "$", "options", ")", ";", "if", "(", "$", "result", "->", "isAcknowledged", "(", ")", ")", "{", "foreach", "(", "$", "result", "->", "getInsertedIds", "(", ")", "as", "$", "key", "=>", "$", "id", ")", "{", "if", "(", "$", "id", "instanceof", "\\", "stdClass", ")", "{", "$", "id", "=", "(", "array", ")", "$", "id", ";", "}", "$", "insertQuery", "[", "$", "key", "]", "[", "\"_id\"", "]", "=", "$", "id", ";", "$", "this", "->", "hydrator", "->", "hydrate", "(", "$", "documents", "[", "$", "key", "]", ",", "$", "insertQuery", "[", "$", "key", "]", ")", ";", "$", "this", "->", "classMetadata", "->", "getEventManager", "(", ")", "->", "execute", "(", "EventManager", "::", "EVENT_POST_INSERT", ",", "$", "documents", "[", "$", "key", "]", ")", ";", "$", "this", "->", "cacheObject", "(", "$", "documents", "[", "$", "key", "]", ")", ";", "}", "return", "true", ";", "}", "else", "{", "foreach", "(", "$", "documents", "as", "$", "document", ")", "{", "$", "this", "->", "cacheObject", "(", "$", "document", ")", ";", "// $this->documentManager->removeObject();", "}", "return", "false", ";", "}", "}" ]
Insert multiple documents in collection @param mixed $documents Documents to insert @param array $options Options @return void
[ "Insert", "multiple", "documents", "in", "collection" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L356-L398
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.updateOne
public function updateOne($document, $update = [], $options = []) { $query = new UpdateOne($this->documentManager, $this, $document, $update, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
php
public function updateOne($document, $update = [], $options = []) { $query = new UpdateOne($this->documentManager, $this, $document, $update, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
[ "public", "function", "updateOne", "(", "$", "document", ",", "$", "update", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "query", "=", "new", "UpdateOne", "(", "$", "this", "->", "documentManager", ",", "$", "this", ",", "$", "document", ",", "$", "update", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'getQuery'", "]", ")", "&&", "$", "options", "[", "'getQuery'", "]", ")", "{", "return", "$", "query", ";", "}", "else", "{", "return", "$", "query", "->", "execute", "(", ")", ";", "}", "}" ]
Update a document in mongoDB @param mixed $document Document or query to update @param array $update Update query, let empty to update document based on object changes @param array $options Options @return void
[ "Update", "a", "document", "in", "mongoDB" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L408-L416
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.updateMany
public function updateMany($filters, $update, $options = []) { $result = $this->collection->updateMany($this->castQuery($filters), $update, $options); if ($result->isAcknowledged()) { return true; } else { return false; } }
php
public function updateMany($filters, $update, $options = []) { $result = $this->collection->updateMany($this->castQuery($filters), $update, $options); if ($result->isAcknowledged()) { return true; } else { return false; } }
[ "public", "function", "updateMany", "(", "$", "filters", ",", "$", "update", ",", "$", "options", "=", "[", "]", ")", "{", "$", "result", "=", "$", "this", "->", "collection", "->", "updateMany", "(", "$", "this", "->", "castQuery", "(", "$", "filters", ")", ",", "$", "update", ",", "$", "options", ")", ";", "if", "(", "$", "result", "->", "isAcknowledged", "(", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Update many document @param array $filters Filters @param array $update Update to perform @param array $options Options @return void
[ "Update", "many", "document" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L426-L435
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.replaceOne
public function replaceOne($document, $replacement, $options = []) { $query = new ReplaceOne($this->documentManager, $this, $document, $replacement, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
php
public function replaceOne($document, $replacement, $options = []) { $query = new ReplaceOne($this->documentManager, $this, $document, $replacement, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
[ "public", "function", "replaceOne", "(", "$", "document", ",", "$", "replacement", ",", "$", "options", "=", "[", "]", ")", "{", "$", "query", "=", "new", "ReplaceOne", "(", "$", "this", "->", "documentManager", ",", "$", "this", ",", "$", "document", ",", "$", "replacement", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'getQuery'", "]", ")", "&&", "$", "options", "[", "'getQuery'", "]", ")", "{", "return", "$", "query", ";", "}", "else", "{", "return", "$", "query", "->", "execute", "(", ")", ";", "}", "}" ]
Update a document in mongoDB @param mixed $document Document or query to update @param array $update Update query, let empty to update document based on object changes @param array $options Options @return void
[ "Update", "a", "document", "in", "mongoDB" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L445-L453
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.deleteOne
public function deleteOne($document, $options = []) { $query = new DeleteOne($this->documentManager, $this, $document, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
php
public function deleteOne($document, $options = []) { $query = new DeleteOne($this->documentManager, $this, $document, $options); if (isset($options['getQuery']) && $options['getQuery']) { return $query; } else { return $query->execute(); } }
[ "public", "function", "deleteOne", "(", "$", "document", ",", "$", "options", "=", "[", "]", ")", "{", "$", "query", "=", "new", "DeleteOne", "(", "$", "this", "->", "documentManager", ",", "$", "this", ",", "$", "document", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'getQuery'", "]", ")", "&&", "$", "options", "[", "'getQuery'", "]", ")", "{", "return", "$", "query", ";", "}", "else", "{", "return", "$", "query", "->", "execute", "(", ")", ";", "}", "}" ]
Delete a document @param object|array $document Document to delete @param array $options Options @return void
[ "Delete", "a", "document" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L462-L470
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.deleteMany
public function deleteMany($filter, $options = []) { $filter = $this->castQuery($filter); $result = $this->collection->deleteMany($filter, $options); if ($result->isAcknowledged()) { return true; } else { return false; } }
php
public function deleteMany($filter, $options = []) { $filter = $this->castQuery($filter); $result = $this->collection->deleteMany($filter, $options); if ($result->isAcknowledged()) { return true; } else { return false; } }
[ "public", "function", "deleteMany", "(", "$", "filter", ",", "$", "options", "=", "[", "]", ")", "{", "$", "filter", "=", "$", "this", "->", "castQuery", "(", "$", "filter", ")", ";", "$", "result", "=", "$", "this", "->", "collection", "->", "deleteMany", "(", "$", "filter", ",", "$", "options", ")", ";", "if", "(", "$", "result", "->", "isAcknowledged", "(", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Delete many document @param array $filter Filter wich match to objects to delete @param array $options Options @return void
[ "Delete", "many", "document" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L479-L489
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.createObject
protected function createObject($data, $options = []) { $object = null; if ($data != null) { $id = isset($data['_id']) ? serialize($data['_id']) . $this->getCollection() : null; $model = $this->getModelName(); $softHydrate = false; if (null !== $this->documentManager->getObject($id)) { $softHydrate = true; $object = $this->documentManager->getObject($id); } else { $object = new $this->modelName(); } $this->hydrator->hydrate($object, $data, $softHydrate); $this->classMetadata->getEventManager()->execute(EventManager::EVENT_POST_LOAD, $object); if (!isset($options['readOnly']) || $options['readOnly'] != true) { $oid = spl_object_hash($object); $data = $this->hydrator->unhydrate($object); $id = isset($data['_id']) ? serialize($data['_id']) . $this->getCollection() : $oid; $projection = isset($options['projection']) ? $options['projection'] : []; $this->lastProjectionCache->save($id, $projection); $this->cacheObject($object); $this->documentManager->addObject($object, DocumentManager::OBJ_MANAGED, $this); } return $object; } return $object; }
php
protected function createObject($data, $options = []) { $object = null; if ($data != null) { $id = isset($data['_id']) ? serialize($data['_id']) . $this->getCollection() : null; $model = $this->getModelName(); $softHydrate = false; if (null !== $this->documentManager->getObject($id)) { $softHydrate = true; $object = $this->documentManager->getObject($id); } else { $object = new $this->modelName(); } $this->hydrator->hydrate($object, $data, $softHydrate); $this->classMetadata->getEventManager()->execute(EventManager::EVENT_POST_LOAD, $object); if (!isset($options['readOnly']) || $options['readOnly'] != true) { $oid = spl_object_hash($object); $data = $this->hydrator->unhydrate($object); $id = isset($data['_id']) ? serialize($data['_id']) . $this->getCollection() : $oid; $projection = isset($options['projection']) ? $options['projection'] : []; $this->lastProjectionCache->save($id, $projection); $this->cacheObject($object); $this->documentManager->addObject($object, DocumentManager::OBJ_MANAGED, $this); } return $object; } return $object; }
[ "protected", "function", "createObject", "(", "$", "data", ",", "$", "options", "=", "[", "]", ")", "{", "$", "object", "=", "null", ";", "if", "(", "$", "data", "!=", "null", ")", "{", "$", "id", "=", "isset", "(", "$", "data", "[", "'_id'", "]", ")", "?", "serialize", "(", "$", "data", "[", "'_id'", "]", ")", ".", "$", "this", "->", "getCollection", "(", ")", ":", "null", ";", "$", "model", "=", "$", "this", "->", "getModelName", "(", ")", ";", "$", "softHydrate", "=", "false", ";", "if", "(", "null", "!==", "$", "this", "->", "documentManager", "->", "getObject", "(", "$", "id", ")", ")", "{", "$", "softHydrate", "=", "true", ";", "$", "object", "=", "$", "this", "->", "documentManager", "->", "getObject", "(", "$", "id", ")", ";", "}", "else", "{", "$", "object", "=", "new", "$", "this", "->", "modelName", "(", ")", ";", "}", "$", "this", "->", "hydrator", "->", "hydrate", "(", "$", "object", ",", "$", "data", ",", "$", "softHydrate", ")", ";", "$", "this", "->", "classMetadata", "->", "getEventManager", "(", ")", "->", "execute", "(", "EventManager", "::", "EVENT_POST_LOAD", ",", "$", "object", ")", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'readOnly'", "]", ")", "||", "$", "options", "[", "'readOnly'", "]", "!=", "true", ")", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "object", ")", ";", "$", "data", "=", "$", "this", "->", "hydrator", "->", "unhydrate", "(", "$", "object", ")", ";", "$", "id", "=", "isset", "(", "$", "data", "[", "'_id'", "]", ")", "?", "serialize", "(", "$", "data", "[", "'_id'", "]", ")", ".", "$", "this", "->", "getCollection", "(", ")", ":", "$", "oid", ";", "$", "projection", "=", "isset", "(", "$", "options", "[", "'projection'", "]", ")", "?", "$", "options", "[", "'projection'", "]", ":", "[", "]", ";", "$", "this", "->", "lastProjectionCache", "->", "save", "(", "$", "id", ",", "$", "projection", ")", ";", "$", "this", "->", "cacheObject", "(", "$", "object", ")", ";", "$", "this", "->", "documentManager", "->", "addObject", "(", "$", "object", ",", "DocumentManager", "::", "OBJ_MANAGED", ",", "$", "this", ")", ";", "}", "return", "$", "object", ";", "}", "return", "$", "object", ";", "}" ]
Create object based on provided data @param array $data Array of data which will hydrate object @param array $options Options @return void
[ "Create", "object", "based", "on", "provided", "data" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L503-L533
JoffreyPoreeCoding/MongoDB-ODM
src/Repository.php
Repository.createOption
protected function createOption($projections, $sort, $otherOptions = []) { $options = []; isset($projections) ? $options["projection"] = $this->castQuery($projections) : null; isset($sort) ? $options["sort"] = $this->castQuery($sort) : null; $options = array_merge($this->documentManager->getDefaultOptions(), $otherOptions, $options); return $options; }
php
protected function createOption($projections, $sort, $otherOptions = []) { $options = []; isset($projections) ? $options["projection"] = $this->castQuery($projections) : null; isset($sort) ? $options["sort"] = $this->castQuery($sort) : null; $options = array_merge($this->documentManager->getDefaultOptions(), $otherOptions, $options); return $options; }
[ "protected", "function", "createOption", "(", "$", "projections", ",", "$", "sort", ",", "$", "otherOptions", "=", "[", "]", ")", "{", "$", "options", "=", "[", "]", ";", "isset", "(", "$", "projections", ")", "?", "$", "options", "[", "\"projection\"", "]", "=", "$", "this", "->", "castQuery", "(", "$", "projections", ")", ":", "null", ";", "isset", "(", "$", "sort", ")", "?", "$", "options", "[", "\"sort\"", "]", "=", "$", "this", "->", "castQuery", "(", "$", "sort", ")", ":", "null", ";", "$", "options", "=", "array_merge", "(", "$", "this", "->", "documentManager", "->", "getDefaultOptions", "(", ")", ",", "$", "otherOptions", ",", "$", "options", ")", ";", "return", "$", "options", ";", "}" ]
Create options based on parameters @param array $projections Projection specification @param array $sort Sort specification @param array $otherOptions Other options @return void
[ "Create", "options", "based", "on", "parameters" ]
train
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Repository.php#L543-L551
pdefreitas/Laravel-VanillaSSO
src/Pdefreitas/VanillaSSO/VanillaSSO.php
VanillaSSO.WriteJsConnect
public static function WriteJsConnect($User, $Request, $Secure = TRUE) { $User = array_change_key_case($User); $ClientID = Config::get("vanillasso.client_id"); $Secret = Config::get("vanillasso.secret"); // Error checking. if ($Secure) { // Check the client. if (!isset($Request['client_id'])) $Error = array('error' => 'invalid_request', 'message' => 'The client_id parameter is missing.'); elseif ($Request['client_id'] != $ClientID) $Error = array('error' => 'invalid_client', 'message' => "Unknown client {$Request['client_id']}."); elseif (!isset($Request['timestamp']) && !isset($Request['signature'])) { if (is_array($User) && count($User) > 0) { // This isn't really an error, but we are just going to return public information when no signature is sent. $Error = array('name' => $User['name'], 'photourl' => @$User['photourl']); } else { $Error = array('name' => '', 'photourl' => ''); } } elseif (!isset($Request['timestamp']) || !is_numeric($Request['timestamp'])) $Error = array('error' => 'invalid_request', 'message' => 'The timestamp parameter is missing or invalid.'); elseif (!isset($Request['signature'])) $Error = array('error' => 'invalid_request', 'message' => 'Missing signature parameter.'); elseif (($Diff = abs($Request['timestamp'] - self::JsTimestamp())) > JS_TIMEOUT) $Error = array('error' => 'invalid_request', 'message' => 'The timestamp is invalid.'); else { // Make sure the timestamp hasn't timed out. $Signature = self::JsHash($Request['timestamp'] . $Secret, $Secure); if ($Signature != $Request['signature']) $Error = array('error' => 'access_denied', 'message' => 'Signature invalid.'); } } if (isset($Error)) $Result = $Error; elseif (is_array($User) && count($User) > 0) { if ($Secure === NULL) { $Result = $User; } else { $Result = self::SignJsConnect($User, $ClientID, $Secret, $Secure, TRUE); } } else $Result = array('name' => '', 'photourl' => ''); $Json = json_encode($Result); if (isset($Request['callback'])) return "{$Request['callback']}($Json)"; else return $Json; }
php
public static function WriteJsConnect($User, $Request, $Secure = TRUE) { $User = array_change_key_case($User); $ClientID = Config::get("vanillasso.client_id"); $Secret = Config::get("vanillasso.secret"); // Error checking. if ($Secure) { // Check the client. if (!isset($Request['client_id'])) $Error = array('error' => 'invalid_request', 'message' => 'The client_id parameter is missing.'); elseif ($Request['client_id'] != $ClientID) $Error = array('error' => 'invalid_client', 'message' => "Unknown client {$Request['client_id']}."); elseif (!isset($Request['timestamp']) && !isset($Request['signature'])) { if (is_array($User) && count($User) > 0) { // This isn't really an error, but we are just going to return public information when no signature is sent. $Error = array('name' => $User['name'], 'photourl' => @$User['photourl']); } else { $Error = array('name' => '', 'photourl' => ''); } } elseif (!isset($Request['timestamp']) || !is_numeric($Request['timestamp'])) $Error = array('error' => 'invalid_request', 'message' => 'The timestamp parameter is missing or invalid.'); elseif (!isset($Request['signature'])) $Error = array('error' => 'invalid_request', 'message' => 'Missing signature parameter.'); elseif (($Diff = abs($Request['timestamp'] - self::JsTimestamp())) > JS_TIMEOUT) $Error = array('error' => 'invalid_request', 'message' => 'The timestamp is invalid.'); else { // Make sure the timestamp hasn't timed out. $Signature = self::JsHash($Request['timestamp'] . $Secret, $Secure); if ($Signature != $Request['signature']) $Error = array('error' => 'access_denied', 'message' => 'Signature invalid.'); } } if (isset($Error)) $Result = $Error; elseif (is_array($User) && count($User) > 0) { if ($Secure === NULL) { $Result = $User; } else { $Result = self::SignJsConnect($User, $ClientID, $Secret, $Secure, TRUE); } } else $Result = array('name' => '', 'photourl' => ''); $Json = json_encode($Result); if (isset($Request['callback'])) return "{$Request['callback']}($Json)"; else return $Json; }
[ "public", "static", "function", "WriteJsConnect", "(", "$", "User", ",", "$", "Request", ",", "$", "Secure", "=", "TRUE", ")", "{", "$", "User", "=", "array_change_key_case", "(", "$", "User", ")", ";", "$", "ClientID", "=", "Config", "::", "get", "(", "\"vanillasso.client_id\"", ")", ";", "$", "Secret", "=", "Config", "::", "get", "(", "\"vanillasso.secret\"", ")", ";", "// Error checking.", "if", "(", "$", "Secure", ")", "{", "// Check the client.", "if", "(", "!", "isset", "(", "$", "Request", "[", "'client_id'", "]", ")", ")", "$", "Error", "=", "array", "(", "'error'", "=>", "'invalid_request'", ",", "'message'", "=>", "'The client_id parameter is missing.'", ")", ";", "elseif", "(", "$", "Request", "[", "'client_id'", "]", "!=", "$", "ClientID", ")", "$", "Error", "=", "array", "(", "'error'", "=>", "'invalid_client'", ",", "'message'", "=>", "\"Unknown client {$Request['client_id']}.\"", ")", ";", "elseif", "(", "!", "isset", "(", "$", "Request", "[", "'timestamp'", "]", ")", "&&", "!", "isset", "(", "$", "Request", "[", "'signature'", "]", ")", ")", "{", "if", "(", "is_array", "(", "$", "User", ")", "&&", "count", "(", "$", "User", ")", ">", "0", ")", "{", "// This isn't really an error, but we are just going to return public information when no signature is sent.", "$", "Error", "=", "array", "(", "'name'", "=>", "$", "User", "[", "'name'", "]", ",", "'photourl'", "=>", "@", "$", "User", "[", "'photourl'", "]", ")", ";", "}", "else", "{", "$", "Error", "=", "array", "(", "'name'", "=>", "''", ",", "'photourl'", "=>", "''", ")", ";", "}", "}", "elseif", "(", "!", "isset", "(", "$", "Request", "[", "'timestamp'", "]", ")", "||", "!", "is_numeric", "(", "$", "Request", "[", "'timestamp'", "]", ")", ")", "$", "Error", "=", "array", "(", "'error'", "=>", "'invalid_request'", ",", "'message'", "=>", "'The timestamp parameter is missing or invalid.'", ")", ";", "elseif", "(", "!", "isset", "(", "$", "Request", "[", "'signature'", "]", ")", ")", "$", "Error", "=", "array", "(", "'error'", "=>", "'invalid_request'", ",", "'message'", "=>", "'Missing signature parameter.'", ")", ";", "elseif", "(", "(", "$", "Diff", "=", "abs", "(", "$", "Request", "[", "'timestamp'", "]", "-", "self", "::", "JsTimestamp", "(", ")", ")", ")", ">", "JS_TIMEOUT", ")", "$", "Error", "=", "array", "(", "'error'", "=>", "'invalid_request'", ",", "'message'", "=>", "'The timestamp is invalid.'", ")", ";", "else", "{", "// Make sure the timestamp hasn't timed out.", "$", "Signature", "=", "self", "::", "JsHash", "(", "$", "Request", "[", "'timestamp'", "]", ".", "$", "Secret", ",", "$", "Secure", ")", ";", "if", "(", "$", "Signature", "!=", "$", "Request", "[", "'signature'", "]", ")", "$", "Error", "=", "array", "(", "'error'", "=>", "'access_denied'", ",", "'message'", "=>", "'Signature invalid.'", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "Error", ")", ")", "$", "Result", "=", "$", "Error", ";", "elseif", "(", "is_array", "(", "$", "User", ")", "&&", "count", "(", "$", "User", ")", ">", "0", ")", "{", "if", "(", "$", "Secure", "===", "NULL", ")", "{", "$", "Result", "=", "$", "User", ";", "}", "else", "{", "$", "Result", "=", "self", "::", "SignJsConnect", "(", "$", "User", ",", "$", "ClientID", ",", "$", "Secret", ",", "$", "Secure", ",", "TRUE", ")", ";", "}", "}", "else", "$", "Result", "=", "array", "(", "'name'", "=>", "''", ",", "'photourl'", "=>", "''", ")", ";", "$", "Json", "=", "json_encode", "(", "$", "Result", ")", ";", "if", "(", "isset", "(", "$", "Request", "[", "'callback'", "]", ")", ")", "return", "\"{$Request['callback']}($Json)\"", ";", "else", "return", "$", "Json", ";", "}" ]
Write the jsConnect string for single sign on. @param array $User An array containing information about the currently signed on user. If no user is signed in then this should be an empty array. @param array $Request An array of the $_GET request. @param string|bool $Secure Whether or not to check for security. This is one of these values. - true: Check for security and sign the response with an md5 hash. - false: Don't check for security, but sign the response with an md5 hash. - string: Check for security and sign the response with the given hash algorithm. See hash_algos() for what your server can support. - null: Don't check for security and don't sign the response. @since 1.1b Added the ability to provide a hash algorithm to $Secure. @return string JSON response formatted.
[ "Write", "the", "jsConnect", "string", "for", "single", "sign", "on", "." ]
train
https://github.com/pdefreitas/Laravel-VanillaSSO/blob/f47a7c33eaf392fb6564a909f622b36ffd373759/src/Pdefreitas/VanillaSSO/VanillaSSO.php#L38-L89
pdefreitas/Laravel-VanillaSSO
src/Pdefreitas/VanillaSSO/VanillaSSO.php
VanillaSSO.JsHash
protected static function JsHash($String, $Secure = TRUE) { if ($Secure === TRUE) $Secure = 'md5'; switch ($Secure) { case 'sha1': return sha1($String); break; case 'md5': case FALSE: return md5($String); default: return hash($Secure, $String); } }
php
protected static function JsHash($String, $Secure = TRUE) { if ($Secure === TRUE) $Secure = 'md5'; switch ($Secure) { case 'sha1': return sha1($String); break; case 'md5': case FALSE: return md5($String); default: return hash($Secure, $String); } }
[ "protected", "static", "function", "JsHash", "(", "$", "String", ",", "$", "Secure", "=", "TRUE", ")", "{", "if", "(", "$", "Secure", "===", "TRUE", ")", "$", "Secure", "=", "'md5'", ";", "switch", "(", "$", "Secure", ")", "{", "case", "'sha1'", ":", "return", "sha1", "(", "$", "String", ")", ";", "break", ";", "case", "'md5'", ":", "case", "FALSE", ":", "return", "md5", "(", "$", "String", ")", ";", "default", ":", "return", "hash", "(", "$", "Secure", ",", "$", "String", ")", ";", "}", "}" ]
Return the hash of a string. @param string $String The string to hash. @param string|bool $Secure The hash algorithm to use. TRUE means md5. @return string @since 1.1b
[ "Return", "the", "hash", "of", "a", "string", "." ]
train
https://github.com/pdefreitas/Laravel-VanillaSSO/blob/f47a7c33eaf392fb6564a909f622b36ffd373759/src/Pdefreitas/VanillaSSO/VanillaSSO.php#L121-L136
pdefreitas/Laravel-VanillaSSO
src/Pdefreitas/VanillaSSO/VanillaSSO.php
VanillaSSO.JsSSOString
protected static function JsSSOString($User, $ClientID, $Secret) { if (!isset($User['client_id'])) $User['client_id'] = $ClientID; $String = base64_encode(json_encode($User)); $Timestamp = time(); $Hash = hash_hmac('sha1', "$String $Timestamp", $Secret); $Result = "$String $Hash $Timestamp hmacsha1"; return $Result; }
php
protected static function JsSSOString($User, $ClientID, $Secret) { if (!isset($User['client_id'])) $User['client_id'] = $ClientID; $String = base64_encode(json_encode($User)); $Timestamp = time(); $Hash = hash_hmac('sha1', "$String $Timestamp", $Secret); $Result = "$String $Hash $Timestamp hmacsha1"; return $Result; }
[ "protected", "static", "function", "JsSSOString", "(", "$", "User", ",", "$", "ClientID", ",", "$", "Secret", ")", "{", "if", "(", "!", "isset", "(", "$", "User", "[", "'client_id'", "]", ")", ")", "$", "User", "[", "'client_id'", "]", "=", "$", "ClientID", ";", "$", "String", "=", "base64_encode", "(", "json_encode", "(", "$", "User", ")", ")", ";", "$", "Timestamp", "=", "time", "(", ")", ";", "$", "Hash", "=", "hash_hmac", "(", "'sha1'", ",", "\"$String $Timestamp\"", ",", "$", "Secret", ")", ";", "$", "Result", "=", "\"$String $Hash $Timestamp hmacsha1\"", ";", "return", "$", "Result", ";", "}" ]
Generate an SSO string suitible for passing in the url for embedded SSO. @param array $User The user to sso. @param string $ClientID Your client ID. @param string $Secret Your secret. @return string
[ "Generate", "an", "SSO", "string", "suitible", "for", "passing", "in", "the", "url", "for", "embedded", "SSO", "." ]
train
https://github.com/pdefreitas/Laravel-VanillaSSO/blob/f47a7c33eaf392fb6564a909f622b36ffd373759/src/Pdefreitas/VanillaSSO/VanillaSSO.php#L151-L162
prooph/link-app-core
src/Service/ActionControllerInitializer.php
ActionControllerInitializer.initialize
public function initialize($instance, ServiceLocatorInterface $serviceLocator) { if ($instance instanceof ActionController) { //We are dealing with a ControllerManager so we need to get the main service manger first $instance->setCommandBus($serviceLocator->getServiceLocator()->get('proophessor.command_bus')); } }
php
public function initialize($instance, ServiceLocatorInterface $serviceLocator) { if ($instance instanceof ActionController) { //We are dealing with a ControllerManager so we need to get the main service manger first $instance->setCommandBus($serviceLocator->getServiceLocator()->get('proophessor.command_bus')); } }
[ "public", "function", "initialize", "(", "$", "instance", ",", "ServiceLocatorInterface", "$", "serviceLocator", ")", "{", "if", "(", "$", "instance", "instanceof", "ActionController", ")", "{", "//We are dealing with a ControllerManager so we need to get the main service manger first", "$", "instance", "->", "setCommandBus", "(", "$", "serviceLocator", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'proophessor.command_bus'", ")", ")", ";", "}", "}" ]
Initialize @param $instance @param ServiceLocatorInterface $serviceLocator @return mixed
[ "Initialize" ]
train
https://github.com/prooph/link-app-core/blob/835a5945dfa7be7b2cebfa6e84e757ecfd783357/src/Service/ActionControllerInitializer.php#L31-L37
fuelphp/display
src/DataContainer.php
DataContainer.getData
public function getData() { $data = $this->data; foreach ($data as $key => $value) { if (is_object($value) and $this->isWhitelisted($value)) { continue; } if ($this->shouldBeFiltered($key)) { if ($value instanceof Sanitize) { $data[$key] = $value->sanitize(); } else { $data[$key] = $this->filter($value); } } } return $data; }
php
public function getData() { $data = $this->data; foreach ($data as $key => $value) { if (is_object($value) and $this->isWhitelisted($value)) { continue; } if ($this->shouldBeFiltered($key)) { if ($value instanceof Sanitize) { $data[$key] = $value->sanitize(); } else { $data[$key] = $this->filter($value); } } } return $data; }
[ "public", "function", "getData", "(", ")", "{", "$", "data", "=", "$", "this", "->", "data", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", "and", "$", "this", "->", "isWhitelisted", "(", "$", "value", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "this", "->", "shouldBeFiltered", "(", "$", "key", ")", ")", "{", "if", "(", "$", "value", "instanceof", "Sanitize", ")", "{", "$", "data", "[", "$", "key", "]", "=", "$", "value", "->", "sanitize", "(", ")", ";", "}", "else", "{", "$", "data", "[", "$", "key", "]", "=", "$", "this", "->", "filter", "(", "$", "value", ")", ";", "}", "}", "}", "return", "$", "data", ";", "}" ]
Retrieves all the view data @return array
[ "Retrieves", "all", "the", "view", "data" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L62-L87
fuelphp/display
src/DataContainer.php
DataContainer.shouldBeFiltered
protected function shouldBeFiltered($key) { if (isset($this->filterIndex[$key])) { return $this->filterIndex[$key]; } return $this->autoFilter; }
php
protected function shouldBeFiltered($key) { if (isset($this->filterIndex[$key])) { return $this->filterIndex[$key]; } return $this->autoFilter; }
[ "protected", "function", "shouldBeFiltered", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "filterIndex", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "filterIndex", "[", "$", "key", "]", ";", "}", "return", "$", "this", "->", "autoFilter", ";", "}" ]
Checks if a key should be filtered or not Uses filterIndex and autoFilter @param string $key @return boolean
[ "Checks", "if", "a", "key", "should", "be", "filtered", "or", "not" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L98-L106
fuelphp/display
src/DataContainer.php
DataContainer.isWhitelisted
protected function isWhitelisted($object) { foreach ($this->whitelist as $whitelisted) { if ($object instanceof $whitelisted) { return true; } } return false; }
php
protected function isWhitelisted($object) { foreach ($this->whitelist as $whitelisted) { if ($object instanceof $whitelisted) { return true; } } return false; }
[ "protected", "function", "isWhitelisted", "(", "$", "object", ")", "{", "foreach", "(", "$", "this", "->", "whitelist", "as", "$", "whitelisted", ")", "{", "if", "(", "$", "object", "instanceof", "$", "whitelisted", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if an object is whitelisted @param object $object @return boolean
[ "Checks", "if", "an", "object", "is", "whitelisted" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L115-L126
fuelphp/display
src/DataContainer.php
DataContainer.filter
public function filter($value) { if (is_array($value) or (is_object($value) and $value instanceof \ArrayAccess)) { return array_map([$this, 'filter'], $value); } return htmlentities($value, ENT_QUOTES | ENT_HTML5); }
php
public function filter($value) { if (is_array($value) or (is_object($value) and $value instanceof \ArrayAccess)) { return array_map([$this, 'filter'], $value); } return htmlentities($value, ENT_QUOTES | ENT_HTML5); }
[ "public", "function", "filter", "(", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "or", "(", "is_object", "(", "$", "value", ")", "and", "$", "value", "instanceof", "\\", "ArrayAccess", ")", ")", "{", "return", "array_map", "(", "[", "$", "this", ",", "'filter'", "]", ",", "$", "value", ")", ";", "}", "return", "htmlentities", "(", "$", "value", ",", "ENT_QUOTES", "|", "ENT_HTML5", ")", ";", "}" ]
Filters the output @param mixed $value @return string
[ "Filters", "the", "output" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L135-L143
fuelphp/display
src/DataContainer.php
DataContainer.set
public function set($key, $value = null, $filter = null) { parent::set($key, $value); if (is_array($key)) { if (is_bool($value)) { $filter = $value; } foreach ($key as $_key => $_value) { $this->filterIndex[$_key] = $filter; } } else { $this->filterIndex[$key] = $filter; } return $this; }
php
public function set($key, $value = null, $filter = null) { parent::set($key, $value); if (is_array($key)) { if (is_bool($value)) { $filter = $value; } foreach ($key as $_key => $_value) { $this->filterIndex[$_key] = $filter; } } else { $this->filterIndex[$key] = $filter; } return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", "=", "null", ",", "$", "filter", "=", "null", ")", "{", "parent", "::", "set", "(", "$", "key", ",", "$", "value", ")", ";", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "filter", "=", "$", "value", ";", "}", "foreach", "(", "$", "key", "as", "$", "_key", "=>", "$", "_value", ")", "{", "$", "this", "->", "filterIndex", "[", "$", "_key", "]", "=", "$", "filter", ";", "}", "}", "else", "{", "$", "this", "->", "filterIndex", "[", "$", "key", "]", "=", "$", "filter", ";", "}", "return", "$", "this", ";", "}" ]
Sets view data @param string|array $key @param mixed $value @param boolean $filter @return $this
[ "Sets", "view", "data" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L154-L176
fuelphp/display
src/DataContainer.php
DataContainer.merge
public function merge($arg) { call_user_func_array('parent::merge', func_get_args()); $arguments = array_map(function ($array) use (&$valid) { if ($array instanceof DataContainer) { return $array->filterIndex; } return []; }, func_get_args()); array_unshift($arguments, $this->filterIndex); $this->filterIndex = call_user_func_array('array_merge', $arguments); return $this; }
php
public function merge($arg) { call_user_func_array('parent::merge', func_get_args()); $arguments = array_map(function ($array) use (&$valid) { if ($array instanceof DataContainer) { return $array->filterIndex; } return []; }, func_get_args()); array_unshift($arguments, $this->filterIndex); $this->filterIndex = call_user_func_array('array_merge', $arguments); return $this; }
[ "public", "function", "merge", "(", "$", "arg", ")", "{", "call_user_func_array", "(", "'parent::merge'", ",", "func_get_args", "(", ")", ")", ";", "$", "arguments", "=", "array_map", "(", "function", "(", "$", "array", ")", "use", "(", "&", "$", "valid", ")", "{", "if", "(", "$", "array", "instanceof", "DataContainer", ")", "{", "return", "$", "array", "->", "filterIndex", ";", "}", "return", "[", "]", ";", "}", ",", "func_get_args", "(", ")", ")", ";", "array_unshift", "(", "$", "arguments", ",", "$", "this", "->", "filterIndex", ")", ";", "$", "this", "->", "filterIndex", "=", "call_user_func_array", "(", "'array_merge'", ",", "$", "arguments", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L181-L200
fuelphp/display
src/DataContainer.php
DataContainer.replaceData
public function replaceData(array $data, $filter = null) { $this->clearData(); return $this->set($data, $filter); }
php
public function replaceData(array $data, $filter = null) { $this->clearData(); return $this->set($data, $filter); }
[ "public", "function", "replaceData", "(", "array", "$", "data", ",", "$", "filter", "=", "null", ")", "{", "$", "this", "->", "clearData", "(", ")", ";", "return", "$", "this", "->", "set", "(", "$", "data", ",", "$", "filter", ")", ";", "}" ]
Overwrites all the view data @param array $data @param boolean $filter @return $this
[ "Overwrites", "all", "the", "view", "data" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L223-L228
fuelphp/display
src/DataContainer.php
DataContainer.bind
public function bind($key, &$value, $filter = null) { if ($this->readOnly) { throw new \RuntimeException('Changing values on this Data Container is not allowed.'); } $this->data[$key] =& $value; $this->filterIndex[$key] = $filter; $this->isModified = true; return $this; }
php
public function bind($key, &$value, $filter = null) { if ($this->readOnly) { throw new \RuntimeException('Changing values on this Data Container is not allowed.'); } $this->data[$key] =& $value; $this->filterIndex[$key] = $filter; $this->isModified = true; return $this; }
[ "public", "function", "bind", "(", "$", "key", ",", "&", "$", "value", ",", "$", "filter", "=", "null", ")", "{", "if", "(", "$", "this", "->", "readOnly", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Changing values on this Data Container is not allowed.'", ")", ";", "}", "$", "this", "->", "data", "[", "$", "key", "]", "=", "&", "$", "value", ";", "$", "this", "->", "filterIndex", "[", "$", "key", "]", "=", "$", "filter", ";", "$", "this", "->", "isModified", "=", "true", ";", "return", "$", "this", ";", "}" ]
Assigns a value by reference. The benefit of binding is that values can be altered without re-setting them. It is also possible to bind variables before they have values. Assigned values will be available as a variable within the view file: // This reference can be accessed as $ref within the object $obj->bind('ref', $bar); @param string $key Variable name @param mixed $value Referenced variable @param boolean $filter Whether to filter the var on output @return $this
[ "Assigns", "a", "value", "by", "reference", ".", "The", "benefit", "of", "binding", "is", "that", "values", "can", "be", "altered", "without", "re", "-", "setting", "them", ".", "It", "is", "also", "possible", "to", "bind", "variables", "before", "they", "have", "values", ".", "Assigned", "values", "will", "be", "available", "as", "a", "variable", "within", "the", "view", "file", ":" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/DataContainer.php#L245-L257
FrenchFrogs/framework
src/Table/Column/Column.php
Column.setTable
public function setTable(\FrenchFrogs\Table\Table\Table $table) { $this->table = $table; return $this; }
php
public function setTable(\FrenchFrogs\Table\Table\Table $table) { $this->table = $table; return $this; }
[ "public", "function", "setTable", "(", "\\", "FrenchFrogs", "\\", "Table", "\\", "Table", "\\", "Table", "$", "table", ")", "{", "$", "this", "->", "table", "=", "$", "table", ";", "return", "$", "this", ";", "}" ]
Setter for $table property @param \FrenchFrogs\Table\Table\Table $table @return $this
[ "Setter", "for", "$table", "property" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Column.php#L154-L158
FrenchFrogs/framework
src/Table/Column/Column.php
Column.order
public function order($direction = null) { if (is_null($direction)) { $direction = $this->getOrderDirection(); } else { $this->setOrderDirection($direction); } // if a direction is set if (!empty($direction)) { if (!is_string($this->order) && is_callable($this->order)) { call_user_func_array($this->order, $this); } else { $table = $this->getTable(); // verify that source is a query if (!$table->isSourceQueryBuilder()) { throw new \Exception('Table source is not an instance of query builder'); } $table->getSource()->orderBy($this->order, $direction); } } return $this; }
php
public function order($direction = null) { if (is_null($direction)) { $direction = $this->getOrderDirection(); } else { $this->setOrderDirection($direction); } // if a direction is set if (!empty($direction)) { if (!is_string($this->order) && is_callable($this->order)) { call_user_func_array($this->order, $this); } else { $table = $this->getTable(); // verify that source is a query if (!$table->isSourceQueryBuilder()) { throw new \Exception('Table source is not an instance of query builder'); } $table->getSource()->orderBy($this->order, $direction); } } return $this; }
[ "public", "function", "order", "(", "$", "direction", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "direction", ")", ")", "{", "$", "direction", "=", "$", "this", "->", "getOrderDirection", "(", ")", ";", "}", "else", "{", "$", "this", "->", "setOrderDirection", "(", "$", "direction", ")", ";", "}", "// if a direction is set", "if", "(", "!", "empty", "(", "$", "direction", ")", ")", "{", "if", "(", "!", "is_string", "(", "$", "this", "->", "order", ")", "&&", "is_callable", "(", "$", "this", "->", "order", ")", ")", "{", "call_user_func_array", "(", "$", "this", "->", "order", ",", "$", "this", ")", ";", "}", "else", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "// verify that source is a query", "if", "(", "!", "$", "table", "->", "isSourceQueryBuilder", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Table source is not an instance of query builder'", ")", ";", "}", "$", "table", "->", "getSource", "(", ")", "->", "orderBy", "(", "$", "this", "->", "order", ",", "$", "direction", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Order process for the column @param $direction (asc or desc) @return $this @throws \Exception
[ "Order", "process", "for", "the", "column" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Column.php#L346-L372
FrenchFrogs/framework
src/Table/Column/Column.php
Column.setOrderDirection
public function setOrderDirection($direction) { $direction = strtolower($direction); if (!in_array($direction, ['asc', 'desc'])) { throw new \InvalidArgumentException('$direction must be "asc" or "desc"'); } $this->orderDirection = $direction; return $this; }
php
public function setOrderDirection($direction) { $direction = strtolower($direction); if (!in_array($direction, ['asc', 'desc'])) { throw new \InvalidArgumentException('$direction must be "asc" or "desc"'); } $this->orderDirection = $direction; return $this; }
[ "public", "function", "setOrderDirection", "(", "$", "direction", ")", "{", "$", "direction", "=", "strtolower", "(", "$", "direction", ")", ";", "if", "(", "!", "in_array", "(", "$", "direction", ",", "[", "'asc'", ",", "'desc'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$direction must be \"asc\" or \"desc\"'", ")", ";", "}", "$", "this", "->", "orderDirection", "=", "$", "direction", ";", "return", "$", "this", ";", "}" ]
Setter for $orderDirection attribute @param $direction @return $this
[ "Setter", "for", "$orderDirection", "attribute" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Column.php#L380-L391
FrenchFrogs/framework
src/Table/Column/Column.php
Column.isVisible
public function isVisible($row = null) { $callable = !is_bool($this->visible) && !is_string($this->visible) && is_callable($this->visible); return (bool) ($callable ? call_user_func($this->visible, $this, $row) : $this->visible); }
php
public function isVisible($row = null) { $callable = !is_bool($this->visible) && !is_string($this->visible) && is_callable($this->visible); return (bool) ($callable ? call_user_func($this->visible, $this, $row) : $this->visible); }
[ "public", "function", "isVisible", "(", "$", "row", "=", "null", ")", "{", "$", "callable", "=", "!", "is_bool", "(", "$", "this", "->", "visible", ")", "&&", "!", "is_string", "(", "$", "this", "->", "visible", ")", "&&", "is_callable", "(", "$", "this", "->", "visible", ")", ";", "return", "(", "bool", ")", "(", "$", "callable", "?", "call_user_func", "(", "$", "this", "->", "visible", ",", "$", "this", ",", "$", "row", ")", ":", "$", "this", "->", "visible", ")", ";", "}" ]
Return if the columns is visible @param $row @return bool
[ "Return", "if", "the", "columns", "is", "visible" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Column.php#L466-L470
tonicospinelli/class-generation
src/ClassGeneration/CompositionCollection.php
CompositionCollection.toString
public function toString() { if ($this->isEmpty()) { return ''; } $traitNames = $this->toArray(); $tabulationFormatted = $this->getTabulationFormatted(); $compositionMethods = ';' . PHP_EOL; if (!$this->getMethods()->isEmpty()) { $compositionMethods = ' ' . $this->getMethods()->toString(); } return $tabulationFormatted . 'use ' . implode(', ', $traitNames) . $compositionMethods; }
php
public function toString() { if ($this->isEmpty()) { return ''; } $traitNames = $this->toArray(); $tabulationFormatted = $this->getTabulationFormatted(); $compositionMethods = ';' . PHP_EOL; if (!$this->getMethods()->isEmpty()) { $compositionMethods = ' ' . $this->getMethods()->toString(); } return $tabulationFormatted . 'use ' . implode(', ', $traitNames) . $compositionMethods; }
[ "public", "function", "toString", "(", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "''", ";", "}", "$", "traitNames", "=", "$", "this", "->", "toArray", "(", ")", ";", "$", "tabulationFormatted", "=", "$", "this", "->", "getTabulationFormatted", "(", ")", ";", "$", "compositionMethods", "=", "';'", ".", "PHP_EOL", ";", "if", "(", "!", "$", "this", "->", "getMethods", "(", ")", "->", "isEmpty", "(", ")", ")", "{", "$", "compositionMethods", "=", "' '", ".", "$", "this", "->", "getMethods", "(", ")", "->", "toString", "(", ")", ";", "}", "return", "$", "tabulationFormatted", ".", "'use '", ".", "implode", "(", "', '", ",", "$", "traitNames", ")", ".", "$", "compositionMethods", ";", "}" ]
Parse the Composition Collection to string. @return string
[ "Parse", "the", "Composition", "Collection", "to", "string", "." ]
train
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/CompositionCollection.php#L130-L145
czim/laravel-pxlcms
src/Generator/Analyzer/Steps/CheckTables.php
CheckTables.checkRequiredTables
protected function checkRequiredTables() { // check if relevant tables are present in the list foreach ([ config('pxlcms.tables.meta.modules'), config('pxlcms.tables.meta.fields'), config('pxlcms.tables.meta.field_options_choices'), //config('pxlcms.tables.meta.groups'), //config('pxlcms.tables.meta.sections'), //config('pxlcms.tables.meta.field_types'), //config('pxlcms.tables.meta.tabs'), //config('pxlcms.tables.meta.users'), //config('pxlcms.tables.meta.field_options_resizes'), config('pxlcms.tables.languages'), config('pxlcms.tables.categories'), config('pxlcms.tables.files'), config('pxlcms.tables.images'), config('pxlcms.tables.references'), config('pxlcms.tables.checkboxes'), //config('pxlcms.tables.slugs'), ] as $checkTable ) { if ( ! in_array($checkTable, $this->tables)) { throw new Exception("Could not find expected CMS table in database: '{$checkTable}'"); } } }
php
protected function checkRequiredTables() { // check if relevant tables are present in the list foreach ([ config('pxlcms.tables.meta.modules'), config('pxlcms.tables.meta.fields'), config('pxlcms.tables.meta.field_options_choices'), //config('pxlcms.tables.meta.groups'), //config('pxlcms.tables.meta.sections'), //config('pxlcms.tables.meta.field_types'), //config('pxlcms.tables.meta.tabs'), //config('pxlcms.tables.meta.users'), //config('pxlcms.tables.meta.field_options_resizes'), config('pxlcms.tables.languages'), config('pxlcms.tables.categories'), config('pxlcms.tables.files'), config('pxlcms.tables.images'), config('pxlcms.tables.references'), config('pxlcms.tables.checkboxes'), //config('pxlcms.tables.slugs'), ] as $checkTable ) { if ( ! in_array($checkTable, $this->tables)) { throw new Exception("Could not find expected CMS table in database: '{$checkTable}'"); } } }
[ "protected", "function", "checkRequiredTables", "(", ")", "{", "// check if relevant tables are present in the list", "foreach", "(", "[", "config", "(", "'pxlcms.tables.meta.modules'", ")", ",", "config", "(", "'pxlcms.tables.meta.fields'", ")", ",", "config", "(", "'pxlcms.tables.meta.field_options_choices'", ")", ",", "//config('pxlcms.tables.meta.groups'),", "//config('pxlcms.tables.meta.sections'),", "//config('pxlcms.tables.meta.field_types'),", "//config('pxlcms.tables.meta.tabs'),", "//config('pxlcms.tables.meta.users'),", "//config('pxlcms.tables.meta.field_options_resizes'),", "config", "(", "'pxlcms.tables.languages'", ")", ",", "config", "(", "'pxlcms.tables.categories'", ")", ",", "config", "(", "'pxlcms.tables.files'", ")", ",", "config", "(", "'pxlcms.tables.images'", ")", ",", "config", "(", "'pxlcms.tables.references'", ")", ",", "config", "(", "'pxlcms.tables.checkboxes'", ")", ",", "//config('pxlcms.tables.slugs'),", "]", "as", "$", "checkTable", ")", "{", "if", "(", "!", "in_array", "(", "$", "checkTable", ",", "$", "this", "->", "tables", ")", ")", "{", "throw", "new", "Exception", "(", "\"Could not find expected CMS table in database: '{$checkTable}'\"", ")", ";", "}", "}", "}" ]
Checks if all required tables are present @throws Exception if a table is not found
[ "Checks", "if", "all", "required", "tables", "are", "present" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Analyzer/Steps/CheckTables.php#L35-L65
czim/laravel-pxlcms
src/Generator/Analyzer/Steps/CheckTables.php
CheckTables.detectSlugStructure
protected function detectSlugStructure() { $this->context->slugStructurePresent = false; $slugsTable = config('pxlcms.slugs.table'); if ( ! in_array($slugsTable, $this->tables)) { $this->context->log("No slugs table detected."); return; } // the table exists.. does it have the content we need / expect? // Note: cannot escape/PDO this, so be careful with your config $columns = $this->loadColumnListForTable($slugsTable); foreach ([ config('pxlcms.slugs.keys.module'), config('pxlcms.slugs.keys.entry'), config('pxlcms.slugs.keys.language'), ] as $requiredColumn ) { if (in_array($requiredColumn, $columns)) continue; // column does not exist! $this->context->log( "Slugs table detected but not usable for Sluggable handling!" . " Missing required column '{$requiredColumn}'.", Generator::LOG_LEVEL_WARNING ); return; } $this->context->slugStructurePresent = true; $this->context->log("Slugs table detected and considered usable for Sluggable handling."); }
php
protected function detectSlugStructure() { $this->context->slugStructurePresent = false; $slugsTable = config('pxlcms.slugs.table'); if ( ! in_array($slugsTable, $this->tables)) { $this->context->log("No slugs table detected."); return; } // the table exists.. does it have the content we need / expect? // Note: cannot escape/PDO this, so be careful with your config $columns = $this->loadColumnListForTable($slugsTable); foreach ([ config('pxlcms.slugs.keys.module'), config('pxlcms.slugs.keys.entry'), config('pxlcms.slugs.keys.language'), ] as $requiredColumn ) { if (in_array($requiredColumn, $columns)) continue; // column does not exist! $this->context->log( "Slugs table detected but not usable for Sluggable handling!" . " Missing required column '{$requiredColumn}'.", Generator::LOG_LEVEL_WARNING ); return; } $this->context->slugStructurePresent = true; $this->context->log("Slugs table detected and considered usable for Sluggable handling."); }
[ "protected", "function", "detectSlugStructure", "(", ")", "{", "$", "this", "->", "context", "->", "slugStructurePresent", "=", "false", ";", "$", "slugsTable", "=", "config", "(", "'pxlcms.slugs.table'", ")", ";", "if", "(", "!", "in_array", "(", "$", "slugsTable", ",", "$", "this", "->", "tables", ")", ")", "{", "$", "this", "->", "context", "->", "log", "(", "\"No slugs table detected.\"", ")", ";", "return", ";", "}", "// the table exists.. does it have the content we need / expect?", "// Note: cannot escape/PDO this, so be careful with your config", "$", "columns", "=", "$", "this", "->", "loadColumnListForTable", "(", "$", "slugsTable", ")", ";", "foreach", "(", "[", "config", "(", "'pxlcms.slugs.keys.module'", ")", ",", "config", "(", "'pxlcms.slugs.keys.entry'", ")", ",", "config", "(", "'pxlcms.slugs.keys.language'", ")", ",", "]", "as", "$", "requiredColumn", ")", "{", "if", "(", "in_array", "(", "$", "requiredColumn", ",", "$", "columns", ")", ")", "continue", ";", "// column does not exist!", "$", "this", "->", "context", "->", "log", "(", "\"Slugs table detected but not usable for Sluggable handling!\"", ".", "\" Missing required column '{$requiredColumn}'.\"", ",", "Generator", "::", "LOG_LEVEL_WARNING", ")", ";", "return", ";", "}", "$", "this", "->", "context", "->", "slugStructurePresent", "=", "true", ";", "$", "this", "->", "context", "->", "log", "(", "\"Slugs table detected and considered usable for Sluggable handling.\"", ")", ";", "}" ]
Detects whether this CMS has the 'typical' slug table setup
[ "Detects", "whether", "this", "CMS", "has", "the", "typical", "slug", "table", "setup" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Analyzer/Steps/CheckTables.php#L70-L105
czim/laravel-pxlcms
src/Generator/Analyzer/Steps/CheckTables.php
CheckTables.loadTableList
protected function loadTableList() { if ($this->getDatabaseDriver() === 'sqlite') { $statement = "SELECT name FROM sqlite_master WHERE type='table';"; } else { $statement = 'SHOW TABLES'; } $tables = DB::select($statement); $this->tables = []; foreach ($tables as $tableObject) { $this->tables[] = array_get(array_values((array) $tableObject), '0'); } }
php
protected function loadTableList() { if ($this->getDatabaseDriver() === 'sqlite') { $statement = "SELECT name FROM sqlite_master WHERE type='table';"; } else { $statement = 'SHOW TABLES'; } $tables = DB::select($statement); $this->tables = []; foreach ($tables as $tableObject) { $this->tables[] = array_get(array_values((array) $tableObject), '0'); } }
[ "protected", "function", "loadTableList", "(", ")", "{", "if", "(", "$", "this", "->", "getDatabaseDriver", "(", ")", "===", "'sqlite'", ")", "{", "$", "statement", "=", "\"SELECT name FROM sqlite_master WHERE type='table';\"", ";", "}", "else", "{", "$", "statement", "=", "'SHOW TABLES'", ";", "}", "$", "tables", "=", "DB", "::", "select", "(", "$", "statement", ")", ";", "$", "this", "->", "tables", "=", "[", "]", ";", "foreach", "(", "$", "tables", "as", "$", "tableObject", ")", "{", "$", "this", "->", "tables", "[", "]", "=", "array_get", "(", "array_values", "(", "(", "array", ")", "$", "tableObject", ")", ",", "'0'", ")", ";", "}", "}" ]
Caches the list of tables in the database
[ "Caches", "the", "list", "of", "tables", "in", "the", "database" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Analyzer/Steps/CheckTables.php#L149-L165
czim/laravel-pxlcms
src/Generator/Analyzer/Steps/CheckTables.php
CheckTables.loadColumnListForTable
protected function loadColumnListForTable($table) { if ($this->getDatabaseDriver() === 'sqlite') { $statement = "PRAGMA table_info(`{$table}`)"; } else { $statement = "SHOW columns FROM `{$table}`"; } $columnResults = DB::select($statement); $columns = []; foreach ($columnResults as $columnObject) { $columns[] = array_get(array_values((array) $columnObject), '0'); } return $columns; }
php
protected function loadColumnListForTable($table) { if ($this->getDatabaseDriver() === 'sqlite') { $statement = "PRAGMA table_info(`{$table}`)"; } else { $statement = "SHOW columns FROM `{$table}`"; } $columnResults = DB::select($statement); $columns = []; foreach ($columnResults as $columnObject) { $columns[] = array_get(array_values((array) $columnObject), '0'); } return $columns; }
[ "protected", "function", "loadColumnListForTable", "(", "$", "table", ")", "{", "if", "(", "$", "this", "->", "getDatabaseDriver", "(", ")", "===", "'sqlite'", ")", "{", "$", "statement", "=", "\"PRAGMA table_info(`{$table}`)\"", ";", "}", "else", "{", "$", "statement", "=", "\"SHOW columns FROM `{$table}`\"", ";", "}", "$", "columnResults", "=", "DB", "::", "select", "(", "$", "statement", ")", ";", "$", "columns", "=", "[", "]", ";", "foreach", "(", "$", "columnResults", "as", "$", "columnObject", ")", "{", "$", "columns", "[", "]", "=", "array_get", "(", "array_values", "(", "(", "array", ")", "$", "columnObject", ")", ",", "'0'", ")", ";", "}", "return", "$", "columns", ";", "}" ]
Returns the column names for a table @param string $table @return array
[ "Returns", "the", "column", "names", "for", "a", "table" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Analyzer/Steps/CheckTables.php#L173-L190
gregorybesson/PlaygroundCore
src/Mail/Service/Message.php
Message.createHtmlMessage
public function createHtmlMessage($from, $to, $subject, $nameOrModel, $values = array()) { if (is_string($from)) { $from = array('email' => $from, 'name' => $from); } $renderer = $this->getRenderer(); $content = $renderer->render($nameOrModel, $values); $resolver = $this->serviceLocator->get('Zend\View\Resolver\TemplatePathStack'); // check if plain text email template exist if ($resolver->resolve($nameOrModel . '-plain')) { $contentText = $renderer->render($nameOrModel . '-plain', $values); } else { $contentText = ''; } $mail = new MailMessage(); $mail->addTo($to); $mail->addFrom($from['email'], $from['name']); $mail->setSubject($subject); $text = new Part($contentText); $text->type = Mime::TYPE_TEXT; $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $text->disposition = Mime::DISPOSITION_INLINE; $text->charset = 'UTF-8'; $html = new Part($content); $html->type = Mime::TYPE_HTML; $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $html->disposition = Mime::DISPOSITION_INLINE; $html->charset = 'UTF-8'; $bodyMessage = new MimeMessage(); $multiPartContentMessage = new MimeMessage(); $multiPartContentMessage->addPart($text); $multiPartContentMessage->addPart($html); $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage()); $multiPartContentMimePart->charset = 'UTF-8'; $multiPartContentMimePart->type = 'multipart/alternative'; $multiPartContentMimePart->boundary = $multiPartContentMessage->getMime()->boundary(); $bodyMessage->addPart($multiPartContentMimePart); $mail->setBody($bodyMessage); $mail->setEncoding('UTF-8'); return $mail; }
php
public function createHtmlMessage($from, $to, $subject, $nameOrModel, $values = array()) { if (is_string($from)) { $from = array('email' => $from, 'name' => $from); } $renderer = $this->getRenderer(); $content = $renderer->render($nameOrModel, $values); $resolver = $this->serviceLocator->get('Zend\View\Resolver\TemplatePathStack'); // check if plain text email template exist if ($resolver->resolve($nameOrModel . '-plain')) { $contentText = $renderer->render($nameOrModel . '-plain', $values); } else { $contentText = ''; } $mail = new MailMessage(); $mail->addTo($to); $mail->addFrom($from['email'], $from['name']); $mail->setSubject($subject); $text = new Part($contentText); $text->type = Mime::TYPE_TEXT; $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $text->disposition = Mime::DISPOSITION_INLINE; $text->charset = 'UTF-8'; $html = new Part($content); $html->type = Mime::TYPE_HTML; $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $html->disposition = Mime::DISPOSITION_INLINE; $html->charset = 'UTF-8'; $bodyMessage = new MimeMessage(); $multiPartContentMessage = new MimeMessage(); $multiPartContentMessage->addPart($text); $multiPartContentMessage->addPart($html); $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage()); $multiPartContentMimePart->charset = 'UTF-8'; $multiPartContentMimePart->type = 'multipart/alternative'; $multiPartContentMimePart->boundary = $multiPartContentMessage->getMime()->boundary(); $bodyMessage->addPart($multiPartContentMimePart); $mail->setBody($bodyMessage); $mail->setEncoding('UTF-8'); return $mail; }
[ "public", "function", "createHtmlMessage", "(", "$", "from", ",", "$", "to", ",", "$", "subject", ",", "$", "nameOrModel", ",", "$", "values", "=", "array", "(", ")", ")", "{", "if", "(", "is_string", "(", "$", "from", ")", ")", "{", "$", "from", "=", "array", "(", "'email'", "=>", "$", "from", ",", "'name'", "=>", "$", "from", ")", ";", "}", "$", "renderer", "=", "$", "this", "->", "getRenderer", "(", ")", ";", "$", "content", "=", "$", "renderer", "->", "render", "(", "$", "nameOrModel", ",", "$", "values", ")", ";", "$", "resolver", "=", "$", "this", "->", "serviceLocator", "->", "get", "(", "'Zend\\View\\Resolver\\TemplatePathStack'", ")", ";", "// check if plain text email template exist", "if", "(", "$", "resolver", "->", "resolve", "(", "$", "nameOrModel", ".", "'-plain'", ")", ")", "{", "$", "contentText", "=", "$", "renderer", "->", "render", "(", "$", "nameOrModel", ".", "'-plain'", ",", "$", "values", ")", ";", "}", "else", "{", "$", "contentText", "=", "''", ";", "}", "$", "mail", "=", "new", "MailMessage", "(", ")", ";", "$", "mail", "->", "addTo", "(", "$", "to", ")", ";", "$", "mail", "->", "addFrom", "(", "$", "from", "[", "'email'", "]", ",", "$", "from", "[", "'name'", "]", ")", ";", "$", "mail", "->", "setSubject", "(", "$", "subject", ")", ";", "$", "text", "=", "new", "Part", "(", "$", "contentText", ")", ";", "$", "text", "->", "type", "=", "Mime", "::", "TYPE_TEXT", ";", "$", "text", "->", "encoding", "=", "Mime", "::", "ENCODING_QUOTEDPRINTABLE", ";", "$", "text", "->", "disposition", "=", "Mime", "::", "DISPOSITION_INLINE", ";", "$", "text", "->", "charset", "=", "'UTF-8'", ";", "$", "html", "=", "new", "Part", "(", "$", "content", ")", ";", "$", "html", "->", "type", "=", "Mime", "::", "TYPE_HTML", ";", "$", "html", "->", "encoding", "=", "Mime", "::", "ENCODING_QUOTEDPRINTABLE", ";", "$", "html", "->", "disposition", "=", "Mime", "::", "DISPOSITION_INLINE", ";", "$", "html", "->", "charset", "=", "'UTF-8'", ";", "$", "bodyMessage", "=", "new", "MimeMessage", "(", ")", ";", "$", "multiPartContentMessage", "=", "new", "MimeMessage", "(", ")", ";", "$", "multiPartContentMessage", "->", "addPart", "(", "$", "text", ")", ";", "$", "multiPartContentMessage", "->", "addPart", "(", "$", "html", ")", ";", "$", "multiPartContentMimePart", "=", "new", "Part", "(", "$", "multiPartContentMessage", "->", "generateMessage", "(", ")", ")", ";", "$", "multiPartContentMimePart", "->", "charset", "=", "'UTF-8'", ";", "$", "multiPartContentMimePart", "->", "type", "=", "'multipart/alternative'", ";", "$", "multiPartContentMimePart", "->", "boundary", "=", "$", "multiPartContentMessage", "->", "getMime", "(", ")", "->", "boundary", "(", ")", ";", "$", "bodyMessage", "->", "addPart", "(", "$", "multiPartContentMimePart", ")", ";", "$", "mail", "->", "setBody", "(", "$", "bodyMessage", ")", ";", "$", "mail", "->", "setEncoding", "(", "'UTF-8'", ")", ";", "return", "$", "mail", ";", "}" ]
Return a HTML message ready to be sent @param array|string $from A string containing the sender e-mail address, or if array with keys email and name @param array|string $to An array containing the recipients of the mail @param string $subject Subject of the mail @param string|\Zend\View\Model\ModelInterface $nameOrModel Either the template to use, or a ViewModel @param null|array $values Values to use when the template is rendered @return Message
[ "Return", "a", "HTML", "message", "ready", "to", "be", "sent" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Mail/Service/Message.php#L51-L94
gregorybesson/PlaygroundCore
src/Mail/Service/Message.php
Message.getRenderer
protected function getRenderer() { if ($this->renderer === null) { $this->renderer = $this->serviceLocator->get('ViewRenderer'); } return $this->renderer; }
php
protected function getRenderer() { if ($this->renderer === null) { $this->renderer = $this->serviceLocator->get('ViewRenderer'); } return $this->renderer; }
[ "protected", "function", "getRenderer", "(", ")", "{", "if", "(", "$", "this", "->", "renderer", "===", "null", ")", "{", "$", "this", "->", "renderer", "=", "$", "this", "->", "serviceLocator", "->", "get", "(", "'ViewRenderer'", ")", ";", "}", "return", "$", "this", "->", "renderer", ";", "}" ]
Get the renderer @return \Zend\View\Renderer\RendererInterface
[ "Get", "the", "renderer" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Mail/Service/Message.php#L135-L142
gregorybesson/PlaygroundCore
src/Mail/Service/Message.php
Message.getTransport
protected function getTransport() { if ($this->transport === null) { $this->transport = $this->serviceLocator->get('playgroundcore_transport'); } return $this->transport; }
php
protected function getTransport() { if ($this->transport === null) { $this->transport = $this->serviceLocator->get('playgroundcore_transport'); } return $this->transport; }
[ "protected", "function", "getTransport", "(", ")", "{", "if", "(", "$", "this", "->", "transport", "===", "null", ")", "{", "$", "this", "->", "transport", "=", "$", "this", "->", "serviceLocator", "->", "get", "(", "'playgroundcore_transport'", ")", ";", "}", "return", "$", "this", "->", "transport", ";", "}" ]
Get the transport @return \Zend\Mail\Transport\TransportInterface
[ "Get", "the", "transport" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Mail/Service/Message.php#L149-L156
iter8-au/builder
src/Builder/Builder.php
Builder.prepareBuilder
private function prepareBuilder(): void { if (!file_exists($this->getReportCacheDir())) { @mkdir($this->getReportCacheDir(), 0777, true); } $this->builder ->setCacheDir($this->getReportCacheDir()) ->initialise(); return; }
php
private function prepareBuilder(): void { if (!file_exists($this->getReportCacheDir())) { @mkdir($this->getReportCacheDir(), 0777, true); } $this->builder ->setCacheDir($this->getReportCacheDir()) ->initialise(); return; }
[ "private", "function", "prepareBuilder", "(", ")", ":", "void", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "getReportCacheDir", "(", ")", ")", ")", "{", "@", "mkdir", "(", "$", "this", "->", "getReportCacheDir", "(", ")", ",", "0777", ",", "true", ")", ";", "}", "$", "this", "->", "builder", "->", "setCacheDir", "(", "$", "this", "->", "getReportCacheDir", "(", ")", ")", "->", "initialise", "(", ")", ";", "return", ";", "}" ]
Prepares the builders and creates the cache directory if it doesn't exist. @return void
[ "Prepares", "the", "builders", "and", "creates", "the", "cache", "directory", "if", "it", "doesn", "t", "exist", "." ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L112-L123
iter8-au/builder
src/Builder/Builder.php
Builder.generate
public function generate($unlinkFlag = true) { // Determine which format we are using and call the appropriate method. if ($this->getReportType() === self::REPORT_EXCEL) { $this->generateExcel(); // Output headers header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/download'); header('Content-Disposition: attachment;filename=' . $this->getFilename() . '.xlsx'); header('Content-Transfer-Encoding: binary '); readfile($this->builder->getTempName()); unlink($this->builder->getTempName()); exit; } throw new UnexpectedValueException('Attempted to generate a report in an unsupported format.'); }
php
public function generate($unlinkFlag = true) { // Determine which format we are using and call the appropriate method. if ($this->getReportType() === self::REPORT_EXCEL) { $this->generateExcel(); // Output headers header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/download'); header('Content-Disposition: attachment;filename=' . $this->getFilename() . '.xlsx'); header('Content-Transfer-Encoding: binary '); readfile($this->builder->getTempName()); unlink($this->builder->getTempName()); exit; } throw new UnexpectedValueException('Attempted to generate a report in an unsupported format.'); }
[ "public", "function", "generate", "(", "$", "unlinkFlag", "=", "true", ")", "{", "// Determine which format we are using and call the appropriate method.", "if", "(", "$", "this", "->", "getReportType", "(", ")", "===", "self", "::", "REPORT_EXCEL", ")", "{", "$", "this", "->", "generateExcel", "(", ")", ";", "// Output headers", "header", "(", "'Pragma: public'", ")", ";", "header", "(", "'Expires: 0'", ")", ";", "header", "(", "'Cache-Control: must-revalidate, post-check=0, pre-check=0'", ")", ";", "header", "(", "'Content-Type: application/force-download'", ")", ";", "header", "(", "'Content-Type: application/octet-stream'", ")", ";", "header", "(", "'Content-Type: application/download'", ")", ";", "header", "(", "'Content-Disposition: attachment;filename='", ".", "$", "this", "->", "getFilename", "(", ")", ".", "'.xlsx'", ")", ";", "header", "(", "'Content-Transfer-Encoding: binary '", ")", ";", "readfile", "(", "$", "this", "->", "builder", "->", "getTempName", "(", ")", ")", ";", "unlink", "(", "$", "this", "->", "builder", "->", "getTempName", "(", ")", ")", ";", "exit", ";", "}", "throw", "new", "UnexpectedValueException", "(", "'Attempted to generate a report in an unsupported format.'", ")", ";", "}" ]
Generate the final report using whatever the set format is. @param bool $unlinkFlag @return void
[ "Generate", "the", "final", "report", "using", "whatever", "the", "set", "format", "is", "." ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L142-L164
iter8-au/builder
src/Builder/Builder.php
Builder.generateExcel
public function generateExcel(): void { // Set Document Properties from Service values. $this->builder ->setCreator($this->getCreator()) ->setLastModifiedBy($this->getCreator()) ->setTitle($this->getTitle()) ->setSubject($this->getTitle()) ->setDescription($this->getDescription()); if ($this->hasSheets()) { // Multiple sheets. $this->createSheets(); } else { // Single sheet - these will be an array and a string. $headers = $this->getHeaders(); $reportArray = $this->getData(); $sheetTitle = $this->getSheetTitles(); $this->builder->setActiveSheetIndex(0); $this->createSheet( $headers, $reportArray, $sheetTitle ); } // Close the builder and write the file. $this->builder->closeAndWrite(); return; }
php
public function generateExcel(): void { // Set Document Properties from Service values. $this->builder ->setCreator($this->getCreator()) ->setLastModifiedBy($this->getCreator()) ->setTitle($this->getTitle()) ->setSubject($this->getTitle()) ->setDescription($this->getDescription()); if ($this->hasSheets()) { // Multiple sheets. $this->createSheets(); } else { // Single sheet - these will be an array and a string. $headers = $this->getHeaders(); $reportArray = $this->getData(); $sheetTitle = $this->getSheetTitles(); $this->builder->setActiveSheetIndex(0); $this->createSheet( $headers, $reportArray, $sheetTitle ); } // Close the builder and write the file. $this->builder->closeAndWrite(); return; }
[ "public", "function", "generateExcel", "(", ")", ":", "void", "{", "// Set Document Properties from Service values.", "$", "this", "->", "builder", "->", "setCreator", "(", "$", "this", "->", "getCreator", "(", ")", ")", "->", "setLastModifiedBy", "(", "$", "this", "->", "getCreator", "(", ")", ")", "->", "setTitle", "(", "$", "this", "->", "getTitle", "(", ")", ")", "->", "setSubject", "(", "$", "this", "->", "getTitle", "(", ")", ")", "->", "setDescription", "(", "$", "this", "->", "getDescription", "(", ")", ")", ";", "if", "(", "$", "this", "->", "hasSheets", "(", ")", ")", "{", "// Multiple sheets.", "$", "this", "->", "createSheets", "(", ")", ";", "}", "else", "{", "// Single sheet - these will be an array and a string.", "$", "headers", "=", "$", "this", "->", "getHeaders", "(", ")", ";", "$", "reportArray", "=", "$", "this", "->", "getData", "(", ")", ";", "$", "sheetTitle", "=", "$", "this", "->", "getSheetTitles", "(", ")", ";", "$", "this", "->", "builder", "->", "setActiveSheetIndex", "(", "0", ")", ";", "$", "this", "->", "createSheet", "(", "$", "headers", ",", "$", "reportArray", ",", "$", "sheetTitle", ")", ";", "}", "// Close the builder and write the file.", "$", "this", "->", "builder", "->", "closeAndWrite", "(", ")", ";", "return", ";", "}" ]
Generates an Excel document. @return void
[ "Generates", "an", "Excel", "document", "." ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L171-L203
iter8-au/builder
src/Builder/Builder.php
Builder.createSheet
public function createSheet( array $headers, array $rows, string $title ): void { // Check if we are setting any custom column widths. if ($this->hasColumnWidths()) { // We have a numeric index array, so create an array of letters that we can use to map to Excel columns. // e.g. 0 = A, 3 = D, etc. $columns = range('A', 'Z'); $this->builder->applyColumnWidths($columns, $this->getColumnWidths()); } // Style settings for agent headers $style = $this->builder->buildRowStyle([ 'alignment' => BuilderInterface::ALIGNMENT_CENTRE, 'font' => [ 'color' => [ 'rgb' => BuilderInterface::COLOUR_BLACK_RGB, ], 'bold' => true, ], ]); // Build column headers. $this->builder->buildHeaderRow($headers, $style); // Build all the rows now. $this->builder->buildRows($rows); // If no column widths are specified, then simply auto-size all columns. if (!$this->hasColumnWidths()) { $this->builder->autoSizeColumns($rows[0]); } // Rename sheet. $this->builder->setSheetTitle($title); }
php
public function createSheet( array $headers, array $rows, string $title ): void { // Check if we are setting any custom column widths. if ($this->hasColumnWidths()) { // We have a numeric index array, so create an array of letters that we can use to map to Excel columns. // e.g. 0 = A, 3 = D, etc. $columns = range('A', 'Z'); $this->builder->applyColumnWidths($columns, $this->getColumnWidths()); } // Style settings for agent headers $style = $this->builder->buildRowStyle([ 'alignment' => BuilderInterface::ALIGNMENT_CENTRE, 'font' => [ 'color' => [ 'rgb' => BuilderInterface::COLOUR_BLACK_RGB, ], 'bold' => true, ], ]); // Build column headers. $this->builder->buildHeaderRow($headers, $style); // Build all the rows now. $this->builder->buildRows($rows); // If no column widths are specified, then simply auto-size all columns. if (!$this->hasColumnWidths()) { $this->builder->autoSizeColumns($rows[0]); } // Rename sheet. $this->builder->setSheetTitle($title); }
[ "public", "function", "createSheet", "(", "array", "$", "headers", ",", "array", "$", "rows", ",", "string", "$", "title", ")", ":", "void", "{", "// Check if we are setting any custom column widths.", "if", "(", "$", "this", "->", "hasColumnWidths", "(", ")", ")", "{", "// We have a numeric index array, so create an array of letters that we can use to map to Excel columns.", "// e.g. 0 = A, 3 = D, etc.", "$", "columns", "=", "range", "(", "'A'", ",", "'Z'", ")", ";", "$", "this", "->", "builder", "->", "applyColumnWidths", "(", "$", "columns", ",", "$", "this", "->", "getColumnWidths", "(", ")", ")", ";", "}", "// Style settings for agent headers", "$", "style", "=", "$", "this", "->", "builder", "->", "buildRowStyle", "(", "[", "'alignment'", "=>", "BuilderInterface", "::", "ALIGNMENT_CENTRE", ",", "'font'", "=>", "[", "'color'", "=>", "[", "'rgb'", "=>", "BuilderInterface", "::", "COLOUR_BLACK_RGB", ",", "]", ",", "'bold'", "=>", "true", ",", "]", ",", "]", ")", ";", "// Build column headers.", "$", "this", "->", "builder", "->", "buildHeaderRow", "(", "$", "headers", ",", "$", "style", ")", ";", "// Build all the rows now.", "$", "this", "->", "builder", "->", "buildRows", "(", "$", "rows", ")", ";", "// If no column widths are specified, then simply auto-size all columns.", "if", "(", "!", "$", "this", "->", "hasColumnWidths", "(", ")", ")", "{", "$", "this", "->", "builder", "->", "autoSizeColumns", "(", "$", "rows", "[", "0", "]", ")", ";", "}", "// Rename sheet.", "$", "this", "->", "builder", "->", "setSheetTitle", "(", "$", "title", ")", ";", "}" ]
@param array $headers @param array $rows @param string $title @return void
[ "@param", "array", "$headers", "@param", "array", "$rows", "@param", "string", "$title" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L255-L293
iter8-au/builder
src/Builder/Builder.php
Builder.setTitle
public function setTitle(string $title): self { if (strlen($title) > 31) { $title = mb_substr($title, 0, 31); } $this->title = $title; return $this; }
php
public function setTitle(string $title): self { if (strlen($title) > 31) { $title = mb_substr($title, 0, 31); } $this->title = $title; return $this; }
[ "public", "function", "setTitle", "(", "string", "$", "title", ")", ":", "self", "{", "if", "(", "strlen", "(", "$", "title", ")", ">", "31", ")", "{", "$", "title", "=", "mb_substr", "(", "$", "title", ",", "0", ",", "31", ")", ";", "}", "$", "this", "->", "title", "=", "$", "title", ";", "return", "$", "this", ";", "}" ]
Note: if the title is longer than 31 characters it'll be trimmed. This is due to a limit in Excel. @param string $title @return $this
[ "Note", ":", "if", "the", "title", "is", "longer", "than", "31", "characters", "it", "ll", "be", "trimmed", ".", "This", "is", "due", "to", "a", "limit", "in", "Excel", "." ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L424-L433
iter8-au/builder
src/Builder/Builder.php
Builder.hasColumnStylesForColumn
public function hasColumnStylesForColumn($columnIndex): bool { if (!$this->hasColumnStyles()) { return false; } $columnStyles = $this->getColumnStyles(); return isset($columnStyles[$columnIndex]) ? true : false; }
php
public function hasColumnStylesForColumn($columnIndex): bool { if (!$this->hasColumnStyles()) { return false; } $columnStyles = $this->getColumnStyles(); return isset($columnStyles[$columnIndex]) ? true : false; }
[ "public", "function", "hasColumnStylesForColumn", "(", "$", "columnIndex", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "hasColumnStyles", "(", ")", ")", "{", "return", "false", ";", "}", "$", "columnStyles", "=", "$", "this", "->", "getColumnStyles", "(", ")", ";", "return", "isset", "(", "$", "columnStyles", "[", "$", "columnIndex", "]", ")", "?", "true", ":", "false", ";", "}" ]
@param int $columnIndex @return bool
[ "@param", "int", "$columnIndex" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L520-L529
iter8-au/builder
src/Builder/Builder.php
Builder.getColumnStylesForColumn
public function getColumnStylesForColumn($columnIndex) { if (!$this->hasColumnStylesForColumn($columnIndex)) { return false; } $columnStyles = $this->getColumnStyles(); return $columnStyles[$columnIndex] ?? false; }
php
public function getColumnStylesForColumn($columnIndex) { if (!$this->hasColumnStylesForColumn($columnIndex)) { return false; } $columnStyles = $this->getColumnStyles(); return $columnStyles[$columnIndex] ?? false; }
[ "public", "function", "getColumnStylesForColumn", "(", "$", "columnIndex", ")", "{", "if", "(", "!", "$", "this", "->", "hasColumnStylesForColumn", "(", "$", "columnIndex", ")", ")", "{", "return", "false", ";", "}", "$", "columnStyles", "=", "$", "this", "->", "getColumnStyles", "(", ")", ";", "return", "$", "columnStyles", "[", "$", "columnIndex", "]", "??", "false", ";", "}" ]
@param int $columnIndex @return bool|array
[ "@param", "int", "$columnIndex" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L536-L545
iter8-au/builder
src/Builder/Builder.php
Builder.getPhpSpreadsheetColumnStylesForColumn
private function getPhpSpreadsheetColumnStylesForColumn($columnIndex) { $phpExcelStyleArray = []; $styleArray = $this->getColumnStylesForColumn($columnIndex); if (empty($styleArray)) { return $phpExcelStyleArray; } // Alignment if (isset($styleArray['alignment'])) { if ($styleArray['alignment'] === self::ALIGNMENT_CENTER) { $phpExcelStyleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_CENTER; } else if ($styleArray['alignment'] === self::ALIGNMENT_LEFT) { $phpExcelStyleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_LEFT; } else if ($styleArray['alignment'] === self::ALIGNMENT_RIGHT) { $phpExcelStyleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_RIGHT; } } if (isset($styleArray['fill'])) { $phpExcelStyleArray['fill'] = [ 'type' => Fill::FILL_SOLID, 'color' => [ 'rgb' => $styleArray['fill'] ] ]; } /* $styleArray = array( 'font' => array( 'color' => array( 'rgb' => 'FFFFFF' ), 'bold' => true ), ); */ return $phpExcelStyleArray; }
php
private function getPhpSpreadsheetColumnStylesForColumn($columnIndex) { $phpExcelStyleArray = []; $styleArray = $this->getColumnStylesForColumn($columnIndex); if (empty($styleArray)) { return $phpExcelStyleArray; } // Alignment if (isset($styleArray['alignment'])) { if ($styleArray['alignment'] === self::ALIGNMENT_CENTER) { $phpExcelStyleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_CENTER; } else if ($styleArray['alignment'] === self::ALIGNMENT_LEFT) { $phpExcelStyleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_LEFT; } else if ($styleArray['alignment'] === self::ALIGNMENT_RIGHT) { $phpExcelStyleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_RIGHT; } } if (isset($styleArray['fill'])) { $phpExcelStyleArray['fill'] = [ 'type' => Fill::FILL_SOLID, 'color' => [ 'rgb' => $styleArray['fill'] ] ]; } /* $styleArray = array( 'font' => array( 'color' => array( 'rgb' => 'FFFFFF' ), 'bold' => true ), ); */ return $phpExcelStyleArray; }
[ "private", "function", "getPhpSpreadsheetColumnStylesForColumn", "(", "$", "columnIndex", ")", "{", "$", "phpExcelStyleArray", "=", "[", "]", ";", "$", "styleArray", "=", "$", "this", "->", "getColumnStylesForColumn", "(", "$", "columnIndex", ")", ";", "if", "(", "empty", "(", "$", "styleArray", ")", ")", "{", "return", "$", "phpExcelStyleArray", ";", "}", "// Alignment", "if", "(", "isset", "(", "$", "styleArray", "[", "'alignment'", "]", ")", ")", "{", "if", "(", "$", "styleArray", "[", "'alignment'", "]", "===", "self", "::", "ALIGNMENT_CENTER", ")", "{", "$", "phpExcelStyleArray", "[", "'alignment'", "]", "[", "'horizontal'", "]", "=", "Alignment", "::", "HORIZONTAL_CENTER", ";", "}", "else", "if", "(", "$", "styleArray", "[", "'alignment'", "]", "===", "self", "::", "ALIGNMENT_LEFT", ")", "{", "$", "phpExcelStyleArray", "[", "'alignment'", "]", "[", "'horizontal'", "]", "=", "Alignment", "::", "HORIZONTAL_LEFT", ";", "}", "else", "if", "(", "$", "styleArray", "[", "'alignment'", "]", "===", "self", "::", "ALIGNMENT_RIGHT", ")", "{", "$", "phpExcelStyleArray", "[", "'alignment'", "]", "[", "'horizontal'", "]", "=", "Alignment", "::", "HORIZONTAL_RIGHT", ";", "}", "}", "if", "(", "isset", "(", "$", "styleArray", "[", "'fill'", "]", ")", ")", "{", "$", "phpExcelStyleArray", "[", "'fill'", "]", "=", "[", "'type'", "=>", "Fill", "::", "FILL_SOLID", ",", "'color'", "=>", "[", "'rgb'", "=>", "$", "styleArray", "[", "'fill'", "]", "]", "]", ";", "}", "/*\n $styleArray = array(\n 'font' => array(\n 'color' => array(\n 'rgb' => 'FFFFFF'\n ),\n 'bold' => true\n ),\n );\n */", "return", "$", "phpExcelStyleArray", ";", "}" ]
TODO: Allow specific (col, row) styles TODO: Allow text styles and colours to be applied @param $columnIndex @return array
[ "TODO", ":", "Allow", "specific", "(", "col", "row", ")", "styles", "TODO", ":", "Allow", "text", "styles", "and", "colours", "to", "be", "applied" ]
train
https://github.com/iter8-au/builder/blob/95105636c2490c5c7a88da466702c523a9d0901c/src/Builder/Builder.php#L554-L595
yosmanyga/resource
src/Yosmanyga/Resource/Cacher/Cacher.php
Cacher.store
public function store($data, Resource $resource) { $this->checker->add($resource); $this->storer->add($data, $resource); }
php
public function store($data, Resource $resource) { $this->checker->add($resource); $this->storer->add($data, $resource); }
[ "public", "function", "store", "(", "$", "data", ",", "Resource", "$", "resource", ")", "{", "$", "this", "->", "checker", "->", "add", "(", "$", "resource", ")", ";", "$", "this", "->", "storer", "->", "add", "(", "$", "data", ",", "$", "resource", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Cacher/Cacher.php#L41-L45
yosmanyga/resource
src/Yosmanyga/Resource/Cacher/Cacher.php
Cacher.check
public function check(Resource $resource) { if ($this->checker->check($resource) && $this->storer->has($resource)) { return true; } return false; }
php
public function check(Resource $resource) { if ($this->checker->check($resource) && $this->storer->has($resource)) { return true; } return false; }
[ "public", "function", "check", "(", "Resource", "$", "resource", ")", "{", "if", "(", "$", "this", "->", "checker", "->", "check", "(", "$", "resource", ")", "&&", "$", "this", "->", "storer", "->", "has", "(", "$", "resource", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Cacher/Cacher.php#L58-L65
datasift/datasift-php
lib/DataSift/User.php
DataSift_User.setApiClient
public function setApiClient($api_client) { if (! class_exists($api_client) || ! method_exists($api_client, 'call')) { throw new DataSift_Exception_InvalidData('Class "' . $api_client . '" does not exist'); } $this->_api_client = $api_client; }
php
public function setApiClient($api_client) { if (! class_exists($api_client) || ! method_exists($api_client, 'call')) { throw new DataSift_Exception_InvalidData('Class "' . $api_client . '" does not exist'); } $this->_api_client = $api_client; }
[ "public", "function", "setApiClient", "(", "$", "api_client", ")", "{", "if", "(", "!", "class_exists", "(", "$", "api_client", ")", "||", "!", "method_exists", "(", "$", "api_client", ",", "'call'", ")", ")", "{", "throw", "new", "DataSift_Exception_InvalidData", "(", "'Class \"'", ".", "$", "api_client", ".", "'\" does not exist'", ")", ";", "}", "$", "this", "->", "_api_client", "=", "$", "api_client", ";", "}" ]
Set the class to use when calling the API @param string $api_client The class to use. @return void @throws DataSift_Exception_InvalidData
[ "Set", "the", "class", "to", "use", "when", "calling", "the", "API" ]
train
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/User.php#L173-L180
datasift/datasift-php
lib/DataSift/User.php
DataSift_User.createHistoric
public function createHistoric($hash, $start, $end, $sources, $name, $sample = DataSift_Historic::DEFAULT_SAMPLE) { return new DataSift_Historic($this, $hash, $start, $end, $sources, $name, $sample); }
php
public function createHistoric($hash, $start, $end, $sources, $name, $sample = DataSift_Historic::DEFAULT_SAMPLE) { return new DataSift_Historic($this, $hash, $start, $end, $sources, $name, $sample); }
[ "public", "function", "createHistoric", "(", "$", "hash", ",", "$", "start", ",", "$", "end", ",", "$", "sources", ",", "$", "name", ",", "$", "sample", "=", "DataSift_Historic", "::", "DEFAULT_SAMPLE", ")", "{", "return", "new", "DataSift_Historic", "(", "$", "this", ",", "$", "hash", ",", "$", "start", ",", "$", "end", ",", "$", "sources", ",", "$", "name", ",", "$", "sample", ")", ";", "}" ]
Create a historic query based on a stream hash. @param string $hash The stream hash. @param int $start The timestamp from which to start the query. @param int $end The timestamp at which to end the query. @param array $sources An array of sources required. @param string $name A friendly name for this query. @param float $sample An optional sample rate for this query. @return DataSift_Historic @throws DataSift_Exception_InvalidData
[ "Create", "a", "historic", "query", "based", "on", "a", "stream", "hash", "." ]
train
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/User.php#L286-L289
datasift/datasift-php
lib/DataSift/User.php
DataSift_User.getConsumer
public function getConsumer($type, $hash, $eventHandler) { return DataSift_StreamConsumer::factory( $this, $type, new DataSift_Definition($this, false, $hash), $eventHandler ); }
php
public function getConsumer($type, $hash, $eventHandler) { return DataSift_StreamConsumer::factory( $this, $type, new DataSift_Definition($this, false, $hash), $eventHandler ); }
[ "public", "function", "getConsumer", "(", "$", "type", ",", "$", "hash", ",", "$", "eventHandler", ")", "{", "return", "DataSift_StreamConsumer", "::", "factory", "(", "$", "this", ",", "$", "type", ",", "new", "DataSift_Definition", "(", "$", "this", ",", "false", ",", "$", "hash", ")", ",", "$", "eventHandler", ")", ";", "}" ]
Returns a DataSift_StreamConsumer-derived object for the given hash, for the given type. @param string $type The consumer type for which to construct a consumer. @param string $hash The hash to be consumed. @param DataSift_IStreamConsumerEventHandler $eventHandler The object that will receive events. @return DataSift_StreamConsumer The consumer object. @throws DataSift_Exception_InvalidData @see DataSift_StreamConsumer
[ "Returns", "a", "DataSift_StreamConsumer", "-", "derived", "object", "for", "the", "given", "hash", "for", "the", "given", "type", "." ]
train
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/User.php#L344-L352
datasift/datasift-php
lib/DataSift/User.php
DataSift_User.getMultiConsumer
public function getMultiConsumer($type, $hashes, $eventHandler) { return DataSift_StreamConsumer::factory($this, $type, $hashes, $eventHandler); }
php
public function getMultiConsumer($type, $hashes, $eventHandler) { return DataSift_StreamConsumer::factory($this, $type, $hashes, $eventHandler); }
[ "public", "function", "getMultiConsumer", "(", "$", "type", ",", "$", "hashes", ",", "$", "eventHandler", ")", "{", "return", "DataSift_StreamConsumer", "::", "factory", "(", "$", "this", ",", "$", "type", ",", "$", "hashes", ",", "$", "eventHandler", ")", ";", "}" ]
Returns a DataSift_StreamConsumer-derived object for the given hashes, for the given type. @param string $type The consumer type for which to construct a consumer. @param string $hashes An array containing hashes and/or Definition objects to be consumed. @param DataSift_IStreamConsumerEventHandler $eventHandler The object that will receive events. @return DataSift_StreamConsumer The consumer object. @throws DataSift_Exception_InvalidData @see DataSift_StreamConsumer
[ "Returns", "a", "DataSift_StreamConsumer", "-", "derived", "object", "for", "the", "given", "hashes", "for", "the", "given", "type", "." ]
train
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/User.php#L367-L370
datasift/datasift-php
lib/DataSift/User.php
DataSift_User.listPushSubscriptions
public function listPushSubscriptions( $page = 1, $per_page = 100, $order_by = DataSift_Push_Subscription::ORDERBY_CREATED_AT, $order_dir = DataSift_Push_Subscription::ORDERDIR_ASC, $include_finished = false ) { return DataSift_Push_Subscription::listSubscriptions( $this, $page, $per_page, $order_by, $order_dir, $include_finished ); }
php
public function listPushSubscriptions( $page = 1, $per_page = 100, $order_by = DataSift_Push_Subscription::ORDERBY_CREATED_AT, $order_dir = DataSift_Push_Subscription::ORDERDIR_ASC, $include_finished = false ) { return DataSift_Push_Subscription::listSubscriptions( $this, $page, $per_page, $order_by, $order_dir, $include_finished ); }
[ "public", "function", "listPushSubscriptions", "(", "$", "page", "=", "1", ",", "$", "per_page", "=", "100", ",", "$", "order_by", "=", "DataSift_Push_Subscription", "::", "ORDERBY_CREATED_AT", ",", "$", "order_dir", "=", "DataSift_Push_Subscription", "::", "ORDERDIR_ASC", ",", "$", "include_finished", "=", "false", ")", "{", "return", "DataSift_Push_Subscription", "::", "listSubscriptions", "(", "$", "this", ",", "$", "page", ",", "$", "per_page", ",", "$", "order_by", ",", "$", "order_dir", ",", "$", "include_finished", ")", ";", "}" ]
Get a list of push subscriptions in your account. @param int $page The page number to get. @param int $per_page The number of items per page. @param String order_by Which field to sort by. @param String order_dir In asc[ending] or desc[ending] order. @param bool $include_finished Set to true when you want to include finished subscription in the results. @return array Of DataSift_Push_Subscription objects. @throws DataSift_Exception_InvalidData @throws DataSift_Exception_APIError @throws DataSift_Exception_AccessDenied
[ "Get", "a", "list", "of", "push", "subscriptions", "in", "your", "account", "." ]
train
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/User.php#L401-L416
datasift/datasift-php
lib/DataSift/User.php
DataSift_User.getPushSubscriptionLogs
public function getPushSubscriptionLogs( $page = 1, $per_page = 100, $order_by = DataSift_Push_Subscription::ORDERBY_REQUEST_TIME, $order_dir = DataSift_Push_Subscription::ORDERDIR_DESC ) { return DataSift_Push_Subscription::getLogs($this, $page, $per_page, $order_by, $order_dir); }
php
public function getPushSubscriptionLogs( $page = 1, $per_page = 100, $order_by = DataSift_Push_Subscription::ORDERBY_REQUEST_TIME, $order_dir = DataSift_Push_Subscription::ORDERDIR_DESC ) { return DataSift_Push_Subscription::getLogs($this, $page, $per_page, $order_by, $order_dir); }
[ "public", "function", "getPushSubscriptionLogs", "(", "$", "page", "=", "1", ",", "$", "per_page", "=", "100", ",", "$", "order_by", "=", "DataSift_Push_Subscription", "::", "ORDERBY_REQUEST_TIME", ",", "$", "order_dir", "=", "DataSift_Push_Subscription", "::", "ORDERDIR_DESC", ")", "{", "return", "DataSift_Push_Subscription", "::", "getLogs", "(", "$", "this", ",", "$", "page", ",", "$", "per_page", ",", "$", "order_by", ",", "$", "order_dir", ")", ";", "}" ]
Page through recent push subscription log entries, specifying the sort order. @param int page Which page to fetch. @param int per_page Based on this page size. @param String order_by Which field to sort by. @param String order_dir In asc[ending] or desc[ending] order. @return ArrayList<LogEntry> @throws DataSift_Exception_AccessDenied @throws DataSift_Exception_InvalidData @throws DataSift_Exception_APIError
[ "Page", "through", "recent", "push", "subscription", "log", "entries", "specifying", "the", "sort", "order", "." ]
train
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/User.php#L432-L439
datasift/datasift-php
lib/DataSift/User.php
DataSift_User.post
public function post($endpoint, $params = array(), $headers = array(), $ingest = false) { $res = call_user_func( array($this->_api_client, 'call'), $this, $endpoint, 'post', $params, $headers, $this->getUserAgent(), array(), $ingest ); $this->_rate_limit = $res['rate_limit']; $this->_rate_limit_remaining = $res['rate_limit_remaining']; return $this->handleResponse($res); }
php
public function post($endpoint, $params = array(), $headers = array(), $ingest = false) { $res = call_user_func( array($this->_api_client, 'call'), $this, $endpoint, 'post', $params, $headers, $this->getUserAgent(), array(), $ingest ); $this->_rate_limit = $res['rate_limit']; $this->_rate_limit_remaining = $res['rate_limit_remaining']; return $this->handleResponse($res); }
[ "public", "function", "post", "(", "$", "endpoint", ",", "$", "params", "=", "array", "(", ")", ",", "$", "headers", "=", "array", "(", ")", ",", "$", "ingest", "=", "false", ")", "{", "$", "res", "=", "call_user_func", "(", "array", "(", "$", "this", "->", "_api_client", ",", "'call'", ")", ",", "$", "this", ",", "$", "endpoint", ",", "'post'", ",", "$", "params", ",", "$", "headers", ",", "$", "this", "->", "getUserAgent", "(", ")", ",", "array", "(", ")", ",", "$", "ingest", ")", ";", "$", "this", "->", "_rate_limit", "=", "$", "res", "[", "'rate_limit'", "]", ";", "$", "this", "->", "_rate_limit_remaining", "=", "$", "res", "[", "'rate_limit_remaining'", "]", ";", "return", "$", "this", "->", "handleResponse", "(", "$", "res", ")", ";", "}" ]
Make a call to a DataSift API endpoint. @param string $endpoint The endpoint of the API call. @param array $params The parameters to be passed along with the request. @return array The response from the server. @throws DataSift_Exception_APIError @throws DataSift_Exception_RateLimitExceeded
[ "Make", "a", "call", "to", "a", "DataSift", "API", "endpoint", "." ]
train
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/User.php#L581-L599