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/Redirect.php
Redirect.input
public function input($cname, $name, $cfg, $value = NULL, $id = 0) { $cfg['option']['value'] = isset($cfg['option']['value']) ? $cfg['option']['value'] : ""; // 字段显示名称 $text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>&nbsp;' : '').$cname; // 表单宽度设置 $width = 'style="width:'.(isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '200').'px;"'; // 表单附加参数 $attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : ''; // 字段提示信息 $tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips']: ''; // 字段默认值 $value = $value ? $value : ''; // 禁止修改 if (!$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && $cfg['validate']['isedit']) { $attr.= ' disabled'; } // 当字段必填时,加入html5验证标签 if (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1) { $attr.= ' required="required"'; } $str = '<input placeholder="http://" class="hstui-input" type="text" name="'.$name.'" id="hstcms_'.$name.'" value="'.$value.'" '.$width.' '.$attr.' />'; return $this->input_format($name, $text, $str, $tips); }
php
public function input($cname, $name, $cfg, $value = NULL, $id = 0) { $cfg['option']['value'] = isset($cfg['option']['value']) ? $cfg['option']['value'] : ""; // 字段显示名称 $text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>&nbsp;' : '').$cname; // 表单宽度设置 $width = 'style="width:'.(isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '200').'px;"'; // 表单附加参数 $attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : ''; // 字段提示信息 $tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips']: ''; // 字段默认值 $value = $value ? $value : ''; // 禁止修改 if (!$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && $cfg['validate']['isedit']) { $attr.= ' disabled'; } // 当字段必填时,加入html5验证标签 if (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1) { $attr.= ' required="required"'; } $str = '<input placeholder="http://" class="hstui-input" type="text" name="'.$name.'" id="hstcms_'.$name.'" value="'.$value.'" '.$width.' '.$attr.' />'; return $this->input_format($name, $text, $str, $tips); }
[ "public", "function", "input", "(", "$", "cname", ",", "$", "name", ",", "$", "cfg", ",", "$", "value", "=", "NULL", ",", "$", "id", "=", "0", ")", "{", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ")", "?", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ":", "\"\"", ";", "// 字段显示名称", "$", "text", "=", "(", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", "==", "1", "?", "'<font color=\"red\">*</font>&nbsp;'", ":", "''", ")", ".", "$", "cname", ";", "// 表单宽度设置", "$", "width", "=", "'style=\"width:'", ".", "(", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'width'", "]", ")", "&&", "$", "cfg", "[", "'option'", "]", "[", "'width'", "]", "?", "$", "cfg", "[", "'option'", "]", "[", "'width'", "]", ":", "'200'", ")", ".", "'px;\"'", ";", "// 表单附加参数", "$", "attr", "=", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'formattr'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'formattr'", "]", "?", "$", "cfg", "[", "'validate'", "]", "[", "'formattr'", "]", ":", "''", ";", "// 字段提示信息", "$", "tips", "=", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", "?", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", ":", "''", ";", "// 字段默认值", "$", "value", "=", "$", "value", "?", "$", "value", ":", "''", ";", "// 禁止修改", "if", "(", "!", "$", "this", "->", "isadmin", "&&", "$", "id", "&&", "$", "value", "&&", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'isedit'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'isedit'", "]", ")", "{", "$", "attr", ".=", "' disabled'", ";", "}", "// 当字段必填时,加入html5验证标签", "if", "(", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", "==", "1", ")", "{", "$", "attr", ".=", "' required=\"required\"'", ";", "}", "$", "str", "=", "'<input placeholder=\"http://\" class=\"hstui-input\" type=\"text\" name=\"'", ".", "$", "name", ".", "'\" id=\"hstcms_'", ".", "$", "name", ".", "'\" value=\"'", ".", "$", "value", ".", "'\" '", ".", "$", "width", ".", "' '", ".", "$", "attr", ".", "' />'", ";", "return", "$", "this", "->", "input_format", "(", "$", "name", ",", "$", "text", ",", "$", "str", ",", "$", "tips", ")", ";", "}" ]
字段表单输入 @param string $cname 字段别名 @param string $name 字段名称 @param array $cfg 字段配置 @param array $value 值 @param array $id 当前内容表的id(表示非发布操作) @return string
[ "字段表单输入" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Redirect.php#L60-L83
huasituo/hstcms
src/Libraries/Fields/Redirect.php
Redirect.insert_value
public function insert_value(Request $request, $filed, $postData = []) { $value = $request->get($field['fieldname']); if ($value) { $value = stripos($value, 'http://') != 0 || stripos($value, 'ftp://') != 0 || stripos($value, 'https://') != 0 ? 'http://'.$value : $value; } $postData[$field['relatedtable']] = [ $fieldname=>trim($value) ]; return $postData; }
php
public function insert_value(Request $request, $filed, $postData = []) { $value = $request->get($field['fieldname']); if ($value) { $value = stripos($value, 'http://') != 0 || stripos($value, 'ftp://') != 0 || stripos($value, 'https://') != 0 ? 'http://'.$value : $value; } $postData[$field['relatedtable']] = [ $fieldname=>trim($value) ]; return $postData; }
[ "public", "function", "insert_value", "(", "Request", "$", "request", ",", "$", "filed", ",", "$", "postData", "=", "[", "]", ")", "{", "$", "value", "=", "$", "request", "->", "get", "(", "$", "field", "[", "'fieldname'", "]", ")", ";", "if", "(", "$", "value", ")", "{", "$", "value", "=", "stripos", "(", "$", "value", ",", "'http://'", ")", "!=", "0", "||", "stripos", "(", "$", "value", ",", "'ftp://'", ")", "!=", "0", "||", "stripos", "(", "$", "value", ",", "'https://'", ")", "!=", "0", "?", "'http://'", ".", "$", "value", ":", "$", "value", ";", "}", "$", "postData", "[", "$", "field", "[", "'relatedtable'", "]", "]", "=", "[", "$", "fieldname", "=>", "trim", "(", "$", "value", ")", "]", ";", "return", "$", "postData", ";", "}" ]
处理输入数据,提供给入库
[ "处理输入数据,提供给入库" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Redirect.php#L88-L98
verschoof/bunq-api
src/Certificate/CertificateType.php
CertificateType.protect
private function protect() { if (!in_array($this->certificateType, self::allAsString(), true)) { throw new \InvalidArgumentException(sprintf('Invalid certificate type %s', $this->certificateType)); } }
php
private function protect() { if (!in_array($this->certificateType, self::allAsString(), true)) { throw new \InvalidArgumentException(sprintf('Invalid certificate type %s', $this->certificateType)); } }
[ "private", "function", "protect", "(", ")", "{", "if", "(", "!", "in_array", "(", "$", "this", "->", "certificateType", ",", "self", "::", "allAsString", "(", ")", ",", "true", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid certificate type %s'", ",", "$", "this", "->", "certificateType", ")", ")", ";", "}", "}" ]
Check if the certificateType exists in our list
[ "Check", "if", "the", "certificateType", "exists", "in", "our", "list" ]
train
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Certificate/CertificateType.php#L113-L118
elkuku/crowdin-api
src/Package.php
Package.getBasePath
protected function getBasePath(string $action) : string { return sprintf( 'project/%s/%s?key=%s', $this->getProjectId(), $action, $this->getApiKey() ); }
php
protected function getBasePath(string $action) : string { return sprintf( 'project/%s/%s?key=%s', $this->getProjectId(), $action, $this->getApiKey() ); }
[ "protected", "function", "getBasePath", "(", "string", "$", "action", ")", ":", "string", "{", "return", "sprintf", "(", "'project/%s/%s?key=%s'", ",", "$", "this", "->", "getProjectId", "(", ")", ",", "$", "action", ",", "$", "this", "->", "getApiKey", "(", ")", ")", ";", "}" ]
Get the base path for the command including an action. @param string $action The action to perform. @return string
[ "Get", "the", "base", "path", "for", "the", "command", "including", "an", "action", "." ]
train
https://github.com/elkuku/crowdin-api/blob/690f00eed8f91a875b3f288d319750d6d8ae0453/src/Package.php#L89-L97
refinery29/piston
src/ApiResponse.php
ApiResponse.setCustomResult
public function setCustomResult(CustomResult $customResult) { $this->checksForCustomObject(); if (\count($this->responseBody->getMembers()) > 0) { throw new \Exception(self::ERROR_CANNOT_USE_CUSTOM_AND_OTHER_RESOURCES); } $this->responseBody->addMember($customResult->getSerializer()); $this->isCustom = true; }
php
public function setCustomResult(CustomResult $customResult) { $this->checksForCustomObject(); if (\count($this->responseBody->getMembers()) > 0) { throw new \Exception(self::ERROR_CANNOT_USE_CUSTOM_AND_OTHER_RESOURCES); } $this->responseBody->addMember($customResult->getSerializer()); $this->isCustom = true; }
[ "public", "function", "setCustomResult", "(", "CustomResult", "$", "customResult", ")", "{", "$", "this", "->", "checksForCustomObject", "(", ")", ";", "if", "(", "\\", "count", "(", "$", "this", "->", "responseBody", "->", "getMembers", "(", ")", ")", ">", "0", ")", "{", "throw", "new", "\\", "Exception", "(", "self", "::", "ERROR_CANNOT_USE_CUSTOM_AND_OTHER_RESOURCES", ")", ";", "}", "$", "this", "->", "responseBody", "->", "addMember", "(", "$", "customResult", "->", "getSerializer", "(", ")", ")", ";", "$", "this", "->", "isCustom", "=", "true", ";", "}" ]
@param CustomResult $customResult @throws \Exception
[ "@param", "CustomResult", "$customResult" ]
train
https://github.com/refinery29/piston/blob/75c402e814136577fa9a02479e8803aca664c865/src/ApiResponse.php#L75-L84
ryanwachtl/silverstripe-foundation-forms
code/forms/FoundationForm.php
FoundationForm.forTemplate
public function forTemplate() { $this->Fields()->bootstrapify(); $this->Actions()->bootstrapify(); Requirements::css(FOUNDATIONFORMS_DIR . '/css/foundationforms.css'); return parent::forTemplate(); }
php
public function forTemplate() { $this->Fields()->bootstrapify(); $this->Actions()->bootstrapify(); Requirements::css(FOUNDATIONFORMS_DIR . '/css/foundationforms.css'); return parent::forTemplate(); }
[ "public", "function", "forTemplate", "(", ")", "{", "$", "this", "->", "Fields", "(", ")", "->", "bootstrapify", "(", ")", ";", "$", "this", "->", "Actions", "(", ")", "->", "bootstrapify", "(", ")", ";", "Requirements", "::", "css", "(", "FOUNDATIONFORMS_DIR", ".", "'/css/foundationforms.css'", ")", ";", "return", "parent", "::", "forTemplate", "(", ")", ";", "}" ]
Includes the dependency if necessary, applies the Bootstrap templates, and renders the form HTML output @return string
[ "Includes", "the", "dependency", "if", "necessary", "applies", "the", "Bootstrap", "templates", "and", "renders", "the", "form", "HTML", "output" ]
train
https://github.com/ryanwachtl/silverstripe-foundation-forms/blob/9055449fcb895811187124d81e57b7c93948403f/code/forms/FoundationForm.php#L25-L32
drunomics/service-utils
src/Core/State/StateTrait.php
StateTrait.getState
public function getState() { if (empty($this->state)) { $this->state = \Drupal::service('state'); } return $this->state; }
php
public function getState() { if (empty($this->state)) { $this->state = \Drupal::service('state'); } return $this->state; }
[ "public", "function", "getState", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "state", ")", ")", "{", "$", "this", "->", "state", "=", "\\", "Drupal", "::", "service", "(", "'state'", ")", ";", "}", "return", "$", "this", "->", "state", ";", "}" ]
Gets the state storage. @return \Drupal\Core\State\StateInterface The state storage.
[ "Gets", "the", "state", "storage", "." ]
train
https://github.com/drunomics/service-utils/blob/56761750043132365ef4ae5d9e0cf4263459328f/src/Core/State/StateTrait.php#L38-L43
comodojo/dispatcher.framework
src/Comodojo/Dispatcher/Traits/HeadersTrait.php
HeadersTrait.get
public function get($header = null) { if (is_null($header)) { return $this->headers; } $index = $this->getIndexCaseInsensitive($header); return $index === null ? null : $this->headers[$index]; }
php
public function get($header = null) { if (is_null($header)) { return $this->headers; } $index = $this->getIndexCaseInsensitive($header); return $index === null ? null : $this->headers[$index]; }
[ "public", "function", "get", "(", "$", "header", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "header", ")", ")", "{", "return", "$", "this", "->", "headers", ";", "}", "$", "index", "=", "$", "this", "->", "getIndexCaseInsensitive", "(", "$", "header", ")", ";", "return", "$", "index", "===", "null", "?", "null", ":", "$", "this", "->", "headers", "[", "$", "index", "]", ";", "}" ]
Get one or all header(s) If $header param is not provided, this method will return all the registered headers. Starting from (v 4.1+) this method is CASE INSENSITIVE @param string $header @return string|array|null
[ "Get", "one", "or", "all", "header", "(", "s", ")", "If", "$header", "param", "is", "not", "provided", "this", "method", "will", "return", "all", "the", "registered", "headers", "." ]
train
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Traits/HeadersTrait.php#L40-L50
comodojo/dispatcher.framework
src/Comodojo/Dispatcher/Traits/HeadersTrait.php
HeadersTrait.getAsString
public function getAsString($header = null) { if (is_null($header)) { return array_map([$this, 'headerToString'], array_keys($this->headers), array_values($this->headers) ); } $index = $this->getIndexCaseInsensitive($header); return $index === null ? null : self::headerToString($index, $this->headers[$index]); }
php
public function getAsString($header = null) { if (is_null($header)) { return array_map([$this, 'headerToString'], array_keys($this->headers), array_values($this->headers) ); } $index = $this->getIndexCaseInsensitive($header); return $index === null ? null : self::headerToString($index, $this->headers[$index]); }
[ "public", "function", "getAsString", "(", "$", "header", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "header", ")", ")", "{", "return", "array_map", "(", "[", "$", "this", ",", "'headerToString'", "]", ",", "array_keys", "(", "$", "this", "->", "headers", ")", ",", "array_values", "(", "$", "this", "->", "headers", ")", ")", ";", "}", "$", "index", "=", "$", "this", "->", "getIndexCaseInsensitive", "(", "$", "header", ")", ";", "return", "$", "index", "===", "null", "?", "null", ":", "self", "::", "headerToString", "(", "$", "index", ",", "$", "this", "->", "headers", "[", "$", "index", "]", ")", ";", "}" ]
Get one or all header(s) as a string If $header param is not provided, this method will return all the registered headers. Starting from (v 4.1+) this method is CASE INSENSITIVE @param string $header @return string|array|null
[ "Get", "one", "or", "all", "header", "(", "s", ")", "as", "a", "string", "If", "$header", "param", "is", "not", "provided", "this", "method", "will", "return", "all", "the", "registered", "headers", "." ]
train
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Traits/HeadersTrait.php#L62-L77
comodojo/dispatcher.framework
src/Comodojo/Dispatcher/Traits/HeadersTrait.php
HeadersTrait.set
public function set($header, $value = null) { if (is_null($value)) { $header = explode(":", $header, 2); $this->headers[$header[0]] = isset($header[1]) ? trim($header[1]) : ''; } else { $this->headers[$header] = $value; } return $this; }
php
public function set($header, $value = null) { if (is_null($value)) { $header = explode(":", $header, 2); $this->headers[$header[0]] = isset($header[1]) ? trim($header[1]) : ''; } else { $this->headers[$header] = $value; } return $this; }
[ "public", "function", "set", "(", "$", "header", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "header", "=", "explode", "(", "\":\"", ",", "$", "header", ",", "2", ")", ";", "$", "this", "->", "headers", "[", "$", "header", "[", "0", "]", "]", "=", "isset", "(", "$", "header", "[", "1", "]", ")", "?", "trim", "(", "$", "header", "[", "1", "]", ")", ":", "''", ";", "}", "else", "{", "$", "this", "->", "headers", "[", "$", "header", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Set an header If $header is an inline header and value is null, this method will split it automatically. $value can be a string or an array. In the latter case, these values will separated by a comma in the string representation of the header. @param string $header Header name or string representation @param mixed $value Header value(s) @return self
[ "Set", "an", "header", "If", "$header", "is", "an", "inline", "header", "and", "value", "is", "null", "this", "method", "will", "split", "it", "automatically", ".", "$value", "can", "be", "a", "string", "or", "an", "array", ".", "In", "the", "latter", "case", "these", "values", "will", "separated", "by", "a", "comma", "in", "the", "string", "representation", "of", "the", "header", "." ]
train
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Traits/HeadersTrait.php#L104-L120
comodojo/dispatcher.framework
src/Comodojo/Dispatcher/Traits/HeadersTrait.php
HeadersTrait.delete
public function delete($header = null) { if (is_null($header)) { $this->headers = []; return true; } $index = $this->getIndexCaseInsensitive($header); if ( $index === null ) { return false; } unset($this->headers[$index]); return true; }
php
public function delete($header = null) { if (is_null($header)) { $this->headers = []; return true; } $index = $this->getIndexCaseInsensitive($header); if ( $index === null ) { return false; } unset($this->headers[$index]); return true; }
[ "public", "function", "delete", "(", "$", "header", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "header", ")", ")", "{", "$", "this", "->", "headers", "=", "[", "]", ";", "return", "true", ";", "}", "$", "index", "=", "$", "this", "->", "getIndexCaseInsensitive", "(", "$", "header", ")", ";", "if", "(", "$", "index", "===", "null", ")", "{", "return", "false", ";", "}", "unset", "(", "$", "this", "->", "headers", "[", "$", "index", "]", ")", ";", "return", "true", ";", "}" ]
Delete one or all header(s) If no argument is provided, all headers will be deleted. Starting from (v 4.1+) this method is CASE INSENSITIVE @param string $header @return bool
[ "Delete", "one", "or", "all", "header", "(", "s", ")" ]
train
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Traits/HeadersTrait.php#L132-L151
comodojo/dispatcher.framework
src/Comodojo/Dispatcher/Traits/HeadersTrait.php
HeadersTrait.merge
public function merge($headers) { foreach ($headers as $key => $value) { $this->set($key, $value); } return $this; }
php
public function merge($headers) { foreach ($headers as $key => $value) { $this->set($key, $value); } return $this; }
[ "public", "function", "merge", "(", "$", "headers", ")", "{", "foreach", "(", "$", "headers", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Merge actual headers with an array of headers @param string $header @return self
[ "Merge", "actual", "headers", "with", "an", "array", "of", "headers" ]
train
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Traits/HeadersTrait.php#L159-L167
braincrafted/arrayquery
src/Braincrafted/ArrayQuery/Operator/NotLikeOperator.php
NotLikeOperator.evaluate
public function evaluate($value, $matchValue) { $pattern = sprintf('/^%s$/i', preg_replace('/(^%)|(%$)/', '.*', $matchValue)); return 1 !== preg_match($pattern, $value); }
php
public function evaluate($value, $matchValue) { $pattern = sprintf('/^%s$/i', preg_replace('/(^%)|(%$)/', '.*', $matchValue)); return 1 !== preg_match($pattern, $value); }
[ "public", "function", "evaluate", "(", "$", "value", ",", "$", "matchValue", ")", "{", "$", "pattern", "=", "sprintf", "(", "'/^%s$/i'", ",", "preg_replace", "(", "'/(^%)|(%$)/'", ",", "'.*'", ",", "$", "matchValue", ")", ")", ";", "return", "1", "!==", "preg_match", "(", "$", "pattern", ",", "$", "value", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/braincrafted/arrayquery/blob/8b0c44ee76cea796589422f52e2f7130676b9bd1/src/Braincrafted/ArrayQuery/Operator/NotLikeOperator.php#L36-L41
jan-dolata/crude-crud
src/Engine/Traits/FromModelTraitPart/CollectionTrait.php
CollectionTrait.getFiltered
public function getFiltered($page, $numRows, $sortAttr, $sortOrder, $searchAttr, $searchValue, $richFilters = []) { $query = $this->prepareQuery(); $query = $this->richFiltersOnQuery($query, $richFilters); if ($sortAttr && $sortOrder && $this->inScope($sortAttr)) { $scope = $this->getScope($sortAttr); $query = $query->orderBy($scope, $sortOrder); } if ($searchAttr && $searchValue && $this->inScope($searchAttr)) { $scope = $this->getScope($searchAttr); $query = $query->where($scope, 'like', '%' . $searchValue . '%'); } $collection = $query->get(); $collection = $this->addPermissions($collection); $collection = $this->formatCollection($collection); $collection = $collection->each(function ($model) { $model = $this->formatModel($model); }); if ($sortAttr && $sortOrder && ! $this->inScope($sortAttr)) { $collection = $sortOrder == 'asc' ? $collection->sortBy($sortAttr) : $collection->sortByDesc($sortAttr); } $collection = $this->richFiltersOnCollection($collection, $richFilters); if ($searchAttr && $searchValue && ! $this->inScope($searchAttr)) { $collection = $collection->filter(function ($model) use ($searchAttr, $searchValue) { $value = (string) $model->$searchAttr; $value = strtolower($value); $search = strtolower($searchValue); return strpos($value, $search) !== false; }); } if ($page && $numRows) { $toSkip = ($page - 1) * $numRows; $count = $collection->count(); $collection = $collection->take(- ($count - $toSkip))->take($numRows); } else if ($numRows) $collection = $collection->take($numRows); return collect(array_values($collection->toArray())); }
php
public function getFiltered($page, $numRows, $sortAttr, $sortOrder, $searchAttr, $searchValue, $richFilters = []) { $query = $this->prepareQuery(); $query = $this->richFiltersOnQuery($query, $richFilters); if ($sortAttr && $sortOrder && $this->inScope($sortAttr)) { $scope = $this->getScope($sortAttr); $query = $query->orderBy($scope, $sortOrder); } if ($searchAttr && $searchValue && $this->inScope($searchAttr)) { $scope = $this->getScope($searchAttr); $query = $query->where($scope, 'like', '%' . $searchValue . '%'); } $collection = $query->get(); $collection = $this->addPermissions($collection); $collection = $this->formatCollection($collection); $collection = $collection->each(function ($model) { $model = $this->formatModel($model); }); if ($sortAttr && $sortOrder && ! $this->inScope($sortAttr)) { $collection = $sortOrder == 'asc' ? $collection->sortBy($sortAttr) : $collection->sortByDesc($sortAttr); } $collection = $this->richFiltersOnCollection($collection, $richFilters); if ($searchAttr && $searchValue && ! $this->inScope($searchAttr)) { $collection = $collection->filter(function ($model) use ($searchAttr, $searchValue) { $value = (string) $model->$searchAttr; $value = strtolower($value); $search = strtolower($searchValue); return strpos($value, $search) !== false; }); } if ($page && $numRows) { $toSkip = ($page - 1) * $numRows; $count = $collection->count(); $collection = $collection->take(- ($count - $toSkip))->take($numRows); } else if ($numRows) $collection = $collection->take($numRows); return collect(array_values($collection->toArray())); }
[ "public", "function", "getFiltered", "(", "$", "page", ",", "$", "numRows", ",", "$", "sortAttr", ",", "$", "sortOrder", ",", "$", "searchAttr", ",", "$", "searchValue", ",", "$", "richFilters", "=", "[", "]", ")", "{", "$", "query", "=", "$", "this", "->", "prepareQuery", "(", ")", ";", "$", "query", "=", "$", "this", "->", "richFiltersOnQuery", "(", "$", "query", ",", "$", "richFilters", ")", ";", "if", "(", "$", "sortAttr", "&&", "$", "sortOrder", "&&", "$", "this", "->", "inScope", "(", "$", "sortAttr", ")", ")", "{", "$", "scope", "=", "$", "this", "->", "getScope", "(", "$", "sortAttr", ")", ";", "$", "query", "=", "$", "query", "->", "orderBy", "(", "$", "scope", ",", "$", "sortOrder", ")", ";", "}", "if", "(", "$", "searchAttr", "&&", "$", "searchValue", "&&", "$", "this", "->", "inScope", "(", "$", "searchAttr", ")", ")", "{", "$", "scope", "=", "$", "this", "->", "getScope", "(", "$", "searchAttr", ")", ";", "$", "query", "=", "$", "query", "->", "where", "(", "$", "scope", ",", "'like'", ",", "'%'", ".", "$", "searchValue", ".", "'%'", ")", ";", "}", "$", "collection", "=", "$", "query", "->", "get", "(", ")", ";", "$", "collection", "=", "$", "this", "->", "addPermissions", "(", "$", "collection", ")", ";", "$", "collection", "=", "$", "this", "->", "formatCollection", "(", "$", "collection", ")", ";", "$", "collection", "=", "$", "collection", "->", "each", "(", "function", "(", "$", "model", ")", "{", "$", "model", "=", "$", "this", "->", "formatModel", "(", "$", "model", ")", ";", "}", ")", ";", "if", "(", "$", "sortAttr", "&&", "$", "sortOrder", "&&", "!", "$", "this", "->", "inScope", "(", "$", "sortAttr", ")", ")", "{", "$", "collection", "=", "$", "sortOrder", "==", "'asc'", "?", "$", "collection", "->", "sortBy", "(", "$", "sortAttr", ")", ":", "$", "collection", "->", "sortByDesc", "(", "$", "sortAttr", ")", ";", "}", "$", "collection", "=", "$", "this", "->", "richFiltersOnCollection", "(", "$", "collection", ",", "$", "richFilters", ")", ";", "if", "(", "$", "searchAttr", "&&", "$", "searchValue", "&&", "!", "$", "this", "->", "inScope", "(", "$", "searchAttr", ")", ")", "{", "$", "collection", "=", "$", "collection", "->", "filter", "(", "function", "(", "$", "model", ")", "use", "(", "$", "searchAttr", ",", "$", "searchValue", ")", "{", "$", "value", "=", "(", "string", ")", "$", "model", "->", "$", "searchAttr", ";", "$", "value", "=", "strtolower", "(", "$", "value", ")", ";", "$", "search", "=", "strtolower", "(", "$", "searchValue", ")", ";", "return", "strpos", "(", "$", "value", ",", "$", "search", ")", "!==", "false", ";", "}", ")", ";", "}", "if", "(", "$", "page", "&&", "$", "numRows", ")", "{", "$", "toSkip", "=", "(", "$", "page", "-", "1", ")", "*", "$", "numRows", ";", "$", "count", "=", "$", "collection", "->", "count", "(", ")", ";", "$", "collection", "=", "$", "collection", "->", "take", "(", "-", "(", "$", "count", "-", "$", "toSkip", ")", ")", "->", "take", "(", "$", "numRows", ")", ";", "}", "else", "if", "(", "$", "numRows", ")", "$", "collection", "=", "$", "collection", "->", "take", "(", "$", "numRows", ")", ";", "return", "collect", "(", "array_values", "(", "$", "collection", "->", "toArray", "(", ")", ")", ")", ";", "}" ]
Get filtered collection @param integer $page @param integer $numRows @param string $sortAttr @param string $sortOrder @param string $searchAttr @param string $searchValue @return Collection
[ "Get", "filtered", "collection" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/CollectionTrait.php#L71-L122
jan-dolata/crude-crud
src/Engine/Traits/FromModelTraitPart/CollectionTrait.php
CollectionTrait.countFiltered
public function countFiltered($searchAttr, $searchValue, $richFilters) { $collection = $this->getFiltered(null, null, null, null, $searchAttr, $searchValue, $richFilters); return count($collection); }
php
public function countFiltered($searchAttr, $searchValue, $richFilters) { $collection = $this->getFiltered(null, null, null, null, $searchAttr, $searchValue, $richFilters); return count($collection); }
[ "public", "function", "countFiltered", "(", "$", "searchAttr", ",", "$", "searchValue", ",", "$", "richFilters", ")", "{", "$", "collection", "=", "$", "this", "->", "getFiltered", "(", "null", ",", "null", ",", "null", ",", "null", ",", "$", "searchAttr", ",", "$", "searchValue", ",", "$", "richFilters", ")", ";", "return", "count", "(", "$", "collection", ")", ";", "}" ]
Count all rows with condition @param string $searchAttr @param string $searchValue @return integer
[ "Count", "all", "rows", "with", "condition" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/CollectionTrait.php#L130-L134
jan-dolata/crude-crud
src/Engine/Traits/FromModelTraitPart/CollectionTrait.php
CollectionTrait.addPermissions
public function addPermissions($collection) { $newCollection = collect([]); $customActions = $this->crudeSetup->getCustomActions(); $collection->each(function ($model) use ($newCollection, $customActions) { if ($this->permissionView($model)) { $model = $this->addPermissionsForModel($model, $customActions); $newCollection->push($model); } }); return $newCollection; }
php
public function addPermissions($collection) { $newCollection = collect([]); $customActions = $this->crudeSetup->getCustomActions(); $collection->each(function ($model) use ($newCollection, $customActions) { if ($this->permissionView($model)) { $model = $this->addPermissionsForModel($model, $customActions); $newCollection->push($model); } }); return $newCollection; }
[ "public", "function", "addPermissions", "(", "$", "collection", ")", "{", "$", "newCollection", "=", "collect", "(", "[", "]", ")", ";", "$", "customActions", "=", "$", "this", "->", "crudeSetup", "->", "getCustomActions", "(", ")", ";", "$", "collection", "->", "each", "(", "function", "(", "$", "model", ")", "use", "(", "$", "newCollection", ",", "$", "customActions", ")", "{", "if", "(", "$", "this", "->", "permissionView", "(", "$", "model", ")", ")", "{", "$", "model", "=", "$", "this", "->", "addPermissionsForModel", "(", "$", "model", ",", "$", "customActions", ")", ";", "$", "newCollection", "->", "push", "(", "$", "model", ")", ";", "}", "}", ")", ";", "return", "$", "newCollection", ";", "}" ]
Filter collection by permissions and add attributes canBeEdited and canBeRemoved @param Collection $collection @return Collection
[ "Filter", "collection", "by", "permissions", "and", "add", "attributes", "canBeEdited", "and", "canBeRemoved" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/CollectionTrait.php#L141-L155
jan-dolata/crude-crud
src/Engine/Traits/FromModelTraitPart/CollectionTrait.php
CollectionTrait.getById
public function getById($id) { $model = $this ->prepareQuery() ->where($this->model->getTable() . '.id', $id) ->first(); if (empty($model)) return null; $model = $this->addPermissionsForModel($model); return $this->formatModel($model); }
php
public function getById($id) { $model = $this ->prepareQuery() ->where($this->model->getTable() . '.id', $id) ->first(); if (empty($model)) return null; $model = $this->addPermissionsForModel($model); return $this->formatModel($model); }
[ "public", "function", "getById", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "prepareQuery", "(", ")", "->", "where", "(", "$", "this", "->", "model", "->", "getTable", "(", ")", ".", "'.id'", ",", "$", "id", ")", "->", "first", "(", ")", ";", "if", "(", "empty", "(", "$", "model", ")", ")", "return", "null", ";", "$", "model", "=", "$", "this", "->", "addPermissionsForModel", "(", "$", "model", ")", ";", "return", "$", "this", "->", "formatModel", "(", "$", "model", ")", ";", "}" ]
Get by id @param integer $id @return Model
[ "Get", "by", "id" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/CollectionTrait.php#L184-L197
mremi/Dolist
src/Mremi/Dolist/Contact/GetContactRequest.php
GetContactRequest.toArray
public function toArray() { return array( 'AllFields' => $this->allFields, 'Interest' => $this->interest, 'LastModifiedOnly' => $this->lastModifiedOnly, 'Offset' => $this->offset, 'RequestFilter' => $this->requestFilter->toArray(), 'ReturnFields' => $this->returnFields, ); }
php
public function toArray() { return array( 'AllFields' => $this->allFields, 'Interest' => $this->interest, 'LastModifiedOnly' => $this->lastModifiedOnly, 'Offset' => $this->offset, 'RequestFilter' => $this->requestFilter->toArray(), 'ReturnFields' => $this->returnFields, ); }
[ "public", "function", "toArray", "(", ")", "{", "return", "array", "(", "'AllFields'", "=>", "$", "this", "->", "allFields", ",", "'Interest'", "=>", "$", "this", "->", "interest", ",", "'LastModifiedOnly'", "=>", "$", "this", "->", "lastModifiedOnly", ",", "'Offset'", "=>", "$", "this", "->", "offset", ",", "'RequestFilter'", "=>", "$", "this", "->", "requestFilter", "->", "toArray", "(", ")", ",", "'ReturnFields'", "=>", "$", "this", "->", "returnFields", ",", ")", ";", "}" ]
Gets an array representation @return array
[ "Gets", "an", "array", "representation" ]
train
https://github.com/mremi/Dolist/blob/452c863aba12ef2965bafdb619c0278f8fc732d0/src/Mremi/Dolist/Contact/GetContactRequest.php#L184-L194
Wonail/wocenter
traits/ParseRulesTrait.php
ParseRulesTrait.parseRulesToArray
protected function parseRulesToArray($rules, $field) { $value = []; if (!empty($rules)) { // 获取所有规则 $array = preg_split('/[;\r\n]+/', trim($rules, ";\r\n")); if (!empty($array)) { foreach ($array as $key => $val) { $value[$key][] = $field; // [$field] $tmp = explode(',', $val); $value[$key][] = $tmp[0]; // [$field, 'required']|[$field, 'string'] array_shift($tmp); // $tmp = max:30|length:1-3 foreach ($tmp as $k => $v) { if (strpos($v, ':')) { $t = explode(':', $v); if (strpos($t[1], '-')) { $value[$key][$t[0]] = explode('-', $t[1]); // [$field, 'string', 'length' => [1,3]] } else { $value[$key][$t[0]] = intval($t[1]); // [$field, 'string', 'max' => 30] } } } } } } return $value; }
php
protected function parseRulesToArray($rules, $field) { $value = []; if (!empty($rules)) { // 获取所有规则 $array = preg_split('/[;\r\n]+/', trim($rules, ";\r\n")); if (!empty($array)) { foreach ($array as $key => $val) { $value[$key][] = $field; // [$field] $tmp = explode(',', $val); $value[$key][] = $tmp[0]; // [$field, 'required']|[$field, 'string'] array_shift($tmp); // $tmp = max:30|length:1-3 foreach ($tmp as $k => $v) { if (strpos($v, ':')) { $t = explode(':', $v); if (strpos($t[1], '-')) { $value[$key][$t[0]] = explode('-', $t[1]); // [$field, 'string', 'length' => [1,3]] } else { $value[$key][$t[0]] = intval($t[1]); // [$field, 'string', 'max' => 30] } } } } } } return $value; }
[ "protected", "function", "parseRulesToArray", "(", "$", "rules", ",", "$", "field", ")", "{", "$", "value", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "rules", ")", ")", "{", "// 获取所有规则", "$", "array", "=", "preg_split", "(", "'/[;\\r\\n]+/'", ",", "trim", "(", "$", "rules", ",", "\";\\r\\n\"", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "array", ")", ")", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "value", "[", "$", "key", "]", "[", "]", "=", "$", "field", ";", "// [$field]", "$", "tmp", "=", "explode", "(", "','", ",", "$", "val", ")", ";", "$", "value", "[", "$", "key", "]", "[", "]", "=", "$", "tmp", "[", "0", "]", ";", "// [$field, 'required']|[$field, 'string']", "array_shift", "(", "$", "tmp", ")", ";", "// $tmp = max:30|length:1-3", "foreach", "(", "$", "tmp", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "strpos", "(", "$", "v", ",", "':'", ")", ")", "{", "$", "t", "=", "explode", "(", "':'", ",", "$", "v", ")", ";", "if", "(", "strpos", "(", "$", "t", "[", "1", "]", ",", "'-'", ")", ")", "{", "$", "value", "[", "$", "key", "]", "[", "$", "t", "[", "0", "]", "]", "=", "explode", "(", "'-'", ",", "$", "t", "[", "1", "]", ")", ";", "// [$field, 'string', 'length' => [1,3]]", "}", "else", "{", "$", "value", "[", "$", "key", "]", "[", "$", "t", "[", "0", "]", "]", "=", "intval", "(", "$", "t", "[", "1", "]", ")", ";", "// [$field, 'string', 'max' => 30]", "}", "}", "}", "}", "}", "}", "return", "$", "value", ";", "}" ]
解析验证规则 @param string $rules 验证规则 e.g. required;string,max:30;string,length:1-3 @param string $field 需要验证的字段 @return array e.g. [ [$field, 'required'], [$field, 'string', 'max' => 30], [$field, 'string', 'length' => [1,3]] ]
[ "解析验证规则" ]
train
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/traits/ParseRulesTrait.php#L26-L53
Atlantic18/CoralCoreBundle
Service/Connector/StarkConnector.php
StarkConnector.doRequest
public function doRequest($method, $uri, $data = null) { $method = strtoupper($method); if( $method != Request::GET && $method != Request::POST && $method != Request::DELETE ) { throw new ConnectorException("Invalid method [$method] for connector."); } $handle = $this->request->createHandle($method, $this->host . $uri); if(null !== $data) { $handle->setPayload(json_encode($data)); } $handle->setHeader('X-Coral-APIKEY', $this->key); return $this->request->doRequestAndParse($handle); }
php
public function doRequest($method, $uri, $data = null) { $method = strtoupper($method); if( $method != Request::GET && $method != Request::POST && $method != Request::DELETE ) { throw new ConnectorException("Invalid method [$method] for connector."); } $handle = $this->request->createHandle($method, $this->host . $uri); if(null !== $data) { $handle->setPayload(json_encode($data)); } $handle->setHeader('X-Coral-APIKEY', $this->key); return $this->request->doRequestAndParse($handle); }
[ "public", "function", "doRequest", "(", "$", "method", ",", "$", "uri", ",", "$", "data", "=", "null", ")", "{", "$", "method", "=", "strtoupper", "(", "$", "method", ")", ";", "if", "(", "$", "method", "!=", "Request", "::", "GET", "&&", "$", "method", "!=", "Request", "::", "POST", "&&", "$", "method", "!=", "Request", "::", "DELETE", ")", "{", "throw", "new", "ConnectorException", "(", "\"Invalid method [$method] for connector.\"", ")", ";", "}", "$", "handle", "=", "$", "this", "->", "request", "->", "createHandle", "(", "$", "method", ",", "$", "this", "->", "host", ".", "$", "uri", ")", ";", "if", "(", "null", "!==", "$", "data", ")", "{", "$", "handle", "->", "setPayload", "(", "json_encode", "(", "$", "data", ")", ")", ";", "}", "$", "handle", "->", "setHeader", "(", "'X-Coral-APIKEY'", ",", "$", "this", "->", "key", ")", ";", "return", "$", "this", "->", "request", "->", "doRequestAndParse", "(", "$", "handle", ")", ";", "}" ]
Create request to CORAL backend @param string $method Method name @param string $uri Service URI @param array $payload Data to be sent @return JsonResponse Response
[ "Create", "request", "to", "CORAL", "backend" ]
train
https://github.com/Atlantic18/CoralCoreBundle/blob/7d74ffaf51046ad13cbfc2b0b69d656a499f38ab/Service/Connector/StarkConnector.php#L44-L66
weavephp/weave
src/Dispatch/Dispatch.php
Dispatch.dispatch
public function dispatch($dispatchable, $resolutionType, $dispatchSource, Request $request, ...$rest) { return $dispatchable($request, ...$rest); }
php
public function dispatch($dispatchable, $resolutionType, $dispatchSource, Request $request, ...$rest) { return $dispatchable($request, ...$rest); }
[ "public", "function", "dispatch", "(", "$", "dispatchable", ",", "$", "resolutionType", ",", "$", "dispatchSource", ",", "Request", "$", "request", ",", "...", "$", "rest", ")", "{", "return", "$", "dispatchable", "(", "$", "request", ",", "...", "$", "rest", ")", ";", "}" ]
Call the callable, providing parameters and returning the returned value. Override this method in subclasses to easily wrap the actual dispatch callable and provide pre- and post-dispatch custom functionality. $resolutionType and $dispatchSource can help in identifying when to conditionally wrap the dispatch to handle translation, templating etc. @param callable $dispatchable The callable to be called. @param string $resolutionType Are we dispatching to a static, invokable etc. @param string $dispatchSource Where the dispatch request came from. @param Request $request The request. @param mixed ...$rest Any remaining parameters passed to the callable. @return mixed Some form of PSR-7 style response.
[ "Call", "the", "callable", "providing", "parameters", "and", "returning", "the", "returned", "value", "." ]
train
https://github.com/weavephp/weave/blob/44183a5bcb9e3ed3754cc76aa9e0724d718caeec/src/Dispatch/Dispatch.php#L31-L34
jan-dolata/crude-crud
src/Engine/Crude.php
Crude.prepareCrudeSetup
public function prepareCrudeSetup() { if (method_exists($this, 'prepareModelCrudeSetup')) return $this->prepareModelCrudeSetup(); $this->crudeSetup = new CrudeSetup($this->getCalledClassName(), []); return $this->crudeSetup; }
php
public function prepareCrudeSetup() { if (method_exists($this, 'prepareModelCrudeSetup')) return $this->prepareModelCrudeSetup(); $this->crudeSetup = new CrudeSetup($this->getCalledClassName(), []); return $this->crudeSetup; }
[ "public", "function", "prepareCrudeSetup", "(", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "'prepareModelCrudeSetup'", ")", ")", "return", "$", "this", "->", "prepareModelCrudeSetup", "(", ")", ";", "$", "this", "->", "crudeSetup", "=", "new", "CrudeSetup", "(", "$", "this", "->", "getCalledClassName", "(", ")", ",", "[", "]", ")", ";", "return", "$", "this", "->", "crudeSetup", ";", "}" ]
Prepare default crude setup @return self
[ "Prepare", "default", "crude", "setup" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Crude.php#L54-L62
wizbii/pipeline
Service/Consumers.php
Consumers.get
public function get($key, $default = null) { return array_key_exists($key, $this->consumers) ? $this->consumers[$key] : $default; }
php
public function get($key, $default = null) { return array_key_exists($key, $this->consumers) ? $this->consumers[$key] : $default; }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "return", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "consumers", ")", "?", "$", "this", "->", "consumers", "[", "$", "key", "]", ":", "$", "default", ";", "}" ]
Returns a Consumer by name. @param string $key The key @param Consumer $default The default value @return Consumer
[ "Returns", "a", "Consumer", "by", "name", ".", "@param", "string", "$key", "The", "key", "@param", "Consumer", "$default", "The", "default", "value" ]
train
https://github.com/wizbii/pipeline/blob/8d22b976a53bb52abf0333b62b308ec7127cf414/Service/Consumers.php#L73-L76
arrilot/collectors
src/Collector.php
Collector.scanCollection
public function scanCollection($collection, $fields) { $fields = (array) $fields; foreach ($collection as $item) { $this->collectIdsFromItem($item, $fields); } return $this; }
php
public function scanCollection($collection, $fields) { $fields = (array) $fields; foreach ($collection as $item) { $this->collectIdsFromItem($item, $fields); } return $this; }
[ "public", "function", "scanCollection", "(", "$", "collection", ",", "$", "fields", ")", "{", "$", "fields", "=", "(", "array", ")", "$", "fields", ";", "foreach", "(", "$", "collection", "as", "$", "item", ")", "{", "$", "this", "->", "collectIdsFromItem", "(", "$", "item", ",", "$", "fields", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a collection source. @param $collection @param mixed $fields @return $this
[ "Add", "a", "collection", "source", "." ]
train
https://github.com/arrilot/collectors/blob/b2084462070d098f088eccea37bf800097e97807/src/Collector.php#L52-L60
arrilot/collectors
src/Collector.php
Collector.scanItem
public function scanItem($item, $fields) { $fields = (array) $fields; $this->collectIdsFromItem($item, $fields); return $this; }
php
public function scanItem($item, $fields) { $fields = (array) $fields; $this->collectIdsFromItem($item, $fields); return $this; }
[ "public", "function", "scanItem", "(", "$", "item", ",", "$", "fields", ")", "{", "$", "fields", "=", "(", "array", ")", "$", "fields", ";", "$", "this", "->", "collectIdsFromItem", "(", "$", "item", ",", "$", "fields", ")", ";", "return", "$", "this", ";", "}" ]
Add an item source. @param $item @param mixed $fields @return $this
[ "Add", "an", "item", "source", "." ]
train
https://github.com/arrilot/collectors/blob/b2084462070d098f088eccea37bf800097e97807/src/Collector.php#L69-L75
arrilot/collectors
src/Collector.php
Collector.addIds
public function addIds($ids) { foreach ($ids as $id) { if ((int) $id) { $this->ids[] = (int) $id; } } return $this; }
php
public function addIds($ids) { foreach ($ids as $id) { if ((int) $id) { $this->ids[] = (int) $id; } } return $this; }
[ "public", "function", "addIds", "(", "$", "ids", ")", "{", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "if", "(", "(", "int", ")", "$", "id", ")", "{", "$", "this", "->", "ids", "[", "]", "=", "(", "int", ")", "$", "id", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add existeing ids array source. @param array $ids @return $this
[ "Add", "existeing", "ids", "array", "source", "." ]
train
https://github.com/arrilot/collectors/blob/b2084462070d098f088eccea37bf800097e97807/src/Collector.php#L83-L92
arrilot/collectors
src/Collector.php
Collector.collectIdsFromItem
protected function collectIdsFromItem($item, array $fields) { foreach ($fields as $field) { foreach ($this->collectIdsFromField($item, $field) as $id) { if ((int) $id) { $this->ids[] = (int) $id; } } } }
php
protected function collectIdsFromItem($item, array $fields) { foreach ($fields as $field) { foreach ($this->collectIdsFromField($item, $field) as $id) { if ((int) $id) { $this->ids[] = (int) $id; } } } }
[ "protected", "function", "collectIdsFromItem", "(", "$", "item", ",", "array", "$", "fields", ")", "{", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "foreach", "(", "$", "this", "->", "collectIdsFromField", "(", "$", "item", ",", "$", "field", ")", "as", "$", "id", ")", "{", "if", "(", "(", "int", ")", "$", "id", ")", "{", "$", "this", "->", "ids", "[", "]", "=", "(", "int", ")", "$", "id", ";", "}", "}", "}", "}" ]
Collect ids from source and add them to $this->ids @param $item @param array $fields
[ "Collect", "ids", "from", "source", "and", "add", "them", "to", "$this", "-", ">", "ids" ]
train
https://github.com/arrilot/collectors/blob/b2084462070d098f088eccea37bf800097e97807/src/Collector.php#L140-L149
arrilot/collectors
src/Collector.php
Collector.collectIdsFromField
protected function collectIdsFromField($item, $field) { $ids = Arr::get($item, $field, []); return is_object($ids) && method_exists($ids, 'toArray') ? $ids->toArray() : (array) $ids; }
php
protected function collectIdsFromField($item, $field) { $ids = Arr::get($item, $field, []); return is_object($ids) && method_exists($ids, 'toArray') ? $ids->toArray() : (array) $ids; }
[ "protected", "function", "collectIdsFromField", "(", "$", "item", ",", "$", "field", ")", "{", "$", "ids", "=", "Arr", "::", "get", "(", "$", "item", ",", "$", "field", ",", "[", "]", ")", ";", "return", "is_object", "(", "$", "ids", ")", "&&", "method_exists", "(", "$", "ids", ",", "'toArray'", ")", "?", "$", "ids", "->", "toArray", "(", ")", ":", "(", "array", ")", "$", "ids", ";", "}" ]
Collect ids from field of item @param $item @param string $field @return array
[ "Collect", "ids", "from", "field", "of", "item" ]
train
https://github.com/arrilot/collectors/blob/b2084462070d098f088eccea37bf800097e97807/src/Collector.php#L158-L163
goblindegook/Syllables
src/Template/Loader/Post_Type_Archive.php
Post_Type_Archive._prepare_filter
protected function _prepare_filter() { $post_type = \get_queried_object(); if ( ! empty( $post_type->name ) && ! empty( $post_type->has_archive ) ) { $this->post_type = $post_type->name; } }
php
protected function _prepare_filter() { $post_type = \get_queried_object(); if ( ! empty( $post_type->name ) && ! empty( $post_type->has_archive ) ) { $this->post_type = $post_type->name; } }
[ "protected", "function", "_prepare_filter", "(", ")", "{", "$", "post_type", "=", "\\", "get_queried_object", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "post_type", "->", "name", ")", "&&", "!", "empty", "(", "$", "post_type", "->", "has_archive", ")", ")", "{", "$", "this", "->", "post_type", "=", "$", "post_type", "->", "name", ";", "}", "}" ]
Prepares the object when the filter is applied. @uses \get_queried_object() @codeCoverageIgnore
[ "Prepares", "the", "object", "when", "the", "filter", "is", "applied", "." ]
train
https://github.com/goblindegook/Syllables/blob/1a98cd15e37595a85b242242f88fee38c4e36acc/src/Template/Loader/Post_Type_Archive.php#L47-L53
ridvanbaluyos/mmda
src/Ridvanbaluyos/Mmda/MMDA.php
MMDA.segments
public function segments($highway = NULL) { if ($highway && isset($this->trafficData[$highway]['segments'])) { return array_keys($this->trafficData[$highway]['segments']); } return null; }
php
public function segments($highway = NULL) { if ($highway && isset($this->trafficData[$highway]['segments'])) { return array_keys($this->trafficData[$highway]['segments']); } return null; }
[ "public", "function", "segments", "(", "$", "highway", "=", "NULL", ")", "{", "if", "(", "$", "highway", "&&", "isset", "(", "$", "this", "->", "trafficData", "[", "$", "highway", "]", "[", "'segments'", "]", ")", ")", "{", "return", "array_keys", "(", "$", "this", "->", "trafficData", "[", "$", "highway", "]", "[", "'segments'", "]", ")", ";", "}", "return", "null", ";", "}" ]
This function returns the list of segments in a given highway. @param $highway @return array|null
[ "This", "function", "returns", "the", "list", "of", "segments", "in", "a", "given", "highway", "." ]
train
https://github.com/ridvanbaluyos/mmda/blob/7aebc360b122fc4fe8d21d482341f5ebe091e7e2/src/Ridvanbaluyos/Mmda/MMDA.php#L66-L73
ridvanbaluyos/mmda
src/Ridvanbaluyos/Mmda/MMDA.php
MMDA.getTrafficData
final private function getTrafficData($feedUrl) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $feedUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); return $this->sanitizeTrafficData($this->parseTrafficData($xml)); }
php
final private function getTrafficData($feedUrl) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $feedUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); return $this->sanitizeTrafficData($this->parseTrafficData($xml)); }
[ "final", "private", "function", "getTrafficData", "(", "$", "feedUrl", ")", "{", "$", "ch", "=", "curl_init", "(", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "feedUrl", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "$", "response", "=", "curl_exec", "(", "$", "ch", ")", ";", "curl_close", "(", "$", "ch", ")", ";", "$", "xml", "=", "simplexml_load_string", "(", "$", "response", ")", ";", "return", "$", "this", "->", "sanitizeTrafficData", "(", "$", "this", "->", "parseTrafficData", "(", "$", "xml", ")", ")", ";", "}" ]
This function retrieves the traffic data from the MMDA Traffic API. @return array
[ "This", "function", "retrieves", "the", "traffic", "data", "from", "the", "MMDA", "Traffic", "API", "." ]
train
https://github.com/ridvanbaluyos/mmda/blob/7aebc360b122fc4fe8d21d482341f5ebe091e7e2/src/Ridvanbaluyos/Mmda/MMDA.php#L80-L91
ridvanbaluyos/mmda
src/Ridvanbaluyos/Mmda/MMDA.php
MMDA.parseTrafficData
final private function parseTrafficData($xml) { $traffic = []; foreach ($xml->channel->item as $item) { $item = get_object_vars($item); $title = $item['title']; $description = $item['description']; $pubDate = $item['pubDate']; $highway = explode('-', $title, 2)[0]; $segment = substr(explode('-', $title, 2)[1], 0, -3); $direction = substr(explode('-', $title, 2)[1], -2); if (empty($traffic[$highway])) $traffic[$highway] = []; if (empty($traffic[$highway][$segment])) $traffic[$highway][$segment] = []; $traffic[$highway][$segment][$direction] = $description; $traffic[$highway][$segment]['pubDate'] = $pubDate; } return $traffic; }
php
final private function parseTrafficData($xml) { $traffic = []; foreach ($xml->channel->item as $item) { $item = get_object_vars($item); $title = $item['title']; $description = $item['description']; $pubDate = $item['pubDate']; $highway = explode('-', $title, 2)[0]; $segment = substr(explode('-', $title, 2)[1], 0, -3); $direction = substr(explode('-', $title, 2)[1], -2); if (empty($traffic[$highway])) $traffic[$highway] = []; if (empty($traffic[$highway][$segment])) $traffic[$highway][$segment] = []; $traffic[$highway][$segment][$direction] = $description; $traffic[$highway][$segment]['pubDate'] = $pubDate; } return $traffic; }
[ "final", "private", "function", "parseTrafficData", "(", "$", "xml", ")", "{", "$", "traffic", "=", "[", "]", ";", "foreach", "(", "$", "xml", "->", "channel", "->", "item", "as", "$", "item", ")", "{", "$", "item", "=", "get_object_vars", "(", "$", "item", ")", ";", "$", "title", "=", "$", "item", "[", "'title'", "]", ";", "$", "description", "=", "$", "item", "[", "'description'", "]", ";", "$", "pubDate", "=", "$", "item", "[", "'pubDate'", "]", ";", "$", "highway", "=", "explode", "(", "'-'", ",", "$", "title", ",", "2", ")", "[", "0", "]", ";", "$", "segment", "=", "substr", "(", "explode", "(", "'-'", ",", "$", "title", ",", "2", ")", "[", "1", "]", ",", "0", ",", "-", "3", ")", ";", "$", "direction", "=", "substr", "(", "explode", "(", "'-'", ",", "$", "title", ",", "2", ")", "[", "1", "]", ",", "-", "2", ")", ";", "if", "(", "empty", "(", "$", "traffic", "[", "$", "highway", "]", ")", ")", "$", "traffic", "[", "$", "highway", "]", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "traffic", "[", "$", "highway", "]", "[", "$", "segment", "]", ")", ")", "$", "traffic", "[", "$", "highway", "]", "[", "$", "segment", "]", "=", "[", "]", ";", "$", "traffic", "[", "$", "highway", "]", "[", "$", "segment", "]", "[", "$", "direction", "]", "=", "$", "description", ";", "$", "traffic", "[", "$", "highway", "]", "[", "$", "segment", "]", "[", "'pubDate'", "]", "=", "$", "pubDate", ";", "}", "return", "$", "traffic", ";", "}" ]
This function parses the XML response from the MMDA Traffic API into JSON. @param $xml @return array
[ "This", "function", "parses", "the", "XML", "response", "from", "the", "MMDA", "Traffic", "API", "into", "JSON", "." ]
train
https://github.com/ridvanbaluyos/mmda/blob/7aebc360b122fc4fe8d21d482341f5ebe091e7e2/src/Ridvanbaluyos/Mmda/MMDA.php#L99-L121
ridvanbaluyos/mmda
src/Ridvanbaluyos/Mmda/MMDA.php
MMDA.sanitizeTrafficData
final private function sanitizeTrafficData(Array $trafficData) { $traffic = []; foreach ($trafficData as $highway=>$segments) { $traffic[$highway] = [ 'name' => $highway, 'label' => $this->convertToTitle($highway), ]; $traffic[$highway]['segments'] = []; $dataSegments = []; foreach ($segments as $segment=>$status) { $dataSegments[$segment] = [ 'name' => $segment, 'label' => $this->convertToTitle($segment), 'status' => $this->convertToStatus($status), ]; $traffic[$highway]['segments'] = $dataSegments; } } return $traffic; }
php
final private function sanitizeTrafficData(Array $trafficData) { $traffic = []; foreach ($trafficData as $highway=>$segments) { $traffic[$highway] = [ 'name' => $highway, 'label' => $this->convertToTitle($highway), ]; $traffic[$highway]['segments'] = []; $dataSegments = []; foreach ($segments as $segment=>$status) { $dataSegments[$segment] = [ 'name' => $segment, 'label' => $this->convertToTitle($segment), 'status' => $this->convertToStatus($status), ]; $traffic[$highway]['segments'] = $dataSegments; } } return $traffic; }
[ "final", "private", "function", "sanitizeTrafficData", "(", "Array", "$", "trafficData", ")", "{", "$", "traffic", "=", "[", "]", ";", "foreach", "(", "$", "trafficData", "as", "$", "highway", "=>", "$", "segments", ")", "{", "$", "traffic", "[", "$", "highway", "]", "=", "[", "'name'", "=>", "$", "highway", ",", "'label'", "=>", "$", "this", "->", "convertToTitle", "(", "$", "highway", ")", ",", "]", ";", "$", "traffic", "[", "$", "highway", "]", "[", "'segments'", "]", "=", "[", "]", ";", "$", "dataSegments", "=", "[", "]", ";", "foreach", "(", "$", "segments", "as", "$", "segment", "=>", "$", "status", ")", "{", "$", "dataSegments", "[", "$", "segment", "]", "=", "[", "'name'", "=>", "$", "segment", ",", "'label'", "=>", "$", "this", "->", "convertToTitle", "(", "$", "segment", ")", ",", "'status'", "=>", "$", "this", "->", "convertToStatus", "(", "$", "status", ")", ",", "]", ";", "$", "traffic", "[", "$", "highway", "]", "[", "'segments'", "]", "=", "$", "dataSegments", ";", "}", "}", "return", "$", "traffic", ";", "}" ]
This function sanitizes the traffic data and organizes them into an envelope @param array $trafficData @return array
[ "This", "function", "sanitizes", "the", "traffic", "data", "and", "organizes", "them", "into", "an", "envelope" ]
train
https://github.com/ridvanbaluyos/mmda/blob/7aebc360b122fc4fe8d21d482341f5ebe091e7e2/src/Ridvanbaluyos/Mmda/MMDA.php#L129-L152
ridvanbaluyos/mmda
src/Ridvanbaluyos/Mmda/MMDA.php
MMDA.convertToStatus
final private function convertToStatus(Array $data) { $statusMatrix = [ 'L' => 'Light', 'ML' => 'Light to Moderate', 'M' => 'Moderate', 'MH' => 'Moderate to Heavy', 'H' => 'Heavy' ]; $status = [ 'NB' => [ 'name' => $data['NB'], 'label' => $statusMatrix[$data['NB']] . ' Traffic', 'last_updated' => $data['pubDate'] ], 'SB' => [ 'name' => $data['SB'], 'label' => $statusMatrix[$data['SB']] . ' Traffic', 'last_updated' => $data['pubDate'] ] ]; return $status; }
php
final private function convertToStatus(Array $data) { $statusMatrix = [ 'L' => 'Light', 'ML' => 'Light to Moderate', 'M' => 'Moderate', 'MH' => 'Moderate to Heavy', 'H' => 'Heavy' ]; $status = [ 'NB' => [ 'name' => $data['NB'], 'label' => $statusMatrix[$data['NB']] . ' Traffic', 'last_updated' => $data['pubDate'] ], 'SB' => [ 'name' => $data['SB'], 'label' => $statusMatrix[$data['SB']] . ' Traffic', 'last_updated' => $data['pubDate'] ] ]; return $status; }
[ "final", "private", "function", "convertToStatus", "(", "Array", "$", "data", ")", "{", "$", "statusMatrix", "=", "[", "'L'", "=>", "'Light'", ",", "'ML'", "=>", "'Light to Moderate'", ",", "'M'", "=>", "'Moderate'", ",", "'MH'", "=>", "'Moderate to Heavy'", ",", "'H'", "=>", "'Heavy'", "]", ";", "$", "status", "=", "[", "'NB'", "=>", "[", "'name'", "=>", "$", "data", "[", "'NB'", "]", ",", "'label'", "=>", "$", "statusMatrix", "[", "$", "data", "[", "'NB'", "]", "]", ".", "' Traffic'", ",", "'last_updated'", "=>", "$", "data", "[", "'pubDate'", "]", "]", ",", "'SB'", "=>", "[", "'name'", "=>", "$", "data", "[", "'SB'", "]", ",", "'label'", "=>", "$", "statusMatrix", "[", "$", "data", "[", "'SB'", "]", "]", ".", "' Traffic'", ",", "'last_updated'", "=>", "$", "data", "[", "'pubDate'", "]", "]", "]", ";", "return", "$", "status", ";", "}" ]
This function converts traffic data status to readable format. @param array $data @return array
[ "This", "function", "converts", "traffic", "data", "status", "to", "readable", "format", "." ]
train
https://github.com/ridvanbaluyos/mmda/blob/7aebc360b122fc4fe8d21d482341f5ebe091e7e2/src/Ridvanbaluyos/Mmda/MMDA.php#L160-L184
ridvanbaluyos/mmda
src/Ridvanbaluyos/Mmda/MMDA.php
MMDA.convertToTitle
final private function convertToTitle($string) { $string2 = []; $string = str_replace(['_', 'AVE.', 'BLVD.'], [' ', 'AVENUE', 'BOULEVARD'], $string); $words = explode(' ', $string); foreach ($words as $word) { if (!in_array($word, ['EDSA', 'U.N.'])) { $word = ucwords(mb_strtolower($word)); } array_push($string2, $word); } return implode(' ', $string2); }
php
final private function convertToTitle($string) { $string2 = []; $string = str_replace(['_', 'AVE.', 'BLVD.'], [' ', 'AVENUE', 'BOULEVARD'], $string); $words = explode(' ', $string); foreach ($words as $word) { if (!in_array($word, ['EDSA', 'U.N.'])) { $word = ucwords(mb_strtolower($word)); } array_push($string2, $word); } return implode(' ', $string2); }
[ "final", "private", "function", "convertToTitle", "(", "$", "string", ")", "{", "$", "string2", "=", "[", "]", ";", "$", "string", "=", "str_replace", "(", "[", "'_'", ",", "'AVE.'", ",", "'BLVD.'", "]", ",", "[", "' '", ",", "'AVENUE'", ",", "'BOULEVARD'", "]", ",", "$", "string", ")", ";", "$", "words", "=", "explode", "(", "' '", ",", "$", "string", ")", ";", "foreach", "(", "$", "words", "as", "$", "word", ")", "{", "if", "(", "!", "in_array", "(", "$", "word", ",", "[", "'EDSA'", ",", "'U.N.'", "]", ")", ")", "{", "$", "word", "=", "ucwords", "(", "mb_strtolower", "(", "$", "word", ")", ")", ";", "}", "array_push", "(", "$", "string2", ",", "$", "word", ")", ";", "}", "return", "implode", "(", "' '", ",", "$", "string2", ")", ";", "}" ]
This function sanitizes certain abbreviations into readable format. @param $string @return string
[ "This", "function", "sanitizes", "certain", "abbreviations", "into", "readable", "format", "." ]
train
https://github.com/ridvanbaluyos/mmda/blob/7aebc360b122fc4fe8d21d482341f5ebe091e7e2/src/Ridvanbaluyos/Mmda/MMDA.php#L192-L206
chris-schmitz/L5SimpleFM
src/L5SimpleFM.php
L5SimpleFM.findByFields
public function findByFields($fieldValues) { if (empty($fieldValues)) { throw new \Exception('No field values specified'); } $this->primeCommandArray(); $this->addToCommandArray($fieldValues); $this->addToCommandArray(['-find' => null]); return $this; }
php
public function findByFields($fieldValues) { if (empty($fieldValues)) { throw new \Exception('No field values specified'); } $this->primeCommandArray(); $this->addToCommandArray($fieldValues); $this->addToCommandArray(['-find' => null]); return $this; }
[ "public", "function", "findByFields", "(", "$", "fieldValues", ")", "{", "if", "(", "empty", "(", "$", "fieldValues", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'No field values specified'", ")", ";", "}", "$", "this", "->", "primeCommandArray", "(", ")", ";", "$", "this", "->", "addToCommandArray", "(", "$", "fieldValues", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-find'", "=>", "null", "]", ")", ";", "return", "$", "this", ";", "}" ]
Find record(s) based on field data @param array An associative array of FieldNames => SearchValues @return object This class
[ "Find", "record", "(", "s", ")", "based", "on", "field", "data" ]
train
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFM.php#L56-L65
chris-schmitz/L5SimpleFM
src/L5SimpleFM.php
L5SimpleFM.findByRecId
public function findByRecId($recId) { if (empty($recId)) { throw new \Exception('No record ID specified'); } $this->primeCommandArray(); $this->addToCommandArray(['-recid' => $recId]); $this->addToCommandArray(['-find' => null]); return $this; }
php
public function findByRecId($recId) { if (empty($recId)) { throw new \Exception('No record ID specified'); } $this->primeCommandArray(); $this->addToCommandArray(['-recid' => $recId]); $this->addToCommandArray(['-find' => null]); return $this; }
[ "public", "function", "findByRecId", "(", "$", "recId", ")", "{", "if", "(", "empty", "(", "$", "recId", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'No record ID specified'", ")", ";", "}", "$", "this", "->", "primeCommandArray", "(", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-recid'", "=>", "$", "recId", "]", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-find'", "=>", "null", "]", ")", ";", "return", "$", "this", ";", "}" ]
Find a record based on it's internal FileMaker record ID @param integer The internal FileMaker Record ID @return object This object
[ "Find", "a", "record", "based", "on", "it", "s", "internal", "FileMaker", "record", "ID" ]
train
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFM.php#L72-L81
chris-schmitz/L5SimpleFM
src/L5SimpleFM.php
L5SimpleFM.createRecord
public function createRecord($data) { $this->primeCommandArray(); $this->addToCommandArray($data); $this->addToCommandArray(['-new' => null]); return $this; }
php
public function createRecord($data) { $this->primeCommandArray(); $this->addToCommandArray($data); $this->addToCommandArray(['-new' => null]); return $this; }
[ "public", "function", "createRecord", "(", "$", "data", ")", "{", "$", "this", "->", "primeCommandArray", "(", ")", ";", "$", "this", "->", "addToCommandArray", "(", "$", "data", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-new'", "=>", "null", "]", ")", ";", "return", "$", "this", ";", "}" ]
Create a new record and populate it with data. @param array An associative array of FileName => Values to populate the record with @return object This object
[ "Create", "a", "new", "record", "and", "populate", "it", "with", "data", "." ]
train
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFM.php#L88-L94
chris-schmitz/L5SimpleFM
src/L5SimpleFM.php
L5SimpleFM.updateRecord
public function updateRecord($recId, $data) { if (empty($recId)) { throw new \Exception('No record ID specified'); } $this->primeCommandArray(); $this->addToCommandArray($data); $this->addToCommandArray(['-recid' => $recId]); $this->addToCommandArray(['-edit' => null]); return $this; }
php
public function updateRecord($recId, $data) { if (empty($recId)) { throw new \Exception('No record ID specified'); } $this->primeCommandArray(); $this->addToCommandArray($data); $this->addToCommandArray(['-recid' => $recId]); $this->addToCommandArray(['-edit' => null]); return $this; }
[ "public", "function", "updateRecord", "(", "$", "recId", ",", "$", "data", ")", "{", "if", "(", "empty", "(", "$", "recId", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'No record ID specified'", ")", ";", "}", "$", "this", "->", "primeCommandArray", "(", ")", ";", "$", "this", "->", "addToCommandArray", "(", "$", "data", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-recid'", "=>", "$", "recId", "]", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-edit'", "=>", "null", "]", ")", ";", "return", "$", "this", ";", "}" ]
Update data in an existing record per it's internal FileMaker record ID. @param integer The internal FileMaker record ID. @param array An associative array of FileName => Values to overwrite the record with Data in fields not included will not be overwritten. @return object This object
[ "Update", "data", "in", "an", "existing", "record", "per", "it", "s", "internal", "FileMaker", "record", "ID", "." ]
train
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFM.php#L103-L113
chris-schmitz/L5SimpleFM
src/L5SimpleFM.php
L5SimpleFM.deleteRecord
public function deleteRecord($recId) { if (empty($recId)) { throw new \Exception('No record ID specified'); } $this->primeCommandArray(); $this->addToCommandArray(['-recid' => $recId]); $this->addToCommandArray(['-delete' => null]); return $this; }
php
public function deleteRecord($recId) { if (empty($recId)) { throw new \Exception('No record ID specified'); } $this->primeCommandArray(); $this->addToCommandArray(['-recid' => $recId]); $this->addToCommandArray(['-delete' => null]); return $this; }
[ "public", "function", "deleteRecord", "(", "$", "recId", ")", "{", "if", "(", "empty", "(", "$", "recId", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'No record ID specified'", ")", ";", "}", "$", "this", "->", "primeCommandArray", "(", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-recid'", "=>", "$", "recId", "]", ")", ";", "$", "this", "->", "addToCommandArray", "(", "[", "'-delete'", "=>", "null", "]", ")", ";", "return", "$", "this", ";", "}" ]
Delete a record per it's internal FileMaker record ID. @param integer The internal FileMaker record ID. @return object This object
[ "Delete", "a", "record", "per", "it", "s", "internal", "FileMaker", "record", "ID", "." ]
train
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFM.php#L120-L129
matthiasbayer/datadog-client
src/Bayer/DataDogClient/Event.php
Event.setPriority
public function setPriority($priority) { if (!$this->isValidPriority($priority)) { throw new InvalidPriorityException('Priority must be on of Event::PRIORITY_*'); } $this->priority = $priority; return $this; }
php
public function setPriority($priority) { if (!$this->isValidPriority($priority)) { throw new InvalidPriorityException('Priority must be on of Event::PRIORITY_*'); } $this->priority = $priority; return $this; }
[ "public", "function", "setPriority", "(", "$", "priority", ")", "{", "if", "(", "!", "$", "this", "->", "isValidPriority", "(", "$", "priority", ")", ")", "{", "throw", "new", "InvalidPriorityException", "(", "'Priority must be on of Event::PRIORITY_*'", ")", ";", "}", "$", "this", "->", "priority", "=", "$", "priority", ";", "return", "$", "this", ";", "}" ]
@param mixed $priority @throws Event\InvalidPriorityException @return Event
[ "@param", "mixed", "$priority", "@throws", "Event", "\\", "InvalidPriorityException" ]
train
https://github.com/matthiasbayer/datadog-client/blob/e625132c34bf36f783077c9ee4ed3214633cd272/src/Bayer/DataDogClient/Event.php#L177-L184
matthiasbayer/datadog-client
src/Bayer/DataDogClient/Event.php
Event.setAlertType
public function setAlertType($type) { if (!$this->isValidType($type)) { throw new InvalidAlertTypeException('Type must be one of Event::TYPE_*'); } $this->alertType = $type; return $this; }
php
public function setAlertType($type) { if (!$this->isValidType($type)) { throw new InvalidAlertTypeException('Type must be one of Event::TYPE_*'); } $this->alertType = $type; return $this; }
[ "public", "function", "setAlertType", "(", "$", "type", ")", "{", "if", "(", "!", "$", "this", "->", "isValidType", "(", "$", "type", ")", ")", "{", "throw", "new", "InvalidAlertTypeException", "(", "'Type must be one of Event::TYPE_*'", ")", ";", "}", "$", "this", "->", "alertType", "=", "$", "type", ";", "return", "$", "this", ";", "}" ]
@param mixed $type @throws InvalidAlertTypeException @return Event
[ "@param", "mixed", "$type", "@throws", "InvalidAlertTypeException" ]
train
https://github.com/matthiasbayer/datadog-client/blob/e625132c34bf36f783077c9ee4ed3214633cd272/src/Bayer/DataDogClient/Event.php#L199-L206
matthiasbayer/datadog-client
src/Bayer/DataDogClient/Event.php
Event.setSourceTypeName
public function setSourceTypeName($sourceType) { if (!$this->isValidSourceType($sourceType)) { throw new InvalidSourceTypeException('SourceTyoe must be on of Event::SOURCE_*'); } $this->sourceTypeName = $sourceType; return $this; }
php
public function setSourceTypeName($sourceType) { if (!$this->isValidSourceType($sourceType)) { throw new InvalidSourceTypeException('SourceTyoe must be on of Event::SOURCE_*'); } $this->sourceTypeName = $sourceType; return $this; }
[ "public", "function", "setSourceTypeName", "(", "$", "sourceType", ")", "{", "if", "(", "!", "$", "this", "->", "isValidSourceType", "(", "$", "sourceType", ")", ")", "{", "throw", "new", "InvalidSourceTypeException", "(", "'SourceTyoe must be on of Event::SOURCE_*'", ")", ";", "}", "$", "this", "->", "sourceTypeName", "=", "$", "sourceType", ";", "return", "$", "this", ";", "}" ]
@param mixed $sourceType @throws Event\InvalidSourceTypeException @return Event
[ "@param", "mixed", "$sourceType", "@throws", "Event", "\\", "InvalidSourceTypeException" ]
train
https://github.com/matthiasbayer/datadog-client/blob/e625132c34bf36f783077c9ee4ed3214633cd272/src/Bayer/DataDogClient/Event.php#L239-L246
100hz/hive
src/Hive/Hive.php
Hive.createDocumentManager
protected function createDocumentManager() { AnnotationDriver::registerAnnotationClasses(); $configuration = new Configuration(); $configuration->setProxyDir($this->configuration['doctrine']['proxyDir']); $configuration->setProxyNamespace($this->configuration['doctrine']['proxyNamespace']); $configuration->setHydratorDir($this->configuration['doctrine']['hydratorDir']); $configuration->setHydratorNamespace($this->configuration['doctrine']['hydratorNamespace']); $configuration->setMetadataDriverImpl(AnnotationDriver::create()); return DocumentManager::create(new Connection($this->configuration['doctrine']['connection']['server']), $configuration); }
php
protected function createDocumentManager() { AnnotationDriver::registerAnnotationClasses(); $configuration = new Configuration(); $configuration->setProxyDir($this->configuration['doctrine']['proxyDir']); $configuration->setProxyNamespace($this->configuration['doctrine']['proxyNamespace']); $configuration->setHydratorDir($this->configuration['doctrine']['hydratorDir']); $configuration->setHydratorNamespace($this->configuration['doctrine']['hydratorNamespace']); $configuration->setMetadataDriverImpl(AnnotationDriver::create()); return DocumentManager::create(new Connection($this->configuration['doctrine']['connection']['server']), $configuration); }
[ "protected", "function", "createDocumentManager", "(", ")", "{", "AnnotationDriver", "::", "registerAnnotationClasses", "(", ")", ";", "$", "configuration", "=", "new", "Configuration", "(", ")", ";", "$", "configuration", "->", "setProxyDir", "(", "$", "this", "->", "configuration", "[", "'doctrine'", "]", "[", "'proxyDir'", "]", ")", ";", "$", "configuration", "->", "setProxyNamespace", "(", "$", "this", "->", "configuration", "[", "'doctrine'", "]", "[", "'proxyNamespace'", "]", ")", ";", "$", "configuration", "->", "setHydratorDir", "(", "$", "this", "->", "configuration", "[", "'doctrine'", "]", "[", "'hydratorDir'", "]", ")", ";", "$", "configuration", "->", "setHydratorNamespace", "(", "$", "this", "->", "configuration", "[", "'doctrine'", "]", "[", "'hydratorNamespace'", "]", ")", ";", "$", "configuration", "->", "setMetadataDriverImpl", "(", "AnnotationDriver", "::", "create", "(", ")", ")", ";", "return", "DocumentManager", "::", "create", "(", "new", "Connection", "(", "$", "this", "->", "configuration", "[", "'doctrine'", "]", "[", "'connection'", "]", "[", "'server'", "]", ")", ",", "$", "configuration", ")", ";", "}" ]
Creates the doctrine document mananger for working on the database @return DocumentManager
[ "Creates", "the", "doctrine", "document", "mananger", "for", "working", "on", "the", "database" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L154-L166
100hz/hive
src/Hive/Hive.php
Hive.initPromises
protected function initPromises($promisesTrait) { return $promisesTrait->findOne($this->createFindOneClosure()) ->findMany($this->createFindManyClosure()) ->renderResult($this->createRenderResultClosure()) ->allowRequest($this->createAllowRequestClosure()); }
php
protected function initPromises($promisesTrait) { return $promisesTrait->findOne($this->createFindOneClosure()) ->findMany($this->createFindManyClosure()) ->renderResult($this->createRenderResultClosure()) ->allowRequest($this->createAllowRequestClosure()); }
[ "protected", "function", "initPromises", "(", "$", "promisesTrait", ")", "{", "return", "$", "promisesTrait", "->", "findOne", "(", "$", "this", "->", "createFindOneClosure", "(", ")", ")", "->", "findMany", "(", "$", "this", "->", "createFindManyClosure", "(", ")", ")", "->", "renderResult", "(", "$", "this", "->", "createRenderResultClosure", "(", ")", ")", "->", "allowRequest", "(", "$", "this", "->", "createAllowRequestClosure", "(", ")", ")", ";", "}" ]
Method for initializing a PromisesTrait object with the Closures @param PromisesTrait|Hive|Resource $promisesTrait @return PromisesTrait|Hive|Resource
[ "Method", "for", "initializing", "a", "PromisesTrait", "object", "with", "the", "Closures" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L174-L180
100hz/hive
src/Hive/Hive.php
Hive.setupIndexReferences
protected function setupIndexReferences($resource) { foreach ($resource->settings['actions']['IndexReferences']['uris'] as $property => $uri) { $this->setupIndex($resource, $uri, $property); } }
php
protected function setupIndexReferences($resource) { foreach ($resource->settings['actions']['IndexReferences']['uris'] as $property => $uri) { $this->setupIndex($resource, $uri, $property); } }
[ "protected", "function", "setupIndexReferences", "(", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "settings", "[", "'actions'", "]", "[", "'IndexReferences'", "]", "[", "'uris'", "]", "as", "$", "property", "=>", "$", "uri", ")", "{", "$", "this", "->", "setupIndex", "(", "$", "resource", ",", "$", "uri", ",", "$", "property", ")", ";", "}", "}" ]
@param \Hive\Resource $resource @return void
[ "@param", "\\", "Hive", "\\", "Resource", "$resource" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L428-L433
100hz/hive
src/Hive/Hive.php
Hive.setupReadReference
protected function setupReadReference($resource) { foreach ($resource->settings['actions']['ReadReference']['uris'] as $property => $uri) { $this->setupRead($resource, $uri, $property); } }
php
protected function setupReadReference($resource) { foreach ($resource->settings['actions']['ReadReference']['uris'] as $property => $uri) { $this->setupRead($resource, $uri, $property); } }
[ "protected", "function", "setupReadReference", "(", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "settings", "[", "'actions'", "]", "[", "'ReadReference'", "]", "[", "'uris'", "]", "as", "$", "property", "=>", "$", "uri", ")", "{", "$", "this", "->", "setupRead", "(", "$", "resource", ",", "$", "uri", ",", "$", "property", ")", ";", "}", "}" ]
@param \Hive\Resource $resource @return void
[ "@param", "\\", "Hive", "\\", "Resource", "$resource" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L440-L445
100hz/hive
src/Hive/Hive.php
Hive.setupCreateReference
protected function setupCreateReference($resource) { foreach ($resource->settings['actions']['CreateReference']['uris'] as $property => $uri) { $this->setupCreate($resource, $uri, $property); } }
php
protected function setupCreateReference($resource) { foreach ($resource->settings['actions']['CreateReference']['uris'] as $property => $uri) { $this->setupCreate($resource, $uri, $property); } }
[ "protected", "function", "setupCreateReference", "(", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "settings", "[", "'actions'", "]", "[", "'CreateReference'", "]", "[", "'uris'", "]", "as", "$", "property", "=>", "$", "uri", ")", "{", "$", "this", "->", "setupCreate", "(", "$", "resource", ",", "$", "uri", ",", "$", "property", ")", ";", "}", "}" ]
@param \Hive\Resource $resource @return void
[ "@param", "\\", "Hive", "\\", "Resource", "$resource" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L452-L457
100hz/hive
src/Hive/Hive.php
Hive.setupUpdateReference
protected function setupUpdateReference($resource) { foreach ($resource->settings['actions']['UpdateReference']['uris'] as $property => $uri) { $this->setupUpdate($resource, $uri, $property); } }
php
protected function setupUpdateReference($resource) { foreach ($resource->settings['actions']['UpdateReference']['uris'] as $property => $uri) { $this->setupUpdate($resource, $uri, $property); } }
[ "protected", "function", "setupUpdateReference", "(", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "settings", "[", "'actions'", "]", "[", "'UpdateReference'", "]", "[", "'uris'", "]", "as", "$", "property", "=>", "$", "uri", ")", "{", "$", "this", "->", "setupUpdate", "(", "$", "resource", ",", "$", "uri", ",", "$", "property", ")", ";", "}", "}" ]
@param \Hive\Resource $resource @return void
[ "@param", "\\", "Hive", "\\", "Resource", "$resource" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L464-L469
100hz/hive
src/Hive/Hive.php
Hive.setupDeleteReference
protected function setupDeleteReference($resource) { foreach ($resource->settings['actions']['DeleteReference']['uris'] as $property => $uri) { $this->setupDelete($resource, $uri, $property); } }
php
protected function setupDeleteReference($resource) { foreach ($resource->settings['actions']['DeleteReference']['uris'] as $property => $uri) { $this->setupDelete($resource, $uri, $property); } }
[ "protected", "function", "setupDeleteReference", "(", "$", "resource", ")", "{", "foreach", "(", "$", "resource", "->", "settings", "[", "'actions'", "]", "[", "'DeleteReference'", "]", "[", "'uris'", "]", "as", "$", "property", "=>", "$", "uri", ")", "{", "$", "this", "->", "setupDelete", "(", "$", "resource", ",", "$", "uri", ",", "$", "property", ")", ";", "}", "}" ]
@param \Hive\Resource $resource @return void
[ "@param", "\\", "Hive", "\\", "Resource", "$resource" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L476-L481
100hz/hive
src/Hive/Hive.php
Hive.createHttpException
protected function createHttpException($code, $message = null) { if ($code == 404) { $message = 'Entity not found'; } $exception = new HttpException($message, $code); return $exception; }
php
protected function createHttpException($code, $message = null) { if ($code == 404) { $message = 'Entity not found'; } $exception = new HttpException($message, $code); return $exception; }
[ "protected", "function", "createHttpException", "(", "$", "code", ",", "$", "message", "=", "null", ")", "{", "if", "(", "$", "code", "==", "404", ")", "{", "$", "message", "=", "'Entity not found'", ";", "}", "$", "exception", "=", "new", "HttpException", "(", "$", "message", ",", "$", "code", ")", ";", "return", "$", "exception", ";", "}" ]
Helper method for creating HTTP exceptions @param int $code @param string $message @return HttpException
[ "Helper", "method", "for", "creating", "HTTP", "exceptions" ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L769-L777
100hz/hive
src/Hive/Hive.php
Hive.resource
public function resource($className, $settings = []) { /** @var \Hive\Resource $resource */ $resource = $this->initPromises(Resource::create($className, $settings, $this)); foreach ($resource->settings['actions'] as $action => $actionSettings) { $methodName = "setup$action"; if (method_exists($this, $methodName)) { $this->{$methodName}($resource); } } return $resource; }
php
public function resource($className, $settings = []) { /** @var \Hive\Resource $resource */ $resource = $this->initPromises(Resource::create($className, $settings, $this)); foreach ($resource->settings['actions'] as $action => $actionSettings) { $methodName = "setup$action"; if (method_exists($this, $methodName)) { $this->{$methodName}($resource); } } return $resource; }
[ "public", "function", "resource", "(", "$", "className", ",", "$", "settings", "=", "[", "]", ")", "{", "/** @var \\Hive\\Resource $resource */", "$", "resource", "=", "$", "this", "->", "initPromises", "(", "Resource", "::", "create", "(", "$", "className", ",", "$", "settings", ",", "$", "this", ")", ")", ";", "foreach", "(", "$", "resource", "->", "settings", "[", "'actions'", "]", "as", "$", "action", "=>", "$", "actionSettings", ")", "{", "$", "methodName", "=", "\"setup$action\"", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "methodName", ")", ")", "{", "$", "this", "->", "{", "$", "methodName", "}", "(", "$", "resource", ")", ";", "}", "}", "return", "$", "resource", ";", "}" ]
The second most important method. Will create RESTful routes for MongoDB model. @param string $className @param array $settings @return PromisesTrait|Resource
[ "The", "second", "most", "important", "method", ".", "Will", "create", "RESTful", "routes", "for", "MongoDB", "model", "." ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L800-L813
100hz/hive
src/Hive/Hive.php
Hive.api
public function api($request = null, $response = null, $sendResponse = true) { $this->klein->respond('POST', '/authenticate', $this->authenticate); $this->klein->onHttpError($this->handleError); // see https://github.com/klein/klein.php/wiki/Sub-Directory-Installation if ($request === null) $request = Request::createFromGlobals(); // Grab the server-passed "REQUEST_URI" $uri = $request->server()->get('REQUEST_URI'); // Set the request URI to a modified one (without the "subdirectory") in it $request->server()->set('REQUEST_URI', '/' . substr($uri, strlen($this->configuration['basePath']))); // Pass our request to our dispatch method $this->klein->dispatch($request, $response, $sendResponse); }
php
public function api($request = null, $response = null, $sendResponse = true) { $this->klein->respond('POST', '/authenticate', $this->authenticate); $this->klein->onHttpError($this->handleError); // see https://github.com/klein/klein.php/wiki/Sub-Directory-Installation if ($request === null) $request = Request::createFromGlobals(); // Grab the server-passed "REQUEST_URI" $uri = $request->server()->get('REQUEST_URI'); // Set the request URI to a modified one (without the "subdirectory") in it $request->server()->set('REQUEST_URI', '/' . substr($uri, strlen($this->configuration['basePath']))); // Pass our request to our dispatch method $this->klein->dispatch($request, $response, $sendResponse); }
[ "public", "function", "api", "(", "$", "request", "=", "null", ",", "$", "response", "=", "null", ",", "$", "sendResponse", "=", "true", ")", "{", "$", "this", "->", "klein", "->", "respond", "(", "'POST'", ",", "'/authenticate'", ",", "$", "this", "->", "authenticate", ")", ";", "$", "this", "->", "klein", "->", "onHttpError", "(", "$", "this", "->", "handleError", ")", ";", "// see https://github.com/klein/klein.php/wiki/Sub-Directory-Installation", "if", "(", "$", "request", "===", "null", ")", "$", "request", "=", "Request", "::", "createFromGlobals", "(", ")", ";", "// Grab the server-passed \"REQUEST_URI\"", "$", "uri", "=", "$", "request", "->", "server", "(", ")", "->", "get", "(", "'REQUEST_URI'", ")", ";", "// Set the request URI to a modified one (without the \"subdirectory\") in it", "$", "request", "->", "server", "(", ")", "->", "set", "(", "'REQUEST_URI'", ",", "'/'", ".", "substr", "(", "$", "uri", ",", "strlen", "(", "$", "this", "->", "configuration", "[", "'basePath'", "]", ")", ")", ")", ";", "// Pass our request to our dispatch method", "$", "this", "->", "klein", "->", "dispatch", "(", "$", "request", ",", "$", "response", ",", "$", "sendResponse", ")", ";", "}" ]
The most important method. Will start the hive engine and listening for requests. @param Request $request @param AbstractResponse $response @param boolean $sendResponse @return void
[ "The", "most", "important", "method", ".", "Will", "start", "the", "hive", "engine", "and", "listening", "for", "requests", "." ]
train
https://github.com/100hz/hive/blob/b336b092255ce885b1ff9bf78d49693c4daf1c72/src/Hive/Hive.php#L825-L842
cronario/cronario
src/AbstractJob.php
AbstractJob.getParam
public function getParam($key = null, $default = null) { if (null === $key) { return $this->data[self::P_PARAMS]; } return $this->hasParam($key) ? $this->data[self::P_PARAMS][$key] : $default; }
php
public function getParam($key = null, $default = null) { if (null === $key) { return $this->data[self::P_PARAMS]; } return $this->hasParam($key) ? $this->data[self::P_PARAMS][$key] : $default; }
[ "public", "function", "getParam", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "null", "===", "$", "key", ")", "{", "return", "$", "this", "->", "data", "[", "self", "::", "P_PARAMS", "]", ";", "}", "return", "$", "this", "->", "hasParam", "(", "$", "key", ")", "?", "$", "this", "->", "data", "[", "self", "::", "P_PARAMS", "]", "[", "$", "key", "]", ":", "$", "default", ";", "}" ]
@param null $key @param null $default @return string|int|null
[ "@param", "null", "$key", "@param", "null", "$default" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L309-L316
cronario/cronario
src/AbstractJob.php
AbstractJob.hasParam
public function hasParam($key) { return $this->hasData(self::P_PARAMS) && array_key_exists($key, (array) $this->data[self::P_PARAMS]); }
php
public function hasParam($key) { return $this->hasData(self::P_PARAMS) && array_key_exists($key, (array) $this->data[self::P_PARAMS]); }
[ "public", "function", "hasParam", "(", "$", "key", ")", "{", "return", "$", "this", "->", "hasData", "(", "self", "::", "P_PARAMS", ")", "&&", "array_key_exists", "(", "$", "key", ",", "(", "array", ")", "$", "this", "->", "data", "[", "self", "::", "P_PARAMS", "]", ")", ";", "}" ]
@param $key @return bool
[ "@param", "$key" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L323-L326
cronario/cronario
src/AbstractJob.php
AbstractJob.setParam
public function setParam($key, $value) { $this->data[self::P_PARAMS][$key] = $value; return $this; }
php
public function setParam($key, $value) { $this->data[self::P_PARAMS][$key] = $value; return $this; }
[ "public", "function", "setParam", "(", "$", "key", ",", "$", "value", ")", "{", "$", "this", "->", "data", "[", "self", "::", "P_PARAMS", "]", "[", "$", "key", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
@param $key @param $value @return $this
[ "@param", "$key", "@param", "$value" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L345-L350
cronario/cronario
src/AbstractJob.php
AbstractJob.setResult
public function setResult($result, $data = null) { if (null === $result) { return $this; } if (is_numeric($result)) { if ($result > 1000) { $result = ResultException::factory($result, $data); } else { $result = new static::$resultClass((int) $result, $data); } } elseif ($result instanceof ResultException) { // continue } elseif (is_array($result) && isset($result[self::RESULT_P_GLOBAL_CODE])) { $result = ResultException::factory($result[self::RESULT_P_GLOBAL_CODE], $result[self::RESULT_P_DATA]); } else { $result = new ResultException(ResultException::E_INTERNAL, $result); } if (!empty($data)) { $result->addData($data); } $this->result = $result; $this->setData(self::P_RESULT, [ self::RESULT_P_GLOBAL_CODE => $result->getGlobalCode(), self::RESULT_P_DATA => $result->getData(), ]); return $this; }
php
public function setResult($result, $data = null) { if (null === $result) { return $this; } if (is_numeric($result)) { if ($result > 1000) { $result = ResultException::factory($result, $data); } else { $result = new static::$resultClass((int) $result, $data); } } elseif ($result instanceof ResultException) { // continue } elseif (is_array($result) && isset($result[self::RESULT_P_GLOBAL_CODE])) { $result = ResultException::factory($result[self::RESULT_P_GLOBAL_CODE], $result[self::RESULT_P_DATA]); } else { $result = new ResultException(ResultException::E_INTERNAL, $result); } if (!empty($data)) { $result->addData($data); } $this->result = $result; $this->setData(self::P_RESULT, [ self::RESULT_P_GLOBAL_CODE => $result->getGlobalCode(), self::RESULT_P_DATA => $result->getData(), ]); return $this; }
[ "public", "function", "setResult", "(", "$", "result", ",", "$", "data", "=", "null", ")", "{", "if", "(", "null", "===", "$", "result", ")", "{", "return", "$", "this", ";", "}", "if", "(", "is_numeric", "(", "$", "result", ")", ")", "{", "if", "(", "$", "result", ">", "1000", ")", "{", "$", "result", "=", "ResultException", "::", "factory", "(", "$", "result", ",", "$", "data", ")", ";", "}", "else", "{", "$", "result", "=", "new", "static", "::", "$", "resultClass", "(", "(", "int", ")", "$", "result", ",", "$", "data", ")", ";", "}", "}", "elseif", "(", "$", "result", "instanceof", "ResultException", ")", "{", "// continue", "}", "elseif", "(", "is_array", "(", "$", "result", ")", "&&", "isset", "(", "$", "result", "[", "self", "::", "RESULT_P_GLOBAL_CODE", "]", ")", ")", "{", "$", "result", "=", "ResultException", "::", "factory", "(", "$", "result", "[", "self", "::", "RESULT_P_GLOBAL_CODE", "]", ",", "$", "result", "[", "self", "::", "RESULT_P_DATA", "]", ")", ";", "}", "else", "{", "$", "result", "=", "new", "ResultException", "(", "ResultException", "::", "E_INTERNAL", ",", "$", "result", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "result", "->", "addData", "(", "$", "data", ")", ";", "}", "$", "this", "->", "result", "=", "$", "result", ";", "$", "this", "->", "setData", "(", "self", "::", "P_RESULT", ",", "[", "self", "::", "RESULT_P_GLOBAL_CODE", "=>", "$", "result", "->", "getGlobalCode", "(", ")", ",", "self", "::", "RESULT_P_DATA", "=>", "$", "result", "->", "getData", "(", ")", ",", "]", ")", ";", "return", "$", "this", ";", "}" ]
@param $result @param null $data @return ResultException|mixed @throws \Result\RuntimeException
[ "@param", "$result", "@param", "null", "$data" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L375-L406
cronario/cronario
src/AbstractJob.php
AbstractJob.setId
public function setId($id) { if ($this->hasData(self::P_ID)) { throw new JobException('Cant set id cause it is already sets!'); } return $this->setData(self::P_ID, $id); }
php
public function setId($id) { if ($this->hasData(self::P_ID)) { throw new JobException('Cant set id cause it is already sets!'); } return $this->setData(self::P_ID, $id); }
[ "public", "function", "setId", "(", "$", "id", ")", "{", "if", "(", "$", "this", "->", "hasData", "(", "self", "::", "P_ID", ")", ")", "{", "throw", "new", "JobException", "(", "'Cant set id cause it is already sets!'", ")", ";", "}", "return", "$", "this", "->", "setData", "(", "self", "::", "P_ID", ",", "$", "id", ")", ";", "}" ]
@param $id @return AbstractJob @throws JobException
[ "@param", "$id" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L458-L465
cronario/cronario
src/AbstractJob.php
AbstractJob.getScheduleDelay
public function getScheduleDelay() { $value = $this->getSchedule(); if (null === $value) { return -1; } $object = CronExpression::factory($value); $format = 'Y-m-d H:i:s'; $timeFirst = strtotime($object->getNextRunDate()->format($format)); $timeSecond = strtotime(date($format)); return (int) $timeFirst - $timeSecond; }
php
public function getScheduleDelay() { $value = $this->getSchedule(); if (null === $value) { return -1; } $object = CronExpression::factory($value); $format = 'Y-m-d H:i:s'; $timeFirst = strtotime($object->getNextRunDate()->format($format)); $timeSecond = strtotime(date($format)); return (int) $timeFirst - $timeSecond; }
[ "public", "function", "getScheduleDelay", "(", ")", "{", "$", "value", "=", "$", "this", "->", "getSchedule", "(", ")", ";", "if", "(", "null", "===", "$", "value", ")", "{", "return", "-", "1", ";", "}", "$", "object", "=", "CronExpression", "::", "factory", "(", "$", "value", ")", ";", "$", "format", "=", "'Y-m-d H:i:s'", ";", "$", "timeFirst", "=", "strtotime", "(", "$", "object", "->", "getNextRunDate", "(", ")", "->", "format", "(", "$", "format", ")", ")", ";", "$", "timeSecond", "=", "strtotime", "(", "date", "(", "$", "format", ")", ")", ";", "return", "(", "int", ")", "$", "timeFirst", "-", "$", "timeSecond", ";", "}" ]
@return int return -1 : if schedule is not set return x >= 0 : if schedule is set
[ "@return", "int" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L638-L652
cronario/cronario
src/AbstractJob.php
AbstractJob.addDebug
public function addDebug($value) { if (!$this->isDebug()) { return $this; } return $this->addData( self::P_DEBUG, is_array($value) ? json_encode($value) : $value ); }
php
public function addDebug($value) { if (!$this->isDebug()) { return $this; } return $this->addData( self::P_DEBUG, is_array($value) ? json_encode($value) : $value ); }
[ "public", "function", "addDebug", "(", "$", "value", ")", "{", "if", "(", "!", "$", "this", "->", "isDebug", "(", ")", ")", "{", "return", "$", "this", ";", "}", "return", "$", "this", "->", "addData", "(", "self", "::", "P_DEBUG", ",", "is_array", "(", "$", "value", ")", "?", "json_encode", "(", "$", "value", ")", ":", "$", "value", ")", ";", "}" ]
@param $value @return $this|AbstractJob
[ "@param", "$value" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L832-L842
cronario/cronario
src/AbstractJob.php
AbstractJob.setCreateOn
public function setCreateOn($value) { if (!is_int($value)) { throw new JobException('Job setExpiredOn can sets only integer type!'); } return $this->setData(self::P_CREATE_ON, $value); }
php
public function setCreateOn($value) { if (!is_int($value)) { throw new JobException('Job setExpiredOn can sets only integer type!'); } return $this->setData(self::P_CREATE_ON, $value); }
[ "public", "function", "setCreateOn", "(", "$", "value", ")", "{", "if", "(", "!", "is_int", "(", "$", "value", ")", ")", "{", "throw", "new", "JobException", "(", "'Job setExpiredOn can sets only integer type!'", ")", ";", "}", "return", "$", "this", "->", "setData", "(", "self", "::", "P_CREATE_ON", ",", "$", "value", ")", ";", "}" ]
@param $value @return AbstractJob @throws JobException
[ "@param", "$value" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L869-L876
cronario/cronario
src/AbstractJob.php
AbstractJob.setExpiredOn
public function setExpiredOn($value) { if (!is_int($value)) { throw new JobException('Job setExpiredOn can sets only integer type!'); } return $this->setData(self::P_EXPIRED_ON, $value); }
php
public function setExpiredOn($value) { if (!is_int($value)) { throw new JobException('Job setExpiredOn can sets only integer type!'); } return $this->setData(self::P_EXPIRED_ON, $value); }
[ "public", "function", "setExpiredOn", "(", "$", "value", ")", "{", "if", "(", "!", "is_int", "(", "$", "value", ")", ")", "{", "throw", "new", "JobException", "(", "'Job setExpiredOn can sets only integer type!'", ")", ";", "}", "return", "$", "this", "->", "setData", "(", "self", "::", "P_EXPIRED_ON", ",", "$", "value", ")", ";", "}" ]
@param $value @return AbstractJob @throws JobException
[ "@param", "$value" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L892-L899
cronario/cronario
src/AbstractJob.php
AbstractJob.setDeleteOn
public function setDeleteOn($value) { if (!is_int($value)) { throw new JobException('Job setStartOn can sets only integer type!'); } return $this->setData(self::P_DELETE_ON, $value); }
php
public function setDeleteOn($value) { if (!is_int($value)) { throw new JobException('Job setStartOn can sets only integer type!'); } return $this->setData(self::P_DELETE_ON, $value); }
[ "public", "function", "setDeleteOn", "(", "$", "value", ")", "{", "if", "(", "!", "is_int", "(", "$", "value", ")", ")", "{", "throw", "new", "JobException", "(", "'Job setStartOn can sets only integer type!'", ")", ";", "}", "return", "$", "this", "->", "setData", "(", "self", "::", "P_DELETE_ON", ",", "$", "value", ")", ";", "}" ]
@param $value @return AbstractJob @throws JobException
[ "@param", "$value" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L915-L922
cronario/cronario
src/AbstractJob.php
AbstractJob.setStartOn
public function setStartOn($value) { if (!is_int($value)) { throw new JobException('Job setStartOn can sets only integer type!'); } return $this->setData(self::P_START_ON, $value); }
php
public function setStartOn($value) { if (!is_int($value)) { throw new JobException('Job setStartOn can sets only integer type!'); } return $this->setData(self::P_START_ON, $value); }
[ "public", "function", "setStartOn", "(", "$", "value", ")", "{", "if", "(", "!", "is_int", "(", "$", "value", ")", ")", "{", "throw", "new", "JobException", "(", "'Job setStartOn can sets only integer type!'", ")", ";", "}", "return", "$", "this", "->", "setData", "(", "self", "::", "P_START_ON", ",", "$", "value", ")", ";", "}" ]
@param $value @return AbstractJob @throws JobException
[ "@param", "$value" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L946-L953
cronario/cronario
src/AbstractJob.php
AbstractJob.getCallbacksByType
public function getCallbacksByType($type) { if (array_key_exists($type, $this->callbacks) && count($this->callbacks[$type]) > 0) { return $this->callbacks[$type]; } return []; }
php
public function getCallbacksByType($type) { if (array_key_exists($type, $this->callbacks) && count($this->callbacks[$type]) > 0) { return $this->callbacks[$type]; } return []; }
[ "public", "function", "getCallbacksByType", "(", "$", "type", ")", "{", "if", "(", "array_key_exists", "(", "$", "type", ",", "$", "this", "->", "callbacks", ")", "&&", "count", "(", "$", "this", "->", "callbacks", "[", "$", "type", "]", ")", ">", "0", ")", "{", "return", "$", "this", "->", "callbacks", "[", "$", "type", "]", ";", "}", "return", "[", "]", ";", "}" ]
@param $type @return array
[ "@param", "$type" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L983-L990
cronario/cronario
src/AbstractJob.php
AbstractJob.setCallbacks
public function setCallbacks(array $callbacks = []) { foreach ($callbacks as $type => $items) { foreach ($items as $item) { $this->addCallbackJob($type, $item); } } return $this; }
php
public function setCallbacks(array $callbacks = []) { foreach ($callbacks as $type => $items) { foreach ($items as $item) { $this->addCallbackJob($type, $item); } } return $this; }
[ "public", "function", "setCallbacks", "(", "array", "$", "callbacks", "=", "[", "]", ")", "{", "foreach", "(", "$", "callbacks", "as", "$", "type", "=>", "$", "items", ")", "{", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "this", "->", "addCallbackJob", "(", "$", "type", ",", "$", "item", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
@param array $callbacks @return $this @throws JobException
[ "@param", "array", "$callbacks" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L998-L1007
cronario/cronario
src/AbstractJob.php
AbstractJob.addCallbackJob
protected function addCallbackJob($type, $job) { if (is_object($job) && $job instanceof self) { $this->data[self::P_CALLBACKS][$type][] = serialize($job); $this->callbacks[$type][] = $job; return $this; } if (is_string($job)) { $this->data[self::P_CALLBACKS][$type][] = $job; $this->callbacks[$type][] = unserialize($job); return $this; } throw new JobException('Callback job must be a serialized string OR object!'); }
php
protected function addCallbackJob($type, $job) { if (is_object($job) && $job instanceof self) { $this->data[self::P_CALLBACKS][$type][] = serialize($job); $this->callbacks[$type][] = $job; return $this; } if (is_string($job)) { $this->data[self::P_CALLBACKS][$type][] = $job; $this->callbacks[$type][] = unserialize($job); return $this; } throw new JobException('Callback job must be a serialized string OR object!'); }
[ "protected", "function", "addCallbackJob", "(", "$", "type", ",", "$", "job", ")", "{", "if", "(", "is_object", "(", "$", "job", ")", "&&", "$", "job", "instanceof", "self", ")", "{", "$", "this", "->", "data", "[", "self", "::", "P_CALLBACKS", "]", "[", "$", "type", "]", "[", "]", "=", "serialize", "(", "$", "job", ")", ";", "$", "this", "->", "callbacks", "[", "$", "type", "]", "[", "]", "=", "$", "job", ";", "return", "$", "this", ";", "}", "if", "(", "is_string", "(", "$", "job", ")", ")", "{", "$", "this", "->", "data", "[", "self", "::", "P_CALLBACKS", "]", "[", "$", "type", "]", "[", "]", "=", "$", "job", ";", "$", "this", "->", "callbacks", "[", "$", "type", "]", "[", "]", "=", "unserialize", "(", "$", "job", ")", ";", "return", "$", "this", ";", "}", "throw", "new", "JobException", "(", "'Callback job must be a serialized string OR object!'", ")", ";", "}" ]
@param $type @param $job @return $this @throws JobException
[ "@param", "$type", "@param", "$job" ]
train
https://github.com/cronario/cronario/blob/954df60e95efd3085269331d435e8ce6f4980441/src/AbstractJob.php#L1092-L1109
FrenchFrogs/framework
src/Laravel/Database/Eloquent/Model.php
Model.insertAndSetId
protected function insertAndSetId(Builder $query, $attributes) { $keyName = $this->getKeyName(); // uuid management if ($this->uuid) { $id = uuid(); $attributes[$keyName] = $id; $query->insert($attributes); // auto increment } else { $id = $query->insertGetId($attributes,$keyName); } $this->setAttribute($keyName, $id); }
php
protected function insertAndSetId(Builder $query, $attributes) { $keyName = $this->getKeyName(); // uuid management if ($this->uuid) { $id = uuid(); $attributes[$keyName] = $id; $query->insert($attributes); // auto increment } else { $id = $query->insertGetId($attributes,$keyName); } $this->setAttribute($keyName, $id); }
[ "protected", "function", "insertAndSetId", "(", "Builder", "$", "query", ",", "$", "attributes", ")", "{", "$", "keyName", "=", "$", "this", "->", "getKeyName", "(", ")", ";", "// uuid management", "if", "(", "$", "this", "->", "uuid", ")", "{", "$", "id", "=", "uuid", "(", ")", ";", "$", "attributes", "[", "$", "keyName", "]", "=", "$", "id", ";", "$", "query", "->", "insert", "(", "$", "attributes", ")", ";", "// auto increment", "}", "else", "{", "$", "id", "=", "$", "query", "->", "insertGetId", "(", "$", "attributes", ",", "$", "keyName", ")", ";", "}", "$", "this", "->", "setAttribute", "(", "$", "keyName", ",", "$", "id", ")", ";", "}" ]
Insert the given attributes and set the ID on the model. @param \Illuminate\Database\Eloquent\Builder $query @param array $attributes @return void
[ "Insert", "the", "given", "attributes", "and", "set", "the", "ID", "on", "the", "model", "." ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Laravel/Database/Eloquent/Model.php#L40-L56
FrenchFrogs/framework
src/Laravel/Database/Eloquent/Model.php
Model.getCasts
public function getCasts() { if ($this->incrementing && !$this->uuid){ return array_merge([ $this->getKeyName() => 'int', ], $this->casts); } return $this->casts; }
php
public function getCasts() { if ($this->incrementing && !$this->uuid){ return array_merge([ $this->getKeyName() => 'int', ], $this->casts); } return $this->casts; }
[ "public", "function", "getCasts", "(", ")", "{", "if", "(", "$", "this", "->", "incrementing", "&&", "!", "$", "this", "->", "uuid", ")", "{", "return", "array_merge", "(", "[", "$", "this", "->", "getKeyName", "(", ")", "=>", "'int'", ",", "]", ",", "$", "this", "->", "casts", ")", ";", "}", "return", "$", "this", "->", "casts", ";", "}" ]
Get the casts array. @return array
[ "Get", "the", "casts", "array", "." ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Laravel/Database/Eloquent/Model.php#L64-L73
gdbots/pbjx-bundle-php
src/Command/CreateSchedulerStorageCommand.php
CreateSchedulerStorageCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $io->title('Scheduler Storage Creator'); $this->getPbjxServiceLocator()->getScheduler()->createStorage(); $io->success(sprintf('Scheduler storage created.')); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $io->title('Scheduler Storage Creator'); $this->getPbjxServiceLocator()->getScheduler()->createStorage(); $io->success(sprintf('Scheduler storage created.')); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "io", "=", "new", "SymfonyStyle", "(", "$", "input", ",", "$", "output", ")", ";", "$", "io", "->", "title", "(", "'Scheduler Storage Creator'", ")", ";", "$", "this", "->", "getPbjxServiceLocator", "(", ")", "->", "getScheduler", "(", ")", "->", "createStorage", "(", ")", ";", "$", "io", "->", "success", "(", "sprintf", "(", "'Scheduler storage created.'", ")", ")", ";", "}" ]
@param InputInterface $input @param OutputInterface $output @return null @throws \Exception
[ "@param", "InputInterface", "$input", "@param", "OutputInterface", "$output" ]
train
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/Command/CreateSchedulerStorageCommand.php#L50-L57
sanpii/assetic
src/Assetic/Filter/UglifyJsFilter.php
UglifyJsFilter.filterDump
public function filterDump(AssetInterface $asset) { $commandline = $this->nodeBin ? array($this->nodeBin, $this->uglifyjsBin) : array($this->uglifyjsBin); if ($this->noCopyright) { array_push($commandline, '--no-copyright'); } if ($this->beautify) { array_push($commandline, '--beautify'); } if ($this->unsafe) { array_push($commandline, '--unsafe'); } if (false === $this->mangle) { array_push($commandline, '--no-mangle'); } if ($this->defines) { foreach ($this->defines as $define) { array_push($commandline, '-d', $define); } } // input and output files $input = FilesystemUtils::createTemporaryFile('uglifyjs_in'); $output = FilesystemUtils::createTemporaryFile('uglifyjs_out'); file_put_contents($input, $asset->getContent()); array_push($commandline, '-o', $output, $input); $proc = new Process(implode(' ', $commandline)); $code = $proc->run(); unlink($input); if (0 !== $code) { if (file_exists($output)) { unlink($output); } if (127 === $code) { throw new \RuntimeException('Path to node executable could not be resolved.'); } throw FilterException::fromProcess($proc)->setInput($asset->getContent()); } if (!file_exists($output)) { throw new \RuntimeException('Error creating output file.'); } $uglifiedJs = file_get_contents($output); unlink($output); $asset->setContent($uglifiedJs); }
php
public function filterDump(AssetInterface $asset) { $commandline = $this->nodeBin ? array($this->nodeBin, $this->uglifyjsBin) : array($this->uglifyjsBin); if ($this->noCopyright) { array_push($commandline, '--no-copyright'); } if ($this->beautify) { array_push($commandline, '--beautify'); } if ($this->unsafe) { array_push($commandline, '--unsafe'); } if (false === $this->mangle) { array_push($commandline, '--no-mangle'); } if ($this->defines) { foreach ($this->defines as $define) { array_push($commandline, '-d', $define); } } // input and output files $input = FilesystemUtils::createTemporaryFile('uglifyjs_in'); $output = FilesystemUtils::createTemporaryFile('uglifyjs_out'); file_put_contents($input, $asset->getContent()); array_push($commandline, '-o', $output, $input); $proc = new Process(implode(' ', $commandline)); $code = $proc->run(); unlink($input); if (0 !== $code) { if (file_exists($output)) { unlink($output); } if (127 === $code) { throw new \RuntimeException('Path to node executable could not be resolved.'); } throw FilterException::fromProcess($proc)->setInput($asset->getContent()); } if (!file_exists($output)) { throw new \RuntimeException('Error creating output file.'); } $uglifiedJs = file_get_contents($output); unlink($output); $asset->setContent($uglifiedJs); }
[ "public", "function", "filterDump", "(", "AssetInterface", "$", "asset", ")", "{", "$", "commandline", "=", "$", "this", "->", "nodeBin", "?", "array", "(", "$", "this", "->", "nodeBin", ",", "$", "this", "->", "uglifyjsBin", ")", ":", "array", "(", "$", "this", "->", "uglifyjsBin", ")", ";", "if", "(", "$", "this", "->", "noCopyright", ")", "{", "array_push", "(", "$", "commandline", ",", "'--no-copyright'", ")", ";", "}", "if", "(", "$", "this", "->", "beautify", ")", "{", "array_push", "(", "$", "commandline", ",", "'--beautify'", ")", ";", "}", "if", "(", "$", "this", "->", "unsafe", ")", "{", "array_push", "(", "$", "commandline", ",", "'--unsafe'", ")", ";", "}", "if", "(", "false", "===", "$", "this", "->", "mangle", ")", "{", "array_push", "(", "$", "commandline", ",", "'--no-mangle'", ")", ";", "}", "if", "(", "$", "this", "->", "defines", ")", "{", "foreach", "(", "$", "this", "->", "defines", "as", "$", "define", ")", "{", "array_push", "(", "$", "commandline", ",", "'-d'", ",", "$", "define", ")", ";", "}", "}", "// input and output files", "$", "input", "=", "FilesystemUtils", "::", "createTemporaryFile", "(", "'uglifyjs_in'", ")", ";", "$", "output", "=", "FilesystemUtils", "::", "createTemporaryFile", "(", "'uglifyjs_out'", ")", ";", "file_put_contents", "(", "$", "input", ",", "$", "asset", "->", "getContent", "(", ")", ")", ";", "array_push", "(", "$", "commandline", ",", "'-o'", ",", "$", "output", ",", "$", "input", ")", ";", "$", "proc", "=", "new", "Process", "(", "implode", "(", "' '", ",", "$", "commandline", ")", ")", ";", "$", "code", "=", "$", "proc", "->", "run", "(", ")", ";", "unlink", "(", "$", "input", ")", ";", "if", "(", "0", "!==", "$", "code", ")", "{", "if", "(", "file_exists", "(", "$", "output", ")", ")", "{", "unlink", "(", "$", "output", ")", ";", "}", "if", "(", "127", "===", "$", "code", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Path to node executable could not be resolved.'", ")", ";", "}", "throw", "FilterException", "::", "fromProcess", "(", "$", "proc", ")", "->", "setInput", "(", "$", "asset", "->", "getContent", "(", ")", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "output", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Error creating output file.'", ")", ";", "}", "$", "uglifiedJs", "=", "file_get_contents", "(", "$", "output", ")", ";", "unlink", "(", "$", "output", ")", ";", "$", "asset", "->", "setContent", "(", "$", "uglifiedJs", ")", ";", "}" ]
Run the asset through UglifyJs @see \Assetic\Filter\FilterInterface::filterDump()
[ "Run", "the", "asset", "through", "UglifyJs" ]
train
https://github.com/sanpii/assetic/blob/5c446eee54cc396cbbd6e252108f430e6e617c95/src/Assetic/Filter/UglifyJsFilter.php#L103-L162
esperecyan/dictionary-php
src/Dictionary.php
Dictionary.setMetadata
public function setMetadata(array $metadata) { $this->metadata = $this->validator->parseMetadata(array_filter($metadata, function ($field): bool { // 文字列型以外の (明らかに構文解析済みである) フィールドは構文解析器にかけない return is_string($field); })) + $metadata; }
php
public function setMetadata(array $metadata) { $this->metadata = $this->validator->parseMetadata(array_filter($metadata, function ($field): bool { // 文字列型以外の (明らかに構文解析済みである) フィールドは構文解析器にかけない return is_string($field); })) + $metadata; }
[ "public", "function", "setMetadata", "(", "array", "$", "metadata", ")", "{", "$", "this", "->", "metadata", "=", "$", "this", "->", "validator", "->", "parseMetadata", "(", "array_filter", "(", "$", "metadata", ",", "function", "(", "$", "field", ")", ":", "bool", "{", "// 文字列型以外の (明らかに構文解析済みである) フィールドは構文解析器にかけない", "return", "is_string", "(", "$", "field", ")", ";", "}", ")", ")", "+", "$", "metadata", ";", "}" ]
メタフィールドを設定します。 @param (string|string[])[]
[ "メタフィールドを設定します。" ]
train
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/Dictionary.php#L82-L88
esperecyan/dictionary-php
src/Dictionary.php
Dictionary.updateFilenames
protected function updateFilenames(): void { $this->files->setFlags(\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS); $this->filenames = array_keys(iterator_to_array($this->files)); }
php
protected function updateFilenames(): void { $this->files->setFlags(\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS); $this->filenames = array_keys(iterator_to_array($this->files)); }
[ "protected", "function", "updateFilenames", "(", ")", ":", "void", "{", "$", "this", "->", "files", "->", "setFlags", "(", "\\", "FilesystemIterator", "::", "KEY_AS_FILENAME", "|", "\\", "FilesystemIterator", "::", "CURRENT_AS_FILEINFO", "|", "\\", "FilesystemIterator", "::", "SKIP_DOTS", ")", ";", "$", "this", "->", "filenames", "=", "array_keys", "(", "iterator_to_array", "(", "$", "this", "->", "files", ")", ")", ";", "}" ]
$this->files からファイル名を抽出して $this->filenames に設定します。
[ "$this", "-", ">", "files", "からファイル名を抽出して", "$this", "-", ">", "filenames", "に設定します。" ]
train
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/Dictionary.php#L150-L156
fproject/yii2-flex
fproject/widgets/FlexWidget.php
FlexWidget.run
public function run() { if(empty($this->name)) throw new Exception(Yii::t('fproject/yii2-flex','FlexWidget.name cannot be empty.')); if(empty($this->baseUrl)) throw new Exception(Yii::t('fproject/yii2-flex','FlexWidget.baseUrl cannot be empty.')); if($this->altHtmlContent===null) $this->altHtmlContent=Yii::t('fproject/yii2-flex','This content requires the {link}',[ 'link' => '<a href="http://www.adobe.com/go/getflash/">Adobe Flash Player</a>.', ]); $this->registerClientScript(); return $this->render('flexWidget', [ 'name' => $this->name, 'logoUrl' => $this->logoUrl, 'flashVersion' => $this->flashVersion, 'baseUrl' => $this->baseUrl, 'flashVarsAsString' => $this->flashVarsAsString, 'quality' => $this->quality, 'bgColor' => $this->bgColor, 'allowScriptAccess' => $this->allowScriptAccess, 'allowFullScreen' => $this->b2s($this->allowFullScreen), 'allowFullScreenInteractive' => $this->b2s($this->allowFullScreenInteractive), 'width' => $this->width, 'height' => $this->height, 'align' => $this->align, ]); }
php
public function run() { if(empty($this->name)) throw new Exception(Yii::t('fproject/yii2-flex','FlexWidget.name cannot be empty.')); if(empty($this->baseUrl)) throw new Exception(Yii::t('fproject/yii2-flex','FlexWidget.baseUrl cannot be empty.')); if($this->altHtmlContent===null) $this->altHtmlContent=Yii::t('fproject/yii2-flex','This content requires the {link}',[ 'link' => '<a href="http://www.adobe.com/go/getflash/">Adobe Flash Player</a>.', ]); $this->registerClientScript(); return $this->render('flexWidget', [ 'name' => $this->name, 'logoUrl' => $this->logoUrl, 'flashVersion' => $this->flashVersion, 'baseUrl' => $this->baseUrl, 'flashVarsAsString' => $this->flashVarsAsString, 'quality' => $this->quality, 'bgColor' => $this->bgColor, 'allowScriptAccess' => $this->allowScriptAccess, 'allowFullScreen' => $this->b2s($this->allowFullScreen), 'allowFullScreenInteractive' => $this->b2s($this->allowFullScreenInteractive), 'width' => $this->width, 'height' => $this->height, 'align' => $this->align, ]); }
[ "public", "function", "run", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "name", ")", ")", "throw", "new", "Exception", "(", "Yii", "::", "t", "(", "'fproject/yii2-flex'", ",", "'FlexWidget.name cannot be empty.'", ")", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "baseUrl", ")", ")", "throw", "new", "Exception", "(", "Yii", "::", "t", "(", "'fproject/yii2-flex'", ",", "'FlexWidget.baseUrl cannot be empty.'", ")", ")", ";", "if", "(", "$", "this", "->", "altHtmlContent", "===", "null", ")", "$", "this", "->", "altHtmlContent", "=", "Yii", "::", "t", "(", "'fproject/yii2-flex'", ",", "'This content requires the {link}'", ",", "[", "'link'", "=>", "'<a href=\"http://www.adobe.com/go/getflash/\">Adobe Flash Player</a>.'", ",", "]", ")", ";", "$", "this", "->", "registerClientScript", "(", ")", ";", "return", "$", "this", "->", "render", "(", "'flexWidget'", ",", "[", "'name'", "=>", "$", "this", "->", "name", ",", "'logoUrl'", "=>", "$", "this", "->", "logoUrl", ",", "'flashVersion'", "=>", "$", "this", "->", "flashVersion", ",", "'baseUrl'", "=>", "$", "this", "->", "baseUrl", ",", "'flashVarsAsString'", "=>", "$", "this", "->", "flashVarsAsString", ",", "'quality'", "=>", "$", "this", "->", "quality", ",", "'bgColor'", "=>", "$", "this", "->", "bgColor", ",", "'allowScriptAccess'", "=>", "$", "this", "->", "allowScriptAccess", ",", "'allowFullScreen'", "=>", "$", "this", "->", "b2s", "(", "$", "this", "->", "allowFullScreen", ")", ",", "'allowFullScreenInteractive'", "=>", "$", "this", "->", "b2s", "(", "$", "this", "->", "allowFullScreenInteractive", ")", ",", "'width'", "=>", "$", "this", "->", "width", ",", "'height'", "=>", "$", "this", "->", "height", ",", "'align'", "=>", "$", "this", "->", "align", ",", "]", ")", ";", "}" ]
Renders the widget.
[ "Renders", "the", "widget", "." ]
train
https://github.com/fproject/yii2-flex/blob/661c8532484ce90592af9111df3cccf4091b10a7/fproject/widgets/FlexWidget.php#L156-L184
fproject/yii2-flex
fproject/widgets/FlexWidget.php
FlexWidget.registerClientScript
public function registerClientScript() { $view = $this->getView(); $view->registerJsFile($this->baseUrl.'/swfobject.js',['position'=>View::POS_BEGIN]); if($this->enableHistory) { $view->registerCssFile($this->baseUrl.'/history/history.css'); $view->registerJsFile($this->baseUrl.'/history/history.js'); } if($this->allowWsBridge) { $view->registerJsFile($this->baseUrl.'/ws_bridge.js',['position'=>View::POS_END]); } }
php
public function registerClientScript() { $view = $this->getView(); $view->registerJsFile($this->baseUrl.'/swfobject.js',['position'=>View::POS_BEGIN]); if($this->enableHistory) { $view->registerCssFile($this->baseUrl.'/history/history.css'); $view->registerJsFile($this->baseUrl.'/history/history.js'); } if($this->allowWsBridge) { $view->registerJsFile($this->baseUrl.'/ws_bridge.js',['position'=>View::POS_END]); } }
[ "public", "function", "registerClientScript", "(", ")", "{", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "$", "view", "->", "registerJsFile", "(", "$", "this", "->", "baseUrl", ".", "'/swfobject.js'", ",", "[", "'position'", "=>", "View", "::", "POS_BEGIN", "]", ")", ";", "if", "(", "$", "this", "->", "enableHistory", ")", "{", "$", "view", "->", "registerCssFile", "(", "$", "this", "->", "baseUrl", ".", "'/history/history.css'", ")", ";", "$", "view", "->", "registerJsFile", "(", "$", "this", "->", "baseUrl", ".", "'/history/history.js'", ")", ";", "}", "if", "(", "$", "this", "->", "allowWsBridge", ")", "{", "$", "view", "->", "registerJsFile", "(", "$", "this", "->", "baseUrl", ".", "'/ws_bridge.js'", ",", "[", "'position'", "=>", "View", "::", "POS_END", "]", ")", ";", "}", "}" ]
Registers the needed CSS and JavaScript.
[ "Registers", "the", "needed", "CSS", "and", "JavaScript", "." ]
train
https://github.com/fproject/yii2-flex/blob/661c8532484ce90592af9111df3cccf4091b10a7/fproject/widgets/FlexWidget.php#L199-L212
fproject/yii2-flex
fproject/widgets/FlexWidget.php
FlexWidget.getFlashVarsAsString
public function getFlashVarsAsString() { $params=array(); foreach($this->flashVars as $k=>$v) { if(!is_string($v)) $v = json_encode($v); $params[] = $k.':"'.urlencode($v).'"'; } if(!array_key_exists('baseUrl', $this->flashVars)) $params[] = 'baseUrl:"'.urlencode($this->baseUrl).'"'; if(!array_key_exists('moduleBaseUrl', $this->flashVars)) $params[] = 'moduleBaseUrl:"'.urlencode($this->moduleBaseUrl).'"'; if(!array_key_exists('rslBaseUrl', $this->flashVars)) $params[] = 'rslBaseUrl:"'.urlencode($this->rslBaseUrl).'"'; if(!array_key_exists('locale', $this->flashVars)) $params[] = 'locale:"'.urlencode($this->getFlexLocale(Yii::$app->language)).'"'; return implode(',',$params); }
php
public function getFlashVarsAsString() { $params=array(); foreach($this->flashVars as $k=>$v) { if(!is_string($v)) $v = json_encode($v); $params[] = $k.':"'.urlencode($v).'"'; } if(!array_key_exists('baseUrl', $this->flashVars)) $params[] = 'baseUrl:"'.urlencode($this->baseUrl).'"'; if(!array_key_exists('moduleBaseUrl', $this->flashVars)) $params[] = 'moduleBaseUrl:"'.urlencode($this->moduleBaseUrl).'"'; if(!array_key_exists('rslBaseUrl', $this->flashVars)) $params[] = 'rslBaseUrl:"'.urlencode($this->rslBaseUrl).'"'; if(!array_key_exists('locale', $this->flashVars)) $params[] = 'locale:"'.urlencode($this->getFlexLocale(Yii::$app->language)).'"'; return implode(',',$params); }
[ "public", "function", "getFlashVarsAsString", "(", ")", "{", "$", "params", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "flashVars", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "!", "is_string", "(", "$", "v", ")", ")", "$", "v", "=", "json_encode", "(", "$", "v", ")", ";", "$", "params", "[", "]", "=", "$", "k", ".", "':\"'", ".", "urlencode", "(", "$", "v", ")", ".", "'\"'", ";", "}", "if", "(", "!", "array_key_exists", "(", "'baseUrl'", ",", "$", "this", "->", "flashVars", ")", ")", "$", "params", "[", "]", "=", "'baseUrl:\"'", ".", "urlencode", "(", "$", "this", "->", "baseUrl", ")", ".", "'\"'", ";", "if", "(", "!", "array_key_exists", "(", "'moduleBaseUrl'", ",", "$", "this", "->", "flashVars", ")", ")", "$", "params", "[", "]", "=", "'moduleBaseUrl:\"'", ".", "urlencode", "(", "$", "this", "->", "moduleBaseUrl", ")", ".", "'\"'", ";", "if", "(", "!", "array_key_exists", "(", "'rslBaseUrl'", ",", "$", "this", "->", "flashVars", ")", ")", "$", "params", "[", "]", "=", "'rslBaseUrl:\"'", ".", "urlencode", "(", "$", "this", "->", "rslBaseUrl", ")", ".", "'\"'", ";", "if", "(", "!", "array_key_exists", "(", "'locale'", ",", "$", "this", "->", "flashVars", ")", ")", "$", "params", "[", "]", "=", "'locale:\"'", ".", "urlencode", "(", "$", "this", "->", "getFlexLocale", "(", "Yii", "::", "$", "app", "->", "language", ")", ")", ".", "'\"'", ";", "return", "implode", "(", "','", ",", "$", "params", ")", ";", "}" ]
Generates the properly quoted flash parameter string. @return string the flash parameter string.
[ "Generates", "the", "properly", "quoted", "flash", "parameter", "string", "." ]
train
https://github.com/fproject/yii2-flex/blob/661c8532484ce90592af9111df3cccf4091b10a7/fproject/widgets/FlexWidget.php#L218-L241
fproject/yii2-flex
fproject/widgets/FlexWidget.php
FlexWidget.getFlexLocale
private function getFlexLocale($language) { if(!empty($language)) { $split = explode("-", $language, 2); if(count($split) == 2 && $split[1] != "") { $split[1] = strtoupper($split[1]); } else { $split = null; } } if(empty($split)) $split = ['en', 'US']; return $split[0] . self::LANGUAGUE_SEPARATOR . $split[1]; }
php
private function getFlexLocale($language) { if(!empty($language)) { $split = explode("-", $language, 2); if(count($split) == 2 && $split[1] != "") { $split[1] = strtoupper($split[1]); } else { $split = null; } } if(empty($split)) $split = ['en', 'US']; return $split[0] . self::LANGUAGUE_SEPARATOR . $split[1]; }
[ "private", "function", "getFlexLocale", "(", "$", "language", ")", "{", "if", "(", "!", "empty", "(", "$", "language", ")", ")", "{", "$", "split", "=", "explode", "(", "\"-\"", ",", "$", "language", ",", "2", ")", ";", "if", "(", "count", "(", "$", "split", ")", "==", "2", "&&", "$", "split", "[", "1", "]", "!=", "\"\"", ")", "{", "$", "split", "[", "1", "]", "=", "strtoupper", "(", "$", "split", "[", "1", "]", ")", ";", "}", "else", "{", "$", "split", "=", "null", ";", "}", "}", "if", "(", "empty", "(", "$", "split", ")", ")", "$", "split", "=", "[", "'en'", ",", "'US'", "]", ";", "return", "$", "split", "[", "0", "]", ".", "self", "::", "LANGUAGUE_SEPARATOR", ".", "$", "split", "[", "1", "]", ";", "}" ]
Returns locale with format for flex application @param string $language the app language @return string
[ "Returns", "locale", "with", "format", "for", "flex", "application" ]
train
https://github.com/fproject/yii2-flex/blob/661c8532484ce90592af9111df3cccf4091b10a7/fproject/widgets/FlexWidget.php#L248-L264
okvpn/fixture-bundle
src/Migration/UpdateDataFixturesFixture.php
UpdateDataFixturesFixture.load
public function load(ObjectManager $manager) { if (!empty($this->dataFixturesClassNames)) { $loadedAt = new \DateTime('now', new \DateTimeZone('UTC')); foreach ($this->dataFixturesClassNames as $className => $version) { $dataFixture = null; if ($version !== null) { $dataFixture = $manager ->getRepository('OkvpnFixtureBundle:DataFixture') ->findOneBy(['className' => $className]); } if (!$dataFixture) { $dataFixture = new DataFixture(); $dataFixture->setClassName($className); } $dataFixture ->setVersion($version) ->setLoadedAt($loadedAt); $manager->persist($dataFixture); } $manager->flush(); } }
php
public function load(ObjectManager $manager) { if (!empty($this->dataFixturesClassNames)) { $loadedAt = new \DateTime('now', new \DateTimeZone('UTC')); foreach ($this->dataFixturesClassNames as $className => $version) { $dataFixture = null; if ($version !== null) { $dataFixture = $manager ->getRepository('OkvpnFixtureBundle:DataFixture') ->findOneBy(['className' => $className]); } if (!$dataFixture) { $dataFixture = new DataFixture(); $dataFixture->setClassName($className); } $dataFixture ->setVersion($version) ->setLoadedAt($loadedAt); $manager->persist($dataFixture); } $manager->flush(); } }
[ "public", "function", "load", "(", "ObjectManager", "$", "manager", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "dataFixturesClassNames", ")", ")", "{", "$", "loadedAt", "=", "new", "\\", "DateTime", "(", "'now'", ",", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "foreach", "(", "$", "this", "->", "dataFixturesClassNames", "as", "$", "className", "=>", "$", "version", ")", "{", "$", "dataFixture", "=", "null", ";", "if", "(", "$", "version", "!==", "null", ")", "{", "$", "dataFixture", "=", "$", "manager", "->", "getRepository", "(", "'OkvpnFixtureBundle:DataFixture'", ")", "->", "findOneBy", "(", "[", "'className'", "=>", "$", "className", "]", ")", ";", "}", "if", "(", "!", "$", "dataFixture", ")", "{", "$", "dataFixture", "=", "new", "DataFixture", "(", ")", ";", "$", "dataFixture", "->", "setClassName", "(", "$", "className", ")", ";", "}", "$", "dataFixture", "->", "setVersion", "(", "$", "version", ")", "->", "setLoadedAt", "(", "$", "loadedAt", ")", ";", "$", "manager", "->", "persist", "(", "$", "dataFixture", ")", ";", "}", "$", "manager", "->", "flush", "(", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/okvpn/fixture-bundle/blob/243b5e4dff9773e97fa447280e929c936a5d66ae/src/Migration/UpdateDataFixturesFixture.php#L31-L54
prooph/link-app-core
src/Command/ConfigureJavascriptTicker.php
ConfigureJavascriptTicker.assertPayload
protected function assertPayload($aPayload = null) { if (! array_key_exists('enabled', $aPayload) || ! array_key_exists('interval', $aPayload)) { throw new \InvalidArgumentException('Payload does not contain a enabled or interval key'); } if (! is_bool($aPayload['enabled'])) throw new \InvalidArgumentException('Enabled flag must be a boolean value'); if (! is_int($aPayload['interval'])) throw new \InvalidArgumentException('Ticker interval must be an integer'); }
php
protected function assertPayload($aPayload = null) { if (! array_key_exists('enabled', $aPayload) || ! array_key_exists('interval', $aPayload)) { throw new \InvalidArgumentException('Payload does not contain a enabled or interval key'); } if (! is_bool($aPayload['enabled'])) throw new \InvalidArgumentException('Enabled flag must be a boolean value'); if (! is_int($aPayload['interval'])) throw new \InvalidArgumentException('Ticker interval must be an integer'); }
[ "protected", "function", "assertPayload", "(", "$", "aPayload", "=", "null", ")", "{", "if", "(", "!", "array_key_exists", "(", "'enabled'", ",", "$", "aPayload", ")", "||", "!", "array_key_exists", "(", "'interval'", ",", "$", "aPayload", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Payload does not contain a enabled or interval key'", ")", ";", "}", "if", "(", "!", "is_bool", "(", "$", "aPayload", "[", "'enabled'", "]", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'Enabled flag must be a boolean value'", ")", ";", "if", "(", "!", "is_int", "(", "$", "aPayload", "[", "'interval'", "]", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'Ticker interval must be an integer'", ")", ";", "}" ]
Assert that payload contains all required information for this command @param null|array $aPayload @throws \InvalidArgumentException
[ "Assert", "that", "payload", "contains", "all", "required", "information", "for", "this", "command" ]
train
https://github.com/prooph/link-app-core/blob/835a5945dfa7be7b2cebfa6e84e757ecfd783357/src/Command/ConfigureJavascriptTicker.php#L60-L68
pageon/SlackWebhookMonolog
src/General/Url.php
Url.setUrl
private function setUrl($url) { // remove the whitespace $url = trim($url); // @see https://gist.github.com/dperini/729294 and https://mathiasbynens.be/demo/url-regex $urlValidationRegex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS'; if (!preg_match($urlValidationRegex, $url)) { throw new InvalidUrlException(sprintf('The url: "%s" is not a valid url.', $url), 400); } $this->url = $url; return $this; }
php
private function setUrl($url) { // remove the whitespace $url = trim($url); // @see https://gist.github.com/dperini/729294 and https://mathiasbynens.be/demo/url-regex $urlValidationRegex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS'; if (!preg_match($urlValidationRegex, $url)) { throw new InvalidUrlException(sprintf('The url: "%s" is not a valid url.', $url), 400); } $this->url = $url; return $this; }
[ "private", "function", "setUrl", "(", "$", "url", ")", "{", "// remove the whitespace", "$", "url", "=", "trim", "(", "$", "url", ")", ";", "// @see https://gist.github.com/dperini/729294 and https://mathiasbynens.be/demo/url-regex", "$", "urlValidationRegex", "=", "'_^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)*(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}]{2,})))(?::\\d{2,5})?(?:/[^\\s]*)?$_iuS'", ";", "if", "(", "!", "preg_match", "(", "$", "urlValidationRegex", ",", "$", "url", ")", ")", "{", "throw", "new", "InvalidUrlException", "(", "sprintf", "(", "'The url: \"%s\" is not a valid url.'", ",", "$", "url", ")", ",", "400", ")", ";", "}", "$", "this", "->", "url", "=", "$", "url", ";", "return", "$", "this", ";", "}" ]
@param string $url @throws InvalidUrlException Thrown when the url is not valid @return $this
[ "@param", "string", "$url" ]
train
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/General/Url.php#L34-L47
movoin/one-swoole
src/Protocol/Providers/ExceptionHandler.php
ExceptionHandler.boot
public function boot() { register_shutdown_function(function () { $error = error_get_last(); $trace = debug_backtrace(); if (isset($error['type'])) { switch ($error['type']) { case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: // {{ log $this->log('error', '核心错误', [ 'error' => $error, 'trace' => $trace ]); // }} break; default: break; } } unset($error, $trace); }); }
php
public function boot() { register_shutdown_function(function () { $error = error_get_last(); $trace = debug_backtrace(); if (isset($error['type'])) { switch ($error['type']) { case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: // {{ log $this->log('error', '核心错误', [ 'error' => $error, 'trace' => $trace ]); // }} break; default: break; } } unset($error, $trace); }); }
[ "public", "function", "boot", "(", ")", "{", "register_shutdown_function", "(", "function", "(", ")", "{", "$", "error", "=", "error_get_last", "(", ")", ";", "$", "trace", "=", "debug_backtrace", "(", ")", ";", "if", "(", "isset", "(", "$", "error", "[", "'type'", "]", ")", ")", "{", "switch", "(", "$", "error", "[", "'type'", "]", ")", "{", "case", "E_ERROR", ":", "case", "E_PARSE", ":", "case", "E_CORE_ERROR", ":", "case", "E_COMPILE_ERROR", ":", "case", "E_USER_ERROR", ":", "// {{ log", "$", "this", "->", "log", "(", "'error'", ",", "'核心错误', [", "", "", "'error'", "=>", "$", "error", ",", "'trace'", "=>", "$", "trace", "]", ")", ";", "// }}", "break", ";", "default", ":", "break", ";", "}", "}", "unset", "(", "$", "error", ",", "$", "trace", ")", ";", "}", ")", ";", "}" ]
初始化环境
[ "初始化环境" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Providers/ExceptionHandler.php#L22-L50
ua1-labs/firebug
Fire/Bug/Panel.php
Panel.renderLabel
public function renderLabel($content, $class = '', $style = '') { $styleAttr = ($style) ? ' style="' . $style . '"' : ''; $classes = ($class) ? ' ' . $class : ''; $renderLabel = ''; $renderLabel .= '<span class="fs-label' . $classes . '"' . $style . '>'; $renderLabel .= $content; $renderLabel .= '</span>'; return $renderLabel; }
php
public function renderLabel($content, $class = '', $style = '') { $styleAttr = ($style) ? ' style="' . $style . '"' : ''; $classes = ($class) ? ' ' . $class : ''; $renderLabel = ''; $renderLabel .= '<span class="fs-label' . $classes . '"' . $style . '>'; $renderLabel .= $content; $renderLabel .= '</span>'; return $renderLabel; }
[ "public", "function", "renderLabel", "(", "$", "content", ",", "$", "class", "=", "''", ",", "$", "style", "=", "''", ")", "{", "$", "styleAttr", "=", "(", "$", "style", ")", "?", "' style=\"'", ".", "$", "style", ".", "'\"'", ":", "''", ";", "$", "classes", "=", "(", "$", "class", ")", "?", "' '", ".", "$", "class", ":", "''", ";", "$", "renderLabel", "=", "''", ";", "$", "renderLabel", ".=", "'<span class=\"fs-label'", ".", "$", "classes", ".", "'\"'", ".", "$", "style", ".", "'>'", ";", "$", "renderLabel", ".=", "$", "content", ";", "$", "renderLabel", ".=", "'</span>'", ";", "return", "$", "renderLabel", ";", "}" ]
Returns a label. @param string $content The content of the label @param string $class CSV list of classes you want to add @param string $style Custom styles you want added @return string HTML code for the separator
[ "Returns", "a", "label", "." ]
train
https://github.com/ua1-labs/firebug/blob/70a45b2c0bbf64978641eb07e5f3cddfc1951162/Fire/Bug/Panel.php#L90-L99
ua1-labs/firebug
Fire/Bug/Panel.php
Panel.renderSeparator
public function renderSeparator($bold = true, $class = '', $style = '') { $styleAttr = ($style) ? ' style="' . $style . '"' : ''; $classes = ($class) ? ' ' . $class : ''; if ($bold) { return '<hr class="fs-hr' . $classes . '"' . $styleAttr . '>'; } else { return '<hr class="fs-hr-dotted' . $classes . '"' . $styleAttr . '>'; } }
php
public function renderSeparator($bold = true, $class = '', $style = '') { $styleAttr = ($style) ? ' style="' . $style . '"' : ''; $classes = ($class) ? ' ' . $class : ''; if ($bold) { return '<hr class="fs-hr' . $classes . '"' . $styleAttr . '>'; } else { return '<hr class="fs-hr-dotted' . $classes . '"' . $styleAttr . '>'; } }
[ "public", "function", "renderSeparator", "(", "$", "bold", "=", "true", ",", "$", "class", "=", "''", ",", "$", "style", "=", "''", ")", "{", "$", "styleAttr", "=", "(", "$", "style", ")", "?", "' style=\"'", ".", "$", "style", ".", "'\"'", ":", "''", ";", "$", "classes", "=", "(", "$", "class", ")", "?", "' '", ".", "$", "class", ":", "''", ";", "if", "(", "$", "bold", ")", "{", "return", "'<hr class=\"fs-hr'", ".", "$", "classes", ".", "'\"'", ".", "$", "styleAttr", ".", "'>'", ";", "}", "else", "{", "return", "'<hr class=\"fs-hr-dotted'", ".", "$", "classes", ".", "'\"'", ".", "$", "styleAttr", ".", "'>'", ";", "}", "}" ]
Returns a separator. @param boolean $bold Do you want a bold separator @param string $class CSV list of classes you want to add @param string $style Custom styles you want added @return string HTML code for the separator.
[ "Returns", "a", "separator", "." ]
train
https://github.com/ua1-labs/firebug/blob/70a45b2c0bbf64978641eb07e5f3cddfc1951162/Fire/Bug/Panel.php#L108-L117
ua1-labs/firebug
Fire/Bug/Panel.php
Panel.renderCode
public function renderCode($code, $dark = true) { $darkClass = ($dark) ? ' fs-dark' : ''; $renderCode = ''; $renderCode .= '<span class="fs-label">'; $renderCode .= '<span class="fs-pre-expand">expand</span>'; $renderCode .= ' | '; $renderCode .= '<span class="fs-pre-wrap">wrap</span>'; $renderCode .= '<pre class="debugger'. $darkClass . '">'; $renderCode .= htmlspecialchars($code); $renderCode .= '</pre>'; $renderCode .= '</span>'; return $renderCode; }
php
public function renderCode($code, $dark = true) { $darkClass = ($dark) ? ' fs-dark' : ''; $renderCode = ''; $renderCode .= '<span class="fs-label">'; $renderCode .= '<span class="fs-pre-expand">expand</span>'; $renderCode .= ' | '; $renderCode .= '<span class="fs-pre-wrap">wrap</span>'; $renderCode .= '<pre class="debugger'. $darkClass . '">'; $renderCode .= htmlspecialchars($code); $renderCode .= '</pre>'; $renderCode .= '</span>'; return $renderCode; }
[ "public", "function", "renderCode", "(", "$", "code", ",", "$", "dark", "=", "true", ")", "{", "$", "darkClass", "=", "(", "$", "dark", ")", "?", "' fs-dark'", ":", "''", ";", "$", "renderCode", "=", "''", ";", "$", "renderCode", ".=", "'<span class=\"fs-label\">'", ";", "$", "renderCode", ".=", "'<span class=\"fs-pre-expand\">expand</span>'", ";", "$", "renderCode", ".=", "' | '", ";", "$", "renderCode", ".=", "'<span class=\"fs-pre-wrap\">wrap</span>'", ";", "$", "renderCode", ".=", "'<pre class=\"debugger'", ".", "$", "darkClass", ".", "'\">'", ";", "$", "renderCode", ".=", "htmlspecialchars", "(", "$", "code", ")", ";", "$", "renderCode", ".=", "'</pre>'", ";", "$", "renderCode", ".=", "'</span>'", ";", "return", "$", "renderCode", ";", "}" ]
Returns the code passed in wrapped within a <pre> tag. @param string $content The code you want to render @param boolean $dark Do you want the dark theme? @return string The HTML to render
[ "Returns", "the", "code", "passed", "in", "wrapped", "within", "a", "<pre", ">", "tag", "." ]
train
https://github.com/ua1-labs/firebug/blob/70a45b2c0bbf64978641eb07e5f3cddfc1951162/Fire/Bug/Panel.php#L125-L139
ua1-labs/firebug
Fire/Bug/Panel.php
Panel.renderJson
public function renderJson($json, $dark = true) { if (is_object($json)) { $jsonCode = json_encode($json, JSON_PRETTY_PRINT); } else if (is_array($json)) { $jsonCode = json_encode(($json) ? $json : (object) $json, JSON_PRETTY_PRINT); } else { $jsonCode = json_encode(json_decode($json), JSON_PRETTY_PRINT); } return $this->renderCode($jsonCode, $dark); }
php
public function renderJson($json, $dark = true) { if (is_object($json)) { $jsonCode = json_encode($json, JSON_PRETTY_PRINT); } else if (is_array($json)) { $jsonCode = json_encode(($json) ? $json : (object) $json, JSON_PRETTY_PRINT); } else { $jsonCode = json_encode(json_decode($json), JSON_PRETTY_PRINT); } return $this->renderCode($jsonCode, $dark); }
[ "public", "function", "renderJson", "(", "$", "json", ",", "$", "dark", "=", "true", ")", "{", "if", "(", "is_object", "(", "$", "json", ")", ")", "{", "$", "jsonCode", "=", "json_encode", "(", "$", "json", ",", "JSON_PRETTY_PRINT", ")", ";", "}", "else", "if", "(", "is_array", "(", "$", "json", ")", ")", "{", "$", "jsonCode", "=", "json_encode", "(", "(", "$", "json", ")", "?", "$", "json", ":", "(", "object", ")", "$", "json", ",", "JSON_PRETTY_PRINT", ")", ";", "}", "else", "{", "$", "jsonCode", "=", "json_encode", "(", "json_decode", "(", "$", "json", ")", ",", "JSON_PRETTY_PRINT", ")", ";", "}", "return", "$", "this", "->", "renderCode", "(", "$", "jsonCode", ",", "$", "dark", ")", ";", "}" ]
Returns the JSON passed in wrapped within a <pre> tag. @param string $content The code you want to render @param boolean $dark Do you want the dark theme? @return string The HTML to render
[ "Returns", "the", "JSON", "passed", "in", "wrapped", "within", "a", "<pre", ">", "tag", "." ]
train
https://github.com/ua1-labs/firebug/blob/70a45b2c0bbf64978641eb07e5f3cddfc1951162/Fire/Bug/Panel.php#L147-L157
ua1-labs/firebug
Fire/Bug/Panel.php
Panel.renderTrace
public function renderTrace($debug_backtrace) { $renderTrace = ''; $renderTrace .= '<span class="fs-label">'; foreach ($debug_backtrace as $index => $trace) { $renderTrace .= '#' . $index . ' '; if (!empty($trace['file'])) { $renderTrace .= $trace['file']; } if (!empty($trace['line'])) { $renderTrace .= '(' . $trace['line'] . ') '; } if (!empty($trace['class'])) { $renderTrace .= $trace['class'] . '::'; } $renderTrace .= $trace['function'] . '()' . '<br>'; } $renderTrace .= '</span>'; return $renderTrace; }
php
public function renderTrace($debug_backtrace) { $renderTrace = ''; $renderTrace .= '<span class="fs-label">'; foreach ($debug_backtrace as $index => $trace) { $renderTrace .= '#' . $index . ' '; if (!empty($trace['file'])) { $renderTrace .= $trace['file']; } if (!empty($trace['line'])) { $renderTrace .= '(' . $trace['line'] . ') '; } if (!empty($trace['class'])) { $renderTrace .= $trace['class'] . '::'; } $renderTrace .= $trace['function'] . '()' . '<br>'; } $renderTrace .= '</span>'; return $renderTrace; }
[ "public", "function", "renderTrace", "(", "$", "debug_backtrace", ")", "{", "$", "renderTrace", "=", "''", ";", "$", "renderTrace", ".=", "'<span class=\"fs-label\">'", ";", "foreach", "(", "$", "debug_backtrace", "as", "$", "index", "=>", "$", "trace", ")", "{", "$", "renderTrace", ".=", "'#'", ".", "$", "index", ".", "' '", ";", "if", "(", "!", "empty", "(", "$", "trace", "[", "'file'", "]", ")", ")", "{", "$", "renderTrace", ".=", "$", "trace", "[", "'file'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "trace", "[", "'line'", "]", ")", ")", "{", "$", "renderTrace", ".=", "'('", ".", "$", "trace", "[", "'line'", "]", ".", "') '", ";", "}", "if", "(", "!", "empty", "(", "$", "trace", "[", "'class'", "]", ")", ")", "{", "$", "renderTrace", ".=", "$", "trace", "[", "'class'", "]", ".", "'::'", ";", "}", "$", "renderTrace", ".=", "$", "trace", "[", "'function'", "]", ".", "'()'", ".", "'<br>'", ";", "}", "$", "renderTrace", ".=", "'</span>'", ";", "return", "$", "renderTrace", ";", "}" ]
Returns a rendered debug_backtrace. @param array $debug_backtrace @return string
[ "Returns", "a", "rendered", "debug_backtrace", "." ]
train
https://github.com/ua1-labs/firebug/blob/70a45b2c0bbf64978641eb07e5f3cddfc1951162/Fire/Bug/Panel.php#L164-L184
php-http/artax-adapter
src/Internal/Promise.php
Promise.then
public function then(callable $onFulfilled = null, callable $onRejected = null) { $deferred = new \Amp\Deferred(); $newPromise = new self($deferred->promise()); $onFulfilled = $onFulfilled ?? function (ResponseInterface $response) { return $response; }; $onRejected = $onRejected ?? function (\Throwable $exception) { if (!$exception instanceof Exception) { $exception = new Exception\TransferException($exception->getMessage(), 0, $exception); } throw $exception; }; $this->onFulfilled = function (ResponseInterface $response) use ($onFulfilled, $deferred) { try { $deferred->resolve($onFulfilled($response)); } catch (Exception $exception) { $deferred->fail($exception); } catch (\Throwable $error) { $deferred->fail(new Exception\TransferException($error->getMessage(), 0, $error)); } }; $this->onRejected = function (Exception $exception) use ($onRejected, $deferred) { try { $deferred->resolve($onRejected($exception)); } catch (Exception $exception) { $deferred->fail($exception); } catch (\Throwable $error) { $deferred->fail(new Exception\TransferException($error->getMessage(), 0, $error)); } }; if (HttpPromise::FULFILLED === $this->state) { $this->resolve($this->response); } if (HttpPromise::REJECTED === $this->state) { $this->reject($this->exception); } return $newPromise; }
php
public function then(callable $onFulfilled = null, callable $onRejected = null) { $deferred = new \Amp\Deferred(); $newPromise = new self($deferred->promise()); $onFulfilled = $onFulfilled ?? function (ResponseInterface $response) { return $response; }; $onRejected = $onRejected ?? function (\Throwable $exception) { if (!$exception instanceof Exception) { $exception = new Exception\TransferException($exception->getMessage(), 0, $exception); } throw $exception; }; $this->onFulfilled = function (ResponseInterface $response) use ($onFulfilled, $deferred) { try { $deferred->resolve($onFulfilled($response)); } catch (Exception $exception) { $deferred->fail($exception); } catch (\Throwable $error) { $deferred->fail(new Exception\TransferException($error->getMessage(), 0, $error)); } }; $this->onRejected = function (Exception $exception) use ($onRejected, $deferred) { try { $deferred->resolve($onRejected($exception)); } catch (Exception $exception) { $deferred->fail($exception); } catch (\Throwable $error) { $deferred->fail(new Exception\TransferException($error->getMessage(), 0, $error)); } }; if (HttpPromise::FULFILLED === $this->state) { $this->resolve($this->response); } if (HttpPromise::REJECTED === $this->state) { $this->reject($this->exception); } return $newPromise; }
[ "public", "function", "then", "(", "callable", "$", "onFulfilled", "=", "null", ",", "callable", "$", "onRejected", "=", "null", ")", "{", "$", "deferred", "=", "new", "\\", "Amp", "\\", "Deferred", "(", ")", ";", "$", "newPromise", "=", "new", "self", "(", "$", "deferred", "->", "promise", "(", ")", ")", ";", "$", "onFulfilled", "=", "$", "onFulfilled", "??", "function", "(", "ResponseInterface", "$", "response", ")", "{", "return", "$", "response", ";", "}", ";", "$", "onRejected", "=", "$", "onRejected", "??", "function", "(", "\\", "Throwable", "$", "exception", ")", "{", "if", "(", "!", "$", "exception", "instanceof", "Exception", ")", "{", "$", "exception", "=", "new", "Exception", "\\", "TransferException", "(", "$", "exception", "->", "getMessage", "(", ")", ",", "0", ",", "$", "exception", ")", ";", "}", "throw", "$", "exception", ";", "}", ";", "$", "this", "->", "onFulfilled", "=", "function", "(", "ResponseInterface", "$", "response", ")", "use", "(", "$", "onFulfilled", ",", "$", "deferred", ")", "{", "try", "{", "$", "deferred", "->", "resolve", "(", "$", "onFulfilled", "(", "$", "response", ")", ")", ";", "}", "catch", "(", "Exception", "$", "exception", ")", "{", "$", "deferred", "->", "fail", "(", "$", "exception", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "error", ")", "{", "$", "deferred", "->", "fail", "(", "new", "Exception", "\\", "TransferException", "(", "$", "error", "->", "getMessage", "(", ")", ",", "0", ",", "$", "error", ")", ")", ";", "}", "}", ";", "$", "this", "->", "onRejected", "=", "function", "(", "Exception", "$", "exception", ")", "use", "(", "$", "onRejected", ",", "$", "deferred", ")", "{", "try", "{", "$", "deferred", "->", "resolve", "(", "$", "onRejected", "(", "$", "exception", ")", ")", ";", "}", "catch", "(", "Exception", "$", "exception", ")", "{", "$", "deferred", "->", "fail", "(", "$", "exception", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "error", ")", "{", "$", "deferred", "->", "fail", "(", "new", "Exception", "\\", "TransferException", "(", "$", "error", "->", "getMessage", "(", ")", ",", "0", ",", "$", "error", ")", ")", ";", "}", "}", ";", "if", "(", "HttpPromise", "::", "FULFILLED", "===", "$", "this", "->", "state", ")", "{", "$", "this", "->", "resolve", "(", "$", "this", "->", "response", ")", ";", "}", "if", "(", "HttpPromise", "::", "REJECTED", "===", "$", "this", "->", "state", ")", "{", "$", "this", "->", "reject", "(", "$", "this", "->", "exception", ")", ";", "}", "return", "$", "newPromise", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-http/artax-adapter/blob/fee1cff8aea42bdd44586cb9a568e2d4228438c7/src/Internal/Promise.php#L61-L107
php-http/artax-adapter
src/Internal/Promise.php
Promise.wait
public function wait($unwrap = true) { try { AmpPromise\wait($this->promise); } catch (Exception $exception) { } if ($unwrap) { if (HttpPromise::REJECTED === $this->getState()) { throw $this->exception; } return $this->response; } }
php
public function wait($unwrap = true) { try { AmpPromise\wait($this->promise); } catch (Exception $exception) { } if ($unwrap) { if (HttpPromise::REJECTED === $this->getState()) { throw $this->exception; } return $this->response; } }
[ "public", "function", "wait", "(", "$", "unwrap", "=", "true", ")", "{", "try", "{", "AmpPromise", "\\", "wait", "(", "$", "this", "->", "promise", ")", ";", "}", "catch", "(", "Exception", "$", "exception", ")", "{", "}", "if", "(", "$", "unwrap", ")", "{", "if", "(", "HttpPromise", "::", "REJECTED", "===", "$", "this", "->", "getState", "(", ")", ")", "{", "throw", "$", "this", "->", "exception", ";", "}", "return", "$", "this", "->", "response", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-http/artax-adapter/blob/fee1cff8aea42bdd44586cb9a568e2d4228438c7/src/Internal/Promise.php#L120-L134
popovserhii/db
src/Db.php
Db.fetch
public function fetch($query) { $result = $this->query($query); return $result->fetch(\PDO::FETCH_ASSOC); }
php
public function fetch($query) { $result = $this->query($query); return $result->fetch(\PDO::FETCH_ASSOC); }
[ "public", "function", "fetch", "(", "$", "query", ")", "{", "$", "result", "=", "$", "this", "->", "query", "(", "$", "query", ")", ";", "return", "$", "result", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "}" ]
Return associate array with all data of one row in table @param $query @return mixed
[ "Return", "associate", "array", "with", "all", "data", "of", "one", "row", "in", "table" ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L173-L178
popovserhii/db
src/Db.php
Db.fetchAssoc
public function fetchAssoc($query) { $data = []; $result = $this->query($query); $keyArray = false; while (false != ($row = $result->fetch(\PDO::FETCH_ASSOC))) { $first = 1; foreach ($row as $key => $value) { if ($first === 1) { $keyArray = $value; $first++; continue; } $data[$keyArray][$key] = $value; } } return $data; }
php
public function fetchAssoc($query) { $data = []; $result = $this->query($query); $keyArray = false; while (false != ($row = $result->fetch(\PDO::FETCH_ASSOC))) { $first = 1; foreach ($row as $key => $value) { if ($first === 1) { $keyArray = $value; $first++; continue; } $data[$keyArray][$key] = $value; } } return $data; }
[ "public", "function", "fetchAssoc", "(", "$", "query", ")", "{", "$", "data", "=", "[", "]", ";", "$", "result", "=", "$", "this", "->", "query", "(", "$", "query", ")", ";", "$", "keyArray", "=", "false", ";", "while", "(", "false", "!=", "(", "$", "row", "=", "$", "result", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", ")", "{", "$", "first", "=", "1", ";", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "first", "===", "1", ")", "{", "$", "keyArray", "=", "$", "value", ";", "$", "first", "++", ";", "continue", ";", "}", "$", "data", "[", "$", "keyArray", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "data", ";", "}" ]
Returns an associative array of values from one sample. Unlike the $ this-> arAll (), the value is not added to the new array, but rather for the unique ID number of the array is set to the first value in the "SELECT first, second FROM table" @param string $query @return array $allData
[ "Returns", "an", "associative", "array", "of", "values", "from", "one", "sample", ".", "Unlike", "the", "$", "this", "-", ">", "arAll", "()", "the", "value", "is", "not", "added", "to", "the", "new", "array", "but", "rather", "for", "the", "unique", "ID", "number", "of", "the", "array", "is", "set", "to", "the", "first", "value", "in", "the", "SELECT", "first", "second", "FROM", "table" ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L189-L207
popovserhii/db
src/Db.php
Db.fetchOne
public function fetchOne($sql, array $parameters = []) { $statement = $this->lazyLoad()->prepare($sql, [\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY]); //$statement = $this->lazyLoad()->prepare($sql); $statement->execute($parameters); $result = $statement->fetch(\PDO::FETCH_ASSOC); return $result; }
php
public function fetchOne($sql, array $parameters = []) { $statement = $this->lazyLoad()->prepare($sql, [\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY]); //$statement = $this->lazyLoad()->prepare($sql); $statement->execute($parameters); $result = $statement->fetch(\PDO::FETCH_ASSOC); return $result; }
[ "public", "function", "fetchOne", "(", "$", "sql", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "statement", "=", "$", "this", "->", "lazyLoad", "(", ")", "->", "prepare", "(", "$", "sql", ",", "[", "\\", "PDO", "::", "ATTR_CURSOR", "=>", "\\", "PDO", "::", "CURSOR_FWDONLY", "]", ")", ";", "//$statement = $this->lazyLoad()->prepare($sql);", "$", "statement", "->", "execute", "(", "$", "parameters", ")", ";", "$", "result", "=", "$", "statement", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "result", ";", "}" ]
Returns the first record of the sample. If passed only the first parameter is returned SQL statement to transfer only necessary to sample data. Execute a prepared statement by passing an array of values For example: $sql = 'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'; $sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); // SQL statement $sth->execute(array(':calories' => 150, ':colour' => 'red')); $red = $sth->fetch(); $sth->execute(array(':calories' => 175, ':colour' => 'yellow')); $yellow = $sth->fetch(); The second parameter passed array template on which to do sampling by default - "named template" For example: $data = array( 'name' => 'Mishel', 'addr' => 'str Shevchenko', 'city' => 'Kyiv' ); @param string $sql @param array $parameters @return mixed
[ "Returns", "the", "first", "record", "of", "the", "sample", ".", "If", "passed", "only", "the", "first", "parameter", "is", "returned", "SQL", "statement", "to", "transfer", "only", "necessary", "to", "sample", "data", ".", "Execute", "a", "prepared", "statement", "by", "passing", "an", "array", "of", "values", "For", "example", ":", "$sql", "=", "SELECT", "name", "colour", "calories", "FROM", "fruit", "WHERE", "calories", "<", ":", "calories", "AND", "colour", "=", ":", "colour", ";", "$sth", "=", "$dbh", "-", ">", "prepare", "(", "$sql", "array", "(", "PDO", "::", "ATTR_CURSOR", "=", ">", "PDO", "::", "CURSOR_FWDONLY", "))", ";", "//", "SQL", "statement", "$sth", "-", ">", "execute", "(", "array", "(", ":", "calories", "=", ">", "150", ":", "colour", "=", ">", "red", "))", ";", "$red", "=", "$sth", "-", ">", "fetch", "()", ";", "$sth", "-", ">", "execute", "(", "array", "(", ":", "calories", "=", ">", "175", ":", "colour", "=", ">", "yellow", "))", ";", "$yellow", "=", "$sth", "-", ">", "fetch", "()", ";", "The", "second", "parameter", "passed", "array", "template", "on", "which", "to", "do", "sampling", "by", "default", "-", "named", "template", "For", "example", ":", "$data", "=", "array", "(", "name", "=", ">", "Mishel", "addr", "=", ">", "str", "Shevchenko", "city", "=", ">", "Kyiv", ")", ";" ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L362-L370
popovserhii/db
src/Db.php
Db.fetchAll
public function fetchAll($sql, array $parameters = []) { $stm = $this->lazyLoad()->prepare($sql); $stm->execute($parameters); $array = $stm->fetchAll(\PDO::FETCH_ASSOC); // @see https://stackoverflow.com/a/883382/1335142 $this->numRows = $stm->rowCount(); return $array; }
php
public function fetchAll($sql, array $parameters = []) { $stm = $this->lazyLoad()->prepare($sql); $stm->execute($parameters); $array = $stm->fetchAll(\PDO::FETCH_ASSOC); // @see https://stackoverflow.com/a/883382/1335142 $this->numRows = $stm->rowCount(); return $array; }
[ "public", "function", "fetchAll", "(", "$", "sql", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "stm", "=", "$", "this", "->", "lazyLoad", "(", ")", "->", "prepare", "(", "$", "sql", ")", ";", "$", "stm", "->", "execute", "(", "$", "parameters", ")", ";", "$", "array", "=", "$", "stm", "->", "fetchAll", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "// @see https://stackoverflow.com/a/883382/1335142", "$", "this", "->", "numRows", "=", "$", "stm", "->", "rowCount", "(", ")", ";", "return", "$", "array", ";", "}" ]
$sql = "SELECT id FROM table WHERE id = ?"; $parameters = array(524); @param string $sql @param array $parameters @return array
[ "$sql", "=", "SELECT", "id", "FROM", "table", "WHERE", "id", "=", "?", ";", "$parameters", "=", "array", "(", "524", ")", ";" ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L380-L389
popovserhii/db
src/Db.php
Db.fetchDropDown
public function fetchDropDown($sql, array $parameters = []) { $result = $this->fetchAll($sql, $parameters); $data = []; foreach ($result as $field) { $data[array_shift($field)] = array_shift($field); } return $data; }
php
public function fetchDropDown($sql, array $parameters = []) { $result = $this->fetchAll($sql, $parameters); $data = []; foreach ($result as $field) { $data[array_shift($field)] = array_shift($field); } return $data; }
[ "public", "function", "fetchDropDown", "(", "$", "sql", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "result", "=", "$", "this", "->", "fetchAll", "(", "$", "sql", ",", "$", "parameters", ")", ";", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "result", "as", "$", "field", ")", "{", "$", "data", "[", "array_shift", "(", "$", "field", ")", "]", "=", "array_shift", "(", "$", "field", ")", ";", "}", "return", "$", "data", ";", "}" ]
Return value need for generate <select /> $sql = "SELECT id, name FROM table WHERE id = ?"; $parameters = array(524); @param $sql @param array $parameters @return array
[ "Return", "value", "need", "for", "generate", "<select", "/", ">" ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L401-L410
popovserhii/db
src/Db.php
Db.save
public function save($table, $field, $idField = 'id') { unset($this->values); $sql = "INSERT INTO `{$table}` ( {$this->addFields($field)} ) VALUES ({$this->_addValue($field)}) ON DUPLICATE KEY UPDATE {$this->_onDuplicateKeyUpdateField($this->addFields($field), $idField)}"; $fields = array_values($field); // reset array indexes $query = $this->lazyLoad()->prepare($sql); $query->execute($fields); return $query->rowCount(); }
php
public function save($table, $field, $idField = 'id') { unset($this->values); $sql = "INSERT INTO `{$table}` ( {$this->addFields($field)} ) VALUES ({$this->_addValue($field)}) ON DUPLICATE KEY UPDATE {$this->_onDuplicateKeyUpdateField($this->addFields($field), $idField)}"; $fields = array_values($field); // reset array indexes $query = $this->lazyLoad()->prepare($sql); $query->execute($fields); return $query->rowCount(); }
[ "public", "function", "save", "(", "$", "table", ",", "$", "field", ",", "$", "idField", "=", "'id'", ")", "{", "unset", "(", "$", "this", "->", "values", ")", ";", "$", "sql", "=", "\"INSERT INTO `{$table}` ( {$this->addFields($field)} ) VALUES ({$this->_addValue($field)}) ON DUPLICATE KEY UPDATE {$this->_onDuplicateKeyUpdateField($this->addFields($field), $idField)}\"", ";", "$", "fields", "=", "array_values", "(", "$", "field", ")", ";", "// reset array indexes", "$", "query", "=", "$", "this", "->", "lazyLoad", "(", ")", "->", "prepare", "(", "$", "sql", ")", ";", "$", "query", "->", "execute", "(", "$", "fields", ")", ";", "return", "$", "query", "->", "rowCount", "(", ")", ";", "}" ]
Regular UPDATE/INSERT In the field $field transferred one-dimensional array, which keys correspond to fields in the database table, and the value of the array - according to data insertion. If UPDATE then the first value in the array $field must be a unique value field (eg: id). @param string $table @param array $field @param string $idField @return int
[ "Regular", "UPDATE", "/", "INSERT", "In", "the", "field", "$field", "transferred", "one", "-", "dimensional", "array", "which", "keys", "correspond", "to", "fields", "in", "the", "database", "table", "and", "the", "value", "of", "the", "array", "-", "according", "to", "data", "insertion", ".", "If", "UPDATE", "then", "the", "first", "value", "in", "the", "array", "$field", "must", "be", "a", "unique", "value", "field", "(", "eg", ":", "id", ")", "." ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L423-L432
popovserhii/db
src/Db.php
Db.multipleSave
public function multipleSave($table, $fields, $idField = 'id') { unset($this->values); $sql = "INSERT INTO `{$table}` ( {$this->addFields($fields[0])} ) VALUES {$this->addValues($fields)} ON DUPLICATE KEY UPDATE {$this->_onDuplicateKeyUpdateField($this->addFields($fields[0]), $idField)};"; //\Zend\Debug\Debug::dump([$fields, $this->values, $sql]); die(__METHOD__); // run sql $query = $this->lazyLoad()->prepare($sql); return $query->execute($this->values); }
php
public function multipleSave($table, $fields, $idField = 'id') { unset($this->values); $sql = "INSERT INTO `{$table}` ( {$this->addFields($fields[0])} ) VALUES {$this->addValues($fields)} ON DUPLICATE KEY UPDATE {$this->_onDuplicateKeyUpdateField($this->addFields($fields[0]), $idField)};"; //\Zend\Debug\Debug::dump([$fields, $this->values, $sql]); die(__METHOD__); // run sql $query = $this->lazyLoad()->prepare($sql); return $query->execute($this->values); }
[ "public", "function", "multipleSave", "(", "$", "table", ",", "$", "fields", ",", "$", "idField", "=", "'id'", ")", "{", "unset", "(", "$", "this", "->", "values", ")", ";", "$", "sql", "=", "\"INSERT INTO `{$table}` ( {$this->addFields($fields[0])} ) VALUES {$this->addValues($fields)} ON DUPLICATE KEY UPDATE {$this->_onDuplicateKeyUpdateField($this->addFields($fields[0]), $idField)};\"", ";", "//\\Zend\\Debug\\Debug::dump([$fields, $this->values, $sql]); die(__METHOD__);", "// run sql", "$", "query", "=", "$", "this", "->", "lazyLoad", "(", ")", "->", "prepare", "(", "$", "sql", ")", ";", "return", "$", "query", "->", "execute", "(", "$", "this", "->", "values", ")", ";", "}" ]
Multiple INSERT/UPDATE. In the $fields transferred multidimensional array. One item which represents the right table in the database. WARNING! Db::multipleUpdate() works only while Db::TEMPLATES_WITHOUT @param string $table Таблиця для вставки даних @param array $fields Многомірний масив даних 1 - array(0 => array('id' => 65, 'name' => Senya, 'lang' => 'ua'), // If the field is a database will UPDATE 2 - array('id' => 0, 'name' => Senya, 'lang' => 'ua')) // If the field is not in the database will INSERT @param $table @param $fields @param string $idField @return bool
[ "Multiple", "INSERT", "/", "UPDATE", ".", "In", "the", "$fields", "transferred", "multidimensional", "array", ".", "One", "item", "which", "represents", "the", "right", "table", "in", "the", "database", ".", "WARNING!", "Db", "::", "multipleUpdate", "()", "works", "only", "while", "Db", "::", "TEMPLATES_WITHOUT" ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L450-L459
popovserhii/db
src/Db.php
Db._onDuplicateKeyUpdateField
private function _onDuplicateKeyUpdateField($fieldsStr, $idField) { $fields_array = explode(',', $fieldsStr); $fields = []; foreach ($fields_array as $field) { if (trim($field, '` ') == $idField) { $fields[] = " {$idField} = LAST_INSERT_ID($idField)"; continue; } $fields[] = " {$field} = VALUES({$field})"; } return (string) implode(',', $fields); }
php
private function _onDuplicateKeyUpdateField($fieldsStr, $idField) { $fields_array = explode(',', $fieldsStr); $fields = []; foreach ($fields_array as $field) { if (trim($field, '` ') == $idField) { $fields[] = " {$idField} = LAST_INSERT_ID($idField)"; continue; } $fields[] = " {$field} = VALUES({$field})"; } return (string) implode(',', $fields); }
[ "private", "function", "_onDuplicateKeyUpdateField", "(", "$", "fieldsStr", ",", "$", "idField", ")", "{", "$", "fields_array", "=", "explode", "(", "','", ",", "$", "fieldsStr", ")", ";", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "fields_array", "as", "$", "field", ")", "{", "if", "(", "trim", "(", "$", "field", ",", "'` '", ")", "==", "$", "idField", ")", "{", "$", "fields", "[", "]", "=", "\" {$idField} = LAST_INSERT_ID($idField)\"", ";", "continue", ";", "}", "$", "fields", "[", "]", "=", "\" {$field} = VALUES({$field})\"", ";", "}", "return", "(", "string", ")", "implode", "(", "','", ",", "$", "fields", ")", ";", "}" ]
Gets tape field names for the condition "ON DUPLICATE KEY UPDATE". Ignore the first field, as it should be unique and should not be changed. Generates set to ON DUPLICATE KEY UPDATE, the type field = VALUES (field), field2 = VALUES (field2), ...
[ "Gets", "tape", "field", "names", "for", "the", "condition", "ON", "DUPLICATE", "KEY", "UPDATE", ".", "Ignore", "the", "first", "field", "as", "it", "should", "be", "unique", "and", "should", "not", "be", "changed", ".", "Generates", "set", "to", "ON", "DUPLICATE", "KEY", "UPDATE", "the", "type", "field", "=", "VALUES", "(", "field", ")", "field2", "=", "VALUES", "(", "field2", ")", "..." ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L466-L479
popovserhii/db
src/Db.php
Db.addFields
protected function addFields($fields) { $fields_array = []; foreach ($fields as $field => $value) { $fields_array[] = $field; } return '`' . implode('`, `', $fields_array) . '`'; }
php
protected function addFields($fields) { $fields_array = []; foreach ($fields as $field => $value) { $fields_array[] = $field; } return '`' . implode('`, `', $fields_array) . '`'; }
[ "protected", "function", "addFields", "(", "$", "fields", ")", "{", "$", "fields_array", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", "=>", "$", "value", ")", "{", "$", "fields_array", "[", "]", "=", "$", "field", ";", "}", "return", "'`'", ".", "implode", "(", "'`, `'", ",", "$", "fields_array", ")", ".", "'`'", ";", "}" ]
Generates a set of fields that need to be updated or inserted. For the terms "INSERT INTO". @param $fields @return string
[ "Generates", "a", "set", "of", "fields", "that", "need", "to", "be", "updated", "or", "inserted", ".", "For", "the", "terms", "INSERT", "INTO", "." ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L487-L495
popovserhii/db
src/Db.php
Db.addValues
protected function addValues($fields) { $values_array = []; foreach ($fields as $values) { $values_array[] = '(' . $this->_addValue($values) . ')'; } return implode(',', $values_array); }
php
protected function addValues($fields) { $values_array = []; foreach ($fields as $values) { $values_array[] = '(' . $this->_addValue($values) . ')'; } return implode(',', $values_array); }
[ "protected", "function", "addValues", "(", "$", "fields", ")", "{", "$", "values_array", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "values", ")", "{", "$", "values_array", "[", "]", "=", "'('", ".", "$", "this", "->", "_addValue", "(", "$", "values", ")", ".", "')'", ";", "}", "return", "implode", "(", "','", ",", "$", "values_array", ")", ";", "}" ]
Handles multi-dimensional array of data and generates a set of groups "(1, 1), (2, 12), (3, 0.5)" @param $fields @return string
[ "Handles", "multi", "-", "dimensional", "array", "of", "data", "and", "generates", "a", "set", "of", "groups", "(", "1", "1", ")", "(", "2", "12", ")", "(", "3", "0", ".", "5", ")" ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L503-L511
popovserhii/db
src/Db.php
Db._addValue
protected function _addValue($values) { $method = $this->getSaveMode(); $value_array = []; foreach ($values as $key => $value) { $value_array[] = $this->$method($key, $value); } return implode(',', $value_array); }
php
protected function _addValue($values) { $method = $this->getSaveMode(); $value_array = []; foreach ($values as $key => $value) { $value_array[] = $this->$method($key, $value); } return implode(',', $value_array); }
[ "protected", "function", "_addValue", "(", "$", "values", ")", "{", "$", "method", "=", "$", "this", "->", "getSaveMode", "(", ")", ";", "$", "value_array", "=", "[", "]", ";", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "value_array", "[", "]", "=", "$", "this", "->", "$", "method", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "implode", "(", "','", ",", "$", "value_array", ")", ";", "}" ]
Handles one-dimensional array of data and generates a set for one group. @param array $values @return string
[ "Handles", "one", "-", "dimensional", "array", "of", "data", "and", "generates", "a", "set", "for", "one", "group", "." ]
train
https://github.com/popovserhii/db/blob/86a1651784eb5763ef5b974233e6356b38b66aaa/src/Db.php#L519-L528
huasituo/hstcms
src/Libraries/Fields/FieldAbs.php
FieldAbs.validate_filter
public function validate_filter(Request $request, $field, $validate, $error = []) { $fieldname = $field['fieldname']; $value = $request->get($fieldname); if($field['fieldtype'] == 'Date' || $field['fieldtype'] == 'DateTime') { $value = hst_str2time($value); } // 验证必填字段 if ($field['fieldtype'] != 'Group' && isset($validate['required']) && $validate['required']) { if ($value == '') { if(isset($validate['kongzhitips']) && $validate['kongzhitips']) { $error[$fieldname] = [$validate['kongzhitips']]; } else { $error[$fieldname] = [hst_buildContent('hstcms::fields.post.content.kongzhi', ['name'=>$field['name']])]; } } else { // 正则验证 if (isset($validate['pattern']) && $validate['pattern'] && !preg_match($validate['pattern'], $value)) { if(isset($validate['errortips']) && $validate['errortips']) { $error[$fieldname] = [$validate['errortips']]; } else { $error[$fieldname] = [hst_buildContent('hstcms::fields.post.content.error', ['name'=>$field['name']])]; } } } } // 判断表字段值的唯一性 if ($field['ismain'] && isset($field['setting']['option']['unique']) && $field['setting']['option']['unique']) { } return $error; }
php
public function validate_filter(Request $request, $field, $validate, $error = []) { $fieldname = $field['fieldname']; $value = $request->get($fieldname); if($field['fieldtype'] == 'Date' || $field['fieldtype'] == 'DateTime') { $value = hst_str2time($value); } // 验证必填字段 if ($field['fieldtype'] != 'Group' && isset($validate['required']) && $validate['required']) { if ($value == '') { if(isset($validate['kongzhitips']) && $validate['kongzhitips']) { $error[$fieldname] = [$validate['kongzhitips']]; } else { $error[$fieldname] = [hst_buildContent('hstcms::fields.post.content.kongzhi', ['name'=>$field['name']])]; } } else { // 正则验证 if (isset($validate['pattern']) && $validate['pattern'] && !preg_match($validate['pattern'], $value)) { if(isset($validate['errortips']) && $validate['errortips']) { $error[$fieldname] = [$validate['errortips']]; } else { $error[$fieldname] = [hst_buildContent('hstcms::fields.post.content.error', ['name'=>$field['name']])]; } } } } // 判断表字段值的唯一性 if ($field['ismain'] && isset($field['setting']['option']['unique']) && $field['setting']['option']['unique']) { } return $error; }
[ "public", "function", "validate_filter", "(", "Request", "$", "request", ",", "$", "field", ",", "$", "validate", ",", "$", "error", "=", "[", "]", ")", "{", "$", "fieldname", "=", "$", "field", "[", "'fieldname'", "]", ";", "$", "value", "=", "$", "request", "->", "get", "(", "$", "fieldname", ")", ";", "if", "(", "$", "field", "[", "'fieldtype'", "]", "==", "'Date'", "||", "$", "field", "[", "'fieldtype'", "]", "==", "'DateTime'", ")", "{", "$", "value", "=", "hst_str2time", "(", "$", "value", ")", ";", "}", "// 验证必填字段", "if", "(", "$", "field", "[", "'fieldtype'", "]", "!=", "'Group'", "&&", "isset", "(", "$", "validate", "[", "'required'", "]", ")", "&&", "$", "validate", "[", "'required'", "]", ")", "{", "if", "(", "$", "value", "==", "''", ")", "{", "if", "(", "isset", "(", "$", "validate", "[", "'kongzhitips'", "]", ")", "&&", "$", "validate", "[", "'kongzhitips'", "]", ")", "{", "$", "error", "[", "$", "fieldname", "]", "=", "[", "$", "validate", "[", "'kongzhitips'", "]", "]", ";", "}", "else", "{", "$", "error", "[", "$", "fieldname", "]", "=", "[", "hst_buildContent", "(", "'hstcms::fields.post.content.kongzhi'", ",", "[", "'name'", "=>", "$", "field", "[", "'name'", "]", "]", ")", "]", ";", "}", "}", "else", "{", "// 正则验证", "if", "(", "isset", "(", "$", "validate", "[", "'pattern'", "]", ")", "&&", "$", "validate", "[", "'pattern'", "]", "&&", "!", "preg_match", "(", "$", "validate", "[", "'pattern'", "]", ",", "$", "value", ")", ")", "{", "if", "(", "isset", "(", "$", "validate", "[", "'errortips'", "]", ")", "&&", "$", "validate", "[", "'errortips'", "]", ")", "{", "$", "error", "[", "$", "fieldname", "]", "=", "[", "$", "validate", "[", "'errortips'", "]", "]", ";", "}", "else", "{", "$", "error", "[", "$", "fieldname", "]", "=", "[", "hst_buildContent", "(", "'hstcms::fields.post.content.error'", ",", "[", "'name'", "=>", "$", "field", "[", "'name'", "]", "]", ")", "]", ";", "}", "}", "}", "}", "// 判断表字段值的唯一性", "if", "(", "$", "field", "[", "'ismain'", "]", "&&", "isset", "(", "$", "field", "[", "'setting'", "]", "[", "'option'", "]", "[", "'unique'", "]", ")", "&&", "$", "field", "[", "'setting'", "]", "[", "'option'", "]", "[", "'unique'", "]", ")", "{", "}", "return", "$", "error", ";", "}" ]
验证字段输入
[ "验证字段输入" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/FieldAbs.php#L76-L107