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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
LapaLabs/YoutubeHelper
Resource/YoutubeResource.php
YoutubeResource.buildEmbedHtml
public function buildEmbedHtml(array $attributes = [], array $parameters = []) { // <iframe width="560" height="315" src="https://www.youtube.com/embed/5qanlirrRWs" frameborder="0" allowfullscreen></iframe> $attributes = array_merge($this->attributes, $attributes, [ 'src' => $this->buildEmbedUrl($parameters), // required attribute ]); $attributeStrings = ['']; foreach ($attributes as $name => $value) { $attributeString = (string)$name; if (null !== $value) { $attributeString .= '="'.htmlspecialchars($value).'"'; } $attributeStrings[] = $attributeString; } return '<iframe'.implode(' ', $attributeStrings).'></iframe>'; }
php
public function buildEmbedHtml(array $attributes = [], array $parameters = []) { // <iframe width="560" height="315" src="https://www.youtube.com/embed/5qanlirrRWs" frameborder="0" allowfullscreen></iframe> $attributes = array_merge($this->attributes, $attributes, [ 'src' => $this->buildEmbedUrl($parameters), // required attribute ]); $attributeStrings = ['']; foreach ($attributes as $name => $value) { $attributeString = (string)$name; if (null !== $value) { $attributeString .= '="'.htmlspecialchars($value).'"'; } $attributeStrings[] = $attributeString; } return '<iframe'.implode(' ', $attributeStrings).'></iframe>'; }
[ "public", "function", "buildEmbedHtml", "(", "array", "$", "attributes", "=", "[", "]", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "// <iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/5qanlirrRWs\" frameborder=\"0\" allowfullscreen></iframe>", "$", "attributes", "=", "array_merge", "(", "$", "this", "->", "attributes", ",", "$", "attributes", ",", "[", "'src'", "=>", "$", "this", "->", "buildEmbedUrl", "(", "$", "parameters", ")", ",", "// required attribute", "]", ")", ";", "$", "attributeStrings", "=", "[", "''", "]", ";", "foreach", "(", "$", "attributes", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "attributeString", "=", "(", "string", ")", "$", "name", ";", "if", "(", "null", "!==", "$", "value", ")", "{", "$", "attributeString", ".=", "'=\"'", ".", "htmlspecialchars", "(", "$", "value", ")", ".", "'\"'", ";", "}", "$", "attributeStrings", "[", "]", "=", "$", "attributeString", ";", "}", "return", "'<iframe'", ".", "implode", "(", "' '", ",", "$", "attributeStrings", ")", ".", "'></iframe>'", ";", "}" ]
Build the valid HTML code to embed this resource @param array $attributes @param array $parameters @return string
[ "Build", "the", "valid", "HTML", "code", "to", "embed", "this", "resource" ]
b94fd4700881494d24f14fb39ed8093215d0b25b
https://github.com/LapaLabs/YoutubeHelper/blob/b94fd4700881494d24f14fb39ed8093215d0b25b/Resource/YoutubeResource.php#L230-L247
train
cityware/city-format
src/Text.php
Text.slugify
public static function slugify($title, $length = 200) { $title = strip_tags($title); // Preserve escaped octets. $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); // Remove percent signs that are not part of an octet. $title = str_replace('%', '', $title); // Restore octets. $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); $title = self::removeAccents($title); if (self::seemsUtf8($title)) { if (function_exists('mb_strtolower')) { $title = mb_strtolower($title, 'UTF-8'); } $title = self::utf8UriEncode($title, $length); } $title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', '-', $title); $title = preg_replace('|-+|', '-', $title); $title = trim($title, '-'); return $title; }
php
public static function slugify($title, $length = 200) { $title = strip_tags($title); // Preserve escaped octets. $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); // Remove percent signs that are not part of an octet. $title = str_replace('%', '', $title); // Restore octets. $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); $title = self::removeAccents($title); if (self::seemsUtf8($title)) { if (function_exists('mb_strtolower')) { $title = mb_strtolower($title, 'UTF-8'); } $title = self::utf8UriEncode($title, $length); } $title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', '-', $title); $title = preg_replace('|-+|', '-', $title); $title = trim($title, '-'); return $title; }
[ "public", "static", "function", "slugify", "(", "$", "title", ",", "$", "length", "=", "200", ")", "{", "$", "title", "=", "strip_tags", "(", "$", "title", ")", ";", "// Preserve escaped octets.", "$", "title", "=", "preg_replace", "(", "'|%([a-fA-F0-9][a-fA-F0-9])|'", ",", "'---$1---'", ",", "$", "title", ")", ";", "// Remove percent signs that are not part of an octet.", "$", "title", "=", "str_replace", "(", "'%'", ",", "''", ",", "$", "title", ")", ";", "// Restore octets.", "$", "title", "=", "preg_replace", "(", "'|---([a-fA-F0-9][a-fA-F0-9])---|'", ",", "'%$1'", ",", "$", "title", ")", ";", "$", "title", "=", "self", "::", "removeAccents", "(", "$", "title", ")", ";", "if", "(", "self", "::", "seemsUtf8", "(", "$", "title", ")", ")", "{", "if", "(", "function_exists", "(", "'mb_strtolower'", ")", ")", "{", "$", "title", "=", "mb_strtolower", "(", "$", "title", ",", "'UTF-8'", ")", ";", "}", "$", "title", "=", "self", "::", "utf8UriEncode", "(", "$", "title", ",", "$", "length", ")", ";", "}", "$", "title", "=", "strtolower", "(", "$", "title", ")", ";", "$", "title", "=", "preg_replace", "(", "'/&.+?;/'", ",", "''", ",", "$", "title", ")", ";", "// kill entities", "$", "title", "=", "preg_replace", "(", "'/[^%a-z0-9 _-]/'", ",", "''", ",", "$", "title", ")", ";", "$", "title", "=", "preg_replace", "(", "'/\\s+/'", ",", "'-'", ",", "$", "title", ")", ";", "$", "title", "=", "preg_replace", "(", "'|-+|'", ",", "'-'", ",", "$", "title", ")", ";", "$", "title", "=", "trim", "(", "$", "title", ",", "'-'", ")", ";", "return", "$", "title", ";", "}" ]
Sanitizes title, replacing whitespace with dashes. Limits the output to alphanumeric characters, underscore (_) and dash (-). Whitespace becomes a dash. @param string $title The title to be sanitized. @return string The sanitized title.
[ "Sanitizes", "title", "replacing", "whitespace", "with", "dashes", "." ]
1e292670639a950ecf561b545462427512950c74
https://github.com/cityware/city-format/blob/1e292670639a950ecf561b545462427512950c74/src/Text.php#L234-L257
train
headzoo/web-tools
src/Headzoo/Web/Tools/WebServer.php
WebServer.sendResponseHeadersToClient
protected function sendResponseHeadersToClient(WebRequest $request, $code, $message) { $headers = [ "Date" => gmdate("D, d M Y H:i:s T"), "Connection" => "close" ]; $bytes = $this->sendToClient($request->getVersion() . " {$code} {$message}\r\n"); foreach($headers as $header => $value) { $bytes += $this->sendToClient("{$header}: {$value}\r\n"); } $bytes += $this->sendToClient("\r\n"); return $bytes; }
php
protected function sendResponseHeadersToClient(WebRequest $request, $code, $message) { $headers = [ "Date" => gmdate("D, d M Y H:i:s T"), "Connection" => "close" ]; $bytes = $this->sendToClient($request->getVersion() . " {$code} {$message}\r\n"); foreach($headers as $header => $value) { $bytes += $this->sendToClient("{$header}: {$value}\r\n"); } $bytes += $this->sendToClient("\r\n"); return $bytes; }
[ "protected", "function", "sendResponseHeadersToClient", "(", "WebRequest", "$", "request", ",", "$", "code", ",", "$", "message", ")", "{", "$", "headers", "=", "[", "\"Date\"", "=>", "gmdate", "(", "\"D, d M Y H:i:s T\"", ")", ",", "\"Connection\"", "=>", "\"close\"", "]", ";", "$", "bytes", "=", "$", "this", "->", "sendToClient", "(", "$", "request", "->", "getVersion", "(", ")", ".", "\" {$code} {$message}\\r\\n\"", ")", ";", "foreach", "(", "$", "headers", "as", "$", "header", "=>", "$", "value", ")", "{", "$", "bytes", "+=", "$", "this", "->", "sendToClient", "(", "\"{$header}: {$value}\\r\\n\"", ")", ";", "}", "$", "bytes", "+=", "$", "this", "->", "sendToClient", "(", "\"\\r\\n\"", ")", ";", "return", "$", "bytes", ";", "}" ]
Sends the response headers through the client socket Returns the number of bytes sent. @param WebRequest $request The http request @param int $code The http status code to sent @param string $message The http status message to send @return int
[ "Sends", "the", "response", "headers", "through", "the", "client", "socket" ]
305ce78029b86fa1fadaf8341d8fc737c84eab87
https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebServer.php#L231-L245
train
headzoo/web-tools
src/Headzoo/Web/Tools/WebServer.php
WebServer.sendToClient
protected function sendToClient($line) { $bytes = 0; $len = strlen($line); if ($len) { while(true) { $sent = socket_write($this->client, $line, $len); if (false === $sent) { throw new Exceptions\HttpStatusError( "Internal server error.", 500 ); } $bytes += $sent; if ($sent < $len) { $line = substr($line, $sent); $len -= $sent; } else { break; } } } return $bytes; }
php
protected function sendToClient($line) { $bytes = 0; $len = strlen($line); if ($len) { while(true) { $sent = socket_write($this->client, $line, $len); if (false === $sent) { throw new Exceptions\HttpStatusError( "Internal server error.", 500 ); } $bytes += $sent; if ($sent < $len) { $line = substr($line, $sent); $len -= $sent; } else { break; } } } return $bytes; }
[ "protected", "function", "sendToClient", "(", "$", "line", ")", "{", "$", "bytes", "=", "0", ";", "$", "len", "=", "strlen", "(", "$", "line", ")", ";", "if", "(", "$", "len", ")", "{", "while", "(", "true", ")", "{", "$", "sent", "=", "socket_write", "(", "$", "this", "->", "client", ",", "$", "line", ",", "$", "len", ")", ";", "if", "(", "false", "===", "$", "sent", ")", "{", "throw", "new", "Exceptions", "\\", "HttpStatusError", "(", "\"Internal server error.\"", ",", "500", ")", ";", "}", "$", "bytes", "+=", "$", "sent", ";", "if", "(", "$", "sent", "<", "$", "len", ")", "{", "$", "line", "=", "substr", "(", "$", "line", ",", "$", "sent", ")", ";", "$", "len", "-=", "$", "sent", ";", "}", "else", "{", "break", ";", "}", "}", "}", "return", "$", "bytes", ";", "}" ]
Sends a string through the client socket Returns the number of bytes sent. @param string $line The string to send @return int @throws Exceptions\HttpStatusError
[ "Sends", "a", "string", "through", "the", "client", "socket" ]
305ce78029b86fa1fadaf8341d8fc737c84eab87
https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebServer.php#L256-L281
train
headzoo/web-tools
src/Headzoo/Web/Tools/WebServer.php
WebServer.getFile
protected function getFile(WebRequest $request) { $path = realpath($this->dirRoot . DIRECTORY_SEPARATOR . $request->getPath()); if (false === $path) { throw new Exceptions\HttpStatusError( "File not found.", 404 ); } if (is_dir($path)) { $path .= DIRECTORY_SEPARATOR . $this->index; } $contents = null; $info = pathinfo($path); if ($info["extension"] == "php") { ob_start(); /** @noinspection PhpIncludeInspection */ include($path); $contents = ob_get_contents(); ob_end_clean(); } else { $contents = file_get_contents($path); } return $contents; }
php
protected function getFile(WebRequest $request) { $path = realpath($this->dirRoot . DIRECTORY_SEPARATOR . $request->getPath()); if (false === $path) { throw new Exceptions\HttpStatusError( "File not found.", 404 ); } if (is_dir($path)) { $path .= DIRECTORY_SEPARATOR . $this->index; } $contents = null; $info = pathinfo($path); if ($info["extension"] == "php") { ob_start(); /** @noinspection PhpIncludeInspection */ include($path); $contents = ob_get_contents(); ob_end_clean(); } else { $contents = file_get_contents($path); } return $contents; }
[ "protected", "function", "getFile", "(", "WebRequest", "$", "request", ")", "{", "$", "path", "=", "realpath", "(", "$", "this", "->", "dirRoot", ".", "DIRECTORY_SEPARATOR", ".", "$", "request", "->", "getPath", "(", ")", ")", ";", "if", "(", "false", "===", "$", "path", ")", "{", "throw", "new", "Exceptions", "\\", "HttpStatusError", "(", "\"File not found.\"", ",", "404", ")", ";", "}", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "$", "path", ".=", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "index", ";", "}", "$", "contents", "=", "null", ";", "$", "info", "=", "pathinfo", "(", "$", "path", ")", ";", "if", "(", "$", "info", "[", "\"extension\"", "]", "==", "\"php\"", ")", "{", "ob_start", "(", ")", ";", "/** @noinspection PhpIncludeInspection */", "include", "(", "$", "path", ")", ";", "$", "contents", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "}", "else", "{", "$", "contents", "=", "file_get_contents", "(", "$", "path", ")", ";", "}", "return", "$", "contents", ";", "}" ]
Returns the data for the requested file @param WebRequest $request The http request @return string @throws Exceptions\HttpStatusError
[ "Returns", "the", "data", "for", "the", "requested", "file" ]
305ce78029b86fa1fadaf8341d8fc737c84eab87
https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebServer.php#L290-L316
train
timostamm/url-builder
src/UrlPath.php
UrlPath.parseComponent
public function parseComponent($str) { if (! is_string($str)) { throw new InvalidUrlException('Unexpected type.'); } if (strpos($str, ' ') !== false) { throw new InvalidUrlException('Path contains whitespace.'); } $p = explode('/', $str); foreach ($p as $i => $v) { $p[$i] = rawurldecode($v); } $decodedPath = join('/', $p); $this->path->set($decodedPath); }
php
public function parseComponent($str) { if (! is_string($str)) { throw new InvalidUrlException('Unexpected type.'); } if (strpos($str, ' ') !== false) { throw new InvalidUrlException('Path contains whitespace.'); } $p = explode('/', $str); foreach ($p as $i => $v) { $p[$i] = rawurldecode($v); } $decodedPath = join('/', $p); $this->path->set($decodedPath); }
[ "public", "function", "parseComponent", "(", "$", "str", ")", "{", "if", "(", "!", "is_string", "(", "$", "str", ")", ")", "{", "throw", "new", "InvalidUrlException", "(", "'Unexpected type.'", ")", ";", "}", "if", "(", "strpos", "(", "$", "str", ",", "' '", ")", "!==", "false", ")", "{", "throw", "new", "InvalidUrlException", "(", "'Path contains whitespace.'", ")", ";", "}", "$", "p", "=", "explode", "(", "'/'", ",", "$", "str", ")", ";", "foreach", "(", "$", "p", "as", "$", "i", "=>", "$", "v", ")", "{", "$", "p", "[", "$", "i", "]", "=", "rawurldecode", "(", "$", "v", ")", ";", "}", "$", "decodedPath", "=", "join", "(", "'/'", ",", "$", "p", ")", ";", "$", "this", "->", "path", "->", "set", "(", "$", "decodedPath", ")", ";", "}" ]
Parses a path component as it appears in a URL. @param string $str @throws \InvalidArgumentException
[ "Parses", "a", "path", "component", "as", "it", "appears", "in", "a", "URL", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlPath.php#L41-L55
train
timostamm/url-builder
src/UrlPath.php
UrlPath.get
public function get() { if (is_null($this->url)) { return $this->path->get(); } if (! $this->url->host->isEmpty()) { return Path::info('/')->resolve($this->path)->get(); } return $this->path->get(); }
php
public function get() { if (is_null($this->url)) { return $this->path->get(); } if (! $this->url->host->isEmpty()) { return Path::info('/')->resolve($this->path)->get(); } return $this->path->get(); }
[ "public", "function", "get", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "url", ")", ")", "{", "return", "$", "this", "->", "path", "->", "get", "(", ")", ";", "}", "if", "(", "!", "$", "this", "->", "url", "->", "host", "->", "isEmpty", "(", ")", ")", "{", "return", "Path", "::", "info", "(", "'/'", ")", "->", "resolve", "(", "$", "this", "->", "path", ")", "->", "get", "(", ")", ";", "}", "return", "$", "this", "->", "path", "->", "get", "(", ")", ";", "}" ]
Returns the decoded path. The path will start with a slash if the host is set, regardless whether the slash was present in the parsed URL and regardless whether you included the slash when setting the path via set(). Please not that __toString() does not prepend the slash. @return string
[ "Returns", "the", "decoded", "path", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlPath.php#L68-L77
train
timostamm/url-builder
src/UrlPath.php
UrlPath.set
public function set($str) { if ($str instanceof Path) { $this->path->set($str->get()); } else if ($str instanceof UrlPath) { $this->path->set($str->get()); } else if (is_string($str)) { $this->path->set($str); } else { throw new \InvalidArgumentException('Unexpected type.'); } }
php
public function set($str) { if ($str instanceof Path) { $this->path->set($str->get()); } else if ($str instanceof UrlPath) { $this->path->set($str->get()); } else if (is_string($str)) { $this->path->set($str); } else { throw new \InvalidArgumentException('Unexpected type.'); } }
[ "public", "function", "set", "(", "$", "str", ")", "{", "if", "(", "$", "str", "instanceof", "Path", ")", "{", "$", "this", "->", "path", "->", "set", "(", "$", "str", "->", "get", "(", ")", ")", ";", "}", "else", "if", "(", "$", "str", "instanceof", "UrlPath", ")", "{", "$", "this", "->", "path", "->", "set", "(", "$", "str", "->", "get", "(", ")", ")", ";", "}", "else", "if", "(", "is_string", "(", "$", "str", ")", ")", "{", "$", "this", "->", "path", "->", "set", "(", "$", "str", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unexpected type.'", ")", ";", "}", "}" ]
Sets the decoded path. @param string|UrlPath|Path $str @throws \InvalidArgumentException
[ "Sets", "the", "decoded", "path", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlPath.php#L85-L96
train
timostamm/url-builder
src/UrlPath.php
UrlPath.isAbsolute
public function isAbsolute() { if (! is_null($this->url) && $this->path->isEmpty()) { return ! $this->url->host->isEmpty(); } return $this->path->isAbsolute(); }
php
public function isAbsolute() { if (! is_null($this->url) && $this->path->isEmpty()) { return ! $this->url->host->isEmpty(); } return $this->path->isAbsolute(); }
[ "public", "function", "isAbsolute", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "url", ")", "&&", "$", "this", "->", "path", "->", "isEmpty", "(", ")", ")", "{", "return", "!", "$", "this", "->", "url", "->", "host", "->", "isEmpty", "(", ")", ";", "}", "return", "$", "this", "->", "path", "->", "isAbsolute", "(", ")", ";", "}" ]
URLs can be relative if scheme and host are omitted. Examples for relative URLs are: - ../foo.html - foo.html However, they can have an absolute path at the same time: - /index.html You can use this method to determine whether the path is absolute or not. @return boolean
[ "URLs", "can", "be", "relative", "if", "scheme", "and", "host", "are", "omitted", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlPath.php#L135-L141
train
timostamm/url-builder
src/UrlPath.php
UrlPath.dirname
public function dirname() { if (! is_null($this->url) && $this->path->isEmpty() && ! $this->url->host->isEmpty()) { return '/'; } return $this->path->dirname(); }
php
public function dirname() { if (! is_null($this->url) && $this->path->isEmpty() && ! $this->url->host->isEmpty()) { return '/'; } return $this->path->dirname(); }
[ "public", "function", "dirname", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "url", ")", "&&", "$", "this", "->", "path", "->", "isEmpty", "(", ")", "&&", "!", "$", "this", "->", "url", "->", "host", "->", "isEmpty", "(", ")", ")", "{", "return", "'/'", ";", "}", "return", "$", "this", "->", "path", "->", "dirname", "(", ")", ";", "}" ]
Return the path excluding the filename. If the URL has a host but no path, we still return '/'. @return string
[ "Return", "the", "path", "excluding", "the", "filename", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlPath.php#L160-L166
train
3ev/wordpress-core
src/Tev/Field/Model/ImageField.php
ImageField.sizeUrl
public function sizeUrl($size) { if (($this->base['return_format'] === 'array') && isset($this->base['value']['sizes'][$size])) { return $this->base['value']['sizes'][$size]; } elseif ($this->base['return_format'] === 'id') { if ($src = wp_get_attachment_image_src($this->id(), $size)) { return $src[0]; } } return ''; }
php
public function sizeUrl($size) { if (($this->base['return_format'] === 'array') && isset($this->base['value']['sizes'][$size])) { return $this->base['value']['sizes'][$size]; } elseif ($this->base['return_format'] === 'id') { if ($src = wp_get_attachment_image_src($this->id(), $size)) { return $src[0]; } } return ''; }
[ "public", "function", "sizeUrl", "(", "$", "size", ")", "{", "if", "(", "(", "$", "this", "->", "base", "[", "'return_format'", "]", "===", "'array'", ")", "&&", "isset", "(", "$", "this", "->", "base", "[", "'value'", "]", "[", "'sizes'", "]", "[", "$", "size", "]", ")", ")", "{", "return", "$", "this", "->", "base", "[", "'value'", "]", "[", "'sizes'", "]", "[", "$", "size", "]", ";", "}", "elseif", "(", "$", "this", "->", "base", "[", "'return_format'", "]", "===", "'id'", ")", "{", "if", "(", "$", "src", "=", "wp_get_attachment_image_src", "(", "$", "this", "->", "id", "(", ")", ",", "$", "size", ")", ")", "{", "return", "$", "src", "[", "0", "]", ";", "}", "}", "return", "''", ";", "}" ]
Get an image URL of a specic size. @param string $size Image size (e.g thumbnail, large or custom size) @return string Image URL
[ "Get", "an", "image", "URL", "of", "a", "specic", "size", "." ]
da674fbec5bf3d5bd2a2141680a4c141113eb6b0
https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Field/Model/ImageField.php#L86-L97
train
SpoonX/SxBootstrap
src/SxBootstrap/View/Helper/Bootstrap/Tooltip.php
Tooltip.setOption
public function setOption($key, $value) { if (!in_array($key, $this->availableOptions)) { throw new Exception\InvalidArgumentException('Invalid option for Tooltip'); } if (is_bool($value)) { $value = $value ? 'true' : 'false'; } if (!is_string($value)) { throw new Exception\InvalidArgumentException(sprintf( 'Invalid value for Tooltip, expected boolean or string, got "%s"', gettype($value) )); } $this->getElement()->addAttribute("data-$key", $value); return $this; }
php
public function setOption($key, $value) { if (!in_array($key, $this->availableOptions)) { throw new Exception\InvalidArgumentException('Invalid option for Tooltip'); } if (is_bool($value)) { $value = $value ? 'true' : 'false'; } if (!is_string($value)) { throw new Exception\InvalidArgumentException(sprintf( 'Invalid value for Tooltip, expected boolean or string, got "%s"', gettype($value) )); } $this->getElement()->addAttribute("data-$key", $value); return $this; }
[ "public", "function", "setOption", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "availableOptions", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "'Invalid option for Tooltip'", ")", ";", "}", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "value", "?", "'true'", ":", "'false'", ";", "}", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid value for Tooltip, expected boolean or string, got \"%s\"'", ",", "gettype", "(", "$", "value", ")", ")", ")", ";", "}", "$", "this", "->", "getElement", "(", ")", "->", "addAttribute", "(", "\"data-$key\"", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Set a single option to the Tooltip @param string $key @param string $value @return \SxBootstrap\View\Helper\Bootstrap\Label @throws Exception\InvalidArgumentException
[ "Set", "a", "single", "option", "to", "the", "Tooltip" ]
768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6
https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/Tooltip.php#L145-L165
train
zara-4/php-sdk
Zara4/API/Communication/Util.php
Util.currentIpAddress
public static function currentIpAddress() { // // Just get the headers if we can or else use the SERVER global // if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); } else { $headers = $_SERVER; } // // Get the forwarded IP if it exists // if ( array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) { $the_ip = $headers['X-Forwarded-For']; } elseif ( array_key_exists('HTTP_X_FORWARDED_FOR', $headers ) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) { $the_ip = $headers['HTTP_X_FORWARDED_FOR']; } else { $the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } return $the_ip; }
php
public static function currentIpAddress() { // // Just get the headers if we can or else use the SERVER global // if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); } else { $headers = $_SERVER; } // // Get the forwarded IP if it exists // if ( array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) { $the_ip = $headers['X-Forwarded-For']; } elseif ( array_key_exists('HTTP_X_FORWARDED_FOR', $headers ) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) { $the_ip = $headers['HTTP_X_FORWARDED_FOR']; } else { $the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } return $the_ip; }
[ "public", "static", "function", "currentIpAddress", "(", ")", "{", "//", "// Just get the headers if we can or else use the SERVER global", "//", "if", "(", "function_exists", "(", "'apache_request_headers'", ")", ")", "{", "$", "headers", "=", "apache_request_headers", "(", ")", ";", "}", "else", "{", "$", "headers", "=", "$", "_SERVER", ";", "}", "//", "// Get the forwarded IP if it exists", "//", "if", "(", "array_key_exists", "(", "'X-Forwarded-For'", ",", "$", "headers", ")", "&&", "filter_var", "(", "$", "headers", "[", "'X-Forwarded-For'", "]", ",", "FILTER_VALIDATE_IP", ",", "FILTER_FLAG_IPV4", ")", ")", "{", "$", "the_ip", "=", "$", "headers", "[", "'X-Forwarded-For'", "]", ";", "}", "elseif", "(", "array_key_exists", "(", "'HTTP_X_FORWARDED_FOR'", ",", "$", "headers", ")", "&&", "filter_var", "(", "$", "headers", "[", "'HTTP_X_FORWARDED_FOR'", "]", ",", "FILTER_VALIDATE_IP", ",", "FILTER_FLAG_IPV4", ")", ")", "{", "$", "the_ip", "=", "$", "headers", "[", "'HTTP_X_FORWARDED_FOR'", "]", ";", "}", "else", "{", "$", "the_ip", "=", "filter_var", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ",", "FILTER_VALIDATE_IP", ",", "FILTER_FLAG_IPV4", ")", ";", "}", "return", "$", "the_ip", ";", "}" ]
Get the ip address from the current request. @return String
[ "Get", "the", "ip", "address", "from", "the", "current", "request", "." ]
33a1bc9676d9d870a0e274ca44068b207e5dae78
https://github.com/zara-4/php-sdk/blob/33a1bc9676d9d870a0e274ca44068b207e5dae78/Zara4/API/Communication/Util.php#L266-L299
train
schpill/thin
src/Navigation/Page.php
Page.setLabel
public function setLabel($label) { if (null !== $label && !is_string($label)) { throw new Exception( 'Invalid argument: $label must be a string or null'); } $this->_label = $label; return $this; }
php
public function setLabel($label) { if (null !== $label && !is_string($label)) { throw new Exception( 'Invalid argument: $label must be a string or null'); } $this->_label = $label; return $this; }
[ "public", "function", "setLabel", "(", "$", "label", ")", "{", "if", "(", "null", "!==", "$", "label", "&&", "!", "is_string", "(", "$", "label", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $label must be a string or null'", ")", ";", "}", "$", "this", "->", "_label", "=", "$", "label", ";", "return", "$", "this", ";", "}" ]
Sets page label @param string $label new page label @return Page fluent interface, returns self @throws Exception if empty/no string is given
[ "Sets", "page", "label" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L262-L271
train
schpill/thin
src/Navigation/Page.php
Page.setFragment
public function setFragment($fragment) { if (null !== $fragment && !is_string($fragment)) { throw new Exception( 'Invalid argument: $fragment must be a string or null'); } $this->_fragment = $fragment; return $this; }
php
public function setFragment($fragment) { if (null !== $fragment && !is_string($fragment)) { throw new Exception( 'Invalid argument: $fragment must be a string or null'); } $this->_fragment = $fragment; return $this; }
[ "public", "function", "setFragment", "(", "$", "fragment", ")", "{", "if", "(", "null", "!==", "$", "fragment", "&&", "!", "is_string", "(", "$", "fragment", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $fragment must be a string or null'", ")", ";", "}", "$", "this", "->", "_fragment", "=", "$", "fragment", ";", "return", "$", "this", ";", "}" ]
Sets a fragment identifier @param string $fragment new fragment identifier @return Page fluent interface, returns self @throws Exception if empty/no string is given
[ "Sets", "a", "fragment", "identifier" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L290-L299
train
schpill/thin
src/Navigation/Page.php
Page.setId
public function setId($id = null) { if (null !== $id && !is_string($id) && !is_numeric($id)) { throw new Exception( 'Invalid argument: $id must be a string, number or null'); } $this->_id = null === $id ? $id : (string) $id; return $this; }
php
public function setId($id = null) { if (null !== $id && !is_string($id) && !is_numeric($id)) { throw new Exception( 'Invalid argument: $id must be a string, number or null'); } $this->_id = null === $id ? $id : (string) $id; return $this; }
[ "public", "function", "setId", "(", "$", "id", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "id", "&&", "!", "is_string", "(", "$", "id", ")", "&&", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $id must be a string, number or null'", ")", ";", "}", "$", "this", "->", "_id", "=", "null", "===", "$", "id", "?", "$", "id", ":", "(", "string", ")", "$", "id", ";", "return", "$", "this", ";", "}" ]
Sets page id @param string|null $id [optional] id to set. Default is null, which sets no id. @return Page fluent interface, returns self @throws Exception if not given string or null
[ "Sets", "page", "id" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L319-L329
train
schpill/thin
src/Navigation/Page.php
Page.setTitle
public function setTitle($title = null) { if (null !== $title && !is_string($title)) { throw new Exception( 'Invalid argument: $title must be a non-empty string'); } $this->_title = $title; return $this; }
php
public function setTitle($title = null) { if (null !== $title && !is_string($title)) { throw new Exception( 'Invalid argument: $title must be a non-empty string'); } $this->_title = $title; return $this; }
[ "public", "function", "setTitle", "(", "$", "title", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "title", "&&", "!", "is_string", "(", "$", "title", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $title must be a non-empty string'", ")", ";", "}", "$", "this", "->", "_title", "=", "$", "title", ";", "return", "$", "this", ";", "}" ]
Sets page title @param string $title [optional] page title. Default is null, which sets no title. @return Page fluent interface, returns self @throws Exception if not given string or null
[ "Sets", "page", "title" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L379-L389
train
schpill/thin
src/Navigation/Page.php
Page.setTarget
public function setTarget($target = null) { if (null !== $target && !is_string($target)) { throw new Exception( 'Invalid argument: $target must be a string or null'); } $this->_target = $target; return $this; }
php
public function setTarget($target = null) { if (null !== $target && !is_string($target)) { throw new Exception( 'Invalid argument: $target must be a string or null'); } $this->_target = $target; return $this; }
[ "public", "function", "setTarget", "(", "$", "target", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "target", "&&", "!", "is_string", "(", "$", "target", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $target must be a string or null'", ")", ";", "}", "$", "this", "->", "_target", "=", "$", "target", ";", "return", "$", "this", ";", "}" ]
Sets page target @param string|null $target [optional] target to set. Default is null, which sets no target. @return Page fluent interface, returns self @throws Exception if target is not string or null
[ "Sets", "page", "target" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L409-L419
train
schpill/thin
src/Navigation/Page.php
Page.setAccesskey
public function setAccesskey($character = null) { if (null !== $character && (!is_string($character) || 1 != strlen($character))) { throw new Exception( 'Invalid argument: $character must be a single character or null' ); } $this->_accesskey = $character; return $this; }
php
public function setAccesskey($character = null) { if (null !== $character && (!is_string($character) || 1 != strlen($character))) { throw new Exception( 'Invalid argument: $character must be a single character or null' ); } $this->_accesskey = $character; return $this; }
[ "public", "function", "setAccesskey", "(", "$", "character", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "character", "&&", "(", "!", "is_string", "(", "$", "character", ")", "||", "1", "!=", "strlen", "(", "$", "character", ")", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $character must be a single character or null'", ")", ";", "}", "$", "this", "->", "_accesskey", "=", "$", "character", ";", "return", "$", "this", ";", "}" ]
Sets access key for this page @param string|null $character [optional] access key to set. Default is null, which sets no access key. @return Page fluent interface, returns self @throws Exception if access key is not string or null or if the string length not equal to one
[ "Sets", "access", "key", "for", "this", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L440-L453
train
schpill/thin
src/Navigation/Page.php
Page.setRel
public function setRel($relations = null) { $this->_rel = array(); if (null !== $relations) { if (!is_array($relations)) { throw new Exception( 'Invalid argument: $relations must be an array'); } foreach ($relations as $name => $relation) { if (is_string($name)) { $this->_rel[$name] = $relation; } } } return $this; }
php
public function setRel($relations = null) { $this->_rel = array(); if (null !== $relations) { if (!is_array($relations)) { throw new Exception( 'Invalid argument: $relations must be an array'); } foreach ($relations as $name => $relation) { if (is_string($name)) { $this->_rel[$name] = $relation; } } } return $this; }
[ "public", "function", "setRel", "(", "$", "relations", "=", "null", ")", "{", "$", "this", "->", "_rel", "=", "array", "(", ")", ";", "if", "(", "null", "!==", "$", "relations", ")", "{", "if", "(", "!", "is_array", "(", "$", "relations", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $relations must be an array'", ")", ";", "}", "foreach", "(", "$", "relations", "as", "$", "name", "=>", "$", "relation", ")", "{", "if", "(", "is_string", "(", "$", "name", ")", ")", "{", "$", "this", "->", "_rel", "[", "$", "name", "]", "=", "$", "relation", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Sets the page's forward links to other pages This method expects an associative array of forward links to other pages, where each element's key is the name of the relation (e.g. alternate, prev, next, help, etc), and the value is a mixed value that could somehow be considered a page. @param array $relations [optional] an associative array of forward links to other pages @return Page fluent interface, returns self
[ "Sets", "the", "page", "s", "forward", "links", "to", "other", "pages" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L477-L496
train
schpill/thin
src/Navigation/Page.php
Page.getRel
public function getRel($relation = null) { if (null !== $relation) { return isset($this->_rel[$relation]) ? $this->_rel[$relation] : null; } return $this->_rel; }
php
public function getRel($relation = null) { if (null !== $relation) { return isset($this->_rel[$relation]) ? $this->_rel[$relation] : null; } return $this->_rel; }
[ "public", "function", "getRel", "(", "$", "relation", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "relation", ")", "{", "return", "isset", "(", "$", "this", "->", "_rel", "[", "$", "relation", "]", ")", "?", "$", "this", "->", "_rel", "[", "$", "relation", "]", ":", "null", ";", "}", "return", "$", "this", "->", "_rel", ";", "}" ]
Returns the page's forward links to other pages This method returns an associative array of forward links to other pages, where each element's key is the name of the relation (e.g. alternate, prev, next, help, etc), and the value is a mixed value that could somehow be considered a page. @param string $relation [optional] name of relation to return. If not given, all relations will be returned. @return array an array of relations. If $relation is not specified, all relations will be returned in an associative array.
[ "Returns", "the", "page", "s", "forward", "links", "to", "other", "pages" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L512-L521
train
schpill/thin
src/Navigation/Page.php
Page.setRev
public function setRev($relations = null) { $this->_rev = array(); if (null !== $relations) { if (!is_array($relations)) { throw new Exception( 'Invalid argument: $relations must be an array'); } foreach ($relations as $name => $relation) { if (is_string($name)) { $this->_rev[$name] = $relation; } } } return $this; }
php
public function setRev($relations = null) { $this->_rev = array(); if (null !== $relations) { if (!is_array($relations)) { throw new Exception( 'Invalid argument: $relations must be an array'); } foreach ($relations as $name => $relation) { if (is_string($name)) { $this->_rev[$name] = $relation; } } } return $this; }
[ "public", "function", "setRev", "(", "$", "relations", "=", "null", ")", "{", "$", "this", "->", "_rev", "=", "array", "(", ")", ";", "if", "(", "null", "!==", "$", "relations", ")", "{", "if", "(", "!", "is_array", "(", "$", "relations", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $relations must be an array'", ")", ";", "}", "foreach", "(", "$", "relations", "as", "$", "name", "=>", "$", "relation", ")", "{", "if", "(", "is_string", "(", "$", "name", ")", ")", "{", "$", "this", "->", "_rev", "[", "$", "name", "]", "=", "$", "relation", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Sets the page's reverse links to other pages This method expects an associative array of reverse links to other pages, where each element's key is the name of the relation (e.g. alternate, prev, next, help, etc), and the value is a mixed value that could somehow be considered a page. @param array $relations [optional] an associative array of reverse links to other pages @return Page fluent interface, returns self
[ "Sets", "the", "page", "s", "reverse", "links", "to", "other", "pages" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L535-L553
train
schpill/thin
src/Navigation/Page.php
Page.getRev
public function getRev($relation = null) { if (null !== $relation) { return isset($this->_rev[$relation]) ? $this->_rev[$relation] : null; } return $this->_rev; }
php
public function getRev($relation = null) { if (null !== $relation) { return isset($this->_rev[$relation]) ? $this->_rev[$relation] : null; } return $this->_rev; }
[ "public", "function", "getRev", "(", "$", "relation", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "relation", ")", "{", "return", "isset", "(", "$", "this", "->", "_rev", "[", "$", "relation", "]", ")", "?", "$", "this", "->", "_rev", "[", "$", "relation", "]", ":", "null", ";", "}", "return", "$", "this", "->", "_rev", ";", "}" ]
Returns the page's reverse links to other pages This method returns an associative array of forward links to other pages, where each element's key is the name of the relation (e.g. alternate, prev, next, help, etc), and the value is a mixed value that could somehow be considered a page. @param string $relation [optional] name of relation to return. If not given, all relations will be returned. @return array an array of relations. If $relation is not specified, all relations will be returned in an associative array.
[ "Returns", "the", "page", "s", "reverse", "links", "to", "other", "pages" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L569-L578
train
schpill/thin
src/Navigation/Page.php
Page.setCustomHtmlAttrib
public function setCustomHtmlAttrib($name, $value) { if (!is_string($name)) { throw new Exception( 'Invalid argument: $name must be a string' ); } if (null !== $value && !is_string($value)) { throw new Exception( 'Invalid argument: $value must be a string or null' ); } if (null === $value && isset($this->_customHtmlAttribs[$name])) { unset($this->_customHtmlAttribs[$name]); } else { $this->_customHtmlAttribs[$name] = $value; } return $this; }
php
public function setCustomHtmlAttrib($name, $value) { if (!is_string($name)) { throw new Exception( 'Invalid argument: $name must be a string' ); } if (null !== $value && !is_string($value)) { throw new Exception( 'Invalid argument: $value must be a string or null' ); } if (null === $value && isset($this->_customHtmlAttribs[$name])) { unset($this->_customHtmlAttribs[$name]); } else { $this->_customHtmlAttribs[$name] = $value; } return $this; }
[ "public", "function", "setCustomHtmlAttrib", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $name must be a string'", ")", ";", "}", "if", "(", "null", "!==", "$", "value", "&&", "!", "is_string", "(", "$", "value", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $value must be a string or null'", ")", ";", "}", "if", "(", "null", "===", "$", "value", "&&", "isset", "(", "$", "this", "->", "_customHtmlAttribs", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "_customHtmlAttribs", "[", "$", "name", "]", ")", ";", "}", "else", "{", "$", "this", "->", "_customHtmlAttribs", "[", "$", "name", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Sets a single custom HTML attribute @param string $name name of the HTML attribute @param string|null $value value for the HTML attribute @return Page fluent interface, returns self @throws Exception if name is not string or value is not null or a string
[ "Sets", "a", "single", "custom", "HTML", "attribute" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L589-L610
train
schpill/thin
src/Navigation/Page.php
Page.getCustomHtmlAttrib
public function getCustomHtmlAttrib($name) { if (!is_string($name)) { throw new Exception( 'Invalid argument: $name must be a string' ); } if (isset($this->_customHtmlAttribs[$name])) { return $this->_customHtmlAttribs[$name]; } return null; }
php
public function getCustomHtmlAttrib($name) { if (!is_string($name)) { throw new Exception( 'Invalid argument: $name must be a string' ); } if (isset($this->_customHtmlAttribs[$name])) { return $this->_customHtmlAttribs[$name]; } return null; }
[ "public", "function", "getCustomHtmlAttrib", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $name must be a string'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_customHtmlAttribs", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "_customHtmlAttribs", "[", "$", "name", "]", ";", "}", "return", "null", ";", "}" ]
Returns a single custom HTML attributes by name @param string $name name of the HTML attribute @return string|null value for the HTML attribute or null @throws Exception if name is not string
[ "Returns", "a", "single", "custom", "HTML", "attributes", "by", "name" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L619-L632
train
schpill/thin
src/Navigation/Page.php
Page.setCustomHtmlAttribs
public function setCustomHtmlAttribs(array $attribs) { foreach ($attribs as $key => $value) { $this->setCustomHtmlAttrib($key, $value); } return $this; }
php
public function setCustomHtmlAttribs(array $attribs) { foreach ($attribs as $key => $value) { $this->setCustomHtmlAttrib($key, $value); } return $this; }
[ "public", "function", "setCustomHtmlAttribs", "(", "array", "$", "attribs", ")", "{", "foreach", "(", "$", "attribs", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "setCustomHtmlAttrib", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets multiple custom HTML attributes at once @param array $attribs an associative array of html attributes @return Page fluent interface, returns self
[ "Sets", "multiple", "custom", "HTML", "attributes", "at", "once" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L640-L646
train
schpill/thin
src/Navigation/Page.php
Page.removeCustomHtmlAttrib
public function removeCustomHtmlAttrib($name) { if (!is_string($name)) { throw new Exception( 'Invalid argument: $name must be a string' ); } if (isset($this->_customHtmlAttribs[$name])) { unset($this->_customHtmlAttribs[$name]); } }
php
public function removeCustomHtmlAttrib($name) { if (!is_string($name)) { throw new Exception( 'Invalid argument: $name must be a string' ); } if (isset($this->_customHtmlAttribs[$name])) { unset($this->_customHtmlAttribs[$name]); } }
[ "public", "function", "removeCustomHtmlAttrib", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $name must be a string'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_customHtmlAttribs", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "_customHtmlAttribs", "[", "$", "name", "]", ")", ";", "}", "}" ]
Removes a custom HTML attribute from the page @param string $name name of the custom HTML attribute @return Page fluent interface, returns self
[ "Removes", "a", "custom", "HTML", "attribute", "from", "the", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L664-L675
train
schpill/thin
src/Navigation/Page.php
Page.setOrder
public function setOrder($order = null) { if (is_string($order)) { $temp = (int) $order; if ($temp < 0 || $temp > 0 || $order == '0') { $order = $temp; } } if (null !== $order && !is_int($order)) { throw new Exception( 'Invalid argument: $order must be an integer or null, ' . 'or a string that casts to an integer'); } $this->_order = $order; // notify parent, if any if (isset($this->_parent)) { $this->_parent->notifyOrderUpdated(); } return $this; }
php
public function setOrder($order = null) { if (is_string($order)) { $temp = (int) $order; if ($temp < 0 || $temp > 0 || $order == '0') { $order = $temp; } } if (null !== $order && !is_int($order)) { throw new Exception( 'Invalid argument: $order must be an integer or null, ' . 'or a string that casts to an integer'); } $this->_order = $order; // notify parent, if any if (isset($this->_parent)) { $this->_parent->notifyOrderUpdated(); } return $this; }
[ "public", "function", "setOrder", "(", "$", "order", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "order", ")", ")", "{", "$", "temp", "=", "(", "int", ")", "$", "order", ";", "if", "(", "$", "temp", "<", "0", "||", "$", "temp", ">", "0", "||", "$", "order", "==", "'0'", ")", "{", "$", "order", "=", "$", "temp", ";", "}", "}", "if", "(", "null", "!==", "$", "order", "&&", "!", "is_int", "(", "$", "order", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $order must be an integer or null, '", ".", "'or a string that casts to an integer'", ")", ";", "}", "$", "this", "->", "_order", "=", "$", "order", ";", "// notify parent, if any", "if", "(", "isset", "(", "$", "this", "->", "_parent", ")", ")", "{", "$", "this", "->", "_parent", "->", "notifyOrderUpdated", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets page order to use in parent container @param int $order [optional] page order in container. Default is null, which sets no specific order. @return Page fluent interface, returns self @throws Exception if order is not integer or null
[ "Sets", "page", "order", "to", "use", "in", "parent", "container" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L698-L721
train
schpill/thin
src/Navigation/Page.php
Page.setResource
public function setResource($resource = null) { if (null === $resource || is_string($resource) || $resource instanceof Acl) { $this->_resource = $resource; } else { require_once 'Zend/Navigation/Exception.php'; throw new Exception( 'Invalid argument: $resource must be null, a string, ' . ' or an instance of Acl'); } return $this; }
php
public function setResource($resource = null) { if (null === $resource || is_string($resource) || $resource instanceof Acl) { $this->_resource = $resource; } else { require_once 'Zend/Navigation/Exception.php'; throw new Exception( 'Invalid argument: $resource must be null, a string, ' . ' or an instance of Acl'); } return $this; }
[ "public", "function", "setResource", "(", "$", "resource", "=", "null", ")", "{", "if", "(", "null", "===", "$", "resource", "||", "is_string", "(", "$", "resource", ")", "||", "$", "resource", "instanceof", "Acl", ")", "{", "$", "this", "->", "_resource", "=", "$", "resource", ";", "}", "else", "{", "require_once", "'Zend/Navigation/Exception.php'", ";", "throw", "new", "Exception", "(", "'Invalid argument: $resource must be null, a string, '", ".", "' or an instance of Acl'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets ACL resource assoicated with this page @param string|Acl $resource [optional] resource to associate with page. Default is null, which sets no resource. @throws Exception if $resource if invalid @return Page fluent interface, returns self
[ "Sets", "ACL", "resource", "assoicated", "with", "this", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L746-L759
train
schpill/thin
src/Navigation/Page.php
Page.setPrivilege
public function setPrivilege($privilege = null) { $this->_privilege = is_string($privilege) ? $privilege : null; return $this; }
php
public function setPrivilege($privilege = null) { $this->_privilege = is_string($privilege) ? $privilege : null; return $this; }
[ "public", "function", "setPrivilege", "(", "$", "privilege", "=", "null", ")", "{", "$", "this", "->", "_privilege", "=", "is_string", "(", "$", "privilege", ")", "?", "$", "privilege", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets ACL privilege associated with this page @param string|null $privilege [optional] ACL privilege to associate with this page. Default is null, which sets no privilege. @return Page fluent interface, returns self
[ "Sets", "ACL", "privilege", "associated", "with", "this", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L779-L783
train
schpill/thin
src/Navigation/Page.php
Page.setVisible
public function setVisible($visible = true) { if (is_string($visible) && 'false' == strtolower($visible)) { $visible = false; } $this->_visible = (bool) $visible; return $this; }
php
public function setVisible($visible = true) { if (is_string($visible) && 'false' == strtolower($visible)) { $visible = false; } $this->_visible = (bool) $visible; return $this; }
[ "public", "function", "setVisible", "(", "$", "visible", "=", "true", ")", "{", "if", "(", "is_string", "(", "$", "visible", ")", "&&", "'false'", "==", "strtolower", "(", "$", "visible", ")", ")", "{", "$", "visible", "=", "false", ";", "}", "$", "this", "->", "_visible", "=", "(", "bool", ")", "$", "visible", ";", "return", "$", "this", ";", "}" ]
Sets whether the page should be visible or not @param bool $visible [optional] whether page should be considered visible or not. Default is true. @return Page fluent interface, returns self
[ "Sets", "whether", "the", "page", "should", "be", "visible", "or", "not" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L851-L858
train
schpill/thin
src/Navigation/Page.php
Page.isVisible
public function isVisible($recursive = false) { if ($recursive && isset($this->_parent) && $this->_parent instanceof Page) { if (!$this->_parent->isVisible(true)) { return false; } } return $this->_visible; }
php
public function isVisible($recursive = false) { if ($recursive && isset($this->_parent) && $this->_parent instanceof Page) { if (!$this->_parent->isVisible(true)) { return false; } } return $this->_visible; }
[ "public", "function", "isVisible", "(", "$", "recursive", "=", "false", ")", "{", "if", "(", "$", "recursive", "&&", "isset", "(", "$", "this", "->", "_parent", ")", "&&", "$", "this", "->", "_parent", "instanceof", "Page", ")", "{", "if", "(", "!", "$", "this", "->", "_parent", "->", "isVisible", "(", "true", ")", ")", "{", "return", "false", ";", "}", "}", "return", "$", "this", "->", "_visible", ";", "}" ]
Returns a boolean value indicating whether the page is visible @param bool $recursive [optional] whether page should be considered invisible if parent is invisible. Default is false. @return bool whether page should be considered visible
[ "Returns", "a", "boolean", "value", "indicating", "whether", "the", "page", "is", "visible" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L868-L878
train
schpill/thin
src/Navigation/Page.php
Page.setParent
public function setParent(Container $parent = null) { if ($parent === $this) { throw new Exception( 'A page cannot have itself as a parent'); } // return if the given parent already is parent if ($parent === $this->_parent) { return $this; } // remove from old parent if (null !== $this->_parent) { $this->_parent->removePage($this); } // set new parent $this->_parent = $parent; // add to parent if page and not already a child if (null !== $this->_parent && !$this->_parent->hasPage($this, false)) { $this->_parent->addPage($this); } return $this; }
php
public function setParent(Container $parent = null) { if ($parent === $this) { throw new Exception( 'A page cannot have itself as a parent'); } // return if the given parent already is parent if ($parent === $this->_parent) { return $this; } // remove from old parent if (null !== $this->_parent) { $this->_parent->removePage($this); } // set new parent $this->_parent = $parent; // add to parent if page and not already a child if (null !== $this->_parent && !$this->_parent->hasPage($this, false)) { $this->_parent->addPage($this); } return $this; }
[ "public", "function", "setParent", "(", "Container", "$", "parent", "=", "null", ")", "{", "if", "(", "$", "parent", "===", "$", "this", ")", "{", "throw", "new", "Exception", "(", "'A page cannot have itself as a parent'", ")", ";", "}", "// return if the given parent already is parent", "if", "(", "$", "parent", "===", "$", "this", "->", "_parent", ")", "{", "return", "$", "this", ";", "}", "// remove from old parent", "if", "(", "null", "!==", "$", "this", "->", "_parent", ")", "{", "$", "this", "->", "_parent", "->", "removePage", "(", "$", "this", ")", ";", "}", "// set new parent", "$", "this", "->", "_parent", "=", "$", "parent", ";", "// add to parent if page and not already a child", "if", "(", "null", "!==", "$", "this", "->", "_parent", "&&", "!", "$", "this", "->", "_parent", "->", "hasPage", "(", "$", "this", ",", "false", ")", ")", "{", "$", "this", "->", "_parent", "->", "addPage", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets parent container @param Container $parent [optional] new parent to set. Default is null which will set no parent. @return Page fluent interface, returns self
[ "Sets", "parent", "container" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L903-L929
train
schpill/thin
src/Navigation/Page.php
Page.set
public function set($property, $value) { if (!is_string($property) || empty($property)) { throw new Exception( 'Invalid argument: $property must be a non-empty string'); } $method = 'set' . self::_normalizePropertyName($property); if ($method != 'setOptions' && $method != 'setConfig' && method_exists($this, $method)) { $this->$method($value); } else { $this->_properties[$property] = $value; } return $this; }
php
public function set($property, $value) { if (!is_string($property) || empty($property)) { throw new Exception( 'Invalid argument: $property must be a non-empty string'); } $method = 'set' . self::_normalizePropertyName($property); if ($method != 'setOptions' && $method != 'setConfig' && method_exists($this, $method)) { $this->$method($value); } else { $this->_properties[$property] = $value; } return $this; }
[ "public", "function", "set", "(", "$", "property", ",", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "property", ")", "||", "empty", "(", "$", "property", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $property must be a non-empty string'", ")", ";", "}", "$", "method", "=", "'set'", ".", "self", "::", "_normalizePropertyName", "(", "$", "property", ")", ";", "if", "(", "$", "method", "!=", "'setOptions'", "&&", "$", "method", "!=", "'setConfig'", "&&", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "$", "this", "->", "$", "method", "(", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "_properties", "[", "$", "property", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Sets the given property If the given property is native (id, class, title, etc), the matching set method will be used. Otherwise, it will be set as a custom property. @param string $property property name @param mixed $value value to set @return Page fluent interface, returns self @throws Exception if property name is invalid
[ "Sets", "the", "given", "property" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L952-L969
train
schpill/thin
src/Navigation/Page.php
Page.get
public function get($property) { if (!is_string($property) || empty($property)) { throw new Exception( 'Invalid argument: $property must be a non-empty string'); } $method = 'get' . self::_normalizePropertyName($property); if (method_exists($this, $method)) { return $this->$method(); } elseif (isset($this->_properties[$property])) { return $this->_properties[$property]; } return null; }
php
public function get($property) { if (!is_string($property) || empty($property)) { throw new Exception( 'Invalid argument: $property must be a non-empty string'); } $method = 'get' . self::_normalizePropertyName($property); if (method_exists($this, $method)) { return $this->$method(); } elseif (isset($this->_properties[$property])) { return $this->_properties[$property]; } return null; }
[ "public", "function", "get", "(", "$", "property", ")", "{", "if", "(", "!", "is_string", "(", "$", "property", ")", "||", "empty", "(", "$", "property", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid argument: $property must be a non-empty string'", ")", ";", "}", "$", "method", "=", "'get'", ".", "self", "::", "_normalizePropertyName", "(", "$", "property", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "return", "$", "this", "->", "$", "method", "(", ")", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "_properties", "[", "$", "property", "]", ")", ")", "{", "return", "$", "this", "->", "_properties", "[", "$", "property", "]", ";", "}", "return", "null", ";", "}" ]
Returns the value of the given property If the given property is native (id, class, title, etc), the matching get method will be used. Otherwise, it will return the matching custom property, or null if not found. @param string $property property name @return mixed the property's value or null @throws Exception if property name is invalid
[ "Returns", "the", "value", "of", "the", "given", "property" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L982-L998
train
schpill/thin
src/Navigation/Page.php
Page.__isset
public function __isset($name) { $method = 'get' . self::_normalizePropertyName($name); if (method_exists($this, $method)) { return true; } return isset($this->_properties[$name]); }
php
public function __isset($name) { $method = 'get' . self::_normalizePropertyName($name); if (method_exists($this, $method)) { return true; } return isset($this->_properties[$name]); }
[ "public", "function", "__isset", "(", "$", "name", ")", "{", "$", "method", "=", "'get'", ".", "self", "::", "_normalizePropertyName", "(", "$", "name", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "return", "true", ";", "}", "return", "isset", "(", "$", "this", "->", "_properties", "[", "$", "name", "]", ")", ";", "}" ]
Checks if a property is set Magic overload for enabling <code>isset($page->propname)</code>. Returns true if the property is native (id, class, title, etc), and true or false if it's a custom property (depending on whether the property actually is set). @param string $name property name @return bool whether the given property exists
[ "Checks", "if", "a", "property", "is", "set" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L1043-L1051
train
schpill/thin
src/Navigation/Page.php
Page.addRel
public function addRel($relation, $value) { if (is_string($relation)) { $this->_rel[$relation] = $value; } return $this; }
php
public function addRel($relation, $value) { if (is_string($relation)) { $this->_rel[$relation] = $value; } return $this; }
[ "public", "function", "addRel", "(", "$", "relation", ",", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "relation", ")", ")", "{", "$", "this", "->", "_rel", "[", "$", "relation", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Adds a forward relation to the page @param string $relation relation name (e.g. alternate, glossary, canonical, etc) @param mixed $value value to set for relation @return Page fluent interface, returns self
[ "Adds", "a", "forward", "relation", "to", "the", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L1098-L1105
train
schpill/thin
src/Navigation/Page.php
Page.addRev
public function addRev($relation, $value) { if (is_string($relation)) { $this->_rev[$relation] = $value; } return $this; }
php
public function addRev($relation, $value) { if (is_string($relation)) { $this->_rev[$relation] = $value; } return $this; }
[ "public", "function", "addRev", "(", "$", "relation", ",", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "relation", ")", ")", "{", "$", "this", "->", "_rev", "[", "$", "relation", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Adds a reverse relation to the page @param string $relation relation name (e.g. alternate, glossary, canonical, etc) @param mixed $value value to set for relation @return Page fluent interface, returns self
[ "Adds", "a", "reverse", "relation", "to", "the", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L1115-L1122
train
schpill/thin
src/Navigation/Page.php
Page.removeRel
public function removeRel($relation) { if (isset($this->_rel[$relation])) { unset($this->_rel[$relation]); } return $this; }
php
public function removeRel($relation) { if (isset($this->_rel[$relation])) { unset($this->_rel[$relation]); } return $this; }
[ "public", "function", "removeRel", "(", "$", "relation", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_rel", "[", "$", "relation", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "_rel", "[", "$", "relation", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Removes a forward relation from the page @param string $relation name of relation to remove @return Page fluent interface, returns self
[ "Removes", "a", "forward", "relation", "from", "the", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L1130-L1137
train
schpill/thin
src/Navigation/Page.php
Page.removeRev
public function removeRev($relation) { if (isset($this->_rev[$relation])) { unset($this->_rev[$relation]); } return $this; }
php
public function removeRev($relation) { if (isset($this->_rev[$relation])) { unset($this->_rev[$relation]); } return $this; }
[ "public", "function", "removeRev", "(", "$", "relation", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_rev", "[", "$", "relation", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "_rev", "[", "$", "relation", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Removes a reverse relation from the page @param string $relation name of relation to remove @return Page fluent interface, returns self
[ "Removes", "a", "reverse", "relation", "from", "the", "page" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page.php#L1145-L1152
train
SpoonX/SxBootstrap
src/SxBootstrap/View/Helper/Bootstrap/AbstractElementHelper.php
AbstractElementHelper.addAttribute
public function addAttribute($key, $value = null) { $this->element->addAttribute($key, $value); return $this; }
php
public function addAttribute($key, $value = null) { $this->element->addAttribute($key, $value); return $this; }
[ "public", "function", "addAttribute", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "$", "this", "->", "element", "->", "addAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Add attribute on element @param string $key @param string $value @return $this
[ "Add", "attribute", "on", "element" ]
768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6
https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/AbstractElementHelper.php#L59-L64
train
inhere/php-library-plus
libs/Task/Worker/Manager.php
Manager.showHelp
protected function showHelp($msg = '', $code = 0) { $usage = Cli::color('USAGE:', 'brown'); $commands = Cli::color('COMMANDS:', 'brown'); $sOptions = Cli::color('SPECIAL OPTIONS:', 'brown'); $pOptions = Cli::color('PUBLIC OPTIONS:', 'brown'); $version = Cli::color(self::VERSION, 'green'); $script = $this->getScript(); if ($msg) { $code = $code ?: self::CODE_UNKNOWN_ERROR; echo Cli::color('ERROR:', 'light_red') . "\n " . wordwrap($msg, 108, "\n ") . "\n\n"; } echo <<<EOF Gearman worker manager(gwm) script tool. Version $version(lite) $usage $script {COMMAND} -c CONFIG [-v LEVEL] [-l LOG_FILE] [-d] [-w] [-p PID_FILE] $script -h $script -D $commands start Start gearman worker manager(default) stop Stop running's gearman worker manager restart Restart running's gearman worker manager reload Reload all running workers of the manager status Get gearman worker manager runtime status $sOptions start/restart -d,--daemon Daemon, detach and run in the background --tasks Only register the assigned tasks, multi task name separated by commas(',') --no-test Not add test handler, when task name prefix is 'test'.(eg: test_task) status --cmd COMMAND Send command when connect to the task server. allow:status,workers.(default:status) --watch-status Watch status command, will auto refresh status. $pOptions -c CONFIG Load a custom worker manager configuration file -s HOST[:PORT] Connect to server HOST and optional PORT, multi server separated by commas(',') -n NUMBER Start NUMBER workers that do all tasks -l LOG_FILE Log output to LOG_FILE or use keyword 'syslog' for syslog support -p PID_FILE File to write master process ID out to -r NUMBER Maximum run task iterations per worker -x SECONDS Maximum seconds for a worker to live -t SECONDS Number of seconds gearmand server should wait for a worker to complete work before timing out -v [LEVEL] Increase verbosity level by one. eg: -v vv | -v vvv -h,--help Shows this help information -V,--version Display the version of the manager -D,--dump [all] Parse the command line and config file then dump it to the screen and exit.\n\n EOF; $this->quit($code); }
php
protected function showHelp($msg = '', $code = 0) { $usage = Cli::color('USAGE:', 'brown'); $commands = Cli::color('COMMANDS:', 'brown'); $sOptions = Cli::color('SPECIAL OPTIONS:', 'brown'); $pOptions = Cli::color('PUBLIC OPTIONS:', 'brown'); $version = Cli::color(self::VERSION, 'green'); $script = $this->getScript(); if ($msg) { $code = $code ?: self::CODE_UNKNOWN_ERROR; echo Cli::color('ERROR:', 'light_red') . "\n " . wordwrap($msg, 108, "\n ") . "\n\n"; } echo <<<EOF Gearman worker manager(gwm) script tool. Version $version(lite) $usage $script {COMMAND} -c CONFIG [-v LEVEL] [-l LOG_FILE] [-d] [-w] [-p PID_FILE] $script -h $script -D $commands start Start gearman worker manager(default) stop Stop running's gearman worker manager restart Restart running's gearman worker manager reload Reload all running workers of the manager status Get gearman worker manager runtime status $sOptions start/restart -d,--daemon Daemon, detach and run in the background --tasks Only register the assigned tasks, multi task name separated by commas(',') --no-test Not add test handler, when task name prefix is 'test'.(eg: test_task) status --cmd COMMAND Send command when connect to the task server. allow:status,workers.(default:status) --watch-status Watch status command, will auto refresh status. $pOptions -c CONFIG Load a custom worker manager configuration file -s HOST[:PORT] Connect to server HOST and optional PORT, multi server separated by commas(',') -n NUMBER Start NUMBER workers that do all tasks -l LOG_FILE Log output to LOG_FILE or use keyword 'syslog' for syslog support -p PID_FILE File to write master process ID out to -r NUMBER Maximum run task iterations per worker -x SECONDS Maximum seconds for a worker to live -t SECONDS Number of seconds gearmand server should wait for a worker to complete work before timing out -v [LEVEL] Increase verbosity level by one. eg: -v vv | -v vvv -h,--help Shows this help information -V,--version Display the version of the manager -D,--dump [all] Parse the command line and config file then dump it to the screen and exit.\n\n EOF; $this->quit($code); }
[ "protected", "function", "showHelp", "(", "$", "msg", "=", "''", ",", "$", "code", "=", "0", ")", "{", "$", "usage", "=", "Cli", "::", "color", "(", "'USAGE:'", ",", "'brown'", ")", ";", "$", "commands", "=", "Cli", "::", "color", "(", "'COMMANDS:'", ",", "'brown'", ")", ";", "$", "sOptions", "=", "Cli", "::", "color", "(", "'SPECIAL OPTIONS:'", ",", "'brown'", ")", ";", "$", "pOptions", "=", "Cli", "::", "color", "(", "'PUBLIC OPTIONS:'", ",", "'brown'", ")", ";", "$", "version", "=", "Cli", "::", "color", "(", "self", "::", "VERSION", ",", "'green'", ")", ";", "$", "script", "=", "$", "this", "->", "getScript", "(", ")", ";", "if", "(", "$", "msg", ")", "{", "$", "code", "=", "$", "code", "?", ":", "self", "::", "CODE_UNKNOWN_ERROR", ";", "echo", "Cli", "::", "color", "(", "'ERROR:'", ",", "'light_red'", ")", ".", "\"\\n \"", ".", "wordwrap", "(", "$", "msg", ",", "108", ",", "\"\\n \"", ")", ".", "\"\\n\\n\"", ";", "}", "echo", " <<<EOF\nGearman worker manager(gwm) script tool. Version $version(lite)\n\n$usage\n $script {COMMAND} -c CONFIG [-v LEVEL] [-l LOG_FILE] [-d] [-w] [-p PID_FILE]\n $script -h\n $script -D\n\n$commands\n start Start gearman worker manager(default)\n stop Stop running's gearman worker manager\n restart Restart running's gearman worker manager\n reload Reload all running workers of the manager\n status Get gearman worker manager runtime status\n\n$sOptions\n start/restart\n -d,--daemon Daemon, detach and run in the background\n --tasks Only register the assigned tasks, multi task name separated by commas(',')\n --no-test Not add test handler, when task name prefix is 'test'.(eg: test_task)\n\n status\n --cmd COMMAND Send command when connect to the task server. allow:status,workers.(default:status)\n --watch-status Watch status command, will auto refresh status.\n\n$pOptions\n -c CONFIG Load a custom worker manager configuration file\n -s HOST[:PORT] Connect to server HOST and optional PORT, multi server separated by commas(',')\n\n -n NUMBER Start NUMBER workers that do all tasks\n\n -l LOG_FILE Log output to LOG_FILE or use keyword 'syslog' for syslog support\n -p PID_FILE File to write master process ID out to\n\n -r NUMBER Maximum run task iterations per worker\n -x SECONDS Maximum seconds for a worker to live\n -t SECONDS Number of seconds gearmand server should wait for a worker to complete work before timing out\n\n -v [LEVEL] Increase verbosity level by one. eg: -v vv | -v vvv\n\n -h,--help Shows this help information\n -V,--version Display the version of the manager\n -D,--dump [all] Parse the command line and config file then dump it to the screen and exit.\\n\\n\nEOF", ";", "$", "this", "->", "quit", "(", "$", "code", ")", ";", "}" ]
Shows the scripts help info with optional error message @param string $msg @param int $code The exit code
[ "Shows", "the", "scripts", "help", "info", "with", "optional", "error", "message" ]
8604e037937d31fa2338d79aaf9d0910cb48f559
https://github.com/inhere/php-library-plus/blob/8604e037937d31fa2338d79aaf9d0910cb48f559/libs/Task/Worker/Manager.php#L249-L308
train
groundctrl/discourse-sso-php
src/QueryString.php
QueryString.isValid
public function isValid($key) { if (! isset ($this['sso'], $this['sig'])) { return false; } return $this['sig'] === Secret::create($key)->sign($this['sso']); }
php
public function isValid($key) { if (! isset ($this['sso'], $this['sig'])) { return false; } return $this['sig'] === Secret::create($key)->sign($this['sso']); }
[ "public", "function", "isValid", "(", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "[", "'sso'", "]", ",", "$", "this", "[", "'sig'", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "[", "'sig'", "]", "===", "Secret", "::", "create", "(", "$", "key", ")", "->", "sign", "(", "$", "this", "[", "'sso'", "]", ")", ";", "}" ]
Checks the validity of this QueryString's against a secret key. @param string|Secret $key @return bool
[ "Checks", "the", "validity", "of", "this", "QueryString", "s", "against", "a", "secret", "key", "." ]
8ef1d0ced2e0502b673b25c46aab09cce2efc765
https://github.com/groundctrl/discourse-sso-php/blob/8ef1d0ced2e0502b673b25c46aab09cce2efc765/src/QueryString.php#L11-L18
train
groundctrl/discourse-sso-php
src/QueryString.php
QueryString.fromString
public static function fromString($query, array $data = []) { $url = parse_url($query); $query = isset($url['query']) ? $url['query'] : $url['path']; parse_str($query, $data); return new QueryString($data); }
php
public static function fromString($query, array $data = []) { $url = parse_url($query); $query = isset($url['query']) ? $url['query'] : $url['path']; parse_str($query, $data); return new QueryString($data); }
[ "public", "static", "function", "fromString", "(", "$", "query", ",", "array", "$", "data", "=", "[", "]", ")", "{", "$", "url", "=", "parse_url", "(", "$", "query", ")", ";", "$", "query", "=", "isset", "(", "$", "url", "[", "'query'", "]", ")", "?", "$", "url", "[", "'query'", "]", ":", "$", "url", "[", "'path'", "]", ";", "parse_str", "(", "$", "query", ",", "$", "data", ")", ";", "return", "new", "QueryString", "(", "$", "data", ")", ";", "}" ]
Creates a QueryString from a string. @param string $query A url or query string part. @param array $data An optional data array. @return QueryString
[ "Creates", "a", "QueryString", "from", "a", "string", "." ]
8ef1d0ced2e0502b673b25c46aab09cce2efc765
https://github.com/groundctrl/discourse-sso-php/blob/8ef1d0ced2e0502b673b25c46aab09cce2efc765/src/QueryString.php#L38-L45
train
groundctrl/discourse-sso-php
src/QueryString.php
QueryString.normalize
static public function normalize(array $params) { $qs = http_build_query($params, null, '&'); if ('' == $qs) { return ''; } $parts = array(); $order = array(); foreach (explode('&', $qs) as $param) { if ('' === $param || '=' === $param[0]) { // Ignore useless delimiters, e.g. "x=y&". // Also ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway. // PHP also does not include them when building _GET. continue; } $keyValuePair = explode('=', $param, 2); // GET parameters, that are submitted from a HTML form, encode spaces as "+" by default (as defined in enctype application/x-www-form-urlencoded). // PHP also converts "+" to spaces when filling the global _GET or when using the function parse_str. This is why we use urldecode and then normalize to // RFC 3986 with rawurlencode. $parts[] = isset($keyValuePair[1]) ? rawurlencode(urldecode($keyValuePair[0])).'='.rawurlencode(urldecode($keyValuePair[1])) : rawurlencode(urldecode($keyValuePair[0])); $order[] = urldecode($keyValuePair[0]); } array_multisort($order, SORT_ASC, $parts); return implode('&', $parts); }
php
static public function normalize(array $params) { $qs = http_build_query($params, null, '&'); if ('' == $qs) { return ''; } $parts = array(); $order = array(); foreach (explode('&', $qs) as $param) { if ('' === $param || '=' === $param[0]) { // Ignore useless delimiters, e.g. "x=y&". // Also ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway. // PHP also does not include them when building _GET. continue; } $keyValuePair = explode('=', $param, 2); // GET parameters, that are submitted from a HTML form, encode spaces as "+" by default (as defined in enctype application/x-www-form-urlencoded). // PHP also converts "+" to spaces when filling the global _GET or when using the function parse_str. This is why we use urldecode and then normalize to // RFC 3986 with rawurlencode. $parts[] = isset($keyValuePair[1]) ? rawurlencode(urldecode($keyValuePair[0])).'='.rawurlencode(urldecode($keyValuePair[1])) : rawurlencode(urldecode($keyValuePair[0])); $order[] = urldecode($keyValuePair[0]); } array_multisort($order, SORT_ASC, $parts); return implode('&', $parts); }
[ "static", "public", "function", "normalize", "(", "array", "$", "params", ")", "{", "$", "qs", "=", "http_build_query", "(", "$", "params", ",", "null", ",", "'&'", ")", ";", "if", "(", "''", "==", "$", "qs", ")", "{", "return", "''", ";", "}", "$", "parts", "=", "array", "(", ")", ";", "$", "order", "=", "array", "(", ")", ";", "foreach", "(", "explode", "(", "'&'", ",", "$", "qs", ")", "as", "$", "param", ")", "{", "if", "(", "''", "===", "$", "param", "||", "'='", "===", "$", "param", "[", "0", "]", ")", "{", "// Ignore useless delimiters, e.g. \"x=y&\".", "// Also ignore pairs with empty key, even if there was a value, e.g. \"=value\", as such nameless values cannot be retrieved anyway.", "// PHP also does not include them when building _GET.", "continue", ";", "}", "$", "keyValuePair", "=", "explode", "(", "'='", ",", "$", "param", ",", "2", ")", ";", "// GET parameters, that are submitted from a HTML form, encode spaces as \"+\" by default (as defined in enctype application/x-www-form-urlencoded).", "// PHP also converts \"+\" to spaces when filling the global _GET or when using the function parse_str. This is why we use urldecode and then normalize to", "// RFC 3986 with rawurlencode.", "$", "parts", "[", "]", "=", "isset", "(", "$", "keyValuePair", "[", "1", "]", ")", "?", "rawurlencode", "(", "urldecode", "(", "$", "keyValuePair", "[", "0", "]", ")", ")", ".", "'='", ".", "rawurlencode", "(", "urldecode", "(", "$", "keyValuePair", "[", "1", "]", ")", ")", ":", "rawurlencode", "(", "urldecode", "(", "$", "keyValuePair", "[", "0", "]", ")", ")", ";", "$", "order", "[", "]", "=", "urldecode", "(", "$", "keyValuePair", "[", "0", "]", ")", ";", "}", "array_multisort", "(", "$", "order", ",", "SORT_ASC", ",", "$", "parts", ")", ";", "return", "implode", "(", "'&'", ",", "$", "parts", ")", ";", "}" ]
Builds a normalized query string from the given parameters. This normalization logic comes direct from Symfony's HttpFoundation Component. Since this is the extent of the dependency, let's opt for a bit of code duplication instead. @param array $params @return string
[ "Builds", "a", "normalized", "query", "string", "from", "the", "given", "parameters", "." ]
8ef1d0ced2e0502b673b25c46aab09cce2efc765
https://github.com/groundctrl/discourse-sso-php/blob/8ef1d0ced2e0502b673b25c46aab09cce2efc765/src/QueryString.php#L56-L89
train
phOnion/framework
src/Dependency/CacheAwareContainer.php
CacheAwareContainer.resolveContainer
private function resolveContainer(): ContainerInterface { if ($this->container === null) { $container = $this->containerFactory->build($this); if (!$container instanceof ContainerInterface) { throw new \RuntimeException( "Invalid factory result, expected ContainerInterface" ); } $this->container = $container; } return $this->container; }
php
private function resolveContainer(): ContainerInterface { if ($this->container === null) { $container = $this->containerFactory->build($this); if (!$container instanceof ContainerInterface) { throw new \RuntimeException( "Invalid factory result, expected ContainerInterface" ); } $this->container = $container; } return $this->container; }
[ "private", "function", "resolveContainer", "(", ")", ":", "ContainerInterface", "{", "if", "(", "$", "this", "->", "container", "===", "null", ")", "{", "$", "container", "=", "$", "this", "->", "containerFactory", "->", "build", "(", "$", "this", ")", ";", "if", "(", "!", "$", "container", "instanceof", "ContainerInterface", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Invalid factory result, expected ContainerInterface\"", ")", ";", "}", "$", "this", "->", "container", "=", "$", "container", ";", "}", "return", "$", "this", "->", "container", ";", "}" ]
Instantiate the container if not and return it @return ContainerInterface
[ "Instantiate", "the", "container", "if", "not", "and", "return", "it" ]
eb2d99cc65d3b39faecbfd49b602fb2c62349d05
https://github.com/phOnion/framework/blob/eb2d99cc65d3b39faecbfd49b602fb2c62349d05/src/Dependency/CacheAwareContainer.php#L76-L91
train
Synapse-Cmf/synapse-cmf
src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php
TemplateAdminController.listAction
public function listAction(Request $request) { $theme = $request->attributes->get( 'synapse_theme', $this->container->get('synapse') ->enableDefaultTheme() ->getCurrentTheme() ); $templateCollection = $this->container->get('synapse.template.loader') ->retrieveAll(array( 'scope' => TemplateInterface::GLOBAL_SCOPE, 'templateTypeId' => $theme->getTemplateTypes()->column('id') )) ; $templateMap = array(); foreach ($templateCollection as $template) { $templateMap[$template->getTemplateType()->getName()][$template->getContentType()->getName()] = $template; } return $this->render('SynapseAdminBundle:Template:list.html.twig', array( 'theme' => $theme, 'content_types' => $this->container->get('synapse.content_type.loader') ->retrieveAll(), 'templates' => $templateMap, )); }
php
public function listAction(Request $request) { $theme = $request->attributes->get( 'synapse_theme', $this->container->get('synapse') ->enableDefaultTheme() ->getCurrentTheme() ); $templateCollection = $this->container->get('synapse.template.loader') ->retrieveAll(array( 'scope' => TemplateInterface::GLOBAL_SCOPE, 'templateTypeId' => $theme->getTemplateTypes()->column('id') )) ; $templateMap = array(); foreach ($templateCollection as $template) { $templateMap[$template->getTemplateType()->getName()][$template->getContentType()->getName()] = $template; } return $this->render('SynapseAdminBundle:Template:list.html.twig', array( 'theme' => $theme, 'content_types' => $this->container->get('synapse.content_type.loader') ->retrieveAll(), 'templates' => $templateMap, )); }
[ "public", "function", "listAction", "(", "Request", "$", "request", ")", "{", "$", "theme", "=", "$", "request", "->", "attributes", "->", "get", "(", "'synapse_theme'", ",", "$", "this", "->", "container", "->", "get", "(", "'synapse'", ")", "->", "enableDefaultTheme", "(", ")", "->", "getCurrentTheme", "(", ")", ")", ";", "$", "templateCollection", "=", "$", "this", "->", "container", "->", "get", "(", "'synapse.template.loader'", ")", "->", "retrieveAll", "(", "array", "(", "'scope'", "=>", "TemplateInterface", "::", "GLOBAL_SCOPE", ",", "'templateTypeId'", "=>", "$", "theme", "->", "getTemplateTypes", "(", ")", "->", "column", "(", "'id'", ")", ")", ")", ";", "$", "templateMap", "=", "array", "(", ")", ";", "foreach", "(", "$", "templateCollection", "as", "$", "template", ")", "{", "$", "templateMap", "[", "$", "template", "->", "getTemplateType", "(", ")", "->", "getName", "(", ")", "]", "[", "$", "template", "->", "getContentType", "(", ")", "->", "getName", "(", ")", "]", "=", "$", "template", ";", "}", "return", "$", "this", "->", "render", "(", "'SynapseAdminBundle:Template:list.html.twig'", ",", "array", "(", "'theme'", "=>", "$", "theme", ",", "'content_types'", "=>", "$", "this", "->", "container", "->", "get", "(", "'synapse.content_type.loader'", ")", "->", "retrieveAll", "(", ")", ",", "'templates'", "=>", "$", "templateMap", ",", ")", ")", ";", "}" ]
Templates listing action. @param Request $request @return Response
[ "Templates", "listing", "action", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php#L25-L51
train
Synapse-Cmf/synapse-cmf
src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php
TemplateAdminController.initAction
public function initAction(Request $request, $templateType, $contentType, $contentId = null) { $templateDomain = $this->container->get('synapse.template.domain'); $template = empty($contentId) ? $templateDomain->createGlobal( $contentType, $templateType ) : $templateDomain->createLocal( $this->container->get('synapse.content.resolver')->resolveContentId($contentType, $contentId), $templateType ) ; return new RedirectResponse(empty($contentId) ? $this->container->get('router')->generate('synapse_admin_template_edition', array( 'id' => $template->getId(), )) : $request->server->get('HTTP_REFERER') ); }
php
public function initAction(Request $request, $templateType, $contentType, $contentId = null) { $templateDomain = $this->container->get('synapse.template.domain'); $template = empty($contentId) ? $templateDomain->createGlobal( $contentType, $templateType ) : $templateDomain->createLocal( $this->container->get('synapse.content.resolver')->resolveContentId($contentType, $contentId), $templateType ) ; return new RedirectResponse(empty($contentId) ? $this->container->get('router')->generate('synapse_admin_template_edition', array( 'id' => $template->getId(), )) : $request->server->get('HTTP_REFERER') ); }
[ "public", "function", "initAction", "(", "Request", "$", "request", ",", "$", "templateType", ",", "$", "contentType", ",", "$", "contentId", "=", "null", ")", "{", "$", "templateDomain", "=", "$", "this", "->", "container", "->", "get", "(", "'synapse.template.domain'", ")", ";", "$", "template", "=", "empty", "(", "$", "contentId", ")", "?", "$", "templateDomain", "->", "createGlobal", "(", "$", "contentType", ",", "$", "templateType", ")", ":", "$", "templateDomain", "->", "createLocal", "(", "$", "this", "->", "container", "->", "get", "(", "'synapse.content.resolver'", ")", "->", "resolveContentId", "(", "$", "contentType", ",", "$", "contentId", ")", ",", "$", "templateType", ")", ";", "return", "new", "RedirectResponse", "(", "empty", "(", "$", "contentId", ")", "?", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "generate", "(", "'synapse_admin_template_edition'", ",", "array", "(", "'id'", "=>", "$", "template", "->", "getId", "(", ")", ",", ")", ")", ":", "$", "request", "->", "server", "->", "get", "(", "'HTTP_REFERER'", ")", ")", ";", "}" ]
Template init action. @param Request $request @param string $templateType @param string $contentType @param int $contentId @return Response
[ "Template", "init", "action", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php#L63-L84
train
Synapse-Cmf/synapse-cmf
src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php
TemplateAdminController.editAction
public function editAction($id, Request $request) { $template = $this->container->get('synapse.template.orm_loader') ->retrieveOne(array( 'id' => $id, 'scope' => TemplateInterface::GLOBAL_SCOPE )) ; if (!$template) { throw new NotFoundHttpException(sprintf('No global template found for id "%s"', $id)); } $form = $this->container->get('form.factory')->createNamed( 'template', TemplateType::class, $template, array( 'theme' => $request->attributes->get( 'synapse_theme', $this->container->get('synapse') ->enableDefaultTheme() ->getCurrentTheme() ), 'content_type' => $template->getContentType(), 'template_type' => $template->getTemplateType(), 'action' => $formUrl = $this->container->get('router')->generate( 'synapse_admin_template_edition', array('id' => $template->getId()) ), 'method' => 'POST', 'csrf_protection' => false, ) ); if ($request->request->has('template')) { $form->handleRequest($request); if ($form->isValid()) { return $this->redirect( $this->container->get('router')->generate( 'synapse_admin_template_edition', array('id' => $template->getId()) ) ); } } return $this->render('SynapseAdminBundle:Template:edit.html.twig', array( 'template' => $template, 'form' => $form->createView(), )); }
php
public function editAction($id, Request $request) { $template = $this->container->get('synapse.template.orm_loader') ->retrieveOne(array( 'id' => $id, 'scope' => TemplateInterface::GLOBAL_SCOPE )) ; if (!$template) { throw new NotFoundHttpException(sprintf('No global template found for id "%s"', $id)); } $form = $this->container->get('form.factory')->createNamed( 'template', TemplateType::class, $template, array( 'theme' => $request->attributes->get( 'synapse_theme', $this->container->get('synapse') ->enableDefaultTheme() ->getCurrentTheme() ), 'content_type' => $template->getContentType(), 'template_type' => $template->getTemplateType(), 'action' => $formUrl = $this->container->get('router')->generate( 'synapse_admin_template_edition', array('id' => $template->getId()) ), 'method' => 'POST', 'csrf_protection' => false, ) ); if ($request->request->has('template')) { $form->handleRequest($request); if ($form->isValid()) { return $this->redirect( $this->container->get('router')->generate( 'synapse_admin_template_edition', array('id' => $template->getId()) ) ); } } return $this->render('SynapseAdminBundle:Template:edit.html.twig', array( 'template' => $template, 'form' => $form->createView(), )); }
[ "public", "function", "editAction", "(", "$", "id", ",", "Request", "$", "request", ")", "{", "$", "template", "=", "$", "this", "->", "container", "->", "get", "(", "'synapse.template.orm_loader'", ")", "->", "retrieveOne", "(", "array", "(", "'id'", "=>", "$", "id", ",", "'scope'", "=>", "TemplateInterface", "::", "GLOBAL_SCOPE", ")", ")", ";", "if", "(", "!", "$", "template", ")", "{", "throw", "new", "NotFoundHttpException", "(", "sprintf", "(", "'No global template found for id \"%s\"'", ",", "$", "id", ")", ")", ";", "}", "$", "form", "=", "$", "this", "->", "container", "->", "get", "(", "'form.factory'", ")", "->", "createNamed", "(", "'template'", ",", "TemplateType", "::", "class", ",", "$", "template", ",", "array", "(", "'theme'", "=>", "$", "request", "->", "attributes", "->", "get", "(", "'synapse_theme'", ",", "$", "this", "->", "container", "->", "get", "(", "'synapse'", ")", "->", "enableDefaultTheme", "(", ")", "->", "getCurrentTheme", "(", ")", ")", ",", "'content_type'", "=>", "$", "template", "->", "getContentType", "(", ")", ",", "'template_type'", "=>", "$", "template", "->", "getTemplateType", "(", ")", ",", "'action'", "=>", "$", "formUrl", "=", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "generate", "(", "'synapse_admin_template_edition'", ",", "array", "(", "'id'", "=>", "$", "template", "->", "getId", "(", ")", ")", ")", ",", "'method'", "=>", "'POST'", ",", "'csrf_protection'", "=>", "false", ",", ")", ")", ";", "if", "(", "$", "request", "->", "request", "->", "has", "(", "'template'", ")", ")", "{", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "generate", "(", "'synapse_admin_template_edition'", ",", "array", "(", "'id'", "=>", "$", "template", "->", "getId", "(", ")", ")", ")", ")", ";", "}", "}", "return", "$", "this", "->", "render", "(", "'SynapseAdminBundle:Template:edit.html.twig'", ",", "array", "(", "'template'", "=>", "$", "template", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ")", ";", "}" ]
Global template edition action. Requires an activated or activable theme. @param Request $request @return Response
[ "Global", "template", "edition", "action", ".", "Requires", "an", "activated", "or", "activable", "theme", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php#L94-L143
train
Synapse-Cmf/synapse-cmf
src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php
TemplateAdminController.addComponentAction
public function addComponentAction($id, $zoneTypeId, $componentTypeId, Request $request) { if (!$template = $this->container->get('synapse.template.loader')->retrieve($id)) { throw new NotFoundHttpException(sprintf('No template found under id "%s"', $id)); } if (!$zoneType = $template->getTemplateType() ->getZoneTypes() ->search(array('id' => $zoneTypeId)) ->first() ) { throw new NotFoundHttpException(sprintf( 'Zone type "%s" is not activated for template "%s". Please check theme configuration.', $zoneTypeId, $templateType->getId() )); } if (!$componentType = $this->container->get('synapse.component_type.loader')->retrieve($componentTypeId)) { throw new NotFoundHttpException(sprintf( 'No defined component type found under id "%s". Please check theme configuration.', $componentTypeId )); } $this->container->get('synapse.zone.domain')->addComponent( $template->getZones()->search(array('zoneType' => $zoneType))->first(), $componentType ); return new RedirectResponse( $request->server->get('HTTP_REFERER') ); }
php
public function addComponentAction($id, $zoneTypeId, $componentTypeId, Request $request) { if (!$template = $this->container->get('synapse.template.loader')->retrieve($id)) { throw new NotFoundHttpException(sprintf('No template found under id "%s"', $id)); } if (!$zoneType = $template->getTemplateType() ->getZoneTypes() ->search(array('id' => $zoneTypeId)) ->first() ) { throw new NotFoundHttpException(sprintf( 'Zone type "%s" is not activated for template "%s". Please check theme configuration.', $zoneTypeId, $templateType->getId() )); } if (!$componentType = $this->container->get('synapse.component_type.loader')->retrieve($componentTypeId)) { throw new NotFoundHttpException(sprintf( 'No defined component type found under id "%s". Please check theme configuration.', $componentTypeId )); } $this->container->get('synapse.zone.domain')->addComponent( $template->getZones()->search(array('zoneType' => $zoneType))->first(), $componentType ); return new RedirectResponse( $request->server->get('HTTP_REFERER') ); }
[ "public", "function", "addComponentAction", "(", "$", "id", ",", "$", "zoneTypeId", ",", "$", "componentTypeId", ",", "Request", "$", "request", ")", "{", "if", "(", "!", "$", "template", "=", "$", "this", "->", "container", "->", "get", "(", "'synapse.template.loader'", ")", "->", "retrieve", "(", "$", "id", ")", ")", "{", "throw", "new", "NotFoundHttpException", "(", "sprintf", "(", "'No template found under id \"%s\"'", ",", "$", "id", ")", ")", ";", "}", "if", "(", "!", "$", "zoneType", "=", "$", "template", "->", "getTemplateType", "(", ")", "->", "getZoneTypes", "(", ")", "->", "search", "(", "array", "(", "'id'", "=>", "$", "zoneTypeId", ")", ")", "->", "first", "(", ")", ")", "{", "throw", "new", "NotFoundHttpException", "(", "sprintf", "(", "'Zone type \"%s\" is not activated for template \"%s\". Please check theme configuration.'", ",", "$", "zoneTypeId", ",", "$", "templateType", "->", "getId", "(", ")", ")", ")", ";", "}", "if", "(", "!", "$", "componentType", "=", "$", "this", "->", "container", "->", "get", "(", "'synapse.component_type.loader'", ")", "->", "retrieve", "(", "$", "componentTypeId", ")", ")", "{", "throw", "new", "NotFoundHttpException", "(", "sprintf", "(", "'No defined component type found under id \"%s\". Please check theme configuration.'", ",", "$", "componentTypeId", ")", ")", ";", "}", "$", "this", "->", "container", "->", "get", "(", "'synapse.zone.domain'", ")", "->", "addComponent", "(", "$", "template", "->", "getZones", "(", ")", "->", "search", "(", "array", "(", "'zoneType'", "=>", "$", "zoneType", ")", ")", "->", "first", "(", ")", ",", "$", "componentType", ")", ";", "return", "new", "RedirectResponse", "(", "$", "request", "->", "server", "->", "get", "(", "'HTTP_REFERER'", ")", ")", ";", "}" ]
Adds a component of given type id into given template id and zone type id. @param int $id @param string $zoneTypeId @param string $componentTypeId @param Request $request @return Response
[ "Adds", "a", "component", "of", "given", "type", "id", "into", "given", "template", "id", "and", "zone", "type", "id", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Admin/Bundle/Controller/TemplateAdminController.php#L155-L186
train
hal-platform/hal-core
src/Repository/EnvironmentRepository.php
EnvironmentRepository.getBuildableEnvironmentsByApplication
public function getBuildableEnvironmentsByApplication(Application $application) { $region = sprintf(self::ENV_QUERY_REGION, $application->id()); $dql = sprintf(self::DQL_BY_APPLICATION, Target::class, Environment::class); $query = $this->getEntityManager() ->createQuery($dql) ->setCacheable(true) ->setCacheRegion($region) ->setParameter('application', $application); $environments = $query->getResult(); usort($environments, $this->environmentSorter()); return $environments; }
php
public function getBuildableEnvironmentsByApplication(Application $application) { $region = sprintf(self::ENV_QUERY_REGION, $application->id()); $dql = sprintf(self::DQL_BY_APPLICATION, Target::class, Environment::class); $query = $this->getEntityManager() ->createQuery($dql) ->setCacheable(true) ->setCacheRegion($region) ->setParameter('application', $application); $environments = $query->getResult(); usort($environments, $this->environmentSorter()); return $environments; }
[ "public", "function", "getBuildableEnvironmentsByApplication", "(", "Application", "$", "application", ")", "{", "$", "region", "=", "sprintf", "(", "self", "::", "ENV_QUERY_REGION", ",", "$", "application", "->", "id", "(", ")", ")", ";", "$", "dql", "=", "sprintf", "(", "self", "::", "DQL_BY_APPLICATION", ",", "Target", "::", "class", ",", "Environment", "::", "class", ")", ";", "$", "query", "=", "$", "this", "->", "getEntityManager", "(", ")", "->", "createQuery", "(", "$", "dql", ")", "->", "setCacheable", "(", "true", ")", "->", "setCacheRegion", "(", "$", "region", ")", "->", "setParameter", "(", "'application'", ",", "$", "application", ")", ";", "$", "environments", "=", "$", "query", "->", "getResult", "(", ")", ";", "usort", "(", "$", "environments", ",", "$", "this", "->", "environmentSorter", "(", ")", ")", ";", "return", "$", "environments", ";", "}" ]
Get all buildable environments for an application. @param Application $application @return Environment[]
[ "Get", "all", "buildable", "environments", "for", "an", "application", "." ]
30d456f8392fc873301ad4217d2ae90436c67090
https://github.com/hal-platform/hal-core/blob/30d456f8392fc873301ad4217d2ae90436c67090/src/Repository/EnvironmentRepository.php#L38-L55
train
hal-platform/hal-core
src/Repository/EnvironmentRepository.php
EnvironmentRepository.clearBuildableEnvironmentsByApplication
public function clearBuildableEnvironmentsByApplication(Application $application) { $region = sprintf(self::ENV_QUERY_REGION, $application->id()); $cache = $this ->getEntityManager() ->getCache(); $cache ->getQueryCache($region) ->clear(); }
php
public function clearBuildableEnvironmentsByApplication(Application $application) { $region = sprintf(self::ENV_QUERY_REGION, $application->id()); $cache = $this ->getEntityManager() ->getCache(); $cache ->getQueryCache($region) ->clear(); }
[ "public", "function", "clearBuildableEnvironmentsByApplication", "(", "Application", "$", "application", ")", "{", "$", "region", "=", "sprintf", "(", "self", "::", "ENV_QUERY_REGION", ",", "$", "application", "->", "id", "(", ")", ")", ";", "$", "cache", "=", "$", "this", "->", "getEntityManager", "(", ")", "->", "getCache", "(", ")", ";", "$", "cache", "->", "getQueryCache", "(", "$", "region", ")", "->", "clear", "(", ")", ";", "}" ]
Clear cache for buildable environments for an application. @param Application $application @return void
[ "Clear", "cache", "for", "buildable", "environments", "for", "an", "application", "." ]
30d456f8392fc873301ad4217d2ae90436c67090
https://github.com/hal-platform/hal-core/blob/30d456f8392fc873301ad4217d2ae90436c67090/src/Repository/EnvironmentRepository.php#L64-L75
train
CodeCollab/Http
src/Response/Response.php
Response.addCookie
public function addCookie(string $key, $value, \DateTimeInterface $expire) { $this->cookies[$key] = $this->cookieFactory->build($key, $value, $expire); }
php
public function addCookie(string $key, $value, \DateTimeInterface $expire) { $this->cookies[$key] = $this->cookieFactory->build($key, $value, $expire); }
[ "public", "function", "addCookie", "(", "string", "$", "key", ",", "$", "value", ",", "\\", "DateTimeInterface", "$", "expire", ")", "{", "$", "this", "->", "cookies", "[", "$", "key", "]", "=", "$", "this", "->", "cookieFactory", "->", "build", "(", "$", "key", ",", "$", "value", ",", "$", "expire", ")", ";", "}" ]
Adds a cookie @param string $key The name of the cookie @param mixed $value The value pf the cookie @param \DateTimeInterface $expire The expiration date
[ "Adds", "a", "cookie" ]
b1f8306b20daebcf26ed4b13c032c5bc008a0861
https://github.com/CodeCollab/Http/blob/b1f8306b20daebcf26ed4b13c032c5bc008a0861/src/Response/Response.php#L127-L130
train
CodeCollab/Http
src/Response/Response.php
Response.send
public function send() { $this->sendCookies(); $this->sendHeaders(); if ($this->request->server('REQUEST_METHOD') === 'HEAD') { return ''; } echo $this->body; }
php
public function send() { $this->sendCookies(); $this->sendHeaders(); if ($this->request->server('REQUEST_METHOD') === 'HEAD') { return ''; } echo $this->body; }
[ "public", "function", "send", "(", ")", "{", "$", "this", "->", "sendCookies", "(", ")", ";", "$", "this", "->", "sendHeaders", "(", ")", ";", "if", "(", "$", "this", "->", "request", "->", "server", "(", "'REQUEST_METHOD'", ")", "===", "'HEAD'", ")", "{", "return", "''", ";", "}", "echo", "$", "this", "->", "body", ";", "}" ]
Sends the response to the client
[ "Sends", "the", "response", "to", "the", "client" ]
b1f8306b20daebcf26ed4b13c032c5bc008a0861
https://github.com/CodeCollab/Http/blob/b1f8306b20daebcf26ed4b13c032c5bc008a0861/src/Response/Response.php#L135-L146
train
CodeCollab/Http
src/Response/Response.php
Response.sendHeaders
private function sendHeaders() { if (!array_key_exists('Content-Type', $this->headers)) { $this->headers['Content-Type'] = 'text/html; charset=UTF-8'; } $this->headers['Content-Length'] = strlen($this->body); header( sprintf( 'HTTP/%s %s %s', $this->request->server('SERVER_PROTOCOL'), $this->numericStatusCode, $this->textualStatusCode ?: $this->statusCode->getText($this->numericStatusCode) ), true, $this->numericStatusCode ); foreach ($this->headers as $key => $value) { header(sprintf('%s: %s', $key, $value)); } }
php
private function sendHeaders() { if (!array_key_exists('Content-Type', $this->headers)) { $this->headers['Content-Type'] = 'text/html; charset=UTF-8'; } $this->headers['Content-Length'] = strlen($this->body); header( sprintf( 'HTTP/%s %s %s', $this->request->server('SERVER_PROTOCOL'), $this->numericStatusCode, $this->textualStatusCode ?: $this->statusCode->getText($this->numericStatusCode) ), true, $this->numericStatusCode ); foreach ($this->headers as $key => $value) { header(sprintf('%s: %s', $key, $value)); } }
[ "private", "function", "sendHeaders", "(", ")", "{", "if", "(", "!", "array_key_exists", "(", "'Content-Type'", ",", "$", "this", "->", "headers", ")", ")", "{", "$", "this", "->", "headers", "[", "'Content-Type'", "]", "=", "'text/html; charset=UTF-8'", ";", "}", "$", "this", "->", "headers", "[", "'Content-Length'", "]", "=", "strlen", "(", "$", "this", "->", "body", ")", ";", "header", "(", "sprintf", "(", "'HTTP/%s %s %s'", ",", "$", "this", "->", "request", "->", "server", "(", "'SERVER_PROTOCOL'", ")", ",", "$", "this", "->", "numericStatusCode", ",", "$", "this", "->", "textualStatusCode", "?", ":", "$", "this", "->", "statusCode", "->", "getText", "(", "$", "this", "->", "numericStatusCode", ")", ")", ",", "true", ",", "$", "this", "->", "numericStatusCode", ")", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "key", "=>", "$", "value", ")", "{", "header", "(", "sprintf", "(", "'%s: %s'", ",", "$", "key", ",", "$", "value", ")", ")", ";", "}", "}" ]
Sends the headers to the client
[ "Sends", "the", "headers", "to", "the", "client" ]
b1f8306b20daebcf26ed4b13c032c5bc008a0861
https://github.com/CodeCollab/Http/blob/b1f8306b20daebcf26ed4b13c032c5bc008a0861/src/Response/Response.php#L161-L183
train
3ev/wordpress-core
src/Tev/Post/Model/Attachment.php
Attachment.getImageUrl
public function getImageUrl($size = 'thumbnail') { $res = wp_get_attachment_image_src($this->getId(), $size); return $res && isset($res[0]) ? $res[0] : null; }
php
public function getImageUrl($size = 'thumbnail') { $res = wp_get_attachment_image_src($this->getId(), $size); return $res && isset($res[0]) ? $res[0] : null; }
[ "public", "function", "getImageUrl", "(", "$", "size", "=", "'thumbnail'", ")", "{", "$", "res", "=", "wp_get_attachment_image_src", "(", "$", "this", "->", "getId", "(", ")", ",", "$", "size", ")", ";", "return", "$", "res", "&&", "isset", "(", "$", "res", "[", "0", "]", ")", "?", "$", "res", "[", "0", "]", ":", "null", ";", "}" ]
Get attachment image URL. @param mixed $size Arguments accepted by second param of wp_get_attachment_image_src() @return string|null Image URL or null if not found
[ "Get", "attachment", "image", "URL", "." ]
da674fbec5bf3d5bd2a2141680a4c141113eb6b0
https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Post/Model/Attachment.php#L36-L40
train
chilimatic/chilimatic-framework
lib/handler/memory/shmop/Entry.php
Entry.save
public function save() { if ($this->id) { $this->id = shmop_open($this->key, $this->mode, $this->permission, $this->size); } @shmop_write($this->id, serialize($this->data), $this->offset); return true; }
php
public function save() { if ($this->id) { $this->id = shmop_open($this->key, $this->mode, $this->permission, $this->size); } @shmop_write($this->id, serialize($this->data), $this->offset); return true; }
[ "public", "function", "save", "(", ")", "{", "if", "(", "$", "this", "->", "id", ")", "{", "$", "this", "->", "id", "=", "shmop_open", "(", "$", "this", "->", "key", ",", "$", "this", "->", "mode", ",", "$", "this", "->", "permission", ",", "$", "this", "->", "size", ")", ";", "}", "@", "shmop_write", "(", "$", "this", "->", "id", ",", "serialize", "(", "$", "this", "->", "data", ")", ",", "$", "this", "->", "offset", ")", ";", "return", "true", ";", "}" ]
saves the data of an entry @return boolean
[ "saves", "the", "data", "of", "an", "entry" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/handler/memory/shmop/Entry.php#L160-L170
train
chilimatic/chilimatic-framework
lib/handler/memory/shmop/Entry.php
Entry.delete
public function delete() { if (empty($this->id)) { $this->id = shmop_open($this->key, $this->mode, $this->permission, $this->size); } @shmop_delete($this->id); @shmop_close($this->id); return true; }
php
public function delete() { if (empty($this->id)) { $this->id = shmop_open($this->key, $this->mode, $this->permission, $this->size); } @shmop_delete($this->id); @shmop_close($this->id); return true; }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "id", ")", ")", "{", "$", "this", "->", "id", "=", "shmop_open", "(", "$", "this", "->", "key", ",", "$", "this", "->", "mode", ",", "$", "this", "->", "permission", ",", "$", "this", "->", "size", ")", ";", "}", "@", "shmop_delete", "(", "$", "this", "->", "id", ")", ";", "@", "shmop_close", "(", "$", "this", "->", "id", ")", ";", "return", "true", ";", "}" ]
deletes the entry @return boolean
[ "deletes", "the", "entry" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/handler/memory/shmop/Entry.php#L209-L219
train
awurth/SlimValidationREST
Validator.php
Validator.validate
public function validate(Request $request, array $rules, array $messages = []) { foreach ($rules as $param => $options) { $value = $request->getParam($param); $this->data[$param] = $value; $isRule = $options instanceof V; try { if ($isRule) { $options->assert($value); } else { if (!isset($options['rules']) || !($options['rules'] instanceof V)) { throw new InvalidArgumentException('Validation rules are missing'); } $options['rules']->assert($value); } } catch (NestedValidationException $e) { $paramRules = $isRule ? $options->getRules() : $options['rules']->getRules(); // Get the names of all rules used for this param $rulesNames = []; foreach ($paramRules as $rule) { $rulesNames[] = lcfirst((new ReflectionClass($rule))->getShortName()); } // If the 'message' key exists, set it as only message for this param if (!$isRule && isset($options['message']) && is_string($options['message'])) { $this->errors[$param] = [$options['message']]; return $this; } else { // If the 'messages' key exists, override global messages $params = [ $e->findMessages($rulesNames) ]; // If default messages are defined if (!empty($this->defaultMessages)) { $params[] = $e->findMessages($this->defaultMessages); } // If global messages are defined if (!empty($messages)) { $params[] = $e->findMessages($messages); } // If individual messages are defined if (!$isRule && isset($options['messages'])) { $params[] = $e->findMessages($options['messages']); } $this->errors[$param] = array_values(array_filter(call_user_func_array('array_merge', $params))); } } } return $this; }
php
public function validate(Request $request, array $rules, array $messages = []) { foreach ($rules as $param => $options) { $value = $request->getParam($param); $this->data[$param] = $value; $isRule = $options instanceof V; try { if ($isRule) { $options->assert($value); } else { if (!isset($options['rules']) || !($options['rules'] instanceof V)) { throw new InvalidArgumentException('Validation rules are missing'); } $options['rules']->assert($value); } } catch (NestedValidationException $e) { $paramRules = $isRule ? $options->getRules() : $options['rules']->getRules(); // Get the names of all rules used for this param $rulesNames = []; foreach ($paramRules as $rule) { $rulesNames[] = lcfirst((new ReflectionClass($rule))->getShortName()); } // If the 'message' key exists, set it as only message for this param if (!$isRule && isset($options['message']) && is_string($options['message'])) { $this->errors[$param] = [$options['message']]; return $this; } else { // If the 'messages' key exists, override global messages $params = [ $e->findMessages($rulesNames) ]; // If default messages are defined if (!empty($this->defaultMessages)) { $params[] = $e->findMessages($this->defaultMessages); } // If global messages are defined if (!empty($messages)) { $params[] = $e->findMessages($messages); } // If individual messages are defined if (!$isRule && isset($options['messages'])) { $params[] = $e->findMessages($options['messages']); } $this->errors[$param] = array_values(array_filter(call_user_func_array('array_merge', $params))); } } } return $this; }
[ "public", "function", "validate", "(", "Request", "$", "request", ",", "array", "$", "rules", ",", "array", "$", "messages", "=", "[", "]", ")", "{", "foreach", "(", "$", "rules", "as", "$", "param", "=>", "$", "options", ")", "{", "$", "value", "=", "$", "request", "->", "getParam", "(", "$", "param", ")", ";", "$", "this", "->", "data", "[", "$", "param", "]", "=", "$", "value", ";", "$", "isRule", "=", "$", "options", "instanceof", "V", ";", "try", "{", "if", "(", "$", "isRule", ")", "{", "$", "options", "->", "assert", "(", "$", "value", ")", ";", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'rules'", "]", ")", "||", "!", "(", "$", "options", "[", "'rules'", "]", "instanceof", "V", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Validation rules are missing'", ")", ";", "}", "$", "options", "[", "'rules'", "]", "->", "assert", "(", "$", "value", ")", ";", "}", "}", "catch", "(", "NestedValidationException", "$", "e", ")", "{", "$", "paramRules", "=", "$", "isRule", "?", "$", "options", "->", "getRules", "(", ")", ":", "$", "options", "[", "'rules'", "]", "->", "getRules", "(", ")", ";", "// Get the names of all rules used for this param", "$", "rulesNames", "=", "[", "]", ";", "foreach", "(", "$", "paramRules", "as", "$", "rule", ")", "{", "$", "rulesNames", "[", "]", "=", "lcfirst", "(", "(", "new", "ReflectionClass", "(", "$", "rule", ")", ")", "->", "getShortName", "(", ")", ")", ";", "}", "// If the 'message' key exists, set it as only message for this param", "if", "(", "!", "$", "isRule", "&&", "isset", "(", "$", "options", "[", "'message'", "]", ")", "&&", "is_string", "(", "$", "options", "[", "'message'", "]", ")", ")", "{", "$", "this", "->", "errors", "[", "$", "param", "]", "=", "[", "$", "options", "[", "'message'", "]", "]", ";", "return", "$", "this", ";", "}", "else", "{", "// If the 'messages' key exists, override global messages", "$", "params", "=", "[", "$", "e", "->", "findMessages", "(", "$", "rulesNames", ")", "]", ";", "// If default messages are defined", "if", "(", "!", "empty", "(", "$", "this", "->", "defaultMessages", ")", ")", "{", "$", "params", "[", "]", "=", "$", "e", "->", "findMessages", "(", "$", "this", "->", "defaultMessages", ")", ";", "}", "// If global messages are defined", "if", "(", "!", "empty", "(", "$", "messages", ")", ")", "{", "$", "params", "[", "]", "=", "$", "e", "->", "findMessages", "(", "$", "messages", ")", ";", "}", "// If individual messages are defined", "if", "(", "!", "$", "isRule", "&&", "isset", "(", "$", "options", "[", "'messages'", "]", ")", ")", "{", "$", "params", "[", "]", "=", "$", "e", "->", "findMessages", "(", "$", "options", "[", "'messages'", "]", ")", ";", "}", "$", "this", "->", "errors", "[", "$", "param", "]", "=", "array_values", "(", "array_filter", "(", "call_user_func_array", "(", "'array_merge'", ",", "$", "params", ")", ")", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Validate request params with the given rules @param Request $request @param array $rules @param array $messages @return $this
[ "Validate", "request", "params", "with", "the", "given", "rules" ]
e1e715b880acc43b963d2bad660a00f68499dfea
https://github.com/awurth/SlimValidationREST/blob/e1e715b880acc43b963d2bad660a00f68499dfea/Validator.php#L56-L112
train
awurth/SlimValidationREST
Validator.php
Validator.addErrors
public function addErrors($param, array $messages) { foreach ($messages as $message) { $this->errors[$param][] = $message; } return $this; }
php
public function addErrors($param, array $messages) { foreach ($messages as $message) { $this->errors[$param][] = $message; } return $this; }
[ "public", "function", "addErrors", "(", "$", "param", ",", "array", "$", "messages", ")", "{", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "this", "->", "errors", "[", "$", "param", "]", "[", "]", "=", "$", "message", ";", "}", "return", "$", "this", ";", "}" ]
Add errors for param @param string $param @param array $messages @return $this
[ "Add", "errors", "for", "param" ]
e1e715b880acc43b963d2bad660a00f68499dfea
https://github.com/awurth/SlimValidationREST/blob/e1e715b880acc43b963d2bad660a00f68499dfea/Validator.php#L134-L141
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.setDelay
public function setDelay($delay) { if (is_string($delay) && ctype_digit($delay)) { $delay = (int) $delay; } elseif (!is_int($delay)) { throw new \RuntimeException('Delay should be an integer in MS.'); } $this->delay = $delay; return $this; }
php
public function setDelay($delay) { if (is_string($delay) && ctype_digit($delay)) { $delay = (int) $delay; } elseif (!is_int($delay)) { throw new \RuntimeException('Delay should be an integer in MS.'); } $this->delay = $delay; return $this; }
[ "public", "function", "setDelay", "(", "$", "delay", ")", "{", "if", "(", "is_string", "(", "$", "delay", ")", "&&", "ctype_digit", "(", "$", "delay", ")", ")", "{", "$", "delay", "=", "(", "int", ")", "$", "delay", ";", "}", "elseif", "(", "!", "is_int", "(", "$", "delay", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Delay should be an integer in MS.'", ")", ";", "}", "$", "this", "->", "delay", "=", "$", "delay", ";", "return", "$", "this", ";", "}" ]
Defines how long the client should wait for the AlphaRPC instances to respond. If the time is reached the next AlphaRPC instance will be asked to execute the request. @param integer $delay @return Client @throws \RuntimeException
[ "Defines", "how", "long", "the", "client", "should", "wait", "for", "the", "AlphaRPC", "instances", "to", "respond", ".", "If", "the", "time", "is", "reached", "the", "next", "AlphaRPC", "instance", "will", "be", "asked", "to", "execute", "the", "request", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L132-L143
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.setTimeout
public function setTimeout($timeout) { if (is_string($timeout) && ctype_digit($timeout)) { $timeout = (int) $timeout; } elseif (!is_int($timeout)) { throw new \RuntimeException('Unable to set timeout.'); } $this->timeout = $timeout; return $this; }
php
public function setTimeout($timeout) { if (is_string($timeout) && ctype_digit($timeout)) { $timeout = (int) $timeout; } elseif (!is_int($timeout)) { throw new \RuntimeException('Unable to set timeout.'); } $this->timeout = $timeout; return $this; }
[ "public", "function", "setTimeout", "(", "$", "timeout", ")", "{", "if", "(", "is_string", "(", "$", "timeout", ")", "&&", "ctype_digit", "(", "$", "timeout", ")", ")", "{", "$", "timeout", "=", "(", "int", ")", "$", "timeout", ";", "}", "elseif", "(", "!", "is_int", "(", "$", "timeout", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to set timeout.'", ")", ";", "}", "$", "this", "->", "timeout", "=", "$", "timeout", ";", "return", "$", "this", ";", "}" ]
Sets the timeout in MS. @param int $timeout @return Client @throws \RuntimeException
[ "Sets", "the", "timeout", "in", "MS", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L197-L207
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.addManager
public function addManager($manager) { if (is_array($manager)) { foreach ($manager as $item) { $this->managerList->add($item); } return $this; } $this->managerList->add($manager); return $this; }
php
public function addManager($manager) { if (is_array($manager)) { foreach ($manager as $item) { $this->managerList->add($item); } return $this; } $this->managerList->add($manager); return $this; }
[ "public", "function", "addManager", "(", "$", "manager", ")", "{", "if", "(", "is_array", "(", "$", "manager", ")", ")", "{", "foreach", "(", "$", "manager", "as", "$", "item", ")", "{", "$", "this", "->", "managerList", "->", "add", "(", "$", "item", ")", ";", "}", "return", "$", "this", ";", "}", "$", "this", "->", "managerList", "->", "add", "(", "$", "manager", ")", ";", "return", "$", "this", ";", "}" ]
Adds an address to a AlphaRPC daemon. @param string|array $manager @return Client @throws \InvalidArgumentException
[ "Adds", "an", "address", "to", "a", "AlphaRPC", "daemon", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L217-L230
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.startRequest
public function startRequest($function, array $params = array(), $cache = null) { if ($cache !== null && !is_string($cache)) { throw new \RuntimeException('$cache is an id for the request and should be a string or null.'); } $request = new Request($function, $params); $prioritizedManagerList = $this->managerList->toPrioritizedArray(); foreach ($prioritizedManagerList as $manager) { try { $response = $this->sendExecuteRequest($manager, $request, $cache); $request->setManager($manager); $request->setRequestId($response->getRequestId()); $this->managerList->flag($manager, ManagerList::FLAG_AVAILABLE); $this->getLogger()->debug($manager.' accepted request '.$response->getRequestId().' '.$request->getFunction()); return $request; } catch (TimeoutException $ex) { $this->managerList->flag($manager, ManagerList::FLAG_UNAVAILABLE); $this->getLogger()->notice($manager.': '.$ex->getMessage()); } } throw new RuntimeException('AlphaRPC ('.implode(', ', $prioritizedManagerList).') did not respond in time.'); }
php
public function startRequest($function, array $params = array(), $cache = null) { if ($cache !== null && !is_string($cache)) { throw new \RuntimeException('$cache is an id for the request and should be a string or null.'); } $request = new Request($function, $params); $prioritizedManagerList = $this->managerList->toPrioritizedArray(); foreach ($prioritizedManagerList as $manager) { try { $response = $this->sendExecuteRequest($manager, $request, $cache); $request->setManager($manager); $request->setRequestId($response->getRequestId()); $this->managerList->flag($manager, ManagerList::FLAG_AVAILABLE); $this->getLogger()->debug($manager.' accepted request '.$response->getRequestId().' '.$request->getFunction()); return $request; } catch (TimeoutException $ex) { $this->managerList->flag($manager, ManagerList::FLAG_UNAVAILABLE); $this->getLogger()->notice($manager.': '.$ex->getMessage()); } } throw new RuntimeException('AlphaRPC ('.implode(', ', $prioritizedManagerList).') did not respond in time.'); }
[ "public", "function", "startRequest", "(", "$", "function", ",", "array", "$", "params", "=", "array", "(", ")", ",", "$", "cache", "=", "null", ")", "{", "if", "(", "$", "cache", "!==", "null", "&&", "!", "is_string", "(", "$", "cache", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'$cache is an id for the request and should be a string or null.'", ")", ";", "}", "$", "request", "=", "new", "Request", "(", "$", "function", ",", "$", "params", ")", ";", "$", "prioritizedManagerList", "=", "$", "this", "->", "managerList", "->", "toPrioritizedArray", "(", ")", ";", "foreach", "(", "$", "prioritizedManagerList", "as", "$", "manager", ")", "{", "try", "{", "$", "response", "=", "$", "this", "->", "sendExecuteRequest", "(", "$", "manager", ",", "$", "request", ",", "$", "cache", ")", ";", "$", "request", "->", "setManager", "(", "$", "manager", ")", ";", "$", "request", "->", "setRequestId", "(", "$", "response", "->", "getRequestId", "(", ")", ")", ";", "$", "this", "->", "managerList", "->", "flag", "(", "$", "manager", ",", "ManagerList", "::", "FLAG_AVAILABLE", ")", ";", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "$", "manager", ".", "' accepted request '", ".", "$", "response", "->", "getRequestId", "(", ")", ".", "' '", ".", "$", "request", "->", "getFunction", "(", ")", ")", ";", "return", "$", "request", ";", "}", "catch", "(", "TimeoutException", "$", "ex", ")", "{", "$", "this", "->", "managerList", "->", "flag", "(", "$", "manager", ",", "ManagerList", "::", "FLAG_UNAVAILABLE", ")", ";", "$", "this", "->", "getLogger", "(", ")", "->", "notice", "(", "$", "manager", ".", "': '", ".", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}", "throw", "new", "RuntimeException", "(", "'AlphaRPC ('", ".", "implode", "(", "', '", ",", "$", "prioritizedManagerList", ")", ".", "') did not respond in time.'", ")", ";", "}" ]
Starts a request. @param string $function @param array $params @param string $cache @return Request @throws \RuntimeException
[ "Starts", "a", "request", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L242-L270
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.request
public function request($function, array $params = array(), $cache = null) { $request = $this->startRequest($function, $params, $cache); return $this->fetchResponse($request); }
php
public function request($function, array $params = array(), $cache = null) { $request = $this->startRequest($function, $params, $cache); return $this->fetchResponse($request); }
[ "public", "function", "request", "(", "$", "function", ",", "array", "$", "params", "=", "array", "(", ")", ",", "$", "cache", "=", "null", ")", "{", "$", "request", "=", "$", "this", "->", "startRequest", "(", "$", "function", ",", "$", "params", ",", "$", "cache", ")", ";", "return", "$", "this", "->", "fetchResponse", "(", "$", "request", ")", ";", "}" ]
Does a full request and returns the result. @param string $function @param array $params @param string $cache @return mixed
[ "Does", "a", "full", "request", "and", "returns", "the", "result", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L281-L286
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.getSocket
protected function getSocket($server) { if (isset($this->socket[$server])) { return $this->socket[$server]; } $context = new ZMQContext(); $socket = Socket::create($context, ZMQ::SOCKET_REQ, $this->logger); $socket->connect($server); $this->socket[$server] = $socket; return $socket; }
php
protected function getSocket($server) { if (isset($this->socket[$server])) { return $this->socket[$server]; } $context = new ZMQContext(); $socket = Socket::create($context, ZMQ::SOCKET_REQ, $this->logger); $socket->connect($server); $this->socket[$server] = $socket; return $socket; }
[ "protected", "function", "getSocket", "(", "$", "server", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "socket", "[", "$", "server", "]", ")", ")", "{", "return", "$", "this", "->", "socket", "[", "$", "server", "]", ";", "}", "$", "context", "=", "new", "ZMQContext", "(", ")", ";", "$", "socket", "=", "Socket", "::", "create", "(", "$", "context", ",", "ZMQ", "::", "SOCKET_REQ", ",", "$", "this", "->", "logger", ")", ";", "$", "socket", "->", "connect", "(", "$", "server", ")", ";", "$", "this", "->", "socket", "[", "$", "server", "]", "=", "$", "socket", ";", "return", "$", "socket", ";", "}" ]
Returns a socket for the given server. If the socket does not yet exist, it is created. @param string $server @return Socket
[ "Returns", "a", "socket", "for", "the", "given", "server", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L297-L310
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.serializeParams
protected function serializeParams(array $params) { $serialized = array(); foreach ($params as $param) { $serialized[] = $this->serializer->serialize($param); } return $serialized; }
php
protected function serializeParams(array $params) { $serialized = array(); foreach ($params as $param) { $serialized[] = $this->serializer->serialize($param); } return $serialized; }
[ "protected", "function", "serializeParams", "(", "array", "$", "params", ")", "{", "$", "serialized", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "$", "serialized", "[", "]", "=", "$", "this", "->", "serializer", "->", "serialize", "(", "$", "param", ")", ";", "}", "return", "$", "serialized", ";", "}" ]
Serializes parameters. @param array $params @return array
[ "Serializes", "parameters", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L333-L341
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.sendExecuteRequest
protected function sendExecuteRequest($manager, Request $request, $cache = null) { $serialized = $this->serializeParams($request->getParams()); $msg = new ExecuteRequest($cache, $request->getFunction(), $serialized); $socket = $this->getSocket($manager); $stream = $socket->getStream(); $stream->send($msg); try { $response = $stream->read(new TimeoutTimer($this->delay)); } catch (TimeoutException $ex) { $this->invalidateSocket($manager); throw $ex; } if (!$response instanceof ExecuteResponse) { $msg = $manager.': Invalid response '.get_class($response).'.'; $this->getLogger()->notice($msg); throw new InvalidResponseException($msg); } if ('' != $response->getResult()) { $this->handleFetchResponse($response, $request); } return $response; }
php
protected function sendExecuteRequest($manager, Request $request, $cache = null) { $serialized = $this->serializeParams($request->getParams()); $msg = new ExecuteRequest($cache, $request->getFunction(), $serialized); $socket = $this->getSocket($manager); $stream = $socket->getStream(); $stream->send($msg); try { $response = $stream->read(new TimeoutTimer($this->delay)); } catch (TimeoutException $ex) { $this->invalidateSocket($manager); throw $ex; } if (!$response instanceof ExecuteResponse) { $msg = $manager.': Invalid response '.get_class($response).'.'; $this->getLogger()->notice($msg); throw new InvalidResponseException($msg); } if ('' != $response->getResult()) { $this->handleFetchResponse($response, $request); } return $response; }
[ "protected", "function", "sendExecuteRequest", "(", "$", "manager", ",", "Request", "$", "request", ",", "$", "cache", "=", "null", ")", "{", "$", "serialized", "=", "$", "this", "->", "serializeParams", "(", "$", "request", "->", "getParams", "(", ")", ")", ";", "$", "msg", "=", "new", "ExecuteRequest", "(", "$", "cache", ",", "$", "request", "->", "getFunction", "(", ")", ",", "$", "serialized", ")", ";", "$", "socket", "=", "$", "this", "->", "getSocket", "(", "$", "manager", ")", ";", "$", "stream", "=", "$", "socket", "->", "getStream", "(", ")", ";", "$", "stream", "->", "send", "(", "$", "msg", ")", ";", "try", "{", "$", "response", "=", "$", "stream", "->", "read", "(", "new", "TimeoutTimer", "(", "$", "this", "->", "delay", ")", ")", ";", "}", "catch", "(", "TimeoutException", "$", "ex", ")", "{", "$", "this", "->", "invalidateSocket", "(", "$", "manager", ")", ";", "throw", "$", "ex", ";", "}", "if", "(", "!", "$", "response", "instanceof", "ExecuteResponse", ")", "{", "$", "msg", "=", "$", "manager", ".", "': Invalid response '", ".", "get_class", "(", "$", "response", ")", ".", "'.'", ";", "$", "this", "->", "getLogger", "(", ")", "->", "notice", "(", "$", "msg", ")", ";", "throw", "new", "InvalidResponseException", "(", "$", "msg", ")", ";", "}", "if", "(", "''", "!=", "$", "response", "->", "getResult", "(", ")", ")", "{", "$", "this", "->", "handleFetchResponse", "(", "$", "response", ",", "$", "request", ")", ";", "}", "return", "$", "response", ";", "}" ]
Send a request to the ClientHandler. @param string $manager @param Request $request @param string $cache @return ExecuteResponse @throws TimeoutException @throws InvalidResponseException
[ "Send", "a", "request", "to", "the", "ClientHandler", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L354-L382
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.fetchResponse
public function fetchResponse(Request $request, $waitForResult = true) { if ($request->hasResponse()) { return $request->getResponse(); } $timer = $this->getFetchTimer($waitForResult); $req = new FetchRequest($request->getRequestId(), $waitForResult); do { try { $response = $this->sendFetchRequest($this->getManagerForRequest($request), $req); $result = $this->handleFetchResponse($response, $request); return $result; } catch (TimeoutException $ex) { $this->getLogger()->debug($request->getRequestId().': '.$ex->getMessage()); } } while (!$timer->isExpired()); throw new TimeoutException('Request '.$request->getRequestId().' timed out.'); }
php
public function fetchResponse(Request $request, $waitForResult = true) { if ($request->hasResponse()) { return $request->getResponse(); } $timer = $this->getFetchTimer($waitForResult); $req = new FetchRequest($request->getRequestId(), $waitForResult); do { try { $response = $this->sendFetchRequest($this->getManagerForRequest($request), $req); $result = $this->handleFetchResponse($response, $request); return $result; } catch (TimeoutException $ex) { $this->getLogger()->debug($request->getRequestId().': '.$ex->getMessage()); } } while (!$timer->isExpired()); throw new TimeoutException('Request '.$request->getRequestId().' timed out.'); }
[ "public", "function", "fetchResponse", "(", "Request", "$", "request", ",", "$", "waitForResult", "=", "true", ")", "{", "if", "(", "$", "request", "->", "hasResponse", "(", ")", ")", "{", "return", "$", "request", "->", "getResponse", "(", ")", ";", "}", "$", "timer", "=", "$", "this", "->", "getFetchTimer", "(", "$", "waitForResult", ")", ";", "$", "req", "=", "new", "FetchRequest", "(", "$", "request", "->", "getRequestId", "(", ")", ",", "$", "waitForResult", ")", ";", "do", "{", "try", "{", "$", "response", "=", "$", "this", "->", "sendFetchRequest", "(", "$", "this", "->", "getManagerForRequest", "(", "$", "request", ")", ",", "$", "req", ")", ";", "$", "result", "=", "$", "this", "->", "handleFetchResponse", "(", "$", "response", ",", "$", "request", ")", ";", "return", "$", "result", ";", "}", "catch", "(", "TimeoutException", "$", "ex", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "$", "request", "->", "getRequestId", "(", ")", ".", "': '", ".", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}", "while", "(", "!", "$", "timer", "->", "isExpired", "(", ")", ")", ";", "throw", "new", "TimeoutException", "(", "'Request '", ".", "$", "request", "->", "getRequestId", "(", ")", ".", "' timed out.'", ")", ";", "}" ]
Fetches the response for a request. Throws a RuntimeException if there is no response (yet) and the timeout is reached. @param \AlphaRPC\Client\Request $request @param boolean $waitForResult @return mixed @throws \RuntimeException
[ "Fetches", "the", "response", "for", "a", "request", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L396-L417
train
alphacomm/alpharpc
src/AlphaRPC/Client/Client.php
Client.getManagerForRequest
private function getManagerForRequest(Request $request) { if (!$request->getManager()) { $request->setManager($this->managerList->get()); } return $request->getManager(); }
php
private function getManagerForRequest(Request $request) { if (!$request->getManager()) { $request->setManager($this->managerList->get()); } return $request->getManager(); }
[ "private", "function", "getManagerForRequest", "(", "Request", "$", "request", ")", "{", "if", "(", "!", "$", "request", "->", "getManager", "(", ")", ")", "{", "$", "request", "->", "setManager", "(", "$", "this", "->", "managerList", "->", "get", "(", ")", ")", ";", "}", "return", "$", "request", "->", "getManager", "(", ")", ";", "}" ]
Returns a manager for the Request. It prefers the manager that is already set, but if it is not, then it adds a random manager from the manager list. @param Request $request @return string
[ "Returns", "a", "manager", "for", "the", "Request", "." ]
cf162854500554c4ba8d39f2675de35a49c30ed0
https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/Client.php#L534-L541
train
rackberg/para
src/Plugin/PluginManager.php
PluginManager.decodeLockFile
private function decodeLockFile(): array { $data = []; $encoder = $this->jsonEncoderFactory->getEncoder(); if (file_exists($this->rootDirectory . 'composer.lock')) { $data = $encoder->decode( file_get_contents($this->rootDirectory.'composer.lock'), JsonEncoder::FORMAT ); } return $data; }
php
private function decodeLockFile(): array { $data = []; $encoder = $this->jsonEncoderFactory->getEncoder(); if (file_exists($this->rootDirectory . 'composer.lock')) { $data = $encoder->decode( file_get_contents($this->rootDirectory.'composer.lock'), JsonEncoder::FORMAT ); } return $data; }
[ "private", "function", "decodeLockFile", "(", ")", ":", "array", "{", "$", "data", "=", "[", "]", ";", "$", "encoder", "=", "$", "this", "->", "jsonEncoderFactory", "->", "getEncoder", "(", ")", ";", "if", "(", "file_exists", "(", "$", "this", "->", "rootDirectory", ".", "'composer.lock'", ")", ")", "{", "$", "data", "=", "$", "encoder", "->", "decode", "(", "file_get_contents", "(", "$", "this", "->", "rootDirectory", ".", "'composer.lock'", ")", ",", "JsonEncoder", "::", "FORMAT", ")", ";", "}", "return", "$", "data", ";", "}" ]
Returns the decoded lock file data. @return array
[ "Returns", "the", "decoded", "lock", "file", "data", "." ]
e0ef1356ed2979670eb7c670d88921406cade46e
https://github.com/rackberg/para/blob/e0ef1356ed2979670eb7c670d88921406cade46e/src/Plugin/PluginManager.php#L206-L219
train
yii2lab/yii2-rbac
src/domain/services/RuleService.php
RuleService.executeRule
public function executeRule($user, $item, $params) { if ($item->ruleName === null) { return true; } $rule = $this->domain->rule->getRule($item->ruleName); if ($rule instanceof Rule) { return $rule->execute($user, $item, $params); } throw new InvalidConfigException("Rule not found: {$item->ruleName}"); }
php
public function executeRule($user, $item, $params) { if ($item->ruleName === null) { return true; } $rule = $this->domain->rule->getRule($item->ruleName); if ($rule instanceof Rule) { return $rule->execute($user, $item, $params); } throw new InvalidConfigException("Rule not found: {$item->ruleName}"); }
[ "public", "function", "executeRule", "(", "$", "user", ",", "$", "item", ",", "$", "params", ")", "{", "if", "(", "$", "item", "->", "ruleName", "===", "null", ")", "{", "return", "true", ";", "}", "$", "rule", "=", "$", "this", "->", "domain", "->", "rule", "->", "getRule", "(", "$", "item", "->", "ruleName", ")", ";", "if", "(", "$", "rule", "instanceof", "Rule", ")", "{", "return", "$", "rule", "->", "execute", "(", "$", "user", ",", "$", "item", ",", "$", "params", ")", ";", "}", "throw", "new", "InvalidConfigException", "(", "\"Rule not found: {$item->ruleName}\"", ")", ";", "}" ]
Executes the rule associated with the specified auth item. If the item does not specify a rule, this method will return true. Otherwise, it will return the value of [[Rule::execute()]]. @param string|int $user the user ID. This should be either an integer or a string representing the unique identifier of a user. See [[\yii\web\User::id]]. @param Item $item the auth item that needs to execute its rule @param array $params parameters passed to [[CheckAccessInterface::checkAccess()]] and will be passed to the rule @return bool the return value of [[Rule::execute()]]. If the auth item does not specify a rule, true will be returned. @throws InvalidConfigException if the auth item has an invalid rule.
[ "Executes", "the", "rule", "associated", "with", "the", "specified", "auth", "item", "." ]
e72ac0359af660690c161451f864208b2d20919d
https://github.com/yii2lab/yii2-rbac/blob/e72ac0359af660690c161451f864208b2d20919d/src/domain/services/RuleService.php#L84-L95
train
gplcart/base
handlers/Install.php
Install.install
public function install(array $data, $db) { $this->db = $db; $this->data = $data; $this->data['step'] = 0; if (GC_CLI) { $this->installCli(); return array(); } return $this->installHttp(); }
php
public function install(array $data, $db) { $this->db = $db; $this->data = $data; $this->data['step'] = 0; if (GC_CLI) { $this->installCli(); return array(); } return $this->installHttp(); }
[ "public", "function", "install", "(", "array", "$", "data", ",", "$", "db", ")", "{", "$", "this", "->", "db", "=", "$", "db", ";", "$", "this", "->", "data", "=", "$", "data", ";", "$", "this", "->", "data", "[", "'step'", "]", "=", "0", ";", "if", "(", "GC_CLI", ")", "{", "$", "this", "->", "installCli", "(", ")", ";", "return", "array", "(", ")", ";", "}", "return", "$", "this", "->", "installHttp", "(", ")", ";", "}" ]
Performs initial system installation. Step 0 @param array $data @param \gplcart\core\Database $db @return array
[ "Performs", "initial", "system", "installation", ".", "Step", "0" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L54-L66
train
gplcart/base
handlers/Install.php
Install.installHttp
protected function installHttp() { $result = array( 'message' => '', 'severity' => 'success', 'redirect' => 'install/' . ($this->data['step'] + 1) ); try { $this->start(); $this->process(); } catch (Exception $ex) { $result = array( 'redirect' => '', 'severity' => 'warning', 'message' => $ex->getMessage() ); } return $result; }
php
protected function installHttp() { $result = array( 'message' => '', 'severity' => 'success', 'redirect' => 'install/' . ($this->data['step'] + 1) ); try { $this->start(); $this->process(); } catch (Exception $ex) { $result = array( 'redirect' => '', 'severity' => 'warning', 'message' => $ex->getMessage() ); } return $result; }
[ "protected", "function", "installHttp", "(", ")", "{", "$", "result", "=", "array", "(", "'message'", "=>", "''", ",", "'severity'", "=>", "'success'", ",", "'redirect'", "=>", "'install/'", ".", "(", "$", "this", "->", "data", "[", "'step'", "]", "+", "1", ")", ")", ";", "try", "{", "$", "this", "->", "start", "(", ")", ";", "$", "this", "->", "process", "(", ")", ";", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "$", "result", "=", "array", "(", "'redirect'", "=>", "''", ",", "'severity'", "=>", "'warning'", ",", "'message'", "=>", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Performs installation via classic web UI @return array
[ "Performs", "installation", "via", "classic", "web", "UI" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L72-L94
train
gplcart/base
handlers/Install.php
Install.installCli
protected function installCli() { try { $this->process(); $this->installCliStep1(); $this->installCliStep2(); $this->installCliStep3(); $this->cli->line($this->getSuccessMessage()); } catch (Exception $ex) { $this->cli->error($ex->getMessage()); } }
php
protected function installCli() { try { $this->process(); $this->installCliStep1(); $this->installCliStep2(); $this->installCliStep3(); $this->cli->line($this->getSuccessMessage()); } catch (Exception $ex) { $this->cli->error($ex->getMessage()); } }
[ "protected", "function", "installCli", "(", ")", "{", "try", "{", "$", "this", "->", "process", "(", ")", ";", "$", "this", "->", "installCliStep1", "(", ")", ";", "$", "this", "->", "installCliStep2", "(", ")", ";", "$", "this", "->", "installCliStep3", "(", ")", ";", "$", "this", "->", "cli", "->", "line", "(", "$", "this", "->", "getSuccessMessage", "(", ")", ")", ";", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "$", "this", "->", "cli", "->", "error", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Install in CLI mode
[ "Install", "in", "CLI", "mode" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L99-L110
train
gplcart/base
handlers/Install.php
Install.installCliStep1
protected function installCliStep1() { $this->data['step'] = 1; $this->setCliMessage('Configuring modules...'); $result = $this->installModules($this->data, $this->db); if ($result['severity'] !== 'success') { throw new UnexpectedValueException($result['message']); } }
php
protected function installCliStep1() { $this->data['step'] = 1; $this->setCliMessage('Configuring modules...'); $result = $this->installModules($this->data, $this->db); if ($result['severity'] !== 'success') { throw new UnexpectedValueException($result['message']); } }
[ "protected", "function", "installCliStep1", "(", ")", "{", "$", "this", "->", "data", "[", "'step'", "]", "=", "1", ";", "$", "this", "->", "setCliMessage", "(", "'Configuring modules...'", ")", ";", "$", "result", "=", "$", "this", "->", "installModules", "(", "$", "this", "->", "data", ",", "$", "this", "->", "db", ")", ";", "if", "(", "$", "result", "[", "'severity'", "]", "!==", "'success'", ")", "{", "throw", "new", "UnexpectedValueException", "(", "$", "result", "[", "'message'", "]", ")", ";", "}", "}" ]
Process step 1 in CLI mode @throws UnexpectedValueException
[ "Process", "step", "1", "in", "CLI", "mode" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L116-L125
train
gplcart/base
handlers/Install.php
Install.installCliStep2
protected function installCliStep2() { $title = $this->translation->text('Please select a demo content package (enter a number)'); $this->data['demo_handler_id'] = $this->cli->menu($this->getDemoOptions(), '', $title); if (!empty($this->data['demo_handler_id'])) { $this->data['step'] = 2; $this->setCliMessage('Installing demo content...'); $result = $this->installDemo($this->data, $this->db); if ($result['severity'] !== 'success') { throw new UnexpectedValueException($result['message']); } $this->setContext('demo_handler_id', $this->data['demo_handler_id']); } }
php
protected function installCliStep2() { $title = $this->translation->text('Please select a demo content package (enter a number)'); $this->data['demo_handler_id'] = $this->cli->menu($this->getDemoOptions(), '', $title); if (!empty($this->data['demo_handler_id'])) { $this->data['step'] = 2; $this->setCliMessage('Installing demo content...'); $result = $this->installDemo($this->data, $this->db); if ($result['severity'] !== 'success') { throw new UnexpectedValueException($result['message']); } $this->setContext('demo_handler_id', $this->data['demo_handler_id']); } }
[ "protected", "function", "installCliStep2", "(", ")", "{", "$", "title", "=", "$", "this", "->", "translation", "->", "text", "(", "'Please select a demo content package (enter a number)'", ")", ";", "$", "this", "->", "data", "[", "'demo_handler_id'", "]", "=", "$", "this", "->", "cli", "->", "menu", "(", "$", "this", "->", "getDemoOptions", "(", ")", ",", "''", ",", "$", "title", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "data", "[", "'demo_handler_id'", "]", ")", ")", "{", "$", "this", "->", "data", "[", "'step'", "]", "=", "2", ";", "$", "this", "->", "setCliMessage", "(", "'Installing demo content...'", ")", ";", "$", "result", "=", "$", "this", "->", "installDemo", "(", "$", "this", "->", "data", ",", "$", "this", "->", "db", ")", ";", "if", "(", "$", "result", "[", "'severity'", "]", "!==", "'success'", ")", "{", "throw", "new", "UnexpectedValueException", "(", "$", "result", "[", "'message'", "]", ")", ";", "}", "$", "this", "->", "setContext", "(", "'demo_handler_id'", ",", "$", "this", "->", "data", "[", "'demo_handler_id'", "]", ")", ";", "}", "}" ]
Process step 2 in CLI mode @throws UnexpectedValueException
[ "Process", "step", "2", "in", "CLI", "mode" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L131-L148
train
gplcart/base
handlers/Install.php
Install.installCliStep3
protected function installCliStep3() { $this->data['step'] = 3; $result = $this->installFinish($this->data, $this->db); if ($result['severity'] !== 'success') { throw new UnexpectedValueException($result['message']); } }
php
protected function installCliStep3() { $this->data['step'] = 3; $result = $this->installFinish($this->data, $this->db); if ($result['severity'] !== 'success') { throw new UnexpectedValueException($result['message']); } }
[ "protected", "function", "installCliStep3", "(", ")", "{", "$", "this", "->", "data", "[", "'step'", "]", "=", "3", ";", "$", "result", "=", "$", "this", "->", "installFinish", "(", "$", "this", "->", "data", ",", "$", "this", "->", "db", ")", ";", "if", "(", "$", "result", "[", "'severity'", "]", "!==", "'success'", ")", "{", "throw", "new", "UnexpectedValueException", "(", "$", "result", "[", "'message'", "]", ")", ";", "}", "}" ]
Precess step 3 in CLI mode @throws UnexpectedValueException
[ "Precess", "step", "3", "in", "CLI", "mode" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L154-L162
train
gplcart/base
handlers/Install.php
Install.installModules
public function installModules(array $data, $db) { $this->db = $db; $this->data = $data; try { $this->install_model->installModules(); $this->configureModules(); return array( 'message' => '', 'severity' => 'success', 'redirect' => 'install/' . ($this->data['step'] + 1) ); } catch (Exception $ex) { $this->setContextError($this->data['step'], $ex->getMessage()); return array( 'redirect' => '', 'severity' => 'danger', 'message' => $ex->getMessage() ); } }
php
public function installModules(array $data, $db) { $this->db = $db; $this->data = $data; try { $this->install_model->installModules(); $this->configureModules(); return array( 'message' => '', 'severity' => 'success', 'redirect' => 'install/' . ($this->data['step'] + 1) ); } catch (Exception $ex) { $this->setContextError($this->data['step'], $ex->getMessage()); return array( 'redirect' => '', 'severity' => 'danger', 'message' => $ex->getMessage() ); } }
[ "public", "function", "installModules", "(", "array", "$", "data", ",", "$", "db", ")", "{", "$", "this", "->", "db", "=", "$", "db", ";", "$", "this", "->", "data", "=", "$", "data", ";", "try", "{", "$", "this", "->", "install_model", "->", "installModules", "(", ")", ";", "$", "this", "->", "configureModules", "(", ")", ";", "return", "array", "(", "'message'", "=>", "''", ",", "'severity'", "=>", "'success'", ",", "'redirect'", "=>", "'install/'", ".", "(", "$", "this", "->", "data", "[", "'step'", "]", "+", "1", ")", ")", ";", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "$", "this", "->", "setContextError", "(", "$", "this", "->", "data", "[", "'step'", "]", ",", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "return", "array", "(", "'redirect'", "=>", "''", ",", "'severity'", "=>", "'danger'", ",", "'message'", "=>", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Installs required modules. Step 1 @param array $data @param \gplcart\core\Database $db @return array
[ "Installs", "required", "modules", ".", "Step", "1" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L170-L196
train
gplcart/base
handlers/Install.php
Install.installDemo
public function installDemo(array $data, $db) { set_time_limit(0); $this->db = $db; $this->data = $data; $success_result = array( 'message' => '', 'severity' => 'success', 'redirect' => 'install/' . ($this->data['step'] + 1) ); if (empty($data['demo_handler_id'])) { return $success_result; } $result = $this->install_model->getDemoModule()->create($this->getContext('store_id'), $data['demo_handler_id']); if ($result !== true) { $this->setContextError($this->data['step'], $result); } return $success_result; }
php
public function installDemo(array $data, $db) { set_time_limit(0); $this->db = $db; $this->data = $data; $success_result = array( 'message' => '', 'severity' => 'success', 'redirect' => 'install/' . ($this->data['step'] + 1) ); if (empty($data['demo_handler_id'])) { return $success_result; } $result = $this->install_model->getDemoModule()->create($this->getContext('store_id'), $data['demo_handler_id']); if ($result !== true) { $this->setContextError($this->data['step'], $result); } return $success_result; }
[ "public", "function", "installDemo", "(", "array", "$", "data", ",", "$", "db", ")", "{", "set_time_limit", "(", "0", ")", ";", "$", "this", "->", "db", "=", "$", "db", ";", "$", "this", "->", "data", "=", "$", "data", ";", "$", "success_result", "=", "array", "(", "'message'", "=>", "''", ",", "'severity'", "=>", "'success'", ",", "'redirect'", "=>", "'install/'", ".", "(", "$", "this", "->", "data", "[", "'step'", "]", "+", "1", ")", ")", ";", "if", "(", "empty", "(", "$", "data", "[", "'demo_handler_id'", "]", ")", ")", "{", "return", "$", "success_result", ";", "}", "$", "result", "=", "$", "this", "->", "install_model", "->", "getDemoModule", "(", ")", "->", "create", "(", "$", "this", "->", "getContext", "(", "'store_id'", ")", ",", "$", "data", "[", "'demo_handler_id'", "]", ")", ";", "if", "(", "$", "result", "!==", "true", ")", "{", "$", "this", "->", "setContextError", "(", "$", "this", "->", "data", "[", "'step'", "]", ",", "$", "result", ")", ";", "}", "return", "$", "success_result", ";", "}" ]
Install a demo-content. Step 2 @param array $data @param \gplcart\core\Database $db @return array
[ "Install", "a", "demo", "-", "content", ".", "Step", "2" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L204-L228
train
gplcart/base
handlers/Install.php
Install.installFinish
public function installFinish(array $data, $db) { $this->db = $db; $this->data = $data; $result = $this->finish(); $errors = $this->getContextErrors(); if (empty($errors)) { if ($this->getContext('demo_handler_id')) { $store_id = $this->getContext('store_id'); $this->getStoreModel()->update($store_id, array('status' => 1)); } } else { $result['severity'] = 'warning'; $result['message'] = implode(PHP_EOL, $errors); } return $result; }
php
public function installFinish(array $data, $db) { $this->db = $db; $this->data = $data; $result = $this->finish(); $errors = $this->getContextErrors(); if (empty($errors)) { if ($this->getContext('demo_handler_id')) { $store_id = $this->getContext('store_id'); $this->getStoreModel()->update($store_id, array('status' => 1)); } } else { $result['severity'] = 'warning'; $result['message'] = implode(PHP_EOL, $errors); } return $result; }
[ "public", "function", "installFinish", "(", "array", "$", "data", ",", "$", "db", ")", "{", "$", "this", "->", "db", "=", "$", "db", ";", "$", "this", "->", "data", "=", "$", "data", ";", "$", "result", "=", "$", "this", "->", "finish", "(", ")", ";", "$", "errors", "=", "$", "this", "->", "getContextErrors", "(", ")", ";", "if", "(", "empty", "(", "$", "errors", ")", ")", "{", "if", "(", "$", "this", "->", "getContext", "(", "'demo_handler_id'", ")", ")", "{", "$", "store_id", "=", "$", "this", "->", "getContext", "(", "'store_id'", ")", ";", "$", "this", "->", "getStoreModel", "(", ")", "->", "update", "(", "$", "store_id", ",", "array", "(", "'status'", "=>", "1", ")", ")", ";", "}", "}", "else", "{", "$", "result", "[", "'severity'", "]", "=", "'warning'", ";", "$", "result", "[", "'message'", "]", "=", "implode", "(", "PHP_EOL", ",", "$", "errors", ")", ";", "}", "return", "$", "result", ";", "}" ]
Performs final tasks. Step 3 @param array $data @param \gplcart\core\Database $db @return array
[ "Performs", "final", "tasks", ".", "Step", "3" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L236-L255
train
gplcart/base
handlers/Install.php
Install.getDemoOptions
protected function getDemoOptions() { $options = array('' => $this->translation->text('No demo')); foreach ($this->install_model->getDemoHandlers() as $id => $handler) { $options[$id] = $handler['title']; } return $options; }
php
protected function getDemoOptions() { $options = array('' => $this->translation->text('No demo')); foreach ($this->install_model->getDemoHandlers() as $id => $handler) { $options[$id] = $handler['title']; } return $options; }
[ "protected", "function", "getDemoOptions", "(", ")", "{", "$", "options", "=", "array", "(", "''", "=>", "$", "this", "->", "translation", "->", "text", "(", "'No demo'", ")", ")", ";", "foreach", "(", "$", "this", "->", "install_model", "->", "getDemoHandlers", "(", ")", "as", "$", "id", "=>", "$", "handler", ")", "{", "$", "options", "[", "$", "id", "]", "=", "$", "handler", "[", "'title'", "]", ";", "}", "return", "$", "options", ";", "}" ]
Returns an array of demo content options @return array
[ "Returns", "an", "array", "of", "demo", "content", "options" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L261-L270
train
gplcart/base
handlers/Install.php
Install.configureModuleDevice
protected function configureModuleDevice() { $store_id = $this->getContext('store_id'); $settings = array(); $settings['theme'][$store_id]['mobile'] = 'mobile'; $settings['theme'][$store_id]['tablet'] = 'mobile'; $this->module->setSettings('device', $settings); }
php
protected function configureModuleDevice() { $store_id = $this->getContext('store_id'); $settings = array(); $settings['theme'][$store_id]['mobile'] = 'mobile'; $settings['theme'][$store_id]['tablet'] = 'mobile'; $this->module->setSettings('device', $settings); }
[ "protected", "function", "configureModuleDevice", "(", ")", "{", "$", "store_id", "=", "$", "this", "->", "getContext", "(", "'store_id'", ")", ";", "$", "settings", "=", "array", "(", ")", ";", "$", "settings", "[", "'theme'", "]", "[", "$", "store_id", "]", "[", "'mobile'", "]", "=", "'mobile'", ";", "$", "settings", "[", "'theme'", "]", "[", "$", "store_id", "]", "[", "'tablet'", "]", "=", "'mobile'", ";", "$", "this", "->", "module", "->", "setSettings", "(", "'device'", ",", "$", "settings", ")", ";", "}" ]
Configure Device module settings
[ "Configure", "Device", "module", "settings" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L284-L293
train
gplcart/base
handlers/Install.php
Install.configureModuleGaReport
protected function configureModuleGaReport() { $info = $this->module->getInfo('ga_report'); $info['settings']['dashboard'] = array( 'visit_date', 'pageview_date', 'content_statistic', 'top_pages', 'source', 'keyword', 'audience' ); $this->module->setSettings('ga_report', $info['settings']); }
php
protected function configureModuleGaReport() { $info = $this->module->getInfo('ga_report'); $info['settings']['dashboard'] = array( 'visit_date', 'pageview_date', 'content_statistic', 'top_pages', 'source', 'keyword', 'audience' ); $this->module->setSettings('ga_report', $info['settings']); }
[ "protected", "function", "configureModuleGaReport", "(", ")", "{", "$", "info", "=", "$", "this", "->", "module", "->", "getInfo", "(", "'ga_report'", ")", ";", "$", "info", "[", "'settings'", "]", "[", "'dashboard'", "]", "=", "array", "(", "'visit_date'", ",", "'pageview_date'", ",", "'content_statistic'", ",", "'top_pages'", ",", "'source'", ",", "'keyword'", ",", "'audience'", ")", ";", "$", "this", "->", "module", "->", "setSettings", "(", "'ga_report'", ",", "$", "info", "[", "'settings'", "]", ")", ";", "}" ]
Configure Google Analytics Report module settings
[ "Configure", "Google", "Analytics", "Report", "module", "settings" ]
bbcd87604d25333a0a1b84d79299fa06ec5dd39e
https://github.com/gplcart/base/blob/bbcd87604d25333a0a1b84d79299fa06ec5dd39e/handlers/Install.php#L298-L313
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.initialize
public function initialize($url, $reset = true) { if ((bool)$reset) $this->reset(); $this->currentRequestUrl = $url; $this->state = self::STATE_INITIALIZED; return $this; }
php
public function initialize($url, $reset = true) { if ((bool)$reset) $this->reset(); $this->currentRequestUrl = $url; $this->state = self::STATE_INITIALIZED; return $this; }
[ "public", "function", "initialize", "(", "$", "url", ",", "$", "reset", "=", "true", ")", "{", "if", "(", "(", "bool", ")", "$", "reset", ")", "$", "this", "->", "reset", "(", ")", ";", "$", "this", "->", "currentRequestUrl", "=", "$", "url", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_INITIALIZED", ";", "return", "$", "this", ";", "}" ]
Create a new CURL resource @param string $url @param bool $reset @return $this
[ "Create", "a", "new", "CURL", "resource" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L82-L92
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.setRequestHeader
public function setRequestHeader($name, $value) { if (!is_string($name)) throw new \InvalidArgumentException('Argument 1 expected to be string, '.gettype($name).' seen.'); if (!is_string($value)) throw new \InvalidArgumentException('Argument 2 expected to be string, '.gettype($value).' seen.'); if (($name = trim($name)) === '') throw new \RuntimeException('Argument 1 cannot be empty string.'); $this->requestHeaders[$name] = $value; return $this; }
php
public function setRequestHeader($name, $value) { if (!is_string($name)) throw new \InvalidArgumentException('Argument 1 expected to be string, '.gettype($name).' seen.'); if (!is_string($value)) throw new \InvalidArgumentException('Argument 2 expected to be string, '.gettype($value).' seen.'); if (($name = trim($name)) === '') throw new \RuntimeException('Argument 1 cannot be empty string.'); $this->requestHeaders[$name] = $value; return $this; }
[ "public", "function", "setRequestHeader", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'Argument 1 expected to be string, '", ".", "gettype", "(", "$", "name", ")", ".", "' seen.'", ")", ";", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'Argument 2 expected to be string, '", ".", "gettype", "(", "$", "value", ")", ".", "' seen.'", ")", ";", "if", "(", "(", "$", "name", "=", "trim", "(", "$", "name", ")", ")", "===", "''", ")", "throw", "new", "\\", "RuntimeException", "(", "'Argument 1 cannot be empty string.'", ")", ";", "$", "this", "->", "requestHeaders", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Add a header string to the request @param string $name @param string $value @throws \RuntimeException @throws \InvalidArgumentException @return $this
[ "Add", "a", "header", "string", "to", "the", "request" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L111-L125
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.setCurlOpt
public function setCurlOpt($opt, $val) { if (!is_int($opt)) { throw new \InvalidArgumentException(sprintf( '%s::setCurlOpt - Argument 1 expected to be integer, %s seen.', get_class($this), gettype($opt) )); } $this->curlOpts[$opt] = $val; return $this; }
php
public function setCurlOpt($opt, $val) { if (!is_int($opt)) { throw new \InvalidArgumentException(sprintf( '%s::setCurlOpt - Argument 1 expected to be integer, %s seen.', get_class($this), gettype($opt) )); } $this->curlOpts[$opt] = $val; return $this; }
[ "public", "function", "setCurlOpt", "(", "$", "opt", ",", "$", "val", ")", "{", "if", "(", "!", "is_int", "(", "$", "opt", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'%s::setCurlOpt - Argument 1 expected to be integer, %s seen.'", ",", "get_class", "(", "$", "this", ")", ",", "gettype", "(", "$", "opt", ")", ")", ")", ";", "}", "$", "this", "->", "curlOpts", "[", "$", "opt", "]", "=", "$", "val", ";", "return", "$", "this", ";", "}" ]
Set CURL option @link http://www.php.net/manual/en/function.curl-setopt.php @param int $opt curl option @param mixed $val curl option value @throws \InvalidArgumentException @return $this
[ "Set", "CURL", "option" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L189-L202
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.close
public function close() { if ('resource' === gettype($this->ch)) curl_close($this->ch); $this->state = self::STATE_CLOSED; return $this; }
php
public function close() { if ('resource' === gettype($this->ch)) curl_close($this->ch); $this->state = self::STATE_CLOSED; return $this; }
[ "public", "function", "close", "(", ")", "{", "if", "(", "'resource'", "===", "gettype", "(", "$", "this", "->", "ch", ")", ")", "curl_close", "(", "$", "this", "->", "ch", ")", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_CLOSED", ";", "return", "$", "this", ";", "}" ]
Close the curl resource, if exists
[ "Close", "the", "curl", "resource", "if", "exists" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L249-L257
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.reset
public function reset() { $this->close(); $this->curlOpts = array(); $this->requestHeaders = array(); $this->currentRequestUrl = null; $this->state = self::STATE_NEW; return $this; }
php
public function reset() { $this->close(); $this->curlOpts = array(); $this->requestHeaders = array(); $this->currentRequestUrl = null; $this->state = self::STATE_NEW; return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "close", "(", ")", ";", "$", "this", "->", "curlOpts", "=", "array", "(", ")", ";", "$", "this", "->", "requestHeaders", "=", "array", "(", ")", ";", "$", "this", "->", "currentRequestUrl", "=", "null", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_NEW", ";", "return", "$", "this", ";", "}" ]
Reset to new state @return $this
[ "Reset", "to", "new", "state" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L264-L274
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.curlOptSet
public function curlOptSet($opt) { return isset($this->curlOpts[$opt]) || array_key_exists($opt, $this->curlOpts); }
php
public function curlOptSet($opt) { return isset($this->curlOpts[$opt]) || array_key_exists($opt, $this->curlOpts); }
[ "public", "function", "curlOptSet", "(", "$", "opt", ")", "{", "return", "isset", "(", "$", "this", "->", "curlOpts", "[", "$", "opt", "]", ")", "||", "array_key_exists", "(", "$", "opt", ",", "$", "this", "->", "curlOpts", ")", ";", "}" ]
Returns true if passed in curl option has a value @param int $opt @return bool
[ "Returns", "true", "if", "passed", "in", "curl", "option", "has", "a", "value" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L282-L285
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.execute
public function execute($resetAfterExecution = false) { $this->buildRequest(); $response = new CurlPlusResponse( curl_exec($this->ch), curl_getinfo($this->ch), curl_error($this->ch), $this->getCurlOpts() ); if ($resetAfterExecution) $this->reset(); return $response; }
php
public function execute($resetAfterExecution = false) { $this->buildRequest(); $response = new CurlPlusResponse( curl_exec($this->ch), curl_getinfo($this->ch), curl_error($this->ch), $this->getCurlOpts() ); if ($resetAfterExecution) $this->reset(); return $response; }
[ "public", "function", "execute", "(", "$", "resetAfterExecution", "=", "false", ")", "{", "$", "this", "->", "buildRequest", "(", ")", ";", "$", "response", "=", "new", "CurlPlusResponse", "(", "curl_exec", "(", "$", "this", "->", "ch", ")", ",", "curl_getinfo", "(", "$", "this", "->", "ch", ")", ",", "curl_error", "(", "$", "this", "->", "ch", ")", ",", "$", "this", "->", "getCurlOpts", "(", ")", ")", ";", "if", "(", "$", "resetAfterExecution", ")", "$", "this", "->", "reset", "(", ")", ";", "return", "$", "response", ";", "}" ]
Execute CURL command @param bool $resetAfterExecution @throws \RuntimeException @return \DCarbone\CurlPlus\CurlPlusResponse
[ "Execute", "CURL", "command" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L308-L323
train
dcarbone/curl-plus
src/CurlPlusClient.php
CurlPlusClient.buildRequest
protected function buildRequest() { if (self::STATE_NEW === $this->state) { throw new \RuntimeException(sprintf( '%s::execute - Could not execute request, curl has not been initialized.', get_class($this) )); } if (self::STATE_EXECUTED === $this->state) $this->close(); if (self::STATE_CLOSED === $this->state) $this->initialize($this->currentRequestUrl, false); // Create curl handle resource $this->ch = curl_init($this->currentRequestUrl); if (false === $this->ch) { throw new \RuntimeException(sprintf( 'Unable to initialize curl with url: %s', $this->getRequestUrl() )); } // Set the Header array (if any) if (count($this->requestHeaders) > 0) { $headers = array(); foreach($this->requestHeaders as $k=>$v) { $headers[] = vsprintf('%s: %s', array($k, $v)); } $this->setCurlOpt(CURLOPT_HTTPHEADER, $headers); } // Return the Request Header as part of the curl_info array unless they specify otherwise if (!$this->curlOptSet(CURLINFO_HEADER_OUT)) $this->setCurlOpt(CURLINFO_HEADER_OUT, true); // If the user has opted to return the data, rather than save to file or output directly, // attempt to get headers back in the response for later use if they have not specified // otherwise. if ($this->getCurlOptValue(CURLOPT_RETURNTRANSFER) && !$this->curlOptSet(CURLOPT_HEADER)) $this->setCurlOpt(CURLOPT_HEADER, true); // Set the CURLOPTS if (false === curl_setopt_array($this->ch, $this->curlOpts)) { throw new \RuntimeException(sprintf( 'Unable to specify curl options, please ensure you\'re passing in valid constants. Specified opts: %s', json_encode($this->getCurlOpts()) )); } }
php
protected function buildRequest() { if (self::STATE_NEW === $this->state) { throw new \RuntimeException(sprintf( '%s::execute - Could not execute request, curl has not been initialized.', get_class($this) )); } if (self::STATE_EXECUTED === $this->state) $this->close(); if (self::STATE_CLOSED === $this->state) $this->initialize($this->currentRequestUrl, false); // Create curl handle resource $this->ch = curl_init($this->currentRequestUrl); if (false === $this->ch) { throw new \RuntimeException(sprintf( 'Unable to initialize curl with url: %s', $this->getRequestUrl() )); } // Set the Header array (if any) if (count($this->requestHeaders) > 0) { $headers = array(); foreach($this->requestHeaders as $k=>$v) { $headers[] = vsprintf('%s: %s', array($k, $v)); } $this->setCurlOpt(CURLOPT_HTTPHEADER, $headers); } // Return the Request Header as part of the curl_info array unless they specify otherwise if (!$this->curlOptSet(CURLINFO_HEADER_OUT)) $this->setCurlOpt(CURLINFO_HEADER_OUT, true); // If the user has opted to return the data, rather than save to file or output directly, // attempt to get headers back in the response for later use if they have not specified // otherwise. if ($this->getCurlOptValue(CURLOPT_RETURNTRANSFER) && !$this->curlOptSet(CURLOPT_HEADER)) $this->setCurlOpt(CURLOPT_HEADER, true); // Set the CURLOPTS if (false === curl_setopt_array($this->ch, $this->curlOpts)) { throw new \RuntimeException(sprintf( 'Unable to specify curl options, please ensure you\'re passing in valid constants. Specified opts: %s', json_encode($this->getCurlOpts()) )); } }
[ "protected", "function", "buildRequest", "(", ")", "{", "if", "(", "self", "::", "STATE_NEW", "===", "$", "this", "->", "state", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'%s::execute - Could not execute request, curl has not been initialized.'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "if", "(", "self", "::", "STATE_EXECUTED", "===", "$", "this", "->", "state", ")", "$", "this", "->", "close", "(", ")", ";", "if", "(", "self", "::", "STATE_CLOSED", "===", "$", "this", "->", "state", ")", "$", "this", "->", "initialize", "(", "$", "this", "->", "currentRequestUrl", ",", "false", ")", ";", "// Create curl handle resource", "$", "this", "->", "ch", "=", "curl_init", "(", "$", "this", "->", "currentRequestUrl", ")", ";", "if", "(", "false", "===", "$", "this", "->", "ch", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Unable to initialize curl with url: %s'", ",", "$", "this", "->", "getRequestUrl", "(", ")", ")", ")", ";", "}", "// Set the Header array (if any)", "if", "(", "count", "(", "$", "this", "->", "requestHeaders", ")", ">", "0", ")", "{", "$", "headers", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "requestHeaders", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "headers", "[", "]", "=", "vsprintf", "(", "'%s: %s'", ",", "array", "(", "$", "k", ",", "$", "v", ")", ")", ";", "}", "$", "this", "->", "setCurlOpt", "(", "CURLOPT_HTTPHEADER", ",", "$", "headers", ")", ";", "}", "// Return the Request Header as part of the curl_info array unless they specify otherwise", "if", "(", "!", "$", "this", "->", "curlOptSet", "(", "CURLINFO_HEADER_OUT", ")", ")", "$", "this", "->", "setCurlOpt", "(", "CURLINFO_HEADER_OUT", ",", "true", ")", ";", "// If the user has opted to return the data, rather than save to file or output directly,", "// attempt to get headers back in the response for later use if they have not specified", "// otherwise.", "if", "(", "$", "this", "->", "getCurlOptValue", "(", "CURLOPT_RETURNTRANSFER", ")", "&&", "!", "$", "this", "->", "curlOptSet", "(", "CURLOPT_HEADER", ")", ")", "$", "this", "->", "setCurlOpt", "(", "CURLOPT_HEADER", ",", "true", ")", ";", "// Set the CURLOPTS", "if", "(", "false", "===", "curl_setopt_array", "(", "$", "this", "->", "ch", ",", "$", "this", "->", "curlOpts", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Unable to specify curl options, please ensure you\\'re passing in valid constants. Specified opts: %s'", ",", "json_encode", "(", "$", "this", "->", "getCurlOpts", "(", ")", ")", ")", ")", ";", "}", "}" ]
Attempts to set up the client for a request, throws an exception if it cannot
[ "Attempts", "to", "set", "up", "the", "client", "for", "a", "request", "throws", "an", "exception", "if", "it", "cannot" ]
7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52
https://github.com/dcarbone/curl-plus/blob/7f6b8269c3045eee6e5ade0bff2ca91cb4f58d52/src/CurlPlusClient.php#L328-L383
train
crisu83/yii-consoletools
helpers/ConfigHelper.php
ConfigHelper.merge
public static function merge(array $array) { $result = array(); foreach ($array as $config) { if (is_string($config)) { if (!file_exists($config)) { continue; } $config = require($config); } if (!is_array($config)) { continue; } $result = self::mergeArray($result, $config); } return $result; }
php
public static function merge(array $array) { $result = array(); foreach ($array as $config) { if (is_string($config)) { if (!file_exists($config)) { continue; } $config = require($config); } if (!is_array($config)) { continue; } $result = self::mergeArray($result, $config); } return $result; }
[ "public", "static", "function", "merge", "(", "array", "$", "array", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "config", ")", "{", "if", "(", "is_string", "(", "$", "config", ")", ")", "{", "if", "(", "!", "file_exists", "(", "$", "config", ")", ")", "{", "continue", ";", "}", "$", "config", "=", "require", "(", "$", "config", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "continue", ";", "}", "$", "result", "=", "self", "::", "mergeArray", "(", "$", "result", ",", "$", "config", ")", ";", "}", "return", "$", "result", ";", "}" ]
Merges the given configurations into a single configuration array. @param array $array the configurations to merge. @return array the merged configuration.
[ "Merges", "the", "given", "configurations", "into", "a", "single", "configuration", "array", "." ]
53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc
https://github.com/crisu83/yii-consoletools/blob/53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc/helpers/ConfigHelper.php#L20-L36
train
znframework/package-helpers
Debugger.php
Debugger.parent
public function parent(Int $index = 1) : stdClass { return $this->_layer($this->debug, $index, $index + 1); }
php
public function parent(Int $index = 1) : stdClass { return $this->_layer($this->debug, $index, $index + 1); }
[ "public", "function", "parent", "(", "Int", "$", "index", "=", "1", ")", ":", "stdClass", "{", "return", "$", "this", "->", "_layer", "(", "$", "this", "->", "debug", ",", "$", "index", ",", "$", "index", "+", "1", ")", ";", "}" ]
Parent Debug Data @param int $index = 1 @return object
[ "Parent", "Debug", "Data" ]
c78502263cdda5c14626a1abf7fc7e02dd2bd57d
https://github.com/znframework/package-helpers/blob/c78502263cdda5c14626a1abf7fc7e02dd2bd57d/Debugger.php#L52-L55
train
crisu83/yii-consoletools
commands/MysqldumpCommand.php
MysqldumpCommand.resolveDumpPath
protected function resolveDumpPath() { $path = $this->basePath . '/' . $this->dumpPath; $this->ensureDirectory($path); return realpath($path) . '/' . $this->dumpFile; }
php
protected function resolveDumpPath() { $path = $this->basePath . '/' . $this->dumpPath; $this->ensureDirectory($path); return realpath($path) . '/' . $this->dumpFile; }
[ "protected", "function", "resolveDumpPath", "(", ")", "{", "$", "path", "=", "$", "this", "->", "basePath", ".", "'/'", ".", "$", "this", "->", "dumpPath", ";", "$", "this", "->", "ensureDirectory", "(", "$", "path", ")", ";", "return", "realpath", "(", "$", "path", ")", ".", "'/'", ".", "$", "this", "->", "dumpFile", ";", "}" ]
Returns the path to the dump-file. @return string the path.
[ "Returns", "the", "path", "to", "the", "dump", "-", "file", "." ]
53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc
https://github.com/crisu83/yii-consoletools/blob/53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc/commands/MysqldumpCommand.php#L135-L140
train
crisu83/yii-consoletools
commands/MysqldumpCommand.php
MysqldumpCommand.normalizeOptions
protected function normalizeOptions($options) { $result = array(); foreach ($options as $name => $value) { $result[] = "--$name=\"$value\""; } return implode(' ', $result); }
php
protected function normalizeOptions($options) { $result = array(); foreach ($options as $name => $value) { $result[] = "--$name=\"$value\""; } return implode(' ', $result); }
[ "protected", "function", "normalizeOptions", "(", "$", "options", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "options", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "result", "[", "]", "=", "\"--$name=\\\"$value\\\"\"", ";", "}", "return", "implode", "(", "' '", ",", "$", "result", ")", ";", "}" ]
Normalizes the given options to a string @param array $options the options. @return string the options.
[ "Normalizes", "the", "given", "options", "to", "a", "string" ]
53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc
https://github.com/crisu83/yii-consoletools/blob/53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc/commands/MysqldumpCommand.php#L147-L154
train
crisu83/yii-consoletools
commands/MysqldumpCommand.php
MysqldumpCommand.getDb
protected function getDb() { if (isset($this->_db)) { return $this->_db; } else { if (($db = Yii::app()->getComponent($this->connectionID)) === null) { throw new CException(sprintf( 'Failed to get database connection. Component %s not found.', $this->connectionID )); } return $this->_db = $db; } }
php
protected function getDb() { if (isset($this->_db)) { return $this->_db; } else { if (($db = Yii::app()->getComponent($this->connectionID)) === null) { throw new CException(sprintf( 'Failed to get database connection. Component %s not found.', $this->connectionID )); } return $this->_db = $db; } }
[ "protected", "function", "getDb", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_db", ")", ")", "{", "return", "$", "this", "->", "_db", ";", "}", "else", "{", "if", "(", "(", "$", "db", "=", "Yii", "::", "app", "(", ")", "->", "getComponent", "(", "$", "this", "->", "connectionID", ")", ")", "===", "null", ")", "{", "throw", "new", "CException", "(", "sprintf", "(", "'Failed to get database connection. Component %s not found.'", ",", "$", "this", "->", "connectionID", ")", ")", ";", "}", "return", "$", "this", "->", "_db", "=", "$", "db", ";", "}", "}" ]
Returns the database connection component. @return CDbConnection the component. @throws CException if the component is not found.
[ "Returns", "the", "database", "connection", "component", "." ]
53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc
https://github.com/crisu83/yii-consoletools/blob/53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc/commands/MysqldumpCommand.php#L161-L174
train
andyburton/Sonic-Framework
src/Model.php
Model.get
public function get ($name) { // If the attribute doesn't exists if (!$this->attributeExists ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!'); } // If attribute getter isn't set or is disabled if (!$this->attributeGet ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute get is disabled!'); } // If no attribute value is set if (!$this->attributeHasValue ($name)) { // If there is a default set to value if (array_key_exists ('default', static::$attributes[$name])) { $this->iset ($name, static::$attributes[$name]['default'], FALSE); } // Else there is no value and no default else { throw new Exception (get_called_class () . '->' . $name . ' attribute isn\'t set and has no default value!'); } } // Return value return $this->attributeValues[$name]; }
php
public function get ($name) { // If the attribute doesn't exists if (!$this->attributeExists ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!'); } // If attribute getter isn't set or is disabled if (!$this->attributeGet ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute get is disabled!'); } // If no attribute value is set if (!$this->attributeHasValue ($name)) { // If there is a default set to value if (array_key_exists ('default', static::$attributes[$name])) { $this->iset ($name, static::$attributes[$name]['default'], FALSE); } // Else there is no value and no default else { throw new Exception (get_called_class () . '->' . $name . ' attribute isn\'t set and has no default value!'); } } // Return value return $this->attributeValues[$name]; }
[ "public", "function", "get", "(", "$", "name", ")", "{", "// If the attribute doesn't exists", "if", "(", "!", "$", "this", "->", "attributeExists", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "get_called_class", "(", ")", ".", "'->'", ".", "$", "name", ".", "' attribute does not exist!'", ")", ";", "}", "// If attribute getter isn't set or is disabled", "if", "(", "!", "$", "this", "->", "attributeGet", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "get_called_class", "(", ")", ".", "'->'", ".", "$", "name", ".", "' attribute get is disabled!'", ")", ";", "}", "// If no attribute value is set", "if", "(", "!", "$", "this", "->", "attributeHasValue", "(", "$", "name", ")", ")", "{", "// If there is a default set to value", "if", "(", "array_key_exists", "(", "'default'", ",", "static", "::", "$", "attributes", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "iset", "(", "$", "name", ",", "static", "::", "$", "attributes", "[", "$", "name", "]", "[", "'default'", "]", ",", "FALSE", ")", ";", "}", "// Else there is no value and no default", "else", "{", "throw", "new", "Exception", "(", "get_called_class", "(", ")", ".", "'->'", ".", "$", "name", ".", "' attribute isn\\'t set and has no default value!'", ")", ";", "}", "}", "// Return value", "return", "$", "this", "->", "attributeValues", "[", "$", "name", "]", ";", "}" ]
Return an attribute value if allowed by attribute getter @param string $name Attribute name @throws Exception @return mixed
[ "Return", "an", "attribute", "value", "if", "allowed", "by", "attribute", "getter" ]
a5999448a0abab4d542413002a780ede391e7374
https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Model.php#L328-L370
train
andyburton/Sonic-Framework
src/Model.php
Model.set
public function set ($name, $val, $validate = TRUE) { // If the attribute doesn't exists if (!$this->attributeExists ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!'); } // If attribute setter isn't set or is disabled if (!$this->attributeSet ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute set is disabled!'); } // If we're validating the value if ($validate) { // Set friendly name if one exists $friendlyName = isset (static::$attributes[$name]['name'])? static::$attributes[$name]['name'] : $name; // Validate it using the parser method $this->parser->Validate ($friendlyName, static::$attributes[$name], $val); } // Set the attribute value $this->attributeValues[$name] = $val; }
php
public function set ($name, $val, $validate = TRUE) { // If the attribute doesn't exists if (!$this->attributeExists ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!'); } // If attribute setter isn't set or is disabled if (!$this->attributeSet ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute set is disabled!'); } // If we're validating the value if ($validate) { // Set friendly name if one exists $friendlyName = isset (static::$attributes[$name]['name'])? static::$attributes[$name]['name'] : $name; // Validate it using the parser method $this->parser->Validate ($friendlyName, static::$attributes[$name], $val); } // Set the attribute value $this->attributeValues[$name] = $val; }
[ "public", "function", "set", "(", "$", "name", ",", "$", "val", ",", "$", "validate", "=", "TRUE", ")", "{", "// If the attribute doesn't exists", "if", "(", "!", "$", "this", "->", "attributeExists", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "get_called_class", "(", ")", ".", "'->'", ".", "$", "name", ".", "' attribute does not exist!'", ")", ";", "}", "// If attribute setter isn't set or is disabled", "if", "(", "!", "$", "this", "->", "attributeSet", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "get_called_class", "(", ")", ".", "'->'", ".", "$", "name", ".", "' attribute set is disabled!'", ")", ";", "}", "// If we're validating the value", "if", "(", "$", "validate", ")", "{", "// Set friendly name if one exists", "$", "friendlyName", "=", "isset", "(", "static", "::", "$", "attributes", "[", "$", "name", "]", "[", "'name'", "]", ")", "?", "static", "::", "$", "attributes", "[", "$", "name", "]", "[", "'name'", "]", ":", "$", "name", ";", "// Validate it using the parser method", "$", "this", "->", "parser", "->", "Validate", "(", "$", "friendlyName", ",", "static", "::", "$", "attributes", "[", "$", "name", "]", ",", "$", "val", ")", ";", "}", "// Set the attribute value", "$", "this", "->", "attributeValues", "[", "$", "name", "]", "=", "$", "val", ";", "}" ]
Set an attribute value if allowed by attribute setter @param string $name Attribute name @param mixed $val Attribute value @param boolean $validate Whether to validate the value @throws Exception|Parser\Exception @return void
[ "Set", "an", "attribute", "value", "if", "allowed", "by", "attribute", "setter" ]
a5999448a0abab4d542413002a780ede391e7374
https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Model.php#L382-L418
train
andyburton/Sonic-Framework
src/Model.php
Model.reset
public function reset ($name) { // If the attribute doesn't exists if (!$this->attributeExists ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!'); } // If attribute reset is disabled if (!$this->attributeReset ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute reset is disabled!'); } // If there is no default attribute value remove the value if (!array_key_exists ('default', static::$attributes[$name])) { unset ($this->attributeValues[$name]); } // Else there is a default attribute value so set it else { $this->iset ($name, static::$attributes[$name]['default'], FALSE); } }
php
public function reset ($name) { // If the attribute doesn't exists if (!$this->attributeExists ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute does not exist!'); } // If attribute reset is disabled if (!$this->attributeReset ($name)) { throw new Exception (get_called_class () . '->' . $name . ' attribute reset is disabled!'); } // If there is no default attribute value remove the value if (!array_key_exists ('default', static::$attributes[$name])) { unset ($this->attributeValues[$name]); } // Else there is a default attribute value so set it else { $this->iset ($name, static::$attributes[$name]['default'], FALSE); } }
[ "public", "function", "reset", "(", "$", "name", ")", "{", "// If the attribute doesn't exists", "if", "(", "!", "$", "this", "->", "attributeExists", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "get_called_class", "(", ")", ".", "'->'", ".", "$", "name", ".", "' attribute does not exist!'", ")", ";", "}", "// If attribute reset is disabled", "if", "(", "!", "$", "this", "->", "attributeReset", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "get_called_class", "(", ")", ".", "'->'", ".", "$", "name", ".", "' attribute reset is disabled!'", ")", ";", "}", "// If there is no default attribute value remove the value", "if", "(", "!", "array_key_exists", "(", "'default'", ",", "static", "::", "$", "attributes", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "attributeValues", "[", "$", "name", "]", ")", ";", "}", "// Else there is a default attribute value so set it", "else", "{", "$", "this", "->", "iset", "(", "$", "name", ",", "static", "::", "$", "attributes", "[", "$", "name", "]", "[", "'default'", "]", ",", "FALSE", ")", ";", "}", "}" ]
Reset an attribute value to its default @param string $name Attribute name @throws Exception @return void
[ "Reset", "an", "attribute", "value", "to", "its", "default" ]
a5999448a0abab4d542413002a780ede391e7374
https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Model.php#L522-L553
train