repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
thenbsp/wechat
src/Menu/Create.php
Create.getRequestBody
public function getRequestBody() { $data = []; foreach ($this->buttons as $k => $v) { $data['button'][$k] = $v->getData(); } return $data; }
php
public function getRequestBody() { $data = []; foreach ($this->buttons as $k => $v) { $data['button'][$k] = $v->getData(); } return $data; }
[ "public", "function", "getRequestBody", "(", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "buttons", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "data", "[", "'button'", "]", "[", "$", "k", "]", "=", "$", "...
获取数据.
[ "获取数据", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Menu/Create.php#L78-L87
thenbsp/wechat
src/OAuth/AbstractClient.php
AbstractClient.getAuthorizeUrl
public function getAuthorizeUrl() { if (null === $this->state) { $this->state = Util::getRandomString(16); } $this->stateManager->setState($this->state); $query = [ 'appid' => $this->appid, 'redirect_uri' => $this->redirectUri ?: Util::getCurrentUrl(), 'response_type' => 'code', 'scope' => $this->resolveScope(), 'state' => $this->state, ]; return $this->resolveAuthorizeUrl().'?'.http_build_query($query); }
php
public function getAuthorizeUrl() { if (null === $this->state) { $this->state = Util::getRandomString(16); } $this->stateManager->setState($this->state); $query = [ 'appid' => $this->appid, 'redirect_uri' => $this->redirectUri ?: Util::getCurrentUrl(), 'response_type' => 'code', 'scope' => $this->resolveScope(), 'state' => $this->state, ]; return $this->resolveAuthorizeUrl().'?'.http_build_query($query); }
[ "public", "function", "getAuthorizeUrl", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "state", ")", "{", "$", "this", "->", "state", "=", "Util", "::", "getRandomString", "(", "16", ")", ";", "}", "$", "this", "->", "stateManager", "->...
获取授权 URL.
[ "获取授权", "URL", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/OAuth/AbstractClient.php#L82-L99
thenbsp/wechat
src/OAuth/AbstractClient.php
AbstractClient.getAccessToken
public function getAccessToken($code, $state = null) { if (null === $state && !isset($_GET['state'])) { throw new \Exception('Invalid Request'); } // http://www.twobotechnologies.com/blog/2014/02/importance-of-state-in-oauth2.html $state = $state ?: $_GET['state']; if (!$this->stateManager->isValid($state)) { throw new \Exception(sprintf('Invalid Authentication State "%s"', $state)); } $query = [ 'appid' => $this->appid, 'secret' => $this->appsecret, 'code' => $code, 'grant_type' => 'authorization_code', ]; $response = Http::request('GET', static::ACCESS_TOKEN) ->withQuery($query) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return new AccessToken($this->appid, $response->toArray()); }
php
public function getAccessToken($code, $state = null) { if (null === $state && !isset($_GET['state'])) { throw new \Exception('Invalid Request'); } // http://www.twobotechnologies.com/blog/2014/02/importance-of-state-in-oauth2.html $state = $state ?: $_GET['state']; if (!$this->stateManager->isValid($state)) { throw new \Exception(sprintf('Invalid Authentication State "%s"', $state)); } $query = [ 'appid' => $this->appid, 'secret' => $this->appsecret, 'code' => $code, 'grant_type' => 'authorization_code', ]; $response = Http::request('GET', static::ACCESS_TOKEN) ->withQuery($query) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return new AccessToken($this->appid, $response->toArray()); }
[ "public", "function", "getAccessToken", "(", "$", "code", ",", "$", "state", "=", "null", ")", "{", "if", "(", "null", "===", "$", "state", "&&", "!", "isset", "(", "$", "_GET", "[", "'state'", "]", ")", ")", "{", "throw", "new", "\\", "Exception",...
通过 code 换取 AccessToken.
[ "通过", "code", "换取", "AccessToken", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/OAuth/AbstractClient.php#L104-L132
thenbsp/wechat
src/Bridge/Serializer.php
Serializer.jsonEncode
public static function jsonEncode($data, array $context = []) { $defaults = [ 'json_encode_options' => defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0, ]; return (new JsonEncoder())->encode($data, 'json', array_replace($defaults, $context)); }
php
public static function jsonEncode($data, array $context = []) { $defaults = [ 'json_encode_options' => defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0, ]; return (new JsonEncoder())->encode($data, 'json', array_replace($defaults, $context)); }
[ "public", "static", "function", "jsonEncode", "(", "$", "data", ",", "array", "$", "context", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'json_encode_options'", "=>", "defined", "(", "'JSON_UNESCAPED_UNICODE'", ")", "?", "JSON_UNESCAPED_UNICODE", ":"...
json encode.
[ "json", "encode", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Bridge/Serializer.php#L13-L22
thenbsp/wechat
src/Bridge/Serializer.php
Serializer.jsonDecode
public static function jsonDecode($data, array $context = []) { $defaults = [ 'json_decode_associative' => true, 'json_decode_recursion_depth' => 512, 'json_decode_options' => 0, ]; return (new JsonEncoder())->decode($data, 'json', array_replace($defaults, $context)); }
php
public static function jsonDecode($data, array $context = []) { $defaults = [ 'json_decode_associative' => true, 'json_decode_recursion_depth' => 512, 'json_decode_options' => 0, ]; return (new JsonEncoder())->decode($data, 'json', array_replace($defaults, $context)); }
[ "public", "static", "function", "jsonDecode", "(", "$", "data", ",", "array", "$", "context", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'json_decode_associative'", "=>", "true", ",", "'json_decode_recursion_depth'", "=>", "512", ",", "'json_decode_o...
json decode.
[ "json", "decode", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Bridge/Serializer.php#L27-L36
thenbsp/wechat
src/Bridge/Serializer.php
Serializer.xmlEncode
public static function xmlEncode($data, array $context = []) { $defaults = [ 'xml_root_node_name' => 'xml', 'xml_format_output' => true, 'xml_version' => '1.0', 'xml_encoding' => 'utf-8', 'xml_standalone' => false, ]; return (new XmlEncoder())->encode($data, 'xml', array_replace($defaults, $context)); }
php
public static function xmlEncode($data, array $context = []) { $defaults = [ 'xml_root_node_name' => 'xml', 'xml_format_output' => true, 'xml_version' => '1.0', 'xml_encoding' => 'utf-8', 'xml_standalone' => false, ]; return (new XmlEncoder())->encode($data, 'xml', array_replace($defaults, $context)); }
[ "public", "static", "function", "xmlEncode", "(", "$", "data", ",", "array", "$", "context", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'xml_root_node_name'", "=>", "'xml'", ",", "'xml_format_output'", "=>", "true", ",", "'xml_version'", "=>", "'...
xml encode.
[ "xml", "encode", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Bridge/Serializer.php#L41-L52
thenbsp/wechat
src/Bridge/Serializer.php
Serializer.parse
public static function parse($string) { if (static::isJSON($string)) { $result = static::jsonDecode($string); } elseif (static::isXML($string)) { $result = static::xmlDecode($string); } else { throw new \InvalidArgumentException(sprintf('Unable to parse: %s', (string) $string)); } return (array) $result; }
php
public static function parse($string) { if (static::isJSON($string)) { $result = static::jsonDecode($string); } elseif (static::isXML($string)) { $result = static::xmlDecode($string); } else { throw new \InvalidArgumentException(sprintf('Unable to parse: %s', (string) $string)); } return (array) $result; }
[ "public", "static", "function", "parse", "(", "$", "string", ")", "{", "if", "(", "static", "::", "isJSON", "(", "$", "string", ")", ")", "{", "$", "result", "=", "static", "::", "jsonDecode", "(", "$", "string", ")", ";", "}", "elseif", "(", "stat...
xml/json to array.
[ "xml", "/", "json", "to", "array", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Bridge/Serializer.php#L65-L76
thenbsp/wechat
src/Menu/Button.php
Button.getData
public function getData() { $data = [ 'name' => $this->name, 'type' => $this->type, ]; return array_merge($data, $this->value); }
php
public function getData() { $data = [ 'name' => $this->name, 'type' => $this->type, ]; return array_merge($data, $this->value); }
[ "public", "function", "getData", "(", ")", "{", "$", "data", "=", "[", "'name'", "=>", "$", "this", "->", "name", ",", "'type'", "=>", "$", "this", "->", "type", ",", "]", ";", "return", "array_merge", "(", "$", "data", ",", "$", "this", "->", "v...
菜单数据.
[ "菜单数据", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Menu/Button.php#L55-L63
thenbsp/wechat
src/Event/Event.php
Event.setResponse
public function setResponse(Entity $entity) { $body = $entity->getBody(); $body['ToUserName'] = $this['FromUserName']; $body['FromUserName'] = $this['ToUserName']; $body['MsgType'] = $entity->getType(); $body['CreateTime'] = time(); $response = new XmlResponse($body); $response->send(); }
php
public function setResponse(Entity $entity) { $body = $entity->getBody(); $body['ToUserName'] = $this['FromUserName']; $body['FromUserName'] = $this['ToUserName']; $body['MsgType'] = $entity->getType(); $body['CreateTime'] = time(); $response = new XmlResponse($body); $response->send(); }
[ "public", "function", "setResponse", "(", "Entity", "$", "entity", ")", "{", "$", "body", "=", "$", "entity", "->", "getBody", "(", ")", ";", "$", "body", "[", "'ToUserName'", "]", "=", "$", "this", "[", "'FromUserName'", "]", ";", "$", "body", "[", ...
response message entity.
[ "response", "message", "entity", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Event/Event.php#L14-L25
thenbsp/wechat
src/Wechat/Qrcode.php
Qrcode.getTemporary
public function getTemporary($scene, $expire = 2592000) { $ticket = new Ticket($this->accessToken, Ticket::QR_SCENE, $scene, $expire); if ($this->cache) { $ticket->setCache($this->cache); } return $this->getResourceUrl($ticket); }
php
public function getTemporary($scene, $expire = 2592000) { $ticket = new Ticket($this->accessToken, Ticket::QR_SCENE, $scene, $expire); if ($this->cache) { $ticket->setCache($this->cache); } return $this->getResourceUrl($ticket); }
[ "public", "function", "getTemporary", "(", "$", "scene", ",", "$", "expire", "=", "2592000", ")", "{", "$", "ticket", "=", "new", "Ticket", "(", "$", "this", "->", "accessToken", ",", "Ticket", "::", "QR_SCENE", ",", "$", "scene", ",", "$", "expire", ...
获取临时二维码
[ "获取临时二维码" ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/Qrcode.php#L36-L45
thenbsp/wechat
src/Wechat/Qrcode.php
Qrcode.getForever
public function getForever($scene) { $type = is_int($scene) ? Ticket::QR_LIMIT_SCENE : Ticket::QR_LIMIT_STR_SCENE; $ticket = new Ticket($this->accessToken, $type, $scene); if ($this->cache) { $ticket->setCache($this->cache); } return $this->getResourceUrl($ticket); }
php
public function getForever($scene) { $type = is_int($scene) ? Ticket::QR_LIMIT_SCENE : Ticket::QR_LIMIT_STR_SCENE; $ticket = new Ticket($this->accessToken, $type, $scene); if ($this->cache) { $ticket->setCache($this->cache); } return $this->getResourceUrl($ticket); }
[ "public", "function", "getForever", "(", "$", "scene", ")", "{", "$", "type", "=", "is_int", "(", "$", "scene", ")", "?", "Ticket", "::", "QR_LIMIT_SCENE", ":", "Ticket", "::", "QR_LIMIT_STR_SCENE", ";", "$", "ticket", "=", "new", "Ticket", "(", "$", "...
获取永久二维码
[ "获取永久二维码" ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/Qrcode.php#L50-L63
thenbsp/wechat
src/Event/EventHandler.php
EventHandler.handle
public function handle(EventListenerInterface $listener) { if (!$listener->getListeners()) { return; } $content = $this->request->getContent(); try { $options = Serializer::parse($content); } catch (\InvalidArgumentException $e) { $options = []; } foreach ($listener->getListeners() as $namespace => $callable) { $event = new $namespace($options); if ($event->isValid()) { $listener->trigger($namespace, $event); break; } } }
php
public function handle(EventListenerInterface $listener) { if (!$listener->getListeners()) { return; } $content = $this->request->getContent(); try { $options = Serializer::parse($content); } catch (\InvalidArgumentException $e) { $options = []; } foreach ($listener->getListeners() as $namespace => $callable) { $event = new $namespace($options); if ($event->isValid()) { $listener->trigger($namespace, $event); break; } } }
[ "public", "function", "handle", "(", "EventListenerInterface", "$", "listener", ")", "{", "if", "(", "!", "$", "listener", "->", "getListeners", "(", ")", ")", "{", "return", ";", "}", "$", "content", "=", "$", "this", "->", "request", "->", "getContent"...
handle event via request.
[ "handle", "event", "via", "request", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Event/EventHandler.php#L44-L65
thenbsp/wechat
src/Message/Template/Template.php
Template.add
public function add($key, $value, $color = null) { $array = ['value' => $value]; if (null !== $color) { $array['color'] = $color; } $this->options[$key] = $array; return $this; }
php
public function add($key, $value, $color = null) { $array = ['value' => $value]; if (null !== $color) { $array['color'] = $color; } $this->options[$key] = $array; return $this; }
[ "public", "function", "add", "(", "$", "key", ",", "$", "value", ",", "$", "color", "=", "null", ")", "{", "$", "array", "=", "[", "'value'", "=>", "$", "value", "]", ";", "if", "(", "null", "!==", "$", "color", ")", "{", "$", "array", "[", "...
添加模板参数.
[ "添加模板参数", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Message/Template/Template.php#L84-L95
thenbsp/wechat
src/Message/Template/Template.php
Template.remove
public function remove($key) { if (isset($this->options[$key])) { unset($this->options[$key]); } return $this; }
php
public function remove($key) { if (isset($this->options[$key])) { unset($this->options[$key]); } return $this; }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "options", "[", "$", "key", "]", ")", ";", "}", "return", ...
移除模板参数.
[ "移除模板参数", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Message/Template/Template.php#L100-L107
thenbsp/wechat
src/Message/Template/Sender.php
Sender.send
public function send(TemplateInterface $template) { $response = Http::request('POST', static::SENDER) ->withAccessToken($this->accessToken) ->withBody($template->getRequestBody()) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response['msgid']; }
php
public function send(TemplateInterface $template) { $response = Http::request('POST', static::SENDER) ->withAccessToken($this->accessToken) ->withBody($template->getRequestBody()) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response['msgid']; }
[ "public", "function", "send", "(", "TemplateInterface", "$", "template", ")", "{", "$", "response", "=", "Http", "::", "request", "(", "'POST'", ",", "static", "::", "SENDER", ")", "->", "withAccessToken", "(", "$", "this", "->", "accessToken", ")", "->", ...
发送模板消息.
[ "发送模板消息", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Message/Template/Sender.php#L31-L43
thenbsp/wechat
src/Wechat/Qrcode/Ticket.php
Ticket.getTicketResponse
public function getTicketResponse() { $response = Http::request('POST', static::TICKET_URL) ->withAccessToken($this->accessToken) ->withBody($this->getRequestBody()) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
php
public function getTicketResponse() { $response = Http::request('POST', static::TICKET_URL) ->withAccessToken($this->accessToken) ->withBody($this->getRequestBody()) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
[ "public", "function", "getTicketResponse", "(", ")", "{", "$", "response", "=", "Http", "::", "request", "(", "'POST'", ",", "static", "::", "TICKET_URL", ")", "->", "withAccessToken", "(", "$", "this", "->", "accessToken", ")", "->", "withBody", "(", "$",...
获取 Qrcode 票据(不缓存,返回原始数据).
[ "获取", "Qrcode", "票据(不缓存,返回原始数据)", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/Qrcode/Ticket.php#L107-L119
thenbsp/wechat
src/Wechat/Qrcode/Ticket.php
Ticket.getRequestBody
public function getRequestBody() { $options = [ 'action_name' => $this->type, 'action_info' => [ 'scene' => [$this->sceneKey => $this->scene], ], ]; if ($options['action_name'] === static::QR_SCENE) { $options['expire_seconds'] = $this->expire; } return $options; }
php
public function getRequestBody() { $options = [ 'action_name' => $this->type, 'action_info' => [ 'scene' => [$this->sceneKey => $this->scene], ], ]; if ($options['action_name'] === static::QR_SCENE) { $options['expire_seconds'] = $this->expire; } return $options; }
[ "public", "function", "getRequestBody", "(", ")", "{", "$", "options", "=", "[", "'action_name'", "=>", "$", "this", "->", "type", ",", "'action_info'", "=>", "[", "'scene'", "=>", "[", "$", "this", "->", "sceneKey", "=>", "$", "this", "->", "scene", "...
获取请求内容.
[ "获取请求内容", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/Qrcode/Ticket.php#L124-L138
thenbsp/wechat
src/Wechat/Qrcode/Ticket.php
Ticket.getCacheId
public function getCacheId() { return implode('_', [$this->accessToken['appid'], $this->type, $this->sceneKey, $this->scene]); }
php
public function getCacheId() { return implode('_', [$this->accessToken['appid'], $this->type, $this->sceneKey, $this->scene]); }
[ "public", "function", "getCacheId", "(", ")", "{", "return", "implode", "(", "'_'", ",", "[", "$", "this", "->", "accessToken", "[", "'appid'", "]", ",", "$", "this", "->", "type", ",", "$", "this", "->", "sceneKey", ",", "$", "this", "->", "scene", ...
获取缓存 ID.
[ "获取缓存", "ID", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/Qrcode/Ticket.php#L153-L156
thenbsp/wechat
src/Payment/Jsapi/ConfigGenerator.php
ConfigGenerator.getConfig
public function getConfig($asArray = false) { $config = $this->resolveConfig(); return $asArray ? $config : Serializer::jsonEncode($config); }
php
public function getConfig($asArray = false) { $config = $this->resolveConfig(); return $asArray ? $config : Serializer::jsonEncode($config); }
[ "public", "function", "getConfig", "(", "$", "asArray", "=", "false", ")", "{", "$", "config", "=", "$", "this", "->", "resolveConfig", "(", ")", ";", "return", "$", "asArray", "?", "$", "config", ":", "Serializer", "::", "jsonEncode", "(", "$", "confi...
获取配置.
[ "获取配置", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Payment/Jsapi/ConfigGenerator.php#L44-L49
thenbsp/wechat
src/Menu/Delete.php
Delete.doDelete
public function doDelete() { $response = Http::request('GET', static::DELETE_URL) ->withAccessToken($this->accessToken) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return true; }
php
public function doDelete() { $response = Http::request('GET', static::DELETE_URL) ->withAccessToken($this->accessToken) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return true; }
[ "public", "function", "doDelete", "(", ")", "{", "$", "response", "=", "Http", "::", "request", "(", "'GET'", ",", "static", "::", "DELETE_URL", ")", "->", "withAccessToken", "(", "$", "this", "->", "accessToken", ")", "->", "send", "(", ")", ";", "if"...
获取响应.
[ "获取响应", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Menu/Delete.php#L31-L42
thenbsp/wechat
src/Wechat/ShortUrl.php
ShortUrl.toShort
public function toShort($longUrl, $cacheLifeTime = 86400) { $cacheId = md5($longUrl); if ($this->cache && $data = $this->cache->fetch($cacheId)) { return $data; } $body = [ 'action' => 'long2short', 'long_url' => $longUrl, ]; $response = Http::request('POST', static::SHORT_URL) ->withAccessToken($this->accessToken) ->withBody($body) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } if ($this->cache) { $this->cache->save($cacheId, $response['short_url'], $cacheLifeTime); } return $response['short_url']; }
php
public function toShort($longUrl, $cacheLifeTime = 86400) { $cacheId = md5($longUrl); if ($this->cache && $data = $this->cache->fetch($cacheId)) { return $data; } $body = [ 'action' => 'long2short', 'long_url' => $longUrl, ]; $response = Http::request('POST', static::SHORT_URL) ->withAccessToken($this->accessToken) ->withBody($body) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } if ($this->cache) { $this->cache->save($cacheId, $response['short_url'], $cacheLifeTime); } return $response['short_url']; }
[ "public", "function", "toShort", "(", "$", "longUrl", ",", "$", "cacheLifeTime", "=", "86400", ")", "{", "$", "cacheId", "=", "md5", "(", "$", "longUrl", ")", ";", "if", "(", "$", "this", "->", "cache", "&&", "$", "data", "=", "$", "this", "->", ...
获取短链接.
[ "获取短链接", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/ShortUrl.php#L36-L63
thenbsp/wechat
src/Menu/Query.php
Query.doQuery
public function doQuery() { $response = Http::request('GET', static::QUERY_URL) ->withAccessToken($this->accessToken) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
php
public function doQuery() { $response = Http::request('GET', static::QUERY_URL) ->withAccessToken($this->accessToken) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
[ "public", "function", "doQuery", "(", ")", "{", "$", "response", "=", "Http", "::", "request", "(", "'GET'", ",", "static", "::", "QUERY_URL", ")", "->", "withAccessToken", "(", "$", "this", "->", "accessToken", ")", "->", "send", "(", ")", ";", "if", ...
获取响应结果.
[ "获取响应结果", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Menu/Query.php#L31-L42
thenbsp/wechat
src/User/User.php
User.lists
public function lists($nextOpenid = null) { $query = null === $nextOpenid ? [] : ['next_openid' => $nextOpenid]; $response = Http::request('GET', static::LISTS) ->withAccessToken($this->accessToken) ->withQuery($query) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
php
public function lists($nextOpenid = null) { $query = null === $nextOpenid ? [] : ['next_openid' => $nextOpenid]; $response = Http::request('GET', static::LISTS) ->withAccessToken($this->accessToken) ->withQuery($query) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
[ "public", "function", "lists", "(", "$", "nextOpenid", "=", "null", ")", "{", "$", "query", "=", "null", "===", "$", "nextOpenid", "?", "[", "]", ":", "[", "'next_openid'", "=>", "$", "nextOpenid", "]", ";", "$", "response", "=", "Http", "::", "reque...
查询用户列表.
[ "查询用户列表", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/User/User.php#L42-L58
thenbsp/wechat
src/User/User.php
User.get
public function get($openid, $lang = 'zh_CN') { $query = [ 'openid' => $openid, 'lang' => $lang, ]; $response = Http::request('GET', static::USERINFO) ->withAccessToken($this->accessToken) ->withQuery($query) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
php
public function get($openid, $lang = 'zh_CN') { $query = [ 'openid' => $openid, 'lang' => $lang, ]; $response = Http::request('GET', static::USERINFO) ->withAccessToken($this->accessToken) ->withQuery($query) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
[ "public", "function", "get", "(", "$", "openid", ",", "$", "lang", "=", "'zh_CN'", ")", "{", "$", "query", "=", "[", "'openid'", "=>", "$", "openid", ",", "'lang'", "=>", "$", "lang", ",", "]", ";", "$", "response", "=", "Http", "::", "request", ...
获取用户信息.
[ "获取用户信息", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/User/User.php#L63-L80
thenbsp/wechat
src/User/User.php
User.getBetch
public function getBetch(array $openid, $lang = 'zh_CN') { $body = []; foreach ($openid as $key => $value) { $body['user_list'][$key]['openid'] = $value; $body['user_list'][$key]['lang'] = $lang; } $response = Http::request('POST', static::BETCH) ->withAccessToken($this->accessToken) ->withBody($body) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return new ArrayCollection($response['user_info_list']); }
php
public function getBetch(array $openid, $lang = 'zh_CN') { $body = []; foreach ($openid as $key => $value) { $body['user_list'][$key]['openid'] = $value; $body['user_list'][$key]['lang'] = $lang; } $response = Http::request('POST', static::BETCH) ->withAccessToken($this->accessToken) ->withBody($body) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return new ArrayCollection($response['user_info_list']); }
[ "public", "function", "getBetch", "(", "array", "$", "openid", ",", "$", "lang", "=", "'zh_CN'", ")", "{", "$", "body", "=", "[", "]", ";", "foreach", "(", "$", "openid", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "body", "[", "'user_li...
批量获取用户信息.
[ "批量获取用户信息", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/User/User.php#L85-L104
thenbsp/wechat
src/Bridge/Http.php
Http.withSSLCert
public function withSSLCert($sslCert, $sslKey) { $this->sslCert = $sslCert; $this->sslKey = $sslKey; return $this; }
php
public function withSSLCert($sslCert, $sslKey) { $this->sslCert = $sslCert; $this->sslKey = $sslKey; return $this; }
[ "public", "function", "withSSLCert", "(", "$", "sslCert", ",", "$", "sslKey", ")", "{", "$", "this", "->", "sslCert", "=", "$", "sslCert", ";", "$", "this", "->", "sslKey", "=", "$", "sslKey", ";", "return", "$", "this", ";", "}" ]
Request SSL Cert.
[ "Request", "SSL", "Cert", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Bridge/Http.php#L102-L108
thenbsp/wechat
src/Bridge/Http.php
Http.send
public function send($asArray = true) { $options = []; // query if (!empty($this->query)) { $options['query'] = $this->query; } // body if (!empty($this->body)) { $options['body'] = $this->body; } // ssl cert if ($this->sslCert && $this->sslKey) { $options['cert'] = $this->sslCert; $options['ssl_key'] = $this->sslKey; } $response = (new Client())->request($this->method, $this->uri, $options); $contents = $response->getBody()->getContents(); if (!$asArray) { return $contents; } $array = Serializer::parse($contents); return new ArrayCollection($array); }
php
public function send($asArray = true) { $options = []; // query if (!empty($this->query)) { $options['query'] = $this->query; } // body if (!empty($this->body)) { $options['body'] = $this->body; } // ssl cert if ($this->sslCert && $this->sslKey) { $options['cert'] = $this->sslCert; $options['ssl_key'] = $this->sslKey; } $response = (new Client())->request($this->method, $this->uri, $options); $contents = $response->getBody()->getContents(); if (!$asArray) { return $contents; } $array = Serializer::parse($contents); return new ArrayCollection($array); }
[ "public", "function", "send", "(", "$", "asArray", "=", "true", ")", "{", "$", "options", "=", "[", "]", ";", "// query", "if", "(", "!", "empty", "(", "$", "this", "->", "query", ")", ")", "{", "$", "options", "[", "'query'", "]", "=", "$", "t...
Send Request.
[ "Send", "Request", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Bridge/Http.php#L113-L143
thenbsp/wechat
src/Payment/Address/ConfigGenerator.php
ConfigGenerator.setAccessToken
public function setAccessToken(AccessToken $accessToken) { if (!$accessToken->isValid()) { $accessToken->refresh(); } $this->accessToken = $accessToken; }
php
public function setAccessToken(AccessToken $accessToken) { if (!$accessToken->isValid()) { $accessToken->refresh(); } $this->accessToken = $accessToken; }
[ "public", "function", "setAccessToken", "(", "AccessToken", "$", "accessToken", ")", "{", "if", "(", "!", "$", "accessToken", "->", "isValid", "(", ")", ")", "{", "$", "accessToken", "->", "refresh", "(", ")", ";", "}", "$", "this", "->", "accessToken", ...
设置用户 AccessToken.
[ "设置用户", "AccessToken", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Payment/Address/ConfigGenerator.php#L27-L34
thenbsp/wechat
src/Payment/Address/ConfigGenerator.php
ConfigGenerator.getConfig
public function getConfig($asArray = false) { $options = [ 'appid' => $this->accessToken->getAppid(), 'url' => Util::getCurrentUrl(), 'timestamp' => Util::getTimestamp(), 'noncestr' => Util::getRandomString(), 'accesstoken' => $this->accessToken['access_token'], ]; // 按 ASCII 码排序 ksort($options); $signature = http_build_query($options); $signature = urldecode($signature); $signature = sha1($signature); $config = [ 'appId' => $options['appid'], 'scope' => 'jsapi_address', 'signType' => 'sha1', 'addrSign' => $signature, 'timeStamp' => $options['timestamp'], 'nonceStr' => $options['noncestr'], ]; return $asArray ? $config : Serializer::jsonEncode($config); }
php
public function getConfig($asArray = false) { $options = [ 'appid' => $this->accessToken->getAppid(), 'url' => Util::getCurrentUrl(), 'timestamp' => Util::getTimestamp(), 'noncestr' => Util::getRandomString(), 'accesstoken' => $this->accessToken['access_token'], ]; // 按 ASCII 码排序 ksort($options); $signature = http_build_query($options); $signature = urldecode($signature); $signature = sha1($signature); $config = [ 'appId' => $options['appid'], 'scope' => 'jsapi_address', 'signType' => 'sha1', 'addrSign' => $signature, 'timeStamp' => $options['timestamp'], 'nonceStr' => $options['noncestr'], ]; return $asArray ? $config : Serializer::jsonEncode($config); }
[ "public", "function", "getConfig", "(", "$", "asArray", "=", "false", ")", "{", "$", "options", "=", "[", "'appid'", "=>", "$", "this", "->", "accessToken", "->", "getAppid", "(", ")", ",", "'url'", "=>", "Util", "::", "getCurrentUrl", "(", ")", ",", ...
获取配置.
[ "获取配置", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Payment/Address/ConfigGenerator.php#L39-L66
thenbsp/wechat
src/Message/Entity/Music.php
Music.getBody
public function getBody() { $body = [ 'Title' => $this->title, 'Description' => $this->description, 'MusicUrl' => $this->musicUrl, 'HQMusicUrl' => $this->HQMusicUrl, 'ThumbMediaId' => $this->thumbMediaId, ]; return ['Music' => $body]; }
php
public function getBody() { $body = [ 'Title' => $this->title, 'Description' => $this->description, 'MusicUrl' => $this->musicUrl, 'HQMusicUrl' => $this->HQMusicUrl, 'ThumbMediaId' => $this->thumbMediaId, ]; return ['Music' => $body]; }
[ "public", "function", "getBody", "(", ")", "{", "$", "body", "=", "[", "'Title'", "=>", "$", "this", "->", "title", ",", "'Description'", "=>", "$", "this", "->", "description", ",", "'MusicUrl'", "=>", "$", "this", "->", "musicUrl", ",", "'HQMusicUrl'",...
消息内容.
[ "消息内容", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Message/Entity/Music.php#L77-L88
thenbsp/wechat
src/Wechat/Jsapi.php
Jsapi.addApi
public function addApi($apis) { if (is_array($apis)) { foreach ($apis as $api) { $this->addApi($api); } } $apiName = (string) $apis; if (!in_array($apiName, $this->apiValids, true)) { throw new \InvalidArgumentException(sprintf('Invalid Api: %s', $apiName)); } array_push($this->api, $apiName); return $this; }
php
public function addApi($apis) { if (is_array($apis)) { foreach ($apis as $api) { $this->addApi($api); } } $apiName = (string) $apis; if (!in_array($apiName, $this->apiValids, true)) { throw new \InvalidArgumentException(sprintf('Invalid Api: %s', $apiName)); } array_push($this->api, $apiName); return $this; }
[ "public", "function", "addApi", "(", "$", "apis", ")", "{", "if", "(", "is_array", "(", "$", "apis", ")", ")", "{", "foreach", "(", "$", "apis", "as", "$", "api", ")", "{", "$", "this", "->", "addApi", "(", "$", "api", ")", ";", "}", "}", "$"...
注入接口.
[ "注入接口", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/Jsapi.php#L71-L88
thenbsp/wechat
src/Wechat/Jsapi.php
Jsapi.getConfig
public function getConfig($asArray = false) { $ticket = new Ticket($this->accessToken); if ($this->cache) { $ticket->setCache($this->cache); } $options = [ 'jsapi_ticket' => $ticket->getTicketString(), 'timestamp' => Util::getTimestamp(), 'url' => $this->currentUrl ?: Util::getCurrentUrl(), 'noncestr' => Util::getRandomString(), ]; ksort($options); $signature = sha1(urldecode(http_build_query($options))); $configure = [ 'appId' => $this->accessToken['appid'], 'nonceStr' => $options['noncestr'], 'timestamp' => $options['timestamp'], 'signature' => $signature, 'jsApiList' => $this->api, 'debug' => (bool) $this->debug, ]; return $asArray ? $configure : Serializer::jsonEncode($configure); }
php
public function getConfig($asArray = false) { $ticket = new Ticket($this->accessToken); if ($this->cache) { $ticket->setCache($this->cache); } $options = [ 'jsapi_ticket' => $ticket->getTicketString(), 'timestamp' => Util::getTimestamp(), 'url' => $this->currentUrl ?: Util::getCurrentUrl(), 'noncestr' => Util::getRandomString(), ]; ksort($options); $signature = sha1(urldecode(http_build_query($options))); $configure = [ 'appId' => $this->accessToken['appid'], 'nonceStr' => $options['noncestr'], 'timestamp' => $options['timestamp'], 'signature' => $signature, 'jsApiList' => $this->api, 'debug' => (bool) $this->debug, ]; return $asArray ? $configure : Serializer::jsonEncode($configure); }
[ "public", "function", "getConfig", "(", "$", "asArray", "=", "false", ")", "{", "$", "ticket", "=", "new", "Ticket", "(", "$", "this", "->", "accessToken", ")", ";", "if", "(", "$", "this", "->", "cache", ")", "{", "$", "ticket", "->", "setCache", ...
获取配置文件.
[ "获取配置文件", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/Jsapi.php#L103-L131
thenbsp/wechat
src/Payment/Notify.php
Notify.fail
public function fail($message = null) { $options = ['return_code' => self::FAIL]; if (null !== $message) { $options['return_msg'] = $message; } $this->xmlResponse($options); }
php
public function fail($message = null) { $options = ['return_code' => self::FAIL]; if (null !== $message) { $options['return_msg'] = $message; } $this->xmlResponse($options); }
[ "public", "function", "fail", "(", "$", "message", "=", "null", ")", "{", "$", "options", "=", "[", "'return_code'", "=>", "self", "::", "FAIL", "]", ";", "if", "(", "null", "!==", "$", "message", ")", "{", "$", "options", "[", "'return_msg'", "]", ...
错误响应.
[ "错误响应", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Payment/Notify.php#L42-L51
thenbsp/wechat
src/Payment/Notify.php
Notify.success
public function success($message = null) { $options = ['return_code' => self::SUCCESS]; if (null !== $message) { $options['return_msg'] = $message; } $this->xmlResponse($options); }
php
public function success($message = null) { $options = ['return_code' => self::SUCCESS]; if (null !== $message) { $options['return_msg'] = $message; } $this->xmlResponse($options); }
[ "public", "function", "success", "(", "$", "message", "=", "null", ")", "{", "$", "options", "=", "[", "'return_code'", "=>", "self", "::", "SUCCESS", "]", ";", "if", "(", "null", "!==", "$", "message", ")", "{", "$", "options", "[", "'return_msg'", ...
成功响应.
[ "成功响应", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Payment/Notify.php#L56-L65
thenbsp/wechat
src/Wechat/AccessToken.php
AccessToken.getTokenString
public function getTokenString() { $cacheId = $this->getCacheId(); if ($this->cache && $data = $this->cache->fetch($cacheId)) { return $data['access_token']; } $response = $this->getTokenResponse(); if ($this->cache) { $this->cache->save($cacheId, $response, $response['expires_in']); } return $response['access_token']; }
php
public function getTokenString() { $cacheId = $this->getCacheId(); if ($this->cache && $data = $this->cache->fetch($cacheId)) { return $data['access_token']; } $response = $this->getTokenResponse(); if ($this->cache) { $this->cache->save($cacheId, $response, $response['expires_in']); } return $response['access_token']; }
[ "public", "function", "getTokenString", "(", ")", "{", "$", "cacheId", "=", "$", "this", "->", "getCacheId", "(", ")", ";", "if", "(", "$", "this", "->", "cache", "&&", "$", "data", "=", "$", "this", "->", "cache", "->", "fetch", "(", "$", "cacheId...
获取 AccessToken(调用缓存,返回 String).
[ "获取", "AccessToken(调用缓存,返回", "String)", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/AccessToken.php#L33-L48
thenbsp/wechat
src/Wechat/AccessToken.php
AccessToken.getTokenResponse
public function getTokenResponse() { $query = [ 'grant_type' => 'client_credential', 'appid' => $this['appid'], 'secret' => $this['appsecret'], ]; $response = Http::request('GET', static::ACCESS_TOKEN) ->withQuery($query) ->send(); if ($response->containsKey('errcode')) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
php
public function getTokenResponse() { $query = [ 'grant_type' => 'client_credential', 'appid' => $this['appid'], 'secret' => $this['appsecret'], ]; $response = Http::request('GET', static::ACCESS_TOKEN) ->withQuery($query) ->send(); if ($response->containsKey('errcode')) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
[ "public", "function", "getTokenResponse", "(", ")", "{", "$", "query", "=", "[", "'grant_type'", "=>", "'client_credential'", ",", "'appid'", "=>", "$", "this", "[", "'appid'", "]", ",", "'secret'", "=>", "$", "this", "[", "'appsecret'", "]", ",", "]", "...
获取 AccessToken(不缓存,返回原始数据).
[ "获取", "AccessToken(不缓存,返回原始数据)", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Wechat/AccessToken.php#L53-L70
thenbsp/wechat
src/User/Remark.php
Remark.update
public function update($openid, $remark) { $body = [ 'openid' => $openid, 'remark' => $remark, ]; $response = Http::request('POST', static::REMARK) ->withAccessToken($this->accessToken) ->withBody($body) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
php
public function update($openid, $remark) { $body = [ 'openid' => $openid, 'remark' => $remark, ]; $response = Http::request('POST', static::REMARK) ->withAccessToken($this->accessToken) ->withBody($body) ->send(); if (0 != $response['errcode']) { throw new \Exception($response['errmsg'], $response['errcode']); } return $response; }
[ "public", "function", "update", "(", "$", "openid", ",", "$", "remark", ")", "{", "$", "body", "=", "[", "'openid'", "=>", "$", "openid", ",", "'remark'", "=>", "$", "remark", ",", "]", ";", "$", "response", "=", "Http", "::", "request", "(", "'POS...
设置/更新用户备注.
[ "设置", "/", "更新用户备注", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/User/Remark.php#L31-L48
thenbsp/wechat
src/Payment/Unifiedorder.php
Unifiedorder.getResponse
public function getResponse() { $options = $this->resolveOptions(); // 按 ASCII 码排序 ksort($options); $signature = urldecode(http_build_query($options)); $signature = strtoupper(md5($signature.'&key='.$this->key)); $options['sign'] = $signature; $response = Http::request('POST', static::UNIFIEDORDER) ->withXmlBody($options) ->send(); if ('FAIL' === $response['return_code']) { throw new \Exception($response['return_msg']); } if ('FAIL' === $response['result_code']) { throw new \Exception($response['err_code_des']); } return $response; }
php
public function getResponse() { $options = $this->resolveOptions(); // 按 ASCII 码排序 ksort($options); $signature = urldecode(http_build_query($options)); $signature = strtoupper(md5($signature.'&key='.$this->key)); $options['sign'] = $signature; $response = Http::request('POST', static::UNIFIEDORDER) ->withXmlBody($options) ->send(); if ('FAIL' === $response['return_code']) { throw new \Exception($response['return_msg']); } if ('FAIL' === $response['result_code']) { throw new \Exception($response['err_code_des']); } return $response; }
[ "public", "function", "getResponse", "(", ")", "{", "$", "options", "=", "$", "this", "->", "resolveOptions", "(", ")", ";", "// 按 ASCII 码排序", "ksort", "(", "$", "options", ")", ";", "$", "signature", "=", "urldecode", "(", "http_build_query", "(", "$", ...
获取响应结果.
[ "获取响应结果", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Payment/Unifiedorder.php#L67-L92
thenbsp/wechat
src/Payment/Unifiedorder.php
Unifiedorder.resolveOptions
public function resolveOptions() { $normalizer = function ($options, $value) { if (('JSAPI' === $value) && !isset($options['openid'])) { throw new \InvalidArgumentException(sprintf( '订单的 trade_type 为 “%s” 时,必需指定 “openid” 字段', $value)); } return $value; }; $defaults = [ 'trade_type' => current($this->tradeTypes), 'spbill_create_ip' => Util::getClientIp(), 'nonce_str' => Util::getRandomString(), ]; $resolver = new OptionsResolver(); $resolver ->setDefined($this->defined) ->setRequired($this->required) ->setAllowedValues('trade_type', $this->tradeTypes) ->setNormalizer('trade_type', $normalizer) ->setDefaults($defaults); return $resolver->resolve($this->toArray()); }
php
public function resolveOptions() { $normalizer = function ($options, $value) { if (('JSAPI' === $value) && !isset($options['openid'])) { throw new \InvalidArgumentException(sprintf( '订单的 trade_type 为 “%s” 时,必需指定 “openid” 字段', $value)); } return $value; }; $defaults = [ 'trade_type' => current($this->tradeTypes), 'spbill_create_ip' => Util::getClientIp(), 'nonce_str' => Util::getRandomString(), ]; $resolver = new OptionsResolver(); $resolver ->setDefined($this->defined) ->setRequired($this->required) ->setAllowedValues('trade_type', $this->tradeTypes) ->setNormalizer('trade_type', $normalizer) ->setDefaults($defaults); return $resolver->resolve($this->toArray()); }
[ "public", "function", "resolveOptions", "(", ")", "{", "$", "normalizer", "=", "function", "(", "$", "options", ",", "$", "value", ")", "{", "if", "(", "(", "'JSAPI'", "===", "$", "value", ")", "&&", "!", "isset", "(", "$", "options", "[", "'openid'"...
合并和校验参数.
[ "合并和校验参数", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Payment/Unifiedorder.php#L97-L123
thenbsp/wechat
src/Message/Entity/Article.php
Article.getBody
public function getBody() { $body = []; foreach ($this->items as $item) { $body['item'][] = $item->getBody(); } $count = isset($body['item']) ? count($body['item']) : 0; return ['Articles' => $body, 'ArticleCount' => $count]; }
php
public function getBody() { $body = []; foreach ($this->items as $item) { $body['item'][] = $item->getBody(); } $count = isset($body['item']) ? count($body['item']) : 0; return ['Articles' => $body, 'ArticleCount' => $count]; }
[ "public", "function", "getBody", "(", ")", "{", "$", "body", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "body", "[", "'item'", "]", "[", "]", "=", "$", "item", "->", "getBody", "(", ")", ...
消息内容.
[ "消息内容", "." ]
train
https://github.com/thenbsp/wechat/blob/1eef58ac53f50dc886914ef260f55d0df067af6f/src/Message/Entity/Article.php#L25-L38
GrafiteInc/CMS
src/Repositories/PageRepository.php
PageRepository.findPagesByURL
public function findPagesByURL($url) { $page = null; $page = $this->model->where('url', $url)->where('is_published', 1)->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'))->first(); if ($page && app()->getLocale() !== config('cms.default-language')) { $page = $this->translationRepo->findByEntityId($page->id, 'Grafite\Cms\Models\Page'); } if (!$page) { $page = $this->translationRepo->findByUrl($url, 'Grafite\Cms\Models\Page'); } if ($url === 'home' && app()->getLocale() !== config('cms.default-language')) { $page = $this->translationRepo->findByUrl($url, 'Grafite\Cms\Models\Page'); } return $page; }
php
public function findPagesByURL($url) { $page = null; $page = $this->model->where('url', $url)->where('is_published', 1)->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'))->first(); if ($page && app()->getLocale() !== config('cms.default-language')) { $page = $this->translationRepo->findByEntityId($page->id, 'Grafite\Cms\Models\Page'); } if (!$page) { $page = $this->translationRepo->findByUrl($url, 'Grafite\Cms\Models\Page'); } if ($url === 'home' && app()->getLocale() !== config('cms.default-language')) { $page = $this->translationRepo->findByUrl($url, 'Grafite\Cms\Models\Page'); } return $page; }
[ "public", "function", "findPagesByURL", "(", "$", "url", ")", "{", "$", "page", "=", "null", ";", "$", "page", "=", "$", "this", "->", "model", "->", "where", "(", "'url'", ",", "$", "url", ")", "->", "where", "(", "'is_published'", ",", "1", ")", ...
Find Pages by given URL. @param string $url @return \Illuminate\Support\Collection|null|static|Pages
[ "Find", "Pages", "by", "given", "URL", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/PageRepository.php#L59-L78
GrafiteInc/CMS
src/Controllers/GrafiteCmsFeatureController.php
GrafiteCmsFeatureController.revert
public function revert($id) { $archive = Archive::find($id); $model = app($archive->entity_type); $modelInstance = $model->find($archive->entity_id); $archiveData = (array) json_decode($archive->entity_data); $modelInstance->fill($archiveData); $modelInstance->save(); Cms::notification('Reversion was successful', 'success'); return redirect(URL::previous()); }
php
public function revert($id) { $archive = Archive::find($id); $model = app($archive->entity_type); $modelInstance = $model->find($archive->entity_id); $archiveData = (array) json_decode($archive->entity_data); $modelInstance->fill($archiveData); $modelInstance->save(); Cms::notification('Reversion was successful', 'success'); return redirect(URL::previous()); }
[ "public", "function", "revert", "(", "$", "id", ")", "{", "$", "archive", "=", "Archive", "::", "find", "(", "$", "id", ")", ";", "$", "model", "=", "app", "(", "$", "archive", "->", "entity_type", ")", ";", "$", "modelInstance", "=", "$", "model",...
Rollback to a previous version of an entity, a specific moment. @param int $id @return Redirect
[ "Rollback", "to", "a", "previous", "version", "of", "an", "entity", "a", "specific", "moment", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/GrafiteCmsFeatureController.php#L26-L41
GrafiteInc/CMS
src/Controllers/GrafiteCmsFeatureController.php
GrafiteCmsFeatureController.rollback
public function rollback($entity, $id) { $modelString = str_replace('_', '\\', $entity); if (!class_exists($modelString)) { Cms::notification('Could not rollback Model not found', 'warning'); return redirect(URL::previous()); } $model = app($modelString); $modelInstance = $model->find($id); $archive = Archive::where('entity_id', $id)->where('entity_type', $modelString)->limit(1)->offset(1)->orderBy('id', 'desc')->first(); if (!$archive) { Cms::notification('Could not rollback', 'warning'); return redirect(URL::previous()); } $archiveData = (array) json_decode($archive->entity_data); $modelInstance->fill($archiveData); $modelInstance->save(); Cms::notification('Rollback was successful', 'success'); return redirect(URL::previous()); }
php
public function rollback($entity, $id) { $modelString = str_replace('_', '\\', $entity); if (!class_exists($modelString)) { Cms::notification('Could not rollback Model not found', 'warning'); return redirect(URL::previous()); } $model = app($modelString); $modelInstance = $model->find($id); $archive = Archive::where('entity_id', $id)->where('entity_type', $modelString)->limit(1)->offset(1)->orderBy('id', 'desc')->first(); if (!$archive) { Cms::notification('Could not rollback', 'warning'); return redirect(URL::previous()); } $archiveData = (array) json_decode($archive->entity_data); $modelInstance->fill($archiveData); $modelInstance->save(); Cms::notification('Rollback was successful', 'success'); return redirect(URL::previous()); }
[ "public", "function", "rollback", "(", "$", "entity", ",", "$", "id", ")", "{", "$", "modelString", "=", "str_replace", "(", "'_'", ",", "'\\\\'", ",", "$", "entity", ")", ";", "if", "(", "!", "class_exists", "(", "$", "modelString", ")", ")", "{", ...
Rollback to a previous version of an entity. @param string $entity @param int $id @return Redirect
[ "Rollback", "to", "a", "previous", "version", "of", "an", "entity", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/GrafiteCmsFeatureController.php#L51-L80
GrafiteInc/CMS
src/Controllers/GrafiteCmsFeatureController.php
GrafiteCmsFeatureController.preview
public function preview($entity, $id) { $modelString = 'Grafite\Cms\Models\\'.ucfirst($entity); if (!class_exists($modelString)) { $modelString = 'Grafite\Cms\Models\\'.ucfirst($entity).'s'; } $model = new $modelString(); $modelInstance = $model->find($id); $data = [ $entity => $modelInstance, ]; if (config('app.locale') != config('cms.default-language', Cms::config('cms.default-language'))) { if ($modelInstance->translation(config('app.locale'))) { $data = [ $entity => $modelInstance->translation(config('app.locale'))->data, ]; } } $view = 'cms-frontend::'.$entity.'.show'; if (!View::exists($view)) { $view = 'cms-frontend::'.$entity.'s.show'; } if ($entity === 'page') { $view = 'cms-frontend::pages.'.$modelInstance->template; } if ($entity === 'blog') { $view = 'cms-frontend::blog.'.$modelInstance->template; } return view($view, $data); }
php
public function preview($entity, $id) { $modelString = 'Grafite\Cms\Models\\'.ucfirst($entity); if (!class_exists($modelString)) { $modelString = 'Grafite\Cms\Models\\'.ucfirst($entity).'s'; } $model = new $modelString(); $modelInstance = $model->find($id); $data = [ $entity => $modelInstance, ]; if (config('app.locale') != config('cms.default-language', Cms::config('cms.default-language'))) { if ($modelInstance->translation(config('app.locale'))) { $data = [ $entity => $modelInstance->translation(config('app.locale'))->data, ]; } } $view = 'cms-frontend::'.$entity.'.show'; if (!View::exists($view)) { $view = 'cms-frontend::'.$entity.'s.show'; } if ($entity === 'page') { $view = 'cms-frontend::pages.'.$modelInstance->template; } if ($entity === 'blog') { $view = 'cms-frontend::blog.'.$modelInstance->template; } return view($view, $data); }
[ "public", "function", "preview", "(", "$", "entity", ",", "$", "id", ")", "{", "$", "modelString", "=", "'Grafite\\Cms\\Models\\\\'", ".", "ucfirst", "(", "$", "entity", ")", ";", "if", "(", "!", "class_exists", "(", "$", "modelString", ")", ")", "{", ...
Preview content. @param string $entity @param int $id @return Response
[ "Preview", "content", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/GrafiteCmsFeatureController.php#L90-L128
GrafiteInc/CMS
src/Controllers/GrafiteCmsFeatureController.php
GrafiteCmsFeatureController.deleteHero
public function deleteHero($entity, $id) { $entity = app('Grafite\Cms\Models\\'.ucfirst($entity))->find($id); if (app(FileService::class)->delete($entity->hero_image)) { $entity->update([ 'hero_image' => null, ]); Cms::notification('Hero image deleted.', 'success'); return back(); } Cms::notification('Hero image could not be deleted', 'error'); return back(); }
php
public function deleteHero($entity, $id) { $entity = app('Grafite\Cms\Models\\'.ucfirst($entity))->find($id); if (app(FileService::class)->delete($entity->hero_image)) { $entity->update([ 'hero_image' => null, ]); Cms::notification('Hero image deleted.', 'success'); return back(); } Cms::notification('Hero image could not be deleted', 'error'); return back(); }
[ "public", "function", "deleteHero", "(", "$", "entity", ",", "$", "id", ")", "{", "$", "entity", "=", "app", "(", "'Grafite\\Cms\\Models\\\\'", ".", "ucfirst", "(", "$", "entity", ")", ")", "->", "find", "(", "$", "id", ")", ";", "if", "(", "app", ...
Delete the hero image @param string $entity @param int $id @return Response
[ "Delete", "the", "hero", "image" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/GrafiteCmsFeatureController.php#L149-L163
GrafiteInc/CMS
src/Services/CryptoService.php
CryptoService.encrypt
public function encrypt($value) { $iv = substr(md5(random_bytes(16)), 0, 16); $encrypted = openssl_encrypt($value, $this->encoding, $this->password, null, $iv); return $this->url_encode($iv.$encrypted); }
php
public function encrypt($value) { $iv = substr(md5(random_bytes(16)), 0, 16); $encrypted = openssl_encrypt($value, $this->encoding, $this->password, null, $iv); return $this->url_encode($iv.$encrypted); }
[ "public", "function", "encrypt", "(", "$", "value", ")", "{", "$", "iv", "=", "substr", "(", "md5", "(", "random_bytes", "(", "16", ")", ")", ",", "0", ",", "16", ")", ";", "$", "encrypted", "=", "openssl_encrypt", "(", "$", "value", ",", "$", "t...
Encrypt the string using your app and session keys, then return the new encrypted string. @param string $value String to encrypt @return string
[ "Encrypt", "the", "string", "using", "your", "app", "and", "session", "keys", "then", "return", "the", "new", "encrypted", "string", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CryptoService.php#L75-L81
GrafiteInc/CMS
src/Console/ModuleMake.php
ModuleMake.handle
public function handle() { $crudGenerator = new CrudGenerator(); $name = ucfirst(str_singular($this->argument('name'))); $moduleDirectory = base_path('cms/Modules/'.ucfirst(str_plural($name))); if (!is_dir(base_path('cms'))) { @mkdir(base_path('cms')); } if (!is_dir(base_path('cms/Modules'))) { @mkdir(base_path('cms/Modules')); } @mkdir($moduleDirectory); @mkdir($moduleDirectory.'/Assets'); @mkdir($moduleDirectory.'/Publishes'); @mkdir($moduleDirectory.'/Publishes/app/Http', 0777, true); @mkdir($moduleDirectory.'/Publishes/routes', 0777, true); @mkdir($moduleDirectory.'/Publishes/app/Http/Controllers/Cms', 0777, true); @mkdir($moduleDirectory.'/Publishes/resources/themes/default', 0777, true); @mkdir($moduleDirectory.'/Controllers'); @mkdir($moduleDirectory.'/Services'); @mkdir($moduleDirectory.'/Views'); @mkdir($moduleDirectory.'/Routes'); @mkdir($moduleDirectory.'/Tests'); file_put_contents($moduleDirectory.'/config.php', "<?php \n\n\nreturn [\n\t'asset_path' => __DIR__.'/Assets',\n\t'url' => '".strtolower(str_plural($name))."',\n\t'is_ignored_in_menu' => false\n];"); file_put_contents($moduleDirectory.'/Views/menu.blade.php', "<li class=\"nav-item @if (Request::is('cms/".strtolower(str_plural($name))."') || Request::is('cms/".strtolower(str_plural($name))."/*')) active @endif\"><a class=\"nav-link\" href=\"{{ url('cms/".strtolower(str_plural($name))."') }}\"><span class=\"fa fa-fw fa-file\"></span> ".ucfirst(str_plural($name)).'</a></li>'); $config = [ 'bootstrap' => false, 'semantic' => false, '_path_service_' => $moduleDirectory.'/Services', '_path_controller_' => $moduleDirectory.'/Controllers', '_path_views_' => $moduleDirectory.'/Views', '_path_tests_' => $moduleDirectory.'/Tests', '_path_routes_' => $moduleDirectory.'/Routes/web.php', 'routes_prefix' => "<?php \n\nRoute::group(['namespace' => 'Cms\Modules\\".ucfirst(str_plural($name))."\Controllers', 'prefix' => 'cms', 'middleware' => ['web', 'auth', 'cms']], function () { \n\n", 'routes_suffix' => "\n\n});", '_app_namespace_' => app()->getInstance()->getNamespace(), '_namespace_services_' => 'Cms\Modules\\'.ucfirst(str_plural($name)).'\Services', '_namespace_controller_' => 'Cms\Modules\\'.ucfirst(str_plural($name)).'\Controllers', '_name_name_' => strtolower($name), '_lower_case_' => strtolower($name), '_lower_casePlural_' => str_plural(strtolower($name)), '_camel_case_' => ucfirst(camel_case($name)), '_camel_casePlural_' => ucfirst(str_plural(camel_case($name))), '_ucCamel_casePlural_' => ucfirst(str_plural(camel_case($name))), 'template_source' => __DIR__.'/../Templates/Basic/', ]; $this->makeTheProvider($config, $moduleDirectory, $name); $appConfig = $config; $appConfig['template_source'] = __DIR__.'/../Templates/AppBasic/'; $appConfig['_path_controller_'] = $moduleDirectory.'/Publishes/app/Http/Controllers/Cms'; $appConfig['_path_views_'] = $moduleDirectory.'/Publishes/resources/themes/default'; $appConfig['_path_routes_'] = $moduleDirectory.'/Publishes/routes/'.$config['_lower_casePlural_'].'-web.php'; $appConfig['_namespace_controller_'] = $config['_app_namespace_'].'Http\Controllers\Cms'; $appConfig['routes_prefix'] = "<?php \n\nRoute::group(['namespace' => 'Cms', 'middleware' => ['web']], function () {\n\n"; $appConfig['routes_suffix'] = "\n\n});"; try { $this->info('Building the admin side...'); $this->line('Building controller...'); $crudGenerator->createController($config); $this->line('Building service...'); $crudGenerator->createService($config); $this->line('Building views...'); $crudGenerator->createViews($config); $this->line('Building routes...'); $crudGenerator->createRoutes($config); $this->info('Building the theme side...'); $this->line('Building controller...'); $crudGenerator->createController($appConfig); $this->line('Building views...'); $crudGenerator->createViews($appConfig); $this->line('Building routes...'); $crudGenerator->createRoutes($appConfig); $this->line('You will need to publish your module to make it available to your vistors:'); $this->comment('php artisan module:publish '.str_plural($name)); $this->line(''); $this->info('Add this to your `app/Providers/RouteServiceProver.php` in the `mapWebRoutes` method:'); $this->comment("\nrequire base_path('routes/".$config['_lower_casePlural_']."-web.php');\n"); } catch (Exception $e) { throw new Exception('Unable to generate your Module', 1); } $this->info('Module for '.$name.' is done.'); }
php
public function handle() { $crudGenerator = new CrudGenerator(); $name = ucfirst(str_singular($this->argument('name'))); $moduleDirectory = base_path('cms/Modules/'.ucfirst(str_plural($name))); if (!is_dir(base_path('cms'))) { @mkdir(base_path('cms')); } if (!is_dir(base_path('cms/Modules'))) { @mkdir(base_path('cms/Modules')); } @mkdir($moduleDirectory); @mkdir($moduleDirectory.'/Assets'); @mkdir($moduleDirectory.'/Publishes'); @mkdir($moduleDirectory.'/Publishes/app/Http', 0777, true); @mkdir($moduleDirectory.'/Publishes/routes', 0777, true); @mkdir($moduleDirectory.'/Publishes/app/Http/Controllers/Cms', 0777, true); @mkdir($moduleDirectory.'/Publishes/resources/themes/default', 0777, true); @mkdir($moduleDirectory.'/Controllers'); @mkdir($moduleDirectory.'/Services'); @mkdir($moduleDirectory.'/Views'); @mkdir($moduleDirectory.'/Routes'); @mkdir($moduleDirectory.'/Tests'); file_put_contents($moduleDirectory.'/config.php', "<?php \n\n\nreturn [\n\t'asset_path' => __DIR__.'/Assets',\n\t'url' => '".strtolower(str_plural($name))."',\n\t'is_ignored_in_menu' => false\n];"); file_put_contents($moduleDirectory.'/Views/menu.blade.php', "<li class=\"nav-item @if (Request::is('cms/".strtolower(str_plural($name))."') || Request::is('cms/".strtolower(str_plural($name))."/*')) active @endif\"><a class=\"nav-link\" href=\"{{ url('cms/".strtolower(str_plural($name))."') }}\"><span class=\"fa fa-fw fa-file\"></span> ".ucfirst(str_plural($name)).'</a></li>'); $config = [ 'bootstrap' => false, 'semantic' => false, '_path_service_' => $moduleDirectory.'/Services', '_path_controller_' => $moduleDirectory.'/Controllers', '_path_views_' => $moduleDirectory.'/Views', '_path_tests_' => $moduleDirectory.'/Tests', '_path_routes_' => $moduleDirectory.'/Routes/web.php', 'routes_prefix' => "<?php \n\nRoute::group(['namespace' => 'Cms\Modules\\".ucfirst(str_plural($name))."\Controllers', 'prefix' => 'cms', 'middleware' => ['web', 'auth', 'cms']], function () { \n\n", 'routes_suffix' => "\n\n});", '_app_namespace_' => app()->getInstance()->getNamespace(), '_namespace_services_' => 'Cms\Modules\\'.ucfirst(str_plural($name)).'\Services', '_namespace_controller_' => 'Cms\Modules\\'.ucfirst(str_plural($name)).'\Controllers', '_name_name_' => strtolower($name), '_lower_case_' => strtolower($name), '_lower_casePlural_' => str_plural(strtolower($name)), '_camel_case_' => ucfirst(camel_case($name)), '_camel_casePlural_' => ucfirst(str_plural(camel_case($name))), '_ucCamel_casePlural_' => ucfirst(str_plural(camel_case($name))), 'template_source' => __DIR__.'/../Templates/Basic/', ]; $this->makeTheProvider($config, $moduleDirectory, $name); $appConfig = $config; $appConfig['template_source'] = __DIR__.'/../Templates/AppBasic/'; $appConfig['_path_controller_'] = $moduleDirectory.'/Publishes/app/Http/Controllers/Cms'; $appConfig['_path_views_'] = $moduleDirectory.'/Publishes/resources/themes/default'; $appConfig['_path_routes_'] = $moduleDirectory.'/Publishes/routes/'.$config['_lower_casePlural_'].'-web.php'; $appConfig['_namespace_controller_'] = $config['_app_namespace_'].'Http\Controllers\Cms'; $appConfig['routes_prefix'] = "<?php \n\nRoute::group(['namespace' => 'Cms', 'middleware' => ['web']], function () {\n\n"; $appConfig['routes_suffix'] = "\n\n});"; try { $this->info('Building the admin side...'); $this->line('Building controller...'); $crudGenerator->createController($config); $this->line('Building service...'); $crudGenerator->createService($config); $this->line('Building views...'); $crudGenerator->createViews($config); $this->line('Building routes...'); $crudGenerator->createRoutes($config); $this->info('Building the theme side...'); $this->line('Building controller...'); $crudGenerator->createController($appConfig); $this->line('Building views...'); $crudGenerator->createViews($appConfig); $this->line('Building routes...'); $crudGenerator->createRoutes($appConfig); $this->line('You will need to publish your module to make it available to your vistors:'); $this->comment('php artisan module:publish '.str_plural($name)); $this->line(''); $this->info('Add this to your `app/Providers/RouteServiceProver.php` in the `mapWebRoutes` method:'); $this->comment("\nrequire base_path('routes/".$config['_lower_casePlural_']."-web.php');\n"); } catch (Exception $e) { throw new Exception('Unable to generate your Module', 1); } $this->info('Module for '.$name.' is done.'); }
[ "public", "function", "handle", "(", ")", "{", "$", "crudGenerator", "=", "new", "CrudGenerator", "(", ")", ";", "$", "name", "=", "ucfirst", "(", "str_singular", "(", "$", "this", "->", "argument", "(", "'name'", ")", ")", ")", ";", "$", "moduleDirect...
Generate a CRUD stack. @return mixed
[ "Generate", "a", "CRUD", "stack", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ModuleMake.php#L32-L133
GrafiteInc/CMS
src/Services/Traits/DefaultModuleServiceTrait.php
DefaultModuleServiceTrait.widget
public function widget($slug) { $widget = app(WidgetRepository::class)->getBySlug($slug); if ($widget) { if (Gate::allows('cms', Auth::user())) { $widget->content .= '<a href="'.url(config('cms.backend-route-prefix', 'cms').'/widgets/'.$widget->id.'/edit').'" class="btn btn-sm ml-2 btn-outline-secondary"><span class="fa fa-edit"></span> Edit</a>'; } if (config('app.locale') !== config('cms.default-language') && $widget->translation(config('app.locale'))) { return $widget->translationData(config('app.locale'))->content; } else { return $widget->content; } } return ''; }
php
public function widget($slug) { $widget = app(WidgetRepository::class)->getBySlug($slug); if ($widget) { if (Gate::allows('cms', Auth::user())) { $widget->content .= '<a href="'.url(config('cms.backend-route-prefix', 'cms').'/widgets/'.$widget->id.'/edit').'" class="btn btn-sm ml-2 btn-outline-secondary"><span class="fa fa-edit"></span> Edit</a>'; } if (config('app.locale') !== config('cms.default-language') && $widget->translation(config('app.locale'))) { return $widget->translationData(config('app.locale'))->content; } else { return $widget->content; } } return ''; }
[ "public", "function", "widget", "(", "$", "slug", ")", "{", "$", "widget", "=", "app", "(", "WidgetRepository", "::", "class", ")", "->", "getBySlug", "(", "$", "slug", ")", ";", "if", "(", "$", "widget", ")", "{", "if", "(", "Gate", "::", "allows"...
Get a widget. @param string $slug @return widget
[ "Get", "a", "widget", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/DefaultModuleServiceTrait.php#L37-L54
GrafiteInc/CMS
src/Services/Traits/DefaultModuleServiceTrait.php
DefaultModuleServiceTrait.promotion
public function promotion($slug) { $promotion = app(PromotionRepository::class)->getBySlug($slug); if ($promotion) { if (Gate::allows('cms', Auth::user())) { $promotion->details .= '<a href="'.url(config('cms.backend-route-prefix', 'cms').'/promotions/'.$promotion->id.'/edit').'" style="margin-left: 8px;" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span> Edit</a>'; } if ($promotion->is_published) { if (config('app.locale') !== config('cms.default-language') && $promotion->translation(config('app.locale'))) { return $promotion->translationData(config('app.locale'))->details; } else { return $promotion->details; } } } return ''; }
php
public function promotion($slug) { $promotion = app(PromotionRepository::class)->getBySlug($slug); if ($promotion) { if (Gate::allows('cms', Auth::user())) { $promotion->details .= '<a href="'.url(config('cms.backend-route-prefix', 'cms').'/promotions/'.$promotion->id.'/edit').'" style="margin-left: 8px;" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span> Edit</a>'; } if ($promotion->is_published) { if (config('app.locale') !== config('cms.default-language') && $promotion->translation(config('app.locale'))) { return $promotion->translationData(config('app.locale'))->details; } else { return $promotion->details; } } } return ''; }
[ "public", "function", "promotion", "(", "$", "slug", ")", "{", "$", "promotion", "=", "app", "(", "PromotionRepository", "::", "class", ")", "->", "getBySlug", "(", "$", "slug", ")", ";", "if", "(", "$", "promotion", ")", "{", "if", "(", "Gate", "::"...
Get an promotion. @param string $slug @return promotion
[ "Get", "an", "promotion", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/DefaultModuleServiceTrait.php#L63-L82
GrafiteInc/CMS
src/Services/Traits/DefaultModuleServiceTrait.php
DefaultModuleServiceTrait.image
public function image($id, $class = '') { $img = ''; if ($image = app('Grafite\Cms\Models\Image')->find($id)) { $img = $image->url; } return '<img class="'.$class.'" src="'.$img.'">'; }
php
public function image($id, $class = '') { $img = ''; if ($image = app('Grafite\Cms\Models\Image')->find($id)) { $img = $image->url; } return '<img class="'.$class.'" src="'.$img.'">'; }
[ "public", "function", "image", "(", "$", "id", ",", "$", "class", "=", "''", ")", "{", "$", "img", "=", "''", ";", "if", "(", "$", "image", "=", "app", "(", "'Grafite\\Cms\\Models\\Image'", ")", "->", "find", "(", "$", "id", ")", ")", "{", "$", ...
Get image. @param string $tag @return collection
[ "Get", "image", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/DefaultModuleServiceTrait.php#L91-L100
GrafiteInc/CMS
src/Services/Traits/DefaultModuleServiceTrait.php
DefaultModuleServiceTrait.images
public function images($tag = null) { $images = []; if (is_array($tag)) { foreach ($tag as $tagName) { $images = array_merge($images, $this->imageRepo->getImagesByTag($tag)->get()->toArray()); } } elseif (is_null($tag)) { $images = array_merge($images, $this->imageRepo->getImagesByTag()->get()->toArray()); } else { $images = array_merge($images, $this->imageRepo->getImagesByTag($tag)->get()->toArray()); } return $images; }
php
public function images($tag = null) { $images = []; if (is_array($tag)) { foreach ($tag as $tagName) { $images = array_merge($images, $this->imageRepo->getImagesByTag($tag)->get()->toArray()); } } elseif (is_null($tag)) { $images = array_merge($images, $this->imageRepo->getImagesByTag()->get()->toArray()); } else { $images = array_merge($images, $this->imageRepo->getImagesByTag($tag)->get()->toArray()); } return $images; }
[ "public", "function", "images", "(", "$", "tag", "=", "null", ")", "{", "$", "images", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "tag", ")", ")", "{", "foreach", "(", "$", "tag", "as", "$", "tagName", ")", "{", "$", "images", "=", ...
Get images. @param string $tag @return collection
[ "Get", "images", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/DefaultModuleServiceTrait.php#L127-L142
GrafiteInc/CMS
src/Repositories/FAQRepository.php
FAQRepository.store
public function store($payload) { $payload['question'] = htmlentities($payload['question']); $payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0; $payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'); return $this->model->create($payload); }
php
public function store($payload) { $payload['question'] = htmlentities($payload['question']); $payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0; $payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'); return $this->model->create($payload); }
[ "public", "function", "store", "(", "$", "payload", ")", "{", "$", "payload", "[", "'question'", "]", "=", "htmlentities", "(", "$", "payload", "[", "'question'", "]", ")", ";", "$", "payload", "[", "'is_published'", "]", "=", "(", "isset", "(", "$", ...
Stores FAQ into database. @param array $payload @return FAQ
[ "Stores", "FAQ", "into", "database", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/FAQRepository.php#L31-L38
GrafiteInc/CMS
src/Repositories/FAQRepository.php
FAQRepository.update
public function update($item, $payload) { $payload['question'] = htmlentities($payload['question']); if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) { return $this->translationRepo->createOrUpdate($item->id, 'Grafite\Cms\Models\FAQ', $payload['lang'], $payload); } else { $payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0; $payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'); unset($payload['lang']); return $item->update($payload); } }
php
public function update($item, $payload) { $payload['question'] = htmlentities($payload['question']); if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) { return $this->translationRepo->createOrUpdate($item->id, 'Grafite\Cms\Models\FAQ', $payload['lang'], $payload); } else { $payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0; $payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'); unset($payload['lang']); return $item->update($payload); } }
[ "public", "function", "update", "(", "$", "item", ",", "$", "payload", ")", "{", "$", "payload", "[", "'question'", "]", "=", "htmlentities", "(", "$", "payload", "[", "'question'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "payload", "[", ...
Updates FAQ into database. @param FAQ $FAQ @param array $input @return FAQ
[ "Updates", "FAQ", "into", "database", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/FAQRepository.php#L48-L62
GrafiteInc/CMS
src/Controllers/PromotionsController.php
PromotionsController.update
public function update($id, PromotionRequest $request) { $promotion = $this->repository->find($id); if (empty($promotion)) { Cms::notification('Promotions not found', 'warning'); return redirect(route($this->routeBase.'.promotions.index')); } $promotion = $this->repository->update($promotion, $request->all()); Cms::notification('Promotions updated successfully.', 'success'); return redirect(url()->previous()); }
php
public function update($id, PromotionRequest $request) { $promotion = $this->repository->find($id); if (empty($promotion)) { Cms::notification('Promotions not found', 'warning'); return redirect(route($this->routeBase.'.promotions.index')); } $promotion = $this->repository->update($promotion, $request->all()); Cms::notification('Promotions updated successfully.', 'success'); return redirect(url()->previous()); }
[ "public", "function", "update", "(", "$", "id", ",", "PromotionRequest", "$", "request", ")", "{", "$", "promotion", "=", "$", "this", "->", "repository", "->", "find", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "promotion", ")", ")", ...
Update the specified Promotions in storage. @param int $id @param PromotionRequest $request @return Response
[ "Update", "the", "specified", "Promotions", "in", "storage", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/PromotionsController.php#L114-L129
GrafiteInc/CMS
src/PublishedAssets/Middleware/GrafiteCmsLanguage.php
GrafiteCmsLanguage.handle
public function handle($request, Closure $next) { if (Cookie::has('language')) { Config::set('app.locale', Cookie::get('language')); } return $next($request); }
php
public function handle($request, Closure $next) { if (Cookie::has('language')) { Config::set('app.locale', Cookie::get('language')); } return $next($request); }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ")", "{", "if", "(", "Cookie", "::", "has", "(", "'language'", ")", ")", "{", "Config", "::", "set", "(", "'app.locale'", ",", "Cookie", "::", "get", "(", "'language'", ...
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Middleware/GrafiteCmsLanguage.php#L19-L26
GrafiteInc/CMS
src/Migrations/2016_06_01_002825_convert_to_published_at.php
ConvertToPublishedAt.up
public function up() { Schema::table(config('cms.db-prefix', '').'pages', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); Schema::table(config('cms.db-prefix', '').'blogs', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); Schema::table(config('cms.db-prefix', '').'events', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); Schema::table(config('cms.db-prefix', '').'faqs', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); }
php
public function up() { Schema::table(config('cms.db-prefix', '').'pages', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); Schema::table(config('cms.db-prefix', '').'blogs', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); Schema::table(config('cms.db-prefix', '').'events', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); Schema::table(config('cms.db-prefix', '').'faqs', function (Blueprint $table) { $table->dateTime('published_at')->nullable(); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "table", "(", "config", "(", "'cms.db-prefix'", ",", "''", ")", ".", "'pages'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "dateTime", "(", "'published_at'", ...
Run the migrations.
[ "Run", "the", "migrations", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Migrations/2016_06_01_002825_convert_to_published_at.php#L11-L28
GrafiteInc/CMS
src/GrafiteCmsProvider.php
GrafiteCmsProvider.boot
public function boot() { $this->publishes([ __DIR__.'/PublishedAssets/Views/themes' => base_path('resources/themes'), __DIR__.'/PublishedAssets/Controllers' => app_path('Http/Controllers/Cms'), __DIR__.'/PublishedAssets/Middleware' => app_path('Http/Middleware'), __DIR__.'/PublishedAssets/Routes' => base_path('routes'), __DIR__.'/PublishedAssets/Config' => base_path('config'), ]); $this->publishes([ __DIR__.'/Views' => base_path('resources/views/vendor/cms'), ], 'backend'); $this->loadMigrationsFrom(__DIR__.'/Migrations'); $theme = config('cms.frontend-theme', 'default'); $this->loadViewsFrom(__DIR__.'/Views', 'cms'); View::addLocation(base_path('resources/themes/'.$theme)); View::addNamespace('cms-frontend', base_path('resources/themes/'.$theme)); /* |-------------------------------------------------------------------------- | Blade Directives |-------------------------------------------------------------------------- */ Blade::directive('theme', function ($expression) { if (Str::startsWith($expression, '(')) { $expression = substr($expression, 1, -1); } $theme = config('cms.frontend-theme'); $view = '"cms-frontend::'.str_replace('"', '', str_replace("'", '', $expression)).'"'; return "<?php echo \$__env->make($view, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; }); Blade::directive('menu', function ($expression) { return "<?php echo Cms::menu($expression); ?>"; }); Blade::directive('block', function ($expression) { $module = Cms::getModule(); return "<?php echo optional(\$".$module.")->block($expression); ?>"; }); Blade::directive('languages', function ($expression) { return "<?php echo Cms::languageLinks($expression); ?>"; }); Blade::directive('modules', function ($expression) { return "<?php echo Cms::moduleLinks($expression); ?>"; }); Blade::directive('widget', function ($expression) { return "<?php echo Cms::widget($expression); ?>"; }); Blade::directive('promotion', function ($expression) { return "<?php echo Cms::promotion($expression); ?>"; }); Blade::directive('image', function ($expression) { return "<?php echo Cms::image($expression); ?>"; }); Blade::directive('image_link', function ($expression) { return "<?php echo Cms::imageLink($expression); ?>"; }); Blade::directive('images', function ($expression) { return "<?php echo Cms::images($expression); ?>"; }); Blade::directive('edit', function ($expression) { return "<?php echo Cms::editBtn($expression); ?>"; }); Blade::directive('editBtn', function ($expression) { return "<?php echo Cms::editBtnSecondary($expression); ?>"; }); Blade::directive('markdown', function ($expression) { return "<?php echo Markdown::convertToHtml($expression); ?>"; }); }
php
public function boot() { $this->publishes([ __DIR__.'/PublishedAssets/Views/themes' => base_path('resources/themes'), __DIR__.'/PublishedAssets/Controllers' => app_path('Http/Controllers/Cms'), __DIR__.'/PublishedAssets/Middleware' => app_path('Http/Middleware'), __DIR__.'/PublishedAssets/Routes' => base_path('routes'), __DIR__.'/PublishedAssets/Config' => base_path('config'), ]); $this->publishes([ __DIR__.'/Views' => base_path('resources/views/vendor/cms'), ], 'backend'); $this->loadMigrationsFrom(__DIR__.'/Migrations'); $theme = config('cms.frontend-theme', 'default'); $this->loadViewsFrom(__DIR__.'/Views', 'cms'); View::addLocation(base_path('resources/themes/'.$theme)); View::addNamespace('cms-frontend', base_path('resources/themes/'.$theme)); /* |-------------------------------------------------------------------------- | Blade Directives |-------------------------------------------------------------------------- */ Blade::directive('theme', function ($expression) { if (Str::startsWith($expression, '(')) { $expression = substr($expression, 1, -1); } $theme = config('cms.frontend-theme'); $view = '"cms-frontend::'.str_replace('"', '', str_replace("'", '', $expression)).'"'; return "<?php echo \$__env->make($view, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; }); Blade::directive('menu', function ($expression) { return "<?php echo Cms::menu($expression); ?>"; }); Blade::directive('block', function ($expression) { $module = Cms::getModule(); return "<?php echo optional(\$".$module.")->block($expression); ?>"; }); Blade::directive('languages', function ($expression) { return "<?php echo Cms::languageLinks($expression); ?>"; }); Blade::directive('modules', function ($expression) { return "<?php echo Cms::moduleLinks($expression); ?>"; }); Blade::directive('widget', function ($expression) { return "<?php echo Cms::widget($expression); ?>"; }); Blade::directive('promotion', function ($expression) { return "<?php echo Cms::promotion($expression); ?>"; }); Blade::directive('image', function ($expression) { return "<?php echo Cms::image($expression); ?>"; }); Blade::directive('image_link', function ($expression) { return "<?php echo Cms::imageLink($expression); ?>"; }); Blade::directive('images', function ($expression) { return "<?php echo Cms::images($expression); ?>"; }); Blade::directive('edit', function ($expression) { return "<?php echo Cms::editBtn($expression); ?>"; }); Blade::directive('editBtn', function ($expression) { return "<?php echo Cms::editBtnSecondary($expression); ?>"; }); Blade::directive('markdown', function ($expression) { return "<?php echo Markdown::convertToHtml($expression); ?>"; }); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/PublishedAssets/Views/themes'", "=>", "base_path", "(", "'resources/themes'", ")", ",", "__DIR__", ".", "'/PublishedAssets/Controllers'", "=>", "app_path", "(...
Alias the services in the boot.
[ "Alias", "the", "services", "in", "the", "boot", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/GrafiteCmsProvider.php#L38-L126
GrafiteInc/CMS
src/GrafiteCmsProvider.php
GrafiteCmsProvider.register
public function register() { $this->app->register(CmsServiceProvider::class); $this->app->register(CmsEventServiceProvider::class); $this->app->register(CmsRouteProvider::class); $this->app->register(CmsModuleProvider::class); $this->app->register(GrafiteBuilderProvider::class); $this->app->register(MinifyServiceProvider::class); $this->app->register(MarkdownServiceProvider::class); $this->app->register(ImageServiceProvider::class); $loader = AliasLoader::getInstance(); $loader->alias('Minify', MinifyFacade::class); $loader->alias('Markdown', Markdown::class); $loader->alias('Image', Image::class); /* |-------------------------------------------------------------------------- | Register the Commands |-------------------------------------------------------------------------- */ $this->commands([ ThemeGenerate::class, ThemePublish::class, ThemeLink::class, ModulePublish::class, ModuleMake::class, ModuleComposer::class, ModuleCrud::class, Setup::class, Keys::class, ]); }
php
public function register() { $this->app->register(CmsServiceProvider::class); $this->app->register(CmsEventServiceProvider::class); $this->app->register(CmsRouteProvider::class); $this->app->register(CmsModuleProvider::class); $this->app->register(GrafiteBuilderProvider::class); $this->app->register(MinifyServiceProvider::class); $this->app->register(MarkdownServiceProvider::class); $this->app->register(ImageServiceProvider::class); $loader = AliasLoader::getInstance(); $loader->alias('Minify', MinifyFacade::class); $loader->alias('Markdown', Markdown::class); $loader->alias('Image', Image::class); /* |-------------------------------------------------------------------------- | Register the Commands |-------------------------------------------------------------------------- */ $this->commands([ ThemeGenerate::class, ThemePublish::class, ThemeLink::class, ModulePublish::class, ModuleMake::class, ModuleComposer::class, ModuleCrud::class, Setup::class, Keys::class, ]); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "app", "->", "register", "(", "CmsServiceProvider", "::", "class", ")", ";", "$", "this", "->", "app", "->", "register", "(", "CmsEventServiceProvider", "::", "class", ")", ";", "$", "th...
Register the services.
[ "Register", "the", "services", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/GrafiteCmsProvider.php#L131-L166
GrafiteInc/CMS
src/Controllers/ApiController.php
ApiController.all
public function all() { $query = $this->model; if (Schema::hasColumn(str_plural($this->modelName), 'is_published')) { $query = $query->where('is_published', true); } if (Schema::hasColumn(str_plural($this->modelName), 'published_at')) { $query = $query->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')); } if (Schema::hasColumn(str_plural($this->modelName), 'finished_at')) { $query = $query->where('finished_at', '>=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')); } return $query ->orderBy('created_at', 'desc') ->paginate(Config::get('cms.pagination', 24)); }
php
public function all() { $query = $this->model; if (Schema::hasColumn(str_plural($this->modelName), 'is_published')) { $query = $query->where('is_published', true); } if (Schema::hasColumn(str_plural($this->modelName), 'published_at')) { $query = $query->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')); } if (Schema::hasColumn(str_plural($this->modelName), 'finished_at')) { $query = $query->where('finished_at', '>=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')); } return $query ->orderBy('created_at', 'desc') ->paginate(Config::get('cms.pagination', 24)); }
[ "public", "function", "all", "(", ")", "{", "$", "query", "=", "$", "this", "->", "model", ";", "if", "(", "Schema", "::", "hasColumn", "(", "str_plural", "(", "$", "this", "->", "modelName", ")", ",", "'is_published'", ")", ")", "{", "$", "query", ...
Collect all items of a resource @return Collection
[ "Collect", "all", "items", "of", "a", "resource" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ApiController.php#L44-L63
GrafiteInc/CMS
src/Controllers/ApiController.php
ApiController.search
public function search($term) { $query = $this->model->orderBy('created_at', 'desc'); $query->where('id', 'LIKE', '%'.$input['term'].'%'); $columns = Schema::getColumnListing(str_plural($this->modelName)); foreach ($columns as $attribute) { $query->orWhere($attribute, 'LIKE', '%'.$input['term'].'%'); } return [ 'term' => $input['term'], 'result' => $query->paginate(Config::get('cms.pagination', 24)), ]; }
php
public function search($term) { $query = $this->model->orderBy('created_at', 'desc'); $query->where('id', 'LIKE', '%'.$input['term'].'%'); $columns = Schema::getColumnListing(str_plural($this->modelName)); foreach ($columns as $attribute) { $query->orWhere($attribute, 'LIKE', '%'.$input['term'].'%'); } return [ 'term' => $input['term'], 'result' => $query->paginate(Config::get('cms.pagination', 24)), ]; }
[ "public", "function", "search", "(", "$", "term", ")", "{", "$", "query", "=", "$", "this", "->", "model", "->", "orderBy", "(", "'created_at'", ",", "'desc'", ")", ";", "$", "query", "->", "where", "(", "'id'", ",", "'LIKE'", ",", "'%'", ".", "$",...
Search for the API Item @param string $term @return array
[ "Search", "for", "the", "API", "Item" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ApiController.php#L72-L87
GrafiteInc/CMS
src/Repositories/LinkRepository.php
LinkRepository.store
public function store($payload) { $payload['external'] = isset($payload['external']) ? $payload['external'] : 0; if ($payload['external'] != 0 && empty($payload['external_url'])) { throw new Exception("Your link was missing a URL", 1); } if (!isset($payload['page_id'])) { $payload['page_id'] = 0; } if ($payload['page_id'] == 0 && $payload['external'] == 0) { throw new Exception("Your link was not connected to anything, and could not be made", 1); } $link = $this->model->create($payload); $order = json_decode($link->menu->order); array_push($order, $link->id); $link->menu->update([ 'order' => json_encode($order), ]); return $link; }
php
public function store($payload) { $payload['external'] = isset($payload['external']) ? $payload['external'] : 0; if ($payload['external'] != 0 && empty($payload['external_url'])) { throw new Exception("Your link was missing a URL", 1); } if (!isset($payload['page_id'])) { $payload['page_id'] = 0; } if ($payload['page_id'] == 0 && $payload['external'] == 0) { throw new Exception("Your link was not connected to anything, and could not be made", 1); } $link = $this->model->create($payload); $order = json_decode($link->menu->order); array_push($order, $link->id); $link->menu->update([ 'order' => json_encode($order), ]); return $link; }
[ "public", "function", "store", "(", "$", "payload", ")", "{", "$", "payload", "[", "'external'", "]", "=", "isset", "(", "$", "payload", "[", "'external'", "]", ")", "?", "$", "payload", "[", "'external'", "]", ":", "0", ";", "if", "(", "$", "paylo...
Stores Links into database. @param array $payload @return Links
[ "Stores", "Links", "into", "database", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/LinkRepository.php#L32-L57
GrafiteInc/CMS
src/Repositories/LinkRepository.php
LinkRepository.update
public function update($link, $payload) { $payload['external'] = isset($payload['external']) ? $payload['external'] : 0; if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) { return $this->translationRepo->createOrUpdate($link->id, 'Grafite\Cms\Models\Link', $payload['lang'], $payload); } unset($payload['lang']); return $link->update($payload); }
php
public function update($link, $payload) { $payload['external'] = isset($payload['external']) ? $payload['external'] : 0; if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) { return $this->translationRepo->createOrUpdate($link->id, 'Grafite\Cms\Models\Link', $payload['lang'], $payload); } unset($payload['lang']); return $link->update($payload); }
[ "public", "function", "update", "(", "$", "link", ",", "$", "payload", ")", "{", "$", "payload", "[", "'external'", "]", "=", "isset", "(", "$", "payload", "[", "'external'", "]", ")", "?", "$", "payload", "[", "'external'", "]", ":", "0", ";", "if...
Updates Links into database. @param Link $link @param array $input @return Link
[ "Updates", "Links", "into", "database", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/LinkRepository.php#L79-L90
GrafiteInc/CMS
src/Providers/CmsModuleProvider.php
CmsModuleProvider.register
public function register() { if (Config::get('cms.load-modules', false)) { $modulePath = base_path(Config::get('cms.module-directory').'/'); $modules = glob($modulePath.'*'); foreach ($modules as $module) { if (is_dir($module)) { $module = lcfirst(str_replace($modulePath, '', $module)); $moduleProvider = '\Cms\Modules\_module_\_module_ModuleProvider'; $moduleProvider = str_replace('_module_', ucfirst($module), $moduleProvider); $this->app->register($moduleProvider); } } } }
php
public function register() { if (Config::get('cms.load-modules', false)) { $modulePath = base_path(Config::get('cms.module-directory').'/'); $modules = glob($modulePath.'*'); foreach ($modules as $module) { if (is_dir($module)) { $module = lcfirst(str_replace($modulePath, '', $module)); $moduleProvider = '\Cms\Modules\_module_\_module_ModuleProvider'; $moduleProvider = str_replace('_module_', ucfirst($module), $moduleProvider); $this->app->register($moduleProvider); } } } }
[ "public", "function", "register", "(", ")", "{", "if", "(", "Config", "::", "get", "(", "'cms.load-modules'", ",", "false", ")", ")", "{", "$", "modulePath", "=", "base_path", "(", "Config", "::", "get", "(", "'cms.module-directory'", ")", ".", "'/'", ")...
Register the services.
[ "Register", "the", "services", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Providers/CmsModuleProvider.php#L13-L28
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.asset
public function asset($path, $contentType = 'null', $fullURL = true) { if (!$fullURL) { return base_path(__DIR__.'/../Assets/'.$path); } return url($this->backendRoute.'/asset/'.CryptoServiceFacade::url_encode($path).'/'.CryptoServiceFacade::url_encode($contentType)); }
php
public function asset($path, $contentType = 'null', $fullURL = true) { if (!$fullURL) { return base_path(__DIR__.'/../Assets/'.$path); } return url($this->backendRoute.'/asset/'.CryptoServiceFacade::url_encode($path).'/'.CryptoServiceFacade::url_encode($contentType)); }
[ "public", "function", "asset", "(", "$", "path", ",", "$", "contentType", "=", "'null'", ",", "$", "fullURL", "=", "true", ")", "{", "if", "(", "!", "$", "fullURL", ")", "{", "return", "base_path", "(", "__DIR__", ".", "'/../Assets/'", ".", "$", "pat...
Get a module's asset. @param string $module Module name @param string $path Path to module asset @param string $contentType Asset type @return string
[ "Get", "a", "module", "s", "asset", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L40-L47
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.languageLinks
public function languageLinks($linkClass = 'nav-link', $itemClass = 'nav-item') { if (count(config('cms.languages')) > 1) { $languageLinks = []; foreach (config('cms.languages') as $key => $value) { $url = url(config('cms.backend-route-prefix', 'cms').'/language/set/'.$key); $languageLinks[] = '<li class="'.$itemClass.'"><a class="language-link '.$linkClass.'" href="'.$url.'">'.ucfirst($value).'</a></li>'; } $languageLinkString = implode($languageLinks); return $languageLinkString; } return ''; }
php
public function languageLinks($linkClass = 'nav-link', $itemClass = 'nav-item') { if (count(config('cms.languages')) > 1) { $languageLinks = []; foreach (config('cms.languages') as $key => $value) { $url = url(config('cms.backend-route-prefix', 'cms').'/language/set/'.$key); $languageLinks[] = '<li class="'.$itemClass.'"><a class="language-link '.$linkClass.'" href="'.$url.'">'.ucfirst($value).'</a></li>'; } $languageLinkString = implode($languageLinks); return $languageLinkString; } return ''; }
[ "public", "function", "languageLinks", "(", "$", "linkClass", "=", "'nav-link'", ",", "$", "itemClass", "=", "'nav-item'", ")", "{", "if", "(", "count", "(", "config", "(", "'cms.languages'", ")", ")", ">", "1", ")", "{", "$", "languageLinks", "=", "[", ...
Links for each supported language @param string $linkClass @param string $itemClass @return string
[ "Links", "for", "each", "supported", "language" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L84-L99
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.notification
public function notification($string, $type = null) { if (is_null($type)) { $type = 'info'; } Session::flash('notification', $string); Session::flash('notificationType', 'alert-'.$type); }
php
public function notification($string, $type = null) { if (is_null($type)) { $type = 'info'; } Session::flash('notification', $string); Session::flash('notificationType', 'alert-'.$type); }
[ "public", "function", "notification", "(", "$", "string", ",", "$", "type", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "type", ")", ")", "{", "$", "type", "=", "'info'", ";", "}", "Session", "::", "flash", "(", "'notification'", ",", "$...
Generates a notification for the app. @param string $string Notification string @param string $type Notification type
[ "Generates", "a", "notification", "for", "the", "app", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L107-L115
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.breadcrumbs
public function breadcrumbs($locations) { $trail = ''; foreach ($locations as $location) { if (is_array($location)) { foreach ($location as $key => $value) { $trail .= '<li class="breadcrumb-item"><a href="'.$value.'">'.ucfirst($key).'</a></li>'; } } else { $trail .= '<li class="breadcrumb-item">'.ucfirst($location).'</li>'; } } return $trail; }
php
public function breadcrumbs($locations) { $trail = ''; foreach ($locations as $location) { if (is_array($location)) { foreach ($location as $key => $value) { $trail .= '<li class="breadcrumb-item"><a href="'.$value.'">'.ucfirst($key).'</a></li>'; } } else { $trail .= '<li class="breadcrumb-item">'.ucfirst($location).'</li>'; } } return $trail; }
[ "public", "function", "breadcrumbs", "(", "$", "locations", ")", "{", "$", "trail", "=", "''", ";", "foreach", "(", "$", "locations", "as", "$", "location", ")", "{", "if", "(", "is_array", "(", "$", "location", ")", ")", "{", "foreach", "(", "$", ...
Creates a breadcrumb trail. @param array $locations Locations array @return string
[ "Creates", "a", "breadcrumb", "trail", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L124-L139
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.config
public function config($key) { $splitKey = explode('.', $key); $moduleConfig = include __DIR__.'/../PublishedAssets/Config/'.$splitKey[0].'.php'; $strippedKey = preg_replace('/'.$splitKey[1].'./', '', preg_replace('/'.$splitKey[0].'./', '', $key, 1), 1); return $moduleConfig[$strippedKey]; }
php
public function config($key) { $splitKey = explode('.', $key); $moduleConfig = include __DIR__.'/../PublishedAssets/Config/'.$splitKey[0].'.php'; $strippedKey = preg_replace('/'.$splitKey[1].'./', '', preg_replace('/'.$splitKey[0].'./', '', $key, 1), 1); return $moduleConfig[$strippedKey]; }
[ "public", "function", "config", "(", "$", "key", ")", "{", "$", "splitKey", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "moduleConfig", "=", "include", "__DIR__", ".", "'/../PublishedAssets/Config/'", ".", "$", "splitKey", "[", "0", "]", ...
Get Module Config. @param string $key Config key @return mixed
[ "Get", "Module", "Config", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L148-L157
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.assignArrayByPath
public function assignArrayByPath(&$arr, $path) { $keys = explode('.', $path); while ($key = array_shift($keys)) { $arr = &$arr[$key]; } return $arr; }
php
public function assignArrayByPath(&$arr, $path) { $keys = explode('.', $path); while ($key = array_shift($keys)) { $arr = &$arr[$key]; } return $arr; }
[ "public", "function", "assignArrayByPath", "(", "&", "$", "arr", ",", "$", "path", ")", "{", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "path", ")", ";", "while", "(", "$", "key", "=", "array_shift", "(", "$", "keys", ")", ")", "{", "$", ...
Assign a value to the path. @param array &$arr Original Array of values @param string $path Array as path string @return mixed
[ "Assign", "a", "value", "to", "the", "path", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L167-L176
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.addToPackages
public function addToPackages($dir) { $files = glob($dir.'/*'); $packageViews = Config::get('cms.package-menus'); if (is_null($packageViews)) { $packageViews = []; } foreach ($files as $view) { array_push($packageViews, $view); } return Config::set('cms.package-menus', $packageViews); }
php
public function addToPackages($dir) { $files = glob($dir.'/*'); $packageViews = Config::get('cms.package-menus'); if (is_null($packageViews)) { $packageViews = []; } foreach ($files as $view) { array_push($packageViews, $view); } return Config::set('cms.package-menus', $packageViews); }
[ "public", "function", "addToPackages", "(", "$", "dir", ")", "{", "$", "files", "=", "glob", "(", "$", "dir", ".", "'/*'", ")", ";", "$", "packageViews", "=", "Config", "::", "get", "(", "'cms.package-menus'", ")", ";", "if", "(", "is_null", "(", "$"...
Add these views to the packages. @param string $dir
[ "Add", "these", "views", "to", "the", "packages", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L195-L210
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.editBtn
public function editBtn($type = null, $id = null, $class="btn-outline-secondary") { if (Gate::allows('cms', Auth::user())) { if (!is_null($id)) { return '<a href="'.url($this->backendRoute.'/'.$type.'/'.$id.'/edit').'" class="btn btn-sm '.$class.'"><span class="fa fa-edit"></span> Edit</a>'; } else { return '<a href="'.url($this->backendRoute.'/'.$type).'" class="btn btn-sm '.$class.'"><span class="fa fa-edit"></span> Edit</a>'; } } return ''; }
php
public function editBtn($type = null, $id = null, $class="btn-outline-secondary") { if (Gate::allows('cms', Auth::user())) { if (!is_null($id)) { return '<a href="'.url($this->backendRoute.'/'.$type.'/'.$id.'/edit').'" class="btn btn-sm '.$class.'"><span class="fa fa-edit"></span> Edit</a>'; } else { return '<a href="'.url($this->backendRoute.'/'.$type).'" class="btn btn-sm '.$class.'"><span class="fa fa-edit"></span> Edit</a>'; } } return ''; }
[ "public", "function", "editBtn", "(", "$", "type", "=", "null", ",", "$", "id", "=", "null", ",", "$", "class", "=", "\"btn-outline-secondary\"", ")", "{", "if", "(", "Gate", "::", "allows", "(", "'cms'", ",", "Auth", "::", "user", "(", ")", ")", "...
Edit button. @param string $type @param int $id @param string $class @return string
[ "Edit", "button", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L221-L232
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.rollbackUrl
public function rollbackUrl($object) { $class = str_replace('\\', '_', get_class($object)); return url($this->backendRoute.'/rollback/'.$class.'/'.$object->id); }
php
public function rollbackUrl($object) { $class = str_replace('\\', '_', get_class($object)); return url($this->backendRoute.'/rollback/'.$class.'/'.$object->id); }
[ "public", "function", "rollbackUrl", "(", "$", "object", ")", "{", "$", "class", "=", "str_replace", "(", "'\\\\'", ",", "'_'", ",", "get_class", "(", "$", "object", ")", ")", ";", "return", "url", "(", "$", "this", "->", "backendRoute", ".", "'/rollba...
Rollback URL. @param obj $object @return string
[ "Rollback", "URL", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L281-L286
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.version
public function version() { $changelog = @file_get_contents(__DIR__.'/../../changelog.md'); if (!$changelog) { return 'unknown version'; } $matches = strstr($changelog, '## ['); $until = strpos($matches, '-'); return str_replace(']', '', substr($matches, 5, $until - 5)); }
php
public function version() { $changelog = @file_get_contents(__DIR__.'/../../changelog.md'); if (!$changelog) { return 'unknown version'; } $matches = strstr($changelog, '## ['); $until = strpos($matches, '-'); return str_replace(']', '', substr($matches, 5, $until - 5)); }
[ "public", "function", "version", "(", ")", "{", "$", "changelog", "=", "@", "file_get_contents", "(", "__DIR__", ".", "'/../../changelog.md'", ")", ";", "if", "(", "!", "$", "changelog", ")", "{", "return", "'unknown version'", ";", "}", "$", "matches", "=...
Get version from the changelog. @return string
[ "Get", "version", "from", "the", "changelog", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L293-L305
GrafiteInc/CMS
src/Services/CmsService.php
CmsService.collectSiteMapItems
public function collectSiteMapItems() { $itemCollection = []; $modules = config('site-mapped-modules', [ 'blog' => 'Grafite\Cms\Repositories\BlogRepository', 'page' => 'Grafite\Cms\Repositories\PageRepository', 'events' => 'Grafite\Cms\Repositories\EventRepository', ]); foreach ($modules as $module => $repository) { try { $items = collect([]); if (method_exists($repository, 'arePublic')) { $items = app($repository)->arePublic(); } foreach ($items as $item) { $itemCollection[] = [ 'url' => url($module.'/'.$item->url), 'updated_at' => $item->updated_at->format('Y-m-d'), ]; } } catch (ReflectionException $e) { // It just means we couldn't find // the Repository class } } return collect($itemCollection); }
php
public function collectSiteMapItems() { $itemCollection = []; $modules = config('site-mapped-modules', [ 'blog' => 'Grafite\Cms\Repositories\BlogRepository', 'page' => 'Grafite\Cms\Repositories\PageRepository', 'events' => 'Grafite\Cms\Repositories\EventRepository', ]); foreach ($modules as $module => $repository) { try { $items = collect([]); if (method_exists($repository, 'arePublic')) { $items = app($repository)->arePublic(); } foreach ($items as $item) { $itemCollection[] = [ 'url' => url($module.'/'.$item->url), 'updated_at' => $item->updated_at->format('Y-m-d'), ]; } } catch (ReflectionException $e) { // It just means we couldn't find // the Repository class } } return collect($itemCollection); }
[ "public", "function", "collectSiteMapItems", "(", ")", "{", "$", "itemCollection", "=", "[", "]", ";", "$", "modules", "=", "config", "(", "'site-mapped-modules'", ",", "[", "'blog'", "=>", "'Grafite\\Cms\\Repositories\\BlogRepository'", ",", "'page'", "=>", "'Gra...
Collect items for a site map @return array
[ "Collect", "items", "for", "a", "site", "map" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsService.php#L312-L342
GrafiteInc/CMS
src/Services/BaseService.php
BaseService.getTemplatesAsOptionsArray
public function getTemplatesAsOptionsArray($module) { $availableTemplates = ['show']; $templates = glob(base_path('resources/themes/'.config('cms.frontend-theme').'/'.$module.'/*')); foreach ($templates as $template) { $template = str_replace(base_path('resources/themes/'.config('cms.frontend-theme').'/'.$module.'/'), '', $template); if (stristr($template, 'template')) { $template = str_replace('-template.blade.php', '', $template); if (!stristr($template, '.php')) { $availableTemplates[] = $template.'-template'; } } } return $availableTemplates; }
php
public function getTemplatesAsOptionsArray($module) { $availableTemplates = ['show']; $templates = glob(base_path('resources/themes/'.config('cms.frontend-theme').'/'.$module.'/*')); foreach ($templates as $template) { $template = str_replace(base_path('resources/themes/'.config('cms.frontend-theme').'/'.$module.'/'), '', $template); if (stristr($template, 'template')) { $template = str_replace('-template.blade.php', '', $template); if (!stristr($template, '.php')) { $availableTemplates[] = $template.'-template'; } } } return $availableTemplates; }
[ "public", "function", "getTemplatesAsOptionsArray", "(", "$", "module", ")", "{", "$", "availableTemplates", "=", "[", "'show'", "]", ";", "$", "templates", "=", "glob", "(", "base_path", "(", "'resources/themes/'", ".", "config", "(", "'cms.frontend-theme'", ")...
Get templates as options @param string $module @return array
[ "Get", "templates", "as", "options" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/BaseService.php#L14-L30
GrafiteInc/CMS
src/Console/ThemeLink.php
ThemeLink.handle
public function handle() { $name = config('cms.frontend-theme'); $result = 'Symlink failed to generate'; if (symlink(base_path('resources/themes/'.strtolower($name).'/public'), base_path('public/theme'))) { $result = 'Symlink generated'; } $this->info($result); }
php
public function handle() { $name = config('cms.frontend-theme'); $result = 'Symlink failed to generate'; if (symlink(base_path('resources/themes/'.strtolower($name).'/public'), base_path('public/theme'))) { $result = 'Symlink generated'; } $this->info($result); }
[ "public", "function", "handle", "(", ")", "{", "$", "name", "=", "config", "(", "'cms.frontend-theme'", ")", ";", "$", "result", "=", "'Symlink failed to generate'", ";", "if", "(", "symlink", "(", "base_path", "(", "'resources/themes/'", ".", "strtolower", "(...
Execute the console command. @return mixed
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ThemeLink.php#L29-L40
GrafiteInc/CMS
src/Repositories/WidgetRepository.php
WidgetRepository.update
public function update($widget, $payload) { $payload['name'] = htmlentities($payload['name']); if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) { return $this->translationRepo->createOrUpdate($widget->id, 'Grafite\Cms\Models\Widget', $payload['lang'], $payload); } else { unset($payload['lang']); return $widget->update($payload); } }
php
public function update($widget, $payload) { $payload['name'] = htmlentities($payload['name']); if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) { return $this->translationRepo->createOrUpdate($widget->id, 'Grafite\Cms\Models\Widget', $payload['lang'], $payload); } else { unset($payload['lang']); return $widget->update($payload); } }
[ "public", "function", "update", "(", "$", "widget", ",", "$", "payload", ")", "{", "$", "payload", "[", "'name'", "]", "=", "htmlentities", "(", "$", "payload", "[", "'name'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "payload", "[", "'lang...
Updates Widget in the database @param Widgets $widget @param array $payload @return Widgets
[ "Updates", "Widget", "in", "the", "database" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/WidgetRepository.php#L46-L57
GrafiteInc/CMS
src/Migrations/2017_07_08_223935_add_entity_to_images.php
AddEntityToImages.up
public function up() { Schema::table(config('cms.db-prefix', '').'images', function (Blueprint $table) { $table->integer('entity_id')->nullable(); $table->string('entity_type')->nullable(); }); }
php
public function up() { Schema::table(config('cms.db-prefix', '').'images', function (Blueprint $table) { $table->integer('entity_id')->nullable(); $table->string('entity_type')->nullable(); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "table", "(", "config", "(", "'cms.db-prefix'", ",", "''", ")", ".", "'images'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "integer", "(", "'entity_id'", ")...
Run the migrations.
[ "Run", "the", "migrations", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Migrations/2017_07_08_223935_add_entity_to_images.php#L12-L18
GrafiteInc/CMS
src/Traits/Translatable.php
Translatable.translation
public function translation($lang) { $result = Translation::where('entity_id', $this->id) ->where('entity_type', get_class($this)) ->where('language', $lang) ->first(); if ($result) { return $result; } $this->data = $this; return $this; }
php
public function translation($lang) { $result = Translation::where('entity_id', $this->id) ->where('entity_type', get_class($this)) ->where('language', $lang) ->first(); if ($result) { return $result; } $this->data = $this; return $this; }
[ "public", "function", "translation", "(", "$", "lang", ")", "{", "$", "result", "=", "Translation", "::", "where", "(", "'entity_id'", ",", "$", "this", "->", "id", ")", "->", "where", "(", "'entity_type'", ",", "get_class", "(", "$", "this", ")", ")",...
Get a translation. @param string $lang @return mixed
[ "Get", "a", "translation", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Traits/Translatable.php#L19-L33
GrafiteInc/CMS
src/Traits/Translatable.php
Translatable.translationData
public function translationData($lang) { $translation = $this->translation($lang); if ($translation) { $data = json_decode($translation->entity_data); if (isset($data->blocks)) { $data->blocks = json_decode($data->blocks, true); } return $data; } return null; }
php
public function translationData($lang) { $translation = $this->translation($lang); if ($translation) { $data = json_decode($translation->entity_data); if (isset($data->blocks)) { $data->blocks = json_decode($data->blocks, true); } return $data; } return null; }
[ "public", "function", "translationData", "(", "$", "lang", ")", "{", "$", "translation", "=", "$", "this", "->", "translation", "(", "$", "lang", ")", ";", "if", "(", "$", "translation", ")", "{", "$", "data", "=", "json_decode", "(", "$", "translation...
Get translation data. @param string $lang @return array|null
[ "Get", "translation", "data", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Traits/Translatable.php#L42-L57
GrafiteInc/CMS
src/Traits/Translatable.php
Translatable.getTranslationsAttribute
public function getTranslationsAttribute() { $translationData = []; $translations = Translation::where('entity_id', $this->id)->where('entity_type', get_class($this))->get(); foreach ($translations as $translation) { $translationData[] = $translation->data->attributes; } return $translationData; }
php
public function getTranslationsAttribute() { $translationData = []; $translations = Translation::where('entity_id', $this->id)->where('entity_type', get_class($this))->get(); foreach ($translations as $translation) { $translationData[] = $translation->data->attributes; } return $translationData; }
[ "public", "function", "getTranslationsAttribute", "(", ")", "{", "$", "translationData", "=", "[", "]", ";", "$", "translations", "=", "Translation", "::", "where", "(", "'entity_id'", ",", "$", "this", "->", "id", ")", "->", "where", "(", "'entity_type'", ...
Get a translations attribute. @return array
[ "Get", "a", "translations", "attribute", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Traits/Translatable.php#L64-L74
GrafiteInc/CMS
src/Traits/Translatable.php
Translatable.afterCreate
public function afterCreate($payload) { if (config('cms.auto-translate', false)) { $entry = $payload->toArray(); unset($entry['created_at']); unset($entry['updated_at']); unset($entry['translations']); unset($entry['is_published']); unset($entry['published_at']); unset($entry['id']); foreach (config('cms.languages') as $code => $language) { if ($code != config('cms.default-language')) { $translateClient = new TranslateClient(config('cms.default-language'), $code); $translation = [ 'lang' => $code, 'template' => 'show', ]; foreach ($entry as $key => $value) { $translation[$key] = $value; if (!empty($value)) { $translation[$key] = json_decode(json_encode($translateClient->translate(strip_tags($value)))); } } // not the biggest fan of this but it works if (empty($translation['blocks'])) { $translation['blocks'] = "{}"; } if (isset($translation['url'])) { $translation['url'] = app(CmsService::class)->convertToURL($translation['url']); } $entityId = $payload->id; $entityType = get_class($payload); app(TranslationRepository::class)->createOrUpdate($entityId, $entityType, $code, $translation); } } } }
php
public function afterCreate($payload) { if (config('cms.auto-translate', false)) { $entry = $payload->toArray(); unset($entry['created_at']); unset($entry['updated_at']); unset($entry['translations']); unset($entry['is_published']); unset($entry['published_at']); unset($entry['id']); foreach (config('cms.languages') as $code => $language) { if ($code != config('cms.default-language')) { $translateClient = new TranslateClient(config('cms.default-language'), $code); $translation = [ 'lang' => $code, 'template' => 'show', ]; foreach ($entry as $key => $value) { $translation[$key] = $value; if (!empty($value)) { $translation[$key] = json_decode(json_encode($translateClient->translate(strip_tags($value)))); } } // not the biggest fan of this but it works if (empty($translation['blocks'])) { $translation['blocks'] = "{}"; } if (isset($translation['url'])) { $translation['url'] = app(CmsService::class)->convertToURL($translation['url']); } $entityId = $payload->id; $entityType = get_class($payload); app(TranslationRepository::class)->createOrUpdate($entityId, $entityType, $code, $translation); } } } }
[ "public", "function", "afterCreate", "(", "$", "payload", ")", "{", "if", "(", "config", "(", "'cms.auto-translate'", ",", "false", ")", ")", "{", "$", "entry", "=", "$", "payload", "->", "toArray", "(", ")", ";", "unset", "(", "$", "entry", "[", "'c...
After the item is created in the database. @param object $payload
[ "After", "the", "item", "is", "created", "in", "the", "database", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Traits/Translatable.php#L81-L124
GrafiteInc/CMS
src/Controllers/BlogController.php
BlogController.index
public function index() { $blogs = $this->repository->paginated(); return view('cms::modules.blogs.index') ->with('blogs', $blogs) ->with('pagination', $blogs->render()); }
php
public function index() { $blogs = $this->repository->paginated(); return view('cms::modules.blogs.index') ->with('blogs', $blogs) ->with('pagination', $blogs->render()); }
[ "public", "function", "index", "(", ")", "{", "$", "blogs", "=", "$", "this", "->", "repository", "->", "paginated", "(", ")", ";", "return", "view", "(", "'cms::modules.blogs.index'", ")", "->", "with", "(", "'blogs'", ",", "$", "blogs", ")", "->", "w...
Display a listing of the Blog. @return Response
[ "Display", "a", "listing", "of", "the", "Blog", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/BlogController.php#L26-L33
GrafiteInc/CMS
src/Controllers/BlogController.php
BlogController.store
public function store(Request $request) { $validation = app(ValidationService::class)->check(Blog::$rules); if (!$validation['errors']) { $blog = $this->repository->store($request->all()); Cms::notification('Blog saved successfully.', 'success'); } else { return $validation['redirect']; } if (!$blog) { Cms::notification('Blog could not be saved.', 'warning'); } return redirect(route($this->routeBase.'.blog.edit', [$blog->id])); }
php
public function store(Request $request) { $validation = app(ValidationService::class)->check(Blog::$rules); if (!$validation['errors']) { $blog = $this->repository->store($request->all()); Cms::notification('Blog saved successfully.', 'success'); } else { return $validation['redirect']; } if (!$blog) { Cms::notification('Blog could not be saved.', 'warning'); } return redirect(route($this->routeBase.'.blog.edit', [$blog->id])); }
[ "public", "function", "store", "(", "Request", "$", "request", ")", "{", "$", "validation", "=", "app", "(", "ValidationService", "::", "class", ")", "->", "check", "(", "Blog", "::", "$", "rules", ")", ";", "if", "(", "!", "$", "validation", "[", "'...
Store a newly created Blog in storage. @param BlogRequest $request @return Response
[ "Store", "a", "newly", "created", "Blog", "in", "storage", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/BlogController.php#L71-L87
GrafiteInc/CMS
src/Controllers/BlogController.php
BlogController.edit
public function edit($id) { $blog = $this->repository->find($id); if (empty($blog)) { Cms::notification('Blog not found', 'warning'); return redirect(route($this->routeBase.'.blog.index')); } return view('cms::modules.blogs.edit')->with('blog', $blog); }
php
public function edit($id) { $blog = $this->repository->find($id); if (empty($blog)) { Cms::notification('Blog not found', 'warning'); return redirect(route($this->routeBase.'.blog.index')); } return view('cms::modules.blogs.edit')->with('blog', $blog); }
[ "public", "function", "edit", "(", "$", "id", ")", "{", "$", "blog", "=", "$", "this", "->", "repository", "->", "find", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "blog", ")", ")", "{", "Cms", "::", "notification", "(", "'Blog not f...
Show the form for editing the specified Blog. @param int $id @return Response
[ "Show", "the", "form", "for", "editing", "the", "specified", "Blog", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/BlogController.php#L96-L107
GrafiteInc/CMS
src/Controllers/BlogController.php
BlogController.update
public function update($id, BlogRequest $request) { $blog = $this->repository->find($id); if (empty($blog)) { Cms::notification('Blog not found', 'warning'); return redirect(route($this->routeBase.'.blog.index')); } $validation = app(ValidationService::class)->check(Blog::$rules); if (!$validation['errors']) { $blog = $this->repository->update($blog, $request->all()); Cms::notification('Blog updated successfully.', 'success'); if (! $blog) { Cms::notification('Blog could not be saved.', 'warning'); } } else { return $validation['redirect']; } return back(); }
php
public function update($id, BlogRequest $request) { $blog = $this->repository->find($id); if (empty($blog)) { Cms::notification('Blog not found', 'warning'); return redirect(route($this->routeBase.'.blog.index')); } $validation = app(ValidationService::class)->check(Blog::$rules); if (!$validation['errors']) { $blog = $this->repository->update($blog, $request->all()); Cms::notification('Blog updated successfully.', 'success'); if (! $blog) { Cms::notification('Blog could not be saved.', 'warning'); } } else { return $validation['redirect']; } return back(); }
[ "public", "function", "update", "(", "$", "id", ",", "BlogRequest", "$", "request", ")", "{", "$", "blog", "=", "$", "this", "->", "repository", "->", "find", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "blog", ")", ")", "{", "Cms", ...
Update the specified Blog in storage. @param int $id @param BlogRequest $request @return Response
[ "Update", "the", "specified", "Blog", "in", "storage", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/BlogController.php#L117-L142
GrafiteInc/CMS
src/Controllers/BlogController.php
BlogController.history
public function history($id) { $blog = $this->repository->find($id); return view('cms::modules.blogs.history') ->with('blog', $blog); }
php
public function history($id) { $blog = $this->repository->find($id); return view('cms::modules.blogs.history') ->with('blog', $blog); }
[ "public", "function", "history", "(", "$", "id", ")", "{", "$", "blog", "=", "$", "this", "->", "repository", "->", "find", "(", "$", "id", ")", ";", "return", "view", "(", "'cms::modules.blogs.history'", ")", "->", "with", "(", "'blog'", ",", "$", "...
Blog history. @param int $id @return Response
[ "Blog", "history", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/BlogController.php#L175-L181
GrafiteInc/CMS
src/PublishedAssets/Controllers/GalleryController.php
GalleryController.show
public function show($tag) { $images = $this->repository->getImagesByTag($tag)->paginate(Config::get('cms.pagination')); $tags = $this->repository->allTags(); if (empty($images)) { abort(404); } return view('cms-frontend::gallery.show') ->with('tags', $tags) ->with('images', $images) ->with('title', $tag); }
php
public function show($tag) { $images = $this->repository->getImagesByTag($tag)->paginate(Config::get('cms.pagination')); $tags = $this->repository->allTags(); if (empty($images)) { abort(404); } return view('cms-frontend::gallery.show') ->with('tags', $tags) ->with('images', $images) ->with('title', $tag); }
[ "public", "function", "show", "(", "$", "tag", ")", "{", "$", "images", "=", "$", "this", "->", "repository", "->", "getImagesByTag", "(", "$", "tag", ")", "->", "paginate", "(", "Config", "::", "get", "(", "'cms.pagination'", ")", ")", ";", "$", "ta...
Display the specified Gallery. @param string $url @return Response
[ "Display", "the", "specified", "Gallery", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/GalleryController.php#L44-L57
GrafiteInc/CMS
src/Repositories/CmsRepository.php
CmsRepository.paginated
public function paginated() { $model = $this->model; if (isset(request()->dir) && isset(request()->field)) { $model = $model->orderBy(request()->field, request()->dir); } else { $model = $model->orderBy('created_at', 'desc'); } return $model->paginate(config('cms.pagination', 25)); }
php
public function paginated() { $model = $this->model; if (isset(request()->dir) && isset(request()->field)) { $model = $model->orderBy(request()->field, request()->dir); } else { $model = $model->orderBy('created_at', 'desc'); } return $model->paginate(config('cms.pagination', 25)); }
[ "public", "function", "paginated", "(", ")", "{", "$", "model", "=", "$", "this", "->", "model", ";", "if", "(", "isset", "(", "request", "(", ")", "->", "dir", ")", "&&", "isset", "(", "request", "(", ")", "->", "field", ")", ")", "{", "$", "m...
Returns all paginated items. @return \Illuminate\Database\Eloquent\Collection|static[]
[ "Returns", "all", "paginated", "items", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/CmsRepository.php#L37-L48
GrafiteInc/CMS
src/Repositories/CmsRepository.php
CmsRepository.published
public function published() { return $this->model->where('is_published', 1) ->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) ->orderBy('created_at', 'desc') ->paginate(config('cms.pagination', 24)); }
php
public function published() { return $this->model->where('is_published', 1) ->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) ->orderBy('created_at', 'desc') ->paginate(config('cms.pagination', 24)); }
[ "public", "function", "published", "(", ")", "{", "return", "$", "this", "->", "model", "->", "where", "(", "'is_published'", ",", "1", ")", "->", "where", "(", "'published_at'", ",", "'<='", ",", "Carbon", "::", "now", "(", "config", "(", "'app.timezone...
Returns all published items. @return \Illuminate\Database\Eloquent\Collection|static[]
[ "Returns", "all", "published", "items", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/CmsRepository.php#L55-L61
GrafiteInc/CMS
src/Repositories/CmsRepository.php
CmsRepository.arePublic
public function arePublic() { if (Schema::hasColumn($this->model->getTable(), 'is_published')) { $query = $this->model->where('is_published', 1); if (Schema::hasColumn($this->model->getTable(), 'published_at')) { $query->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')); } return $query->orderBy('created_at', 'desc')->get(); } return $this->model->orderBy('created_at', 'desc')->get(); }
php
public function arePublic() { if (Schema::hasColumn($this->model->getTable(), 'is_published')) { $query = $this->model->where('is_published', 1); if (Schema::hasColumn($this->model->getTable(), 'published_at')) { $query->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')); } return $query->orderBy('created_at', 'desc')->get(); } return $this->model->orderBy('created_at', 'desc')->get(); }
[ "public", "function", "arePublic", "(", ")", "{", "if", "(", "Schema", "::", "hasColumn", "(", "$", "this", "->", "model", "->", "getTable", "(", ")", ",", "'is_published'", ")", ")", "{", "$", "query", "=", "$", "this", "->", "model", "->", "where",...
Returns all public items @return \Illuminate\Database\Eloquent\Collection|static[]
[ "Returns", "all", "public", "items" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/CmsRepository.php#L68-L81
GrafiteInc/CMS
src/Repositories/CmsRepository.php
CmsRepository.search
public function search($payload) { $query = $this->model->orderBy('created_at', 'desc'); $query->where('id', 'LIKE', '%'.$payload['term'].'%'); $columns = Schema::getColumnListing($this->table); foreach ($columns as $attribute) { $query->orWhere($attribute, 'LIKE', '%'.$payload['term'].'%'); } return [$query, $payload['term'], $query->paginate(25)->render()]; }
php
public function search($payload) { $query = $this->model->orderBy('created_at', 'desc'); $query->where('id', 'LIKE', '%'.$payload['term'].'%'); $columns = Schema::getColumnListing($this->table); foreach ($columns as $attribute) { $query->orWhere($attribute, 'LIKE', '%'.$payload['term'].'%'); } return [$query, $payload['term'], $query->paginate(25)->render()]; }
[ "public", "function", "search", "(", "$", "payload", ")", "{", "$", "query", "=", "$", "this", "->", "model", "->", "orderBy", "(", "'created_at'", ",", "'desc'", ")", ";", "$", "query", "->", "where", "(", "'id'", ",", "'LIKE'", ",", "'%'", ".", "...
Search the columns of a given table @param array $payload @return array
[ "Search", "the", "columns", "of", "a", "given", "table" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/CmsRepository.php#L90-L102
GrafiteInc/CMS
src/Repositories/CmsRepository.php
CmsRepository.parseBlocks
public function parseBlocks($payload, $module) { $blockCollection = []; foreach ($payload as $key => $value) { if (stristr($key, 'block_')) { $blockName = str_replace('block_', '', $key); $blockCollection[$blockName] = $value; unset($payload[$key]); } } $blockCollection = $this->parseTemplate($payload, $blockCollection, $module); if (empty($blockCollection)) { $payload['blocks'] = "{}"; } else { $payload['blocks'] = json_encode($blockCollection); } return $payload; }
php
public function parseBlocks($payload, $module) { $blockCollection = []; foreach ($payload as $key => $value) { if (stristr($key, 'block_')) { $blockName = str_replace('block_', '', $key); $blockCollection[$blockName] = $value; unset($payload[$key]); } } $blockCollection = $this->parseTemplate($payload, $blockCollection, $module); if (empty($blockCollection)) { $payload['blocks'] = "{}"; } else { $payload['blocks'] = json_encode($blockCollection); } return $payload; }
[ "public", "function", "parseBlocks", "(", "$", "payload", ",", "$", "module", ")", "{", "$", "blockCollection", "=", "[", "]", ";", "foreach", "(", "$", "payload", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "stristr", "(", "$", "key...
Convert block payloads into json @param array $payload @param string $module @return array
[ "Convert", "block", "payloads", "into", "json" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/CmsRepository.php#L173-L194
GrafiteInc/CMS
src/Repositories/CmsRepository.php
CmsRepository.parseTemplate
public function parseTemplate($payload, $currentBlocks, $module) { if (isset($payload['template'])) { $content = file_get_contents(base_path('resources/themes/'.config('cms.frontend-theme').'/'.$module.'/'.$payload['template'].'.blade.php')); preg_match_all('/->block\((.*)\)/', $content, $pageMethodMatches); preg_match_all('/\@block\((.*)\)/', $content, $bladeMatches); $matches = array_unique(array_merge($pageMethodMatches[1], $bladeMatches[1])); foreach ($matches as $match) { $match = str_replace('"', "", $match); $match = str_replace("'", "", $match); if (!isset($currentBlocks[$match])) { $currentBlocks[$match] = ''; } } } return $currentBlocks; }
php
public function parseTemplate($payload, $currentBlocks, $module) { if (isset($payload['template'])) { $content = file_get_contents(base_path('resources/themes/'.config('cms.frontend-theme').'/'.$module.'/'.$payload['template'].'.blade.php')); preg_match_all('/->block\((.*)\)/', $content, $pageMethodMatches); preg_match_all('/\@block\((.*)\)/', $content, $bladeMatches); $matches = array_unique(array_merge($pageMethodMatches[1], $bladeMatches[1])); foreach ($matches as $match) { $match = str_replace('"', "", $match); $match = str_replace("'", "", $match); if (!isset($currentBlocks[$match])) { $currentBlocks[$match] = ''; } } } return $currentBlocks; }
[ "public", "function", "parseTemplate", "(", "$", "payload", ",", "$", "currentBlocks", ",", "$", "module", ")", "{", "if", "(", "isset", "(", "$", "payload", "[", "'template'", "]", ")", ")", "{", "$", "content", "=", "file_get_contents", "(", "base_path...
Parse the template for blocks. @param array $payload @param array $currentBlocks @return array
[ "Parse", "the", "template", "for", "blocks", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/CmsRepository.php#L204-L224
GrafiteInc/CMS
src/Repositories/EventRepository.php
EventRepository.findEventsByDate
public function findEventsByDate($date) { return $this->model->where('is_published', 1) ->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) ->orderBy('created_at', 'desc')->where('start_date', '<=', $date) ->where('end_date', '>=', $date)->get(); }
php
public function findEventsByDate($date) { return $this->model->where('is_published', 1) ->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) ->orderBy('created_at', 'desc')->where('start_date', '<=', $date) ->where('end_date', '>=', $date)->get(); }
[ "public", "function", "findEventsByDate", "(", "$", "date", ")", "{", "return", "$", "this", "->", "model", "->", "where", "(", "'is_published'", ",", "1", ")", "->", "where", "(", "'published_at'", ",", "'<='", ",", "Carbon", "::", "now", "(", "config",...
Returns all published Events. @return \Illuminate\Database\Eloquent\Collection|static[]
[ "Returns", "all", "published", "Events", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/EventRepository.php#L30-L36
GrafiteInc/CMS
src/Services/EventService.php
EventService.generate
public function generate($date = null) { $this->date = $date; if (is_null($date)) { $this->date = date('Y-m-d'); } $dateAsArray = explode('-', $this->date); $today = Carbon::createFromDate($dateAsArray[0], $dateAsArray[1], $dateAsArray[2]); foreach (range(1, $today->daysInMonth) as $dayAsNumber) { $day = Carbon::createFromDate($today->year, $today->month, $dayAsNumber); if ($day->dayOfWeek === 0) { $dayOfTheWeek = 7; } else { $dayOfTheWeek = $day->dayOfWeek; } $this->weeks[$day->weekOfYear][$dayOfTheWeek] = $day; } return $this; }
php
public function generate($date = null) { $this->date = $date; if (is_null($date)) { $this->date = date('Y-m-d'); } $dateAsArray = explode('-', $this->date); $today = Carbon::createFromDate($dateAsArray[0], $dateAsArray[1], $dateAsArray[2]); foreach (range(1, $today->daysInMonth) as $dayAsNumber) { $day = Carbon::createFromDate($today->year, $today->month, $dayAsNumber); if ($day->dayOfWeek === 0) { $dayOfTheWeek = 7; } else { $dayOfTheWeek = $day->dayOfWeek; } $this->weeks[$day->weekOfYear][$dayOfTheWeek] = $day; } return $this; }
[ "public", "function", "generate", "(", "$", "date", "=", "null", ")", "{", "$", "this", "->", "date", "=", "$", "date", ";", "if", "(", "is_null", "(", "$", "date", ")", ")", "{", "$", "this", "->", "date", "=", "date", "(", "'Y-m-d'", ")", ";"...
Generate a calendar @param string $date @return Grafite\Cms\Services\EventService
[ "Generate", "a", "calendar" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/EventService.php#L27-L52
GrafiteInc/CMS
src/Services/EventService.php
EventService.calendar
public function calendar($date) { $events = $this->eventRepository->all(); $dateArray = explode('-', $date); $daysInMonth = Carbon::create($dateArray[0], $dateArray[1], $dateArray[2])->daysInMonth; $eventsByDate = []; foreach (range(1, $daysInMonth) as $day) { $date = $dateArray[0].'-'.$dateArray[1].'-'.sprintf('%02d', $day); foreach ($events as $event) { $startDate = explode('-', $event->start_date); $endDate = explode('-', $event->end_date); $first = Carbon::create($startDate[0], $startDate[1], $startDate[2]); $second = Carbon::create($endDate[0], $endDate[1], $endDate[2]); if (Carbon::create($dateArray[0], $dateArray[1], sprintf('%02d', $day))->between($first, $second)) { $eventsByDate[$date][] = $event; } } } return $eventsByDate; }
php
public function calendar($date) { $events = $this->eventRepository->all(); $dateArray = explode('-', $date); $daysInMonth = Carbon::create($dateArray[0], $dateArray[1], $dateArray[2])->daysInMonth; $eventsByDate = []; foreach (range(1, $daysInMonth) as $day) { $date = $dateArray[0].'-'.$dateArray[1].'-'.sprintf('%02d', $day); foreach ($events as $event) { $startDate = explode('-', $event->start_date); $endDate = explode('-', $event->end_date); $first = Carbon::create($startDate[0], $startDate[1], $startDate[2]); $second = Carbon::create($endDate[0], $endDate[1], $endDate[2]); if (Carbon::create($dateArray[0], $dateArray[1], sprintf('%02d', $day))->between($first, $second)) { $eventsByDate[$date][] = $event; } } } return $eventsByDate; }
[ "public", "function", "calendar", "(", "$", "date", ")", "{", "$", "events", "=", "$", "this", "->", "eventRepository", "->", "all", "(", ")", ";", "$", "dateArray", "=", "explode", "(", "'-'", ",", "$", "date", ")", ";", "$", "daysInMonth", "=", "...
Get a calendar by date @param string $date @return array
[ "Get", "a", "calendar", "by", "date" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/EventService.php#L61-L83
GrafiteInc/CMS
src/Services/EventService.php
EventService.asHtml
public function asHtml($config) { $class = $config['class']; $dates = $config['dates']; $daysOfTheWeek = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', ]; $output = '<table class="'.$class.'">'; $output .= '<thead>'; foreach ($daysOfTheWeek as $day) { $output .= '<th>'.$day.'</th>'; } $output .= '</thead>'; foreach ($this->weeks as $week) { $output .= '<tr>'; foreach (range(1, 7) as $dayAsNumber) { if (isset($week[$dayAsNumber])) { $content = ''; if (isset($dates[$week[$dayAsNumber]->toDateString()])) { $content = $dates[$week[$dayAsNumber]->toDateString()]; } if (is_array($content)) { $itemString = ''; foreach ($content as $item) { if (config('app.locale') !== config('cms.default-language')) { if ($item->translationData(config('app.locale'))) { $itemString .= '<a href="'.url('events/event/'.$item->id).'">'.$item->translationData(config('app.locale'))->title.'</a><br>'; } } else { $itemString .= '<a href="'.url('events/event/'.$item->id).'">'.$item->title.'</a><br>'; } } $content = $itemString; } $output .= '<td><span class="date"><a href="'.url('events/date/'.$week[$dayAsNumber]->format('Y-m-d')).'">'.$week[$dayAsNumber]->toFormattedDateString().'</a></span><span class="content">'.$content.'</span></td>'; } else { $output .= '<td>&nbsp;</td>'; } } $output .= '</tr>'; } $output .= '</table>'; return $output; }
php
public function asHtml($config) { $class = $config['class']; $dates = $config['dates']; $daysOfTheWeek = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', ]; $output = '<table class="'.$class.'">'; $output .= '<thead>'; foreach ($daysOfTheWeek as $day) { $output .= '<th>'.$day.'</th>'; } $output .= '</thead>'; foreach ($this->weeks as $week) { $output .= '<tr>'; foreach (range(1, 7) as $dayAsNumber) { if (isset($week[$dayAsNumber])) { $content = ''; if (isset($dates[$week[$dayAsNumber]->toDateString()])) { $content = $dates[$week[$dayAsNumber]->toDateString()]; } if (is_array($content)) { $itemString = ''; foreach ($content as $item) { if (config('app.locale') !== config('cms.default-language')) { if ($item->translationData(config('app.locale'))) { $itemString .= '<a href="'.url('events/event/'.$item->id).'">'.$item->translationData(config('app.locale'))->title.'</a><br>'; } } else { $itemString .= '<a href="'.url('events/event/'.$item->id).'">'.$item->title.'</a><br>'; } } $content = $itemString; } $output .= '<td><span class="date"><a href="'.url('events/date/'.$week[$dayAsNumber]->format('Y-m-d')).'">'.$week[$dayAsNumber]->toFormattedDateString().'</a></span><span class="content">'.$content.'</span></td>'; } else { $output .= '<td>&nbsp;</td>'; } } $output .= '</tr>'; } $output .= '</table>'; return $output; }
[ "public", "function", "asHtml", "(", "$", "config", ")", "{", "$", "class", "=", "$", "config", "[", "'class'", "]", ";", "$", "dates", "=", "$", "config", "[", "'dates'", "]", ";", "$", "daysOfTheWeek", "=", "[", "'Monday'", ",", "'Tuesday'", ",", ...
Get a calendar as html @param array $config @return string
[ "Get", "a", "calendar", "as", "html" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/EventService.php#L92-L147
GrafiteInc/CMS
src/Services/EventService.php
EventService.links
public function links($class = null) { if (is_null($class)) { $class = ''; } $dateArray = explode('-', $this->date); $previousMonth = Carbon::create($dateArray[0], $dateArray[1], $dateArray[2])->subMonth()->toDateString(); $nextMonth = Carbon::create($dateArray[0], $dateArray[1], $dateArray[2])->addMonth()->toDateString(); $links = '<div class="row calendar-links"><div class="col-12">'; $links .= '<a class="previous '.$class.'" href="'.url('events/'.$previousMonth).'">Previous Month</a>'; $links .= '<a class="next '.$class.'" href="'.url('events/'.$nextMonth).'">Next Month</a>'; $links .= '</div></div>'; return $links; }
php
public function links($class = null) { if (is_null($class)) { $class = ''; } $dateArray = explode('-', $this->date); $previousMonth = Carbon::create($dateArray[0], $dateArray[1], $dateArray[2])->subMonth()->toDateString(); $nextMonth = Carbon::create($dateArray[0], $dateArray[1], $dateArray[2])->addMonth()->toDateString(); $links = '<div class="row calendar-links"><div class="col-12">'; $links .= '<a class="previous '.$class.'" href="'.url('events/'.$previousMonth).'">Previous Month</a>'; $links .= '<a class="next '.$class.'" href="'.url('events/'.$nextMonth).'">Next Month</a>'; $links .= '</div></div>'; return $links; }
[ "public", "function", "links", "(", "$", "class", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "class", ")", ")", "{", "$", "class", "=", "''", ";", "}", "$", "dateArray", "=", "explode", "(", "'-'", ",", "$", "this", "->", "date", ")...
Generate HTML links @param string $class @return string
[ "Generate", "HTML", "links" ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/EventService.php#L156-L172
GrafiteInc/CMS
src/Controllers/FilesController.php
FilesController.index
public function index() { $result = $this->repository->paginated(); return view('cms::modules.files.index') ->with('files', $result) ->with('pagination', $result->render()); }
php
public function index() { $result = $this->repository->paginated(); return view('cms::modules.files.index') ->with('files', $result) ->with('pagination', $result->render()); }
[ "public", "function", "index", "(", ")", "{", "$", "result", "=", "$", "this", "->", "repository", "->", "paginated", "(", ")", ";", "return", "view", "(", "'cms::modules.files.index'", ")", "->", "with", "(", "'files'", ",", "$", "result", ")", "->", ...
Display a listing of the Files. @param Request $request @return Response
[ "Display", "a", "listing", "of", "the", "Files", "." ]
train
https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L42-L49