repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
amphp/http-server
src/Server.php
Server.attach
public function attach(ServerObserver $observer) { if ($this->state) { throw new \Error("Cannot attach observers after the server has started"); } $this->observers->attach($observer); }
php
public function attach(ServerObserver $observer) { if ($this->state) { throw new \Error("Cannot attach observers after the server has started"); } $this->observers->attach($observer); }
[ "public", "function", "attach", "(", "ServerObserver", "$", "observer", ")", "{", "if", "(", "$", "this", "->", "state", ")", "{", "throw", "new", "\\", "Error", "(", "\"Cannot attach observers after the server has started\"", ")", ";", "}", "$", "this", "->",...
Attach an observer. @param ServerObserver $observer @throws \Error If the server has started.
[ "Attach", "an", "observer", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Server.php#L248-L255
amphp/http-server
src/Server.php
Server.start
public function start(): Promise { try { if ($this->state === self::STOPPED) { return new Coroutine($this->doStart()); } return new Failure(new \Error( "Cannot start server: already " . self::STATES[$this->state] )); } ...
php
public function start(): Promise { try { if ($this->state === self::STOPPED) { return new Coroutine($this->doStart()); } return new Failure(new \Error( "Cannot start server: already " . self::STATES[$this->state] )); } ...
[ "public", "function", "start", "(", ")", ":", "Promise", "{", "try", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STOPPED", ")", "{", "return", "new", "Coroutine", "(", "$", "this", "->", "doStart", "(", ")", ")", ";", "}", "...
Start the server. @return \Amp\Promise
[ "Start", "the", "server", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Server.php#L262-L275
amphp/http-server
src/Server.php
Server.stop
public function stop(int $timeout = self::DEFAULT_SHUTDOWN_TIMEOUT): Promise { switch ($this->state) { case self::STARTED: return new Coroutine($this->doStop($timeout)); case self::STOPPED: return new Success; default: retur...
php
public function stop(int $timeout = self::DEFAULT_SHUTDOWN_TIMEOUT): Promise { switch ($this->state) { case self::STARTED: return new Coroutine($this->doStop($timeout)); case self::STOPPED: return new Success; default: retur...
[ "public", "function", "stop", "(", "int", "$", "timeout", "=", "self", "::", "DEFAULT_SHUTDOWN_TIMEOUT", ")", ":", "Promise", "{", "switch", "(", "$", "this", "->", "state", ")", "{", "case", "self", "::", "STARTED", ":", "return", "new", "Coroutine", "(...
Stop the server. @param int $timeout Number of milliseconds to allow clients to gracefully shutdown before forcefully closing. @return Promise
[ "Stop", "the", "server", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Server.php#L414-L426
amphp/http-server
src/Middleware/Internal/MiddlewareRequestHandler.php
MiddlewareRequestHandler.handleRequest
public function handleRequest(Request $request): Promise { return $this->middleware->handleRequest($request, $this->next); }
php
public function handleRequest(Request $request): Promise { return $this->middleware->handleRequest($request, $this->next); }
[ "public", "function", "handleRequest", "(", "Request", "$", "request", ")", ":", "Promise", "{", "return", "$", "this", "->", "middleware", "->", "handleRequest", "(", "$", "request", ",", "$", "this", "->", "next", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Middleware/Internal/MiddlewareRequestHandler.php#L33-L36
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.start
public function start(HttpDriverFactory $driverFactory) { if ($this->readWatcher) { throw new \Error("Client already started"); } $this->timeoutCache->renew($this->id); $this->writeWatcher = Loop::onWritable($this->socket, $this->callableFromInstanceMethod("onWritable")...
php
public function start(HttpDriverFactory $driverFactory) { if ($this->readWatcher) { throw new \Error("Client already started"); } $this->timeoutCache->renew($this->id); $this->writeWatcher = Loop::onWritable($this->socket, $this->callableFromInstanceMethod("onWritable")...
[ "public", "function", "start", "(", "HttpDriverFactory", "$", "driverFactory", ")", "{", "if", "(", "$", "this", "->", "readWatcher", ")", "{", "throw", "new", "\\", "Error", "(", "\"Client already started\"", ")", ";", "}", "$", "this", "->", "timeoutCache"...
Listen for requests on the client and parse them using the given HTTP driver. @param \Amp\Http\Server\Driver\HttpDriverFactory $driverFactory @throws \Error If the client has already been started.
[ "Listen", "for", "requests", "on", "the", "client", "and", "parse", "them", "using", "the", "given", "HTTP", "driver", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L168-L192
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.onReadable
private function onReadable() { $data = @\stream_get_contents($this->socket, $this->options->getChunkSize()); if ($data !== false && $data !== "") { $this->timeoutCache->renew($this->id); $this->parse($data); return; } if (!\is_resource($this->soc...
php
private function onReadable() { $data = @\stream_get_contents($this->socket, $this->options->getChunkSize()); if ($data !== false && $data !== "") { $this->timeoutCache->renew($this->id); $this->parse($data); return; } if (!\is_resource($this->soc...
[ "private", "function", "onReadable", "(", ")", "{", "$", "data", "=", "@", "\\", "stream_get_contents", "(", "$", "this", "->", "socket", ",", "$", "this", "->", "options", "->", "getChunkSize", "(", ")", ")", ";", "if", "(", "$", "data", "!==", "fal...
Called by the onReadable watcher (after encryption has been negotiated if applicable).
[ "Called", "by", "the", "onReadable", "watcher", "(", "after", "encryption", "has", "been", "negotiated", "if", "applicable", ")", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L375-L387
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.parse
private function parse(string $data = "") { try { $promise = $this->requestParser->send($data); if ($promise instanceof Promise && !$this->isExported && !($this->status & self::CLOSED_RDWR)) { // Parser wants to wait until a promise completes. $this->...
php
private function parse(string $data = "") { try { $promise = $this->requestParser->send($data); if ($promise instanceof Promise && !$this->isExported && !($this->status & self::CLOSED_RDWR)) { // Parser wants to wait until a promise completes. $this->...
[ "private", "function", "parse", "(", "string", "$", "data", "=", "\"\"", ")", "{", "try", "{", "$", "promise", "=", "$", "this", "->", "requestParser", "->", "send", "(", "$", "data", ")", ";", "if", "(", "$", "promise", "instanceof", "Promise", "&&"...
Sends data to the request parser. @param string $data
[ "Sends", "data", "to", "the", "request", "parser", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L394-L412
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.negotiateCrypto
private function negotiateCrypto(string $watcher, $socket, HttpDriverFactory $driverFactory) { if ($handshake = @\stream_socket_enable_crypto($this->socket, true)) { Loop::cancel($this->readWatcher); $this->isEncrypted = true; $this->cryptoInfo = \stream_get_meta_data($t...
php
private function negotiateCrypto(string $watcher, $socket, HttpDriverFactory $driverFactory) { if ($handshake = @\stream_socket_enable_crypto($this->socket, true)) { Loop::cancel($this->readWatcher); $this->isEncrypted = true; $this->cryptoInfo = \stream_get_meta_data($t...
[ "private", "function", "negotiateCrypto", "(", "string", "$", "watcher", ",", "$", "socket", ",", "HttpDriverFactory", "$", "driverFactory", ")", "{", "if", "(", "$", "handshake", "=", "@", "\\", "stream_socket_enable_crypto", "(", "$", "this", "->", "socket",...
Called by the onReadable watcher after the client connects until encryption is enabled. @param string $watcher @param resource $socket @param \Amp\Http\Server\Driver\HttpDriverFactory $driverFactory
[ "Called", "by", "the", "onReadable", "watcher", "after", "the", "client", "connects", "until", "encryption", "is", "enabled", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L421-L446
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.onWritable
private function onWritable() { $bytesWritten = @\fwrite($this->socket, $this->writeBuffer); if ($bytesWritten === false) { $this->close(); return; } if ($bytesWritten === 0) { return; } $this->timeoutCache->renew($this->id); ...
php
private function onWritable() { $bytesWritten = @\fwrite($this->socket, $this->writeBuffer); if ($bytesWritten === false) { $this->close(); return; } if ($bytesWritten === 0) { return; } $this->timeoutCache->renew($this->id); ...
[ "private", "function", "onWritable", "(", ")", "{", "$", "bytesWritten", "=", "@", "\\", "fwrite", "(", "$", "this", "->", "socket", ",", "$", "this", "->", "writeBuffer", ")", ";", "if", "(", "$", "bytesWritten", "===", "false", ")", "{", "$", "this...
Called by the onWritable watcher.
[ "Called", "by", "the", "onWritable", "watcher", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L451-L477
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.write
private function write(string $data, bool $close = false): Promise { if ($this->status & self::CLOSED_WR) { return new Failure(new ClientException("The client disconnected")); } if (!$this->writeDeferred) { $bytesWritten = @\fwrite($this->socket, $data); ...
php
private function write(string $data, bool $close = false): Promise { if ($this->status & self::CLOSED_WR) { return new Failure(new ClientException("The client disconnected")); } if (!$this->writeDeferred) { $bytesWritten = @\fwrite($this->socket, $data); ...
[ "private", "function", "write", "(", "string", "$", "data", ",", "bool", "$", "close", "=", "false", ")", ":", "Promise", "{", "if", "(", "$", "this", "->", "status", "&", "self", "::", "CLOSED_WR", ")", "{", "return", "new", "Failure", "(", "new", ...
Adds the given data to the buffer of data to be written to the client socket. Returns a promise that resolves once the client write buffer has emptied. @param string $data The data to write. @param bool $close If true, close the client after the given chunk of data has been written. @return \Amp\Promise
[ "Adds", "the", "given", "data", "to", "the", "buffer", "of", "data", "to", "be", "written", "to", "the", "client", "socket", ".", "Returns", "a", "promise", "that", "resolves", "once", "the", "client", "write", "buffer", "has", "emptied", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L488-L531
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.onMessage
private function onMessage(Request $request, string $buffer = ''): Promise { \assert($this->logger->debug(\sprintf( "%s %s HTTP/%s @ %s:%s", $request->getMethod(), $request->getUri(), $request->getProtocolVersion(), $this->clientAddress, ...
php
private function onMessage(Request $request, string $buffer = ''): Promise { \assert($this->logger->debug(\sprintf( "%s %s HTTP/%s @ %s:%s", $request->getMethod(), $request->getUri(), $request->getProtocolVersion(), $this->clientAddress, ...
[ "private", "function", "onMessage", "(", "Request", "$", "request", ",", "string", "$", "buffer", "=", "''", ")", ":", "Promise", "{", "\\", "assert", "(", "$", "this", "->", "logger", "->", "debug", "(", "\\", "sprintf", "(", "\"%s %s HTTP/%s @ %s:%s\"", ...
Invoked by the HTTP parser when a request is parsed. @param Request $request @param string $buffer Remaining buffer in the parser. @return \Amp\Promise
[ "Invoked", "by", "the", "HTTP", "parser", "when", "a", "request", "is", "parsed", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L541-L555
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.resume
private function resume(\Throwable $exception = null) { if ($exception) { $this->close(); return; } if (!$this->isExported && !($this->status & self::CLOSED_RDWR)) { $this->paused = false; Loop::enable($this->readWatcher); $this->p...
php
private function resume(\Throwable $exception = null) { if ($exception) { $this->close(); return; } if (!$this->isExported && !($this->status & self::CLOSED_RDWR)) { $this->paused = false; Loop::enable($this->readWatcher); $this->p...
[ "private", "function", "resume", "(", "\\", "Throwable", "$", "exception", "=", "null", ")", "{", "if", "(", "$", "exception", ")", "{", "$", "this", "->", "close", "(", ")", ";", "return", ";", "}", "if", "(", "!", "$", "this", "->", "isExported",...
Resumes the request parser after it has yielded a promise. @param \Throwable|null $exception
[ "Resumes", "the", "request", "parser", "after", "it", "has", "yielded", "a", "promise", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L562-L574
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.respond
private function respond(Request $request, string $buffer): \Generator { try { $method = $request->getMethod(); if (!\in_array($method, $this->options->getAllowedMethods(), true)) { if (!\in_array($method, HttpDriver::KNOWN_METHODS, true)) { $resp...
php
private function respond(Request $request, string $buffer): \Generator { try { $method = $request->getMethod(); if (!\in_array($method, $this->options->getAllowedMethods(), true)) { if (!\in_array($method, HttpDriver::KNOWN_METHODS, true)) { $resp...
[ "private", "function", "respond", "(", "Request", "$", "request", ",", "string", "$", "buffer", ")", ":", "\\", "Generator", "{", "try", "{", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "if", "(", "!", "\\", "in_array", "(",...
Respond to a parsed request. @param Request $request @param string $buffer @return \Generator
[ "Respond", "to", "a", "parsed", "request", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L584-L624
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.makeExceptionResponse
private function makeExceptionResponse(Request $request): \Generator { $status = Status::INTERNAL_SERVER_ERROR; try { return yield $this->errorHandler->handleError($status, null, $request); } catch (\Throwable $exception) { // If the error handler throws, fallback to...
php
private function makeExceptionResponse(Request $request): \Generator { $status = Status::INTERNAL_SERVER_ERROR; try { return yield $this->errorHandler->handleError($status, null, $request); } catch (\Throwable $exception) { // If the error handler throws, fallback to...
[ "private", "function", "makeExceptionResponse", "(", "Request", "$", "request", ")", ":", "\\", "Generator", "{", "$", "status", "=", "Status", "::", "INTERNAL_SERVER_ERROR", ";", "try", "{", "return", "yield", "$", "this", "->", "errorHandler", "->", "handleE...
Used if an exception is thrown from a request handler. @param Request $request @return \Generator
[ "Used", "if", "an", "exception", "is", "thrown", "from", "a", "request", "handler", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L658-L671
amphp/http-server
src/Driver/RemoteClient.php
RemoteClient.export
private function export(callable $upgrade, string $buffer) { if ($this->status & self::CLOSED_RDWR || $this->isExported) { return; } $this->clear(); $this->isExported = true; \assert($this->logger->debug("Upgrade {$this->clientAddress}:{$this->clientPort} #{$thi...
php
private function export(callable $upgrade, string $buffer) { if ($this->status & self::CLOSED_RDWR || $this->isExported) { return; } $this->clear(); $this->isExported = true; \assert($this->logger->debug("Upgrade {$this->clientAddress}:{$this->clientPort} #{$thi...
[ "private", "function", "export", "(", "callable", "$", "upgrade", ",", "string", "$", "buffer", ")", "{", "if", "(", "$", "this", "->", "status", "&", "self", "::", "CLOSED_RDWR", "||", "$", "this", "->", "isExported", ")", "{", "return", ";", "}", "...
Invokes the export function on Response with the socket detached from the HTTP server. @param callable $upgrade callable @param string $buffer Remaining buffer read from the socket.
[ "Invokes", "the", "export", "function", "on", "Response", "with", "the", "socket", "detached", "from", "the", "HTTP", "server", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/RemoteClient.php#L679-L696
amphp/http-server
src/Driver/TimeoutCache.php
TimeoutCache.renew
public function renew(int $id) { $this->updates[$id] = $this->now + $this->timeout; }
php
public function renew(int $id) { $this->updates[$id] = $this->now + $this->timeout; }
[ "public", "function", "renew", "(", "int", "$", "id", ")", "{", "$", "this", "->", "updates", "[", "$", "id", "]", "=", "$", "this", "->", "now", "+", "$", "this", "->", "timeout", ";", "}" ]
Renews the timeout for the given ID. @param int $id
[ "Renews", "the", "timeout", "for", "the", "given", "ID", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/TimeoutCache.php#L47-L50
amphp/http-server
src/Driver/TimeoutCache.php
TimeoutCache.clear
public function clear(int $id) { unset($this->updates[$id]); $this->cache->remove($id); }
php
public function clear(int $id) { unset($this->updates[$id]); $this->cache->remove($id); }
[ "public", "function", "clear", "(", "int", "$", "id", ")", "{", "unset", "(", "$", "this", "->", "updates", "[", "$", "id", "]", ")", ";", "$", "this", "->", "cache", "->", "remove", "(", "$", "id", ")", ";", "}" ]
Clears the timeout for the given ID, removing it completely from the list. @param int $id
[ "Clears", "the", "timeout", "for", "the", "given", "ID", "removing", "it", "completely", "from", "the", "list", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/TimeoutCache.php#L57-L61
amphp/http-server
src/Driver/DefaultHttpDriverFactory.php
DefaultHttpDriverFactory.selectDriver
public function selectDriver(Client $client): HttpDriver { if ($client->isEncrypted() && ($client->getCryptoContext()["alpn_protocol"] ?? null) === "h2") { return new Http2Driver($this->options, $this->timeReference); } return new Http1Driver($this->options, $this->timeReference...
php
public function selectDriver(Client $client): HttpDriver { if ($client->isEncrypted() && ($client->getCryptoContext()["alpn_protocol"] ?? null) === "h2") { return new Http2Driver($this->options, $this->timeReference); } return new Http1Driver($this->options, $this->timeReference...
[ "public", "function", "selectDriver", "(", "Client", "$", "client", ")", ":", "HttpDriver", "{", "if", "(", "$", "client", "->", "isEncrypted", "(", ")", "&&", "(", "$", "client", "->", "getCryptoContext", "(", ")", "[", "\"alpn_protocol\"", "]", "??", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/DefaultHttpDriverFactory.php#L35-L42
amphp/http-server
src/Response.php
Response.setBody
public function setBody($stringOrStream) { if ($stringOrStream instanceof InputStream) { $this->body = $stringOrStream; $this->removeHeader("content-length"); return; } try { // Use method with string type declaration, so we don't need to impl...
php
public function setBody($stringOrStream) { if ($stringOrStream instanceof InputStream) { $this->body = $stringOrStream; $this->removeHeader("content-length"); return; } try { // Use method with string type declaration, so we don't need to impl...
[ "public", "function", "setBody", "(", "$", "stringOrStream", ")", "{", "if", "(", "$", "stringOrStream", "instanceof", "InputStream", ")", "{", "$", "this", "->", "body", "=", "$", "stringOrStream", ";", "$", "this", "->", "removeHeader", "(", "\"content-len...
Sets the stream for the message body. Note that using a string will automatically set the Content-Length header to the length of the given string. Setting a stream will remove the Content-Length header. @param \Amp\ByteStream\InputStream|string|null $stringOrStream @throws \TypeError If the body given is not a string...
[ "Sets", "the", "stream", "for", "the", "message", "body", ".", "Note", "that", "using", "a", "string", "will", "automatically", "set", "the", "Content", "-", "Length", "header", "to", "the", "length", "of", "the", "given", "string", ".", "Setting", "a", ...
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L89-L104
amphp/http-server
src/Response.php
Response.setHeaders
public function setHeaders(array $headers) { $cookies = $this->cookies; try { parent::setHeaders($headers); } catch (\Throwable $e) { $this->cookies = $cookies; throw $e; } }
php
public function setHeaders(array $headers) { $cookies = $this->cookies; try { parent::setHeaders($headers); } catch (\Throwable $e) { $this->cookies = $cookies; throw $e; } }
[ "public", "function", "setHeaders", "(", "array", "$", "headers", ")", "{", "$", "cookies", "=", "$", "this", "->", "cookies", ";", "try", "{", "parent", "::", "setHeaders", "(", "$", "headers", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e...
Sets the headers from the given array. Any cookie headers will automatically populate the contained array of ResponseCookie objects. @param string[]|string[][] $headers
[ "Sets", "the", "headers", "from", "the", "given", "array", ".", "Any", "cookie", "headers", "will", "automatically", "populate", "the", "contained", "array", "of", "ResponseCookie", "objects", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L118-L129
amphp/http-server
src/Response.php
Response.setHeader
public function setHeader(string $name, $value) { parent::setHeader($name, $value); if (\stripos($name, "set-cookie") === 0) { $this->setCookiesFromHeaders(); } }
php
public function setHeader(string $name, $value) { parent::setHeader($name, $value); if (\stripos($name, "set-cookie") === 0) { $this->setCookiesFromHeaders(); } }
[ "public", "function", "setHeader", "(", "string", "$", "name", ",", "$", "value", ")", "{", "parent", "::", "setHeader", "(", "$", "name", ",", "$", "value", ")", ";", "if", "(", "\\", "stripos", "(", "$", "name", ",", "\"set-cookie\"", ")", "===", ...
Sets the named header to the given value. @param string $name @param string|string[] $value @throws \Error If the header name or value is invalid.
[ "Sets", "the", "named", "header", "to", "the", "given", "value", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L139-L146
amphp/http-server
src/Response.php
Response.setStatus
public function setStatus(int $code, string $reason = null) { $this->status = $this->validateStatusCode($code); $this->reason = $reason ?? Status::getReason($this->status); if ($this->upgrade && $this->status !== Status::SWITCHING_PROTOCOLS) { $this->upgrade = null; } ...
php
public function setStatus(int $code, string $reason = null) { $this->status = $this->validateStatusCode($code); $this->reason = $reason ?? Status::getReason($this->status); if ($this->upgrade && $this->status !== Status::SWITCHING_PROTOCOLS) { $this->upgrade = null; } ...
[ "public", "function", "setStatus", "(", "int", "$", "code", ",", "string", "$", "reason", "=", "null", ")", "{", "$", "this", "->", "status", "=", "$", "this", "->", "validateStatusCode", "(", "$", "code", ")", ";", "$", "this", "->", "reason", "=", ...
Sets the response status code and reason phrase. Use null for the reason phrase to use the default phrase associated with the status code. @param int $code 100 - 599 @param string|null $reason
[ "Sets", "the", "response", "status", "code", "and", "reason", "phrase", ".", "Use", "null", "for", "the", "reason", "phrase", "to", "use", "the", "default", "phrase", "associated", "with", "the", "status", "code", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L206-L214
amphp/http-server
src/Response.php
Response.setCookie
public function setCookie(ResponseCookie $cookie) { $this->cookies[$cookie->getName()] = $cookie; $this->setHeadersFromCookies(); }
php
public function setCookie(ResponseCookie $cookie) { $this->cookies[$cookie->getName()] = $cookie; $this->setHeadersFromCookies(); }
[ "public", "function", "setCookie", "(", "ResponseCookie", "$", "cookie", ")", "{", "$", "this", "->", "cookies", "[", "$", "cookie", "->", "getName", "(", ")", "]", "=", "$", "cookie", ";", "$", "this", "->", "setHeadersFromCookies", "(", ")", ";", "}"...
Adds a cookie to the response. @param ResponseCookie $cookie
[ "Adds", "a", "cookie", "to", "the", "response", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L239-L243
amphp/http-server
src/Response.php
Response.removeCookie
public function removeCookie(string $name) { if (isset($this->cookies[$name])) { unset($this->cookies[$name]); $this->setHeadersFromCookies(); } }
php
public function removeCookie(string $name) { if (isset($this->cookies[$name])) { unset($this->cookies[$name]); $this->setHeadersFromCookies(); } }
[ "public", "function", "removeCookie", "(", "string", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "cookies", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "cookies", "[", "$", "name", "]", ")", ";", ...
Removes a cookie from the response. @param string $name
[ "Removes", "a", "cookie", "from", "the", "response", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L250-L256
amphp/http-server
src/Response.php
Response.setCookiesFromHeaders
private function setCookiesFromHeaders() { $this->cookies = []; $headers = $this->getHeaderArray("set-cookie"); foreach ($headers as $line) { $cookie = ResponseCookie::fromHeader($line); $this->cookies[$cookie->getName()] = $cookie; } }
php
private function setCookiesFromHeaders() { $this->cookies = []; $headers = $this->getHeaderArray("set-cookie"); foreach ($headers as $line) { $cookie = ResponseCookie::fromHeader($line); $this->cookies[$cookie->getName()] = $cookie; } }
[ "private", "function", "setCookiesFromHeaders", "(", ")", "{", "$", "this", "->", "cookies", "=", "[", "]", ";", "$", "headers", "=", "$", "this", "->", "getHeaderArray", "(", "\"set-cookie\"", ")", ";", "foreach", "(", "$", "headers", "as", "$", "line",...
Sets cookies based on headers. @throws \Error
[ "Sets", "cookies", "based", "on", "headers", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L281-L291
amphp/http-server
src/Response.php
Response.push
public function push(string $url, array $headers = []) { \assert((function (array $headers) { foreach ($headers as $name => $header) { if ($name[0] === ":" || !\strncasecmp("host", $name, 4)) { return false; } } return t...
php
public function push(string $url, array $headers = []) { \assert((function (array $headers) { foreach ($headers as $name => $header) { if ($name[0] === ":" || !\strncasecmp("host", $name, 4)) { return false; } } return t...
[ "public", "function", "push", "(", "string", "$", "url", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "\\", "assert", "(", "(", "function", "(", "array", "$", "headers", ")", "{", "foreach", "(", "$", "headers", "as", "$", "name", "=>", ...
Indicate resources which a client likely needs to fetch (e.g. Link: preload or HTTP/2 Server Push). @param string $url URL of resource to push to the client. @param string[][] Additional headers to attach to the request. @throws \Error If the given url is invalid.
[ "Indicate", "resources", "which", "a", "client", "likely", "needs", "to", "fetch", "(", "e", ".", "g", ".", "Link", ":", "preload", "or", "HTTP", "/", "2", "Server", "Push", ")", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L323-L341
amphp/http-server
src/Response.php
Response.upgrade
public function upgrade(callable $upgrade) { $this->upgrade = $upgrade; $this->status = Status::SWITCHING_PROTOCOLS; $this->reason = Status::getReason($this->status); }
php
public function upgrade(callable $upgrade) { $this->upgrade = $upgrade; $this->status = Status::SWITCHING_PROTOCOLS; $this->reason = Status::getReason($this->status); }
[ "public", "function", "upgrade", "(", "callable", "$", "upgrade", ")", "{", "$", "this", "->", "upgrade", "=", "$", "upgrade", ";", "$", "this", "->", "status", "=", "Status", "::", "SWITCHING_PROTOCOLS", ";", "$", "this", "->", "reason", "=", "Status", ...
Sets a callback to be invoked once the response has been written to the client and changes the status of the response to 101 (Switching Protocols). The callback may be removed by changing the status to something else. @param callable $upgrade Callback invoked once the response has been written to the client. The callb...
[ "Sets", "a", "callback", "to", "be", "invoked", "once", "the", "response", "has", "been", "written", "to", "the", "client", "and", "changes", "the", "status", "of", "the", "response", "to", "101", "(", "Switching", "Protocols", ")", ".", "The", "callback",...
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Response.php#L358-L363
amphp/http-server
src/Driver/Http2Driver.php
Http2Driver.setup
public function setup(Client $client, callable $onMessage, callable $write, string $settings = null): \Generator { \assert(!$this->client, "The driver has already been setup"); $this->client = $client; $this->onMessage = $onMessage; $this->write = $write; return $this->pars...
php
public function setup(Client $client, callable $onMessage, callable $write, string $settings = null): \Generator { \assert(!$this->client, "The driver has already been setup"); $this->client = $client; $this->onMessage = $onMessage; $this->write = $write; return $this->pars...
[ "public", "function", "setup", "(", "Client", "$", "client", ",", "callable", "$", "onMessage", ",", "callable", "$", "write", ",", "string", "$", "settings", "=", "null", ")", ":", "\\", "Generator", "{", "\\", "assert", "(", "!", "$", "this", "->", ...
@param Client $client @param callable $onMessage @param callable $write @param string|null $settings HTTP2-Settings header content from upgrade request or null for direct HTTP/2. @return \Generator
[ "@param", "Client", "$client", "@param", "callable", "$onMessage", "@param", "callable", "$write", "@param", "string|null", "$settings", "HTTP2", "-", "Settings", "header", "content", "from", "upgrade", "request", "or", "null", "for", "direct", "HTTP", "/", "2", ...
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http2Driver.php#L169-L178
amphp/http-server
src/Driver/Http2Driver.php
Http2Driver.parser
private function parser(string $settings = null): \Generator { $maxHeaderSize = $this->options->getHeaderSizeLimit(); $maxBodySize = $this->options->getBodySizeLimit(); $maxFramesPerSecond = $this->options->getFramesPerSecondLimit(); $minAverageFrameSize = $this->options->getMinimumA...
php
private function parser(string $settings = null): \Generator { $maxHeaderSize = $this->options->getHeaderSizeLimit(); $maxBodySize = $this->options->getBodySizeLimit(); $maxFramesPerSecond = $this->options->getFramesPerSecondLimit(); $minAverageFrameSize = $this->options->getMinimumA...
[ "private", "function", "parser", "(", "string", "$", "settings", "=", "null", ")", ":", "\\", "Generator", "{", "$", "maxHeaderSize", "=", "$", "this", "->", "options", "->", "getHeaderSizeLimit", "(", ")", ";", "$", "maxBodySize", "=", "$", "this", "->"...
@param string|null $settings HTTP2-Settings header content from upgrade request or null for direct HTTP/2. @return \Generator
[ "@param", "string|null", "$settings", "HTTP2", "-", "Settings", "header", "content", "from", "upgrade", "request", "or", "null", "for", "direct", "HTTP", "/", "2", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http2Driver.php#L477-L1250
amphp/http-server
src/Driver/Http2Driver.php
Http2Driver.shutdown
public function shutdown(int $lastId = null, int $reason = self::GRACEFUL_SHUTDOWN): Promise { $this->stopping = true; return call(function () use ($lastId, $reason) { $promises = []; foreach ($this->streams as $id => $stream) { if ($lastId && $id > $lastId) ...
php
public function shutdown(int $lastId = null, int $reason = self::GRACEFUL_SHUTDOWN): Promise { $this->stopping = true; return call(function () use ($lastId, $reason) { $promises = []; foreach ($this->streams as $id => $stream) { if ($lastId && $id > $lastId) ...
[ "public", "function", "shutdown", "(", "int", "$", "lastId", "=", "null", ",", "int", "$", "reason", "=", "self", "::", "GRACEFUL_SHUTDOWN", ")", ":", "Promise", "{", "$", "this", "->", "stopping", "=", "true", ";", "return", "call", "(", "function", "...
@param int|null $lastId ID of last processed frame. Null to use the last opened frame ID or 0 if no frames have been opened. @return Promise
[ "@param", "int|null", "$lastId", "ID", "of", "last", "processed", "frame", ".", "Null", "to", "use", "the", "last", "opened", "frame", "ID", "or", "0", "if", "no", "frames", "have", "been", "opened", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http2Driver.php#L1264-L1299
amphp/http-server
src/Driver/Http2Driver.php
Http2Driver.updateSetting
private function updateSetting(string $buffer): int { $unpacked = \unpack("nsetting/Nvalue", $buffer); if ($unpacked["value"] < 0) { return self::PROTOCOL_ERROR; } switch ($unpacked["setting"]) { case self::INITIAL_WINDOW_SIZE: if ($unpacked[...
php
private function updateSetting(string $buffer): int { $unpacked = \unpack("nsetting/Nvalue", $buffer); if ($unpacked["value"] < 0) { return self::PROTOCOL_ERROR; } switch ($unpacked["setting"]) { case self::INITIAL_WINDOW_SIZE: if ($unpacked[...
[ "private", "function", "updateSetting", "(", "string", "$", "buffer", ")", ":", "int", "{", "$", "unpacked", "=", "\\", "unpack", "(", "\"nsetting/Nvalue\"", ",", "$", "buffer", ")", ";", "if", "(", "$", "unpacked", "[", "\"value\"", "]", "<", "0", ")"...
@param string $buffer Entire settings frame payload. Only the first 6 bytes are examined. @return int Error code, or 0 if the setting was valid or unknown.
[ "@param", "string", "$buffer", "Entire", "settings", "frame", "payload", ".", "Only", "the", "first", "6", "bytes", "are", "examined", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http2Driver.php#L1311-L1352
amphp/http-server
src/Request.php
Request.addHeader
public function addHeader(string $name, $value) { parent::addHeader($name, $value); if (\stripos($name, "cookie") === 0) { $this->setCookiesFromHeaders(); } }
php
public function addHeader(string $name, $value) { parent::addHeader($name, $value); if (\stripos($name, "cookie") === 0) { $this->setCookiesFromHeaders(); } }
[ "public", "function", "addHeader", "(", "string", "$", "name", ",", "$", "value", ")", "{", "parent", "::", "addHeader", "(", "$", "name", ",", "$", "value", ")", ";", "if", "(", "\\", "stripos", "(", "$", "name", ",", "\"cookie\"", ")", "===", "0"...
Adds the value to the named header, or creates the header with the given value if it did not exist. @param string $name @param string|string[] $value @throws \Error If the header name or value is invalid.
[ "Adds", "the", "value", "to", "the", "named", "header", "or", "creates", "the", "header", "with", "the", "given", "value", "if", "it", "did", "not", "exist", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Request.php#L178-L185
amphp/http-server
src/Request.php
Request.removeHeader
public function removeHeader(string $name) { parent::removeHeader($name); if (\stripos($name, "cookie") === 0) { $this->cookies = []; } }
php
public function removeHeader(string $name) { parent::removeHeader($name); if (\stripos($name, "cookie") === 0) { $this->cookies = []; } }
[ "public", "function", "removeHeader", "(", "string", "$", "name", ")", "{", "parent", "::", "removeHeader", "(", "$", "name", ")", ";", "if", "(", "\\", "stripos", "(", "$", "name", ",", "\"cookie\"", ")", "===", "0", ")", "{", "$", "this", "->", "...
Removes the given header if it exists. @param string $name
[ "Removes", "the", "given", "header", "if", "it", "exists", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Request.php#L192-L199
amphp/http-server
src/Request.php
Request.getBody
public function getBody(): RequestBody { if ($this->body === null) { $this->body = new RequestBody(new InMemoryStream); } return $this->body; }
php
public function getBody(): RequestBody { if ($this->body === null) { $this->body = new RequestBody(new InMemoryStream); } return $this->body; }
[ "public", "function", "getBody", "(", ")", ":", "RequestBody", "{", "if", "(", "$", "this", "->", "body", "===", "null", ")", "{", "$", "this", "->", "body", "=", "new", "RequestBody", "(", "new", "InMemoryStream", ")", ";", "}", "return", "$", "this...
Retrieve the request body. @return \Amp\Http\Server\RequestBody
[ "Retrieve", "the", "request", "body", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Request.php#L206-L213
amphp/http-server
src/Request.php
Request.setBody
public function setBody($stringOrStream) { if ($stringOrStream instanceof RequestBody) { $this->body = $stringOrStream; $this->removeHeader("content-length"); return; } if ($stringOrStream instanceof InputStream) { $this->body = new RequestBod...
php
public function setBody($stringOrStream) { if ($stringOrStream instanceof RequestBody) { $this->body = $stringOrStream; $this->removeHeader("content-length"); return; } if ($stringOrStream instanceof InputStream) { $this->body = new RequestBod...
[ "public", "function", "setBody", "(", "$", "stringOrStream", ")", "{", "if", "(", "$", "stringOrStream", "instanceof", "RequestBody", ")", "{", "$", "this", "->", "body", "=", "$", "stringOrStream", ";", "$", "this", "->", "removeHeader", "(", "\"content-len...
Sets the stream for the message body. Note that using a string will automatically set the Content-Length header to the length of the given string. Using an InputStream or Body instance will remove the Content-Length header. @param RequestBody|InputStream|string|null $stringOrStream @throws \Error @throws \TypeError
[ "Sets", "the", "stream", "for", "the", "message", "body", ".", "Note", "that", "using", "a", "string", "will", "automatically", "set", "the", "Content", "-", "Length", "header", "to", "the", "length", "of", "the", "given", "string", ".", "Using", "an", "...
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Request.php#L224-L248
amphp/http-server
src/Request.php
Request.setCookie
public function setCookie(RequestCookie $cookie) { $this->cookies[$cookie->getName()] = $cookie; $this->setHeadersFromCookies(); }
php
public function setCookie(RequestCookie $cookie) { $this->cookies[$cookie->getName()] = $cookie; $this->setHeadersFromCookies(); }
[ "public", "function", "setCookie", "(", "RequestCookie", "$", "cookie", ")", "{", "$", "this", "->", "cookies", "[", "$", "cookie", "->", "getName", "(", ")", "]", "=", "$", "cookie", ";", "$", "this", "->", "setHeadersFromCookies", "(", ")", ";", "}" ...
Adds a cookie to the request. @param RequestCookie $cookie
[ "Adds", "a", "cookie", "to", "the", "request", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Request.php#L286-L290
amphp/http-server
src/Request.php
Request.setHeadersFromCookies
private function setHeadersFromCookies() { $values = []; foreach ($this->cookies as $cookie) { $values[] = (string) $cookie; } $this->setHeader("cookie", $values); }
php
private function setHeadersFromCookies() { $values = []; foreach ($this->cookies as $cookie) { $values[] = (string) $cookie; } $this->setHeader("cookie", $values); }
[ "private", "function", "setHeadersFromCookies", "(", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "cookie", ")", "{", "$", "values", "[", "]", "=", "(", "string", ")", "$", "cookie", ";", "}"...
Sets headers based on cookie values.
[ "Sets", "headers", "based", "on", "cookie", "values", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Request.php#L327-L336
amphp/http-server
src/Request.php
Request.getAttribute
public function getAttribute(string $name) { if (!$this->hasAttribute($name)) { throw new MissingAttributeError("The requested attribute '{$name}' does not exist"); } return $this->attributes[$name]; }
php
public function getAttribute(string $name) { if (!$this->hasAttribute($name)) { throw new MissingAttributeError("The requested attribute '{$name}' does not exist"); } return $this->attributes[$name]; }
[ "public", "function", "getAttribute", "(", "string", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "hasAttribute", "(", "$", "name", ")", ")", "{", "throw", "new", "MissingAttributeError", "(", "\"The requested attribute '{$name}' does not exist\"", ...
Retrieve a variable from the request's mutable local storage. Each request has its own mutable local storage to which request handlers and middleware may read and write data. Other request handlers or middleware which are aware of this data can then access it without the server being tightly coupled to specific implem...
[ "Retrieve", "a", "variable", "from", "the", "request", "s", "mutable", "local", "storage", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Request.php#L365-L372
amphp/http-server
src/Driver/SystemTimeReference.php
SystemTimeReference.updateTime
private function updateTime() { // Date string generation is (relatively) expensive. Since we only need HTTP // dates at a granularity of one second we're better off to generate this // information once per second and cache it. $this->currentTime = \time(); $this->currentHttp...
php
private function updateTime() { // Date string generation is (relatively) expensive. Since we only need HTTP // dates at a granularity of one second we're better off to generate this // information once per second and cache it. $this->currentTime = \time(); $this->currentHttp...
[ "private", "function", "updateTime", "(", ")", "{", "// Date string generation is (relatively) expensive. Since we only need HTTP", "// dates at a granularity of one second we're better off to generate this", "// information once per second and cache it.", "$", "this", "->", "currentTime", ...
Updates the context with the current time.
[ "Updates", "the", "context", "with", "the", "current", "time", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/SystemTimeReference.php#L72-L83
amphp/http-server
src/Driver/Http1Driver.php
Http1Driver.setup
public function setup(Client $client, callable $onMessage, callable $write): \Generator { \assert(!$this->client, "The driver has already been setup"); $this->client = $client; $this->onMessage = $onMessage; $this->write = $write; return $this->parser(); }
php
public function setup(Client $client, callable $onMessage, callable $write): \Generator { \assert(!$this->client, "The driver has already been setup"); $this->client = $client; $this->onMessage = $onMessage; $this->write = $write; return $this->parser(); }
[ "public", "function", "setup", "(", "Client", "$", "client", ",", "callable", "$", "onMessage", ",", "callable", "$", "write", ")", ":", "\\", "Generator", "{", "\\", "assert", "(", "!", "$", "this", "->", "client", ",", "\"The driver has already been setup\...
{@inheritdoc}
[ "{" ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http1Driver.php#L86-L95
amphp/http-server
src/Driver/Http1Driver.php
Http1Driver.write
public function write(Request $request, Response $response): Promise { if ($this->http2) { return $this->http2->write($request, $response); } return $this->lastWrite = new Coroutine($this->send($response, $request)); }
php
public function write(Request $request, Response $response): Promise { if ($this->http2) { return $this->http2->write($request, $response); } return $this->lastWrite = new Coroutine($this->send($response, $request)); }
[ "public", "function", "write", "(", "Request", "$", "request", ",", "Response", "$", "response", ")", ":", "Promise", "{", "if", "(", "$", "this", "->", "http2", ")", "{", "return", "$", "this", "->", "http2", "->", "write", "(", "$", "request", ",",...
{@inheritdoc} Selects HTTP/2 or HTTP/1.x writer depending on connection status.
[ "{", "@inheritdoc", "}" ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http1Driver.php#L102-L109
amphp/http-server
src/Driver/Http1Driver.php
Http1Driver.send
private function send(Response $response, Request $request = null): \Generator { \assert($this->client, "The driver has not been setup; call setup first"); if ($this->lastWrite) { yield $this->lastWrite; // Prevent writing another response until the first is finished. } ...
php
private function send(Response $response, Request $request = null): \Generator { \assert($this->client, "The driver has not been setup; call setup first"); if ($this->lastWrite) { yield $this->lastWrite; // Prevent writing another response until the first is finished. } ...
[ "private", "function", "send", "(", "Response", "$", "response", ",", "Request", "$", "request", "=", "null", ")", ":", "\\", "Generator", "{", "\\", "assert", "(", "$", "this", "->", "client", ",", "\"The driver has not been setup; call setup first\"", ")", "...
HTTP/1.x response writer. @param \Amp\Http\Server\Response $response @param \Amp\Http\Server\Request|null $request @return \Generator
[ "HTTP", "/", "1", ".", "x", "response", "writer", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http1Driver.php#L119-L201
amphp/http-server
src/Driver/Http1Driver.php
Http1Driver.sendErrorResponse
private function sendErrorResponse(ClientException $exception): \Generator { $message = $exception->getMessage(); $status = $exception->getCode() ?: Status::BAD_REQUEST; /** @var \Amp\Http\Server\Response $response */ $response = yield $this->errorHandler->handleError($status, $mess...
php
private function sendErrorResponse(ClientException $exception): \Generator { $message = $exception->getMessage(); $status = $exception->getCode() ?: Status::BAD_REQUEST; /** @var \Amp\Http\Server\Response $response */ $response = yield $this->errorHandler->handleError($status, $mess...
[ "private", "function", "sendErrorResponse", "(", "ClientException", "$", "exception", ")", ":", "\\", "Generator", "{", "$", "message", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "$", "status", "=", "$", "exception", "->", "getCode", "(", ")...
Creates an error response from the error handler and sends that response to the client. @param \Amp\Http\Server\ClientException $exception @return \Generator
[ "Creates", "an", "error", "response", "from", "the", "error", "handler", "and", "sends", "that", "response", "to", "the", "client", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http1Driver.php#L692-L703
amphp/http-server
src/Driver/Http1Driver.php
Http1Driver.filter
private function filter(Response $response, string $protocol = "1.0", array $connection = []): array { $headers = $response->getHeaders(); if ($response->getStatus() < Status::OK) { unset($headers['content-length']); // 1xx responses do not have a body. return $headers; ...
php
private function filter(Response $response, string $protocol = "1.0", array $connection = []): array { $headers = $response->getHeaders(); if ($response->getStatus() < Status::OK) { unset($headers['content-length']); // 1xx responses do not have a body. return $headers; ...
[ "private", "function", "filter", "(", "Response", "$", "response", ",", "string", "$", "protocol", "=", "\"1.0\"", ",", "array", "$", "connection", "=", "[", "]", ")", ":", "array", "{", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")...
Filters and updates response headers based on protocol and connection header from the request. @param \Amp\Http\Server\Response $response @param string $protocol Request protocol. @param array $connection Request connection header. @return string[][] Response headers to be writt...
[ "Filters", "and", "updates", "response", "headers", "based", "on", "protocol", "and", "connection", "header", "from", "the", "request", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Driver/Http1Driver.php#L727-L769
amphp/http-server
src/Options.php
Options.withAllowedMethods
public function withAllowedMethods(array $allowedMethods): self { foreach ($allowedMethods as $key => $method) { if (!\is_string($method)) { throw new \Error( \sprintf( "Invalid type at key %s of allowed methods array: %s", ...
php
public function withAllowedMethods(array $allowedMethods): self { foreach ($allowedMethods as $key => $method) { if (!\is_string($method)) { throw new \Error( \sprintf( "Invalid type at key %s of allowed methods array: %s", ...
[ "public", "function", "withAllowedMethods", "(", "array", "$", "allowedMethods", ")", ":", "self", "{", "foreach", "(", "$", "allowedMethods", "as", "$", "key", "=>", "$", "method", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "method", ")", ...
@param string[] $allowedMethods An array of allowed request methods. Default is GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE. @return self @throws \Error If the array contains non-strings, empty method names, or does not contain GET or HEAD.
[ "@param", "string", "[]", "$allowedMethods", "An", "array", "of", "allowed", "request", "methods", ".", "Default", "is", "GET", "POST", "PUT", "PATCH", "HEAD", "OPTIONS", "DELETE", "." ]
train
https://github.com/amphp/http-server/blob/e332da0c7f282cbea36c32e32b3dedbc73a339ae/src/Options.php#L371-L409
antonioribeiro/google2fa-laravel
src/Google2FA.php
Google2FA.storeOldTimestamp
protected function storeOldTimestamp($key) { return $this->config('forbid_old_passwords') === true ? $this->sessionPut(Constants::SESSION_OTP_TIMESTAMP, $key) : $key; }
php
protected function storeOldTimestamp($key) { return $this->config('forbid_old_passwords') === true ? $this->sessionPut(Constants::SESSION_OTP_TIMESTAMP, $key) : $key; }
[ "protected", "function", "storeOldTimestamp", "(", "$", "key", ")", "{", "return", "$", "this", "->", "config", "(", "'forbid_old_passwords'", ")", "===", "true", "?", "$", "this", "->", "sessionPut", "(", "Constants", "::", "SESSION_OTP_TIMESTAMP", ",", "$", ...
Store the old OTP timestamp. @param $key @return mixed
[ "Store", "the", "old", "OTP", "timestamp", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Google2FA.php#L79-L84
antonioribeiro/google2fa-laravel
src/Google2FA.php
Google2FA.passwordExpired
protected function passwordExpired() { if (($minutes = $this->config('lifetime')) !== 0 && $this->minutesSinceLastActivity() > $minutes) { event(new OneTimePasswordExpired($this->getUser())); $this->logout(); return true; } $this->keepAlive(); ...
php
protected function passwordExpired() { if (($minutes = $this->config('lifetime')) !== 0 && $this->minutesSinceLastActivity() > $minutes) { event(new OneTimePasswordExpired($this->getUser())); $this->logout(); return true; } $this->keepAlive(); ...
[ "protected", "function", "passwordExpired", "(", ")", "{", "if", "(", "(", "$", "minutes", "=", "$", "this", "->", "config", "(", "'lifetime'", ")", ")", "!==", "0", "&&", "$", "this", "->", "minutesSinceLastActivity", "(", ")", ">", "$", "minutes", ")...
Check if OTP has expired. @return bool
[ "Check", "if", "OTP", "has", "expired", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Google2FA.php#L135-L148
antonioribeiro/google2fa-laravel
src/Google2FA.php
Google2FA.verifyGoogle2FA
public function verifyGoogle2FA($secret, $one_time_password) { return $this->verifyKey( $secret, $one_time_password, $this->config('window'), null, // $timestamp $this->getOldTimestamp() ?: Google2FAConstants::ARGUMENT_NOT_SET ...
php
public function verifyGoogle2FA($secret, $one_time_password) { return $this->verifyKey( $secret, $one_time_password, $this->config('window'), null, // $timestamp $this->getOldTimestamp() ?: Google2FAConstants::ARGUMENT_NOT_SET ...
[ "public", "function", "verifyGoogle2FA", "(", "$", "secret", ",", "$", "one_time_password", ")", "{", "return", "$", "this", "->", "verifyKey", "(", "$", "secret", ",", "$", "one_time_password", ",", "$", "this", "->", "config", "(", "'window'", ")", ",", ...
Verify the OTP. @param $secret @param $one_time_password @return mixed
[ "Verify", "the", "OTP", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Google2FA.php#L210-L219
antonioribeiro/google2fa-laravel
src/Support/Config.php
Config.config
protected function config($string, $default = null) { if (is_null(config($config = Constants::CONFIG_PACKAGE_NAME))) { throw new \Exception("Config ({$config}.php) not found. Have you published it?"); } return config( implode('.', [Constants::CONFIG_PACKAGE_NAME, $st...
php
protected function config($string, $default = null) { if (is_null(config($config = Constants::CONFIG_PACKAGE_NAME))) { throw new \Exception("Config ({$config}.php) not found. Have you published it?"); } return config( implode('.', [Constants::CONFIG_PACKAGE_NAME, $st...
[ "protected", "function", "config", "(", "$", "string", ",", "$", "default", "=", "null", ")", "{", "if", "(", "is_null", "(", "config", "(", "$", "config", "=", "Constants", "::", "CONFIG_PACKAGE_NAME", ")", ")", ")", "{", "throw", "new", "\\", "Except...
Get a config value. @param $string @throws \Exception @return mixed
[ "Get", "a", "config", "value", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Config.php#L16-L26
antonioribeiro/google2fa-laravel
src/Support/Auth.php
Auth.getAuth
protected function getAuth() { if (is_null($this->auth)) { $this->auth = app($this->config('auth')); } return $this->auth; }
php
protected function getAuth() { if (is_null($this->auth)) { $this->auth = app($this->config('auth')); } return $this->auth; }
[ "protected", "function", "getAuth", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "auth", ")", ")", "{", "$", "this", "->", "auth", "=", "app", "(", "$", "this", "->", "config", "(", "'auth'", ")", ")", ";", "}", "return", "$", "...
Get or make an auth instance. @return \Illuminate\Foundation\Application|mixed
[ "Get", "or", "make", "an", "auth", "instance", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Auth.php#L19-L26
antonioribeiro/google2fa-laravel
src/Support/Authenticator.php
Authenticator.fireLoginEvent
private function fireLoginEvent($succeeded) { event( $succeeded ? new LoginSucceeded($this->getUser()) : new LoginFailed($this->getUser()) ); return $succeeded; }
php
private function fireLoginEvent($succeeded) { event( $succeeded ? new LoginSucceeded($this->getUser()) : new LoginFailed($this->getUser()) ); return $succeeded; }
[ "private", "function", "fireLoginEvent", "(", "$", "succeeded", ")", "{", "event", "(", "$", "succeeded", "?", "new", "LoginSucceeded", "(", "$", "this", "->", "getUser", "(", ")", ")", ":", "new", "LoginFailed", "(", "$", "this", "->", "getUser", "(", ...
Fire login (success or failed). @param $succeeded
[ "Fire", "login", "(", "success", "or", "failed", ")", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Authenticator.php#L75-L84
antonioribeiro/google2fa-laravel
src/Support/Authenticator.php
Authenticator.getOneTimePassword
protected function getOneTimePassword() { if (is_null($password = $this->getInputOneTimePassword()) || empty($password)) { event(new EmptyOneTimePasswordReceived()); if ($this->config('throw_exceptions', true)) { throw new InvalidOneTimePassword('One Time Password ca...
php
protected function getOneTimePassword() { if (is_null($password = $this->getInputOneTimePassword()) || empty($password)) { event(new EmptyOneTimePasswordReceived()); if ($this->config('throw_exceptions', true)) { throw new InvalidOneTimePassword('One Time Password ca...
[ "protected", "function", "getOneTimePassword", "(", ")", "{", "if", "(", "is_null", "(", "$", "password", "=", "$", "this", "->", "getInputOneTimePassword", "(", ")", ")", "||", "empty", "(", "$", "password", ")", ")", "{", "event", "(", "new", "EmptyOne...
Get the OTP from user input. @throws InvalidOneTimePassword @return mixed
[ "Get", "the", "OTP", "from", "user", "input", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Authenticator.php#L93-L104
antonioribeiro/google2fa-laravel
src/Support/Authenticator.php
Authenticator.checkOTP
protected function checkOTP() { if (!$this->inputHasOneTimePassword()) { return false; } if ($isValid = $this->verifyOneTimePassword()) { $this->login(); } return $this->fireLoginEvent($isValid); }
php
protected function checkOTP() { if (!$this->inputHasOneTimePassword()) { return false; } if ($isValid = $this->verifyOneTimePassword()) { $this->login(); } return $this->fireLoginEvent($isValid); }
[ "protected", "function", "checkOTP", "(", ")", "{", "if", "(", "!", "$", "this", "->", "inputHasOneTimePassword", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "isValid", "=", "$", "this", "->", "verifyOneTimePassword", "(", ")", ")"...
Check if the input OTP is valid. @return bool
[ "Check", "if", "the", "input", "OTP", "is", "valid", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Authenticator.php#L145-L156
antonioribeiro/google2fa-laravel
src/Support/Response.php
Response.makeHtmlResponse
protected function makeHtmlResponse($statusCode) { $view = $this->getView(); if ($statusCode !== SymfonyResponse::HTTP_OK) { $view->withErrors($this->getErrorBagForStatusCode($statusCode)); } return new IlluminateHtmlResponse($view, $statusCode); }
php
protected function makeHtmlResponse($statusCode) { $view = $this->getView(); if ($statusCode !== SymfonyResponse::HTTP_OK) { $view->withErrors($this->getErrorBagForStatusCode($statusCode)); } return new IlluminateHtmlResponse($view, $statusCode); }
[ "protected", "function", "makeHtmlResponse", "(", "$", "statusCode", ")", "{", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "if", "(", "$", "statusCode", "!==", "SymfonyResponse", "::", "HTTP_OK", ")", "{", "$", "view", "->", "withError...
Make a web response. @param $statusCode @return \Illuminate\Http\Response
[ "Make", "a", "web", "response", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Response.php#L48-L57
antonioribeiro/google2fa-laravel
src/Support/Response.php
Response.makeRequestOneTimePasswordResponse
public function makeRequestOneTimePasswordResponse() { event( app()->version() < '5.4' ? new OneTimePasswordRequested53($this->getUser()) : new OneTimePasswordRequested($this->getUser()) ); $expectJson = app()->version() < '5.4' ? $thi...
php
public function makeRequestOneTimePasswordResponse() { event( app()->version() < '5.4' ? new OneTimePasswordRequested53($this->getUser()) : new OneTimePasswordRequested($this->getUser()) ); $expectJson = app()->version() < '5.4' ? $thi...
[ "public", "function", "makeRequestOneTimePasswordResponse", "(", ")", "{", "event", "(", "app", "(", ")", "->", "version", "(", ")", "<", "'5.4'", "?", "new", "OneTimePasswordRequested53", "(", "$", "this", "->", "getUser", "(", ")", ")", ":", "new", "OneT...
Create a response to request the OTP. @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
[ "Create", "a", "response", "to", "request", "the", "OTP", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Response.php#L64-L79
antonioribeiro/google2fa-laravel
src/Support/Session.php
Session.makeSessionVarName
protected function makeSessionVarName($name = null) { return $this->config('session_var').(is_null($name) || empty($name) ? '' : '.'.$name); }
php
protected function makeSessionVarName($name = null) { return $this->config('session_var').(is_null($name) || empty($name) ? '' : '.'.$name); }
[ "protected", "function", "makeSessionVarName", "(", "$", "name", "=", "null", ")", "{", "return", "$", "this", "->", "config", "(", "'session_var'", ")", ".", "(", "is_null", "(", "$", "name", ")", "||", "empty", "(", "$", "name", ")", "?", "''", ":"...
Make a session var name for. @param null $name @return mixed
[ "Make", "a", "session", "var", "name", "for", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Session.php#L14-L17
antonioribeiro/google2fa-laravel
src/Support/Session.php
Session.sessionGet
public function sessionGet($var = null, $default = null) { if ($this->stateless) { return $default; } return $this->getRequest()->session()->get( $this->makeSessionVarName($var), $default ); }
php
public function sessionGet($var = null, $default = null) { if ($this->stateless) { return $default; } return $this->getRequest()->session()->get( $this->makeSessionVarName($var), $default ); }
[ "public", "function", "sessionGet", "(", "$", "var", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "this", "->", "stateless", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "getRequest", "(", "...
Get a session var value. @param null $var @return mixed
[ "Get", "a", "session", "var", "value", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Session.php#L26-L36
antonioribeiro/google2fa-laravel
src/Support/Session.php
Session.sessionPut
protected function sessionPut($var, $value) { if ($this->stateless) { return $value; } $this->getRequest()->session()->put( $this->makeSessionVarName($var), $value ); return $value; }
php
protected function sessionPut($var, $value) { if ($this->stateless) { return $value; } $this->getRequest()->session()->put( $this->makeSessionVarName($var), $value ); return $value; }
[ "protected", "function", "sessionPut", "(", "$", "var", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "stateless", ")", "{", "return", "$", "value", ";", "}", "$", "this", "->", "getRequest", "(", ")", "->", "session", "(", ")", "->", ...
Put a var value to the current session. @param $var @param $value @return mixed
[ "Put", "a", "var", "value", "to", "the", "current", "session", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Session.php#L46-L58
antonioribeiro/google2fa-laravel
src/Support/Session.php
Session.sessionForget
protected function sessionForget($var = null) { if ($this->stateless) { return; } $this->getRequest()->session()->forget( $this->makeSessionVarName($var) ); }
php
protected function sessionForget($var = null) { if ($this->stateless) { return; } $this->getRequest()->session()->forget( $this->makeSessionVarName($var) ); }
[ "protected", "function", "sessionForget", "(", "$", "var", "=", "null", ")", "{", "if", "(", "$", "this", "->", "stateless", ")", "{", "return", ";", "}", "$", "this", "->", "getRequest", "(", ")", "->", "session", "(", ")", "->", "forget", "(", "$...
Forget a session var. @param null $var
[ "Forget", "a", "session", "var", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/Support/Session.php#L65-L74
antonioribeiro/google2fa-laravel
src/ServiceProvider.php
ServiceProvider.register
public function register() { $this->app->singleton('pragmarx.google2fa', function ($app) { return $app->make(Google2FA::class); }); $this->configurePaths(); $this->mergeConfig(); }
php
public function register() { $this->app->singleton('pragmarx.google2fa', function ($app) { return $app->make(Google2FA::class); }); $this->configurePaths(); $this->mergeConfig(); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'pragmarx.google2fa'", ",", "function", "(", "$", "app", ")", "{", "return", "$", "app", "->", "make", "(", "Google2FA", "::", "class", ")", ";", "}", ...
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/antonioribeiro/google2fa-laravel/blob/b5f5bc71dcc52c48720441bc01c701023bd82882/src/ServiceProvider.php#L51-L60
overtrue/laravel-follow
src/FollowRelation.php
FollowRelation.scopePopular
public function scopePopular($query, $type = null) { $query->select('followable_id', 'followable_type', \DB::raw('COUNT(*) AS count')) ->groupBy('followable_id', 'followable_type') ->orderByDesc('count'); if ($type) { $query->where('follow...
php
public function scopePopular($query, $type = null) { $query->select('followable_id', 'followable_type', \DB::raw('COUNT(*) AS count')) ->groupBy('followable_id', 'followable_type') ->orderByDesc('count'); if ($type) { $query->where('follow...
[ "public", "function", "scopePopular", "(", "$", "query", ",", "$", "type", "=", "null", ")", "{", "$", "query", "->", "select", "(", "'followable_id'", ",", "'followable_type'", ",", "\\", "DB", "::", "raw", "(", "'COUNT(*) AS count'", ")", ")", "->", "g...
@param \Illuminate\Database\Eloquent\Builder $query @param string|null $type @return \Illuminate\Database\Eloquent\Builder
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Builder", "$query", "@param", "string|null", "$type" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/FollowRelation.php#L50-L61
overtrue/laravel-follow
src/FollowRelation.php
FollowRelation.normalizeFollowableType
protected function normalizeFollowableType($type) { $morphMap = Relation::morphMap(); if (!empty($morphMap) && in_array($type, $morphMap, true)) { $type = array_search($type, $morphMap, true); } if (class_exists($type)) { return $type; } $na...
php
protected function normalizeFollowableType($type) { $morphMap = Relation::morphMap(); if (!empty($morphMap) && in_array($type, $morphMap, true)) { $type = array_search($type, $morphMap, true); } if (class_exists($type)) { return $type; } $na...
[ "protected", "function", "normalizeFollowableType", "(", "$", "type", ")", "{", "$", "morphMap", "=", "Relation", "::", "morphMap", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "morphMap", ")", "&&", "in_array", "(", "$", "type", ",", "$", "morphM...
@param string $type @throws \InvalidArgumentException @return string
[ "@param", "string", "$type" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/FollowRelation.php#L90-L111
overtrue/laravel-follow
src/Traits/CanBeVoted.php
CanBeVoted.voters
public function voters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivotIn('relation', [Follow::RELATION_UPVOTE, Follow::RELATION_DOWNVOTE]) ->withPivot('followable_type', 'relatio...
php
public function voters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivotIn('relation', [Follow::RELATION_UPVOTE, Follow::RELATION_DOWNVOTE]) ->withPivot('followable_type', 'relatio...
[ "public", "function", "voters", "(", ")", "{", "return", "$", "this", "->", "morphToMany", "(", "config", "(", "'follow.user_model'", ")", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", "where...
Return voters. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "voters", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeVoted.php#L62-L67
overtrue/laravel-follow
src/Traits/CanBeVoted.php
CanBeVoted.upvoters
public function upvoters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_UPVOTE) ->withPivot('followable_type', 'relation', 'created_at'); }
php
public function upvoters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_UPVOTE) ->withPivot('followable_type', 'relation', 'created_at'); }
[ "public", "function", "upvoters", "(", ")", "{", "return", "$", "this", "->", "morphToMany", "(", "config", "(", "'follow.user_model'", ")", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", "whe...
Return upvoters. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "upvoters", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeVoted.php#L74-L79
overtrue/laravel-follow
src/Traits/CanBeVoted.php
CanBeVoted.downvoters
public function downvoters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE) ->withPivot('followable_type', 'relation', 'created_at'); ...
php
public function downvoters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE) ->withPivot('followable_type', 'relation', 'created_at'); ...
[ "public", "function", "downvoters", "(", ")", "{", "return", "$", "this", "->", "morphToMany", "(", "config", "(", "'follow.user_model'", ")", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", "w...
Return downvoters. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "downvoters", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeVoted.php#L86-L91
overtrue/laravel-follow
database/migrations/2018_06_29_032244_create_laravel_follow_tables.php
CreateLaravelFollowTables.up
public function up() { Schema::create(config('follow.followable_table', 'followables'), function (Blueprint $table) { $userForeignKey = config('follow.users_table_foreign_key', 'user_id'); $table->unsignedInteger($userForeignKey); $table->unsignedInteger('followable_id');...
php
public function up() { Schema::create(config('follow.followable_table', 'followables'), function (Blueprint $table) { $userForeignKey = config('follow.users_table_foreign_key', 'user_id'); $table->unsignedInteger($userForeignKey); $table->unsignedInteger('followable_id');...
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "create", "(", "config", "(", "'follow.followable_table'", ",", "'followables'", ")", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "userForeignKey", "=", "config", "(", "'follow.us...
Run the migrations.
[ "Run", "the", "migrations", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/database/migrations/2018_06_29_032244_create_laravel_follow_tables.php#L20-L37
overtrue/laravel-follow
database/migrations/2018_06_29_032244_create_laravel_follow_tables.php
CreateLaravelFollowTables.down
public function down() { Schema::table(config('follow.followable_table', 'followables'), function ($table) { $table->dropForeign(config('follow.followable_table', 'followables').'_user_id_foreign'); }); Schema::drop(config('follow.followable_table', 'followables')); }
php
public function down() { Schema::table(config('follow.followable_table', 'followables'), function ($table) { $table->dropForeign(config('follow.followable_table', 'followables').'_user_id_foreign'); }); Schema::drop(config('follow.followable_table', 'followables')); }
[ "public", "function", "down", "(", ")", "{", "Schema", "::", "table", "(", "config", "(", "'follow.followable_table'", ",", "'followables'", ")", ",", "function", "(", "$", "table", ")", "{", "$", "table", "->", "dropForeign", "(", "config", "(", "'follow....
Reverse the migrations.
[ "Reverse", "the", "migrations", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/database/migrations/2018_06_29_032244_create_laravel_follow_tables.php#L42-L49
overtrue/laravel-follow
src/Traits/CanBeBookmarked.php
CanBeBookmarked.bookmarkers
public function bookmarkers() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_BOOKMARK) ->withPivot('followable_type', 'relation', 'created_at'); ...
php
public function bookmarkers() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_BOOKMARK) ->withPivot('followable_type', 'relation', 'created_at'); ...
[ "public", "function", "bookmarkers", "(", ")", "{", "return", "$", "this", "->", "morphToMany", "(", "config", "(", "'follow.user_model'", ")", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", "...
Return bookmarkers. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "bookmarkers", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeBookmarked.php#L38-L43
overtrue/laravel-follow
src/Traits/CanFavorite.php
CanFavorite.favorites
public function favorites($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_FAVORITE) ->withPivot('followable_type', 'relation', 'created_at'); ...
php
public function favorites($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_FAVORITE) ->withPivot('followable_type', 'relation', 'created_at'); ...
[ "public", "function", "favorites", "(", "$", "class", "=", "__CLASS__", ")", "{", "return", "$", "this", "->", "morphedByMany", "(", "$", "class", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "-...
Return item favorites. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "item", "favorites", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanFavorite.php#L80-L85
overtrue/laravel-follow
src/Traits/CanBeFollowed.php
CanBeFollowed.followers
public function followers() { $table = config('follow.followable_table'); $class = \get_class($this); $userTable = config('follow.users_table_name', 'users'); $foreignKey = config('follow.users_table_foreign_key', 'user_id'); $tablePrefixedForeignKey = app('db.connection')->g...
php
public function followers() { $table = config('follow.followable_table'); $class = \get_class($this); $userTable = config('follow.users_table_name', 'users'); $foreignKey = config('follow.users_table_foreign_key', 'user_id'); $tablePrefixedForeignKey = app('db.connection')->g...
[ "public", "function", "followers", "(", ")", "{", "$", "table", "=", "config", "(", "'follow.followable_table'", ")", ";", "$", "class", "=", "\\", "get_class", "(", "$", "this", ")", ";", "$", "userTable", "=", "config", "(", "'follow.users_table_name'", ...
Return followers. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "followers", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeFollowed.php#L39-L57
overtrue/laravel-follow
src/Traits/CanBeFavorited.php
CanBeFavorited.favoriters
public function favoriters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_FAVORITE) ->withPivot('followable_type', 'relation', 'created_at'); ...
php
public function favoriters() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_FAVORITE) ->withPivot('followable_type', 'relation', 'created_at'); ...
[ "public", "function", "favoriters", "(", ")", "{", "return", "$", "this", "->", "morphToMany", "(", "config", "(", "'follow.user_model'", ")", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", "w...
Return favoriters. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "favoriters", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeFavorited.php#L38-L43
overtrue/laravel-follow
src/Follow.php
Follow.isRelationExists
public static function isRelationExists(Model $model, $relation, $target, $class = null) { $target = self::formatTargets($target, $class ?: config('follow.user_model')); if ($model->relationLoaded($relation)) { return $model->{$relation}->where('id', head($target->ids))->isNotEmpty(); ...
php
public static function isRelationExists(Model $model, $relation, $target, $class = null) { $target = self::formatTargets($target, $class ?: config('follow.user_model')); if ($model->relationLoaded($relation)) { return $model->{$relation}->where('id', head($target->ids))->isNotEmpty(); ...
[ "public", "static", "function", "isRelationExists", "(", "Model", "$", "model", ",", "$", "relation", ",", "$", "target", ",", "$", "class", "=", "null", ")", "{", "$", "target", "=", "self", "::", "formatTargets", "(", "$", "target", ",", "$", "class"...
@param \Illuminate\Database\Eloquent\Model $model @param string $relation @param array|string|\Illuminate\Database\Eloquent\Model $target @param string $class @return bool
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$model", "@param", "string", "$relation", "@param", "array|string|", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$target", "@param", "string", "$class" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Follow.php#L73-L82
overtrue/laravel-follow
src/Follow.php
Follow.attachRelations
public static function attachRelations(Model $model, $relation, $targets, $class) { if (false === \event(new RelationAttaching($model, $relation, $targets, $class))) { return false; } $targets = self::attachPivotsFromRelation($model->{$relation}(), $targets, $class); if...
php
public static function attachRelations(Model $model, $relation, $targets, $class) { if (false === \event(new RelationAttaching($model, $relation, $targets, $class))) { return false; } $targets = self::attachPivotsFromRelation($model->{$relation}(), $targets, $class); if...
[ "public", "static", "function", "attachRelations", "(", "Model", "$", "model", ",", "$", "relation", ",", "$", "targets", ",", "$", "class", ")", "{", "if", "(", "false", "===", "\\", "event", "(", "new", "RelationAttaching", "(", "$", "model", ",", "$...
@param \Illuminate\Database\Eloquent\Model $model @param string $relation @param array|string|\Illuminate\Database\Eloquent\Model $targets @param string $class @throws \Exception @return array
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$model", "@param", "string", "$relation", "@param", "array|string|", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$targets", "@param", "string", "$class" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Follow.php#L94-L107
overtrue/laravel-follow
src/Follow.php
Follow.detachRelations
public static function detachRelations(Model $model, $relation, $targets, $class) { if (false === \event(new RelationDetaching($model, $relation, $targets, $class))) { return false; } $targets = self::formatTargets($targets, $class); if (false === \event(new RelationDet...
php
public static function detachRelations(Model $model, $relation, $targets, $class) { if (false === \event(new RelationDetaching($model, $relation, $targets, $class))) { return false; } $targets = self::formatTargets($targets, $class); if (false === \event(new RelationDet...
[ "public", "static", "function", "detachRelations", "(", "Model", "$", "model", ",", "$", "relation", ",", "$", "targets", ",", "$", "class", ")", "{", "if", "(", "false", "===", "\\", "event", "(", "new", "RelationDetaching", "(", "$", "model", ",", "$...
@param \Illuminate\Database\Eloquent\Model $model @param string $relation @param array|string|\Illuminate\Database\Eloquent\Model $targets @param string $class @return array
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$model", "@param", "string", "$relation", "@param", "array|string|", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$targets", "@param", "string", "$class" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Follow.php#L117-L130
overtrue/laravel-follow
src/Follow.php
Follow.toggleRelations
public static function toggleRelations(Model $model, $relation, $targets, $class) { if (false === \event(new RelationToggling($model, $relation, $targets, $class))) { return false; } $targets = self::attachPivotsFromRelation($model->{$relation}(), $targets, $class); $re...
php
public static function toggleRelations(Model $model, $relation, $targets, $class) { if (false === \event(new RelationToggling($model, $relation, $targets, $class))) { return false; } $targets = self::attachPivotsFromRelation($model->{$relation}(), $targets, $class); $re...
[ "public", "static", "function", "toggleRelations", "(", "Model", "$", "model", ",", "$", "relation", ",", "$", "targets", ",", "$", "class", ")", "{", "if", "(", "false", "===", "\\", "event", "(", "new", "RelationToggling", "(", "$", "model", ",", "$"...
@param \Illuminate\Database\Eloquent\Model $model @param string $relation @param array|string|\Illuminate\Database\Eloquent\Model $targets @param string $class @throws \Exception @return array
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$model", "@param", "string", "$relation", "@param", "array|string|", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$targets", "@param", "string", "$class" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Follow.php#L142-L157
overtrue/laravel-follow
src/Follow.php
Follow.attachPivotsFromRelation
public static function attachPivotsFromRelation(MorphToMany $morph, $targets, $class) { return self::formatTargets($targets, $class, [ 'relation' => self::getRelationTypeFromRelation($morph), 'created_at' => Carbon::now()->format(config('follow.date_format', 'Y-m-d H:i:s')), ...
php
public static function attachPivotsFromRelation(MorphToMany $morph, $targets, $class) { return self::formatTargets($targets, $class, [ 'relation' => self::getRelationTypeFromRelation($morph), 'created_at' => Carbon::now()->format(config('follow.date_format', 'Y-m-d H:i:s')), ...
[ "public", "static", "function", "attachPivotsFromRelation", "(", "MorphToMany", "$", "morph", ",", "$", "targets", ",", "$", "class", ")", "{", "return", "self", "::", "formatTargets", "(", "$", "targets", ",", "$", "class", ",", "[", "'relation'", "=>", "...
@param \Illuminate\Database\Eloquent\Relations\MorphToMany $morph @param array|string|\Illuminate\Database\Eloquent\Model $targets @param string $class @throws \Exception @return \stdClass
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "MorphToMany", "$morph", "@param", "array|string|", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$targets", "@param", "string", "$class" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Follow.php#L168-L174
overtrue/laravel-follow
src/Follow.php
Follow.formatTargets
public static function formatTargets($targets, $classname, array $update = []) { $result = new stdClass(); $result->classname = $classname; if (!is_array($targets)) { $targets = [$targets]; } $result->ids = array_map(function ($target) use ($result) { ...
php
public static function formatTargets($targets, $classname, array $update = []) { $result = new stdClass(); $result->classname = $classname; if (!is_array($targets)) { $targets = [$targets]; } $result->ids = array_map(function ($target) use ($result) { ...
[ "public", "static", "function", "formatTargets", "(", "$", "targets", ",", "$", "classname", ",", "array", "$", "update", "=", "[", "]", ")", "{", "$", "result", "=", "new", "stdClass", "(", ")", ";", "$", "result", "->", "classname", "=", "$", "clas...
@param array|string|\Illuminate\Database\Eloquent\Model $targets @param string $classname @param array $update @return \stdClass
[ "@param", "array|string|", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$targets", "@param", "string", "$classname", "@param", "array", "$update" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Follow.php#L183-L205
overtrue/laravel-follow
src/Follow.php
Follow.getRelationTypeFromRelation
protected static function getRelationTypeFromRelation(MorphToMany $relation) { if (!\array_key_exists($relation->getRelationName(), self::RELATION_TYPES)) { throw new \Exception('Invalid relation definition.'); } return self::RELATION_TYPES[$relation->getRelationName()]; }
php
protected static function getRelationTypeFromRelation(MorphToMany $relation) { if (!\array_key_exists($relation->getRelationName(), self::RELATION_TYPES)) { throw new \Exception('Invalid relation definition.'); } return self::RELATION_TYPES[$relation->getRelationName()]; }
[ "protected", "static", "function", "getRelationTypeFromRelation", "(", "MorphToMany", "$", "relation", ")", "{", "if", "(", "!", "\\", "array_key_exists", "(", "$", "relation", "->", "getRelationName", "(", ")", ",", "self", "::", "RELATION_TYPES", ")", ")", "...
@param \Illuminate\Database\Eloquent\Relations\MorphToMany $relation @throws \Exception @return array
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "MorphToMany", "$relation" ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Follow.php#L214-L221
overtrue/laravel-follow
src/Traits/CanFollow.php
CanFollow.areFollowingEachOther
public function areFollowingEachOther($target, $class = __CLASS__) { return Follow::isRelationExists($this, 'followings', $target, $class) && Follow::isRelationExists($target, 'followings', $this, $class); }
php
public function areFollowingEachOther($target, $class = __CLASS__) { return Follow::isRelationExists($this, 'followings', $target, $class) && Follow::isRelationExists($target, 'followings', $this, $class); }
[ "public", "function", "areFollowingEachOther", "(", "$", "target", ",", "$", "class", "=", "__CLASS__", ")", "{", "return", "Follow", "::", "isRelationExists", "(", "$", "this", ",", "'followings'", ",", "$", "target", ",", "$", "class", ")", "&&", "Follow...
Check if user and target user is following each other. @param int|array|\Illuminate\Database\Eloquent\Model $target @param string $class @return bool
[ "Check", "if", "user", "and", "target", "user", "is", "following", "each", "other", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanFollow.php#L86-L89
overtrue/laravel-follow
src/Traits/CanFollow.php
CanFollow.followings
public function followings($class = __CLASS__) { $table = config('follow.followable_table'); $foreignKey = config('follow.users_table_foreign_key', 'user_id'); $targetTable = (new $class())->getTable(); $tablePrefixedForeignKey = app('db.connection')->getQueryGrammar()->wrap(\sprintf...
php
public function followings($class = __CLASS__) { $table = config('follow.followable_table'); $foreignKey = config('follow.users_table_foreign_key', 'user_id'); $targetTable = (new $class())->getTable(); $tablePrefixedForeignKey = app('db.connection')->getQueryGrammar()->wrap(\sprintf...
[ "public", "function", "followings", "(", "$", "class", "=", "__CLASS__", ")", "{", "$", "table", "=", "config", "(", "'follow.followable_table'", ")", ";", "$", "foreignKey", "=", "config", "(", "'follow.users_table_foreign_key'", ",", "'user_id'", ")", ";", "...
Return item followings. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "item", "followings", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanFollow.php#L98-L115
overtrue/laravel-follow
src/Traits/CanVote.php
CanVote.vote
public function vote($targets, $type = 'upvote', $class = __CLASS__) { $this->cancelVote($targets); return Follow::attachRelations($this, str_plural($type), $targets, $class); }
php
public function vote($targets, $type = 'upvote', $class = __CLASS__) { $this->cancelVote($targets); return Follow::attachRelations($this, str_plural($type), $targets, $class); }
[ "public", "function", "vote", "(", "$", "targets", ",", "$", "type", "=", "'upvote'", ",", "$", "class", "=", "__CLASS__", ")", "{", "$", "this", "->", "cancelVote", "(", "$", "targets", ")", ";", "return", "Follow", "::", "attachRelations", "(", "$", ...
Vote an item or items. @param int|array|\Illuminate\Database\Eloquent\Model $targets @param string $type @param string $class @throws \Exception @return array
[ "Vote", "an", "item", "or", "items", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanVote.php#L32-L37
overtrue/laravel-follow
src/Traits/CanVote.php
CanVote.cancelVote
public function cancelVote($targets, $class = __CLASS__) { $this->hasUpvoted($targets) && Follow::detachRelations($this, 'upvotes', $targets, $class); $this->hasDownvoted($targets) && Follow::detachRelations($this, 'downvotes', $targets, $class); return $this; }
php
public function cancelVote($targets, $class = __CLASS__) { $this->hasUpvoted($targets) && Follow::detachRelations($this, 'upvotes', $targets, $class); $this->hasDownvoted($targets) && Follow::detachRelations($this, 'downvotes', $targets, $class); return $this; }
[ "public", "function", "cancelVote", "(", "$", "targets", ",", "$", "class", "=", "__CLASS__", ")", "{", "$", "this", "->", "hasUpvoted", "(", "$", "targets", ")", "&&", "Follow", "::", "detachRelations", "(", "$", "this", ",", "'upvotes'", ",", "$", "t...
Cancel vote for an item or items. @param int|array|\Illuminate\Database\Eloquent\Model $targets @param string $class @return \Overtrue\LaravelFollow\Traits\CanVote
[ "Cancel", "vote", "for", "an", "item", "or", "items", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanVote.php#L77-L83
overtrue/laravel-follow
src/Traits/CanVote.php
CanVote.votes
public function votes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivotIn('relation', [Follow::RELATION_UPVOTE, Follow::RELATION_DOWNVOTE]) ->withPivot('followable_type', 'relation'...
php
public function votes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivotIn('relation', [Follow::RELATION_UPVOTE, Follow::RELATION_DOWNVOTE]) ->withPivot('followable_type', 'relation'...
[ "public", "function", "votes", "(", "$", "class", "=", "__CLASS__", ")", "{", "return", "$", "this", "->", "morphedByMany", "(", "$", "class", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", ...
Return item votes. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "item", "votes", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanVote.php#L118-L123
overtrue/laravel-follow
src/Traits/CanVote.php
CanVote.upvotes
public function upvotes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_UPVOTE) ->withPivot('followable_type', 'relation', 'created_at'); }
php
public function upvotes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_UPVOTE) ->withPivot('followable_type', 'relation', 'created_at'); }
[ "public", "function", "upvotes", "(", "$", "class", "=", "__CLASS__", ")", "{", "return", "$", "this", "->", "morphedByMany", "(", "$", "class", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->"...
Return item upvotes. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "item", "upvotes", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanVote.php#L132-L137
overtrue/laravel-follow
src/Traits/CanVote.php
CanVote.downvotes
public function downvotes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE) ->withPivot('followable_type', 'relation', 'created_at'); ...
php
public function downvotes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE) ->withPivot('followable_type', 'relation', 'created_at'); ...
[ "public", "function", "downvotes", "(", "$", "class", "=", "__CLASS__", ")", "{", "return", "$", "this", "->", "morphedByMany", "(", "$", "class", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "-...
Return item downvotes. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "item", "downvotes", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanVote.php#L146-L151
overtrue/laravel-follow
src/FollowServiceProvider.php
FollowServiceProvider.boot
public function boot() { $this->publishes([ realpath(__DIR__.'/../config/follow.php') => config_path('follow.php'), ], 'config'); $this->publishes([ realpath(__DIR__.'/../database/migrations') => database_path('migrations'), ], 'migrations'); }
php
public function boot() { $this->publishes([ realpath(__DIR__.'/../config/follow.php') => config_path('follow.php'), ], 'config'); $this->publishes([ realpath(__DIR__.'/../database/migrations') => database_path('migrations'), ], 'migrations'); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "publishes", "(", "[", "realpath", "(", "__DIR__", ".", "'/../config/follow.php'", ")", "=>", "config_path", "(", "'follow.php'", ")", ",", "]", ",", "'config'", ")", ";", "$", "this", "->",...
Application bootstrap event.
[ "Application", "bootstrap", "event", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/FollowServiceProvider.php#L21-L30
overtrue/laravel-follow
src/Traits/CanBeLiked.php
CanBeLiked.likers
public function likers() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_LIKE) ->withPivot('followable_type', 'relation', 'created_at'); }
php
public function likers() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_LIKE) ->withPivot('followable_type', 'relation', 'created_at'); }
[ "public", "function", "likers", "(", ")", "{", "return", "$", "this", "->", "morphToMany", "(", "config", "(", "'follow.user_model'", ")", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", "where...
Return followers. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "followers", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeLiked.php#L38-L43
overtrue/laravel-follow
src/Traits/CanBeSubscribed.php
CanBeSubscribed.subscribers
public function subscribers() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_SUBSCRIBE) ->withPivot('followable_type', 'relation', 'created_at');...
php
public function subscribers() { return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_SUBSCRIBE) ->withPivot('followable_type', 'relation', 'created_at');...
[ "public", "function", "subscribers", "(", ")", "{", "return", "$", "this", "->", "morphToMany", "(", "config", "(", "'follow.user_model'", ")", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", "...
Return followers. @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "followers", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBeSubscribed.php#L38-L43
overtrue/laravel-follow
src/Traits/CanSubscribe.php
CanSubscribe.subscriptions
public function subscriptions($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_SUBSCRIBE) ->withPivot('followable_type', 'relation', 'created_at')...
php
public function subscriptions($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_SUBSCRIBE) ->withPivot('followable_type', 'relation', 'created_at')...
[ "public", "function", "subscriptions", "(", "$", "class", "=", "__CLASS__", ")", "{", "return", "$", "this", "->", "morphedByMany", "(", "$", "class", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", ...
Return user subscriptions. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "user", "subscriptions", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanSubscribe.php#L84-L89
overtrue/laravel-follow
src/Traits/CanBookmark.php
CanBookmark.bookmarks
public function bookmarks($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_BOOKMARK) ->withPivot('followable_type', 'relation', 'created_at'); ...
php
public function bookmarks($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_BOOKMARK) ->withPivot('followable_type', 'relation', 'created_at'); ...
[ "public", "function", "bookmarks", "(", "$", "class", "=", "__CLASS__", ")", "{", "return", "$", "this", "->", "morphedByMany", "(", "$", "class", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "-...
Return item bookmarks. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "item", "bookmarks", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanBookmark.php#L84-L89
overtrue/laravel-follow
src/Traits/CanLike.php
CanLike.likes
public function likes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_LIKE) ->withPivot('followable_type', 'relation', 'created_at'); }
php
public function likes($class = __CLASS__) { return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table')) ->wherePivot('relation', '=', Follow::RELATION_LIKE) ->withPivot('followable_type', 'relation', 'created_at'); }
[ "public", "function", "likes", "(", "$", "class", "=", "__CLASS__", ")", "{", "return", "$", "this", "->", "morphedByMany", "(", "$", "class", ",", "config", "(", "'follow.morph_prefix'", ")", ",", "config", "(", "'follow.followable_table'", ")", ")", "->", ...
Return item likes. @param string $class @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Return", "item", "likes", "." ]
train
https://github.com/overtrue/laravel-follow/blob/3a5b50f919415972870b2d543840343e3f3a6ad3/src/Traits/CanLike.php#L84-L89
ptrofimov/beanstalk_console
lib/Pheanstalk/Command/PauseTubeCommand.php
Pheanstalk_Command_PauseTubeCommand.parseResponse
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( '%s: tube %d does not exist.', $responseLine, $this->_tube )); } elseif ($responseLine == Pheanstalk_Response::...
php
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( '%s: tube %d does not exist.', $responseLine, $this->_tube )); } elseif ($responseLine == Pheanstalk_Response::...
[ "public", "function", "parseResponse", "(", "$", "responseLine", ",", "$", "responseData", ")", "{", "if", "(", "$", "responseLine", "==", "Pheanstalk_Response", "::", "RESPONSE_NOT_FOUND", ")", "{", "throw", "new", "Pheanstalk_Exception_ServerException", "(", "spri...
/* (non-phpdoc) @see Pheanstalk_ResponseParser::parseRespose()
[ "/", "*", "(", "non", "-", "phpdoc", ")" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/Command/PauseTubeCommand.php#L43-L61
ptrofimov/beanstalk_console
lib/Pheanstalk/Command/KickJobCommand.php
Pheanstalk_Command_KickJobCommand.parseResponse
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( '%s: Job %d does not exist or is not in a kickable state.', $responseLine, $this->_job->getId() ...
php
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( '%s: Job %d does not exist or is not in a kickable state.', $responseLine, $this->_job->getId() ...
[ "public", "function", "parseResponse", "(", "$", "responseLine", ",", "$", "responseData", ")", "{", "if", "(", "$", "responseLine", "==", "Pheanstalk_Response", "::", "RESPONSE_NOT_FOUND", ")", "{", "throw", "new", "Pheanstalk_Exception_ServerException", "(", "spri...
/* (non-phpdoc) @see Pheanstalk_ResponseParser::parseRespose()
[ "/", "*", "(", "non", "-", "phpdoc", ")" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/Command/KickJobCommand.php#L37-L48
ptrofimov/beanstalk_console
lib/Pheanstalk/Command/ReleaseCommand.php
Pheanstalk_Command_ReleaseCommand.parseResponse
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_BURIED) { throw new Pheanstalk_Exception_ServerException(sprintf( 'Job %s %d: out of memory trying to grow data structure', $this->_job->getId(), $responseLine )); } if ($response...
php
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_BURIED) { throw new Pheanstalk_Exception_ServerException(sprintf( 'Job %s %d: out of memory trying to grow data structure', $this->_job->getId(), $responseLine )); } if ($response...
[ "public", "function", "parseResponse", "(", "$", "responseLine", ",", "$", "responseData", ")", "{", "if", "(", "$", "responseLine", "==", "Pheanstalk_Response", "::", "RESPONSE_BURIED", ")", "{", "throw", "new", "Pheanstalk_Exception_ServerException", "(", "sprintf...
/* (non-phpdoc) @see Pheanstalk_ResponseParser::parseRespose()
[ "/", "*", "(", "non", "-", "phpdoc", ")" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/Command/ReleaseCommand.php#L47-L68
ptrofimov/beanstalk_console
lib/Pheanstalk/Command/BuryCommand.php
Pheanstalk_Command_BuryCommand.parseResponse
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( '%s: Job %d is not reserved or does not exist.', $responseLine, $this->_job->getId() )); } elseif ($responseLin...
php
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( '%s: Job %d is not reserved or does not exist.', $responseLine, $this->_job->getId() )); } elseif ($responseLin...
[ "public", "function", "parseResponse", "(", "$", "responseLine", ",", "$", "responseData", ")", "{", "if", "(", "$", "responseLine", "==", "Pheanstalk_Response", "::", "RESPONSE_NOT_FOUND", ")", "{", "throw", "new", "Pheanstalk_Exception_ServerException", "(", "spri...
/* (non-phpdoc) @see Pheanstalk_ResponseParser::parseRespose()
[ "/", "*", "(", "non", "-", "phpdoc", ")" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/Command/BuryCommand.php#L43-L61
ptrofimov/beanstalk_console
lib/Pheanstalk/Command/PutCommand.php
Pheanstalk_Command_PutCommand.getCommandLine
public function getCommandLine() { return sprintf( 'put %d %d %d %d', $this->_priority, $this->_delay, $this->_ttr, $this->getDataLength() ); }
php
public function getCommandLine() { return sprintf( 'put %d %d %d %d', $this->_priority, $this->_delay, $this->_ttr, $this->getDataLength() ); }
[ "public", "function", "getCommandLine", "(", ")", "{", "return", "sprintf", "(", "'put %d %d %d %d'", ",", "$", "this", "->", "_priority", ",", "$", "this", "->", "_delay", ",", "$", "this", "->", "_ttr", ",", "$", "this", "->", "getDataLength", "(", ")"...
/* (non-phpdoc) @see Pheanstalk_Command::getCommandLine()
[ "/", "*", "(", "non", "-", "phpdoc", ")" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/Command/PutCommand.php#L39-L48
ptrofimov/beanstalk_console
lib/Pheanstalk/Command/PutCommand.php
Pheanstalk_Command_PutCommand.parseResponse
public function parseResponse($responseLine, $responseData) { if (preg_match('#^INSERTED (\d+)$#', $responseLine, $matches)) { return $this->_createResponse('INSERTED', array( 'id' => (int)$matches[1] )); } elseif (preg_match('#^BURIED (\d)+$#', $responseLine, $matches)) { throw new Pheanstalk_E...
php
public function parseResponse($responseLine, $responseData) { if (preg_match('#^INSERTED (\d+)$#', $responseLine, $matches)) { return $this->_createResponse('INSERTED', array( 'id' => (int)$matches[1] )); } elseif (preg_match('#^BURIED (\d)+$#', $responseLine, $matches)) { throw new Pheanstalk_E...
[ "public", "function", "parseResponse", "(", "$", "responseLine", ",", "$", "responseData", ")", "{", "if", "(", "preg_match", "(", "'#^INSERTED (\\d+)$#'", ",", "$", "responseLine", ",", "$", "matches", ")", ")", "{", "return", "$", "this", "->", "_createRes...
/* (non-phpdoc) @see Pheanstalk_ResponseParser::parseRespose()
[ "/", "*", "(", "non", "-", "phpdoc", ")" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/Command/PutCommand.php#L77-L113
ptrofimov/beanstalk_console
lib/Pheanstalk/ClassLoader.php
Pheanstalk_ClassLoader.register
public static function register($path) { self::$_path = $path; self::addPath($path); if ($loaders = spl_autoload_functions()) array_map('spl_autoload_unregister', $loaders); else $loaders = function_exists('__autoload') ? array('__autoload') : array(); array_unshift($loaders, array(__CLASS__, 'load')...
php
public static function register($path) { self::$_path = $path; self::addPath($path); if ($loaders = spl_autoload_functions()) array_map('spl_autoload_unregister', $loaders); else $loaders = function_exists('__autoload') ? array('__autoload') : array(); array_unshift($loaders, array(__CLASS__, 'load')...
[ "public", "static", "function", "register", "(", "$", "path", ")", "{", "self", "::", "$", "_path", "=", "$", "path", ";", "self", "::", "addPath", "(", "$", "path", ")", ";", "if", "(", "$", "loaders", "=", "spl_autoload_functions", "(", ")", ")", ...
Registers Pheanstalk_ClassLoader as an SPL class loader. Inserts self first, retains existing loaders and __autoload() @param string $path Path to Pheanstalk classes directory
[ "Registers", "Pheanstalk_ClassLoader", "as", "an", "SPL", "class", "loader", ".", "Inserts", "self", "first", "retains", "existing", "loaders", "and", "__autoload", "()" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/ClassLoader.php#L22-L34
ptrofimov/beanstalk_console
lib/Pheanstalk/ClassLoader.php
Pheanstalk_ClassLoader.load
public static function load($class) { if (substr($class, 0, strlen(self::PACKAGE)) != self::PACKAGE) return false; $path = sprintf( '%s/%s.php', self::$_path, str_replace('_', '/', $class) ); if (file_exists($path)) require_once($path); }
php
public static function load($class) { if (substr($class, 0, strlen(self::PACKAGE)) != self::PACKAGE) return false; $path = sprintf( '%s/%s.php', self::$_path, str_replace('_', '/', $class) ); if (file_exists($path)) require_once($path); }
[ "public", "static", "function", "load", "(", "$", "class", ")", "{", "if", "(", "substr", "(", "$", "class", ",", "0", ",", "strlen", "(", "self", "::", "PACKAGE", ")", ")", "!=", "self", "::", "PACKAGE", ")", "return", "false", ";", "$", "path", ...
Attempts to load a Pheanstalk class file. @param string $class @see http://php.net/manual/en/function.spl-autoload-register.php
[ "Attempts", "to", "load", "a", "Pheanstalk", "class", "file", "." ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/ClassLoader.php#L42-L54
ptrofimov/beanstalk_console
lib/Pheanstalk/YamlResponseParser.php
Pheanstalk_YamlResponseParser.parseResponse
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( 'Server reported %s', $responseLine )); } if (!preg_match('#^OK \d+$#', $responseLine)) { throw new Pheanstal...
php
public function parseResponse($responseLine, $responseData) { if ($responseLine == Pheanstalk_Response::RESPONSE_NOT_FOUND) { throw new Pheanstalk_Exception_ServerException(sprintf( 'Server reported %s', $responseLine )); } if (!preg_match('#^OK \d+$#', $responseLine)) { throw new Pheanstal...
[ "public", "function", "parseResponse", "(", "$", "responseLine", ",", "$", "responseData", ")", "{", "if", "(", "$", "responseLine", "==", "Pheanstalk_Response", "::", "RESPONSE_NOT_FOUND", ")", "{", "throw", "new", "Pheanstalk_Exception_ServerException", "(", "spri...
/* (non-phpdoc) @see Pheanstalk_ResponseParser::parseRespose()
[ "/", "*", "(", "non", "-", "phpdoc", ")" ]
train
https://github.com/ptrofimov/beanstalk_console/blob/829dd83e920f76244a0a1b266b25bbca27c879a6/lib/Pheanstalk/YamlResponseParser.php#L31-L72