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
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.updateState
public function updateState($name, $value = null) { $state = $this->retrieveState(); if (is_array($name)) { $state = array_merge($state, $name); } elseif (is_string($name)) { $state[$name] = $value; } $key = $this->generateKey(self::STATE_KEY); self::storage()->set($key, $state); }
php
public function updateState($name, $value = null) { $state = $this->retrieveState(); if (is_array($name)) { $state = array_merge($state, $name); } elseif (is_string($name)) { $state[$name] = $value; } $key = $this->generateKey(self::STATE_KEY); self::storage()->set($key, $state); }
[ "public", "function", "updateState", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "$", "state", "=", "$", "this", "->", "retrieveState", "(", ")", ";", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "state", "=", "arr...
更新发送状态 @param string|array $name @param mixed $value
[ "更新发送状态" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L341-L351
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.retrieveState
public function retrieveState($name = null) { $key = $this->generateKey(self::STATE_KEY); $state = self::storage()->get($key, []); if ($name !== null) { return isset($state[$name]) ? $state[$name] : null; } return $state; }
php
public function retrieveState($name = null) { $key = $this->generateKey(self::STATE_KEY); $state = self::storage()->get($key, []); if ($name !== null) { return isset($state[$name]) ? $state[$name] : null; } return $state; }
[ "public", "function", "retrieveState", "(", "$", "name", "=", "null", ")", "{", "$", "key", "=", "$", "this", "->", "generateKey", "(", "self", "::", "STATE_KEY", ")", ";", "$", "state", "=", "self", "::", "storage", "(", ")", "->", "get", "(", "$"...
从存储器中获取发送状态 @param string|null $name @return array
[ "从存储器中获取发送状态" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L360-L369
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.forgetState
public function forgetState() { $key = $this->generateKey(self::STATE_KEY); self::storage()->forget($key); }
php
public function forgetState() { $key = $this->generateKey(self::STATE_KEY); self::storage()->forget($key); }
[ "public", "function", "forgetState", "(", ")", "{", "$", "key", "=", "$", "this", "->", "generateKey", "(", "self", "::", "STATE_KEY", ")", ";", "self", "::", "storage", "(", ")", "->", "forget", "(", "$", "key", ")", ";", "}" ]
从存储器中删除发送状态
[ "从存储器中删除发送状态" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L374-L378
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.setCanResendAfter
public function setCanResendAfter($interval) { $key = $this->generateKey(self::CAN_RESEND_UNTIL_KEY); $time = time() + intval($interval); self::storage()->set($key, $time); }
php
public function setCanResendAfter($interval) { $key = $this->generateKey(self::CAN_RESEND_UNTIL_KEY); $time = time() + intval($interval); self::storage()->set($key, $time); }
[ "public", "function", "setCanResendAfter", "(", "$", "interval", ")", "{", "$", "key", "=", "$", "this", "->", "generateKey", "(", "self", "::", "CAN_RESEND_UNTIL_KEY", ")", ";", "$", "time", "=", "time", "(", ")", "+", "intval", "(", "$", "interval", ...
设置多少秒后才能再次请求 @param int $interval @return int
[ "设置多少秒后才能再次请求" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L387-L392
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.getCanResendTime
public function getCanResendTime() { $key = $this->generateKey(self::CAN_RESEND_UNTIL_KEY); return (int) self::storage()->get($key, 0); }
php
public function getCanResendTime() { $key = $this->generateKey(self::CAN_RESEND_UNTIL_KEY); return (int) self::storage()->get($key, 0); }
[ "public", "function", "getCanResendTime", "(", ")", "{", "$", "key", "=", "$", "this", "->", "generateKey", "(", "self", "::", "CAN_RESEND_UNTIL_KEY", ")", ";", "return", "(", "int", ")", "self", "::", "storage", "(", ")", "->", "get", "(", "$", "key",...
从存储器中获取可再次发送的截止时间 @return int
[ "从存储器中获取可再次发送的截止时间" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L399-L404
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.storeRule
public function storeRule($field, $name, $rule = null) { self::validateFieldName($field); if (is_array($name)) { foreach ($name as $k => $v) { $this->storeRule($field, $k, $v); } return; } if ($rule === null && is_string($name)) { $rule = $name; $name = null; } if (empty($name) || !is_string($name)) { $name = Util::pathOfUrl(URL::current(), function ($e) use ($field) { throw new LaravelSmsException("Expected a name for the dynamic rule which belongs to field `$field`."); }); } $allRules = $this->retrieveRules($field); $allRules[$name] = $rule; $key = $this->generateKey(self::DYNAMIC_RULE_KEY, $field); self::storage()->set($key, $allRules); }
php
public function storeRule($field, $name, $rule = null) { self::validateFieldName($field); if (is_array($name)) { foreach ($name as $k => $v) { $this->storeRule($field, $k, $v); } return; } if ($rule === null && is_string($name)) { $rule = $name; $name = null; } if (empty($name) || !is_string($name)) { $name = Util::pathOfUrl(URL::current(), function ($e) use ($field) { throw new LaravelSmsException("Expected a name for the dynamic rule which belongs to field `$field`."); }); } $allRules = $this->retrieveRules($field); $allRules[$name] = $rule; $key = $this->generateKey(self::DYNAMIC_RULE_KEY, $field); self::storage()->set($key, $allRules); }
[ "public", "function", "storeRule", "(", "$", "field", ",", "$", "name", ",", "$", "rule", "=", "null", ")", "{", "self", "::", "validateFieldName", "(", "$", "field", ")", ";", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "foreach", "(",...
存储指定字段的指定名称的动态验证规则 @param string $field @param string $name @param string|null $rule @throws LaravelSmsException
[ "存储指定字段的指定名称的动态验证规则" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L415-L438
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.retrieveRule
public function retrieveRule($field, $name = null) { $key = $this->generateKey(self::DYNAMIC_RULE_KEY, $field); $allRules = self::storage()->get($key, []); if (empty($name)) { return $allRules; } return isset($allRules[$name]) ? $allRules[$name] : null; }
php
public function retrieveRule($field, $name = null) { $key = $this->generateKey(self::DYNAMIC_RULE_KEY, $field); $allRules = self::storage()->get($key, []); if (empty($name)) { return $allRules; } return isset($allRules[$name]) ? $allRules[$name] : null; }
[ "public", "function", "retrieveRule", "(", "$", "field", ",", "$", "name", "=", "null", ")", "{", "$", "key", "=", "$", "this", "->", "generateKey", "(", "self", "::", "DYNAMIC_RULE_KEY", ",", "$", "field", ")", ";", "$", "allRules", "=", "self", "::...
从存储器中获取指定字段的指定名称的动态验证规则 @param string $field @param string|null $name @return string|null
[ "从存储器中获取指定字段的指定名称的动态验证规则" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L448-L457
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.forgetRule
public function forgetRule($field, $name = null) { $allRules = []; if (!(empty($name))) { $allRules = $this->retrieveRules($field); if (!isset($allRules[$name])) { return; } unset($allRules[$name]); } $key = $this->generateKey(self::DYNAMIC_RULE_KEY, $field); self::storage()->set($key, $allRules); }
php
public function forgetRule($field, $name = null) { $allRules = []; if (!(empty($name))) { $allRules = $this->retrieveRules($field); if (!isset($allRules[$name])) { return; } unset($allRules[$name]); } $key = $this->generateKey(self::DYNAMIC_RULE_KEY, $field); self::storage()->set($key, $allRules); }
[ "public", "function", "forgetRule", "(", "$", "field", ",", "$", "name", "=", "null", ")", "{", "$", "allRules", "=", "[", "]", ";", "if", "(", "!", "(", "empty", "(", "$", "name", ")", ")", ")", "{", "$", "allRules", "=", "$", "this", "->", ...
从存储器中删除指定字段的指定名称的动态验证规则 @param string $field @param string|null $name
[ "从存储器中删除指定字段的指定名称的动态验证规则" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L477-L489
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.retrieveAllData
public function retrieveAllData() { $data = []; $data[self::STATE_KEY] = $this->retrieveState(); $data[self::CAN_RESEND_UNTIL_KEY] = $this->getCanResendTime(); $data[self::DYNAMIC_RULE_KEY] = []; $fields = self::getFields(); foreach ($fields as $field) { $data[self::DYNAMIC_RULE_KEY][$field] = $this->retrieveRules($field); } return $data; }
php
public function retrieveAllData() { $data = []; $data[self::STATE_KEY] = $this->retrieveState(); $data[self::CAN_RESEND_UNTIL_KEY] = $this->getCanResendTime(); $data[self::DYNAMIC_RULE_KEY] = []; $fields = self::getFields(); foreach ($fields as $field) { $data[self::DYNAMIC_RULE_KEY][$field] = $this->retrieveRules($field); } return $data; }
[ "public", "function", "retrieveAllData", "(", ")", "{", "$", "data", "=", "[", "]", ";", "$", "data", "[", "self", "::", "STATE_KEY", "]", "=", "$", "this", "->", "retrieveState", "(", ")", ";", "$", "data", "[", "self", "::", "CAN_RESEND_UNTIL_KEY", ...
从存储器中获取用户的所有数据 @return array
[ "从存储器中获取用户的所有数据" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L508-L520
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.generateKey
protected function generateKey() { $split = '.'; $prefix = config('laravel-sms.storage.prefix', 'laravel_sms'); $args = func_get_args(); array_unshift($args, $this->token); $args = array_filter($args, function ($value) { return $value && is_string($value); }); if (!(empty($args))) { $prefix .= $split . implode($split, $args); } return $prefix; }
php
protected function generateKey() { $split = '.'; $prefix = config('laravel-sms.storage.prefix', 'laravel_sms'); $args = func_get_args(); array_unshift($args, $this->token); $args = array_filter($args, function ($value) { return $value && is_string($value); }); if (!(empty($args))) { $prefix .= $split . implode($split, $args); } return $prefix; }
[ "protected", "function", "generateKey", "(", ")", "{", "$", "split", "=", "'.'", ";", "$", "prefix", "=", "config", "(", "'laravel-sms.storage.prefix'", ",", "'laravel_sms'", ")", ";", "$", "args", "=", "func_get_args", "(", ")", ";", "array_unshift", "(", ...
生成key @return string
[ "生成key" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L527-L541
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.generateSmsContent
protected function generateSmsContent($code, $minutes) { $content = config('laravel-sms.verifySmsContent') ?: config('laravel-sms.content'); if (is_string($content)) { $content = Util::unserializeClosure($content); } if (is_callable($content)) { $content = call_user_func_array($content, [$code, $minutes, $this->input()]); } return is_string($content) ? $content : ''; }
php
protected function generateSmsContent($code, $minutes) { $content = config('laravel-sms.verifySmsContent') ?: config('laravel-sms.content'); if (is_string($content)) { $content = Util::unserializeClosure($content); } if (is_callable($content)) { $content = call_user_func_array($content, [$code, $minutes, $this->input()]); } return is_string($content) ? $content : ''; }
[ "protected", "function", "generateSmsContent", "(", "$", "code", ",", "$", "minutes", ")", "{", "$", "content", "=", "config", "(", "'laravel-sms.verifySmsContent'", ")", "?", ":", "config", "(", "'laravel-sms.content'", ")", ";", "if", "(", "is_string", "(", ...
生成验证码短信通用内容 @param string $code @param int $minutes @return string
[ "生成验证码短信通用内容" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L551-L562
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.generateTemplates
protected function generateTemplates($type) { $templates = config('laravel-sms.templates'); if (is_string($templates)) { $templates = Util::unserializeClosure($templates); } if (is_callable($templates)) { $templates = call_user_func_array($templates, [$this->input(), $type]); } if (!is_array($templates) || empty($templates)) { $key = $type === self::VERIFY_SMS ? self::VERIFY_SMS_TEMPLATE_KEY : self::VOICE_VERIFY_TEMPLATE_KEY; return self::getTemplatesByKey($key); } foreach ($templates as $key => $id) { if (is_string($id) && preg_match(self::closurePattern, $id)) { $id = Util::unserializeClosure($id); } if (is_callable($id)) { $id = call_user_func_array($id, [$this->input(), $type]); } if (is_array($id)) { $id = $type === self::VERIFY_SMS ? $id[0] : $id[1]; } $templates[$key] = $id; } return $templates; }
php
protected function generateTemplates($type) { $templates = config('laravel-sms.templates'); if (is_string($templates)) { $templates = Util::unserializeClosure($templates); } if (is_callable($templates)) { $templates = call_user_func_array($templates, [$this->input(), $type]); } if (!is_array($templates) || empty($templates)) { $key = $type === self::VERIFY_SMS ? self::VERIFY_SMS_TEMPLATE_KEY : self::VOICE_VERIFY_TEMPLATE_KEY; return self::getTemplatesByKey($key); } foreach ($templates as $key => $id) { if (is_string($id) && preg_match(self::closurePattern, $id)) { $id = Util::unserializeClosure($id); } if (is_callable($id)) { $id = call_user_func_array($id, [$this->input(), $type]); } if (is_array($id)) { $id = $type === self::VERIFY_SMS ? $id[0] : $id[1]; } $templates[$key] = $id; } return $templates; }
[ "protected", "function", "generateTemplates", "(", "$", "type", ")", "{", "$", "templates", "=", "config", "(", "'laravel-sms.templates'", ")", ";", "if", "(", "is_string", "(", "$", "templates", ")", ")", "{", "$", "templates", "=", "Util", "::", "unseria...
生成模版ids @param $type @return array
[ "生成模版ids" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L571-L599
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.generateTemplateData
protected function generateTemplateData($code, $minutes, $type) { $tplData = config('laravel-sms.templateData') ?: config('laravel-sms.data'); if (is_string($tplData)) { $tplData = Util::unserializeClosure($tplData); } if (is_callable($tplData)) { $tplData = call_user_func_array($tplData, [$code, $minutes, $this->input(), $type]); } if (!is_array($tplData) || empty($tplData)) { return [ 'code' => $code, 'minutes' => $minutes, ]; } foreach ($tplData as $key => $value) { if (is_string($value) && preg_match(self::closurePattern, $value)) { $value = Util::unserializeClosure($value); } if (is_callable($value)) { $tplData[$key] = call_user_func_array($value, [$code, $minutes, $this->input(), $type]); } } return array_filter($tplData, function ($value) { return $value !== null; }); }
php
protected function generateTemplateData($code, $minutes, $type) { $tplData = config('laravel-sms.templateData') ?: config('laravel-sms.data'); if (is_string($tplData)) { $tplData = Util::unserializeClosure($tplData); } if (is_callable($tplData)) { $tplData = call_user_func_array($tplData, [$code, $minutes, $this->input(), $type]); } if (!is_array($tplData) || empty($tplData)) { return [ 'code' => $code, 'minutes' => $minutes, ]; } foreach ($tplData as $key => $value) { if (is_string($value) && preg_match(self::closurePattern, $value)) { $value = Util::unserializeClosure($value); } if (is_callable($value)) { $tplData[$key] = call_user_func_array($value, [$code, $minutes, $this->input(), $type]); } } return array_filter($tplData, function ($value) { return $value !== null; }); }
[ "protected", "function", "generateTemplateData", "(", "$", "code", ",", "$", "minutes", ",", "$", "type", ")", "{", "$", "tplData", "=", "config", "(", "'laravel-sms.templateData'", ")", "?", ":", "config", "(", "'laravel-sms.data'", ")", ";", "if", "(", "...
生成模版数据 @param string $code @param int $minutes @param string $type @return array
[ "生成模版数据" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L610-L637
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.getMobileField
protected static function getMobileField() { $config = config('laravel-sms.validation', []); foreach ($config as $key => $value) { if (!is_array($value)) { continue; } if (isset($value['isMobile']) && $value['isMobile']) { return $key; } } throw new LaravelSmsException('Not find the mobile field, please define it.'); }
php
protected static function getMobileField() { $config = config('laravel-sms.validation', []); foreach ($config as $key => $value) { if (!is_array($value)) { continue; } if (isset($value['isMobile']) && $value['isMobile']) { return $key; } } throw new LaravelSmsException('Not find the mobile field, please define it.'); }
[ "protected", "static", "function", "getMobileField", "(", ")", "{", "$", "config", "=", "config", "(", "'laravel-sms.validation'", ",", "[", "]", ")", ";", "foreach", "(", "$", "config", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", ...
获取手机号的字段名 @throws LaravelSmsException @return string
[ "获取手机号的字段名" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L656-L668
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.storage
protected static function storage() { if (self::$storage) { return self::$storage; } $className = self::getStorageClassName(); if (!class_exists($className)) { throw new LaravelSmsException("Generate storage failed, the class [$className] does not exists."); } $store = new $className(); if (!($store instanceof Storage)) { throw new LaravelSmsException("Generate storage failed, the class [$className] does not implement the interface [Toplan\\Sms\\Storage]."); } return self::$storage = $store; }
php
protected static function storage() { if (self::$storage) { return self::$storage; } $className = self::getStorageClassName(); if (!class_exists($className)) { throw new LaravelSmsException("Generate storage failed, the class [$className] does not exists."); } $store = new $className(); if (!($store instanceof Storage)) { throw new LaravelSmsException("Generate storage failed, the class [$className] does not implement the interface [Toplan\\Sms\\Storage]."); } return self::$storage = $store; }
[ "protected", "static", "function", "storage", "(", ")", "{", "if", "(", "self", "::", "$", "storage", ")", "{", "return", "self", "::", "$", "storage", ";", "}", "$", "className", "=", "self", "::", "getStorageClassName", "(", ")", ";", "if", "(", "!...
获取存储器 @throws LaravelSmsException @return Storage
[ "获取存储器" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L677-L692
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.getStorageClassName
protected static function getStorageClassName() { $className = config('laravel-sms.storage.driver', null); if ($className && is_string($className)) { return $className; } $middleware = config('laravel-sms.route.middleware', null); if ($middleware === 'web' || (is_array($middleware) && in_array('web', $middleware))) { return 'Toplan\Sms\SessionStorage'; } if ($middleware === 'api' || (is_array($middleware) && in_array('api', $middleware))) { return 'Toplan\Sms\CacheStorage'; } return 'Toplan\Sms\SessionStorage'; }
php
protected static function getStorageClassName() { $className = config('laravel-sms.storage.driver', null); if ($className && is_string($className)) { return $className; } $middleware = config('laravel-sms.route.middleware', null); if ($middleware === 'web' || (is_array($middleware) && in_array('web', $middleware))) { return 'Toplan\Sms\SessionStorage'; } if ($middleware === 'api' || (is_array($middleware) && in_array('api', $middleware))) { return 'Toplan\Sms\CacheStorage'; } return 'Toplan\Sms\SessionStorage'; }
[ "protected", "static", "function", "getStorageClassName", "(", ")", "{", "$", "className", "=", "config", "(", "'laravel-sms.storage.driver'", ",", "null", ")", ";", "if", "(", "$", "className", "&&", "is_string", "(", "$", "className", ")", ")", "{", "retur...
获取存储器类名 @return string
[ "获取存储器类名" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L699-L714
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.getStaticRule
protected static function getStaticRule($field, $ruleName) { $data = self::getValidationConfigByField($field); return isset($data['staticRules'][$ruleName]) ? $data['staticRules'][$ruleName] : null; }
php
protected static function getStaticRule($field, $ruleName) { $data = self::getValidationConfigByField($field); return isset($data['staticRules'][$ruleName]) ? $data['staticRules'][$ruleName] : null; }
[ "protected", "static", "function", "getStaticRule", "(", "$", "field", ",", "$", "ruleName", ")", "{", "$", "data", "=", "self", "::", "getValidationConfigByField", "(", "$", "field", ")", ";", "return", "isset", "(", "$", "data", "[", "'staticRules'", "]"...
获取指定字段的指定名称的静态验证规则 @param $field @param $ruleName @return string|null
[ "获取指定字段的指定名称的静态验证规则" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L738-L743
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.getValidationConfigByField
protected static function getValidationConfigByField($field) { $data = config('laravel-sms.validation', []); if (isset($data[$field])) { return $data[$field]; } throw new LaravelSmsException("Not find the configuration information of field `$field`, please define it."); }
php
protected static function getValidationConfigByField($field) { $data = config('laravel-sms.validation', []); if (isset($data[$field])) { return $data[$field]; } throw new LaravelSmsException("Not find the configuration information of field `$field`, please define it."); }
[ "protected", "static", "function", "getValidationConfigByField", "(", "$", "field", ")", "{", "$", "data", "=", "config", "(", "'laravel-sms.validation'", ",", "[", "]", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "$", "field", "]", ")", ")", ...
获取验证配置 @param string $field @throws LaravelSmsException @return array
[ "获取验证配置" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L768-L775
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.validateFieldName
protected static function validateFieldName($name) { $fields = self::getFields(); if (!in_array($name, $fields)) { $names = implode(', ', $fields); throw new LaravelSmsException("Illegal field `$name`, the field name must be one of $names."); } }
php
protected static function validateFieldName($name) { $fields = self::getFields(); if (!in_array($name, $fields)) { $names = implode(', ', $fields); throw new LaravelSmsException("Illegal field `$name`, the field name must be one of $names."); } }
[ "protected", "static", "function", "validateFieldName", "(", "$", "name", ")", "{", "$", "fields", "=", "self", "::", "getFields", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "fields", ")", ")", "{", "$", "names", "=", "i...
检查字段名称是否合法 @param $name @throws LaravelSmsException
[ "检查字段名称是否合法" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L784-L791
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.getTemplatesByKey
protected static function getTemplatesByKey($key) { $templates = []; $scheme = PhpSms::scheme(); $config = PhpSms::config(); foreach (array_keys($scheme) as $name) { if (isset($config[$name][$key])) { $templates[$name] = $config[$name][$key]; } } return $templates; }
php
protected static function getTemplatesByKey($key) { $templates = []; $scheme = PhpSms::scheme(); $config = PhpSms::config(); foreach (array_keys($scheme) as $name) { if (isset($config[$name][$key])) { $templates[$name] = $config[$name][$key]; } } return $templates; }
[ "protected", "static", "function", "getTemplatesByKey", "(", "$", "key", ")", "{", "$", "templates", "=", "[", "]", ";", "$", "scheme", "=", "PhpSms", "::", "scheme", "(", ")", ";", "$", "config", "=", "PhpSms", "::", "config", "(", ")", ";", "foreac...
从配置信息中获取指定键名的所有模版id 保留以兼容<2.6.0版本 @param string $key @return array
[ "从配置信息中获取指定键名的所有模版id", "保留以兼容<2", ".", "6", ".", "0版本" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L801-L813
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.generateCode
protected static function generateCode($length = null, $characters = null) { $length = (int) ($length ?: config('laravel-sms.verifyCode.length', config('laravel-sms.code.length', 5))); $characters = (string) ($characters ?: '0123456789'); $charLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; ++$i) { $randomString .= $characters[mt_rand(0, $charLength - 1)]; } return $randomString; }
php
protected static function generateCode($length = null, $characters = null) { $length = (int) ($length ?: config('laravel-sms.verifyCode.length', config('laravel-sms.code.length', 5))); $characters = (string) ($characters ?: '0123456789'); $charLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; ++$i) { $randomString .= $characters[mt_rand(0, $charLength - 1)]; } return $randomString; }
[ "protected", "static", "function", "generateCode", "(", "$", "length", "=", "null", ",", "$", "characters", "=", "null", ")", "{", "$", "length", "=", "(", "int", ")", "(", "$", "length", "?", ":", "config", "(", "'laravel-sms.verifyCode.length'", ",", "...
根据配置文件中的长度生成验证码 @param int|null $length @param string|null $characters @return string
[ "根据配置文件中的长度生成验证码" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L823-L835
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManager.php
SmsManager.generateResult
public static function generateResult($pass, $type, $message = '', $data = []) { $result = []; $result['success'] = (bool) $pass; $result['type'] = $type; if (is_array($message)) { $data = $message; $message = ''; } $message = $message ?: self::getNotifyMessage($type); $result['message'] = Util::vsprintf($message, $data); return $result; }
php
public static function generateResult($pass, $type, $message = '', $data = []) { $result = []; $result['success'] = (bool) $pass; $result['type'] = $type; if (is_array($message)) { $data = $message; $message = ''; } $message = $message ?: self::getNotifyMessage($type); $result['message'] = Util::vsprintf($message, $data); return $result; }
[ "public", "static", "function", "generateResult", "(", "$", "pass", ",", "$", "type", ",", "$", "message", "=", "''", ",", "$", "data", "=", "[", "]", ")", "{", "$", "result", "=", "[", "]", ";", "$", "result", "[", "'success'", "]", "=", "(", ...
合成结果数组 todo 改为抛出异常,然后在控制器中catch @param bool $pass @param string $type @param string $message @param array $data @return array
[ "合成结果数组" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManager.php#L887-L900
toplan/laravel-sms
src/Toplan/LaravelSms/Util.php
Util.vsprintf
public static function vsprintf($template, array $data, \Closure $onError = null) { if (!is_string($template)) { return ''; } if ($template && !(empty($data))) { try { $template = vsprintf($template, $data); } catch (\Exception $e) { if ($onError) { call_user_func($onError, $e); } } } return $template; }
php
public static function vsprintf($template, array $data, \Closure $onError = null) { if (!is_string($template)) { return ''; } if ($template && !(empty($data))) { try { $template = vsprintf($template, $data); } catch (\Exception $e) { if ($onError) { call_user_func($onError, $e); } } } return $template; }
[ "public", "static", "function", "vsprintf", "(", "$", "template", ",", "array", "$", "data", ",", "\\", "Closure", "$", "onError", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "template", ")", ")", "{", "return", "''", ";", "}", "i...
根据模版和数据合成字符串 @param string $template @param array $data @param \Closure|null $onError @return string
[ "根据模版和数据合成字符串" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/Util.php#L25-L41
toplan/laravel-sms
src/Toplan/LaravelSms/Util.php
Util.pathOfUrl
public static function pathOfUrl($url, \Closure $onError = null) { $path = ''; if (!is_string($url)) { return $path; } try { $parsed = parse_url($url); $path = $parsed['path']; } catch (\Exception $e) { if ($onError) { call_user_func($onError, $e); } } return $path; }
php
public static function pathOfUrl($url, \Closure $onError = null) { $path = ''; if (!is_string($url)) { return $path; } try { $parsed = parse_url($url); $path = $parsed['path']; } catch (\Exception $e) { if ($onError) { call_user_func($onError, $e); } } return $path; }
[ "public", "static", "function", "pathOfUrl", "(", "$", "url", ",", "\\", "Closure", "$", "onError", "=", "null", ")", "{", "$", "path", "=", "''", ";", "if", "(", "!", "is_string", "(", "$", "url", ")", ")", "{", "return", "$", "path", ";", "}", ...
获取路径中的path部分 @param string $url @param \Closure|null $onError @return string
[ "获取路径中的path部分" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/Util.php#L51-L67
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManagerServiceProvider.php
SmsManagerServiceProvider.boot
public function boot() { $this->publishes([ __DIR__ . '/../../config/laravel-sms.php' => config_path('laravel-sms.php'), ], 'config'); $this->publishes([ __DIR__ . '/../../../migrations/' => database_path('/migrations'), ], 'migrations'); if (config('laravel-sms.route.enable', true)) { require __DIR__ . '/routes.php'; } require __DIR__ . '/validations.php'; $this->phpSms(); }
php
public function boot() { $this->publishes([ __DIR__ . '/../../config/laravel-sms.php' => config_path('laravel-sms.php'), ], 'config'); $this->publishes([ __DIR__ . '/../../../migrations/' => database_path('/migrations'), ], 'migrations'); if (config('laravel-sms.route.enable', true)) { require __DIR__ . '/routes.php'; } require __DIR__ . '/validations.php'; $this->phpSms(); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/../../config/laravel-sms.php'", "=>", "config_path", "(", "'laravel-sms.php'", ")", ",", "]", ",", "'config'", ")", ";", "$", "this", "->", "publishes",...
启动服务
[ "启动服务" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManagerServiceProvider.php#L17-L34
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManagerServiceProvider.php
SmsManagerServiceProvider.register
public function register() { $this->mergeConfigFrom(__DIR__ . '/../../config/laravel-sms.php', 'laravel-sms'); $this->app->singleton('Toplan\\Sms\\SmsManager', function ($app) { $token = $app->request->header('access-token', null); if (empty($token)) { $token = $app->request->input('access_token', null); } $input = $app->request->all(); return new SmsManager($token, $input); }); }
php
public function register() { $this->mergeConfigFrom(__DIR__ . '/../../config/laravel-sms.php', 'laravel-sms'); $this->app->singleton('Toplan\\Sms\\SmsManager', function ($app) { $token = $app->request->header('access-token', null); if (empty($token)) { $token = $app->request->input('access_token', null); } $input = $app->request->all(); return new SmsManager($token, $input); }); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "mergeConfigFrom", "(", "__DIR__", ".", "'/../../config/laravel-sms.php'", ",", "'laravel-sms'", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "'Toplan\\\\Sms\\\\SmsManager'", ",", ...
注册服务
[ "注册服务" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManagerServiceProvider.php#L39-L52
toplan/laravel-sms
src/Toplan/LaravelSms/SmsManagerServiceProvider.php
SmsManagerServiceProvider.phpSms
protected function phpSms() { $queueJob = config('laravel-sms.queueJob', 'Toplan\Sms\SendReminderSms'); PhpSms::queue(false, function ($sms) use ($queueJob) { if (!class_exists($queueJob)) { throw new LaravelSmsException("Class [$queueJob] does not exists."); } $this->dispatch(new $queueJob($sms)); }); PhpSms::beforeSend(function ($task) { if (!config('laravel-sms.dbLogs', false)) { return true; } $data = $task->data ?: []; $to = is_array($data['to']) ? json_encode($data['to']) : $data['to']; $id = DB::table('laravel_sms')->insertGetId([ 'to' => $to ?: '', 'temp_id' => json_encode($data['templates']), 'data' => json_encode($data['data']), 'content' => $data['content'] ?: '', 'voice_code' => $data['code'] ?: '', 'created_at' => date('Y-m-d H:i:s', time()), ]); $data['_sms_id'] = $id; $task->data($data); }); PhpSms::afterSend(function ($task, $result) { if (!config('laravel-sms.dbLogs', false)) { return true; } $microTime = $result['time']['finished_at']; $finishedAt = explode(' ', $microTime)[1]; $data = $task->data; if (!isset($data['_sms_id'])) { return true; } DB::beginTransaction(); $dbData = []; $dbData['updated_at'] = date('Y-m-d H:i:s', $finishedAt); $dbData['result_info'] = json_encode($result['logs']); if ($result['success']) { $dbData['sent_time'] = $finishedAt; } else { DB::table('laravel_sms')->where('id', $data['_sms_id'])->increment('fail_times'); $dbData['last_fail_time'] = $finishedAt; } DB::table('laravel_sms')->where('id', $data['_sms_id'])->update($dbData); DB::commit(); }); }
php
protected function phpSms() { $queueJob = config('laravel-sms.queueJob', 'Toplan\Sms\SendReminderSms'); PhpSms::queue(false, function ($sms) use ($queueJob) { if (!class_exists($queueJob)) { throw new LaravelSmsException("Class [$queueJob] does not exists."); } $this->dispatch(new $queueJob($sms)); }); PhpSms::beforeSend(function ($task) { if (!config('laravel-sms.dbLogs', false)) { return true; } $data = $task->data ?: []; $to = is_array($data['to']) ? json_encode($data['to']) : $data['to']; $id = DB::table('laravel_sms')->insertGetId([ 'to' => $to ?: '', 'temp_id' => json_encode($data['templates']), 'data' => json_encode($data['data']), 'content' => $data['content'] ?: '', 'voice_code' => $data['code'] ?: '', 'created_at' => date('Y-m-d H:i:s', time()), ]); $data['_sms_id'] = $id; $task->data($data); }); PhpSms::afterSend(function ($task, $result) { if (!config('laravel-sms.dbLogs', false)) { return true; } $microTime = $result['time']['finished_at']; $finishedAt = explode(' ', $microTime)[1]; $data = $task->data; if (!isset($data['_sms_id'])) { return true; } DB::beginTransaction(); $dbData = []; $dbData['updated_at'] = date('Y-m-d H:i:s', $finishedAt); $dbData['result_info'] = json_encode($result['logs']); if ($result['success']) { $dbData['sent_time'] = $finishedAt; } else { DB::table('laravel_sms')->where('id', $data['_sms_id'])->increment('fail_times'); $dbData['last_fail_time'] = $finishedAt; } DB::table('laravel_sms')->where('id', $data['_sms_id'])->update($dbData); DB::commit(); }); }
[ "protected", "function", "phpSms", "(", ")", "{", "$", "queueJob", "=", "config", "(", "'laravel-sms.queueJob'", ",", "'Toplan\\Sms\\SendReminderSms'", ")", ";", "PhpSms", "::", "queue", "(", "false", ",", "function", "(", "$", "sms", ")", "use", "(", "$", ...
配置PhpSms
[ "配置PhpSms" ]
train
https://github.com/toplan/laravel-sms/blob/9c8427493c768c07a15fb993436267b81f31bae5/src/Toplan/LaravelSms/SmsManagerServiceProvider.php#L57-L109
henrikbjorn/GravatarBundle
Twig/GravatarExtension.php
GravatarExtension.getUrl
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true) { return $this->baseHelper->getUrl($email, $size, $rating, $default, $secure); }
php
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true) { return $this->baseHelper->getUrl($email, $size, $rating, $default, $secure); }
[ "public", "function", "getUrl", "(", "$", "email", ",", "$", "size", "=", "null", ",", "$", "rating", "=", "null", ",", "$", "default", "=", "null", ",", "$", "secure", "=", "true", ")", "{", "return", "$", "this", "->", "baseHelper", "->", "getUrl...
{@inheritdoc}
[ "{" ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/Twig/GravatarExtension.php#L40-L43
henrikbjorn/GravatarBundle
Twig/GravatarExtension.php
GravatarExtension.getUrlForHash
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true) { return $this->baseHelper->getUrlForHash($hash, $size, $rating, $default, $secure); }
php
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true) { return $this->baseHelper->getUrlForHash($hash, $size, $rating, $default, $secure); }
[ "public", "function", "getUrlForHash", "(", "$", "hash", ",", "$", "size", "=", "null", ",", "$", "rating", "=", "null", ",", "$", "default", "=", "null", ",", "$", "secure", "=", "true", ")", "{", "return", "$", "this", "->", "baseHelper", "->", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/Twig/GravatarExtension.php#L48-L51
henrikbjorn/GravatarBundle
GravatarApi.php
GravatarApi.getProfileUrl
public function getProfileUrl($email, $secure = true) { $hash = md5(strtolower(trim($email))); return $this->getProfileUrlForHash($hash, $secure); }
php
public function getProfileUrl($email, $secure = true) { $hash = md5(strtolower(trim($email))); return $this->getProfileUrlForHash($hash, $secure); }
[ "public", "function", "getProfileUrl", "(", "$", "email", ",", "$", "secure", "=", "true", ")", "{", "$", "hash", "=", "md5", "(", "strtolower", "(", "trim", "(", "$", "email", ")", ")", ")", ";", "return", "$", "this", "->", "getProfileUrlForHash", ...
Returns a url for a gravatar profile. @param string $email @param bool $secure @return string
[ "Returns", "a", "url", "for", "a", "gravatar", "profile", "." ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/GravatarApi.php#L87-L92
henrikbjorn/GravatarBundle
GravatarApi.php
GravatarApi.getProfileUrlForHash
public function getProfileUrlForHash($hash, $secure = true) { $secure = $secure ?: $this->defaults['secure']; return ($secure ? 'https://secure' : 'http://www').'.gravatar.com/'.$hash; }
php
public function getProfileUrlForHash($hash, $secure = true) { $secure = $secure ?: $this->defaults['secure']; return ($secure ? 'https://secure' : 'http://www').'.gravatar.com/'.$hash; }
[ "public", "function", "getProfileUrlForHash", "(", "$", "hash", ",", "$", "secure", "=", "true", ")", "{", "$", "secure", "=", "$", "secure", "?", ":", "$", "this", "->", "defaults", "[", "'secure'", "]", ";", "return", "(", "$", "secure", "?", "'htt...
Returns a url for a gravatar profile for the given hash. @param string $hash @param bool $secure @return string
[ "Returns", "a", "url", "for", "a", "gravatar", "profile", "for", "the", "given", "hash", "." ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/GravatarApi.php#L102-L107
henrikbjorn/GravatarBundle
GravatarApi.php
GravatarApi.exists
public function exists($email) { $path = $this->getUrl($email, null, null, '404'); if (!$sock = @fsockopen('gravatar.com', 80, $errorNo, $error)) { return; } fwrite($sock, 'HEAD '.$path." HTTP/1.0\r\n\r\n"); $header = fgets($sock, 128); fclose($sock); return strpos($header, '404') ? false : true; }
php
public function exists($email) { $path = $this->getUrl($email, null, null, '404'); if (!$sock = @fsockopen('gravatar.com', 80, $errorNo, $error)) { return; } fwrite($sock, 'HEAD '.$path." HTTP/1.0\r\n\r\n"); $header = fgets($sock, 128); fclose($sock); return strpos($header, '404') ? false : true; }
[ "public", "function", "exists", "(", "$", "email", ")", "{", "$", "path", "=", "$", "this", "->", "getUrl", "(", "$", "email", ",", "null", ",", "null", ",", "'404'", ")", ";", "if", "(", "!", "$", "sock", "=", "@", "fsockopen", "(", "'gravatar.c...
Checks if a gravatar exists for the email. It does this by checking for the presence of 404 in the header returned. Will return null if fsockopen fails, for example when the hostname cannot be resolved. @param string $email @return bool|null Boolean if we could connect, null if no connection to gravatar.com
[ "Checks", "if", "a", "gravatar", "exists", "for", "the", "email", ".", "It", "does", "this", "by", "checking", "for", "the", "presence", "of", "404", "in", "the", "header", "returned", ".", "Will", "return", "null", "if", "fsockopen", "fails", "for", "ex...
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/GravatarApi.php#L117-L130
henrikbjorn/GravatarBundle
Templating/Helper/GravatarHelper.php
GravatarHelper.getUrl
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true) { return $this->api->getUrl($email, $size, $rating, $default, $this->isSecure($secure)); }
php
public function getUrl($email, $size = null, $rating = null, $default = null, $secure = true) { return $this->api->getUrl($email, $size, $rating, $default, $this->isSecure($secure)); }
[ "public", "function", "getUrl", "(", "$", "email", ",", "$", "size", "=", "null", ",", "$", "rating", "=", "null", ",", "$", "default", "=", "null", ",", "$", "secure", "=", "true", ")", "{", "return", "$", "this", "->", "api", "->", "getUrl", "(...
{@inheritdoc}
[ "{" ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/Templating/Helper/GravatarHelper.php#L42-L45
henrikbjorn/GravatarBundle
Templating/Helper/GravatarHelper.php
GravatarHelper.getUrlForHash
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true) { return $this->api->getUrlForHash($hash, $size, $rating, $default, $this->isSecure($secure)); }
php
public function getUrlForHash($hash, $size = null, $rating = null, $default = null, $secure = true) { return $this->api->getUrlForHash($hash, $size, $rating, $default, $this->isSecure($secure)); }
[ "public", "function", "getUrlForHash", "(", "$", "hash", ",", "$", "size", "=", "null", ",", "$", "rating", "=", "null", ",", "$", "default", "=", "null", ",", "$", "secure", "=", "true", ")", "{", "return", "$", "this", "->", "api", "->", "getUrlF...
{@inheritdoc}
[ "{" ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/Templating/Helper/GravatarHelper.php#L50-L53
henrikbjorn/GravatarBundle
Templating/Helper/GravatarHelper.php
GravatarHelper.getProfileUrl
public function getProfileUrl($email, $secure = true) { return $this->api->getProfileUrl($email, $this->isSecure($secure)); }
php
public function getProfileUrl($email, $secure = true) { return $this->api->getProfileUrl($email, $this->isSecure($secure)); }
[ "public", "function", "getProfileUrl", "(", "$", "email", ",", "$", "secure", "=", "true", ")", "{", "return", "$", "this", "->", "api", "->", "getProfileUrl", "(", "$", "email", ",", "$", "this", "->", "isSecure", "(", "$", "secure", ")", ")", ";", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/Templating/Helper/GravatarHelper.php#L58-L61
henrikbjorn/GravatarBundle
Templating/Helper/GravatarHelper.php
GravatarHelper.getProfileUrlForHash
public function getProfileUrlForHash($hash, $secure = true) { return $this->api->getProfileUrlForHash($hash, $this->isSecure($secure)); }
php
public function getProfileUrlForHash($hash, $secure = true) { return $this->api->getProfileUrlForHash($hash, $this->isSecure($secure)); }
[ "public", "function", "getProfileUrlForHash", "(", "$", "hash", ",", "$", "secure", "=", "true", ")", "{", "return", "$", "this", "->", "api", "->", "getProfileUrlForHash", "(", "$", "hash", ",", "$", "this", "->", "isSecure", "(", "$", "secure", ")", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/Templating/Helper/GravatarHelper.php#L66-L69
henrikbjorn/GravatarBundle
Templating/Helper/GravatarHelper.php
GravatarHelper.isSecure
protected function isSecure($preset = true) { if (null !== $preset) { return (bool) $preset; } if (null === $this->router) { return false; } return 'https' == strtolower($this->router->getContext()->getScheme()); }
php
protected function isSecure($preset = true) { if (null !== $preset) { return (bool) $preset; } if (null === $this->router) { return false; } return 'https' == strtolower($this->router->getContext()->getScheme()); }
[ "protected", "function", "isSecure", "(", "$", "preset", "=", "true", ")", "{", "if", "(", "null", "!==", "$", "preset", ")", "{", "return", "(", "bool", ")", "$", "preset", ";", "}", "if", "(", "null", "===", "$", "this", "->", "router", ")", "{...
Returns true if avatar should be fetched over secure connection. @param mixed $preset @return bool
[ "Returns", "true", "if", "avatar", "should", "be", "fetched", "over", "secure", "connection", "." ]
train
https://github.com/henrikbjorn/GravatarBundle/blob/5a4e3619f0654eaa3ad4e4a45d927bd0bf044e7c/Templating/Helper/GravatarHelper.php#L106-L117
joshdifabio/composed
src/RootPackage.php
RootPackage.getPackages
public function getPackages() : PackageCollection { if (null === $this->packages) { $packages = array_merge( array( $this->getName() => $this, ), $this->getInstalledPackagesFile()->getPackages()->toArray() ); $this->packages = new PackageCollection($packages); } return $this->packages; }
php
public function getPackages() : PackageCollection { if (null === $this->packages) { $packages = array_merge( array( $this->getName() => $this, ), $this->getInstalledPackagesFile()->getPackages()->toArray() ); $this->packages = new PackageCollection($packages); } return $this->packages; }
[ "public", "function", "getPackages", "(", ")", ":", "PackageCollection", "{", "if", "(", "null", "===", "$", "this", "->", "packages", ")", "{", "$", "packages", "=", "array_merge", "(", "array", "(", "$", "this", "->", "getName", "(", ")", "=>", "$", ...
Returns all packages in the project, including the root one
[ "Returns", "all", "packages", "in", "the", "project", "including", "the", "root", "one" ]
train
https://github.com/joshdifabio/composed/blob/0889b1647e2e8c41068d2c7f5eff76b0e340bbe6/src/RootPackage.php#L25-L39
joshdifabio/composed
src/PackageCollection.php
PackageCollection.getConfig
public function getConfig($keys = [], $default = null) : array { if (2 > func_num_args()) { $default = new \stdClass; } $config = @array_map( function (AbstractPackage $package) use ($keys, $default) { return $package->getConfig($keys, $default); }, $this->packages ); if (2 > func_num_args()) { $config = array_filter($config, function ($value) use ($default) { return $value !== $default; }); } return $config; }
php
public function getConfig($keys = [], $default = null) : array { if (2 > func_num_args()) { $default = new \stdClass; } $config = @array_map( function (AbstractPackage $package) use ($keys, $default) { return $package->getConfig($keys, $default); }, $this->packages ); if (2 > func_num_args()) { $config = array_filter($config, function ($value) use ($default) { return $value !== $default; }); } return $config; }
[ "public", "function", "getConfig", "(", "$", "keys", "=", "[", "]", ",", "$", "default", "=", "null", ")", ":", "array", "{", "if", "(", "2", ">", "func_num_args", "(", ")", ")", "{", "$", "default", "=", "new", "\\", "stdClass", ";", "}", "$", ...
Get a config value from all packages @param string|array $keys Either a string, e.g. 'required' to get the dependencies by a package, or an array, e.g. ['required', 'php'] to get the version of PHP required by a package @param mixed $default If this is not explicitly specified, packages which do not provide any config value will be omitted from the result. Explicitly setting this to NULL is not the same as omitting it and will result in packages which do not provide config being returned with a value of NULL @return array Keys are package names, values are the retrieved config as an array or scalar
[ "Get", "a", "config", "value", "from", "all", "packages" ]
train
https://github.com/joshdifabio/composed/blob/0889b1647e2e8c41068d2c7f5eff76b0e340bbe6/src/PackageCollection.php#L44-L64
joshdifabio/composed
src/PackageCollection.php
PackageCollection.sortByDependencies
public function sortByDependencies() : self { /** @var $packages Package[] */ $packages = $this->packages; $sortedPackages = []; while (!empty($packages)) { foreach ($packages as $packageName => $package) { $dependentPackages = $package->getDependencies()->toArray(); if (empty(array_diff_key($dependentPackages, $sortedPackages))) { // all of this packages dependencies are already in the sorted array, so it can be appended $sortedPackages[$packageName] = $package; unset($packages[$packageName]); continue(2); } } throw new \LogicException('Packages have circular dependencies'); } return new static($sortedPackages); }
php
public function sortByDependencies() : self { /** @var $packages Package[] */ $packages = $this->packages; $sortedPackages = []; while (!empty($packages)) { foreach ($packages as $packageName => $package) { $dependentPackages = $package->getDependencies()->toArray(); if (empty(array_diff_key($dependentPackages, $sortedPackages))) { // all of this packages dependencies are already in the sorted array, so it can be appended $sortedPackages[$packageName] = $package; unset($packages[$packageName]); continue(2); } } throw new \LogicException('Packages have circular dependencies'); } return new static($sortedPackages); }
[ "public", "function", "sortByDependencies", "(", ")", ":", "self", "{", "/** @var $packages Package[] */", "$", "packages", "=", "$", "this", "->", "packages", ";", "$", "sortedPackages", "=", "[", "]", ";", "while", "(", "!", "empty", "(", "$", "packages", ...
Returns all packages sorted based on their dependencies. Each package is guaranteed to appear after all of its dependencies in the collection
[ "Returns", "all", "packages", "sorted", "based", "on", "their", "dependencies", ".", "Each", "package", "is", "guaranteed", "to", "appear", "after", "all", "of", "its", "dependencies", "in", "the", "collection" ]
train
https://github.com/joshdifabio/composed/blob/0889b1647e2e8c41068d2c7f5eff76b0e340bbe6/src/PackageCollection.php#L80-L100
PayU/openpayu_php
lib/OpenPayU/Oauth/Oauth.php
OpenPayU_Oauth.parseResponse
private static function parseResponse($response) { $httpStatus = $response['code']; if ($httpStatus == 500) { $result = new ResultError(); $result->setErrorDescription($response['response']); OpenPayU_Http::throwErrorHttpStatusException($httpStatus, $result); } $message = OpenPayU_Util::convertJsonToArray($response['response'], true); if (json_last_error() == JSON_ERROR_SYNTAX) { throw new OpenPayU_Exception_ServerError('Incorrect json response. Response: [' . $response['response'] . ']'); } if ($httpStatus == 200) { $result = new OauthResultClientCredentials(); $result->setAccessToken($message['access_token']) ->setTokenType($message['token_type']) ->setExpiresIn($message['expires_in']) ->setGrantType($message['grant_type']) ->calculateExpireDate(new \DateTime()); return $result; } $result = new ResultError(); $result->setError($message['error']) ->setErrorDescription($message['error_description']); OpenPayU_Http::throwErrorHttpStatusException($httpStatus, $result); }
php
private static function parseResponse($response) { $httpStatus = $response['code']; if ($httpStatus == 500) { $result = new ResultError(); $result->setErrorDescription($response['response']); OpenPayU_Http::throwErrorHttpStatusException($httpStatus, $result); } $message = OpenPayU_Util::convertJsonToArray($response['response'], true); if (json_last_error() == JSON_ERROR_SYNTAX) { throw new OpenPayU_Exception_ServerError('Incorrect json response. Response: [' . $response['response'] . ']'); } if ($httpStatus == 200) { $result = new OauthResultClientCredentials(); $result->setAccessToken($message['access_token']) ->setTokenType($message['token_type']) ->setExpiresIn($message['expires_in']) ->setGrantType($message['grant_type']) ->calculateExpireDate(new \DateTime()); return $result; } $result = new ResultError(); $result->setError($message['error']) ->setErrorDescription($message['error_description']); OpenPayU_Http::throwErrorHttpStatusException($httpStatus, $result); }
[ "private", "static", "function", "parseResponse", "(", "$", "response", ")", "{", "$", "httpStatus", "=", "$", "response", "[", "'code'", "]", ";", "if", "(", "$", "httpStatus", "==", "500", ")", "{", "$", "result", "=", "new", "ResultError", "(", ")",...
Parse response from PayU @param array $response @return OauthResultClientCredentials @throws OpenPayU_Exception @throws OpenPayU_Exception_Authorization @throws OpenPayU_Exception_Network @throws OpenPayU_Exception_ServerError @throws OpenPayU_Exception_ServerMaintenance
[ "Parse", "response", "from", "PayU" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/Oauth/Oauth.php#L77-L110
PayU/openpayu_php
lib/OpenPayU/Util.php
OpenPayU_Util.generateSignData
public static function generateSignData(array $data, $algorithm = 'SHA-256', $merchantPosId = '', $signatureKey = '') { if (empty($signatureKey)) throw new OpenPayU_Exception_Configuration('Merchant Signature Key should not be null or empty.'); if (empty($merchantPosId)) throw new OpenPayU_Exception_Configuration('MerchantPosId should not be null or empty.'); $contentForSign = ''; ksort($data); foreach ($data as $key => $value) { $contentForSign .= $key . '=' . urlencode($value) . '&'; } if (in_array($algorithm, array('SHA-256', 'SHA'))) { $hashAlgorithm = 'sha256'; $algorithm = 'SHA-256'; } else if ($algorithm == 'SHA-384') { $hashAlgorithm = 'sha384'; $algorithm = 'SHA-384'; } else if ($algorithm == 'SHA-512') { $hashAlgorithm = 'sha512'; $algorithm = 'SHA-512'; } $signature = hash($hashAlgorithm, $contentForSign . $signatureKey); $signData = 'sender=' . $merchantPosId . ';algorithm=' . $algorithm . ';signature=' . $signature; return $signData; }
php
public static function generateSignData(array $data, $algorithm = 'SHA-256', $merchantPosId = '', $signatureKey = '') { if (empty($signatureKey)) throw new OpenPayU_Exception_Configuration('Merchant Signature Key should not be null or empty.'); if (empty($merchantPosId)) throw new OpenPayU_Exception_Configuration('MerchantPosId should not be null or empty.'); $contentForSign = ''; ksort($data); foreach ($data as $key => $value) { $contentForSign .= $key . '=' . urlencode($value) . '&'; } if (in_array($algorithm, array('SHA-256', 'SHA'))) { $hashAlgorithm = 'sha256'; $algorithm = 'SHA-256'; } else if ($algorithm == 'SHA-384') { $hashAlgorithm = 'sha384'; $algorithm = 'SHA-384'; } else if ($algorithm == 'SHA-512') { $hashAlgorithm = 'sha512'; $algorithm = 'SHA-512'; } $signature = hash($hashAlgorithm, $contentForSign . $signatureKey); $signData = 'sender=' . $merchantPosId . ';algorithm=' . $algorithm . ';signature=' . $signature; return $signData; }
[ "public", "static", "function", "generateSignData", "(", "array", "$", "data", ",", "$", "algorithm", "=", "'SHA-256'", ",", "$", "merchantPosId", "=", "''", ",", "$", "signatureKey", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "signatureKey", ")"...
Function generate sign data @param array $data @param string $algorithm @param string $merchantPosId @param string $signatureKey @return string @throws OpenPayU_Exception_Configuration
[ "Function", "generate", "sign", "data" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/Util.php#L25-L56
PayU/openpayu_php
lib/OpenPayU/Util.php
OpenPayU_Util.parseSignature
public static function parseSignature($data) { if (empty($data)) { return null; } $signatureData = array(); $list = explode(';', rtrim($data, ';')); if (empty($list)) { return null; } foreach ($list as $value) { $explode = explode('=', $value); if (count($explode) != 2) { return null; } $signatureData[$explode[0]] = $explode[1]; } return $signatureData; }
php
public static function parseSignature($data) { if (empty($data)) { return null; } $signatureData = array(); $list = explode(';', rtrim($data, ';')); if (empty($list)) { return null; } foreach ($list as $value) { $explode = explode('=', $value); if (count($explode) != 2) { return null; } $signatureData[$explode[0]] = $explode[1]; } return $signatureData; }
[ "public", "static", "function", "parseSignature", "(", "$", "data", ")", "{", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "return", "null", ";", "}", "$", "signatureData", "=", "array", "(", ")", ";", "$", "list", "=", "explode", "(", "';'...
Function returns signature data object @param string $data @return null|array
[ "Function", "returns", "signature", "data", "object" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/Util.php#L65-L87
PayU/openpayu_php
lib/OpenPayU/Util.php
OpenPayU_Util.verifySignature
public static function verifySignature($message, $signature, $signatureKey, $algorithm = 'MD5') { if (isset($signature)) { if ($algorithm === 'MD5') { $hash = md5($message . $signatureKey); } else if (in_array($algorithm, array('SHA', 'SHA1', 'SHA-1'))) { $hash = sha1($message . $signatureKey); } else { $hash = hash('sha256', $message . $signatureKey); } if (strcmp($signature, $hash) == 0) { return true; } } return false; }
php
public static function verifySignature($message, $signature, $signatureKey, $algorithm = 'MD5') { if (isset($signature)) { if ($algorithm === 'MD5') { $hash = md5($message . $signatureKey); } else if (in_array($algorithm, array('SHA', 'SHA1', 'SHA-1'))) { $hash = sha1($message . $signatureKey); } else { $hash = hash('sha256', $message . $signatureKey); } if (strcmp($signature, $hash) == 0) { return true; } } return false; }
[ "public", "static", "function", "verifySignature", "(", "$", "message", ",", "$", "signature", ",", "$", "signatureKey", ",", "$", "algorithm", "=", "'MD5'", ")", "{", "if", "(", "isset", "(", "$", "signature", ")", ")", "{", "if", "(", "$", "algorithm...
Function returns signature validate @param string $message @param string $signature @param string $signatureKey @param string $algorithm @return bool
[ "Function", "returns", "signature", "validate" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/Util.php#L99-L116
PayU/openpayu_php
lib/OpenPayU/Util.php
OpenPayU_Util.buildJsonFromArray
public static function buildJsonFromArray($data, $rootElement = '') { if (!is_array($data)) { return null; } if (!empty($rootElement)) { $data = array($rootElement => $data); } $data = self::setSenderProperty($data); return json_encode($data); }
php
public static function buildJsonFromArray($data, $rootElement = '') { if (!is_array($data)) { return null; } if (!empty($rootElement)) { $data = array($rootElement => $data); } $data = self::setSenderProperty($data); return json_encode($data); }
[ "public", "static", "function", "buildJsonFromArray", "(", "$", "data", ",", "$", "rootElement", "=", "''", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "empty", "(", "$", "rootE...
Function builds OpenPayU Json Document @param string $data @param string $rootElement @return null|string
[ "Function", "builds", "OpenPayU", "Json", "Document" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/Util.php#L126-L139
PayU/openpayu_php
lib/OpenPayU/v2/Token.php
OpenPayU_Token.delete
public static function delete($token) { try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } if (!$authType instanceof AuthType_Oauth) { throw new OpenPayU_Exception_Configuration('Delete token works only with OAuth'); } if (OpenPayU_Configuration::getOauthGrantType() !== OauthGrantType::TRUSTED_MERCHANT) { throw new OpenPayU_Exception_Configuration('Token delete request is available only for trusted_merchant'); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::TOKENS_SERVICE . '/' . $token; $response = self::verifyResponse(OpenPayU_Http::doDelete($pathUrl, $authType)); return $response; }
php
public static function delete($token) { try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } if (!$authType instanceof AuthType_Oauth) { throw new OpenPayU_Exception_Configuration('Delete token works only with OAuth'); } if (OpenPayU_Configuration::getOauthGrantType() !== OauthGrantType::TRUSTED_MERCHANT) { throw new OpenPayU_Exception_Configuration('Token delete request is available only for trusted_merchant'); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::TOKENS_SERVICE . '/' . $token; $response = self::verifyResponse(OpenPayU_Http::doDelete($pathUrl, $authType)); return $response; }
[ "public", "static", "function", "delete", "(", "$", "token", ")", "{", "try", "{", "$", "authType", "=", "self", "::", "getAuth", "(", ")", ";", "}", "catch", "(", "OpenPayU_Exception", "$", "e", ")", "{", "throw", "new", "OpenPayU_Exception", "(", "$"...
Deleting a payment token @param string $token @return null|OpenPayU_Result @throws OpenPayU_Exception @throws OpenPayU_Exception_Configuration
[ "Deleting", "a", "payment", "token" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Token.php#L23-L45
PayU/openpayu_php
lib/OpenPayU/v2/Retrieve.php
OpenPayU_Retrieve.payMethods
public static function payMethods($lang = null) { try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } if (!$authType instanceof AuthType_Oauth) { throw new OpenPayU_Exception_Configuration('Retrieve works only with OAuth'); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::PAYMETHODS_SERVICE; if ($lang !== null) { $pathUrl .= '?lang=' . $lang; } $response = self::verifyResponse(OpenPayU_Http::doGet($pathUrl, $authType)); return $response; }
php
public static function payMethods($lang = null) { try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } if (!$authType instanceof AuthType_Oauth) { throw new OpenPayU_Exception_Configuration('Retrieve works only with OAuth'); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::PAYMETHODS_SERVICE; if ($lang !== null) { $pathUrl .= '?lang=' . $lang; } $response = self::verifyResponse(OpenPayU_Http::doGet($pathUrl, $authType)); return $response; }
[ "public", "static", "function", "payMethods", "(", "$", "lang", "=", "null", ")", "{", "try", "{", "$", "authType", "=", "self", "::", "getAuth", "(", ")", ";", "}", "catch", "(", "OpenPayU_Exception", "$", "e", ")", "{", "throw", "new", "OpenPayU_Exce...
Get Pay Methods from POS @param string $lang @return null|OpenPayU_Result @throws OpenPayU_Exception @throws OpenPayU_Exception_Configuration
[ "Get", "Pay", "Methods", "from", "POS" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Retrieve.php#L23-L44
PayU/openpayu_php
lib/OpenPayU/HttpCurl.php
OpenPayU_HttpCurl.getSignature
public static function getSignature($headers) { foreach($headers as $name => $value) { if(preg_match('/X-OpenPayU-Signature/i', $name) || preg_match('/OpenPayu-Signature/i', $name)) return $value; } return null; }
php
public static function getSignature($headers) { foreach($headers as $name => $value) { if(preg_match('/X-OpenPayU-Signature/i', $name) || preg_match('/OpenPayu-Signature/i', $name)) return $value; } return null; }
[ "public", "static", "function", "getSignature", "(", "$", "headers", ")", "{", "foreach", "(", "$", "headers", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "preg_match", "(", "'/X-OpenPayU-Signature/i'", ",", "$", "name", ")", "||", "preg_...
@param array $headers @return mixed
[ "@param", "array", "$headers" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/HttpCurl.php#L72-L81
PayU/openpayu_php
lib/OpenPayU/v2/Order.php
OpenPayU_Order.create
public static function create($order) { $data = OpenPayU_Util::buildJsonFromArray($order); if (empty($data)) { throw new OpenPayU_Exception('Empty message OrderCreateRequest'); } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE; $result = self::verifyResponse(OpenPayU_Http::doPost($pathUrl, $data, $authType), 'OrderCreateResponse'); return $result; }
php
public static function create($order) { $data = OpenPayU_Util::buildJsonFromArray($order); if (empty($data)) { throw new OpenPayU_Exception('Empty message OrderCreateRequest'); } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE; $result = self::verifyResponse(OpenPayU_Http::doPost($pathUrl, $data, $authType), 'OrderCreateResponse'); return $result; }
[ "public", "static", "function", "create", "(", "$", "order", ")", "{", "$", "data", "=", "OpenPayU_Util", "::", "buildJsonFromArray", "(", "$", "order", ")", ";", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "throw", "new", "OpenPayU_Exception", ...
Creates new Order - Sends to PayU OrderCreateRequest @param array $order A array containing full Order @return object $result Response array with OrderCreateResponse @throws OpenPayU_Exception
[ "Creates", "new", "Order", "-", "Sends", "to", "PayU", "OrderCreateRequest" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Order.php#L41-L60
PayU/openpayu_php
lib/OpenPayU/v2/Order.php
OpenPayU_Order.retrieve
public static function retrieve($orderId) { if (empty($orderId)) { throw new OpenPayU_Exception('Empty value of orderId'); } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE . $orderId; $result = self::verifyResponse(OpenPayU_Http::doGet($pathUrl, $authType), 'OrderRetrieveResponse'); return $result; }
php
public static function retrieve($orderId) { if (empty($orderId)) { throw new OpenPayU_Exception('Empty value of orderId'); } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE . $orderId; $result = self::verifyResponse(OpenPayU_Http::doGet($pathUrl, $authType), 'OrderRetrieveResponse'); return $result; }
[ "public", "static", "function", "retrieve", "(", "$", "orderId", ")", "{", "if", "(", "empty", "(", "$", "orderId", ")", ")", "{", "throw", "new", "OpenPayU_Exception", "(", "'Empty value of orderId'", ")", ";", "}", "try", "{", "$", "authType", "=", "se...
Retrieves information about the order - Sends to PayU OrderRetrieveRequest @param string $orderId PayU OrderId sent back in OrderCreateResponse @return OpenPayU_Result $result Response array with OrderRetrieveResponse @throws OpenPayU_Exception
[ "Retrieves", "information", "about", "the", "order", "-", "Sends", "to", "PayU", "OrderRetrieveRequest" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Order.php#L70-L87
PayU/openpayu_php
lib/OpenPayU/v2/Order.php
OpenPayU_Order.statusUpdate
public static function statusUpdate($orderStatusUpdate) { if (empty($orderStatusUpdate)) { throw new OpenPayU_Exception('Empty order status data'); } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $data = OpenPayU_Util::buildJsonFromArray($orderStatusUpdate); $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE . $orderStatusUpdate['orderId'] . '/status'; $result = self::verifyResponse(OpenPayU_Http::doPut($pathUrl, $data, $authType), 'OrderStatusUpdateResponse'); return $result; }
php
public static function statusUpdate($orderStatusUpdate) { if (empty($orderStatusUpdate)) { throw new OpenPayU_Exception('Empty order status data'); } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $data = OpenPayU_Util::buildJsonFromArray($orderStatusUpdate); $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE . $orderStatusUpdate['orderId'] . '/status'; $result = self::verifyResponse(OpenPayU_Http::doPut($pathUrl, $data, $authType), 'OrderStatusUpdateResponse'); return $result; }
[ "public", "static", "function", "statusUpdate", "(", "$", "orderStatusUpdate", ")", "{", "if", "(", "empty", "(", "$", "orderStatusUpdate", ")", ")", "{", "throw", "new", "OpenPayU_Exception", "(", "'Empty order status data'", ")", ";", "}", "try", "{", "$", ...
Updates Order status - Sends to PayU OrderStatusUpdateRequest @param string $orderStatusUpdate A array containing full OrderStatus @return OpenPayU_Result $result Response array with OrderStatusUpdateResponse @throws OpenPayU_Exception
[ "Updates", "Order", "status", "-", "Sends", "to", "PayU", "OrderStatusUpdateRequest" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Order.php#L150-L168
PayU/openpayu_php
lib/OpenPayU/v2/Order.php
OpenPayU_Order.consumeNotification
public static function consumeNotification($data) { if (empty($data)) { throw new OpenPayU_Exception('Empty value of data'); } $headers = OpenPayU_Util::getRequestHeaders(); $incomingSignature = OpenPayU_HttpCurl::getSignature($headers); self::verifyDocumentSignature($data, $incomingSignature); return OpenPayU_Order::verifyResponse(array('response' => $data, 'code' => 200), 'OrderNotifyRequest'); }
php
public static function consumeNotification($data) { if (empty($data)) { throw new OpenPayU_Exception('Empty value of data'); } $headers = OpenPayU_Util::getRequestHeaders(); $incomingSignature = OpenPayU_HttpCurl::getSignature($headers); self::verifyDocumentSignature($data, $incomingSignature); return OpenPayU_Order::verifyResponse(array('response' => $data, 'code' => 200), 'OrderNotifyRequest'); }
[ "public", "static", "function", "consumeNotification", "(", "$", "data", ")", "{", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "throw", "new", "OpenPayU_Exception", "(", "'Empty value of data'", ")", ";", "}", "$", "headers", "=", "OpenPayU_Util", ...
Consume notification message @access public @param $data string Request array received from with PayU OrderNotifyRequest @return null|OpenPayU_Result Response array with OrderNotifyRequest @throws OpenPayU_Exception
[ "Consume", "notification", "message" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Order.php#L178-L190
PayU/openpayu_php
lib/OpenPayU/v2/Order.php
OpenPayU_Order.verifyResponse
public static function verifyResponse($response, $messageName) { $data = array(); $httpStatus = $response['code']; $message = OpenPayU_Util::convertJsonToArray($response['response'], true); $data['status'] = isset($message['status']['statusCode']) ? $message['status']['statusCode'] : null; if (json_last_error() == JSON_ERROR_SYNTAX) { $data['response'] = $response['response']; } elseif (isset($message[$messageName])) { unset($message[$messageName]['Status']); $data['response'] = $message[$messageName]; } elseif (isset($message)) { $data['response'] = $message; unset($message['status']); } $result = self::build($data); if ($httpStatus == 200 || $httpStatus == 201 || $httpStatus == 422 || $httpStatus == 301 || $httpStatus == 302) { return $result; } OpenPayU_Http::throwHttpStatusException($httpStatus, $result); }
php
public static function verifyResponse($response, $messageName) { $data = array(); $httpStatus = $response['code']; $message = OpenPayU_Util::convertJsonToArray($response['response'], true); $data['status'] = isset($message['status']['statusCode']) ? $message['status']['statusCode'] : null; if (json_last_error() == JSON_ERROR_SYNTAX) { $data['response'] = $response['response']; } elseif (isset($message[$messageName])) { unset($message[$messageName]['Status']); $data['response'] = $message[$messageName]; } elseif (isset($message)) { $data['response'] = $message; unset($message['status']); } $result = self::build($data); if ($httpStatus == 200 || $httpStatus == 201 || $httpStatus == 422 || $httpStatus == 301 || $httpStatus == 302) { return $result; } OpenPayU_Http::throwHttpStatusException($httpStatus, $result); }
[ "public", "static", "function", "verifyResponse", "(", "$", "response", ",", "$", "messageName", ")", "{", "$", "data", "=", "array", "(", ")", ";", "$", "httpStatus", "=", "$", "response", "[", "'code'", "]", ";", "$", "message", "=", "OpenPayU_Util", ...
Verify response from PayU @param string $response @param string $messageName @return null|OpenPayU_Result @throws OpenPayU_Exception @throws OpenPayU_Exception_Authorization @throws OpenPayU_Exception_Network @throws OpenPayU_Exception_ServerError @throws OpenPayU_Exception_ServerMaintenance
[ "Verify", "response", "from", "PayU" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Order.php#L204-L230
PayU/openpayu_php
lib/OpenPayU/v2/Order.php
OpenPayU_Order.hostedOrderForm
public static function hostedOrderForm($order, $params = array()) { $orderFormUrl = OpenPayU_Configuration::getServiceUrl() . 'orders'; $formFieldValuesAsArray = array(); $htmlFormFields = OpenPayU_Util::convertArrayToHtmlForm($order, '', $formFieldValuesAsArray); $signature = OpenPayU_Util::generateSignData( $formFieldValuesAsArray, OpenPayU_Configuration::getHashAlgorithm(), OpenPayU_Configuration::getMerchantPosId(), OpenPayU_Configuration::getSignatureKey() ); $formParams = array_merge(self::$defaultFormParams, $params); $htmlOutput = sprintf("<form method=\"POST\" action=\"%s\" id=\"%s\" class=\"%s\">\n", $orderFormUrl, $formParams['formId'], $formParams['formClass']); $htmlOutput .= $htmlFormFields; $htmlOutput .= sprintf("<input type=\"hidden\" name=\"OpenPayu-Signature\" value=\"%s\" />", $signature); $htmlOutput .= sprintf("<button type=\"submit\" formtarget=\"%s\" id=\"%s\" class=\"%s\">%s</button>", $formParams['submitTarget'], $formParams['submitId'], $formParams['submitClass'], $formParams['submitContent']); $htmlOutput .= "</form>\n"; return $htmlOutput; }
php
public static function hostedOrderForm($order, $params = array()) { $orderFormUrl = OpenPayU_Configuration::getServiceUrl() . 'orders'; $formFieldValuesAsArray = array(); $htmlFormFields = OpenPayU_Util::convertArrayToHtmlForm($order, '', $formFieldValuesAsArray); $signature = OpenPayU_Util::generateSignData( $formFieldValuesAsArray, OpenPayU_Configuration::getHashAlgorithm(), OpenPayU_Configuration::getMerchantPosId(), OpenPayU_Configuration::getSignatureKey() ); $formParams = array_merge(self::$defaultFormParams, $params); $htmlOutput = sprintf("<form method=\"POST\" action=\"%s\" id=\"%s\" class=\"%s\">\n", $orderFormUrl, $formParams['formId'], $formParams['formClass']); $htmlOutput .= $htmlFormFields; $htmlOutput .= sprintf("<input type=\"hidden\" name=\"OpenPayu-Signature\" value=\"%s\" />", $signature); $htmlOutput .= sprintf("<button type=\"submit\" formtarget=\"%s\" id=\"%s\" class=\"%s\">%s</button>", $formParams['submitTarget'], $formParams['submitId'], $formParams['submitClass'], $formParams['submitContent']); $htmlOutput .= "</form>\n"; return $htmlOutput; }
[ "public", "static", "function", "hostedOrderForm", "(", "$", "order", ",", "$", "params", "=", "array", "(", ")", ")", "{", "$", "orderFormUrl", "=", "OpenPayU_Configuration", "::", "getServiceUrl", "(", ")", ".", "'orders'", ";", "$", "formFieldValuesAsArray"...
Generate a form body for hosted order @access public @param array $order an array containing full Order @param array $params an optional array with form elements' params @return string Response html form @throws OpenPayU_Exception_Configuration
[ "Generate", "a", "form", "body", "for", "hosted", "order" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Order.php#L241-L264
PayU/openpayu_php
lib/OpenPayU/v2/Refund.php
OpenPayU_Refund.create
public static function create($orderId, $description, $amount = null, $extCustomerId = null, $extRefundId = null) { if (empty($orderId)) { throw new OpenPayU_Exception('Invalid orderId value for refund'); } if (empty($description)) { throw new OpenPayU_Exception('Invalid description of refund'); } $refund = array( 'orderId' => $orderId, 'refund' => array('description' => $description) ); if (!empty($amount)) { $refund['refund']['amount'] = (int) $amount; } if (!empty($extCustomerId)) { $refund['refund']['extCustomerId'] = $extCustomerId; } if (!empty($extRefundId)) { $refund['refund']['extRefundId'] = $extRefundId; } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $pathUrl = OpenPayU_Configuration::getServiceUrl().'orders/'. $refund['orderId'] . '/refund'; $data = OpenPayU_Util::buildJsonFromArray($refund); $result = self::verifyResponse(OpenPayU_Http::doPost($pathUrl, $data, $authType), 'RefundCreateResponse'); return $result; }
php
public static function create($orderId, $description, $amount = null, $extCustomerId = null, $extRefundId = null) { if (empty($orderId)) { throw new OpenPayU_Exception('Invalid orderId value for refund'); } if (empty($description)) { throw new OpenPayU_Exception('Invalid description of refund'); } $refund = array( 'orderId' => $orderId, 'refund' => array('description' => $description) ); if (!empty($amount)) { $refund['refund']['amount'] = (int) $amount; } if (!empty($extCustomerId)) { $refund['refund']['extCustomerId'] = $extCustomerId; } if (!empty($extRefundId)) { $refund['refund']['extRefundId'] = $extRefundId; } try { $authType = self::getAuth(); } catch (OpenPayU_Exception $e) { throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); } $pathUrl = OpenPayU_Configuration::getServiceUrl().'orders/'. $refund['orderId'] . '/refund'; $data = OpenPayU_Util::buildJsonFromArray($refund); $result = self::verifyResponse(OpenPayU_Http::doPost($pathUrl, $data, $authType), 'RefundCreateResponse'); return $result; }
[ "public", "static", "function", "create", "(", "$", "orderId", ",", "$", "description", ",", "$", "amount", "=", "null", ",", "$", "extCustomerId", "=", "null", ",", "$", "extRefundId", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "orderId", ...
Function make refund for order @param $orderId @param $description @param null|int $amount Amount of refund in pennies @param null|string $extCustomerId Marketplace external customer ID @param null|string $extRefundId Marketplace external refund ID @return null|OpenPayU_Result @throws OpenPayU_Exception
[ "Function", "make", "refund", "for", "order" ]
train
https://github.com/PayU/openpayu_php/blob/2138d174c653b2926d68217fadbae605b8ec3ae2/lib/OpenPayU/v2/Refund.php#L24-L63
rmariuzzo/Laravel-JS-Localization
src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php
LangJsCommand.handle
public function handle() { $target = $this->argument('target'); $options = [ 'compress' => $this->option('compress'), 'json' => $this->option('json'), 'no-lib' => $this->option('no-lib'), 'source' => $this->option('source'), ]; if ($this->generator->generate($target, $options)) { $this->info("Created: {$target}"); return; } $this->error("Could not create: {$target}"); }
php
public function handle() { $target = $this->argument('target'); $options = [ 'compress' => $this->option('compress'), 'json' => $this->option('json'), 'no-lib' => $this->option('no-lib'), 'source' => $this->option('source'), ]; if ($this->generator->generate($target, $options)) { $this->info("Created: {$target}"); return; } $this->error("Could not create: {$target}"); }
[ "public", "function", "handle", "(", ")", "{", "$", "target", "=", "$", "this", "->", "argument", "(", "'target'", ")", ";", "$", "options", "=", "[", "'compress'", "=>", "$", "this", "->", "option", "(", "'compress'", ")", ",", "'json'", "=>", "$", ...
Handle the command.
[ "Handle", "the", "command", "." ]
train
https://github.com/rmariuzzo/Laravel-JS-Localization/blob/1ad478d7aabeafe76c0c52b16762d2852f0a430e/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php#L61-L78
rmariuzzo/Laravel-JS-Localization
src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php
LangJsGenerator.generate
public function generate($target, $options) { if ($options['source']) { $this->sourcePath = $options['source']; } $messages = $this->getMessages(); $this->prepareTarget($target); if ($options['no-lib']) { $template = $this->file->get(__DIR__.'/Templates/messages.js'); } else if ($options['json']) { $template = $this->file->get(__DIR__.'/Templates/messages.json'); } else { $template = $this->file->get(__DIR__.'/Templates/langjs_with_messages.js'); $langjs = $this->file->get(__DIR__.'/../../../../lib/lang.min.js'); $template = str_replace('\'{ langjs }\';', $langjs, $template); } $template = str_replace('\'{ messages }\'', json_encode($messages), $template); if ($options['compress']) { $template = Minifier::minify($template); } return $this->file->put($target, $template); }
php
public function generate($target, $options) { if ($options['source']) { $this->sourcePath = $options['source']; } $messages = $this->getMessages(); $this->prepareTarget($target); if ($options['no-lib']) { $template = $this->file->get(__DIR__.'/Templates/messages.js'); } else if ($options['json']) { $template = $this->file->get(__DIR__.'/Templates/messages.json'); } else { $template = $this->file->get(__DIR__.'/Templates/langjs_with_messages.js'); $langjs = $this->file->get(__DIR__.'/../../../../lib/lang.min.js'); $template = str_replace('\'{ langjs }\';', $langjs, $template); } $template = str_replace('\'{ messages }\'', json_encode($messages), $template); if ($options['compress']) { $template = Minifier::minify($template); } return $this->file->put($target, $template); }
[ "public", "function", "generate", "(", "$", "target", ",", "$", "options", ")", "{", "if", "(", "$", "options", "[", "'source'", "]", ")", "{", "$", "this", "->", "sourcePath", "=", "$", "options", "[", "'source'", "]", ";", "}", "$", "messages", "...
Generate a JS lang file from all language files. @param string $target The target directory. @param array $options Array of options. @return int
[ "Generate", "a", "JS", "lang", "file", "from", "all", "language", "files", "." ]
train
https://github.com/rmariuzzo/Laravel-JS-Localization/blob/1ad478d7aabeafe76c0c52b16762d2852f0a430e/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php#L65-L91
rmariuzzo/Laravel-JS-Localization
src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php
LangJsGenerator.sortMessages
protected function sortMessages(&$messages) { if (is_array($messages)) { ksort($messages); foreach ($messages as $key => &$value) { $this->sortMessages($value); } } }
php
protected function sortMessages(&$messages) { if (is_array($messages)) { ksort($messages); foreach ($messages as $key => &$value) { $this->sortMessages($value); } } }
[ "protected", "function", "sortMessages", "(", "&", "$", "messages", ")", "{", "if", "(", "is_array", "(", "$", "messages", ")", ")", "{", "ksort", "(", "$", "messages", ")", ";", "foreach", "(", "$", "messages", "as", "$", "key", "=>", "&", "$", "v...
Recursively sorts all messages by key. @param array $messages The messages to sort by key.
[ "Recursively", "sorts", "all", "messages", "by", "key", "." ]
train
https://github.com/rmariuzzo/Laravel-JS-Localization/blob/1ad478d7aabeafe76c0c52b16762d2852f0a430e/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php#L98-L107
rmariuzzo/Laravel-JS-Localization
src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php
LangJsGenerator.getMessages
protected function getMessages() { $messages = []; $path = $this->sourcePath; if (!$this->file->exists($path)) { throw new \Exception("${path} doesn't exists!"); } foreach ($this->file->allFiles($path) as $file) { $pathName = $file->getRelativePathName(); $extension = $this->file->extension($pathName); if ($extension != 'php' && $extension != 'json') { continue; } if ($this->isMessagesExcluded($pathName)) { continue; } $key = substr($pathName, 0, -4); $key = str_replace('\\', '.', $key); $key = str_replace('/', '.', $key); if (starts_with($key, 'vendor')) { $key = $this->getVendorKey($key); } $fullPath = $path.DIRECTORY_SEPARATOR.$pathName; if ($extension == 'php') { $messages[$key] = include $fullPath; } else { $key = $key.$this->stringsDomain; $fileContent = file_get_contents($fullPath); $messages[$key] = json_decode($fileContent, true); } } $this->sortMessages($messages); return $messages; }
php
protected function getMessages() { $messages = []; $path = $this->sourcePath; if (!$this->file->exists($path)) { throw new \Exception("${path} doesn't exists!"); } foreach ($this->file->allFiles($path) as $file) { $pathName = $file->getRelativePathName(); $extension = $this->file->extension($pathName); if ($extension != 'php' && $extension != 'json') { continue; } if ($this->isMessagesExcluded($pathName)) { continue; } $key = substr($pathName, 0, -4); $key = str_replace('\\', '.', $key); $key = str_replace('/', '.', $key); if (starts_with($key, 'vendor')) { $key = $this->getVendorKey($key); } $fullPath = $path.DIRECTORY_SEPARATOR.$pathName; if ($extension == 'php') { $messages[$key] = include $fullPath; } else { $key = $key.$this->stringsDomain; $fileContent = file_get_contents($fullPath); $messages[$key] = json_decode($fileContent, true); } } $this->sortMessages($messages); return $messages; }
[ "protected", "function", "getMessages", "(", ")", "{", "$", "messages", "=", "[", "]", ";", "$", "path", "=", "$", "this", "->", "sourcePath", ";", "if", "(", "!", "$", "this", "->", "file", "->", "exists", "(", "$", "path", ")", ")", "{", "throw...
Return all language messages. @return array @throws \Exception
[ "Return", "all", "language", "messages", "." ]
train
https://github.com/rmariuzzo/Laravel-JS-Localization/blob/1ad478d7aabeafe76c0c52b16762d2852f0a430e/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php#L116-L157
rmariuzzo/Laravel-JS-Localization
src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php
LangJsGenerator.isMessagesExcluded
protected function isMessagesExcluded($filePath) { if (empty($this->messagesIncluded)) { return false; } $filePath = str_replace(DIRECTORY_SEPARATOR, '/', $filePath); $localeDirSeparatorPosition = strpos($filePath, '/'); $filePath = substr($filePath, $localeDirSeparatorPosition); $filePath = ltrim($filePath, '/'); $filePath = substr($filePath, 0, -4); if (in_array($filePath, $this->messagesIncluded)) { return false; } return true; }
php
protected function isMessagesExcluded($filePath) { if (empty($this->messagesIncluded)) { return false; } $filePath = str_replace(DIRECTORY_SEPARATOR, '/', $filePath); $localeDirSeparatorPosition = strpos($filePath, '/'); $filePath = substr($filePath, $localeDirSeparatorPosition); $filePath = ltrim($filePath, '/'); $filePath = substr($filePath, 0, -4); if (in_array($filePath, $this->messagesIncluded)) { return false; } return true; }
[ "protected", "function", "isMessagesExcluded", "(", "$", "filePath", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "messagesIncluded", ")", ")", "{", "return", "false", ";", "}", "$", "filePath", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", ...
If messages should be excluded from build. @param string $filePath @return bool
[ "If", "messages", "should", "be", "excluded", "from", "build", "." ]
train
https://github.com/rmariuzzo/Laravel-JS-Localization/blob/1ad478d7aabeafe76c0c52b16762d2852f0a430e/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php#L180-L198
rmariuzzo/Laravel-JS-Localization
src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php
LaravelJsLocalizationServiceProvider.boot
public function boot() { $configPath = __DIR__.'/../../config/config.php'; $configKey = 'localization-js'; // Determines Laravel major version. $app = $this->app; $laravelMajorVersion = (int) $app::VERSION; // Publishes Laravel-JS-Localization package files and merge user and // package configurations. if ($laravelMajorVersion === 4) { $config = $this->app['config']->get($configKey, []); $this->app['config']->set($configKey, array_merge(require $configPath, $config)); } elseif ($laravelMajorVersion === 5) { $this->publishes([ $configPath => config_path("$configKey.php"), ]); $this->mergeConfigFrom( $configPath, $configKey ); } }
php
public function boot() { $configPath = __DIR__.'/../../config/config.php'; $configKey = 'localization-js'; // Determines Laravel major version. $app = $this->app; $laravelMajorVersion = (int) $app::VERSION; // Publishes Laravel-JS-Localization package files and merge user and // package configurations. if ($laravelMajorVersion === 4) { $config = $this->app['config']->get($configKey, []); $this->app['config']->set($configKey, array_merge(require $configPath, $config)); } elseif ($laravelMajorVersion === 5) { $this->publishes([ $configPath => config_path("$configKey.php"), ]); $this->mergeConfigFrom( $configPath, $configKey ); } }
[ "public", "function", "boot", "(", ")", "{", "$", "configPath", "=", "__DIR__", ".", "'/../../config/config.php'", ";", "$", "configKey", "=", "'localization-js'", ";", "// Determines Laravel major version.", "$", "app", "=", "$", "this", "->", "app", ";", "$", ...
Bootstrap the application events.
[ "Bootstrap", "the", "application", "events", "." ]
train
https://github.com/rmariuzzo/Laravel-JS-Localization/blob/1ad478d7aabeafe76c0c52b16762d2852f0a430e/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php#L37-L59
rmariuzzo/Laravel-JS-Localization
src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php
LaravelJsLocalizationServiceProvider.register
public function register() { // Bind the Laravel JS Localization command into the app IOC. $this->app->singleton('localization.js', function ($app) { $app = $this->app; $laravelMajorVersion = (int) $app::VERSION; $files = $app['files']; if ($laravelMajorVersion === 4) { $langs = $app['path.base'].'/app/lang'; } elseif ($laravelMajorVersion === 5) { $langs = $app['path.base'].'/resources/lang'; } $messages = $app['config']->get('localization-js.messages'); $generator = new Generators\LangJsGenerator($files, $langs, $messages); return new Commands\LangJsCommand($generator); }); // Bind the Laravel JS Localization command into Laravel Artisan. $this->commands('localization.js'); }
php
public function register() { // Bind the Laravel JS Localization command into the app IOC. $this->app->singleton('localization.js', function ($app) { $app = $this->app; $laravelMajorVersion = (int) $app::VERSION; $files = $app['files']; if ($laravelMajorVersion === 4) { $langs = $app['path.base'].'/app/lang'; } elseif ($laravelMajorVersion === 5) { $langs = $app['path.base'].'/resources/lang'; } $messages = $app['config']->get('localization-js.messages'); $generator = new Generators\LangJsGenerator($files, $langs, $messages); return new Commands\LangJsCommand($generator); }); // Bind the Laravel JS Localization command into Laravel Artisan. $this->commands('localization.js'); }
[ "public", "function", "register", "(", ")", "{", "// Bind the Laravel JS Localization command into the app IOC.", "$", "this", "->", "app", "->", "singleton", "(", "'localization.js'", ",", "function", "(", "$", "app", ")", "{", "$", "app", "=", "$", "this", "->...
Register the service provider.
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/rmariuzzo/Laravel-JS-Localization/blob/1ad478d7aabeafe76c0c52b16762d2852f0a430e/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php#L64-L86
jippi/vault-php-sdk
examples/task.php
VaultTask.factory
public function factory() { if (!$this->factory) { $options = []; $options['headers']['X-Vault-Token'] = $this->getVaultToken(); $this->factory = new VaultFactory($options); } return $this->factory; }
php
public function factory() { if (!$this->factory) { $options = []; $options['headers']['X-Vault-Token'] = $this->getVaultToken(); $this->factory = new VaultFactory($options); } return $this->factory; }
[ "public", "function", "factory", "(", ")", "{", "if", "(", "!", "$", "this", "->", "factory", ")", "{", "$", "options", "=", "[", "]", ";", "$", "options", "[", "'headers'", "]", "[", "'X-Vault-Token'", "]", "=", "$", "this", "->", "getVaultToken", ...
Get the Vault Service Factory If the ~/.bownty_vault_keys file exist, the X-Vault-Token header will automatically be sent in all requests @return Jippi\Vault\ServiceFactory
[ "Get", "the", "Vault", "Service", "Factory" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/task.php#L49-L58
jippi/vault-php-sdk
examples/task.php
VaultTask.waitFor
public function waitFor(array $pairs = []) { $allowedPairs = ['initialized' => null, 'sealed' => null, 'standby' => null]; $pairs = array_intersect_key($pairs, $allowedPairs); $this->out('Waiting for health returning ' . json_encode($pairs) . ': ', 0); $count = 0; while (true) { try { $res = $this->sys()->health(['standbyok' => 1, 'standbycode' => 200, 'sealedcode' => 200])->json(); $this->info('.', 0); } catch (ServerException $e) { $res = $e->response()->json(); $this->err('.', 0); } if (!array_diff_assoc($pairs, $res)) { $this->success(' Done!'); return true; } $count++; if ($count > 120) { $this->err(' Failed after 120 attempts...'); return false; } sleep(1); } }
php
public function waitFor(array $pairs = []) { $allowedPairs = ['initialized' => null, 'sealed' => null, 'standby' => null]; $pairs = array_intersect_key($pairs, $allowedPairs); $this->out('Waiting for health returning ' . json_encode($pairs) . ': ', 0); $count = 0; while (true) { try { $res = $this->sys()->health(['standbyok' => 1, 'standbycode' => 200, 'sealedcode' => 200])->json(); $this->info('.', 0); } catch (ServerException $e) { $res = $e->response()->json(); $this->err('.', 0); } if (!array_diff_assoc($pairs, $res)) { $this->success(' Done!'); return true; } $count++; if ($count > 120) { $this->err(' Failed after 120 attempts...'); return false; } sleep(1); } }
[ "public", "function", "waitFor", "(", "array", "$", "pairs", "=", "[", "]", ")", "{", "$", "allowedPairs", "=", "[", "'initialized'", "=>", "null", ",", "'sealed'", "=>", "null", ",", "'standby'", "=>", "null", "]", ";", "$", "pairs", "=", "array_inter...
Wait for Vault health to return the key/value $pairs specified @see https://www.vaultproject.io/docs/http/sys-health.html @param array $pairs Key/Value to expect health to return @param array $arguments Additional arguments for health endpoint @return boolean
[ "Wait", "for", "Vault", "health", "to", "return", "the", "key", "/", "value", "$pairs", "specified" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/task.php#L87-L117
jippi/vault-php-sdk
examples/task.php
VaultTask.unseal
public function unseal() { $file = $this->getVaultKeyFile(); if (!file_exists($file)) { return $this->abort($file . ' does not exist - call "create" first'); } $sysService = $this->sys(); $sealed = $sysService->sealed(); if (!$sealed) { return $this->success('Vault is unsealed'); } $content = json_decode(file_get_contents($file), true); while ($sysService->sealed()) { $this->info('Unsealing with key ...'); $sysService->unseal(['key' => array_pop($content['keys'])]); } $this->success('Vault has been unsealed successfully'); }
php
public function unseal() { $file = $this->getVaultKeyFile(); if (!file_exists($file)) { return $this->abort($file . ' does not exist - call "create" first'); } $sysService = $this->sys(); $sealed = $sysService->sealed(); if (!$sealed) { return $this->success('Vault is unsealed'); } $content = json_decode(file_get_contents($file), true); while ($sysService->sealed()) { $this->info('Unsealing with key ...'); $sysService->unseal(['key' => array_pop($content['keys'])]); } $this->success('Vault has been unsealed successfully'); }
[ "public", "function", "unseal", "(", ")", "{", "$", "file", "=", "$", "this", "->", "getVaultKeyFile", "(", ")", ";", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "return", "$", "this", "->", "abort", "(", "$", "file", ".", "' ...
Unseal the vault using the keys provided @return void
[ "Unseal", "the", "vault", "using", "the", "keys", "provided" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/task.php#L124-L147
jippi/vault-php-sdk
src/Services/Auth/AppRole.php
AppRole.login
public function login(string $roleId, string $secretId) { $body = ['role_id' => $roleId, 'secret_id' => $secretId]; $params = [ 'body' => json_encode($body) ]; return \GuzzleHttp\json_decode($this->client->post('/v1/auth/approle/login', $params)->getBody()); }
php
public function login(string $roleId, string $secretId) { $body = ['role_id' => $roleId, 'secret_id' => $secretId]; $params = [ 'body' => json_encode($body) ]; return \GuzzleHttp\json_decode($this->client->post('/v1/auth/approle/login', $params)->getBody()); }
[ "public", "function", "login", "(", "string", "$", "roleId", ",", "string", "$", "secretId", ")", "{", "$", "body", "=", "[", "'role_id'", "=>", "$", "roleId", ",", "'secret_id'", "=>", "$", "secretId", "]", ";", "$", "params", "=", "[", "'body'", "=...
Issues a Vault token based on the presented credentials. @param string $roleId The role_id in Vault @param string $secretId The secret_id in Vault @return mixed
[ "Issues", "a", "Vault", "token", "based", "on", "the", "presented", "credentials", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Auth/AppRole.php#L35-L42
jippi/vault-php-sdk
src/Services/Sys.php
Sys.init
public function init(array $body = []) { $body = OptionsResolver::resolve($body, ['secret_shares', 'secret_threshold', 'pgp_keys']); $body = OptionsResolver::required($body, ['secret_shares', 'secret_threshold']); $params = [ 'body' => json_encode($body) ]; return $this->client->put('/v1/sys/init', $params); }
php
public function init(array $body = []) { $body = OptionsResolver::resolve($body, ['secret_shares', 'secret_threshold', 'pgp_keys']); $body = OptionsResolver::required($body, ['secret_shares', 'secret_threshold']); $params = [ 'body' => json_encode($body) ]; return $this->client->put('/v1/sys/init', $params); }
[ "public", "function", "init", "(", "array", "$", "body", "=", "[", "]", ")", "{", "$", "body", "=", "OptionsResolver", "::", "resolve", "(", "$", "body", ",", "[", "'secret_shares'", ",", "'secret_threshold'", ",", "'pgp_keys'", "]", ")", ";", "$", "bo...
Initializes a new Vault. The Vault must've not been previously initialized @see https://www.vaultproject.io/docs/http/sys-init.html @return mixed
[ "Initializes", "a", "new", "Vault", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L49-L59
jippi/vault-php-sdk
src/Services/Sys.php
Sys.unseal
public function unseal(array $body = []) { $body = OptionsResolver::resolve($body, ['key', 'reset']); $params = [ 'body' => json_encode($body) ]; return $this->client->put('/v1/sys/unseal', $params); }
php
public function unseal(array $body = []) { $body = OptionsResolver::resolve($body, ['key', 'reset']); $params = [ 'body' => json_encode($body) ]; return $this->client->put('/v1/sys/unseal', $params); }
[ "public", "function", "unseal", "(", "array", "$", "body", "=", "[", "]", ")", "{", "$", "body", "=", "OptionsResolver", "::", "resolve", "(", "$", "body", ",", "[", "'key'", ",", "'reset'", "]", ")", ";", "$", "params", "=", "[", "'body'", "=>", ...
Enter a single master key share to progress the unsealing of the Vault. If the threshold number of master key shares is reached, Vault will attempt to unseal the Vault. Otherwise, this API must be called multiple times until that threshold is met. Either the key or reset parameter must be provided; if both are provided, reset takes precedence. @see https://www.vaultproject.io/docs/http/sys-unseal.html @param array $body @return mixed
[ "Enter", "a", "single", "master", "key", "share", "to", "progress", "the", "unsealing", "of", "the", "Vault", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L124-L133
jippi/vault-php-sdk
src/Services/Sys.php
Sys.createMount
public function createMount($name, array $body) { $body = OptionsResolver::resolve($body, ['type', 'description', 'config']); $params = [ 'body' => json_encode($body) ]; return $this->client->post('/v1/sys/mounts/' . $name, $params); }
php
public function createMount($name, array $body) { $body = OptionsResolver::resolve($body, ['type', 'description', 'config']); $params = [ 'body' => json_encode($body) ]; return $this->client->post('/v1/sys/mounts/' . $name, $params); }
[ "public", "function", "createMount", "(", "$", "name", ",", "array", "$", "body", ")", "{", "$", "body", "=", "OptionsResolver", "::", "resolve", "(", "$", "body", ",", "[", "'type'", ",", "'description'", ",", "'config'", "]", ")", ";", "$", "params",...
Mount a new secret backend to the mount point in the URL. @param string $name @param array $body @return mixed
[ "Mount", "a", "new", "secret", "backend", "to", "the", "mount", "point", "in", "the", "URL", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L155-L164
jippi/vault-php-sdk
src/Services/Sys.php
Sys.remount
public function remount($from, $to) { $body = compact('from', 'to'); $params = [ 'body' => json_encode($body) ]; return $this->client->post('/v1/sys/remount', $params); }
php
public function remount($from, $to) { $body = compact('from', 'to'); $params = [ 'body' => json_encode($body) ]; return $this->client->post('/v1/sys/remount', $params); }
[ "public", "function", "remount", "(", "$", "from", ",", "$", "to", ")", "{", "$", "body", "=", "compact", "(", "'from'", ",", "'to'", ")", ";", "$", "params", "=", "[", "'body'", "=>", "json_encode", "(", "$", "body", ")", "]", ";", "return", "$"...
Remount an already-mounted backend to a new mount point. @see https://www.vaultproject.io/docs/http/sys-remount.html @param string $from @param string $to @return mixed
[ "Remount", "an", "already", "-", "mounted", "backend", "to", "a", "new", "mount", "point", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L186-L195
jippi/vault-php-sdk
src/Services/Sys.php
Sys.tuneMount
public function tuneMount($name, array $body = []) { if (empty($body)) { return $this->client->get('/v1/sys/mounts/' . $name . '/tune'); } $params = [ 'body' => json_encode(OptionsResolver::resolve($body, ['default_lease_ttl', 'max_lease_ttl'])) ]; return $this->client->post('/v1/sys/mounts/' . $name . '/tune', $params); }
php
public function tuneMount($name, array $body = []) { if (empty($body)) { return $this->client->get('/v1/sys/mounts/' . $name . '/tune'); } $params = [ 'body' => json_encode(OptionsResolver::resolve($body, ['default_lease_ttl', 'max_lease_ttl'])) ]; return $this->client->post('/v1/sys/mounts/' . $name . '/tune', $params); }
[ "public", "function", "tuneMount", "(", "$", "name", ",", "array", "$", "body", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "body", ")", ")", "{", "return", "$", "this", "->", "client", "->", "get", "(", "'/v1/sys/mounts/'", ".", "$", ...
List or change the given mount's configuration. if `$body` is not empty, a POST to update a mount tune is assumed. Unlike the mounts endpoint, this will return the current time in seconds for each TTL, which may be the system default or a mount-specific value. @param string $name @param array $body @return mixed
[ "List", "or", "change", "the", "given", "mount", "s", "configuration", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L209-L220
jippi/vault-php-sdk
src/Services/Sys.php
Sys.putPolicy
public function putPolicy($name, array $body) { $body = OptionsResolver::resolve($body, ['policy']); $params = [ 'body' => json_encode($body) ]; return $this->client->put('/v1/sys/policy/' . $name, $params); }
php
public function putPolicy($name, array $body) { $body = OptionsResolver::resolve($body, ['policy']); $params = [ 'body' => json_encode($body) ]; return $this->client->put('/v1/sys/policy/' . $name, $params); }
[ "public", "function", "putPolicy", "(", "$", "name", ",", "array", "$", "body", ")", "{", "$", "body", "=", "OptionsResolver", "::", "resolve", "(", "$", "body", ",", "[", "'policy'", "]", ")", ";", "$", "params", "=", "[", "'body'", "=>", "json_enco...
Add or update a policy. Once a policy is updated, it takes effect immediately to all associated users. @see https://www.vaultproject.io/docs/http/sys-policy.html @param string $name @param array $body @return mixed
[ "Add", "or", "update", "a", "policy", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L255-L264
jippi/vault-php-sdk
src/Services/Sys.php
Sys.capabilities
public function capabilities($path, $token = null) { $params = [ 'body' => json_encode(array_filter(compact('token', 'path'))) ]; if (empty($token)) { return $this->client->post('/v1/sys/capabilities-self', $params); } return $this->client->post('/v1/sys/capabilities', $params); }
php
public function capabilities($path, $token = null) { $params = [ 'body' => json_encode(array_filter(compact('token', 'path'))) ]; if (empty($token)) { return $this->client->post('/v1/sys/capabilities-self', $params); } return $this->client->post('/v1/sys/capabilities', $params); }
[ "public", "function", "capabilities", "(", "$", "path", ",", "$", "token", "=", "null", ")", "{", "$", "params", "=", "[", "'body'", "=>", "json_encode", "(", "array_filter", "(", "compact", "(", "'token'", ",", "'path'", ")", ")", ")", "]", ";", "if...
Returns the capabilities of the token on the given path. If token is empty, 'capabilities-self' is assumed @see https://www.vaultproject.io/docs/http/sys-capabilities.html @see https://www.vaultproject.io/docs/http/sys-capabilities-self.html @param string $path @param string|null $token @return mixed
[ "Returns", "the", "capabilities", "of", "the", "token", "on", "the", "given", "path", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L291-L302
jippi/vault-php-sdk
src/Services/Sys.php
Sys.renew
public function renew($leaseId, $increment = null) { $params = [ 'body' => json_encode(array_filter(compact('increment'))) ]; return $this->client->put('/v1/sys/renew/' . $leaseId, $params); }
php
public function renew($leaseId, $increment = null) { $params = [ 'body' => json_encode(array_filter(compact('increment'))) ]; return $this->client->put('/v1/sys/renew/' . $leaseId, $params); }
[ "public", "function", "renew", "(", "$", "leaseId", ",", "$", "increment", "=", "null", ")", "{", "$", "params", "=", "[", "'body'", "=>", "json_encode", "(", "array_filter", "(", "compact", "(", "'increment'", ")", ")", ")", "]", ";", "return", "$", ...
Renew a secret, requesting to extend the lease @see https://www.vaultproject.io/docs/http/sys-renew.html @param string $leaseId @param string|null $increment @return mixed
[ "Renew", "a", "secret", "requesting", "to", "extend", "the", "lease" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L312-L319
jippi/vault-php-sdk
src/Services/Sys.php
Sys.raw
public function raw($path, $value = null) { if ($value === null) { return $this->client->get('/v1/sys/raw/' . $path); } $params = [ 'body' => json_encode(compact('value')) ]; return $this->client->put('/v1/sys/raw/' . $path, $params); }
php
public function raw($path, $value = null) { if ($value === null) { return $this->client->get('/v1/sys/raw/' . $path); } $params = [ 'body' => json_encode(compact('value')) ]; return $this->client->put('/v1/sys/raw/' . $path, $params); }
[ "public", "function", "raw", "(", "$", "path", ",", "$", "value", "=", "null", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "$", "this", "->", "client", "->", "get", "(", "'/v1/sys/raw/'", ".", "$", "path", ")", ";", "}",...
Reads the value of the key at the given path. This is the raw path in the storage backend and not the logical path that is exposed via the mount system. If `$value` is empty, GET is assumed - otherwise PUT. @see https://www.vaultproject.io/docs/http/sys-raw.html @param string $path @param string|null $value @return mixed
[ "Reads", "the", "value", "of", "the", "key", "at", "the", "given", "path", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Sys.php#L436-L447
jippi/vault-php-sdk
src/Services/Auth/Token.php
Token.create
public function create(array $body = []) { $body = OptionsResolver::resolve($body, [ 'id', 'policies', 'meta', 'no_parent', 'no_default_policy', 'renewable', 'ttl', 'explicit_max_ttl', 'display_name', 'num_uses' ]); $params = [ 'body' => json_encode($body) ]; return $this->client->post('/v1/auth/token/create', $params)->json(); }
php
public function create(array $body = []) { $body = OptionsResolver::resolve($body, [ 'id', 'policies', 'meta', 'no_parent', 'no_default_policy', 'renewable', 'ttl', 'explicit_max_ttl', 'display_name', 'num_uses' ]); $params = [ 'body' => json_encode($body) ]; return $this->client->post('/v1/auth/token/create', $params)->json(); }
[ "public", "function", "create", "(", "array", "$", "body", "=", "[", "]", ")", "{", "$", "body", "=", "OptionsResolver", "::", "resolve", "(", "$", "body", ",", "[", "'id'", ",", "'policies'", ",", "'meta'", ",", "'no_parent'", ",", "'no_default_policy'"...
Creates a new token. Certain options are only available when called by a root token. If used via the /auth/token/create-orphan endpoint, a root token is not required to create an orphan token (otherwise set with the no_parent option). If used with a role name in the path, the token will be created against the specified role name; this may override options set during this call. @see https://www.vaultproject.io/docs/auth/token.html @param array $body @return mixed
[ "Creates", "a", "new", "token", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Auth/Token.php#L43-L55
jippi/vault-php-sdk
src/Services/Auth/Token.php
Token.renewSelf
public function renewSelf(array $body = []) { $body = OptionsResolver::resolve($body, ['increment']); $params = ['body' => json_encode($body)]; return $this->client->post('/v1/auth/token/renew-self', $params); }
php
public function renewSelf(array $body = []) { $body = OptionsResolver::resolve($body, ['increment']); $params = ['body' => json_encode($body)]; return $this->client->post('/v1/auth/token/renew-self', $params); }
[ "public", "function", "renewSelf", "(", "array", "$", "body", "=", "[", "]", ")", "{", "$", "body", "=", "OptionsResolver", "::", "resolve", "(", "$", "body", ",", "[", "'increment'", "]", ")", ";", "$", "params", "=", "[", "'body'", "=>", "json_enco...
Renews a lease associated with the calling token. This is used to prevent the expiration of a token, and the automatic revocation of it. Token renewal is possible only if there is a lease associated with it. @see https://www.vaultproject.io/docs/auth/token.html @param array $body @return mixed
[ "Renews", "a", "lease", "associated", "with", "the", "calling", "token", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Auth/Token.php#L91-L96
jippi/vault-php-sdk
src/Services/Auth/Token.php
Token.createRole
public function createRole(string $role, array $body = []) { $body = OptionsResolver::resolve($body, ['allowed_policies', 'orphan', 'period', 'renewable', 'path_suffix', 'explicit_max_ttl']); $params = ['body' => json_encode($body)]; return $this->client->post('/v1/auth/token/roles/' . $role, $params); }
php
public function createRole(string $role, array $body = []) { $body = OptionsResolver::resolve($body, ['allowed_policies', 'orphan', 'period', 'renewable', 'path_suffix', 'explicit_max_ttl']); $params = ['body' => json_encode($body)]; return $this->client->post('/v1/auth/token/roles/' . $role, $params); }
[ "public", "function", "createRole", "(", "string", "$", "role", ",", "array", "$", "body", "=", "[", "]", ")", "{", "$", "body", "=", "OptionsResolver", "::", "resolve", "(", "$", "body", ",", "[", "'allowed_policies'", ",", "'orphan'", ",", "'period'", ...
Creates (or replaces) the named role. Roles enforce specific behavior when creating tokens that allow token functionality that is otherwise not available or would require sudo/root privileges to access. Role parameters, when set, override any provided options to the create endpoints. The role name is also included in the token path, allowing all tokens created against a role to be revoked using the sys/revoke-prefix endpoint. @see https://www.vaultproject.io/docs/auth/token.html @return mixed
[ "Creates", "(", "or", "replaces", ")", "the", "named", "role", "." ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/src/Services/Auth/Token.php#L213-L218
jippi/vault-php-sdk
examples/shell.php
VaultShell.getOptionParser
public function getOptionParser() { $requireProject = [ 'arguments' => [ 'project' => ['help' => 'Project name (folder)', 'required' => true] ] ]; return parent::getOptionParser() ->addSubCommand('all', [ 'help' => 'Same as "start" + "create" + "unseal" + "mounts"' ]) ->addSubCommand('start', [ 'help' => 'Start vault' ]) ->addSubCommand('stop', [ 'help' => 'Stop vault' ]) ->addSubCommand('restart', [ 'help' => 'Stop vault' ]) ->addSubCommand('reset', [ 'help' => 'Wipe Vault and all its configuration' ]) ->addSubCommand('status', [ 'help' => 'Get the status of the Vault instance' ]) ->addSubCommand('create', [ 'help' => 'Initialize Vault and store the secrets safely' ]) ->addSubCommand('env', [ 'help' => join(PHP_EOL, [ 'Export the ENV variables for using the vault CLI tool directly.', 'Please run: eval $(sudo bownty-cli vault env)' ]) ]) ->addSubCommand('mounts', [ 'help' => 'Create the mounts required for global operation' ]) ->addSubCommand('seal', [ 'help' => 'Seal the Vault' ]) ->addSubCommand('unseal', [ 'help' => 'Unseal the Vault' ]) ->addSubCommand('sync_vault_key', [ 'help' => 'Sync the Vault key into Consul (used by consul-template)' ]) ->addSubCommand('wait_for', [ 'help' => 'Wait for something' ]); }
php
public function getOptionParser() { $requireProject = [ 'arguments' => [ 'project' => ['help' => 'Project name (folder)', 'required' => true] ] ]; return parent::getOptionParser() ->addSubCommand('all', [ 'help' => 'Same as "start" + "create" + "unseal" + "mounts"' ]) ->addSubCommand('start', [ 'help' => 'Start vault' ]) ->addSubCommand('stop', [ 'help' => 'Stop vault' ]) ->addSubCommand('restart', [ 'help' => 'Stop vault' ]) ->addSubCommand('reset', [ 'help' => 'Wipe Vault and all its configuration' ]) ->addSubCommand('status', [ 'help' => 'Get the status of the Vault instance' ]) ->addSubCommand('create', [ 'help' => 'Initialize Vault and store the secrets safely' ]) ->addSubCommand('env', [ 'help' => join(PHP_EOL, [ 'Export the ENV variables for using the vault CLI tool directly.', 'Please run: eval $(sudo bownty-cli vault env)' ]) ]) ->addSubCommand('mounts', [ 'help' => 'Create the mounts required for global operation' ]) ->addSubCommand('seal', [ 'help' => 'Seal the Vault' ]) ->addSubCommand('unseal', [ 'help' => 'Unseal the Vault' ]) ->addSubCommand('sync_vault_key', [ 'help' => 'Sync the Vault key into Consul (used by consul-template)' ]) ->addSubCommand('wait_for', [ 'help' => 'Wait for something' ]); }
[ "public", "function", "getOptionParser", "(", ")", "{", "$", "requireProject", "=", "[", "'arguments'", "=>", "[", "'project'", "=>", "[", "'help'", "=>", "'Project name (folder)'", ",", "'required'", "=>", "true", "]", "]", "]", ";", "return", "parent", "::...
Nice CLI validation and help output @return mixed
[ "Nice", "CLI", "validation", "and", "help", "output" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L25-L75
jippi/vault-php-sdk
examples/shell.php
VaultShell.all
public function all() { $this->hr(); $this->out('Ensure Vault is running'); $this->hr(); $this->start(); $this->out(''); $this->hr(); $this->out('Ensure Vault is initialized'); $this->hr(); $this->create(); $this->out(''); $this->Vault->waitFor(['initialized' => true]); $this->hr(); $this->out('Ensure Vault is unsealed'); $this->hr(); $this->unseal(); $this->out(''); $this->Vault->waitFor(['sealed' => false, 'standby' => false]); $this->Vault->clear(); $this->hr(); $this->out('Writing mount-points'); $this->hr(); $this->mounts(); $this->hr(); $this->syncVaultKey(true); }
php
public function all() { $this->hr(); $this->out('Ensure Vault is running'); $this->hr(); $this->start(); $this->out(''); $this->hr(); $this->out('Ensure Vault is initialized'); $this->hr(); $this->create(); $this->out(''); $this->Vault->waitFor(['initialized' => true]); $this->hr(); $this->out('Ensure Vault is unsealed'); $this->hr(); $this->unseal(); $this->out(''); $this->Vault->waitFor(['sealed' => false, 'standby' => false]); $this->Vault->clear(); $this->hr(); $this->out('Writing mount-points'); $this->hr(); $this->mounts(); $this->hr(); $this->syncVaultKey(true); }
[ "public", "function", "all", "(", ")", "{", "$", "this", "->", "hr", "(", ")", ";", "$", "this", "->", "out", "(", "'Ensure Vault is running'", ")", ";", "$", "this", "->", "hr", "(", ")", ";", "$", "this", "->", "start", "(", ")", ";", "$", "t...
Same as "start" + "create" + "unseal" + "mounts" @return void
[ "Same", "as", "start", "+", "create", "+", "unseal", "+", "mounts" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L82-L114
jippi/vault-php-sdk
examples/shell.php
VaultShell.reset
public function reset() { $this->Consul->ensureRunning(); $this->Vault->ensureStopped(); $this->Consul->kv()->delete('vault/', ['recurse' => true])->json(); $file = $this->Vault->getVaultKeyFile(); if (file_exists($file)) { unlink($file); } $this->Vault->ensureRunning(); }
php
public function reset() { $this->Consul->ensureRunning(); $this->Vault->ensureStopped(); $this->Consul->kv()->delete('vault/', ['recurse' => true])->json(); $file = $this->Vault->getVaultKeyFile(); if (file_exists($file)) { unlink($file); } $this->Vault->ensureRunning(); }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "Consul", "->", "ensureRunning", "(", ")", ";", "$", "this", "->", "Vault", "->", "ensureStopped", "(", ")", ";", "$", "this", "->", "Consul", "->", "kv", "(", ")", "->", "delete", "(...
Reset Vault - Stop Vault - Delete the vault/ keyprefix from Consul - Start Vault @return void
[ "Reset", "Vault" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L173-L186
jippi/vault-php-sdk
examples/shell.php
VaultShell.status
public function status() { $status = $this->Vault->sys()->status()->json(); if ($status['initialized'] !== true) { $this->warn('Vault is not initialized. Please run the "create" command'); return false; } if ($this->Vault->sys()->sealed()) { $this->warn('Vault is not unsealed. Please run the "unseal" command'); return true; } $this->success('Vault is initialized and unsealed'); return true; }
php
public function status() { $status = $this->Vault->sys()->status()->json(); if ($status['initialized'] !== true) { $this->warn('Vault is not initialized. Please run the "create" command'); return false; } if ($this->Vault->sys()->sealed()) { $this->warn('Vault is not unsealed. Please run the "unseal" command'); return true; } $this->success('Vault is initialized and unsealed'); return true; }
[ "public", "function", "status", "(", ")", "{", "$", "status", "=", "$", "this", "->", "Vault", "->", "sys", "(", ")", "->", "status", "(", ")", "->", "json", "(", ")", ";", "if", "(", "$", "status", "[", "'initialized'", "]", "!==", "true", ")", ...
Check the status of Vault @return boolean
[ "Check", "the", "status", "of", "Vault" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L193-L208
jippi/vault-php-sdk
examples/shell.php
VaultShell.create
public function create() { if ($this->status()) { $this->success('Vault already initialized'); return false; } $response = $this->Vault->sys()->init([ 'secret_shares' => 5, 'secret_threshold' => 3 ])->json(); $file = env('HOME') . '/.bownty_vault_keys'; file_put_contents($file, json_encode($response, JSON_PRETTY_PRINT)); $this->success('Vault is initialized, keys have been written to ' . $file); $this->success('Please run "unseal" to start working with Vault'); return true; }
php
public function create() { if ($this->status()) { $this->success('Vault already initialized'); return false; } $response = $this->Vault->sys()->init([ 'secret_shares' => 5, 'secret_threshold' => 3 ])->json(); $file = env('HOME') . '/.bownty_vault_keys'; file_put_contents($file, json_encode($response, JSON_PRETTY_PRINT)); $this->success('Vault is initialized, keys have been written to ' . $file); $this->success('Please run "unseal" to start working with Vault'); return true; }
[ "public", "function", "create", "(", ")", "{", "if", "(", "$", "this", "->", "status", "(", ")", ")", "{", "$", "this", "->", "success", "(", "'Vault already initialized'", ")", ";", "return", "false", ";", "}", "$", "response", "=", "$", "this", "->...
Create a new Vault instance - initialize vault and save the response in ~/.bownty_vault_keys @see https://www.vaultproject.io/docs/http/sys-init.html @return void
[ "Create", "a", "new", "Vault", "instance" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L218-L236
jippi/vault-php-sdk
examples/shell.php
VaultShell.env
public function env() { $token = $this->Vault->getVaultToken(); if (empty($token)) { return $this->abort('Token file does not exist - call "create" first'); } $this->out('export VAULT_ADDR="http://127.0.0.1:8200" VAULT_TOKEN="' . $token . '";'); $this->out('echo "You can now execute Vault commands using the \"vault\" CLI tool";'); }
php
public function env() { $token = $this->Vault->getVaultToken(); if (empty($token)) { return $this->abort('Token file does not exist - call "create" first'); } $this->out('export VAULT_ADDR="http://127.0.0.1:8200" VAULT_TOKEN="' . $token . '";'); $this->out('echo "You can now execute Vault commands using the \"vault\" CLI tool";'); }
[ "public", "function", "env", "(", ")", "{", "$", "token", "=", "$", "this", "->", "Vault", "->", "getVaultToken", "(", ")", ";", "if", "(", "empty", "(", "$", "token", ")", ")", "{", "return", "$", "this", "->", "abort", "(", "'Token file does not ex...
Export ENV variables for Vault CLI usage @return void
[ "Export", "ENV", "variables", "for", "Vault", "CLI", "usage" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L264-L273
jippi/vault-php-sdk
examples/shell.php
VaultShell.mounts
public function mounts() { $config = yaml_parse(file_get_contents(CONFIG . 'vault.yml')); $mounts = $this->Vault->sys()->mounts()->json(); foreach ($config['secret_backends'] as $backend) { $this->out('Backend: ' . $backend['path']); if (!array_key_exists($backend['path'] . DS, $mounts)) { $this->info(' Creating ...'); $resp = $this->Vault->sys()->createMount($backend['path'], [ 'type' => $backend['type'], 'description' => isset($backend['description']) ? $backend['description'] : '' ]); } else { $this->success(' Already exist'); } switch ($backend['type']) { case 'mysql': $this->_mysqlBackend($backend); break; default: $this->_secretBackend($backend); break; } $this->out(''); } }
php
public function mounts() { $config = yaml_parse(file_get_contents(CONFIG . 'vault.yml')); $mounts = $this->Vault->sys()->mounts()->json(); foreach ($config['secret_backends'] as $backend) { $this->out('Backend: ' . $backend['path']); if (!array_key_exists($backend['path'] . DS, $mounts)) { $this->info(' Creating ...'); $resp = $this->Vault->sys()->createMount($backend['path'], [ 'type' => $backend['type'], 'description' => isset($backend['description']) ? $backend['description'] : '' ]); } else { $this->success(' Already exist'); } switch ($backend['type']) { case 'mysql': $this->_mysqlBackend($backend); break; default: $this->_secretBackend($backend); break; } $this->out(''); } }
[ "public", "function", "mounts", "(", ")", "{", "$", "config", "=", "yaml_parse", "(", "file_get_contents", "(", "CONFIG", ".", "'vault.yml'", ")", ")", ";", "$", "mounts", "=", "$", "this", "->", "Vault", "->", "sys", "(", ")", "->", "mounts", "(", "...
Create the required mount points @return void
[ "Create", "the", "required", "mount", "points" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L280-L310
jippi/vault-php-sdk
examples/shell.php
VaultShell._secretBackend
protected function _secretBackend($backend) { $data = $this->Vault->data(); foreach ($backend['secrets'] as $secret) { $this->info(' ' . $secret['path']); $data->write('secret/' . $secret['path'], $secret['payload']); } }
php
protected function _secretBackend($backend) { $data = $this->Vault->data(); foreach ($backend['secrets'] as $secret) { $this->info(' ' . $secret['path']); $data->write('secret/' . $secret['path'], $secret['payload']); } }
[ "protected", "function", "_secretBackend", "(", "$", "backend", ")", "{", "$", "data", "=", "$", "this", "->", "Vault", "->", "data", "(", ")", ";", "foreach", "(", "$", "backend", "[", "'secrets'", "]", "as", "$", "secret", ")", "{", "$", "this", ...
Specific handler for "secret" secret backends @param array $backend @return void
[ "Specific", "handler", "for", "secret", "secret", "backends" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L318-L325
jippi/vault-php-sdk
examples/shell.php
VaultShell._mysqlBackend
protected function _mysqlBackend(array $backend) { if (empty($backend['config']['ini_file'])) { return $this->abort('Missing config.ini_file key for mysql backend'); } if (!is_file($backend['config']['ini_file'])) { return $this->abort('ini file do not exist (' . $backend['config']['ini_file'] . ')'); } $ini = parse_ini_file($backend['config']['ini_file']); $connection_url = sprintf('%s:%s@unix(/var/run/mysqld/mysqld.sock)/', $ini['user'], $ini['password']); $data = $this->Vault->data(); $this->info(' Writing connection string'); $max_open_connections = 10; $data->write('mysql/config/connection', compact('connection_url', 'max_open_connections')); $this->info(' Writing lease configuration'); $data->write('mysql/config/lease', ['lease' => '1h', 'lease_max' => '24h']); $this->info(' Writing role configuration(s)'); foreach ($backend['roles'] as $role) { $this->info(' ' . $role['name']); $data->write('mysql/roles/' . $role['name'], ['sql' => join(';', $role['sql'])]); } }
php
protected function _mysqlBackend(array $backend) { if (empty($backend['config']['ini_file'])) { return $this->abort('Missing config.ini_file key for mysql backend'); } if (!is_file($backend['config']['ini_file'])) { return $this->abort('ini file do not exist (' . $backend['config']['ini_file'] . ')'); } $ini = parse_ini_file($backend['config']['ini_file']); $connection_url = sprintf('%s:%s@unix(/var/run/mysqld/mysqld.sock)/', $ini['user'], $ini['password']); $data = $this->Vault->data(); $this->info(' Writing connection string'); $max_open_connections = 10; $data->write('mysql/config/connection', compact('connection_url', 'max_open_connections')); $this->info(' Writing lease configuration'); $data->write('mysql/config/lease', ['lease' => '1h', 'lease_max' => '24h']); $this->info(' Writing role configuration(s)'); foreach ($backend['roles'] as $role) { $this->info(' ' . $role['name']); $data->write('mysql/roles/' . $role['name'], ['sql' => join(';', $role['sql'])]); } }
[ "protected", "function", "_mysqlBackend", "(", "array", "$", "backend", ")", "{", "if", "(", "empty", "(", "$", "backend", "[", "'config'", "]", "[", "'ini_file'", "]", ")", ")", "{", "return", "$", "this", "->", "abort", "(", "'Missing config.ini_file key...
Specific handler for MySQL secret backends @param array $backend @return void
[ "Specific", "handler", "for", "MySQL", "secret", "backends" ]
train
https://github.com/jippi/vault-php-sdk/blob/975086687ac95234cad779c42ce68e8ead46d2bf/examples/shell.php#L333-L359
spatie/laravel-server-monitor
src/HostRepository.php
HostRepository.determineHostModel
public static function determineHostModel(): string { $hostModel = config('server-monitor.host_model') ?? Host::class; if (! is_a($hostModel, Host::class, true)) { throw InvalidConfiguration::hostModelIsNotValid($hostModel); } return $hostModel; }
php
public static function determineHostModel(): string { $hostModel = config('server-monitor.host_model') ?? Host::class; if (! is_a($hostModel, Host::class, true)) { throw InvalidConfiguration::hostModelIsNotValid($hostModel); } return $hostModel; }
[ "public", "static", "function", "determineHostModel", "(", ")", ":", "string", "{", "$", "hostModel", "=", "config", "(", "'server-monitor.host_model'", ")", "??", "Host", "::", "class", ";", "if", "(", "!", "is_a", "(", "$", "hostModel", ",", "Host", "::"...
Determine the host model class name. @return string @throws \Spatie\ServerMonitor\Exceptions\InvalidConfiguration
[ "Determine", "the", "host", "model", "class", "name", "." ]
train
https://github.com/spatie/laravel-server-monitor/blob/df439247d51bacfec493d844b99343d1259efab9/src/HostRepository.php#L33-L42
spatie/laravel-server-monitor
src/Notifications/Notifications/CheckWarning.php
CheckWarning.toMail
public function toMail($notifiable) { return (new MailMessage) ->error() ->subject($this->getSubject()) ->line($this->getMessageText()); }
php
public function toMail($notifiable) { return (new MailMessage) ->error() ->subject($this->getSubject()) ->line($this->getMessageText()); }
[ "public", "function", "toMail", "(", "$", "notifiable", ")", "{", "return", "(", "new", "MailMessage", ")", "->", "error", "(", ")", "->", "subject", "(", "$", "this", "->", "getSubject", "(", ")", ")", "->", "line", "(", "$", "this", "->", "getMessa...
Get the mail representation of the notification. @param mixed $notifiable @return \Illuminate\Notifications\Messages\MailMessage
[ "Get", "the", "mail", "representation", "of", "the", "notification", "." ]
train
https://github.com/spatie/laravel-server-monitor/blob/df439247d51bacfec493d844b99343d1259efab9/src/Notifications/Notifications/CheckWarning.php#L24-L30
spatie/laravel-server-monitor
src/Models/Concerns/HasCustomProperties.php
HasCustomProperties.setCustomProperty
public function setCustomProperty(string $name, $value) { $customProperties = $this->custom_properties; Arr::set($customProperties, $name, $value); $this->custom_properties = $customProperties; return $this; }
php
public function setCustomProperty(string $name, $value) { $customProperties = $this->custom_properties; Arr::set($customProperties, $name, $value); $this->custom_properties = $customProperties; return $this; }
[ "public", "function", "setCustomProperty", "(", "string", "$", "name", ",", "$", "value", ")", "{", "$", "customProperties", "=", "$", "this", "->", "custom_properties", ";", "Arr", "::", "set", "(", "$", "customProperties", ",", "$", "name", ",", "$", "...
@param string $name @param mixed $value @return $this
[ "@param", "string", "$name", "@param", "mixed", "$value" ]
train
https://github.com/spatie/laravel-server-monitor/blob/df439247d51bacfec493d844b99343d1259efab9/src/Models/Concerns/HasCustomProperties.php#L31-L40
spatie/laravel-server-monitor
src/Models/Concerns/HasCustomProperties.php
HasCustomProperties.forgetCustomProperty
public function forgetCustomProperty(string $name) { $customProperties = $this->custom_properties; Arr::forget($customProperties, $name); $this->custom_properties = $customProperties; return $this; }
php
public function forgetCustomProperty(string $name) { $customProperties = $this->custom_properties; Arr::forget($customProperties, $name); $this->custom_properties = $customProperties; return $this; }
[ "public", "function", "forgetCustomProperty", "(", "string", "$", "name", ")", "{", "$", "customProperties", "=", "$", "this", "->", "custom_properties", ";", "Arr", "::", "forget", "(", "$", "customProperties", ",", "$", "name", ")", ";", "$", "this", "->...
@param string $name @return $this
[ "@param", "string", "$name" ]
train
https://github.com/spatie/laravel-server-monitor/blob/df439247d51bacfec493d844b99343d1259efab9/src/Models/Concerns/HasCustomProperties.php#L47-L56
spatie/laravel-server-monitor
src/Notifications/Notifiable.php
Notifiable.setEvent
public function setEvent(\Spatie\ServerMonitor\Events\Event $event): self { $this->event = $event; return $this; }
php
public function setEvent(\Spatie\ServerMonitor\Events\Event $event): self { $this->event = $event; return $this; }
[ "public", "function", "setEvent", "(", "\\", "Spatie", "\\", "ServerMonitor", "\\", "Events", "\\", "Event", "$", "event", ")", ":", "self", "{", "$", "this", "->", "event", "=", "$", "event", ";", "return", "$", "this", ";", "}" ]
Set the event for the notification. @param \Spatie\ServerMonitor\Events\Event $event @return Notifiable
[ "Set", "the", "event", "for", "the", "notification", "." ]
train
https://github.com/spatie/laravel-server-monitor/blob/df439247d51bacfec493d844b99343d1259efab9/src/Notifications/Notifiable.php#L52-L57
spatie/laravel-blade-x
src/BladeX.php
BladeX.component
public function component($view, string $tag = ''): ?Component { if (is_array($view)) { foreach ($view as $singleView) { $this->component($singleView); } return null; } if ($view instanceof Component) { $this->registeredComponents[$view->tag] = $view; return $view; } if (! is_string($view)) { throw CouldNotRegisterComponent::invalidArgument(); } if (ends_with($view, '*')) { $this->registerComponents($view); return null; } if (! view()->exists($view)) { throw CouldNotRegisterComponent::viewNotFound($view, $tag); } $component = new Component($view, $tag); $this->registeredComponents[$component->tag] = $component; return $component; }
php
public function component($view, string $tag = ''): ?Component { if (is_array($view)) { foreach ($view as $singleView) { $this->component($singleView); } return null; } if ($view instanceof Component) { $this->registeredComponents[$view->tag] = $view; return $view; } if (! is_string($view)) { throw CouldNotRegisterComponent::invalidArgument(); } if (ends_with($view, '*')) { $this->registerComponents($view); return null; } if (! view()->exists($view)) { throw CouldNotRegisterComponent::viewNotFound($view, $tag); } $component = new Component($view, $tag); $this->registeredComponents[$component->tag] = $component; return $component; }
[ "public", "function", "component", "(", "$", "view", ",", "string", "$", "tag", "=", "''", ")", ":", "?", "Component", "{", "if", "(", "is_array", "(", "$", "view", ")", ")", "{", "foreach", "(", "$", "view", "as", "$", "singleView", ")", "{", "$...
@param string|array $view @param string $tag @return null|\Spatie\BladeX\Component
[ "@param", "string|array", "$view", "@param", "string", "$tag" ]
train
https://github.com/spatie/laravel-blade-x/blob/db4f3dfd1f5f3d05ca3f4a688cdd708129a652f4/src/BladeX.php#L26-L61
callmez/yii2-wechat
components/BaseController.php
BaseController.message
public function message($message, $type = 'error', $redirect = null, $resultType = null) { $request = Yii::$app->getRequest(); if ($resultType === null) { $resultType = $request->getIsAjax() ? 'json' : 'html'; } elseif ($resultType === 'flash') { $resultType = Yii::$app->getRequest()->getIsAjax() ? 'json' : $resultType; } $data = [ 'type' => $type, 'message' => $message, 'redirect' => $redirect === null ? null : Url::to($redirect) ]; switch ($resultType) { case 'html': return $this->render(Yii::$app->getModule('wechat')->messageLayout, $data); case 'json': Yii::$app->getResponse()->format = Response::FORMAT_JSON; return $data; case 'flash': Yii::$app->session->setFlash($type, $message); $data['redirect'] == null && $data['redirect'] = $request->getReferrer(); Yii::$app->end(0, $this->redirect($data['redirect'])); return true; default: return $message; } }
php
public function message($message, $type = 'error', $redirect = null, $resultType = null) { $request = Yii::$app->getRequest(); if ($resultType === null) { $resultType = $request->getIsAjax() ? 'json' : 'html'; } elseif ($resultType === 'flash') { $resultType = Yii::$app->getRequest()->getIsAjax() ? 'json' : $resultType; } $data = [ 'type' => $type, 'message' => $message, 'redirect' => $redirect === null ? null : Url::to($redirect) ]; switch ($resultType) { case 'html': return $this->render(Yii::$app->getModule('wechat')->messageLayout, $data); case 'json': Yii::$app->getResponse()->format = Response::FORMAT_JSON; return $data; case 'flash': Yii::$app->session->setFlash($type, $message); $data['redirect'] == null && $data['redirect'] = $request->getReferrer(); Yii::$app->end(0, $this->redirect($data['redirect'])); return true; default: return $message; } }
[ "public", "function", "message", "(", "$", "message", ",", "$", "type", "=", "'error'", ",", "$", "redirect", "=", "null", ",", "$", "resultType", "=", "null", ")", "{", "$", "request", "=", "Yii", "::", "$", "app", "->", "getRequest", "(", ")", ";...
发送消息 @param $message @param string $type @param null $redirect @param null $resultType @return array|bool|string
[ "发送消息" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/BaseController.php#L26-L53
callmez/yii2-wechat
components/BaseController.php
BaseController.flash
public function flash($message, $status = 'error', $redirect = null) { return $this->message($message, $status, $redirect, 'flash'); }
php
public function flash($message, $status = 'error', $redirect = null) { return $this->message($message, $status, $redirect, 'flash'); }
[ "public", "function", "flash", "(", "$", "message", ",", "$", "status", "=", "'error'", ",", "$", "redirect", "=", "null", ")", "{", "return", "$", "this", "->", "message", "(", "$", "message", ",", "$", "status", ",", "$", "redirect", ",", "'flash'"...
flash消息 @param $message @param string $status @param null $redirect @return array|bool|string
[ "flash消息" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/BaseController.php#L62-L64
callmez/yii2-wechat
assets/FileApiAsset.php
FileApiAsset.registerAssetFiles
public function registerAssetFiles($view) { $view = Yii::$app->controller->getView(); $settings = array_merge([ 'debug' => YII_DEBUG ? 1: 0, 'staticPath' => Yii::getAlias($this->baseUrl) ], $this->settings); $view->registerJs('window.FileAPI=' . Json::encode($settings) . ';', View::POS_HEAD); parent::registerAssetFiles($view); }
php
public function registerAssetFiles($view) { $view = Yii::$app->controller->getView(); $settings = array_merge([ 'debug' => YII_DEBUG ? 1: 0, 'staticPath' => Yii::getAlias($this->baseUrl) ], $this->settings); $view->registerJs('window.FileAPI=' . Json::encode($settings) . ';', View::POS_HEAD); parent::registerAssetFiles($view); }
[ "public", "function", "registerAssetFiles", "(", "$", "view", ")", "{", "$", "view", "=", "Yii", "::", "$", "app", "->", "controller", "->", "getView", "(", ")", ";", "$", "settings", "=", "array_merge", "(", "[", "'debug'", "=>", "YII_DEBUG", "?", "1"...
注册FileAPI默认设置 @inheritdoc
[ "注册FileAPI默认设置" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/assets/FileApiAsset.php#L35-L44
callmez/yii2-wechat
controllers/process/FansController.php
FansController.actionRecord
public function actionRecord() { $wechat = $this->getWechat(); $fans = $this->getFans(); if (!$fans) { // 存储粉丝信息 $fans = Yii::createObject(Fans::className()); $fans->setAttributes([ 'wid' => $wechat->id, 'open_id' => $this->message['FromUserName'], 'status' => Fans::STATUS_SUBSCRIBED ]); if ($fans->save() && $wechat->status > Wechat::TYPE_SUBSCRIBE) { // 更新用户详细数据, 普通订阅号无权限获取 $fans->updateUser(); } } elseif ($fans->status != Fans::STATUS_SUBSCRIBED) { // 更新关注状态 $fans->subscribe(); } // $history = new MessageHistory(); // $attributes = [ // 'wid' => $wechat->id, // 'module' => $this->getModuleName($this->api->lastProcessController), // ]; }
php
public function actionRecord() { $wechat = $this->getWechat(); $fans = $this->getFans(); if (!$fans) { // 存储粉丝信息 $fans = Yii::createObject(Fans::className()); $fans->setAttributes([ 'wid' => $wechat->id, 'open_id' => $this->message['FromUserName'], 'status' => Fans::STATUS_SUBSCRIBED ]); if ($fans->save() && $wechat->status > Wechat::TYPE_SUBSCRIBE) { // 更新用户详细数据, 普通订阅号无权限获取 $fans->updateUser(); } } elseif ($fans->status != Fans::STATUS_SUBSCRIBED) { // 更新关注状态 $fans->subscribe(); } // $history = new MessageHistory(); // $attributes = [ // 'wid' => $wechat->id, // 'module' => $this->getModuleName($this->api->lastProcessController), // ]; }
[ "public", "function", "actionRecord", "(", ")", "{", "$", "wechat", "=", "$", "this", "->", "getWechat", "(", ")", ";", "$", "fans", "=", "$", "this", "->", "getFans", "(", ")", ";", "if", "(", "!", "$", "fans", ")", "{", "// 存储粉丝信息", "$", "fans"...
数据记录 @return array @throws \yii\base\InvalidConfigException
[ "数据记录" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/process/FansController.php#L21-L44
callmez/yii2-wechat
components/MpWechat.php
MpWechat.getAuthorizeUserInfo
public function getAuthorizeUserInfo($state = 'authorize', $scope = 'snsapi_base') { $request = Yii::$app->request; if (($code = $request->get('code')) && $request->get('state') == $state) { return $this->getOauth2AccessToken($code); } else { Yii::$app->getResponse()->redirect($this->getOauth2AuthorizeUrl($request->getAbsoluteUrl(), $state, $scope)); Yii::$app->end(); } }
php
public function getAuthorizeUserInfo($state = 'authorize', $scope = 'snsapi_base') { $request = Yii::$app->request; if (($code = $request->get('code')) && $request->get('state') == $state) { return $this->getOauth2AccessToken($code); } else { Yii::$app->getResponse()->redirect($this->getOauth2AuthorizeUrl($request->getAbsoluteUrl(), $state, $scope)); Yii::$app->end(); } }
[ "public", "function", "getAuthorizeUserInfo", "(", "$", "state", "=", "'authorize'", ",", "$", "scope", "=", "'snsapi_base'", ")", "{", "$", "request", "=", "Yii", "::", "$", "app", "->", "request", ";", "if", "(", "(", "$", "code", "=", "$", "request"...
跳转微信网页获取用户授权信息 @param string $state @return mixed
[ "跳转微信网页获取用户授权信息" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/MpWechat.php#L41-L50
callmez/yii2-wechat
models/Module.php
Module.save
public function save($runValidation = true, $attributeNames = null) { $transaction = static::getDb()->beginTransaction(); try { if ($this->getIsNewRecord()) { $migrationType = self::MIGRATION_INSTALL; $result = $this->insert($runValidation, $attributeNames); } else { $migrationType = self::MIGRATION_UPGRADE; $result = $this->update($runValidation, $attributeNames) !== false; } if ($result !== false && $this->migration) { $result = $this->migration($migrationType); } if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); static::updateCache(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } }
php
public function save($runValidation = true, $attributeNames = null) { $transaction = static::getDb()->beginTransaction(); try { if ($this->getIsNewRecord()) { $migrationType = self::MIGRATION_INSTALL; $result = $this->insert($runValidation, $attributeNames); } else { $migrationType = self::MIGRATION_UPGRADE; $result = $this->update($runValidation, $attributeNames) !== false; } if ($result !== false && $this->migration) { $result = $this->migration($migrationType); } if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); static::updateCache(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } }
[ "public", "function", "save", "(", "$", "runValidation", "=", "true", ",", "$", "attributeNames", "=", "null", ")", "{", "$", "transaction", "=", "static", "::", "getDb", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "if", "(", "$", ...
加入安装和升级migration操作, 使用事务(self::transactions()禁止默认事务)来控制数据一致性 并更新数据缓存 @inheritdoc
[ "加入安装和升级migration操作", "使用事务", "(", "self", "::", "transactions", "()", "禁止默认事务", ")", "来控制数据一致性", "并更新数据缓存" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Module.php#L81-L109
callmez/yii2-wechat
models/Module.php
Module.delete
public function delete() { $transaction = static::getDb()->beginTransaction(); try { $result = $this->deleteInternal(); if ($result !== false && $this->migration) { // 有迁移执行迁移脚本 $result = $this->migration(self::MIGRATION_UNINSTALL); } if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); static::updateCache(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } }
php
public function delete() { $transaction = static::getDb()->beginTransaction(); try { $result = $this->deleteInternal(); if ($result !== false && $this->migration) { // 有迁移执行迁移脚本 $result = $this->migration(self::MIGRATION_UNINSTALL); } if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); static::updateCache(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } }
[ "public", "function", "delete", "(", ")", "{", "$", "transaction", "=", "static", "::", "getDb", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "$", "result", "=", "$", "this", "->", "deleteInternal", "(", ")", ";", "if", "(", "$", ...
加入卸载migration操作, 使用事务(self::transactions()禁止默认事务)来控制数据一致性 并更新数据缓存 @inheritdoc
[ "加入卸载migration操作", "使用事务", "(", "self", "::", "transactions", "()", "禁止默认事务", ")", "来控制数据一致性", "并更新数据缓存" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Module.php#L116-L138