repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
stomp-php/stomp-php | src/Transport/Parser.php | Parser.extractFrameMeta | private function extractFrameMeta($source)
{
$headers = preg_split("/(\r?\n)+/", $source);
$this->command = array_shift($headers);
foreach ($headers as $header) {
$headerDetails = explode(':', $header, 2);
$name = $this->decodeHeaderValue($headerDetails[0]);
$value = isset($headerDetails[1]) ? $this->decodeHeaderValue($headerDetails[1]) : true;
if (!isset($this->headers[$name])) {
$this->headers[$name] = $value;
}
}
if (isset($this->headers['content-length'])) {
$this->expectedBodyLength = (int)$this->headers['content-length'];
}
} | php | private function extractFrameMeta($source)
{
$headers = preg_split("/(\r?\n)+/", $source);
$this->command = array_shift($headers);
foreach ($headers as $header) {
$headerDetails = explode(':', $header, 2);
$name = $this->decodeHeaderValue($headerDetails[0]);
$value = isset($headerDetails[1]) ? $this->decodeHeaderValue($headerDetails[1]) : true;
if (!isset($this->headers[$name])) {
$this->headers[$name] = $value;
}
}
if (isset($this->headers['content-length'])) {
$this->expectedBodyLength = (int)$this->headers['content-length'];
}
} | [
"private",
"function",
"extractFrameMeta",
"(",
"$",
"source",
")",
"{",
"$",
"headers",
"=",
"preg_split",
"(",
"\"/(\\r?\\n)+/\"",
",",
"$",
"source",
")",
";",
"$",
"this",
"->",
"command",
"=",
"array_shift",
"(",
"$",
"headers",
")",
";",
"foreach",
... | Extracts command and headers from given header source.
@param string $source
@return void | [
"Extracts",
"command",
"and",
"headers",
"from",
"given",
"header",
"source",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/Parser.php#L340-L358 | train |
stomp-php/stomp-php | src/Transport/Parser.php | Parser.flushBuffer | public function flushBuffer()
{
$this->expectedBodyLength = null;
$this->headers = [];
$this->mode = self::MODE_HEADER;
$currentBuffer = substr($this->buffer, $this->offset);
$this->offset = 0;
$this->bufferSize = 0;
$this->buffer = '';
return $currentBuffer;
} | php | public function flushBuffer()
{
$this->expectedBodyLength = null;
$this->headers = [];
$this->mode = self::MODE_HEADER;
$currentBuffer = substr($this->buffer, $this->offset);
$this->offset = 0;
$this->bufferSize = 0;
$this->buffer = '';
return $currentBuffer;
} | [
"public",
"function",
"flushBuffer",
"(",
")",
"{",
"$",
"this",
"->",
"expectedBodyLength",
"=",
"null",
";",
"$",
"this",
"->",
"headers",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"mode",
"=",
"self",
"::",
"MODE_HEADER",
";",
"$",
"currentBuffer",
"="... | Resets the current buffer within this parser and returns the flushed buffer value.
@return string | [
"Resets",
"the",
"current",
"buffer",
"within",
"this",
"parser",
"and",
"returns",
"the",
"flushed",
"buffer",
"value",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/Parser.php#L379-L390 | train |
stomp-php/stomp-php | src/Network/Observer/ConnectionObserverCollection.php | ConnectionObserverCollection.addObserver | public function addObserver(ConnectionObserver $observer)
{
if (!in_array($observer, $this->observers, true)) {
$this->observers[] = $observer;
}
return $this;
} | php | public function addObserver(ConnectionObserver $observer)
{
if (!in_array($observer, $this->observers, true)) {
$this->observers[] = $observer;
}
return $this;
} | [
"public",
"function",
"addObserver",
"(",
"ConnectionObserver",
"$",
"observer",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"observer",
",",
"$",
"this",
"->",
"observers",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"observers",
"[",
"]",
"=",... | Adds new observers to the collection.
@param ConnectionObserver $observer
@return ConnectionObserverCollection this collection | [
"Adds",
"new",
"observers",
"to",
"the",
"collection",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/ConnectionObserverCollection.php#L32-L38 | train |
stomp-php/stomp-php | src/Network/Observer/ConnectionObserverCollection.php | ConnectionObserverCollection.removeObserver | public function removeObserver(ConnectionObserver $observer)
{
$index = array_search($observer, $this->observers, true);
if ($index !== false) {
unset($this->observers[$index]);
}
return $this;
} | php | public function removeObserver(ConnectionObserver $observer)
{
$index = array_search($observer, $this->observers, true);
if ($index !== false) {
unset($this->observers[$index]);
}
return $this;
} | [
"public",
"function",
"removeObserver",
"(",
"ConnectionObserver",
"$",
"observer",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"observer",
",",
"$",
"this",
"->",
"observers",
",",
"true",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")... | Removes the observers from the collection.
@param ConnectionObserver $observer
@return ConnectionObserverCollection this collection | [
"Removes",
"the",
"observers",
"from",
"the",
"collection",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/ConnectionObserverCollection.php#L46-L53 | train |
stomp-php/stomp-php | src/Network/Observer/ConnectionObserverCollection.php | ConnectionObserverCollection.receivedFrame | public function receivedFrame(Frame $frame)
{
foreach ($this->observers as $item) {
$item->receivedFrame($frame);
}
} | php | public function receivedFrame(Frame $frame)
{
foreach ($this->observers as $item) {
$item->receivedFrame($frame);
}
} | [
"public",
"function",
"receivedFrame",
"(",
"Frame",
"$",
"frame",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"observers",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"receivedFrame",
"(",
"$",
"frame",
")",
";",
"}",
"}"
] | Indicates that a frame has been received.
@param Frame $frame that has been received
@return void | [
"Indicates",
"that",
"a",
"frame",
"has",
"been",
"received",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/ConnectionObserverCollection.php#L83-L88 | train |
stomp-php/stomp-php | src/Network/Observer/ConnectionObserverCollection.php | ConnectionObserverCollection.sentFrame | public function sentFrame(Frame $frame)
{
foreach ($this->observers as $item) {
$item->sentFrame($frame);
}
} | php | public function sentFrame(Frame $frame)
{
foreach ($this->observers as $item) {
$item->sentFrame($frame);
}
} | [
"public",
"function",
"sentFrame",
"(",
"Frame",
"$",
"frame",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"observers",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"sentFrame",
"(",
"$",
"frame",
")",
";",
"}",
"}"
] | Indicates that a frame has been transmitted.
@param Frame $frame
@return void | [
"Indicates",
"that",
"a",
"frame",
"has",
"been",
"transmitted",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/ConnectionObserverCollection.php#L96-L101 | train |
stomp-php/stomp-php | src/Broker/ActiveMq/Mode/DurableSubscription.php | DurableSubscription.activate | public function activate()
{
if (!$this->active) {
$this->client->sendFrame(
$this->getProtocol()->getSubscribeFrame(
$this->subscription->getDestination(),
$this->subscription->getSubscriptionId(),
$this->subscription->getAck(),
$this->subscription->getSelector(),
true
)->addHeaders(
$this->options->getOptions()
)
);
$this->active = true;
}
} | php | public function activate()
{
if (!$this->active) {
$this->client->sendFrame(
$this->getProtocol()->getSubscribeFrame(
$this->subscription->getDestination(),
$this->subscription->getSubscriptionId(),
$this->subscription->getAck(),
$this->subscription->getSelector(),
true
)->addHeaders(
$this->options->getOptions()
)
);
$this->active = true;
}
} | [
"public",
"function",
"activate",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"active",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getSubscribeFrame",
"(",
"$",
"this",
"->"... | Init the subscription.
@return void | [
"Init",
"the",
"subscription",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Broker/ActiveMq/Mode/DurableSubscription.php#L58-L74 | train |
stomp-php/stomp-php | src/Broker/ActiveMq/Mode/DurableSubscription.php | DurableSubscription.deactivate | public function deactivate()
{
if ($this->active) {
$this->inactive();
$this->client->sendFrame(
$this->getProtocol()
->getUnsubscribeFrame(
$this->subscription->getDestination(),
$this->subscription->getSubscriptionId(),
true
)
);
$this->active = false;
}
} | php | public function deactivate()
{
if ($this->active) {
$this->inactive();
$this->client->sendFrame(
$this->getProtocol()
->getUnsubscribeFrame(
$this->subscription->getDestination(),
$this->subscription->getSubscriptionId(),
true
)
);
$this->active = false;
}
} | [
"public",
"function",
"deactivate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"active",
")",
"{",
"$",
"this",
"->",
"inactive",
"(",
")",
";",
"$",
"this",
"->",
"client",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->"... | Permanently remove durable subscription.
@see inactive() if you just want to indicate that the consumer is offline now.
@return void | [
"Permanently",
"remove",
"durable",
"subscription",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Broker/ActiveMq/Mode/DurableSubscription.php#L102-L116 | train |
stomp-php/stomp-php | src/Util/IdGenerator.php | IdGenerator.generateId | public static function generateId()
{
while ($rand = rand(1, PHP_INT_MAX)) {
if (!in_array($rand, static::$generatedIds, true)) {
static::$generatedIds[] = $rand;
return $rand;
}
}
} | php | public static function generateId()
{
while ($rand = rand(1, PHP_INT_MAX)) {
if (!in_array($rand, static::$generatedIds, true)) {
static::$generatedIds[] = $rand;
return $rand;
}
}
} | [
"public",
"static",
"function",
"generateId",
"(",
")",
"{",
"while",
"(",
"$",
"rand",
"=",
"rand",
"(",
"1",
",",
"PHP_INT_MAX",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"rand",
",",
"static",
"::",
"$",
"generatedIds",
",",
"true",
"... | Generate a not used id.
@return int | [
"Generate",
"a",
"not",
"used",
"id",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Util/IdGenerator.php#L29-L37 | train |
stomp-php/stomp-php | src/Util/IdGenerator.php | IdGenerator.releaseId | public static function releaseId($generatedId)
{
$index = array_search($generatedId, static::$generatedIds, true);
if ($index !== false) {
unset(static::$generatedIds[$index]);
}
} | php | public static function releaseId($generatedId)
{
$index = array_search($generatedId, static::$generatedIds, true);
if ($index !== false) {
unset(static::$generatedIds[$index]);
}
} | [
"public",
"static",
"function",
"releaseId",
"(",
"$",
"generatedId",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"generatedId",
",",
"static",
"::",
"$",
"generatedIds",
",",
"true",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"... | Removes a previous generated id from currently used ids.
@param int $generatedId | [
"Removes",
"a",
"previous",
"generated",
"id",
"from",
"currently",
"used",
"ids",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Util/IdGenerator.php#L44-L50 | train |
stomp-php/stomp-php | src/States/Meta/SubscriptionList.php | SubscriptionList.getSubscription | public function getSubscription(Frame $frame)
{
foreach ($this->subscriptions as $subscription) {
if ($subscription->belongsTo($frame)) {
return $subscription;
}
}
return false;
} | php | public function getSubscription(Frame $frame)
{
foreach ($this->subscriptions as $subscription) {
if ($subscription->belongsTo($frame)) {
return $subscription;
}
}
return false;
} | [
"public",
"function",
"getSubscription",
"(",
"Frame",
"$",
"frame",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"subscriptions",
"as",
"$",
"subscription",
")",
"{",
"if",
"(",
"$",
"subscription",
"->",
"belongsTo",
"(",
"$",
"frame",
")",
")",
"{",
... | Returns the subscription the frame belongs to or false if no matching subscription was found.
@param Frame $frame
@return Subscription|false | [
"Returns",
"the",
"subscription",
"the",
"frame",
"belongs",
"to",
"or",
"false",
"if",
"no",
"matching",
"subscription",
"was",
"found",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/States/Meta/SubscriptionList.php#L47-L55 | train |
stomp-php/stomp-php | src/SimpleStomp.php | SimpleStomp.subscribe | public function subscribe($destination, $subscriptionId = null, $ack = 'auto', $selector = null, array $header = [])
{
return $this->client->sendFrame(
$this->getProtocol()->getSubscribeFrame($destination, $subscriptionId, $ack, $selector)->addHeaders($header)
);
} | php | public function subscribe($destination, $subscriptionId = null, $ack = 'auto', $selector = null, array $header = [])
{
return $this->client->sendFrame(
$this->getProtocol()->getSubscribeFrame($destination, $subscriptionId, $ack, $selector)->addHeaders($header)
);
} | [
"public",
"function",
"subscribe",
"(",
"$",
"destination",
",",
"$",
"subscriptionId",
"=",
"null",
",",
"$",
"ack",
"=",
"'auto'",
",",
"$",
"selector",
"=",
"null",
",",
"array",
"$",
"header",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",... | Register to listen to a given destination
@param string $destination Destination queue
@param null $subscriptionId
@param string $ack
@param string $selector
@param array $header
@return bool | [
"Register",
"to",
"listen",
"to",
"a",
"given",
"destination"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/SimpleStomp.php#L62-L67 | train |
stomp-php/stomp-php | src/SimpleStomp.php | SimpleStomp.unsubscribe | public function unsubscribe($destination, $subscriptionId = null, array $header = [])
{
return $this->client->sendFrame(
$this->getProtocol()->getUnsubscribeFrame($destination, $subscriptionId)->addHeaders($header)
);
} | php | public function unsubscribe($destination, $subscriptionId = null, array $header = [])
{
return $this->client->sendFrame(
$this->getProtocol()->getUnsubscribeFrame($destination, $subscriptionId)->addHeaders($header)
);
} | [
"public",
"function",
"unsubscribe",
"(",
"$",
"destination",
",",
"$",
"subscriptionId",
"=",
"null",
",",
"array",
"$",
"header",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
... | Remove an existing subscription
@param string $destination
@param string $subscriptionId
@param array $header
@return boolean
@throws StompException | [
"Remove",
"an",
"existing",
"subscription"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/SimpleStomp.php#L99-L104 | train |
stomp-php/stomp-php | src/SimpleStomp.php | SimpleStomp.commit | public function commit($transactionId = null)
{
return $this->client->sendFrame($this->getProtocol()->getCommitFrame($transactionId));
} | php | public function commit($transactionId = null)
{
return $this->client->sendFrame($this->getProtocol()->getCommitFrame($transactionId));
} | [
"public",
"function",
"commit",
"(",
"$",
"transactionId",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getCommitFrame",
"(",
"$",
"transactionId",
")",
")",
";",... | Commit a transaction in progress
@param string $transactionId
@return boolean
@throws StompException | [
"Commit",
"a",
"transaction",
"in",
"progress"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/SimpleStomp.php#L125-L128 | train |
stomp-php/stomp-php | src/SimpleStomp.php | SimpleStomp.abort | public function abort($transactionId = null)
{
return $this->client->sendFrame($this->getProtocol()->getAbortFrame($transactionId));
} | php | public function abort($transactionId = null)
{
return $this->client->sendFrame($this->getProtocol()->getAbortFrame($transactionId));
} | [
"public",
"function",
"abort",
"(",
"$",
"transactionId",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getAbortFrame",
"(",
"$",
"transactionId",
")",
")",
";",
... | Roll back a transaction in progress
@param string $transactionId
@return bool | [
"Roll",
"back",
"a",
"transaction",
"in",
"progress"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/SimpleStomp.php#L136-L139 | train |
stomp-php/stomp-php | src/States/ConsumerState.php | ConsumerState.endSubscription | protected function endSubscription($subscriptionId = null)
{
if (!$subscriptionId) {
$subscriptionId = $this->subscriptions->getLast()->getSubscriptionId();
}
if (!isset($this->subscriptions[$subscriptionId])) {
throw new InvalidArgumentException(sprintf('%s is no active subscription!', $subscriptionId));
}
$subscription = $this->subscriptions[$subscriptionId];
$this->getClient()->sendFrame(
$this->getProtocol()->getUnsubscribeFrame(
$subscription->getDestination(),
$subscription->getSubscriptionId()
)
);
IdGenerator::releaseId($subscription->getSubscriptionId());
unset($this->subscriptions[$subscription->getSubscriptionId()]);
if ($this->subscriptions->count() == 0) {
return true;
}
return false;
} | php | protected function endSubscription($subscriptionId = null)
{
if (!$subscriptionId) {
$subscriptionId = $this->subscriptions->getLast()->getSubscriptionId();
}
if (!isset($this->subscriptions[$subscriptionId])) {
throw new InvalidArgumentException(sprintf('%s is no active subscription!', $subscriptionId));
}
$subscription = $this->subscriptions[$subscriptionId];
$this->getClient()->sendFrame(
$this->getProtocol()->getUnsubscribeFrame(
$subscription->getDestination(),
$subscription->getSubscriptionId()
)
);
IdGenerator::releaseId($subscription->getSubscriptionId());
unset($this->subscriptions[$subscription->getSubscriptionId()]);
if ($this->subscriptions->count() == 0) {
return true;
}
return false;
} | [
"protected",
"function",
"endSubscription",
"(",
"$",
"subscriptionId",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"subscriptionId",
")",
"{",
"$",
"subscriptionId",
"=",
"$",
"this",
"->",
"subscriptions",
"->",
"getLast",
"(",
")",
"->",
"getSubscriptionI... | Closes given subscription or last opened.
@param string $subscriptionId
@return bool true if last one was closed | [
"Closes",
"given",
"subscription",
"or",
"last",
"opened",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/States/ConsumerState.php#L140-L163 | train |
stomp-php/stomp-php | src/Client.php | Client.getConnectedFrame | private function getConnectedFrame()
{
$deadline = microtime(true) + $this->getConnection()->getConnectTimeout();
do {
if ($frame = $this->connection->readFrame()) {
return $frame;
}
} while (microtime(true) <= $deadline);
return null;
} | php | private function getConnectedFrame()
{
$deadline = microtime(true) + $this->getConnection()->getConnectTimeout();
do {
if ($frame = $this->connection->readFrame()) {
return $frame;
}
} while (microtime(true) <= $deadline);
return null;
} | [
"private",
"function",
"getConnectedFrame",
"(",
")",
"{",
"$",
"deadline",
"=",
"microtime",
"(",
"true",
")",
"+",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"getConnectTimeout",
"(",
")",
";",
"do",
"{",
"if",
"(",
"$",
"frame",
"=",
"$",
... | Returns the next available frame from the connection, respecting the connect timeout.
@return null|Frame
@throws ConnectionException
@throws Exception\ErrorFrameException | [
"Returns",
"the",
"next",
"available",
"frame",
"from",
"the",
"connection",
"respecting",
"the",
"connect",
"timeout",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Client.php#L244-L254 | train |
stomp-php/stomp-php | src/Client.php | Client.send | public function send($destination, $msg, array $header = [], $sync = null)
{
if (!$msg instanceof Frame) {
return $this->send($destination, new Frame('SEND', $header, $msg), [], $sync);
}
$msg->addHeaders($header);
$msg['destination'] = $destination;
return $this->sendFrame($msg, $sync);
} | php | public function send($destination, $msg, array $header = [], $sync = null)
{
if (!$msg instanceof Frame) {
return $this->send($destination, new Frame('SEND', $header, $msg), [], $sync);
}
$msg->addHeaders($header);
$msg['destination'] = $destination;
return $this->sendFrame($msg, $sync);
} | [
"public",
"function",
"send",
"(",
"$",
"destination",
",",
"$",
"msg",
",",
"array",
"$",
"header",
"=",
"[",
"]",
",",
"$",
"sync",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"msg",
"instanceof",
"Frame",
")",
"{",
"return",
"$",
"this",
"->",... | Send a message to a destination in the messaging system
@param string $destination Destination queue
@param string|Frame $msg Message
@param array $header
@param boolean $sync Perform request synchronously
@return boolean | [
"Send",
"a",
"message",
"to",
"a",
"destination",
"in",
"the",
"messaging",
"system"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Client.php#L265-L274 | train |
stomp-php/stomp-php | src/Client.php | Client.sendFrame | public function sendFrame(Frame $frame, $sync = null)
{
if (!$this->isConnecting && !$this->isConnected()) {
$this->connect();
}
// determine if client was configured to write sync or not
$writeSync = $sync !== null ? $sync : $this->sync;
if ($writeSync) {
return $this->sendFrameExpectingReceipt($frame);
} else {
return $this->connection->writeFrame($frame);
}
} | php | public function sendFrame(Frame $frame, $sync = null)
{
if (!$this->isConnecting && !$this->isConnected()) {
$this->connect();
}
// determine if client was configured to write sync or not
$writeSync = $sync !== null ? $sync : $this->sync;
if ($writeSync) {
return $this->sendFrameExpectingReceipt($frame);
} else {
return $this->connection->writeFrame($frame);
}
} | [
"public",
"function",
"sendFrame",
"(",
"Frame",
"$",
"frame",
",",
"$",
"sync",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isConnecting",
"&&",
"!",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"$",
"this",
"->",
"connect"... | Send a frame.
@param Frame $frame
@param boolean $sync
@return boolean | [
"Send",
"a",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Client.php#L283-L295 | train |
stomp-php/stomp-php | src/Client.php | Client.sendFrameExpectingReceipt | protected function sendFrameExpectingReceipt(Frame $stompFrame)
{
$receipt = md5(microtime());
$stompFrame['receipt'] = $receipt;
$this->connection->writeFrame($stompFrame);
return $this->waitForReceipt($receipt);
} | php | protected function sendFrameExpectingReceipt(Frame $stompFrame)
{
$receipt = md5(microtime());
$stompFrame['receipt'] = $receipt;
$this->connection->writeFrame($stompFrame);
return $this->waitForReceipt($receipt);
} | [
"protected",
"function",
"sendFrameExpectingReceipt",
"(",
"Frame",
"$",
"stompFrame",
")",
"{",
"$",
"receipt",
"=",
"md5",
"(",
"microtime",
"(",
")",
")",
";",
"$",
"stompFrame",
"[",
"'receipt'",
"]",
"=",
"$",
"receipt",
";",
"$",
"this",
"->",
"con... | Write frame to server and expect an matching receipt frame
@param Frame $stompFrame
@return bool | [
"Write",
"frame",
"to",
"server",
"and",
"expect",
"an",
"matching",
"receipt",
"frame"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Client.php#L304-L310 | train |
stomp-php/stomp-php | src/Client.php | Client.waitForReceipt | protected function waitForReceipt($receipt)
{
$stopAfter = $this->calculateReceiptWaitEnd();
while (true) {
if ($frame = $this->connection->readFrame()) {
if ($frame->getCommand() == 'RECEIPT') {
if ($frame['receipt-id'] == $receipt) {
return true;
} else {
throw new UnexpectedResponseException($frame, sprintf('Expected receipt id %s', $receipt));
}
} else {
$this->unprocessedFrames[] = $frame;
}
}
if (microtime(true) >= $stopAfter) {
break;
}
}
throw new MissingReceiptException($receipt);
} | php | protected function waitForReceipt($receipt)
{
$stopAfter = $this->calculateReceiptWaitEnd();
while (true) {
if ($frame = $this->connection->readFrame()) {
if ($frame->getCommand() == 'RECEIPT') {
if ($frame['receipt-id'] == $receipt) {
return true;
} else {
throw new UnexpectedResponseException($frame, sprintf('Expected receipt id %s', $receipt));
}
} else {
$this->unprocessedFrames[] = $frame;
}
}
if (microtime(true) >= $stopAfter) {
break;
}
}
throw new MissingReceiptException($receipt);
} | [
"protected",
"function",
"waitForReceipt",
"(",
"$",
"receipt",
")",
"{",
"$",
"stopAfter",
"=",
"$",
"this",
"->",
"calculateReceiptWaitEnd",
"(",
")",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"$",
"frame",
"=",
"$",
"this",
"->",
"connection",
... | Wait for an receipt
@param string $receipt
@return boolean
@throws UnexpectedResponseException If response has an invalid receipt.
@throws MissingReceiptException If no receipt is received. | [
"Wait",
"for",
"an",
"receipt"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Client.php#L321-L341 | train |
stomp-php/stomp-php | src/Client.php | Client.disconnect | public function disconnect($sync = false)
{
try {
if ($this->connection && $this->connection->isConnected()) {
if ($this->protocol) {
$this->sendFrame($this->protocol->getDisconnectFrame(), $sync);
}
}
} catch (StompException $ex) {
// nothing!
}
if ($this->connection) {
$this->connection->disconnect();
}
$this->sessionId = null;
$this->unprocessedFrames = [];
$this->protocol = null;
$this->isConnecting = false;
} | php | public function disconnect($sync = false)
{
try {
if ($this->connection && $this->connection->isConnected()) {
if ($this->protocol) {
$this->sendFrame($this->protocol->getDisconnectFrame(), $sync);
}
}
} catch (StompException $ex) {
// nothing!
}
if ($this->connection) {
$this->connection->disconnect();
}
$this->sessionId = null;
$this->unprocessedFrames = [];
$this->protocol = null;
$this->isConnecting = false;
} | [
"public",
"function",
"disconnect",
"(",
"$",
"sync",
"=",
"false",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"connection",
"&&",
"$",
"this",
"->",
"connection",
"->",
"isConnected",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pro... | Graceful disconnect from the server
@param bool $sync
@return void | [
"Graceful",
"disconnect",
"from",
"the",
"server"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Client.php#L369-L388 | train |
stomp-php/stomp-php | src/States/TransactionsTrait.php | TransactionsTrait.initTransaction | protected function initTransaction(array $options = [])
{
if (!isset($options['transactionId'])) {
$this->transactionId = IdGenerator::generateId();
$this->getClient()->sendFrame(
$this->getProtocol()->getBeginFrame($this->transactionId)
);
} else {
$this->transactionId = $options['transactionId'];
}
} | php | protected function initTransaction(array $options = [])
{
if (!isset($options['transactionId'])) {
$this->transactionId = IdGenerator::generateId();
$this->getClient()->sendFrame(
$this->getProtocol()->getBeginFrame($this->transactionId)
);
} else {
$this->transactionId = $options['transactionId'];
}
} | [
"protected",
"function",
"initTransaction",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'transactionId'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"transactionId",
"=",
"IdGenerator",
"::",
"... | Init the transaction state.
@param array $options | [
"Init",
"the",
"transaction",
"state",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/States/TransactionsTrait.php#L48-L58 | train |
stomp-php/stomp-php | src/States/TransactionsTrait.php | TransactionsTrait.send | public function send($destination, Message $message)
{
return $this->getClient()->send($destination, $message, ['transaction' => $this->transactionId], false);
} | php | public function send($destination, Message $message)
{
return $this->getClient()->send($destination, $message, ['transaction' => $this->transactionId], false);
} | [
"public",
"function",
"send",
"(",
"$",
"destination",
",",
"Message",
"$",
"message",
")",
"{",
"return",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"send",
"(",
"$",
"destination",
",",
"$",
"message",
",",
"[",
"'transaction'",
"=>",
"$",
"this... | Send a message within this transaction.
@param string $destination
@param \Stomp\Transport\Message $message
@return bool | [
"Send",
"a",
"message",
"within",
"this",
"transaction",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/States/TransactionsTrait.php#L77-L80 | train |
stomp-php/stomp-php | src/States/TransactionsTrait.php | TransactionsTrait.transactionCommit | protected function transactionCommit()
{
$this->getClient()->sendFrame($this->getProtocol()->getCommitFrame($this->transactionId));
IdGenerator::releaseId($this->transactionId);
} | php | protected function transactionCommit()
{
$this->getClient()->sendFrame($this->getProtocol()->getCommitFrame($this->transactionId));
IdGenerator::releaseId($this->transactionId);
} | [
"protected",
"function",
"transactionCommit",
"(",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getCommitFrame",
"(",
"$",
"this",
"->",
"transactionId",
")",
")",
";",
"Id... | Commit current transaction. | [
"Commit",
"current",
"transaction",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/States/TransactionsTrait.php#L85-L89 | train |
stomp-php/stomp-php | src/States/TransactionsTrait.php | TransactionsTrait.transactionAbort | protected function transactionAbort()
{
$this->getClient()->sendFrame($this->getProtocol()->getAbortFrame($this->transactionId));
IdGenerator::releaseId($this->transactionId);
} | php | protected function transactionAbort()
{
$this->getClient()->sendFrame($this->getProtocol()->getAbortFrame($this->transactionId));
IdGenerator::releaseId($this->transactionId);
} | [
"protected",
"function",
"transactionAbort",
"(",
")",
"{",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
"(",
")",
"->",
"getAbortFrame",
"(",
"$",
"this",
"->",
"transactionId",
")",
")",
";",
"IdGe... | Abort the current transaction. | [
"Abort",
"the",
"current",
"transaction",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/States/TransactionsTrait.php#L94-L98 | train |
stomp-php/stomp-php | src/StatefulStomp.php | StatefulStomp.subscribe | public function subscribe($destination, $selector = null, $ack = 'auto', array $header = [])
{
return $this->state->subscribe($destination, $selector, $ack, $header);
} | php | public function subscribe($destination, $selector = null, $ack = 'auto', array $header = [])
{
return $this->state->subscribe($destination, $selector, $ack, $header);
} | [
"public",
"function",
"subscribe",
"(",
"$",
"destination",
",",
"$",
"selector",
"=",
"null",
",",
"$",
"ack",
"=",
"'auto'",
",",
"array",
"$",
"header",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"state",
"->",
"subscribe",
"(",
"$",
... | Subscribe to given destination.
Returns the subscriptionId used for this.
@param string $destination
@param string $selector
@param string $ack
@param array $header
@return int | [
"Subscribe",
"to",
"given",
"destination",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/StatefulStomp.php#L129-L132 | train |
stomp-php/stomp-php | src/Network/Observer/AbstractBeats.php | AbstractBeats.isDelayed | public function isDelayed()
{
if ($this->enabled && $this->lastbeat) {
$now = microtime(true);
return ($now - $this->lastbeat > $this->intervalUsed);
}
return false;
} | php | public function isDelayed()
{
if ($this->enabled && $this->lastbeat) {
$now = microtime(true);
return ($now - $this->lastbeat > $this->intervalUsed);
}
return false;
} | [
"public",
"function",
"isDelayed",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
"&&",
"$",
"this",
"->",
"lastbeat",
")",
"{",
"$",
"now",
"=",
"microtime",
"(",
"true",
")",
";",
"return",
"(",
"$",
"now",
"-",
"$",
"this",
"->",
"las... | Returns if the emitter is in a state that indicates a delay.
@return bool | [
"Returns",
"if",
"the",
"emitter",
"is",
"in",
"a",
"state",
"that",
"indicates",
"a",
"delay",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/AbstractBeats.php#L128-L135 | train |
stomp-php/stomp-php | src/Network/Observer/AbstractBeats.php | AbstractBeats.enable | private function enable(Frame $frame)
{
$this->onHeartbeatFrame($frame, $this->getHeartbeats($frame));
if ($this->intervalServer && $this->intervalClient) {
$intervalAgreement = $this->calculateInterval(max($this->intervalClient, $this->intervalServer));
$this->intervalUsed = $intervalAgreement / 1000; // milli to micro
if ($intervalAgreement) {
$this->enabled = true;
$this->rememberActivity();
}
}
} | php | private function enable(Frame $frame)
{
$this->onHeartbeatFrame($frame, $this->getHeartbeats($frame));
if ($this->intervalServer && $this->intervalClient) {
$intervalAgreement = $this->calculateInterval(max($this->intervalClient, $this->intervalServer));
$this->intervalUsed = $intervalAgreement / 1000; // milli to micro
if ($intervalAgreement) {
$this->enabled = true;
$this->rememberActivity();
}
}
} | [
"private",
"function",
"enable",
"(",
"Frame",
"$",
"frame",
")",
"{",
"$",
"this",
"->",
"onHeartbeatFrame",
"(",
"$",
"frame",
",",
"$",
"this",
"->",
"getHeartbeats",
"(",
"$",
"frame",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"intervalServer",
... | Enables the delay detection when preconditions are fulfilled.
@param Frame $frame
@return void | [
"Enables",
"the",
"delay",
"detection",
"when",
"preconditions",
"are",
"fulfilled",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/AbstractBeats.php#L190-L201 | train |
WildSideUK/Laravel-Userstamps | src/Listeners/Creating.php | Creating.handle | public function handle($model)
{
if (! $model -> isUserstamping()) {
return;
}
if (is_null($model -> {$model -> getCreatedByColumn()})) {
$model -> {$model -> getCreatedByColumn()} = auth() -> id();
}
if (is_null($model -> {$model -> getUpdatedByColumn()}) && ! is_null($model -> getUpdatedByColumn())) {
$model -> {$model -> getUpdatedByColumn()} = auth() -> id();
}
} | php | public function handle($model)
{
if (! $model -> isUserstamping()) {
return;
}
if (is_null($model -> {$model -> getCreatedByColumn()})) {
$model -> {$model -> getCreatedByColumn()} = auth() -> id();
}
if (is_null($model -> {$model -> getUpdatedByColumn()}) && ! is_null($model -> getUpdatedByColumn())) {
$model -> {$model -> getUpdatedByColumn()} = auth() -> id();
}
} | [
"public",
"function",
"handle",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"->",
"isUserstamping",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"model",
"->",
"{",
"$",
"model",
"->",
"getCreatedByColumn",
... | When the model is being created.
@param Illuminate\Database\Eloquent $model
@return void | [
"When",
"the",
"model",
"is",
"being",
"created",
"."
] | 3323b14931d11f3b1a66ca94c5ab82cbc69e792a | https://github.com/WildSideUK/Laravel-Userstamps/blob/3323b14931d11f3b1a66ca94c5ab82cbc69e792a/src/Listeners/Creating.php#L13-L26 | train |
WildSideUK/Laravel-Userstamps | src/Listeners/Deleting.php | Deleting.handle | public function handle($model)
{
if (! $model -> isUserstamping()) {
return;
}
if (is_null($model -> {$model -> getDeletedByColumn()})) {
$model -> {$model -> getDeletedByColumn()} = auth() -> id();
}
$dispatcher = $model -> getEventDispatcher();
$model -> unsetEventDispatcher();
$model -> save();
$model -> setEventDispatcher($dispatcher);
} | php | public function handle($model)
{
if (! $model -> isUserstamping()) {
return;
}
if (is_null($model -> {$model -> getDeletedByColumn()})) {
$model -> {$model -> getDeletedByColumn()} = auth() -> id();
}
$dispatcher = $model -> getEventDispatcher();
$model -> unsetEventDispatcher();
$model -> save();
$model -> setEventDispatcher($dispatcher);
} | [
"public",
"function",
"handle",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"->",
"isUserstamping",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"model",
"->",
"{",
"$",
"model",
"->",
"getDeletedByColumn",
... | When the model is being deleted.
@param Illuminate\Database\Eloquent $model
@return void | [
"When",
"the",
"model",
"is",
"being",
"deleted",
"."
] | 3323b14931d11f3b1a66ca94c5ab82cbc69e792a | https://github.com/WildSideUK/Laravel-Userstamps/blob/3323b14931d11f3b1a66ca94c5ab82cbc69e792a/src/Listeners/Deleting.php#L13-L30 | train |
WildSideUK/Laravel-Userstamps | src/Userstamps.php | Userstamps.getUserClass | protected function getUserClass()
{
if (get_class(auth()) === 'Illuminate\Auth\Guard') {
return auth() -> getProvider() -> getModel();
}
return auth() -> guard() -> getProvider() -> getModel();
} | php | protected function getUserClass()
{
if (get_class(auth()) === 'Illuminate\Auth\Guard') {
return auth() -> getProvider() -> getModel();
}
return auth() -> guard() -> getProvider() -> getModel();
} | [
"protected",
"function",
"getUserClass",
"(",
")",
"{",
"if",
"(",
"get_class",
"(",
"auth",
"(",
")",
")",
"===",
"'Illuminate\\Auth\\Guard'",
")",
"{",
"return",
"auth",
"(",
")",
"->",
"getProvider",
"(",
")",
"->",
"getModel",
"(",
")",
";",
"}",
"... | Get the class being used to provide a User.
@return string | [
"Get",
"the",
"class",
"being",
"used",
"to",
"provide",
"a",
"User",
"."
] | 3323b14931d11f3b1a66ca94c5ab82cbc69e792a | https://github.com/WildSideUK/Laravel-Userstamps/blob/3323b14931d11f3b1a66ca94c5ab82cbc69e792a/src/Userstamps.php#L145-L152 | train |
WildSideUK/Laravel-Userstamps | src/Listeners/Updating.php | Updating.handle | public function handle($model)
{
if (! $model -> isUserstamping() || is_null($model -> getUpdatedByColumn())) {
return;
}
$model -> {$model -> getUpdatedByColumn()} = auth() -> id();
} | php | public function handle($model)
{
if (! $model -> isUserstamping() || is_null($model -> getUpdatedByColumn())) {
return;
}
$model -> {$model -> getUpdatedByColumn()} = auth() -> id();
} | [
"public",
"function",
"handle",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"->",
"isUserstamping",
"(",
")",
"||",
"is_null",
"(",
"$",
"model",
"->",
"getUpdatedByColumn",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"model",
... | When the model is being updated.
@param Illuminate\Database\Eloquent $model
@return void | [
"When",
"the",
"model",
"is",
"being",
"updated",
"."
] | 3323b14931d11f3b1a66ca94c5ab82cbc69e792a | https://github.com/WildSideUK/Laravel-Userstamps/blob/3323b14931d11f3b1a66ca94c5ab82cbc69e792a/src/Listeners/Updating.php#L13-L20 | train |
friends-of-reactphp/mysql | src/Io/Query.php | Query.getSql | public function getSql()
{
if ($this->builtSql === null) {
$this->builtSql = $this->buildSql();
}
return $this->builtSql;
} | php | public function getSql()
{
if ($this->builtSql === null) {
$this->builtSql = $this->buildSql();
}
return $this->builtSql;
} | [
"public",
"function",
"getSql",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"builtSql",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"builtSql",
"=",
"$",
"this",
"->",
"buildSql",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"builtSql",
";",
... | Get the constructed and escaped sql string.
@return string | [
"Get",
"the",
"constructed",
"and",
"escaped",
"sql",
"string",
"."
] | c420ca0d199f2867854508473f5eccecbcb692f1 | https://github.com/friends-of-reactphp/mysql/blob/c420ca0d199f2867854508473f5eccecbcb692f1/src/Io/Query.php#L190-L197 | train |
friends-of-reactphp/mysql | src/Io/Buffer.php | Buffer.prepend | public function prepend($str)
{
$this->buffer = $str . \substr($this->buffer, $this->bufferPos);
$this->bufferPos = 0;
} | php | public function prepend($str)
{
$this->buffer = $str . \substr($this->buffer, $this->bufferPos);
$this->bufferPos = 0;
} | [
"public",
"function",
"prepend",
"(",
"$",
"str",
")",
"{",
"$",
"this",
"->",
"buffer",
"=",
"$",
"str",
".",
"\\",
"substr",
"(",
"$",
"this",
"->",
"buffer",
",",
"$",
"this",
"->",
"bufferPos",
")",
";",
"$",
"this",
"->",
"bufferPos",
"=",
"... | prepends some data to start of buffer and resets buffer position to start
@param string $str
@return void | [
"prepends",
"some",
"data",
"to",
"start",
"of",
"buffer",
"and",
"resets",
"buffer",
"position",
"to",
"start"
] | c420ca0d199f2867854508473f5eccecbcb692f1 | https://github.com/friends-of-reactphp/mysql/blob/c420ca0d199f2867854508473f5eccecbcb692f1/src/Io/Buffer.php#L29-L33 | train |
friends-of-reactphp/mysql | src/Io/Buffer.php | Buffer.read | public function read($len)
{
// happy path to return empty string for zero length string
if ($len === 0) {
return '';
}
// happy path for single byte strings without using substrings
if ($len === 1 && isset($this->buffer[$this->bufferPos])) {
return $this->buffer[$this->bufferPos++];
}
// ensure buffer size contains $len bytes by checking target buffer position
if ($len < 0 || !isset($this->buffer[$this->bufferPos + $len - 1])) {
throw new \LogicException('Not enough data in buffer to read ' . $len . ' bytes');
}
$buffer = \substr($this->buffer, $this->bufferPos, $len);
$this->bufferPos += $len;
return $buffer;
} | php | public function read($len)
{
// happy path to return empty string for zero length string
if ($len === 0) {
return '';
}
// happy path for single byte strings without using substrings
if ($len === 1 && isset($this->buffer[$this->bufferPos])) {
return $this->buffer[$this->bufferPos++];
}
// ensure buffer size contains $len bytes by checking target buffer position
if ($len < 0 || !isset($this->buffer[$this->bufferPos + $len - 1])) {
throw new \LogicException('Not enough data in buffer to read ' . $len . ' bytes');
}
$buffer = \substr($this->buffer, $this->bufferPos, $len);
$this->bufferPos += $len;
return $buffer;
} | [
"public",
"function",
"read",
"(",
"$",
"len",
")",
"{",
"// happy path to return empty string for zero length string",
"if",
"(",
"$",
"len",
"===",
"0",
")",
"{",
"return",
"''",
";",
"}",
"// happy path for single byte strings without using substrings",
"if",
"(",
... | Reads binary string data with given byte length from buffer
@param int $len length in bytes, must be positive or zero
@return string
@throws \LogicException | [
"Reads",
"binary",
"string",
"data",
"with",
"given",
"byte",
"length",
"from",
"buffer"
] | c420ca0d199f2867854508473f5eccecbcb692f1 | https://github.com/friends-of-reactphp/mysql/blob/c420ca0d199f2867854508473f5eccecbcb692f1/src/Io/Buffer.php#L42-L62 | train |
friends-of-reactphp/mysql | src/Io/Buffer.php | Buffer.skip | public function skip($len)
{
if ($len < 1 || !isset($this->buffer[$this->bufferPos + $len - 1])) {
throw new \LogicException('Not enough data in buffer');
}
$this->bufferPos += $len;
} | php | public function skip($len)
{
if ($len < 1 || !isset($this->buffer[$this->bufferPos + $len - 1])) {
throw new \LogicException('Not enough data in buffer');
}
$this->bufferPos += $len;
} | [
"public",
"function",
"skip",
"(",
"$",
"len",
")",
"{",
"if",
"(",
"$",
"len",
"<",
"1",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"bufferPos",
"+",
"$",
"len",
"-",
"1",
"]",
")",
")",
"{",
"throw",
"new"... | Skips binary string data with given byte length from buffer
This method can be used instead of `read()` if you do not care about the
bytes that will be skipped.
@param int $len length in bytes, must be positve and non-zero
@return void
@throws \LogicException | [
"Skips",
"binary",
"string",
"data",
"with",
"given",
"byte",
"length",
"from",
"buffer"
] | c420ca0d199f2867854508473f5eccecbcb692f1 | https://github.com/friends-of-reactphp/mysql/blob/c420ca0d199f2867854508473f5eccecbcb692f1/src/Io/Buffer.php#L74-L80 | train |
friends-of-reactphp/mysql | src/Io/Buffer.php | Buffer.trim | public function trim()
{
if (!isset($this->buffer[$this->bufferPos])) {
$this->buffer = '';
} else {
$this->buffer = \substr($this->buffer, $this->bufferPos);
}
$this->bufferPos = 0;
} | php | public function trim()
{
if (!isset($this->buffer[$this->bufferPos])) {
$this->buffer = '';
} else {
$this->buffer = \substr($this->buffer, $this->bufferPos);
}
$this->bufferPos = 0;
} | [
"public",
"function",
"trim",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"bufferPos",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buffer",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"this",
"->",
... | Clears all consumed data from the buffer
This class keeps consumed data in memory for performance reasons and only
advances the internal buffer position until this method is called.
@return void | [
"Clears",
"all",
"consumed",
"data",
"from",
"the",
"buffer"
] | c420ca0d199f2867854508473f5eccecbcb692f1 | https://github.com/friends-of-reactphp/mysql/blob/c420ca0d199f2867854508473f5eccecbcb692f1/src/Io/Buffer.php#L90-L98 | train |
friends-of-reactphp/mysql | src/Io/Buffer.php | Buffer.readStringLen | public function readStringLen()
{
$l = $this->readIntLen();
if ($l === null) {
return $l;
}
return $this->read($l);
} | php | public function readStringLen()
{
$l = $this->readIntLen();
if ($l === null) {
return $l;
}
return $this->read($l);
} | [
"public",
"function",
"readStringLen",
"(",
")",
"{",
"$",
"l",
"=",
"$",
"this",
"->",
"readIntLen",
"(",
")",
";",
"if",
"(",
"$",
"l",
"===",
"null",
")",
"{",
"return",
"$",
"l",
";",
"}",
"return",
"$",
"this",
"->",
"read",
"(",
"$",
"l",... | Parses length-encoded binary string
@return string|null decoded string or null if length indicates null | [
"Parses",
"length",
"-",
"encoded",
"binary",
"string"
] | c420ca0d199f2867854508473f5eccecbcb692f1 | https://github.com/friends-of-reactphp/mysql/blob/c420ca0d199f2867854508473f5eccecbcb692f1/src/Io/Buffer.php#L190-L198 | train |
friends-of-reactphp/mysql | src/Io/Buffer.php | Buffer.readStringNull | public function readStringNull()
{
$pos = \strpos($this->buffer, "\0", $this->bufferPos);
if ($pos === false) {
throw new \LogicException('Missing NULL character');
}
$ret = $this->read($pos - $this->bufferPos);
++$this->bufferPos;
return $ret;
} | php | public function readStringNull()
{
$pos = \strpos($this->buffer, "\0", $this->bufferPos);
if ($pos === false) {
throw new \LogicException('Missing NULL character');
}
$ret = $this->read($pos - $this->bufferPos);
++$this->bufferPos;
return $ret;
} | [
"public",
"function",
"readStringNull",
"(",
")",
"{",
"$",
"pos",
"=",
"\\",
"strpos",
"(",
"$",
"this",
"->",
"buffer",
",",
"\"\\0\"",
",",
"$",
"this",
"->",
"bufferPos",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"throw",
"new"... | Reads string until NULL character
@return string
@throws \LogicException | [
"Reads",
"string",
"until",
"NULL",
"character"
] | c420ca0d199f2867854508473f5eccecbcb692f1 | https://github.com/friends-of-reactphp/mysql/blob/c420ca0d199f2867854508473f5eccecbcb692f1/src/Io/Buffer.php#L206-L217 | train |
artesaos/defender | src/Defender/Commands/MakeRole.php | MakeRole.createRole | protected function createRole($roleName)
{
// No need to check is_null($role) as create() throwsException
$role = $this->roleRepository->create($roleName);
$this->info('Role created successfully');
return $role;
} | php | protected function createRole($roleName)
{
// No need to check is_null($role) as create() throwsException
$role = $this->roleRepository->create($roleName);
$this->info('Role created successfully');
return $role;
} | [
"protected",
"function",
"createRole",
"(",
"$",
"roleName",
")",
"{",
"// No need to check is_null($role) as create() throwsException",
"$",
"role",
"=",
"$",
"this",
"->",
"roleRepository",
"->",
"create",
"(",
"$",
"roleName",
")",
";",
"$",
"this",
"->",
"info... | Create role.
@param string $roleName
@return \Artesaos\Defender\Role | [
"Create",
"role",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Commands/MakeRole.php#L80-L88 | train |
artesaos/defender | src/Defender/Commands/MakeRole.php | MakeRole.attachRoleToUser | protected function attachRoleToUser($role, $userId)
{
// Check if user exists
if ($user = $this->userRepository->findById($userId)) {
$user->attachRole($role);
$this->info('Role attached successfully to user');
} else {
$this->error('Not possible to attach role. User not found');
}
} | php | protected function attachRoleToUser($role, $userId)
{
// Check if user exists
if ($user = $this->userRepository->findById($userId)) {
$user->attachRole($role);
$this->info('Role attached successfully to user');
} else {
$this->error('Not possible to attach role. User not found');
}
} | [
"protected",
"function",
"attachRoleToUser",
"(",
"$",
"role",
",",
"$",
"userId",
")",
"{",
"// Check if user exists",
"if",
"(",
"$",
"user",
"=",
"$",
"this",
"->",
"userRepository",
"->",
"findById",
"(",
"$",
"userId",
")",
")",
"{",
"$",
"user",
"-... | Attach role to user.
@param \Artesaos\Defender\Role $role
@param int $userId | [
"Attach",
"role",
"to",
"user",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Commands/MakeRole.php#L96-L105 | train |
artesaos/defender | src/Defender/Commands/MakePermission.php | MakePermission.createPermission | protected function createPermission($name, $readableName)
{
// No need to check is_null($permission) as create() throwsException
$permission = $this->permissionRepository->create($name, $readableName);
$this->info('Permission created successfully');
return $permission;
} | php | protected function createPermission($name, $readableName)
{
// No need to check is_null($permission) as create() throwsException
$permission = $this->permissionRepository->create($name, $readableName);
$this->info('Permission created successfully');
return $permission;
} | [
"protected",
"function",
"createPermission",
"(",
"$",
"name",
",",
"$",
"readableName",
")",
"{",
"// No need to check is_null($permission) as create() throwsException",
"$",
"permission",
"=",
"$",
"this",
"->",
"permissionRepository",
"->",
"create",
"(",
"$",
"name"... | Create permission.
@param string $name
@param string $readableName
@return \Artesaos\Defender\Permission | [
"Create",
"permission",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Commands/MakePermission.php#L102-L110 | train |
artesaos/defender | src/Defender/Commands/MakePermission.php | MakePermission.attachPermissionToUser | protected function attachPermissionToUser($permission, $userId)
{
// Check if user exists
if ($user = $this->userRepository->findById($userId)) {
$user->attachPermission($permission);
$this->info('Permission attached successfully to user');
} else {
$this->error('Not possible to attach permission. User not found');
}
} | php | protected function attachPermissionToUser($permission, $userId)
{
// Check if user exists
if ($user = $this->userRepository->findById($userId)) {
$user->attachPermission($permission);
$this->info('Permission attached successfully to user');
} else {
$this->error('Not possible to attach permission. User not found');
}
} | [
"protected",
"function",
"attachPermissionToUser",
"(",
"$",
"permission",
",",
"$",
"userId",
")",
"{",
"// Check if user exists",
"if",
"(",
"$",
"user",
"=",
"$",
"this",
"->",
"userRepository",
"->",
"findById",
"(",
"$",
"userId",
")",
")",
"{",
"$",
... | Attach Permission to user.
@param \Artesaos\Defender\Permission $permission
@param int $userId | [
"Attach",
"Permission",
"to",
"user",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Commands/MakePermission.php#L118-L127 | train |
artesaos/defender | src/Defender/Traits/Permissions/InteractsWithPermissions.php | InteractsWithPermissions.attachPermission | public function attachPermission($permission, array $options = [])
{
if (! is_array($permission)) {
if ($this->existPermission($permission->name)) {
return;
}
}
$this->permissions()->attach($permission, [
'value' => array_get($options, 'value', true),
'expires' => array_get($options, 'expires', null),
]);
} | php | public function attachPermission($permission, array $options = [])
{
if (! is_array($permission)) {
if ($this->existPermission($permission->name)) {
return;
}
}
$this->permissions()->attach($permission, [
'value' => array_get($options, 'value', true),
'expires' => array_get($options, 'expires', null),
]);
} | [
"public",
"function",
"attachPermission",
"(",
"$",
"permission",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"permission",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"existPermission",
"(",
"$",
"pe... | Attach the given permission.
@param array|\Artesaos\Defender\Permission $permission
@param array $options | [
"Attach",
"the",
"given",
"permission",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Permissions/InteractsWithPermissions.php#L16-L28 | train |
artesaos/defender | src/Defender/Traits/Permissions/InteractsWithPermissions.php | InteractsWithPermissions.existPermission | public function existPermission($permissionName)
{
$permission = $this->permissions->first(function ($key, $value) use ($permissionName) {
return ((isset($key->name)) ? $key->name : $value->name) == $permissionName;
});
if (! empty($permission)) {
$active = (is_null($permission->pivot->expires) or $permission->pivot->expires->isFuture());
if ($active) {
return (bool) $permission->pivot->value;
}
}
return false;
} | php | public function existPermission($permissionName)
{
$permission = $this->permissions->first(function ($key, $value) use ($permissionName) {
return ((isset($key->name)) ? $key->name : $value->name) == $permissionName;
});
if (! empty($permission)) {
$active = (is_null($permission->pivot->expires) or $permission->pivot->expires->isFuture());
if ($active) {
return (bool) $permission->pivot->value;
}
}
return false;
} | [
"public",
"function",
"existPermission",
"(",
"$",
"permissionName",
")",
"{",
"$",
"permission",
"=",
"$",
"this",
"->",
"permissions",
"->",
"first",
"(",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"use",
"(",
"$",
"permissionName",
")",
"{",... | Get the a permission using the permission name.
@param string $permissionName
@return bool | [
"Get",
"the",
"a",
"permission",
"using",
"the",
"permission",
"name",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Permissions/InteractsWithPermissions.php#L37-L52 | train |
artesaos/defender | src/Defender/Traits/Permissions/InteractsWithPermissions.php | InteractsWithPermissions.revokeExpiredPermissions | public function revokeExpiredPermissions()
{
$expiredPermissions = $this->permissions()->wherePivot('expires', '<', Carbon::now())->get();
if ($expiredPermissions->count() > 0) {
return $this->permissions()->detach($expiredPermissions->modelKeys());
}
} | php | public function revokeExpiredPermissions()
{
$expiredPermissions = $this->permissions()->wherePivot('expires', '<', Carbon::now())->get();
if ($expiredPermissions->count() > 0) {
return $this->permissions()->detach($expiredPermissions->modelKeys());
}
} | [
"public",
"function",
"revokeExpiredPermissions",
"(",
")",
"{",
"$",
"expiredPermissions",
"=",
"$",
"this",
"->",
"permissions",
"(",
")",
"->",
"wherePivot",
"(",
"'expires'",
",",
"'<'",
",",
"Carbon",
"::",
"now",
"(",
")",
")",
"->",
"get",
"(",
")... | Revoke expired user permissions.
@return int|null | [
"Revoke",
"expired",
"user",
"permissions",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Permissions/InteractsWithPermissions.php#L105-L112 | train |
artesaos/defender | src/Defender/Traits/Permissions/InteractsWithPermissions.php | InteractsWithPermissions.extendPermission | public function extendPermission($permission, array $options)
{
foreach ($this->permissions as $_permission) {
if ($_permission->name === $permission) {
return $this->permissions()->updateExistingPivot(
$_permission->id,
array_only($options, ['value', 'expires'])
);
}
}
} | php | public function extendPermission($permission, array $options)
{
foreach ($this->permissions as $_permission) {
if ($_permission->name === $permission) {
return $this->permissions()->updateExistingPivot(
$_permission->id,
array_only($options, ['value', 'expires'])
);
}
}
} | [
"public",
"function",
"extendPermission",
"(",
"$",
"permission",
",",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"permissions",
"as",
"$",
"_permission",
")",
"{",
"if",
"(",
"$",
"_permission",
"->",
"name",
"===",
"$",
"perm... | Extend an existing temporary permission.
@param string $permission
@param array $options
@return bool|null | [
"Extend",
"an",
"existing",
"temporary",
"permission",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Permissions/InteractsWithPermissions.php#L122-L132 | train |
artesaos/defender | src/Defender/Traits/Permissions/RoleHasPermissions.php | RoleHasPermissions.permissions | public function permissions()
{
$permissionModel = config('defender.permission_model');
$permissionRoleTable = config('defender.permission_role_table');
$roleKey = config('defender.role_key');
$permissionKey = config('defender.permission_key');
return $this->belongsToMany($permissionModel, $permissionRoleTable, $roleKey, $permissionKey)->withPivot('value', 'expires');
} | php | public function permissions()
{
$permissionModel = config('defender.permission_model');
$permissionRoleTable = config('defender.permission_role_table');
$roleKey = config('defender.role_key');
$permissionKey = config('defender.permission_key');
return $this->belongsToMany($permissionModel, $permissionRoleTable, $roleKey, $permissionKey)->withPivot('value', 'expires');
} | [
"public",
"function",
"permissions",
"(",
")",
"{",
"$",
"permissionModel",
"=",
"config",
"(",
"'defender.permission_model'",
")",
";",
"$",
"permissionRoleTable",
"=",
"config",
"(",
"'defender.permission_role_table'",
")",
";",
"$",
"roleKey",
"=",
"config",
"(... | Many-to-many permission-user relationship.
@return \Illuminate\Database\Eloquent\Relations\BelongsToMany | [
"Many",
"-",
"to",
"-",
"many",
"permission",
"-",
"user",
"relationship",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Permissions/RoleHasPermissions.php#L20-L28 | train |
artesaos/defender | src/Defender/Middlewares/AbstractDefenderMiddleware.php | AbstractDefenderMiddleware.forbiddenResponse | protected function forbiddenResponse()
{
$handler = app()->make(config('defender.forbidden_callback'));
return ($handler instanceof ForbiddenHandler) ? $handler->handle() : response('Forbidden', 403);
} | php | protected function forbiddenResponse()
{
$handler = app()->make(config('defender.forbidden_callback'));
return ($handler instanceof ForbiddenHandler) ? $handler->handle() : response('Forbidden', 403);
} | [
"protected",
"function",
"forbiddenResponse",
"(",
")",
"{",
"$",
"handler",
"=",
"app",
"(",
")",
"->",
"make",
"(",
"config",
"(",
"'defender.forbidden_callback'",
")",
")",
";",
"return",
"(",
"$",
"handler",
"instanceof",
"ForbiddenHandler",
")",
"?",
"$... | Handles the forbidden response.
@return mixed | [
"Handles",
"the",
"forbidden",
"response",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Middlewares/AbstractDefenderMiddleware.php#L53-L58 | train |
artesaos/defender | src/Defender/Defender.php | Defender.roleHasPermission | public function roleHasPermission($permission, $force = false)
{
if (! is_null($this->getUser())) {
return $this->getUser()->roleHasPermission($permission, $force);
}
return false;
} | php | public function roleHasPermission($permission, $force = false)
{
if (! is_null($this->getUser())) {
return $this->getUser()->roleHasPermission($permission, $force);
}
return false;
} | [
"public",
"function",
"roleHasPermission",
"(",
"$",
"permission",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getUser",
"(",
")",
"... | Check if the authenticated user has the given permission
using only the roles.
@param string $permission
@param bool $force
@return bool | [
"Check",
"if",
"the",
"authenticated",
"user",
"has",
"the",
"given",
"permission",
"using",
"only",
"the",
"roles",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Defender.php#L108-L115 | train |
artesaos/defender | src/Defender/Defender.php | Defender.hasRoles | public function hasRoles($roles)
{
if (! is_null($this->getUser())) {
return $this->getUser()->hasRoles($roles);
}
return false;
} | php | public function hasRoles($roles)
{
if (! is_null($this->getUser())) {
return $this->getUser()->hasRoles($roles);
}
return false;
} | [
"public",
"function",
"hasRoles",
"(",
"$",
"roles",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"hasRoles",
"(",
"$",
"roles",
")",
";",... | Return if the authenticated user has any of the given roles.
@param string $roles
@return bool | [
"Return",
"if",
"the",
"authenticated",
"user",
"has",
"any",
"of",
"the",
"given",
"roles",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Defender.php#L140-L147 | train |
artesaos/defender | src/Defender/Providers/DefenderServiceProvider.php | DefenderServiceProvider.registerRepositoryInterfaces | protected function registerRepositoryInterfaces()
{
$this->app->bind('Artesaos\Defender\Contracts\Permission', function ($app) {
return $app->make($this->app['config']->get('defender.permission_model'));
});
$this->app->bind('Artesaos\Defender\Contracts\Role', function ($app) {
return $app->make($this->app['config']->get('defender.role_model'));
});
$this->app->singleton('defender.role', function ($app) {
return new EloquentRoleRepository($app, $app->make(\Artesaos\Defender\Contracts\Role::class));
});
$this->app->singleton('Artesaos\Defender\Contracts\Repositories\RoleRepository', function ($app) {
return $app['defender.role'];
});
$this->app->singleton('defender.permission', function ($app) {
return new EloquentPermissionRepository($app, $app->make(\Artesaos\Defender\Contracts\Permission::class));
});
$this->app->singleton('Artesaos\Defender\Contracts\Repositories\PermissionRepository', function ($app) {
return $app['defender.permission'];
});
$this->app->singleton('defender.user', function ($app) {
$userModel = $app['config']->get('defender.user_model');
return new EloquentUserRepository($app, $app->make($userModel));
});
$this->app->singleton('Artesaos\Defender\Contracts\Repositories\UserRepository', function ($app) {
return $app['defender.user'];
});
} | php | protected function registerRepositoryInterfaces()
{
$this->app->bind('Artesaos\Defender\Contracts\Permission', function ($app) {
return $app->make($this->app['config']->get('defender.permission_model'));
});
$this->app->bind('Artesaos\Defender\Contracts\Role', function ($app) {
return $app->make($this->app['config']->get('defender.role_model'));
});
$this->app->singleton('defender.role', function ($app) {
return new EloquentRoleRepository($app, $app->make(\Artesaos\Defender\Contracts\Role::class));
});
$this->app->singleton('Artesaos\Defender\Contracts\Repositories\RoleRepository', function ($app) {
return $app['defender.role'];
});
$this->app->singleton('defender.permission', function ($app) {
return new EloquentPermissionRepository($app, $app->make(\Artesaos\Defender\Contracts\Permission::class));
});
$this->app->singleton('Artesaos\Defender\Contracts\Repositories\PermissionRepository', function ($app) {
return $app['defender.permission'];
});
$this->app->singleton('defender.user', function ($app) {
$userModel = $app['config']->get('defender.user_model');
return new EloquentUserRepository($app, $app->make($userModel));
});
$this->app->singleton('Artesaos\Defender\Contracts\Repositories\UserRepository', function ($app) {
return $app['defender.user'];
});
} | [
"protected",
"function",
"registerRepositoryInterfaces",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Artesaos\\Defender\\Contracts\\Permission'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(",
"$",
"this"... | Bind repositories interfaces with their implementations. | [
"Bind",
"repositories",
"interfaces",
"with",
"their",
"implementations",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Providers/DefenderServiceProvider.php#L77-L111 | train |
artesaos/defender | src/Defender/Providers/DefenderServiceProvider.php | DefenderServiceProvider.registerBladeExtensions | protected function registerBladeExtensions()
{
if (false === $this->app['config']->get('defender.template_helpers', true)) {
return;
}
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
/*
* add @shield and @endshield to blade compiler
*/
$bladeCompiler->directive('shield', function ($expression) {
return "<?php if(app('defender')->canDo({$this->stripParentheses($expression)})): ?>";
});
$bladeCompiler->directive('endshield', function ($expression) {
return '<?php endif; ?>';
});
/*
* add @is and @endis to blade compiler
*/
$bladeCompiler->directive('is', function ($expression) {
return "<?php if(app('defender')->hasRoles({$this->stripParentheses($expression)})): ?>";
});
$bladeCompiler->directive('endis', function ($expression) {
return '<?php endif; ?>';
});
/*
* add @isnot and @endisnot to blade compiler
*/
$bladeCompiler->directive('isnot', function ($expression) {
return "<?php if(!app('defender')->hasRoles({$this->stripParentheses($expression)})): ?>";
});
$bladeCompiler->directive('endisnot', function ($expression) {
return '<?php endif; ?>';
});
});
} | php | protected function registerBladeExtensions()
{
if (false === $this->app['config']->get('defender.template_helpers', true)) {
return;
}
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
/*
* add @shield and @endshield to blade compiler
*/
$bladeCompiler->directive('shield', function ($expression) {
return "<?php if(app('defender')->canDo({$this->stripParentheses($expression)})): ?>";
});
$bladeCompiler->directive('endshield', function ($expression) {
return '<?php endif; ?>';
});
/*
* add @is and @endis to blade compiler
*/
$bladeCompiler->directive('is', function ($expression) {
return "<?php if(app('defender')->hasRoles({$this->stripParentheses($expression)})): ?>";
});
$bladeCompiler->directive('endis', function ($expression) {
return '<?php endif; ?>';
});
/*
* add @isnot and @endisnot to blade compiler
*/
$bladeCompiler->directive('isnot', function ($expression) {
return "<?php if(!app('defender')->hasRoles({$this->stripParentheses($expression)})): ?>";
});
$bladeCompiler->directive('endisnot', function ($expression) {
return '<?php endif; ?>';
});
});
} | [
"protected",
"function",
"registerBladeExtensions",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'defender.template_helpers'",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"-... | Register new blade extensions. | [
"Register",
"new",
"blade",
"extensions",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Providers/DefenderServiceProvider.php#L116-L156 | train |
artesaos/defender | src/Defender/Providers/DefenderServiceProvider.php | DefenderServiceProvider.setUserModelConfig | private function setUserModelConfig()
{
if (config('defender.user_model') == '') {
if (str_contains($this->app->version(), '5.1')) {
return config(['defender.user_model' => $this->app['auth']->getProvider()->getModel()]);
}
return config(['defender.user_model' => $this->app['auth']->guard()->getProvider()->getModel()]);
}
} | php | private function setUserModelConfig()
{
if (config('defender.user_model') == '') {
if (str_contains($this->app->version(), '5.1')) {
return config(['defender.user_model' => $this->app['auth']->getProvider()->getModel()]);
}
return config(['defender.user_model' => $this->app['auth']->guard()->getProvider()->getModel()]);
}
} | [
"private",
"function",
"setUserModelConfig",
"(",
")",
"{",
"if",
"(",
"config",
"(",
"'defender.user_model'",
")",
"==",
"''",
")",
"{",
"if",
"(",
"str_contains",
"(",
"$",
"this",
"->",
"app",
"->",
"version",
"(",
")",
",",
"'5.1'",
")",
")",
"{",
... | Set the default configuration for the user model. | [
"Set",
"the",
"default",
"configuration",
"for",
"the",
"user",
"model",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Providers/DefenderServiceProvider.php#L202-L211 | train |
artesaos/defender | src/Defender/Repositories/Eloquent/EloquentPermissionRepository.php | EloquentPermissionRepository.create | public function create($permissionName, $readableName = null)
{
if (! is_null($this->findByName($permissionName))) {
throw new PermissionExistsException('The permission '.$permissionName.' already exists'); // TODO: add translation support
}
// Do we have a display_name set?
$readableName = is_null($readableName) ? $permissionName : $readableName;
return $permission = $this->model->create([
'name' => $permissionName,
'readable_name' => $readableName,
]);
} | php | public function create($permissionName, $readableName = null)
{
if (! is_null($this->findByName($permissionName))) {
throw new PermissionExistsException('The permission '.$permissionName.' already exists'); // TODO: add translation support
}
// Do we have a display_name set?
$readableName = is_null($readableName) ? $permissionName : $readableName;
return $permission = $this->model->create([
'name' => $permissionName,
'readable_name' => $readableName,
]);
} | [
"public",
"function",
"create",
"(",
"$",
"permissionName",
",",
"$",
"readableName",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"findByName",
"(",
"$",
"permissionName",
")",
")",
")",
"{",
"throw",
"new",
"PermissionExist... | Create a new permission using the given name.
@param string $permissionName
@param string $readableName
@throws PermissionExistsException
@return Permission | [
"Create",
"a",
"new",
"permission",
"using",
"the",
"given",
"name",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Repositories/Eloquent/EloquentPermissionRepository.php#L35-L48 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.hasPermission | public function hasPermission($permission, $force = false)
{
$permissions = $this->getAllPermissions($force)->pluck('name')->toArray();
if (strpos($permission, '*')) {
$permission = substr($permission, 0, -2);
return (bool) preg_grep('~'.$permission.'~', $permissions);
}
return in_array($permission, $permissions);
} | php | public function hasPermission($permission, $force = false)
{
$permissions = $this->getAllPermissions($force)->pluck('name')->toArray();
if (strpos($permission, '*')) {
$permission = substr($permission, 0, -2);
return (bool) preg_grep('~'.$permission.'~', $permissions);
}
return in_array($permission, $permissions);
} | [
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"getAllPermissions",
"(",
"$",
"force",
")",
"->",
"pluck",
"(",
"'name'",
")",
"->",
"toArray",
"(",
... | Returns if the current user has the given permission.
User permissions override role permissions.
@param string $permission
@param bool $force
@return bool | [
"Returns",
"if",
"the",
"current",
"user",
"has",
"the",
"given",
"permission",
".",
"User",
"permissions",
"override",
"role",
"permissions",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L34-L45 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.hasPermissions | public function hasPermissions(array $permissions, $strict = true, $force = false)
{
$allPermissions = $this->getAllPermissions($force)->pluck('name')->toArray();
$equalPermissions = array_intersect($permissions, $allPermissions);
$countEqual = count($equalPermissions);
if ($countEqual > 0 && ($strict === false || $countEqual === count($permissions))) {
return true;
}
return false;
} | php | public function hasPermissions(array $permissions, $strict = true, $force = false)
{
$allPermissions = $this->getAllPermissions($force)->pluck('name')->toArray();
$equalPermissions = array_intersect($permissions, $allPermissions);
$countEqual = count($equalPermissions);
if ($countEqual > 0 && ($strict === false || $countEqual === count($permissions))) {
return true;
}
return false;
} | [
"public",
"function",
"hasPermissions",
"(",
"array",
"$",
"permissions",
",",
"$",
"strict",
"=",
"true",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"allPermissions",
"=",
"$",
"this",
"->",
"getAllPermissions",
"(",
"$",
"force",
")",
"->",
"pluck... | Returns if the current user has all or one permission of the given array.
User permissions override role permissions.
@param array $permissions Array of permissions
@param bool $strict Check if has all permissions from array or one of them
@param bool $force
@return bool | [
"Returns",
"if",
"the",
"current",
"user",
"has",
"all",
"or",
"one",
"permission",
"of",
"the",
"given",
"array",
".",
"User",
"permissions",
"override",
"role",
"permissions",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L56-L66 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.canDo | public function canDo($permission, $force = false)
{
// If has superuser role
if ($this->isSuperUser()) {
return true;
}
return $this->hasPermission($permission, $force);
} | php | public function canDo($permission, $force = false)
{
// If has superuser role
if ($this->isSuperUser()) {
return true;
}
return $this->hasPermission($permission, $force);
} | [
"public",
"function",
"canDo",
"(",
"$",
"permission",
",",
"$",
"force",
"=",
"false",
")",
"{",
"// If has superuser role",
"if",
"(",
"$",
"this",
"->",
"isSuperUser",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"has... | Checks for permission
If has superuser group automatically passes.
@param string $permission
@param bool $force
@return bool | [
"Checks",
"for",
"permission",
"If",
"has",
"superuser",
"group",
"automatically",
"passes",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L77-L85 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.roleHasPermission | public function roleHasPermission($permission, $force = false)
{
$permissions = $this->getRolesPermissions($force)->pluck('name')->toArray();
return in_array($permission, $permissions);
} | php | public function roleHasPermission($permission, $force = false)
{
$permissions = $this->getRolesPermissions($force)->pluck('name')->toArray();
return in_array($permission, $permissions);
} | [
"public",
"function",
"roleHasPermission",
"(",
"$",
"permission",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"getRolesPermissions",
"(",
"$",
"force",
")",
"->",
"pluck",
"(",
"'name'",
")",
"->",
"toArray",
"... | Check if the user has the given permission using
only his roles.
@param string $permission
@param bool $force
@return bool | [
"Check",
"if",
"the",
"user",
"has",
"the",
"given",
"permission",
"using",
"only",
"his",
"roles",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L106-L111 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.getAllPermissions | public function getAllPermissions($force = false)
{
if (empty($this->cachedPermissions) or $force) {
$this->cachedPermissions = $this->getFreshAllPermissions();
}
return $this->cachedPermissions;
} | php | public function getAllPermissions($force = false)
{
if (empty($this->cachedPermissions) or $force) {
$this->cachedPermissions = $this->getFreshAllPermissions();
}
return $this->cachedPermissions;
} | [
"public",
"function",
"getAllPermissions",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"cachedPermissions",
")",
"or",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"cachedPermissions",
"=",
"$",
"this",
"->",
"g... | Retrieve all user permissions.
@param bool $force
@return \Illuminate\Support\Collection | [
"Retrieve",
"all",
"user",
"permissions",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L120-L127 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.getRolesPermissions | public function getRolesPermissions($force = false)
{
if (empty($this->cachedRolePermissions) or $force) {
$this->cachedRolePermissions = $this->getFreshRolesPermissions();
}
return $this->cachedRolePermissions;
} | php | public function getRolesPermissions($force = false)
{
if (empty($this->cachedRolePermissions) or $force) {
$this->cachedRolePermissions = $this->getFreshRolesPermissions();
}
return $this->cachedRolePermissions;
} | [
"public",
"function",
"getRolesPermissions",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"cachedRolePermissions",
")",
"or",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"cachedRolePermissions",
"=",
"$",
"this",
... | Get permissions from database based on roles.
@param bool $force
@return \Illuminate\Support\Collection | [
"Get",
"permissions",
"from",
"database",
"based",
"on",
"roles",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L136-L143 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.getFreshRolesPermissions | protected function getFreshRolesPermissions()
{
$roles = $this->roles()->get(['id'])->pluck('id')->toArray();
return app('defender.permission')->getByRoles($roles);
} | php | protected function getFreshRolesPermissions()
{
$roles = $this->roles()->get(['id'])->pluck('id')->toArray();
return app('defender.permission')->getByRoles($roles);
} | [
"protected",
"function",
"getFreshRolesPermissions",
"(",
")",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"roles",
"(",
")",
"->",
"get",
"(",
"[",
"'id'",
"]",
")",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"toArray",
"(",
")",
";",
"return",
"app",
... | Get fresh permissions from database based on roles.
@return \Illuminate\Support\Collection | [
"Get",
"fresh",
"permissions",
"from",
"database",
"based",
"on",
"roles",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L150-L155 | train |
artesaos/defender | src/Defender/Traits/HasDefender.php | HasDefender.getFreshAllPermissions | protected function getFreshAllPermissions()
{
$permissionsRoles = $this->getRolesPermissions(true);
$permissions = app('defender.permission')->getActivesByUser($this);
$permissions = $permissions->merge($permissionsRoles)
->map(function ($permission) {
unset($permission->pivot, $permission->created_at, $permission->updated_at);
return $permission;
});
return $permissions->toBase();
} | php | protected function getFreshAllPermissions()
{
$permissionsRoles = $this->getRolesPermissions(true);
$permissions = app('defender.permission')->getActivesByUser($this);
$permissions = $permissions->merge($permissionsRoles)
->map(function ($permission) {
unset($permission->pivot, $permission->created_at, $permission->updated_at);
return $permission;
});
return $permissions->toBase();
} | [
"protected",
"function",
"getFreshAllPermissions",
"(",
")",
"{",
"$",
"permissionsRoles",
"=",
"$",
"this",
"->",
"getRolesPermissions",
"(",
"true",
")",
";",
"$",
"permissions",
"=",
"app",
"(",
"'defender.permission'",
")",
"->",
"getActivesByUser",
"(",
"$"... | Get fresh permissions from database.
@return \Illuminate\Support\Collection | [
"Get",
"fresh",
"permissions",
"from",
"database",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/HasDefender.php#L162-L176 | train |
artesaos/defender | src/Defender/Repositories/Eloquent/EloquentRoleRepository.php | EloquentRoleRepository.create | public function create($roleName)
{
if (! is_null($this->findByName($roleName))) {
// TODO: add translation support
throw new RoleExistsException('A role with the given name already exists');
}
return $role = $this->model->create(['name' => $roleName]);
} | php | public function create($roleName)
{
if (! is_null($this->findByName($roleName))) {
// TODO: add translation support
throw new RoleExistsException('A role with the given name already exists');
}
return $role = $this->model->create(['name' => $roleName]);
} | [
"public",
"function",
"create",
"(",
"$",
"roleName",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"findByName",
"(",
"$",
"roleName",
")",
")",
")",
"{",
"// TODO: add translation support",
"throw",
"new",
"RoleExistsException",
"(",
"'A rol... | Create a new role with the given name.
@param $roleName
@throws \Exception
@return Role | [
"Create",
"a",
"new",
"role",
"with",
"the",
"given",
"name",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Repositories/Eloquent/EloquentRoleRepository.php#L33-L41 | train |
artesaos/defender | src/Defender/Traits/Users/HasRoles.php | HasRoles.hasRoles | public function hasRoles($roles)
{
$roles = is_array($roles) ? $roles : func_get_args();
foreach ($roles as $role) {
if ($this->hasRole($role)) {
return true;
}
}
return false;
} | php | public function hasRoles($roles)
{
$roles = is_array($roles) ? $roles : func_get_args();
foreach ($roles as $role) {
if ($this->hasRole($role)) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasRoles",
"(",
"$",
"roles",
")",
"{",
"$",
"roles",
"=",
"is_array",
"(",
"$",
"roles",
")",
"?",
"$",
"roles",
":",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"$... | Returns true if the given user has any of the given roles.
@param string|array $roles array or many strings of role name
@return bool | [
"Returns",
"true",
"if",
"the",
"given",
"user",
"has",
"any",
"of",
"the",
"given",
"roles",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Users/HasRoles.php#L17-L28 | train |
artesaos/defender | src/Defender/Traits/Users/HasRoles.php | HasRoles.attachRole | public function attachRole($role)
{
if (! $this->hasRole($role->name)) {
$this->roles()->attach($role);
}
} | php | public function attachRole($role)
{
if (! $this->hasRole($role->name)) {
$this->roles()->attach($role);
}
} | [
"public",
"function",
"attachRole",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRole",
"(",
"$",
"role",
"->",
"name",
")",
")",
"{",
"$",
"this",
"->",
"roles",
"(",
")",
"->",
"attach",
"(",
"$",
"role",
")",
";",
"}",
... | Attach the given role.
@param \Artesaos\Defender\Role $role | [
"Attach",
"the",
"given",
"role",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Users/HasRoles.php#L49-L54 | train |
artesaos/defender | src/Defender/Traits/Users/HasRoles.php | HasRoles.roles | public function roles()
{
$roleModel = config('defender.role_model', 'Artesaos\Defender\Role');
$roleUserTable = config('defender.role_user_table', 'role_user');
$roleKey = config('defender.role_key', 'role_id');
return $this->belongsToMany($roleModel, $roleUserTable, 'user_id', $roleKey);
} | php | public function roles()
{
$roleModel = config('defender.role_model', 'Artesaos\Defender\Role');
$roleUserTable = config('defender.role_user_table', 'role_user');
$roleKey = config('defender.role_key', 'role_id');
return $this->belongsToMany($roleModel, $roleUserTable, 'user_id', $roleKey);
} | [
"public",
"function",
"roles",
"(",
")",
"{",
"$",
"roleModel",
"=",
"config",
"(",
"'defender.role_model'",
",",
"'Artesaos\\Defender\\Role'",
")",
";",
"$",
"roleUserTable",
"=",
"config",
"(",
"'defender.role_user_table'",
",",
"'role_user'",
")",
";",
"$",
"... | Many-to-many role-user relationship.
@return \Illuminate\Database\Eloquent\Relations\BelongsToMany | [
"Many",
"-",
"to",
"-",
"many",
"role",
"-",
"user",
"relationship",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Users/HasRoles.php#L61-L68 | train |
artesaos/defender | src/Defender/Traits/Users/HasRoles.php | HasRoles.scopeWhichRoles | public function scopeWhichRoles($query, $roles)
{
return $query->whereHas('roles', function ($query) use ($roles) {
$roles = (is_array($roles)) ? $roles : [$roles];
$query->whereIn('name', $roles);
});
} | php | public function scopeWhichRoles($query, $roles)
{
return $query->whereHas('roles', function ($query) use ($roles) {
$roles = (is_array($roles)) ? $roles : [$roles];
$query->whereIn('name', $roles);
});
} | [
"public",
"function",
"scopeWhichRoles",
"(",
"$",
"query",
",",
"$",
"roles",
")",
"{",
"return",
"$",
"query",
"->",
"whereHas",
"(",
"'roles'",
",",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"roles",
")",
"{",
"$",
"roles",
"=",
"(",
... | Take user by roles.
@param \Illuminate\Database\Query\Builder $query
@param string|array $roles
@return \Illuminate\Database\Query\Builder | [
"Take",
"user",
"by",
"roles",
"."
] | 066b11bffa35de7632e78700a30002cf0cddf598 | https://github.com/artesaos/defender/blob/066b11bffa35de7632e78700a30002cf0cddf598/src/Defender/Traits/Users/HasRoles.php#L102-L109 | train |
andywer/laravel-js-localization | src/Console/ExportCommand.php | ExportCommand.createPath | public function createPath($filename)
{
$dir = Config::get('js-localization.storage_path');
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
return $dir . $filename;
} | php | public function createPath($filename)
{
$dir = Config::get('js-localization.storage_path');
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
return $dir . $filename;
} | [
"public",
"function",
"createPath",
"(",
"$",
"filename",
")",
"{",
"$",
"dir",
"=",
"Config",
"::",
"get",
"(",
"'js-localization.storage_path'",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"mkdir",
"(",
"$",
"dir",
",",
"077... | Create full file path.
This method will also generate the directories if they don't exist already.
@var string $filename
@return string $path | [
"Create",
"full",
"file",
"path",
".",
"This",
"method",
"will",
"also",
"generate",
"the",
"directories",
"if",
"they",
"don",
"t",
"exist",
"already",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Console/ExportCommand.php#L95-L103 | train |
andywer/laravel-js-localization | src/Console/ExportCommand.php | ExportCommand.generateMessagesFile | public function generateMessagesFile($path, $noCache = false)
{
$splitFiles = Config::get('js-localization.split_export_files');
$messages = MessageCachingService::getMessagesJson($noCache);
if ($splitFiles) {
$this->generateMessageFiles(File::dirname($path), $messages);
}
$contents = 'Lang.addMessages(' . $messages . ');';
File::put($path, $contents);
$this->line("Generated $path");
} | php | public function generateMessagesFile($path, $noCache = false)
{
$splitFiles = Config::get('js-localization.split_export_files');
$messages = MessageCachingService::getMessagesJson($noCache);
if ($splitFiles) {
$this->generateMessageFiles(File::dirname($path), $messages);
}
$contents = 'Lang.addMessages(' . $messages . ');';
File::put($path, $contents);
$this->line("Generated $path");
} | [
"public",
"function",
"generateMessagesFile",
"(",
"$",
"path",
",",
"$",
"noCache",
"=",
"false",
")",
"{",
"$",
"splitFiles",
"=",
"Config",
"::",
"get",
"(",
"'js-localization.split_export_files'",
")",
";",
"$",
"messages",
"=",
"MessageCachingService",
"::"... | Generate the messages file.
@param string $path
@param bool $noCache | [
"Generate",
"the",
"messages",
"file",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Console/ExportCommand.php#L111-L125 | train |
andywer/laravel-js-localization | src/Console/ExportCommand.php | ExportCommand.generateConfigFile | public function generateConfigFile($path, $noCache = false)
{
$config = ConfigCachingService::getConfigJson($noCache);
if ($config === '{}') {
$this->line('No config specified. Config not written to file.');
return;
}
$contents = 'Config.addConfig(' . $config . ');';
File::put($path, $contents);
$this->line("Generated $path");
} | php | public function generateConfigFile($path, $noCache = false)
{
$config = ConfigCachingService::getConfigJson($noCache);
if ($config === '{}') {
$this->line('No config specified. Config not written to file.');
return;
}
$contents = 'Config.addConfig(' . $config . ');';
File::put($path, $contents);
$this->line("Generated $path");
} | [
"public",
"function",
"generateConfigFile",
"(",
"$",
"path",
",",
"$",
"noCache",
"=",
"false",
")",
"{",
"$",
"config",
"=",
"ConfigCachingService",
"::",
"getConfigJson",
"(",
"$",
"noCache",
")",
";",
"if",
"(",
"$",
"config",
"===",
"'{}'",
")",
"{"... | Generate the config file.
@param string $path
@param bool $noCache | [
"Generate",
"the",
"config",
"file",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Console/ExportCommand.php#L156-L169 | train |
andywer/laravel-js-localization | src/Caching/AbstractCachingService.php | AbstractCachingService.refreshCacheUsing | public function refreshCacheUsing($data)
{
Cache::forever($this->cacheKey, $data);
Cache::forever($this->cacheTimestampKey, time());
} | php | public function refreshCacheUsing($data)
{
Cache::forever($this->cacheKey, $data);
Cache::forever($this->cacheTimestampKey, time());
} | [
"public",
"function",
"refreshCacheUsing",
"(",
"$",
"data",
")",
"{",
"Cache",
"::",
"forever",
"(",
"$",
"this",
"->",
"cacheKey",
",",
"$",
"data",
")",
";",
"Cache",
"::",
"forever",
"(",
"$",
"this",
"->",
"cacheTimestampKey",
",",
"time",
"(",
")... | Refresh the cached data.
@param mixed $data | [
"Refresh",
"the",
"cached",
"data",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Caching/AbstractCachingService.php#L62-L66 | train |
andywer/laravel-js-localization | src/Caching/AbstractCachingService.php | AbstractCachingService.getData | public function getData()
{
if (!Cache::has($this->cacheKey)) {
$this->refreshCache();
}
return Cache::get($this->cacheKey);
} | php | public function getData()
{
if (!Cache::has($this->cacheKey)) {
$this->refreshCache();
}
return Cache::get($this->cacheKey);
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"!",
"Cache",
"::",
"has",
"(",
"$",
"this",
"->",
"cacheKey",
")",
")",
"{",
"$",
"this",
"->",
"refreshCache",
"(",
")",
";",
"}",
"return",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->"... | Return the cached data. Refresh cache if cache has not yet been initialized.
@return mixed | [
"Return",
"the",
"cached",
"data",
".",
"Refresh",
"cache",
"if",
"cache",
"has",
"not",
"yet",
"been",
"initialized",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Caching/AbstractCachingService.php#L81-L88 | train |
andywer/laravel-js-localization | src/Caching/MessageCachingService.php | MessageCachingService.getTranslatedMessagesForLocales | protected function getTranslatedMessagesForLocales(array $messageKeys, array $locales)
{
$translatedMessages = [];
foreach ($locales as $locale) {
if (!isset($translatedMessages[$locale])) {
$translatedMessages[$locale] = [];
}
$translatedMessages[$locale] = $this->getTranslatedMessages($messageKeys, $locale);
}
return $translatedMessages;
} | php | protected function getTranslatedMessagesForLocales(array $messageKeys, array $locales)
{
$translatedMessages = [];
foreach ($locales as $locale) {
if (!isset($translatedMessages[$locale])) {
$translatedMessages[$locale] = [];
}
$translatedMessages[$locale] = $this->getTranslatedMessages($messageKeys, $locale);
}
return $translatedMessages;
} | [
"protected",
"function",
"getTranslatedMessagesForLocales",
"(",
"array",
"$",
"messageKeys",
",",
"array",
"$",
"locales",
")",
"{",
"$",
"translatedMessages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"if",
"(",
"... | Returns the translated messages for the given keys and locales.
@param array $messageKeys
@param array $locales
@return array The translated messages as [<locale> => [ <message id> => <translation>, ... ], ...] | [
"Returns",
"the",
"translated",
"messages",
"for",
"the",
"given",
"keys",
"and",
"locales",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Caching/MessageCachingService.php#L98-L111 | train |
andywer/laravel-js-localization | src/Caching/MessageCachingService.php | MessageCachingService.getTranslatedMessages | protected function getTranslatedMessages(array $messageKeys, $locale)
{
$translatedMessages = [];
foreach ($messageKeys as $key) {
$translation = Lang::get($key, [], $locale);
if (is_array($translation)) {
$flattened = $this->flattenTranslations($translation, $key.'.');
$translatedMessages = array_merge($translatedMessages, $flattened);
} else {
$translatedMessages[$key] = $translation;
}
}
return $translatedMessages;
} | php | protected function getTranslatedMessages(array $messageKeys, $locale)
{
$translatedMessages = [];
foreach ($messageKeys as $key) {
$translation = Lang::get($key, [], $locale);
if (is_array($translation)) {
$flattened = $this->flattenTranslations($translation, $key.'.');
$translatedMessages = array_merge($translatedMessages, $flattened);
} else {
$translatedMessages[$key] = $translation;
}
}
return $translatedMessages;
} | [
"protected",
"function",
"getTranslatedMessages",
"(",
"array",
"$",
"messageKeys",
",",
"$",
"locale",
")",
"{",
"$",
"translatedMessages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"messageKeys",
"as",
"$",
"key",
")",
"{",
"$",
"translation",
"=",
"Lang"... | Returns the translated messages for the given keys.
@param array $messageKeys
@param $locale
@return array The translated messages as [ <message id> => <translation>, ... ] | [
"Returns",
"the",
"translated",
"messages",
"for",
"the",
"given",
"keys",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Caching/MessageCachingService.php#L120-L136 | train |
andywer/laravel-js-localization | src/Caching/MessageCachingService.php | MessageCachingService.getMessageKeys | protected function getMessageKeys()
{
$messageKeys = Config::get('js-localization.messages');
$messageKeys = JsLocalizationHelper::resolveMessageKeyArray($messageKeys);
$messageKeys = array_unique(
array_merge($messageKeys, JsLocalizationHelper::getAdditionalMessages())
);
return $messageKeys;
} | php | protected function getMessageKeys()
{
$messageKeys = Config::get('js-localization.messages');
$messageKeys = JsLocalizationHelper::resolveMessageKeyArray($messageKeys);
$messageKeys = array_unique(
array_merge($messageKeys, JsLocalizationHelper::getAdditionalMessages())
);
return $messageKeys;
} | [
"protected",
"function",
"getMessageKeys",
"(",
")",
"{",
"$",
"messageKeys",
"=",
"Config",
"::",
"get",
"(",
"'js-localization.messages'",
")",
";",
"$",
"messageKeys",
"=",
"JsLocalizationHelper",
"::",
"resolveMessageKeyArray",
"(",
"$",
"messageKeys",
")",
";... | Returns the message keys of all messages
that are supposed to be sent to the browser.
@return array Array of message keys. | [
"Returns",
"the",
"message",
"keys",
"of",
"all",
"messages",
"that",
"are",
"supposed",
"to",
"be",
"sent",
"to",
"the",
"browser",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Caching/MessageCachingService.php#L167-L177 | train |
andywer/laravel-js-localization | src/Utils/Helper.php | Helper.resolveMessageKeyArray | public function resolveMessageKeyArray(array $messageKeys)
{
$flatArray = [];
foreach ($messageKeys as $index=>$key) {
$this->resolveMessageKey($key, $index, function($qualifiedKey) use(&$flatArray)
{
$flatArray[] = $qualifiedKey;
});
}
return $flatArray;
} | php | public function resolveMessageKeyArray(array $messageKeys)
{
$flatArray = [];
foreach ($messageKeys as $index=>$key) {
$this->resolveMessageKey($key, $index, function($qualifiedKey) use(&$flatArray)
{
$flatArray[] = $qualifiedKey;
});
}
return $flatArray;
} | [
"public",
"function",
"resolveMessageKeyArray",
"(",
"array",
"$",
"messageKeys",
")",
"{",
"$",
"flatArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"messageKeys",
"as",
"$",
"index",
"=>",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"resolveMessageKey",
... | Takes an array of message keys with nested
sub-arrays and returns a flat array of
fully qualified message keys.
@param array $messageKeys Complex array of message keys.
@return array Flat array of fully qualified message keys. | [
"Takes",
"an",
"array",
"of",
"message",
"keys",
"with",
"nested",
"sub",
"-",
"arrays",
"and",
"returns",
"a",
"flat",
"array",
"of",
"fully",
"qualified",
"message",
"keys",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Utils/Helper.php#L92-L104 | train |
andywer/laravel-js-localization | src/Utils/Helper.php | Helper.resolveMessageArrayToMessageKeys | public function resolveMessageArrayToMessageKeys(array $messages, $prefix="")
{
$flatArray = [];
foreach ($messages as $key=>$message) {
$this->resolveMessageToKeys($message, $key, function($qualifiedKey) use(&$flatArray)
{
$flatArray[] = $qualifiedKey;
}, $prefix);
}
return $flatArray;
} | php | public function resolveMessageArrayToMessageKeys(array $messages, $prefix="")
{
$flatArray = [];
foreach ($messages as $key=>$message) {
$this->resolveMessageToKeys($message, $key, function($qualifiedKey) use(&$flatArray)
{
$flatArray[] = $qualifiedKey;
}, $prefix);
}
return $flatArray;
} | [
"public",
"function",
"resolveMessageArrayToMessageKeys",
"(",
"array",
"$",
"messages",
",",
"$",
"prefix",
"=",
"\"\"",
")",
"{",
"$",
"flatArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"key",
"=>",
"$",
"message",
")",
"{",
... | Resolves a message array with nested
sub-arrays to a flat array of fully
qualified message keys.
@param array $messages Complex message array (like the ones in the app/lang/* files).
@return array Flat array of fully qualified message keys. | [
"Resolves",
"a",
"message",
"array",
"with",
"nested",
"sub",
"-",
"arrays",
"to",
"a",
"flat",
"array",
"of",
"fully",
"qualified",
"message",
"keys",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Utils/Helper.php#L114-L126 | train |
andywer/laravel-js-localization | src/Utils/Helper.php | Helper.resolveMessageKey | private function resolveMessageKey($key, $keyIndex, $callback, $prefix="")
{
if (is_array($key)) {
$_prefix = $prefix ? $prefix.$keyIndex."." : $keyIndex.".";
foreach ($key as $_index=>$_key) {
$this->resolveMessageKey($_key, $_index, $callback, $_prefix);
}
} else {
$callback($prefix.$key);
}
} | php | private function resolveMessageKey($key, $keyIndex, $callback, $prefix="")
{
if (is_array($key)) {
$_prefix = $prefix ? $prefix.$keyIndex."." : $keyIndex.".";
foreach ($key as $_index=>$_key) {
$this->resolveMessageKey($_key, $_index, $callback, $_prefix);
}
} else {
$callback($prefix.$key);
}
} | [
"private",
"function",
"resolveMessageKey",
"(",
"$",
"key",
",",
"$",
"keyIndex",
",",
"$",
"callback",
",",
"$",
"prefix",
"=",
"\"\"",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"_prefix",
"=",
"$",
"prefix",
"?",
"$",... | Returns the concatenation of prefix and key if the key
is a string. If the key is an array then the function
will recurse.
@param mixed $key An array item read from the configuration ('messages' array).
@param mixed $keyIndex The array index of $key. Is necessary if $key is an array.
@param callable $callback A callback function: function($fullyQualifiedKey).
@param string $prefix Optional key prefix. | [
"Returns",
"the",
"concatenation",
"of",
"prefix",
"and",
"key",
"if",
"the",
"key",
"is",
"a",
"string",
".",
"If",
"the",
"key",
"is",
"an",
"array",
"then",
"the",
"function",
"will",
"recurse",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Utils/Helper.php#L138-L150 | train |
andywer/laravel-js-localization | src/Utils/Helper.php | Helper.resolveMessageToKeys | private function resolveMessageToKeys($message, $key, $callback, $prefix="")
{
if (is_array($message)) {
$_prefix = $prefix ? $prefix.$key."." : $key.".";
foreach ($message as $_key=>$_message) {
$this->resolveMessageToKeys($_message, $_key, $callback, $_prefix);
}
} else {
$callback($prefix.$key);
}
} | php | private function resolveMessageToKeys($message, $key, $callback, $prefix="")
{
if (is_array($message)) {
$_prefix = $prefix ? $prefix.$key."." : $key.".";
foreach ($message as $_key=>$_message) {
$this->resolveMessageToKeys($_message, $_key, $callback, $_prefix);
}
} else {
$callback($prefix.$key);
}
} | [
"private",
"function",
"resolveMessageToKeys",
"(",
"$",
"message",
",",
"$",
"key",
",",
"$",
"callback",
",",
"$",
"prefix",
"=",
"\"\"",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"_prefix",
"=",
"$",
"prefix",
"?",
... | Returns the concatenation of prefix and key if the value
is a message. If the value is an array then the function
will recurse.
@param mixed $message An array item read from a message file array.
@param mixed $key The array key of $message.
@param callable $callback A callback function: function($fullyQualifiedKey).
@param string $prefix Optional key prefix. | [
"Returns",
"the",
"concatenation",
"of",
"prefix",
"and",
"key",
"if",
"the",
"value",
"is",
"a",
"message",
".",
"If",
"the",
"value",
"is",
"an",
"array",
"then",
"the",
"function",
"will",
"recurse",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Utils/Helper.php#L162-L174 | train |
andywer/laravel-js-localization | src/Utils/Helper.php | Helper.prefix | private function prefix($prefix)
{
if ($prefix) {
$prefixLastChar = substr($prefix, -1);
if ($prefixLastChar != '.' && $prefixLastChar != ':') {
$prefix .= '.';
}
}
return $prefix;
} | php | private function prefix($prefix)
{
if ($prefix) {
$prefixLastChar = substr($prefix, -1);
if ($prefixLastChar != '.' && $prefixLastChar != ':') {
$prefix .= '.';
}
}
return $prefix;
} | [
"private",
"function",
"prefix",
"(",
"$",
"prefix",
")",
"{",
"if",
"(",
"$",
"prefix",
")",
"{",
"$",
"prefixLastChar",
"=",
"substr",
"(",
"$",
"prefix",
",",
"-",
"1",
")",
";",
"if",
"(",
"$",
"prefixLastChar",
"!=",
"'.'",
"&&",
"$",
"prefixL... | Appends a dot to the prefix if necessary.
@param string $prefix Prefix to validate and possibly append dot to.
@return string Processed prefix. | [
"Appends",
"a",
"dot",
"to",
"the",
"prefix",
"if",
"necessary",
"."
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Utils/Helper.php#L182-L193 | train |
andywer/laravel-js-localization | src/Http/Controllers/JsLocalizationController.php | JsLocalizationController.createJsMessages | public function createJsMessages()
{
$contents = $this->getMessagesJson();
return response($contents)
->header('Content-Type', 'text/javascript')
->setLastModified(MessageCachingService::getLastRefreshTimestamp());
} | php | public function createJsMessages()
{
$contents = $this->getMessagesJson();
return response($contents)
->header('Content-Type', 'text/javascript')
->setLastModified(MessageCachingService::getLastRefreshTimestamp());
} | [
"public",
"function",
"createJsMessages",
"(",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"getMessagesJson",
"(",
")",
";",
"return",
"response",
"(",
"$",
"contents",
")",
"->",
"header",
"(",
"'Content-Type'",
",",
"'text/javascript'",
")",
"->",
... | Create the JS-Response for all configured translation messages
@return \Illuminate\Http\Response | [
"Create",
"the",
"JS",
"-",
"Response",
"for",
"all",
"configured",
"translation",
"messages"
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Http/Controllers/JsLocalizationController.php#L18-L25 | train |
andywer/laravel-js-localization | src/Http/Controllers/JsLocalizationController.php | JsLocalizationController.deliverAllInOne | public function deliverAllInOne()
{
$contents = file_get_contents( __DIR__."/../../../public/js/localization.min.js" );
$contents .= "\n";
$contents .= $this->getMessagesJson();
$contents .= $this->getConfigJson();
/** @var \Illuminate\Http\Response $response */
$response = response($contents);
$response->header('Content-Type', 'text/javascript');
if (ConfigCachingService::isDisabled()) {
$response->setEtag(md5($contents));
} else {
$response->setLastModified(MessageCachingService::getLastRefreshTimestamp());
}
return $response;
} | php | public function deliverAllInOne()
{
$contents = file_get_contents( __DIR__."/../../../public/js/localization.min.js" );
$contents .= "\n";
$contents .= $this->getMessagesJson();
$contents .= $this->getConfigJson();
/** @var \Illuminate\Http\Response $response */
$response = response($contents);
$response->header('Content-Type', 'text/javascript');
if (ConfigCachingService::isDisabled()) {
$response->setEtag(md5($contents));
} else {
$response->setLastModified(MessageCachingService::getLastRefreshTimestamp());
}
return $response;
} | [
"public",
"function",
"deliverAllInOne",
"(",
")",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"__DIR__",
".",
"\"/../../../public/js/localization.min.js\"",
")",
";",
"$",
"contents",
".=",
"\"\\n\"",
";",
"$",
"contents",
".=",
"$",
"this",
"->",
"get... | Deliver one file that combines messages and framework.
Saves one additional HTTP-Request
@return \Illuminate\Http\Response | [
"Deliver",
"one",
"file",
"that",
"combines",
"messages",
"and",
"framework",
".",
"Saves",
"one",
"additional",
"HTTP",
"-",
"Request"
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Http/Controllers/JsLocalizationController.php#L67-L85 | train |
andywer/laravel-js-localization | src/Http/Controllers/JsLocalizationController.php | JsLocalizationController.getMessagesJson | protected function getMessagesJson()
{
$messages = MessageCachingService::getMessagesJson();
$messages = $this->ensureBackwardsCompatibility($messages);
$contents = 'Lang.addMessages(' . $messages . ');';
return $contents;
} | php | protected function getMessagesJson()
{
$messages = MessageCachingService::getMessagesJson();
$messages = $this->ensureBackwardsCompatibility($messages);
$contents = 'Lang.addMessages(' . $messages . ');';
return $contents;
} | [
"protected",
"function",
"getMessagesJson",
"(",
")",
"{",
"$",
"messages",
"=",
"MessageCachingService",
"::",
"getMessagesJson",
"(",
")",
";",
"$",
"messages",
"=",
"$",
"this",
"->",
"ensureBackwardsCompatibility",
"(",
"$",
"messages",
")",
";",
"$",
"con... | Get the configured messages from the translation files
@return string | [
"Get",
"the",
"configured",
"messages",
"from",
"the",
"translation",
"files"
] | 720fb91eb250ac868ad16190162385a6e31acf18 | https://github.com/andywer/laravel-js-localization/blob/720fb91eb250ac868ad16190162385a6e31acf18/src/Http/Controllers/JsLocalizationController.php#L107-L115 | train |
bamarni/composer-bin-plugin | src/BinCommand.php | BinCommand.resetComposers | private function resetComposers(ComposerApplication $application)
{
$application->resetComposer();
foreach ($this->getApplication()->all() as $command) {
if ($command instanceof BaseCommand) {
$command->resetComposer();
}
}
} | php | private function resetComposers(ComposerApplication $application)
{
$application->resetComposer();
foreach ($this->getApplication()->all() as $command) {
if ($command instanceof BaseCommand) {
$command->resetComposer();
}
}
} | [
"private",
"function",
"resetComposers",
"(",
"ComposerApplication",
"$",
"application",
")",
"{",
"$",
"application",
"->",
"resetComposer",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"all",
"(",
")",
"as",
"$",
"c... | Resets all Composer references in the application.
@param ComposerApplication $application | [
"Resets",
"all",
"Composer",
"references",
"in",
"the",
"application",
"."
] | fcf04e1713f580f5e9fd4472e61d34d529e498b1 | https://github.com/bamarni/composer-bin-plugin/blob/fcf04e1713f580f5e9fd4472e61d34d529e498b1/src/BinCommand.php#L131-L139 | train |
wirecardBrasil/moip-sdk-php | src/Resource/OrdersList.php | OrdersList.get | public function get(Pagination $pagination = null, Filters $filters = null, $qParam = '')
{
return $this->getByPath($this->generateListPath($pagination, $filters, ['q' => $qParam]));
} | php | public function get(Pagination $pagination = null, Filters $filters = null, $qParam = '')
{
return $this->getByPath($this->generateListPath($pagination, $filters, ['q' => $qParam]));
} | [
"public",
"function",
"get",
"(",
"Pagination",
"$",
"pagination",
"=",
"null",
",",
"Filters",
"$",
"filters",
"=",
"null",
",",
"$",
"qParam",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"getByPath",
"(",
"$",
"this",
"->",
"generateListPath",
... | Get an order list in MoIP.
@param Pagination $pagination
@param Filters $filters
@param string $qParam Query a specific value.
@return stdClass | [
"Get",
"an",
"order",
"list",
"in",
"MoIP",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/OrdersList.php#L61-L64 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Entry.php | Entry.populate | protected function populate(stdClass $response)
{
$entry = clone $this;
$entry->data->id = $this->getIfSet('id', $response);
$entry->data->status = $this->getIfSet('status', $response);
$entry->data->operation = $this->getIfSet('operation', $response);
if (isset($response->amount)) {
$entry->data->amount->total = $this->getIfSet('total', $response->amount);
$entry->data->amount->fee = $this->getIfSet('fee', $response->amount);
$entry->data->amount->liquid = $this->getIfSet('liquid', $response->amount);
$entry->data->amount->currency = $this->getIfSet('currency', $response->amount);
}
if (isset($response->details)) {
$entry->data->details = $this->getIfSet('details', $response);
}
if (isset($response->{'parent'}) && isset($response->{'parent'}->payments)) {
$payments = new Payment($entry->moip);
$payments->populate($response->{'parent'}->payments);
$entry->data->parentPayments = $payments;
}
return $entry;
} | php | protected function populate(stdClass $response)
{
$entry = clone $this;
$entry->data->id = $this->getIfSet('id', $response);
$entry->data->status = $this->getIfSet('status', $response);
$entry->data->operation = $this->getIfSet('operation', $response);
if (isset($response->amount)) {
$entry->data->amount->total = $this->getIfSet('total', $response->amount);
$entry->data->amount->fee = $this->getIfSet('fee', $response->amount);
$entry->data->amount->liquid = $this->getIfSet('liquid', $response->amount);
$entry->data->amount->currency = $this->getIfSet('currency', $response->amount);
}
if (isset($response->details)) {
$entry->data->details = $this->getIfSet('details', $response);
}
if (isset($response->{'parent'}) && isset($response->{'parent'}->payments)) {
$payments = new Payment($entry->moip);
$payments->populate($response->{'parent'}->payments);
$entry->data->parentPayments = $payments;
}
return $entry;
} | [
"protected",
"function",
"populate",
"(",
"stdClass",
"$",
"response",
")",
"{",
"$",
"entry",
"=",
"clone",
"$",
"this",
";",
"$",
"entry",
"->",
"data",
"->",
"id",
"=",
"$",
"this",
"->",
"getIfSet",
"(",
"'id'",
",",
"$",
"response",
")",
";",
... | Mount the entry.
@param \stdClass $response
@return Entry Entry information. | [
"Mount",
"the",
"entry",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Entry.php#L35-L62 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Entry.php | Entry.get | public function get($id_moip)
{
return $this->getByPath(sprintf('/%s/%s/%s/', MoipResource::VERSION, self::PATH, $id_moip));
} | php | public function get($id_moip)
{
return $this->getByPath(sprintf('/%s/%s/%s/', MoipResource::VERSION, self::PATH, $id_moip));
} | [
"public",
"function",
"get",
"(",
"$",
"id_moip",
")",
"{",
"return",
"$",
"this",
"->",
"getByPath",
"(",
"sprintf",
"(",
"'/%s/%s/%s/'",
",",
"MoipResource",
"::",
"VERSION",
",",
"self",
"::",
"PATH",
",",
"$",
"id_moip",
")",
")",
";",
"}"
] | Get entry in api by id.
@param string $id_moip Event ID that generated the launch.
@return stdClass | [
"Get",
"entry",
"in",
"api",
"by",
"id",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Entry.php#L71-L74 | train |
wirecardBrasil/moip-sdk-php | src/Resource/WebhookList.php | WebhookList.populate | protected function populate(stdClass $response)
{
$webhookList = clone $this;
$webhookList->data = new stdClass();
$webhookList->data->webhooks = $response->webhooks;
return $webhookList;
} | php | protected function populate(stdClass $response)
{
$webhookList = clone $this;
$webhookList->data = new stdClass();
$webhookList->data->webhooks = $response->webhooks;
return $webhookList;
} | [
"protected",
"function",
"populate",
"(",
"stdClass",
"$",
"response",
")",
"{",
"$",
"webhookList",
"=",
"clone",
"$",
"this",
";",
"$",
"webhookList",
"->",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"webhookList",
"->",
"data",
"->",
"webhook... | Mount structure of Webhook List.
@param \stdClass $response
@return \Moip\Resource\WebhookList Webhook List | [
"Mount",
"structure",
"of",
"Webhook",
"List",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/WebhookList.php#L70-L78 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Holder.php | Holder.setAddress | public function setAddress($type, $street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY)
{
$address = new stdClass();
$address->street = $street;
$address->streetNumber = $number;
$address->complement = $complement;
$address->district = $district;
$address->city = $city;
$address->state = $state;
$address->country = $country;
$address->zipCode = $zip;
$this->data->billingAddress = $address;
return $this;
} | php | public function setAddress($type, $street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY)
{
$address = new stdClass();
$address->street = $street;
$address->streetNumber = $number;
$address->complement = $complement;
$address->district = $district;
$address->city = $city;
$address->state = $state;
$address->country = $country;
$address->zipCode = $zip;
$this->data->billingAddress = $address;
return $this;
} | [
"public",
"function",
"setAddress",
"(",
"$",
"type",
",",
"$",
"street",
",",
"$",
"number",
",",
"$",
"district",
",",
"$",
"city",
",",
"$",
"state",
",",
"$",
"zip",
",",
"$",
"complement",
"=",
"null",
",",
"$",
"country",
"=",
"self",
"::",
... | Add a new address to the holder.
@param string $type Address type: BILLING.
@param string $street Street address.
@param string $number Number address.
@param string $district Neighborhood address.
@param string $city City address.
@param string $state State address.
@param string $zip The zip code billing address.
@param string $complement Address complement.
@param string $country Country ISO-alpha3 format, BRA example.
@return $this | [
"Add",
"a",
"new",
"address",
"to",
"the",
"holder",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Holder.php#L56-L71 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Holder.php | Holder.populate | protected function populate(stdClass $response)
{
$holder = clone $this;
$holder->data = new stdClass();
$holder->data->fullname = $this->getIfSet('fullname', $response);
$holder->data->phone = new stdClass();
$phone = $this->getIfSet('phone', $response);
$holder->data->phone->countryCode = $this->getIfSet('countryCode', $phone);
$holder->data->phone->areaCode = $this->getIfSet('areaCode', $phone);
$holder->data->phone->number = $this->getIfSet('number', $phone);
$holder->data->birthDate = $this->getIfSet('birthDate', $response);
$holder->data->taxDocument = new stdClass();
$holder->data->taxDocument->type = $this->getIfSet('type', $this->getIfSet('taxDocument', $response));
$holder->data->taxDocument->number = $this->getIfSet('number', $this->getIfSet('taxDocument', $response));
$holder->data->billingAddress = $this->getIfSet('billingAddress', $response);
return $holder;
} | php | protected function populate(stdClass $response)
{
$holder = clone $this;
$holder->data = new stdClass();
$holder->data->fullname = $this->getIfSet('fullname', $response);
$holder->data->phone = new stdClass();
$phone = $this->getIfSet('phone', $response);
$holder->data->phone->countryCode = $this->getIfSet('countryCode', $phone);
$holder->data->phone->areaCode = $this->getIfSet('areaCode', $phone);
$holder->data->phone->number = $this->getIfSet('number', $phone);
$holder->data->birthDate = $this->getIfSet('birthDate', $response);
$holder->data->taxDocument = new stdClass();
$holder->data->taxDocument->type = $this->getIfSet('type', $this->getIfSet('taxDocument', $response));
$holder->data->taxDocument->number = $this->getIfSet('number', $this->getIfSet('taxDocument', $response));
$holder->data->billingAddress = $this->getIfSet('billingAddress', $response);
return $holder;
} | [
"protected",
"function",
"populate",
"(",
"stdClass",
"$",
"response",
")",
"{",
"$",
"holder",
"=",
"clone",
"$",
"this",
";",
"$",
"holder",
"->",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"holder",
"->",
"data",
"->",
"fullname",
"=",
"$... | Mount the buyer structure from holder.
@param \stdClass $response
@return Holder information. | [
"Mount",
"the",
"buyer",
"structure",
"from",
"holder",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Holder.php#L160-L179 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Holder.php | Holder.setBirthDate | public function setBirthDate($birthDate)
{
if ($birthDate instanceof \DateTime) {
$birthDate = $birthDate->format('Y-m-d');
}
$this->data->birthDate = $birthDate;
return $this;
} | php | public function setBirthDate($birthDate)
{
if ($birthDate instanceof \DateTime) {
$birthDate = $birthDate->format('Y-m-d');
}
$this->data->birthDate = $birthDate;
return $this;
} | [
"public",
"function",
"setBirthDate",
"(",
"$",
"birthDate",
")",
"{",
"if",
"(",
"$",
"birthDate",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"birthDate",
"=",
"$",
"birthDate",
"->",
"format",
"(",
"'Y-m-d'",
")",
";",
"}",
"$",
"this",
"->",
"da... | Set birth date from holder.
@param \DateTime|string $birthDate Date of birth of the credit card holder.
@return $this | [
"Set",
"birth",
"date",
"from",
"holder",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Holder.php#L202-L211 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Holder.php | Holder.setTaxDocument | public function setTaxDocument($number, $type = self::TAX_DOCUMENT)
{
$this->data->taxDocument = new stdClass();
$this->data->taxDocument->type = $type;
$this->data->taxDocument->number = $number;
return $this;
} | php | public function setTaxDocument($number, $type = self::TAX_DOCUMENT)
{
$this->data->taxDocument = new stdClass();
$this->data->taxDocument->type = $type;
$this->data->taxDocument->number = $number;
return $this;
} | [
"public",
"function",
"setTaxDocument",
"(",
"$",
"number",
",",
"$",
"type",
"=",
"self",
"::",
"TAX_DOCUMENT",
")",
"{",
"$",
"this",
"->",
"data",
"->",
"taxDocument",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"this",
"->",
"data",
"->",
"taxDocum... | Set tax document from holder.
@param string $number Document number.
@param string $type Document type.
@return $this | [
"Set",
"tax",
"document",
"from",
"holder",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Holder.php#L221-L228 | train |
wirecardBrasil/moip-sdk-php | src/Auth/BasicAuth.php | BasicAuth.before_request | public function before_request(&$url, &$headers, &$data, &$type, &$options)
{
$headers['Authorization'] = 'Basic '.base64_encode($this->token.':'.$this->key);
} | php | public function before_request(&$url, &$headers, &$data, &$type, &$options)
{
$headers['Authorization'] = 'Basic '.base64_encode($this->token.':'.$this->key);
} | [
"public",
"function",
"before_request",
"(",
"&",
"$",
"url",
",",
"&",
"$",
"headers",
",",
"&",
"$",
"data",
",",
"&",
"$",
"type",
",",
"&",
"$",
"options",
")",
"{",
"$",
"headers",
"[",
"'Authorization'",
"]",
"=",
"'Basic '",
".",
"base64_encod... | Sets the authentication header.
@param string $url
@param array $headers
@param array|string $data
@param string $type
@param array $options | [
"Sets",
"the",
"authentication",
"header",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Auth/BasicAuth.php#L58-L61 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Balances.php | Balances.populate | protected function populate(stdClass $response)
{
$balances = clone $this;
$balances->data->unavailable = $this->getIfSet('unavailable', $response) ?: [];
$balances->data->future = $this->getIfSet('future', $response) ?: [];
$balances->data->current = $this->getIfSet('current', $response) ?: [];
return $balances;
} | php | protected function populate(stdClass $response)
{
$balances = clone $this;
$balances->data->unavailable = $this->getIfSet('unavailable', $response) ?: [];
$balances->data->future = $this->getIfSet('future', $response) ?: [];
$balances->data->current = $this->getIfSet('current', $response) ?: [];
return $balances;
} | [
"protected",
"function",
"populate",
"(",
"stdClass",
"$",
"response",
")",
"{",
"$",
"balances",
"=",
"clone",
"$",
"this",
";",
"$",
"balances",
"->",
"data",
"->",
"unavailable",
"=",
"$",
"this",
"->",
"getIfSet",
"(",
"'unavailable'",
",",
"$",
"res... | Populate this instance.
@param stdClass $response response object
@return mixed|Balances | [
"Populate",
"this",
"instance",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Balances.php#L37-L45 | train |
wirecardBrasil/moip-sdk-php | src/Resource/Balances.php | Balances.get | public function get()
{
$path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH);
return $this->getByPath($path, ['Accept' => static::ACCEPT_VERSION]);
} | php | public function get()
{
$path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH);
return $this->getByPath($path, ['Accept' => static::ACCEPT_VERSION]);
} | [
"public",
"function",
"get",
"(",
")",
"{",
"$",
"path",
"=",
"sprintf",
"(",
"'/%s/%s'",
",",
"MoipResource",
"::",
"VERSION",
",",
"self",
"::",
"PATH",
")",
";",
"return",
"$",
"this",
"->",
"getByPath",
"(",
"$",
"path",
",",
"[",
"'Accept'",
"=>... | Get all balances.
@return stdClass | [
"Get",
"all",
"balances",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/Balances.php#L52-L57 | train |
wirecardBrasil/moip-sdk-php | src/Resource/MoipResource.php | MoipResource.getIfSet | protected function getIfSet($key, stdClass $data = null)
{
if (empty($data)) {
$data = $this->data;
}
if (isset($data->$key)) {
return $data->$key;
}
} | php | protected function getIfSet($key, stdClass $data = null)
{
if (empty($data)) {
$data = $this->data;
}
if (isset($data->$key)) {
return $data->$key;
}
} | [
"protected",
"function",
"getIfSet",
"(",
"$",
"key",
",",
"stdClass",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
";",
"}",
"if",
"(",
"isset",
"(",
"$",... | Get a key of an object if it exists.
@param string $key
@param \stdClass|null $data
@return mixed | [
"Get",
"a",
"key",
"of",
"an",
"object",
"if",
"it",
"exists",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/MoipResource.php#L78-L87 | train |
wirecardBrasil/moip-sdk-php | src/Resource/MoipResource.php | MoipResource.generatePath | public function generatePath($action, $id = null)
{
if (!is_null($id)) {
return sprintf('%s/%s/%s/%s', self::VERSION, static::PATH, $action, $id);
}
return sprintf('%s/%s/%s', self::VERSION, static::PATH, $action);
} | php | public function generatePath($action, $id = null)
{
if (!is_null($id)) {
return sprintf('%s/%s/%s/%s', self::VERSION, static::PATH, $action, $id);
}
return sprintf('%s/%s/%s', self::VERSION, static::PATH, $action);
} | [
"public",
"function",
"generatePath",
"(",
"$",
"action",
",",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"id",
")",
")",
"{",
"return",
"sprintf",
"(",
"'%s/%s/%s/%s'",
",",
"self",
"::",
"VERSION",
",",
"static",
"::",
... | Generate URL to request.
@param $action
@param $id
@return string | [
"Generate",
"URL",
"to",
"request",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/MoipResource.php#L169-L176 | train |
wirecardBrasil/moip-sdk-php | src/Resource/MoipResource.php | MoipResource.generateListPath | public function generateListPath(Pagination $pagination = null, Filters $filters = null, $params = [])
{
$queryParams = [];
if (!is_null($pagination)) {
if ($pagination->getLimit() != 0) {
$queryParams['limit'] = $pagination->getLimit();
}
if ($pagination->getOffset() >= 0) {
$queryParams['offset'] = $pagination->getOffset();
}
}
if (!is_null($filters)) {
$queryParams['filters'] = $filters->__toString();
}
if (!empty($params)) {
$queryParams = array_merge($queryParams, $params);
}
if (!empty($queryParams)) {
return sprintf('/%s/%s?%s', self::VERSION, static::PATH, http_build_query($queryParams));
}
return sprintf('/%s/%s', self::VERSION, static::PATH);
} | php | public function generateListPath(Pagination $pagination = null, Filters $filters = null, $params = [])
{
$queryParams = [];
if (!is_null($pagination)) {
if ($pagination->getLimit() != 0) {
$queryParams['limit'] = $pagination->getLimit();
}
if ($pagination->getOffset() >= 0) {
$queryParams['offset'] = $pagination->getOffset();
}
}
if (!is_null($filters)) {
$queryParams['filters'] = $filters->__toString();
}
if (!empty($params)) {
$queryParams = array_merge($queryParams, $params);
}
if (!empty($queryParams)) {
return sprintf('/%s/%s?%s', self::VERSION, static::PATH, http_build_query($queryParams));
}
return sprintf('/%s/%s', self::VERSION, static::PATH);
} | [
"public",
"function",
"generateListPath",
"(",
"Pagination",
"$",
"pagination",
"=",
"null",
",",
"Filters",
"$",
"filters",
"=",
"null",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"queryParams",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_null",
... | Generate URL to request a get list.
@param Pagination $pagination
@param Filters $filters
@param array $params
@return string | [
"Generate",
"URL",
"to",
"request",
"a",
"get",
"list",
"."
] | 28610a664c0058fa77d1b956a6506591376d39f2 | https://github.com/wirecardBrasil/moip-sdk-php/blob/28610a664c0058fa77d1b956a6506591376d39f2/src/Resource/MoipResource.php#L187-L214 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.