repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
ppetermann/king23
src/Http/Router.php
Router.cleanHostName
private function cleanHostName(ServerRequestInterface $request) { if (is_null($this->baseHost)) { $hostname = $request->getUri()->getHost(); } else { $hostname = str_replace($this->baseHost, "", $request->getUri()->getHost()); } if (substr($hostname, -1) == ".") { $hostname = substr($hostname, 0, -1); } return $hostname; }
php
private function cleanHostName(ServerRequestInterface $request) { if (is_null($this->baseHost)) { $hostname = $request->getUri()->getHost(); } else { $hostname = str_replace($this->baseHost, "", $request->getUri()->getHost()); } if (substr($hostname, -1) == ".") { $hostname = substr($hostname, 0, -1); } return $hostname; }
[ "private", "function", "cleanHostName", "(", "ServerRequestInterface", "$", "request", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "baseHost", ")", ")", "{", "$", "hostname", "=", "$", "request", "->", "getUri", "(", ")", "->", "getHost", "(", ")", ";", "}", "else", "{", "$", "hostname", "=", "str_replace", "(", "$", "this", "->", "baseHost", ",", "\"\"", ",", "$", "request", "->", "getUri", "(", ")", "->", "getHost", "(", ")", ")", ";", "}", "if", "(", "substr", "(", "$", "hostname", ",", "-", "1", ")", "==", "\".\"", ")", "{", "$", "hostname", "=", "substr", "(", "$", "hostname", ",", "0", ",", "-", "1", ")", ";", "}", "return", "$", "hostname", ";", "}" ]
will get hostname, and clean basehost off it @param ServerRequestInterface $request @return string
[ "will", "get", "hostname", "and", "clean", "basehost", "off", "it" ]
train
https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L223-L237
inc2734/wp-share-buttons
src/App/Model/Requester/Hatena.php
Hatena._get_count
protected function _get_count( $permalink ) { $request = "https://b.hatena.ne.jp/entry.count?url=$permalink"; $response = wp_remote_get( $request ); $body = wp_remote_retrieve_body( $response ); if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { error_log( '[WP Share Buttons] Hatena request / ' . $request . ' / ' . json_encode( $body ) ); } if ( '' === $body ) { return 0; } return $body; }
php
protected function _get_count( $permalink ) { $request = "https://b.hatena.ne.jp/entry.count?url=$permalink"; $response = wp_remote_get( $request ); $body = wp_remote_retrieve_body( $response ); if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { error_log( '[WP Share Buttons] Hatena request / ' . $request . ' / ' . json_encode( $body ) ); } if ( '' === $body ) { return 0; } return $body; }
[ "protected", "function", "_get_count", "(", "$", "permalink", ")", "{", "$", "request", "=", "\"https://b.hatena.ne.jp/entry.count?url=$permalink\"", ";", "$", "response", "=", "wp_remote_get", "(", "$", "request", ")", ";", "$", "body", "=", "wp_remote_retrieve_body", "(", "$", "response", ")", ";", "if", "(", "defined", "(", "'WP_DEBUG'", ")", "&&", "true", "===", "WP_DEBUG", ")", "{", "error_log", "(", "'[WP Share Buttons] Hatena request / '", ".", "$", "request", ".", "' / '", ".", "json_encode", "(", "$", "body", ")", ")", ";", "}", "if", "(", "''", "===", "$", "body", ")", "{", "return", "0", ";", "}", "return", "$", "body", ";", "}" ]
Get count from API @param string $permalink @return int Count
[ "Get", "count", "from", "API" ]
train
https://github.com/inc2734/wp-share-buttons/blob/cd032893ca083a343f5871e855cce68f4ede3a17/src/App/Model/Requester/Hatena.php#L30-L44
kharanenka/laravel-cache-helper
src/Kharanenka/Helper/CCache.php
CCache.get
public static function get($arTags, $sKeys) { $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { return Cache::tags($arTags)->get($sKeys); } else { $sKeys = implode('_', $arTags).'_'.$sKeys; } } return Cache::get($sKeys); }
php
public static function get($arTags, $sKeys) { $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { return Cache::tags($arTags)->get($sKeys); } else { $sKeys = implode('_', $arTags).'_'.$sKeys; } } return Cache::get($sKeys); }
[ "public", "static", "function", "get", "(", "$", "arTags", ",", "$", "sKeys", ")", "{", "$", "sCacheDriver", "=", "config", "(", "'cache.default'", ")", ";", "if", "(", "!", "empty", "(", "$", "arTags", ")", ")", "{", "if", "(", "$", "sCacheDriver", "==", "'redis'", ")", "{", "return", "Cache", "::", "tags", "(", "$", "arTags", ")", "->", "get", "(", "$", "sKeys", ")", ";", "}", "else", "{", "$", "sKeys", "=", "implode", "(", "'_'", ",", "$", "arTags", ")", ".", "'_'", ".", "$", "sKeys", ";", "}", "}", "return", "Cache", "::", "get", "(", "$", "sKeys", ")", ";", "}" ]
Get cache value @param array $arTags @param string $sKeys @return mixed
[ "Get", "cache", "value" ]
train
https://github.com/kharanenka/laravel-cache-helper/blob/5423eed6830ade6f7af8b02eb6ad33a97db7b848/src/Kharanenka/Helper/CCache.php#L21-L33
kharanenka/laravel-cache-helper
src/Kharanenka/Helper/CCache.php
CCache.put
public static function put($arTags, $sKeys, &$arValue, $iMinute) { $obDate = Carbon::now()->addMinute($iMinute); $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { Cache::tags($arTags)->put($sKeys, $arValue, $obDate); return; } else { $sKeys = implode('_', $arTags).'_'.$sKeys; } } Cache::put($sKeys, $arValue, $obDate); }
php
public static function put($arTags, $sKeys, &$arValue, $iMinute) { $obDate = Carbon::now()->addMinute($iMinute); $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { Cache::tags($arTags)->put($sKeys, $arValue, $obDate); return; } else { $sKeys = implode('_', $arTags).'_'.$sKeys; } } Cache::put($sKeys, $arValue, $obDate); }
[ "public", "static", "function", "put", "(", "$", "arTags", ",", "$", "sKeys", ",", "&", "$", "arValue", ",", "$", "iMinute", ")", "{", "$", "obDate", "=", "Carbon", "::", "now", "(", ")", "->", "addMinute", "(", "$", "iMinute", ")", ";", "$", "sCacheDriver", "=", "config", "(", "'cache.default'", ")", ";", "if", "(", "!", "empty", "(", "$", "arTags", ")", ")", "{", "if", "(", "$", "sCacheDriver", "==", "'redis'", ")", "{", "Cache", "::", "tags", "(", "$", "arTags", ")", "->", "put", "(", "$", "sKeys", ",", "$", "arValue", ",", "$", "obDate", ")", ";", "return", ";", "}", "else", "{", "$", "sKeys", "=", "implode", "(", "'_'", ",", "$", "arTags", ")", ".", "'_'", ".", "$", "sKeys", ";", "}", "}", "Cache", "::", "put", "(", "$", "sKeys", ",", "$", "arValue", ",", "$", "obDate", ")", ";", "}" ]
Put cache data @param array $arTags @param string $sKeys @param mixed $arValue @param int $iMinute
[ "Put", "cache", "data" ]
train
https://github.com/kharanenka/laravel-cache-helper/blob/5423eed6830ade6f7af8b02eb6ad33a97db7b848/src/Kharanenka/Helper/CCache.php#L62-L77
kharanenka/laravel-cache-helper
src/Kharanenka/Helper/CCache.php
CCache.forever
public static function forever($arTags, $sKeys, &$arValue) { $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { Cache::tags($arTags)->forever($sKeys, $arValue); return; } else { $sKeys = implode('_', $arTags).'_'.$sKeys; } } Cache::forever($sKeys, $arValue); }
php
public static function forever($arTags, $sKeys, &$arValue) { $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { Cache::tags($arTags)->forever($sKeys, $arValue); return; } else { $sKeys = implode('_', $arTags).'_'.$sKeys; } } Cache::forever($sKeys, $arValue); }
[ "public", "static", "function", "forever", "(", "$", "arTags", ",", "$", "sKeys", ",", "&", "$", "arValue", ")", "{", "$", "sCacheDriver", "=", "config", "(", "'cache.default'", ")", ";", "if", "(", "!", "empty", "(", "$", "arTags", ")", ")", "{", "if", "(", "$", "sCacheDriver", "==", "'redis'", ")", "{", "Cache", "::", "tags", "(", "$", "arTags", ")", "->", "forever", "(", "$", "sKeys", ",", "$", "arValue", ")", ";", "return", ";", "}", "else", "{", "$", "sKeys", "=", "implode", "(", "'_'", ",", "$", "arTags", ")", ".", "'_'", ".", "$", "sKeys", ";", "}", "}", "Cache", "::", "forever", "(", "$", "sKeys", ",", "$", "arValue", ")", ";", "}" ]
Forever cache data @param array $arTags @param string $sKeys @param mixed $arValue
[ "Forever", "cache", "data" ]
train
https://github.com/kharanenka/laravel-cache-helper/blob/5423eed6830ade6f7af8b02eb6ad33a97db7b848/src/Kharanenka/Helper/CCache.php#L85-L98
kharanenka/laravel-cache-helper
src/Kharanenka/Helper/CCache.php
CCache.clear
public static function clear($arTags, $sKeys = null) { $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { if(!empty($sKeys)) { Cache::tags($arTags)->forget($sKeys); } else { Cache::tags($arTags)->flush(); } } else { $sKeys = implode('_', $arTags).'_'.$sKeys; Cache::forget($sKeys); } } }
php
public static function clear($arTags, $sKeys = null) { $sCacheDriver = config('cache.default'); if(!empty($arTags)) { if($sCacheDriver == 'redis') { if(!empty($sKeys)) { Cache::tags($arTags)->forget($sKeys); } else { Cache::tags($arTags)->flush(); } } else { $sKeys = implode('_', $arTags).'_'.$sKeys; Cache::forget($sKeys); } } }
[ "public", "static", "function", "clear", "(", "$", "arTags", ",", "$", "sKeys", "=", "null", ")", "{", "$", "sCacheDriver", "=", "config", "(", "'cache.default'", ")", ";", "if", "(", "!", "empty", "(", "$", "arTags", ")", ")", "{", "if", "(", "$", "sCacheDriver", "==", "'redis'", ")", "{", "if", "(", "!", "empty", "(", "$", "sKeys", ")", ")", "{", "Cache", "::", "tags", "(", "$", "arTags", ")", "->", "forget", "(", "$", "sKeys", ")", ";", "}", "else", "{", "Cache", "::", "tags", "(", "$", "arTags", ")", "->", "flush", "(", ")", ";", "}", "}", "else", "{", "$", "sKeys", "=", "implode", "(", "'_'", ",", "$", "arTags", ")", ".", "'_'", ".", "$", "sKeys", ";", "Cache", "::", "forget", "(", "$", "sKeys", ")", ";", "}", "}", "}" ]
Clear cache data @param array $arTags @param string $sKeys
[ "Clear", "cache", "data" ]
train
https://github.com/kharanenka/laravel-cache-helper/blob/5423eed6830ade6f7af8b02eb6ad33a97db7b848/src/Kharanenka/Helper/CCache.php#L105-L120
infinity-next/braintree
src/Billable.php
Billable.findInvoice
public function findInvoice($id) { $invoice = $this->subscription()->findInvoice($id); if ($invoice && $invoice->customer == $this->getBraintreeId()) { return $invoice; } }
php
public function findInvoice($id) { $invoice = $this->subscription()->findInvoice($id); if ($invoice && $invoice->customer == $this->getBraintreeId()) { return $invoice; } }
[ "public", "function", "findInvoice", "(", "$", "id", ")", "{", "$", "invoice", "=", "$", "this", "->", "subscription", "(", ")", "->", "findInvoice", "(", "$", "id", ")", ";", "if", "(", "$", "invoice", "&&", "$", "invoice", "->", "customer", "==", "$", "this", "->", "getBraintreeId", "(", ")", ")", "{", "return", "$", "invoice", ";", "}", "}" ]
Find an invoice by ID. @param string $id @return \InfinityNext\Braintree\Invoice|null
[ "Find", "an", "invoice", "by", "ID", "." ]
train
https://github.com/infinity-next/braintree/blob/4bf6f49d4d8a05734a295003137f360e331cc10f/src/Billable.php#L98-L105
infinity-next/braintree
src/Billable.php
Billable.onTrial
public function onTrial() { if (! is_null($this->getTrialEndDate())) { return Carbon::today()->lt($this->getTrialEndDate()); } else { return false; } }
php
public function onTrial() { if (! is_null($this->getTrialEndDate())) { return Carbon::today()->lt($this->getTrialEndDate()); } else { return false; } }
[ "public", "function", "onTrial", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "getTrialEndDate", "(", ")", ")", ")", "{", "return", "Carbon", "::", "today", "(", ")", "->", "lt", "(", "$", "this", "->", "getTrialEndDate", "(", ")", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Determine if the entity is within their trial period. @return bool
[ "Determine", "if", "the", "entity", "is", "within", "their", "trial", "period", "." ]
train
https://github.com/infinity-next/braintree/blob/4bf6f49d4d8a05734a295003137f360e331cc10f/src/Billable.php#L196-L203
infinity-next/braintree
src/Billable.php
Billable.onGracePeriod
public function onGracePeriod() { if (! is_null($endsAt = $this->getSubscriptionEndDate())) { return Carbon::now()->lt(Carbon::instance($endsAt)); } else { return false; } }
php
public function onGracePeriod() { if (! is_null($endsAt = $this->getSubscriptionEndDate())) { return Carbon::now()->lt(Carbon::instance($endsAt)); } else { return false; } }
[ "public", "function", "onGracePeriod", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "endsAt", "=", "$", "this", "->", "getSubscriptionEndDate", "(", ")", ")", ")", "{", "return", "Carbon", "::", "now", "(", ")", "->", "lt", "(", "Carbon", "::", "instance", "(", "$", "endsAt", ")", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Determine if the entity is on grace period after cancellation. @return bool
[ "Determine", "if", "the", "entity", "is", "on", "grace", "period", "after", "cancellation", "." ]
train
https://github.com/infinity-next/braintree/blob/4bf6f49d4d8a05734a295003137f360e331cc10f/src/Billable.php#L210-L217
infinity-next/braintree
src/Billable.php
Billable.subscribed
public function subscribed() { if ($this->requiresCardUpFront()) { return $this->braintreeIsActive() || $this->onGracePeriod(); } else { return $this->braintreeIsActive() || $this->onTrial() || $this->onGracePeriod(); } }
php
public function subscribed() { if ($this->requiresCardUpFront()) { return $this->braintreeIsActive() || $this->onGracePeriod(); } else { return $this->braintreeIsActive() || $this->onTrial() || $this->onGracePeriod(); } }
[ "public", "function", "subscribed", "(", ")", "{", "if", "(", "$", "this", "->", "requiresCardUpFront", "(", ")", ")", "{", "return", "$", "this", "->", "braintreeIsActive", "(", ")", "||", "$", "this", "->", "onGracePeriod", "(", ")", ";", "}", "else", "{", "return", "$", "this", "->", "braintreeIsActive", "(", ")", "||", "$", "this", "->", "onTrial", "(", ")", "||", "$", "this", "->", "onGracePeriod", "(", ")", ";", "}", "}" ]
Determine if the entity has an active subscription. @return bool
[ "Determine", "if", "the", "entity", "has", "an", "active", "subscription", "." ]
train
https://github.com/infinity-next/braintree/blob/4bf6f49d4d8a05734a295003137f360e331cc10f/src/Billable.php#L224-L232
tbreuss/pvc
src/Middleware/MiddlewareStack.php
MiddlewareStack.push
public function push(MiddlewareInterface $middleware): self { $stack = clone $this; array_unshift($stack->middlewares, $middleware); return $stack; }
php
public function push(MiddlewareInterface $middleware): self { $stack = clone $this; array_unshift($stack->middlewares, $middleware); return $stack; }
[ "public", "function", "push", "(", "MiddlewareInterface", "$", "middleware", ")", ":", "self", "{", "$", "stack", "=", "clone", "$", "this", ";", "array_unshift", "(", "$", "stack", "->", "middlewares", ",", "$", "middleware", ")", ";", "return", "$", "stack", ";", "}" ]
Creates a new stack with the given middleware pushed. @param MiddlewareInterface $middleware @return self
[ "Creates", "a", "new", "stack", "with", "the", "given", "middleware", "pushed", "." ]
train
https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/Middleware/MiddlewareStack.php#L65-L70
fubhy/graphql-php
src/Type/Directives/SkipDirective.php
SkipDirective.getType
public function getType() { if (!isset($this->type)) { $this->type = new NonNullModifier(Type::booleanType()); } return $this->type; }
php
public function getType() { if (!isset($this->type)) { $this->type = new NonNullModifier(Type::booleanType()); } return $this->type; }
[ "public", "function", "getType", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "type", ")", ")", "{", "$", "this", "->", "type", "=", "new", "NonNullModifier", "(", "Type", "::", "booleanType", "(", ")", ")", ";", "}", "return", "$", "this", "->", "type", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Type/Directives/SkipDirective.php#L56-L63
echo58/sms
src/Message.php
Message.addRecipient
public function addRecipient($recipients, $prepend = false) { if (!$prepend) { $this->appendRecipient($recipients); } else { $this->prependRecipient($recipients); } return $this; }
php
public function addRecipient($recipients, $prepend = false) { if (!$prepend) { $this->appendRecipient($recipients); } else { $this->prependRecipient($recipients); } return $this; }
[ "public", "function", "addRecipient", "(", "$", "recipients", ",", "$", "prepend", "=", "false", ")", "{", "if", "(", "!", "$", "prepend", ")", "{", "$", "this", "->", "appendRecipient", "(", "$", "recipients", ")", ";", "}", "else", "{", "$", "this", "->", "prependRecipient", "(", "$", "recipients", ")", ";", "}", "return", "$", "this", ";", "}" ]
添加短信接收者 @param string|string[] $recipients @param bool $prepend 控制是否添加在头部,默认从尾部添加 @return self @throws \InvalidArgumentException
[ "添加短信接收者" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L146-L155
echo58/sms
src/Message.php
Message.appendRecipient
protected function appendRecipient($recipients) { $recipients = static::formatRecipient($recipients); $this->recipients = array_merge($this->recipients, $recipients); }
php
protected function appendRecipient($recipients) { $recipients = static::formatRecipient($recipients); $this->recipients = array_merge($this->recipients, $recipients); }
[ "protected", "function", "appendRecipient", "(", "$", "recipients", ")", "{", "$", "recipients", "=", "static", "::", "formatRecipient", "(", "$", "recipients", ")", ";", "$", "this", "->", "recipients", "=", "array_merge", "(", "$", "this", "->", "recipients", ",", "$", "recipients", ")", ";", "}" ]
添加短信接收者到当前列表的尾部 @param string|string[] $recipients @throws \InvalidArgumentException
[ "添加短信接收者到当前列表的尾部" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L163-L167
echo58/sms
src/Message.php
Message.prependRecipient
protected function prependRecipient($recipients) { $recipients = static::formatRecipient($recipients); $this->recipients = array_merge($recipients, $this->recipients); }
php
protected function prependRecipient($recipients) { $recipients = static::formatRecipient($recipients); $this->recipients = array_merge($recipients, $this->recipients); }
[ "protected", "function", "prependRecipient", "(", "$", "recipients", ")", "{", "$", "recipients", "=", "static", "::", "formatRecipient", "(", "$", "recipients", ")", ";", "$", "this", "->", "recipients", "=", "array_merge", "(", "$", "recipients", ",", "$", "this", "->", "recipients", ")", ";", "}" ]
添加短信接收者到当前列表的头部 @param string|string[] $recipients @throws \InvalidArgumentException
[ "添加短信接收者到当前列表的头部" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L175-L179
echo58/sms
src/Message.php
Message.formatRecipient
public static function formatRecipient($recipients) { if (is_string($recipients)) { $recipients = explode(',', trim($recipients, ", \t\n\r\0\x0B")); } elseif (!is_array($recipients)) { throw new \InvalidArgumentException('接受者必须为字符串或字符串数组'); } return $recipients; }
php
public static function formatRecipient($recipients) { if (is_string($recipients)) { $recipients = explode(',', trim($recipients, ", \t\n\r\0\x0B")); } elseif (!is_array($recipients)) { throw new \InvalidArgumentException('接受者必须为字符串或字符串数组'); } return $recipients; }
[ "public", "static", "function", "formatRecipient", "(", "$", "recipients", ")", "{", "if", "(", "is_string", "(", "$", "recipients", ")", ")", "{", "$", "recipients", "=", "explode", "(", "','", ",", "trim", "(", "$", "recipients", ",", "\", \\t\\n\\r\\0\\x0B\"", ")", ")", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "recipients", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'接受者必须为字符串或字符串数组');", "", "", "}", "return", "$", "recipients", ";", "}" ]
转换接收者格式 @param string|string[] $recipients @return string[] @throws \InvalidArgumentException
[ "转换接收者格式" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L188-L197
echo58/sms
src/Message.php
Message.setStatus
public function setStatus($status) { if (!in_array($status, MessageStatus::getValidStatus())) { throw new \InvalidArgumentException('短信状态非法'); } $this->status = $status; }
php
public function setStatus($status) { if (!in_array($status, MessageStatus::getValidStatus())) { throw new \InvalidArgumentException('短信状态非法'); } $this->status = $status; }
[ "public", "function", "setStatus", "(", "$", "status", ")", "{", "if", "(", "!", "in_array", "(", "$", "status", ",", "MessageStatus", "::", "getValidStatus", "(", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'短信状态非法');", "", "", "}", "$", "this", "->", "status", "=", "$", "status", ";", "}" ]
设置短信状态 @param int $status
[ "设置短信状态" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L357-L363
echo58/sms
src/Message.php
Message.fromArray
public function fromArray(array $data) { if (!empty($data['id'])) { $this->setId($data['id']); } if (isset($data['recipients'])) { $this->setRecipients($data['recipients']); } if (isset($data['recipient'])) { $this->addRecipient($data['recipient']); } if (isset($data['from'])) { $this->setFrom($data['from']); } if (isset($data['body'])) { $this->setBody($data['body']); } if (isset($data['data'])) { $this->setData($data['data']); } if (isset($data['template_id'])) { $this->setTemplateId($data['template_id']); } if (isset($data['status'])) { $this->setStatus($data['status']); } else { $this->setStatus(MessageStatus::STATUS_QUEUED); } return $this; }
php
public function fromArray(array $data) { if (!empty($data['id'])) { $this->setId($data['id']); } if (isset($data['recipients'])) { $this->setRecipients($data['recipients']); } if (isset($data['recipient'])) { $this->addRecipient($data['recipient']); } if (isset($data['from'])) { $this->setFrom($data['from']); } if (isset($data['body'])) { $this->setBody($data['body']); } if (isset($data['data'])) { $this->setData($data['data']); } if (isset($data['template_id'])) { $this->setTemplateId($data['template_id']); } if (isset($data['status'])) { $this->setStatus($data['status']); } else { $this->setStatus(MessageStatus::STATUS_QUEUED); } return $this; }
[ "public", "function", "fromArray", "(", "array", "$", "data", ")", "{", "if", "(", "!", "empty", "(", "$", "data", "[", "'id'", "]", ")", ")", "{", "$", "this", "->", "setId", "(", "$", "data", "[", "'id'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'recipients'", "]", ")", ")", "{", "$", "this", "->", "setRecipients", "(", "$", "data", "[", "'recipients'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'recipient'", "]", ")", ")", "{", "$", "this", "->", "addRecipient", "(", "$", "data", "[", "'recipient'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'from'", "]", ")", ")", "{", "$", "this", "->", "setFrom", "(", "$", "data", "[", "'from'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'body'", "]", ")", ")", "{", "$", "this", "->", "setBody", "(", "$", "data", "[", "'body'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'data'", "]", ")", ")", "{", "$", "this", "->", "setData", "(", "$", "data", "[", "'data'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'template_id'", "]", ")", ")", "{", "$", "this", "->", "setTemplateId", "(", "$", "data", "[", "'template_id'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'status'", "]", ")", ")", "{", "$", "this", "->", "setStatus", "(", "$", "data", "[", "'status'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "setStatus", "(", "MessageStatus", "::", "STATUS_QUEUED", ")", ";", "}", "return", "$", "this", ";", "}" ]
初始化短信内容 @param array $data @return self
[ "初始化短信内容" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L465-L502
echo58/sms
src/Message.php
Message.toArray
public function toArray() { return [ 'id' => $this->getId(), 'recipients' => $this->getRecipients(), 'from' => $this->getFrom(), 'body' => $this->getBody(), 'data' => $this->getData(), 'template_id' => $this->getTemplateId(), 'status' => $this->getStatus(), ]; }
php
public function toArray() { return [ 'id' => $this->getId(), 'recipients' => $this->getRecipients(), 'from' => $this->getFrom(), 'body' => $this->getBody(), 'data' => $this->getData(), 'template_id' => $this->getTemplateId(), 'status' => $this->getStatus(), ]; }
[ "public", "function", "toArray", "(", ")", "{", "return", "[", "'id'", "=>", "$", "this", "->", "getId", "(", ")", ",", "'recipients'", "=>", "$", "this", "->", "getRecipients", "(", ")", ",", "'from'", "=>", "$", "this", "->", "getFrom", "(", ")", ",", "'body'", "=>", "$", "this", "->", "getBody", "(", ")", ",", "'data'", "=>", "$", "this", "->", "getData", "(", ")", ",", "'template_id'", "=>", "$", "this", "->", "getTemplateId", "(", ")", ",", "'status'", "=>", "$", "this", "->", "getStatus", "(", ")", ",", "]", ";", "}" ]
生成包含短信相关信息的数组 @return array
[ "生成包含短信相关信息的数组" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L509-L520
echo58/sms
src/Message.php
Message.send
public function send() { $provider = $this->getProvider(); if (!$provider) { throw new \RuntimeException('未设置短信供应商'); } $provider->send($this); return $this; }
php
public function send() { $provider = $this->getProvider(); if (!$provider) { throw new \RuntimeException('未设置短信供应商'); } $provider->send($this); return $this; }
[ "public", "function", "send", "(", ")", "{", "$", "provider", "=", "$", "this", "->", "getProvider", "(", ")", ";", "if", "(", "!", "$", "provider", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'未设置短信供应商');", "", "", "}", "$", "provider", "->", "send", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}" ]
发送短信 @return Message 返回发送状态改变后的短信 @throws \RuntimeException 未设置短信供应商
[ "发送短信" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L543-L553
echo58/sms
src/Message.php
Message.offsetExists
public function offsetExists($offset) { $method = 'get'.static::formatOffset($offset); return method_exists($this, $method) && null !== $this->{$method}(); }
php
public function offsetExists($offset) { $method = 'get'.static::formatOffset($offset); return method_exists($this, $method) && null !== $this->{$method}(); }
[ "public", "function", "offsetExists", "(", "$", "offset", ")", "{", "$", "method", "=", "'get'", ".", "static", "::", "formatOffset", "(", "$", "offset", ")", ";", "return", "method_exists", "(", "$", "this", ",", "$", "method", ")", "&&", "null", "!==", "$", "this", "->", "{", "$", "method", "}", "(", ")", ";", "}" ]
检查一个偏移位置是否存在 @param string $offset 需要检查的偏移位置 @return boolean 成功时返回 TRUE, 或者在失败时返回 FALSE
[ "检查一个偏移位置是否存在" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L561-L566
echo58/sms
src/Message.php
Message.offsetGet
public function offsetGet($offset) { $method = 'get'.static::formatOffset($offset); return $this->offsetExists($offset) ? $this->{$method}() : null; }
php
public function offsetGet($offset) { $method = 'get'.static::formatOffset($offset); return $this->offsetExists($offset) ? $this->{$method}() : null; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "$", "method", "=", "'get'", ".", "static", "::", "formatOffset", "(", "$", "offset", ")", ";", "return", "$", "this", "->", "offsetExists", "(", "$", "offset", ")", "?", "$", "this", "->", "{", "$", "method", "}", "(", ")", ":", "null", ";", "}" ]
获取一个偏移位置的值 @param string $offset @return mixed
[ "获取一个偏移位置的值" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L574-L579
echo58/sms
src/Message.php
Message.offsetSet
public function offsetSet($offset, $value) { if ($this->offsetExists($offset)) { $method = 'set'.static::formatOffset($offset); $this->{$method}($value); } }
php
public function offsetSet($offset, $value) { if ($this->offsetExists($offset)) { $method = 'set'.static::formatOffset($offset); $this->{$method}($value); } }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "offset", ")", ")", "{", "$", "method", "=", "'set'", ".", "static", "::", "formatOffset", "(", "$", "offset", ")", ";", "$", "this", "->", "{", "$", "method", "}", "(", "$", "value", ")", ";", "}", "}" ]
设置一个偏移位置的值 @param string $offset @param mixed $value
[ "设置一个偏移位置的值" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L587-L593
echo58/sms
src/Message.php
Message.offsetUnset
public function offsetUnset($offset) { if ($this->offsetExists($offset)) { $method = 'set'.static::formatOffset($offset); $this->{$method}(null); } }
php
public function offsetUnset($offset) { if ($this->offsetExists($offset)) { $method = 'set'.static::formatOffset($offset); $this->{$method}(null); } }
[ "public", "function", "offsetUnset", "(", "$", "offset", ")", "{", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "offset", ")", ")", "{", "$", "method", "=", "'set'", ".", "static", "::", "formatOffset", "(", "$", "offset", ")", ";", "$", "this", "->", "{", "$", "method", "}", "(", "null", ")", ";", "}", "}" ]
复位一个偏移位置的值 @param mixed $offset
[ "复位一个偏移位置的值" ]
train
https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/Message.php#L600-L606
php-lug/lug
src/Component/Translation/Factory/TranslatableFactory.php
TranslatableFactory.create
public function create(array $options = []) { return parent::create(array_merge($options, [ 'locales' => $this->localeContext->getLocales(), 'fallbackLocale' => $this->localeContext->getFallbackLocale(), 'translationFactory' => $this->translationFactory, ])); }
php
public function create(array $options = []) { return parent::create(array_merge($options, [ 'locales' => $this->localeContext->getLocales(), 'fallbackLocale' => $this->localeContext->getFallbackLocale(), 'translationFactory' => $this->translationFactory, ])); }
[ "public", "function", "create", "(", "array", "$", "options", "=", "[", "]", ")", "{", "return", "parent", "::", "create", "(", "array_merge", "(", "$", "options", ",", "[", "'locales'", "=>", "$", "this", "->", "localeContext", "->", "getLocales", "(", ")", ",", "'fallbackLocale'", "=>", "$", "this", "->", "localeContext", "->", "getFallbackLocale", "(", ")", ",", "'translationFactory'", "=>", "$", "this", "->", "translationFactory", ",", "]", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Translation/Factory/TranslatableFactory.php#L57-L64
expectation-php/expect
src/package/DefaultMatcherPackage.php
DefaultMatcherPackage.registerTo
public function registerTo(MatcherRegistry $registry) { $matcherPackage = new MatcherPackage( $this->matcherNamespace, $this->matcherDirectory ); $matcherPackage->registerTo($registry); }
php
public function registerTo(MatcherRegistry $registry) { $matcherPackage = new MatcherPackage( $this->matcherNamespace, $this->matcherDirectory ); $matcherPackage->registerTo($registry); }
[ "public", "function", "registerTo", "(", "MatcherRegistry", "$", "registry", ")", "{", "$", "matcherPackage", "=", "new", "MatcherPackage", "(", "$", "this", "->", "matcherNamespace", ",", "$", "this", "->", "matcherDirectory", ")", ";", "$", "matcherPackage", "->", "registerTo", "(", "$", "registry", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/package/DefaultMatcherPackage.php#L47-L54
spiral-modules/listing
source/Listing/Filters/ComplexFilter.php
ComplexFilter.withValue
public function withValue($value) { $value = trim((string)$value); if (!$this->isApplicable($value)) { throw new FilterException("Invalid filter value, '" . $value . "' given"); } $filter = clone $this; $filter->filter = $value; return $filter; }
php
public function withValue($value) { $value = trim((string)$value); if (!$this->isApplicable($value)) { throw new FilterException("Invalid filter value, '" . $value . "' given"); } $filter = clone $this; $filter->filter = $value; return $filter; }
[ "public", "function", "withValue", "(", "$", "value", ")", "{", "$", "value", "=", "trim", "(", "(", "string", ")", "$", "value", ")", ";", "if", "(", "!", "$", "this", "->", "isApplicable", "(", "$", "value", ")", ")", "{", "throw", "new", "FilterException", "(", "\"Invalid filter value, '\"", ".", "$", "value", ".", "\"' given\"", ")", ";", "}", "$", "filter", "=", "clone", "$", "this", ";", "$", "filter", "->", "filter", "=", "$", "value", ";", "return", "$", "filter", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Filters/ComplexFilter.php#L43-L55
HedronDev/hedron
src/Parser/BaseParser.php
BaseParser.getClientDirectoryName
protected function getClientDirectoryName() { return strtolower($this->getEnvironment()->getClient()) . '-' . strtolower($this->getEnvironment()->getName()) . '-' . $this->getConfiguration()->getBranch(); }
php
protected function getClientDirectoryName() { return strtolower($this->getEnvironment()->getClient()) . '-' . strtolower($this->getEnvironment()->getName()) . '-' . $this->getConfiguration()->getBranch(); }
[ "protected", "function", "getClientDirectoryName", "(", ")", "{", "return", "strtolower", "(", "$", "this", "->", "getEnvironment", "(", ")", "->", "getClient", "(", ")", ")", ".", "'-'", ".", "strtolower", "(", "$", "this", "->", "getEnvironment", "(", ")", "->", "getName", "(", ")", ")", ".", "'-'", ".", "$", "this", "->", "getConfiguration", "(", ")", "->", "getBranch", "(", ")", ";", "}" ]
The client directory in {client}-{branch} format. @return string The client directory name.
[ "The", "client", "directory", "in", "{", "client", "}", "-", "{", "branch", "}", "format", "." ]
train
https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Parser/BaseParser.php#L99-L101
HedronDev/hedron
src/Parser/BaseParser.php
BaseParser.getDataDirectoryPath
protected function getDataDirectoryPath() { $data_dir = $this->getEnvironment()->getDataDirectory(); $config = $this->getConfiguration(); return str_replace('{branch}', $config->getBranch(), $data_dir); }
php
protected function getDataDirectoryPath() { $data_dir = $this->getEnvironment()->getDataDirectory(); $config = $this->getConfiguration(); return str_replace('{branch}', $config->getBranch(), $data_dir); }
[ "protected", "function", "getDataDirectoryPath", "(", ")", "{", "$", "data_dir", "=", "$", "this", "->", "getEnvironment", "(", ")", "->", "getDataDirectory", "(", ")", ";", "$", "config", "=", "$", "this", "->", "getConfiguration", "(", ")", ";", "return", "str_replace", "(", "'{branch}'", ",", "$", "config", "->", "getBranch", "(", ")", ",", "$", "data_dir", ")", ";", "}" ]
The absolute path of the client site data directory. @return string The absolute path of the client site data directory.
[ "The", "absolute", "path", "of", "the", "client", "site", "data", "directory", "." ]
train
https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Parser/BaseParser.php#L119-L123
giftcards/Encryption
Cipher/MysqlAes.php
MysqlAes.mysqlAesKey
protected function mysqlAesKey($key) { $newKey = str_repeat(chr(0), 16); for ($i = 0, $len = strlen($key); $i < $len; $i++) { $newKey[$i % 16] = $newKey[$i % 16] ^ $key[$i]; } return $newKey; }
php
protected function mysqlAesKey($key) { $newKey = str_repeat(chr(0), 16); for ($i = 0, $len = strlen($key); $i < $len; $i++) { $newKey[$i % 16] = $newKey[$i % 16] ^ $key[$i]; } return $newKey; }
[ "protected", "function", "mysqlAesKey", "(", "$", "key", ")", "{", "$", "newKey", "=", "str_repeat", "(", "chr", "(", "0", ")", ",", "16", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "len", "=", "strlen", "(", "$", "key", ")", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "$", "newKey", "[", "$", "i", "%", "16", "]", "=", "$", "newKey", "[", "$", "i", "%", "16", "]", "^", "$", "key", "[", "$", "i", "]", ";", "}", "return", "$", "newKey", ";", "}" ]
Converts the key into the MySQL equivalent version @param $key @return string
[ "Converts", "the", "key", "into", "the", "MySQL", "equivalent", "version" ]
train
https://github.com/giftcards/Encryption/blob/a48f92408538e2ffe1c8603f168d57803aad7100/Cipher/MysqlAes.php#L61-L70
Smile-SA/EzUICronBundle
DependencyInjection/SmileEzUICronExtension.php
SmileEzUICronExtension.prepend
public function prepend(ContainerBuilder $container) { $container->prependExtensionConfig('assetic', array('bundles' => array('SmileEzUICronBundle'))); $this->prependYui($container); $this->prependCss($container); }
php
public function prepend(ContainerBuilder $container) { $container->prependExtensionConfig('assetic', array('bundles' => array('SmileEzUICronBundle'))); $this->prependYui($container); $this->prependCss($container); }
[ "public", "function", "prepend", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "container", "->", "prependExtensionConfig", "(", "'assetic'", ",", "array", "(", "'bundles'", "=>", "array", "(", "'SmileEzUICronBundle'", ")", ")", ")", ";", "$", "this", "->", "prependYui", "(", "$", "container", ")", ";", "$", "this", "->", "prependCss", "(", "$", "container", ")", ";", "}" ]
Prepend settings @param ContainerBuilder $container
[ "Prepend", "settings" ]
train
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/DependencyInjection/SmileEzUICronExtension.php#L35-L41
Smile-SA/EzUICronBundle
DependencyInjection/SmileEzUICronExtension.php
SmileEzUICronExtension.prependYui
private function prependYui(ContainerBuilder $container) { $container->setParameter( 'smile_ez_uicron.public_dir', 'bundles/smileezuicron' ); $yuiConfigFile = __DIR__ . '/../Resources/config/yui.yml'; $config = Yaml::parse(file_get_contents($yuiConfigFile)); $container->prependExtensionConfig('ez_platformui', $config); $container->addResource(new FileResource($yuiConfigFile)); }
php
private function prependYui(ContainerBuilder $container) { $container->setParameter( 'smile_ez_uicron.public_dir', 'bundles/smileezuicron' ); $yuiConfigFile = __DIR__ . '/../Resources/config/yui.yml'; $config = Yaml::parse(file_get_contents($yuiConfigFile)); $container->prependExtensionConfig('ez_platformui', $config); $container->addResource(new FileResource($yuiConfigFile)); }
[ "private", "function", "prependYui", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "container", "->", "setParameter", "(", "'smile_ez_uicron.public_dir'", ",", "'bundles/smileezuicron'", ")", ";", "$", "yuiConfigFile", "=", "__DIR__", ".", "'/../Resources/config/yui.yml'", ";", "$", "config", "=", "Yaml", "::", "parse", "(", "file_get_contents", "(", "$", "yuiConfigFile", ")", ")", ";", "$", "container", "->", "prependExtensionConfig", "(", "'ez_platformui'", ",", "$", "config", ")", ";", "$", "container", "->", "addResource", "(", "new", "FileResource", "(", "$", "yuiConfigFile", ")", ")", ";", "}" ]
Prepend ezplatform yui interface plugin @param ContainerBuilder $container
[ "Prepend", "ezplatform", "yui", "interface", "plugin" ]
train
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/DependencyInjection/SmileEzUICronExtension.php#L48-L58
Smile-SA/EzUICronBundle
DependencyInjection/SmileEzUICronExtension.php
SmileEzUICronExtension.prependCss
private function prependCss(ContainerBuilder $container) { $container->setParameter( 'smile_ez_uicron.css_dir', 'bundles/smileezuicron/css' ); $cssConfigFile = __DIR__ . '/../Resources/config/css.yml'; $config = Yaml::parse(file_get_contents($cssConfigFile)); $container->prependExtensionConfig('ez_platformui', $config); $container->addResource(new FileResource($cssConfigFile)); }
php
private function prependCss(ContainerBuilder $container) { $container->setParameter( 'smile_ez_uicron.css_dir', 'bundles/smileezuicron/css' ); $cssConfigFile = __DIR__ . '/../Resources/config/css.yml'; $config = Yaml::parse(file_get_contents($cssConfigFile)); $container->prependExtensionConfig('ez_platformui', $config); $container->addResource(new FileResource($cssConfigFile)); }
[ "private", "function", "prependCss", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "container", "->", "setParameter", "(", "'smile_ez_uicron.css_dir'", ",", "'bundles/smileezuicron/css'", ")", ";", "$", "cssConfigFile", "=", "__DIR__", ".", "'/../Resources/config/css.yml'", ";", "$", "config", "=", "Yaml", "::", "parse", "(", "file_get_contents", "(", "$", "cssConfigFile", ")", ")", ";", "$", "container", "->", "prependExtensionConfig", "(", "'ez_platformui'", ",", "$", "config", ")", ";", "$", "container", "->", "addResource", "(", "new", "FileResource", "(", "$", "cssConfigFile", ")", ")", ";", "}" ]
Prepend ezplatform css interface plugin @param ContainerBuilder $container
[ "Prepend", "ezplatform", "css", "interface", "plugin" ]
train
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/DependencyInjection/SmileEzUICronExtension.php#L65-L75
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/text.php
ezcMailText.generateHeaders
public function generateHeaders() { $this->setHeader( "Content-Type", "text/" . $this->subType . "; charset=" . $this->charset ); $this->setHeader( "Content-Transfer-Encoding", $this->encoding ); return parent::generateHeaders(); }
php
public function generateHeaders() { $this->setHeader( "Content-Type", "text/" . $this->subType . "; charset=" . $this->charset ); $this->setHeader( "Content-Transfer-Encoding", $this->encoding ); return parent::generateHeaders(); }
[ "public", "function", "generateHeaders", "(", ")", "{", "$", "this", "->", "setHeader", "(", "\"Content-Type\"", ",", "\"text/\"", ".", "$", "this", "->", "subType", ".", "\"; charset=\"", ".", "$", "this", "->", "charset", ")", ";", "$", "this", "->", "setHeader", "(", "\"Content-Transfer-Encoding\"", ",", "$", "this", "->", "encoding", ")", ";", "return", "parent", "::", "generateHeaders", "(", ")", ";", "}" ]
Returns the headers set for this part as a RFC822 compliant string. This method does not add the required two lines of space to separate the headers from the body of the part. @see setHeader() @return string
[ "Returns", "the", "headers", "set", "for", "this", "part", "as", "a", "RFC822", "compliant", "string", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/text.php#L155-L160
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/text.php
ezcMailText.generateBody
public function generateBody() { switch ( $this->encoding ) { case ezcMail::BASE64: // leaves a \r\n to much at the end, but since it is base64 it will decode // properly so we just leave it return chunk_split( base64_encode( $this->text ), 76, ezcMailTools::lineBreak() ); break; case ezcMail::QUOTED_PRINTABLE: $text = preg_replace( '/[^\x21-\x3C\x3E-\x7E\x09\x20]/e', 'sprintf( "=%02X", ord ( "$0" ) ) ;', $this->text ); preg_match_all( '/.{1,73}([^=]{0,2})?/', $text, $match ); $text = implode( '=' . ezcMailTools::lineBreak(), $match[0] ); return $text; break; default: return preg_replace( "/\r\n|\r|\n/", ezcMailTools::lineBreak(), $this->text ); } }
php
public function generateBody() { switch ( $this->encoding ) { case ezcMail::BASE64: // leaves a \r\n to much at the end, but since it is base64 it will decode // properly so we just leave it return chunk_split( base64_encode( $this->text ), 76, ezcMailTools::lineBreak() ); break; case ezcMail::QUOTED_PRINTABLE: $text = preg_replace( '/[^\x21-\x3C\x3E-\x7E\x09\x20]/e', 'sprintf( "=%02X", ord ( "$0" ) ) ;', $this->text ); preg_match_all( '/.{1,73}([^=]{0,2})?/', $text, $match ); $text = implode( '=' . ezcMailTools::lineBreak(), $match[0] ); return $text; break; default: return preg_replace( "/\r\n|\r|\n/", ezcMailTools::lineBreak(), $this->text ); } }
[ "public", "function", "generateBody", "(", ")", "{", "switch", "(", "$", "this", "->", "encoding", ")", "{", "case", "ezcMail", "::", "BASE64", ":", "// leaves a \\r\\n to much at the end, but since it is base64 it will decode", "// properly so we just leave it", "return", "chunk_split", "(", "base64_encode", "(", "$", "this", "->", "text", ")", ",", "76", ",", "ezcMailTools", "::", "lineBreak", "(", ")", ")", ";", "break", ";", "case", "ezcMail", "::", "QUOTED_PRINTABLE", ":", "$", "text", "=", "preg_replace", "(", "'/[^\\x21-\\x3C\\x3E-\\x7E\\x09\\x20]/e'", ",", "'sprintf( \"=%02X\", ord ( \"$0\" ) ) ;'", ",", "$", "this", "->", "text", ")", ";", "preg_match_all", "(", "'/.{1,73}([^=]{0,2})?/'", ",", "$", "text", ",", "$", "match", ")", ";", "$", "text", "=", "implode", "(", "'='", ".", "ezcMailTools", "::", "lineBreak", "(", ")", ",", "$", "match", "[", "0", "]", ")", ";", "return", "$", "text", ";", "break", ";", "default", ":", "return", "preg_replace", "(", "\"/\\r\\n|\\r|\\n/\"", ",", "ezcMailTools", "::", "lineBreak", "(", ")", ",", "$", "this", "->", "text", ")", ";", "}", "}" ]
Returns the generated text body of this part as a string. @return string
[ "Returns", "the", "generated", "text", "body", "of", "this", "part", "as", "a", "string", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/text.php#L167-L186
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Scrybe/Command/Manual/BaseConvertCommand.php
BaseConvertCommand.buildCollection
protected function buildCollection(array $sources, array $extensions) { $collection = new Collection(); $collection->setAllowedExtensions($extensions); foreach ($sources as $path) { if (is_dir($path)) { $collection->addDirectory($path); continue; } $collection->addFile($path); } return $collection; }
php
protected function buildCollection(array $sources, array $extensions) { $collection = new Collection(); $collection->setAllowedExtensions($extensions); foreach ($sources as $path) { if (is_dir($path)) { $collection->addDirectory($path); continue; } $collection->addFile($path); } return $collection; }
[ "protected", "function", "buildCollection", "(", "array", "$", "sources", ",", "array", "$", "extensions", ")", "{", "$", "collection", "=", "new", "Collection", "(", ")", ";", "$", "collection", "->", "setAllowedExtensions", "(", "$", "extensions", ")", ";", "foreach", "(", "$", "sources", "as", "$", "path", ")", "{", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "$", "collection", "->", "addDirectory", "(", "$", "path", ")", ";", "continue", ";", "}", "$", "collection", "->", "addFile", "(", "$", "path", ")", ";", "}", "return", "$", "collection", ";", "}" ]
Constructs a Fileset collection and returns that. @param array $sources List of source paths. @param array $extensions List of extensions to scan for in directories. @return Collection
[ "Constructs", "a", "Fileset", "collection", "and", "returns", "that", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Command/Manual/BaseConvertCommand.php#L195-L209
simbiosis-group/yii2-helper
widgets/ModalForm.php
ModalForm.init
public function init() { parent::init(); if ($this->hasHint) { $this->getView()->registerJs(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/js/modal-hint.js'))); $this->getView()->registerCss(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/css/hint.css'))); } $this->getView()->registerJs(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/js/modal-submit.js'))); $this->getView()->registerCss(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/css/select2.css'))); }
php
public function init() { parent::init(); if ($this->hasHint) { $this->getView()->registerJs(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/js/modal-hint.js'))); $this->getView()->registerCss(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/css/hint.css'))); } $this->getView()->registerJs(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/js/modal-submit.js'))); $this->getView()->registerCss(file_get_contents(Yii::getAlias('@vendor/anli/yii2-helper/css/select2.css'))); }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "if", "(", "$", "this", "->", "hasHint", ")", "{", "$", "this", "->", "getView", "(", ")", "->", "registerJs", "(", "file_get_contents", "(", "Yii", "::", "getAlias", "(", "'@vendor/anli/yii2-helper/js/modal-hint.js'", ")", ")", ")", ";", "$", "this", "->", "getView", "(", ")", "->", "registerCss", "(", "file_get_contents", "(", "Yii", "::", "getAlias", "(", "'@vendor/anli/yii2-helper/css/hint.css'", ")", ")", ")", ";", "}", "$", "this", "->", "getView", "(", ")", "->", "registerJs", "(", "file_get_contents", "(", "Yii", "::", "getAlias", "(", "'@vendor/anli/yii2-helper/js/modal-submit.js'", ")", ")", ")", ";", "$", "this", "->", "getView", "(", ")", "->", "registerCss", "(", "file_get_contents", "(", "Yii", "::", "getAlias", "(", "'@vendor/anli/yii2-helper/css/select2.css'", ")", ")", ")", ";", "}" ]
Initializes the widget.
[ "Initializes", "the", "widget", "." ]
train
https://github.com/simbiosis-group/yii2-helper/blob/c85c4204dd06b16e54210e75fe6deb51869d1dd9/widgets/ModalForm.php#L29-L40
tequila/mongodb-odm
src/Proxy/Generator/AbstractGenerator.php
AbstractGenerator.generateClass
public function generateClass(): ClassGenerator { $interfaces = $this->getInterfaces(); foreach ($interfaces as $interface) { $this->classGenerator->addUse($interface); } $this->classGenerator->setImplementedInterfaces($interfaces); $traits = $this->getTraits(); foreach ($traits as $trait) { $this->classGenerator->addUse($trait); $this->classGenerator->addTrait((new \ReflectionClass($trait))->getShortName()); } foreach ($this->metadata->getFieldsMetadata() as $fieldMetadata) { $fieldMetadata->generateProxy($this); } $this->generateBsonUnserializeMethod(); return $this->classGenerator; }
php
public function generateClass(): ClassGenerator { $interfaces = $this->getInterfaces(); foreach ($interfaces as $interface) { $this->classGenerator->addUse($interface); } $this->classGenerator->setImplementedInterfaces($interfaces); $traits = $this->getTraits(); foreach ($traits as $trait) { $this->classGenerator->addUse($trait); $this->classGenerator->addTrait((new \ReflectionClass($trait))->getShortName()); } foreach ($this->metadata->getFieldsMetadata() as $fieldMetadata) { $fieldMetadata->generateProxy($this); } $this->generateBsonUnserializeMethod(); return $this->classGenerator; }
[ "public", "function", "generateClass", "(", ")", ":", "ClassGenerator", "{", "$", "interfaces", "=", "$", "this", "->", "getInterfaces", "(", ")", ";", "foreach", "(", "$", "interfaces", "as", "$", "interface", ")", "{", "$", "this", "->", "classGenerator", "->", "addUse", "(", "$", "interface", ")", ";", "}", "$", "this", "->", "classGenerator", "->", "setImplementedInterfaces", "(", "$", "interfaces", ")", ";", "$", "traits", "=", "$", "this", "->", "getTraits", "(", ")", ";", "foreach", "(", "$", "traits", "as", "$", "trait", ")", "{", "$", "this", "->", "classGenerator", "->", "addUse", "(", "$", "trait", ")", ";", "$", "this", "->", "classGenerator", "->", "addTrait", "(", "(", "new", "\\", "ReflectionClass", "(", "$", "trait", ")", ")", "->", "getShortName", "(", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "metadata", "->", "getFieldsMetadata", "(", ")", "as", "$", "fieldMetadata", ")", "{", "$", "fieldMetadata", "->", "generateProxy", "(", "$", "this", ")", ";", "}", "$", "this", "->", "generateBsonUnserializeMethod", "(", ")", ";", "return", "$", "this", "->", "classGenerator", ";", "}" ]
@return ClassGenerator @throws \ReflectionException
[ "@return", "ClassGenerator" ]
train
https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/Proxy/Generator/AbstractGenerator.php#L128-L149
gregoryv/php-logger
src/CachedWriter.php
CachedWriter.swrite
public function swrite($severity, $value='') { if(sizeof($this->cache) == $this->messageLimit) { array_shift($this->cache); } $this->cache[] = $value; }
php
public function swrite($severity, $value='') { if(sizeof($this->cache) == $this->messageLimit) { array_shift($this->cache); } $this->cache[] = $value; }
[ "public", "function", "swrite", "(", "$", "severity", ",", "$", "value", "=", "''", ")", "{", "if", "(", "sizeof", "(", "$", "this", "->", "cache", ")", "==", "$", "this", "->", "messageLimit", ")", "{", "array_shift", "(", "$", "this", "->", "cache", ")", ";", "}", "$", "this", "->", "cache", "[", "]", "=", "$", "value", ";", "}" ]
Stores messages in the public cache by priority
[ "Stores", "messages", "in", "the", "public", "cache", "by", "priority" ]
train
https://github.com/gregoryv/php-logger/blob/0f8ffc360a0233531a9775359929af8876997862/src/CachedWriter.php#L29-L35
ShaoZeMing/laravel-merchant
src/Grid.php
Grid.registerColumnDisplayer
public static function registerColumnDisplayer() { $map = [ 'editable' => \ShaoZeMing\Merchant\Grid\Displayers\Editable::class, 'switch' => \ShaoZeMing\Merchant\Grid\Displayers\SwitchDisplay::class, 'switchGroup' => \ShaoZeMing\Merchant\Grid\Displayers\SwitchGroup::class, 'select' => \ShaoZeMing\Merchant\Grid\Displayers\Select::class, 'image' => \ShaoZeMing\Merchant\Grid\Displayers\Image::class, 'label' => \ShaoZeMing\Merchant\Grid\Displayers\Label::class, 'button' => \ShaoZeMing\Merchant\Grid\Displayers\Button::class, 'link' => \ShaoZeMing\Merchant\Grid\Displayers\Link::class, 'badge' => \ShaoZeMing\Merchant\Grid\Displayers\Badge::class, 'progressBar' => \ShaoZeMing\Merchant\Grid\Displayers\ProgressBar::class, 'radio' => \ShaoZeMing\Merchant\Grid\Displayers\Radio::class, 'checkbox' => \ShaoZeMing\Merchant\Grid\Displayers\Checkbox::class, 'orderable' => \ShaoZeMing\Merchant\Grid\Displayers\Orderable::class, ]; foreach ($map as $abstract => $class) { Column::extend($abstract, $class); } }
php
public static function registerColumnDisplayer() { $map = [ 'editable' => \ShaoZeMing\Merchant\Grid\Displayers\Editable::class, 'switch' => \ShaoZeMing\Merchant\Grid\Displayers\SwitchDisplay::class, 'switchGroup' => \ShaoZeMing\Merchant\Grid\Displayers\SwitchGroup::class, 'select' => \ShaoZeMing\Merchant\Grid\Displayers\Select::class, 'image' => \ShaoZeMing\Merchant\Grid\Displayers\Image::class, 'label' => \ShaoZeMing\Merchant\Grid\Displayers\Label::class, 'button' => \ShaoZeMing\Merchant\Grid\Displayers\Button::class, 'link' => \ShaoZeMing\Merchant\Grid\Displayers\Link::class, 'badge' => \ShaoZeMing\Merchant\Grid\Displayers\Badge::class, 'progressBar' => \ShaoZeMing\Merchant\Grid\Displayers\ProgressBar::class, 'radio' => \ShaoZeMing\Merchant\Grid\Displayers\Radio::class, 'checkbox' => \ShaoZeMing\Merchant\Grid\Displayers\Checkbox::class, 'orderable' => \ShaoZeMing\Merchant\Grid\Displayers\Orderable::class, ]; foreach ($map as $abstract => $class) { Column::extend($abstract, $class); } }
[ "public", "static", "function", "registerColumnDisplayer", "(", ")", "{", "$", "map", "=", "[", "'editable'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Editable", "::", "class", ",", "'switch'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "SwitchDisplay", "::", "class", ",", "'switchGroup'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "SwitchGroup", "::", "class", ",", "'select'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Select", "::", "class", ",", "'image'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Image", "::", "class", ",", "'label'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Label", "::", "class", ",", "'button'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Button", "::", "class", ",", "'link'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Link", "::", "class", ",", "'badge'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Badge", "::", "class", ",", "'progressBar'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "ProgressBar", "::", "class", ",", "'radio'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Radio", "::", "class", ",", "'checkbox'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Checkbox", "::", "class", ",", "'orderable'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Grid", "\\", "Displayers", "\\", "Orderable", "::", "class", ",", "]", ";", "foreach", "(", "$", "map", "as", "$", "abstract", "=>", "$", "class", ")", "{", "Column", "::", "extend", "(", "$", "abstract", ",", "$", "class", ")", ";", "}", "}" ]
Register column displayers. @return void.
[ "Register", "column", "displayers", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Grid.php#L895-L916
caffeinated/beverage
src/ConsoleServiceProvider.php
ConsoleServiceProvider.register
public function register() { $errorMsg = "Your ConsoleServiceProvider(AbstractConsoleProvider) requires property"; if (! isset($this->namespace) or ! is_string($this->namespace)) { throw new ErrorException("$errorMsg \$namespace to be an string"); } if (! isset($this->commands) or ! is_array($this->commands)) { throw new ErrorException("$errorMsg \$commands to be an array"); } $bindings = [ ]; foreach ($this->commands as $binding => $command) { $binding = $this->prefix . $binding; $bindings[] = $binding; $this->{"registerCommand"}($binding, $command); } $this->commands($bindings); }
php
public function register() { $errorMsg = "Your ConsoleServiceProvider(AbstractConsoleProvider) requires property"; if (! isset($this->namespace) or ! is_string($this->namespace)) { throw new ErrorException("$errorMsg \$namespace to be an string"); } if (! isset($this->commands) or ! is_array($this->commands)) { throw new ErrorException("$errorMsg \$commands to be an array"); } $bindings = [ ]; foreach ($this->commands as $binding => $command) { $binding = $this->prefix . $binding; $bindings[] = $binding; $this->{"registerCommand"}($binding, $command); } $this->commands($bindings); }
[ "public", "function", "register", "(", ")", "{", "$", "errorMsg", "=", "\"Your ConsoleServiceProvider(AbstractConsoleProvider) requires property\"", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "namespace", ")", "or", "!", "is_string", "(", "$", "this", "->", "namespace", ")", ")", "{", "throw", "new", "ErrorException", "(", "\"$errorMsg \\$namespace to be an string\"", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "commands", ")", "or", "!", "is_array", "(", "$", "this", "->", "commands", ")", ")", "{", "throw", "new", "ErrorException", "(", "\"$errorMsg \\$commands to be an array\"", ")", ";", "}", "$", "bindings", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "commands", "as", "$", "binding", "=>", "$", "command", ")", "{", "$", "binding", "=", "$", "this", "->", "prefix", ".", "$", "binding", ";", "$", "bindings", "[", "]", "=", "$", "binding", ";", "$", "this", "->", "{", "\"registerCommand\"", "}", "(", "$", "binding", ",", "$", "command", ")", ";", "}", "$", "this", "->", "commands", "(", "$", "bindings", ")", ";", "}" ]
Register the service provider. @throws ErrorException
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/ConsoleServiceProvider.php#L53-L71
caffeinated/beverage
src/ConsoleServiceProvider.php
ConsoleServiceProvider.registerCommand
protected function registerCommand($binding, $command) { $class = $this->namespace . '\\' . $command . 'Command'; if (! class_exists($class)) { throw new ErrorException("Your ConsoleServiceProvider(AbstractConsoleProvider)->registerCommand($command, $binding) could not find $class"); } $this->app->singleton($binding, $class); }
php
protected function registerCommand($binding, $command) { $class = $this->namespace . '\\' . $command . 'Command'; if (! class_exists($class)) { throw new ErrorException("Your ConsoleServiceProvider(AbstractConsoleProvider)->registerCommand($command, $binding) could not find $class"); } $this->app->singleton($binding, $class); }
[ "protected", "function", "registerCommand", "(", "$", "binding", ",", "$", "command", ")", "{", "$", "class", "=", "$", "this", "->", "namespace", ".", "'\\\\'", ".", "$", "command", ".", "'Command'", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "ErrorException", "(", "\"Your ConsoleServiceProvider(AbstractConsoleProvider)->registerCommand($command, $binding) could not find $class\"", ")", ";", "}", "$", "this", "->", "app", "->", "singleton", "(", "$", "binding", ",", "$", "class", ")", ";", "}" ]
Register the command. @param $command @param $binding @throws ErrorException
[ "Register", "the", "command", "." ]
train
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/ConsoleServiceProvider.php#L80-L87
openclerk/db
src/ReplicatedConnection.php
ReplicatedConnection.shouldUseMaster
function shouldUseMaster($query) { if (defined('USE_MASTER_DB') && USE_MASTER_DB) { return true; } if ($this->isWriteQuery($query)) { return true; } foreach ($_SESSION['master_slave_data'] as $table => $last_updated) { if ($this->queryUsesTable($query, $table)) { return true; } } return false; }
php
function shouldUseMaster($query) { if (defined('USE_MASTER_DB') && USE_MASTER_DB) { return true; } if ($this->isWriteQuery($query)) { return true; } foreach ($_SESSION['master_slave_data'] as $table => $last_updated) { if ($this->queryUsesTable($query, $table)) { return true; } } return false; }
[ "function", "shouldUseMaster", "(", "$", "query", ")", "{", "if", "(", "defined", "(", "'USE_MASTER_DB'", ")", "&&", "USE_MASTER_DB", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", "isWriteQuery", "(", "$", "query", ")", ")", "{", "return", "true", ";", "}", "foreach", "(", "$", "_SESSION", "[", "'master_slave_data'", "]", "as", "$", "table", "=>", "$", "last_updated", ")", "{", "if", "(", "$", "this", "->", "queryUsesTable", "(", "$", "query", ",", "$", "table", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true if one of the following situations is true: - {@code USE_MASTER_DB} is defined and true - the query is a write query: {@link #isWriteQuery()} - this session has recently updated the table used in this query
[ "Returns", "true", "if", "one", "of", "the", "following", "situations", "is", "true", ":", "-", "{" ]
train
https://github.com/openclerk/db/blob/923275ed6e9414d8952585b77331c28dbd032bac/src/ReplicatedConnection.php#L73-L89
openclerk/db
src/ReplicatedConnection.php
ReplicatedConnection.isWriteQuery
static function isWriteQuery($query) { $q = " " . strtolower(preg_replace("/\\s/i", " ", $query)) . " "; return strpos($q, " update ") !== false || strpos($q, " insert ") !== false || strpos($q, " delete ") !== false || strpos($q, " create table ") !== false || strpos($q, " alter table ") !== false || strpos($q, " drop table ") !== false || strpos($q, " show tables ") !== false || strpos($q, " from migrations ") !== false; }
php
static function isWriteQuery($query) { $q = " " . strtolower(preg_replace("/\\s/i", " ", $query)) . " "; return strpos($q, " update ") !== false || strpos($q, " insert ") !== false || strpos($q, " delete ") !== false || strpos($q, " create table ") !== false || strpos($q, " alter table ") !== false || strpos($q, " drop table ") !== false || strpos($q, " show tables ") !== false || strpos($q, " from migrations ") !== false; }
[ "static", "function", "isWriteQuery", "(", "$", "query", ")", "{", "$", "q", "=", "\" \"", ".", "strtolower", "(", "preg_replace", "(", "\"/\\\\s/i\"", ",", "\" \"", ",", "$", "query", ")", ")", ".", "\" \"", ";", "return", "strpos", "(", "$", "q", ",", "\" update \"", ")", "!==", "false", "||", "strpos", "(", "$", "q", ",", "\" insert \"", ")", "!==", "false", "||", "strpos", "(", "$", "q", ",", "\" delete \"", ")", "!==", "false", "||", "strpos", "(", "$", "q", ",", "\" create table \"", ")", "!==", "false", "||", "strpos", "(", "$", "q", ",", "\" alter table \"", ")", "!==", "false", "||", "strpos", "(", "$", "q", ",", "\" drop table \"", ")", "!==", "false", "||", "strpos", "(", "$", "q", ",", "\" show tables \"", ")", "!==", "false", "||", "strpos", "(", "$", "q", ",", "\" from migrations \"", ")", "!==", "false", ";", "}" ]
NOTE this is a very simple implementation @return false if there is any chance the given query is a write (UPDATE, SELECT, INSERT) query.
[ "NOTE", "this", "is", "a", "very", "simple", "implementation" ]
train
https://github.com/openclerk/db/blob/923275ed6e9414d8952585b77331c28dbd032bac/src/ReplicatedConnection.php#L95-L105
openclerk/db
src/ReplicatedConnection.php
ReplicatedConnection.getTable
static function getTable($query) { if (!self::isWriteQuery($query)) { throw new DbException("Query '$query' is not a write query"); } $query = " " . strtolower(preg_replace("/\\s+/i", " ", $query)) . " "; if (preg_match("# (update|delete from|insert into|create table|alter table|drop table) ([^ ;]+)[ ;]#i", $query, $matches)) { return $matches[2]; } if (preg_match("# from migrations #i", $query, $matches)) { return "migrations"; } if (preg_match("# (show tables) #i", $query, $matches)) { return "global"; } throw new DbException("Could not identify table for query '$query'"); }
php
static function getTable($query) { if (!self::isWriteQuery($query)) { throw new DbException("Query '$query' is not a write query"); } $query = " " . strtolower(preg_replace("/\\s+/i", " ", $query)) . " "; if (preg_match("# (update|delete from|insert into|create table|alter table|drop table) ([^ ;]+)[ ;]#i", $query, $matches)) { return $matches[2]; } if (preg_match("# from migrations #i", $query, $matches)) { return "migrations"; } if (preg_match("# (show tables) #i", $query, $matches)) { return "global"; } throw new DbException("Could not identify table for query '$query'"); }
[ "static", "function", "getTable", "(", "$", "query", ")", "{", "if", "(", "!", "self", "::", "isWriteQuery", "(", "$", "query", ")", ")", "{", "throw", "new", "DbException", "(", "\"Query '$query' is not a write query\"", ")", ";", "}", "$", "query", "=", "\" \"", ".", "strtolower", "(", "preg_replace", "(", "\"/\\\\s+/i\"", ",", "\" \"", ",", "$", "query", ")", ")", ".", "\" \"", ";", "if", "(", "preg_match", "(", "\"# (update|delete from|insert into|create table|alter table|drop table) ([^ ;]+)[ ;]#i\"", ",", "$", "query", ",", "$", "matches", ")", ")", "{", "return", "$", "matches", "[", "2", "]", ";", "}", "if", "(", "preg_match", "(", "\"# from migrations #i\"", ",", "$", "query", ",", "$", "matches", ")", ")", "{", "return", "\"migrations\"", ";", "}", "if", "(", "preg_match", "(", "\"# (show tables) #i\"", ",", "$", "query", ",", "$", "matches", ")", ")", "{", "return", "\"global\"", ";", "}", "throw", "new", "DbException", "(", "\"Could not identify table for query '$query'\"", ")", ";", "}" ]
NOTE this is a very simple implementation @return the table name, in lowercase, from the given query @throws DbException if this is not a write query.
[ "NOTE", "this", "is", "a", "very", "simple", "implementation" ]
train
https://github.com/openclerk/db/blob/923275ed6e9414d8952585b77331c28dbd032bac/src/ReplicatedConnection.php#L112-L127
superjimpupcake/Pupcake
src/Pupcake/Plugin/Async/Main.php
Main.sendAsyncRequest
public function sendAsyncRequest( $request_type = 'GET', /* HTTP Request Method (GET and POST supported) */ $url, /* Full url (example: http://example.com/test */ $data = array(), /* HTTP GET or POST Data ie. array('var1' => 'val1', 'var2' => 'val2') */ $timeout = 3 /* Request timeout */ ) { $user_agent = $_SERVER['HTTP_USER_AGENT']; $port = 80; $schema = ""; //find the protocol $schema_pattern = substr($url, 0, 4); if ($schema_pattern != "http") { if ($url[0] == "/") { $url[0] = ""; $url =trim($url); } $server_protocol_comps = explode("/", strtolower($_SERVER['SERVER_PROTOCOL'])); $schema = $server_protocol_comps[0]; if ($schema == "https") { $port = 443; } } $host = $_SERVER['HTTP_HOST']; $url = $schema.":/".$host."/".$url; $url_parts = parse_url($url); if (isset($url_parts['path'])) { $uri = str_replace($host."/", "", $url_parts['path']); } //if the host has custom port number, override the default one if (isset($url_parts['port'])) { $port = $url_parts['port']; } $ret = ''; $request_type = strtoupper($request_type); //allow using lowercase in request type $getdata = array(); $postdata = array(); if ($request_type == 'GET') { $getdata = $data; } else if ($request_type == 'POST') { $postdata = $data; } $cookie = $_COOKIE; //preserve the cookie data $cookie_str = ''; $getdata_str = count($getdata) ? '?' : ''; $postdata_str = ''; foreach ($getdata as $k => $v) $getdata_str .= urlencode($k) .'='. urlencode($v) . '&'; foreach ($postdata as $k => $v) $postdata_str .= urlencode($k) .'='. urlencode($v) .'&'; foreach ($cookie as $k => $v) $cookie_str .= urlencode($k) .'='. urlencode($v) .'; '; $crlf = "\r\n"; $req = $request_type .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf; $req .= 'Host: '. $host . $crlf; $req .= 'User-Agent: '.$user_agent . $crlf; $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf; $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf; $req .= 'Accept-Encoding: deflate' . $crlf; $req .= 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' . $crlf; if (!empty($cookie_str)) $req .= 'Cookie: '. substr($cookie_str, 0, -2) . $crlf; if ($request_type == 'POST' && !empty($postdata_str)) { $postdata_str = substr($postdata_str, 0, -1); $req .= 'Content-Type: application/x-www-form-urlencoded' . $crlf; $req .= 'Content-Length: '. strlen($postdata_str) . $crlf . $crlf; $req .= $postdata_str; } else $req .= $crlf; if (($fp = @fsockopen($host, $port, $errno, $errstr)) == false) return "Error $errno: $errstr\n"; stream_set_timeout($fp, 0, $timeout * 1000); fputs($fp, $req); while ($line = fgets($fp)) $ret .= $line; fclose($fp); }
php
public function sendAsyncRequest( $request_type = 'GET', /* HTTP Request Method (GET and POST supported) */ $url, /* Full url (example: http://example.com/test */ $data = array(), /* HTTP GET or POST Data ie. array('var1' => 'val1', 'var2' => 'val2') */ $timeout = 3 /* Request timeout */ ) { $user_agent = $_SERVER['HTTP_USER_AGENT']; $port = 80; $schema = ""; //find the protocol $schema_pattern = substr($url, 0, 4); if ($schema_pattern != "http") { if ($url[0] == "/") { $url[0] = ""; $url =trim($url); } $server_protocol_comps = explode("/", strtolower($_SERVER['SERVER_PROTOCOL'])); $schema = $server_protocol_comps[0]; if ($schema == "https") { $port = 443; } } $host = $_SERVER['HTTP_HOST']; $url = $schema.":/".$host."/".$url; $url_parts = parse_url($url); if (isset($url_parts['path'])) { $uri = str_replace($host."/", "", $url_parts['path']); } //if the host has custom port number, override the default one if (isset($url_parts['port'])) { $port = $url_parts['port']; } $ret = ''; $request_type = strtoupper($request_type); //allow using lowercase in request type $getdata = array(); $postdata = array(); if ($request_type == 'GET') { $getdata = $data; } else if ($request_type == 'POST') { $postdata = $data; } $cookie = $_COOKIE; //preserve the cookie data $cookie_str = ''; $getdata_str = count($getdata) ? '?' : ''; $postdata_str = ''; foreach ($getdata as $k => $v) $getdata_str .= urlencode($k) .'='. urlencode($v) . '&'; foreach ($postdata as $k => $v) $postdata_str .= urlencode($k) .'='. urlencode($v) .'&'; foreach ($cookie as $k => $v) $cookie_str .= urlencode($k) .'='. urlencode($v) .'; '; $crlf = "\r\n"; $req = $request_type .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf; $req .= 'Host: '. $host . $crlf; $req .= 'User-Agent: '.$user_agent . $crlf; $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf; $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf; $req .= 'Accept-Encoding: deflate' . $crlf; $req .= 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' . $crlf; if (!empty($cookie_str)) $req .= 'Cookie: '. substr($cookie_str, 0, -2) . $crlf; if ($request_type == 'POST' && !empty($postdata_str)) { $postdata_str = substr($postdata_str, 0, -1); $req .= 'Content-Type: application/x-www-form-urlencoded' . $crlf; $req .= 'Content-Length: '. strlen($postdata_str) . $crlf . $crlf; $req .= $postdata_str; } else $req .= $crlf; if (($fp = @fsockopen($host, $port, $errno, $errstr)) == false) return "Error $errno: $errstr\n"; stream_set_timeout($fp, 0, $timeout * 1000); fputs($fp, $req); while ($line = fgets($fp)) $ret .= $line; fclose($fp); }
[ "public", "function", "sendAsyncRequest", "(", "$", "request_type", "=", "'GET'", ",", "/* HTTP Request Method (GET and POST supported) */", "$", "url", ",", "/* Full url (example: http://example.com/test */", "$", "data", "=", "array", "(", ")", ",", "/* HTTP GET or POST Data ie. array('var1' => 'val1', 'var2' => 'val2') */", "$", "timeout", "=", "3", "/* Request timeout */", ")", "{", "$", "user_agent", "=", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ";", "$", "port", "=", "80", ";", "$", "schema", "=", "\"\"", ";", "//find the protocol", "$", "schema_pattern", "=", "substr", "(", "$", "url", ",", "0", ",", "4", ")", ";", "if", "(", "$", "schema_pattern", "!=", "\"http\"", ")", "{", "if", "(", "$", "url", "[", "0", "]", "==", "\"/\"", ")", "{", "$", "url", "[", "0", "]", "=", "\"\"", ";", "$", "url", "=", "trim", "(", "$", "url", ")", ";", "}", "$", "server_protocol_comps", "=", "explode", "(", "\"/\"", ",", "strtolower", "(", "$", "_SERVER", "[", "'SERVER_PROTOCOL'", "]", ")", ")", ";", "$", "schema", "=", "$", "server_protocol_comps", "[", "0", "]", ";", "if", "(", "$", "schema", "==", "\"https\"", ")", "{", "$", "port", "=", "443", ";", "}", "}", "$", "host", "=", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ";", "$", "url", "=", "$", "schema", ".", "\":/\"", ".", "$", "host", ".", "\"/\"", ".", "$", "url", ";", "$", "url_parts", "=", "parse_url", "(", "$", "url", ")", ";", "if", "(", "isset", "(", "$", "url_parts", "[", "'path'", "]", ")", ")", "{", "$", "uri", "=", "str_replace", "(", "$", "host", ".", "\"/\"", ",", "\"\"", ",", "$", "url_parts", "[", "'path'", "]", ")", ";", "}", "//if the host has custom port number, override the default one", "if", "(", "isset", "(", "$", "url_parts", "[", "'port'", "]", ")", ")", "{", "$", "port", "=", "$", "url_parts", "[", "'port'", "]", ";", "}", "$", "ret", "=", "''", ";", "$", "request_type", "=", "strtoupper", "(", "$", "request_type", ")", ";", "//allow using lowercase in request type", "$", "getdata", "=", "array", "(", ")", ";", "$", "postdata", "=", "array", "(", ")", ";", "if", "(", "$", "request_type", "==", "'GET'", ")", "{", "$", "getdata", "=", "$", "data", ";", "}", "else", "if", "(", "$", "request_type", "==", "'POST'", ")", "{", "$", "postdata", "=", "$", "data", ";", "}", "$", "cookie", "=", "$", "_COOKIE", ";", "//preserve the cookie data", "$", "cookie_str", "=", "''", ";", "$", "getdata_str", "=", "count", "(", "$", "getdata", ")", "?", "'?'", ":", "''", ";", "$", "postdata_str", "=", "''", ";", "foreach", "(", "$", "getdata", "as", "$", "k", "=>", "$", "v", ")", "$", "getdata_str", ".=", "urlencode", "(", "$", "k", ")", ".", "'='", ".", "urlencode", "(", "$", "v", ")", ".", "'&'", ";", "foreach", "(", "$", "postdata", "as", "$", "k", "=>", "$", "v", ")", "$", "postdata_str", ".=", "urlencode", "(", "$", "k", ")", ".", "'='", ".", "urlencode", "(", "$", "v", ")", ".", "'&'", ";", "foreach", "(", "$", "cookie", "as", "$", "k", "=>", "$", "v", ")", "$", "cookie_str", ".=", "urlencode", "(", "$", "k", ")", ".", "'='", ".", "urlencode", "(", "$", "v", ")", ".", "'; '", ";", "$", "crlf", "=", "\"\\r\\n\"", ";", "$", "req", "=", "$", "request_type", ".", "' '", ".", "$", "uri", ".", "$", "getdata_str", ".", "' HTTP/1.1'", ".", "$", "crlf", ";", "$", "req", ".=", "'Host: '", ".", "$", "host", ".", "$", "crlf", ";", "$", "req", ".=", "'User-Agent: '", ".", "$", "user_agent", ".", "$", "crlf", ";", "$", "req", ".=", "'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'", ".", "$", "crlf", ";", "$", "req", ".=", "'Accept-Language: en-us,en;q=0.5'", ".", "$", "crlf", ";", "$", "req", ".=", "'Accept-Encoding: deflate'", ".", "$", "crlf", ";", "$", "req", ".=", "'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'", ".", "$", "crlf", ";", "if", "(", "!", "empty", "(", "$", "cookie_str", ")", ")", "$", "req", ".=", "'Cookie: '", ".", "substr", "(", "$", "cookie_str", ",", "0", ",", "-", "2", ")", ".", "$", "crlf", ";", "if", "(", "$", "request_type", "==", "'POST'", "&&", "!", "empty", "(", "$", "postdata_str", ")", ")", "{", "$", "postdata_str", "=", "substr", "(", "$", "postdata_str", ",", "0", ",", "-", "1", ")", ";", "$", "req", ".=", "'Content-Type: application/x-www-form-urlencoded'", ".", "$", "crlf", ";", "$", "req", ".=", "'Content-Length: '", ".", "strlen", "(", "$", "postdata_str", ")", ".", "$", "crlf", ".", "$", "crlf", ";", "$", "req", ".=", "$", "postdata_str", ";", "}", "else", "$", "req", ".=", "$", "crlf", ";", "if", "(", "(", "$", "fp", "=", "@", "fsockopen", "(", "$", "host", ",", "$", "port", ",", "$", "errno", ",", "$", "errstr", ")", ")", "==", "false", ")", "return", "\"Error $errno: $errstr\\n\"", ";", "stream_set_timeout", "(", "$", "fp", ",", "0", ",", "$", "timeout", "*", "1000", ")", ";", "fputs", "(", "$", "fp", ",", "$", "req", ")", ";", "while", "(", "$", "line", "=", "fgets", "(", "$", "fp", ")", ")", "$", "ret", ".=", "$", "line", ";", "fclose", "(", "$", "fp", ")", ";", "}" ]
make asynchronous request credit: http://www.php.net/manual/en/function.fsockopen.php#101872
[ "make", "asynchronous", "request", "credit", ":", "http", ":", "//", "www", ".", "php", ".", "net", "/", "manual", "/", "en", "/", "function", ".", "fsockopen", ".", "php#101872" ]
train
https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Plugin/Async/Main.php#L32-L130
ShaoZeMing/laravel-merchant
src/Grid/Displayers/Actions.php
Actions.deleteAction
protected function deleteAction() { $deleteConfirm = trans('merchant.delete_confirm'); $confirm = trans('merchant.confirm'); $cancel = trans('merchant.cancel'); $script = <<<SCRIPT $('.grid-row-delete').unbind('click').click(function() { var id = $(this).data('id'); swal({ title: "$deleteConfirm", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "$confirm", closeOnConfirm: false, cancelButtonText: "$cancel" }, function(){ $.ajax({ method: 'post', url: '{$this->getResource()}/' + id, data: { _method:'delete', _token:LA.token, }, success: function (data) { $.pjax.reload('#pjax-container'); if (typeof data === 'object') { if (data.status) { swal(data.message, '', 'success'); } else { swal(data.message, '', 'error'); } } } }); }); }); SCRIPT; Merchant::script($script); return <<<EOT <a href="javascript:void(0);" data-id="{$this->getKey()}" class="grid-row-delete"> <i class="fa fa-trash"></i> </a> EOT; }
php
protected function deleteAction() { $deleteConfirm = trans('merchant.delete_confirm'); $confirm = trans('merchant.confirm'); $cancel = trans('merchant.cancel'); $script = <<<SCRIPT $('.grid-row-delete').unbind('click').click(function() { var id = $(this).data('id'); swal({ title: "$deleteConfirm", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "$confirm", closeOnConfirm: false, cancelButtonText: "$cancel" }, function(){ $.ajax({ method: 'post', url: '{$this->getResource()}/' + id, data: { _method:'delete', _token:LA.token, }, success: function (data) { $.pjax.reload('#pjax-container'); if (typeof data === 'object') { if (data.status) { swal(data.message, '', 'success'); } else { swal(data.message, '', 'error'); } } } }); }); }); SCRIPT; Merchant::script($script); return <<<EOT <a href="javascript:void(0);" data-id="{$this->getKey()}" class="grid-row-delete"> <i class="fa fa-trash"></i> </a> EOT; }
[ "protected", "function", "deleteAction", "(", ")", "{", "$", "deleteConfirm", "=", "trans", "(", "'merchant.delete_confirm'", ")", ";", "$", "confirm", "=", "trans", "(", "'merchant.confirm'", ")", ";", "$", "cancel", "=", "trans", "(", "'merchant.cancel'", ")", ";", "$", "script", "=", " <<<SCRIPT\n\n$('.grid-row-delete').unbind('click').click(function() {\n\n var id = $(this).data('id');\n\n swal({\n title: \"$deleteConfirm\",\n type: \"warning\",\n showCancelButton: true,\n confirmButtonColor: \"#DD6B55\",\n confirmButtonText: \"$confirm\",\n closeOnConfirm: false,\n cancelButtonText: \"$cancel\"\n },\n function(){\n $.ajax({\n method: 'post',\n url: '{$this->getResource()}/' + id,\n data: {\n _method:'delete',\n _token:LA.token,\n },\n success: function (data) {\n $.pjax.reload('#pjax-container');\n\n if (typeof data === 'object') {\n if (data.status) {\n swal(data.message, '', 'success');\n } else {\n swal(data.message, '', 'error');\n }\n }\n }\n });\n });\n});\n\nSCRIPT", ";", "Merchant", "::", "script", "(", "$", "script", ")", ";", "return", " <<<EOT\n<a href=\"javascript:void(0);\" data-id=\"{$this->getKey()}\" class=\"grid-row-delete\">\n <i class=\"fa fa-trash\"></i>\n</a>\nEOT", ";", "}" ]
Built delete action. @return string
[ "Built", "delete", "action", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Grid/Displayers/Actions.php#L167-L220
zhouyl/mellivora
Mellivora/Support/Traits/CapsuleManagerTrait.php
CapsuleManagerTrait.setupContainer
protected function setupContainer(Container $container) { $this->container = $container; if (!$this->container->has('config')) { $this->container['config'] = new Fluent; } }
php
protected function setupContainer(Container $container) { $this->container = $container; if (!$this->container->has('config')) { $this->container['config'] = new Fluent; } }
[ "protected", "function", "setupContainer", "(", "Container", "$", "container", ")", "{", "$", "this", "->", "container", "=", "$", "container", ";", "if", "(", "!", "$", "this", "->", "container", "->", "has", "(", "'config'", ")", ")", "{", "$", "this", "->", "container", "[", "'config'", "]", "=", "new", "Fluent", ";", "}", "}" ]
Setup the IoC container instance. @param \Mellivora\Application\Container $container @return void
[ "Setup", "the", "IoC", "container", "instance", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Support/Traits/CapsuleManagerTrait.php#L24-L31
znck/countries
src/Country.php
Country.getNameAttribute
public function getNameAttribute(string $val) { if (static::$locale === 'en') { return $val; } $name = static::$countries->getName($this->code, static::$locale); if ($name === $this->code) { return $val; } return $name; }
php
public function getNameAttribute(string $val) { if (static::$locale === 'en') { return $val; } $name = static::$countries->getName($this->code, static::$locale); if ($name === $this->code) { return $val; } return $name; }
[ "public", "function", "getNameAttribute", "(", "string", "$", "val", ")", "{", "if", "(", "static", "::", "$", "locale", "===", "'en'", ")", "{", "return", "$", "val", ";", "}", "$", "name", "=", "static", "::", "$", "countries", "->", "getName", "(", "$", "this", "->", "code", ",", "static", "::", "$", "locale", ")", ";", "if", "(", "$", "name", "===", "$", "this", "->", "code", ")", "{", "return", "$", "val", ";", "}", "return", "$", "name", ";", "}" ]
@param string $val @return string
[ "@param", "string", "$val" ]
train
https://github.com/znck/countries/blob/a78a2b302dfa8eacab8fe0c06127dbb37fa98fd3/src/Country.php#L35-L48
DevGroup-ru/yii2-users-module
src/controllers/RbacManageController.php
RbacManageController.actionRemoveItems
public function actionRemoveItems() { if (false === Yii::$app->request->isAjax) { throw new NotFoundHttpException(Yii::t('users', 'Page not found')); } $type = Yii::$app->request->post('item-type', 0); self::checkPermissions($type); $items = Yii::$app->request->post('items', []); $authManager = Yii::$app->getAuthManager(); $removed = 0; foreach ($items as $item) { try { $authManager->remove(new Item(['name' => $item])); $removed++; } catch (\Exception $e) { Yii::$app->session->setFlash( 'warning', Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $item]) ); } } if (0 !== $removed) { Yii::$app->session->setFlash( 'info', Yii::t('users', "Items removed: {count}", ['count' => $removed]) ); } }
php
public function actionRemoveItems() { if (false === Yii::$app->request->isAjax) { throw new NotFoundHttpException(Yii::t('users', 'Page not found')); } $type = Yii::$app->request->post('item-type', 0); self::checkPermissions($type); $items = Yii::$app->request->post('items', []); $authManager = Yii::$app->getAuthManager(); $removed = 0; foreach ($items as $item) { try { $authManager->remove(new Item(['name' => $item])); $removed++; } catch (\Exception $e) { Yii::$app->session->setFlash( 'warning', Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $item]) ); } } if (0 !== $removed) { Yii::$app->session->setFlash( 'info', Yii::t('users', "Items removed: {count}", ['count' => $removed]) ); } }
[ "public", "function", "actionRemoveItems", "(", ")", "{", "if", "(", "false", "===", "Yii", "::", "$", "app", "->", "request", "->", "isAjax", ")", "{", "throw", "new", "NotFoundHttpException", "(", "Yii", "::", "t", "(", "'users'", ",", "'Page not found'", ")", ")", ";", "}", "$", "type", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'item-type'", ",", "0", ")", ";", "self", "::", "checkPermissions", "(", "$", "type", ")", ";", "$", "items", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'items'", ",", "[", "]", ")", ";", "$", "authManager", "=", "Yii", "::", "$", "app", "->", "getAuthManager", "(", ")", ";", "$", "removed", "=", "0", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "try", "{", "$", "authManager", "->", "remove", "(", "new", "Item", "(", "[", "'name'", "=>", "$", "item", "]", ")", ")", ";", "$", "removed", "++", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'warning'", ",", "Yii", "::", "t", "(", "'users'", ",", "\"Unknown RBAC item name '{name}'\"", ",", "[", "'name'", "=>", "$", "item", "]", ")", ")", ";", "}", "}", "if", "(", "0", "!==", "$", "removed", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'info'", ",", "Yii", "::", "t", "(", "'users'", ",", "\"Items removed: {count}\"", ",", "[", "'count'", "=>", "$", "removed", "]", ")", ")", ";", "}", "}" ]
Respond only on Ajax @throws NotFoundHttpException
[ "Respond", "only", "on", "Ajax" ]
train
https://github.com/DevGroup-ru/yii2-users-module/blob/ff0103dc55c3462627ccc704c33e70c96053f750/src/controllers/RbacManageController.php#L90-L117
DevGroup-ru/yii2-users-module
src/controllers/RbacManageController.php
RbacManageController.actionDelete
public function actionDelete($id, $type, $returnUrl = '') { self::checkPermissions($type); if (true === Yii::$app->getAuthManager()->remove(new Item(['name' => $id]))) { Yii::$app->session->setFlash( 'info', Yii::t('users', "Item successfully removed") ); } else { Yii::$app->session->setFlash( 'warning', Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $id]) ); } $returnUrl = empty($returnUrl) ? ['/users/rbac-manage/index', 'type' => $type] : $returnUrl; return $this->redirect($returnUrl); }
php
public function actionDelete($id, $type, $returnUrl = '') { self::checkPermissions($type); if (true === Yii::$app->getAuthManager()->remove(new Item(['name' => $id]))) { Yii::$app->session->setFlash( 'info', Yii::t('users', "Item successfully removed") ); } else { Yii::$app->session->setFlash( 'warning', Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $id]) ); } $returnUrl = empty($returnUrl) ? ['/users/rbac-manage/index', 'type' => $type] : $returnUrl; return $this->redirect($returnUrl); }
[ "public", "function", "actionDelete", "(", "$", "id", ",", "$", "type", ",", "$", "returnUrl", "=", "''", ")", "{", "self", "::", "checkPermissions", "(", "$", "type", ")", ";", "if", "(", "true", "===", "Yii", "::", "$", "app", "->", "getAuthManager", "(", ")", "->", "remove", "(", "new", "Item", "(", "[", "'name'", "=>", "$", "id", "]", ")", ")", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'info'", ",", "Yii", "::", "t", "(", "'users'", ",", "\"Item successfully removed\"", ")", ")", ";", "}", "else", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'warning'", ",", "Yii", "::", "t", "(", "'users'", ",", "\"Unknown RBAC item name '{name}'\"", ",", "[", "'name'", "=>", "$", "id", "]", ")", ")", ";", "}", "$", "returnUrl", "=", "empty", "(", "$", "returnUrl", ")", "?", "[", "'/users/rbac-manage/index'", ",", "'type'", "=>", "$", "type", "]", ":", "$", "returnUrl", ";", "return", "$", "this", "->", "redirect", "(", "$", "returnUrl", ")", ";", "}" ]
Deletes an existing RBAC Item model. @param integer $id @param $type @param string $returnUrl @return mixed @throws ForbiddenHttpException
[ "Deletes", "an", "existing", "RBAC", "Item", "model", "." ]
train
https://github.com/DevGroup-ru/yii2-users-module/blob/ff0103dc55c3462627ccc704c33e70c96053f750/src/controllers/RbacManageController.php#L128-L144
dave-redfern/somnambulist-value-objects
src/Types/DateTime/Traits/Comparable.php
Comparable.equals
public function equals($object): bool { if (get_class($object) !== get_class($this)) { return false; } return $this == $object; }
php
public function equals($object): bool { if (get_class($object) !== get_class($this)) { return false; } return $this == $object; }
[ "public", "function", "equals", "(", "$", "object", ")", ":", "bool", "{", "if", "(", "get_class", "(", "$", "object", ")", "!==", "get_class", "(", "$", "this", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "==", "$", "object", ";", "}" ]
@param mixed $object @return bool
[ "@param", "mixed", "$object" ]
train
https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Comparable.php#L39-L46
dave-redfern/somnambulist-value-objects
src/Types/DateTime/Traits/Comparable.php
Comparable.min
public function min(DateTime $dt = null) { $dt = $dt ?: static::now($this->timezone()); return $this->lt($dt) ? $this : $dt; }
php
public function min(DateTime $dt = null) { $dt = $dt ?: static::now($this->timezone()); return $this->lt($dt) ? $this : $dt; }
[ "public", "function", "min", "(", "DateTime", "$", "dt", "=", "null", ")", "{", "$", "dt", "=", "$", "dt", "?", ":", "static", "::", "now", "(", "$", "this", "->", "timezone", "(", ")", ")", ";", "return", "$", "this", "->", "lt", "(", "$", "dt", ")", "?", "$", "this", ":", "$", "dt", ";", "}" ]
Get the minimum instance between a given instance (default now) and the current instance. @param DateTime|null $dt @return static
[ "Get", "the", "minimum", "instance", "between", "a", "given", "instance", "(", "default", "now", ")", "and", "the", "current", "instance", "." ]
train
https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Comparable.php#L221-L226
dave-redfern/somnambulist-value-objects
src/Types/DateTime/Traits/Comparable.php
Comparable.max
public function max(DateTime $dt = null) { $dt = $dt ?: static::now($this->timezone()); return $this->gt($dt) ? $this : $dt; }
php
public function max(DateTime $dt = null) { $dt = $dt ?: static::now($this->timezone()); return $this->gt($dt) ? $this : $dt; }
[ "public", "function", "max", "(", "DateTime", "$", "dt", "=", "null", ")", "{", "$", "dt", "=", "$", "dt", "?", ":", "static", "::", "now", "(", "$", "this", "->", "timezone", "(", ")", ")", ";", "return", "$", "this", "->", "gt", "(", "$", "dt", ")", "?", "$", "this", ":", "$", "dt", ";", "}" ]
Get the maximum instance between a given instance (default now) and the current instance. @param DateTime|null $dt @return static
[ "Get", "the", "maximum", "instance", "between", "a", "given", "instance", "(", "default", "now", ")", "and", "the", "current", "instance", "." ]
train
https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Comparable.php#L249-L254
dave-redfern/somnambulist-value-objects
src/Types/DateTime/Traits/Comparable.php
Comparable.isSameAs
public function isSameAs($format, DateTime $dt = null) { $dt = $dt ?: static::now($this->timezone()); return $this->format($format) === $dt->format($format); }
php
public function isSameAs($format, DateTime $dt = null) { $dt = $dt ?: static::now($this->timezone()); return $this->format($format) === $dt->format($format); }
[ "public", "function", "isSameAs", "(", "$", "format", ",", "DateTime", "$", "dt", "=", "null", ")", "{", "$", "dt", "=", "$", "dt", "?", ":", "static", "::", "now", "(", "$", "this", "->", "timezone", "(", ")", ")", ";", "return", "$", "this", "->", "format", "(", "$", "format", ")", "===", "$", "dt", "->", "format", "(", "$", "format", ")", ";", "}" ]
Compares the formatted values of the two dates. @param string $format The date formats to compare. @param DateTime|null $dt The instance to compare with or null to use current day. @return bool
[ "Compares", "the", "formatted", "values", "of", "the", "two", "dates", "." ]
train
https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Comparable.php#L410-L415
dave-redfern/somnambulist-value-objects
src/Types/DateTime/Traits/Comparable.php
Comparable.isSameMonth
public function isSameMonth(DateTime $dt = null, $ofSameYear = false) { $format = $ofSameYear ? 'Y-m' : 'm'; return $this->isSameAs($format, $dt); }
php
public function isSameMonth(DateTime $dt = null, $ofSameYear = false) { $format = $ofSameYear ? 'Y-m' : 'm'; return $this->isSameAs($format, $dt); }
[ "public", "function", "isSameMonth", "(", "DateTime", "$", "dt", "=", "null", ",", "$", "ofSameYear", "=", "false", ")", "{", "$", "format", "=", "$", "ofSameYear", "?", "'Y-m'", ":", "'m'", ";", "return", "$", "this", "->", "isSameAs", "(", "$", "format", ",", "$", "dt", ")", ";", "}" ]
Checks if the passed in date is in the same month as the instance month (and year if needed). @param DateTime|null $dt The instance to compare with or null to use current day. @param bool $ofSameYear Check if it is the same month in the same year. @return bool
[ "Checks", "if", "the", "passed", "in", "date", "is", "in", "the", "same", "month", "as", "the", "instance", "month", "(", "and", "year", "if", "needed", ")", "." ]
train
https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Comparable.php#L457-L462
creolab/resources
src/Transformer.php
Transformer.transform
public function transform($data = null, $rules = null) { // The data if ( ! $data) $data = $this->data; // The rules if ( ! $rules) $rules = $this->rules; // Merge the default ones in $rules = array_merge($this->defaultRules, $rules); foreach ($rules as $key => $rule) { if (isset($data[$key])) { if ($rule == 'datetime') $data[$key] = Carbon::parse($data[$key]); elseif ($rule == 'time') $data[$key] = Carbon::parse($data[$key]); elseif ($rule == 'date') $data[$key] = Carbon::parse($data[$key]); elseif ($rule == 'image') $data[$key] = $this->transformImage($data[$key]); elseif ($rule == 'strip_tags') $data[$key] = strip_tags($data[$key]); elseif (is_string($rule) and class_exists($rule)) $data[$key] = new $rule($data[$key]); elseif (is_array($rule)) $data[$key] = $data[$key]; } } return $data; }
php
public function transform($data = null, $rules = null) { // The data if ( ! $data) $data = $this->data; // The rules if ( ! $rules) $rules = $this->rules; // Merge the default ones in $rules = array_merge($this->defaultRules, $rules); foreach ($rules as $key => $rule) { if (isset($data[$key])) { if ($rule == 'datetime') $data[$key] = Carbon::parse($data[$key]); elseif ($rule == 'time') $data[$key] = Carbon::parse($data[$key]); elseif ($rule == 'date') $data[$key] = Carbon::parse($data[$key]); elseif ($rule == 'image') $data[$key] = $this->transformImage($data[$key]); elseif ($rule == 'strip_tags') $data[$key] = strip_tags($data[$key]); elseif (is_string($rule) and class_exists($rule)) $data[$key] = new $rule($data[$key]); elseif (is_array($rule)) $data[$key] = $data[$key]; } } return $data; }
[ "public", "function", "transform", "(", "$", "data", "=", "null", ",", "$", "rules", "=", "null", ")", "{", "// The data", "if", "(", "!", "$", "data", ")", "$", "data", "=", "$", "this", "->", "data", ";", "// The rules", "if", "(", "!", "$", "rules", ")", "$", "rules", "=", "$", "this", "->", "rules", ";", "// Merge the default ones in", "$", "rules", "=", "array_merge", "(", "$", "this", "->", "defaultRules", ",", "$", "rules", ")", ";", "foreach", "(", "$", "rules", "as", "$", "key", "=>", "$", "rule", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "key", "]", ")", ")", "{", "if", "(", "$", "rule", "==", "'datetime'", ")", "$", "data", "[", "$", "key", "]", "=", "Carbon", "::", "parse", "(", "$", "data", "[", "$", "key", "]", ")", ";", "elseif", "(", "$", "rule", "==", "'time'", ")", "$", "data", "[", "$", "key", "]", "=", "Carbon", "::", "parse", "(", "$", "data", "[", "$", "key", "]", ")", ";", "elseif", "(", "$", "rule", "==", "'date'", ")", "$", "data", "[", "$", "key", "]", "=", "Carbon", "::", "parse", "(", "$", "data", "[", "$", "key", "]", ")", ";", "elseif", "(", "$", "rule", "==", "'image'", ")", "$", "data", "[", "$", "key", "]", "=", "$", "this", "->", "transformImage", "(", "$", "data", "[", "$", "key", "]", ")", ";", "elseif", "(", "$", "rule", "==", "'strip_tags'", ")", "$", "data", "[", "$", "key", "]", "=", "strip_tags", "(", "$", "data", "[", "$", "key", "]", ")", ";", "elseif", "(", "is_string", "(", "$", "rule", ")", "and", "class_exists", "(", "$", "rule", ")", ")", "$", "data", "[", "$", "key", "]", "=", "new", "$", "rule", "(", "$", "data", "[", "$", "key", "]", ")", ";", "elseif", "(", "is_array", "(", "$", "rule", ")", ")", "$", "data", "[", "$", "key", "]", "=", "$", "data", "[", "$", "key", "]", ";", "}", "}", "return", "$", "data", ";", "}" ]
Transform data types for item @param array $data @param array $rules @return array
[ "Transform", "data", "types", "for", "item" ]
train
https://github.com/creolab/resources/blob/6e1bdd266aa373f6dafd2408b230f7d2fa05a637/src/Transformer.php#L39-L65
creolab/resources
src/Transformer.php
Transformer.transformBack
public function transformBack($data = null, $rules = null) { // The data if ( ! $data) $data = $this->data; // The rules if ( ! $rules) $rules = $this->rules; // Merge the default ones in $rules = array_merge($this->defaultRules, $rules); foreach ($rules as $key => $rule) { if (isset($data[$key])) { if ($rule == 'datetime' and is_a($data[$key], 'Carbon')) $data[$key] = $data[$key]->format('Y-m-d H:i:s'); elseif ($rule == 'time' and is_a($data[$key], 'Carbon')) $data[$key] = $data[$key]->format('H:i:s'); elseif ($rule == 'date' and is_a($data[$key], 'Carbon')) $data[$key] = $data[$key]->format('Y-m-d'); elseif ($rule == 'image' and is_a($data[$key], 'Creolab\Image\ImageItem')) $data[$key] = $data[$key]->src(); elseif (is_string($rule) and method_exists($data[$key], 'toArray')) $data[$key] = $data[$key]->toArray(); // elseif (is_array($rule)) $data[$key] = $data[$key]; } } return $data; }
php
public function transformBack($data = null, $rules = null) { // The data if ( ! $data) $data = $this->data; // The rules if ( ! $rules) $rules = $this->rules; // Merge the default ones in $rules = array_merge($this->defaultRules, $rules); foreach ($rules as $key => $rule) { if (isset($data[$key])) { if ($rule == 'datetime' and is_a($data[$key], 'Carbon')) $data[$key] = $data[$key]->format('Y-m-d H:i:s'); elseif ($rule == 'time' and is_a($data[$key], 'Carbon')) $data[$key] = $data[$key]->format('H:i:s'); elseif ($rule == 'date' and is_a($data[$key], 'Carbon')) $data[$key] = $data[$key]->format('Y-m-d'); elseif ($rule == 'image' and is_a($data[$key], 'Creolab\Image\ImageItem')) $data[$key] = $data[$key]->src(); elseif (is_string($rule) and method_exists($data[$key], 'toArray')) $data[$key] = $data[$key]->toArray(); // elseif (is_array($rule)) $data[$key] = $data[$key]; } } return $data; }
[ "public", "function", "transformBack", "(", "$", "data", "=", "null", ",", "$", "rules", "=", "null", ")", "{", "// The data", "if", "(", "!", "$", "data", ")", "$", "data", "=", "$", "this", "->", "data", ";", "// The rules", "if", "(", "!", "$", "rules", ")", "$", "rules", "=", "$", "this", "->", "rules", ";", "// Merge the default ones in", "$", "rules", "=", "array_merge", "(", "$", "this", "->", "defaultRules", ",", "$", "rules", ")", ";", "foreach", "(", "$", "rules", "as", "$", "key", "=>", "$", "rule", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "key", "]", ")", ")", "{", "if", "(", "$", "rule", "==", "'datetime'", "and", "is_a", "(", "$", "data", "[", "$", "key", "]", ",", "'Carbon'", ")", ")", "$", "data", "[", "$", "key", "]", "=", "$", "data", "[", "$", "key", "]", "->", "format", "(", "'Y-m-d H:i:s'", ")", ";", "elseif", "(", "$", "rule", "==", "'time'", "and", "is_a", "(", "$", "data", "[", "$", "key", "]", ",", "'Carbon'", ")", ")", "$", "data", "[", "$", "key", "]", "=", "$", "data", "[", "$", "key", "]", "->", "format", "(", "'H:i:s'", ")", ";", "elseif", "(", "$", "rule", "==", "'date'", "and", "is_a", "(", "$", "data", "[", "$", "key", "]", ",", "'Carbon'", ")", ")", "$", "data", "[", "$", "key", "]", "=", "$", "data", "[", "$", "key", "]", "->", "format", "(", "'Y-m-d'", ")", ";", "elseif", "(", "$", "rule", "==", "'image'", "and", "is_a", "(", "$", "data", "[", "$", "key", "]", ",", "'Creolab\\Image\\ImageItem'", ")", ")", "$", "data", "[", "$", "key", "]", "=", "$", "data", "[", "$", "key", "]", "->", "src", "(", ")", ";", "elseif", "(", "is_string", "(", "$", "rule", ")", "and", "method_exists", "(", "$", "data", "[", "$", "key", "]", ",", "'toArray'", ")", ")", "$", "data", "[", "$", "key", "]", "=", "$", "data", "[", "$", "key", "]", "->", "toArray", "(", ")", ";", "// elseif (is_array($rule)) $data[$key] = $data[$key];", "}", "}", "return", "$", "data", ";", "}" ]
Transform back data types to array/string values @param array $data @param array $rules @return array
[ "Transform", "back", "data", "types", "to", "array", "/", "string", "values" ]
train
https://github.com/creolab/resources/blob/6e1bdd266aa373f6dafd2408b230f7d2fa05a637/src/Transformer.php#L85-L110
yuncms/yii2-authentication
jobs/AuthenticationJob.php
AuthenticationJob.execute
public function execute($queue) { if (($authentication = Authentication::findOne(['user_id' => $this->userId, 'id_type' => Authentication::TYPE_ID])) != null) { $fileContent = file_get_contents($authentication->passport_cover); $base64Content = base64_encode($fileContent); $oci = $this->ocrIdCard($base64Content); if ($oci && (isset($oci['name']) && isset($oci['name']))) { if ($oci['name'] == $authentication->real_name && $oci['num'] == $authentication->id_card) {//比对身份证 $result = Yii::$app->id98->getIdCard($authentication->real_name, $authentication->id_card); if ($result['success'] == true) { if ($result['data'] == 1) { $authentication->status = Authentication::STATUS_AUTHENTICATED; $authentication->failed_reason = '信息比对一致'; } else if ($result['data'] == 2) { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '姓名和身份证号码不一致'; } else if ($result['data'] == 3) { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '身份证中心查无此身份证号码'; } } } else { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '姓名和身份证号码不一致'; } } else { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '身份证图像识别失败了,请上传清晰的身份证照片。'; } $authentication->save(false); } }
php
public function execute($queue) { if (($authentication = Authentication::findOne(['user_id' => $this->userId, 'id_type' => Authentication::TYPE_ID])) != null) { $fileContent = file_get_contents($authentication->passport_cover); $base64Content = base64_encode($fileContent); $oci = $this->ocrIdCard($base64Content); if ($oci && (isset($oci['name']) && isset($oci['name']))) { if ($oci['name'] == $authentication->real_name && $oci['num'] == $authentication->id_card) {//比对身份证 $result = Yii::$app->id98->getIdCard($authentication->real_name, $authentication->id_card); if ($result['success'] == true) { if ($result['data'] == 1) { $authentication->status = Authentication::STATUS_AUTHENTICATED; $authentication->failed_reason = '信息比对一致'; } else if ($result['data'] == 2) { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '姓名和身份证号码不一致'; } else if ($result['data'] == 3) { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '身份证中心查无此身份证号码'; } } } else { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '姓名和身份证号码不一致'; } } else { $authentication->status = Authentication::STATUS_REJECTED; $authentication->failed_reason = '身份证图像识别失败了,请上传清晰的身份证照片。'; } $authentication->save(false); } }
[ "public", "function", "execute", "(", "$", "queue", ")", "{", "if", "(", "(", "$", "authentication", "=", "Authentication", "::", "findOne", "(", "[", "'user_id'", "=>", "$", "this", "->", "userId", ",", "'id_type'", "=>", "Authentication", "::", "TYPE_ID", "]", ")", ")", "!=", "null", ")", "{", "$", "fileContent", "=", "file_get_contents", "(", "$", "authentication", "->", "passport_cover", ")", ";", "$", "base64Content", "=", "base64_encode", "(", "$", "fileContent", ")", ";", "$", "oci", "=", "$", "this", "->", "ocrIdCard", "(", "$", "base64Content", ")", ";", "if", "(", "$", "oci", "&&", "(", "isset", "(", "$", "oci", "[", "'name'", "]", ")", "&&", "isset", "(", "$", "oci", "[", "'name'", "]", ")", ")", ")", "{", "if", "(", "$", "oci", "[", "'name'", "]", "==", "$", "authentication", "->", "real_name", "&&", "$", "oci", "[", "'num'", "]", "==", "$", "authentication", "->", "id_card", ")", "{", "//比对身份证", "$", "result", "=", "Yii", "::", "$", "app", "->", "id98", "->", "getIdCard", "(", "$", "authentication", "->", "real_name", ",", "$", "authentication", "->", "id_card", ")", ";", "if", "(", "$", "result", "[", "'success'", "]", "==", "true", ")", "{", "if", "(", "$", "result", "[", "'data'", "]", "==", "1", ")", "{", "$", "authentication", "->", "status", "=", "Authentication", "::", "STATUS_AUTHENTICATED", ";", "$", "authentication", "->", "failed_reason", "=", "'信息比对一致';", "", "}", "else", "if", "(", "$", "result", "[", "'data'", "]", "==", "2", ")", "{", "$", "authentication", "->", "status", "=", "Authentication", "::", "STATUS_REJECTED", ";", "$", "authentication", "->", "failed_reason", "=", "'姓名和身份证号码不一致';", "", "}", "else", "if", "(", "$", "result", "[", "'data'", "]", "==", "3", ")", "{", "$", "authentication", "->", "status", "=", "Authentication", "::", "STATUS_REJECTED", ";", "$", "authentication", "->", "failed_reason", "=", "'身份证中心查无此身份证号码';", "", "}", "}", "}", "else", "{", "$", "authentication", "->", "status", "=", "Authentication", "::", "STATUS_REJECTED", ";", "$", "authentication", "->", "failed_reason", "=", "'姓名和身份证号码不一致';", "", "}", "}", "else", "{", "$", "authentication", "->", "status", "=", "Authentication", "::", "STATUS_REJECTED", ";", "$", "authentication", "->", "failed_reason", "=", "'身份证图像识别失败了,请上传清晰的身份证照片。';", "", "}", "$", "authentication", "->", "save", "(", "false", ")", ";", "}", "}" ]
执行实名认证任务 @param Queue $queue
[ "执行实名认证任务" ]
train
https://github.com/yuncms/yii2-authentication/blob/02b70f7d2587480edb6dcc18ce256db662f1ed0d/jobs/AuthenticationJob.php#L29-L60
yuncms/yii2-authentication
jobs/AuthenticationJob.php
AuthenticationJob.ocrIdCard
public function ocrIdCard($dataValue) { $httpClient = new Client([ 'baseUrl' => 'https://dm-51.data.aliyun.com', 'responseConfig' => [ 'format' => Client::FORMAT_JSON ], ]); $bodys = "{\"inputs\": [{\"image\": {\"dataType\": 50,\"dataValue\": \"{$dataValue}\"},\"configure\": {\"dataType\": 50,\"dataValue\": \"{\\\"side\\\":\\\"face\\\"}\"}}]}"; $response = $httpClient->createRequest() ->setUrl('rest/160601/ocr/ocr_idcard.json') ->setMethod('POST') ->setContent($bodys) ->addHeaders([ 'Authorization' => 'APPCODE ' . Yii::$app->settings->get('authentication', 'ociAppCode'), 'Content-Type' => 'application/json', ]) ->send(); if ($response->isOk && isset($response->data['outputs'][0]['outputValue']['dataValue'])) { return Json::decode($response->data['outputs'][0]['outputValue']['dataValue']); } return false; }
php
public function ocrIdCard($dataValue) { $httpClient = new Client([ 'baseUrl' => 'https://dm-51.data.aliyun.com', 'responseConfig' => [ 'format' => Client::FORMAT_JSON ], ]); $bodys = "{\"inputs\": [{\"image\": {\"dataType\": 50,\"dataValue\": \"{$dataValue}\"},\"configure\": {\"dataType\": 50,\"dataValue\": \"{\\\"side\\\":\\\"face\\\"}\"}}]}"; $response = $httpClient->createRequest() ->setUrl('rest/160601/ocr/ocr_idcard.json') ->setMethod('POST') ->setContent($bodys) ->addHeaders([ 'Authorization' => 'APPCODE ' . Yii::$app->settings->get('authentication', 'ociAppCode'), 'Content-Type' => 'application/json', ]) ->send(); if ($response->isOk && isset($response->data['outputs'][0]['outputValue']['dataValue'])) { return Json::decode($response->data['outputs'][0]['outputValue']['dataValue']); } return false; }
[ "public", "function", "ocrIdCard", "(", "$", "dataValue", ")", "{", "$", "httpClient", "=", "new", "Client", "(", "[", "'baseUrl'", "=>", "'https://dm-51.data.aliyun.com'", ",", "'responseConfig'", "=>", "[", "'format'", "=>", "Client", "::", "FORMAT_JSON", "]", ",", "]", ")", ";", "$", "bodys", "=", "\"{\\\"inputs\\\": [{\\\"image\\\": {\\\"dataType\\\": 50,\\\"dataValue\\\": \\\"{$dataValue}\\\"},\\\"configure\\\": {\\\"dataType\\\": 50,\\\"dataValue\\\": \\\"{\\\\\\\"side\\\\\\\":\\\\\\\"face\\\\\\\"}\\\"}}]}\"", ";", "$", "response", "=", "$", "httpClient", "->", "createRequest", "(", ")", "->", "setUrl", "(", "'rest/160601/ocr/ocr_idcard.json'", ")", "->", "setMethod", "(", "'POST'", ")", "->", "setContent", "(", "$", "bodys", ")", "->", "addHeaders", "(", "[", "'Authorization'", "=>", "'APPCODE '", ".", "Yii", "::", "$", "app", "->", "settings", "->", "get", "(", "'authentication'", ",", "'ociAppCode'", ")", ",", "'Content-Type'", "=>", "'application/json'", ",", "]", ")", "->", "send", "(", ")", ";", "if", "(", "$", "response", "->", "isOk", "&&", "isset", "(", "$", "response", "->", "data", "[", "'outputs'", "]", "[", "0", "]", "[", "'outputValue'", "]", "[", "'dataValue'", "]", ")", ")", "{", "return", "Json", "::", "decode", "(", "$", "response", "->", "data", "[", "'outputs'", "]", "[", "0", "]", "[", "'outputValue'", "]", "[", "'dataValue'", "]", ")", ";", "}", "return", "false", ";", "}" ]
Ocr图像识别 @param string $dataValue @return mixed
[ "Ocr图像识别" ]
train
https://github.com/yuncms/yii2-authentication/blob/02b70f7d2587480edb6dcc18ce256db662f1ed0d/jobs/AuthenticationJob.php#L68-L91
yuncms/yii2-authentication
jobs/AuthenticationJob.php
AuthenticationJob.getHttpClient
public function getHttpClient() { if (!is_object($this->_httpClient)) { $this->_httpClient = new Client([ 'baseUrl' => $this->baseUrl, 'requestConfig' => [ 'options' => $this->requestOptions ], 'responseConfig' => [ 'format' => Client::FORMAT_JSON ], ]); } return $this->_httpClient; }
php
public function getHttpClient() { if (!is_object($this->_httpClient)) { $this->_httpClient = new Client([ 'baseUrl' => $this->baseUrl, 'requestConfig' => [ 'options' => $this->requestOptions ], 'responseConfig' => [ 'format' => Client::FORMAT_JSON ], ]); } return $this->_httpClient; }
[ "public", "function", "getHttpClient", "(", ")", "{", "if", "(", "!", "is_object", "(", "$", "this", "->", "_httpClient", ")", ")", "{", "$", "this", "->", "_httpClient", "=", "new", "Client", "(", "[", "'baseUrl'", "=>", "$", "this", "->", "baseUrl", ",", "'requestConfig'", "=>", "[", "'options'", "=>", "$", "this", "->", "requestOptions", "]", ",", "'responseConfig'", "=>", "[", "'format'", "=>", "Client", "::", "FORMAT_JSON", "]", ",", "]", ")", ";", "}", "return", "$", "this", "->", "_httpClient", ";", "}" ]
获取Http Client @return Client
[ "获取Http", "Client" ]
train
https://github.com/yuncms/yii2-authentication/blob/02b70f7d2587480edb6dcc18ce256db662f1ed0d/jobs/AuthenticationJob.php#L97-L111
mothership-ec/composer
src/Composer/Installer/PluginInstaller.php
PluginInstaller.install
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { $extra = $package->getExtra(); if (empty($extra['class'])) { throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.'); } parent::install($repo, $package); $this->composer->getPluginManager()->registerPackage($package, true); }
php
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { $extra = $package->getExtra(); if (empty($extra['class'])) { throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.'); } parent::install($repo, $package); $this->composer->getPluginManager()->registerPackage($package, true); }
[ "public", "function", "install", "(", "InstalledRepositoryInterface", "$", "repo", ",", "PackageInterface", "$", "package", ")", "{", "$", "extra", "=", "$", "package", "->", "getExtra", "(", ")", ";", "if", "(", "empty", "(", "$", "extra", "[", "'class'", "]", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Error while installing '", ".", "$", "package", "->", "getPrettyName", "(", ")", ".", "', composer-plugin packages should have a class defined in their extra key to be usable.'", ")", ";", "}", "parent", "::", "install", "(", "$", "repo", ",", "$", "package", ")", ";", "$", "this", "->", "composer", "->", "getPluginManager", "(", ")", "->", "registerPackage", "(", "$", "package", ",", "true", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Installer/PluginInstaller.php#L56-L65
FrenzelGmbH/cm-address
widgets/IPLocation.php
IPLocation.run
public function run() { $result = \frenzelgmbh\cmaddress\models\Address::getIPLocation(); if($result->getLatitude() == 0) { return $this->render('@frenzelgmbh/cmaddress/widgets/views/_iplocation',[ 'latitude' => 48.8077, 'longitude' => 9.15362, 'options' => $this->options ]); } else { return $this->render('@frenzelgmbh/cmaddress/widgets/views/_iplocation',[ 'latitude' => $result->getLatitude(), 'longitude' => $result->getLongitude(), 'options' => $this->options ]); } }
php
public function run() { $result = \frenzelgmbh\cmaddress\models\Address::getIPLocation(); if($result->getLatitude() == 0) { return $this->render('@frenzelgmbh/cmaddress/widgets/views/_iplocation',[ 'latitude' => 48.8077, 'longitude' => 9.15362, 'options' => $this->options ]); } else { return $this->render('@frenzelgmbh/cmaddress/widgets/views/_iplocation',[ 'latitude' => $result->getLatitude(), 'longitude' => $result->getLongitude(), 'options' => $this->options ]); } }
[ "public", "function", "run", "(", ")", "{", "$", "result", "=", "\\", "frenzelgmbh", "\\", "cmaddress", "\\", "models", "\\", "Address", "::", "getIPLocation", "(", ")", ";", "if", "(", "$", "result", "->", "getLatitude", "(", ")", "==", "0", ")", "{", "return", "$", "this", "->", "render", "(", "'@frenzelgmbh/cmaddress/widgets/views/_iplocation'", ",", "[", "'latitude'", "=>", "48.8077", ",", "'longitude'", "=>", "9.15362", ",", "'options'", "=>", "$", "this", "->", "options", "]", ")", ";", "}", "else", "{", "return", "$", "this", "->", "render", "(", "'@frenzelgmbh/cmaddress/widgets/views/_iplocation'", ",", "[", "'latitude'", "=>", "$", "result", "->", "getLatitude", "(", ")", ",", "'longitude'", "=>", "$", "result", "->", "getLongitude", "(", ")", ",", "'options'", "=>", "$", "this", "->", "options", "]", ")", ";", "}", "}" ]
[renderContent description] @return [type] [description]
[ "[", "renderContent", "description", "]" ]
train
https://github.com/FrenzelGmbH/cm-address/blob/4295671dc603beed4bea6c5a7f77dac9846127f3/widgets/IPLocation.php#L48-L68
php-lug/lug
src/Component/Grid/Model/Builder/ColumnBuilder.php
ColumnBuilder.build
public function build(array $config) { return new Column( $this->buildName($config), $this->buildLabel($config), $this->buildType($config), $this->buildOptions($config) ); }
php
public function build(array $config) { return new Column( $this->buildName($config), $this->buildLabel($config), $this->buildType($config), $this->buildOptions($config) ); }
[ "public", "function", "build", "(", "array", "$", "config", ")", "{", "return", "new", "Column", "(", "$", "this", "->", "buildName", "(", "$", "config", ")", ",", "$", "this", "->", "buildLabel", "(", "$", "config", ")", ",", "$", "this", "->", "buildType", "(", "$", "config", ")", ",", "$", "this", "->", "buildOptions", "(", "$", "config", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/ColumnBuilder.php#L25-L33
php-lug/lug
src/Component/Grid/Model/Builder/ColumnBuilder.php
ColumnBuilder.buildOptions
protected function buildOptions(array $config) { switch ($this->buildType($config)) { case 'resource': if (!isset($config['options']['resource'])) { $config['options']['resource'] = $this->buildName($config); } break; } return isset($config['options']) ? $config['options'] : []; }
php
protected function buildOptions(array $config) { switch ($this->buildType($config)) { case 'resource': if (!isset($config['options']['resource'])) { $config['options']['resource'] = $this->buildName($config); } break; } return isset($config['options']) ? $config['options'] : []; }
[ "protected", "function", "buildOptions", "(", "array", "$", "config", ")", "{", "switch", "(", "$", "this", "->", "buildType", "(", "$", "config", ")", ")", "{", "case", "'resource'", ":", "if", "(", "!", "isset", "(", "$", "config", "[", "'options'", "]", "[", "'resource'", "]", ")", ")", "{", "$", "config", "[", "'options'", "]", "[", "'resource'", "]", "=", "$", "this", "->", "buildName", "(", "$", "config", ")", ";", "}", "break", ";", "}", "return", "isset", "(", "$", "config", "[", "'options'", "]", ")", "?", "$", "config", "[", "'options'", "]", ":", "[", "]", ";", "}" ]
@param mixed[] $config @return mixed[]
[ "@param", "mixed", "[]", "$config" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/ColumnBuilder.php#L74-L85
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.match
public function match($permissions, array $authzGroups) { $privileges = []; foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) { $matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups); if (!$matchingAuthzGroup) { continue; } $privileges[] = $permissionPrivileges; } return $this->flatten($privileges); }
php
public function match($permissions, array $authzGroups) { $privileges = []; foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) { $matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups); if (!$matchingAuthzGroup) { continue; } $privileges[] = $permissionPrivileges; } return $this->flatten($privileges); }
[ "public", "function", "match", "(", "$", "permissions", ",", "array", "$", "authzGroups", ")", "{", "$", "privileges", "=", "[", "]", ";", "foreach", "(", "$", "permissions", "as", "$", "permissionAuthzGroup", "=>", "$", "permissionPrivileges", ")", "{", "$", "matchingAuthzGroup", "=", "$", "this", "->", "getMatchingAuthzGroup", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroups", ")", ";", "if", "(", "!", "$", "matchingAuthzGroup", ")", "{", "continue", ";", "}", "$", "privileges", "[", "]", "=", "$", "permissionPrivileges", ";", "}", "return", "$", "this", "->", "flatten", "(", "$", "privileges", ")", ";", "}" ]
Get a flat list of privileges for matching authz groups @param array|object $permissions @param array $authzGroups @return array
[ "Get", "a", "flat", "list", "of", "privileges", "for", "matching", "authz", "groups" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L17-L32
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.matchFull
public function matchFull($permissions, array $authzGroups) { $privileges = []; foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) { $matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups); if (!$matchingAuthzGroup) { continue; } $privileges = $this->addAuthzGroupsToPrivileges($privileges, $permissionPrivileges, [ $permissionAuthzGroup, $matchingAuthzGroup ]); } return $privileges; }
php
public function matchFull($permissions, array $authzGroups) { $privileges = []; foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) { $matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups); if (!$matchingAuthzGroup) { continue; } $privileges = $this->addAuthzGroupsToPrivileges($privileges, $permissionPrivileges, [ $permissionAuthzGroup, $matchingAuthzGroup ]); } return $privileges; }
[ "public", "function", "matchFull", "(", "$", "permissions", ",", "array", "$", "authzGroups", ")", "{", "$", "privileges", "=", "[", "]", ";", "foreach", "(", "$", "permissions", "as", "$", "permissionAuthzGroup", "=>", "$", "permissionPrivileges", ")", "{", "$", "matchingAuthzGroup", "=", "$", "this", "->", "getMatchingAuthzGroup", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroups", ")", ";", "if", "(", "!", "$", "matchingAuthzGroup", ")", "{", "continue", ";", "}", "$", "privileges", "=", "$", "this", "->", "addAuthzGroupsToPrivileges", "(", "$", "privileges", ",", "$", "permissionPrivileges", ",", "[", "$", "permissionAuthzGroup", ",", "$", "matchingAuthzGroup", "]", ")", ";", "}", "return", "$", "privileges", ";", "}" ]
Get a list of privileges for matching authz groups containing more information Returns an array of objects where the privilege is the key and authzgroups the value @param array|object $permissions @param array $authzGroups @return array
[ "Get", "a", "list", "of", "privileges", "for", "matching", "authz", "groups", "containing", "more", "information", "Returns", "an", "array", "of", "objects", "where", "the", "privilege", "is", "the", "key", "and", "authzgroups", "the", "value" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L42-L59
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.getMatchingAuthzGroup
protected function getMatchingAuthzGroup($permissionAuthzGroup, array $authzGroups) { $invert = $this->stringStartsWith($permissionAuthzGroup, '!'); if ($invert) { $permissionAuthzGroup = substr($permissionAuthzGroup, 1); } $matches = []; foreach ($authzGroups as $authzGroup) { $match = $this->authzGroupsAreEqual($permissionAuthzGroup, $authzGroup); if ($match && $invert) { return null; } if ($match && !$invert || !$match && $invert) { $matches[] = $authzGroup; } } return !empty($matches) ? $matches[0] : null; }
php
protected function getMatchingAuthzGroup($permissionAuthzGroup, array $authzGroups) { $invert = $this->stringStartsWith($permissionAuthzGroup, '!'); if ($invert) { $permissionAuthzGroup = substr($permissionAuthzGroup, 1); } $matches = []; foreach ($authzGroups as $authzGroup) { $match = $this->authzGroupsAreEqual($permissionAuthzGroup, $authzGroup); if ($match && $invert) { return null; } if ($match && !$invert || !$match && $invert) { $matches[] = $authzGroup; } } return !empty($matches) ? $matches[0] : null; }
[ "protected", "function", "getMatchingAuthzGroup", "(", "$", "permissionAuthzGroup", ",", "array", "$", "authzGroups", ")", "{", "$", "invert", "=", "$", "this", "->", "stringStartsWith", "(", "$", "permissionAuthzGroup", ",", "'!'", ")", ";", "if", "(", "$", "invert", ")", "{", "$", "permissionAuthzGroup", "=", "substr", "(", "$", "permissionAuthzGroup", ",", "1", ")", ";", "}", "$", "matches", "=", "[", "]", ";", "foreach", "(", "$", "authzGroups", "as", "$", "authzGroup", ")", "{", "$", "match", "=", "$", "this", "->", "authzGroupsAreEqual", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroup", ")", ";", "if", "(", "$", "match", "&&", "$", "invert", ")", "{", "return", "null", ";", "}", "if", "(", "$", "match", "&&", "!", "$", "invert", "||", "!", "$", "match", "&&", "$", "invert", ")", "{", "$", "matches", "[", "]", "=", "$", "authzGroup", ";", "}", "}", "return", "!", "empty", "(", "$", "matches", ")", "?", "$", "matches", "[", "0", "]", ":", "null", ";", "}" ]
Check if one of the authz groups match @param string $permissionAuthzGroup @param array $authzGroups @return string|null
[ "Check", "if", "one", "of", "the", "authz", "groups", "match" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L68-L91
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.authzGroupsAreEqual
protected function authzGroupsAreEqual($permissionAuthzGroup, $authzGroup) { return $this->pathsAreEqual($permissionAuthzGroup, $authzGroup) && $this->queryParamsAreEqual($permissionAuthzGroup, $authzGroup); }
php
protected function authzGroupsAreEqual($permissionAuthzGroup, $authzGroup) { return $this->pathsAreEqual($permissionAuthzGroup, $authzGroup) && $this->queryParamsAreEqual($permissionAuthzGroup, $authzGroup); }
[ "protected", "function", "authzGroupsAreEqual", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroup", ")", "{", "return", "$", "this", "->", "pathsAreEqual", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroup", ")", "&&", "$", "this", "->", "queryParamsAreEqual", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroup", ")", ";", "}" ]
Check if authz groups match @param string $permissionAuthzGroup @param string $authzGroup @return boolean
[ "Check", "if", "authz", "groups", "match" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L101-L105
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.pathsAreEqual
protected function pathsAreEqual($permissionAuthzGroup, $authzGroup) { $permissionAuthzGroupPath = rtrim(strtok($permissionAuthzGroup, '?'), '/'); $authzGroupPath = rtrim(strtok($authzGroup, '?'), '/'); return $this->matchAuthzGroupPaths($permissionAuthzGroupPath, $authzGroupPath) || $this->matchAuthzGroupPaths($authzGroupPath, $permissionAuthzGroupPath); }
php
protected function pathsAreEqual($permissionAuthzGroup, $authzGroup) { $permissionAuthzGroupPath = rtrim(strtok($permissionAuthzGroup, '?'), '/'); $authzGroupPath = rtrim(strtok($authzGroup, '?'), '/'); return $this->matchAuthzGroupPaths($permissionAuthzGroupPath, $authzGroupPath) || $this->matchAuthzGroupPaths($authzGroupPath, $permissionAuthzGroupPath); }
[ "protected", "function", "pathsAreEqual", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroup", ")", "{", "$", "permissionAuthzGroupPath", "=", "rtrim", "(", "strtok", "(", "$", "permissionAuthzGroup", ",", "'?'", ")", ",", "'/'", ")", ";", "$", "authzGroupPath", "=", "rtrim", "(", "strtok", "(", "$", "authzGroup", ",", "'?'", ")", ",", "'/'", ")", ";", "return", "$", "this", "->", "matchAuthzGroupPaths", "(", "$", "permissionAuthzGroupPath", ",", "$", "authzGroupPath", ")", "||", "$", "this", "->", "matchAuthzGroupPaths", "(", "$", "authzGroupPath", ",", "$", "permissionAuthzGroupPath", ")", ";", "}" ]
Compare the paths of two authz groups @param string $permissionAuthzGroup @param string $authzGroup @return boolean
[ "Compare", "the", "paths", "of", "two", "authz", "groups" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L114-L121
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.matchAuthzGroupPaths
protected function matchAuthzGroupPaths($pattern, $subject) { $regex = '^' . str_replace('[^/]+', '\\*', preg_quote($pattern, '~')) . '$'; $regex = str_replace('\\*', '(.*)', $regex); $match = preg_match('~' . $regex . '~i', $subject); return $match; }
php
protected function matchAuthzGroupPaths($pattern, $subject) { $regex = '^' . str_replace('[^/]+', '\\*', preg_quote($pattern, '~')) . '$'; $regex = str_replace('\\*', '(.*)', $regex); $match = preg_match('~' . $regex . '~i', $subject); return $match; }
[ "protected", "function", "matchAuthzGroupPaths", "(", "$", "pattern", ",", "$", "subject", ")", "{", "$", "regex", "=", "'^'", ".", "str_replace", "(", "'[^/]+'", ",", "'\\\\*'", ",", "preg_quote", "(", "$", "pattern", ",", "'~'", ")", ")", ".", "'$'", ";", "$", "regex", "=", "str_replace", "(", "'\\\\*'", ",", "'(.*)'", ",", "$", "regex", ")", ";", "$", "match", "=", "preg_match", "(", "'~'", ".", "$", "regex", ".", "'~i'", ",", "$", "subject", ")", ";", "return", "$", "match", ";", "}" ]
Check if one paths mathes the other @param string $pattern @param string $subject @return boolean
[ "Check", "if", "one", "paths", "mathes", "the", "other" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L130-L138
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.queryParamsAreEqual
protected function queryParamsAreEqual($permissionAuthzGroup, $authzGroup) { $authzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($authzGroup), CASE_LOWER); $permissionAuthzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($permissionAuthzGroup), CASE_LOWER); ksort($authzGroupQueryParams); ksort($permissionAuthzGroupQueryParams); return $permissionAuthzGroupQueryParams === $authzGroupQueryParams; }
php
protected function queryParamsAreEqual($permissionAuthzGroup, $authzGroup) { $authzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($authzGroup), CASE_LOWER); $permissionAuthzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($permissionAuthzGroup), CASE_LOWER); ksort($authzGroupQueryParams); ksort($permissionAuthzGroupQueryParams); return $permissionAuthzGroupQueryParams === $authzGroupQueryParams; }
[ "protected", "function", "queryParamsAreEqual", "(", "$", "permissionAuthzGroup", ",", "$", "authzGroup", ")", "{", "$", "authzGroupQueryParams", "=", "array_change_key_case", "(", "$", "this", "->", "getStringQueryParameters", "(", "$", "authzGroup", ")", ",", "CASE_LOWER", ")", ";", "$", "permissionAuthzGroupQueryParams", "=", "array_change_key_case", "(", "$", "this", "->", "getStringQueryParameters", "(", "$", "permissionAuthzGroup", ")", ",", "CASE_LOWER", ")", ";", "ksort", "(", "$", "authzGroupQueryParams", ")", ";", "ksort", "(", "$", "permissionAuthzGroupQueryParams", ")", ";", "return", "$", "permissionAuthzGroupQueryParams", "===", "$", "authzGroupQueryParams", ";", "}" ]
Compare the query parameters of two authz groups @param string $permissionAuthzGroup @param string $authzGroup @return boolean
[ "Compare", "the", "query", "parameters", "of", "two", "authz", "groups" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L148-L157
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.getStringQueryParameters
protected function getStringQueryParameters($string) { $query = parse_url($string, PHP_URL_QUERY); $params = []; if ($query) parse_str($query, $params); return $params; }
php
protected function getStringQueryParameters($string) { $query = parse_url($string, PHP_URL_QUERY); $params = []; if ($query) parse_str($query, $params); return $params; }
[ "protected", "function", "getStringQueryParameters", "(", "$", "string", ")", "{", "$", "query", "=", "parse_url", "(", "$", "string", ",", "PHP_URL_QUERY", ")", ";", "$", "params", "=", "[", "]", ";", "if", "(", "$", "query", ")", "parse_str", "(", "$", "query", ",", "$", "params", ")", ";", "return", "$", "params", ";", "}" ]
Get the query parameters used in a string @param string $string @return array
[ "Get", "the", "query", "parameters", "used", "in", "a", "string" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L165-L173
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.flatten
protected function flatten($input) { $list = []; foreach ($input as $item) { $list = array_merge($list, (array)$item); } return array_unique($list); }
php
protected function flatten($input) { $list = []; foreach ($input as $item) { $list = array_merge($list, (array)$item); } return array_unique($list); }
[ "protected", "function", "flatten", "(", "$", "input", ")", "{", "$", "list", "=", "[", "]", ";", "foreach", "(", "$", "input", "as", "$", "item", ")", "{", "$", "list", "=", "array_merge", "(", "$", "list", ",", "(", "array", ")", "$", "item", ")", ";", "}", "return", "array_unique", "(", "$", "list", ")", ";", "}" ]
Turn a 2 dimensional privilege array into a list of privileges @param array $input @return array
[ "Turn", "a", "2", "dimensional", "privilege", "array", "into", "a", "list", "of", "privileges" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L182-L191
legalthings/permission-matcher
src/PermissionMatcher.php
PermissionMatcher.addAuthzGroupsToPrivileges
protected function addAuthzGroupsToPrivileges(array $privileges, $authzGroupsPrivileges, array $authzGroups) { $authzGroupsPrivileges = !is_string($authzGroupsPrivileges) ? $authzGroupsPrivileges : [$authzGroupsPrivileges]; foreach($authzGroupsPrivileges as $privilege) { $current = !empty($privileges[$privilege]) ? $privileges[$privilege] : []; $privileges[$privilege] = array_unique(array_merge($current, $authzGroups)); } return $privileges; }
php
protected function addAuthzGroupsToPrivileges(array $privileges, $authzGroupsPrivileges, array $authzGroups) { $authzGroupsPrivileges = !is_string($authzGroupsPrivileges) ? $authzGroupsPrivileges : [$authzGroupsPrivileges]; foreach($authzGroupsPrivileges as $privilege) { $current = !empty($privileges[$privilege]) ? $privileges[$privilege] : []; $privileges[$privilege] = array_unique(array_merge($current, $authzGroups)); } return $privileges; }
[ "protected", "function", "addAuthzGroupsToPrivileges", "(", "array", "$", "privileges", ",", "$", "authzGroupsPrivileges", ",", "array", "$", "authzGroups", ")", "{", "$", "authzGroupsPrivileges", "=", "!", "is_string", "(", "$", "authzGroupsPrivileges", ")", "?", "$", "authzGroupsPrivileges", ":", "[", "$", "authzGroupsPrivileges", "]", ";", "foreach", "(", "$", "authzGroupsPrivileges", "as", "$", "privilege", ")", "{", "$", "current", "=", "!", "empty", "(", "$", "privileges", "[", "$", "privilege", "]", ")", "?", "$", "privileges", "[", "$", "privilege", "]", ":", "[", "]", ";", "$", "privileges", "[", "$", "privilege", "]", "=", "array_unique", "(", "array_merge", "(", "$", "current", ",", "$", "authzGroups", ")", ")", ";", "}", "return", "$", "privileges", ";", "}" ]
Populate an array of privileges with their corresponding authz groups @param array $privileges The resulting array @param string|array $authzGroupsPrivileges The privileges that the authzgroup has @param array $authzGroups @return array $privileges
[ "Populate", "an", "array", "of", "privileges", "with", "their", "corresponding", "authz", "groups" ]
train
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L201-L211
dstuecken/notify
src/Handler/AbstractShellCommandHandler.php
AbstractShellCommandHandler.shouldHandle
public function shouldHandle(NotificationInterface $notification, $level) { return $this->shellCommandAvailable ? $this->level >= $level : false; }
php
public function shouldHandle(NotificationInterface $notification, $level) { return $this->shellCommandAvailable ? $this->level >= $level : false; }
[ "public", "function", "shouldHandle", "(", "NotificationInterface", "$", "notification", ",", "$", "level", ")", "{", "return", "$", "this", "->", "shellCommandAvailable", "?", "$", "this", "->", "level", ">=", "$", "level", ":", "false", ";", "}" ]
@param NotificationInterface $notification The notification itself @param int $level Level of the current notification @return bool
[ "@param", "NotificationInterface", "$notification", "The", "notification", "itself", "@param", "int", "$level", "Level", "of", "the", "current", "notification" ]
train
https://github.com/dstuecken/notify/blob/abccf0a6a272caf66baea74323f18e2212c6e11e/src/Handler/AbstractShellCommandHandler.php#L34-L37
dstuecken/notify
src/Handler/AbstractShellCommandHandler.php
AbstractShellCommandHandler.available
public function available() { if ($this->shellCommandAvailable === null) { exec("which {$this->shellCommand} > /dev/null", $output, $code); $this->shellCommandAvailable = ($code === 0); } return $this->shellCommandAvailable; }
php
public function available() { if ($this->shellCommandAvailable === null) { exec("which {$this->shellCommand} > /dev/null", $output, $code); $this->shellCommandAvailable = ($code === 0); } return $this->shellCommandAvailable; }
[ "public", "function", "available", "(", ")", "{", "if", "(", "$", "this", "->", "shellCommandAvailable", "===", "null", ")", "{", "exec", "(", "\"which {$this->shellCommand} > /dev/null\"", ",", "$", "output", ",", "$", "code", ")", ";", "$", "this", "->", "shellCommandAvailable", "=", "(", "$", "code", "===", "0", ")", ";", "}", "return", "$", "this", "->", "shellCommandAvailable", ";", "}" ]
Checks if osasend is usable by querying WHICH(1). @return bool
[ "Checks", "if", "osasend", "is", "usable", "by", "querying", "WHICH", "(", "1", ")", "." ]
train
https://github.com/dstuecken/notify/blob/abccf0a6a272caf66baea74323f18e2212c6e11e/src/Handler/AbstractShellCommandHandler.php#L44-L53
InactiveProjects/limoncello-illuminate
app/Database/Factories/PostFactory.php
PostFactory.getRandomBoard
private function getRandomBoard() { if ($this->boards === null) { $this->boards = Board::all(); } return $this->boards->random(); }
php
private function getRandomBoard() { if ($this->boards === null) { $this->boards = Board::all(); } return $this->boards->random(); }
[ "private", "function", "getRandomBoard", "(", ")", "{", "if", "(", "$", "this", "->", "boards", "===", "null", ")", "{", "$", "this", "->", "boards", "=", "Board", "::", "all", "(", ")", ";", "}", "return", "$", "this", "->", "boards", "->", "random", "(", ")", ";", "}" ]
@return Board @SuppressWarnings(PHPMD.StaticAccess)
[ "@return", "Board" ]
train
https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Database/Factories/PostFactory.php#L38-L45
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.initialize
protected function initialize() { $cache = $this->app->get_shared_object( 'user_info_cache', 'all' ); if ( ! isset( $cache ) ) { $cache = $this->get_user_data(); $this->app->set_shared_object( 'user_info_cache', $cache, 'all' ); } foreach ( $cache as $k => $v ) { $this->$k = $v; } }
php
protected function initialize() { $cache = $this->app->get_shared_object( 'user_info_cache', 'all' ); if ( ! isset( $cache ) ) { $cache = $this->get_user_data(); $this->app->set_shared_object( 'user_info_cache', $cache, 'all' ); } foreach ( $cache as $k => $v ) { $this->$k = $v; } }
[ "protected", "function", "initialize", "(", ")", "{", "$", "cache", "=", "$", "this", "->", "app", "->", "get_shared_object", "(", "'user_info_cache'", ",", "'all'", ")", ";", "if", "(", "!", "isset", "(", "$", "cache", ")", ")", "{", "$", "cache", "=", "$", "this", "->", "get_user_data", "(", ")", ";", "$", "this", "->", "app", "->", "set_shared_object", "(", "'user_info_cache'", ",", "$", "cache", ",", "'all'", ")", ";", "}", "foreach", "(", "$", "cache", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "$", "k", "=", "$", "v", ";", "}", "}" ]
initialize
[ "initialize" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L62-L71
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.reset_user_data
public function reset_user_data() { $data = $this->get_user_data(); $this->app->set_shared_object( 'user_info_cache', $data, 'all' ); foreach ( $data as $k => $v ) { $this->$k = $v; } }
php
public function reset_user_data() { $data = $this->get_user_data(); $this->app->set_shared_object( 'user_info_cache', $data, 'all' ); foreach ( $data as $k => $v ) { $this->$k = $v; } }
[ "public", "function", "reset_user_data", "(", ")", "{", "$", "data", "=", "$", "this", "->", "get_user_data", "(", ")", ";", "$", "this", "->", "app", "->", "set_shared_object", "(", "'user_info_cache'", ",", "$", "data", ",", "'all'", ")", ";", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "$", "k", "=", "$", "v", ";", "}", "}" ]
reset
[ "reset" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L120-L126
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.get
public function get( $key, $user_id = null, $single = true, $default = '' ) { if ( ! isset( $user_id ) ) { $user_id = $this->user_id; } if ( $user_id <= 0 ) { return $this->apply_filters( 'get_user_meta', $default, $key, $user_id, $single, $default ); } return $this->apply_filters( 'get_user_meta', get_user_meta( $user_id, $this->get_meta_key( $key ), $single ), $key, $user_id, $single, $default, $this->get_user_prefix() ); }
php
public function get( $key, $user_id = null, $single = true, $default = '' ) { if ( ! isset( $user_id ) ) { $user_id = $this->user_id; } if ( $user_id <= 0 ) { return $this->apply_filters( 'get_user_meta', $default, $key, $user_id, $single, $default ); } return $this->apply_filters( 'get_user_meta', get_user_meta( $user_id, $this->get_meta_key( $key ), $single ), $key, $user_id, $single, $default, $this->get_user_prefix() ); }
[ "public", "function", "get", "(", "$", "key", ",", "$", "user_id", "=", "null", ",", "$", "single", "=", "true", ",", "$", "default", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "user_id", ")", ")", "{", "$", "user_id", "=", "$", "this", "->", "user_id", ";", "}", "if", "(", "$", "user_id", "<=", "0", ")", "{", "return", "$", "this", "->", "apply_filters", "(", "'get_user_meta'", ",", "$", "default", ",", "$", "key", ",", "$", "user_id", ",", "$", "single", ",", "$", "default", ")", ";", "}", "return", "$", "this", "->", "apply_filters", "(", "'get_user_meta'", ",", "get_user_meta", "(", "$", "user_id", ",", "$", "this", "->", "get_meta_key", "(", "$", "key", ")", ",", "$", "single", ")", ",", "$", "key", ",", "$", "user_id", ",", "$", "single", ",", "$", "default", ",", "$", "this", "->", "get_user_prefix", "(", ")", ")", ";", "}" ]
@param string $key @param int|null $user_id @param bool $single @param mixed $default @return mixed
[ "@param", "string", "$key", "@param", "int|null", "$user_id", "@param", "bool", "$single", "@param", "mixed", "$default" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L152-L161
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.set
public function set( $key, $value, $user_id = null ) { if ( ! isset( $user_id ) ) { $user_id = $this->user_id; } if ( $user_id <= 0 ) { return false; } return update_user_meta( $user_id, $this->get_meta_key( $key ), $value ); }
php
public function set( $key, $value, $user_id = null ) { if ( ! isset( $user_id ) ) { $user_id = $this->user_id; } if ( $user_id <= 0 ) { return false; } return update_user_meta( $user_id, $this->get_meta_key( $key ), $value ); }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ",", "$", "user_id", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "user_id", ")", ")", "{", "$", "user_id", "=", "$", "this", "->", "user_id", ";", "}", "if", "(", "$", "user_id", "<=", "0", ")", "{", "return", "false", ";", "}", "return", "update_user_meta", "(", "$", "user_id", ",", "$", "this", "->", "get_meta_key", "(", "$", "key", ")", ",", "$", "value", ")", ";", "}" ]
@param $key @param $value @param int|null $user_id @return bool|int
[ "@param", "$key", "@param", "$value", "@param", "int|null", "$user_id" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L170-L179
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.delete
public function delete( $key, $user_id = null, $meta_value = '' ) { if ( ! isset( $user_id ) ) { $user_id = $this->user_id; } if ( $user_id <= 0 ) { return false; } return delete_user_meta( $user_id, $this->get_meta_key( $key ), $meta_value ); }
php
public function delete( $key, $user_id = null, $meta_value = '' ) { if ( ! isset( $user_id ) ) { $user_id = $this->user_id; } if ( $user_id <= 0 ) { return false; } return delete_user_meta( $user_id, $this->get_meta_key( $key ), $meta_value ); }
[ "public", "function", "delete", "(", "$", "key", ",", "$", "user_id", "=", "null", ",", "$", "meta_value", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "user_id", ")", ")", "{", "$", "user_id", "=", "$", "this", "->", "user_id", ";", "}", "if", "(", "$", "user_id", "<=", "0", ")", "{", "return", "false", ";", "}", "return", "delete_user_meta", "(", "$", "user_id", ",", "$", "this", "->", "get_meta_key", "(", "$", "key", ")", ",", "$", "meta_value", ")", ";", "}" ]
@param string $key @param int|null $user_id @param mixed $meta_value @return bool
[ "@param", "string", "$key", "@param", "int|null", "$user_id", "@param", "mixed", "$meta_value" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L188-L197
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.delete_matched
public function delete_matched( $key, $value ) { $user_ids = $this->find( $key, $value ); if ( empty( $user_ids ) ) { return true; } foreach ( $user_ids as $user_id ) { $this->delete( $key, $user_id ); } return true; }
php
public function delete_matched( $key, $value ) { $user_ids = $this->find( $key, $value ); if ( empty( $user_ids ) ) { return true; } foreach ( $user_ids as $user_id ) { $this->delete( $key, $user_id ); } return true; }
[ "public", "function", "delete_matched", "(", "$", "key", ",", "$", "value", ")", "{", "$", "user_ids", "=", "$", "this", "->", "find", "(", "$", "key", ",", "$", "value", ")", ";", "if", "(", "empty", "(", "$", "user_ids", ")", ")", "{", "return", "true", ";", "}", "foreach", "(", "$", "user_ids", "as", "$", "user_id", ")", "{", "$", "this", "->", "delete", "(", "$", "key", ",", "$", "user_id", ")", ";", "}", "return", "true", ";", "}" ]
@param string $key @param string $value @return bool
[ "@param", "string", "$key", "@param", "string", "$value" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L224-L234
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.find
public function find( $key, $value ) { global $wpdb; $query = <<< SQL SELECT * FROM {$wpdb->usermeta} WHERE meta_key LIKE %s AND meta_value LIKE %s SQL; $results = $wpdb->get_results( $wpdb->prepare( $query, $this->get_meta_key( $key ), $value ) ); return $this->apply_filters( 'find_user_meta', $this->app->utility->array_pluck( $results, 'user_id' ), $key, $value ); }
php
public function find( $key, $value ) { global $wpdb; $query = <<< SQL SELECT * FROM {$wpdb->usermeta} WHERE meta_key LIKE %s AND meta_value LIKE %s SQL; $results = $wpdb->get_results( $wpdb->prepare( $query, $this->get_meta_key( $key ), $value ) ); return $this->apply_filters( 'find_user_meta', $this->app->utility->array_pluck( $results, 'user_id' ), $key, $value ); }
[ "public", "function", "find", "(", "$", "key", ",", "$", "value", ")", "{", "global", "$", "wpdb", ";", "$", "query", "=", " <<< SQL\n\t\t\tSELECT * FROM {$wpdb->usermeta}\n\t\t\tWHERE meta_key LIKE %s\n\t\t\tAND meta_value LIKE %s\nSQL", ";", "$", "results", "=", "$", "wpdb", "->", "get_results", "(", "$", "wpdb", "->", "prepare", "(", "$", "query", ",", "$", "this", "->", "get_meta_key", "(", "$", "key", ")", ",", "$", "value", ")", ")", ";", "return", "$", "this", "->", "apply_filters", "(", "'find_user_meta'", ",", "$", "this", "->", "app", "->", "utility", "->", "array_pluck", "(", "$", "results", ",", "'user_id'", ")", ",", "$", "key", ",", "$", "value", ")", ";", "}" ]
@param string $key @param string $value @return array
[ "@param", "string", "$key", "@param", "string", "$value" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L242-L252
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.first
public function first( $key, $value ) { $user_ids = $this->find( $key, $value ); if ( empty( $user_ids ) ) { return false; } return reset( $user_ids ); }
php
public function first( $key, $value ) { $user_ids = $this->find( $key, $value ); if ( empty( $user_ids ) ) { return false; } return reset( $user_ids ); }
[ "public", "function", "first", "(", "$", "key", ",", "$", "value", ")", "{", "$", "user_ids", "=", "$", "this", "->", "find", "(", "$", "key", ",", "$", "value", ")", ";", "if", "(", "empty", "(", "$", "user_ids", ")", ")", "{", "return", "false", ";", "}", "return", "reset", "(", "$", "user_ids", ")", ";", "}" ]
@param string $key @param string $value @return false|int
[ "@param", "string", "$key", "@param", "string", "$value" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L260-L267
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.user_can
public function user_can( $capability = null ) { if ( ! isset( $capability ) ) { $capability = $this->app->get_config( 'capability', 'default_user', 'manage_options' ); } if ( false === $capability ) { return true; } if ( '' === $capability ) { return false; } return $this->has_cap( $capability ) || in_array( $capability, $this->user_roles ); }
php
public function user_can( $capability = null ) { if ( ! isset( $capability ) ) { $capability = $this->app->get_config( 'capability', 'default_user', 'manage_options' ); } if ( false === $capability ) { return true; } if ( '' === $capability ) { return false; } return $this->has_cap( $capability ) || in_array( $capability, $this->user_roles ); }
[ "public", "function", "user_can", "(", "$", "capability", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "capability", ")", ")", "{", "$", "capability", "=", "$", "this", "->", "app", "->", "get_config", "(", "'capability'", ",", "'default_user'", ",", "'manage_options'", ")", ";", "}", "if", "(", "false", "===", "$", "capability", ")", "{", "return", "true", ";", "}", "if", "(", "''", "===", "$", "capability", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "has_cap", "(", "$", "capability", ")", "||", "in_array", "(", "$", "capability", ",", "$", "this", "->", "user_roles", ")", ";", "}" ]
@param null|string|false $capability @return bool
[ "@param", "null|string|false", "$capability" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L290-L302
technote-space/wordpress-plugin-base
src/classes/models/lib/user.php
User.uninstall
public function uninstall() { global $wpdb; $query = $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s", $this->get_user_prefix() . '%' ); $wpdb->query( $query ); }
php
public function uninstall() { global $wpdb; $query = $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s", $this->get_user_prefix() . '%' ); $wpdb->query( $query ); }
[ "public", "function", "uninstall", "(", ")", "{", "global", "$", "wpdb", ";", "$", "query", "=", "$", "wpdb", "->", "prepare", "(", "\"DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s\"", ",", "$", "this", "->", "get_user_prefix", "(", ")", ".", "'%'", ")", ";", "$", "wpdb", "->", "query", "(", "$", "query", ")", ";", "}" ]
uninstall
[ "uninstall" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/user.php#L316-L320
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Helper/Str.php
Str.fromHex
public static function fromHex($hex) { $string = ""; if(strlen($hex)%2 == 1) { throw new Exception("given parameter '" . $hex . "' is not a valid hexadecimal number"); } foreach(str_split($hex, 2) as $chunk) { $string .= chr(hexdec($chunk)); } return new self($string); }
php
public static function fromHex($hex) { $string = ""; if(strlen($hex)%2 == 1) { throw new Exception("given parameter '" . $hex . "' is not a valid hexadecimal number"); } foreach(str_split($hex, 2) as $chunk) { $string .= chr(hexdec($chunk)); } return new self($string); }
[ "public", "static", "function", "fromHex", "(", "$", "hex", ")", "{", "$", "string", "=", "\"\"", ";", "if", "(", "strlen", "(", "$", "hex", ")", "%", "2", "==", "1", ")", "{", "throw", "new", "Exception", "(", "\"given parameter '\"", ".", "$", "hex", ".", "\"' is not a valid hexadecimal number\"", ")", ";", "}", "foreach", "(", "str_split", "(", "$", "hex", ",", "2", ")", "as", "$", "chunk", ")", "{", "$", "string", ".=", "chr", "(", "hexdec", "(", "$", "chunk", ")", ")", ";", "}", "return", "new", "self", "(", "$", "string", ")", ";", "}" ]
Returns the Str based on a given hex value. @param string $hex @throws Exception @return Str
[ "Returns", "the", "Str", "based", "on", "a", "given", "hex", "value", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Helper/Str.php#L529-L544
skmetaly/laravel-twitch-restful-api
src/API/BaseApi.php
BaseApi.getToken
public function getToken($token = null) { if ($token != null) { return $token; } if ($this->token == null) { throw new RequestRequiresAuthenticationException(); } return $this->token; }
php
public function getToken($token = null) { if ($token != null) { return $token; } if ($this->token == null) { throw new RequestRequiresAuthenticationException(); } return $this->token; }
[ "public", "function", "getToken", "(", "$", "token", "=", "null", ")", "{", "if", "(", "$", "token", "!=", "null", ")", "{", "return", "$", "token", ";", "}", "if", "(", "$", "this", "->", "token", "==", "null", ")", "{", "throw", "new", "RequestRequiresAuthenticationException", "(", ")", ";", "}", "return", "$", "this", "->", "token", ";", "}" ]
@param null $token @return null @throws RequestRequiresAuthenticationException
[ "@param", "null", "$token" ]
train
https://github.com/skmetaly/laravel-twitch-restful-api/blob/70c83e441deb411ade2e343ad5cb0339c90dc6c2/src/API/BaseApi.php#L58-L71
skmetaly/laravel-twitch-restful-api
src/API/BaseApi.php
BaseApi.createRequest
protected function createRequest($type, $url, $token) { return $this->client->createRequest($type, $url, $this->getDefaultHeaders($token)); }
php
protected function createRequest($type, $url, $token) { return $this->client->createRequest($type, $url, $this->getDefaultHeaders($token)); }
[ "protected", "function", "createRequest", "(", "$", "type", ",", "$", "url", ",", "$", "token", ")", "{", "return", "$", "this", "->", "client", "->", "createRequest", "(", "$", "type", ",", "$", "url", ",", "$", "this", "->", "getDefaultHeaders", "(", "$", "token", ")", ")", ";", "}" ]
Creates an authorized request @param $type @param $url @param $token @return \GuzzleHttp\Message\Request|\GuzzleHttp\Message\RequestInterface
[ "Creates", "an", "authorized", "request" ]
train
https://github.com/skmetaly/laravel-twitch-restful-api/blob/70c83e441deb411ade2e343ad5cb0339c90dc6c2/src/API/BaseApi.php#L82-L85
NuclearCMS/Hierarchy
src/Builders/BuilderService.php
BuilderService.buildTable
public function buildTable($name, $id) { $this->modelBuilder->build($name); $this->formBuilder->build($name); $migration = $this->migrationBuilder->buildSourceTableMigration($name); $this->migrateUp($migration); }
php
public function buildTable($name, $id) { $this->modelBuilder->build($name); $this->formBuilder->build($name); $migration = $this->migrationBuilder->buildSourceTableMigration($name); $this->migrateUp($migration); }
[ "public", "function", "buildTable", "(", "$", "name", ",", "$", "id", ")", "{", "$", "this", "->", "modelBuilder", "->", "build", "(", "$", "name", ")", ";", "$", "this", "->", "formBuilder", "->", "build", "(", "$", "name", ")", ";", "$", "migration", "=", "$", "this", "->", "migrationBuilder", "->", "buildSourceTableMigration", "(", "$", "name", ")", ";", "$", "this", "->", "migrateUp", "(", "$", "migration", ")", ";", "}" ]
Builds a source table and associated entities @param string $name @param int $id
[ "Builds", "a", "source", "table", "and", "associated", "entities" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/BuilderService.php#L50-L57
NuclearCMS/Hierarchy
src/Builders/BuilderService.php
BuilderService.buildField
public function buildField($name, $type, $indexed, $tableName, NodeTypeContract $nodeType) { $this->modelBuilder->build($tableName, $nodeType->getFields()); $this->buildForm($nodeType); $migration = $this->migrationBuilder->buildFieldMigrationForTable($name, $type, $indexed, $tableName); $this->migrateUp($migration); }
php
public function buildField($name, $type, $indexed, $tableName, NodeTypeContract $nodeType) { $this->modelBuilder->build($tableName, $nodeType->getFields()); $this->buildForm($nodeType); $migration = $this->migrationBuilder->buildFieldMigrationForTable($name, $type, $indexed, $tableName); $this->migrateUp($migration); }
[ "public", "function", "buildField", "(", "$", "name", ",", "$", "type", ",", "$", "indexed", ",", "$", "tableName", ",", "NodeTypeContract", "$", "nodeType", ")", "{", "$", "this", "->", "modelBuilder", "->", "build", "(", "$", "tableName", ",", "$", "nodeType", "->", "getFields", "(", ")", ")", ";", "$", "this", "->", "buildForm", "(", "$", "nodeType", ")", ";", "$", "migration", "=", "$", "this", "->", "migrationBuilder", "->", "buildFieldMigrationForTable", "(", "$", "name", ",", "$", "type", ",", "$", "indexed", ",", "$", "tableName", ")", ";", "$", "this", "->", "migrateUp", "(", "$", "migration", ")", ";", "}" ]
Builds a field on a source table and associated entities @param string $name @param string $type @param bool $indexed @param string $tableName @param NodeTypeContract $nodeType
[ "Builds", "a", "field", "on", "a", "source", "table", "and", "associated", "entities" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/BuilderService.php#L68-L75
NuclearCMS/Hierarchy
src/Builders/BuilderService.php
BuilderService.buildForm
public function buildForm(NodeTypeContract $nodeType) { $this->formBuilder->build($nodeType->getName(), $nodeType->getFields()); }
php
public function buildForm(NodeTypeContract $nodeType) { $this->formBuilder->build($nodeType->getName(), $nodeType->getFields()); }
[ "public", "function", "buildForm", "(", "NodeTypeContract", "$", "nodeType", ")", "{", "$", "this", "->", "formBuilder", "->", "build", "(", "$", "nodeType", "->", "getName", "(", ")", ",", "$", "nodeType", "->", "getFields", "(", ")", ")", ";", "}" ]
(Re)builds a form for given NodeType @param NodeTypeContract $nodeType
[ "(", "Re", ")", "builds", "a", "form", "for", "given", "NodeType" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/BuilderService.php#L82-L85
NuclearCMS/Hierarchy
src/Builders/BuilderService.php
BuilderService.destroyTable
public function destroyTable($name, array $fields, $id) { $this->modelBuilder->destroy($name); $this->formBuilder->destroy($name); $migration = $this->migrationBuilder ->getMigrationClassPathByKey($name); $this->migrateDown($migration); $this->migrationBuilder->destroySourceTableMigration($name, $fields); }
php
public function destroyTable($name, array $fields, $id) { $this->modelBuilder->destroy($name); $this->formBuilder->destroy($name); $migration = $this->migrationBuilder ->getMigrationClassPathByKey($name); $this->migrateDown($migration); $this->migrationBuilder->destroySourceTableMigration($name, $fields); }
[ "public", "function", "destroyTable", "(", "$", "name", ",", "array", "$", "fields", ",", "$", "id", ")", "{", "$", "this", "->", "modelBuilder", "->", "destroy", "(", "$", "name", ")", ";", "$", "this", "->", "formBuilder", "->", "destroy", "(", "$", "name", ")", ";", "$", "migration", "=", "$", "this", "->", "migrationBuilder", "->", "getMigrationClassPathByKey", "(", "$", "name", ")", ";", "$", "this", "->", "migrateDown", "(", "$", "migration", ")", ";", "$", "this", "->", "migrationBuilder", "->", "destroySourceTableMigration", "(", "$", "name", ",", "$", "fields", ")", ";", "}" ]
Destroys a source table and all associated entities @param string $name @param array $fields @param int $id
[ "Destroys", "a", "source", "table", "and", "all", "associated", "entities" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/BuilderService.php#L94-L105
NuclearCMS/Hierarchy
src/Builders/BuilderService.php
BuilderService.destroyField
public function destroyField($name, $tableName, NodeTypeContract $nodeType) { $this->modelBuilder->build($tableName, $nodeType->getFields()); $this->formBuilder->build($tableName, $nodeType->getFields()); $migration = $this->migrationBuilder ->getMigrationClassPathByKey($tableName, $name); $this->migrateDown($migration); $this->migrationBuilder->destroyFieldMigrationForTable($name, $tableName); }
php
public function destroyField($name, $tableName, NodeTypeContract $nodeType) { $this->modelBuilder->build($tableName, $nodeType->getFields()); $this->formBuilder->build($tableName, $nodeType->getFields()); $migration = $this->migrationBuilder ->getMigrationClassPathByKey($tableName, $name); $this->migrateDown($migration); $this->migrationBuilder->destroyFieldMigrationForTable($name, $tableName); }
[ "public", "function", "destroyField", "(", "$", "name", ",", "$", "tableName", ",", "NodeTypeContract", "$", "nodeType", ")", "{", "$", "this", "->", "modelBuilder", "->", "build", "(", "$", "tableName", ",", "$", "nodeType", "->", "getFields", "(", ")", ")", ";", "$", "this", "->", "formBuilder", "->", "build", "(", "$", "tableName", ",", "$", "nodeType", "->", "getFields", "(", ")", ")", ";", "$", "migration", "=", "$", "this", "->", "migrationBuilder", "->", "getMigrationClassPathByKey", "(", "$", "tableName", ",", "$", "name", ")", ";", "$", "this", "->", "migrateDown", "(", "$", "migration", ")", ";", "$", "this", "->", "migrationBuilder", "->", "destroyFieldMigrationForTable", "(", "$", "name", ",", "$", "tableName", ")", ";", "}" ]
Destroys a field on a source table and all associated entities @param string $name @param string $tableName @param NodeTypeContract $nodeType
[ "Destroys", "a", "field", "on", "a", "source", "table", "and", "all", "associated", "entities" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/BuilderService.php#L114-L125
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Filter/Filter.php
Filter.attach
public function attach($fqcn, $filter, $priority = self::DEFAULT_PRIORITY) { $chain = $this->factory->getChainFor($fqcn); $chain->attach($filter, $priority); }
php
public function attach($fqcn, $filter, $priority = self::DEFAULT_PRIORITY) { $chain = $this->factory->getChainFor($fqcn); $chain->attach($filter, $priority); }
[ "public", "function", "attach", "(", "$", "fqcn", ",", "$", "filter", ",", "$", "priority", "=", "self", "::", "DEFAULT_PRIORITY", ")", "{", "$", "chain", "=", "$", "this", "->", "factory", "->", "getChainFor", "(", "$", "fqcn", ")", ";", "$", "chain", "->", "attach", "(", "$", "filter", ",", "$", "priority", ")", ";", "}" ]
Attaches a filter to a specific FQCN. @param string $fqcn @param FilterInterface $filter @param int $priority [1000] @return void
[ "Attaches", "a", "filter", "to", "a", "specific", "FQCN", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Filter/Filter.php#L49-L53
ronaldborla/chikka
src/Borla/Chikka/Adapters/Timestamp/TimestampTrait.php
TimestampTrait.setTimestampAttribute
public function setTimestampAttribute($value) { // If nothing if ( ! $value) { // Creat new return new Carbon(null, $this->getTimezone()); } // Use carbon return ($value instanceof Carbon) ? $value : Carbon::createFromTimestamp($value, $this->getTimezone()); }
php
public function setTimestampAttribute($value) { // If nothing if ( ! $value) { // Creat new return new Carbon(null, $this->getTimezone()); } // Use carbon return ($value instanceof Carbon) ? $value : Carbon::createFromTimestamp($value, $this->getTimezone()); }
[ "public", "function", "setTimestampAttribute", "(", "$", "value", ")", "{", "// If nothing", "if", "(", "!", "$", "value", ")", "{", "// Creat new ", "return", "new", "Carbon", "(", "null", ",", "$", "this", "->", "getTimezone", "(", ")", ")", ";", "}", "// Use carbon", "return", "(", "$", "value", "instanceof", "Carbon", ")", "?", "$", "value", ":", "Carbon", "::", "createFromTimestamp", "(", "$", "value", ",", "$", "this", "->", "getTimezone", "(", ")", ")", ";", "}" ]
Set timestamp
[ "Set", "timestamp" ]
train
https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Adapters/Timestamp/TimestampTrait.php#L15-L23
jasny/controller
src/Controller/RouteAction.php
RouteAction.getRoute
protected function getRoute() { $route = $this->getRequest()->getAttribute('route'); if (!isset($route)) { throw new \LogicException("Route has not been set"); } if (is_array($route)) { $route = (object)$route; } if (!$route instanceof \stdClass) { $type = (is_object($route) ? get_class($route) . ' ' : '') . gettype($route); throw new \UnexpectedValueException("Expected route to be a stdClass object, not a $type"); } return $route; }
php
protected function getRoute() { $route = $this->getRequest()->getAttribute('route'); if (!isset($route)) { throw new \LogicException("Route has not been set"); } if (is_array($route)) { $route = (object)$route; } if (!$route instanceof \stdClass) { $type = (is_object($route) ? get_class($route) . ' ' : '') . gettype($route); throw new \UnexpectedValueException("Expected route to be a stdClass object, not a $type"); } return $route; }
[ "protected", "function", "getRoute", "(", ")", "{", "$", "route", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getAttribute", "(", "'route'", ")", ";", "if", "(", "!", "isset", "(", "$", "route", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "\"Route has not been set\"", ")", ";", "}", "if", "(", "is_array", "(", "$", "route", ")", ")", "{", "$", "route", "=", "(", "object", ")", "$", "route", ";", "}", "if", "(", "!", "$", "route", "instanceof", "\\", "stdClass", ")", "{", "$", "type", "=", "(", "is_object", "(", "$", "route", ")", "?", "get_class", "(", "$", "route", ")", ".", "' '", ":", "''", ")", ".", "gettype", "(", "$", "route", ")", ";", "throw", "new", "\\", "UnexpectedValueException", "(", "\"Expected route to be a stdClass object, not a $type\"", ")", ";", "}", "return", "$", "route", ";", "}" ]
Get the route @return \stdClass
[ "Get", "the", "route" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/RouteAction.php#L48-L66
jasny/controller
src/Controller/RouteAction.php
RouteAction.run
public function run() { $route = $this->getRoute(); $method = $this->getActionMethod(isset($route->action) ? $route->action : 'default'); if (!method_exists($this, $method)) { return $this->notFound(); } $this->before(); if (!$this->isCancelled()) { $args = isset($route->args) ? $route->args : $this->getFunctionArgs($route, new \ReflectionMethod($this, $method)); call_user_func_array([$this, $method], $args); } $this->after(); }
php
public function run() { $route = $this->getRoute(); $method = $this->getActionMethod(isset($route->action) ? $route->action : 'default'); if (!method_exists($this, $method)) { return $this->notFound(); } $this->before(); if (!$this->isCancelled()) { $args = isset($route->args) ? $route->args : $this->getFunctionArgs($route, new \ReflectionMethod($this, $method)); call_user_func_array([$this, $method], $args); } $this->after(); }
[ "public", "function", "run", "(", ")", "{", "$", "route", "=", "$", "this", "->", "getRoute", "(", ")", ";", "$", "method", "=", "$", "this", "->", "getActionMethod", "(", "isset", "(", "$", "route", "->", "action", ")", "?", "$", "route", "->", "action", ":", "'default'", ")", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "return", "$", "this", "->", "notFound", "(", ")", ";", "}", "$", "this", "->", "before", "(", ")", ";", "if", "(", "!", "$", "this", "->", "isCancelled", "(", ")", ")", "{", "$", "args", "=", "isset", "(", "$", "route", "->", "args", ")", "?", "$", "route", "->", "args", ":", "$", "this", "->", "getFunctionArgs", "(", "$", "route", ",", "new", "\\", "ReflectionMethod", "(", "$", "this", ",", "$", "method", ")", ")", ";", "call_user_func_array", "(", "[", "$", "this", ",", "$", "method", "]", ",", "$", "args", ")", ";", "}", "$", "this", "->", "after", "(", ")", ";", "}" ]
Run the controller @return ResponseInterface
[ "Run", "the", "controller" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/RouteAction.php#L133-L152