id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
34,400
appstract/lush-http
src/Request/RequestGetters.php
RequestGetters.getParameter
public function getParameter($parameter) { return isset($this->getParameters()[$parameter]) ? $this->getParameters()[$parameter] : null; }
php
public function getParameter($parameter) { return isset($this->getParameters()[$parameter]) ? $this->getParameters()[$parameter] : null; }
[ "public", "function", "getParameter", "(", "$", "parameter", ")", "{", "return", "isset", "(", "$", "this", "->", "getParameters", "(", ")", "[", "$", "parameter", "]", ")", "?", "$", "this", "->", "getParameters", "(", ")", "[", "$", "parameter", "]", ":", "null", ";", "}" ]
Get a specific parameter. @param $parameter @return mixed
[ "Get", "a", "specific", "parameter", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/RequestGetters.php#L44-L47
34,401
appstract/lush-http
src/Request/Adapter/CurlMock.php
CurlMock.setOptions
public function setOptions(array $curlOptions, array $lushOptions = null) { $this->curlOptions = $curlOptions; $this->lushOptions = $lushOptions; }
php
public function setOptions(array $curlOptions, array $lushOptions = null) { $this->curlOptions = $curlOptions; $this->lushOptions = $lushOptions; }
[ "public", "function", "setOptions", "(", "array", "$", "curlOptions", ",", "array", "$", "lushOptions", "=", "null", ")", "{", "$", "this", "->", "curlOptions", "=", "$", "curlOptions", ";", "$", "this", "->", "lushOptions", "=", "$", "lushOptions", ";", "}" ]
Set options array. @param array $curlOptions @param array $lushOptions
[ "Set", "options", "array", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/Adapter/CurlMock.php#L73-L77
34,402
appstract/lush-http
src/Request/Adapter/CurlMock.php
CurlMock.createResponse
protected function createResponse($statusCode, $contentType) { switch ($statusCode) { case 200: case 201: return $this->createContent($contentType); default: // fail on error if ($this->curlOptions[45]) { throw new LushRequestException($this, ['message' => sprintf('%d - Mocked server error', $statusCode), 'code' => $statusCode, 'response' => 'false']); } return json_encode(['url' => $this->ch, 'status' => sprintf('Error: %d', $statusCode)]); } }
php
protected function createResponse($statusCode, $contentType) { switch ($statusCode) { case 200: case 201: return $this->createContent($contentType); default: // fail on error if ($this->curlOptions[45]) { throw new LushRequestException($this, ['message' => sprintf('%d - Mocked server error', $statusCode), 'code' => $statusCode, 'response' => 'false']); } return json_encode(['url' => $this->ch, 'status' => sprintf('Error: %d', $statusCode)]); } }
[ "protected", "function", "createResponse", "(", "$", "statusCode", ",", "$", "contentType", ")", "{", "switch", "(", "$", "statusCode", ")", "{", "case", "200", ":", "case", "201", ":", "return", "$", "this", "->", "createContent", "(", "$", "contentType", ")", ";", "default", ":", "// fail on error", "if", "(", "$", "this", "->", "curlOptions", "[", "45", "]", ")", "{", "throw", "new", "LushRequestException", "(", "$", "this", ",", "[", "'message'", "=>", "sprintf", "(", "'%d - Mocked server error'", ",", "$", "statusCode", ")", ",", "'code'", "=>", "$", "statusCode", ",", "'response'", "=>", "'false'", "]", ")", ";", "}", "return", "json_encode", "(", "[", "'url'", "=>", "$", "this", "->", "ch", ",", "'status'", "=>", "sprintf", "(", "'Error: %d'", ",", "$", "statusCode", ")", "]", ")", ";", "}", "}" ]
Create a example response based on statuscode. @param $statusCode @param $contentType @return string
[ "Create", "a", "example", "response", "based", "on", "statuscode", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/Adapter/CurlMock.php#L163-L177
34,403
appstract/lush-http
src/Request/Adapter/CurlMock.php
CurlMock.createContent
protected function createContent($type) { if ($type == 'json') { $this->headers['content_type'] = 'application/json; charset=UTF-8'; return json_encode(['url' => $this->ch, 'status' => 'ok']); } elseif ($type == 'xml') { $this->headers['content_type'] = 'text/xml; charset=UTF-8'; return '<?xml version="1.0" encoding="UTF-8"?><result><url>'.$this->ch.'</url><status>ok</status></result>'; } return 'ok'; }
php
protected function createContent($type) { if ($type == 'json') { $this->headers['content_type'] = 'application/json; charset=UTF-8'; return json_encode(['url' => $this->ch, 'status' => 'ok']); } elseif ($type == 'xml') { $this->headers['content_type'] = 'text/xml; charset=UTF-8'; return '<?xml version="1.0" encoding="UTF-8"?><result><url>'.$this->ch.'</url><status>ok</status></result>'; } return 'ok'; }
[ "protected", "function", "createContent", "(", "$", "type", ")", "{", "if", "(", "$", "type", "==", "'json'", ")", "{", "$", "this", "->", "headers", "[", "'content_type'", "]", "=", "'application/json; charset=UTF-8'", ";", "return", "json_encode", "(", "[", "'url'", "=>", "$", "this", "->", "ch", ",", "'status'", "=>", "'ok'", "]", ")", ";", "}", "elseif", "(", "$", "type", "==", "'xml'", ")", "{", "$", "this", "->", "headers", "[", "'content_type'", "]", "=", "'text/xml; charset=UTF-8'", ";", "return", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?><result><url>'", ".", "$", "this", "->", "ch", ".", "'</url><status>ok</status></result>'", ";", "}", "return", "'ok'", ";", "}" ]
Create sample content for response. @param $type @return string
[ "Create", "sample", "content", "for", "response", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/Adapter/CurlMock.php#L186-L199
34,404
appstract/lush-http
src/Response/ResponseGetters.php
ResponseGetters.getResult
public function getResult() { if ($this->autoFormat && ! empty($this->object)) { return $this->object; } return $this->content; }
php
public function getResult() { if ($this->autoFormat && ! empty($this->object)) { return $this->object; } return $this->content; }
[ "public", "function", "getResult", "(", ")", "{", "if", "(", "$", "this", "->", "autoFormat", "&&", "!", "empty", "(", "$", "this", "->", "object", ")", ")", "{", "return", "$", "this", "->", "object", ";", "}", "return", "$", "this", "->", "content", ";", "}" ]
Get the content of the result. @return mixed
[ "Get", "the", "content", "of", "the", "result", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/ResponseGetters.php#L14-L21
34,405
appstract/lush-http
src/Response/LushResponse.php
LushResponse.isJson
public function isJson() { if (isset($this->isJson)) { return $this->isJson; } // check based on content header if (strpos($this->getHeader('content_type'), 'application/json') !== false) { $this->isJson = true; } else { // check based on content json_decode($this->content); $this->isJson = (json_last_error() == JSON_ERROR_NONE); } return $this->isJson; }
php
public function isJson() { if (isset($this->isJson)) { return $this->isJson; } // check based on content header if (strpos($this->getHeader('content_type'), 'application/json') !== false) { $this->isJson = true; } else { // check based on content json_decode($this->content); $this->isJson = (json_last_error() == JSON_ERROR_NONE); } return $this->isJson; }
[ "public", "function", "isJson", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "isJson", ")", ")", "{", "return", "$", "this", "->", "isJson", ";", "}", "// check based on content header", "if", "(", "strpos", "(", "$", "this", "->", "getHeader", "(", "'content_type'", ")", ",", "'application/json'", ")", "!==", "false", ")", "{", "$", "this", "->", "isJson", "=", "true", ";", "}", "else", "{", "// check based on content", "json_decode", "(", "$", "this", "->", "content", ")", ";", "$", "this", "->", "isJson", "=", "(", "json_last_error", "(", ")", "==", "JSON_ERROR_NONE", ")", ";", "}", "return", "$", "this", "->", "isJson", ";", "}" ]
Check if content is json. @return null
[ "Check", "if", "content", "is", "json", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/LushResponse.php#L57-L73
34,406
appstract/lush-http
src/Response/LushResponse.php
LushResponse.formatContent
protected function formatContent($content) { if ($this->request->method == 'HEAD') { return (object) $this->headers; } if ($this->isXml()) { return json_decode($this->parseXml($content)); } if ($this->isJson()) { return json_decode($content); } }
php
protected function formatContent($content) { if ($this->request->method == 'HEAD') { return (object) $this->headers; } if ($this->isXml()) { return json_decode($this->parseXml($content)); } if ($this->isJson()) { return json_decode($content); } }
[ "protected", "function", "formatContent", "(", "$", "content", ")", "{", "if", "(", "$", "this", "->", "request", "->", "method", "==", "'HEAD'", ")", "{", "return", "(", "object", ")", "$", "this", "->", "headers", ";", "}", "if", "(", "$", "this", "->", "isXml", "(", ")", ")", "{", "return", "json_decode", "(", "$", "this", "->", "parseXml", "(", "$", "content", ")", ")", ";", "}", "if", "(", "$", "this", "->", "isJson", "(", ")", ")", "{", "return", "json_decode", "(", "$", "content", ")", ";", "}", "}" ]
format content. @param $content @return mixed
[ "format", "content", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/LushResponse.php#L100-L113
34,407
appstract/lush-http
src/Response/LushResponse.php
LushResponse.&
public function &__get($property) { $return = null; // check if the property is present in the content object if (isset($this->object->{ $property })) { $return = $this->object->{ $property }; } return $return; }
php
public function &__get($property) { $return = null; // check if the property is present in the content object if (isset($this->object->{ $property })) { $return = $this->object->{ $property }; } return $return; }
[ "public", "function", "&", "__get", "(", "$", "property", ")", "{", "$", "return", "=", "null", ";", "// check if the property is present in the content object", "if", "(", "isset", "(", "$", "this", "->", "object", "->", "{", "$", "property", "}", ")", ")", "{", "$", "return", "=", "$", "this", "->", "object", "->", "{", "$", "property", "}", ";", "}", "return", "$", "return", ";", "}" ]
Magic getter for content properties. @param $property @return mixed
[ "Magic", "getter", "for", "content", "properties", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/LushResponse.php#L136-L146
34,408
appstract/lush-http
src/Lush.php
Lush.url
public function url($url, $parameters = []) { $this->url = $url; $this->parameters = $parameters; return $this; }
php
public function url($url, $parameters = []) { $this->url = $url; $this->parameters = $parameters; return $this; }
[ "public", "function", "url", "(", "$", "url", ",", "$", "parameters", "=", "[", "]", ")", "{", "$", "this", "->", "url", "=", "$", "url", ";", "$", "this", "->", "parameters", "=", "$", "parameters", ";", "return", "$", "this", ";", "}" ]
Set the url with parameters. @param $url @param array|object $parameters @return $this
[ "Set", "the", "url", "with", "parameters", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Lush.php#L49-L55
34,409
appstract/lush-http
src/Lush.php
Lush.reset
public function reset() { $this->url = ''; $this->parameters = []; $this->headers = []; $this->options = []; return $this; }
php
public function reset() { $this->url = ''; $this->parameters = []; $this->headers = []; $this->options = []; return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "url", "=", "''", ";", "$", "this", "->", "parameters", "=", "[", "]", ";", "$", "this", "->", "headers", "=", "[", "]", ";", "$", "this", "->", "options", "=", "[", "]", ";", "return", "$", "this", ";", "}" ]
Reset all request options. @return $this
[ "Reset", "all", "request", "options", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Lush.php#L90-L98
34,410
appstract/lush-http
src/Lush.php
Lush.addOption
protected function addOption($name, $value) { $this->baseload['options'] = array_merge($this->baseload['options'], [$name => $value]); }
php
protected function addOption($name, $value) { $this->baseload['options'] = array_merge($this->baseload['options'], [$name => $value]); }
[ "protected", "function", "addOption", "(", "$", "name", ",", "$", "value", ")", "{", "$", "this", "->", "baseload", "[", "'options'", "]", "=", "array_merge", "(", "$", "this", "->", "baseload", "[", "'options'", "]", ",", "[", "$", "name", "=>", "$", "value", "]", ")", ";", "}" ]
Add option. @param $name @param $value
[ "Add", "option", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Lush.php#L182-L185
34,411
appstract/lush-http
src/Request/LushRequest.php
LushRequest.formatUrl
protected function formatUrl() { // append trailing slash to the // baseUrl if it is missing if (! empty($this->payload['base_url']) && substr($this->payload['base_url'], -1) !== '/') { $this->payload['base_url'] = $this->payload['base_url'].'/'; } // append the base url $this->payload['url'] = trim($this->payload['base_url'].$this->payload['url']); }
php
protected function formatUrl() { // append trailing slash to the // baseUrl if it is missing if (! empty($this->payload['base_url']) && substr($this->payload['base_url'], -1) !== '/') { $this->payload['base_url'] = $this->payload['base_url'].'/'; } // append the base url $this->payload['url'] = trim($this->payload['base_url'].$this->payload['url']); }
[ "protected", "function", "formatUrl", "(", ")", "{", "// append trailing slash to the", "// baseUrl if it is missing", "if", "(", "!", "empty", "(", "$", "this", "->", "payload", "[", "'base_url'", "]", ")", "&&", "substr", "(", "$", "this", "->", "payload", "[", "'base_url'", "]", ",", "-", "1", ")", "!==", "'/'", ")", "{", "$", "this", "->", "payload", "[", "'base_url'", "]", "=", "$", "this", "->", "payload", "[", "'base_url'", "]", ".", "'/'", ";", "}", "// append the base url", "$", "this", "->", "payload", "[", "'url'", "]", "=", "trim", "(", "$", "this", "->", "payload", "[", "'base_url'", "]", ".", "$", "this", "->", "payload", "[", "'url'", "]", ")", ";", "}" ]
Format url.
[ "Format", "url", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L51-L61
34,412
appstract/lush-http
src/Request/LushRequest.php
LushRequest.validateInput
protected function validateInput() { if (! filter_var($this->payload['url'], FILTER_VALIDATE_URL)) { throw new LushException('URL is invalid', 100); } if (! in_array($this->method, $this->allowedMethods)) { throw new LushException(sprintf("Method '%s' is not supported", $this->method), 101); } }
php
protected function validateInput() { if (! filter_var($this->payload['url'], FILTER_VALIDATE_URL)) { throw new LushException('URL is invalid', 100); } if (! in_array($this->method, $this->allowedMethods)) { throw new LushException(sprintf("Method '%s' is not supported", $this->method), 101); } }
[ "protected", "function", "validateInput", "(", ")", "{", "if", "(", "!", "filter_var", "(", "$", "this", "->", "payload", "[", "'url'", "]", ",", "FILTER_VALIDATE_URL", ")", ")", "{", "throw", "new", "LushException", "(", "'URL is invalid'", ",", "100", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "this", "->", "method", ",", "$", "this", "->", "allowedMethods", ")", ")", "{", "throw", "new", "LushException", "(", "sprintf", "(", "\"Method '%s' is not supported\"", ",", "$", "this", "->", "method", ")", ",", "101", ")", ";", "}", "}" ]
Validate given options.
[ "Validate", "given", "options", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L66-L75
34,413
appstract/lush-http
src/Request/LushRequest.php
LushRequest.addHeaders
protected function addHeaders() { $userHeaders = array_map(function ($key, $value) { // format header like this 'x-header: value' return sprintf('%s: %s', $key, $value); }, array_keys($this->payload['headers']), $this->payload['headers']); $headers = array_merge($this->defaultHeaders, $userHeaders); $this->addCurlOption(CURLOPT_HTTPHEADER, $headers); }
php
protected function addHeaders() { $userHeaders = array_map(function ($key, $value) { // format header like this 'x-header: value' return sprintf('%s: %s', $key, $value); }, array_keys($this->payload['headers']), $this->payload['headers']); $headers = array_merge($this->defaultHeaders, $userHeaders); $this->addCurlOption(CURLOPT_HTTPHEADER, $headers); }
[ "protected", "function", "addHeaders", "(", ")", "{", "$", "userHeaders", "=", "array_map", "(", "function", "(", "$", "key", ",", "$", "value", ")", "{", "// format header like this 'x-header: value'", "return", "sprintf", "(", "'%s: %s'", ",", "$", "key", ",", "$", "value", ")", ";", "}", ",", "array_keys", "(", "$", "this", "->", "payload", "[", "'headers'", "]", ")", ",", "$", "this", "->", "payload", "[", "'headers'", "]", ")", ";", "$", "headers", "=", "array_merge", "(", "$", "this", "->", "defaultHeaders", ",", "$", "userHeaders", ")", ";", "$", "this", "->", "addCurlOption", "(", "CURLOPT_HTTPHEADER", ",", "$", "headers", ")", ";", "}" ]
Add request headers.
[ "Add", "request", "headers", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L80-L90
34,414
appstract/lush-http
src/Request/LushRequest.php
LushRequest.addRequestBody
protected function addRequestBody() { if (! empty($this->payload['parameters'])) { if (in_array($this->method, ['DELETE', 'PATCH', 'POST', 'PUT'])) { $this->addCurlOption(CURLOPT_POSTFIELDS, $this->formattedRequestBody()); } elseif (is_array($this->payload['parameters'])) { // append parameters in the url $this->payload['url'] = sprintf('%s?%s', $this->payload['url'], $this->formattedRequestBody()); } } }
php
protected function addRequestBody() { if (! empty($this->payload['parameters'])) { if (in_array($this->method, ['DELETE', 'PATCH', 'POST', 'PUT'])) { $this->addCurlOption(CURLOPT_POSTFIELDS, $this->formattedRequestBody()); } elseif (is_array($this->payload['parameters'])) { // append parameters in the url $this->payload['url'] = sprintf('%s?%s', $this->payload['url'], $this->formattedRequestBody()); } } }
[ "protected", "function", "addRequestBody", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "payload", "[", "'parameters'", "]", ")", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "method", ",", "[", "'DELETE'", ",", "'PATCH'", ",", "'POST'", ",", "'PUT'", "]", ")", ")", "{", "$", "this", "->", "addCurlOption", "(", "CURLOPT_POSTFIELDS", ",", "$", "this", "->", "formattedRequestBody", "(", ")", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "this", "->", "payload", "[", "'parameters'", "]", ")", ")", "{", "// append parameters in the url", "$", "this", "->", "payload", "[", "'url'", "]", "=", "sprintf", "(", "'%s?%s'", ",", "$", "this", "->", "payload", "[", "'url'", "]", ",", "$", "this", "->", "formattedRequestBody", "(", ")", ")", ";", "}", "}", "}" ]
Add request body.
[ "Add", "request", "body", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L95-L105
34,415
appstract/lush-http
src/Request/LushRequest.php
LushRequest.formattedRequestBody
protected function formattedRequestBody() { if (isset($this->payload['options']['body_format']) && $this->payload['options']['body_format'] == 'json') { return json_encode($this->payload['parameters']); } return http_build_query($this->payload['parameters']); }
php
protected function formattedRequestBody() { if (isset($this->payload['options']['body_format']) && $this->payload['options']['body_format'] == 'json') { return json_encode($this->payload['parameters']); } return http_build_query($this->payload['parameters']); }
[ "protected", "function", "formattedRequestBody", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "payload", "[", "'options'", "]", "[", "'body_format'", "]", ")", "&&", "$", "this", "->", "payload", "[", "'options'", "]", "[", "'body_format'", "]", "==", "'json'", ")", "{", "return", "json_encode", "(", "$", "this", "->", "payload", "[", "'parameters'", "]", ")", ";", "}", "return", "http_build_query", "(", "$", "this", "->", "payload", "[", "'parameters'", "]", ")", ";", "}" ]
Get formatted request body based on body_format. @return null|string
[ "Get", "formatted", "request", "body", "based", "on", "body_format", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L112-L119
34,416
appstract/lush-http
src/Request/LushRequest.php
LushRequest.initOptions
protected function initOptions() { // Set method if ($this->method == 'POST') { $this->addCurlOption(CURLOPT_POST, true); } elseif (in_array($this->method, ['DELETE', 'HEAD', 'PATCH', 'PUT'])) { if ($this->method == 'HEAD') { $this->addCurlOption(CURLOPT_NOBODY, true); } $this->addCurlOption(CURLOPT_CUSTOMREQUEST, $this->method); } // Set allowed protocols if (defined('CURLOPT_PROTOCOLS')) { $this->addCurlOption(CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); } // Handle options from payload if (! empty($this->payload['options']) && is_array($this->payload['options'])) { // Add authentication $this->handleAuthentication(); // Add user options $this->handleUserOptions(); } $this->mergeCurlOptions(); }
php
protected function initOptions() { // Set method if ($this->method == 'POST') { $this->addCurlOption(CURLOPT_POST, true); } elseif (in_array($this->method, ['DELETE', 'HEAD', 'PATCH', 'PUT'])) { if ($this->method == 'HEAD') { $this->addCurlOption(CURLOPT_NOBODY, true); } $this->addCurlOption(CURLOPT_CUSTOMREQUEST, $this->method); } // Set allowed protocols if (defined('CURLOPT_PROTOCOLS')) { $this->addCurlOption(CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); } // Handle options from payload if (! empty($this->payload['options']) && is_array($this->payload['options'])) { // Add authentication $this->handleAuthentication(); // Add user options $this->handleUserOptions(); } $this->mergeCurlOptions(); }
[ "protected", "function", "initOptions", "(", ")", "{", "// Set method", "if", "(", "$", "this", "->", "method", "==", "'POST'", ")", "{", "$", "this", "->", "addCurlOption", "(", "CURLOPT_POST", ",", "true", ")", ";", "}", "elseif", "(", "in_array", "(", "$", "this", "->", "method", ",", "[", "'DELETE'", ",", "'HEAD'", ",", "'PATCH'", ",", "'PUT'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "method", "==", "'HEAD'", ")", "{", "$", "this", "->", "addCurlOption", "(", "CURLOPT_NOBODY", ",", "true", ")", ";", "}", "$", "this", "->", "addCurlOption", "(", "CURLOPT_CUSTOMREQUEST", ",", "$", "this", "->", "method", ")", ";", "}", "// Set allowed protocols", "if", "(", "defined", "(", "'CURLOPT_PROTOCOLS'", ")", ")", "{", "$", "this", "->", "addCurlOption", "(", "CURLOPT_PROTOCOLS", ",", "CURLPROTO_HTTP", "|", "CURLPROTO_HTTPS", ")", ";", "}", "// Handle options from payload", "if", "(", "!", "empty", "(", "$", "this", "->", "payload", "[", "'options'", "]", ")", "&&", "is_array", "(", "$", "this", "->", "payload", "[", "'options'", "]", ")", ")", "{", "// Add authentication", "$", "this", "->", "handleAuthentication", "(", ")", ";", "// Add user options", "$", "this", "->", "handleUserOptions", "(", ")", ";", "}", "$", "this", "->", "mergeCurlOptions", "(", ")", ";", "}" ]
Set request options.
[ "Set", "request", "options", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L146-L174
34,417
appstract/lush-http
src/Request/LushRequest.php
LushRequest.handleAuthentication
protected function handleAuthentication() { if (isset($this->payload['options']['username'], $this->payload['options']['password'])) { $this->addCurlOption(CURLOPT_USERPWD, sprintf('%s:%s', $this->payload['options']['username'], $this->payload['options']['password'])); } }
php
protected function handleAuthentication() { if (isset($this->payload['options']['username'], $this->payload['options']['password'])) { $this->addCurlOption(CURLOPT_USERPWD, sprintf('%s:%s', $this->payload['options']['username'], $this->payload['options']['password'])); } }
[ "protected", "function", "handleAuthentication", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "payload", "[", "'options'", "]", "[", "'username'", "]", ",", "$", "this", "->", "payload", "[", "'options'", "]", "[", "'password'", "]", ")", ")", "{", "$", "this", "->", "addCurlOption", "(", "CURLOPT_USERPWD", ",", "sprintf", "(", "'%s:%s'", ",", "$", "this", "->", "payload", "[", "'options'", "]", "[", "'username'", "]", ",", "$", "this", "->", "payload", "[", "'options'", "]", "[", "'password'", "]", ")", ")", ";", "}", "}" ]
Handle authentication.
[ "Handle", "authentication", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L179-L184
34,418
appstract/lush-http
src/Request/LushRequest.php
LushRequest.handleUserOptions
protected function handleUserOptions() { foreach ($this->payload['options'] as $option => $value) { $resolvedOption = RequestOptions::resolve($option); if ($resolvedOption['type'] == 'curl_option') { $this->addCurlOption($resolvedOption['option'], $value); } else { $this->addOption($option, $value); } } }
php
protected function handleUserOptions() { foreach ($this->payload['options'] as $option => $value) { $resolvedOption = RequestOptions::resolve($option); if ($resolvedOption['type'] == 'curl_option') { $this->addCurlOption($resolvedOption['option'], $value); } else { $this->addOption($option, $value); } } }
[ "protected", "function", "handleUserOptions", "(", ")", "{", "foreach", "(", "$", "this", "->", "payload", "[", "'options'", "]", "as", "$", "option", "=>", "$", "value", ")", "{", "$", "resolvedOption", "=", "RequestOptions", "::", "resolve", "(", "$", "option", ")", ";", "if", "(", "$", "resolvedOption", "[", "'type'", "]", "==", "'curl_option'", ")", "{", "$", "this", "->", "addCurlOption", "(", "$", "resolvedOption", "[", "'option'", "]", ",", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "addOption", "(", "$", "option", ",", "$", "value", ")", ";", "}", "}", "}" ]
Handle user options.
[ "Handle", "user", "options", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L189-L200
34,419
appstract/lush-http
src/Request/CurlRequest.php
CurlRequest.makeRequest
protected function makeRequest() { // init Curl $this->client->init($this->payload['url']); $this->client->setOptions($this->curlOptions, $this->options); // get results $content = $this->client->execute(); $headers = $this->client->getInfo(); $response = new LushResponse(compact('content', 'headers'), $this); // handle errors if ($content === false || substr($headers['http_code'], 0, 1) != 2) { $error = [ 'code' => $this->client->getErrorCode(), 'message' => $this->client->getErrorMessage(), 'response' => $response, ]; $this->client->close(); throw new LushRequestException($this, $error); } $this->client->close(); return $response; }
php
protected function makeRequest() { // init Curl $this->client->init($this->payload['url']); $this->client->setOptions($this->curlOptions, $this->options); // get results $content = $this->client->execute(); $headers = $this->client->getInfo(); $response = new LushResponse(compact('content', 'headers'), $this); // handle errors if ($content === false || substr($headers['http_code'], 0, 1) != 2) { $error = [ 'code' => $this->client->getErrorCode(), 'message' => $this->client->getErrorMessage(), 'response' => $response, ]; $this->client->close(); throw new LushRequestException($this, $error); } $this->client->close(); return $response; }
[ "protected", "function", "makeRequest", "(", ")", "{", "// init Curl", "$", "this", "->", "client", "->", "init", "(", "$", "this", "->", "payload", "[", "'url'", "]", ")", ";", "$", "this", "->", "client", "->", "setOptions", "(", "$", "this", "->", "curlOptions", ",", "$", "this", "->", "options", ")", ";", "// get results", "$", "content", "=", "$", "this", "->", "client", "->", "execute", "(", ")", ";", "$", "headers", "=", "$", "this", "->", "client", "->", "getInfo", "(", ")", ";", "$", "response", "=", "new", "LushResponse", "(", "compact", "(", "'content'", ",", "'headers'", ")", ",", "$", "this", ")", ";", "// handle errors", "if", "(", "$", "content", "===", "false", "||", "substr", "(", "$", "headers", "[", "'http_code'", "]", ",", "0", ",", "1", ")", "!=", "2", ")", "{", "$", "error", "=", "[", "'code'", "=>", "$", "this", "->", "client", "->", "getErrorCode", "(", ")", ",", "'message'", "=>", "$", "this", "->", "client", "->", "getErrorMessage", "(", ")", ",", "'response'", "=>", "$", "response", ",", "]", ";", "$", "this", "->", "client", "->", "close", "(", ")", ";", "throw", "new", "LushRequestException", "(", "$", "this", ",", "$", "error", ")", ";", "}", "$", "this", "->", "client", "->", "close", "(", ")", ";", "return", "$", "response", ";", "}" ]
Sends the Curl requests and returns result array. @return \Appstract\LushHttp\Response\LushResponse
[ "Sends", "the", "Curl", "requests", "and", "returns", "result", "array", "." ]
771c501e1ea6a16b6c33917f595a04e5e37ad9b7
https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/CurlRequest.php#L63-L91
34,420
nails/module-cdn
cdn/controllers/Serve.php
Serve.serveBadSrc
protected function serveBadSrc(array $params) { $error = $params['error']; $oInput = Factory::service('Input'); header('Cache-Control: no-cache, must-revalidate', true); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT', true); header('Content-Type: application/json', true); header($oInput->server('SERVER_PROTOCOL') . ' 400 Bad Request', true, 400); // -------------------------------------------------------------------------- $out = [ 'status' => 400, 'message' => 'Invalid Request', ]; if (!empty($error)) { $out['error'] = $error; } echo json_encode($out); // -------------------------------------------------------------------------- /** * Kill script, th, th, that's all folks. Stop the output class from hijacking * our headers and setting an incorrect Content-Type */ exit(0); }
php
protected function serveBadSrc(array $params) { $error = $params['error']; $oInput = Factory::service('Input'); header('Cache-Control: no-cache, must-revalidate', true); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT', true); header('Content-Type: application/json', true); header($oInput->server('SERVER_PROTOCOL') . ' 400 Bad Request', true, 400); // -------------------------------------------------------------------------- $out = [ 'status' => 400, 'message' => 'Invalid Request', ]; if (!empty($error)) { $out['error'] = $error; } echo json_encode($out); // -------------------------------------------------------------------------- /** * Kill script, th, th, that's all folks. Stop the output class from hijacking * our headers and setting an incorrect Content-Type */ exit(0); }
[ "protected", "function", "serveBadSrc", "(", "array", "$", "params", ")", "{", "$", "error", "=", "$", "params", "[", "'error'", "]", ";", "$", "oInput", "=", "Factory", "::", "service", "(", "'Input'", ")", ";", "header", "(", "'Cache-Control: no-cache, must-revalidate'", ",", "true", ")", ";", "header", "(", "'Expires: Mon, 26 Jul 1997 05:00:00 GMT'", ",", "true", ")", ";", "header", "(", "'Content-Type: application/json'", ",", "true", ")", ";", "header", "(", "$", "oInput", "->", "server", "(", "'SERVER_PROTOCOL'", ")", ".", "' 400 Bad Request'", ",", "true", ",", "400", ")", ";", "// --------------------------------------------------------------------------", "$", "out", "=", "[", "'status'", "=>", "400", ",", "'message'", "=>", "'Invalid Request'", ",", "]", ";", "if", "(", "!", "empty", "(", "$", "error", ")", ")", "{", "$", "out", "[", "'error'", "]", "=", "$", "error", ";", "}", "echo", "json_encode", "(", "$", "out", ")", ";", "// --------------------------------------------------------------------------", "/**\n * Kill script, th, th, that's all folks. Stop the output class from hijacking\n * our headers and setting an incorrect Content-Type\n */", "exit", "(", "0", ")", ";", "}" ]
Serves a response for bad requests @param array $params @internal param string $error The error which occurred
[ "Serves", "a", "response", "for", "bad", "requests" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/cdn/controllers/Serve.php#L260-L291
34,421
jon48/webtrees-lib
src/Webtrees/Family.php
Family.getIntance
public static function getIntance($xref, Tree $tree, $gedcom = null){ $dfam = null; $fam = fw\Family::getInstance($xref, $tree, $gedcom); if($fam){ $dfam = new Family($fam); } return $dfam; }
php
public static function getIntance($xref, Tree $tree, $gedcom = null){ $dfam = null; $fam = fw\Family::getInstance($xref, $tree, $gedcom); if($fam){ $dfam = new Family($fam); } return $dfam; }
[ "public", "static", "function", "getIntance", "(", "$", "xref", ",", "Tree", "$", "tree", ",", "$", "gedcom", "=", "null", ")", "{", "$", "dfam", "=", "null", ";", "$", "fam", "=", "fw", "\\", "Family", "::", "getInstance", "(", "$", "xref", ",", "$", "tree", ",", "$", "gedcom", ")", ";", "if", "(", "$", "fam", ")", "{", "$", "dfam", "=", "new", "Family", "(", "$", "fam", ")", ";", "}", "return", "$", "dfam", ";", "}" ]
Extend \Fisharebest\Webtrees\Family getInstance, in order to retrieve directly a \MyArtJaub\Webtrees\Family object @param string $xref @param Tree $tree @param string $gedcom @return NULL|\MyArtJaub\Webtrees\Family
[ "Extend", "\\", "Fisharebest", "\\", "Webtrees", "\\", "Family", "getInstance", "in", "order", "to", "retrieve", "directly", "a", "\\", "MyArtJaub", "\\", "Webtrees", "\\", "Family", "object" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Family.php#L33-L40
34,422
jon48/webtrees-lib
src/Webtrees/Family.php
Family.isMarriageSourced
function isMarriageSourced(){ if($this->is_marriage_sourced !== null) return $this->is_marriage_sourced; $this->is_marriage_sourced = $this->isFactSourced(WT_EVENTS_MARR.'|MARC'); return $this->is_marriage_sourced; }
php
function isMarriageSourced(){ if($this->is_marriage_sourced !== null) return $this->is_marriage_sourced; $this->is_marriage_sourced = $this->isFactSourced(WT_EVENTS_MARR.'|MARC'); return $this->is_marriage_sourced; }
[ "function", "isMarriageSourced", "(", ")", "{", "if", "(", "$", "this", "->", "is_marriage_sourced", "!==", "null", ")", "return", "$", "this", "->", "is_marriage_sourced", ";", "$", "this", "->", "is_marriage_sourced", "=", "$", "this", "->", "isFactSourced", "(", "WT_EVENTS_MARR", ".", "'|MARC'", ")", ";", "return", "$", "this", "->", "is_marriage_sourced", ";", "}" ]
Check if this family's marriages are sourced @return int Level of sources
[ "Check", "if", "this", "family", "s", "marriages", "are", "sourced" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Family.php#L47-L51
34,423
jon48/webtrees-lib
src/Webtrees/Family.php
Family.getSpouseById
public function getSpouseById(\Fisharebest\Webtrees\Individual $person) { if ($this->gedcomrecord->getWife() && $person->getXref() === $this->gedcomrecord->getWife()->getXref()) { return $this->gedcomrecord->getHusband(); } else { return $this->gedcomrecord->getWife(); } }
php
public function getSpouseById(\Fisharebest\Webtrees\Individual $person) { if ($this->gedcomrecord->getWife() && $person->getXref() === $this->gedcomrecord->getWife()->getXref()) { return $this->gedcomrecord->getHusband(); } else { return $this->gedcomrecord->getWife(); } }
[ "public", "function", "getSpouseById", "(", "\\", "Fisharebest", "\\", "Webtrees", "\\", "Individual", "$", "person", ")", "{", "if", "(", "$", "this", "->", "gedcomrecord", "->", "getWife", "(", ")", "&&", "$", "person", "->", "getXref", "(", ")", "===", "$", "this", "->", "gedcomrecord", "->", "getWife", "(", ")", "->", "getXref", "(", ")", ")", "{", "return", "$", "this", "->", "gedcomrecord", "->", "getHusband", "(", ")", ";", "}", "else", "{", "return", "$", "this", "->", "gedcomrecord", "->", "getWife", "(", ")", ";", "}", "}" ]
Find the spouse of a person, using the Xref comparison. @param Individual $person @return Individual|null
[ "Find", "the", "spouse", "of", "a", "person", "using", "the", "Xref", "comparison", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Family.php#L60-L67
34,424
kadet1090/KeyLighter
Language/GreedyLanguage.php
GreedyLanguage.parse
public function parse($tokens = null, $additional = [], $embedded = false) { if (is_string($tokens)) { $tokens = $this->tokenize($tokens, $additional, $embedded); } elseif (!$tokens instanceof TokenIterator) { // Todo: Own Exceptions throw new \InvalidArgumentException('$tokens must be string or TokenIterator'); } return $this->_process($tokens); }
php
public function parse($tokens = null, $additional = [], $embedded = false) { if (is_string($tokens)) { $tokens = $this->tokenize($tokens, $additional, $embedded); } elseif (!$tokens instanceof TokenIterator) { // Todo: Own Exceptions throw new \InvalidArgumentException('$tokens must be string or TokenIterator'); } return $this->_process($tokens); }
[ "public", "function", "parse", "(", "$", "tokens", "=", "null", ",", "$", "additional", "=", "[", "]", ",", "$", "embedded", "=", "false", ")", "{", "if", "(", "is_string", "(", "$", "tokens", ")", ")", "{", "$", "tokens", "=", "$", "this", "->", "tokenize", "(", "$", "tokens", ",", "$", "additional", ",", "$", "embedded", ")", ";", "}", "elseif", "(", "!", "$", "tokens", "instanceof", "TokenIterator", ")", "{", "// Todo: Own Exceptions", "throw", "new", "\\", "InvalidArgumentException", "(", "'$tokens must be string or TokenIterator'", ")", ";", "}", "return", "$", "this", "->", "_process", "(", "$", "tokens", ")", ";", "}" ]
Parses source and removes wrong tokens. @param TokenIterator|string $tokens @param array $additional @param bool $embedded @return Tokens @throws \InvalidArgumentException
[ "Parses", "source", "and", "removes", "wrong", "tokens", "." ]
6aac402b7fe0170edf3c5afbae652009951068af
https://github.com/kadet1090/KeyLighter/blob/6aac402b7fe0170edf3c5afbae652009951068af/Language/GreedyLanguage.php#L84-L94
34,425
GrupaZero/cms
src/Gzero/Cms/Policies/ContentPolicy.php
ContentPolicy.viewOnFrontend
public function viewOnFrontend(User $user, Content $content) { if ($content->canBeShown()) { return true; } return ($content->author->id === $user->id); }
php
public function viewOnFrontend(User $user, Content $content) { if ($content->canBeShown()) { return true; } return ($content->author->id === $user->id); }
[ "public", "function", "viewOnFrontend", "(", "User", "$", "user", ",", "Content", "$", "content", ")", "{", "if", "(", "$", "content", "->", "canBeShown", "(", ")", ")", "{", "return", "true", ";", "}", "return", "(", "$", "content", "->", "author", "->", "id", "===", "$", "user", "->", "id", ")", ";", "}" ]
Policy for viewing single unpublished element @param User $user User trying to do it @param Content $content Content that we're trying to update @return boolean
[ "Policy", "for", "viewing", "single", "unpublished", "element" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Policies/ContentPolicy.php#L84-L90
34,426
Rareloop/primer-core
src/Primer/Renderable/Pattern.php
Pattern.render
public function render($showChrome = true) { $html = $this->template->render($this->data); // Tidy the HTML $parser = new Parser(); $html = $parser->indent($html); if ($showChrome) { return View::render('pattern', [ 'title' => $this->title, 'id' => $this->id, 'html' => $html, 'template' => $this->templateRaw, 'copy' => $this->copy, 'data' => json_encode($this->data, JSON_PRETTY_PRINT), ]); } else { return $html; } }
php
public function render($showChrome = true) { $html = $this->template->render($this->data); // Tidy the HTML $parser = new Parser(); $html = $parser->indent($html); if ($showChrome) { return View::render('pattern', [ 'title' => $this->title, 'id' => $this->id, 'html' => $html, 'template' => $this->templateRaw, 'copy' => $this->copy, 'data' => json_encode($this->data, JSON_PRETTY_PRINT), ]); } else { return $html; } }
[ "public", "function", "render", "(", "$", "showChrome", "=", "true", ")", "{", "$", "html", "=", "$", "this", "->", "template", "->", "render", "(", "$", "this", "->", "data", ")", ";", "// Tidy the HTML", "$", "parser", "=", "new", "Parser", "(", ")", ";", "$", "html", "=", "$", "parser", "->", "indent", "(", "$", "html", ")", ";", "if", "(", "$", "showChrome", ")", "{", "return", "View", "::", "render", "(", "'pattern'", ",", "[", "'title'", "=>", "$", "this", "->", "title", ",", "'id'", "=>", "$", "this", "->", "id", ",", "'html'", "=>", "$", "html", ",", "'template'", "=>", "$", "this", "->", "templateRaw", ",", "'copy'", "=>", "$", "this", "->", "copy", ",", "'data'", "=>", "json_encode", "(", "$", "this", "->", "data", ",", "JSON_PRETTY_PRINT", ")", ",", "]", ")", ";", "}", "else", "{", "return", "$", "html", ";", "}", "}" ]
Renders the pattern @param boolean $showChrome Whether or not the item should render descriptive chrome @return String HTML text
[ "Renders", "the", "pattern" ]
fe098d6794a4add368f97672397dc93d223a1786
https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Renderable/Pattern.php#L132-L152
34,427
Rareloop/primer-core
src/Primer/Renderable/Pattern.php
Pattern.loadPatternsInPath
public static function loadPatternsInPath($path) { $patterns = array(); if ($handle = opendir($path)) { while (false !== ($entry = readdir($handle))) { $fullPath = $path . '/' . $entry; if ($entry != '..' && $entry != '.' && is_dir($fullPath)) { $id = trim(str_replace(Primer::$PATTERN_PATH, '', $fullPath), '/'); // Load the pattern $patterns[] = new Pattern($id); } } closedir($handle); } return $patterns; }
php
public static function loadPatternsInPath($path) { $patterns = array(); if ($handle = opendir($path)) { while (false !== ($entry = readdir($handle))) { $fullPath = $path . '/' . $entry; if ($entry != '..' && $entry != '.' && is_dir($fullPath)) { $id = trim(str_replace(Primer::$PATTERN_PATH, '', $fullPath), '/'); // Load the pattern $patterns[] = new Pattern($id); } } closedir($handle); } return $patterns; }
[ "public", "static", "function", "loadPatternsInPath", "(", "$", "path", ")", "{", "$", "patterns", "=", "array", "(", ")", ";", "if", "(", "$", "handle", "=", "opendir", "(", "$", "path", ")", ")", "{", "while", "(", "false", "!==", "(", "$", "entry", "=", "readdir", "(", "$", "handle", ")", ")", ")", "{", "$", "fullPath", "=", "$", "path", ".", "'/'", ".", "$", "entry", ";", "if", "(", "$", "entry", "!=", "'..'", "&&", "$", "entry", "!=", "'.'", "&&", "is_dir", "(", "$", "fullPath", ")", ")", "{", "$", "id", "=", "trim", "(", "str_replace", "(", "Primer", "::", "$", "PATTERN_PATH", ",", "''", ",", "$", "fullPath", ")", ",", "'/'", ")", ";", "// Load the pattern", "$", "patterns", "[", "]", "=", "new", "Pattern", "(", "$", "id", ")", ";", "}", "}", "closedir", "(", "$", "handle", ")", ";", "}", "return", "$", "patterns", ";", "}" ]
Helper function to load all patterns in a folder @param String $path The path of the directory to load from @return Array Array of all patterns loaded
[ "Helper", "function", "to", "load", "all", "patterns", "in", "a", "folder" ]
fe098d6794a4add368f97672397dc93d223a1786
https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Renderable/Pattern.php#L162-L182
34,428
locomotivemtl/charcoal-user
src/Charcoal/User/Authenticator.php
Authenticator.authenticate
public function authenticate() { $u = $this->authenticateBySession(); if ($u) { return $u; } $u = $this->authenticateByToken(); if ($u) { return $u; } return null; }
php
public function authenticate() { $u = $this->authenticateBySession(); if ($u) { return $u; } $u = $this->authenticateByToken(); if ($u) { return $u; } return null; }
[ "public", "function", "authenticate", "(", ")", "{", "$", "u", "=", "$", "this", "->", "authenticateBySession", "(", ")", ";", "if", "(", "$", "u", ")", "{", "return", "$", "u", ";", "}", "$", "u", "=", "$", "this", "->", "authenticateByToken", "(", ")", ";", "if", "(", "$", "u", ")", "{", "return", "$", "u", ";", "}", "return", "null", ";", "}" ]
Determine if the current user is authenticated. The user is authenticated via _session ID_ or _auth token_. @return \Charcoal\User\UserInterface|null Returns the authenticated user object or NULL if not authenticated.
[ "Determine", "if", "the", "current", "user", "is", "authenticated", "." ]
86405a592379ebc2b77a7a9a7f68a85f2afe85f0
https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/Authenticator.php#L81-L94
34,429
locomotivemtl/charcoal-user
src/Charcoal/User/Authenticator.php
Authenticator.authenticateBySession
private function authenticateBySession() { $u = $this->userFactory()->create($this->userType()); // Call static method on user $u = call_user_func([get_class($u), 'getAuthenticated'], $this->userFactory()); if ($u && $u->id()) { $u->saveToSession(); return $u; } else { return null; } }
php
private function authenticateBySession() { $u = $this->userFactory()->create($this->userType()); // Call static method on user $u = call_user_func([get_class($u), 'getAuthenticated'], $this->userFactory()); if ($u && $u->id()) { $u->saveToSession(); return $u; } else { return null; } }
[ "private", "function", "authenticateBySession", "(", ")", "{", "$", "u", "=", "$", "this", "->", "userFactory", "(", ")", "->", "create", "(", "$", "this", "->", "userType", "(", ")", ")", ";", "// Call static method on user", "$", "u", "=", "call_user_func", "(", "[", "get_class", "(", "$", "u", ")", ",", "'getAuthenticated'", "]", ",", "$", "this", "->", "userFactory", "(", ")", ")", ";", "if", "(", "$", "u", "&&", "$", "u", "->", "id", "(", ")", ")", "{", "$", "u", "->", "saveToSession", "(", ")", ";", "return", "$", "u", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Attempt to authenticate a user using their session ID. @return \Charcoal\User\UserInterface|null Returns the authenticated user object or NULL if not authenticated.
[ "Attempt", "to", "authenticate", "a", "user", "using", "their", "session", "ID", "." ]
86405a592379ebc2b77a7a9a7f68a85f2afe85f0
https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/Authenticator.php#L269-L282
34,430
locomotivemtl/charcoal-user
src/Charcoal/User/Authenticator.php
Authenticator.authenticateByToken
private function authenticateByToken() { $tokenType = $this->tokenType(); $authToken = $this->tokenFactory()->create($tokenType); if ($authToken->metadata()->enabled() !== true) { return null; } $tokenData = $authToken->getTokenDataFromCookie(); if (!$tokenData) { return null; } $userId = $authToken->getUserIdFromToken($tokenData['ident'], $tokenData['token']); if (!$userId) { return null; } $u = $this->userFactory()->create($this->userType()); $u->load($userId); if ($u->id()) { $u->saveToSession(); return $u; } else { return null; } }
php
private function authenticateByToken() { $tokenType = $this->tokenType(); $authToken = $this->tokenFactory()->create($tokenType); if ($authToken->metadata()->enabled() !== true) { return null; } $tokenData = $authToken->getTokenDataFromCookie(); if (!$tokenData) { return null; } $userId = $authToken->getUserIdFromToken($tokenData['ident'], $tokenData['token']); if (!$userId) { return null; } $u = $this->userFactory()->create($this->userType()); $u->load($userId); if ($u->id()) { $u->saveToSession(); return $u; } else { return null; } }
[ "private", "function", "authenticateByToken", "(", ")", "{", "$", "tokenType", "=", "$", "this", "->", "tokenType", "(", ")", ";", "$", "authToken", "=", "$", "this", "->", "tokenFactory", "(", ")", "->", "create", "(", "$", "tokenType", ")", ";", "if", "(", "$", "authToken", "->", "metadata", "(", ")", "->", "enabled", "(", ")", "!==", "true", ")", "{", "return", "null", ";", "}", "$", "tokenData", "=", "$", "authToken", "->", "getTokenDataFromCookie", "(", ")", ";", "if", "(", "!", "$", "tokenData", ")", "{", "return", "null", ";", "}", "$", "userId", "=", "$", "authToken", "->", "getUserIdFromToken", "(", "$", "tokenData", "[", "'ident'", "]", ",", "$", "tokenData", "[", "'token'", "]", ")", ";", "if", "(", "!", "$", "userId", ")", "{", "return", "null", ";", "}", "$", "u", "=", "$", "this", "->", "userFactory", "(", ")", "->", "create", "(", "$", "this", "->", "userType", "(", ")", ")", ";", "$", "u", "->", "load", "(", "$", "userId", ")", ";", "if", "(", "$", "u", "->", "id", "(", ")", ")", "{", "$", "u", "->", "saveToSession", "(", ")", ";", "return", "$", "u", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Attempt to authenticate a user using their auth token. @return \Charcoal\User\UserInterface|null Returns the authenticated user object or NULL if not authenticated.
[ "Attempt", "to", "authenticate", "a", "user", "using", "their", "auth", "token", "." ]
86405a592379ebc2b77a7a9a7f68a85f2afe85f0
https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/Authenticator.php#L290-L317
34,431
GrupaZero/cms
src/Gzero/Cms/Models/Block.php
Block.files
public function files($active = true) { $query = $this->morphToMany(File::class, 'uploadable') ->with('translations') ->withPivot('weight') ->orderBy('weight', 'ASC') ->withTimestamps(); if ($active) { $query->where('is_active', '=', 1); } return $query; }
php
public function files($active = true) { $query = $this->morphToMany(File::class, 'uploadable') ->with('translations') ->withPivot('weight') ->orderBy('weight', 'ASC') ->withTimestamps(); if ($active) { $query->where('is_active', '=', 1); } return $query; }
[ "public", "function", "files", "(", "$", "active", "=", "true", ")", "{", "$", "query", "=", "$", "this", "->", "morphToMany", "(", "File", "::", "class", ",", "'uploadable'", ")", "->", "with", "(", "'translations'", ")", "->", "withPivot", "(", "'weight'", ")", "->", "orderBy", "(", "'weight'", ",", "'ASC'", ")", "->", "withTimestamps", "(", ")", ";", "if", "(", "$", "active", ")", "{", "$", "query", "->", "where", "(", "'is_active'", ",", "'='", ",", "1", ")", ";", "}", "return", "$", "query", ";", "}" ]
Get all of the files for the content. @param bool $active Only active file @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|\Illuminate\Database\Eloquent\Relations\morphToMany
[ "Get", "all", "of", "the", "files", "for", "the", "content", "." ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L85-L98
34,432
GrupaZero/cms
src/Gzero/Cms/Models/Block.php
Block.getActiveTranslation
public function getActiveTranslation($languageCode) { return $this->translations->first(function ($translation) use ($languageCode) { return $translation->is_active === true && $translation->language_code === $languageCode; }); }
php
public function getActiveTranslation($languageCode) { return $this->translations->first(function ($translation) use ($languageCode) { return $translation->is_active === true && $translation->language_code === $languageCode; }); }
[ "public", "function", "getActiveTranslation", "(", "$", "languageCode", ")", "{", "return", "$", "this", "->", "translations", "->", "first", "(", "function", "(", "$", "translation", ")", "use", "(", "$", "languageCode", ")", "{", "return", "$", "translation", "->", "is_active", "===", "true", "&&", "$", "translation", "->", "language_code", "===", "$", "languageCode", ";", "}", ")", ";", "}" ]
Returns active translation in specific language @param string $languageCode Language code @return mixed
[ "Returns", "active", "translation", "in", "specific", "language" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L150-L155
34,433
GrupaZero/cms
src/Gzero/Cms/Models/Block.php
Block.setFilterAttribute
public function setFilterAttribute($value) { return ($value) ? $this->attributes['filter'] = json_encode($value) : $this->attributes['filter'] = null; }
php
public function setFilterAttribute($value) { return ($value) ? $this->attributes['filter'] = json_encode($value) : $this->attributes['filter'] = null; }
[ "public", "function", "setFilterAttribute", "(", "$", "value", ")", "{", "return", "(", "$", "value", ")", "?", "$", "this", "->", "attributes", "[", "'filter'", "]", "=", "json_encode", "(", "$", "value", ")", ":", "$", "this", "->", "attributes", "[", "'filter'", "]", "=", "null", ";", "}" ]
Set the filter value @param string $value filter value @return string
[ "Set", "the", "filter", "value" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L174-L177
34,434
GrupaZero/cms
src/Gzero/Cms/Models/Block.php
Block.setOptionsAttribute
public function setOptionsAttribute($value) { return ($value) ? $this->attributes['options'] = json_encode($value) : $this->attributes['options'] = null; }
php
public function setOptionsAttribute($value) { return ($value) ? $this->attributes['options'] = json_encode($value) : $this->attributes['options'] = null; }
[ "public", "function", "setOptionsAttribute", "(", "$", "value", ")", "{", "return", "(", "$", "value", ")", "?", "$", "this", "->", "attributes", "[", "'options'", "]", "=", "json_encode", "(", "$", "value", ")", ":", "$", "this", "->", "attributes", "[", "'options'", "]", "=", "null", ";", "}" ]
Set the options value @param string $value filter value @return string
[ "Set", "the", "options", "value" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L198-L201
34,435
jon48/webtrees-lib
src/Webtrees/Mvc/View/ViewBag.php
ViewBag.set
public function set($key, $value, $override = true) { if(is_null($key)) return; if(!$override && array_key_exists($key, $this->data)) return; $this->data[$key] = $value; }
php
public function set($key, $value, $override = true) { if(is_null($key)) return; if(!$override && array_key_exists($key, $this->data)) return; $this->data[$key] = $value; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ",", "$", "override", "=", "true", ")", "{", "if", "(", "is_null", "(", "$", "key", ")", ")", "return", ";", "if", "(", "!", "$", "override", "&&", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "data", ")", ")", "return", ";", "$", "this", "->", "data", "[", "$", "key", "]", "=", "$", "value", ";", "}" ]
Set the value for the specified key. Can define whether to override an existing value; @param string $key @param mixed $value @param bool $override
[ "Set", "the", "value", "for", "the", "specified", "key", ".", "Can", "define", "whether", "to", "override", "an", "existing", "value", ";" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Mvc/View/ViewBag.php#L75-L79
34,436
GrupaZero/cms
src/Gzero/Cms/BlockFinder.php
BlockFinder.getBlocksIds
public function getBlocksIds($routable, $onlyActive = false) { return $this->findBlocksForPath($routable, $this->getFilterArray($onlyActive)); }
php
public function getBlocksIds($routable, $onlyActive = false) { return $this->findBlocksForPath($routable, $this->getFilterArray($onlyActive)); }
[ "public", "function", "getBlocksIds", "(", "$", "routable", ",", "$", "onlyActive", "=", "false", ")", "{", "return", "$", "this", "->", "findBlocksForPath", "(", "$", "routable", ",", "$", "this", "->", "getFilterArray", "(", "$", "onlyActive", ")", ")", ";", "}" ]
It returns blocks ids that should be displayed on specified content @param string|Routable $routable Routable @param bool $onlyActive Trigger to display only active blocks @return array
[ "It", "returns", "blocks", "ids", "that", "should", "be", "displayed", "on", "specified", "content" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L41-L44
34,437
GrupaZero/cms
src/Gzero/Cms/BlockFinder.php
BlockFinder.findBlocksForPath
protected function findBlocksForPath($routable, $filter) { if (is_string($routable)) { // static page like "home", "contact" etc. return $this->handleStaticPageCase($routable, $filter); } $ids = $routable->getTreePath(); $idsCount = count($ids); $blockIds = []; if ($idsCount === 1) { // Root case $allIds = []; $rootPath = $ids[0] . '/'; if (isset($filter['paths'][$rootPath])) { $allIds = $filter['paths'][$rootPath]; } // We're returning only blocks ids that uses filter property $blockIds = array_keys($allIds + $filter['excluded'], true, true); } else { $allIds = []; $parentPath = ''; foreach ($ids as $index => $id) { $parentPath .= $id . '/'; $pathMatch = ($index + 1 < $idsCount) ? $parentPath . '*' : $parentPath; if (isset($filter['paths'][$pathMatch])) { // Order of operation is important! We want to override $allIds be lower level filter (left overrides right) $allIds = $filter['paths'][$pathMatch] + $allIds; } } // We're returning only blocks ids that uses filter property $blockIds = array_keys($allIds + $filter['excluded'], true, true); } return $blockIds; }
php
protected function findBlocksForPath($routable, $filter) { if (is_string($routable)) { // static page like "home", "contact" etc. return $this->handleStaticPageCase($routable, $filter); } $ids = $routable->getTreePath(); $idsCount = count($ids); $blockIds = []; if ($idsCount === 1) { // Root case $allIds = []; $rootPath = $ids[0] . '/'; if (isset($filter['paths'][$rootPath])) { $allIds = $filter['paths'][$rootPath]; } // We're returning only blocks ids that uses filter property $blockIds = array_keys($allIds + $filter['excluded'], true, true); } else { $allIds = []; $parentPath = ''; foreach ($ids as $index => $id) { $parentPath .= $id . '/'; $pathMatch = ($index + 1 < $idsCount) ? $parentPath . '*' : $parentPath; if (isset($filter['paths'][$pathMatch])) { // Order of operation is important! We want to override $allIds be lower level filter (left overrides right) $allIds = $filter['paths'][$pathMatch] + $allIds; } } // We're returning only blocks ids that uses filter property $blockIds = array_keys($allIds + $filter['excluded'], true, true); } return $blockIds; }
[ "protected", "function", "findBlocksForPath", "(", "$", "routable", ",", "$", "filter", ")", "{", "if", "(", "is_string", "(", "$", "routable", ")", ")", "{", "// static page like \"home\", \"contact\" etc.", "return", "$", "this", "->", "handleStaticPageCase", "(", "$", "routable", ",", "$", "filter", ")", ";", "}", "$", "ids", "=", "$", "routable", "->", "getTreePath", "(", ")", ";", "$", "idsCount", "=", "count", "(", "$", "ids", ")", ";", "$", "blockIds", "=", "[", "]", ";", "if", "(", "$", "idsCount", "===", "1", ")", "{", "// Root case", "$", "allIds", "=", "[", "]", ";", "$", "rootPath", "=", "$", "ids", "[", "0", "]", ".", "'/'", ";", "if", "(", "isset", "(", "$", "filter", "[", "'paths'", "]", "[", "$", "rootPath", "]", ")", ")", "{", "$", "allIds", "=", "$", "filter", "[", "'paths'", "]", "[", "$", "rootPath", "]", ";", "}", "// We're returning only blocks ids that uses filter property", "$", "blockIds", "=", "array_keys", "(", "$", "allIds", "+", "$", "filter", "[", "'excluded'", "]", ",", "true", ",", "true", ")", ";", "}", "else", "{", "$", "allIds", "=", "[", "]", ";", "$", "parentPath", "=", "''", ";", "foreach", "(", "$", "ids", "as", "$", "index", "=>", "$", "id", ")", "{", "$", "parentPath", ".=", "$", "id", ".", "'/'", ";", "$", "pathMatch", "=", "(", "$", "index", "+", "1", "<", "$", "idsCount", ")", "?", "$", "parentPath", ".", "'*'", ":", "$", "parentPath", ";", "if", "(", "isset", "(", "$", "filter", "[", "'paths'", "]", "[", "$", "pathMatch", "]", ")", ")", "{", "// Order of operation is important! We want to override $allIds be lower level filter (left overrides right)", "$", "allIds", "=", "$", "filter", "[", "'paths'", "]", "[", "$", "pathMatch", "]", "+", "$", "allIds", ";", "}", "}", "// We're returning only blocks ids that uses filter property", "$", "blockIds", "=", "array_keys", "(", "$", "allIds", "+", "$", "filter", "[", "'excluded'", "]", ",", "true", ",", "true", ")", ";", "}", "return", "$", "blockIds", ";", "}" ]
Find all blocks ids that should be displayed on specific path @param string|Routable $routable Routable path or static page named route @param array $filter Array with all filters @return array
[ "Find", "all", "blocks", "ids", "that", "should", "be", "displayed", "on", "specific", "path" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L54-L85
34,438
GrupaZero/cms
src/Gzero/Cms/BlockFinder.php
BlockFinder.getFilterArray
protected function getFilterArray($onlyActive) { $cacheKey = ($onlyActive) ? 'public' : 'admin'; if ($this->cache->tags(['blocks'])->has('blocks:filter:' . $cacheKey)) { return $this->cache->tags(['blocks'])->get('blocks:filter:' . $cacheKey); } else { $blocks = $this->blockRepository->getBlocksWithFilter($onlyActive); $filter = $this->buildFilterArray($blocks); $this->cache->tags(['blocks'])->forever('blocks:filter:' . $cacheKey, $filter); return $filter; } }
php
protected function getFilterArray($onlyActive) { $cacheKey = ($onlyActive) ? 'public' : 'admin'; if ($this->cache->tags(['blocks'])->has('blocks:filter:' . $cacheKey)) { return $this->cache->tags(['blocks'])->get('blocks:filter:' . $cacheKey); } else { $blocks = $this->blockRepository->getBlocksWithFilter($onlyActive); $filter = $this->buildFilterArray($blocks); $this->cache->tags(['blocks'])->forever('blocks:filter:' . $cacheKey, $filter); return $filter; } }
[ "protected", "function", "getFilterArray", "(", "$", "onlyActive", ")", "{", "$", "cacheKey", "=", "(", "$", "onlyActive", ")", "?", "'public'", ":", "'admin'", ";", "if", "(", "$", "this", "->", "cache", "->", "tags", "(", "[", "'blocks'", "]", ")", "->", "has", "(", "'blocks:filter:'", ".", "$", "cacheKey", ")", ")", "{", "return", "$", "this", "->", "cache", "->", "tags", "(", "[", "'blocks'", "]", ")", "->", "get", "(", "'blocks:filter:'", ".", "$", "cacheKey", ")", ";", "}", "else", "{", "$", "blocks", "=", "$", "this", "->", "blockRepository", "->", "getBlocksWithFilter", "(", "$", "onlyActive", ")", ";", "$", "filter", "=", "$", "this", "->", "buildFilterArray", "(", "$", "blocks", ")", ";", "$", "this", "->", "cache", "->", "tags", "(", "[", "'blocks'", "]", ")", "->", "forever", "(", "'blocks:filter:'", ".", "$", "cacheKey", ",", "$", "filter", ")", ";", "return", "$", "filter", ";", "}", "}" ]
It builds filter array with all blocks @param bool $onlyActive Filter only public blocks @return array
[ "It", "builds", "filter", "array", "with", "all", "blocks" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L94-L105
34,439
GrupaZero/cms
src/Gzero/Cms/BlockFinder.php
BlockFinder.buildFilterArray
protected function buildFilterArray($blocks) { $filter = []; $excluded = []; foreach ($blocks as $block) { $this->extractFilter($block, $filter, $excluded); } return ['paths' => $filter, 'excluded' => $excluded]; }
php
protected function buildFilterArray($blocks) { $filter = []; $excluded = []; foreach ($blocks as $block) { $this->extractFilter($block, $filter, $excluded); } return ['paths' => $filter, 'excluded' => $excluded]; }
[ "protected", "function", "buildFilterArray", "(", "$", "blocks", ")", "{", "$", "filter", "=", "[", "]", ";", "$", "excluded", "=", "[", "]", ";", "foreach", "(", "$", "blocks", "as", "$", "block", ")", "{", "$", "this", "->", "extractFilter", "(", "$", "block", ",", "$", "filter", ",", "$", "excluded", ")", ";", "}", "return", "[", "'paths'", "=>", "$", "filter", ",", "'excluded'", "=>", "$", "excluded", "]", ";", "}" ]
It extracts all filters from blocks & build filter array @param array|Collection $blocks Blocks @return array
[ "It", "extracts", "all", "filters", "from", "blocks", "&", "build", "filter", "array" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L114-L122
34,440
GrupaZero/cms
src/Gzero/Cms/BlockFinder.php
BlockFinder.handleStaticPageCase
protected function handleStaticPageCase($path, $filter) { if (isset($filter['paths'][$path])) { return array_keys($filter['paths'][$path] + $filter['excluded'], true, true); } return array_keys($filter['excluded'], true, true); }
php
protected function handleStaticPageCase($path, $filter) { if (isset($filter['paths'][$path])) { return array_keys($filter['paths'][$path] + $filter['excluded'], true, true); } return array_keys($filter['excluded'], true, true); }
[ "protected", "function", "handleStaticPageCase", "(", "$", "path", ",", "$", "filter", ")", "{", "if", "(", "isset", "(", "$", "filter", "[", "'paths'", "]", "[", "$", "path", "]", ")", ")", "{", "return", "array_keys", "(", "$", "filter", "[", "'paths'", "]", "[", "$", "path", "]", "+", "$", "filter", "[", "'excluded'", "]", ",", "true", ",", "true", ")", ";", "}", "return", "array_keys", "(", "$", "filter", "[", "'excluded'", "]", ",", "true", ",", "true", ")", ";", "}" ]
It checks which blocks should be displayed for specific static page @param string $path Static page named route @param array $filter Array with all filters @return array
[ "It", "checks", "which", "blocks", "should", "be", "displayed", "for", "specific", "static", "page" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L144-L150
34,441
GrupaZero/cms
src/Gzero/Cms/BlockFinder.php
BlockFinder.extractFilter
protected function extractFilter(Block $block, array &$filter, array &$excluded) { if (isset($block->filter['+'])) { foreach ($block->filter['+'] as $filterValue) { if (isset($filter[$filterValue])) { $filter[$filterValue][$block->id] = true; } else { $filter[$filterValue] = [$block->id => true]; } } } if (isset($block->filter['-'])) { foreach ($block->filter['-'] as $filterValue) { if (isset($filter[$filterValue])) { $filter[$filterValue][$block->id] = false; } else { $filter[$filterValue] = [$block->id => false]; } // By default block with - should display on all sited except those from filter $excluded[$block->id] = true; } } }
php
protected function extractFilter(Block $block, array &$filter, array &$excluded) { if (isset($block->filter['+'])) { foreach ($block->filter['+'] as $filterValue) { if (isset($filter[$filterValue])) { $filter[$filterValue][$block->id] = true; } else { $filter[$filterValue] = [$block->id => true]; } } } if (isset($block->filter['-'])) { foreach ($block->filter['-'] as $filterValue) { if (isset($filter[$filterValue])) { $filter[$filterValue][$block->id] = false; } else { $filter[$filterValue] = [$block->id => false]; } // By default block with - should display on all sited except those from filter $excluded[$block->id] = true; } } }
[ "protected", "function", "extractFilter", "(", "Block", "$", "block", ",", "array", "&", "$", "filter", ",", "array", "&", "$", "excluded", ")", "{", "if", "(", "isset", "(", "$", "block", "->", "filter", "[", "'+'", "]", ")", ")", "{", "foreach", "(", "$", "block", "->", "filter", "[", "'+'", "]", "as", "$", "filterValue", ")", "{", "if", "(", "isset", "(", "$", "filter", "[", "$", "filterValue", "]", ")", ")", "{", "$", "filter", "[", "$", "filterValue", "]", "[", "$", "block", "->", "id", "]", "=", "true", ";", "}", "else", "{", "$", "filter", "[", "$", "filterValue", "]", "=", "[", "$", "block", "->", "id", "=>", "true", "]", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "block", "->", "filter", "[", "'-'", "]", ")", ")", "{", "foreach", "(", "$", "block", "->", "filter", "[", "'-'", "]", "as", "$", "filterValue", ")", "{", "if", "(", "isset", "(", "$", "filter", "[", "$", "filterValue", "]", ")", ")", "{", "$", "filter", "[", "$", "filterValue", "]", "[", "$", "block", "->", "id", "]", "=", "false", ";", "}", "else", "{", "$", "filter", "[", "$", "filterValue", "]", "=", "[", "$", "block", "->", "id", "=>", "false", "]", ";", "}", "// By default block with - should display on all sited except those from filter", "$", "excluded", "[", "$", "block", "->", "id", "]", "=", "true", ";", "}", "}", "}" ]
It extracts filter property from single block @param Block $block Block instance @param array $filter Filter array @param array $excluded Excluded array @return void
[ "It", "extracts", "filter", "property", "from", "single", "block" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L161-L183
34,442
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.getResizedImageSize
static public function getResizedImageSize($file, $target=25){ list($width, $height, , ) = getimagesize($file); $max = max($width, $height); $rapp = $target / $max; $width = intval($rapp * $width); $height = intval($rapp * $height); return array($width, $height); }
php
static public function getResizedImageSize($file, $target=25){ list($width, $height, , ) = getimagesize($file); $max = max($width, $height); $rapp = $target / $max; $width = intval($rapp * $width); $height = intval($rapp * $height); return array($width, $height); }
[ "static", "public", "function", "getResizedImageSize", "(", "$", "file", ",", "$", "target", "=", "25", ")", "{", "list", "(", "$", "width", ",", "$", "height", ",", ",", ")", "=", "getimagesize", "(", "$", "file", ")", ";", "$", "max", "=", "max", "(", "$", "width", ",", "$", "height", ")", ";", "$", "rapp", "=", "$", "target", "/", "$", "max", ";", "$", "width", "=", "intval", "(", "$", "rapp", "*", "$", "width", ")", ";", "$", "height", "=", "intval", "(", "$", "rapp", "*", "$", "height", ")", ";", "return", "array", "(", "$", "width", ",", "$", "height", ")", ";", "}" ]
Get width and heigth of an image resized in order fit a target size. @param string $file The image to resize @param int $target The final max width/height @return array array of ($width, $height). One of them must be $target
[ "Get", "width", "and", "heigth", "of", "an", "image", "resized", "in", "order", "fit", "a", "target", "size", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L75-L82
34,443
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.doesTableExist
public static function doesTableExist($table) { try { fw\Database::prepare("SELECT 1 FROM {$table}")->fetchOne(); return true; } catch (\PDOException $ex) { return false; } }
php
public static function doesTableExist($table) { try { fw\Database::prepare("SELECT 1 FROM {$table}")->fetchOne(); return true; } catch (\PDOException $ex) { return false; } }
[ "public", "static", "function", "doesTableExist", "(", "$", "table", ")", "{", "try", "{", "fw", "\\", "Database", "::", "prepare", "(", "\"SELECT 1 FROM {$table}\"", ")", "->", "fetchOne", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "PDOException", "$", "ex", ")", "{", "return", "false", ";", "}", "}" ]
Checks if a table exist in the DB schema @param string $table Name of the table to look for @return boolean Does the table exist
[ "Checks", "if", "a", "table", "exist", "in", "the", "DB", "schema" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L91-L98
34,444
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.generateRandomToken
public static function generateRandomToken($length=32) { $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); $len_chars = count($chars); $token = ''; for ($i = 0; $i < $length; $i++) $token .= $chars[ mt_rand(0, $len_chars - 1) ]; # Number of 32 char chunks $chunks = ceil( strlen($token) / 32 ); $md5token = ''; # Run each chunk through md5 for ( $i=1; $i<=$chunks; $i++ ) $md5token .= md5( substr($token, $i * 32 - 32, 32) ); # Trim the token return substr($md5token, 0, $length); }
php
public static function generateRandomToken($length=32) { $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); $len_chars = count($chars); $token = ''; for ($i = 0; $i < $length; $i++) $token .= $chars[ mt_rand(0, $len_chars - 1) ]; # Number of 32 char chunks $chunks = ceil( strlen($token) / 32 ); $md5token = ''; # Run each chunk through md5 for ( $i=1; $i<=$chunks; $i++ ) $md5token .= md5( substr($token, $i * 32 - 32, 32) ); # Trim the token return substr($md5token, 0, $length); }
[ "public", "static", "function", "generateRandomToken", "(", "$", "length", "=", "32", ")", "{", "$", "chars", "=", "str_split", "(", "'abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'", ")", ";", "$", "len_chars", "=", "count", "(", "$", "chars", ")", ";", "$", "token", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "$", "token", ".=", "$", "chars", "[", "mt_rand", "(", "0", ",", "$", "len_chars", "-", "1", ")", "]", ";", "# Number of 32 char chunks", "$", "chunks", "=", "ceil", "(", "strlen", "(", "$", "token", ")", "/", "32", ")", ";", "$", "md5token", "=", "''", ";", "# Run each chunk through md5", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "chunks", ";", "$", "i", "++", ")", "$", "md5token", ".=", "md5", "(", "substr", "(", "$", "token", ",", "$", "i", "*", "32", "-", "32", ",", "32", ")", ")", ";", "# Trim the token", "return", "substr", "(", "$", "md5token", ",", "0", ",", "$", "length", ")", ";", "}" ]
Returns a randomy generated token of a given size @param int $length Length of the token, default to 32 @return string Random token
[ "Returns", "a", "randomy", "generated", "token", "of", "a", "given", "size" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L106-L124
34,445
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.getBase64EncryptionKey
protected static function getBase64EncryptionKey() { $key = 'STANDARDKEYIFNOSERVER'; if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); return $key; }
php
protected static function getBase64EncryptionKey() { $key = 'STANDARDKEYIFNOSERVER'; if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); return $key; }
[ "protected", "static", "function", "getBase64EncryptionKey", "(", ")", "{", "$", "key", "=", "'STANDARDKEYIFNOSERVER'", ";", "if", "(", "!", "empty", "(", "Filter", "::", "server", "(", "'SERVER_NAME'", ")", ")", "&&", "!", "empty", "(", "Filter", "::", "server", "(", "'SERVER_SOFTWARE'", ")", ")", ")", "$", "key", "=", "md5", "(", "Filter", "::", "server", "(", "'SERVER_NAME'", ")", ".", "Filter", "::", "server", "(", "'SERVER_SOFTWARE'", ")", ")", ";", "return", "$", "key", ";", "}" ]
Generate the key used by the encryption to safe base64 functions. @return string Encryption key
[ "Generate", "the", "key", "used", "by", "the", "encryption", "to", "safe", "base64", "functions", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L131-L137
34,446
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.decryptFromSafeBase64
public static function decryptFromSafeBase64($encrypted){ $encrypted = str_replace('-', '+', $encrypted); $encrypted = str_replace('_', '/', $encrypted); $encrypted = str_replace('*', '=', $encrypted); $encrypted = base64_decode($encrypted); if($encrypted === false) throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); if($decrypted === false) { throw new \InvalidArgumentException('The message has been tampered with in transit.'); } //sodium_memzero($encrypted); // Requires PHP 7.2 return $decrypted; }
php
public static function decryptFromSafeBase64($encrypted){ $encrypted = str_replace('-', '+', $encrypted); $encrypted = str_replace('_', '/', $encrypted); $encrypted = str_replace('*', '=', $encrypted); $encrypted = base64_decode($encrypted); if($encrypted === false) throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); if($decrypted === false) { throw new \InvalidArgumentException('The message has been tampered with in transit.'); } //sodium_memzero($encrypted); // Requires PHP 7.2 return $decrypted; }
[ "public", "static", "function", "decryptFromSafeBase64", "(", "$", "encrypted", ")", "{", "$", "encrypted", "=", "str_replace", "(", "'-'", ",", "'+'", ",", "$", "encrypted", ")", ";", "$", "encrypted", "=", "str_replace", "(", "'_'", ",", "'/'", ",", "$", "encrypted", ")", ";", "$", "encrypted", "=", "str_replace", "(", "'*'", ",", "'='", ",", "$", "encrypted", ")", ";", "$", "encrypted", "=", "base64_decode", "(", "$", "encrypted", ")", ";", "if", "(", "$", "encrypted", "===", "false", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'The encrypted value is not in correct base64 format.'", ")", ";", "if", "(", "mb_strlen", "(", "$", "encrypted", ",", "'8bit'", ")", "<", "(", "SODIUM_CRYPTO_SECRETBOX_NONCEBYTES", "+", "SODIUM_CRYPTO_SECRETBOX_MACBYTES", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'The encrypted value does not contain enough characters for the key.'", ")", ";", "$", "nonce", "=", "mb_substr", "(", "$", "encrypted", ",", "0", ",", "SODIUM_CRYPTO_SECRETBOX_NONCEBYTES", ",", "'8bit'", ")", ";", "$", "ciphertext", "=", "mb_substr", "(", "$", "encrypted", ",", "SODIUM_CRYPTO_SECRETBOX_NONCEBYTES", ",", "null", ",", "'8bit'", ")", ";", "$", "decrypted", "=", "sodium_crypto_secretbox_open", "(", "$", "ciphertext", ",", "$", "nonce", ",", "self", "::", "getBase64EncryptionKey", "(", ")", ")", ";", "if", "(", "$", "decrypted", "===", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The message has been tampered with in transit.'", ")", ";", "}", "//sodium_memzero($encrypted); // Requires PHP 7.2", "return", "$", "decrypted", ";", "}" ]
Decode and encrypt a text from base64 compatible with URL use @param string $encrypted Text to decrypt @return string Decrypted text
[ "Decode", "and", "encrypt", "a", "text", "from", "base64", "compatible", "with", "URL", "use" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L166-L189
34,447
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.isValidPath
public static function isValidPath($filename, $acceptfolder = FALSE) { if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; return false; }
php
public static function isValidPath($filename, $acceptfolder = FALSE) { if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; return false; }
[ "public", "static", "function", "isValidPath", "(", "$", "filename", ",", "$", "acceptfolder", "=", "FALSE", ")", "{", "if", "(", "strpbrk", "(", "$", "filename", ",", "$", "acceptfolder", "?", "'?%*:|\"<>'", ":", "'\\\\/?%*:|\"<>'", ")", "===", "FALSE", ")", "return", "true", ";", "return", "false", ";", "}" ]
Check whether a path is under a valid form. @param string $filename Filename path to check @param boolean $acceptfolder Should folders be accepted? @return boolean True if path valid
[ "Check", "whether", "a", "path", "is", "under", "a", "valid", "form", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L224-L227
34,448
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.getCalendarShortMonths
public static function getCalendarShortMonths($calendarId = 0) { if(!isset(self::$calendarShortMonths[$calendarId])) { $calendar_info = cal_info($calendarId); self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths']; } return self::$calendarShortMonths[$calendarId]; }
php
public static function getCalendarShortMonths($calendarId = 0) { if(!isset(self::$calendarShortMonths[$calendarId])) { $calendar_info = cal_info($calendarId); self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths']; } return self::$calendarShortMonths[$calendarId]; }
[ "public", "static", "function", "getCalendarShortMonths", "(", "$", "calendarId", "=", "0", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "calendarShortMonths", "[", "$", "calendarId", "]", ")", ")", "{", "$", "calendar_info", "=", "cal_info", "(", "$", "calendarId", ")", ";", "self", "::", "$", "calendarShortMonths", "[", "$", "calendarId", "]", "=", "$", "calendar_info", "[", "'abbrevmonths'", "]", ";", "}", "return", "self", "::", "$", "calendarShortMonths", "[", "$", "calendarId", "]", ";", "}" ]
Return short names for the months of the specific calendar. @see \cal_info() @param integer $calendarId Calendar ID (according to PHP cal_info) @return array Array of month short names
[ "Return", "short", "names", "for", "the", "months", "of", "the", "specific", "calendar", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L236-L242
34,449
jon48/webtrees-lib
src/Webtrees/Functions/Functions.php
Functions.isImageTypeSupported
public static function isImageTypeSupported($reqtype) { $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); $reqtype = strtolower($reqtype); if (empty($supportByGD[$reqtype])) { return false; } $type = $supportByGD[$reqtype]; if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { return $type; } return false; }
php
public static function isImageTypeSupported($reqtype) { $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); $reqtype = strtolower($reqtype); if (empty($supportByGD[$reqtype])) { return false; } $type = $supportByGD[$reqtype]; if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { return $type; } return false; }
[ "public", "static", "function", "isImageTypeSupported", "(", "$", "reqtype", ")", "{", "$", "supportByGD", "=", "array", "(", "'jpg'", "=>", "'jpeg'", ",", "'jpeg'", "=>", "'jpeg'", ",", "'gif'", "=>", "'gif'", ",", "'png'", "=>", "'png'", ")", ";", "$", "reqtype", "=", "strtolower", "(", "$", "reqtype", ")", ";", "if", "(", "empty", "(", "$", "supportByGD", "[", "$", "reqtype", "]", ")", ")", "{", "return", "false", ";", "}", "$", "type", "=", "$", "supportByGD", "[", "$", "reqtype", "]", ";", "if", "(", "function_exists", "(", "'imagecreatefrom'", ".", "$", "type", ")", "&&", "function_exists", "(", "'image'", ".", "$", "type", ")", ")", "{", "return", "$", "type", ";", "}", "return", "false", ";", "}" ]
Returns whether the image type is supported by the system, and if so, return the standardised type @param string $reqtype Extension to test @return boolean|string Is supported?
[ "Returns", "whether", "the", "image", "type", "is", "supported", "by", "the", "system", "and", "if", "so", "return", "the", "standardised", "type" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/Functions.php#L263-L278
34,450
GrupaZero/cms
src/Gzero/Cms/Http/Resources/Content.php
Content.buildPath
private function buildPath($path) { $result = []; foreach (explode('/', $path) as $value) { if (!empty($value)) { $result[] = (int) $value; } } return $result; }
php
private function buildPath($path) { $result = []; foreach (explode('/', $path) as $value) { if (!empty($value)) { $result[] = (int) $value; } } return $result; }
[ "private", "function", "buildPath", "(", "$", "path", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "explode", "(", "'/'", ",", "$", "path", ")", "as", "$", "value", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "result", "[", "]", "=", "(", "int", ")", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns array of path ids as integers @param Content $path path to explode @return array extracted path
[ "Returns", "array", "of", "path", "ids", "as", "integers" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Http/Resources/Content.php#L151-L160
34,451
jon48/webtrees-lib
src/Webtrees/Module/AdminTasks/Model/AbstractTask.php
AbstractTask.setParameters
public function setParameters($is_enabled, \DateTime $last_updated, $last_result, $frequency, $nb_occur, $is_running){ $this->is_enabled = $is_enabled; $this->last_updated = $last_updated; $this->last_result = $last_result; $this->frequency = $frequency; $this->nb_occurrences = $nb_occur; $this->is_running = $is_running; }
php
public function setParameters($is_enabled, \DateTime $last_updated, $last_result, $frequency, $nb_occur, $is_running){ $this->is_enabled = $is_enabled; $this->last_updated = $last_updated; $this->last_result = $last_result; $this->frequency = $frequency; $this->nb_occurrences = $nb_occur; $this->is_running = $is_running; }
[ "public", "function", "setParameters", "(", "$", "is_enabled", ",", "\\", "DateTime", "$", "last_updated", ",", "$", "last_result", ",", "$", "frequency", ",", "$", "nb_occur", ",", "$", "is_running", ")", "{", "$", "this", "->", "is_enabled", "=", "$", "is_enabled", ";", "$", "this", "->", "last_updated", "=", "$", "last_updated", ";", "$", "this", "->", "last_result", "=", "$", "last_result", ";", "$", "this", "->", "frequency", "=", "$", "frequency", ";", "$", "this", "->", "nb_occurrences", "=", "$", "nb_occur", ";", "$", "this", "->", "is_running", "=", "$", "is_running", ";", "}" ]
Set parameters of the Task @param bool $is_enabled Status of the task @param \DateTime $lastupdated Time of the last task run @param bool $last_result Result of the last run, true for success, false for failure @param int $frequency Frequency of execution in minutes @param int $nb_occur Number of remaining occurrences, 0 for tasks not limited @param bool $is_running Indicates if the task is currently running
[ "Set", "parameters", "of", "the", "Task" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/AdminTasks/Model/AbstractTask.php#L118-L125
34,452
jon48/webtrees-lib
src/Webtrees/Module/AdminTasks/Model/AbstractTask.php
AbstractTask.execute
public function execute(){ if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) $this->is_running = false; if(!$this->is_running){ $this->last_result = false; $this->is_running = true; $this->save(); Log::addDebugLog('Start execution of Admin task: '.$this->getTitle()); $this->last_result = $this->executeSteps(); if($this->last_result){ $this->last_updated = new \DateTime(); if($this->nb_occurrences > 0){ $this->nb_occurrences--; if($this->nb_occurrences == 0) $this->is_enabled = false; } } $this->is_running = false; $this->save(); Log::addDebugLog('Execution completed for Admin task: '.$this->getTitle().' - '.($this->last_result ? 'Success' : 'Failure')); } }
php
public function execute(){ if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) $this->is_running = false; if(!$this->is_running){ $this->last_result = false; $this->is_running = true; $this->save(); Log::addDebugLog('Start execution of Admin task: '.$this->getTitle()); $this->last_result = $this->executeSteps(); if($this->last_result){ $this->last_updated = new \DateTime(); if($this->nb_occurrences > 0){ $this->nb_occurrences--; if($this->nb_occurrences == 0) $this->is_enabled = false; } } $this->is_running = false; $this->save(); Log::addDebugLog('Execution completed for Admin task: '.$this->getTitle().' - '.($this->last_result ? 'Success' : 'Failure')); } }
[ "public", "function", "execute", "(", ")", "{", "if", "(", "$", "this", "->", "last_updated", "->", "add", "(", "new", "\\", "DateInterval", "(", "'PT'", ".", "self", "::", "TASK_TIME_OUT", ".", "'S'", ")", ")", "<", "new", "\\", "DateTime", "(", ")", ")", "$", "this", "->", "is_running", "=", "false", ";", "if", "(", "!", "$", "this", "->", "is_running", ")", "{", "$", "this", "->", "last_result", "=", "false", ";", "$", "this", "->", "is_running", "=", "true", ";", "$", "this", "->", "save", "(", ")", ";", "Log", "::", "addDebugLog", "(", "'Start execution of Admin task: '", ".", "$", "this", "->", "getTitle", "(", ")", ")", ";", "$", "this", "->", "last_result", "=", "$", "this", "->", "executeSteps", "(", ")", ";", "if", "(", "$", "this", "->", "last_result", ")", "{", "$", "this", "->", "last_updated", "=", "new", "\\", "DateTime", "(", ")", ";", "if", "(", "$", "this", "->", "nb_occurrences", ">", "0", ")", "{", "$", "this", "->", "nb_occurrences", "--", ";", "if", "(", "$", "this", "->", "nb_occurrences", "==", "0", ")", "$", "this", "->", "is_enabled", "=", "false", ";", "}", "}", "$", "this", "->", "is_running", "=", "false", ";", "$", "this", "->", "save", "(", ")", ";", "Log", "::", "addDebugLog", "(", "'Execution completed for Admin task: '", ".", "$", "this", "->", "getTitle", "(", ")", ".", "' - '", ".", "(", "$", "this", "->", "last_result", "?", "'Success'", ":", "'Failure'", ")", ")", ";", "}", "}" ]
Execute the task, default skeleton
[ "Execute", "the", "task", "default", "skeleton" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/AdminTasks/Model/AbstractTask.php#L246-L269
34,453
Rareloop/primer-core
src/Primer/Primer.php
Primer.start
public static function start($options) { ErrorHandler::register(); ExceptionHandler::register(); // Default params $defaultTemplateClass = 'Rareloop\Primer\TemplateEngine\Handlebars\Template'; // Work out what we were passed as an argument if (is_string($options)) { // Backwards compatibility Primer::$BASE_PATH = realpath($options); Primer::$PATTERN_PATH = Primer::$BASE_PATH . '/patterns'; Primer::$PATTERN_PATH = Primer::$BASE_PATH . '/views'; Primer::$CACHE_PATH = Primer::$BASE_PATH . '/cache'; Primer::$TEMPLATE_CLASS = $defaultTemplateClass; Primer::$WRAP_TEMPLATES = true; } else { // New more expressive function params if (!isset($options['basePath'])) { throw new Exception('No `basePath` param passed to Primer::start()'); } Primer::$BASE_PATH = realpath($options['basePath']); Primer::$PATTERN_PATH = isset($options['patternPath']) ? realpath($options['patternPath']) : Primer::$BASE_PATH . '/patterns'; Primer::$VIEW_PATH = isset($options['viewPath']) ? realpath($options['viewPath']) : Primer::$BASE_PATH . '/views'; Primer::$CACHE_PATH = isset($options['cachePath']) ? realpath($options['cachePath']) : Primer::$BASE_PATH . '/cache'; Primer::$TEMPLATE_CLASS = isset($options['templateClass']) ? $options['templateClass'] : $defaultTemplateClass; Primer::$WRAP_TEMPLATES = isset($options['wrapTemplate']) ? $options['wrapTemplate'] : true; } // Attempt to load all `init.php` files. We shouldn't really have to do this here but currently // include functions don't actually load patterns so its hard to track when things are loaded // TODO: Move everything through Pattern constructors $finder = new Finder(); $initFiles = $finder->in(Primer::$PATTERN_PATH)->files()->name('init.php'); foreach ($initFiles as $file) { include_once($file); } return Primer::instance(); }
php
public static function start($options) { ErrorHandler::register(); ExceptionHandler::register(); // Default params $defaultTemplateClass = 'Rareloop\Primer\TemplateEngine\Handlebars\Template'; // Work out what we were passed as an argument if (is_string($options)) { // Backwards compatibility Primer::$BASE_PATH = realpath($options); Primer::$PATTERN_PATH = Primer::$BASE_PATH . '/patterns'; Primer::$PATTERN_PATH = Primer::$BASE_PATH . '/views'; Primer::$CACHE_PATH = Primer::$BASE_PATH . '/cache'; Primer::$TEMPLATE_CLASS = $defaultTemplateClass; Primer::$WRAP_TEMPLATES = true; } else { // New more expressive function params if (!isset($options['basePath'])) { throw new Exception('No `basePath` param passed to Primer::start()'); } Primer::$BASE_PATH = realpath($options['basePath']); Primer::$PATTERN_PATH = isset($options['patternPath']) ? realpath($options['patternPath']) : Primer::$BASE_PATH . '/patterns'; Primer::$VIEW_PATH = isset($options['viewPath']) ? realpath($options['viewPath']) : Primer::$BASE_PATH . '/views'; Primer::$CACHE_PATH = isset($options['cachePath']) ? realpath($options['cachePath']) : Primer::$BASE_PATH . '/cache'; Primer::$TEMPLATE_CLASS = isset($options['templateClass']) ? $options['templateClass'] : $defaultTemplateClass; Primer::$WRAP_TEMPLATES = isset($options['wrapTemplate']) ? $options['wrapTemplate'] : true; } // Attempt to load all `init.php` files. We shouldn't really have to do this here but currently // include functions don't actually load patterns so its hard to track when things are loaded // TODO: Move everything through Pattern constructors $finder = new Finder(); $initFiles = $finder->in(Primer::$PATTERN_PATH)->files()->name('init.php'); foreach ($initFiles as $file) { include_once($file); } return Primer::instance(); }
[ "public", "static", "function", "start", "(", "$", "options", ")", "{", "ErrorHandler", "::", "register", "(", ")", ";", "ExceptionHandler", "::", "register", "(", ")", ";", "// Default params", "$", "defaultTemplateClass", "=", "'Rareloop\\Primer\\TemplateEngine\\Handlebars\\Template'", ";", "// Work out what we were passed as an argument", "if", "(", "is_string", "(", "$", "options", ")", ")", "{", "// Backwards compatibility", "Primer", "::", "$", "BASE_PATH", "=", "realpath", "(", "$", "options", ")", ";", "Primer", "::", "$", "PATTERN_PATH", "=", "Primer", "::", "$", "BASE_PATH", ".", "'/patterns'", ";", "Primer", "::", "$", "PATTERN_PATH", "=", "Primer", "::", "$", "BASE_PATH", ".", "'/views'", ";", "Primer", "::", "$", "CACHE_PATH", "=", "Primer", "::", "$", "BASE_PATH", ".", "'/cache'", ";", "Primer", "::", "$", "TEMPLATE_CLASS", "=", "$", "defaultTemplateClass", ";", "Primer", "::", "$", "WRAP_TEMPLATES", "=", "true", ";", "}", "else", "{", "// New more expressive function params", "if", "(", "!", "isset", "(", "$", "options", "[", "'basePath'", "]", ")", ")", "{", "throw", "new", "Exception", "(", "'No `basePath` param passed to Primer::start()'", ")", ";", "}", "Primer", "::", "$", "BASE_PATH", "=", "realpath", "(", "$", "options", "[", "'basePath'", "]", ")", ";", "Primer", "::", "$", "PATTERN_PATH", "=", "isset", "(", "$", "options", "[", "'patternPath'", "]", ")", "?", "realpath", "(", "$", "options", "[", "'patternPath'", "]", ")", ":", "Primer", "::", "$", "BASE_PATH", ".", "'/patterns'", ";", "Primer", "::", "$", "VIEW_PATH", "=", "isset", "(", "$", "options", "[", "'viewPath'", "]", ")", "?", "realpath", "(", "$", "options", "[", "'viewPath'", "]", ")", ":", "Primer", "::", "$", "BASE_PATH", ".", "'/views'", ";", "Primer", "::", "$", "CACHE_PATH", "=", "isset", "(", "$", "options", "[", "'cachePath'", "]", ")", "?", "realpath", "(", "$", "options", "[", "'cachePath'", "]", ")", ":", "Primer", "::", "$", "BASE_PATH", ".", "'/cache'", ";", "Primer", "::", "$", "TEMPLATE_CLASS", "=", "isset", "(", "$", "options", "[", "'templateClass'", "]", ")", "?", "$", "options", "[", "'templateClass'", "]", ":", "$", "defaultTemplateClass", ";", "Primer", "::", "$", "WRAP_TEMPLATES", "=", "isset", "(", "$", "options", "[", "'wrapTemplate'", "]", ")", "?", "$", "options", "[", "'wrapTemplate'", "]", ":", "true", ";", "}", "// Attempt to load all `init.php` files. We shouldn't really have to do this here but currently", "// include functions don't actually load patterns so its hard to track when things are loaded", "// TODO: Move everything through Pattern constructors", "$", "finder", "=", "new", "Finder", "(", ")", ";", "$", "initFiles", "=", "$", "finder", "->", "in", "(", "Primer", "::", "$", "PATTERN_PATH", ")", "->", "files", "(", ")", "->", "name", "(", "'init.php'", ")", ";", "foreach", "(", "$", "initFiles", "as", "$", "file", ")", "{", "include_once", "(", "$", "file", ")", ";", "}", "return", "Primer", "::", "instance", "(", ")", ";", "}" ]
Bootstrap the Primer singleton For backwards compatibility the first param is either a string to the BASE_PATH or it can be an assoc array array( 'basePath' => '', 'patternPath' => '', // Defaults to PRIMER::$BASE_PATH . '/pattern' 'cachePath' => '', // Defaults to PRIMER::$BASE_PATH . '/cache' 'templateEngine' => '' // Defaults to 'Rareloop\Primer\TemplateEngine\Handlebars\Template' ) @param String|Array $options @return Rareloop\Primer\Primer
[ "Bootstrap", "the", "Primer", "singleton" ]
fe098d6794a4add368f97672397dc93d223a1786
https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Primer.php#L100-L144
34,454
Rareloop/primer-core
src/Primer/Primer.php
Primer.getTemplate
public function getTemplate($id) { // Default system wide template wrapping config $wrapTemplate = Primer::$WRAP_TEMPLATES; $id = Primer::cleanId($id); // Create the template $template = new Pattern('templates/' . $id); $templateData = new ViewData([ "primer" => [ 'bodyClass' => 'is-template', 'template' => $id, ], ]); $data = $template->getData(); // Template level wrapping config if (isset($data->primer->wrapTemplate)) { $wrapTemplate = $data->primer->wrapTemplate; } if ($wrapTemplate) { $view = 'template'; // Check the data to see if there is a custom view if (isset($data->primer) && isset($data->primer->view)) { $view = $data->primer->view; } $templateData->primer->items = $template->render(false); Event::fire('render', $templateData); return View::render($view, $templateData); } else { // Merge the data we would have passed into the view into the template $template->setData($templateData); // Get a reference to the template data so that we can pass it to anyone who's listening $viewData = $template->getData(); Event::fire('render', $viewData); return $template->render(false); } }
php
public function getTemplate($id) { // Default system wide template wrapping config $wrapTemplate = Primer::$WRAP_TEMPLATES; $id = Primer::cleanId($id); // Create the template $template = new Pattern('templates/' . $id); $templateData = new ViewData([ "primer" => [ 'bodyClass' => 'is-template', 'template' => $id, ], ]); $data = $template->getData(); // Template level wrapping config if (isset($data->primer->wrapTemplate)) { $wrapTemplate = $data->primer->wrapTemplate; } if ($wrapTemplate) { $view = 'template'; // Check the data to see if there is a custom view if (isset($data->primer) && isset($data->primer->view)) { $view = $data->primer->view; } $templateData->primer->items = $template->render(false); Event::fire('render', $templateData); return View::render($view, $templateData); } else { // Merge the data we would have passed into the view into the template $template->setData($templateData); // Get a reference to the template data so that we can pass it to anyone who's listening $viewData = $template->getData(); Event::fire('render', $viewData); return $template->render(false); } }
[ "public", "function", "getTemplate", "(", "$", "id", ")", "{", "// Default system wide template wrapping config", "$", "wrapTemplate", "=", "Primer", "::", "$", "WRAP_TEMPLATES", ";", "$", "id", "=", "Primer", "::", "cleanId", "(", "$", "id", ")", ";", "// Create the template", "$", "template", "=", "new", "Pattern", "(", "'templates/'", ".", "$", "id", ")", ";", "$", "templateData", "=", "new", "ViewData", "(", "[", "\"primer\"", "=>", "[", "'bodyClass'", "=>", "'is-template'", ",", "'template'", "=>", "$", "id", ",", "]", ",", "]", ")", ";", "$", "data", "=", "$", "template", "->", "getData", "(", ")", ";", "// Template level wrapping config", "if", "(", "isset", "(", "$", "data", "->", "primer", "->", "wrapTemplate", ")", ")", "{", "$", "wrapTemplate", "=", "$", "data", "->", "primer", "->", "wrapTemplate", ";", "}", "if", "(", "$", "wrapTemplate", ")", "{", "$", "view", "=", "'template'", ";", "// Check the data to see if there is a custom view", "if", "(", "isset", "(", "$", "data", "->", "primer", ")", "&&", "isset", "(", "$", "data", "->", "primer", "->", "view", ")", ")", "{", "$", "view", "=", "$", "data", "->", "primer", "->", "view", ";", "}", "$", "templateData", "->", "primer", "->", "items", "=", "$", "template", "->", "render", "(", "false", ")", ";", "Event", "::", "fire", "(", "'render'", ",", "$", "templateData", ")", ";", "return", "View", "::", "render", "(", "$", "view", ",", "$", "templateData", ")", ";", "}", "else", "{", "// Merge the data we would have passed into the view into the template", "$", "template", "->", "setData", "(", "$", "templateData", ")", ";", "// Get a reference to the template data so that we can pass it to anyone who's listening", "$", "viewData", "=", "$", "template", "->", "getData", "(", ")", ";", "Event", "::", "fire", "(", "'render'", ",", "$", "viewData", ")", ";", "return", "$", "template", "->", "render", "(", "false", ")", ";", "}", "}" ]
Get a specific page template @param String $id The template id @return String
[ "Get", "a", "specific", "page", "template" ]
fe098d6794a4add368f97672397dc93d223a1786
https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Primer.php#L169-L216
34,455
Rareloop/primer-core
src/Primer/Primer.php
Primer.getPatterns
public function getPatterns($ids, $showChrome = true) { $renderList = new RenderList(); foreach ($ids as $id) { $id = Primer::cleanId($id); // Check if the Id is for a pattern or a group $parts = explode('/', $id); if (count($parts) > 2) { // It's a pattern $renderList->add(new Pattern($id)); } elseif (count($parts) > 1) { // It's a group $renderList->add(new Group($id)); } else { // It's a section (e.g. all elements or all components) $renderList->add(new Section($id)); } } return $this->prepareViewForPatterns($renderList, $showChrome); }
php
public function getPatterns($ids, $showChrome = true) { $renderList = new RenderList(); foreach ($ids as $id) { $id = Primer::cleanId($id); // Check if the Id is for a pattern or a group $parts = explode('/', $id); if (count($parts) > 2) { // It's a pattern $renderList->add(new Pattern($id)); } elseif (count($parts) > 1) { // It's a group $renderList->add(new Group($id)); } else { // It's a section (e.g. all elements or all components) $renderList->add(new Section($id)); } } return $this->prepareViewForPatterns($renderList, $showChrome); }
[ "public", "function", "getPatterns", "(", "$", "ids", ",", "$", "showChrome", "=", "true", ")", "{", "$", "renderList", "=", "new", "RenderList", "(", ")", ";", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "$", "id", "=", "Primer", "::", "cleanId", "(", "$", "id", ")", ";", "// Check if the Id is for a pattern or a group", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "id", ")", ";", "if", "(", "count", "(", "$", "parts", ")", ">", "2", ")", "{", "// It's a pattern", "$", "renderList", "->", "add", "(", "new", "Pattern", "(", "$", "id", ")", ")", ";", "}", "elseif", "(", "count", "(", "$", "parts", ")", ">", "1", ")", "{", "// It's a group", "$", "renderList", "->", "add", "(", "new", "Group", "(", "$", "id", ")", ")", ";", "}", "else", "{", "// It's a section (e.g. all elements or all components)", "$", "renderList", "->", "add", "(", "new", "Section", "(", "$", "id", ")", ")", ";", "}", "}", "return", "$", "this", "->", "prepareViewForPatterns", "(", "$", "renderList", ",", "$", "showChrome", ")", ";", "}" ]
Get a selection of patterns @param Array $ids An array of pattern/group/section ids @param boolean $showChrome Should we show the chrome @return String
[ "Get", "a", "selection", "of", "patterns" ]
fe098d6794a4add368f97672397dc93d223a1786
https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Primer.php#L256-L278
34,456
Rareloop/primer-core
src/Primer/Primer.php
Primer.getTemplates
public function getTemplates() { $templates = array(); if ($handle = opendir(Primer::$PATTERN_PATH . '/templates')) { while (false !== ($entry = readdir($handle))) { if (substr($entry, 0, 1) !== '.') { $templates[] = array( 'id' => $entry, 'title' => preg_replace('/[^A-Za-z0-9]/', ' ', $entry), ); } } closedir($handle); } return $templates; }
php
public function getTemplates() { $templates = array(); if ($handle = opendir(Primer::$PATTERN_PATH . '/templates')) { while (false !== ($entry = readdir($handle))) { if (substr($entry, 0, 1) !== '.') { $templates[] = array( 'id' => $entry, 'title' => preg_replace('/[^A-Za-z0-9]/', ' ', $entry), ); } } closedir($handle); } return $templates; }
[ "public", "function", "getTemplates", "(", ")", "{", "$", "templates", "=", "array", "(", ")", ";", "if", "(", "$", "handle", "=", "opendir", "(", "Primer", "::", "$", "PATTERN_PATH", ".", "'/templates'", ")", ")", "{", "while", "(", "false", "!==", "(", "$", "entry", "=", "readdir", "(", "$", "handle", ")", ")", ")", "{", "if", "(", "substr", "(", "$", "entry", ",", "0", ",", "1", ")", "!==", "'.'", ")", "{", "$", "templates", "[", "]", "=", "array", "(", "'id'", "=>", "$", "entry", ",", "'title'", "=>", "preg_replace", "(", "'/[^A-Za-z0-9]/'", ",", "' '", ",", "$", "entry", ")", ",", ")", ";", "}", "}", "closedir", "(", "$", "handle", ")", ";", "}", "return", "$", "templates", ";", "}" ]
Get the list of templates available. Returns an array of associative arrays e.g. array( array( 'id' => 'home', 'title' => 'Home', ), array( 'id' => 'about-us', 'title' => 'About Us' ) ); @return array
[ "Get", "the", "list", "of", "templates", "available", ".", "Returns", "an", "array", "of", "associative", "arrays" ]
fe098d6794a4add368f97672397dc93d223a1786
https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Primer.php#L336-L354
34,457
jon48/webtrees-lib
src/Webtrees/Mvc/View/ViewFactory.php
ViewFactory.makeView
public function makeView($view_name, MvcController $mvc_ctrl, BaseController $ctrl, ViewBag $data) { if(!$mvc_ctrl) throw new \Exception('Mvc Controller not defined'); if(!$ctrl) throw new \Exception('Base Controller not defined'); if(!$view_name) throw new \Exception('View not defined'); $mvc_ctrl_refl = new \ReflectionObject($mvc_ctrl); $view_class = $mvc_ctrl_refl->getNamespaceName() . '\\Views\\' . $view_name . 'View'; if(!class_exists($view_class)) throw new \Exception('View does not exist'); return new $view_class($ctrl, $data); }
php
public function makeView($view_name, MvcController $mvc_ctrl, BaseController $ctrl, ViewBag $data) { if(!$mvc_ctrl) throw new \Exception('Mvc Controller not defined'); if(!$ctrl) throw new \Exception('Base Controller not defined'); if(!$view_name) throw new \Exception('View not defined'); $mvc_ctrl_refl = new \ReflectionObject($mvc_ctrl); $view_class = $mvc_ctrl_refl->getNamespaceName() . '\\Views\\' . $view_name . 'View'; if(!class_exists($view_class)) throw new \Exception('View does not exist'); return new $view_class($ctrl, $data); }
[ "public", "function", "makeView", "(", "$", "view_name", ",", "MvcController", "$", "mvc_ctrl", ",", "BaseController", "$", "ctrl", ",", "ViewBag", "$", "data", ")", "{", "if", "(", "!", "$", "mvc_ctrl", ")", "throw", "new", "\\", "Exception", "(", "'Mvc Controller not defined'", ")", ";", "if", "(", "!", "$", "ctrl", ")", "throw", "new", "\\", "Exception", "(", "'Base Controller not defined'", ")", ";", "if", "(", "!", "$", "view_name", ")", "throw", "new", "\\", "Exception", "(", "'View not defined'", ")", ";", "$", "mvc_ctrl_refl", "=", "new", "\\", "ReflectionObject", "(", "$", "mvc_ctrl", ")", ";", "$", "view_class", "=", "$", "mvc_ctrl_refl", "->", "getNamespaceName", "(", ")", ".", "'\\\\Views\\\\'", ".", "$", "view_name", ".", "'View'", ";", "if", "(", "!", "class_exists", "(", "$", "view_class", ")", ")", "throw", "new", "\\", "Exception", "(", "'View does not exist'", ")", ";", "return", "new", "$", "view_class", "(", "$", "ctrl", ",", "$", "data", ")", ";", "}" ]
Return the view specified by the controller and view name, using data from the ViewBag @param string $view_name @param \MyArtJaub\Webtrees\Mvc\Controller\MvcControllerInterface $mvc_ctrl @param \Fisharebest\Webtrees\Controller\BaseController $ctrl @param \MyArtJaub\Webtrees\Mvc\View\ViewBag $data @return \MyArtJaub\Webtrees\Mvc\View\AbstractView View @throws \Exception
[ "Return", "the", "view", "specified", "by", "the", "controller", "and", "view", "name", "using", "data", "from", "the", "ViewBag" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Mvc/View/ViewFactory.php#L54-L65
34,458
jon48/webtrees-lib
src/Webtrees/Mvc/View/ViewFactory.php
ViewFactory.make
public static function make($view_name, MvcController $mvc_ctrl, BaseController $ctrl, ViewBag $data) { return self::getInstance()->makeView($view_name, $mvc_ctrl, $ctrl, $data); }
php
public static function make($view_name, MvcController $mvc_ctrl, BaseController $ctrl, ViewBag $data) { return self::getInstance()->makeView($view_name, $mvc_ctrl, $ctrl, $data); }
[ "public", "static", "function", "make", "(", "$", "view_name", ",", "MvcController", "$", "mvc_ctrl", ",", "BaseController", "$", "ctrl", ",", "ViewBag", "$", "data", ")", "{", "return", "self", "::", "getInstance", "(", ")", "->", "makeView", "(", "$", "view_name", ",", "$", "mvc_ctrl", ",", "$", "ctrl", ",", "$", "data", ")", ";", "}" ]
Static invocation of the makeView method @param string $view_name @param \MyArtJaub\Webtrees\Mvc\Controller\MvcControllerInterface $mvc_ctrl @param \Fisharebest\Webtrees\Controller\BaseController $ctrl @param \MyArtJaub\Webtrees\Mvc\View\ViewBag $data @return \MyArtJaub\Webtrees\Mvc\View\AbstractView View @see \MyArtJaub\Webtrees\Mvc\View\ViewFactory::handle()
[ "Static", "invocation", "of", "the", "makeView", "method" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Mvc/View/ViewFactory.php#L77-L80
34,459
alexislefebvre/AsyncTweetsBundle
src/Entity/Tweet.php
Tweet.addMedia
public function addMedia(Media $media) { $this->medias->add($media); $media->addTweet($this); return $this; }
php
public function addMedia(Media $media) { $this->medias->add($media); $media->addTweet($this); return $this; }
[ "public", "function", "addMedia", "(", "Media", "$", "media", ")", "{", "$", "this", "->", "medias", "->", "add", "(", "$", "media", ")", ";", "$", "media", "->", "addTweet", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}" ]
Add a media. @param Media $media @return Tweet
[ "Add", "a", "media", "." ]
76266fae7de978963e05dadb14c81f8398bb00a6
https://github.com/alexislefebvre/AsyncTweetsBundle/blob/76266fae7de978963e05dadb14c81f8398bb00a6/src/Entity/Tweet.php#L288-L294
34,460
alexislefebvre/AsyncTweetsBundle
src/Entity/Tweet.php
Tweet.removeMedia
public function removeMedia(Media $media) { $this->medias->removeElement($media); $media->removeTweet($this); return $this; }
php
public function removeMedia(Media $media) { $this->medias->removeElement($media); $media->removeTweet($this); return $this; }
[ "public", "function", "removeMedia", "(", "Media", "$", "media", ")", "{", "$", "this", "->", "medias", "->", "removeElement", "(", "$", "media", ")", ";", "$", "media", "->", "removeTweet", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}" ]
Remove a media. @param Media $media @return Tweet
[ "Remove", "a", "media", "." ]
76266fae7de978963e05dadb14c81f8398bb00a6
https://github.com/alexislefebvre/AsyncTweetsBundle/blob/76266fae7de978963e05dadb14c81f8398bb00a6/src/Entity/Tweet.php#L303-L309
34,461
alexislefebvre/AsyncTweetsBundle
src/Entity/Tweet.php
Tweet.mustBeKept
public function mustBeKept($tweetId) { if (count($this->getRetweetingStatuses()) == 0) { // This tweet has not been retweeted return false; } // Check that this tweet has not been retweeted after $tweetId foreach ($this->getRetweetingStatuses() as $retweeting_status) { // This tweet is retweeted in the timeline, keep it if ($retweeting_status->getId() >= $tweetId) { return true; } } return false; }
php
public function mustBeKept($tweetId) { if (count($this->getRetweetingStatuses()) == 0) { // This tweet has not been retweeted return false; } // Check that this tweet has not been retweeted after $tweetId foreach ($this->getRetweetingStatuses() as $retweeting_status) { // This tweet is retweeted in the timeline, keep it if ($retweeting_status->getId() >= $tweetId) { return true; } } return false; }
[ "public", "function", "mustBeKept", "(", "$", "tweetId", ")", "{", "if", "(", "count", "(", "$", "this", "->", "getRetweetingStatuses", "(", ")", ")", "==", "0", ")", "{", "// This tweet has not been retweeted", "return", "false", ";", "}", "// Check that this tweet has not been retweeted after $tweetId", "foreach", "(", "$", "this", "->", "getRetweetingStatuses", "(", ")", "as", "$", "retweeting_status", ")", "{", "// This tweet is retweeted in the timeline, keep it", "if", "(", "$", "retweeting_status", "->", "getId", "(", ")", ">=", "$", "tweetId", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check that tweet can be deleted. @param int $tweetId @return bool
[ "Check", "that", "tweet", "can", "be", "deleted", "." ]
76266fae7de978963e05dadb14c81f8398bb00a6
https://github.com/alexislefebvre/AsyncTweetsBundle/blob/76266fae7de978963e05dadb14c81f8398bb00a6/src/Entity/Tweet.php#L346-L362
34,462
GrupaZero/cms
src/Gzero/Cms/CMSSeeder.php
CMSSeeder.run
public function run() { config()->set('gzero-core.db_transactions', false); $languages = Language::all()->keyBy('code'); $users = $this->seedUsers(); $contents = $this->seedContent($languages, $users); $this->seedBlock(BlockType::all(), $languages, $users, $contents); //$fileTypes = $this->seedFileTypes(); //$files = $this->seedFiles($fileTypes, $languages, $users, $contents, $blocks); //$this->seedOptions($languages); }
php
public function run() { config()->set('gzero-core.db_transactions', false); $languages = Language::all()->keyBy('code'); $users = $this->seedUsers(); $contents = $this->seedContent($languages, $users); $this->seedBlock(BlockType::all(), $languages, $users, $contents); //$fileTypes = $this->seedFileTypes(); //$files = $this->seedFiles($fileTypes, $languages, $users, $contents, $blocks); //$this->seedOptions($languages); }
[ "public", "function", "run", "(", ")", "{", "config", "(", ")", "->", "set", "(", "'gzero-core.db_transactions'", ",", "false", ")", ";", "$", "languages", "=", "Language", "::", "all", "(", ")", "->", "keyBy", "(", "'code'", ")", ";", "$", "users", "=", "$", "this", "->", "seedUsers", "(", ")", ";", "$", "contents", "=", "$", "this", "->", "seedContent", "(", "$", "languages", ",", "$", "users", ")", ";", "$", "this", "->", "seedBlock", "(", "BlockType", "::", "all", "(", ")", ",", "$", "languages", ",", "$", "users", ",", "$", "contents", ")", ";", "//$fileTypes = $this->seedFileTypes();", "//$files = $this->seedFiles($fileTypes, $languages, $users, $contents, $blocks);", "//$this->seedOptions($languages);", "}" ]
This function run all seeds @return void
[ "This", "function", "run", "all", "seeds" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/CMSSeeder.php#L47-L57
34,463
GrupaZero/cms
src/Gzero/Cms/CMSSeeder.php
CMSSeeder.seedRandomContent
private function seedRandomContent(string $type, $parent, $languages, $users) { $user = $users->random(); $en = $languages['en']; $pl = $languages['pl']; $faker = Factory::create($en->i18n); $title = $faker->realText(38, 1); $content = dispatch_now(CreateContent::make($title, $en, $user, array_merge( [ 'type' => $type, 'parent_id' => array_get($parent, 'id', null), 'weight' => rand(0, 10), 'rating' => rand(0, 5), 'is_on_home' => (bool) rand(0, 1), 'is_comment_allowed' => (bool) rand(0, 1), 'is_promoted' => (bool) rand(0, 1), 'is_sticky' => (bool) rand(0, 1), 'is_active' => (bool) rand(0, 1), 'published_at' => Carbon::now() ], $this->generateContentTranslation($en) ))); $faker = Factory::create($pl->i18n); $title = $faker->realText(38, 1); dispatch_now(new AddContentTranslation($content, $title, $pl, $user, $this->generateContentTranslation($pl))); return $content; }
php
private function seedRandomContent(string $type, $parent, $languages, $users) { $user = $users->random(); $en = $languages['en']; $pl = $languages['pl']; $faker = Factory::create($en->i18n); $title = $faker->realText(38, 1); $content = dispatch_now(CreateContent::make($title, $en, $user, array_merge( [ 'type' => $type, 'parent_id' => array_get($parent, 'id', null), 'weight' => rand(0, 10), 'rating' => rand(0, 5), 'is_on_home' => (bool) rand(0, 1), 'is_comment_allowed' => (bool) rand(0, 1), 'is_promoted' => (bool) rand(0, 1), 'is_sticky' => (bool) rand(0, 1), 'is_active' => (bool) rand(0, 1), 'published_at' => Carbon::now() ], $this->generateContentTranslation($en) ))); $faker = Factory::create($pl->i18n); $title = $faker->realText(38, 1); dispatch_now(new AddContentTranslation($content, $title, $pl, $user, $this->generateContentTranslation($pl))); return $content; }
[ "private", "function", "seedRandomContent", "(", "string", "$", "type", ",", "$", "parent", ",", "$", "languages", ",", "$", "users", ")", "{", "$", "user", "=", "$", "users", "->", "random", "(", ")", ";", "$", "en", "=", "$", "languages", "[", "'en'", "]", ";", "$", "pl", "=", "$", "languages", "[", "'pl'", "]", ";", "$", "faker", "=", "Factory", "::", "create", "(", "$", "en", "->", "i18n", ")", ";", "$", "title", "=", "$", "faker", "->", "realText", "(", "38", ",", "1", ")", ";", "$", "content", "=", "dispatch_now", "(", "CreateContent", "::", "make", "(", "$", "title", ",", "$", "en", ",", "$", "user", ",", "array_merge", "(", "[", "'type'", "=>", "$", "type", ",", "'parent_id'", "=>", "array_get", "(", "$", "parent", ",", "'id'", ",", "null", ")", ",", "'weight'", "=>", "rand", "(", "0", ",", "10", ")", ",", "'rating'", "=>", "rand", "(", "0", ",", "5", ")", ",", "'is_on_home'", "=>", "(", "bool", ")", "rand", "(", "0", ",", "1", ")", ",", "'is_comment_allowed'", "=>", "(", "bool", ")", "rand", "(", "0", ",", "1", ")", ",", "'is_promoted'", "=>", "(", "bool", ")", "rand", "(", "0", ",", "1", ")", ",", "'is_sticky'", "=>", "(", "bool", ")", "rand", "(", "0", ",", "1", ")", ",", "'is_active'", "=>", "(", "bool", ")", "rand", "(", "0", ",", "1", ")", ",", "'published_at'", "=>", "Carbon", "::", "now", "(", ")", "]", ",", "$", "this", "->", "generateContentTranslation", "(", "$", "en", ")", ")", ")", ")", ";", "$", "faker", "=", "Factory", "::", "create", "(", "$", "pl", "->", "i18n", ")", ";", "$", "title", "=", "$", "faker", "->", "realText", "(", "38", ",", "1", ")", ";", "dispatch_now", "(", "new", "AddContentTranslation", "(", "$", "content", ",", "$", "title", ",", "$", "pl", ",", "$", "user", ",", "$", "this", "->", "generateContentTranslation", "(", "$", "pl", ")", ")", ")", ";", "return", "$", "content", ";", "}" ]
Seed single content @param string $type Content type @param Content|Null $parent Parent element @param array $languages Array with languages @param array $users Array with users @return bool
[ "Seed", "single", "content" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/CMSSeeder.php#L118-L147
34,464
GrupaZero/cms
src/Gzero/Cms/CMSSeeder.php
CMSSeeder.seedRandomBlock
private function seedRandomBlock(BlockType $type, $languages, $users, $contents) { $language = $languages->random(); $faker = Factory::create($language->i18n); $isActive = (bool) rand(0, 1); $isCacheable = (bool) rand(0, 1); $filter = (rand(0, 1)) ? [ '+' => [$this->getRandomBlockFilter($contents)], '-' => [$this->getRandomBlockFilter($contents)] ] : null; $input = [ 'type' => $type->name, 'region' => $this->getRandomBlockRegion(), 'weight' => rand(0, 12), 'filter' => $filter, 'options' => array_combine($this->faker->words(), $this->faker->words()), 'is_active' => $isActive, 'is_cacheable' => $isCacheable, 'translations' => $this->prepareBlockTranslation($languages['en']), 'body' => $faker->realText(300), 'custom_fields' => array_combine($this->faker->words(), $this->faker->words()), ]; $block = dispatch_now(CreateBlock::make($faker->realText(38, 1), $language, $users->random(), $input)); return $block; }
php
private function seedRandomBlock(BlockType $type, $languages, $users, $contents) { $language = $languages->random(); $faker = Factory::create($language->i18n); $isActive = (bool) rand(0, 1); $isCacheable = (bool) rand(0, 1); $filter = (rand(0, 1)) ? [ '+' => [$this->getRandomBlockFilter($contents)], '-' => [$this->getRandomBlockFilter($contents)] ] : null; $input = [ 'type' => $type->name, 'region' => $this->getRandomBlockRegion(), 'weight' => rand(0, 12), 'filter' => $filter, 'options' => array_combine($this->faker->words(), $this->faker->words()), 'is_active' => $isActive, 'is_cacheable' => $isCacheable, 'translations' => $this->prepareBlockTranslation($languages['en']), 'body' => $faker->realText(300), 'custom_fields' => array_combine($this->faker->words(), $this->faker->words()), ]; $block = dispatch_now(CreateBlock::make($faker->realText(38, 1), $language, $users->random(), $input)); return $block; }
[ "private", "function", "seedRandomBlock", "(", "BlockType", "$", "type", ",", "$", "languages", ",", "$", "users", ",", "$", "contents", ")", "{", "$", "language", "=", "$", "languages", "->", "random", "(", ")", ";", "$", "faker", "=", "Factory", "::", "create", "(", "$", "language", "->", "i18n", ")", ";", "$", "isActive", "=", "(", "bool", ")", "rand", "(", "0", ",", "1", ")", ";", "$", "isCacheable", "=", "(", "bool", ")", "rand", "(", "0", ",", "1", ")", ";", "$", "filter", "=", "(", "rand", "(", "0", ",", "1", ")", ")", "?", "[", "'+'", "=>", "[", "$", "this", "->", "getRandomBlockFilter", "(", "$", "contents", ")", "]", ",", "'-'", "=>", "[", "$", "this", "->", "getRandomBlockFilter", "(", "$", "contents", ")", "]", "]", ":", "null", ";", "$", "input", "=", "[", "'type'", "=>", "$", "type", "->", "name", ",", "'region'", "=>", "$", "this", "->", "getRandomBlockRegion", "(", ")", ",", "'weight'", "=>", "rand", "(", "0", ",", "12", ")", ",", "'filter'", "=>", "$", "filter", ",", "'options'", "=>", "array_combine", "(", "$", "this", "->", "faker", "->", "words", "(", ")", ",", "$", "this", "->", "faker", "->", "words", "(", ")", ")", ",", "'is_active'", "=>", "$", "isActive", ",", "'is_cacheable'", "=>", "$", "isCacheable", ",", "'translations'", "=>", "$", "this", "->", "prepareBlockTranslation", "(", "$", "languages", "[", "'en'", "]", ")", ",", "'body'", "=>", "$", "faker", "->", "realText", "(", "300", ")", ",", "'custom_fields'", "=>", "array_combine", "(", "$", "this", "->", "faker", "->", "words", "(", ")", ",", "$", "this", "->", "faker", "->", "words", "(", ")", ")", ",", "]", ";", "$", "block", "=", "dispatch_now", "(", "CreateBlock", "::", "make", "(", "$", "faker", "->", "realText", "(", "38", ",", "1", ")", ",", "$", "language", ",", "$", "users", "->", "random", "(", ")", ",", "$", "input", ")", ")", ";", "return", "$", "block", ";", "}" ]
Seed single block @param BlockType $type Block type @param array $languages Array with languages @param array $users Array with users @param array $contents Array with contents @return Block
[ "Seed", "single", "block" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/CMSSeeder.php#L246-L272
34,465
GrupaZero/cms
src/Gzero/Cms/CMSSeeder.php
CMSSeeder.generateBodyHTML
private function generateBodyHTML(Generator $faker) { $html = []; $imageCategories = [ 'abstract', 'animals', 'business', 'cats', 'city', 'food', 'nightlife', 'fashion', 'people', 'nature', 'sports', 'technics', 'transport' ]; $paragraphImageNumber = rand(0, 5); $headingNumber = rand(0, 5); $imageUrl = $faker->imageUrl(1140, 480, $imageCategories[array_rand($imageCategories)]); // random dumber of paragraphs for ($i = 0; $i < rand(5, 10); $i++) { $html[] = '<p>' . $faker->realText(rand(300, 1500)) . '</p>'; // insert heading if ($i == $headingNumber) { $html[] = '<h3>' . $faker->realText(100) . '</h3>'; } // insert image if ($i == $paragraphImageNumber) { $html[] = '<p><img src="' . $imageUrl . '" class="img-fluid"/></p>'; } } return implode('', $html); }
php
private function generateBodyHTML(Generator $faker) { $html = []; $imageCategories = [ 'abstract', 'animals', 'business', 'cats', 'city', 'food', 'nightlife', 'fashion', 'people', 'nature', 'sports', 'technics', 'transport' ]; $paragraphImageNumber = rand(0, 5); $headingNumber = rand(0, 5); $imageUrl = $faker->imageUrl(1140, 480, $imageCategories[array_rand($imageCategories)]); // random dumber of paragraphs for ($i = 0; $i < rand(5, 10); $i++) { $html[] = '<p>' . $faker->realText(rand(300, 1500)) . '</p>'; // insert heading if ($i == $headingNumber) { $html[] = '<h3>' . $faker->realText(100) . '</h3>'; } // insert image if ($i == $paragraphImageNumber) { $html[] = '<p><img src="' . $imageUrl . '" class="img-fluid"/></p>'; } } return implode('', $html); }
[ "private", "function", "generateBodyHTML", "(", "Generator", "$", "faker", ")", "{", "$", "html", "=", "[", "]", ";", "$", "imageCategories", "=", "[", "'abstract'", ",", "'animals'", ",", "'business'", ",", "'cats'", ",", "'city'", ",", "'food'", ",", "'nightlife'", ",", "'fashion'", ",", "'people'", ",", "'nature'", ",", "'sports'", ",", "'technics'", ",", "'transport'", "]", ";", "$", "paragraphImageNumber", "=", "rand", "(", "0", ",", "5", ")", ";", "$", "headingNumber", "=", "rand", "(", "0", ",", "5", ")", ";", "$", "imageUrl", "=", "$", "faker", "->", "imageUrl", "(", "1140", ",", "480", ",", "$", "imageCategories", "[", "array_rand", "(", "$", "imageCategories", ")", "]", ")", ";", "// random dumber of paragraphs", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "rand", "(", "5", ",", "10", ")", ";", "$", "i", "++", ")", "{", "$", "html", "[", "]", "=", "'<p>'", ".", "$", "faker", "->", "realText", "(", "rand", "(", "300", ",", "1500", ")", ")", ".", "'</p>'", ";", "// insert heading", "if", "(", "$", "i", "==", "$", "headingNumber", ")", "{", "$", "html", "[", "]", "=", "'<h3>'", ".", "$", "faker", "->", "realText", "(", "100", ")", ".", "'</h3>'", ";", "}", "// insert image", "if", "(", "$", "i", "==", "$", "paragraphImageNumber", ")", "{", "$", "html", "[", "]", "=", "'<p><img src=\"'", ".", "$", "imageUrl", ".", "'\" class=\"img-fluid\"/></p>'", ";", "}", "}", "return", "implode", "(", "''", ",", "$", "html", ")", ";", "}" ]
Function generates translation body HTML @param Generator $faker Faker factory @return string generated HTML
[ "Function", "generates", "translation", "body", "HTML" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/CMSSeeder.php#L417-L452
34,466
GrupaZero/cms
src/Gzero/Cms/CMSSeeder.php
CMSSeeder.getRandomBlockFilter
private function getRandomBlockFilter($contents) { return rand(0, 1) ? $contents[array_rand($contents)]->path . '*' : $contents[array_rand($contents)]->path; }
php
private function getRandomBlockFilter($contents) { return rand(0, 1) ? $contents[array_rand($contents)]->path . '*' : $contents[array_rand($contents)]->path; }
[ "private", "function", "getRandomBlockFilter", "(", "$", "contents", ")", "{", "return", "rand", "(", "0", ",", "1", ")", "?", "$", "contents", "[", "array_rand", "(", "$", "contents", ")", "]", "->", "path", ".", "'*'", ":", "$", "contents", "[", "array_rand", "(", "$", "contents", ")", "]", "->", "path", ";", "}" ]
Function generates block filter path @param array $contents Array with contents @return string
[ "Function", "generates", "block", "filter", "path" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/CMSSeeder.php#L461-L464
34,467
GrupaZero/cms
src/Gzero/Cms/Repositories/ContentReadRepository.php
ContentReadRepository.getByPath
public function getByPath(string $path, string $languageCode, bool $onlyActive = false) { return Content::query() ->with(self::$loadRelations) ->join('routes', function ($join) use ($languageCode, $path, $onlyActive) { $join->on('contents.id', '=', 'routes.routable_id') ->where('routes.routable_type', '=', Content::class) ->where('routes.language_code', $languageCode) ->where('routes.path', $path) ->when($onlyActive, function ($query) { $query->where('routes.is_active', true); }); }) ->first(['contents.*']); }
php
public function getByPath(string $path, string $languageCode, bool $onlyActive = false) { return Content::query() ->with(self::$loadRelations) ->join('routes', function ($join) use ($languageCode, $path, $onlyActive) { $join->on('contents.id', '=', 'routes.routable_id') ->where('routes.routable_type', '=', Content::class) ->where('routes.language_code', $languageCode) ->where('routes.path', $path) ->when($onlyActive, function ($query) { $query->where('routes.is_active', true); }); }) ->first(['contents.*']); }
[ "public", "function", "getByPath", "(", "string", "$", "path", ",", "string", "$", "languageCode", ",", "bool", "$", "onlyActive", "=", "false", ")", "{", "return", "Content", "::", "query", "(", ")", "->", "with", "(", "self", "::", "$", "loadRelations", ")", "->", "join", "(", "'routes'", ",", "function", "(", "$", "join", ")", "use", "(", "$", "languageCode", ",", "$", "path", ",", "$", "onlyActive", ")", "{", "$", "join", "->", "on", "(", "'contents.id'", ",", "'='", ",", "'routes.routable_id'", ")", "->", "where", "(", "'routes.routable_type'", ",", "'='", ",", "Content", "::", "class", ")", "->", "where", "(", "'routes.language_code'", ",", "$", "languageCode", ")", "->", "where", "(", "'routes.path'", ",", "$", "path", ")", "->", "when", "(", "$", "onlyActive", ",", "function", "(", "$", "query", ")", "{", "$", "query", "->", "where", "(", "'routes.is_active'", ",", "true", ")", ";", "}", ")", ";", "}", ")", "->", "first", "(", "[", "'contents.*'", "]", ")", ";", "}" ]
Retrieve a content by given path @param string $path URI path @param string $languageCode Language code @param bool $onlyActive Trigger @return Content|mixed
[ "Retrieve", "a", "content", "by", "given", "path" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Repositories/ContentReadRepository.php#L103-L117
34,468
GrupaZero/cms
src/Gzero/Cms/Repositories/ContentReadRepository.php
ContentReadRepository.getAncestorsTitlesAndPaths
public function getAncestorsTitlesAndPaths(Content $content, Language $language, $onlyActive = true) { $ancestorIds = array_filter(explode('/', $content->path)); return \DB::table('contents as c') ->join('routes as r', function ($join) use ($language, $onlyActive) { $join->on('c.id', '=', 'r.routable_id') ->where('r.routable_type', '=', Content::class) ->where('r.language_code', $language->code) ->when($onlyActive, function ($query) { $query->where('r.is_active', true); }); }) ->join('content_translations as ct', function ($join) use ($language, $onlyActive) { $join->on('c.id', '=', 'ct.content_id')->where('ct.language_code', $language->code) ->when($onlyActive, function ($query) { $query->where('ct.is_active', true); }); }) ->whereIn('c.id', $ancestorIds) ->orderBy('level', 'ASC') ->select(['ct.title', 'r.path']) ->get(); }
php
public function getAncestorsTitlesAndPaths(Content $content, Language $language, $onlyActive = true) { $ancestorIds = array_filter(explode('/', $content->path)); return \DB::table('contents as c') ->join('routes as r', function ($join) use ($language, $onlyActive) { $join->on('c.id', '=', 'r.routable_id') ->where('r.routable_type', '=', Content::class) ->where('r.language_code', $language->code) ->when($onlyActive, function ($query) { $query->where('r.is_active', true); }); }) ->join('content_translations as ct', function ($join) use ($language, $onlyActive) { $join->on('c.id', '=', 'ct.content_id')->where('ct.language_code', $language->code) ->when($onlyActive, function ($query) { $query->where('ct.is_active', true); }); }) ->whereIn('c.id', $ancestorIds) ->orderBy('level', 'ASC') ->select(['ct.title', 'r.path']) ->get(); }
[ "public", "function", "getAncestorsTitlesAndPaths", "(", "Content", "$", "content", ",", "Language", "$", "language", ",", "$", "onlyActive", "=", "true", ")", "{", "$", "ancestorIds", "=", "array_filter", "(", "explode", "(", "'/'", ",", "$", "content", "->", "path", ")", ")", ";", "return", "\\", "DB", "::", "table", "(", "'contents as c'", ")", "->", "join", "(", "'routes as r'", ",", "function", "(", "$", "join", ")", "use", "(", "$", "language", ",", "$", "onlyActive", ")", "{", "$", "join", "->", "on", "(", "'c.id'", ",", "'='", ",", "'r.routable_id'", ")", "->", "where", "(", "'r.routable_type'", ",", "'='", ",", "Content", "::", "class", ")", "->", "where", "(", "'r.language_code'", ",", "$", "language", "->", "code", ")", "->", "when", "(", "$", "onlyActive", ",", "function", "(", "$", "query", ")", "{", "$", "query", "->", "where", "(", "'r.is_active'", ",", "true", ")", ";", "}", ")", ";", "}", ")", "->", "join", "(", "'content_translations as ct'", ",", "function", "(", "$", "join", ")", "use", "(", "$", "language", ",", "$", "onlyActive", ")", "{", "$", "join", "->", "on", "(", "'c.id'", ",", "'='", ",", "'ct.content_id'", ")", "->", "where", "(", "'ct.language_code'", ",", "$", "language", "->", "code", ")", "->", "when", "(", "$", "onlyActive", ",", "function", "(", "$", "query", ")", "{", "$", "query", "->", "where", "(", "'ct.is_active'", ",", "true", ")", ";", "}", ")", ";", "}", ")", "->", "whereIn", "(", "'c.id'", ",", "$", "ancestorIds", ")", "->", "orderBy", "(", "'level'", ",", "'ASC'", ")", "->", "select", "(", "[", "'ct.title'", ",", "'r.path'", "]", ")", "->", "get", "(", ")", ";", "}" ]
Returns titles & url paths from ancestors @param Content $content Content @param Language $language Language @param bool $onlyActive isActive trigger @return \Illuminate\Support\Collection
[ "Returns", "titles", "&", "url", "paths", "from", "ancestors" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Repositories/ContentReadRepository.php#L128-L150
34,469
GrupaZero/cms
src/Gzero/Cms/Repositories/ContentReadRepository.php
ContentReadRepository.getChildren
public function getChildren(Content $content, Language $language) { return $content->children() ->with(self::$loadRelations) ->where('published_at', '<=', Carbon::now()) ->whereHas('routes', function ($query) use ($language) { $query->where('routes.is_active', true) ->where('language_code', $language->code); }) ->orderBy('is_promoted', 'DESC') ->orderBy('is_sticky', 'DESC') ->orderBy('weight', 'ASC') ->orderBy('published_at', 'DESC') ->paginate(option('general', 'default_page_size', 20)); }
php
public function getChildren(Content $content, Language $language) { return $content->children() ->with(self::$loadRelations) ->where('published_at', '<=', Carbon::now()) ->whereHas('routes', function ($query) use ($language) { $query->where('routes.is_active', true) ->where('language_code', $language->code); }) ->orderBy('is_promoted', 'DESC') ->orderBy('is_sticky', 'DESC') ->orderBy('weight', 'ASC') ->orderBy('published_at', 'DESC') ->paginate(option('general', 'default_page_size', 20)); }
[ "public", "function", "getChildren", "(", "Content", "$", "content", ",", "Language", "$", "language", ")", "{", "return", "$", "content", "->", "children", "(", ")", "->", "with", "(", "self", "::", "$", "loadRelations", ")", "->", "where", "(", "'published_at'", ",", "'<='", ",", "Carbon", "::", "now", "(", ")", ")", "->", "whereHas", "(", "'routes'", ",", "function", "(", "$", "query", ")", "use", "(", "$", "language", ")", "{", "$", "query", "->", "where", "(", "'routes.is_active'", ",", "true", ")", "->", "where", "(", "'language_code'", ",", "$", "language", "->", "code", ")", ";", "}", ")", "->", "orderBy", "(", "'is_promoted'", ",", "'DESC'", ")", "->", "orderBy", "(", "'is_sticky'", ",", "'DESC'", ")", "->", "orderBy", "(", "'weight'", ",", "'ASC'", ")", "->", "orderBy", "(", "'published_at'", ",", "'DESC'", ")", "->", "paginate", "(", "option", "(", "'general'", ",", "'default_page_size'", ",", "20", ")", ")", ";", "}" ]
Get all children specific content @param Content $content parent @param Language $language Current language @return mixed
[ "Get", "all", "children", "specific", "content" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Repositories/ContentReadRepository.php#L237-L251
34,470
jon48/webtrees-lib
src/Webtrees/Mvc/View/AbstractView.php
AbstractView.render
public function render() { global $controller; if(!$this->ctrl) throw new \Exception('Controller not initialised'); $controller = $this->ctrl; $this->ctrl->pageHeader(); echo $this->renderContent(); }
php
public function render() { global $controller; if(!$this->ctrl) throw new \Exception('Controller not initialised'); $controller = $this->ctrl; $this->ctrl->pageHeader(); echo $this->renderContent(); }
[ "public", "function", "render", "(", ")", "{", "global", "$", "controller", ";", "if", "(", "!", "$", "this", "->", "ctrl", ")", "throw", "new", "\\", "Exception", "(", "'Controller not initialised'", ")", ";", "$", "controller", "=", "$", "this", "->", "ctrl", ";", "$", "this", "->", "ctrl", "->", "pageHeader", "(", ")", ";", "echo", "$", "this", "->", "renderContent", "(", ")", ";", "}" ]
Render the view to the page, including header. @throws \Exception
[ "Render", "the", "view", "to", "the", "page", "including", "header", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Mvc/View/AbstractView.php#L45-L54
34,471
jon48/webtrees-lib
src/Webtrees/Mvc/View/AbstractView.php
AbstractView.getHtmlPartial
public function getHtmlPartial() { ob_start(); $html_render = $this->renderContent(); $html_buffer = ob_get_clean(); return empty($html_render) ? $html_buffer : $html_render; }
php
public function getHtmlPartial() { ob_start(); $html_render = $this->renderContent(); $html_buffer = ob_get_clean(); return empty($html_render) ? $html_buffer : $html_render; }
[ "public", "function", "getHtmlPartial", "(", ")", "{", "ob_start", "(", ")", ";", "$", "html_render", "=", "$", "this", "->", "renderContent", "(", ")", ";", "$", "html_buffer", "=", "ob_get_clean", "(", ")", ";", "return", "empty", "(", "$", "html_render", ")", "?", "$", "html_buffer", ":", "$", "html_render", ";", "}" ]
Return the HTML code generated by the view, without any header
[ "Return", "the", "HTML", "code", "generated", "by", "the", "view", "without", "any", "header" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Mvc/View/AbstractView.php#L66-L72
34,472
pckg/database
src/Pckg/Database/Repository/RepositoryFactory.php
RepositoryFactory.getRepositoryByConfig
protected static function getRepositoryByConfig($config, $name) { if (!is_array($config)) { if (class_exists($config)) { return new $config; } throw new Exception('Cannot create repository from string'); } elseif ($config['driver'] == 'faker') { return new Faker(Factory::create()); } elseif ($config['driver'] == 'middleware') { return resolve($config['middleware'])->execute(function() { } ); } return static::initPdoDatabase($config, $name); }
php
protected static function getRepositoryByConfig($config, $name) { if (!is_array($config)) { if (class_exists($config)) { return new $config; } throw new Exception('Cannot create repository from string'); } elseif ($config['driver'] == 'faker') { return new Faker(Factory::create()); } elseif ($config['driver'] == 'middleware') { return resolve($config['middleware'])->execute(function() { } ); } return static::initPdoDatabase($config, $name); }
[ "protected", "static", "function", "getRepositoryByConfig", "(", "$", "config", ",", "$", "name", ")", "{", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "if", "(", "class_exists", "(", "$", "config", ")", ")", "{", "return", "new", "$", "config", ";", "}", "throw", "new", "Exception", "(", "'Cannot create repository from string'", ")", ";", "}", "elseif", "(", "$", "config", "[", "'driver'", "]", "==", "'faker'", ")", "{", "return", "new", "Faker", "(", "Factory", "::", "create", "(", ")", ")", ";", "}", "elseif", "(", "$", "config", "[", "'driver'", "]", "==", "'middleware'", ")", "{", "return", "resolve", "(", "$", "config", "[", "'middleware'", "]", ")", "->", "execute", "(", "function", "(", ")", "{", "}", ")", ";", "}", "return", "static", "::", "initPdoDatabase", "(", "$", "config", ",", "$", "name", ")", ";", "}" ]
Instantiate connection for defined driver. @param $config @param $name @return Faker|RepositoryPDO @throws Exception
[ "Instantiate", "connection", "for", "defined", "driver", "." ]
99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3
https://github.com/pckg/database/blob/99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3/src/Pckg/Database/Repository/RepositoryFactory.php#L212-L229
34,473
voslartomas/WebCMS2
install/Form.php
Form.signalReceived
public function signalReceived($signal) { if ($signal === 'submit') { if (!$this->getPresenter()->getRequest()->hasFlag(Nette\Application\Request::RESTORED)) { $this->fireEvents(); } } else { $class = get_class($this); throw new BadSignalException("Missing handler for signal '$signal' in $class."); } }
php
public function signalReceived($signal) { if ($signal === 'submit') { if (!$this->getPresenter()->getRequest()->hasFlag(Nette\Application\Request::RESTORED)) { $this->fireEvents(); } } else { $class = get_class($this); throw new BadSignalException("Missing handler for signal '$signal' in $class."); } }
[ "public", "function", "signalReceived", "(", "$", "signal", ")", "{", "if", "(", "$", "signal", "===", "'submit'", ")", "{", "if", "(", "!", "$", "this", "->", "getPresenter", "(", ")", "->", "getRequest", "(", ")", "->", "hasFlag", "(", "Nette", "\\", "Application", "\\", "Request", "::", "RESTORED", ")", ")", "{", "$", "this", "->", "fireEvents", "(", ")", ";", "}", "}", "else", "{", "$", "class", "=", "get_class", "(", "$", "this", ")", ";", "throw", "new", "BadSignalException", "(", "\"Missing handler for signal '$signal' in $class.\"", ")", ";", "}", "}" ]
This method is called by presenter. @param string @return void
[ "This", "method", "is", "called", "by", "presenter", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/install/Form.php#L121-L131
34,474
c4studio/chronos
src/Chronos/Scaffolding/database/migrations/2016_10_17_300000_alter_users_table.php
AlterUsersTable.up
public function up() { Schema::table('users', function (Blueprint $table) { if (Schema::hasColumn('users', 'name')) $table->dropColumn('name'); $table->integer('role_id')->unsigned()->nullable(); $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); $table->string('firstname')->default(''); $table->string('lastname')->default(''); $table->string('picture')->nullable(); }); }
php
public function up() { Schema::table('users', function (Blueprint $table) { if (Schema::hasColumn('users', 'name')) $table->dropColumn('name'); $table->integer('role_id')->unsigned()->nullable(); $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); $table->string('firstname')->default(''); $table->string('lastname')->default(''); $table->string('picture')->nullable(); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "table", "(", "'users'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "if", "(", "Schema", "::", "hasColumn", "(", "'users'", ",", "'name'", ")", ")", "$", "table", "->", "dropColumn", "(", "'name'", ")", ";", "$", "table", "->", "integer", "(", "'role_id'", ")", "->", "unsigned", "(", ")", "->", "nullable", "(", ")", ";", "$", "table", "->", "foreign", "(", "'role_id'", ")", "->", "references", "(", "'id'", ")", "->", "on", "(", "'roles'", ")", "->", "onDelete", "(", "'cascade'", ")", ";", "$", "table", "->", "string", "(", "'firstname'", ")", "->", "default", "(", "''", ")", ";", "$", "table", "->", "string", "(", "'lastname'", ")", "->", "default", "(", "''", ")", ";", "$", "table", "->", "string", "(", "'picture'", ")", "->", "nullable", "(", ")", ";", "}", ")", ";", "}" ]
Run the database. @return void
[ "Run", "the", "database", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Scaffolding/database/migrations/2016_10_17_300000_alter_users_table.php#L14-L25
34,475
c4studio/chronos
src/Chronos/Scaffolding/database/migrations/2016_10_17_300000_alter_users_table.php
AlterUsersTable.down
public function down() { Schema::table('users', function ($table) { $table->string('name')->after('id'); $table->dropColumn('picture'); $table->dropColumn('lastname'); $table->dropColumn('firstname'); $table->dropForeign('users_role_id_foreign'); $table->dropColumn('role_id'); }); }
php
public function down() { Schema::table('users', function ($table) { $table->string('name')->after('id'); $table->dropColumn('picture'); $table->dropColumn('lastname'); $table->dropColumn('firstname'); $table->dropForeign('users_role_id_foreign'); $table->dropColumn('role_id'); }); }
[ "public", "function", "down", "(", ")", "{", "Schema", "::", "table", "(", "'users'", ",", "function", "(", "$", "table", ")", "{", "$", "table", "->", "string", "(", "'name'", ")", "->", "after", "(", "'id'", ")", ";", "$", "table", "->", "dropColumn", "(", "'picture'", ")", ";", "$", "table", "->", "dropColumn", "(", "'lastname'", ")", ";", "$", "table", "->", "dropColumn", "(", "'firstname'", ")", ";", "$", "table", "->", "dropForeign", "(", "'users_role_id_foreign'", ")", ";", "$", "table", "->", "dropColumn", "(", "'role_id'", ")", ";", "}", ")", ";", "}" ]
Reverse the database. @return void
[ "Reverse", "the", "database", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Scaffolding/database/migrations/2016_10_17_300000_alter_users_table.php#L32-L42
34,476
GrupaZero/cms
src/Gzero/Cms/Listeners/BlockLoad.php
BlockLoad.handle
public function handle($event) { if ($event instanceof RouteMatched) { $this->handleLaravelRoute($event); } if ($event instanceof GzeroRouteMatched) { $this->handleRoute($event); } }
php
public function handle($event) { if ($event instanceof RouteMatched) { $this->handleLaravelRoute($event); } if ($event instanceof GzeroRouteMatched) { $this->handleRoute($event); } }
[ "public", "function", "handle", "(", "$", "event", ")", "{", "if", "(", "$", "event", "instanceof", "RouteMatched", ")", "{", "$", "this", "->", "handleLaravelRoute", "(", "$", "event", ")", ";", "}", "if", "(", "$", "event", "instanceof", "GzeroRouteMatched", ")", "{", "$", "this", "->", "handleRoute", "(", "$", "event", ")", ";", "}", "}" ]
Handle the event. It loads block for matched routes. @param mixed $event Matched route or content @return void
[ "Handle", "the", "event", ".", "It", "loads", "block", "for", "matched", "routes", "." ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Listeners/BlockLoad.php#L49-L58
34,477
GrupaZero/cms
src/Gzero/Cms/Listeners/BlockLoad.php
BlockLoad.handleLaravelRoute
public function handleLaravelRoute(RouteMatched $event) { if ($this->isValidFrontendRoute($event)) { ViewComposer::addCallback(function () use ($event) { $blockIds = $this->blockFinder->getBlocksIds($event->route->getName(), true); $blocks = $this->blockRepository->getVisibleBlocks($blockIds, $this->languageService->getCurrent(), true); $this->handleBlockRendering($blocks); $blocks = $blocks->groupBy('region'); view()->share('blocks', $blocks); }); } }
php
public function handleLaravelRoute(RouteMatched $event) { if ($this->isValidFrontendRoute($event)) { ViewComposer::addCallback(function () use ($event) { $blockIds = $this->blockFinder->getBlocksIds($event->route->getName(), true); $blocks = $this->blockRepository->getVisibleBlocks($blockIds, $this->languageService->getCurrent(), true); $this->handleBlockRendering($blocks); $blocks = $blocks->groupBy('region'); view()->share('blocks', $blocks); }); } }
[ "public", "function", "handleLaravelRoute", "(", "RouteMatched", "$", "event", ")", "{", "if", "(", "$", "this", "->", "isValidFrontendRoute", "(", "$", "event", ")", ")", "{", "ViewComposer", "::", "addCallback", "(", "function", "(", ")", "use", "(", "$", "event", ")", "{", "$", "blockIds", "=", "$", "this", "->", "blockFinder", "->", "getBlocksIds", "(", "$", "event", "->", "route", "->", "getName", "(", ")", ",", "true", ")", ";", "$", "blocks", "=", "$", "this", "->", "blockRepository", "->", "getVisibleBlocks", "(", "$", "blockIds", ",", "$", "this", "->", "languageService", "->", "getCurrent", "(", ")", ",", "true", ")", ";", "$", "this", "->", "handleBlockRendering", "(", "$", "blocks", ")", ";", "$", "blocks", "=", "$", "blocks", "->", "groupBy", "(", "'region'", ")", ";", "view", "(", ")", "->", "share", "(", "'blocks'", ",", "$", "blocks", ")", ";", "}", ")", ";", "}", "}" ]
Handle the event. It loads block for static named routes. @param RouteMatched $event dispatched event @return void
[ "Handle", "the", "event", ".", "It", "loads", "block", "for", "static", "named", "routes", "." ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Listeners/BlockLoad.php#L67-L78
34,478
GrupaZero/cms
src/Gzero/Cms/Listeners/BlockLoad.php
BlockLoad.handleRoute
public function handleRoute(GzeroRouteMatched $event) { $blockIds = $this->blockFinder->getBlocksIds($event->route->getRoutable(), true); $blocks = $this->blockRepository->getVisibleBlocks($blockIds, $this->languageService->getCurrent(), true); $this->handleBlockRendering($blocks); $blocks = $blocks->groupBy('region'); view()->share('blocks', $blocks); }
php
public function handleRoute(GzeroRouteMatched $event) { $blockIds = $this->blockFinder->getBlocksIds($event->route->getRoutable(), true); $blocks = $this->blockRepository->getVisibleBlocks($blockIds, $this->languageService->getCurrent(), true); $this->handleBlockRendering($blocks); $blocks = $blocks->groupBy('region'); view()->share('blocks', $blocks); }
[ "public", "function", "handleRoute", "(", "GzeroRouteMatched", "$", "event", ")", "{", "$", "blockIds", "=", "$", "this", "->", "blockFinder", "->", "getBlocksIds", "(", "$", "event", "->", "route", "->", "getRoutable", "(", ")", ",", "true", ")", ";", "$", "blocks", "=", "$", "this", "->", "blockRepository", "->", "getVisibleBlocks", "(", "$", "blockIds", ",", "$", "this", "->", "languageService", "->", "getCurrent", "(", ")", ",", "true", ")", ";", "$", "this", "->", "handleBlockRendering", "(", "$", "blocks", ")", ";", "$", "blocks", "=", "$", "blocks", "->", "groupBy", "(", "'region'", ")", ";", "view", "(", ")", "->", "share", "(", "'blocks'", ",", "$", "blocks", ")", ";", "}" ]
Handle the event. It loads block for dynamic router. @param GzeroRouteMatched $event dispatched event @return void
[ "Handle", "the", "event", ".", "It", "loads", "block", "for", "dynamic", "router", "." ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Listeners/BlockLoad.php#L87-L94
34,479
GrupaZero/cms
src/Gzero/Cms/Listeners/BlockLoad.php
BlockLoad.handleBlockRendering
protected function handleBlockRendering($blocks) { foreach ($blocks as &$block) { $type = resolve($block->type->handler); $block->view = $type->handle($block, $this->languageService->getCurrent()); } }
php
protected function handleBlockRendering($blocks) { foreach ($blocks as &$block) { $type = resolve($block->type->handler); $block->view = $type->handle($block, $this->languageService->getCurrent()); } }
[ "protected", "function", "handleBlockRendering", "(", "$", "blocks", ")", "{", "foreach", "(", "$", "blocks", "as", "&", "$", "block", ")", "{", "$", "type", "=", "resolve", "(", "$", "block", "->", "type", "->", "handler", ")", ";", "$", "block", "->", "view", "=", "$", "type", "->", "handle", "(", "$", "block", ",", "$", "this", "->", "languageService", "->", "getCurrent", "(", ")", ")", ";", "}", "}" ]
It renders blocks @param Collection $blocks List of blocks to render @return void
[ "It", "renders", "blocks" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Listeners/BlockLoad.php#L103-L109
34,480
pckg/database
src/Pckg/Database/Query/Helper/With.php
With.fillRecordWithRelations
public function fillRecordWithRelations(Record $record) { foreach ($this->getWith() as $relation) { $relation->fillRecord($record); } return $record; }
php
public function fillRecordWithRelations(Record $record) { foreach ($this->getWith() as $relation) { $relation->fillRecord($record); } return $record; }
[ "public", "function", "fillRecordWithRelations", "(", "Record", "$", "record", ")", "{", "foreach", "(", "$", "this", "->", "getWith", "(", ")", "as", "$", "relation", ")", "{", "$", "relation", "->", "fillRecord", "(", "$", "record", ")", ";", "}", "return", "$", "record", ";", "}" ]
Fill record with all it's relations. @param Record $record @return Record
[ "Fill", "record", "with", "all", "it", "s", "relations", "." ]
99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3
https://github.com/pckg/database/blob/99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3/src/Pckg/Database/Query/Helper/With.php#L155-L162
34,481
pckg/database
src/Pckg/Database/Query/Helper/With.php
With.fillCollectionWithRelations
public function fillCollectionWithRelations(CollectionInterface $collection) { if (!$collection->count()) { return $collection; } foreach ($this->getWith() as $relation) { $relation->fillCollection($collection); } return $collection; }
php
public function fillCollectionWithRelations(CollectionInterface $collection) { if (!$collection->count()) { return $collection; } foreach ($this->getWith() as $relation) { $relation->fillCollection($collection); } return $collection; }
[ "public", "function", "fillCollectionWithRelations", "(", "CollectionInterface", "$", "collection", ")", "{", "if", "(", "!", "$", "collection", "->", "count", "(", ")", ")", "{", "return", "$", "collection", ";", "}", "foreach", "(", "$", "this", "->", "getWith", "(", ")", "as", "$", "relation", ")", "{", "$", "relation", "->", "fillCollection", "(", "$", "collection", ")", ";", "}", "return", "$", "collection", ";", "}" ]
Fill collection of records with all of their relations. @param CollectionInterface $collection @return CollectionInterface
[ "Fill", "collection", "of", "records", "with", "all", "of", "their", "relations", "." ]
99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3
https://github.com/pckg/database/blob/99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3/src/Pckg/Database/Query/Helper/With.php#L179-L190
34,482
jon48/webtrees-lib
src/Webtrees/Module/GeoDispersion/AdminConfigController.php
AdminConfigController.renderEdit
protected function renderEdit(GeoAnalysis $ga = null) { $wt_tree = Globals::getTree(); Theme::theme(new AdministrationTheme)->init($wt_tree); $controller = new PageController(); $controller ->restrictAccess(Auth::isManager($wt_tree)) ->addInlineJavascript(' function toggleMapOptions() { if($("input:radio[name=\'use_map\']:checked").val() == 1) { $("#map_options").show(); } else { $("#map_options").hide(); } } $("[name=\'use_map\']").on("change", toggleMapOptions); toggleMapOptions(); '); $data = new ViewBag(); if($ga) { $controller->setPageTitle(I18N::translate('Edit the geographical dispersion analysis')); $data->set('geo_analysis', $ga); } else { $controller->setPageTitle(I18N::translate('Add a geographical dispersion analysis')); } $data->set('title', $controller->getPageTitle()); $data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $wt_tree->getNameUrl()); $data->set('module_title', $this->module->getTitle()); $data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@save&ged=' . $wt_tree->getNameUrl()); $data->set('places_hierarchy', $this->provider->getPlacesHierarchy()); $map_list = array_map( function(OutlineMap $map) { return $map->getDescription(); }, $this->provider->getOutlineMapsList() ); asort($map_list); $data->set('map_list', $map_list); $gen_details = array(0 => I18N::translate('All')); for($i = 1; $i <= 10 ; $i++) $gen_details[$i] = $i; $data->set('generation_details', $gen_details); ViewFactory::make('GeoAnalysisEdit', $this, $controller, $data)->render(); }
php
protected function renderEdit(GeoAnalysis $ga = null) { $wt_tree = Globals::getTree(); Theme::theme(new AdministrationTheme)->init($wt_tree); $controller = new PageController(); $controller ->restrictAccess(Auth::isManager($wt_tree)) ->addInlineJavascript(' function toggleMapOptions() { if($("input:radio[name=\'use_map\']:checked").val() == 1) { $("#map_options").show(); } else { $("#map_options").hide(); } } $("[name=\'use_map\']").on("change", toggleMapOptions); toggleMapOptions(); '); $data = new ViewBag(); if($ga) { $controller->setPageTitle(I18N::translate('Edit the geographical dispersion analysis')); $data->set('geo_analysis', $ga); } else { $controller->setPageTitle(I18N::translate('Add a geographical dispersion analysis')); } $data->set('title', $controller->getPageTitle()); $data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $wt_tree->getNameUrl()); $data->set('module_title', $this->module->getTitle()); $data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@save&ged=' . $wt_tree->getNameUrl()); $data->set('places_hierarchy', $this->provider->getPlacesHierarchy()); $map_list = array_map( function(OutlineMap $map) { return $map->getDescription(); }, $this->provider->getOutlineMapsList() ); asort($map_list); $data->set('map_list', $map_list); $gen_details = array(0 => I18N::translate('All')); for($i = 1; $i <= 10 ; $i++) $gen_details[$i] = $i; $data->set('generation_details', $gen_details); ViewFactory::make('GeoAnalysisEdit', $this, $controller, $data)->render(); }
[ "protected", "function", "renderEdit", "(", "GeoAnalysis", "$", "ga", "=", "null", ")", "{", "$", "wt_tree", "=", "Globals", "::", "getTree", "(", ")", ";", "Theme", "::", "theme", "(", "new", "AdministrationTheme", ")", "->", "init", "(", "$", "wt_tree", ")", ";", "$", "controller", "=", "new", "PageController", "(", ")", ";", "$", "controller", "->", "restrictAccess", "(", "Auth", "::", "isManager", "(", "$", "wt_tree", ")", ")", "->", "addInlineJavascript", "(", "'\n function toggleMapOptions() {\n if($(\"input:radio[name=\\'use_map\\']:checked\").val() == 1) {\n $(\"#map_options\").show();\n }\n else {\n $(\"#map_options\").hide();\n }\n }\n \n $(\"[name=\\'use_map\\']\").on(\"change\", toggleMapOptions);\n toggleMapOptions();\n '", ")", ";", "$", "data", "=", "new", "ViewBag", "(", ")", ";", "if", "(", "$", "ga", ")", "{", "$", "controller", "->", "setPageTitle", "(", "I18N", "::", "translate", "(", "'Edit the geographical dispersion analysis'", ")", ")", ";", "$", "data", "->", "set", "(", "'geo_analysis'", ",", "$", "ga", ")", ";", "}", "else", "{", "$", "controller", "->", "setPageTitle", "(", "I18N", "::", "translate", "(", "'Add a geographical dispersion analysis'", ")", ")", ";", "}", "$", "data", "->", "set", "(", "'title'", ",", "$", "controller", "->", "getPageTitle", "(", ")", ")", ";", "$", "data", "->", "set", "(", "'admin_config_url'", ",", "'module.php?mod='", ".", "$", "this", "->", "module", "->", "getName", "(", ")", ".", "'&mod_action=AdminConfig&ged='", ".", "$", "wt_tree", "->", "getNameUrl", "(", ")", ")", ";", "$", "data", "->", "set", "(", "'module_title'", ",", "$", "this", "->", "module", "->", "getTitle", "(", ")", ")", ";", "$", "data", "->", "set", "(", "'save_url'", ",", "'module.php?mod='", ".", "$", "this", "->", "module", "->", "getName", "(", ")", ".", "'&mod_action=AdminConfig@save&ged='", ".", "$", "wt_tree", "->", "getNameUrl", "(", ")", ")", ";", "$", "data", "->", "set", "(", "'places_hierarchy'", ",", "$", "this", "->", "provider", "->", "getPlacesHierarchy", "(", ")", ")", ";", "$", "map_list", "=", "array_map", "(", "function", "(", "OutlineMap", "$", "map", ")", "{", "return", "$", "map", "->", "getDescription", "(", ")", ";", "}", ",", "$", "this", "->", "provider", "->", "getOutlineMapsList", "(", ")", ")", ";", "asort", "(", "$", "map_list", ")", ";", "$", "data", "->", "set", "(", "'map_list'", ",", "$", "map_list", ")", ";", "$", "gen_details", "=", "array", "(", "0", "=>", "I18N", "::", "translate", "(", "'All'", ")", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "10", ";", "$", "i", "++", ")", "$", "gen_details", "[", "$", "i", "]", "=", "$", "i", ";", "$", "data", "->", "set", "(", "'generation_details'", ",", "$", "gen_details", ")", ";", "ViewFactory", "::", "make", "(", "'GeoAnalysisEdit'", ",", "$", "this", ",", "$", "controller", ",", "$", "data", ")", "->", "render", "(", ")", ";", "}" ]
Renders the edit form, whether it is an edition of an existing GeoAnalysis, or the addition of a new one. @param (GeoAnalysis!null) $ga GeoAnalysis to edit
[ "Renders", "the", "edit", "form", "whether", "it", "is", "an", "edition", "of", "an", "existing", "GeoAnalysis", "or", "the", "addition", "of", "a", "new", "one", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/GeoDispersion/AdminConfigController.php#L394-L442
34,483
GrupaZero/cms
src/Gzero/Cms/Jobs/CreateBlock.php
CreateBlock.slider
public static function slider(string $title, Language $language, User $author, array $attributes = []) { return new self($title, $language, $author, array_merge($attributes, ['type' => 'slider'])); }
php
public static function slider(string $title, Language $language, User $author, array $attributes = []) { return new self($title, $language, $author, array_merge($attributes, ['type' => 'slider'])); }
[ "public", "static", "function", "slider", "(", "string", "$", "title", ",", "Language", "$", "language", ",", "User", "$", "author", ",", "array", "$", "attributes", "=", "[", "]", ")", "{", "return", "new", "self", "(", "$", "title", ",", "$", "language", ",", "$", "author", ",", "array_merge", "(", "$", "attributes", ",", "[", "'type'", "=>", "'slider'", "]", ")", ")", ";", "}" ]
It creates job to create block @param string $title Translation title @param Language $language Language @param User $author User model @param array $attributes Array of optional attributes @return CreateBlock
[ "It", "creates", "job", "to", "create", "block" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Jobs/CreateBlock.php#L113-L116
34,484
jon48/webtrees-lib
src/Webtrees/Hook/Hook.php
Hook.subscribe
public function subscribe($hsubscriber){ if(HookProvider::getInstance()->isModuleOperational()){ Database::prepare( "INSERT IGNORE INTO `##maj_hooks` (majh_hook_function, majh_hook_context, majh_module_name)". " VALUES (?, ?, ?)" )->execute(array($this->hook_function, $this->hook_context, $hsubscriber)); } }
php
public function subscribe($hsubscriber){ if(HookProvider::getInstance()->isModuleOperational()){ Database::prepare( "INSERT IGNORE INTO `##maj_hooks` (majh_hook_function, majh_hook_context, majh_module_name)". " VALUES (?, ?, ?)" )->execute(array($this->hook_function, $this->hook_context, $hsubscriber)); } }
[ "public", "function", "subscribe", "(", "$", "hsubscriber", ")", "{", "if", "(", "HookProvider", "::", "getInstance", "(", ")", "->", "isModuleOperational", "(", ")", ")", "{", "Database", "::", "prepare", "(", "\"INSERT IGNORE INTO `##maj_hooks` (majh_hook_function, majh_hook_context, majh_module_name)\"", ".", "\" VALUES (?, ?, ?)\"", ")", "->", "execute", "(", "array", "(", "$", "this", "->", "hook_function", ",", "$", "this", "->", "hook_context", ",", "$", "hsubscriber", ")", ")", ";", "}", "}" ]
Subscribe a class implementing HookSubscriberInterface to the Hook The Hook is by default enabled. @param string $hsubscriber Name of the subscriber module
[ "Subscribe", "a", "class", "implementing", "HookSubscriberInterface", "to", "the", "Hook", "The", "Hook", "is", "by", "default", "enabled", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Hook/Hook.php#L50-L57
34,485
jon48/webtrees-lib
src/Webtrees/Hook/Hook.php
Hook.setPriority
public function setPriority($hsubscriber, $priority){ if(HookProvider::getInstance()->isModuleOperational()){ Database::prepare( "UPDATE `##maj_hooks`". " SET majh_module_priority=?". " WHERE majh_hook_function=?". " AND majh_hook_context=?". " AND majh_module_name=?" )->execute(array($priority, $this->hook_function, $this->hook_context, $hsubscriber)); } }
php
public function setPriority($hsubscriber, $priority){ if(HookProvider::getInstance()->isModuleOperational()){ Database::prepare( "UPDATE `##maj_hooks`". " SET majh_module_priority=?". " WHERE majh_hook_function=?". " AND majh_hook_context=?". " AND majh_module_name=?" )->execute(array($priority, $this->hook_function, $this->hook_context, $hsubscriber)); } }
[ "public", "function", "setPriority", "(", "$", "hsubscriber", ",", "$", "priority", ")", "{", "if", "(", "HookProvider", "::", "getInstance", "(", ")", "->", "isModuleOperational", "(", ")", ")", "{", "Database", "::", "prepare", "(", "\"UPDATE `##maj_hooks`\"", ".", "\" SET majh_module_priority=?\"", ".", "\" WHERE majh_hook_function=?\"", ".", "\" AND majh_hook_context=?\"", ".", "\" AND majh_module_name=?\"", ")", "->", "execute", "(", "array", "(", "$", "priority", ",", "$", "this", "->", "hook_function", ",", "$", "this", "->", "hook_context", ",", "$", "hsubscriber", ")", ")", ";", "}", "}" ]
Define the priority for execution of the Hook for the specific HookSubscriberInterface @param string $hsubscriber Name of the subscriber module @param int $priority Priority of execution
[ "Define", "the", "priority", "for", "execution", "of", "the", "Hook", "for", "the", "specific", "HookSubscriberInterface" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Hook/Hook.php#L65-L75
34,486
jon48/webtrees-lib
src/Webtrees/Hook/Hook.php
Hook.executeOnlyFor
public function executeOnlyFor(array $module_names) { $result = array(); if(HookProvider::getInstance()->isModuleOperational()){ $params = func_get_args(); array_shift($params); foreach ($module_names as $module_name) { if($module = Module::getModuleByName($module_name)) { $result[] = call_user_func_array(array($module, $this->hook_function), $params); } } } return $result; }
php
public function executeOnlyFor(array $module_names) { $result = array(); if(HookProvider::getInstance()->isModuleOperational()){ $params = func_get_args(); array_shift($params); foreach ($module_names as $module_name) { if($module = Module::getModuleByName($module_name)) { $result[] = call_user_func_array(array($module, $this->hook_function), $params); } } } return $result; }
[ "public", "function", "executeOnlyFor", "(", "array", "$", "module_names", ")", "{", "$", "result", "=", "array", "(", ")", ";", "if", "(", "HookProvider", "::", "getInstance", "(", ")", "->", "isModuleOperational", "(", ")", ")", "{", "$", "params", "=", "func_get_args", "(", ")", ";", "array_shift", "(", "$", "params", ")", ";", "foreach", "(", "$", "module_names", "as", "$", "module_name", ")", "{", "if", "(", "$", "module", "=", "Module", "::", "getModuleByName", "(", "$", "module_name", ")", ")", "{", "$", "result", "[", "]", "=", "call_user_func_array", "(", "array", "(", "$", "module", ",", "$", "this", "->", "hook_function", ")", ",", "$", "params", ")", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Return the resuls of the execution of the hook function for a defined list of modules, only for those enabled. @param string[] $module_names List of Modules to execute @return array Results of the hook executions
[ "Return", "the", "resuls", "of", "the", "execution", "of", "the", "hook", "function", "for", "a", "defined", "list", "of", "modules", "only", "for", "those", "enabled", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Hook/Hook.php#L139-L151
34,487
jon48/webtrees-lib
src/Webtrees/Hook/Hook.php
Hook.execute
public function execute(){ $result = array(); if(HookProvider::getInstance()->isModuleOperational()){ $params = func_get_args(); $sqlquery = ''; $sqlparams = array($this->hook_function); if($this->hook_context != 'all') { $sqlparams = array($this->hook_function, $this->hook_context); $sqlquery = " OR majh_hook_context=?"; } $module_names=Database::prepare( "SELECT majh_module_name AS module, majh_module_priority AS priority FROM `##maj_hooks`". " WHERE majh_hook_function = ? AND (majh_hook_context='all'".$sqlquery.") AND majh_status='enabled'". " ORDER BY majh_module_priority ASC, module ASC" )->execute($sqlparams)->fetchAssoc(); asort($module_names); array_unshift($params, array_keys($module_names)); $result = call_user_func_array(array(&$this, 'executeOnlyFor'), $params); } return $result; }
php
public function execute(){ $result = array(); if(HookProvider::getInstance()->isModuleOperational()){ $params = func_get_args(); $sqlquery = ''; $sqlparams = array($this->hook_function); if($this->hook_context != 'all') { $sqlparams = array($this->hook_function, $this->hook_context); $sqlquery = " OR majh_hook_context=?"; } $module_names=Database::prepare( "SELECT majh_module_name AS module, majh_module_priority AS priority FROM `##maj_hooks`". " WHERE majh_hook_function = ? AND (majh_hook_context='all'".$sqlquery.") AND majh_status='enabled'". " ORDER BY majh_module_priority ASC, module ASC" )->execute($sqlparams)->fetchAssoc(); asort($module_names); array_unshift($params, array_keys($module_names)); $result = call_user_func_array(array(&$this, 'executeOnlyFor'), $params); } return $result; }
[ "public", "function", "execute", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "if", "(", "HookProvider", "::", "getInstance", "(", ")", "->", "isModuleOperational", "(", ")", ")", "{", "$", "params", "=", "func_get_args", "(", ")", ";", "$", "sqlquery", "=", "''", ";", "$", "sqlparams", "=", "array", "(", "$", "this", "->", "hook_function", ")", ";", "if", "(", "$", "this", "->", "hook_context", "!=", "'all'", ")", "{", "$", "sqlparams", "=", "array", "(", "$", "this", "->", "hook_function", ",", "$", "this", "->", "hook_context", ")", ";", "$", "sqlquery", "=", "\" OR majh_hook_context=?\"", ";", "}", "$", "module_names", "=", "Database", "::", "prepare", "(", "\"SELECT majh_module_name AS module, majh_module_priority AS priority FROM `##maj_hooks`\"", ".", "\" WHERE majh_hook_function = ? AND (majh_hook_context='all'\"", ".", "$", "sqlquery", ".", "\") AND majh_status='enabled'\"", ".", "\" ORDER BY majh_module_priority ASC, module ASC\"", ")", "->", "execute", "(", "$", "sqlparams", ")", "->", "fetchAssoc", "(", ")", ";", "asort", "(", "$", "module_names", ")", ";", "array_unshift", "(", "$", "params", ",", "array_keys", "(", "$", "module_names", ")", ")", ";", "$", "result", "=", "call_user_func_array", "(", "array", "(", "&", "$", "this", ",", "'executeOnlyFor'", ")", ",", "$", "params", ")", ";", "}", "return", "$", "result", ";", "}" ]
Return the results of the execution of the hook function for all subscribed and enabled modules, in the order defined by their priority. Parameters can be passed if the hook requires them. @return array Results of the hook executions
[ "Return", "the", "results", "of", "the", "execution", "of", "the", "hook", "function", "for", "all", "subscribed", "and", "enabled", "modules", "in", "the", "order", "defined", "by", "their", "priority", ".", "Parameters", "can", "be", "passed", "if", "the", "hook", "requires", "them", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Hook/Hook.php#L159-L179
34,488
jon48/webtrees-lib
src/Webtrees/Hook/Hook.php
Hook.getNumberActiveModules
public function getNumberActiveModules(){ if(HookProvider::getInstance()->isModuleOperational()){ $sqlquery = ''; $sqlparams = array($this->hook_function); if($this->hook_context != 'all') { $sqlparams = array($this->hook_function, $this->hook_context); $sqlquery = " OR majh_hook_context=?"; } $module_names=Database::prepare( "SELECT majh_module_name AS modules FROM `##maj_hooks`". " WHERE majh_hook_function = ? AND (majh_hook_context='all'".$sqlquery.") AND majh_status='enabled'" )->execute($sqlparams)->fetchOneColumn(); return count($module_names); } return 0; }
php
public function getNumberActiveModules(){ if(HookProvider::getInstance()->isModuleOperational()){ $sqlquery = ''; $sqlparams = array($this->hook_function); if($this->hook_context != 'all') { $sqlparams = array($this->hook_function, $this->hook_context); $sqlquery = " OR majh_hook_context=?"; } $module_names=Database::prepare( "SELECT majh_module_name AS modules FROM `##maj_hooks`". " WHERE majh_hook_function = ? AND (majh_hook_context='all'".$sqlquery.") AND majh_status='enabled'" )->execute($sqlparams)->fetchOneColumn(); return count($module_names); } return 0; }
[ "public", "function", "getNumberActiveModules", "(", ")", "{", "if", "(", "HookProvider", "::", "getInstance", "(", ")", "->", "isModuleOperational", "(", ")", ")", "{", "$", "sqlquery", "=", "''", ";", "$", "sqlparams", "=", "array", "(", "$", "this", "->", "hook_function", ")", ";", "if", "(", "$", "this", "->", "hook_context", "!=", "'all'", ")", "{", "$", "sqlparams", "=", "array", "(", "$", "this", "->", "hook_function", ",", "$", "this", "->", "hook_context", ")", ";", "$", "sqlquery", "=", "\" OR majh_hook_context=?\"", ";", "}", "$", "module_names", "=", "Database", "::", "prepare", "(", "\"SELECT majh_module_name AS modules FROM `##maj_hooks`\"", ".", "\" WHERE majh_hook_function = ? AND (majh_hook_context='all'\"", ".", "$", "sqlquery", ".", "\") AND majh_status='enabled'\"", ")", "->", "execute", "(", "$", "sqlparams", ")", "->", "fetchOneColumn", "(", ")", ";", "return", "count", "(", "$", "module_names", ")", ";", "}", "return", "0", ";", "}" ]
Returns the number of active modules linked to a hook @return int Number of active modules
[ "Returns", "the", "number", "of", "active", "modules", "linked", "to", "a", "hook" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Hook/Hook.php#L186-L201
34,489
jon48/webtrees-lib
src/Webtrees/Module/CertificatesModule.php
CertificatesModule.getProvider
public function getProvider() { if(!$this->provider) { $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); $this->provider = new CertificateFileProvider($root_path, Globals::getTree()); } return $this->provider; }
php
public function getProvider() { if(!$this->provider) { $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); $this->provider = new CertificateFileProvider($root_path, Globals::getTree()); } return $this->provider; }
[ "public", "function", "getProvider", "(", ")", "{", "if", "(", "!", "$", "this", "->", "provider", ")", "{", "$", "root_path", "=", "$", "this", "->", "getSetting", "(", "'MAJ_CERT_ROOTDIR'", ",", "'certificates/'", ")", ";", "$", "this", "->", "provider", "=", "new", "CertificateFileProvider", "(", "$", "root_path", ",", "Globals", "::", "getTree", "(", ")", ")", ";", "}", "return", "$", "this", "->", "provider", ";", "}" ]
Returns the default Certificate File Provider, as configured in the module @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface
[ "Returns", "the", "default", "Certificate", "File", "Provider", "as", "configured", "in", "the", "module" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/CertificatesModule.php#L241-L247
34,490
jon48/webtrees-lib
src/Webtrees/Module/CertificatesModule.php
CertificatesModule.getDisplay_ACT
protected function getDisplay_ACT(Certificate $certificate, $sid = null){ $html = ''; if($certificate){ $certificate->setSource($sid); $html = $certificate->displayImage('icon'); } return $html; }
php
protected function getDisplay_ACT(Certificate $certificate, $sid = null){ $html = ''; if($certificate){ $certificate->setSource($sid); $html = $certificate->displayImage('icon'); } return $html; }
[ "protected", "function", "getDisplay_ACT", "(", "Certificate", "$", "certificate", ",", "$", "sid", "=", "null", ")", "{", "$", "html", "=", "''", ";", "if", "(", "$", "certificate", ")", "{", "$", "certificate", "->", "setSource", "(", "$", "sid", ")", ";", "$", "html", "=", "$", "certificate", "->", "displayImage", "(", "'icon'", ")", ";", "}", "return", "$", "html", ";", "}" ]
Return the HTML code for custom simple tag _ACT @param Certificate $certificatePath Certificate (as per the GEDCOM) @param string|null $sid Linked Source ID, if it exists
[ "Return", "the", "HTML", "code", "for", "custom", "simple", "tag", "_ACT" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/CertificatesModule.php#L256-L263
34,491
g4code/log
src/Debug.php
Debug.handlerShutdown
public static function handlerShutdown() { $error = error_get_last(); if($error !== NULL) { self::handlerError($error['type'], '[SHUTDOWN] ' . $error['message'], $error['file'], $error['line']); } }
php
public static function handlerShutdown() { $error = error_get_last(); if($error !== NULL) { self::handlerError($error['type'], '[SHUTDOWN] ' . $error['message'], $error['file'], $error['line']); } }
[ "public", "static", "function", "handlerShutdown", "(", ")", "{", "$", "error", "=", "error_get_last", "(", ")", ";", "if", "(", "$", "error", "!==", "NULL", ")", "{", "self", "::", "handlerError", "(", "$", "error", "[", "'type'", "]", ",", "'[SHUTDOWN] '", ".", "$", "error", "[", "'message'", "]", ",", "$", "error", "[", "'file'", "]", ",", "$", "error", "[", "'line'", "]", ")", ";", "}", "}" ]
Error handler for fatal errors @return void
[ "Error", "handler", "for", "fatal", "errors" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Debug.php#L171-L177
34,492
g4code/log
src/Debug.php
Debug._writeLog
private static function _writeLog($filename, $msg, $addTime = true) { // preppend details if($addTime) { $msg = self::formatHeaderWithTime() . $msg; } if(DI::has('BufferOptions')) { $options = DI::get('BufferConnectionOptions'); $callback = function($data) use ($filename) { Writer::writeLogVerbose($filename, implode("\n\n", $data) . "\n\n"); }; // just to be on safe side, set max size to 500, that is reasonable number $maxSize = 500; $size = isset($options['size']) && is_int($options['size']) && $options['size'] > 0 && $options['size'] < $maxSize ? $options['size'] : $maxSize; $buffer = new Buffer($filename, Buffer::ADAPTER_REDIS, $size, $callback, $options); $buffer->add($msg); } else { Writer::writeLogVerbose($filename, $msg); } }
php
private static function _writeLog($filename, $msg, $addTime = true) { // preppend details if($addTime) { $msg = self::formatHeaderWithTime() . $msg; } if(DI::has('BufferOptions')) { $options = DI::get('BufferConnectionOptions'); $callback = function($data) use ($filename) { Writer::writeLogVerbose($filename, implode("\n\n", $data) . "\n\n"); }; // just to be on safe side, set max size to 500, that is reasonable number $maxSize = 500; $size = isset($options['size']) && is_int($options['size']) && $options['size'] > 0 && $options['size'] < $maxSize ? $options['size'] : $maxSize; $buffer = new Buffer($filename, Buffer::ADAPTER_REDIS, $size, $callback, $options); $buffer->add($msg); } else { Writer::writeLogVerbose($filename, $msg); } }
[ "private", "static", "function", "_writeLog", "(", "$", "filename", ",", "$", "msg", ",", "$", "addTime", "=", "true", ")", "{", "// preppend details", "if", "(", "$", "addTime", ")", "{", "$", "msg", "=", "self", "::", "formatHeaderWithTime", "(", ")", ".", "$", "msg", ";", "}", "if", "(", "DI", "::", "has", "(", "'BufferOptions'", ")", ")", "{", "$", "options", "=", "DI", "::", "get", "(", "'BufferConnectionOptions'", ")", ";", "$", "callback", "=", "function", "(", "$", "data", ")", "use", "(", "$", "filename", ")", "{", "Writer", "::", "writeLogVerbose", "(", "$", "filename", ",", "implode", "(", "\"\\n\\n\"", ",", "$", "data", ")", ".", "\"\\n\\n\"", ")", ";", "}", ";", "// just to be on safe side, set max size to 500, that is reasonable number", "$", "maxSize", "=", "500", ";", "$", "size", "=", "isset", "(", "$", "options", "[", "'size'", "]", ")", "&&", "is_int", "(", "$", "options", "[", "'size'", "]", ")", "&&", "$", "options", "[", "'size'", "]", ">", "0", "&&", "$", "options", "[", "'size'", "]", "<", "$", "maxSize", "?", "$", "options", "[", "'size'", "]", ":", "$", "maxSize", ";", "$", "buffer", "=", "new", "Buffer", "(", "$", "filename", ",", "Buffer", "::", "ADAPTER_REDIS", ",", "$", "size", ",", "$", "callback", ",", "$", "options", ")", ";", "$", "buffer", "->", "add", "(", "$", "msg", ")", ";", "}", "else", "{", "Writer", "::", "writeLogVerbose", "(", "$", "filename", ",", "$", "msg", ")", ";", "}", "}" ]
Write log with buffer support @param string $filename @param string $msg @return void
[ "Write", "log", "with", "buffer", "support" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Debug.php#L185-L213
34,493
g4code/log
src/Debug.php
Debug._parseException
private static function _parseException(\Exception $e, $plain_text = false) { $exMsg = $e->getMessage(); $exCode = $e->getCode(); $exLine = $e->getLine(); $exFile = basename($e->getFile()); $exTrace = $e->getTrace(); $trace = ''; foreach ($exTrace as $key => $row) { $trace .= '<span class="traceLine">#' . ($key++) . ' '; if (!empty($row['function'])) { $trace .= "<b>"; if (!empty($row['class'])) { $trace .= $row['class'] . $row['type']; } $trace .= "{$row['function']}</b>()"; } if (!empty($row['file'])) { $trace .= " | LINE: <b>{$row['line']}</b> | FILE: <u>" . basename($row['file']) . '</u>'; } $trace .= "</span>\n"; } $msg = "<em style='font-size:larger;'>{$exMsg}</em> (code: {$exCode})<br />\nLINE: <b>{$exLine}</b>\nFILE: <u>{$exFile}</u>"; $parsed = sprintf("<pre>\n<p style='%s'>\n<strong>EXCEPTION:</strong><br />%s\n%s\n</p>\n</pre>\n\n", self::getFormattedCss(), $msg, $trace); return $plain_text ? str_replace(array("\t"), '', strip_tags($parsed)) : $parsed; }
php
private static function _parseException(\Exception $e, $plain_text = false) { $exMsg = $e->getMessage(); $exCode = $e->getCode(); $exLine = $e->getLine(); $exFile = basename($e->getFile()); $exTrace = $e->getTrace(); $trace = ''; foreach ($exTrace as $key => $row) { $trace .= '<span class="traceLine">#' . ($key++) . ' '; if (!empty($row['function'])) { $trace .= "<b>"; if (!empty($row['class'])) { $trace .= $row['class'] . $row['type']; } $trace .= "{$row['function']}</b>()"; } if (!empty($row['file'])) { $trace .= " | LINE: <b>{$row['line']}</b> | FILE: <u>" . basename($row['file']) . '</u>'; } $trace .= "</span>\n"; } $msg = "<em style='font-size:larger;'>{$exMsg}</em> (code: {$exCode})<br />\nLINE: <b>{$exLine}</b>\nFILE: <u>{$exFile}</u>"; $parsed = sprintf("<pre>\n<p style='%s'>\n<strong>EXCEPTION:</strong><br />%s\n%s\n</p>\n</pre>\n\n", self::getFormattedCss(), $msg, $trace); return $plain_text ? str_replace(array("\t"), '', strip_tags($parsed)) : $parsed; }
[ "private", "static", "function", "_parseException", "(", "\\", "Exception", "$", "e", ",", "$", "plain_text", "=", "false", ")", "{", "$", "exMsg", "=", "$", "e", "->", "getMessage", "(", ")", ";", "$", "exCode", "=", "$", "e", "->", "getCode", "(", ")", ";", "$", "exLine", "=", "$", "e", "->", "getLine", "(", ")", ";", "$", "exFile", "=", "basename", "(", "$", "e", "->", "getFile", "(", ")", ")", ";", "$", "exTrace", "=", "$", "e", "->", "getTrace", "(", ")", ";", "$", "trace", "=", "''", ";", "foreach", "(", "$", "exTrace", "as", "$", "key", "=>", "$", "row", ")", "{", "$", "trace", ".=", "'<span class=\"traceLine\">#'", ".", "(", "$", "key", "++", ")", ".", "' '", ";", "if", "(", "!", "empty", "(", "$", "row", "[", "'function'", "]", ")", ")", "{", "$", "trace", ".=", "\"<b>\"", ";", "if", "(", "!", "empty", "(", "$", "row", "[", "'class'", "]", ")", ")", "{", "$", "trace", ".=", "$", "row", "[", "'class'", "]", ".", "$", "row", "[", "'type'", "]", ";", "}", "$", "trace", ".=", "\"{$row['function']}</b>()\"", ";", "}", "if", "(", "!", "empty", "(", "$", "row", "[", "'file'", "]", ")", ")", "{", "$", "trace", ".=", "\" | LINE: <b>{$row['line']}</b> | FILE: <u>\"", ".", "basename", "(", "$", "row", "[", "'file'", "]", ")", ".", "'</u>'", ";", "}", "$", "trace", ".=", "\"</span>\\n\"", ";", "}", "$", "msg", "=", "\"<em style='font-size:larger;'>{$exMsg}</em> (code: {$exCode})<br />\\nLINE: <b>{$exLine}</b>\\nFILE: <u>{$exFile}</u>\"", ";", "$", "parsed", "=", "sprintf", "(", "\"<pre>\\n<p style='%s'>\\n<strong>EXCEPTION:</strong><br />%s\\n%s\\n</p>\\n</pre>\\n\\n\"", ",", "self", "::", "getFormattedCss", "(", ")", ",", "$", "msg", ",", "$", "trace", ")", ";", "return", "$", "plain_text", "?", "str_replace", "(", "array", "(", "\"\\t\"", ")", ",", "''", ",", "strip_tags", "(", "$", "parsed", ")", ")", ":", "$", "parsed", ";", "}" ]
Parses exceptions into human readable format + html styling @param Exception $e Exception object that's being parsed @param bool $plain_text flag to return formated exception, or plain text @todo: finish plain text implemntation @return string
[ "Parses", "exceptions", "into", "human", "readable", "format", "+", "html", "styling" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Debug.php#L225-L258
34,494
g4code/log
src/Debug.php
Debug.formatRequestData
public static function formatRequestData($asString = true) { $fromServer = array( 'REQUEST_URI', 'REQUEST_METHOD', 'HTTP_REFERER', 'QUERY_STRING', 'HTTP_USER_AGENT', 'REMOTE_ADDR', ); if($asString) { $s = "\n\n"; $s .= isset($_REQUEST)? "REQUEST: " . print_r($_REQUEST, true) . PHP_EOL : ''; foreach ($fromServer as $item) { $s .= isset($_SERVER[$item]) ? "{$item}: {$_SERVER[$item]}\n" : ''; } } else { $s = array( 'REQUEST' => $_REQUEST, 'SERVER' => $_SERVER, ); } return $s; }
php
public static function formatRequestData($asString = true) { $fromServer = array( 'REQUEST_URI', 'REQUEST_METHOD', 'HTTP_REFERER', 'QUERY_STRING', 'HTTP_USER_AGENT', 'REMOTE_ADDR', ); if($asString) { $s = "\n\n"; $s .= isset($_REQUEST)? "REQUEST: " . print_r($_REQUEST, true) . PHP_EOL : ''; foreach ($fromServer as $item) { $s .= isset($_SERVER[$item]) ? "{$item}: {$_SERVER[$item]}\n" : ''; } } else { $s = array( 'REQUEST' => $_REQUEST, 'SERVER' => $_SERVER, ); } return $s; }
[ "public", "static", "function", "formatRequestData", "(", "$", "asString", "=", "true", ")", "{", "$", "fromServer", "=", "array", "(", "'REQUEST_URI'", ",", "'REQUEST_METHOD'", ",", "'HTTP_REFERER'", ",", "'QUERY_STRING'", ",", "'HTTP_USER_AGENT'", ",", "'REMOTE_ADDR'", ",", ")", ";", "if", "(", "$", "asString", ")", "{", "$", "s", "=", "\"\\n\\n\"", ";", "$", "s", ".=", "isset", "(", "$", "_REQUEST", ")", "?", "\"REQUEST: \"", ".", "print_r", "(", "$", "_REQUEST", ",", "true", ")", ".", "PHP_EOL", ":", "''", ";", "foreach", "(", "$", "fromServer", "as", "$", "item", ")", "{", "$", "s", ".=", "isset", "(", "$", "_SERVER", "[", "$", "item", "]", ")", "?", "\"{$item}: {$_SERVER[$item]}\\n\"", ":", "''", ";", "}", "}", "else", "{", "$", "s", "=", "array", "(", "'REQUEST'", "=>", "$", "_REQUEST", ",", "'SERVER'", "=>", "$", "_SERVER", ",", ")", ";", "}", "return", "$", "s", ";", "}" ]
Returns all request data formated into string @return string
[ "Returns", "all", "request", "data", "formated", "into", "string" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Debug.php#L264-L289
34,495
g4code/log
src/Debug.php
Debug._skipFormating
private static function _skipFormating() { return false; if(null !== self::$_isAjaxOrCli) { return self::$_isAjaxOrCli; } self::$_isAjaxOrCli = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') || (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])); return self::$_isAjaxOrCli; }
php
private static function _skipFormating() { return false; if(null !== self::$_isAjaxOrCli) { return self::$_isAjaxOrCli; } self::$_isAjaxOrCli = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') || (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])); return self::$_isAjaxOrCli; }
[ "private", "static", "function", "_skipFormating", "(", ")", "{", "return", "false", ";", "if", "(", "null", "!==", "self", "::", "$", "_isAjaxOrCli", ")", "{", "return", "self", "::", "$", "_isAjaxOrCli", ";", "}", "self", "::", "$", "_isAjaxOrCli", "=", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_X_REQUESTED_WITH'", "]", ")", "&&", "$", "_SERVER", "[", "'HTTP_X_REQUESTED_WITH'", "]", "==", "'XMLHttpRequest'", ")", "||", "(", "php_sapi_name", "(", ")", "==", "'cli'", "&&", "empty", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ")", ")", ";", "return", "self", "::", "$", "_isAjaxOrCli", ";", "}" ]
Check if request is ajax or cli and skip formating @return bool
[ "Check", "if", "request", "is", "ajax", "or", "cli", "and", "skip", "formating" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Debug.php#L306-L319
34,496
jon48/webtrees-lib
src/Webtrees/Module/Sosa/Model/SosaProvider.php
SosaProvider.getRootIndi
public function getRootIndi() { $root_indi_id = $this->getRootIndiId(); if(!empty($root_indi_id)) { return Individual::getInstance($root_indi_id, $this->tree); } return null; }
php
public function getRootIndi() { $root_indi_id = $this->getRootIndiId(); if(!empty($root_indi_id)) { return Individual::getInstance($root_indi_id, $this->tree); } return null; }
[ "public", "function", "getRootIndi", "(", ")", "{", "$", "root_indi_id", "=", "$", "this", "->", "getRootIndiId", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "root_indi_id", ")", ")", "{", "return", "Individual", "::", "getInstance", "(", "$", "root_indi_id", ",", "$", "this", "->", "tree", ")", ";", "}", "return", "null", ";", "}" ]
Return the root individual for the reference tree and user. @return Individual Individual
[ "Return", "the", "root", "individual", "for", "the", "reference", "tree", "and", "user", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L128-L134
34,497
jon48/webtrees-lib
src/Webtrees/Module/Sosa/Model/SosaProvider.php
SosaProvider.deleteAll
public function deleteAll() { if(!$this->is_setup) return; Database::prepare( 'DELETE FROM `##maj_sosa`'. ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') ->execute(array( 'tree_id' => $this->tree->getTreeId(), 'user_id' => $this->user->getUserId() )); }
php
public function deleteAll() { if(!$this->is_setup) return; Database::prepare( 'DELETE FROM `##maj_sosa`'. ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') ->execute(array( 'tree_id' => $this->tree->getTreeId(), 'user_id' => $this->user->getUserId() )); }
[ "public", "function", "deleteAll", "(", ")", "{", "if", "(", "!", "$", "this", "->", "is_setup", ")", "return", ";", "Database", "::", "prepare", "(", "'DELETE FROM `##maj_sosa`'", ".", "' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id '", ")", "->", "execute", "(", "array", "(", "'tree_id'", "=>", "$", "this", "->", "tree", "->", "getTreeId", "(", ")", ",", "'user_id'", "=>", "$", "this", "->", "user", "->", "getUserId", "(", ")", ")", ")", ";", "}" ]
Remove all Sosa entries related to the gedcom file and user
[ "Remove", "all", "Sosa", "entries", "related", "to", "the", "gedcom", "file", "and", "user" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L143-L152
34,498
jon48/webtrees-lib
src/Webtrees/Module/Sosa/Model/SosaProvider.php
SosaProvider.deleteAncestors
public function deleteAncestors($sosa) { if(!$this->is_setup) return; $gen = Functions::getGeneration($sosa); Database::prepare( 'DELETE FROM `##maj_sosa`'. ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . ' AND majs_gen >= :gen' . ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' )->execute(array( 'tree_id' => $this->tree->getTreeId(), 'user_id' => $this->user->getUserId(), 'gen' => $gen, 'sosa' => $sosa )); }
php
public function deleteAncestors($sosa) { if(!$this->is_setup) return; $gen = Functions::getGeneration($sosa); Database::prepare( 'DELETE FROM `##maj_sosa`'. ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . ' AND majs_gen >= :gen' . ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' )->execute(array( 'tree_id' => $this->tree->getTreeId(), 'user_id' => $this->user->getUserId(), 'gen' => $gen, 'sosa' => $sosa )); }
[ "public", "function", "deleteAncestors", "(", "$", "sosa", ")", "{", "if", "(", "!", "$", "this", "->", "is_setup", ")", "return", ";", "$", "gen", "=", "Functions", "::", "getGeneration", "(", "$", "sosa", ")", ";", "Database", "::", "prepare", "(", "'DELETE FROM `##maj_sosa`'", ".", "' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id'", ".", "' AND majs_gen >= :gen'", ".", "' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa'", ")", "->", "execute", "(", "array", "(", "'tree_id'", "=>", "$", "this", "->", "tree", "->", "getTreeId", "(", ")", ",", "'user_id'", "=>", "$", "this", "->", "user", "->", "getUserId", "(", ")", ",", "'gen'", "=>", "$", "gen", ",", "'sosa'", "=>", "$", "sosa", ")", ")", ";", "}" ]
Remove all ancestors of a sosa number @param int $sosa
[ "Remove", "all", "ancestors", "of", "a", "sosa", "number" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L159-L173
34,499
jon48/webtrees-lib
src/Webtrees/Module/Sosa/Model/SosaProvider.php
SosaProvider.getAllSosaWithGenerations
public function getAllSosaWithGenerations(){ if(!$this->is_setup) return array(); return Database::prepare( 'SELECT majs_i_id AS indi,' . ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . ' FROM `##maj_sosa`' . ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . ' GROUP BY majs_i_id' )->execute(array( 'tree_id' => $this->tree->getTreeId(), 'user_id' => $this->user->getUserId() ))->fetchAssoc(); }
php
public function getAllSosaWithGenerations(){ if(!$this->is_setup) return array(); return Database::prepare( 'SELECT majs_i_id AS indi,' . ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . ' FROM `##maj_sosa`' . ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . ' GROUP BY majs_i_id' )->execute(array( 'tree_id' => $this->tree->getTreeId(), 'user_id' => $this->user->getUserId() ))->fetchAssoc(); }
[ "public", "function", "getAllSosaWithGenerations", "(", ")", "{", "if", "(", "!", "$", "this", "->", "is_setup", ")", "return", "array", "(", ")", ";", "return", "Database", "::", "prepare", "(", "'SELECT majs_i_id AS indi,'", ".", "' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR \",\") AS generations'", ".", "' FROM `##maj_sosa`'", ".", "' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'", ".", "' GROUP BY majs_i_id'", ")", "->", "execute", "(", "array", "(", "'tree_id'", "=>", "$", "this", "->", "tree", "->", "getTreeId", "(", ")", ",", "'user_id'", "=>", "$", "this", "->", "user", "->", "getUserId", "(", ")", ")", ")", "->", "fetchAssoc", "(", ")", ";", "}" ]
Return the list of all sosas, with the generations it belongs to @return array Associative array of Sosa ancestors, with their generation, comma separated
[ "Return", "the", "list", "of", "all", "sosas", "with", "the", "generations", "it", "belongs", "to" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L263-L275