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
vimeo/psalm
src/Psalm/Codebase.php
Codebase.canTypeBeContainedByType
public function canTypeBeContainedByType( Type\Union $input_type, Type\Union $container_type ): bool { return TypeAnalyzer::canBeContainedBy($this, $input_type, $container_type); }
php
public function canTypeBeContainedByType( Type\Union $input_type, Type\Union $container_type ): bool { return TypeAnalyzer::canBeContainedBy($this, $input_type, $container_type); }
[ "public", "function", "canTypeBeContainedByType", "(", "Type", "\\", "Union", "$", "input_type", ",", "Type", "\\", "Union", "$", "container_type", ")", ":", "bool", "{", "return", "TypeAnalyzer", "::", "canBeContainedBy", "(", "$", "this", ",", "$", "input_type", ",", "$", "container_type", ")", ";", "}" ]
Checks if type has any part that is a subtype of other Given two types, checks if *any part* of `$input_type` is a subtype of `$container_type`. If you consider `Type\Union` as a set of types, this will tell you if intersection of `$input_type` with `$container_type` is not empty. $input_type ∩ $container_type ≠ ∅ , e.g. they are not disjoint. Useful for emitting issues like PossiblyInvalidArgument, where argument at the call site should be a subtype of the function parameter type, but it's has some types that are not a subtype of the required type.
[ "Checks", "if", "type", "has", "any", "part", "that", "is", "a", "subtype", "of", "other" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Codebase.php#L1171-L1176
train
vimeo/psalm
src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php
FunctionDocblockManipulator.setReturnType
public function setReturnType($php_type, $new_type, $phpdoc_type, $is_php_compatible, $description) { $new_type = str_replace(['<mixed, mixed>', '<array-key, mixed>', '<empty, empty>'], '', $new_type); $this->new_php_return_type = $php_type; $this->new_phpdoc_return_type = $phpdoc_type; $this->new_psalm_return_type = $new_type; $this->return_type_is_php_compatible = $is_php_compatible; $this->return_type_description = $description; }
php
public function setReturnType($php_type, $new_type, $phpdoc_type, $is_php_compatible, $description) { $new_type = str_replace(['<mixed, mixed>', '<array-key, mixed>', '<empty, empty>'], '', $new_type); $this->new_php_return_type = $php_type; $this->new_phpdoc_return_type = $phpdoc_type; $this->new_psalm_return_type = $new_type; $this->return_type_is_php_compatible = $is_php_compatible; $this->return_type_description = $description; }
[ "public", "function", "setReturnType", "(", "$", "php_type", ",", "$", "new_type", ",", "$", "phpdoc_type", ",", "$", "is_php_compatible", ",", "$", "description", ")", "{", "$", "new_type", "=", "str_replace", "(", "[", "'<mixed, mixed>'", ",", "'<array-key, mixed>'", ",", "'<empty, empty>'", "]", ",", "''", ",", "$", "new_type", ")", ";", "$", "this", "->", "new_php_return_type", "=", "$", "php_type", ";", "$", "this", "->", "new_phpdoc_return_type", "=", "$", "phpdoc_type", ";", "$", "this", "->", "new_psalm_return_type", "=", "$", "new_type", ";", "$", "this", "->", "return_type_is_php_compatible", "=", "$", "is_php_compatible", ";", "$", "this", "->", "return_type_description", "=", "$", "description", ";", "}" ]
Sets the new return type @param ?string $php_type @param string $new_type @param string $phpdoc_type @param bool $is_php_compatible @param ?string $description @return void
[ "Sets", "the", "new", "return", "type" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php#L253-L262
train
vimeo/psalm
src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php
FunctionDocblockManipulator.setParamType
public function setParamType($param_name, $php_type, $new_type, $phpdoc_type, $is_php_compatible) { $new_type = str_replace(['<mixed, mixed>', '<array-key, mixed>', '<empty, empty>'], '', $new_type); if ($php_type) { $this->new_php_param_types[$param_name] = $php_type; } $this->new_phpdoc_param_types[$param_name] = $phpdoc_type; $this->new_psalm_param_types[$param_name] = $new_type; $this->param_type_is_php_compatible[$param_name] = $is_php_compatible; }
php
public function setParamType($param_name, $php_type, $new_type, $phpdoc_type, $is_php_compatible) { $new_type = str_replace(['<mixed, mixed>', '<array-key, mixed>', '<empty, empty>'], '', $new_type); if ($php_type) { $this->new_php_param_types[$param_name] = $php_type; } $this->new_phpdoc_param_types[$param_name] = $phpdoc_type; $this->new_psalm_param_types[$param_name] = $new_type; $this->param_type_is_php_compatible[$param_name] = $is_php_compatible; }
[ "public", "function", "setParamType", "(", "$", "param_name", ",", "$", "php_type", ",", "$", "new_type", ",", "$", "phpdoc_type", ",", "$", "is_php_compatible", ")", "{", "$", "new_type", "=", "str_replace", "(", "[", "'<mixed, mixed>'", ",", "'<array-key, mixed>'", ",", "'<empty, empty>'", "]", ",", "''", ",", "$", "new_type", ")", ";", "if", "(", "$", "php_type", ")", "{", "$", "this", "->", "new_php_param_types", "[", "$", "param_name", "]", "=", "$", "php_type", ";", "}", "$", "this", "->", "new_phpdoc_param_types", "[", "$", "param_name", "]", "=", "$", "phpdoc_type", ";", "$", "this", "->", "new_psalm_param_types", "[", "$", "param_name", "]", "=", "$", "new_type", ";", "$", "this", "->", "param_type_is_php_compatible", "[", "$", "param_name", "]", "=", "$", "is_php_compatible", ";", "}" ]
Sets a new param type @param string $param_name @param ?string $php_type @param string $new_type @param string $phpdoc_type @param bool $is_php_compatible @return void
[ "Sets", "a", "new", "param", "type" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php#L275-L285
train
vimeo/psalm
src/Psalm/Internal/LanguageServer/LanguageServer.php
LanguageServer.pathToUri
public static function pathToUri(string $filepath): string { $filepath = trim(str_replace('\\', '/', $filepath), '/'); $parts = explode('/', $filepath); // Don't %-encode the colon after a Windows drive letter $first = array_shift($parts); if (substr($first, -1) !== ':') { $first = rawurlencode($first); } $parts = array_map('rawurlencode', $parts); array_unshift($parts, $first); $filepath = implode('/', $parts); return 'file:///' . $filepath; }
php
public static function pathToUri(string $filepath): string { $filepath = trim(str_replace('\\', '/', $filepath), '/'); $parts = explode('/', $filepath); // Don't %-encode the colon after a Windows drive letter $first = array_shift($parts); if (substr($first, -1) !== ':') { $first = rawurlencode($first); } $parts = array_map('rawurlencode', $parts); array_unshift($parts, $first); $filepath = implode('/', $parts); return 'file:///' . $filepath; }
[ "public", "static", "function", "pathToUri", "(", "string", "$", "filepath", ")", ":", "string", "{", "$", "filepath", "=", "trim", "(", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "filepath", ")", ",", "'/'", ")", ";", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "filepath", ")", ";", "// Don't %-encode the colon after a Windows drive letter", "$", "first", "=", "array_shift", "(", "$", "parts", ")", ";", "if", "(", "substr", "(", "$", "first", ",", "-", "1", ")", "!==", "':'", ")", "{", "$", "first", "=", "rawurlencode", "(", "$", "first", ")", ";", "}", "$", "parts", "=", "array_map", "(", "'rawurlencode'", ",", "$", "parts", ")", ";", "array_unshift", "(", "$", "parts", ",", "$", "first", ")", ";", "$", "filepath", "=", "implode", "(", "'/'", ",", "$", "parts", ")", ";", "return", "'file:///'", ".", "$", "filepath", ";", "}" ]
Transforms an absolute file path into a URI as used by the language server protocol. @param string $filepath @return string
[ "Transforms", "an", "absolute", "file", "path", "into", "a", "URI", "as", "used", "by", "the", "language", "server", "protocol", "." ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/LanguageServer/LanguageServer.php#L395-L408
train
vimeo/psalm
src/Psalm/Internal/LanguageServer/LanguageServer.php
LanguageServer.uriToPath
public static function uriToPath(string $uri) { $fragments = parse_url($uri); if ($fragments === false || !isset($fragments['scheme']) || $fragments['scheme'] !== 'file') { throw new \InvalidArgumentException("Not a valid file URI: $uri"); } $filepath = urldecode((string) $fragments['path']); if (strpos($filepath, ':') !== false) { if ($filepath[0] === '/') { $filepath = substr($filepath, 1); } $filepath = str_replace('/', '\\', $filepath); } return $filepath; }
php
public static function uriToPath(string $uri) { $fragments = parse_url($uri); if ($fragments === false || !isset($fragments['scheme']) || $fragments['scheme'] !== 'file') { throw new \InvalidArgumentException("Not a valid file URI: $uri"); } $filepath = urldecode((string) $fragments['path']); if (strpos($filepath, ':') !== false) { if ($filepath[0] === '/') { $filepath = substr($filepath, 1); } $filepath = str_replace('/', '\\', $filepath); } return $filepath; }
[ "public", "static", "function", "uriToPath", "(", "string", "$", "uri", ")", "{", "$", "fragments", "=", "parse_url", "(", "$", "uri", ")", ";", "if", "(", "$", "fragments", "===", "false", "||", "!", "isset", "(", "$", "fragments", "[", "'scheme'", "]", ")", "||", "$", "fragments", "[", "'scheme'", "]", "!==", "'file'", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Not a valid file URI: $uri\"", ")", ";", "}", "$", "filepath", "=", "urldecode", "(", "(", "string", ")", "$", "fragments", "[", "'path'", "]", ")", ";", "if", "(", "strpos", "(", "$", "filepath", ",", "':'", ")", "!==", "false", ")", "{", "if", "(", "$", "filepath", "[", "0", "]", "===", "'/'", ")", "{", "$", "filepath", "=", "substr", "(", "$", "filepath", ",", "1", ")", ";", "}", "$", "filepath", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "filepath", ")", ";", "}", "return", "$", "filepath", ";", "}" ]
Transforms URI into file path @param string $uri @return string
[ "Transforms", "URI", "into", "file", "path" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/LanguageServer/LanguageServer.php#L416-L430
train
vimeo/psalm
src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
FunctionLikeAnalyzer.addReturnTypes
public function addReturnTypes(Context $context) { if ($this->return_vars_in_scope !== null) { $this->return_vars_in_scope = TypeAnalyzer::combineKeyedTypes( $context->vars_in_scope, $this->return_vars_in_scope ); } else { $this->return_vars_in_scope = $context->vars_in_scope; } if ($this->return_vars_possibly_in_scope !== null) { $this->return_vars_possibly_in_scope = array_merge( $context->vars_possibly_in_scope, $this->return_vars_possibly_in_scope ); } else { $this->return_vars_possibly_in_scope = $context->vars_possibly_in_scope; } }
php
public function addReturnTypes(Context $context) { if ($this->return_vars_in_scope !== null) { $this->return_vars_in_scope = TypeAnalyzer::combineKeyedTypes( $context->vars_in_scope, $this->return_vars_in_scope ); } else { $this->return_vars_in_scope = $context->vars_in_scope; } if ($this->return_vars_possibly_in_scope !== null) { $this->return_vars_possibly_in_scope = array_merge( $context->vars_possibly_in_scope, $this->return_vars_possibly_in_scope ); } else { $this->return_vars_possibly_in_scope = $context->vars_possibly_in_scope; } }
[ "public", "function", "addReturnTypes", "(", "Context", "$", "context", ")", "{", "if", "(", "$", "this", "->", "return_vars_in_scope", "!==", "null", ")", "{", "$", "this", "->", "return_vars_in_scope", "=", "TypeAnalyzer", "::", "combineKeyedTypes", "(", "$", "context", "->", "vars_in_scope", ",", "$", "this", "->", "return_vars_in_scope", ")", ";", "}", "else", "{", "$", "this", "->", "return_vars_in_scope", "=", "$", "context", "->", "vars_in_scope", ";", "}", "if", "(", "$", "this", "->", "return_vars_possibly_in_scope", "!==", "null", ")", "{", "$", "this", "->", "return_vars_possibly_in_scope", "=", "array_merge", "(", "$", "context", "->", "vars_possibly_in_scope", ",", "$", "this", "->", "return_vars_possibly_in_scope", ")", ";", "}", "else", "{", "$", "this", "->", "return_vars_possibly_in_scope", "=", "$", "context", "->", "vars_possibly_in_scope", ";", "}", "}" ]
Adds return types for the given function @param string $return_type @param Context $context @return void
[ "Adds", "return", "types", "for", "the", "given", "function" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php#L998-L1017
train
vimeo/psalm
src/Psalm/Internal/LanguageServer/ClientHandler.php
ClientHandler.notify
public function notify(string $method, $params): Promise { return $this->protocolWriter->write( new Message( new AdvancedJsonRpc\Notification($method, (object)$params) ) ); }
php
public function notify(string $method, $params): Promise { return $this->protocolWriter->write( new Message( new AdvancedJsonRpc\Notification($method, (object)$params) ) ); }
[ "public", "function", "notify", "(", "string", "$", "method", ",", "$", "params", ")", ":", "Promise", "{", "return", "$", "this", "->", "protocolWriter", "->", "write", "(", "new", "Message", "(", "new", "AdvancedJsonRpc", "\\", "Notification", "(", "$", "method", ",", "(", "object", ")", "$", "params", ")", ")", ")", ";", "}" ]
Sends a notification to the client @param string $method The method to call @param array|object $params The method parameters @return Promise <null> Will be resolved as soon as the notification has been sent
[ "Sends", "a", "notification", "to", "the", "client" ]
dd409871876fcafb4a85ac3901453fb05c46814c
https://github.com/vimeo/psalm/blob/dd409871876fcafb4a85ac3901453fb05c46814c/src/Psalm/Internal/LanguageServer/ClientHandler.php#L98-L105
train
facebook/php-webdriver
lib/Interactions/WebDriverActions.php
WebDriverActions.moveByOffset
public function moveByOffset($x_offset, $y_offset) { $this->action->addAction( new WebDriverMoveToOffsetAction($this->mouse, null, $x_offset, $y_offset) ); return $this; }
php
public function moveByOffset($x_offset, $y_offset) { $this->action->addAction( new WebDriverMoveToOffsetAction($this->mouse, null, $x_offset, $y_offset) ); return $this; }
[ "public", "function", "moveByOffset", "(", "$", "x_offset", ",", "$", "y_offset", ")", "{", "$", "this", "->", "action", "->", "addAction", "(", "new", "WebDriverMoveToOffsetAction", "(", "$", "this", "->", "mouse", ",", "null", ",", "$", "x_offset", ",", "$", "y_offset", ")", ")", ";", "return", "$", "this", ";", "}" ]
Mouse move by offset. @param int $x_offset @param int $y_offset @return WebDriverActions
[ "Mouse", "move", "by", "offset", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Interactions/WebDriverActions.php#L177-L184
train
facebook/php-webdriver
lib/Cookie.php
Cookie.setDomain
public function setDomain($domain) { if (mb_strpos($domain, ':') !== false) { throw new InvalidArgumentException(sprintf('Cookie domain "%s" should not contain a port', $domain)); } $this->cookie['domain'] = $domain; }
php
public function setDomain($domain) { if (mb_strpos($domain, ':') !== false) { throw new InvalidArgumentException(sprintf('Cookie domain "%s" should not contain a port', $domain)); } $this->cookie['domain'] = $domain; }
[ "public", "function", "setDomain", "(", "$", "domain", ")", "{", "if", "(", "mb_strpos", "(", "$", "domain", ",", "':'", ")", "!==", "false", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Cookie domain \"%s\" should not contain a port'", ",", "$", "domain", ")", ")", ";", "}", "$", "this", "->", "cookie", "[", "'domain'", "]", "=", "$", "domain", ";", "}" ]
The domain the cookie is visible to. Defaults to the current browsing context's document's URL domain if omitted. @param string $domain
[ "The", "domain", "the", "cookie", "is", "visible", "to", ".", "Defaults", "to", "the", "current", "browsing", "context", "s", "document", "s", "URL", "domain", "if", "omitted", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Cookie.php#L119-L126
train
facebook/php-webdriver
lib/Remote/RemoteKeyboard.php
RemoteKeyboard.sendKeys
public function sendKeys($keys) { $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [ 'value' => WebDriverKeys::encode($keys), ]); return $this; }
php
public function sendKeys($keys) { $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [ 'value' => WebDriverKeys::encode($keys), ]); return $this; }
[ "public", "function", "sendKeys", "(", "$", "keys", ")", "{", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SEND_KEYS_TO_ACTIVE_ELEMENT", ",", "[", "'value'", "=>", "WebDriverKeys", "::", "encode", "(", "$", "keys", ")", ",", "]", ")", ";", "return", "$", "this", ";", "}" ]
Send keys to active element @param string|array $keys @return $this
[ "Send", "keys", "to", "active", "element" ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteKeyboard.php#L44-L51
train
facebook/php-webdriver
lib/Remote/RemoteKeyboard.php
RemoteKeyboard.pressKey
public function pressKey($key) { $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [ 'value' => [(string) $key], ]); return $this; }
php
public function pressKey($key) { $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [ 'value' => [(string) $key], ]); return $this; }
[ "public", "function", "pressKey", "(", "$", "key", ")", "{", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SEND_KEYS_TO_ACTIVE_ELEMENT", ",", "[", "'value'", "=>", "[", "(", "string", ")", "$", "key", "]", ",", "]", ")", ";", "return", "$", "this", ";", "}" ]
Press a modifier key @see WebDriverKeys @param string $key @return $this
[ "Press", "a", "modifier", "key" ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteKeyboard.php#L60-L67
train
facebook/php-webdriver
lib/Remote/RemoteKeyboard.php
RemoteKeyboard.releaseKey
public function releaseKey($key) { $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [ 'value' => [(string) $key], ]); return $this; }
php
public function releaseKey($key) { $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [ 'value' => [(string) $key], ]); return $this; }
[ "public", "function", "releaseKey", "(", "$", "key", ")", "{", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SEND_KEYS_TO_ACTIVE_ELEMENT", ",", "[", "'value'", "=>", "[", "(", "string", ")", "$", "key", "]", ",", "]", ")", ";", "return", "$", "this", ";", "}" ]
Release a modifier key @see WebDriverKeys @param string $key @return $this
[ "Release", "a", "modifier", "key" ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteKeyboard.php#L76-L83
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.titleContains
public static function titleContains($title) { return new static( function (WebDriver $driver) use ($title) { return mb_strpos($driver->getTitle(), $title) !== false; } ); }
php
public static function titleContains($title) { return new static( function (WebDriver $driver) use ($title) { return mb_strpos($driver->getTitle(), $title) !== false; } ); }
[ "public", "static", "function", "titleContains", "(", "$", "title", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "title", ")", "{", "return", "mb_strpos", "(", "$", "driver", "->", "getTitle", "(", ")", ",", "$", "title", ")", "!==", "false", ";", "}", ")", ";", "}" ]
An expectation for checking substring of a page Title. @param string $title The expected substring of Title. @return static Condition returns whether current page title contains given string.
[ "An", "expectation", "for", "checking", "substring", "of", "a", "page", "Title", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L71-L78
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.titleMatches
public static function titleMatches($titleRegexp) { return new static( function (WebDriver $driver) use ($titleRegexp) { return (bool) preg_match($titleRegexp, $driver->getTitle()); } ); }
php
public static function titleMatches($titleRegexp) { return new static( function (WebDriver $driver) use ($titleRegexp) { return (bool) preg_match($titleRegexp, $driver->getTitle()); } ); }
[ "public", "static", "function", "titleMatches", "(", "$", "titleRegexp", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "titleRegexp", ")", "{", "return", "(", "bool", ")", "preg_match", "(", "$", "titleRegexp", ",", "$", "driver", "->", "getTitle", "(", ")", ")", ";", "}", ")", ";", "}" ]
An expectation for checking current page title matches the given regular expression. @param string $titleRegexp The regular expression to test against. @return static Condition returns whether current page title matches the regular expression.
[ "An", "expectation", "for", "checking", "current", "page", "title", "matches", "the", "given", "regular", "expression", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L86-L93
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.urlContains
public static function urlContains($url) { return new static( function (WebDriver $driver) use ($url) { return mb_strpos($driver->getCurrentURL(), $url) !== false; } ); }
php
public static function urlContains($url) { return new static( function (WebDriver $driver) use ($url) { return mb_strpos($driver->getCurrentURL(), $url) !== false; } ); }
[ "public", "static", "function", "urlContains", "(", "$", "url", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "url", ")", "{", "return", "mb_strpos", "(", "$", "driver", "->", "getCurrentURL", "(", ")", ",", "$", "url", ")", "!==", "false", ";", "}", ")", ";", "}" ]
An expectation for checking substring of the URL of a page. @param string $url The expected substring of the URL @return static Condition returns whether current URL contains given string.
[ "An", "expectation", "for", "checking", "substring", "of", "the", "URL", "of", "a", "page", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L116-L123
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.urlMatches
public static function urlMatches($urlRegexp) { return new static( function (WebDriver $driver) use ($urlRegexp) { return (bool) preg_match($urlRegexp, $driver->getCurrentURL()); } ); }
php
public static function urlMatches($urlRegexp) { return new static( function (WebDriver $driver) use ($urlRegexp) { return (bool) preg_match($urlRegexp, $driver->getCurrentURL()); } ); }
[ "public", "static", "function", "urlMatches", "(", "$", "urlRegexp", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "urlRegexp", ")", "{", "return", "(", "bool", ")", "preg_match", "(", "$", "urlRegexp", ",", "$", "driver", "->", "getCurrentURL", "(", ")", ")", ";", "}", ")", ";", "}" ]
An expectation for checking current page URL matches the given regular expression. @param string $urlRegexp The regular expression to test against. @return static Condition returns whether current URL matches the regular expression.
[ "An", "expectation", "for", "checking", "current", "page", "URL", "matches", "the", "given", "regular", "expression", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L131-L138
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.presenceOfAllElementsLocatedBy
public static function presenceOfAllElementsLocatedBy(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { $elements = $driver->findElements($by); return count($elements) > 0 ? $elements : null; } ); }
php
public static function presenceOfAllElementsLocatedBy(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { $elements = $driver->findElements($by); return count($elements) > 0 ? $elements : null; } ); }
[ "public", "static", "function", "presenceOfAllElementsLocatedBy", "(", "WebDriverBy", "$", "by", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "by", ")", "{", "$", "elements", "=", "$", "driver", "->", "findElements", "(", "$", "by", ")", ";", "return", "count", "(", "$", "elements", ")", ">", "0", "?", "$", "elements", ":", "null", ";", "}", ")", ";", "}" ]
An expectation for checking that there is at least one element present on a web page. @param WebDriverBy $by The locator used to find the element. @return static Condition return an array of WebDriverElement once they are located.
[ "An", "expectation", "for", "checking", "that", "there", "is", "at", "least", "one", "element", "present", "on", "a", "web", "page", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L162-L171
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.visibilityOfElementLocated
public static function visibilityOfElementLocated(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { try { $element = $driver->findElement($by); return $element->isDisplayed() ? $element : null; } catch (StaleElementReferenceException $e) { return null; } } ); }
php
public static function visibilityOfElementLocated(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { try { $element = $driver->findElement($by); return $element->isDisplayed() ? $element : null; } catch (StaleElementReferenceException $e) { return null; } } ); }
[ "public", "static", "function", "visibilityOfElementLocated", "(", "WebDriverBy", "$", "by", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "by", ")", "{", "try", "{", "$", "element", "=", "$", "driver", "->", "findElement", "(", "$", "by", ")", ";", "return", "$", "element", "->", "isDisplayed", "(", ")", "?", "$", "element", ":", "null", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "null", ";", "}", "}", ")", ";", "}" ]
An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. @param WebDriverBy $by The locator used to find the element. @return static Condition returns the WebDriverElement which is located and visible.
[ "An", "expectation", "for", "checking", "that", "an", "element", "is", "present", "on", "the", "DOM", "of", "a", "page", "and", "visible", ".", "Visibility", "means", "that", "the", "element", "is", "not", "only", "displayed", "but", "also", "has", "a", "height", "and", "width", "that", "is", "greater", "than", "0", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L180-L193
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.visibilityOfAnyElementLocated
public static function visibilityOfAnyElementLocated(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { $elements = $driver->findElements($by); $visibleElements = []; foreach ($elements as $element) { try { if ($element->isDisplayed()) { $visibleElements[] = $element; } } catch (StaleElementReferenceException $e) { } } return count($visibleElements) > 0 ? $visibleElements : null; } ); }
php
public static function visibilityOfAnyElementLocated(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { $elements = $driver->findElements($by); $visibleElements = []; foreach ($elements as $element) { try { if ($element->isDisplayed()) { $visibleElements[] = $element; } } catch (StaleElementReferenceException $e) { } } return count($visibleElements) > 0 ? $visibleElements : null; } ); }
[ "public", "static", "function", "visibilityOfAnyElementLocated", "(", "WebDriverBy", "$", "by", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "by", ")", "{", "$", "elements", "=", "$", "driver", "->", "findElements", "(", "$", "by", ")", ";", "$", "visibleElements", "=", "[", "]", ";", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "try", "{", "if", "(", "$", "element", "->", "isDisplayed", "(", ")", ")", "{", "$", "visibleElements", "[", "]", "=", "$", "element", ";", "}", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "}", "}", "return", "count", "(", "$", "visibleElements", ")", ">", "0", "?", "$", "visibleElements", ":", "null", ";", "}", ")", ";", "}" ]
An expectation for checking than at least one element in an array of elements is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. @param WebDriverBy $by The located used to find the element. @return static Condition returns the array of WebDriverElement that are located and visible.
[ "An", "expectation", "for", "checking", "than", "at", "least", "one", "element", "in", "an", "array", "of", "elements", "is", "present", "on", "the", "DOM", "of", "a", "page", "and", "visible", ".", "Visibility", "means", "that", "the", "element", "is", "not", "only", "displayed", "but", "also", "has", "a", "height", "and", "width", "that", "is", "greater", "than", "0", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L203-L222
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.elementTextMatches
public static function elementTextMatches(WebDriverBy $by, $regexp) { return new static( function (WebDriver $driver) use ($by, $regexp) { try { return (bool) preg_match($regexp, $driver->findElement($by)->getText()); } catch (StaleElementReferenceException $e) { return null; } } ); }
php
public static function elementTextMatches(WebDriverBy $by, $regexp) { return new static( function (WebDriver $driver) use ($by, $regexp) { try { return (bool) preg_match($regexp, $driver->findElement($by)->getText()); } catch (StaleElementReferenceException $e) { return null; } } ); }
[ "public", "static", "function", "elementTextMatches", "(", "WebDriverBy", "$", "by", ",", "$", "regexp", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "by", ",", "$", "regexp", ")", "{", "try", "{", "return", "(", "bool", ")", "preg_match", "(", "$", "regexp", ",", "$", "driver", "->", "findElement", "(", "$", "by", ")", "->", "getText", "(", ")", ")", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "null", ";", "}", "}", ")", ";", "}" ]
An expectation for checking if the given regular expression matches the text in specified element. @param WebDriverBy $by The locator used to find the element. @param string $regexp The regular expression to test against. @return static Condition returns whether the element has text value equal to given one.
[ "An", "expectation", "for", "checking", "if", "the", "given", "regular", "expression", "matches", "the", "text", "in", "specified", "element", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L306-L317
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.elementValueContains
public static function elementValueContains(WebDriverBy $by, $text) { return new static( function (WebDriver $driver) use ($by, $text) { try { $element_text = $driver->findElement($by)->getAttribute('value'); return mb_strpos($element_text, $text) !== false; } catch (StaleElementReferenceException $e) { return null; } } ); }
php
public static function elementValueContains(WebDriverBy $by, $text) { return new static( function (WebDriver $driver) use ($by, $text) { try { $element_text = $driver->findElement($by)->getAttribute('value'); return mb_strpos($element_text, $text) !== false; } catch (StaleElementReferenceException $e) { return null; } } ); }
[ "public", "static", "function", "elementValueContains", "(", "WebDriverBy", "$", "by", ",", "$", "text", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "by", ",", "$", "text", ")", "{", "try", "{", "$", "element_text", "=", "$", "driver", "->", "findElement", "(", "$", "by", ")", "->", "getAttribute", "(", "'value'", ")", ";", "return", "mb_strpos", "(", "$", "element_text", ",", "$", "text", ")", "!==", "false", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "null", ";", "}", "}", ")", ";", "}" ]
An expectation for checking if the given text is present in the specified elements value attribute. @param WebDriverBy $by The locator used to find the element. @param string $text The text to be presented in the element value. @return static Condition returns whether the text is present in value attribute.
[ "An", "expectation", "for", "checking", "if", "the", "given", "text", "is", "present", "in", "the", "specified", "elements", "value", "attribute", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L340-L353
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.frameToBeAvailableAndSwitchToIt
public static function frameToBeAvailableAndSwitchToIt($frame_locator) { return new static( function (WebDriver $driver) use ($frame_locator) { try { return $driver->switchTo()->frame($frame_locator); } catch (NoSuchFrameException $e) { return false; } } ); }
php
public static function frameToBeAvailableAndSwitchToIt($frame_locator) { return new static( function (WebDriver $driver) use ($frame_locator) { try { return $driver->switchTo()->frame($frame_locator); } catch (NoSuchFrameException $e) { return false; } } ); }
[ "public", "static", "function", "frameToBeAvailableAndSwitchToIt", "(", "$", "frame_locator", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "frame_locator", ")", "{", "try", "{", "return", "$", "driver", "->", "switchTo", "(", ")", "->", "frame", "(", "$", "frame_locator", ")", ";", "}", "catch", "(", "NoSuchFrameException", "$", "e", ")", "{", "return", "false", ";", "}", "}", ")", ";", "}" ]
Expectation for checking if iFrame exists. If iFrame exists switches driver's focus to the iFrame. @param string $frame_locator The locator used to find the iFrame expected to be either the id or name value of the i/frame @return static Condition returns object focused on new frame when frame is found, false otherwise.
[ "Expectation", "for", "checking", "if", "iFrame", "exists", ".", "If", "iFrame", "exists", "switches", "driver", "s", "focus", "to", "the", "iFrame", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L362-L373
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.invisibilityOfElementLocated
public static function invisibilityOfElementLocated(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { try { return !$driver->findElement($by)->isDisplayed(); } catch (NoSuchElementException $e) { return true; } catch (StaleElementReferenceException $e) { return true; } } ); }
php
public static function invisibilityOfElementLocated(WebDriverBy $by) { return new static( function (WebDriver $driver) use ($by) { try { return !$driver->findElement($by)->isDisplayed(); } catch (NoSuchElementException $e) { return true; } catch (StaleElementReferenceException $e) { return true; } } ); }
[ "public", "static", "function", "invisibilityOfElementLocated", "(", "WebDriverBy", "$", "by", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "by", ")", "{", "try", "{", "return", "!", "$", "driver", "->", "findElement", "(", "$", "by", ")", "->", "isDisplayed", "(", ")", ";", "}", "catch", "(", "NoSuchElementException", "$", "e", ")", "{", "return", "true", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "true", ";", "}", "}", ")", ";", "}" ]
An expectation for checking that an element is either invisible or not present on the DOM. @param WebDriverBy $by The locator used to find the element. @return static Condition returns whether no visible element located.
[ "An", "expectation", "for", "checking", "that", "an", "element", "is", "either", "invisible", "or", "not", "present", "on", "the", "DOM", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L381-L394
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.invisibilityOfElementWithText
public static function invisibilityOfElementWithText(WebDriverBy $by, $text) { return new static( function (WebDriver $driver) use ($by, $text) { try { return !($driver->findElement($by)->getText() === $text); } catch (NoSuchElementException $e) { return true; } catch (StaleElementReferenceException $e) { return true; } } ); }
php
public static function invisibilityOfElementWithText(WebDriverBy $by, $text) { return new static( function (WebDriver $driver) use ($by, $text) { try { return !($driver->findElement($by)->getText() === $text); } catch (NoSuchElementException $e) { return true; } catch (StaleElementReferenceException $e) { return true; } } ); }
[ "public", "static", "function", "invisibilityOfElementWithText", "(", "WebDriverBy", "$", "by", ",", "$", "text", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "by", ",", "$", "text", ")", "{", "try", "{", "return", "!", "(", "$", "driver", "->", "findElement", "(", "$", "by", ")", "->", "getText", "(", ")", "===", "$", "text", ")", ";", "}", "catch", "(", "NoSuchElementException", "$", "e", ")", "{", "return", "true", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "true", ";", "}", "}", ")", ";", "}" ]
An expectation for checking that an element with text is either invisible or not present on the DOM. @param WebDriverBy $by The locator used to find the element. @param string $text The text of the element. @return static Condition returns whether the text is found in the element located.
[ "An", "expectation", "for", "checking", "that", "an", "element", "with", "text", "is", "either", "invisible", "or", "not", "present", "on", "the", "DOM", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L403-L416
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.elementToBeClickable
public static function elementToBeClickable(WebDriverBy $by) { $visibility_of_element_located = self::visibilityOfElementLocated($by); return new static( function (WebDriver $driver) use ($visibility_of_element_located) { $element = call_user_func( $visibility_of_element_located->getApply(), $driver ); try { if ($element !== null && $element->isEnabled()) { return $element; } return null; } catch (StaleElementReferenceException $e) { return null; } } ); }
php
public static function elementToBeClickable(WebDriverBy $by) { $visibility_of_element_located = self::visibilityOfElementLocated($by); return new static( function (WebDriver $driver) use ($visibility_of_element_located) { $element = call_user_func( $visibility_of_element_located->getApply(), $driver ); try { if ($element !== null && $element->isEnabled()) { return $element; } return null; } catch (StaleElementReferenceException $e) { return null; } } ); }
[ "public", "static", "function", "elementToBeClickable", "(", "WebDriverBy", "$", "by", ")", "{", "$", "visibility_of_element_located", "=", "self", "::", "visibilityOfElementLocated", "(", "$", "by", ")", ";", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "visibility_of_element_located", ")", "{", "$", "element", "=", "call_user_func", "(", "$", "visibility_of_element_located", "->", "getApply", "(", ")", ",", "$", "driver", ")", ";", "try", "{", "if", "(", "$", "element", "!==", "null", "&&", "$", "element", "->", "isEnabled", "(", ")", ")", "{", "return", "$", "element", ";", "}", "return", "null", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "null", ";", "}", "}", ")", ";", "}" ]
An expectation for checking an element is visible and enabled such that you can click it. @param WebDriverBy $by The locator used to find the element @return static Condition return the WebDriverElement once it is located, visible and clickable.
[ "An", "expectation", "for", "checking", "an", "element", "is", "visible", "and", "enabled", "such", "that", "you", "can", "click", "it", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L424-L446
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.stalenessOf
public static function stalenessOf(WebDriverElement $element) { return new static( function () use ($element) { try { $element->isEnabled(); return false; } catch (StaleElementReferenceException $e) { return true; } } ); }
php
public static function stalenessOf(WebDriverElement $element) { return new static( function () use ($element) { try { $element->isEnabled(); return false; } catch (StaleElementReferenceException $e) { return true; } } ); }
[ "public", "static", "function", "stalenessOf", "(", "WebDriverElement", "$", "element", ")", "{", "return", "new", "static", "(", "function", "(", ")", "use", "(", "$", "element", ")", "{", "try", "{", "$", "element", "->", "isEnabled", "(", ")", ";", "return", "false", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "true", ";", "}", "}", ")", ";", "}" ]
Wait until an element is no longer attached to the DOM. @param WebDriverElement $element The element to wait for. @return static Condition returns whether the element is still attached to the DOM.
[ "Wait", "until", "an", "element", "is", "no", "longer", "attached", "to", "the", "DOM", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L454-L467
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.refreshed
public static function refreshed(self $condition) { return new static( function (WebDriver $driver) use ($condition) { try { return call_user_func($condition->getApply(), $driver); } catch (StaleElementReferenceException $e) { return null; } } ); }
php
public static function refreshed(self $condition) { return new static( function (WebDriver $driver) use ($condition) { try { return call_user_func($condition->getApply(), $driver); } catch (StaleElementReferenceException $e) { return null; } } ); }
[ "public", "static", "function", "refreshed", "(", "self", "$", "condition", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "condition", ")", "{", "try", "{", "return", "call_user_func", "(", "$", "condition", "->", "getApply", "(", ")", ",", "$", "driver", ")", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "null", ";", "}", "}", ")", ";", "}" ]
Wrapper for a condition, which allows for elements to update by redrawing. This works around the problem of conditions which have two parts: find an element and then check for some condition on it. For these conditions it is possible that an element is located and then subsequently it is redrawn on the client. When this happens a StaleElementReferenceException is thrown when the second part of the condition is checked. @param WebDriverExpectedCondition $condition The condition wrapped. @return static Condition returns the return value of the getApply() of the given condition.
[ "Wrapper", "for", "a", "condition", "which", "allows", "for", "elements", "to", "update", "by", "redrawing", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L480-L491
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.elementSelectionStateToBe
public static function elementSelectionStateToBe($element_or_by, $selected) { if ($element_or_by instanceof WebDriverElement) { return new static( function () use ($element_or_by, $selected) { return $element_or_by->isSelected() === $selected; } ); } else { if ($element_or_by instanceof WebDriverBy) { return new static( function (WebDriver $driver) use ($element_or_by, $selected) { try { $element = $driver->findElement($element_or_by); return $element->isSelected() === $selected; } catch (StaleElementReferenceException $e) { return null; } } ); } } }
php
public static function elementSelectionStateToBe($element_or_by, $selected) { if ($element_or_by instanceof WebDriverElement) { return new static( function () use ($element_or_by, $selected) { return $element_or_by->isSelected() === $selected; } ); } else { if ($element_or_by instanceof WebDriverBy) { return new static( function (WebDriver $driver) use ($element_or_by, $selected) { try { $element = $driver->findElement($element_or_by); return $element->isSelected() === $selected; } catch (StaleElementReferenceException $e) { return null; } } ); } } }
[ "public", "static", "function", "elementSelectionStateToBe", "(", "$", "element_or_by", ",", "$", "selected", ")", "{", "if", "(", "$", "element_or_by", "instanceof", "WebDriverElement", ")", "{", "return", "new", "static", "(", "function", "(", ")", "use", "(", "$", "element_or_by", ",", "$", "selected", ")", "{", "return", "$", "element_or_by", "->", "isSelected", "(", ")", "===", "$", "selected", ";", "}", ")", ";", "}", "else", "{", "if", "(", "$", "element_or_by", "instanceof", "WebDriverBy", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "element_or_by", ",", "$", "selected", ")", "{", "try", "{", "$", "element", "=", "$", "driver", "->", "findElement", "(", "$", "element_or_by", ")", ";", "return", "$", "element", "->", "isSelected", "(", ")", "===", "$", "selected", ";", "}", "catch", "(", "StaleElementReferenceException", "$", "e", ")", "{", "return", "null", ";", "}", "}", ")", ";", "}", "}", "}" ]
An expectation for checking if the given element is selected. @param mixed $element_or_by Either the element or the locator. @param bool $selected The required state. @return static Condition returns whether the element is selected.
[ "An", "expectation", "for", "checking", "if", "the", "given", "element", "is", "selected", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L514-L537
train
facebook/php-webdriver
lib/WebDriverExpectedCondition.php
WebDriverExpectedCondition.not
public static function not(self $condition) { return new static( function (WebDriver $driver) use ($condition) { $result = call_user_func($condition->getApply(), $driver); return !$result; } ); }
php
public static function not(self $condition) { return new static( function (WebDriver $driver) use ($condition) { $result = call_user_func($condition->getApply(), $driver); return !$result; } ); }
[ "public", "static", "function", "not", "(", "self", "$", "condition", ")", "{", "return", "new", "static", "(", "function", "(", "WebDriver", "$", "driver", ")", "use", "(", "$", "condition", ")", "{", "$", "result", "=", "call_user_func", "(", "$", "condition", "->", "getApply", "(", ")", ",", "$", "driver", ")", ";", "return", "!", "$", "result", ";", "}", ")", ";", "}" ]
An expectation with the logical opposite condition of the given condition. @param WebDriverExpectedCondition $condition The condition to be negated. @return mixed The negation of the result of the given condition.
[ "An", "expectation", "with", "the", "logical", "opposite", "condition", "of", "the", "given", "condition", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverExpectedCondition.php#L584-L593
train
facebook/php-webdriver
lib/AbstractWebDriverCheckboxOrRadio.php
AbstractWebDriverCheckboxOrRadio.byIndex
protected function byIndex($index, $select = true) { $elements = $this->getRelatedElements(); if (!isset($elements[$index])) { throw new NoSuchElementException(sprintf('Cannot locate %s with index: %d', $this->type, $index)); } $select ? $this->selectOption($elements[$index]) : $this->deselectOption($elements[$index]); }
php
protected function byIndex($index, $select = true) { $elements = $this->getRelatedElements(); if (!isset($elements[$index])) { throw new NoSuchElementException(sprintf('Cannot locate %s with index: %d', $this->type, $index)); } $select ? $this->selectOption($elements[$index]) : $this->deselectOption($elements[$index]); }
[ "protected", "function", "byIndex", "(", "$", "index", ",", "$", "select", "=", "true", ")", "{", "$", "elements", "=", "$", "this", "->", "getRelatedElements", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "elements", "[", "$", "index", "]", ")", ")", "{", "throw", "new", "NoSuchElementException", "(", "sprintf", "(", "'Cannot locate %s with index: %d'", ",", "$", "this", "->", "type", ",", "$", "index", ")", ")", ";", "}", "$", "select", "?", "$", "this", "->", "selectOption", "(", "$", "elements", "[", "$", "index", "]", ")", ":", "$", "this", "->", "deselectOption", "(", "$", "elements", "[", "$", "index", "]", ")", ";", "}" ]
Selects or deselects a checkbox or a radio button by its index. @param int $index @param bool $select @throws NoSuchElementException
[ "Selects", "or", "deselects", "a", "checkbox", "or", "a", "radio", "button", "by", "its", "index", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/AbstractWebDriverCheckboxOrRadio.php#L139-L147
train
facebook/php-webdriver
lib/Remote/RemoteTargetLocator.php
RemoteTargetLocator.defaultContent
public function defaultContent() { $params = ['id' => null]; $this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params); return $this->driver; }
php
public function defaultContent() { $params = ['id' => null]; $this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params); return $this->driver; }
[ "public", "function", "defaultContent", "(", ")", "{", "$", "params", "=", "[", "'id'", "=>", "null", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SWITCH_TO_FRAME", ",", "$", "params", ")", ";", "return", "$", "this", "->", "driver", ";", "}" ]
Switch to the main document if the page contains iframes. Otherwise, switch to the first frame on the page. @return WebDriver The driver focused on the top window or the first frame.
[ "Switch", "to", "the", "main", "document", "if", "the", "page", "contains", "iframes", ".", "Otherwise", "switch", "to", "the", "first", "frame", "on", "the", "page", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteTargetLocator.php#L49-L55
train
facebook/php-webdriver
lib/Remote/RemoteTargetLocator.php
RemoteTargetLocator.frame
public function frame($frame) { if ($frame instanceof WebDriverElement) { $id = ['ELEMENT' => $frame->getID()]; } else { $id = (string) $frame; } $params = ['id' => $id]; $this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params); return $this->driver; }
php
public function frame($frame) { if ($frame instanceof WebDriverElement) { $id = ['ELEMENT' => $frame->getID()]; } else { $id = (string) $frame; } $params = ['id' => $id]; $this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params); return $this->driver; }
[ "public", "function", "frame", "(", "$", "frame", ")", "{", "if", "(", "$", "frame", "instanceof", "WebDriverElement", ")", "{", "$", "id", "=", "[", "'ELEMENT'", "=>", "$", "frame", "->", "getID", "(", ")", "]", ";", "}", "else", "{", "$", "id", "=", "(", "string", ")", "$", "frame", ";", "}", "$", "params", "=", "[", "'id'", "=>", "$", "id", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SWITCH_TO_FRAME", ",", "$", "params", ")", ";", "return", "$", "this", "->", "driver", ";", "}" ]
Switch to the iframe by its id or name. @param WebDriverElement|string $frame The WebDriverElement, the id or the name of the frame. @return WebDriver The driver focused on the given frame.
[ "Switch", "to", "the", "iframe", "by", "its", "id", "or", "name", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteTargetLocator.php#L64-L76
train
facebook/php-webdriver
lib/Remote/RemoteTargetLocator.php
RemoteTargetLocator.window
public function window($handle) { $params = ['name' => (string) $handle]; $this->executor->execute(DriverCommand::SWITCH_TO_WINDOW, $params); return $this->driver; }
php
public function window($handle) { $params = ['name' => (string) $handle]; $this->executor->execute(DriverCommand::SWITCH_TO_WINDOW, $params); return $this->driver; }
[ "public", "function", "window", "(", "$", "handle", ")", "{", "$", "params", "=", "[", "'name'", "=>", "(", "string", ")", "$", "handle", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SWITCH_TO_WINDOW", ",", "$", "params", ")", ";", "return", "$", "this", "->", "driver", ";", "}" ]
Switch the focus to another window by its handle. @param string $handle The handle of the window to be focused on. @return WebDriver The driver focused on the given window. @see WebDriver::getWindowHandles
[ "Switch", "the", "focus", "to", "another", "window", "by", "its", "handle", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteTargetLocator.php#L85-L91
train
facebook/php-webdriver
lib/Remote/RemoteTargetLocator.php
RemoteTargetLocator.activeElement
public function activeElement() { $response = $this->driver->execute(DriverCommand::GET_ACTIVE_ELEMENT, []); $method = new RemoteExecuteMethod($this->driver); return new RemoteWebElement($method, $response['ELEMENT']); }
php
public function activeElement() { $response = $this->driver->execute(DriverCommand::GET_ACTIVE_ELEMENT, []); $method = new RemoteExecuteMethod($this->driver); return new RemoteWebElement($method, $response['ELEMENT']); }
[ "public", "function", "activeElement", "(", ")", "{", "$", "response", "=", "$", "this", "->", "driver", "->", "execute", "(", "DriverCommand", "::", "GET_ACTIVE_ELEMENT", ",", "[", "]", ")", ";", "$", "method", "=", "new", "RemoteExecuteMethod", "(", "$", "this", "->", "driver", ")", ";", "return", "new", "RemoteWebElement", "(", "$", "method", ",", "$", "response", "[", "'ELEMENT'", "]", ")", ";", "}" ]
Switches to the element that currently has focus within the document currently "switched to", or the body element if this cannot be detected. @return RemoteWebElement
[ "Switches", "to", "the", "element", "that", "currently", "has", "focus", "within", "the", "document", "currently", "switched", "to", "or", "the", "body", "element", "if", "this", "cannot", "be", "detected", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteTargetLocator.php#L110-L116
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.findElement
public function findElement(WebDriverBy $by) { $params = [ 'using' => $by->getMechanism(), 'value' => $by->getValue(), ':id' => $this->id, ]; $raw_element = $this->executor->execute( DriverCommand::FIND_CHILD_ELEMENT, $params ); return $this->newElement($raw_element['ELEMENT']); }
php
public function findElement(WebDriverBy $by) { $params = [ 'using' => $by->getMechanism(), 'value' => $by->getValue(), ':id' => $this->id, ]; $raw_element = $this->executor->execute( DriverCommand::FIND_CHILD_ELEMENT, $params ); return $this->newElement($raw_element['ELEMENT']); }
[ "public", "function", "findElement", "(", "WebDriverBy", "$", "by", ")", "{", "$", "params", "=", "[", "'using'", "=>", "$", "by", "->", "getMechanism", "(", ")", ",", "'value'", "=>", "$", "by", "->", "getValue", "(", ")", ",", "':id'", "=>", "$", "this", "->", "id", ",", "]", ";", "$", "raw_element", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "FIND_CHILD_ELEMENT", ",", "$", "params", ")", ";", "return", "$", "this", "->", "newElement", "(", "$", "raw_element", "[", "'ELEMENT'", "]", ")", ";", "}" ]
Find the first WebDriverElement within this element using the given mechanism. @param WebDriverBy $by @return RemoteWebElement NoSuchElementException is thrown in HttpCommandExecutor if no element is found. @see WebDriverBy
[ "Find", "the", "first", "WebDriverElement", "within", "this", "element", "using", "the", "given", "mechanism", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L95-L108
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.findElements
public function findElements(WebDriverBy $by) { $params = [ 'using' => $by->getMechanism(), 'value' => $by->getValue(), ':id' => $this->id, ]; $raw_elements = $this->executor->execute( DriverCommand::FIND_CHILD_ELEMENTS, $params ); $elements = []; foreach ($raw_elements as $raw_element) { $elements[] = $this->newElement($raw_element['ELEMENT']); } return $elements; }
php
public function findElements(WebDriverBy $by) { $params = [ 'using' => $by->getMechanism(), 'value' => $by->getValue(), ':id' => $this->id, ]; $raw_elements = $this->executor->execute( DriverCommand::FIND_CHILD_ELEMENTS, $params ); $elements = []; foreach ($raw_elements as $raw_element) { $elements[] = $this->newElement($raw_element['ELEMENT']); } return $elements; }
[ "public", "function", "findElements", "(", "WebDriverBy", "$", "by", ")", "{", "$", "params", "=", "[", "'using'", "=>", "$", "by", "->", "getMechanism", "(", ")", ",", "'value'", "=>", "$", "by", "->", "getValue", "(", ")", ",", "':id'", "=>", "$", "this", "->", "id", ",", "]", ";", "$", "raw_elements", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "FIND_CHILD_ELEMENTS", ",", "$", "params", ")", ";", "$", "elements", "=", "[", "]", ";", "foreach", "(", "$", "raw_elements", "as", "$", "raw_element", ")", "{", "$", "elements", "[", "]", "=", "$", "this", "->", "newElement", "(", "$", "raw_element", "[", "'ELEMENT'", "]", ")", ";", "}", "return", "$", "elements", ";", "}" ]
Find all WebDriverElements within this element using the given mechanism. @param WebDriverBy $by @return RemoteWebElement[] A list of all WebDriverElements, or an empty array if nothing matches @see WebDriverBy
[ "Find", "all", "WebDriverElements", "within", "this", "element", "using", "the", "given", "mechanism", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L118-L136
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.getAttribute
public function getAttribute($attribute_name) { $params = [ ':name' => $attribute_name, ':id' => $this->id, ]; return $this->executor->execute( DriverCommand::GET_ELEMENT_ATTRIBUTE, $params ); }
php
public function getAttribute($attribute_name) { $params = [ ':name' => $attribute_name, ':id' => $this->id, ]; return $this->executor->execute( DriverCommand::GET_ELEMENT_ATTRIBUTE, $params ); }
[ "public", "function", "getAttribute", "(", "$", "attribute_name", ")", "{", "$", "params", "=", "[", "':name'", "=>", "$", "attribute_name", ",", "':id'", "=>", "$", "this", "->", "id", ",", "]", ";", "return", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_ELEMENT_ATTRIBUTE", ",", "$", "params", ")", ";", "}" ]
Get the value of a the given attribute of the element. @param string $attribute_name The name of the attribute. @return string|null The value of the attribute.
[ "Get", "the", "value", "of", "a", "the", "given", "attribute", "of", "the", "element", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L144-L155
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.getCSSValue
public function getCSSValue($css_property_name) { $params = [ ':propertyName' => $css_property_name, ':id' => $this->id, ]; return $this->executor->execute( DriverCommand::GET_ELEMENT_VALUE_OF_CSS_PROPERTY, $params ); }
php
public function getCSSValue($css_property_name) { $params = [ ':propertyName' => $css_property_name, ':id' => $this->id, ]; return $this->executor->execute( DriverCommand::GET_ELEMENT_VALUE_OF_CSS_PROPERTY, $params ); }
[ "public", "function", "getCSSValue", "(", "$", "css_property_name", ")", "{", "$", "params", "=", "[", "':propertyName'", "=>", "$", "css_property_name", ",", "':id'", "=>", "$", "this", "->", "id", ",", "]", ";", "return", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_ELEMENT_VALUE_OF_CSS_PROPERTY", ",", "$", "params", ")", ";", "}" ]
Get the value of a given CSS property. @param string $css_property_name The name of the CSS property. @return string The value of the CSS property.
[ "Get", "the", "value", "of", "a", "given", "CSS", "property", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L163-L174
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.getLocation
public function getLocation() { $location = $this->executor->execute( DriverCommand::GET_ELEMENT_LOCATION, [':id' => $this->id] ); return new WebDriverPoint($location['x'], $location['y']); }
php
public function getLocation() { $location = $this->executor->execute( DriverCommand::GET_ELEMENT_LOCATION, [':id' => $this->id] ); return new WebDriverPoint($location['x'], $location['y']); }
[ "public", "function", "getLocation", "(", ")", "{", "$", "location", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_ELEMENT_LOCATION", ",", "[", "':id'", "=>", "$", "this", "->", "id", "]", ")", ";", "return", "new", "WebDriverPoint", "(", "$", "location", "[", "'x'", "]", ",", "$", "location", "[", "'y'", "]", ")", ";", "}" ]
Get the location of element relative to the top-left corner of the page. @return WebDriverPoint The location of the element.
[ "Get", "the", "location", "of", "element", "relative", "to", "the", "top", "-", "left", "corner", "of", "the", "page", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L181-L189
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.getLocationOnScreenOnceScrolledIntoView
public function getLocationOnScreenOnceScrolledIntoView() { $location = $this->executor->execute( DriverCommand::GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW, [':id' => $this->id] ); return new WebDriverPoint($location['x'], $location['y']); }
php
public function getLocationOnScreenOnceScrolledIntoView() { $location = $this->executor->execute( DriverCommand::GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW, [':id' => $this->id] ); return new WebDriverPoint($location['x'], $location['y']); }
[ "public", "function", "getLocationOnScreenOnceScrolledIntoView", "(", ")", "{", "$", "location", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW", ",", "[", "':id'", "=>", "$", "this", "->", "id", "]", ")", ";", "return", "new", "WebDriverPoint", "(", "$", "location", "[", "'x'", "]", ",", "$", "location", "[", "'y'", "]", ")", ";", "}" ]
Try scrolling the element into the view port and return the location of element relative to the top-left corner of the page afterwards. @return WebDriverPoint The location of the element.
[ "Try", "scrolling", "the", "element", "into", "the", "view", "port", "and", "return", "the", "location", "of", "element", "relative", "to", "the", "top", "-", "left", "corner", "of", "the", "page", "afterwards", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L197-L205
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.getSize
public function getSize() { $size = $this->executor->execute( DriverCommand::GET_ELEMENT_SIZE, [':id' => $this->id] ); return new WebDriverDimension($size['width'], $size['height']); }
php
public function getSize() { $size = $this->executor->execute( DriverCommand::GET_ELEMENT_SIZE, [':id' => $this->id] ); return new WebDriverDimension($size['width'], $size['height']); }
[ "public", "function", "getSize", "(", ")", "{", "$", "size", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_ELEMENT_SIZE", ",", "[", "':id'", "=>", "$", "this", "->", "id", "]", ")", ";", "return", "new", "WebDriverDimension", "(", "$", "size", "[", "'width'", "]", ",", "$", "size", "[", "'height'", "]", ")", ";", "}" ]
Get the size of element. @return WebDriverDimension The dimension of the element.
[ "Get", "the", "size", "of", "element", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L236-L244
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.sendKeys
public function sendKeys($value) { $local_file = $this->fileDetector->getLocalFile($value); if ($local_file === null) { $params = [ 'value' => WebDriverKeys::encode($value), ':id' => $this->id, ]; $this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params); } else { $remote_path = $this->upload($local_file); $params = [ 'value' => WebDriverKeys::encode($remote_path), ':id' => $this->id, ]; $this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params); } return $this; }
php
public function sendKeys($value) { $local_file = $this->fileDetector->getLocalFile($value); if ($local_file === null) { $params = [ 'value' => WebDriverKeys::encode($value), ':id' => $this->id, ]; $this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params); } else { $remote_path = $this->upload($local_file); $params = [ 'value' => WebDriverKeys::encode($remote_path), ':id' => $this->id, ]; $this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params); } return $this; }
[ "public", "function", "sendKeys", "(", "$", "value", ")", "{", "$", "local_file", "=", "$", "this", "->", "fileDetector", "->", "getLocalFile", "(", "$", "value", ")", ";", "if", "(", "$", "local_file", "===", "null", ")", "{", "$", "params", "=", "[", "'value'", "=>", "WebDriverKeys", "::", "encode", "(", "$", "value", ")", ",", "':id'", "=>", "$", "this", "->", "id", ",", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SEND_KEYS_TO_ELEMENT", ",", "$", "params", ")", ";", "}", "else", "{", "$", "remote_path", "=", "$", "this", "->", "upload", "(", "$", "local_file", ")", ";", "$", "params", "=", "[", "'value'", "=>", "WebDriverKeys", "::", "encode", "(", "$", "remote_path", ")", ",", "':id'", "=>", "$", "this", "->", "id", ",", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SEND_KEYS_TO_ELEMENT", ",", "$", "params", ")", ";", "}", "return", "$", "this", ";", "}" ]
Simulate typing into an element, which may set its value. @param mixed $value The data to be typed. @return RemoteWebElement The current instance.
[ "Simulate", "typing", "into", "an", "element", "which", "may", "set", "its", "value", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L324-L343
train
facebook/php-webdriver
lib/Remote/RemoteWebElement.php
RemoteWebElement.upload
protected function upload($local_file) { if (!is_file($local_file)) { throw new WebDriverException('You may only upload files: ' . $local_file); } // Create a temporary file in the system temp directory. $temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverZip'); $zip = new ZipArchive(); if ($zip->open($temp_zip, ZipArchive::CREATE) !== true) { return false; } $info = pathinfo($local_file); $file_name = $info['basename']; $zip->addFile($local_file, $file_name); $zip->close(); $params = [ 'file' => base64_encode(file_get_contents($temp_zip)), ]; $remote_path = $this->executor->execute( DriverCommand::UPLOAD_FILE, $params ); unlink($temp_zip); return $remote_path; }
php
protected function upload($local_file) { if (!is_file($local_file)) { throw new WebDriverException('You may only upload files: ' . $local_file); } // Create a temporary file in the system temp directory. $temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverZip'); $zip = new ZipArchive(); if ($zip->open($temp_zip, ZipArchive::CREATE) !== true) { return false; } $info = pathinfo($local_file); $file_name = $info['basename']; $zip->addFile($local_file, $file_name); $zip->close(); $params = [ 'file' => base64_encode(file_get_contents($temp_zip)), ]; $remote_path = $this->executor->execute( DriverCommand::UPLOAD_FILE, $params ); unlink($temp_zip); return $remote_path; }
[ "protected", "function", "upload", "(", "$", "local_file", ")", "{", "if", "(", "!", "is_file", "(", "$", "local_file", ")", ")", "{", "throw", "new", "WebDriverException", "(", "'You may only upload files: '", ".", "$", "local_file", ")", ";", "}", "// Create a temporary file in the system temp directory.", "$", "temp_zip", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "'WebDriverZip'", ")", ";", "$", "zip", "=", "new", "ZipArchive", "(", ")", ";", "if", "(", "$", "zip", "->", "open", "(", "$", "temp_zip", ",", "ZipArchive", "::", "CREATE", ")", "!==", "true", ")", "{", "return", "false", ";", "}", "$", "info", "=", "pathinfo", "(", "$", "local_file", ")", ";", "$", "file_name", "=", "$", "info", "[", "'basename'", "]", ";", "$", "zip", "->", "addFile", "(", "$", "local_file", ",", "$", "file_name", ")", ";", "$", "zip", "->", "close", "(", ")", ";", "$", "params", "=", "[", "'file'", "=>", "base64_encode", "(", "file_get_contents", "(", "$", "temp_zip", ")", ")", ",", "]", ";", "$", "remote_path", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "UPLOAD_FILE", ",", "$", "params", ")", ";", "unlink", "(", "$", "temp_zip", ")", ";", "return", "$", "remote_path", ";", "}" ]
Upload a local file to the server @param string $local_file @throws WebDriverException @return string The remote path of the file.
[ "Upload", "a", "local", "file", "to", "the", "server" ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebElement.php#L426-L452
train
facebook/php-webdriver
lib/WebDriverWindow.php
WebDriverWindow.getPosition
public function getPosition() { $position = $this->executor->execute( DriverCommand::GET_WINDOW_POSITION, [':windowHandle' => 'current'] ); return new WebDriverPoint( $position['x'], $position['y'] ); }
php
public function getPosition() { $position = $this->executor->execute( DriverCommand::GET_WINDOW_POSITION, [':windowHandle' => 'current'] ); return new WebDriverPoint( $position['x'], $position['y'] ); }
[ "public", "function", "getPosition", "(", ")", "{", "$", "position", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_WINDOW_POSITION", ",", "[", "':windowHandle'", "=>", "'current'", "]", ")", ";", "return", "new", "WebDriverPoint", "(", "$", "position", "[", "'x'", "]", ",", "$", "position", "[", "'y'", "]", ")", ";", "}" ]
Get the position of the current window, relative to the upper left corner of the screen. @return WebDriverPoint The current window position.
[ "Get", "the", "position", "of", "the", "current", "window", "relative", "to", "the", "upper", "left", "corner", "of", "the", "screen", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverWindow.php#L43-L54
train
facebook/php-webdriver
lib/WebDriverWindow.php
WebDriverWindow.getSize
public function getSize() { $size = $this->executor->execute( DriverCommand::GET_WINDOW_SIZE, [':windowHandle' => 'current'] ); return new WebDriverDimension( $size['width'], $size['height'] ); }
php
public function getSize() { $size = $this->executor->execute( DriverCommand::GET_WINDOW_SIZE, [':windowHandle' => 'current'] ); return new WebDriverDimension( $size['width'], $size['height'] ); }
[ "public", "function", "getSize", "(", ")", "{", "$", "size", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_WINDOW_SIZE", ",", "[", "':windowHandle'", "=>", "'current'", "]", ")", ";", "return", "new", "WebDriverDimension", "(", "$", "size", "[", "'width'", "]", ",", "$", "size", "[", "'height'", "]", ")", ";", "}" ]
Get the size of the current window. This will return the outer window dimension, not just the view port. @return WebDriverDimension The current window size.
[ "Get", "the", "size", "of", "the", "current", "window", ".", "This", "will", "return", "the", "outer", "window", "dimension", "not", "just", "the", "view", "port", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverWindow.php#L62-L73
train
facebook/php-webdriver
lib/WebDriverWindow.php
WebDriverWindow.setSize
public function setSize(WebDriverDimension $size) { $params = [ 'width' => $size->getWidth(), 'height' => $size->getHeight(), ':windowHandle' => 'current', ]; $this->executor->execute(DriverCommand::SET_WINDOW_SIZE, $params); return $this; }
php
public function setSize(WebDriverDimension $size) { $params = [ 'width' => $size->getWidth(), 'height' => $size->getHeight(), ':windowHandle' => 'current', ]; $this->executor->execute(DriverCommand::SET_WINDOW_SIZE, $params); return $this; }
[ "public", "function", "setSize", "(", "WebDriverDimension", "$", "size", ")", "{", "$", "params", "=", "[", "'width'", "=>", "$", "size", "->", "getWidth", "(", ")", ",", "'height'", "=>", "$", "size", "->", "getHeight", "(", ")", ",", "':windowHandle'", "=>", "'current'", ",", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SET_WINDOW_SIZE", ",", "$", "params", ")", ";", "return", "$", "this", ";", "}" ]
Set the size of the current window. This will change the outer window dimension, not just the view port. @param WebDriverDimension $size @return WebDriverWindow The instance.
[ "Set", "the", "size", "of", "the", "current", "window", ".", "This", "will", "change", "the", "outer", "window", "dimension", "not", "just", "the", "view", "port", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverWindow.php#L97-L107
train
facebook/php-webdriver
lib/WebDriverWindow.php
WebDriverWindow.setPosition
public function setPosition(WebDriverPoint $position) { $params = [ 'x' => $position->getX(), 'y' => $position->getY(), ':windowHandle' => 'current', ]; $this->executor->execute(DriverCommand::SET_WINDOW_POSITION, $params); return $this; }
php
public function setPosition(WebDriverPoint $position) { $params = [ 'x' => $position->getX(), 'y' => $position->getY(), ':windowHandle' => 'current', ]; $this->executor->execute(DriverCommand::SET_WINDOW_POSITION, $params); return $this; }
[ "public", "function", "setPosition", "(", "WebDriverPoint", "$", "position", ")", "{", "$", "params", "=", "[", "'x'", "=>", "$", "position", "->", "getX", "(", ")", ",", "'y'", "=>", "$", "position", "->", "getY", "(", ")", ",", "':windowHandle'", "=>", "'current'", ",", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SET_WINDOW_POSITION", ",", "$", "params", ")", ";", "return", "$", "this", ";", "}" ]
Set the position of the current window. This is relative to the upper left corner of the screen. @param WebDriverPoint $position @return WebDriverWindow The instance.
[ "Set", "the", "position", "of", "the", "current", "window", ".", "This", "is", "relative", "to", "the", "upper", "left", "corner", "of", "the", "screen", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverWindow.php#L116-L126
train
facebook/php-webdriver
lib/WebDriverWindow.php
WebDriverWindow.setScreenOrientation
public function setScreenOrientation($orientation) { $orientation = mb_strtoupper($orientation); if (!in_array($orientation, ['PORTRAIT', 'LANDSCAPE'])) { throw new IndexOutOfBoundsException( 'Orientation must be either PORTRAIT, or LANDSCAPE' ); } $this->executor->execute( DriverCommand::SET_SCREEN_ORIENTATION, ['orientation' => $orientation] ); return $this; }
php
public function setScreenOrientation($orientation) { $orientation = mb_strtoupper($orientation); if (!in_array($orientation, ['PORTRAIT', 'LANDSCAPE'])) { throw new IndexOutOfBoundsException( 'Orientation must be either PORTRAIT, or LANDSCAPE' ); } $this->executor->execute( DriverCommand::SET_SCREEN_ORIENTATION, ['orientation' => $orientation] ); return $this; }
[ "public", "function", "setScreenOrientation", "(", "$", "orientation", ")", "{", "$", "orientation", "=", "mb_strtoupper", "(", "$", "orientation", ")", ";", "if", "(", "!", "in_array", "(", "$", "orientation", ",", "[", "'PORTRAIT'", ",", "'LANDSCAPE'", "]", ")", ")", "{", "throw", "new", "IndexOutOfBoundsException", "(", "'Orientation must be either PORTRAIT, or LANDSCAPE'", ")", ";", "}", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "SET_SCREEN_ORIENTATION", ",", "[", "'orientation'", "=>", "$", "orientation", "]", ")", ";", "return", "$", "this", ";", "}" ]
Set the browser orientation. The orientation should either LANDSCAPE|PORTRAIT @param string $orientation @throws IndexOutOfBoundsException @return WebDriverWindow The instance.
[ "Set", "the", "browser", "orientation", ".", "The", "orientation", "should", "either", "LANDSCAPE|PORTRAIT" ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverWindow.php#L146-L161
train
facebook/php-webdriver
lib/Remote/DesiredCapabilities.php
DesiredCapabilities.setJavascriptEnabled
public function setJavascriptEnabled($enabled) { $browser = $this->getBrowserName(); if ($browser && $browser !== WebDriverBrowserType::HTMLUNIT) { throw new Exception( 'isJavascriptEnabled() is a htmlunit-only option. ' . 'See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities.' ); } $this->set(WebDriverCapabilityType::JAVASCRIPT_ENABLED, $enabled); return $this; }
php
public function setJavascriptEnabled($enabled) { $browser = $this->getBrowserName(); if ($browser && $browser !== WebDriverBrowserType::HTMLUNIT) { throw new Exception( 'isJavascriptEnabled() is a htmlunit-only option. ' . 'See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities.' ); } $this->set(WebDriverCapabilityType::JAVASCRIPT_ENABLED, $enabled); return $this; }
[ "public", "function", "setJavascriptEnabled", "(", "$", "enabled", ")", "{", "$", "browser", "=", "$", "this", "->", "getBrowserName", "(", ")", ";", "if", "(", "$", "browser", "&&", "$", "browser", "!==", "WebDriverBrowserType", "::", "HTMLUNIT", ")", "{", "throw", "new", "Exception", "(", "'isJavascriptEnabled() is a htmlunit-only option. '", ".", "'See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities.'", ")", ";", "}", "$", "this", "->", "set", "(", "WebDriverCapabilityType", "::", "JAVASCRIPT_ENABLED", ",", "$", "enabled", ")", ";", "return", "$", "this", ";", "}" ]
This is a htmlUnit-only option. @param bool $enabled @throws Exception @return DesiredCapabilities @see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities
[ "This", "is", "a", "htmlUnit", "-", "only", "option", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/DesiredCapabilities.php#L143-L156
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.create
public static function create( $selenium_server_url = 'http://localhost:4444/wd/hub', $desired_capabilities = null, $connection_timeout_in_ms = null, $request_timeout_in_ms = null, $http_proxy = null, $http_proxy_port = null, DesiredCapabilities $required_capabilities = null ) { $selenium_server_url = preg_replace('#/+$#', '', $selenium_server_url); $desired_capabilities = self::castToDesiredCapabilitiesObject($desired_capabilities); $executor = new HttpCommandExecutor($selenium_server_url, $http_proxy, $http_proxy_port); if ($connection_timeout_in_ms !== null) { $executor->setConnectionTimeout($connection_timeout_in_ms); } if ($request_timeout_in_ms !== null) { $executor->setRequestTimeout($request_timeout_in_ms); } if ($required_capabilities !== null) { // TODO: Selenium (as of v3.0.1) does accept requiredCapabilities only as a property of desiredCapabilities. // This will probably change in future with the W3C WebDriver spec, but is the only way how to pass these // values now. $desired_capabilities->setCapability('requiredCapabilities', $required_capabilities->toArray()); } $command = new WebDriverCommand( null, DriverCommand::NEW_SESSION, ['desiredCapabilities' => $desired_capabilities->toArray()] ); $response = $executor->execute($command); $returnedCapabilities = new DesiredCapabilities($response->getValue()); $driver = new static($executor, $response->getSessionID(), $returnedCapabilities); return $driver; }
php
public static function create( $selenium_server_url = 'http://localhost:4444/wd/hub', $desired_capabilities = null, $connection_timeout_in_ms = null, $request_timeout_in_ms = null, $http_proxy = null, $http_proxy_port = null, DesiredCapabilities $required_capabilities = null ) { $selenium_server_url = preg_replace('#/+$#', '', $selenium_server_url); $desired_capabilities = self::castToDesiredCapabilitiesObject($desired_capabilities); $executor = new HttpCommandExecutor($selenium_server_url, $http_proxy, $http_proxy_port); if ($connection_timeout_in_ms !== null) { $executor->setConnectionTimeout($connection_timeout_in_ms); } if ($request_timeout_in_ms !== null) { $executor->setRequestTimeout($request_timeout_in_ms); } if ($required_capabilities !== null) { // TODO: Selenium (as of v3.0.1) does accept requiredCapabilities only as a property of desiredCapabilities. // This will probably change in future with the W3C WebDriver spec, but is the only way how to pass these // values now. $desired_capabilities->setCapability('requiredCapabilities', $required_capabilities->toArray()); } $command = new WebDriverCommand( null, DriverCommand::NEW_SESSION, ['desiredCapabilities' => $desired_capabilities->toArray()] ); $response = $executor->execute($command); $returnedCapabilities = new DesiredCapabilities($response->getValue()); $driver = new static($executor, $response->getSessionID(), $returnedCapabilities); return $driver; }
[ "public", "static", "function", "create", "(", "$", "selenium_server_url", "=", "'http://localhost:4444/wd/hub'", ",", "$", "desired_capabilities", "=", "null", ",", "$", "connection_timeout_in_ms", "=", "null", ",", "$", "request_timeout_in_ms", "=", "null", ",", "$", "http_proxy", "=", "null", ",", "$", "http_proxy_port", "=", "null", ",", "DesiredCapabilities", "$", "required_capabilities", "=", "null", ")", "{", "$", "selenium_server_url", "=", "preg_replace", "(", "'#/+$#'", ",", "''", ",", "$", "selenium_server_url", ")", ";", "$", "desired_capabilities", "=", "self", "::", "castToDesiredCapabilitiesObject", "(", "$", "desired_capabilities", ")", ";", "$", "executor", "=", "new", "HttpCommandExecutor", "(", "$", "selenium_server_url", ",", "$", "http_proxy", ",", "$", "http_proxy_port", ")", ";", "if", "(", "$", "connection_timeout_in_ms", "!==", "null", ")", "{", "$", "executor", "->", "setConnectionTimeout", "(", "$", "connection_timeout_in_ms", ")", ";", "}", "if", "(", "$", "request_timeout_in_ms", "!==", "null", ")", "{", "$", "executor", "->", "setRequestTimeout", "(", "$", "request_timeout_in_ms", ")", ";", "}", "if", "(", "$", "required_capabilities", "!==", "null", ")", "{", "// TODO: Selenium (as of v3.0.1) does accept requiredCapabilities only as a property of desiredCapabilities.", "// This will probably change in future with the W3C WebDriver spec, but is the only way how to pass these", "// values now.", "$", "desired_capabilities", "->", "setCapability", "(", "'requiredCapabilities'", ",", "$", "required_capabilities", "->", "toArray", "(", ")", ")", ";", "}", "$", "command", "=", "new", "WebDriverCommand", "(", "null", ",", "DriverCommand", "::", "NEW_SESSION", ",", "[", "'desiredCapabilities'", "=>", "$", "desired_capabilities", "->", "toArray", "(", ")", "]", ")", ";", "$", "response", "=", "$", "executor", "->", "execute", "(", "$", "command", ")", ";", "$", "returnedCapabilities", "=", "new", "DesiredCapabilities", "(", "$", "response", "->", "getValue", "(", ")", ")", ";", "$", "driver", "=", "new", "static", "(", "$", "executor", ",", "$", "response", "->", "getSessionID", "(", ")", ",", "$", "returnedCapabilities", ")", ";", "return", "$", "driver", ";", "}" ]
Construct the RemoteWebDriver by a desired capabilities. @param string $selenium_server_url The url of the remote Selenium WebDriver server @param DesiredCapabilities|array $desired_capabilities The desired capabilities @param int|null $connection_timeout_in_ms Set timeout for the connect phase to remote Selenium WebDriver server @param int|null $request_timeout_in_ms Set the maximum time of a request to remote Selenium WebDriver server @param string|null $http_proxy The proxy to tunnel requests to the remote Selenium WebDriver through @param int|null $http_proxy_port The proxy port to tunnel requests to the remote Selenium WebDriver through @param DesiredCapabilities $required_capabilities The required capabilities @return static
[ "Construct", "the", "RemoteWebDriver", "by", "a", "desired", "capabilities", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L92-L132
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.findElement
public function findElement(WebDriverBy $by) { $params = ['using' => $by->getMechanism(), 'value' => $by->getValue()]; $raw_element = $this->execute( DriverCommand::FIND_ELEMENT, $params ); return $this->newElement($raw_element['ELEMENT']); }
php
public function findElement(WebDriverBy $by) { $params = ['using' => $by->getMechanism(), 'value' => $by->getValue()]; $raw_element = $this->execute( DriverCommand::FIND_ELEMENT, $params ); return $this->newElement($raw_element['ELEMENT']); }
[ "public", "function", "findElement", "(", "WebDriverBy", "$", "by", ")", "{", "$", "params", "=", "[", "'using'", "=>", "$", "by", "->", "getMechanism", "(", ")", ",", "'value'", "=>", "$", "by", "->", "getValue", "(", ")", "]", ";", "$", "raw_element", "=", "$", "this", "->", "execute", "(", "DriverCommand", "::", "FIND_ELEMENT", ",", "$", "params", ")", ";", "return", "$", "this", "->", "newElement", "(", "$", "raw_element", "[", "'ELEMENT'", "]", ")", ";", "}" ]
Find the first WebDriverElement using the given mechanism. @param WebDriverBy $by @return RemoteWebElement NoSuchElementException is thrown in HttpCommandExecutor if no element is found. @see WebDriverBy
[ "Find", "the", "first", "WebDriverElement", "using", "the", "given", "mechanism", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L182-L191
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.findElements
public function findElements(WebDriverBy $by) { $params = ['using' => $by->getMechanism(), 'value' => $by->getValue()]; $raw_elements = $this->execute( DriverCommand::FIND_ELEMENTS, $params ); $elements = []; foreach ($raw_elements as $raw_element) { $elements[] = $this->newElement($raw_element['ELEMENT']); } return $elements; }
php
public function findElements(WebDriverBy $by) { $params = ['using' => $by->getMechanism(), 'value' => $by->getValue()]; $raw_elements = $this->execute( DriverCommand::FIND_ELEMENTS, $params ); $elements = []; foreach ($raw_elements as $raw_element) { $elements[] = $this->newElement($raw_element['ELEMENT']); } return $elements; }
[ "public", "function", "findElements", "(", "WebDriverBy", "$", "by", ")", "{", "$", "params", "=", "[", "'using'", "=>", "$", "by", "->", "getMechanism", "(", ")", ",", "'value'", "=>", "$", "by", "->", "getValue", "(", ")", "]", ";", "$", "raw_elements", "=", "$", "this", "->", "execute", "(", "DriverCommand", "::", "FIND_ELEMENTS", ",", "$", "params", ")", ";", "$", "elements", "=", "[", "]", ";", "foreach", "(", "$", "raw_elements", "as", "$", "raw_element", ")", "{", "$", "elements", "[", "]", "=", "$", "this", "->", "newElement", "(", "$", "raw_element", "[", "'ELEMENT'", "]", ")", ";", "}", "return", "$", "elements", ";", "}" ]
Find all WebDriverElements within the current page using the given mechanism. @param WebDriverBy $by @return RemoteWebElement[] A list of all WebDriverElements, or an empty array if nothing matches @see WebDriverBy
[ "Find", "all", "WebDriverElements", "within", "the", "current", "page", "using", "the", "given", "mechanism", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L200-L214
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.get
public function get($url) { $params = ['url' => (string) $url]; $this->execute(DriverCommand::GET, $params); return $this; }
php
public function get($url) { $params = ['url' => (string) $url]; $this->execute(DriverCommand::GET, $params); return $this; }
[ "public", "function", "get", "(", "$", "url", ")", "{", "$", "params", "=", "[", "'url'", "=>", "(", "string", ")", "$", "url", "]", ";", "$", "this", "->", "execute", "(", "DriverCommand", "::", "GET", ",", "$", "params", ")", ";", "return", "$", "this", ";", "}" ]
Load a new web page in the current browser window. @param string $url @return RemoteWebDriver The current instance.
[ "Load", "a", "new", "web", "page", "in", "the", "current", "browser", "window", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L223-L229
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.executeScript
public function executeScript($script, array $arguments = []) { $params = [ 'script' => $script, 'args' => $this->prepareScriptArguments($arguments), ]; return $this->execute(DriverCommand::EXECUTE_SCRIPT, $params); }
php
public function executeScript($script, array $arguments = []) { $params = [ 'script' => $script, 'args' => $this->prepareScriptArguments($arguments), ]; return $this->execute(DriverCommand::EXECUTE_SCRIPT, $params); }
[ "public", "function", "executeScript", "(", "$", "script", ",", "array", "$", "arguments", "=", "[", "]", ")", "{", "$", "params", "=", "[", "'script'", "=>", "$", "script", ",", "'args'", "=>", "$", "this", "->", "prepareScriptArguments", "(", "$", "arguments", ")", ",", "]", ";", "return", "$", "this", "->", "execute", "(", "DriverCommand", "::", "EXECUTE_SCRIPT", ",", "$", "params", ")", ";", "}" ]
Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and the result of evaluating the script will be returned. @param string $script The script to inject. @param array $arguments The arguments of the script. @return mixed The return value of the script.
[ "Inject", "a", "snippet", "of", "JavaScript", "into", "the", "page", "for", "execution", "in", "the", "context", "of", "the", "currently", "selected", "frame", ".", "The", "executed", "script", "is", "assumed", "to", "be", "synchronous", "and", "the", "result", "of", "evaluating", "the", "script", "will", "be", "returned", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L301-L309
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.executeAsyncScript
public function executeAsyncScript($script, array $arguments = []) { $params = [ 'script' => $script, 'args' => $this->prepareScriptArguments($arguments), ]; return $this->execute( DriverCommand::EXECUTE_ASYNC_SCRIPT, $params ); }
php
public function executeAsyncScript($script, array $arguments = []) { $params = [ 'script' => $script, 'args' => $this->prepareScriptArguments($arguments), ]; return $this->execute( DriverCommand::EXECUTE_ASYNC_SCRIPT, $params ); }
[ "public", "function", "executeAsyncScript", "(", "$", "script", ",", "array", "$", "arguments", "=", "[", "]", ")", "{", "$", "params", "=", "[", "'script'", "=>", "$", "script", ",", "'args'", "=>", "$", "this", "->", "prepareScriptArguments", "(", "$", "arguments", ")", ",", "]", ";", "return", "$", "this", "->", "execute", "(", "DriverCommand", "::", "EXECUTE_ASYNC_SCRIPT", ",", "$", "params", ")", ";", "}" ]
Inject a snippet of JavaScript into the page for asynchronous execution in the context of the currently selected frame. The driver will pass a callback as the last argument to the snippet, and block until the callback is invoked. You may need to define script timeout using `setScriptTimeout()` method of `WebDriverTimeouts` first. @param string $script The script to inject. @param array $arguments The arguments of the script. @return mixed The value passed by the script to the callback.
[ "Inject", "a", "snippet", "of", "JavaScript", "into", "the", "page", "for", "asynchronous", "execution", "in", "the", "context", "of", "the", "currently", "selected", "frame", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L323-L334
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.takeScreenshot
public function takeScreenshot($save_as = null) { $screenshot = base64_decode( $this->execute(DriverCommand::SCREENSHOT) ); if ($save_as) { file_put_contents($save_as, $screenshot); } return $screenshot; }
php
public function takeScreenshot($save_as = null) { $screenshot = base64_decode( $this->execute(DriverCommand::SCREENSHOT) ); if ($save_as) { file_put_contents($save_as, $screenshot); } return $screenshot; }
[ "public", "function", "takeScreenshot", "(", "$", "save_as", "=", "null", ")", "{", "$", "screenshot", "=", "base64_decode", "(", "$", "this", "->", "execute", "(", "DriverCommand", "::", "SCREENSHOT", ")", ")", ";", "if", "(", "$", "save_as", ")", "{", "file_put_contents", "(", "$", "save_as", ",", "$", "screenshot", ")", ";", "}", "return", "$", "screenshot", ";", "}" ]
Take a screenshot of the current page. @param string $save_as The path of the screenshot to be saved. @return string The screenshot in PNG format.
[ "Take", "a", "screenshot", "of", "the", "current", "page", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L342-L352
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.getAllSessions
public static function getAllSessions($selenium_server_url = 'http://localhost:4444/wd/hub', $timeout_in_ms = 30000) { $executor = new HttpCommandExecutor($selenium_server_url); $executor->setConnectionTimeout($timeout_in_ms); $command = new WebDriverCommand( null, DriverCommand::GET_ALL_SESSIONS, [] ); return $executor->execute($command)->getValue(); }
php
public static function getAllSessions($selenium_server_url = 'http://localhost:4444/wd/hub', $timeout_in_ms = 30000) { $executor = new HttpCommandExecutor($selenium_server_url); $executor->setConnectionTimeout($timeout_in_ms); $command = new WebDriverCommand( null, DriverCommand::GET_ALL_SESSIONS, [] ); return $executor->execute($command)->getValue(); }
[ "public", "static", "function", "getAllSessions", "(", "$", "selenium_server_url", "=", "'http://localhost:4444/wd/hub'", ",", "$", "timeout_in_ms", "=", "30000", ")", "{", "$", "executor", "=", "new", "HttpCommandExecutor", "(", "$", "selenium_server_url", ")", ";", "$", "executor", "->", "setConnectionTimeout", "(", "$", "timeout_in_ms", ")", ";", "$", "command", "=", "new", "WebDriverCommand", "(", "null", ",", "DriverCommand", "::", "GET_ALL_SESSIONS", ",", "[", "]", ")", ";", "return", "$", "executor", "->", "execute", "(", "$", "command", ")", "->", "getValue", "(", ")", ";", "}" ]
Returns a list of the currently active sessions. @param string $selenium_server_url The url of the remote Selenium WebDriver server @param int $timeout_in_ms @return array
[ "Returns", "a", "list", "of", "the", "currently", "active", "sessions", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L524-L536
train
facebook/php-webdriver
lib/Remote/RemoteWebDriver.php
RemoteWebDriver.prepareScriptArguments
protected function prepareScriptArguments(array $arguments) { $args = []; foreach ($arguments as $key => $value) { if ($value instanceof WebDriverElement) { $args[$key] = ['ELEMENT' => $value->getID()]; } else { if (is_array($value)) { $value = $this->prepareScriptArguments($value); } $args[$key] = $value; } } return $args; }
php
protected function prepareScriptArguments(array $arguments) { $args = []; foreach ($arguments as $key => $value) { if ($value instanceof WebDriverElement) { $args[$key] = ['ELEMENT' => $value->getID()]; } else { if (is_array($value)) { $value = $this->prepareScriptArguments($value); } $args[$key] = $value; } } return $args; }
[ "protected", "function", "prepareScriptArguments", "(", "array", "$", "arguments", ")", "{", "$", "args", "=", "[", "]", ";", "foreach", "(", "$", "arguments", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "WebDriverElement", ")", "{", "$", "args", "[", "$", "key", "]", "=", "[", "'ELEMENT'", "=>", "$", "value", "->", "getID", "(", ")", "]", ";", "}", "else", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "this", "->", "prepareScriptArguments", "(", "$", "value", ")", ";", "}", "$", "args", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "args", ";", "}" ]
Prepare arguments for JavaScript injection @param array $arguments @return array
[ "Prepare", "arguments", "for", "JavaScript", "injection" ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Remote/RemoteWebDriver.php#L561-L576
train
facebook/php-webdriver
lib/WebDriverPoint.php
WebDriverPoint.move
public function move($new_x, $new_y) { $this->x = $new_x; $this->y = $new_y; return $this; }
php
public function move($new_x, $new_y) { $this->x = $new_x; $this->y = $new_y; return $this; }
[ "public", "function", "move", "(", "$", "new_x", ",", "$", "new_y", ")", "{", "$", "this", "->", "x", "=", "$", "new_x", ";", "$", "this", "->", "y", "=", "$", "new_y", ";", "return", "$", "this", ";", "}" ]
Set the point to a new position. @param int $new_x @param int $new_y @return WebDriverPoint The same instance with updated coordinates.
[ "Set", "the", "point", "to", "a", "new", "position", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverPoint.php#L59-L65
train
facebook/php-webdriver
lib/WebDriverPoint.php
WebDriverPoint.moveBy
public function moveBy($x_offset, $y_offset) { $this->x += $x_offset; $this->y += $y_offset; return $this; }
php
public function moveBy($x_offset, $y_offset) { $this->x += $x_offset; $this->y += $y_offset; return $this; }
[ "public", "function", "moveBy", "(", "$", "x_offset", ",", "$", "y_offset", ")", "{", "$", "this", "->", "x", "+=", "$", "x_offset", ";", "$", "this", "->", "y", "+=", "$", "y_offset", ";", "return", "$", "this", ";", "}" ]
Move the current by offsets. @param int $x_offset @param int $y_offset @return WebDriverPoint The same instance with updated coordinates.
[ "Move", "the", "current", "by", "offsets", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverPoint.php#L74-L80
train
facebook/php-webdriver
lib/WebDriverPoint.php
WebDriverPoint.equals
public function equals(self $point) { return $this->x === $point->getX() && $this->y === $point->getY(); }
php
public function equals(self $point) { return $this->x === $point->getX() && $this->y === $point->getY(); }
[ "public", "function", "equals", "(", "self", "$", "point", ")", "{", "return", "$", "this", "->", "x", "===", "$", "point", "->", "getX", "(", ")", "&&", "$", "this", "->", "y", "===", "$", "point", "->", "getY", "(", ")", ";", "}" ]
Check whether the given point is the same as the instance. @param WebDriverPoint $point The point to be compared with. @return bool Whether the x and y coordinates are the same as the instance.
[ "Check", "whether", "the", "given", "point", "is", "the", "same", "as", "the", "instance", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverPoint.php#L88-L92
train
facebook/php-webdriver
lib/WebDriverDimension.php
WebDriverDimension.equals
public function equals(self $dimension) { return $this->height === $dimension->getHeight() && $this->width === $dimension->getWidth(); }
php
public function equals(self $dimension) { return $this->height === $dimension->getHeight() && $this->width === $dimension->getWidth(); }
[ "public", "function", "equals", "(", "self", "$", "dimension", ")", "{", "return", "$", "this", "->", "height", "===", "$", "dimension", "->", "getHeight", "(", ")", "&&", "$", "this", "->", "width", "===", "$", "dimension", "->", "getWidth", "(", ")", ";", "}" ]
Check whether the given dimension is the same as the instance. @param WebDriverDimension $dimension The dimension to be compared with. @return bool Whether the height and the width are the same as the instance.
[ "Check", "whether", "the", "given", "dimension", "is", "the", "same", "as", "the", "instance", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverDimension.php#L68-L71
train
facebook/php-webdriver
lib/WebDriverOptions.php
WebDriverOptions.addCookie
public function addCookie($cookie) { if (is_array($cookie)) { $cookie = Cookie::createFromArray($cookie); } if (!$cookie instanceof Cookie) { throw new InvalidArgumentException('Cookie must be set from instance of Cookie class or from array.'); } $this->executor->execute( DriverCommand::ADD_COOKIE, ['cookie' => $cookie->toArray()] ); return $this; }
php
public function addCookie($cookie) { if (is_array($cookie)) { $cookie = Cookie::createFromArray($cookie); } if (!$cookie instanceof Cookie) { throw new InvalidArgumentException('Cookie must be set from instance of Cookie class or from array.'); } $this->executor->execute( DriverCommand::ADD_COOKIE, ['cookie' => $cookie->toArray()] ); return $this; }
[ "public", "function", "addCookie", "(", "$", "cookie", ")", "{", "if", "(", "is_array", "(", "$", "cookie", ")", ")", "{", "$", "cookie", "=", "Cookie", "::", "createFromArray", "(", "$", "cookie", ")", ";", "}", "if", "(", "!", "$", "cookie", "instanceof", "Cookie", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Cookie must be set from instance of Cookie class or from array.'", ")", ";", "}", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "ADD_COOKIE", ",", "[", "'cookie'", "=>", "$", "cookie", "->", "toArray", "(", ")", "]", ")", ";", "return", "$", "this", ";", "}" ]
Add a specific cookie. @see Cookie for description of possible cookie properties @param Cookie|array $cookie Cookie object. May be also created from array for compatibility reasons. @return WebDriverOptions The current instance.
[ "Add", "a", "specific", "cookie", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverOptions.php#L44-L59
train
facebook/php-webdriver
lib/WebDriverOptions.php
WebDriverOptions.getCookieNamed
public function getCookieNamed($name) { $cookies = $this->getCookies(); foreach ($cookies as $cookie) { if ($cookie['name'] === $name) { return $cookie; } } return null; }
php
public function getCookieNamed($name) { $cookies = $this->getCookies(); foreach ($cookies as $cookie) { if ($cookie['name'] === $name) { return $cookie; } } return null; }
[ "public", "function", "getCookieNamed", "(", "$", "name", ")", "{", "$", "cookies", "=", "$", "this", "->", "getCookies", "(", ")", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "if", "(", "$", "cookie", "[", "'name'", "]", "===", "$", "name", ")", "{", "return", "$", "cookie", ";", "}", "}", "return", "null", ";", "}" ]
Get the cookie with a given name. @param string $name @return Cookie|null The cookie, or null if no cookie with the given name is presented.
[ "Get", "the", "cookie", "with", "a", "given", "name", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverOptions.php#L95-L105
train
facebook/php-webdriver
lib/WebDriverOptions.php
WebDriverOptions.getCookies
public function getCookies() { $cookieArrays = $this->executor->execute(DriverCommand::GET_ALL_COOKIES); $cookies = []; foreach ($cookieArrays as $cookieArray) { $cookies[] = Cookie::createFromArray($cookieArray); } return $cookies; }
php
public function getCookies() { $cookieArrays = $this->executor->execute(DriverCommand::GET_ALL_COOKIES); $cookies = []; foreach ($cookieArrays as $cookieArray) { $cookies[] = Cookie::createFromArray($cookieArray); } return $cookies; }
[ "public", "function", "getCookies", "(", ")", "{", "$", "cookieArrays", "=", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET_ALL_COOKIES", ")", ";", "$", "cookies", "=", "[", "]", ";", "foreach", "(", "$", "cookieArrays", "as", "$", "cookieArray", ")", "{", "$", "cookies", "[", "]", "=", "Cookie", "::", "createFromArray", "(", "$", "cookieArray", ")", ";", "}", "return", "$", "cookies", ";", "}" ]
Get all the cookies for the current domain. @return Cookie[] The array of cookies presented.
[ "Get", "all", "the", "cookies", "for", "the", "current", "domain", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverOptions.php#L112-L122
train
facebook/php-webdriver
lib/Exception/WebDriverException.php
WebDriverException.throwException
public static function throwException($status_code, $message, $results) { switch ($status_code) { case 1: throw new IndexOutOfBoundsException($message, $results); case 2: throw new NoCollectionException($message, $results); case 3: throw new NoStringException($message, $results); case 4: throw new NoStringLengthException($message, $results); case 5: throw new NoStringWrapperException($message, $results); case 6: throw new NoSuchDriverException($message, $results); case 7: throw new NoSuchElementException($message, $results); case 8: throw new NoSuchFrameException($message, $results); case 9: throw new UnknownCommandException($message, $results); case 10: throw new StaleElementReferenceException($message, $results); case 11: throw new ElementNotVisibleException($message, $results); case 12: throw new InvalidElementStateException($message, $results); case 13: throw new UnknownServerException($message, $results); case 14: throw new ExpectedException($message, $results); case 15: throw new ElementNotSelectableException($message, $results); case 16: throw new NoSuchDocumentException($message, $results); case 17: throw new UnexpectedJavascriptException($message, $results); case 18: throw new NoScriptResultException($message, $results); case 19: throw new XPathLookupException($message, $results); case 20: throw new NoSuchCollectionException($message, $results); case 21: throw new TimeOutException($message, $results); case 22: throw new NullPointerException($message, $results); case 23: throw new NoSuchWindowException($message, $results); case 24: throw new InvalidCookieDomainException($message, $results); case 25: throw new UnableToSetCookieException($message, $results); case 26: throw new UnexpectedAlertOpenException($message, $results); case 27: throw new NoAlertOpenException($message, $results); case 28: throw new ScriptTimeoutException($message, $results); case 29: throw new InvalidCoordinatesException($message, $results); case 30: throw new IMENotAvailableException($message, $results); case 31: throw new IMEEngineActivationFailedException($message, $results); case 32: throw new InvalidSelectorException($message, $results); case 33: throw new SessionNotCreatedException($message, $results); case 34: throw new MoveTargetOutOfBoundsException($message, $results); default: throw new UnrecognizedExceptionException($message, $results); } }
php
public static function throwException($status_code, $message, $results) { switch ($status_code) { case 1: throw new IndexOutOfBoundsException($message, $results); case 2: throw new NoCollectionException($message, $results); case 3: throw new NoStringException($message, $results); case 4: throw new NoStringLengthException($message, $results); case 5: throw new NoStringWrapperException($message, $results); case 6: throw new NoSuchDriverException($message, $results); case 7: throw new NoSuchElementException($message, $results); case 8: throw new NoSuchFrameException($message, $results); case 9: throw new UnknownCommandException($message, $results); case 10: throw new StaleElementReferenceException($message, $results); case 11: throw new ElementNotVisibleException($message, $results); case 12: throw new InvalidElementStateException($message, $results); case 13: throw new UnknownServerException($message, $results); case 14: throw new ExpectedException($message, $results); case 15: throw new ElementNotSelectableException($message, $results); case 16: throw new NoSuchDocumentException($message, $results); case 17: throw new UnexpectedJavascriptException($message, $results); case 18: throw new NoScriptResultException($message, $results); case 19: throw new XPathLookupException($message, $results); case 20: throw new NoSuchCollectionException($message, $results); case 21: throw new TimeOutException($message, $results); case 22: throw new NullPointerException($message, $results); case 23: throw new NoSuchWindowException($message, $results); case 24: throw new InvalidCookieDomainException($message, $results); case 25: throw new UnableToSetCookieException($message, $results); case 26: throw new UnexpectedAlertOpenException($message, $results); case 27: throw new NoAlertOpenException($message, $results); case 28: throw new ScriptTimeoutException($message, $results); case 29: throw new InvalidCoordinatesException($message, $results); case 30: throw new IMENotAvailableException($message, $results); case 31: throw new IMEEngineActivationFailedException($message, $results); case 32: throw new InvalidSelectorException($message, $results); case 33: throw new SessionNotCreatedException($message, $results); case 34: throw new MoveTargetOutOfBoundsException($message, $results); default: throw new UnrecognizedExceptionException($message, $results); } }
[ "public", "static", "function", "throwException", "(", "$", "status_code", ",", "$", "message", ",", "$", "results", ")", "{", "switch", "(", "$", "status_code", ")", "{", "case", "1", ":", "throw", "new", "IndexOutOfBoundsException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "2", ":", "throw", "new", "NoCollectionException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "3", ":", "throw", "new", "NoStringException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "4", ":", "throw", "new", "NoStringLengthException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "5", ":", "throw", "new", "NoStringWrapperException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "6", ":", "throw", "new", "NoSuchDriverException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "7", ":", "throw", "new", "NoSuchElementException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "8", ":", "throw", "new", "NoSuchFrameException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "9", ":", "throw", "new", "UnknownCommandException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "10", ":", "throw", "new", "StaleElementReferenceException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "11", ":", "throw", "new", "ElementNotVisibleException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "12", ":", "throw", "new", "InvalidElementStateException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "13", ":", "throw", "new", "UnknownServerException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "14", ":", "throw", "new", "ExpectedException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "15", ":", "throw", "new", "ElementNotSelectableException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "16", ":", "throw", "new", "NoSuchDocumentException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "17", ":", "throw", "new", "UnexpectedJavascriptException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "18", ":", "throw", "new", "NoScriptResultException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "19", ":", "throw", "new", "XPathLookupException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "20", ":", "throw", "new", "NoSuchCollectionException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "21", ":", "throw", "new", "TimeOutException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "22", ":", "throw", "new", "NullPointerException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "23", ":", "throw", "new", "NoSuchWindowException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "24", ":", "throw", "new", "InvalidCookieDomainException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "25", ":", "throw", "new", "UnableToSetCookieException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "26", ":", "throw", "new", "UnexpectedAlertOpenException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "27", ":", "throw", "new", "NoAlertOpenException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "28", ":", "throw", "new", "ScriptTimeoutException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "29", ":", "throw", "new", "InvalidCoordinatesException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "30", ":", "throw", "new", "IMENotAvailableException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "31", ":", "throw", "new", "IMEEngineActivationFailedException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "32", ":", "throw", "new", "InvalidSelectorException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "33", ":", "throw", "new", "SessionNotCreatedException", "(", "$", "message", ",", "$", "results", ")", ";", "case", "34", ":", "throw", "new", "MoveTargetOutOfBoundsException", "(", "$", "message", ",", "$", "results", ")", ";", "default", ":", "throw", "new", "UnrecognizedExceptionException", "(", "$", "message", ",", "$", "results", ")", ";", "}", "}" ]
Throw WebDriverExceptions based on WebDriver status code. @param int $status_code @param string $message @param mixed $results @throws ElementNotSelectableException @throws ElementNotVisibleException @throws ExpectedException @throws IMEEngineActivationFailedException @throws IMENotAvailableException @throws IndexOutOfBoundsException @throws InvalidCookieDomainException @throws InvalidCoordinatesException @throws InvalidElementStateException @throws InvalidSelectorException @throws MoveTargetOutOfBoundsException @throws NoAlertOpenException @throws NoCollectionException @throws NoScriptResultException @throws NoStringException @throws NoStringLengthException @throws NoStringWrapperException @throws NoSuchCollectionException @throws NoSuchDocumentException @throws NoSuchDriverException @throws NoSuchElementException @throws NoSuchFrameException @throws NoSuchWindowException @throws NullPointerException @throws ScriptTimeoutException @throws SessionNotCreatedException @throws StaleElementReferenceException @throws TimeOutException @throws UnableToSetCookieException @throws UnexpectedAlertOpenException @throws UnexpectedJavascriptException @throws UnknownCommandException @throws UnknownServerException @throws UnrecognizedExceptionException @throws WebDriverCurlException @throws XPathLookupException
[ "Throw", "WebDriverExceptions", "based", "on", "WebDriver", "status", "code", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/Exception/WebDriverException.php#L86-L160
train
facebook/php-webdriver
lib/WebDriverNavigation.php
WebDriverNavigation.to
public function to($url) { $params = ['url' => (string) $url]; $this->executor->execute(DriverCommand::GET, $params); return $this; }
php
public function to($url) { $params = ['url' => (string) $url]; $this->executor->execute(DriverCommand::GET, $params); return $this; }
[ "public", "function", "to", "(", "$", "url", ")", "{", "$", "params", "=", "[", "'url'", "=>", "(", "string", ")", "$", "url", "]", ";", "$", "this", "->", "executor", "->", "execute", "(", "DriverCommand", "::", "GET", ",", "$", "params", ")", ";", "return", "$", "this", ";", "}" ]
Navigate to the given URL. @see WebDriver::get() @param string $url @return WebDriverNavigation The instance.
[ "Navigate", "to", "the", "given", "URL", "." ]
2dbfa7029fc317a2d649f0ccbdaf5d225662df6b
https://github.com/facebook/php-webdriver/blob/2dbfa7029fc317a2d649f0ccbdaf5d225662df6b/lib/WebDriverNavigation.php#L82-L88
train
LaravelCollective/html
src/HtmlBuilder.php
HtmlBuilder.nestedListing
protected function nestedListing($key, $type, $value) { if (is_int($key)) { return $this->listing($type, $value); } else { return '<li>' . $key . $this->listing($type, $value) . '</li>'; } }
php
protected function nestedListing($key, $type, $value) { if (is_int($key)) { return $this->listing($type, $value); } else { return '<li>' . $key . $this->listing($type, $value) . '</li>'; } }
[ "protected", "function", "nestedListing", "(", "$", "key", ",", "$", "type", ",", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "listing", "(", "$", "type", ",", "$", "value", ")", ";", "}", "else", "{", "return", "'<li>'", ".", "$", "key", ".", "$", "this", "->", "listing", "(", "$", "type", ",", "$", "value", ")", ".", "'</li>'", ";", "}", "}" ]
Create the HTML for a nested listing attribute. @param mixed $key @param string $type @param mixed $value @return string
[ "Create", "the", "HTML", "for", "a", "nested", "listing", "attribute", "." ]
b3b35b61433e77d8673e51e3b99183d2db4621c1
https://github.com/LaravelCollective/html/blob/b3b35b61433e77d8673e51e3b99183d2db4621c1/src/HtmlBuilder.php#L403-L410
train
LaravelCollective/html
src/FormBuilder.php
FormBuilder.tel
public function tel($name, $value = null, $options = []) { return $this->input('tel', $name, $value, $options); }
php
public function tel($name, $value = null, $options = []) { return $this->input('tel', $name, $value, $options); }
[ "public", "function", "tel", "(", "$", "name", ",", "$", "value", "=", "null", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "input", "(", "'tel'", ",", "$", "name", ",", "$", "value", ",", "$", "options", ")", ";", "}" ]
Create a tel input field. @param string $name @param string $value @param array $options @return \Illuminate\Support\HtmlString
[ "Create", "a", "tel", "input", "field", "." ]
b3b35b61433e77d8673e51e3b99183d2db4621c1
https://github.com/LaravelCollective/html/blob/b3b35b61433e77d8673e51e3b99183d2db4621c1/src/FormBuilder.php#L405-L408
train
LaravelCollective/html
src/FormBuilder.php
FormBuilder.month
public function month($name, $value = null, $options = []) { if ($value instanceof DateTime) { $value = $value->format('Y-m'); } return $this->input('month', $name, $value, $options); }
php
public function month($name, $value = null, $options = []) { if ($value instanceof DateTime) { $value = $value->format('Y-m'); } return $this->input('month', $name, $value, $options); }
[ "public", "function", "month", "(", "$", "name", ",", "$", "value", "=", "null", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "value", "instanceof", "DateTime", ")", "{", "$", "value", "=", "$", "value", "->", "format", "(", "'Y-m'", ")", ";", "}", "return", "$", "this", "->", "input", "(", "'month'", ",", "$", "name", ",", "$", "value", ",", "$", "options", ")", ";", "}" ]
Create a month input field. @param string $name @param string $value @param array $options @return \Illuminate\Support\HtmlString
[ "Create", "a", "month", "input", "field", "." ]
b3b35b61433e77d8673e51e3b99183d2db4621c1
https://github.com/LaravelCollective/html/blob/b3b35b61433e77d8673e51e3b99183d2db4621c1/src/FormBuilder.php#L1038-L1045
train
drupal-composer/drupal-project
drush/Commands/PolicyCommands.php
PolicyCommands.rsyncValidate
public function rsyncValidate(CommandData $commandData) { if (preg_match("/^@prod/", $commandData->input()->getArgument('target'))) { throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__])); } }
php
public function rsyncValidate(CommandData $commandData) { if (preg_match("/^@prod/", $commandData->input()->getArgument('target'))) { throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__])); } }
[ "public", "function", "rsyncValidate", "(", "CommandData", "$", "commandData", ")", "{", "if", "(", "preg_match", "(", "\"/^@prod/\"", ",", "$", "commandData", "->", "input", "(", ")", "->", "getArgument", "(", "'target'", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "dt", "(", "'Per !file, you may never rsync to the production site.'", ",", "[", "'!file'", "=>", "__FILE__", "]", ")", ")", ";", "}", "}" ]
Limit rsync operations to production site. @hook validate core:rsync @throws \Exception
[ "Limit", "rsync", "operations", "to", "production", "site", "." ]
ec0f41171516c18357ca4cda9068ee4cdeabaa19
https://github.com/drupal-composer/drupal-project/blob/ec0f41171516c18357ca4cda9068ee4cdeabaa19/drush/Commands/PolicyCommands.php#L33-L37
train
spiral/roadrunner
src/PSR7Client.php
PSR7Client.configureServer
protected function configureServer(array $ctx): array { $server = $this->originalServer; $server['REQUEST_TIME'] = time(); $server['REQUEST_TIME_FLOAT'] = microtime(true); $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; $server['HTTP_USER_AGENT'] = ''; foreach ($ctx['headers'] as $key => $value) { $key = strtoupper(str_replace('-', '_', $key)); if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) { $server[$key] = implode(', ', $value); } else { $server['HTTP_' . $key] = implode(', ', $value); } } return $server; }
php
protected function configureServer(array $ctx): array { $server = $this->originalServer; $server['REQUEST_TIME'] = time(); $server['REQUEST_TIME_FLOAT'] = microtime(true); $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; $server['HTTP_USER_AGENT'] = ''; foreach ($ctx['headers'] as $key => $value) { $key = strtoupper(str_replace('-', '_', $key)); if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) { $server[$key] = implode(', ', $value); } else { $server['HTTP_' . $key] = implode(', ', $value); } } return $server; }
[ "protected", "function", "configureServer", "(", "array", "$", "ctx", ")", ":", "array", "{", "$", "server", "=", "$", "this", "->", "originalServer", ";", "$", "server", "[", "'REQUEST_TIME'", "]", "=", "time", "(", ")", ";", "$", "server", "[", "'REQUEST_TIME_FLOAT'", "]", "=", "microtime", "(", "true", ")", ";", "$", "server", "[", "'REMOTE_ADDR'", "]", "=", "$", "ctx", "[", "'attributes'", "]", "[", "'ipAddress'", "]", "??", "$", "ctx", "[", "'remoteAddr'", "]", "??", "'127.0.0.1'", ";", "$", "server", "[", "'HTTP_USER_AGENT'", "]", "=", "''", ";", "foreach", "(", "$", "ctx", "[", "'headers'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "key", "=", "strtoupper", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "key", ")", ")", ";", "if", "(", "\\", "in_array", "(", "$", "key", ",", "[", "'CONTENT_TYPE'", ",", "'CONTENT_LENGTH'", "]", ")", ")", "{", "$", "server", "[", "$", "key", "]", "=", "implode", "(", "', '", ",", "$", "value", ")", ";", "}", "else", "{", "$", "server", "[", "'HTTP_'", ".", "$", "key", "]", "=", "implode", "(", "', '", ",", "$", "value", ")", ";", "}", "}", "return", "$", "server", ";", "}" ]
Returns altered copy of _SERVER variable. Sets ip-address, request-time and other values. @param array $ctx @return array
[ "Returns", "altered", "copy", "of", "_SERVER", "variable", ".", "Sets", "ip", "-", "address", "request", "-", "time", "and", "other", "values", "." ]
aa80896b3c7c2dd1e43fbd986720192df22f033b
https://github.com/spiral/roadrunner/blob/aa80896b3c7c2dd1e43fbd986720192df22f033b/src/PSR7Client.php#L132-L150
train
spiral/roadrunner
src/PSR7Client.php
PSR7Client.wrapUploads
private function wrapUploads($files): array { if (empty($files)) { return []; } $result = []; foreach ($files as $index => $f) { if (!isset($f['name'])) { $result[$index] = $this->wrapUploads($f); continue; } if (UPLOAD_ERR_OK === $f['error']) { $stream = $this->streamFactory->createStreamFromFile($f['tmpName']); } else { $stream = $this->streamFactory->createStream(); } $result[$index] = $this->uploadsFactory->createUploadedFile( $stream, $f['size'], $f['error'], $f['name'], $f['mime'] ); } return $result; }
php
private function wrapUploads($files): array { if (empty($files)) { return []; } $result = []; foreach ($files as $index => $f) { if (!isset($f['name'])) { $result[$index] = $this->wrapUploads($f); continue; } if (UPLOAD_ERR_OK === $f['error']) { $stream = $this->streamFactory->createStreamFromFile($f['tmpName']); } else { $stream = $this->streamFactory->createStream(); } $result[$index] = $this->uploadsFactory->createUploadedFile( $stream, $f['size'], $f['error'], $f['name'], $f['mime'] ); } return $result; }
[ "private", "function", "wrapUploads", "(", "$", "files", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "index", "=>", "$", "f", ")", "{", "if", "(", "!", "isset", "(", "$", "f", "[", "'name'", "]", ")", ")", "{", "$", "result", "[", "$", "index", "]", "=", "$", "this", "->", "wrapUploads", "(", "$", "f", ")", ";", "continue", ";", "}", "if", "(", "UPLOAD_ERR_OK", "===", "$", "f", "[", "'error'", "]", ")", "{", "$", "stream", "=", "$", "this", "->", "streamFactory", "->", "createStreamFromFile", "(", "$", "f", "[", "'tmpName'", "]", ")", ";", "}", "else", "{", "$", "stream", "=", "$", "this", "->", "streamFactory", "->", "createStream", "(", ")", ";", "}", "$", "result", "[", "$", "index", "]", "=", "$", "this", "->", "uploadsFactory", "->", "createUploadedFile", "(", "$", "stream", ",", "$", "f", "[", "'size'", "]", ",", "$", "f", "[", "'error'", "]", ",", "$", "f", "[", "'name'", "]", ",", "$", "f", "[", "'mime'", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Wraps all uploaded files with UploadedFile. @param array $files @return array
[ "Wraps", "all", "uploaded", "files", "with", "UploadedFile", "." ]
aa80896b3c7c2dd1e43fbd986720192df22f033b
https://github.com/spiral/roadrunner/blob/aa80896b3c7c2dd1e43fbd986720192df22f033b/src/PSR7Client.php#L159-L188
train
spiral/roadrunner
src/PSR7Client.php
PSR7Client.fetchProtocolVersion
private static function fetchProtocolVersion(string $version): string { $v = substr($version, 5); if ($v === '2.0') { return '2'; } // Fallback for values outside of valid protocol versions if (!in_array($v, static::$allowedVersions, true)) { return '1.1'; } return $v; }
php
private static function fetchProtocolVersion(string $version): string { $v = substr($version, 5); if ($v === '2.0') { return '2'; } // Fallback for values outside of valid protocol versions if (!in_array($v, static::$allowedVersions, true)) { return '1.1'; } return $v; }
[ "private", "static", "function", "fetchProtocolVersion", "(", "string", "$", "version", ")", ":", "string", "{", "$", "v", "=", "substr", "(", "$", "version", ",", "5", ")", ";", "if", "(", "$", "v", "===", "'2.0'", ")", "{", "return", "'2'", ";", "}", "// Fallback for values outside of valid protocol versions", "if", "(", "!", "in_array", "(", "$", "v", ",", "static", "::", "$", "allowedVersions", ",", "true", ")", ")", "{", "return", "'1.1'", ";", "}", "return", "$", "v", ";", "}" ]
Normalize HTTP protocol version to valid values @param string $version @return string
[ "Normalize", "HTTP", "protocol", "version", "to", "valid", "values" ]
aa80896b3c7c2dd1e43fbd986720192df22f033b
https://github.com/spiral/roadrunner/blob/aa80896b3c7c2dd1e43fbd986720192df22f033b/src/PSR7Client.php#L196-L210
train
spiral/roadrunner
src/Worker.php
Worker.receive
public function receive(&$header) { $body = $this->relay->receiveSync($flags); if ($flags & Relay::PAYLOAD_CONTROL) { if ($this->handleControl($body, $header, $flags)) { // wait for the next command return $this->receive($header); } // no context for the termination. $header = null; // Expect process termination return null; } if ($flags & Relay::PAYLOAD_ERROR) { return new \Error($body); } return $body; }
php
public function receive(&$header) { $body = $this->relay->receiveSync($flags); if ($flags & Relay::PAYLOAD_CONTROL) { if ($this->handleControl($body, $header, $flags)) { // wait for the next command return $this->receive($header); } // no context for the termination. $header = null; // Expect process termination return null; } if ($flags & Relay::PAYLOAD_ERROR) { return new \Error($body); } return $body; }
[ "public", "function", "receive", "(", "&", "$", "header", ")", "{", "$", "body", "=", "$", "this", "->", "relay", "->", "receiveSync", "(", "$", "flags", ")", ";", "if", "(", "$", "flags", "&", "Relay", "::", "PAYLOAD_CONTROL", ")", "{", "if", "(", "$", "this", "->", "handleControl", "(", "$", "body", ",", "$", "header", ",", "$", "flags", ")", ")", "{", "// wait for the next command", "return", "$", "this", "->", "receive", "(", "$", "header", ")", ";", "}", "// no context for the termination.", "$", "header", "=", "null", ";", "// Expect process termination", "return", "null", ";", "}", "if", "(", "$", "flags", "&", "Relay", "::", "PAYLOAD_ERROR", ")", "{", "return", "new", "\\", "Error", "(", "$", "body", ")", ";", "}", "return", "$", "body", ";", "}" ]
Receive packet of information to process, returns null when process must be stopped. Might return Error to wrap error message from server. @param mixed $header @return \Error|null|string @throws GoridgeException
[ "Receive", "packet", "of", "information", "to", "process", "returns", "null", "when", "process", "must", "be", "stopped", ".", "Might", "return", "Error", "to", "wrap", "error", "message", "from", "server", "." ]
aa80896b3c7c2dd1e43fbd986720192df22f033b
https://github.com/spiral/roadrunner/blob/aa80896b3c7c2dd1e43fbd986720192df22f033b/src/Worker.php#L50-L72
train
spiral/roadrunner
src/Worker.php
Worker.send
public function send(string $payload = null, string $header = null) { if (is_null($header)) { $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); } else { $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); } $this->relay->send($payload, Relay::PAYLOAD_RAW); }
php
public function send(string $payload = null, string $header = null) { if (is_null($header)) { $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); } else { $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); } $this->relay->send($payload, Relay::PAYLOAD_RAW); }
[ "public", "function", "send", "(", "string", "$", "payload", "=", "null", ",", "string", "$", "header", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "header", ")", ")", "{", "$", "this", "->", "relay", "->", "send", "(", "$", "header", ",", "Relay", "::", "PAYLOAD_CONTROL", "|", "Relay", "::", "PAYLOAD_NONE", ")", ";", "}", "else", "{", "$", "this", "->", "relay", "->", "send", "(", "$", "header", ",", "Relay", "::", "PAYLOAD_CONTROL", "|", "Relay", "::", "PAYLOAD_RAW", ")", ";", "}", "$", "this", "->", "relay", "->", "send", "(", "$", "payload", ",", "Relay", "::", "PAYLOAD_RAW", ")", ";", "}" ]
Respond to the server with result of task execution and execution context. Example: $worker->respond((string)$response->getBody(), json_encode($response->getHeaders())); @param string|null $payload @param string|null $header
[ "Respond", "to", "the", "server", "with", "result", "of", "task", "execution", "and", "execution", "context", "." ]
aa80896b3c7c2dd1e43fbd986720192df22f033b
https://github.com/spiral/roadrunner/blob/aa80896b3c7c2dd1e43fbd986720192df22f033b/src/Worker.php#L83-L92
train
spiral/roadrunner
src/Worker.php
Worker.error
public function error(string $message) { $this->relay->send( $message, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW | Relay::PAYLOAD_ERROR ); }
php
public function error(string $message) { $this->relay->send( $message, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW | Relay::PAYLOAD_ERROR ); }
[ "public", "function", "error", "(", "string", "$", "message", ")", "{", "$", "this", "->", "relay", "->", "send", "(", "$", "message", ",", "Relay", "::", "PAYLOAD_CONTROL", "|", "Relay", "::", "PAYLOAD_RAW", "|", "Relay", "::", "PAYLOAD_ERROR", ")", ";", "}" ]
Respond to the server with an error. Error must be treated as TaskError and might not cause worker destruction. Example: $worker->error("invalid payload"); @param string $message
[ "Respond", "to", "the", "server", "with", "an", "error", ".", "Error", "must", "be", "treated", "as", "TaskError", "and", "might", "not", "cause", "worker", "destruction", "." ]
aa80896b3c7c2dd1e43fbd986720192df22f033b
https://github.com/spiral/roadrunner/blob/aa80896b3c7c2dd1e43fbd986720192df22f033b/src/Worker.php#L104-L110
train
spiral/roadrunner
src/Worker.php
Worker.handleControl
private function handleControl(string $body = null, &$header = null, int $flags = 0): bool { $header = $body; if (is_null($body) || $flags & Relay::PAYLOAD_RAW) { // empty or raw prefix return true; } $p = json_decode($body, true); if ($p === false) { throw new RoadRunnerException("invalid task context, JSON payload is expected"); } // PID negotiation (socket connections only) if (!empty($p['pid'])) { $this->relay->send( sprintf('{"pid":%s}', getmypid()), Relay::PAYLOAD_CONTROL ); } // termination request if (!empty($p['stop'])) { return false; } // parsed header $header = $p; return true; }
php
private function handleControl(string $body = null, &$header = null, int $flags = 0): bool { $header = $body; if (is_null($body) || $flags & Relay::PAYLOAD_RAW) { // empty or raw prefix return true; } $p = json_decode($body, true); if ($p === false) { throw new RoadRunnerException("invalid task context, JSON payload is expected"); } // PID negotiation (socket connections only) if (!empty($p['pid'])) { $this->relay->send( sprintf('{"pid":%s}', getmypid()), Relay::PAYLOAD_CONTROL ); } // termination request if (!empty($p['stop'])) { return false; } // parsed header $header = $p; return true; }
[ "private", "function", "handleControl", "(", "string", "$", "body", "=", "null", ",", "&", "$", "header", "=", "null", ",", "int", "$", "flags", "=", "0", ")", ":", "bool", "{", "$", "header", "=", "$", "body", ";", "if", "(", "is_null", "(", "$", "body", ")", "||", "$", "flags", "&", "Relay", "::", "PAYLOAD_RAW", ")", "{", "// empty or raw prefix", "return", "true", ";", "}", "$", "p", "=", "json_decode", "(", "$", "body", ",", "true", ")", ";", "if", "(", "$", "p", "===", "false", ")", "{", "throw", "new", "RoadRunnerException", "(", "\"invalid task context, JSON payload is expected\"", ")", ";", "}", "// PID negotiation (socket connections only)", "if", "(", "!", "empty", "(", "$", "p", "[", "'pid'", "]", ")", ")", "{", "$", "this", "->", "relay", "->", "send", "(", "sprintf", "(", "'{\"pid\":%s}'", ",", "getmypid", "(", ")", ")", ",", "Relay", "::", "PAYLOAD_CONTROL", ")", ";", "}", "// termination request", "if", "(", "!", "empty", "(", "$", "p", "[", "'stop'", "]", ")", ")", "{", "return", "false", ";", "}", "// parsed header", "$", "header", "=", "$", "p", ";", "return", "true", ";", "}" ]
Handles incoming control command payload and executes it if required. @param string $body @param mixed $header Exported context (if any). @param int $flags @return bool True when continue processing. @throws RoadRunnerException
[ "Handles", "incoming", "control", "command", "payload", "and", "executes", "it", "if", "required", "." ]
aa80896b3c7c2dd1e43fbd986720192df22f033b
https://github.com/spiral/roadrunner/blob/aa80896b3c7c2dd1e43fbd986720192df22f033b/src/Worker.php#L136-L165
train
rebing/graphql-laravel
src/Rebing/GraphQL/Support/SelectFields.php
SelectFields.validateField
protected static function validateField($fieldObject) { $selectable = true; // If not a selectable field if(isset($fieldObject->config['selectable']) && $fieldObject->config['selectable'] === false) { $selectable = false; } if(isset($fieldObject->config['privacy'])) { $privacyClass = $fieldObject->config['privacy']; // If privacy given as a closure if(is_callable($privacyClass) && call_user_func($privacyClass, self::$args) === false) { $selectable = null; } // If Privacy class given elseif(is_string($privacyClass)) { if(array_has(self::$privacyValidations, $privacyClass)) { $validated = self::$privacyValidations[$privacyClass]; } else { $validated = call_user_func([app($privacyClass), 'fire'], self::$args); self::$privacyValidations[$privacyClass] = $validated; } if( ! $validated) { $selectable = null; } } } return $selectable; }
php
protected static function validateField($fieldObject) { $selectable = true; // If not a selectable field if(isset($fieldObject->config['selectable']) && $fieldObject->config['selectable'] === false) { $selectable = false; } if(isset($fieldObject->config['privacy'])) { $privacyClass = $fieldObject->config['privacy']; // If privacy given as a closure if(is_callable($privacyClass) && call_user_func($privacyClass, self::$args) === false) { $selectable = null; } // If Privacy class given elseif(is_string($privacyClass)) { if(array_has(self::$privacyValidations, $privacyClass)) { $validated = self::$privacyValidations[$privacyClass]; } else { $validated = call_user_func([app($privacyClass), 'fire'], self::$args); self::$privacyValidations[$privacyClass] = $validated; } if( ! $validated) { $selectable = null; } } } return $selectable; }
[ "protected", "static", "function", "validateField", "(", "$", "fieldObject", ")", "{", "$", "selectable", "=", "true", ";", "// If not a selectable field", "if", "(", "isset", "(", "$", "fieldObject", "->", "config", "[", "'selectable'", "]", ")", "&&", "$", "fieldObject", "->", "config", "[", "'selectable'", "]", "===", "false", ")", "{", "$", "selectable", "=", "false", ";", "}", "if", "(", "isset", "(", "$", "fieldObject", "->", "config", "[", "'privacy'", "]", ")", ")", "{", "$", "privacyClass", "=", "$", "fieldObject", "->", "config", "[", "'privacy'", "]", ";", "// If privacy given as a closure", "if", "(", "is_callable", "(", "$", "privacyClass", ")", "&&", "call_user_func", "(", "$", "privacyClass", ",", "self", "::", "$", "args", ")", "===", "false", ")", "{", "$", "selectable", "=", "null", ";", "}", "// If Privacy class given", "elseif", "(", "is_string", "(", "$", "privacyClass", ")", ")", "{", "if", "(", "array_has", "(", "self", "::", "$", "privacyValidations", ",", "$", "privacyClass", ")", ")", "{", "$", "validated", "=", "self", "::", "$", "privacyValidations", "[", "$", "privacyClass", "]", ";", "}", "else", "{", "$", "validated", "=", "call_user_func", "(", "[", "app", "(", "$", "privacyClass", ")", ",", "'fire'", "]", ",", "self", "::", "$", "args", ")", ";", "self", "::", "$", "privacyValidations", "[", "$", "privacyClass", "]", "=", "$", "validated", ";", "}", "if", "(", "!", "$", "validated", ")", "{", "$", "selectable", "=", "null", ";", "}", "}", "}", "return", "$", "selectable", ";", "}" ]
Check the privacy status, if it's given @return boolean | null - true, if selectable; false, if not selectable, but allowed; null, if not allowed
[ "Check", "the", "privacy", "status", "if", "it", "s", "given" ]
277d9ca00e1dd847315d75e6499cc9a0f201f576
https://github.com/rebing/graphql-laravel/blob/277d9ca00e1dd847315d75e6499cc9a0f201f576/src/Rebing/GraphQL/Support/SelectFields.php#L267-L307
train
rebing/graphql-laravel
src/Rebing/GraphQL/Support/SelectFields.php
SelectFields.addAlwaysFields
protected static function addAlwaysFields($fieldObject, array &$select, $parentTable, $forRelation = false) { if(isset($fieldObject->config['always'])) { $always = $fieldObject->config['always']; if(is_string($always)) { $always = explode(',', $always); } // Get as 'field' => true foreach($always as $field) { self::addFieldToSelect($field, $select, $parentTable, $forRelation); } } }
php
protected static function addAlwaysFields($fieldObject, array &$select, $parentTable, $forRelation = false) { if(isset($fieldObject->config['always'])) { $always = $fieldObject->config['always']; if(is_string($always)) { $always = explode(',', $always); } // Get as 'field' => true foreach($always as $field) { self::addFieldToSelect($field, $select, $parentTable, $forRelation); } } }
[ "protected", "static", "function", "addAlwaysFields", "(", "$", "fieldObject", ",", "array", "&", "$", "select", ",", "$", "parentTable", ",", "$", "forRelation", "=", "false", ")", "{", "if", "(", "isset", "(", "$", "fieldObject", "->", "config", "[", "'always'", "]", ")", ")", "{", "$", "always", "=", "$", "fieldObject", "->", "config", "[", "'always'", "]", ";", "if", "(", "is_string", "(", "$", "always", ")", ")", "{", "$", "always", "=", "explode", "(", "','", ",", "$", "always", ")", ";", "}", "// Get as 'field' => true", "foreach", "(", "$", "always", "as", "$", "field", ")", "{", "self", "::", "addFieldToSelect", "(", "$", "field", ",", "$", "select", ",", "$", "parentTable", ",", "$", "forRelation", ")", ";", "}", "}", "}" ]
Add selects that are given by the 'always' attribute
[ "Add", "selects", "that", "are", "given", "by", "the", "always", "attribute" ]
277d9ca00e1dd847315d75e6499cc9a0f201f576
https://github.com/rebing/graphql-laravel/blob/277d9ca00e1dd847315d75e6499cc9a0f201f576/src/Rebing/GraphQL/Support/SelectFields.php#L322-L339
train
rebing/graphql-laravel
src/Rebing/GraphQL/GraphQLUploadMiddleware.php
GraphQLUploadMiddleware.processRequest
public function processRequest(Request $request) { $contentType = $request->header('content-type') ?: ''; if (mb_stripos($contentType, 'multipart/form-data') !== false) { $this->validateParsedBody($request); $request = $this->parseUploadedFiles($request); } return $request; }
php
public function processRequest(Request $request) { $contentType = $request->header('content-type') ?: ''; if (mb_stripos($contentType, 'multipart/form-data') !== false) { $this->validateParsedBody($request); $request = $this->parseUploadedFiles($request); } return $request; }
[ "public", "function", "processRequest", "(", "Request", "$", "request", ")", "{", "$", "contentType", "=", "$", "request", "->", "header", "(", "'content-type'", ")", "?", ":", "''", ";", "if", "(", "mb_stripos", "(", "$", "contentType", ",", "'multipart/form-data'", ")", "!==", "false", ")", "{", "$", "this", "->", "validateParsedBody", "(", "$", "request", ")", ";", "$", "request", "=", "$", "this", "->", "parseUploadedFiles", "(", "$", "request", ")", ";", "}", "return", "$", "request", ";", "}" ]
Process the request and return either a modified request or the original one @param \Illuminate\Http\Request $request @return \Illuminate\Http\Request
[ "Process", "the", "request", "and", "return", "either", "a", "modified", "request", "or", "the", "original", "one" ]
277d9ca00e1dd847315d75e6499cc9a0f201f576
https://github.com/rebing/graphql-laravel/blob/277d9ca00e1dd847315d75e6499cc9a0f201f576/src/Rebing/GraphQL/GraphQLUploadMiddleware.php#L34-L44
train
rebing/graphql-laravel
src/Rebing/GraphQL/GraphQLUploadMiddleware.php
GraphQLUploadMiddleware.parseUploadedFiles
private function parseUploadedFiles(Request $request) { $bodyParams = $request->all(); if (!isset($bodyParams['map'])) { throw new RequestError('The request must define a `map`'); } $map = json_decode($bodyParams['map'], true); $result = json_decode($bodyParams['operations'], true); if (isset($result['operationName'])) { $result['operation'] = $result['operationName']; unset($result['operationName']); } foreach ($map as $fileKey => $locations) { foreach ($locations as $location) { $items = &$result; foreach (explode('.', $location) as $key) { if (!isset($items[$key]) || !is_array($items[$key])) { $items[$key] = []; } $items = &$items[$key]; } $items = $request->allFiles()[$fileKey]; } } $request->replace($result); return $request; }
php
private function parseUploadedFiles(Request $request) { $bodyParams = $request->all(); if (!isset($bodyParams['map'])) { throw new RequestError('The request must define a `map`'); } $map = json_decode($bodyParams['map'], true); $result = json_decode($bodyParams['operations'], true); if (isset($result['operationName'])) { $result['operation'] = $result['operationName']; unset($result['operationName']); } foreach ($map as $fileKey => $locations) { foreach ($locations as $location) { $items = &$result; foreach (explode('.', $location) as $key) { if (!isset($items[$key]) || !is_array($items[$key])) { $items[$key] = []; } $items = &$items[$key]; } $items = $request->allFiles()[$fileKey]; } } $request->replace($result); return $request; }
[ "private", "function", "parseUploadedFiles", "(", "Request", "$", "request", ")", "{", "$", "bodyParams", "=", "$", "request", "->", "all", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "bodyParams", "[", "'map'", "]", ")", ")", "{", "throw", "new", "RequestError", "(", "'The request must define a `map`'", ")", ";", "}", "$", "map", "=", "json_decode", "(", "$", "bodyParams", "[", "'map'", "]", ",", "true", ")", ";", "$", "result", "=", "json_decode", "(", "$", "bodyParams", "[", "'operations'", "]", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "result", "[", "'operationName'", "]", ")", ")", "{", "$", "result", "[", "'operation'", "]", "=", "$", "result", "[", "'operationName'", "]", ";", "unset", "(", "$", "result", "[", "'operationName'", "]", ")", ";", "}", "foreach", "(", "$", "map", "as", "$", "fileKey", "=>", "$", "locations", ")", "{", "foreach", "(", "$", "locations", "as", "$", "location", ")", "{", "$", "items", "=", "&", "$", "result", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "location", ")", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "items", "[", "$", "key", "]", ")", "||", "!", "is_array", "(", "$", "items", "[", "$", "key", "]", ")", ")", "{", "$", "items", "[", "$", "key", "]", "=", "[", "]", ";", "}", "$", "items", "=", "&", "$", "items", "[", "$", "key", "]", ";", "}", "$", "items", "=", "$", "request", "->", "allFiles", "(", ")", "[", "$", "fileKey", "]", ";", "}", "}", "$", "request", "->", "replace", "(", "$", "result", ")", ";", "return", "$", "request", ";", "}" ]
Inject uploaded files defined in the 'map' key into the 'variables' key @param \Illuminate\Http\Request $request @return \Illuminate\Http\Request
[ "Inject", "uploaded", "files", "defined", "in", "the", "map", "key", "into", "the", "variables", "key" ]
277d9ca00e1dd847315d75e6499cc9a0f201f576
https://github.com/rebing/graphql-laravel/blob/277d9ca00e1dd847315d75e6499cc9a0f201f576/src/Rebing/GraphQL/GraphQLUploadMiddleware.php#L53-L84
train
rebing/graphql-laravel
src/Rebing/GraphQL/GraphQLUploadMiddleware.php
GraphQLUploadMiddleware.validateParsedBody
private function validateParsedBody(Request $request) { $bodyParams = $request->all(); if (null === $bodyParams) { throw new InvariantViolation( 'Request is expected to provide parsed body for "multipart/form-data" requests but got null' ); } if (!is_array($bodyParams)) { throw new RequestError( 'GraphQL Server expects JSON object or array, but got ' . Utils::printSafeJson($bodyParams) ); } if (empty($bodyParams)) { throw new InvariantViolation( 'Request is expected to provide parsed body for "multipart/form-data" requests but got empty array' ); } }
php
private function validateParsedBody(Request $request) { $bodyParams = $request->all(); if (null === $bodyParams) { throw new InvariantViolation( 'Request is expected to provide parsed body for "multipart/form-data" requests but got null' ); } if (!is_array($bodyParams)) { throw new RequestError( 'GraphQL Server expects JSON object or array, but got ' . Utils::printSafeJson($bodyParams) ); } if (empty($bodyParams)) { throw new InvariantViolation( 'Request is expected to provide parsed body for "multipart/form-data" requests but got empty array' ); } }
[ "private", "function", "validateParsedBody", "(", "Request", "$", "request", ")", "{", "$", "bodyParams", "=", "$", "request", "->", "all", "(", ")", ";", "if", "(", "null", "===", "$", "bodyParams", ")", "{", "throw", "new", "InvariantViolation", "(", "'Request is expected to provide parsed body for \"multipart/form-data\" requests but got null'", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "bodyParams", ")", ")", "{", "throw", "new", "RequestError", "(", "'GraphQL Server expects JSON object or array, but got '", ".", "Utils", "::", "printSafeJson", "(", "$", "bodyParams", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "bodyParams", ")", ")", "{", "throw", "new", "InvariantViolation", "(", "'Request is expected to provide parsed body for \"multipart/form-data\" requests but got empty array'", ")", ";", "}", "}" ]
Validates that the request meet our expectations @param \Illuminate\Http\Request $request
[ "Validates", "that", "the", "request", "meet", "our", "expectations" ]
277d9ca00e1dd847315d75e6499cc9a0f201f576
https://github.com/rebing/graphql-laravel/blob/277d9ca00e1dd847315d75e6499cc9a0f201f576/src/Rebing/GraphQL/GraphQLUploadMiddleware.php#L91-L112
train
rebing/graphql-laravel
src/Rebing/GraphQL/GraphQLServiceProvider.php
GraphQLServiceProvider.bootSchemas
protected function bootSchemas() { $configSchemas = config('graphql.schemas'); foreach ($configSchemas as $name => $schema) { $this->app['graphql']->addSchema($name, $schema); } }
php
protected function bootSchemas() { $configSchemas = config('graphql.schemas'); foreach ($configSchemas as $name => $schema) { $this->app['graphql']->addSchema($name, $schema); } }
[ "protected", "function", "bootSchemas", "(", ")", "{", "$", "configSchemas", "=", "config", "(", "'graphql.schemas'", ")", ";", "foreach", "(", "$", "configSchemas", "as", "$", "name", "=>", "$", "schema", ")", "{", "$", "this", "->", "app", "[", "'graphql'", "]", "->", "addSchema", "(", "$", "name", ",", "$", "schema", ")", ";", "}", "}" ]
Add schemas from config @return void
[ "Add", "schemas", "from", "config" ]
277d9ca00e1dd847315d75e6499cc9a0f201f576
https://github.com/rebing/graphql-laravel/blob/277d9ca00e1dd847315d75e6499cc9a0f201f576/src/Rebing/GraphQL/GraphQLServiceProvider.php#L88-L94
train
rebing/graphql-laravel
src/Rebing/GraphQL/GraphQLServiceProvider.php
GraphQLServiceProvider.applySecurityRules
protected function applySecurityRules() { $maxQueryComplexity = config('graphql.security.query_max_complexity'); if ($maxQueryComplexity !== null) { /** @var QueryComplexity $queryComplexity */ $queryComplexity = DocumentValidator::getRule('QueryComplexity'); $queryComplexity->setMaxQueryComplexity($maxQueryComplexity); } $maxQueryDepth = config('graphql.security.query_max_depth'); if ($maxQueryDepth !== null) { /** @var QueryDepth $queryDepth */ $queryDepth = DocumentValidator::getRule('QueryDepth'); $queryDepth->setMaxQueryDepth($maxQueryDepth); } $disableIntrospection = config('graphql.security.disable_introspection'); if ($disableIntrospection === true) { /** @var DisableIntrospection $disableIntrospection */ $disableIntrospection = DocumentValidator::getRule('DisableIntrospection'); $disableIntrospection->setEnabled(DisableIntrospection::ENABLED); } }
php
protected function applySecurityRules() { $maxQueryComplexity = config('graphql.security.query_max_complexity'); if ($maxQueryComplexity !== null) { /** @var QueryComplexity $queryComplexity */ $queryComplexity = DocumentValidator::getRule('QueryComplexity'); $queryComplexity->setMaxQueryComplexity($maxQueryComplexity); } $maxQueryDepth = config('graphql.security.query_max_depth'); if ($maxQueryDepth !== null) { /** @var QueryDepth $queryDepth */ $queryDepth = DocumentValidator::getRule('QueryDepth'); $queryDepth->setMaxQueryDepth($maxQueryDepth); } $disableIntrospection = config('graphql.security.disable_introspection'); if ($disableIntrospection === true) { /** @var DisableIntrospection $disableIntrospection */ $disableIntrospection = DocumentValidator::getRule('DisableIntrospection'); $disableIntrospection->setEnabled(DisableIntrospection::ENABLED); } }
[ "protected", "function", "applySecurityRules", "(", ")", "{", "$", "maxQueryComplexity", "=", "config", "(", "'graphql.security.query_max_complexity'", ")", ";", "if", "(", "$", "maxQueryComplexity", "!==", "null", ")", "{", "/** @var QueryComplexity $queryComplexity */", "$", "queryComplexity", "=", "DocumentValidator", "::", "getRule", "(", "'QueryComplexity'", ")", ";", "$", "queryComplexity", "->", "setMaxQueryComplexity", "(", "$", "maxQueryComplexity", ")", ";", "}", "$", "maxQueryDepth", "=", "config", "(", "'graphql.security.query_max_depth'", ")", ";", "if", "(", "$", "maxQueryDepth", "!==", "null", ")", "{", "/** @var QueryDepth $queryDepth */", "$", "queryDepth", "=", "DocumentValidator", "::", "getRule", "(", "'QueryDepth'", ")", ";", "$", "queryDepth", "->", "setMaxQueryDepth", "(", "$", "maxQueryDepth", ")", ";", "}", "$", "disableIntrospection", "=", "config", "(", "'graphql.security.disable_introspection'", ")", ";", "if", "(", "$", "disableIntrospection", "===", "true", ")", "{", "/** @var DisableIntrospection $disableIntrospection */", "$", "disableIntrospection", "=", "DocumentValidator", "::", "getRule", "(", "'DisableIntrospection'", ")", ";", "$", "disableIntrospection", "->", "setEnabled", "(", "DisableIntrospection", "::", "ENABLED", ")", ";", "}", "}" ]
Configure security from config @return void
[ "Configure", "security", "from", "config" ]
277d9ca00e1dd847315d75e6499cc9a0f201f576
https://github.com/rebing/graphql-laravel/blob/277d9ca00e1dd847315d75e6499cc9a0f201f576/src/Rebing/GraphQL/GraphQLServiceProvider.php#L101-L123
train
writingink/wink
src/Http/Controllers/PostsController.php
PostsController.store
public function store($id) { $data = [ 'title' => request('title'), 'excerpt' => request('excerpt', ''), 'slug' => request('slug'), 'body' => request('body', ''), 'published' => request('published'), 'author_id' => request('author_id'), 'featured_image' => request('featured_image'), 'featured_image_caption' => request('featured_image_caption', ''), 'publish_date' => request('publish_date', ''), 'meta' => request('meta', (object) []), ]; validator($data, [ 'publish_date' => 'required|date', 'author_id' => 'required', 'title' => 'required', 'slug' => 'required|'.Rule::unique(config('wink.database_connection').'.wink_posts', 'slug')->ignore(request('id')), ])->validate(); $entry = $id !== 'new' ? WinkPost::findOrFail($id) : new WinkPost(['id' => request('id')]); $entry->fill($data); $entry->save(); $entry->tags()->sync( $this->collectTags(request('tags')) ); return response()->json([ 'entry' => $entry, ]); }
php
public function store($id) { $data = [ 'title' => request('title'), 'excerpt' => request('excerpt', ''), 'slug' => request('slug'), 'body' => request('body', ''), 'published' => request('published'), 'author_id' => request('author_id'), 'featured_image' => request('featured_image'), 'featured_image_caption' => request('featured_image_caption', ''), 'publish_date' => request('publish_date', ''), 'meta' => request('meta', (object) []), ]; validator($data, [ 'publish_date' => 'required|date', 'author_id' => 'required', 'title' => 'required', 'slug' => 'required|'.Rule::unique(config('wink.database_connection').'.wink_posts', 'slug')->ignore(request('id')), ])->validate(); $entry = $id !== 'new' ? WinkPost::findOrFail($id) : new WinkPost(['id' => request('id')]); $entry->fill($data); $entry->save(); $entry->tags()->sync( $this->collectTags(request('tags')) ); return response()->json([ 'entry' => $entry, ]); }
[ "public", "function", "store", "(", "$", "id", ")", "{", "$", "data", "=", "[", "'title'", "=>", "request", "(", "'title'", ")", ",", "'excerpt'", "=>", "request", "(", "'excerpt'", ",", "''", ")", ",", "'slug'", "=>", "request", "(", "'slug'", ")", ",", "'body'", "=>", "request", "(", "'body'", ",", "''", ")", ",", "'published'", "=>", "request", "(", "'published'", ")", ",", "'author_id'", "=>", "request", "(", "'author_id'", ")", ",", "'featured_image'", "=>", "request", "(", "'featured_image'", ")", ",", "'featured_image_caption'", "=>", "request", "(", "'featured_image_caption'", ",", "''", ")", ",", "'publish_date'", "=>", "request", "(", "'publish_date'", ",", "''", ")", ",", "'meta'", "=>", "request", "(", "'meta'", ",", "(", "object", ")", "[", "]", ")", ",", "]", ";", "validator", "(", "$", "data", ",", "[", "'publish_date'", "=>", "'required|date'", ",", "'author_id'", "=>", "'required'", ",", "'title'", "=>", "'required'", ",", "'slug'", "=>", "'required|'", ".", "Rule", "::", "unique", "(", "config", "(", "'wink.database_connection'", ")", ".", "'.wink_posts'", ",", "'slug'", ")", "->", "ignore", "(", "request", "(", "'id'", ")", ")", ",", "]", ")", "->", "validate", "(", ")", ";", "$", "entry", "=", "$", "id", "!==", "'new'", "?", "WinkPost", "::", "findOrFail", "(", "$", "id", ")", ":", "new", "WinkPost", "(", "[", "'id'", "=>", "request", "(", "'id'", ")", "]", ")", ";", "$", "entry", "->", "fill", "(", "$", "data", ")", ";", "$", "entry", "->", "save", "(", ")", ";", "$", "entry", "->", "tags", "(", ")", "->", "sync", "(", "$", "this", "->", "collectTags", "(", "request", "(", "'tags'", ")", ")", ")", ";", "return", "response", "(", ")", "->", "json", "(", "[", "'entry'", "=>", "$", "entry", ",", "]", ")", ";", "}" ]
Store a single post. @param string $id @return \Illuminate\Http\JsonResponse
[ "Store", "a", "single", "post", "." ]
b477213dc017779476e1f1bee3ed683324841f68
https://github.com/writingink/wink/blob/b477213dc017779476e1f1bee3ed683324841f68/src/Http/Controllers/PostsController.php#L65-L100
train
writingink/wink
src/Http/Controllers/PostsController.php
PostsController.collectTags
private function collectTags($incomingTags) { $allTags = WinkTag::all(); return collect($incomingTags)->map(function ($incomingTag) use ($allTags) { $tag = $allTags->where('slug', Str::slug($incomingTag['name']))->first(); if (! $tag) { $tag = WinkTag::create([ 'id' => $id = Str::uuid(), 'name' => $incomingTag['name'], 'slug' => Str::slug($incomingTag['name']), ]); } return (string) $tag->id; })->toArray(); }
php
private function collectTags($incomingTags) { $allTags = WinkTag::all(); return collect($incomingTags)->map(function ($incomingTag) use ($allTags) { $tag = $allTags->where('slug', Str::slug($incomingTag['name']))->first(); if (! $tag) { $tag = WinkTag::create([ 'id' => $id = Str::uuid(), 'name' => $incomingTag['name'], 'slug' => Str::slug($incomingTag['name']), ]); } return (string) $tag->id; })->toArray(); }
[ "private", "function", "collectTags", "(", "$", "incomingTags", ")", "{", "$", "allTags", "=", "WinkTag", "::", "all", "(", ")", ";", "return", "collect", "(", "$", "incomingTags", ")", "->", "map", "(", "function", "(", "$", "incomingTag", ")", "use", "(", "$", "allTags", ")", "{", "$", "tag", "=", "$", "allTags", "->", "where", "(", "'slug'", ",", "Str", "::", "slug", "(", "$", "incomingTag", "[", "'name'", "]", ")", ")", "->", "first", "(", ")", ";", "if", "(", "!", "$", "tag", ")", "{", "$", "tag", "=", "WinkTag", "::", "create", "(", "[", "'id'", "=>", "$", "id", "=", "Str", "::", "uuid", "(", ")", ",", "'name'", "=>", "$", "incomingTag", "[", "'name'", "]", ",", "'slug'", "=>", "Str", "::", "slug", "(", "$", "incomingTag", "[", "'name'", "]", ")", ",", "]", ")", ";", "}", "return", "(", "string", ")", "$", "tag", "->", "id", ";", "}", ")", "->", "toArray", "(", ")", ";", "}" ]
Tags incoming from the request. @param array $incomingTags @return array
[ "Tags", "incoming", "from", "the", "request", "." ]
b477213dc017779476e1f1bee3ed683324841f68
https://github.com/writingink/wink/blob/b477213dc017779476e1f1bee3ed683324841f68/src/Http/Controllers/PostsController.php#L108-L125
train
writingink/wink
src/Http/Controllers/TeamController.php
TeamController.delete
public function delete($id) { $entry = WinkAuthor::findOrFail($id); if ($entry->posts()->count()) { return response()->json(['message' => 'Please remove the author\'s posts first.'], 402); } if ($entry->id == auth('wink')->user()->id) { return response()->json(['message' => 'You cannot delete yourself.'], 402); } $entry->delete(); }
php
public function delete($id) { $entry = WinkAuthor::findOrFail($id); if ($entry->posts()->count()) { return response()->json(['message' => 'Please remove the author\'s posts first.'], 402); } if ($entry->id == auth('wink')->user()->id) { return response()->json(['message' => 'You cannot delete yourself.'], 402); } $entry->delete(); }
[ "public", "function", "delete", "(", "$", "id", ")", "{", "$", "entry", "=", "WinkAuthor", "::", "findOrFail", "(", "$", "id", ")", ";", "if", "(", "$", "entry", "->", "posts", "(", ")", "->", "count", "(", ")", ")", "{", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'Please remove the author\\'s posts first.'", "]", ",", "402", ")", ";", "}", "if", "(", "$", "entry", "->", "id", "==", "auth", "(", "'wink'", ")", "->", "user", "(", ")", "->", "id", ")", "{", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'You cannot delete yourself.'", "]", ",", "402", ")", ";", "}", "$", "entry", "->", "delete", "(", ")", ";", "}" ]
Return a single author. @param string $id @return \Illuminate\Http\JsonResponse|null
[ "Return", "a", "single", "author", "." ]
b477213dc017779476e1f1bee3ed683324841f68
https://github.com/writingink/wink/blob/b477213dc017779476e1f1bee3ed683324841f68/src/Http/Controllers/TeamController.php#L104-L117
train
writingink/wink
src/WinkServiceProvider.php
WinkServiceProvider.registerRoutes
private function registerRoutes() { $path = config('wink.path'); $middlewareGroup = config('wink.middleware_group'); Route::namespace('Wink\Http\Controllers') ->middleware($middlewareGroup) ->as('wink.') ->prefix($path) ->group(function () { Route::get('/login', 'LoginController@showLoginForm')->name('auth.login'); Route::post('/login', 'LoginController@login')->name('auth.attempt'); Route::get('/password/forgot', 'ForgotPasswordController@showResetRequestForm')->name('password.forgot'); Route::post('/password/forgot', 'ForgotPasswordController@sendResetLinkEmail')->name('password.email'); Route::get('/password/reset/{token}', 'ForgotPasswordController@showNewPassword')->name('password.reset'); }); Route::namespace('Wink\Http\Controllers') ->middleware([$middlewareGroup, Authenticate::class]) ->as('wink.') ->prefix($path) ->group(function () { $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); }); }
php
private function registerRoutes() { $path = config('wink.path'); $middlewareGroup = config('wink.middleware_group'); Route::namespace('Wink\Http\Controllers') ->middleware($middlewareGroup) ->as('wink.') ->prefix($path) ->group(function () { Route::get('/login', 'LoginController@showLoginForm')->name('auth.login'); Route::post('/login', 'LoginController@login')->name('auth.attempt'); Route::get('/password/forgot', 'ForgotPasswordController@showResetRequestForm')->name('password.forgot'); Route::post('/password/forgot', 'ForgotPasswordController@sendResetLinkEmail')->name('password.email'); Route::get('/password/reset/{token}', 'ForgotPasswordController@showNewPassword')->name('password.reset'); }); Route::namespace('Wink\Http\Controllers') ->middleware([$middlewareGroup, Authenticate::class]) ->as('wink.') ->prefix($path) ->group(function () { $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); }); }
[ "private", "function", "registerRoutes", "(", ")", "{", "$", "path", "=", "config", "(", "'wink.path'", ")", ";", "$", "middlewareGroup", "=", "config", "(", "'wink.middleware_group'", ")", ";", "Route", "::", "namespace", "(", "'Wink\\Http\\Controllers'", ")", "->", "middleware", "(", "$", "middlewareGroup", ")", "->", "as", "(", "'wink.'", ")", "->", "prefix", "(", "$", "path", ")", "->", "group", "(", "function", "(", ")", "{", "Route", "::", "get", "(", "'/login'", ",", "'LoginController@showLoginForm'", ")", "->", "name", "(", "'auth.login'", ")", ";", "Route", "::", "post", "(", "'/login'", ",", "'LoginController@login'", ")", "->", "name", "(", "'auth.attempt'", ")", ";", "Route", "::", "get", "(", "'/password/forgot'", ",", "'ForgotPasswordController@showResetRequestForm'", ")", "->", "name", "(", "'password.forgot'", ")", ";", "Route", "::", "post", "(", "'/password/forgot'", ",", "'ForgotPasswordController@sendResetLinkEmail'", ")", "->", "name", "(", "'password.email'", ")", ";", "Route", "::", "get", "(", "'/password/reset/{token}'", ",", "'ForgotPasswordController@showNewPassword'", ")", "->", "name", "(", "'password.reset'", ")", ";", "}", ")", ";", "Route", "::", "namespace", "(", "'Wink\\Http\\Controllers'", ")", "->", "middleware", "(", "[", "$", "middlewareGroup", ",", "Authenticate", "::", "class", "]", ")", "->", "as", "(", "'wink.'", ")", "->", "prefix", "(", "$", "path", ")", "->", "group", "(", "function", "(", ")", "{", "$", "this", "->", "loadRoutesFrom", "(", "__DIR__", ".", "'/Http/routes.php'", ")", ";", "}", ")", ";", "}" ]
Register the package routes. @return void
[ "Register", "the", "package", "routes", "." ]
b477213dc017779476e1f1bee3ed683324841f68
https://github.com/writingink/wink/blob/b477213dc017779476e1f1bee3ed683324841f68/src/WinkServiceProvider.php#L32-L57
train
writingink/wink
src/Http/Controllers/ForgotPasswordController.php
ForgotPasswordController.sendResetLinkEmail
public function sendResetLinkEmail() { validator(request()->all(), [ 'email' => 'required|email', ])->validate(); if ($author = WinkAuthor::whereEmail(request('email'))->first()) { cache(['password.reset.'.$author->id => $token = Str::random()], now()->addMinutes(30) ); Mail::to($author->email)->send(new ResetPasswordEmail( encrypt($author->id.'|'.$token) )); } return redirect()->route('wink.password.forgot')->with('sent', true); }
php
public function sendResetLinkEmail() { validator(request()->all(), [ 'email' => 'required|email', ])->validate(); if ($author = WinkAuthor::whereEmail(request('email'))->first()) { cache(['password.reset.'.$author->id => $token = Str::random()], now()->addMinutes(30) ); Mail::to($author->email)->send(new ResetPasswordEmail( encrypt($author->id.'|'.$token) )); } return redirect()->route('wink.password.forgot')->with('sent', true); }
[ "public", "function", "sendResetLinkEmail", "(", ")", "{", "validator", "(", "request", "(", ")", "->", "all", "(", ")", ",", "[", "'email'", "=>", "'required|email'", ",", "]", ")", "->", "validate", "(", ")", ";", "if", "(", "$", "author", "=", "WinkAuthor", "::", "whereEmail", "(", "request", "(", "'email'", ")", ")", "->", "first", "(", ")", ")", "{", "cache", "(", "[", "'password.reset.'", ".", "$", "author", "->", "id", "=>", "$", "token", "=", "Str", "::", "random", "(", ")", "]", ",", "now", "(", ")", "->", "addMinutes", "(", "30", ")", ")", ";", "Mail", "::", "to", "(", "$", "author", "->", "email", ")", "->", "send", "(", "new", "ResetPasswordEmail", "(", "encrypt", "(", "$", "author", "->", "id", ".", "'|'", ".", "$", "token", ")", ")", ")", ";", "}", "return", "redirect", "(", ")", "->", "route", "(", "'wink.password.forgot'", ")", "->", "with", "(", "'sent'", ",", "true", ")", ";", "}" ]
Send password reset email. @return \Illuminate\Http\Response
[ "Send", "password", "reset", "email", "." ]
b477213dc017779476e1f1bee3ed683324841f68
https://github.com/writingink/wink/blob/b477213dc017779476e1f1bee3ed683324841f68/src/Http/Controllers/ForgotPasswordController.php#L29-L46
train
writingink/wink
src/Http/Controllers/ForgotPasswordController.php
ForgotPasswordController.showNewPassword
public function showNewPassword($token) { try { $token = decrypt($token); [$authorId, $token] = explode('|', $token); $author = WinkAuthor::findOrFail($authorId); } catch (Throwable $e) { return redirect()->route('wink.password.forgot')->with('invalidResetToken', true); } if (cache('password.reset.'.$authorId) != $token) { return redirect()->route('wink.password.forgot')->with('invalidResetToken', true); } cache()->forget('password.reset.'.$authorId); $author->password = \Hash::make($password = Str::random()); $author->save(); return view('wink::reset-password', [ 'password' => $password, ]); }
php
public function showNewPassword($token) { try { $token = decrypt($token); [$authorId, $token] = explode('|', $token); $author = WinkAuthor::findOrFail($authorId); } catch (Throwable $e) { return redirect()->route('wink.password.forgot')->with('invalidResetToken', true); } if (cache('password.reset.'.$authorId) != $token) { return redirect()->route('wink.password.forgot')->with('invalidResetToken', true); } cache()->forget('password.reset.'.$authorId); $author->password = \Hash::make($password = Str::random()); $author->save(); return view('wink::reset-password', [ 'password' => $password, ]); }
[ "public", "function", "showNewPassword", "(", "$", "token", ")", "{", "try", "{", "$", "token", "=", "decrypt", "(", "$", "token", ")", ";", "[", "$", "authorId", ",", "$", "token", "]", "=", "explode", "(", "'|'", ",", "$", "token", ")", ";", "$", "author", "=", "WinkAuthor", "::", "findOrFail", "(", "$", "authorId", ")", ";", "}", "catch", "(", "Throwable", "$", "e", ")", "{", "return", "redirect", "(", ")", "->", "route", "(", "'wink.password.forgot'", ")", "->", "with", "(", "'invalidResetToken'", ",", "true", ")", ";", "}", "if", "(", "cache", "(", "'password.reset.'", ".", "$", "authorId", ")", "!=", "$", "token", ")", "{", "return", "redirect", "(", ")", "->", "route", "(", "'wink.password.forgot'", ")", "->", "with", "(", "'invalidResetToken'", ",", "true", ")", ";", "}", "cache", "(", ")", "->", "forget", "(", "'password.reset.'", ".", "$", "authorId", ")", ";", "$", "author", "->", "password", "=", "\\", "Hash", "::", "make", "(", "$", "password", "=", "Str", "::", "random", "(", ")", ")", ";", "$", "author", "->", "save", "(", ")", ";", "return", "view", "(", "'wink::reset-password'", ",", "[", "'password'", "=>", "$", "password", ",", "]", ")", ";", "}" ]
Show the new password to the user. @param string $token @return \Illuminate\Http\Response
[ "Show", "the", "new", "password", "to", "the", "user", "." ]
b477213dc017779476e1f1bee3ed683324841f68
https://github.com/writingink/wink/blob/b477213dc017779476e1f1bee3ed683324841f68/src/Http/Controllers/ForgotPasswordController.php#L54-L79
train
writingink/wink
src/Http/Controllers/PagesController.php
PagesController.index
public function index() { $entries = WinkPage::when(request()->has('search'), function ($q) { $q->where('title', 'LIKE', '%'.request('search').'%'); }) ->orderBy('created_at', 'DESC') ->paginate(30); return PagesResource::collection($entries); }
php
public function index() { $entries = WinkPage::when(request()->has('search'), function ($q) { $q->where('title', 'LIKE', '%'.request('search').'%'); }) ->orderBy('created_at', 'DESC') ->paginate(30); return PagesResource::collection($entries); }
[ "public", "function", "index", "(", ")", "{", "$", "entries", "=", "WinkPage", "::", "when", "(", "request", "(", ")", "->", "has", "(", "'search'", ")", ",", "function", "(", "$", "q", ")", "{", "$", "q", "->", "where", "(", "'title'", ",", "'LIKE'", ",", "'%'", ".", "request", "(", "'search'", ")", ".", "'%'", ")", ";", "}", ")", "->", "orderBy", "(", "'created_at'", ",", "'DESC'", ")", "->", "paginate", "(", "30", ")", ";", "return", "PagesResource", "::", "collection", "(", "$", "entries", ")", ";", "}" ]
Return pages. @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
[ "Return", "pages", "." ]
b477213dc017779476e1f1bee3ed683324841f68
https://github.com/writingink/wink/blob/b477213dc017779476e1f1bee3ed683324841f68/src/Http/Controllers/PagesController.php#L17-L26
train
dingo/api
src/Http/Response.php
Response.makeFromExisting
public static function makeFromExisting(IlluminateResponse $old) { $new = static::create($old->getOriginalContent(), $old->getStatusCode()); $new->headers = $old->headers; return $new; }
php
public static function makeFromExisting(IlluminateResponse $old) { $new = static::create($old->getOriginalContent(), $old->getStatusCode()); $new->headers = $old->headers; return $new; }
[ "public", "static", "function", "makeFromExisting", "(", "IlluminateResponse", "$", "old", ")", "{", "$", "new", "=", "static", "::", "create", "(", "$", "old", "->", "getOriginalContent", "(", ")", ",", "$", "old", "->", "getStatusCode", "(", ")", ")", ";", "$", "new", "->", "headers", "=", "$", "old", "->", "headers", ";", "return", "$", "new", ";", "}" ]
Make an API response from an existing Illuminate response. @param \Illuminate\Http\Response $old @return \Dingo\Api\Http\Response
[ "Make", "an", "API", "response", "from", "an", "existing", "Illuminate", "response", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Http/Response.php#L87-L94
train
dingo/api
src/Http/Response.php
Response.withHeader
public function withHeader($key, $value, $replace = true) { return $this->header($key, $value, $replace); }
php
public function withHeader($key, $value, $replace = true) { return $this->header($key, $value, $replace); }
[ "public", "function", "withHeader", "(", "$", "key", ",", "$", "value", ",", "$", "replace", "=", "true", ")", "{", "return", "$", "this", "->", "header", "(", "$", "key", ",", "$", "value", ",", "$", "replace", ")", ";", "}" ]
Add a header to the response. @param string $key @param string $value @param bool $replace @return \Dingo\Api\Http\Response
[ "Add", "a", "header", "to", "the", "response", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Http/Response.php#L409-L412
train
dingo/api
src/Http/Request.php
Request.createFromIlluminate
public function createFromIlluminate(IlluminateRequest $old) { $new = new static( $old->query->all(), $old->request->all(), $old->attributes->all(), $old->cookies->all(), $old->files->all(), $old->server->all(), $old->content ); if ($session = $old->getSession()) { $new->setLaravelSession($old->getSession()); } $new->setRouteResolver($old->getRouteResolver()); $new->setUserResolver($old->getUserResolver()); return $new; }
php
public function createFromIlluminate(IlluminateRequest $old) { $new = new static( $old->query->all(), $old->request->all(), $old->attributes->all(), $old->cookies->all(), $old->files->all(), $old->server->all(), $old->content ); if ($session = $old->getSession()) { $new->setLaravelSession($old->getSession()); } $new->setRouteResolver($old->getRouteResolver()); $new->setUserResolver($old->getUserResolver()); return $new; }
[ "public", "function", "createFromIlluminate", "(", "IlluminateRequest", "$", "old", ")", "{", "$", "new", "=", "new", "static", "(", "$", "old", "->", "query", "->", "all", "(", ")", ",", "$", "old", "->", "request", "->", "all", "(", ")", ",", "$", "old", "->", "attributes", "->", "all", "(", ")", ",", "$", "old", "->", "cookies", "->", "all", "(", ")", ",", "$", "old", "->", "files", "->", "all", "(", ")", ",", "$", "old", "->", "server", "->", "all", "(", ")", ",", "$", "old", "->", "content", ")", ";", "if", "(", "$", "session", "=", "$", "old", "->", "getSession", "(", ")", ")", "{", "$", "new", "->", "setLaravelSession", "(", "$", "old", "->", "getSession", "(", ")", ")", ";", "}", "$", "new", "->", "setRouteResolver", "(", "$", "old", "->", "getRouteResolver", "(", ")", ")", ";", "$", "new", "->", "setUserResolver", "(", "$", "old", "->", "getUserResolver", "(", ")", ")", ";", "return", "$", "new", ";", "}" ]
Create a new Dingo request instance from an Illuminate request instance. @param \Illuminate\Http\Request $old @return \Dingo\Api\Http\Request
[ "Create", "a", "new", "Dingo", "request", "instance", "from", "an", "Illuminate", "request", "instance", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Http/Request.php#L32-L47
train
dingo/api
src/Routing/Adapter/Laravel.php
Laravel.getRoutes
public function getRoutes($version = null) { if (! is_null($version)) { return $this->routes[$version]; } return $this->routes; }
php
public function getRoutes($version = null) { if (! is_null($version)) { return $this->routes[$version]; } return $this->routes; }
[ "public", "function", "getRoutes", "(", "$", "version", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "version", ")", ")", "{", "return", "$", "this", "->", "routes", "[", "$", "version", "]", ";", "}", "return", "$", "this", "->", "routes", ";", "}" ]
Get all routes or only for a specific version. @param string $version @return mixed
[ "Get", "all", "routes", "or", "only", "for", "a", "specific", "version", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Routing/Adapter/Laravel.php#L183-L190
train
dingo/api
src/Routing/Adapter/Laravel.php
Laravel.gatherRouteMiddlewares
public function gatherRouteMiddlewares($route) { if (method_exists($this->router, 'gatherRouteMiddleware')) { return $this->router->gatherRouteMiddleware($route); } return $this->router->gatherRouteMiddlewares($route); }
php
public function gatherRouteMiddlewares($route) { if (method_exists($this->router, 'gatherRouteMiddleware')) { return $this->router->gatherRouteMiddleware($route); } return $this->router->gatherRouteMiddlewares($route); }
[ "public", "function", "gatherRouteMiddlewares", "(", "$", "route", ")", "{", "if", "(", "method_exists", "(", "$", "this", "->", "router", ",", "'gatherRouteMiddleware'", ")", ")", "{", "return", "$", "this", "->", "router", "->", "gatherRouteMiddleware", "(", "$", "route", ")", ";", "}", "return", "$", "this", "->", "router", "->", "gatherRouteMiddlewares", "(", "$", "route", ")", ";", "}" ]
Gather the route middlewares. @param \Illuminate\Routing\Route $route @return array
[ "Gather", "the", "route", "middlewares", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Routing/Adapter/Laravel.php#L237-L244
train
dingo/api
src/Transformer/Adapter/Fractal.php
Fractal.shouldEagerLoad
protected function shouldEagerLoad($response) { if ($response instanceof IlluminatePaginator) { $response = $response->getCollection(); } return $response instanceof EloquentCollection && $this->eagerLoading; }
php
protected function shouldEagerLoad($response) { if ($response instanceof IlluminatePaginator) { $response = $response->getCollection(); } return $response instanceof EloquentCollection && $this->eagerLoading; }
[ "protected", "function", "shouldEagerLoad", "(", "$", "response", ")", "{", "if", "(", "$", "response", "instanceof", "IlluminatePaginator", ")", "{", "$", "response", "=", "$", "response", "->", "getCollection", "(", ")", ";", "}", "return", "$", "response", "instanceof", "EloquentCollection", "&&", "$", "this", "->", "eagerLoading", ";", "}" ]
Eager loading is only performed when the response is or contains an Eloquent collection and eager loading is enabled. @param mixed $response @return bool
[ "Eager", "loading", "is", "only", "performed", "when", "the", "response", "is", "or", "contains", "an", "Eloquent", "collection", "and", "eager", "loading", "is", "enabled", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Transformer/Adapter/Fractal.php#L120-L127
train
dingo/api
src/Transformer/Adapter/Fractal.php
Fractal.parseFractalIncludes
public function parseFractalIncludes(Request $request) { $includes = $request->input($this->includeKey); if (! is_array($includes)) { $includes = array_map('trim', array_filter(explode($this->includeSeparator, $includes))); } $this->fractal->parseIncludes($includes); }
php
public function parseFractalIncludes(Request $request) { $includes = $request->input($this->includeKey); if (! is_array($includes)) { $includes = array_map('trim', array_filter(explode($this->includeSeparator, $includes))); } $this->fractal->parseIncludes($includes); }
[ "public", "function", "parseFractalIncludes", "(", "Request", "$", "request", ")", "{", "$", "includes", "=", "$", "request", "->", "input", "(", "$", "this", "->", "includeKey", ")", ";", "if", "(", "!", "is_array", "(", "$", "includes", ")", ")", "{", "$", "includes", "=", "array_map", "(", "'trim'", ",", "array_filter", "(", "explode", "(", "$", "this", "->", "includeSeparator", ",", "$", "includes", ")", ")", ")", ";", "}", "$", "this", "->", "fractal", "->", "parseIncludes", "(", "$", "includes", ")", ";", "}" ]
Parse the includes. @param \Dingo\Api\Http\Request $request @return void
[ "Parse", "the", "includes", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Transformer/Adapter/Fractal.php#L168-L177
train
dingo/api
src/Transformer/Adapter/Fractal.php
Fractal.mergeEagerLoads
protected function mergeEagerLoads($transformer, $requestedIncludes) { $includes = array_merge($requestedIncludes, $transformer->getDefaultIncludes()); $eagerLoads = []; foreach ($includes as $key => $value) { $eagerLoads[] = is_string($key) ? $key : $value; } if (property_exists($transformer, 'lazyLoadedIncludes')) { $eagerLoads = array_diff($eagerLoads, $transformer->lazyLoadedIncludes); } return $eagerLoads; }
php
protected function mergeEagerLoads($transformer, $requestedIncludes) { $includes = array_merge($requestedIncludes, $transformer->getDefaultIncludes()); $eagerLoads = []; foreach ($includes as $key => $value) { $eagerLoads[] = is_string($key) ? $key : $value; } if (property_exists($transformer, 'lazyLoadedIncludes')) { $eagerLoads = array_diff($eagerLoads, $transformer->lazyLoadedIncludes); } return $eagerLoads; }
[ "protected", "function", "mergeEagerLoads", "(", "$", "transformer", ",", "$", "requestedIncludes", ")", "{", "$", "includes", "=", "array_merge", "(", "$", "requestedIncludes", ",", "$", "transformer", "->", "getDefaultIncludes", "(", ")", ")", ";", "$", "eagerLoads", "=", "[", "]", ";", "foreach", "(", "$", "includes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "eagerLoads", "[", "]", "=", "is_string", "(", "$", "key", ")", "?", "$", "key", ":", "$", "value", ";", "}", "if", "(", "property_exists", "(", "$", "transformer", ",", "'lazyLoadedIncludes'", ")", ")", "{", "$", "eagerLoads", "=", "array_diff", "(", "$", "eagerLoads", ",", "$", "transformer", "->", "lazyLoadedIncludes", ")", ";", "}", "return", "$", "eagerLoads", ";", "}" ]
Get includes as their array keys for eager loading. @param \League\Fractal\TransformerAbstract $transformer @param string|array $requestedIncludes @return array
[ "Get", "includes", "as", "their", "array", "keys", "for", "eager", "loading", "." ]
8f97fadae800202e618e0c3f678b4aab78e1dc05
https://github.com/dingo/api/blob/8f97fadae800202e618e0c3f678b4aab78e1dc05/src/Transformer/Adapter/Fractal.php#L197-L212
train