id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
222,300
|
nabbar/SwaggerValidator-PHP
|
src/Common/Context.php
|
Context.logModel
|
public function logModel($method = null, $line = null)
{
if (self::getConfig('log', 'model')) {
$this->logMessage('MODEL', 'Model Created "' . $this->getDataPath() . '"', $method, $line);
}
}
|
php
|
public function logModel($method = null, $line = null)
{
if (self::getConfig('log', 'model')) {
$this->logMessage('MODEL', 'Model Created "' . $this->getDataPath() . '"', $method, $line);
}
}
|
[
"public",
"function",
"logModel",
"(",
"$",
"method",
"=",
"null",
",",
"$",
"line",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"getConfig",
"(",
"'log'",
",",
"'model'",
")",
")",
"{",
"$",
"this",
"->",
"logMessage",
"(",
"'MODEL'",
",",
"'Model Created \"'",
".",
"$",
"this",
"->",
"getDataPath",
"(",
")",
".",
"'\"'",
",",
"$",
"method",
",",
"$",
"line",
")",
";",
"}",
"}"
] |
Log a creation model success
@param string $path
@param string $method
@param int $line
|
[
"Log",
"a",
"creation",
"model",
"success"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/Context.php#L845-L850
|
222,301
|
nabbar/SwaggerValidator-PHP
|
src/Common/Context.php
|
Context.logReference
|
public function logReference($type, $ref, $oldRef = null, $method = null, $line = null)
{
if (self::getConfig('log', 'reference') || self::getConfig('log', $type . 'Ref')) {
switch ($type) {
case 'replace':
$this->logMessage('REPLACE REF', 'Replacing Reference From "' . $oldRef . '" to "' . $ref . '"', $method, $line);
break;
case 'load':
$this->logMessage('LOAD REF', 'Loading Reference : "' . $ref . '"', $method, $line);
break;
case 'register':
$this->logMessage('REGISTER REF', 'Registier Reference Definition : "' . $ref . '"', $method, $line);
break;
case 'drop':
$this->logMessage('DROP REF', 'Drop Reference : "' . $ref . '"', $method, $line);
break;
}
}
}
|
php
|
public function logReference($type, $ref, $oldRef = null, $method = null, $line = null)
{
if (self::getConfig('log', 'reference') || self::getConfig('log', $type . 'Ref')) {
switch ($type) {
case 'replace':
$this->logMessage('REPLACE REF', 'Replacing Reference From "' . $oldRef . '" to "' . $ref . '"', $method, $line);
break;
case 'load':
$this->logMessage('LOAD REF', 'Loading Reference : "' . $ref . '"', $method, $line);
break;
case 'register':
$this->logMessage('REGISTER REF', 'Registier Reference Definition : "' . $ref . '"', $method, $line);
break;
case 'drop':
$this->logMessage('DROP REF', 'Drop Reference : "' . $ref . '"', $method, $line);
break;
}
}
}
|
[
"public",
"function",
"logReference",
"(",
"$",
"type",
",",
"$",
"ref",
",",
"$",
"oldRef",
"=",
"null",
",",
"$",
"method",
"=",
"null",
",",
"$",
"line",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"getConfig",
"(",
"'log'",
",",
"'reference'",
")",
"||",
"self",
"::",
"getConfig",
"(",
"'log'",
",",
"$",
"type",
".",
"'Ref'",
")",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'replace'",
":",
"$",
"this",
"->",
"logMessage",
"(",
"'REPLACE REF'",
",",
"'Replacing Reference From \"'",
".",
"$",
"oldRef",
".",
"'\" to \"'",
".",
"$",
"ref",
".",
"'\"'",
",",
"$",
"method",
",",
"$",
"line",
")",
";",
"break",
";",
"case",
"'load'",
":",
"$",
"this",
"->",
"logMessage",
"(",
"'LOAD REF'",
",",
"'Loading Reference : \"'",
".",
"$",
"ref",
".",
"'\"'",
",",
"$",
"method",
",",
"$",
"line",
")",
";",
"break",
";",
"case",
"'register'",
":",
"$",
"this",
"->",
"logMessage",
"(",
"'REGISTER REF'",
",",
"'Registier Reference Definition : \"'",
".",
"$",
"ref",
".",
"'\"'",
",",
"$",
"method",
",",
"$",
"line",
")",
";",
"break",
";",
"case",
"'drop'",
":",
"$",
"this",
"->",
"logMessage",
"(",
"'DROP REF'",
",",
"'Drop Reference : \"'",
".",
"$",
"ref",
".",
"'\"'",
",",
"$",
"method",
",",
"$",
"line",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
Log an external reference action
@param string $type Type of action
@param string $ref
@param string $oldRef
@param string $method
@param int $line
|
[
"Log",
"an",
"external",
"reference",
"action"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/Context.php#L860-L878
|
222,302
|
nabbar/SwaggerValidator-PHP
|
src/Common/Context.php
|
Context.logMessage
|
public function logMessage($type, $message, $method = null, $line = null)
{
if (is_array($message) || is_object($message)) {
$message = \SwaggerValidator\Common\Collection::jsonEncode($message);
}
print "[" . date('Y-m-d H:i:s') . "][{$type}][{{$method}#{$line}] - {$message} \n";
//file_put_contents('php://stdout', "[" . date('Y-m-d H:i:s') . "][DEBUG][{{$method}#{$line}] - {$message} \n");
}
|
php
|
public function logMessage($type, $message, $method = null, $line = null)
{
if (is_array($message) || is_object($message)) {
$message = \SwaggerValidator\Common\Collection::jsonEncode($message);
}
print "[" . date('Y-m-d H:i:s') . "][{$type}][{{$method}#{$line}] - {$message} \n";
//file_put_contents('php://stdout', "[" . date('Y-m-d H:i:s') . "][DEBUG][{{$method}#{$line}] - {$message} \n");
}
|
[
"public",
"function",
"logMessage",
"(",
"$",
"type",
",",
"$",
"message",
",",
"$",
"method",
"=",
"null",
",",
"$",
"line",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
"||",
"is_object",
"(",
"$",
"message",
")",
")",
"{",
"$",
"message",
"=",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Collection",
"::",
"jsonEncode",
"(",
"$",
"message",
")",
";",
"}",
"print",
"\"[\"",
".",
"date",
"(",
"'Y-m-d H:i:s'",
")",
".",
"\"][{$type}][{{$method}#{$line}] - {$message} \\n\"",
";",
"//file_put_contents('php://stdout', \"[\" . date('Y-m-d H:i:s') . \"][DEBUG][{{$method}#{$line}] - {$message} \\n\");",
"}"
] |
Used to customizing log and more when a debug is send
@param string $message
@param mixed $context
@param string $method
@param TypeInteger $line
|
[
"Used",
"to",
"customizing",
"log",
"and",
"more",
"when",
"a",
"debug",
"is",
"send"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/Context.php#L888-L896
|
222,303
|
nabbar/SwaggerValidator-PHP
|
src/Common/Context.php
|
Context.throwException
|
public function throwException($message, $method = null, $line = null)
{
$this->logException($message, $method, $line);
$e = new \SwaggerValidator\Exception($message);
$e->setFile($method);
$e->setLine($line);
$e->setContext($this);
throw $e;
}
|
php
|
public function throwException($message, $method = null, $line = null)
{
$this->logException($message, $method, $line);
$e = new \SwaggerValidator\Exception($message);
$e->setFile($method);
$e->setLine($line);
$e->setContext($this);
throw $e;
}
|
[
"public",
"function",
"throwException",
"(",
"$",
"message",
",",
"$",
"method",
"=",
"null",
",",
"$",
"line",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"logException",
"(",
"$",
"message",
",",
"$",
"method",
",",
"$",
"line",
")",
";",
"$",
"e",
"=",
"new",
"\\",
"SwaggerValidator",
"\\",
"Exception",
"(",
"$",
"message",
")",
";",
"$",
"e",
"->",
"setFile",
"(",
"$",
"method",
")",
";",
"$",
"e",
"->",
"setLine",
"(",
"$",
"line",
")",
";",
"$",
"e",
"->",
"setContext",
"(",
"$",
"this",
")",
";",
"throw",
"$",
"e",
";",
"}"
] |
Throw a new \SwaggerValidator\Exception with automatic find method, line, ...
@param string $message
@param mixed $context
@throws \SwaggerValidator\Exception
|
[
"Throw",
"a",
"new",
"\\",
"SwaggerValidator",
"\\",
"Exception",
"with",
"automatic",
"find",
"method",
"line",
"..."
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/Context.php#L931-L942
|
222,304
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.prepareTransaction
|
private function prepareTransaction(AbstractTransactionCommand $transaction, bool $force = false): void
{
if (!$force && (null !== $transaction->getLastMsid()) && (null !== $transaction->getLastHash())) {
return;
}
$sender = $transaction->getSender();
if (null !== $sender) {
$resp = $this->getAccount($sender);
} else {
$resp = $this->getMe();
}
$transaction->setLastMsid($resp->getAccount()->getMsid());
$transaction->setLastHash($resp->getAccount()->getHash());
}
|
php
|
private function prepareTransaction(AbstractTransactionCommand $transaction, bool $force = false): void
{
if (!$force && (null !== $transaction->getLastMsid()) && (null !== $transaction->getLastHash())) {
return;
}
$sender = $transaction->getSender();
if (null !== $sender) {
$resp = $this->getAccount($sender);
} else {
$resp = $this->getMe();
}
$transaction->setLastMsid($resp->getAccount()->getMsid());
$transaction->setLastHash($resp->getAccount()->getHash());
}
|
[
"private",
"function",
"prepareTransaction",
"(",
"AbstractTransactionCommand",
"$",
"transaction",
",",
"bool",
"$",
"force",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"force",
"&&",
"(",
"null",
"!==",
"$",
"transaction",
"->",
"getLastMsid",
"(",
")",
")",
"&&",
"(",
"null",
"!==",
"$",
"transaction",
"->",
"getLastHash",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"sender",
"=",
"$",
"transaction",
"->",
"getSender",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"sender",
")",
"{",
"$",
"resp",
"=",
"$",
"this",
"->",
"getAccount",
"(",
"$",
"sender",
")",
";",
"}",
"else",
"{",
"$",
"resp",
"=",
"$",
"this",
"->",
"getMe",
"(",
")",
";",
"}",
"$",
"transaction",
"->",
"setLastMsid",
"(",
"$",
"resp",
"->",
"getAccount",
"(",
")",
"->",
"getMsid",
"(",
")",
")",
";",
"$",
"transaction",
"->",
"setLastHash",
"(",
"$",
"resp",
"->",
"getAccount",
"(",
")",
"->",
"getHash",
"(",
")",
")",
";",
"}"
] |
Fills last account hash and message id in request. Function needs to be called before transaction.
Otherwise above parameters should be passed explicitly.
@param AbstractTransactionCommand $transaction
@param bool $force force set msid and hash
@throws CommandException
|
[
"Fills",
"last",
"account",
"hash",
"and",
"message",
"id",
"in",
"request",
".",
"Function",
"needs",
"to",
"be",
"called",
"before",
"transaction",
".",
"Otherwise",
"above",
"parameters",
"should",
"be",
"passed",
"explicitly",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L105-L119
|
222,305
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.changeAccountKey
|
public function changeAccountKey(ChangeAccountKeyCommand $command, bool $isDryRun = false): ChangeAccountKeyResponse
{
$this->prepareTransaction($command);
$response = $this->driver->executeTransaction($command, $isDryRun);
return new ChangeAccountKeyResponse($response->getRawData());
}
|
php
|
public function changeAccountKey(ChangeAccountKeyCommand $command, bool $isDryRun = false): ChangeAccountKeyResponse
{
$this->prepareTransaction($command);
$response = $this->driver->executeTransaction($command, $isDryRun);
return new ChangeAccountKeyResponse($response->getRawData());
}
|
[
"public",
"function",
"changeAccountKey",
"(",
"ChangeAccountKeyCommand",
"$",
"command",
",",
"bool",
"$",
"isDryRun",
"=",
"false",
")",
":",
"ChangeAccountKeyResponse",
"{",
"$",
"this",
"->",
"prepareTransaction",
"(",
"$",
"command",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeTransaction",
"(",
"$",
"command",
",",
"$",
"isDryRun",
")",
";",
"return",
"new",
"ChangeAccountKeyResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Executes `change_account_key` transaction.
@param ChangeAccountKeyCommand $command
@param bool $isDryRun if true, transaction won't be send to network
@return ChangeAccountKeyResponse
|
[
"Executes",
"change_account_key",
"transaction",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L128-L134
|
222,306
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.changeNodeKey
|
public function changeNodeKey(ChangeNodeKeyCommand $command, bool $isDryRun = false): ChangeNodeKeyResponse
{
$this->prepareTransaction($command);
$response = $this->driver->executeTransaction($command, $isDryRun);
return new ChangeNodeKeyResponse($response->getRawData());
}
|
php
|
public function changeNodeKey(ChangeNodeKeyCommand $command, bool $isDryRun = false): ChangeNodeKeyResponse
{
$this->prepareTransaction($command);
$response = $this->driver->executeTransaction($command, $isDryRun);
return new ChangeNodeKeyResponse($response->getRawData());
}
|
[
"public",
"function",
"changeNodeKey",
"(",
"ChangeNodeKeyCommand",
"$",
"command",
",",
"bool",
"$",
"isDryRun",
"=",
"false",
")",
":",
"ChangeNodeKeyResponse",
"{",
"$",
"this",
"->",
"prepareTransaction",
"(",
"$",
"command",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeTransaction",
"(",
"$",
"command",
",",
"$",
"isDryRun",
")",
";",
"return",
"new",
"ChangeNodeKeyResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Executes `change_node_key` transaction.
@param ChangeNodeKeyCommand $command
@param bool $isDryRun if true, transaction won't be send to network
@return ChangeNodeKeyResponse
|
[
"Executes",
"change_node_key",
"transaction",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L143-L149
|
222,307
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.createAccount
|
public function createAccount(CreateAccountCommand $command, bool $isDryRun = false): CreateAccountResponse
{
$this->prepareTransaction($command);
$response = $this->driver->executeTransaction($command, $isDryRun);
return new CreateAccountResponse($response->getRawData());
}
|
php
|
public function createAccount(CreateAccountCommand $command, bool $isDryRun = false): CreateAccountResponse
{
$this->prepareTransaction($command);
$response = $this->driver->executeTransaction($command, $isDryRun);
return new CreateAccountResponse($response->getRawData());
}
|
[
"public",
"function",
"createAccount",
"(",
"CreateAccountCommand",
"$",
"command",
",",
"bool",
"$",
"isDryRun",
"=",
"false",
")",
":",
"CreateAccountResponse",
"{",
"$",
"this",
"->",
"prepareTransaction",
"(",
"$",
"command",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeTransaction",
"(",
"$",
"command",
",",
"$",
"isDryRun",
")",
";",
"return",
"new",
"CreateAccountResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Executes `create_account` transaction.
@param CreateAccountCommand $command
@param bool $isDryRun if true, transaction won't be send to network
@return CreateAccountResponse
|
[
"Executes",
"create_account",
"transaction",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L158-L164
|
222,308
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getAccount
|
public function getAccount(string $address): GetAccountResponse
{
$command = new GetAccountCommand($address);
$response = $this->driver->executeCommand($command);
return new GetAccountResponse($response->getRawData());
}
|
php
|
public function getAccount(string $address): GetAccountResponse
{
$command = new GetAccountCommand($address);
$response = $this->driver->executeCommand($command);
return new GetAccountResponse($response->getRawData());
}
|
[
"public",
"function",
"getAccount",
"(",
"string",
"$",
"address",
")",
":",
"GetAccountResponse",
"{",
"$",
"command",
"=",
"new",
"GetAccountCommand",
"(",
"$",
"address",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetAccountResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns account data.
@param string $address account address
@return GetAccountResponse
@throws CommandException
|
[
"Returns",
"account",
"data",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L175-L181
|
222,309
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getAccounts
|
public function getAccounts(string $nodeId, ?string $blockId = null): GetAccountsResponse
{
$node = hexdec($nodeId);
$command = new GetAccountsCommand($node, $blockId);
$response = $this->driver->executeCommand($command);
return new GetAccountsResponse($response->getRawData());
}
|
php
|
public function getAccounts(string $nodeId, ?string $blockId = null): GetAccountsResponse
{
$node = hexdec($nodeId);
$command = new GetAccountsCommand($node, $blockId);
$response = $this->driver->executeCommand($command);
return new GetAccountsResponse($response->getRawData());
}
|
[
"public",
"function",
"getAccounts",
"(",
"string",
"$",
"nodeId",
",",
"?",
"string",
"$",
"blockId",
"=",
"null",
")",
":",
"GetAccountsResponse",
"{",
"$",
"node",
"=",
"hexdec",
"(",
"$",
"nodeId",
")",
";",
"$",
"command",
"=",
"new",
"GetAccountsCommand",
"(",
"$",
"node",
",",
"$",
"blockId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetAccountsResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns account list for node.
@param string $nodeId node id (hex)
@param null|string $blockId block id, time in Unix Epoch seconds as hexadecimal string.
If null, last block will be taken.
@return GetAccountsResponse
@throws CommandException
|
[
"Returns",
"account",
"list",
"for",
"node",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L194-L201
|
222,310
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getBlock
|
public function getBlock(?string $blockId = null): GetBlockResponse
{
$command = new GetBlockCommand($blockId);
$response = $this->driver->executeCommand($command);
return new GetBlockResponse($response->getRawData());
}
|
php
|
public function getBlock(?string $blockId = null): GetBlockResponse
{
$command = new GetBlockCommand($blockId);
$response = $this->driver->executeCommand($command);
return new GetBlockResponse($response->getRawData());
}
|
[
"public",
"function",
"getBlock",
"(",
"?",
"string",
"$",
"blockId",
"=",
"null",
")",
":",
"GetBlockResponse",
"{",
"$",
"command",
"=",
"new",
"GetBlockCommand",
"(",
"$",
"blockId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetBlockResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns block data.
@param null|string $blockId block id, time in Unix Epoch seconds as hexadecimal string.
If null, last block will be taken.
@return GetBlockResponse
@throws CommandException
|
[
"Returns",
"block",
"data",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L213-L219
|
222,311
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getBlockIds
|
public function getBlockIds(?string $blockIdFrom = null, ?string $blockIdTo = null): GetBlockIdsResponse
{
$command = new GetBlockIdsCommand($blockIdFrom, $blockIdTo);
$response = $this->driver->executeCommand($command);
return new GetBlockIdsResponse($response->getRawData());
}
|
php
|
public function getBlockIds(?string $blockIdFrom = null, ?string $blockIdTo = null): GetBlockIdsResponse
{
$command = new GetBlockIdsCommand($blockIdFrom, $blockIdTo);
$response = $this->driver->executeCommand($command);
return new GetBlockIdsResponse($response->getRawData());
}
|
[
"public",
"function",
"getBlockIds",
"(",
"?",
"string",
"$",
"blockIdFrom",
"=",
"null",
",",
"?",
"string",
"$",
"blockIdTo",
"=",
"null",
")",
":",
"GetBlockIdsResponse",
"{",
"$",
"command",
"=",
"new",
"GetBlockIdsCommand",
"(",
"$",
"blockIdFrom",
",",
"$",
"blockIdTo",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetBlockIdsResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Updates block data for selected period and returns ids of updated blocks.
@param null|string $blockIdFrom starting block id, time in Unix Epoch seconds as hexadecimal string.
If null, first block (genesis) will be taken.
@param null|string $blockIdTo ending block id, time in Unix Epoch seconds as hexadecimal string.
If null, last block will be taken.
@return GetBlockIdsResponse
@throws CommandException
|
[
"Updates",
"block",
"data",
"for",
"selected",
"period",
"and",
"returns",
"ids",
"of",
"updated",
"blocks",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L233-L239
|
222,312
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getBroadcast
|
public function getBroadcast(?string $blockId = null): GetBroadcastResponse
{
$command = new GetBroadcastCommand($blockId);
$response = $this->driver->executeCommand($command);
return new GetBroadcastResponse($response->getRawData());
}
|
php
|
public function getBroadcast(?string $blockId = null): GetBroadcastResponse
{
$command = new GetBroadcastCommand($blockId);
$response = $this->driver->executeCommand($command);
return new GetBroadcastResponse($response->getRawData());
}
|
[
"public",
"function",
"getBroadcast",
"(",
"?",
"string",
"$",
"blockId",
"=",
"null",
")",
":",
"GetBroadcastResponse",
"{",
"$",
"command",
"=",
"new",
"GetBroadcastCommand",
"(",
"$",
"blockId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetBroadcastResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Collects broadcast messages for particular block. Messages are in random order and can be duplicated.
@param null|string $blockId block id, time in Unix Epoch seconds as hexadecimal string.
If null, last block will be taken.
@return GetBroadcastResponse
@throws CommandException
|
[
"Collects",
"broadcast",
"messages",
"for",
"particular",
"block",
".",
"Messages",
"are",
"in",
"random",
"order",
"and",
"can",
"be",
"duplicated",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L251-L257
|
222,313
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getLog
|
public function getLog(?\DateTime $from = null): GetLogResponse
{
$command = new GetLogCommand($from);
$response = $this->driver->executeCommand($command);
return new GetLogResponse($response->getRawData());
}
|
php
|
public function getLog(?\DateTime $from = null): GetLogResponse
{
$command = new GetLogCommand($from);
$response = $this->driver->executeCommand($command);
return new GetLogResponse($response->getRawData());
}
|
[
"public",
"function",
"getLog",
"(",
"?",
"\\",
"DateTime",
"$",
"from",
"=",
"null",
")",
":",
"GetLogResponse",
"{",
"$",
"command",
"=",
"new",
"GetLogCommand",
"(",
"$",
"from",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetLogResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns available log event.
@param null|\DateTime $from start date of event log
@return GetLogResponse
@throws CommandException
|
[
"Returns",
"available",
"log",
"event",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L268-L274
|
222,314
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getMe
|
public function getMe(): GetAccountResponse
{
$command = new GetMeCommand();
$response = $this->driver->executeCommand($command);
return new GetAccountResponse($response->getRawData());
}
|
php
|
public function getMe(): GetAccountResponse
{
$command = new GetMeCommand();
$response = $this->driver->executeCommand($command);
return new GetAccountResponse($response->getRawData());
}
|
[
"public",
"function",
"getMe",
"(",
")",
":",
"GetAccountResponse",
"{",
"$",
"command",
"=",
"new",
"GetMeCommand",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetAccountResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns current account data. Current account is the account, which was used to initialize AdsClient.
@return GetAccountResponse
@throws CommandException
|
[
"Returns",
"current",
"account",
"data",
".",
"Current",
"account",
"is",
"the",
"account",
"which",
"was",
"used",
"to",
"initialize",
"AdsClient",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L283-L289
|
222,315
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getMessage
|
public function getMessage(string $messageId, ?string $blockId = null): GetMessageResponse
{
$command = new GetMessageCommand($messageId, $blockId);
$response = $this->driver->executeCommand($command);
return new GetMessageResponse($response->getRawData());
}
|
php
|
public function getMessage(string $messageId, ?string $blockId = null): GetMessageResponse
{
$command = new GetMessageCommand($messageId, $blockId);
$response = $this->driver->executeCommand($command);
return new GetMessageResponse($response->getRawData());
}
|
[
"public",
"function",
"getMessage",
"(",
"string",
"$",
"messageId",
",",
"?",
"string",
"$",
"blockId",
"=",
"null",
")",
":",
"GetMessageResponse",
"{",
"$",
"command",
"=",
"new",
"GetMessageCommand",
"(",
"$",
"messageId",
",",
"$",
"blockId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetMessageResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns message data. Each message contains one or more transactions.
@param string $messageId message id
@param null|string $blockId block id, time in Unix Epoch seconds as hexadecimal string.
If null, block will be calculated automatically.
@return GetMessageResponse
@throws CommandException
|
[
"Returns",
"message",
"data",
".",
"Each",
"message",
"contains",
"one",
"or",
"more",
"transactions",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L302-L308
|
222,316
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getMessageIds
|
public function getMessageIds(?string $blockId = null): GetMessageIdsResponse
{
$command = new GetMessageIdsCommand($blockId);
$response = $this->driver->executeCommand($command);
return new GetMessageIdsResponse($response->getRawData());
}
|
php
|
public function getMessageIds(?string $blockId = null): GetMessageIdsResponse
{
$command = new GetMessageIdsCommand($blockId);
$response = $this->driver->executeCommand($command);
return new GetMessageIdsResponse($response->getRawData());
}
|
[
"public",
"function",
"getMessageIds",
"(",
"?",
"string",
"$",
"blockId",
"=",
"null",
")",
":",
"GetMessageIdsResponse",
"{",
"$",
"command",
"=",
"new",
"GetMessageIdsCommand",
"(",
"$",
"blockId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetMessageIdsResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns message ids for selected block.
@param null|string $blockId block id, time in Unix Epoch seconds as hexadecimal string.
If null, last block will be taken.
@return GetMessageIdsResponse
@throws CommandException
|
[
"Returns",
"message",
"ids",
"for",
"selected",
"block",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L320-L326
|
222,317
|
adshares/ads-php-client
|
src/AdsClient.php
|
AdsClient.getTransaction
|
public function getTransaction(string $txid): GetTransactionResponse
{
$command = new GetTransactionCommand($txid);
$response = $this->driver->executeCommand($command);
return new GetTransactionResponse($response->getRawData());
}
|
php
|
public function getTransaction(string $txid): GetTransactionResponse
{
$command = new GetTransactionCommand($txid);
$response = $this->driver->executeCommand($command);
return new GetTransactionResponse($response->getRawData());
}
|
[
"public",
"function",
"getTransaction",
"(",
"string",
"$",
"txid",
")",
":",
"GetTransactionResponse",
"{",
"$",
"command",
"=",
"new",
"GetTransactionCommand",
"(",
"$",
"txid",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"driver",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"return",
"new",
"GetTransactionResponse",
"(",
"$",
"response",
"->",
"getRawData",
"(",
")",
")",
";",
"}"
] |
Returns single transaction data.
@param string $txid transaction id
@return GetTransactionResponse
@throws CommandException
|
[
"Returns",
"single",
"transaction",
"data",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/AdsClient.php#L337-L343
|
222,318
|
nabbar/SwaggerValidator-PHP
|
src/SwaggerAutoload.php
|
SwaggerAutoload.autoload
|
final public static function autoload($className)
{
if (\Phar::running() && defined('PHAR_SWAGGER_VALIDATOR_ROOT_PATH')) {
$baseDir = PHAR_SWAGGER_VALIDATOR_ROOT_PATH;
}
elseif (\Phar::running()) {
$baseDir = null;
}
else {
$baseDir = __DIR__ . DIRECTORY_SEPARATOR;
}
$thisClass = 'SwaggerValidator';
$namespace = explode('\\', $className);
$className = array_pop($namespace);
$rootPath = array_shift($namespace);
if ($rootPath == $thisClass) {
$namespace = $baseDir . trim(implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
}
else {
$namespace = $baseDir . trim($rootPath . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
}
if (substr($namespace, -1, 1) != DIRECTORY_SEPARATOR) {
$namespace .= DIRECTORY_SEPARATOR;
}
if ($namespace == DIRECTORY_SEPARATOR) {
$namespace = "";
}
$fileName = $namespace . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if (file_exists($fileName)) {
require_once $fileName;
}
}
|
php
|
final public static function autoload($className)
{
if (\Phar::running() && defined('PHAR_SWAGGER_VALIDATOR_ROOT_PATH')) {
$baseDir = PHAR_SWAGGER_VALIDATOR_ROOT_PATH;
}
elseif (\Phar::running()) {
$baseDir = null;
}
else {
$baseDir = __DIR__ . DIRECTORY_SEPARATOR;
}
$thisClass = 'SwaggerValidator';
$namespace = explode('\\', $className);
$className = array_pop($namespace);
$rootPath = array_shift($namespace);
if ($rootPath == $thisClass) {
$namespace = $baseDir . trim(implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
}
else {
$namespace = $baseDir . trim($rootPath . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
}
if (substr($namespace, -1, 1) != DIRECTORY_SEPARATOR) {
$namespace .= DIRECTORY_SEPARATOR;
}
if ($namespace == DIRECTORY_SEPARATOR) {
$namespace = "";
}
$fileName = $namespace . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if (file_exists($fileName)) {
require_once $fileName;
}
}
|
[
"final",
"public",
"static",
"function",
"autoload",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"\\",
"Phar",
"::",
"running",
"(",
")",
"&&",
"defined",
"(",
"'PHAR_SWAGGER_VALIDATOR_ROOT_PATH'",
")",
")",
"{",
"$",
"baseDir",
"=",
"PHAR_SWAGGER_VALIDATOR_ROOT_PATH",
";",
"}",
"elseif",
"(",
"\\",
"Phar",
"::",
"running",
"(",
")",
")",
"{",
"$",
"baseDir",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"baseDir",
"=",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"$",
"thisClass",
"=",
"'SwaggerValidator'",
";",
"$",
"namespace",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"className",
")",
";",
"$",
"className",
"=",
"array_pop",
"(",
"$",
"namespace",
")",
";",
"$",
"rootPath",
"=",
"array_shift",
"(",
"$",
"namespace",
")",
";",
"if",
"(",
"$",
"rootPath",
"==",
"$",
"thisClass",
")",
"{",
"$",
"namespace",
"=",
"$",
"baseDir",
".",
"trim",
"(",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"namespace",
")",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
"else",
"{",
"$",
"namespace",
"=",
"$",
"baseDir",
".",
"trim",
"(",
"$",
"rootPath",
".",
"DIRECTORY_SEPARATOR",
".",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"namespace",
")",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"namespace",
",",
"-",
"1",
",",
"1",
")",
"!=",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"namespace",
".=",
"DIRECTORY_SEPARATOR",
";",
"}",
"if",
"(",
"$",
"namespace",
"==",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"namespace",
"=",
"\"\"",
";",
"}",
"$",
"fileName",
"=",
"$",
"namespace",
".",
"str_replace",
"(",
"'_'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"className",
")",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"require_once",
"$",
"fileName",
";",
"}",
"}"
] |
Slim PSR-0 autoloader
|
[
"Slim",
"PSR",
"-",
"0",
"autoloader"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/SwaggerAutoload.php#L38-L76
|
222,319
|
adshares/ads-php-client
|
src/Util/AdsChecksumGenerator.php
|
AdsChecksumGenerator.crc16
|
private static function crc16(string $hexChars): int
{
$chars = hex2bin($hexChars);
if ($chars) {
$crc = 0x1D0F;
for ($i = 0; $i < strlen($chars); $i++) {
$x = ($crc >> 8) ^ ord($chars[$i]);
$x ^= $x >> 4;
$crc = (($crc << 8) ^ ($x << 12) ^ ($x << 5) ^ ($x)) & 0xFFFF;
}
} else {
$crc = 0;
}
return $crc;
}
|
php
|
private static function crc16(string $hexChars): int
{
$chars = hex2bin($hexChars);
if ($chars) {
$crc = 0x1D0F;
for ($i = 0; $i < strlen($chars); $i++) {
$x = ($crc >> 8) ^ ord($chars[$i]);
$x ^= $x >> 4;
$crc = (($crc << 8) ^ ($x << 12) ^ ($x << 5) ^ ($x)) & 0xFFFF;
}
} else {
$crc = 0;
}
return $crc;
}
|
[
"private",
"static",
"function",
"crc16",
"(",
"string",
"$",
"hexChars",
")",
":",
"int",
"{",
"$",
"chars",
"=",
"hex2bin",
"(",
"$",
"hexChars",
")",
";",
"if",
"(",
"$",
"chars",
")",
"{",
"$",
"crc",
"=",
"0x1D0F",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"chars",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"x",
"=",
"(",
"$",
"crc",
">>",
"8",
")",
"^",
"ord",
"(",
"$",
"chars",
"[",
"$",
"i",
"]",
")",
";",
"$",
"x",
"^=",
"$",
"x",
">>",
"4",
";",
"$",
"crc",
"=",
"(",
"(",
"$",
"crc",
"<<",
"8",
")",
"^",
"(",
"$",
"x",
"<<",
"12",
")",
"^",
"(",
"$",
"x",
"<<",
"5",
")",
"^",
"(",
"$",
"x",
")",
")",
"&",
"0xFFFF",
";",
"}",
"}",
"else",
"{",
"$",
"crc",
"=",
"0",
";",
"}",
"return",
"$",
"crc",
";",
"}"
] |
Generates CRC16 checksum.
@param string $hexChars string
@return int checksum
|
[
"Generates",
"CRC16",
"checksum",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/Util/AdsChecksumGenerator.php#L36-L50
|
222,320
|
adshares/ads-php-client
|
src/Util/AdsChecksumGenerator.php
|
AdsChecksumGenerator.getAccountChecksum
|
public static function getAccountChecksum(int $node, int $user): string
{
return sprintf('%04X', self::crc16(sprintf('%04X%08X', $node, $user)));
}
|
php
|
public static function getAccountChecksum(int $node, int $user): string
{
return sprintf('%04X', self::crc16(sprintf('%04X%08X', $node, $user)));
}
|
[
"public",
"static",
"function",
"getAccountChecksum",
"(",
"int",
"$",
"node",
",",
"int",
"$",
"user",
")",
":",
"string",
"{",
"return",
"sprintf",
"(",
"'%04X'",
",",
"self",
"::",
"crc16",
"(",
"sprintf",
"(",
"'%04X%08X'",
",",
"$",
"node",
",",
"$",
"user",
")",
")",
")",
";",
"}"
] |
Generate checksum for account.
@param int $node node number
@param int $user account number in node
@return string
|
[
"Generate",
"checksum",
"for",
"account",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/Util/AdsChecksumGenerator.php#L59-L62
|
222,321
|
paulzi/yii2-materialized-path
|
MaterializedPathBehavior.php
|
MaterializedPathBehavior.getSiblings
|
public function getSiblings($andSelf = false)
{
$tableName = $this->owner->tableName();
$path = $this->getParentPath();
$like = strtr($path . $this->delimiter, ['%' => '\%', '_' => '\_', '\\' => '\\\\']);
$query = $this->owner->find()
->andWhere(['like', "{$tableName}.[[{$this->pathAttribute}]]", $like . '%', false])
->andWhere(['<=', "{$tableName}.[[{$this->depthAttribute}]]", $this->owner->{$this->depthAttribute}]);
if (!$andSelf) {
$query->andWhere(["!=", "{$tableName}.[[{$this->itemAttribute}]]", $this->owner->{$this->itemAttribute}]);
}
$orderBy = [];
$orderBy["{$tableName}.[[{$this->depthAttribute}]]"] = SORT_ASC;
if ($this->sortable !== false) {
$orderBy["{$tableName}.[[{$this->behavior->sortAttribute}]]"] = SORT_ASC;
}
$orderBy["{$tableName}.[[{$this->itemAttribute}]]"] = SORT_ASC;
$query
->andWhere($this->treeCondition())
->addOrderBy($orderBy);
$query->multiple = true;
return $query;
}
|
php
|
public function getSiblings($andSelf = false)
{
$tableName = $this->owner->tableName();
$path = $this->getParentPath();
$like = strtr($path . $this->delimiter, ['%' => '\%', '_' => '\_', '\\' => '\\\\']);
$query = $this->owner->find()
->andWhere(['like', "{$tableName}.[[{$this->pathAttribute}]]", $like . '%', false])
->andWhere(['<=', "{$tableName}.[[{$this->depthAttribute}]]", $this->owner->{$this->depthAttribute}]);
if (!$andSelf) {
$query->andWhere(["!=", "{$tableName}.[[{$this->itemAttribute}]]", $this->owner->{$this->itemAttribute}]);
}
$orderBy = [];
$orderBy["{$tableName}.[[{$this->depthAttribute}]]"] = SORT_ASC;
if ($this->sortable !== false) {
$orderBy["{$tableName}.[[{$this->behavior->sortAttribute}]]"] = SORT_ASC;
}
$orderBy["{$tableName}.[[{$this->itemAttribute}]]"] = SORT_ASC;
$query
->andWhere($this->treeCondition())
->addOrderBy($orderBy);
$query->multiple = true;
return $query;
}
|
[
"public",
"function",
"getSiblings",
"(",
"$",
"andSelf",
"=",
"false",
")",
"{",
"$",
"tableName",
"=",
"$",
"this",
"->",
"owner",
"->",
"tableName",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getParentPath",
"(",
")",
";",
"$",
"like",
"=",
"strtr",
"(",
"$",
"path",
".",
"$",
"this",
"->",
"delimiter",
",",
"[",
"'%'",
"=>",
"'\\%'",
",",
"'_'",
"=>",
"'\\_'",
",",
"'\\\\'",
"=>",
"'\\\\\\\\'",
"]",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"owner",
"->",
"find",
"(",
")",
"->",
"andWhere",
"(",
"[",
"'like'",
",",
"\"{$tableName}.[[{$this->pathAttribute}]]\"",
",",
"$",
"like",
".",
"'%'",
",",
"false",
"]",
")",
"->",
"andWhere",
"(",
"[",
"'<='",
",",
"\"{$tableName}.[[{$this->depthAttribute}]]\"",
",",
"$",
"this",
"->",
"owner",
"->",
"{",
"$",
"this",
"->",
"depthAttribute",
"}",
"]",
")",
";",
"if",
"(",
"!",
"$",
"andSelf",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"[",
"\"!=\"",
",",
"\"{$tableName}.[[{$this->itemAttribute}]]\"",
",",
"$",
"this",
"->",
"owner",
"->",
"{",
"$",
"this",
"->",
"itemAttribute",
"}",
"]",
")",
";",
"}",
"$",
"orderBy",
"=",
"[",
"]",
";",
"$",
"orderBy",
"[",
"\"{$tableName}.[[{$this->depthAttribute}]]\"",
"]",
"=",
"SORT_ASC",
";",
"if",
"(",
"$",
"this",
"->",
"sortable",
"!==",
"false",
")",
"{",
"$",
"orderBy",
"[",
"\"{$tableName}.[[{$this->behavior->sortAttribute}]]\"",
"]",
"=",
"SORT_ASC",
";",
"}",
"$",
"orderBy",
"[",
"\"{$tableName}.[[{$this->itemAttribute}]]\"",
"]",
"=",
"SORT_ASC",
";",
"$",
"query",
"->",
"andWhere",
"(",
"$",
"this",
"->",
"treeCondition",
"(",
")",
")",
"->",
"addOrderBy",
"(",
"$",
"orderBy",
")",
";",
"$",
"query",
"->",
"multiple",
"=",
"true",
";",
"return",
"$",
"query",
";",
"}"
] |
Returns all sibilings of node.
@param bool $andSelf = false Include self node into result.
@return \yii\db\ActiveQuery
|
[
"Returns",
"all",
"sibilings",
"of",
"node",
"."
] |
ece0f8ec52a125522fd8b7d984119789e76e5cdc
|
https://github.com/paulzi/yii2-materialized-path/blob/ece0f8ec52a125522fd8b7d984119789e76e5cdc/MaterializedPathBehavior.php#L316-L342
|
222,322
|
nabbar/SwaggerValidator-PHP
|
src/Common/Factory.php
|
Factory.getClass
|
private function getClass($type)
{
$collType = \SwaggerValidator\Common\CollectionType::getInstance();
$class = $collType->get($type);
if (empty($class)) {
$e = new \SwaggerValidator\Exception('Cannot retrieve the callable for this type : ' . $type);
$e->setFile(__METHOD__);
$e->setLine(__LINE__);
throw $e;
}
return $class;
}
|
php
|
private function getClass($type)
{
$collType = \SwaggerValidator\Common\CollectionType::getInstance();
$class = $collType->get($type);
if (empty($class)) {
$e = new \SwaggerValidator\Exception('Cannot retrieve the callable for this type : ' . $type);
$e->setFile(__METHOD__);
$e->setLine(__LINE__);
throw $e;
}
return $class;
}
|
[
"private",
"function",
"getClass",
"(",
"$",
"type",
")",
"{",
"$",
"collType",
"=",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"CollectionType",
"::",
"getInstance",
"(",
")",
";",
"$",
"class",
"=",
"$",
"collType",
"->",
"get",
"(",
"$",
"type",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"class",
")",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"SwaggerValidator",
"\\",
"Exception",
"(",
"'Cannot retrieve the callable for this type : '",
".",
"$",
"type",
")",
";",
"$",
"e",
"->",
"setFile",
"(",
"__METHOD__",
")",
";",
"$",
"e",
"->",
"setLine",
"(",
"__LINE__",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"class",
";",
"}"
] |
Check if the type is defined and return his callable string
@param callable $type
@throws Exception
|
[
"Check",
"if",
"the",
"type",
"is",
"defined",
"and",
"return",
"his",
"callable",
"string"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/Factory.php#L102-L115
|
222,323
|
nabbar/SwaggerValidator-PHP
|
src/Common/Factory.php
|
Factory.invoke
|
public function invoke($type, $parameters = null)
{
$class = $this->getClass($type);
$name = $this->normalizeType($type);
$params = func_get_args();
array_shift($params);
$reflector = new \ReflectionClass($class);
$instance = $reflector->newInstanceArgs($params);
if (empty($params)) {
parent::__set($name, $instance);
}
return (clone $instance);
}
|
php
|
public function invoke($type, $parameters = null)
{
$class = $this->getClass($type);
$name = $this->normalizeType($type);
$params = func_get_args();
array_shift($params);
$reflector = new \ReflectionClass($class);
$instance = $reflector->newInstanceArgs($params);
if (empty($params)) {
parent::__set($name, $instance);
}
return (clone $instance);
}
|
[
"public",
"function",
"invoke",
"(",
"$",
"type",
",",
"$",
"parameters",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getClass",
"(",
"$",
"type",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"normalizeType",
"(",
"$",
"type",
")",
";",
"$",
"params",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"params",
")",
";",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"instance",
"=",
"$",
"reflector",
"->",
"newInstanceArgs",
"(",
"$",
"params",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"parent",
"::",
"__set",
"(",
"$",
"name",
",",
"$",
"instance",
")",
";",
"}",
"return",
"(",
"clone",
"$",
"instance",
")",
";",
"}"
] |
Start new instance of the object type
@param string $type the name of the object type for the new instance
@param type $parameters [optional] the parameters to the constructor
@return object
@throws Exception
|
[
"Start",
"new",
"instance",
"of",
"the",
"object",
"type"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/Factory.php#L144-L160
|
222,324
|
nabbar/SwaggerValidator-PHP
|
src/Common/Factory.php
|
Factory.registerClosure
|
public function registerClosure($type, $object)
{
$class = $this->getClass($type);
$name = $this->normalizeType($type);
if (is_object($object) || ($object instanceof \Closure)) {
parent::__set($name, $object);
return true;
}
return false;
}
|
php
|
public function registerClosure($type, $object)
{
$class = $this->getClass($type);
$name = $this->normalizeType($type);
if (is_object($object) || ($object instanceof \Closure)) {
parent::__set($name, $object);
return true;
}
return false;
}
|
[
"public",
"function",
"registerClosure",
"(",
"$",
"type",
",",
"$",
"object",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getClass",
"(",
"$",
"type",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"normalizeType",
"(",
"$",
"type",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"||",
"(",
"$",
"object",
"instanceof",
"\\",
"Closure",
")",
")",
"{",
"parent",
"::",
"__set",
"(",
"$",
"name",
",",
"$",
"object",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Register the base instance to be clone when a new instance is call
@param string $type
@param object|\Closure $object
|
[
"Register",
"the",
"base",
"instance",
"to",
"be",
"clone",
"when",
"a",
"new",
"instance",
"is",
"call"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/Factory.php#L202-L213
|
222,325
|
nabbar/SwaggerValidator-PHP
|
src/Swagger.php
|
Swagger.setCachePath
|
public static function setCachePath($pathCacheFile)
{
self::$cacheEnable = false;
if (!empty($pathCacheFile) && file_exists($pathCacheFile)) {
self::$cacheEnable = true;
self::$cachePath = $pathCacheFile;
}
elseif (!empty($pathCacheFile) && !file_exists(dirname($pathCacheFile))) {
self::$cacheEnable = false;
self::$cachePath = $pathCacheFile;
}
elseif (!empty($pathCacheFile) && touch($pathCacheFile)) {
unlink($pathCacheFile);
self::$cacheEnable = true;
self::$cachePath = $pathCacheFile;
}
}
|
php
|
public static function setCachePath($pathCacheFile)
{
self::$cacheEnable = false;
if (!empty($pathCacheFile) && file_exists($pathCacheFile)) {
self::$cacheEnable = true;
self::$cachePath = $pathCacheFile;
}
elseif (!empty($pathCacheFile) && !file_exists(dirname($pathCacheFile))) {
self::$cacheEnable = false;
self::$cachePath = $pathCacheFile;
}
elseif (!empty($pathCacheFile) && touch($pathCacheFile)) {
unlink($pathCacheFile);
self::$cacheEnable = true;
self::$cachePath = $pathCacheFile;
}
}
|
[
"public",
"static",
"function",
"setCachePath",
"(",
"$",
"pathCacheFile",
")",
"{",
"self",
"::",
"$",
"cacheEnable",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"pathCacheFile",
")",
"&&",
"file_exists",
"(",
"$",
"pathCacheFile",
")",
")",
"{",
"self",
"::",
"$",
"cacheEnable",
"=",
"true",
";",
"self",
"::",
"$",
"cachePath",
"=",
"$",
"pathCacheFile",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"pathCacheFile",
")",
"&&",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"pathCacheFile",
")",
")",
")",
"{",
"self",
"::",
"$",
"cacheEnable",
"=",
"false",
";",
"self",
"::",
"$",
"cachePath",
"=",
"$",
"pathCacheFile",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"pathCacheFile",
")",
"&&",
"touch",
"(",
"$",
"pathCacheFile",
")",
")",
"{",
"unlink",
"(",
"$",
"pathCacheFile",
")",
";",
"self",
"::",
"$",
"cacheEnable",
"=",
"true",
";",
"self",
"::",
"$",
"cachePath",
"=",
"$",
"pathCacheFile",
";",
"}",
"}"
] |
Store the cache path and check if the file cache can enabled or not
@param string $pathCacheFile
|
[
"Store",
"the",
"cache",
"path",
"and",
"check",
"if",
"the",
"file",
"cache",
"can",
"enabled",
"or",
"not"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Swagger.php#L67-L84
|
222,326
|
nabbar/SwaggerValidator-PHP
|
src/Swagger.php
|
Swagger.load
|
public static function load(\SwaggerValidator\Common\Context $context)
{
if (self::$cacheEnable !== true || !file_exists(self::$cachePath)) {
return self::regenSwagger($context);
}
if ((filemtime(self::$cachePath) + self::$cacheLifeTime) < time() && self::$cacheLifeTime > 0) {
return self::regenSwagger($context);
}
return self::loadCache($context);
}
|
php
|
public static function load(\SwaggerValidator\Common\Context $context)
{
if (self::$cacheEnable !== true || !file_exists(self::$cachePath)) {
return self::regenSwagger($context);
}
if ((filemtime(self::$cachePath) + self::$cacheLifeTime) < time() && self::$cacheLifeTime > 0) {
return self::regenSwagger($context);
}
return self::loadCache($context);
}
|
[
"public",
"static",
"function",
"load",
"(",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Context",
"$",
"context",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"cacheEnable",
"!==",
"true",
"||",
"!",
"file_exists",
"(",
"self",
"::",
"$",
"cachePath",
")",
")",
"{",
"return",
"self",
"::",
"regenSwagger",
"(",
"$",
"context",
")",
";",
"}",
"if",
"(",
"(",
"filemtime",
"(",
"self",
"::",
"$",
"cachePath",
")",
"+",
"self",
"::",
"$",
"cacheLifeTime",
")",
"<",
"time",
"(",
")",
"&&",
"self",
"::",
"$",
"cacheLifeTime",
">",
"0",
")",
"{",
"return",
"self",
"::",
"regenSwagger",
"(",
"$",
"context",
")",
";",
"}",
"return",
"self",
"::",
"loadCache",
"(",
"$",
"context",
")",
";",
"}"
] |
Load the Swagger Object from the cache file or create a new
@param \SwaggerValidator\Common\Context $context
@return \SwaggerValidator\Object\Swagger
|
[
"Load",
"the",
"Swagger",
"Object",
"from",
"the",
"cache",
"file",
"or",
"create",
"a",
"new"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Swagger.php#L137-L148
|
222,327
|
nabbar/SwaggerValidator-PHP
|
src/Swagger.php
|
Swagger.regenSwagger
|
protected static function regenSwagger(\SwaggerValidator\Common\Context $context)
{
$fileObj = \SwaggerValidator\Common\CollectionFile::getInstance()->get($context, self::$swaggerFile);
if (!is_object($fileObj) && ($fileObj instanceof \SwaggerValidator\Common\ReferenceFile)) {
$context->throwException('Cannot load the given file "' . self::$swaggerFile . '"', __METHOD__, __LINE__);
}
$swagger = \SwaggerValidator\Common\Factory::getInstance()->get(\SwaggerValidator\Common\CollectionType::Swagger);
if (!is_object($swagger) && ($swagger instanceof \SwaggerValidator\Object\Swagger)) {
$context->throwException('Cannot create the swagger object !!', __METHOD__, __LINE__);
}
$swagger->jsonUnSerialize($context, $fileObj->fileObj);
if (self::$cacheEnable !== true) {
return $swagger;
}
return self::storeCache($swagger, $context);
}
|
php
|
protected static function regenSwagger(\SwaggerValidator\Common\Context $context)
{
$fileObj = \SwaggerValidator\Common\CollectionFile::getInstance()->get($context, self::$swaggerFile);
if (!is_object($fileObj) && ($fileObj instanceof \SwaggerValidator\Common\ReferenceFile)) {
$context->throwException('Cannot load the given file "' . self::$swaggerFile . '"', __METHOD__, __LINE__);
}
$swagger = \SwaggerValidator\Common\Factory::getInstance()->get(\SwaggerValidator\Common\CollectionType::Swagger);
if (!is_object($swagger) && ($swagger instanceof \SwaggerValidator\Object\Swagger)) {
$context->throwException('Cannot create the swagger object !!', __METHOD__, __LINE__);
}
$swagger->jsonUnSerialize($context, $fileObj->fileObj);
if (self::$cacheEnable !== true) {
return $swagger;
}
return self::storeCache($swagger, $context);
}
|
[
"protected",
"static",
"function",
"regenSwagger",
"(",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Context",
"$",
"context",
")",
"{",
"$",
"fileObj",
"=",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"CollectionFile",
"::",
"getInstance",
"(",
")",
"->",
"get",
"(",
"$",
"context",
",",
"self",
"::",
"$",
"swaggerFile",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"fileObj",
")",
"&&",
"(",
"$",
"fileObj",
"instanceof",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"ReferenceFile",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Cannot load the given file \"'",
".",
"self",
"::",
"$",
"swaggerFile",
".",
"'\"'",
",",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"$",
"swagger",
"=",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Factory",
"::",
"getInstance",
"(",
")",
"->",
"get",
"(",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"CollectionType",
"::",
"Swagger",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"swagger",
")",
"&&",
"(",
"$",
"swagger",
"instanceof",
"\\",
"SwaggerValidator",
"\\",
"Object",
"\\",
"Swagger",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Cannot create the swagger object !!'",
",",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"$",
"swagger",
"->",
"jsonUnSerialize",
"(",
"$",
"context",
",",
"$",
"fileObj",
"->",
"fileObj",
")",
";",
"if",
"(",
"self",
"::",
"$",
"cacheEnable",
"!==",
"true",
")",
"{",
"return",
"$",
"swagger",
";",
"}",
"return",
"self",
"::",
"storeCache",
"(",
"$",
"swagger",
",",
"$",
"context",
")",
";",
"}"
] |
Return a Swagger Object new object
@param \SwaggerValidator\Common\Context $context
@return \SwaggerValidator\Object\Swagger
|
[
"Return",
"a",
"Swagger",
"Object",
"new",
"object"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Swagger.php#L155-L176
|
222,328
|
nabbar/SwaggerValidator-PHP
|
src/Swagger.php
|
Swagger.loadCache
|
protected static function loadCache(\SwaggerValidator\Common\Context $context)
{
self::cleanInstances();
$swagger = include self::$cachePath;
if (!is_array($swagger)) {
$context->throwException('Cannot Load Cache file : ' . self::$cachePath, __METHOD__, __LINE__);
}
$swagger = $swagger['swg'];
if (!is_object($swagger) && ($swagger instanceof \SwaggerValidator\Object\Swagger)) {
$context->throwException('Cannot Load Cache file : ' . self::$cachePath, __METHOD__, __LINE__);
}
return $swagger;
}
|
php
|
protected static function loadCache(\SwaggerValidator\Common\Context $context)
{
self::cleanInstances();
$swagger = include self::$cachePath;
if (!is_array($swagger)) {
$context->throwException('Cannot Load Cache file : ' . self::$cachePath, __METHOD__, __LINE__);
}
$swagger = $swagger['swg'];
if (!is_object($swagger) && ($swagger instanceof \SwaggerValidator\Object\Swagger)) {
$context->throwException('Cannot Load Cache file : ' . self::$cachePath, __METHOD__, __LINE__);
}
return $swagger;
}
|
[
"protected",
"static",
"function",
"loadCache",
"(",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Context",
"$",
"context",
")",
"{",
"self",
"::",
"cleanInstances",
"(",
")",
";",
"$",
"swagger",
"=",
"include",
"self",
"::",
"$",
"cachePath",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"swagger",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Cannot Load Cache file : '",
".",
"self",
"::",
"$",
"cachePath",
",",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"$",
"swagger",
"=",
"$",
"swagger",
"[",
"'swg'",
"]",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"swagger",
")",
"&&",
"(",
"$",
"swagger",
"instanceof",
"\\",
"SwaggerValidator",
"\\",
"Object",
"\\",
"Swagger",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Cannot Load Cache file : '",
".",
"self",
"::",
"$",
"cachePath",
",",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"return",
"$",
"swagger",
";",
"}"
] |
load cache file or call regen file cache
@param \SwaggerValidator\Common\Context $context
@return \SwaggerValidator\Object\Swagger
|
[
"load",
"cache",
"file",
"or",
"call",
"regen",
"file",
"cache"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Swagger.php#L183-L200
|
222,329
|
nabbar/SwaggerValidator-PHP
|
src/Swagger.php
|
Swagger.storeCache
|
protected static function storeCache(\SwaggerValidator\Object\Swagger $swagger, \SwaggerValidator\Common\Context $context)
{
if (self::$cacheEnable !== true) {
return $swagger;
}
if (!file_exists(self::$cachePath) && !touch(self::$cachePath)) {
self::$cacheEnable = false;
$context->throwException('Cannot Write Cache file : ' . self::$cachePath, __METHOD__, __LINE__);
}
$array = array(
'ref' => \SwaggerValidator\Common\CollectionReference::getInstance(),
'swg' => $swagger,
);
file_put_contents(self::$cachePath, '<?php return ' . var_export($array, true) . ';');
touch(self::$cachePath);
return $swagger;
}
|
php
|
protected static function storeCache(\SwaggerValidator\Object\Swagger $swagger, \SwaggerValidator\Common\Context $context)
{
if (self::$cacheEnable !== true) {
return $swagger;
}
if (!file_exists(self::$cachePath) && !touch(self::$cachePath)) {
self::$cacheEnable = false;
$context->throwException('Cannot Write Cache file : ' . self::$cachePath, __METHOD__, __LINE__);
}
$array = array(
'ref' => \SwaggerValidator\Common\CollectionReference::getInstance(),
'swg' => $swagger,
);
file_put_contents(self::$cachePath, '<?php return ' . var_export($array, true) . ';');
touch(self::$cachePath);
return $swagger;
}
|
[
"protected",
"static",
"function",
"storeCache",
"(",
"\\",
"SwaggerValidator",
"\\",
"Object",
"\\",
"Swagger",
"$",
"swagger",
",",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Context",
"$",
"context",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"cacheEnable",
"!==",
"true",
")",
"{",
"return",
"$",
"swagger",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"self",
"::",
"$",
"cachePath",
")",
"&&",
"!",
"touch",
"(",
"self",
"::",
"$",
"cachePath",
")",
")",
"{",
"self",
"::",
"$",
"cacheEnable",
"=",
"false",
";",
"$",
"context",
"->",
"throwException",
"(",
"'Cannot Write Cache file : '",
".",
"self",
"::",
"$",
"cachePath",
",",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"$",
"array",
"=",
"array",
"(",
"'ref'",
"=>",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"CollectionReference",
"::",
"getInstance",
"(",
")",
",",
"'swg'",
"=>",
"$",
"swagger",
",",
")",
";",
"file_put_contents",
"(",
"self",
"::",
"$",
"cachePath",
",",
"'<?php return '",
".",
"var_export",
"(",
"$",
"array",
",",
"true",
")",
".",
"';'",
")",
";",
"touch",
"(",
"self",
"::",
"$",
"cachePath",
")",
";",
"return",
"$",
"swagger",
";",
"}"
] |
store the new swagger object is available
@param \SwaggerValidator\Object\Swagger $swagger
@return \SwaggerValidator\Object\Swagger
|
[
"store",
"the",
"new",
"swagger",
"object",
"is",
"available"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Swagger.php#L207-L227
|
222,330
|
mdmsoft/yii2-widgets
|
Column.php
|
Column.renderDataCell
|
public function renderDataCell($model, $key, $index)
{
if (is_callable($this->value)) {
$value = call_user_func($this->value, $model, $key, $index);
} else {
$value = $this->value;
}
if ($this->format !== null) {
$value = Yii::$app->getFormatter()->format($value, $this->format);
}
return Html::tag('td', $value, $this->contentOptions);
}
|
php
|
public function renderDataCell($model, $key, $index)
{
if (is_callable($this->value)) {
$value = call_user_func($this->value, $model, $key, $index);
} else {
$value = $this->value;
}
if ($this->format !== null) {
$value = Yii::$app->getFormatter()->format($value, $this->format);
}
return Html::tag('td', $value, $this->contentOptions);
}
|
[
"public",
"function",
"renderDataCell",
"(",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"value",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"value",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"format",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getFormatter",
"(",
")",
"->",
"format",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"format",
")",
";",
"}",
"return",
"Html",
"::",
"tag",
"(",
"'td'",
",",
"$",
"value",
",",
"$",
"this",
"->",
"contentOptions",
")",
";",
"}"
] |
Render data cell
@param Model $model model for cell
@param string $key
@param integer $index
@return string
|
[
"Render",
"data",
"cell"
] |
1ef3c4cd29ec54560c14def54f9961b6715069ea
|
https://github.com/mdmsoft/yii2-widgets/blob/1ef3c4cd29ec54560c14def54f9961b6715069ea/Column.php#L81-L92
|
222,331
|
adshares/ads-php-client
|
src/Util/AdsConverter.php
|
AdsConverter.adsToClicks
|
public static function adsToClicks($amount): int
{
$amountAsString = (string)$amount;
if (strpos($amountAsString, '.') !== false) {
$ar = explode('.', $amountAsString);
$ar[1] = str_pad($ar[1], 11, '0');
$amountAsString = implode($ar);
} else {
$amountAsString = $amountAsString . '00000000000';
}
return (int)$amountAsString;
}
|
php
|
public static function adsToClicks($amount): int
{
$amountAsString = (string)$amount;
if (strpos($amountAsString, '.') !== false) {
$ar = explode('.', $amountAsString);
$ar[1] = str_pad($ar[1], 11, '0');
$amountAsString = implode($ar);
} else {
$amountAsString = $amountAsString . '00000000000';
}
return (int)$amountAsString;
}
|
[
"public",
"static",
"function",
"adsToClicks",
"(",
"$",
"amount",
")",
":",
"int",
"{",
"$",
"amountAsString",
"=",
"(",
"string",
")",
"$",
"amount",
";",
"if",
"(",
"strpos",
"(",
"$",
"amountAsString",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"ar",
"=",
"explode",
"(",
"'.'",
",",
"$",
"amountAsString",
")",
";",
"$",
"ar",
"[",
"1",
"]",
"=",
"str_pad",
"(",
"$",
"ar",
"[",
"1",
"]",
",",
"11",
",",
"'0'",
")",
";",
"$",
"amountAsString",
"=",
"implode",
"(",
"$",
"ar",
")",
";",
"}",
"else",
"{",
"$",
"amountAsString",
"=",
"$",
"amountAsString",
".",
"'00000000000'",
";",
"}",
"return",
"(",
"int",
")",
"$",
"amountAsString",
";",
"}"
] |
Converts Ads to clicks.
@param mixed $amount
@return int
|
[
"Converts",
"Ads",
"to",
"clicks",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/Util/AdsConverter.php#L36-L47
|
222,332
|
adshares/ads-php-client
|
src/Util/AdsConverter.php
|
AdsConverter.clicksToAds
|
public static function clicksToAds($amount): string
{
$amountAsString = (string)$amount;
$isNegativeValue = false;
if ('-' === $amountAsString[0]) {
$isNegativeValue = true;
// cut minus sign from negative value
$amountAsString = substr($amountAsString, 1, strlen($amountAsString));
}
//add leading zeros
$amountAsString = str_pad($amountAsString, 12, '0', STR_PAD_LEFT);
// insert decimal separator
$amountAsString = substr_replace($amountAsString, '.', strlen($amountAsString) - 11, 0);
if ($isNegativeValue) {
// prepend minus sign for negative value
$amountAsString = '-' . $amountAsString;
}
return $amountAsString;
}
|
php
|
public static function clicksToAds($amount): string
{
$amountAsString = (string)$amount;
$isNegativeValue = false;
if ('-' === $amountAsString[0]) {
$isNegativeValue = true;
// cut minus sign from negative value
$amountAsString = substr($amountAsString, 1, strlen($amountAsString));
}
//add leading zeros
$amountAsString = str_pad($amountAsString, 12, '0', STR_PAD_LEFT);
// insert decimal separator
$amountAsString = substr_replace($amountAsString, '.', strlen($amountAsString) - 11, 0);
if ($isNegativeValue) {
// prepend minus sign for negative value
$amountAsString = '-' . $amountAsString;
}
return $amountAsString;
}
|
[
"public",
"static",
"function",
"clicksToAds",
"(",
"$",
"amount",
")",
":",
"string",
"{",
"$",
"amountAsString",
"=",
"(",
"string",
")",
"$",
"amount",
";",
"$",
"isNegativeValue",
"=",
"false",
";",
"if",
"(",
"'-'",
"===",
"$",
"amountAsString",
"[",
"0",
"]",
")",
"{",
"$",
"isNegativeValue",
"=",
"true",
";",
"// cut minus sign from negative value",
"$",
"amountAsString",
"=",
"substr",
"(",
"$",
"amountAsString",
",",
"1",
",",
"strlen",
"(",
"$",
"amountAsString",
")",
")",
";",
"}",
"//add leading zeros",
"$",
"amountAsString",
"=",
"str_pad",
"(",
"$",
"amountAsString",
",",
"12",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"// insert decimal separator",
"$",
"amountAsString",
"=",
"substr_replace",
"(",
"$",
"amountAsString",
",",
"'.'",
",",
"strlen",
"(",
"$",
"amountAsString",
")",
"-",
"11",
",",
"0",
")",
";",
"if",
"(",
"$",
"isNegativeValue",
")",
"{",
"// prepend minus sign for negative value",
"$",
"amountAsString",
"=",
"'-'",
".",
"$",
"amountAsString",
";",
"}",
"return",
"$",
"amountAsString",
";",
"}"
] |
Converts clicks to Ads.
@param int $amount
@return string
|
[
"Converts",
"clicks",
"to",
"Ads",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/Util/AdsConverter.php#L55-L73
|
222,333
|
hprose/hprose-yii
|
src/Hprose/Yii/DiscoveryController.php
|
DiscoveryController.getActions
|
protected function getActions($controller)
{
$actions = array_keys($controller->actions());
$class = new \ReflectionClass($controller);
foreach ($class->getMethods() as $method) {
$name = $method->getName();
if ($name !== 'actions' && $method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0) {
$actions[] = Inflector::camel2id(substr($name, 6), '-', true);
}
}
sort($actions);
return array_unique($actions);
}
|
php
|
protected function getActions($controller)
{
$actions = array_keys($controller->actions());
$class = new \ReflectionClass($controller);
foreach ($class->getMethods() as $method) {
$name = $method->getName();
if ($name !== 'actions' && $method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0) {
$actions[] = Inflector::camel2id(substr($name, 6), '-', true);
}
}
sort($actions);
return array_unique($actions);
}
|
[
"protected",
"function",
"getActions",
"(",
"$",
"controller",
")",
"{",
"$",
"actions",
"=",
"array_keys",
"(",
"$",
"controller",
"->",
"actions",
"(",
")",
")",
";",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"controller",
")",
";",
"foreach",
"(",
"$",
"class",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"$",
"name",
"=",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"'actions'",
"&&",
"$",
"method",
"->",
"isPublic",
"(",
")",
"&&",
"!",
"$",
"method",
"->",
"isStatic",
"(",
")",
"&&",
"strpos",
"(",
"$",
"name",
",",
"'action'",
")",
"===",
"0",
")",
"{",
"$",
"actions",
"[",
"]",
"=",
"Inflector",
"::",
"camel2id",
"(",
"substr",
"(",
"$",
"name",
",",
"6",
")",
",",
"'-'",
",",
"true",
")",
";",
"}",
"}",
"sort",
"(",
"$",
"actions",
")",
";",
"return",
"array_unique",
"(",
"$",
"actions",
")",
";",
"}"
] |
Returns all available actions of the specified controller.
@param Controller $controller the controller instance
@return array all available action IDs.
|
[
"Returns",
"all",
"available",
"actions",
"of",
"the",
"specified",
"controller",
"."
] |
716059c5baafd98ccd9159321eb67acb197426bc
|
https://github.com/hprose/hprose-yii/blob/716059c5baafd98ccd9159321eb67acb197426bc/src/Hprose/Yii/DiscoveryController.php#L107-L120
|
222,334
|
php-mock/php-mock-prophecy
|
classes/PHPProphet.php
|
PHPProphet.getProperty
|
private static function getProperty(Prophet $prophet, $property)
{
$reflection = new \ReflectionProperty($prophet, $property);
$reflection->setAccessible(true);
return $reflection->getValue($prophet);
}
|
php
|
private static function getProperty(Prophet $prophet, $property)
{
$reflection = new \ReflectionProperty($prophet, $property);
$reflection->setAccessible(true);
return $reflection->getValue($prophet);
}
|
[
"private",
"static",
"function",
"getProperty",
"(",
"Prophet",
"$",
"prophet",
",",
"$",
"property",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionProperty",
"(",
"$",
"prophet",
",",
"$",
"property",
")",
";",
"$",
"reflection",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"reflection",
"->",
"getValue",
"(",
"$",
"prophet",
")",
";",
"}"
] |
Returns a private property of a prophet.
@param Prophet $prophet prophet
@param string $property property name
@return mixed property value of that prophet
|
[
"Returns",
"a",
"private",
"property",
"of",
"a",
"prophet",
"."
] |
8a0dce6deeb9190b8b62c57a236310dc910c078c
|
https://github.com/php-mock/php-mock-prophecy/blob/8a0dce6deeb9190b8b62c57a236310dc910c078c/classes/PHPProphet.php#L121-L126
|
222,335
|
nabbar/SwaggerValidator-PHP
|
src/Common/CollectionType.php
|
CollectionType.registerCallable
|
public function registerCallable(\SwaggerValidator\Common\Context $context, $type, $callable)
{
if (!$this->__isset($type)) {
$context->throwException('Cannot find type : "' . $type . '" (Normalized : "' . $this->normalizeType($type) . '" ', __FILE__, __LINE__);
}
if (is_callable(array($callable, '__construct'))) {
return parent::__set($this->normalizeType($type), $callable);
}
if (is_string($callable) && class_exists($callable)) {
//there is a class. but can we instantiate it?
$class = new \ReflectionClass($callable);
if (!$class->isAbstract()) {
return parent::__set($this->normalizeType($type), $callable);
}
else {
$context->throwException('Callable is an abstract class : ' . $callable, __FILE__, __LINE__);
}
}
$context->throwException('Callable is not callable : ' . $callable, __FILE__, __LINE__);
}
|
php
|
public function registerCallable(\SwaggerValidator\Common\Context $context, $type, $callable)
{
if (!$this->__isset($type)) {
$context->throwException('Cannot find type : "' . $type . '" (Normalized : "' . $this->normalizeType($type) . '" ', __FILE__, __LINE__);
}
if (is_callable(array($callable, '__construct'))) {
return parent::__set($this->normalizeType($type), $callable);
}
if (is_string($callable) && class_exists($callable)) {
//there is a class. but can we instantiate it?
$class = new \ReflectionClass($callable);
if (!$class->isAbstract()) {
return parent::__set($this->normalizeType($type), $callable);
}
else {
$context->throwException('Callable is an abstract class : ' . $callable, __FILE__, __LINE__);
}
}
$context->throwException('Callable is not callable : ' . $callable, __FILE__, __LINE__);
}
|
[
"public",
"function",
"registerCallable",
"(",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Context",
"$",
"context",
",",
"$",
"type",
",",
"$",
"callable",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"__isset",
"(",
"$",
"type",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Cannot find type : \"'",
".",
"$",
"type",
".",
"'\" (Normalized : \"'",
".",
"$",
"this",
"->",
"normalizeType",
"(",
"$",
"type",
")",
".",
"'\" '",
",",
"__FILE__",
",",
"__LINE__",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"array",
"(",
"$",
"callable",
",",
"'__construct'",
")",
")",
")",
"{",
"return",
"parent",
"::",
"__set",
"(",
"$",
"this",
"->",
"normalizeType",
"(",
"$",
"type",
")",
",",
"$",
"callable",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"callable",
")",
"&&",
"class_exists",
"(",
"$",
"callable",
")",
")",
"{",
"//there is a class. but can we instantiate it?\r",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"callable",
")",
";",
"if",
"(",
"!",
"$",
"class",
"->",
"isAbstract",
"(",
")",
")",
"{",
"return",
"parent",
"::",
"__set",
"(",
"$",
"this",
"->",
"normalizeType",
"(",
"$",
"type",
")",
",",
"$",
"callable",
")",
";",
"}",
"else",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Callable is an abstract class : '",
".",
"$",
"callable",
",",
"__FILE__",
",",
"__LINE__",
")",
";",
"}",
"}",
"$",
"context",
"->",
"throwException",
"(",
"'Callable is not callable : '",
".",
"$",
"callable",
",",
"__FILE__",
",",
"__LINE__",
")",
";",
"}"
] |
Replace the default callable string by the given for the type in parameters
@param string $type
@param callable $callable
|
[
"Replace",
"the",
"default",
"callable",
"string",
"by",
"the",
"given",
"for",
"the",
"type",
"in",
"parameters"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/CollectionType.php#L219-L242
|
222,336
|
adshares/ads-php-client
|
src/Entity/AbstractEntity.php
|
AbstractEntity.toCamelCase
|
private static function toCamelCase(string $text): string
{
if (strpos($text, '_') !== false) {
$text = str_replace(' ', '', ucwords(str_replace('_', ' ', $text)));
}
$text[0] = strtolower($text[0]);
return $text;
}
|
php
|
private static function toCamelCase(string $text): string
{
if (strpos($text, '_') !== false) {
$text = str_replace(' ', '', ucwords(str_replace('_', ' ', $text)));
}
$text[0] = strtolower($text[0]);
return $text;
}
|
[
"private",
"static",
"function",
"toCamelCase",
"(",
"string",
"$",
"text",
")",
":",
"string",
"{",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"'_'",
")",
"!==",
"false",
")",
"{",
"$",
"text",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"text",
")",
")",
")",
";",
"}",
"$",
"text",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"text",
"[",
"0",
"]",
")",
";",
"return",
"$",
"text",
";",
"}"
] |
Changes string with underscores to camelCase string. First letter is low.
@param string $text text to change case
@return string text in camelCase
|
[
"Changes",
"string",
"with",
"underscores",
"to",
"camelCase",
"string",
".",
"First",
"letter",
"is",
"low",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/Entity/AbstractEntity.php#L36-L44
|
222,337
|
LeaseWeb/LswGettextTranslationBundle
|
Routing/GettextLocaleListener.php
|
GettextLocaleListener.onKernelRequest
|
public function onKernelRequest(GetResponseEvent $event)
{
$currentLocale = $this->getCurrentLocale();
$requestedLocale = $this->getRequestedLocale();
if ($requestedLocale && $currentLocale != $requestedLocale) {
$request = $event->getRequest();
// ugly backwards compatibility fix for symfony 2.0 (start)
if (!method_exists($request, 'setLocale')) {
$request = $request->getSession();
}
// ugly backwards compatibility fix for symfony 2.0 (end)
if (!setlocale(LC_MESSAGES, $requestedLocale.'.UTF-8', $requestedLocale.'.utf8', $requestedLocale.'.utf-8', $requestedLocale.'UTF8')) {
$request->setLocale(null);
throw new InvalidParameterException("Requested locale '$requestedLocale' could not be set. Is this locale installed? Hint: Execute 'locale -a' on the Linux command line to list installed locales.");
}
$request->setLocale($requestedLocale);
}
$this->setupGetText();
}
|
php
|
public function onKernelRequest(GetResponseEvent $event)
{
$currentLocale = $this->getCurrentLocale();
$requestedLocale = $this->getRequestedLocale();
if ($requestedLocale && $currentLocale != $requestedLocale) {
$request = $event->getRequest();
// ugly backwards compatibility fix for symfony 2.0 (start)
if (!method_exists($request, 'setLocale')) {
$request = $request->getSession();
}
// ugly backwards compatibility fix for symfony 2.0 (end)
if (!setlocale(LC_MESSAGES, $requestedLocale.'.UTF-8', $requestedLocale.'.utf8', $requestedLocale.'.utf-8', $requestedLocale.'UTF8')) {
$request->setLocale(null);
throw new InvalidParameterException("Requested locale '$requestedLocale' could not be set. Is this locale installed? Hint: Execute 'locale -a' on the Linux command line to list installed locales.");
}
$request->setLocale($requestedLocale);
}
$this->setupGetText();
}
|
[
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"$",
"currentLocale",
"=",
"$",
"this",
"->",
"getCurrentLocale",
"(",
")",
";",
"$",
"requestedLocale",
"=",
"$",
"this",
"->",
"getRequestedLocale",
"(",
")",
";",
"if",
"(",
"$",
"requestedLocale",
"&&",
"$",
"currentLocale",
"!=",
"$",
"requestedLocale",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"// ugly backwards compatibility fix for symfony 2.0 (start)",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"request",
",",
"'setLocale'",
")",
")",
"{",
"$",
"request",
"=",
"$",
"request",
"->",
"getSession",
"(",
")",
";",
"}",
"// ugly backwards compatibility fix for symfony 2.0 (end)",
"if",
"(",
"!",
"setlocale",
"(",
"LC_MESSAGES",
",",
"$",
"requestedLocale",
".",
"'.UTF-8'",
",",
"$",
"requestedLocale",
".",
"'.utf8'",
",",
"$",
"requestedLocale",
".",
"'.utf-8'",
",",
"$",
"requestedLocale",
".",
"'UTF8'",
")",
")",
"{",
"$",
"request",
"->",
"setLocale",
"(",
"null",
")",
";",
"throw",
"new",
"InvalidParameterException",
"(",
"\"Requested locale '$requestedLocale' could not be set. Is this locale installed? Hint: Execute 'locale -a' on the Linux command line to list installed locales.\"",
")",
";",
"}",
"$",
"request",
"->",
"setLocale",
"(",
"$",
"requestedLocale",
")",
";",
"}",
"$",
"this",
"->",
"setupGetText",
"(",
")",
";",
"}"
] |
Binds the default domain to the combined translations on Kernel Request
@param GetResponseEvent $event event
@throws InvalidParameterException
|
[
"Binds",
"the",
"default",
"domain",
"to",
"the",
"combined",
"translations",
"on",
"Kernel",
"Request"
] |
614003db44a0f498349f1ef779f44dc6323dcdb0
|
https://github.com/LeaseWeb/LswGettextTranslationBundle/blob/614003db44a0f498349f1ef779f44dc6323dcdb0/Routing/GettextLocaleListener.php#L44-L64
|
222,338
|
adshares/ads-php-client
|
src/Command/CreateAccountCommand.php
|
CreateAccountCommand.setAccountKey
|
public function setAccountKey(string $publicKey, string $confirm)
{
$this->publicKey = $publicKey;
$this->confirm = $confirm;
}
|
php
|
public function setAccountKey(string $publicKey, string $confirm)
{
$this->publicKey = $publicKey;
$this->confirm = $confirm;
}
|
[
"public",
"function",
"setAccountKey",
"(",
"string",
"$",
"publicKey",
",",
"string",
"$",
"confirm",
")",
"{",
"$",
"this",
"->",
"publicKey",
"=",
"$",
"publicKey",
";",
"$",
"this",
"->",
"confirm",
"=",
"$",
"confirm",
";",
"}"
] |
Sets key of account.
@param string $publicKey Public key
@param string $confirm Signature of empty string generated using secret key
|
[
"Sets",
"key",
"of",
"account",
"."
] |
b9a897219dfa60a316a29191dbeb836c5e1aa760
|
https://github.com/adshares/ads-php-client/blob/b9a897219dfa60a316a29191dbeb836c5e1aa760/src/Command/CreateAccountCommand.php#L52-L56
|
222,339
|
mdmsoft/yii2-widgets
|
TabularWidget.php
|
TabularWidget.getClientOptions
|
protected function getClientOptions()
{
$counter = count($this->allModels) ? max(array_keys($this->allModels)) + 1 : 0;
$clientOptions = $this->clientOptions;
$clientOptions['counter'] = $counter;
if (empty($clientOptions['itemSelector'])) {
throw new InvalidConfigException('Value of "clientOptions[\'itemSelector\']" must be specified.');
}
if ($this->form instanceof ActiveForm) {
$clientOptions['formSelector'] = '#' . $this->form->options['id'];
$oldAttrs = $this->form->attributes;
$this->form->attributes = [];
}
// template and js
$view = $this->getView();
$oldJs = $view->js;
$view->js = [];
$template = $this->renderItem($this->model, "_dkey{$this->level}_", "_dindex{$this->level}_");
if (isset($oldAttrs)) {
$clientOptions['validations'] = $this->form->attributes;
$this->form->attributes = $oldAttrs;
}
$js = [];
foreach ($view->js as $pieces) {
$js[] = implode("\n", $pieces);
}
if (count($js)) {
$clientOptions['templateJs'] = implode("\n", $js);
}
$view->js = $oldJs;
// ***
$clientOptions['template'] = $template;
$clientOptions['replaces'] = [
'key' => new JsExpression("/_dkey{$this->level}_/g"),
'index' => new JsExpression("/_dindex{$this->level}_/g"),
];
return $clientOptions;
}
|
php
|
protected function getClientOptions()
{
$counter = count($this->allModels) ? max(array_keys($this->allModels)) + 1 : 0;
$clientOptions = $this->clientOptions;
$clientOptions['counter'] = $counter;
if (empty($clientOptions['itemSelector'])) {
throw new InvalidConfigException('Value of "clientOptions[\'itemSelector\']" must be specified.');
}
if ($this->form instanceof ActiveForm) {
$clientOptions['formSelector'] = '#' . $this->form->options['id'];
$oldAttrs = $this->form->attributes;
$this->form->attributes = [];
}
// template and js
$view = $this->getView();
$oldJs = $view->js;
$view->js = [];
$template = $this->renderItem($this->model, "_dkey{$this->level}_", "_dindex{$this->level}_");
if (isset($oldAttrs)) {
$clientOptions['validations'] = $this->form->attributes;
$this->form->attributes = $oldAttrs;
}
$js = [];
foreach ($view->js as $pieces) {
$js[] = implode("\n", $pieces);
}
if (count($js)) {
$clientOptions['templateJs'] = implode("\n", $js);
}
$view->js = $oldJs;
// ***
$clientOptions['template'] = $template;
$clientOptions['replaces'] = [
'key' => new JsExpression("/_dkey{$this->level}_/g"),
'index' => new JsExpression("/_dindex{$this->level}_/g"),
];
return $clientOptions;
}
|
[
"protected",
"function",
"getClientOptions",
"(",
")",
"{",
"$",
"counter",
"=",
"count",
"(",
"$",
"this",
"->",
"allModels",
")",
"?",
"max",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"allModels",
")",
")",
"+",
"1",
":",
"0",
";",
"$",
"clientOptions",
"=",
"$",
"this",
"->",
"clientOptions",
";",
"$",
"clientOptions",
"[",
"'counter'",
"]",
"=",
"$",
"counter",
";",
"if",
"(",
"empty",
"(",
"$",
"clientOptions",
"[",
"'itemSelector'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'Value of \"clientOptions[\\'itemSelector\\']\" must be specified.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"form",
"instanceof",
"ActiveForm",
")",
"{",
"$",
"clientOptions",
"[",
"'formSelector'",
"]",
"=",
"'#'",
".",
"$",
"this",
"->",
"form",
"->",
"options",
"[",
"'id'",
"]",
";",
"$",
"oldAttrs",
"=",
"$",
"this",
"->",
"form",
"->",
"attributes",
";",
"$",
"this",
"->",
"form",
"->",
"attributes",
"=",
"[",
"]",
";",
"}",
"// template and js",
"$",
"view",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
";",
"$",
"oldJs",
"=",
"$",
"view",
"->",
"js",
";",
"$",
"view",
"->",
"js",
"=",
"[",
"]",
";",
"$",
"template",
"=",
"$",
"this",
"->",
"renderItem",
"(",
"$",
"this",
"->",
"model",
",",
"\"_dkey{$this->level}_\"",
",",
"\"_dindex{$this->level}_\"",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"oldAttrs",
")",
")",
"{",
"$",
"clientOptions",
"[",
"'validations'",
"]",
"=",
"$",
"this",
"->",
"form",
"->",
"attributes",
";",
"$",
"this",
"->",
"form",
"->",
"attributes",
"=",
"$",
"oldAttrs",
";",
"}",
"$",
"js",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"view",
"->",
"js",
"as",
"$",
"pieces",
")",
"{",
"$",
"js",
"[",
"]",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"pieces",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"js",
")",
")",
"{",
"$",
"clientOptions",
"[",
"'templateJs'",
"]",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"js",
")",
";",
"}",
"$",
"view",
"->",
"js",
"=",
"$",
"oldJs",
";",
"// ***",
"$",
"clientOptions",
"[",
"'template'",
"]",
"=",
"$",
"template",
";",
"$",
"clientOptions",
"[",
"'replaces'",
"]",
"=",
"[",
"'key'",
"=>",
"new",
"JsExpression",
"(",
"\"/_dkey{$this->level}_/g\"",
")",
",",
"'index'",
"=>",
"new",
"JsExpression",
"(",
"\"/_dindex{$this->level}_/g\"",
")",
",",
"]",
";",
"return",
"$",
"clientOptions",
";",
"}"
] |
Get client options
@return array
|
[
"Get",
"client",
"options"
] |
1ef3c4cd29ec54560c14def54f9961b6715069ea
|
https://github.com/mdmsoft/yii2-widgets/blob/1ef3c4cd29ec54560c14def54f9961b6715069ea/TabularWidget.php#L186-L227
|
222,340
|
nabbar/SwaggerValidator-PHP
|
src/Common/CollectionSwagger.php
|
CollectionSwagger.checkMandatoryKey
|
public function checkMandatoryKey()
{
foreach ($this->mandatoryKeys as $key) {
if (!array_key_exists($key, $this)) {
return $key;
}
}
return true;
}
|
php
|
public function checkMandatoryKey()
{
foreach ($this->mandatoryKeys as $key) {
if (!array_key_exists($key, $this)) {
return $key;
}
}
return true;
}
|
[
"public",
"function",
"checkMandatoryKey",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mandatoryKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
")",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Return true if all mandatory keys are defined or the missing key name
@return boolean|string
|
[
"Return",
"true",
"if",
"all",
"mandatory",
"keys",
"are",
"defined",
"or",
"the",
"missing",
"key",
"name"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/CollectionSwagger.php#L104-L113
|
222,341
|
nabbar/SwaggerValidator-PHP
|
src/Common/CollectionSwagger.php
|
CollectionSwagger.checkJsonObject
|
protected function checkJsonObject(\SwaggerValidator\Common\Context $context, &$jsonData)
{
if (!is_object($jsonData)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
if (!($jsonData instanceof \stdClass)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
return true;
}
|
php
|
protected function checkJsonObject(\SwaggerValidator\Common\Context $context, &$jsonData)
{
if (!is_object($jsonData)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
if (!($jsonData instanceof \stdClass)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
return true;
}
|
[
"protected",
"function",
"checkJsonObject",
"(",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Context",
"$",
"context",
",",
"&",
"$",
"jsonData",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"jsonData",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Mismatching type of JSON Data received'",
",",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"jsonData",
"instanceof",
"\\",
"stdClass",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Mismatching type of JSON Data received'",
",",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Check that entry JsonData is an object of stdClass
@param \stdClass $jsonData
@return boolean
|
[
"Check",
"that",
"entry",
"JsonData",
"is",
"an",
"object",
"of",
"stdClass"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/CollectionSwagger.php#L263-L274
|
222,342
|
nabbar/SwaggerValidator-PHP
|
src/Common/CollectionSwagger.php
|
CollectionSwagger.checkJsonObjectOrArray
|
protected function checkJsonObjectOrArray(\SwaggerValidator\Common\Context $context, &$jsonData)
{
if (is_object($jsonData) && !($jsonData instanceof \stdClass)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
elseif (!is_object($jsonData) && !is_array($jsonData)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
if (is_array($jsonData)) {
parent::setJSONIsArray();
}
return true;
}
|
php
|
protected function checkJsonObjectOrArray(\SwaggerValidator\Common\Context $context, &$jsonData)
{
if (is_object($jsonData) && !($jsonData instanceof \stdClass)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
elseif (!is_object($jsonData) && !is_array($jsonData)) {
$context->throwException('Mismatching type of JSON Data received', get_class($this) . '::' . __METHOD__, __LINE__);
}
if (is_array($jsonData)) {
parent::setJSONIsArray();
}
return true;
}
|
[
"protected",
"function",
"checkJsonObjectOrArray",
"(",
"\\",
"SwaggerValidator",
"\\",
"Common",
"\\",
"Context",
"$",
"context",
",",
"&",
"$",
"jsonData",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"jsonData",
")",
"&&",
"!",
"(",
"$",
"jsonData",
"instanceof",
"\\",
"stdClass",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Mismatching type of JSON Data received'",
",",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"elseif",
"(",
"!",
"is_object",
"(",
"$",
"jsonData",
")",
"&&",
"!",
"is_array",
"(",
"$",
"jsonData",
")",
")",
"{",
"$",
"context",
"->",
"throwException",
"(",
"'Mismatching type of JSON Data received'",
",",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"__METHOD__",
",",
"__LINE__",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"jsonData",
")",
")",
"{",
"parent",
"::",
"setJSONIsArray",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Check that entry JsonData is an object of stdClass or an array
@param \stdClass $jsonData
@return boolean
|
[
"Check",
"that",
"entry",
"JsonData",
"is",
"an",
"object",
"of",
"stdClass",
"or",
"an",
"array"
] |
c3518c53beed71b653a98ea7d56bd12a580d5aa8
|
https://github.com/nabbar/SwaggerValidator-PHP/blob/c3518c53beed71b653a98ea7d56bd12a580d5aa8/src/Common/CollectionSwagger.php#L281-L295
|
222,343
|
php-mock/php-mock-prophecy
|
classes/Revelation.php
|
Revelation.reveal
|
public function reveal()
{
$delegate = $this->prophecy->reveal();
$builder = new MockBuilder();
$builder->setNamespace($this->namespace)
->setName($this->functionName)
->setFunction([$delegate, MockDelegateFunctionBuilder::METHOD]);
$mock = $builder->build();
$mock->enable();
return $mock;
}
|
php
|
public function reveal()
{
$delegate = $this->prophecy->reveal();
$builder = new MockBuilder();
$builder->setNamespace($this->namespace)
->setName($this->functionName)
->setFunction([$delegate, MockDelegateFunctionBuilder::METHOD]);
$mock = $builder->build();
$mock->enable();
return $mock;
}
|
[
"public",
"function",
"reveal",
"(",
")",
"{",
"$",
"delegate",
"=",
"$",
"this",
"->",
"prophecy",
"->",
"reveal",
"(",
")",
";",
"$",
"builder",
"=",
"new",
"MockBuilder",
"(",
")",
";",
"$",
"builder",
"->",
"setNamespace",
"(",
"$",
"this",
"->",
"namespace",
")",
"->",
"setName",
"(",
"$",
"this",
"->",
"functionName",
")",
"->",
"setFunction",
"(",
"[",
"$",
"delegate",
",",
"MockDelegateFunctionBuilder",
"::",
"METHOD",
"]",
")",
";",
"$",
"mock",
"=",
"$",
"builder",
"->",
"build",
"(",
")",
";",
"$",
"mock",
"->",
"enable",
"(",
")",
";",
"return",
"$",
"mock",
";",
"}"
] |
Reveals the function prophecy.
I.e. the prophesized function will become effective.
@return Mock enabled function mock
|
[
"Reveals",
"the",
"function",
"prophecy",
"."
] |
8a0dce6deeb9190b8b62c57a236310dc910c078c
|
https://github.com/php-mock/php-mock-prophecy/blob/8a0dce6deeb9190b8b62c57a236310dc910c078c/classes/Revelation.php#L56-L66
|
222,344
|
mdmsoft/yii2-widgets
|
DataColumn.php
|
DataColumn.renderInputCell
|
public function renderInputCell($model, $key, $index)
{
$form = $this->grid->form;
$items = $this->items;
if ($this->widget !== null) {
if (is_array($this->widget)) {
list($widget, $options) = $this->widget;
if ($options instanceof \Closure) {
$options = call_user_func($options, $model, $key, $index);
}
} else {
$widget = $this->widget;
$options = [];
}
if ($form instanceof ActiveForm) {
return $form->field($model, "[$key]{$this->attribute}", ['template' => $this->template])
->widget($widget, $options);
} else {
$options = array_merge([
'model' => $model,
'attribute' => "[$key]{$this->attribute}"
], $options);
return $widget::widget($options);
}
} elseif ($items !== null) {
if ($items instanceof \Closure) {
$items = call_user_func($items, $model, $key, $index);
}
if ($form instanceof ActiveForm) {
return $form->field($model, "[$key]{$this->attribute}", ['template' => $this->template])
->dropDownList($items, $this->inputOptions);
} else {
return Html::activeDropDownList($model, "[$key]{$this->attribute}", $items, $this->inputOptions);
}
} else {
if ($form instanceof ActiveForm) {
return $form->field($model, "[$key]{$this->attribute}", ['template' => $this->template])
->textInput($this->inputOptions);
}
return Html::activeTextInput($model, "[$key]{$this->attribute}", $this->inputOptions);
}
}
|
php
|
public function renderInputCell($model, $key, $index)
{
$form = $this->grid->form;
$items = $this->items;
if ($this->widget !== null) {
if (is_array($this->widget)) {
list($widget, $options) = $this->widget;
if ($options instanceof \Closure) {
$options = call_user_func($options, $model, $key, $index);
}
} else {
$widget = $this->widget;
$options = [];
}
if ($form instanceof ActiveForm) {
return $form->field($model, "[$key]{$this->attribute}", ['template' => $this->template])
->widget($widget, $options);
} else {
$options = array_merge([
'model' => $model,
'attribute' => "[$key]{$this->attribute}"
], $options);
return $widget::widget($options);
}
} elseif ($items !== null) {
if ($items instanceof \Closure) {
$items = call_user_func($items, $model, $key, $index);
}
if ($form instanceof ActiveForm) {
return $form->field($model, "[$key]{$this->attribute}", ['template' => $this->template])
->dropDownList($items, $this->inputOptions);
} else {
return Html::activeDropDownList($model, "[$key]{$this->attribute}", $items, $this->inputOptions);
}
} else {
if ($form instanceof ActiveForm) {
return $form->field($model, "[$key]{$this->attribute}", ['template' => $this->template])
->textInput($this->inputOptions);
}
return Html::activeTextInput($model, "[$key]{$this->attribute}", $this->inputOptions);
}
}
|
[
"public",
"function",
"renderInputCell",
"(",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"grid",
"->",
"form",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"items",
";",
"if",
"(",
"$",
"this",
"->",
"widget",
"!==",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"widget",
")",
")",
"{",
"list",
"(",
"$",
"widget",
",",
"$",
"options",
")",
"=",
"$",
"this",
"->",
"widget",
";",
"if",
"(",
"$",
"options",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"options",
"=",
"call_user_func",
"(",
"$",
"options",
",",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
";",
"}",
"}",
"else",
"{",
"$",
"widget",
"=",
"$",
"this",
"->",
"widget",
";",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"form",
"instanceof",
"ActiveForm",
")",
"{",
"return",
"$",
"form",
"->",
"field",
"(",
"$",
"model",
",",
"\"[$key]{$this->attribute}\"",
",",
"[",
"'template'",
"=>",
"$",
"this",
"->",
"template",
"]",
")",
"->",
"widget",
"(",
"$",
"widget",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'model'",
"=>",
"$",
"model",
",",
"'attribute'",
"=>",
"\"[$key]{$this->attribute}\"",
"]",
",",
"$",
"options",
")",
";",
"return",
"$",
"widget",
"::",
"widget",
"(",
"$",
"options",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"items",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"items",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"items",
"=",
"call_user_func",
"(",
"$",
"items",
",",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
";",
"}",
"if",
"(",
"$",
"form",
"instanceof",
"ActiveForm",
")",
"{",
"return",
"$",
"form",
"->",
"field",
"(",
"$",
"model",
",",
"\"[$key]{$this->attribute}\"",
",",
"[",
"'template'",
"=>",
"$",
"this",
"->",
"template",
"]",
")",
"->",
"dropDownList",
"(",
"$",
"items",
",",
"$",
"this",
"->",
"inputOptions",
")",
";",
"}",
"else",
"{",
"return",
"Html",
"::",
"activeDropDownList",
"(",
"$",
"model",
",",
"\"[$key]{$this->attribute}\"",
",",
"$",
"items",
",",
"$",
"this",
"->",
"inputOptions",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"form",
"instanceof",
"ActiveForm",
")",
"{",
"return",
"$",
"form",
"->",
"field",
"(",
"$",
"model",
",",
"\"[$key]{$this->attribute}\"",
",",
"[",
"'template'",
"=>",
"$",
"this",
"->",
"template",
"]",
")",
"->",
"textInput",
"(",
"$",
"this",
"->",
"inputOptions",
")",
";",
"}",
"return",
"Html",
"::",
"activeTextInput",
"(",
"$",
"model",
",",
"\"[$key]{$this->attribute}\"",
",",
"$",
"this",
"->",
"inputOptions",
")",
";",
"}",
"}"
] |
Render input cell
@param Model $model model for cell
@param string $key
@param integer $index
@return string
|
[
"Render",
"input",
"cell"
] |
1ef3c4cd29ec54560c14def54f9961b6715069ea
|
https://github.com/mdmsoft/yii2-widgets/blob/1ef3c4cd29ec54560c14def54f9961b6715069ea/DataColumn.php#L88-L129
|
222,345
|
LeaseWeb/LswGettextTranslationBundle
|
Command/AbstractCommand.php
|
AbstractCommand.findFilesInFolder
|
protected function findFilesInFolder($dir, $extension)
{
$templates = array();
if (is_dir($dir)) {
$finder = new Finder();
foreach ($finder->files()->followLinks()->in($dir)->exclude('cache')->name('*.' . $extension) as $file) {
$templates[] = $this->relative($file->getPathname());
}
}
return $templates;
}
|
php
|
protected function findFilesInFolder($dir, $extension)
{
$templates = array();
if (is_dir($dir)) {
$finder = new Finder();
foreach ($finder->files()->followLinks()->in($dir)->exclude('cache')->name('*.' . $extension) as $file) {
$templates[] = $this->relative($file->getPathname());
}
}
return $templates;
}
|
[
"protected",
"function",
"findFilesInFolder",
"(",
"$",
"dir",
",",
"$",
"extension",
")",
"{",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"foreach",
"(",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"followLinks",
"(",
")",
"->",
"in",
"(",
"$",
"dir",
")",
"->",
"exclude",
"(",
"'cache'",
")",
"->",
"name",
"(",
"'*.'",
".",
"$",
"extension",
")",
"as",
"$",
"file",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"$",
"this",
"->",
"relative",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"templates",
";",
"}"
] |
Search for files with specific extension
@param string $dir
@param string $extension
@return array
|
[
"Search",
"for",
"files",
"with",
"specific",
"extension"
] |
614003db44a0f498349f1ef779f44dc6323dcdb0
|
https://github.com/LeaseWeb/LswGettextTranslationBundle/blob/614003db44a0f498349f1ef779f44dc6323dcdb0/Command/AbstractCommand.php#L34-L45
|
222,346
|
LeaseWeb/LswGettextTranslationBundle
|
Command/AbstractCommand.php
|
AbstractCommand.relativePath
|
private function relativePath($from, $to, $ps = DIRECTORY_SEPARATOR)
{
$from = realpath($from);
$to = realpath($to);
$equalOffset = 0;
$minLength = min(strlen($from), strlen($to));
while ($equalOffset < $minLength && $from[$equalOffset] == $to[$equalOffset]) {
$equalOffset++;
}
$backCount = $equalOffset == $minLength && strlen($from) < strlen($to) ?
0 : substr_count($from, $ps, $equalOffset-1);
return rtrim(str_repeat('..'.$ps, $backCount).ltrim(substr($to, $equalOffset), $ps), $ps);
}
|
php
|
private function relativePath($from, $to, $ps = DIRECTORY_SEPARATOR)
{
$from = realpath($from);
$to = realpath($to);
$equalOffset = 0;
$minLength = min(strlen($from), strlen($to));
while ($equalOffset < $minLength && $from[$equalOffset] == $to[$equalOffset]) {
$equalOffset++;
}
$backCount = $equalOffset == $minLength && strlen($from) < strlen($to) ?
0 : substr_count($from, $ps, $equalOffset-1);
return rtrim(str_repeat('..'.$ps, $backCount).ltrim(substr($to, $equalOffset), $ps), $ps);
}
|
[
"private",
"function",
"relativePath",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"ps",
"=",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"from",
"=",
"realpath",
"(",
"$",
"from",
")",
";",
"$",
"to",
"=",
"realpath",
"(",
"$",
"to",
")",
";",
"$",
"equalOffset",
"=",
"0",
";",
"$",
"minLength",
"=",
"min",
"(",
"strlen",
"(",
"$",
"from",
")",
",",
"strlen",
"(",
"$",
"to",
")",
")",
";",
"while",
"(",
"$",
"equalOffset",
"<",
"$",
"minLength",
"&&",
"$",
"from",
"[",
"$",
"equalOffset",
"]",
"==",
"$",
"to",
"[",
"$",
"equalOffset",
"]",
")",
"{",
"$",
"equalOffset",
"++",
";",
"}",
"$",
"backCount",
"=",
"$",
"equalOffset",
"==",
"$",
"minLength",
"&&",
"strlen",
"(",
"$",
"from",
")",
"<",
"strlen",
"(",
"$",
"to",
")",
"?",
"0",
":",
"substr_count",
"(",
"$",
"from",
",",
"$",
"ps",
",",
"$",
"equalOffset",
"-",
"1",
")",
";",
"return",
"rtrim",
"(",
"str_repeat",
"(",
"'..'",
".",
"$",
"ps",
",",
"$",
"backCount",
")",
".",
"ltrim",
"(",
"substr",
"(",
"$",
"to",
",",
"$",
"equalOffset",
")",
",",
"$",
"ps",
")",
",",
"$",
"ps",
")",
";",
"}"
] |
Get relative path from file to directory
@param string $from
@param string $to
@param string $ps
@return string
|
[
"Get",
"relative",
"path",
"from",
"file",
"to",
"directory"
] |
614003db44a0f498349f1ef779f44dc6323dcdb0
|
https://github.com/LeaseWeb/LswGettextTranslationBundle/blob/614003db44a0f498349f1ef779f44dc6323dcdb0/Command/AbstractCommand.php#L55-L71
|
222,347
|
LeaseWeb/LswGettextTranslationBundle
|
Command/AbstractCommand.php
|
AbstractCommand.initializeFromTemplate
|
protected function initializeFromTemplate($template, $languages)
{
$results = array();
$target = dirname($template);
if (!file_exists($template)) {
throw new ResourceNotFoundException("Template not found in: $template\n\nRun 'app/console gettext:bundle:extract' first.");
}
$results[$this->relative($template)] = 'Scanned';
$languages = explode(',', trim($languages));
foreach ($languages as $lang) {
$lang = trim($lang);
$file = "$target/locale/$lang/LC_MESSAGES/messages.po";
if (file_exists($file)) {
$results[$this->relative($file)] = 'Skipped';
continue;
}
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0755, true);
}
$data = file_get_contents($template);
$version = $this->relative($target . '/../..') . '@' . date('YmdHis');
$data = preg_replace('/Project-Id-Version: PACKAGE VERSION\\\n/', 'Project-Id-Version: ' . $version . '\n', $data, 1);
$data = preg_replace('/Language: \\\n/','Language: ' . $lang . '\n', $data, 1);
$data = preg_replace('/charset=CHARSET/', 'charset=UTF-8', $data, 1);
$status = file_put_contents($file, $data) ? 'Created' : 'Failed';
$results[$this->relative($file)] = $status;
}
return $results;
}
|
php
|
protected function initializeFromTemplate($template, $languages)
{
$results = array();
$target = dirname($template);
if (!file_exists($template)) {
throw new ResourceNotFoundException("Template not found in: $template\n\nRun 'app/console gettext:bundle:extract' first.");
}
$results[$this->relative($template)] = 'Scanned';
$languages = explode(',', trim($languages));
foreach ($languages as $lang) {
$lang = trim($lang);
$file = "$target/locale/$lang/LC_MESSAGES/messages.po";
if (file_exists($file)) {
$results[$this->relative($file)] = 'Skipped';
continue;
}
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0755, true);
}
$data = file_get_contents($template);
$version = $this->relative($target . '/../..') . '@' . date('YmdHis');
$data = preg_replace('/Project-Id-Version: PACKAGE VERSION\\\n/', 'Project-Id-Version: ' . $version . '\n', $data, 1);
$data = preg_replace('/Language: \\\n/','Language: ' . $lang . '\n', $data, 1);
$data = preg_replace('/charset=CHARSET/', 'charset=UTF-8', $data, 1);
$status = file_put_contents($file, $data) ? 'Created' : 'Failed';
$results[$this->relative($file)] = $status;
}
return $results;
}
|
[
"protected",
"function",
"initializeFromTemplate",
"(",
"$",
"template",
",",
"$",
"languages",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"$",
"target",
"=",
"dirname",
"(",
"$",
"template",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"template",
")",
")",
"{",
"throw",
"new",
"ResourceNotFoundException",
"(",
"\"Template not found in: $template\\n\\nRun 'app/console gettext:bundle:extract' first.\"",
")",
";",
"}",
"$",
"results",
"[",
"$",
"this",
"->",
"relative",
"(",
"$",
"template",
")",
"]",
"=",
"'Scanned'",
";",
"$",
"languages",
"=",
"explode",
"(",
"','",
",",
"trim",
"(",
"$",
"languages",
")",
")",
";",
"foreach",
"(",
"$",
"languages",
"as",
"$",
"lang",
")",
"{",
"$",
"lang",
"=",
"trim",
"(",
"$",
"lang",
")",
";",
"$",
"file",
"=",
"\"$target/locale/$lang/LC_MESSAGES/messages.po\"",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"results",
"[",
"$",
"this",
"->",
"relative",
"(",
"$",
"file",
")",
"]",
"=",
"'Skipped'",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"file",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"file",
")",
",",
"0755",
",",
"true",
")",
";",
"}",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"template",
")",
";",
"$",
"version",
"=",
"$",
"this",
"->",
"relative",
"(",
"$",
"target",
".",
"'/../..'",
")",
".",
"'@'",
".",
"date",
"(",
"'YmdHis'",
")",
";",
"$",
"data",
"=",
"preg_replace",
"(",
"'/Project-Id-Version: PACKAGE VERSION\\\\\\n/'",
",",
"'Project-Id-Version: '",
".",
"$",
"version",
".",
"'\\n'",
",",
"$",
"data",
",",
"1",
")",
";",
"$",
"data",
"=",
"preg_replace",
"(",
"'/Language: \\\\\\n/'",
",",
"'Language: '",
".",
"$",
"lang",
".",
"'\\n'",
",",
"$",
"data",
",",
"1",
")",
";",
"$",
"data",
"=",
"preg_replace",
"(",
"'/charset=CHARSET/'",
",",
"'charset=UTF-8'",
",",
"$",
"data",
",",
"1",
")",
";",
"$",
"status",
"=",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"data",
")",
"?",
"'Created'",
":",
"'Failed'",
";",
"$",
"results",
"[",
"$",
"this",
"->",
"relative",
"(",
"$",
"file",
")",
"]",
"=",
"$",
"status",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
Initialize .po file from template
@param string $template
@param string $languages
@return array
@throws ResourceNotFoundException
|
[
"Initialize",
".",
"po",
"file",
"from",
"template"
] |
614003db44a0f498349f1ef779f44dc6323dcdb0
|
https://github.com/LeaseWeb/LswGettextTranslationBundle/blob/614003db44a0f498349f1ef779f44dc6323dcdb0/Command/AbstractCommand.php#L198-L227
|
222,348
|
LeaseWeb/LswGettextTranslationBundle
|
Command/AbstractCommand.php
|
AbstractCommand.compile
|
protected function compile($file,$path)
{
$results = array();
// if .tmp file exists, clean it for further using it as cache
if (file_exists("$path.tmp")) {
unlink("$path.tmp");
}
$options = implode(' ',array(
'--check',
"-o $path.tmp",
$file,
));
$process = new Process('msgfmt '.$options);
$process->run();
$output = $process->getOutput();
if (!$process->isSuccessful()) {
throw new \Exception($process->getErrorOutput());
}
if (!file_exists("$path.tmp")) {
throw new \Exception('msgfmt failed to compile messages for translating. Did you install gettext?');
}
rename("$path.tmp", $path);
$results[$this->relative($file)] = 'Scanned';
$results[$this->relative($path)] = 'Written';
return $results;
}
|
php
|
protected function compile($file,$path)
{
$results = array();
// if .tmp file exists, clean it for further using it as cache
if (file_exists("$path.tmp")) {
unlink("$path.tmp");
}
$options = implode(' ',array(
'--check',
"-o $path.tmp",
$file,
));
$process = new Process('msgfmt '.$options);
$process->run();
$output = $process->getOutput();
if (!$process->isSuccessful()) {
throw new \Exception($process->getErrorOutput());
}
if (!file_exists("$path.tmp")) {
throw new \Exception('msgfmt failed to compile messages for translating. Did you install gettext?');
}
rename("$path.tmp", $path);
$results[$this->relative($file)] = 'Scanned';
$results[$this->relative($path)] = 'Written';
return $results;
}
|
[
"protected",
"function",
"compile",
"(",
"$",
"file",
",",
"$",
"path",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"// if .tmp file exists, clean it for further using it as cache",
"if",
"(",
"file_exists",
"(",
"\"$path.tmp\"",
")",
")",
"{",
"unlink",
"(",
"\"$path.tmp\"",
")",
";",
"}",
"$",
"options",
"=",
"implode",
"(",
"' '",
",",
"array",
"(",
"'--check'",
",",
"\"-o $path.tmp\"",
",",
"$",
"file",
",",
")",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"'msgfmt '",
".",
"$",
"options",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"$",
"output",
"=",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"if",
"(",
"!",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"\"$path.tmp\"",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'msgfmt failed to compile messages for translating. Did you install gettext?'",
")",
";",
"}",
"rename",
"(",
"\"$path.tmp\"",
",",
"$",
"path",
")",
";",
"$",
"results",
"[",
"$",
"this",
"->",
"relative",
"(",
"$",
"file",
")",
"]",
"=",
"'Scanned'",
";",
"$",
"results",
"[",
"$",
"this",
"->",
"relative",
"(",
"$",
"path",
")",
"]",
"=",
"'Written'",
";",
"return",
"$",
"results",
";",
"}"
] |
Compile message catalog to binary format
@param string $file
@param string $path
@return array
@throws \Exception
|
[
"Compile",
"message",
"catalog",
"to",
"binary",
"format"
] |
614003db44a0f498349f1ef779f44dc6323dcdb0
|
https://github.com/LeaseWeb/LswGettextTranslationBundle/blob/614003db44a0f498349f1ef779f44dc6323dcdb0/Command/AbstractCommand.php#L285-L314
|
222,349
|
middlewares/php-session
|
src/PhpSession.php
|
PhpSession.regenerateId
|
public function regenerateId(int $interval, string $key = 'session-id-expires'): self
{
$this->regenerateIdInterval = $interval;
$this->sessionIdExpiryKey = $key;
return $this;
}
|
php
|
public function regenerateId(int $interval, string $key = 'session-id-expires'): self
{
$this->regenerateIdInterval = $interval;
$this->sessionIdExpiryKey = $key;
return $this;
}
|
[
"public",
"function",
"regenerateId",
"(",
"int",
"$",
"interval",
",",
"string",
"$",
"key",
"=",
"'session-id-expires'",
")",
":",
"self",
"{",
"$",
"this",
"->",
"regenerateIdInterval",
"=",
"$",
"interval",
";",
"$",
"this",
"->",
"sessionIdExpiryKey",
"=",
"$",
"key",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the session id regenerate interval and id expiry key name.
|
[
"Set",
"the",
"session",
"id",
"regenerate",
"interval",
"and",
"id",
"expiry",
"key",
"name",
"."
] |
1ab5c308f510c1ad99c17d517df7c50b178be760
|
https://github.com/middlewares/php-session/blob/1ab5c308f510c1ad99c17d517df7c50b178be760/src/PhpSession.php#L72-L79
|
222,350
|
middlewares/php-session
|
src/PhpSession.php
|
PhpSession.runIdRegeneration
|
private static function runIdRegeneration(int $interval = null, string $key = null)
{
if (empty($interval)) {
return;
}
$expiry = time() + $interval;
if (!isset($_SESSION[$key])) {
$_SESSION[$key] = $expiry;
}
if ($_SESSION[$key] < time() || $_SESSION[$key] > $expiry) {
session_regenerate_id(true);
$_SESSION[$key] = $expiry;
}
}
|
php
|
private static function runIdRegeneration(int $interval = null, string $key = null)
{
if (empty($interval)) {
return;
}
$expiry = time() + $interval;
if (!isset($_SESSION[$key])) {
$_SESSION[$key] = $expiry;
}
if ($_SESSION[$key] < time() || $_SESSION[$key] > $expiry) {
session_regenerate_id(true);
$_SESSION[$key] = $expiry;
}
}
|
[
"private",
"static",
"function",
"runIdRegeneration",
"(",
"int",
"$",
"interval",
"=",
"null",
",",
"string",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"interval",
")",
")",
"{",
"return",
";",
"}",
"$",
"expiry",
"=",
"time",
"(",
")",
"+",
"$",
"interval",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
"=",
"$",
"expiry",
";",
"}",
"if",
"(",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
"<",
"time",
"(",
")",
"||",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
">",
"$",
"expiry",
")",
"{",
"session_regenerate_id",
"(",
"true",
")",
";",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
"=",
"$",
"expiry",
";",
"}",
"}"
] |
Regenerate the session id if it's needed
|
[
"Regenerate",
"the",
"session",
"id",
"if",
"it",
"s",
"needed"
] |
1ab5c308f510c1ad99c17d517df7c50b178be760
|
https://github.com/middlewares/php-session/blob/1ab5c308f510c1ad99c17d517df7c50b178be760/src/PhpSession.php#L144-L161
|
222,351
|
wandersonwhcr/romans
|
src/Filter/IntToRoman.php
|
IntToRoman.filter
|
public function filter(int $value) : string
{
if ($value < 0) {
throw new Exception(sprintf('Invalid integer: %d', $value), Exception::INVALID_INTEGER);
}
$tokens = $this->getGrammar()->getTokens();
$values = array_reverse($this->getGrammar()->getValuesWithModifiers(), true /* preserve keys */);
$result = '';
if ($value === 0) {
$dataset = $values[0];
foreach ($dataset as $token) {
$result = $result . $tokens[$token];
}
return $result;
}
foreach ($values as $current => $dataset) {
while ($current > 0 && $value >= $current) {
$value = $value - $current;
foreach ($dataset as $token) {
$result = $result . $tokens[$token];
}
}
}
return $result;
}
|
php
|
public function filter(int $value) : string
{
if ($value < 0) {
throw new Exception(sprintf('Invalid integer: %d', $value), Exception::INVALID_INTEGER);
}
$tokens = $this->getGrammar()->getTokens();
$values = array_reverse($this->getGrammar()->getValuesWithModifiers(), true /* preserve keys */);
$result = '';
if ($value === 0) {
$dataset = $values[0];
foreach ($dataset as $token) {
$result = $result . $tokens[$token];
}
return $result;
}
foreach ($values as $current => $dataset) {
while ($current > 0 && $value >= $current) {
$value = $value - $current;
foreach ($dataset as $token) {
$result = $result . $tokens[$token];
}
}
}
return $result;
}
|
[
"public",
"function",
"filter",
"(",
"int",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"$",
"value",
"<",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Invalid integer: %d'",
",",
"$",
"value",
")",
",",
"Exception",
"::",
"INVALID_INTEGER",
")",
";",
"}",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getGrammar",
"(",
")",
"->",
"getTokens",
"(",
")",
";",
"$",
"values",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"getGrammar",
"(",
")",
"->",
"getValuesWithModifiers",
"(",
")",
",",
"true",
"/* preserve keys */",
")",
";",
"$",
"result",
"=",
"''",
";",
"if",
"(",
"$",
"value",
"===",
"0",
")",
"{",
"$",
"dataset",
"=",
"$",
"values",
"[",
"0",
"]",
";",
"foreach",
"(",
"$",
"dataset",
"as",
"$",
"token",
")",
"{",
"$",
"result",
"=",
"$",
"result",
".",
"$",
"tokens",
"[",
"$",
"token",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"current",
"=>",
"$",
"dataset",
")",
"{",
"while",
"(",
"$",
"current",
">",
"0",
"&&",
"$",
"value",
">=",
"$",
"current",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"-",
"$",
"current",
";",
"foreach",
"(",
"$",
"dataset",
"as",
"$",
"token",
")",
"{",
"$",
"result",
"=",
"$",
"result",
".",
"$",
"tokens",
"[",
"$",
"token",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Filter Integer to Roman Number
@param int Integer
@return string Roman Number Result
|
[
"Filter",
"Integer",
"to",
"Roman",
"Number"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Filter/IntToRoman.php#L35-L65
|
222,352
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/AbstractMigration.php
|
AbstractMigration.warnIf
|
public function warnIf($condition, $message = '')
{
$message = (strlen($message)) ? $message : 'Unknown Reason';
if (true === $condition) {
$this->outputWriter->write(' <warning>Warning during ' . $this->version->getExecutionState() . ': ' . $message . '</warning>');
}
}
|
php
|
public function warnIf($condition, $message = '')
{
$message = (strlen($message)) ? $message : 'Unknown Reason';
if (true === $condition) {
$this->outputWriter->write(' <warning>Warning during ' . $this->version->getExecutionState() . ': ' . $message . '</warning>');
}
}
|
[
"public",
"function",
"warnIf",
"(",
"$",
"condition",
",",
"$",
"message",
"=",
"''",
")",
"{",
"$",
"message",
"=",
"(",
"strlen",
"(",
"$",
"message",
")",
")",
"?",
"$",
"message",
":",
"'Unknown Reason'",
";",
"if",
"(",
"true",
"===",
"$",
"condition",
")",
"{",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"' <warning>Warning during '",
".",
"$",
"this",
"->",
"version",
"->",
"getExecutionState",
"(",
")",
".",
"': '",
".",
"$",
"message",
".",
"'</warning>'",
")",
";",
"}",
"}"
] |
Print a warning message if the condition evalutes to TRUE.
@param bool $condition
@param string $message
|
[
"Print",
"a",
"warning",
"message",
"if",
"the",
"condition",
"evalutes",
"to",
"TRUE",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/AbstractMigration.php#L102-L109
|
222,353
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/AbstractMigration.php
|
AbstractMigration.abortIf
|
public function abortIf($condition, $message = '')
{
$message = (strlen($message)) ? $message : 'Unknown Reason';
if (true === $condition) {
throw new AbortException($message);
}
}
|
php
|
public function abortIf($condition, $message = '')
{
$message = (strlen($message)) ? $message : 'Unknown Reason';
if (true === $condition) {
throw new AbortException($message);
}
}
|
[
"public",
"function",
"abortIf",
"(",
"$",
"condition",
",",
"$",
"message",
"=",
"''",
")",
"{",
"$",
"message",
"=",
"(",
"strlen",
"(",
"$",
"message",
")",
")",
"?",
"$",
"message",
":",
"'Unknown Reason'",
";",
"if",
"(",
"true",
"===",
"$",
"condition",
")",
"{",
"throw",
"new",
"AbortException",
"(",
"$",
"message",
")",
";",
"}",
"}"
] |
Abort the migration if the condition evalutes to TRUE.
@param bool $condition
@param string $message
@throws AntiMattr\MongoDB\Migrations\Exception\AbortException
|
[
"Abort",
"the",
"migration",
"if",
"the",
"condition",
"evalutes",
"to",
"TRUE",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/AbstractMigration.php#L119-L126
|
222,354
|
idr0id/Papper
|
src/Papper/FluentSyntax/MappingFluentSyntax.php
|
MappingFluentSyntax.constructUsing
|
public function constructUsing($objectCreator)
{
if ($objectCreator instanceof \Closure) {
$objectCreator = new ClosureObjectCreator($objectCreator);
}
if (!$objectCreator instanceof ObjectCreatorInterface) {
throw new PapperConfigurationException('Argument objectCreator must be closure or instance of Papper\ObjectCreatorInterface');
}
$this->typeMap->setObjectCreator($objectCreator);
}
|
php
|
public function constructUsing($objectCreator)
{
if ($objectCreator instanceof \Closure) {
$objectCreator = new ClosureObjectCreator($objectCreator);
}
if (!$objectCreator instanceof ObjectCreatorInterface) {
throw new PapperConfigurationException('Argument objectCreator must be closure or instance of Papper\ObjectCreatorInterface');
}
$this->typeMap->setObjectCreator($objectCreator);
}
|
[
"public",
"function",
"constructUsing",
"(",
"$",
"objectCreator",
")",
"{",
"if",
"(",
"$",
"objectCreator",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"objectCreator",
"=",
"new",
"ClosureObjectCreator",
"(",
"$",
"objectCreator",
")",
";",
"}",
"if",
"(",
"!",
"$",
"objectCreator",
"instanceof",
"ObjectCreatorInterface",
")",
"{",
"throw",
"new",
"PapperConfigurationException",
"(",
"'Argument objectCreator must be closure or instance of Papper\\ObjectCreatorInterface'",
")",
";",
"}",
"$",
"this",
"->",
"typeMap",
"->",
"setObjectCreator",
"(",
"$",
"objectCreator",
")",
";",
"}"
] |
Supply a custom instantiation function for the destination type
@param ObjectCreatorInterface|\Closure $objectCreator Callback to create the destination type given the source object
@throws PapperConfigurationException
@return MappingFluentSyntax
|
[
"Supply",
"a",
"custom",
"instantiation",
"function",
"for",
"the",
"destination",
"type"
] |
53682bd058934027dbd4376abab93ac0cd06dffb
|
https://github.com/idr0id/Papper/blob/53682bd058934027dbd4376abab93ac0cd06dffb/src/Papper/FluentSyntax/MappingFluentSyntax.php#L38-L47
|
222,355
|
idr0id/Papper
|
src/Papper/FluentSyntax/MappingFluentSyntax.php
|
MappingFluentSyntax.forMember
|
public function forMember($name, $memberOptions)
{
$propertyMap = $this->typeMap->getPropertyMap($name);
if ($propertyMap === null) {
throw new PapperConfigurationException(sprintf('Unable to find destination member %s on type %s', $name, $this->typeMap->getDestinationType()));
}
$memberOptions = is_array($memberOptions) ? $memberOptions : array($memberOptions);
foreach ($memberOptions as $memberOption) {
if (!$memberOption instanceof MemberOptionInterface) {
throw new PapperConfigurationException('Member options must be array or instance of Papper\MemberOptionInterface');
}
$memberOption->apply($this->typeMap, $propertyMap);
}
return $this;
}
|
php
|
public function forMember($name, $memberOptions)
{
$propertyMap = $this->typeMap->getPropertyMap($name);
if ($propertyMap === null) {
throw new PapperConfigurationException(sprintf('Unable to find destination member %s on type %s', $name, $this->typeMap->getDestinationType()));
}
$memberOptions = is_array($memberOptions) ? $memberOptions : array($memberOptions);
foreach ($memberOptions as $memberOption) {
if (!$memberOption instanceof MemberOptionInterface) {
throw new PapperConfigurationException('Member options must be array or instance of Papper\MemberOptionInterface');
}
$memberOption->apply($this->typeMap, $propertyMap);
}
return $this;
}
|
[
"public",
"function",
"forMember",
"(",
"$",
"name",
",",
"$",
"memberOptions",
")",
"{",
"$",
"propertyMap",
"=",
"$",
"this",
"->",
"typeMap",
"->",
"getPropertyMap",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"propertyMap",
"===",
"null",
")",
"{",
"throw",
"new",
"PapperConfigurationException",
"(",
"sprintf",
"(",
"'Unable to find destination member %s on type %s'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"typeMap",
"->",
"getDestinationType",
"(",
")",
")",
")",
";",
"}",
"$",
"memberOptions",
"=",
"is_array",
"(",
"$",
"memberOptions",
")",
"?",
"$",
"memberOptions",
":",
"array",
"(",
"$",
"memberOptions",
")",
";",
"foreach",
"(",
"$",
"memberOptions",
"as",
"$",
"memberOption",
")",
"{",
"if",
"(",
"!",
"$",
"memberOption",
"instanceof",
"MemberOptionInterface",
")",
"{",
"throw",
"new",
"PapperConfigurationException",
"(",
"'Member options must be array or instance of Papper\\MemberOptionInterface'",
")",
";",
"}",
"$",
"memberOption",
"->",
"apply",
"(",
"$",
"this",
"->",
"typeMap",
",",
"$",
"propertyMap",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Customize configuration for individual member
@param string $name Destination member name
@param MemberOptionInterface|MemberOptionInterface[] $memberOptions Member option
@throws PapperConfigurationException
@return MappingFluentSyntax
|
[
"Customize",
"configuration",
"for",
"individual",
"member"
] |
53682bd058934027dbd4376abab93ac0cd06dffb
|
https://github.com/idr0id/Papper/blob/53682bd058934027dbd4376abab93ac0cd06dffb/src/Papper/FluentSyntax/MappingFluentSyntax.php#L57-L71
|
222,356
|
idr0id/Papper
|
src/Papper/FluentSyntax/MappingFluentSyntax.php
|
MappingFluentSyntax.forDynamicMember
|
public function forDynamicMember($name, $memberOptions = null)
{
$propertyMap = $this->typeMap->getPropertyMap($name);
if ($propertyMap !== null) {
throw new PapperConfigurationException(sprintf('Unable to create dynamic destination member %s on type %s because it already exists in type', $name, $this->typeMap->getDestinationType()));
}
$setter = $this->typeMap->getDestinationType() === 'stdClass'
? new StdClassPropertySetter($name)
: new PropertyAccessSetter($name);
$this->typeMap->addPropertyMap($propertyMap = new PropertyMap($setter));
$memberOptions = is_array($memberOptions) ? $memberOptions : array($memberOptions);
foreach ($memberOptions as $memberOption) {
if (!$memberOption instanceof MemberOptionInterface) {
throw new PapperConfigurationException('Member options must be array or instance of Papper\MemberOptionInterface');
}
$memberOption->apply($this->typeMap, $propertyMap);
}
return $this;
}
|
php
|
public function forDynamicMember($name, $memberOptions = null)
{
$propertyMap = $this->typeMap->getPropertyMap($name);
if ($propertyMap !== null) {
throw new PapperConfigurationException(sprintf('Unable to create dynamic destination member %s on type %s because it already exists in type', $name, $this->typeMap->getDestinationType()));
}
$setter = $this->typeMap->getDestinationType() === 'stdClass'
? new StdClassPropertySetter($name)
: new PropertyAccessSetter($name);
$this->typeMap->addPropertyMap($propertyMap = new PropertyMap($setter));
$memberOptions = is_array($memberOptions) ? $memberOptions : array($memberOptions);
foreach ($memberOptions as $memberOption) {
if (!$memberOption instanceof MemberOptionInterface) {
throw new PapperConfigurationException('Member options must be array or instance of Papper\MemberOptionInterface');
}
$memberOption->apply($this->typeMap, $propertyMap);
}
return $this;
}
|
[
"public",
"function",
"forDynamicMember",
"(",
"$",
"name",
",",
"$",
"memberOptions",
"=",
"null",
")",
"{",
"$",
"propertyMap",
"=",
"$",
"this",
"->",
"typeMap",
"->",
"getPropertyMap",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"propertyMap",
"!==",
"null",
")",
"{",
"throw",
"new",
"PapperConfigurationException",
"(",
"sprintf",
"(",
"'Unable to create dynamic destination member %s on type %s because it already exists in type'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"typeMap",
"->",
"getDestinationType",
"(",
")",
")",
")",
";",
"}",
"$",
"setter",
"=",
"$",
"this",
"->",
"typeMap",
"->",
"getDestinationType",
"(",
")",
"===",
"'stdClass'",
"?",
"new",
"StdClassPropertySetter",
"(",
"$",
"name",
")",
":",
"new",
"PropertyAccessSetter",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"typeMap",
"->",
"addPropertyMap",
"(",
"$",
"propertyMap",
"=",
"new",
"PropertyMap",
"(",
"$",
"setter",
")",
")",
";",
"$",
"memberOptions",
"=",
"is_array",
"(",
"$",
"memberOptions",
")",
"?",
"$",
"memberOptions",
":",
"array",
"(",
"$",
"memberOptions",
")",
";",
"foreach",
"(",
"$",
"memberOptions",
"as",
"$",
"memberOption",
")",
"{",
"if",
"(",
"!",
"$",
"memberOption",
"instanceof",
"MemberOptionInterface",
")",
"{",
"throw",
"new",
"PapperConfigurationException",
"(",
"'Member options must be array or instance of Papper\\MemberOptionInterface'",
")",
";",
"}",
"$",
"memberOption",
"->",
"apply",
"(",
"$",
"this",
"->",
"typeMap",
",",
"$",
"propertyMap",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Create configuration for individual dynamic member
@param string $name Destination member name
@param MemberOptionInterface|MemberOptionInterface[] $memberOptions Member option
@throws PapperConfigurationException
@return MappingFluentSyntax
|
[
"Create",
"configuration",
"for",
"individual",
"dynamic",
"member"
] |
53682bd058934027dbd4376abab93ac0cd06dffb
|
https://github.com/idr0id/Papper/blob/53682bd058934027dbd4376abab93ac0cd06dffb/src/Papper/FluentSyntax/MappingFluentSyntax.php#L81-L102
|
222,357
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.addTokenValue
|
protected function addTokenValue(string $token, string $modifier = null, int $quantity = 1) : self
{
$tokens = array_flip($this->getGrammar()->getTokens());
$values = $this->getGrammar()->getValuesWithModifiers();
$elements = [];
if (isset($modifier)) {
$elements[] = $tokens[$modifier];
}
$elements[] = $tokens[$token];
$this->addValue((array_search($elements, $values)) * $quantity);
return $this;
}
|
php
|
protected function addTokenValue(string $token, string $modifier = null, int $quantity = 1) : self
{
$tokens = array_flip($this->getGrammar()->getTokens());
$values = $this->getGrammar()->getValuesWithModifiers();
$elements = [];
if (isset($modifier)) {
$elements[] = $tokens[$modifier];
}
$elements[] = $tokens[$token];
$this->addValue((array_search($elements, $values)) * $quantity);
return $this;
}
|
[
"protected",
"function",
"addTokenValue",
"(",
"string",
"$",
"token",
",",
"string",
"$",
"modifier",
"=",
"null",
",",
"int",
"$",
"quantity",
"=",
"1",
")",
":",
"self",
"{",
"$",
"tokens",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"getGrammar",
"(",
")",
"->",
"getTokens",
"(",
")",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"getGrammar",
"(",
")",
"->",
"getValuesWithModifiers",
"(",
")",
";",
"$",
"elements",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"modifier",
")",
")",
"{",
"$",
"elements",
"[",
"]",
"=",
"$",
"tokens",
"[",
"$",
"modifier",
"]",
";",
"}",
"$",
"elements",
"[",
"]",
"=",
"$",
"tokens",
"[",
"$",
"token",
"]",
";",
"$",
"this",
"->",
"addValue",
"(",
"(",
"array_search",
"(",
"$",
"elements",
",",
"$",
"values",
")",
")",
"*",
"$",
"quantity",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add Token Value
@param string $token Token
@param string $modifier Modifier Token
@param int $quantity Quantity
@return self Fluent Interface
|
[
"Add",
"Token",
"Value"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L165-L180
|
222,358
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromY
|
private function doTransitionFromY() : self
{
if ($this->getToken() !== '$') {
throw (new Exception('Invalid Roman', Exception::INVALID_ROMAN))
->setPosition($this->getPosition())
->setToken($this->getToken());
}
// done!
$this->setState(self::STATE_Z);
return $this;
}
|
php
|
private function doTransitionFromY() : self
{
if ($this->getToken() !== '$') {
throw (new Exception('Invalid Roman', Exception::INVALID_ROMAN))
->setPosition($this->getPosition())
->setToken($this->getToken());
}
// done!
$this->setState(self::STATE_Z);
return $this;
}
|
[
"private",
"function",
"doTransitionFromY",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"!==",
"'$'",
")",
"{",
"throw",
"(",
"new",
"Exception",
"(",
"'Invalid Roman'",
",",
"Exception",
"::",
"INVALID_ROMAN",
")",
")",
"->",
"setPosition",
"(",
"$",
"this",
"->",
"getPosition",
"(",
")",
")",
"->",
"setToken",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
")",
";",
"}",
"// done!",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Z",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition from Y
@return self Fluent Interface
|
[
"Do",
"Transition",
"from",
"Y"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L246-L257
|
222,359
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromG
|
private function doTransitionFromG() : self
{
if ($this->getToken() === Grammar::T_N) {
$this
->setState(self::STATE_Y)
->addPosition(1);
return $this;
}
if ($this->getToken() === Grammar::T_M) {
$this
->setState(self::STATE_G)
->addPosition(1)
->addTokenValue(Grammar::T_M);
return $this;
}
$this->setState(self::STATE_F);
return $this;
}
|
php
|
private function doTransitionFromG() : self
{
if ($this->getToken() === Grammar::T_N) {
$this
->setState(self::STATE_Y)
->addPosition(1);
return $this;
}
if ($this->getToken() === Grammar::T_M) {
$this
->setState(self::STATE_G)
->addPosition(1)
->addTokenValue(Grammar::T_M);
return $this;
}
$this->setState(self::STATE_F);
return $this;
}
|
[
"private",
"function",
"doTransitionFromG",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_N",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Y",
")",
"->",
"addPosition",
"(",
"1",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_M",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_G",
")",
"->",
"addPosition",
"(",
"1",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_M",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_F",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition from G
@return self Fluent Interface
|
[
"Do",
"Transition",
"from",
"G"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L264-L283
|
222,360
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromF
|
private function doTransitionFromF() : self
{
if ($this->getToken() === Grammar::T_D) {
$this
->setState(self::STATE_E)
->addPosition(1)
->addTokenValue(Grammar::T_D);
return $this;
}
if ($this->getToken() === Grammar::T_C && $this->hasToken(1) && $this->getToken(1) === Grammar::T_D) {
$this
->setState(self::STATE_D)
->addPosition(2)
->addTokenValue(Grammar::T_D, Grammar::T_C);
return $this;
}
if ($this->getToken() === Grammar::T_C && $this->hasToken(1) && $this->getToken(1) === Grammar::T_M) {
$this
->setState(self::STATE_D)
->addPosition(2)
->addTokenValue(Grammar::T_M, Grammar::T_C);
return $this;
}
$this->setState(self::STATE_E);
return $this;
}
|
php
|
private function doTransitionFromF() : self
{
if ($this->getToken() === Grammar::T_D) {
$this
->setState(self::STATE_E)
->addPosition(1)
->addTokenValue(Grammar::T_D);
return $this;
}
if ($this->getToken() === Grammar::T_C && $this->hasToken(1) && $this->getToken(1) === Grammar::T_D) {
$this
->setState(self::STATE_D)
->addPosition(2)
->addTokenValue(Grammar::T_D, Grammar::T_C);
return $this;
}
if ($this->getToken() === Grammar::T_C && $this->hasToken(1) && $this->getToken(1) === Grammar::T_M) {
$this
->setState(self::STATE_D)
->addPosition(2)
->addTokenValue(Grammar::T_M, Grammar::T_C);
return $this;
}
$this->setState(self::STATE_E);
return $this;
}
|
[
"private",
"function",
"doTransitionFromF",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_D",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_E",
")",
"->",
"addPosition",
"(",
"1",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_D",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_C",
"&&",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_D",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_D",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_D",
",",
"Grammar",
"::",
"T_C",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_C",
"&&",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_M",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_D",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_M",
",",
"Grammar",
"::",
"T_C",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_E",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition from F
@return self Fluent Interface
|
[
"Do",
"Transition",
"from",
"F"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L290-L318
|
222,361
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromE
|
private function doTransitionFromE() : self
{
if ($this->getToken() === Grammar::T_C) {
if ($this->hasToken(1) && $this->getToken(1) === Grammar::T_C) {
if ($this->hasToken(2) && $this->getToken(2) === Grammar::T_C) {
$this
->setState(self::STATE_D)
->addPosition(3)
->addTokenValue(Grammar::T_C, null, 3);
return $this;
}
$this
->setState(self::STATE_D)
->addPosition(2)
->addTokenValue(Grammar::T_C, null, 2);
return $this;
}
$this
->setState(self::STATE_D)
->addPosition(1)
->addTokenValue(Grammar::T_C);
return $this;
}
$this->setState(self::STATE_D);
return $this;
}
|
php
|
private function doTransitionFromE() : self
{
if ($this->getToken() === Grammar::T_C) {
if ($this->hasToken(1) && $this->getToken(1) === Grammar::T_C) {
if ($this->hasToken(2) && $this->getToken(2) === Grammar::T_C) {
$this
->setState(self::STATE_D)
->addPosition(3)
->addTokenValue(Grammar::T_C, null, 3);
return $this;
}
$this
->setState(self::STATE_D)
->addPosition(2)
->addTokenValue(Grammar::T_C, null, 2);
return $this;
}
$this
->setState(self::STATE_D)
->addPosition(1)
->addTokenValue(Grammar::T_C);
return $this;
}
$this->setState(self::STATE_D);
return $this;
}
|
[
"private",
"function",
"doTransitionFromE",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_C",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_C",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasToken",
"(",
"2",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"2",
")",
"===",
"Grammar",
"::",
"T_C",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_D",
")",
"->",
"addPosition",
"(",
"3",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_C",
",",
"null",
",",
"3",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_D",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_C",
",",
"null",
",",
"2",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_D",
")",
"->",
"addPosition",
"(",
"1",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_C",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_D",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition from E
@return self Fluent Interface
|
[
"Do",
"Transition",
"from",
"E"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L325-L353
|
222,362
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromD
|
private function doTransitionFromD() : self
{
if ($this->getToken() === Grammar::T_L) {
$this
->setState(self::STATE_C)
->addPosition(1)
->addTokenValue(Grammar::T_L);
return $this;
}
if ($this->getToken() === Grammar::T_X && $this->hasToken(1) && $this->getToken(1) === Grammar::T_L) {
$this
->setState(self::STATE_B)
->addPosition(2)
->addTokenValue(Grammar::T_L, Grammar::T_X);
return $this;
}
if ($this->getToken() === Grammar::T_X && $this->hasToken(1) && $this->getToken(1) === Grammar::T_C) {
$this
->setState(self::STATE_B)
->addPosition(2)
->addTokenValue(Grammar::T_C, Grammar::T_X);
return $this;
}
$this->setState(self::STATE_C);
return $this;
}
|
php
|
private function doTransitionFromD() : self
{
if ($this->getToken() === Grammar::T_L) {
$this
->setState(self::STATE_C)
->addPosition(1)
->addTokenValue(Grammar::T_L);
return $this;
}
if ($this->getToken() === Grammar::T_X && $this->hasToken(1) && $this->getToken(1) === Grammar::T_L) {
$this
->setState(self::STATE_B)
->addPosition(2)
->addTokenValue(Grammar::T_L, Grammar::T_X);
return $this;
}
if ($this->getToken() === Grammar::T_X && $this->hasToken(1) && $this->getToken(1) === Grammar::T_C) {
$this
->setState(self::STATE_B)
->addPosition(2)
->addTokenValue(Grammar::T_C, Grammar::T_X);
return $this;
}
$this->setState(self::STATE_C);
return $this;
}
|
[
"private",
"function",
"doTransitionFromD",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_L",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_C",
")",
"->",
"addPosition",
"(",
"1",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_L",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_X",
"&&",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_L",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_B",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_L",
",",
"Grammar",
"::",
"T_X",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_X",
"&&",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_C",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_B",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_C",
",",
"Grammar",
"::",
"T_X",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_C",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition from D
@return self Fluent Interface
|
[
"Do",
"Transition",
"from",
"D"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L360-L388
|
222,363
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromC
|
private function doTransitionFromC() : self
{
if ($this->getToken() === Grammar::T_X) {
if ($this->hasToken(1) && $this->getToken(1) === Grammar::T_X) {
if ($this->hasToken(2) && $this->getToken(2) === Grammar::T_X) {
$this
->setState(self::STATE_B)
->addPosition(3)
->addTokenValue(Grammar::T_X, null, 3);
return $this;
}
$this
->setState(self::STATE_B)
->addPosition(2)
->addTokenValue(Grammar::T_X, null, 2);
return $this;
}
$this
->setState(self::STATE_B)
->addPosition(1)
->addTokenValue(Grammar::T_X);
return $this;
}
$this->setState(self::STATE_B);
return $this;
}
|
php
|
private function doTransitionFromC() : self
{
if ($this->getToken() === Grammar::T_X) {
if ($this->hasToken(1) && $this->getToken(1) === Grammar::T_X) {
if ($this->hasToken(2) && $this->getToken(2) === Grammar::T_X) {
$this
->setState(self::STATE_B)
->addPosition(3)
->addTokenValue(Grammar::T_X, null, 3);
return $this;
}
$this
->setState(self::STATE_B)
->addPosition(2)
->addTokenValue(Grammar::T_X, null, 2);
return $this;
}
$this
->setState(self::STATE_B)
->addPosition(1)
->addTokenValue(Grammar::T_X);
return $this;
}
$this->setState(self::STATE_B);
return $this;
}
|
[
"private",
"function",
"doTransitionFromC",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_X",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_X",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasToken",
"(",
"2",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"2",
")",
"===",
"Grammar",
"::",
"T_X",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_B",
")",
"->",
"addPosition",
"(",
"3",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_X",
",",
"null",
",",
"3",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_B",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_X",
",",
"null",
",",
"2",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_B",
")",
"->",
"addPosition",
"(",
"1",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_X",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_B",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition from C
@return self Fluent Interface
|
[
"Do",
"Transition",
"from",
"C"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L395-L423
|
222,364
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromB
|
private function doTransitionFromB() : self
{
if ($this->getToken() === Grammar::T_V) {
$this
->setState(self::STATE_A)
->addPosition(1)
->addTokenValue(Grammar::T_V);
return $this;
}
if ($this->getToken() === Grammar::T_I && $this->hasToken(1) && $this->getToken(1) === Grammar::T_V) {
$this
->setState(self::STATE_Y)
->addPosition(2)
->addTokenValue(Grammar::T_V, Grammar::T_I);
return $this;
}
if ($this->getToken() === Grammar::T_I && $this->hasToken(1) && $this->getToken(1) === Grammar::T_X) {
$this
->setState(self::STATE_Y)
->addPosition(2)
->addTokenValue(Grammar::T_X, Grammar::T_I);
return $this;
}
$this->setState(self::STATE_A);
return $this;
}
|
php
|
private function doTransitionFromB() : self
{
if ($this->getToken() === Grammar::T_V) {
$this
->setState(self::STATE_A)
->addPosition(1)
->addTokenValue(Grammar::T_V);
return $this;
}
if ($this->getToken() === Grammar::T_I && $this->hasToken(1) && $this->getToken(1) === Grammar::T_V) {
$this
->setState(self::STATE_Y)
->addPosition(2)
->addTokenValue(Grammar::T_V, Grammar::T_I);
return $this;
}
if ($this->getToken() === Grammar::T_I && $this->hasToken(1) && $this->getToken(1) === Grammar::T_X) {
$this
->setState(self::STATE_Y)
->addPosition(2)
->addTokenValue(Grammar::T_X, Grammar::T_I);
return $this;
}
$this->setState(self::STATE_A);
return $this;
}
|
[
"private",
"function",
"doTransitionFromB",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_V",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_A",
")",
"->",
"addPosition",
"(",
"1",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_V",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_I",
"&&",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_V",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Y",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_V",
",",
"Grammar",
"::",
"T_I",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_I",
"&&",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_X",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Y",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_X",
",",
"Grammar",
"::",
"T_I",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_A",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition from B
@return self Fluent Interface
|
[
"Do",
"Transition",
"from",
"B"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L430-L458
|
222,365
|
wandersonwhcr/romans
|
src/Parser/Automaton.php
|
Automaton.doTransitionFromA
|
private function doTransitionFromA() : self
{
if ($this->getToken() === Grammar::T_I) {
if ($this->hasToken(1) && $this->getToken(1) === Grammar::T_I) {
if ($this->hasToken(2) && $this->getToken(2) === Grammar::T_I) {
$this
->setState(self::STATE_Y)
->addPosition(3)
->addTokenValue(Grammar::T_I, null, 3);
return $this;
}
$this
->setState(self::STATE_Y)
->addPosition(2)
->addTokenValue(Grammar::T_I, null, 2);
return $this;
}
$this
->setState(self::STATE_Y)
->addPosition(1)
->addTokenValue(Grammar::T_I);
return $this;
}
$this->setState(self::STATE_Y);
return $this;
}
|
php
|
private function doTransitionFromA() : self
{
if ($this->getToken() === Grammar::T_I) {
if ($this->hasToken(1) && $this->getToken(1) === Grammar::T_I) {
if ($this->hasToken(2) && $this->getToken(2) === Grammar::T_I) {
$this
->setState(self::STATE_Y)
->addPosition(3)
->addTokenValue(Grammar::T_I, null, 3);
return $this;
}
$this
->setState(self::STATE_Y)
->addPosition(2)
->addTokenValue(Grammar::T_I, null, 2);
return $this;
}
$this
->setState(self::STATE_Y)
->addPosition(1)
->addTokenValue(Grammar::T_I);
return $this;
}
$this->setState(self::STATE_Y);
return $this;
}
|
[
"private",
"function",
"doTransitionFromA",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
"===",
"Grammar",
"::",
"T_I",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasToken",
"(",
"1",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"1",
")",
"===",
"Grammar",
"::",
"T_I",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasToken",
"(",
"2",
")",
"&&",
"$",
"this",
"->",
"getToken",
"(",
"2",
")",
"===",
"Grammar",
"::",
"T_I",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Y",
")",
"->",
"addPosition",
"(",
"3",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_I",
",",
"null",
",",
"3",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Y",
")",
"->",
"addPosition",
"(",
"2",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_I",
",",
"null",
",",
"2",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Y",
")",
"->",
"addPosition",
"(",
"1",
")",
"->",
"addTokenValue",
"(",
"Grammar",
"::",
"T_I",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"STATE_Y",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Do Transition From A
@return self Fluent Interface
|
[
"Do",
"Transition",
"From",
"A"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Parser/Automaton.php#L465-L493
|
222,366
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/ConfigurationBuilder.php
|
ConfigurationBuilder.getDirectoryRelativeToFile
|
protected function getDirectoryRelativeToFile(string $configFile, ?string $directory = null): ?string
{
if (!$directory) {
return null;
}
$path = realpath(dirname($configFile) . '/' . $directory);
if (false !== $path) {
return $path;
}
return $directory;
}
|
php
|
protected function getDirectoryRelativeToFile(string $configFile, ?string $directory = null): ?string
{
if (!$directory) {
return null;
}
$path = realpath(dirname($configFile) . '/' . $directory);
if (false !== $path) {
return $path;
}
return $directory;
}
|
[
"protected",
"function",
"getDirectoryRelativeToFile",
"(",
"string",
"$",
"configFile",
",",
"?",
"string",
"$",
"directory",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"!",
"$",
"directory",
")",
"{",
"return",
"null",
";",
"}",
"$",
"path",
"=",
"realpath",
"(",
"dirname",
"(",
"$",
"configFile",
")",
".",
"'/'",
".",
"$",
"directory",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"path",
")",
"{",
"return",
"$",
"path",
";",
"}",
"return",
"$",
"directory",
";",
"}"
] |
Get the path to the directory relative to the config file.
@param string $configFile
@param string|null $directory
@return string|null
|
[
"Get",
"the",
"path",
"to",
"the",
"directory",
"relative",
"to",
"the",
"config",
"file",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/ConfigurationBuilder.php#L234-L247
|
222,367
|
idr0id/Papper
|
src/Papper/Engine.php
|
Engine.execute
|
public function execute(MappingContext $context)
{
$typeMap = $this->config->findTypeMap($context->getSourceType(), $context->getDestinationType());
try {
$typeMap->validate();
$mapFunc = $typeMap->getMapFunc();
$destination = is_array($context->getSource())
? $this->mapCollection($context, $mapFunc)
: $this->mapObject($context, $mapFunc);
return $destination;
} catch (\Exception $e) {
$message = sprintf("Error while mapping %s -> %s", $typeMap->getSourceType(), $typeMap->getDestinationType());
throw new MappingException($message, 0, $e);
}
}
|
php
|
public function execute(MappingContext $context)
{
$typeMap = $this->config->findTypeMap($context->getSourceType(), $context->getDestinationType());
try {
$typeMap->validate();
$mapFunc = $typeMap->getMapFunc();
$destination = is_array($context->getSource())
? $this->mapCollection($context, $mapFunc)
: $this->mapObject($context, $mapFunc);
return $destination;
} catch (\Exception $e) {
$message = sprintf("Error while mapping %s -> %s", $typeMap->getSourceType(), $typeMap->getDestinationType());
throw new MappingException($message, 0, $e);
}
}
|
[
"public",
"function",
"execute",
"(",
"MappingContext",
"$",
"context",
")",
"{",
"$",
"typeMap",
"=",
"$",
"this",
"->",
"config",
"->",
"findTypeMap",
"(",
"$",
"context",
"->",
"getSourceType",
"(",
")",
",",
"$",
"context",
"->",
"getDestinationType",
"(",
")",
")",
";",
"try",
"{",
"$",
"typeMap",
"->",
"validate",
"(",
")",
";",
"$",
"mapFunc",
"=",
"$",
"typeMap",
"->",
"getMapFunc",
"(",
")",
";",
"$",
"destination",
"=",
"is_array",
"(",
"$",
"context",
"->",
"getSource",
"(",
")",
")",
"?",
"$",
"this",
"->",
"mapCollection",
"(",
"$",
"context",
",",
"$",
"mapFunc",
")",
":",
"$",
"this",
"->",
"mapObject",
"(",
"$",
"context",
",",
"$",
"mapFunc",
")",
";",
"return",
"$",
"destination",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"\"Error while mapping %s -> %s\"",
",",
"$",
"typeMap",
"->",
"getSourceType",
"(",
")",
",",
"$",
"typeMap",
"->",
"getDestinationType",
"(",
")",
")",
";",
"throw",
"new",
"MappingException",
"(",
"$",
"message",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] |
Execute a mapping using MappingContext
@param MappingContext $context Mapping context
@return object|object[] Mapped destination object or collection
@throws MappingException
@throws ClassNotFoundException
|
[
"Execute",
"a",
"mapping",
"using",
"MappingContext"
] |
53682bd058934027dbd4376abab93ac0cd06dffb
|
https://github.com/idr0id/Papper/blob/53682bd058934027dbd4376abab93ac0cd06dffb/src/Papper/Engine.php#L81-L97
|
222,368
|
idr0id/Papper
|
src/Papper/Engine.php
|
Engine.validate
|
public function validate()
{
$errors = array();
foreach ($this->config->getAllTypeMaps() as $typeMap) {
try {
$typeMap->validate();
} catch (\Exception $e) {
$errors[] = $e->getMessage();
}
}
if (!empty($errors)) {
throw new ValidationException(implode("\n\n", $errors));
}
}
|
php
|
public function validate()
{
$errors = array();
foreach ($this->config->getAllTypeMaps() as $typeMap) {
try {
$typeMap->validate();
} catch (\Exception $e) {
$errors[] = $e->getMessage();
}
}
if (!empty($errors)) {
throw new ValidationException(implode("\n\n", $errors));
}
}
|
[
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"config",
"->",
"getAllTypeMaps",
"(",
")",
"as",
"$",
"typeMap",
")",
"{",
"try",
"{",
"$",
"typeMap",
"->",
"validate",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"implode",
"(",
"\"\\n\\n\"",
",",
"$",
"errors",
")",
")",
";",
"}",
"}"
] |
Validates that every top level destination property is mapped to source property.
If not, a ConfigurationException is thrown detailing any missing mappings.
@throws ValidationException if any TypeMaps contain unmapped properties
|
[
"Validates",
"that",
"every",
"top",
"level",
"destination",
"property",
"is",
"mapped",
"to",
"source",
"property",
".",
"If",
"not",
"a",
"ConfigurationException",
"is",
"thrown",
"detailing",
"any",
"missing",
"mappings",
"."
] |
53682bd058934027dbd4376abab93ac0cd06dffb
|
https://github.com/idr0id/Papper/blob/53682bd058934027dbd4376abab93ac0cd06dffb/src/Papper/Engine.php#L105-L119
|
222,369
|
wandersonwhcr/romans
|
src/Grammar/Grammar.php
|
Grammar.getValuesWithModifiers
|
public function getValuesWithModifiers()
{
$values = array_map(function ($value) {
return [$value];
}, array_flip($this->getValues()));
$valuesWithModifiers = $values + $this->getModifiers(); // merge and keep keys (append)
ksort($valuesWithModifiers);
return $valuesWithModifiers;
}
|
php
|
public function getValuesWithModifiers()
{
$values = array_map(function ($value) {
return [$value];
}, array_flip($this->getValues()));
$valuesWithModifiers = $values + $this->getModifiers(); // merge and keep keys (append)
ksort($valuesWithModifiers);
return $valuesWithModifiers;
}
|
[
"public",
"function",
"getValuesWithModifiers",
"(",
")",
"{",
"$",
"values",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"[",
"$",
"value",
"]",
";",
"}",
",",
"array_flip",
"(",
"$",
"this",
"->",
"getValues",
"(",
")",
")",
")",
";",
"$",
"valuesWithModifiers",
"=",
"$",
"values",
"+",
"$",
"this",
"->",
"getModifiers",
"(",
")",
";",
"// merge and keep keys (append)",
"ksort",
"(",
"$",
"valuesWithModifiers",
")",
";",
"return",
"$",
"valuesWithModifiers",
";",
"}"
] |
Get Values with Modifiers
@return array Values with Modifiers Available
|
[
"Get",
"Values",
"with",
"Modifiers"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Grammar/Grammar.php#L79-L90
|
222,370
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Version.php
|
Version.execute
|
public function execute($direction, $replay = false)
{
if ('down' === $direction && $replay) {
throw new AbortException(
'Cannot run \'down\' and replay it. Use replay with \'up\''
);
}
try {
$start = microtime(true);
$this->state = self::STATE_PRE;
$this->migration->{'pre' . ucfirst($direction)}($this->db);
if ('up' === $direction) {
$this->outputWriter->write("\n" . sprintf(' <info>++</info> migrating <comment>%s</comment>', $this->version) . "\n");
} else {
$this->outputWriter->write("\n" . sprintf(' <info>--</info> reverting <comment>%s</comment>', $this->version) . "\n");
}
$this->state = self::STATE_EXEC;
$this->migration->$direction($this->db);
$this->updateStatisticsAfter();
if ('up' === $direction) {
$this->markMigrated($replay);
} else {
$this->markNotMigrated();
}
$this->summarizeStatistics();
$this->state = self::STATE_POST;
$this->migration->{'post' . ucfirst($direction)}($this->db);
$end = microtime(true);
$this->time = round($end - $start, 2);
if ('up' === $direction) {
$this->outputWriter->write(sprintf("\n <info>++</info> migrated (%ss)", $this->time));
} else {
$this->outputWriter->write(sprintf("\n <info>--</info> reverted (%ss)", $this->time));
}
$this->state = self::STATE_NONE;
} catch (SkipException $e) {
// now mark it as migrated
if ('up' === $direction) {
$this->markMigrated();
} else {
$this->markNotMigrated();
}
$this->outputWriter->write(sprintf("\n <info>SS</info> skipped (Reason: %s)", $e->getMessage()));
$this->state = self::STATE_NONE;
} catch (\Exception $e) {
$this->outputWriter->write(sprintf(
'<error>Migration %s failed during %s. Error %s</error>',
$this->version, $this->getExecutionState(), $e->getMessage()
));
$this->state = self::STATE_NONE;
throw $e;
}
}
|
php
|
public function execute($direction, $replay = false)
{
if ('down' === $direction && $replay) {
throw new AbortException(
'Cannot run \'down\' and replay it. Use replay with \'up\''
);
}
try {
$start = microtime(true);
$this->state = self::STATE_PRE;
$this->migration->{'pre' . ucfirst($direction)}($this->db);
if ('up' === $direction) {
$this->outputWriter->write("\n" . sprintf(' <info>++</info> migrating <comment>%s</comment>', $this->version) . "\n");
} else {
$this->outputWriter->write("\n" . sprintf(' <info>--</info> reverting <comment>%s</comment>', $this->version) . "\n");
}
$this->state = self::STATE_EXEC;
$this->migration->$direction($this->db);
$this->updateStatisticsAfter();
if ('up' === $direction) {
$this->markMigrated($replay);
} else {
$this->markNotMigrated();
}
$this->summarizeStatistics();
$this->state = self::STATE_POST;
$this->migration->{'post' . ucfirst($direction)}($this->db);
$end = microtime(true);
$this->time = round($end - $start, 2);
if ('up' === $direction) {
$this->outputWriter->write(sprintf("\n <info>++</info> migrated (%ss)", $this->time));
} else {
$this->outputWriter->write(sprintf("\n <info>--</info> reverted (%ss)", $this->time));
}
$this->state = self::STATE_NONE;
} catch (SkipException $e) {
// now mark it as migrated
if ('up' === $direction) {
$this->markMigrated();
} else {
$this->markNotMigrated();
}
$this->outputWriter->write(sprintf("\n <info>SS</info> skipped (Reason: %s)", $e->getMessage()));
$this->state = self::STATE_NONE;
} catch (\Exception $e) {
$this->outputWriter->write(sprintf(
'<error>Migration %s failed during %s. Error %s</error>',
$this->version, $this->getExecutionState(), $e->getMessage()
));
$this->state = self::STATE_NONE;
throw $e;
}
}
|
[
"public",
"function",
"execute",
"(",
"$",
"direction",
",",
"$",
"replay",
"=",
"false",
")",
"{",
"if",
"(",
"'down'",
"===",
"$",
"direction",
"&&",
"$",
"replay",
")",
"{",
"throw",
"new",
"AbortException",
"(",
"'Cannot run \\'down\\' and replay it. Use replay with \\'up\\''",
")",
";",
"}",
"try",
"{",
"$",
"start",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_PRE",
";",
"$",
"this",
"->",
"migration",
"->",
"{",
"'pre'",
".",
"ucfirst",
"(",
"$",
"direction",
")",
"}",
"(",
"$",
"this",
"->",
"db",
")",
";",
"if",
"(",
"'up'",
"===",
"$",
"direction",
")",
"{",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"\"\\n\"",
".",
"sprintf",
"(",
"' <info>++</info> migrating <comment>%s</comment>'",
",",
"$",
"this",
"->",
"version",
")",
".",
"\"\\n\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"\"\\n\"",
".",
"sprintf",
"(",
"' <info>--</info> reverting <comment>%s</comment>'",
",",
"$",
"this",
"->",
"version",
")",
".",
"\"\\n\"",
")",
";",
"}",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_EXEC",
";",
"$",
"this",
"->",
"migration",
"->",
"$",
"direction",
"(",
"$",
"this",
"->",
"db",
")",
";",
"$",
"this",
"->",
"updateStatisticsAfter",
"(",
")",
";",
"if",
"(",
"'up'",
"===",
"$",
"direction",
")",
"{",
"$",
"this",
"->",
"markMigrated",
"(",
"$",
"replay",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"markNotMigrated",
"(",
")",
";",
"}",
"$",
"this",
"->",
"summarizeStatistics",
"(",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_POST",
";",
"$",
"this",
"->",
"migration",
"->",
"{",
"'post'",
".",
"ucfirst",
"(",
"$",
"direction",
")",
"}",
"(",
"$",
"this",
"->",
"db",
")",
";",
"$",
"end",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"time",
"=",
"round",
"(",
"$",
"end",
"-",
"$",
"start",
",",
"2",
")",
";",
"if",
"(",
"'up'",
"===",
"$",
"direction",
")",
"{",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"sprintf",
"(",
"\"\\n <info>++</info> migrated (%ss)\"",
",",
"$",
"this",
"->",
"time",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"sprintf",
"(",
"\"\\n <info>--</info> reverted (%ss)\"",
",",
"$",
"this",
"->",
"time",
")",
")",
";",
"}",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_NONE",
";",
"}",
"catch",
"(",
"SkipException",
"$",
"e",
")",
"{",
"// now mark it as migrated",
"if",
"(",
"'up'",
"===",
"$",
"direction",
")",
"{",
"$",
"this",
"->",
"markMigrated",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"markNotMigrated",
"(",
")",
";",
"}",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"sprintf",
"(",
"\"\\n <info>SS</info> skipped (Reason: %s)\"",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_NONE",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"sprintf",
"(",
"'<error>Migration %s failed during %s. Error %s</error>'",
",",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"getExecutionState",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_NONE",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Execute this migration version up or down.
@param string $direction The direction to execute the migration
@param bool $replay If the migration is being replayed
@throws \Exception when migration fails
|
[
"Execute",
"this",
"migration",
"version",
"up",
"or",
"down",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Version.php#L182-L249
|
222,371
|
php-fig/cache-util
|
src/KeyValidatorTrait.php
|
KeyValidatorTrait.validateKey
|
protected function validateKey($key)
{
if (!is_string($key) || $key === '') {
throw new InvalidArgumentException('Key should be a non empty string');
}
$unsupportedMatched = preg_match('#[' . preg_quote($this->getReservedKeyCharacters()) . ']#', $key);
if ($unsupportedMatched > 0) {
throw new InvalidArgumentException('Can\'t validate the specified key');
}
return true;
}
|
php
|
protected function validateKey($key)
{
if (!is_string($key) || $key === '') {
throw new InvalidArgumentException('Key should be a non empty string');
}
$unsupportedMatched = preg_match('#[' . preg_quote($this->getReservedKeyCharacters()) . ']#', $key);
if ($unsupportedMatched > 0) {
throw new InvalidArgumentException('Can\'t validate the specified key');
}
return true;
}
|
[
"protected",
"function",
"validateKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
"||",
"$",
"key",
"===",
"''",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Key should be a non empty string'",
")",
";",
"}",
"$",
"unsupportedMatched",
"=",
"preg_match",
"(",
"'#['",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"getReservedKeyCharacters",
"(",
")",
")",
".",
"']#'",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"unsupportedMatched",
">",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Can\\'t validate the specified key'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Determines if the specified key is legal under PSR-6.
@param string $key
The key to validate.
@throws InvalidArgumentException
An exception implementing The Cache InvalidArgumentException interface
will be thrown if the key does not validate.
@return bool
TRUE if the specified key is legal.
|
[
"Determines",
"if",
"the",
"specified",
"key",
"is",
"legal",
"under",
"PSR",
"-",
"6",
"."
] |
771adf39e9a09325b8c20f35f3d2bdafcb78ac8c
|
https://github.com/php-fig/cache-util/blob/771adf39e9a09325b8c20f35f3d2bdafcb78ac8c/src/KeyValidatorTrait.php#L34-L46
|
222,372
|
idr0id/Papper
|
src/Papper/FluentSyntax/ExecuteMappingFluentSyntax.php
|
ExecuteMappingFluentSyntax.to
|
public function to($destination, $destinationType = null)
{
$this->context->setDestination($destination, $destinationType);
return $this->engine->execute($this->context);
}
|
php
|
public function to($destination, $destinationType = null)
{
$this->context->setDestination($destination, $destinationType);
return $this->engine->execute($this->context);
}
|
[
"public",
"function",
"to",
"(",
"$",
"destination",
",",
"$",
"destinationType",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"context",
"->",
"setDestination",
"(",
"$",
"destination",
",",
"$",
"destinationType",
")",
";",
"return",
"$",
"this",
"->",
"engine",
"->",
"execute",
"(",
"$",
"this",
"->",
"context",
")",
";",
"}"
] |
Execute a mapping to the existing destination object.
If no Map exists then one is created.
@param object|object[] $destination Destination object or collection to map into
@param string|null $destinationType Destination type to map
@return object|object[] The mapped destination object, same instance as the $destination object
@throws NotSupportedException
@throws MappingException
|
[
"Execute",
"a",
"mapping",
"to",
"the",
"existing",
"destination",
"object",
".",
"If",
"no",
"Map",
"exists",
"then",
"one",
"is",
"created",
"."
] |
53682bd058934027dbd4376abab93ac0cd06dffb
|
https://github.com/idr0id/Papper/blob/53682bd058934027dbd4376abab93ac0cd06dffb/src/Papper/FluentSyntax/ExecuteMappingFluentSyntax.php#L37-L41
|
222,373
|
idr0id/Papper
|
src/Papper/FluentSyntax/ExecuteMappingFluentSyntax.php
|
ExecuteMappingFluentSyntax.toType
|
public function toType($destinationType)
{
$this->context->setDestination(null, $destinationType);
return $this->engine->execute($this->context);
}
|
php
|
public function toType($destinationType)
{
$this->context->setDestination(null, $destinationType);
return $this->engine->execute($this->context);
}
|
[
"public",
"function",
"toType",
"(",
"$",
"destinationType",
")",
"{",
"$",
"this",
"->",
"context",
"->",
"setDestination",
"(",
"null",
",",
"$",
"destinationType",
")",
";",
"return",
"$",
"this",
"->",
"engine",
"->",
"execute",
"(",
"$",
"this",
"->",
"context",
")",
";",
"}"
] |
Execute a mapping to a new destination object.
If no Map exists then one is created.
@param string $destinationType Destination type to create and map
@return object|object[]
@throws NotSupportedException
@throws MappingException
|
[
"Execute",
"a",
"mapping",
"to",
"a",
"new",
"destination",
"object",
".",
"If",
"no",
"Map",
"exists",
"then",
"one",
"is",
"created",
"."
] |
53682bd058934027dbd4376abab93ac0cd06dffb
|
https://github.com/idr0id/Papper/blob/53682bd058934027dbd4376abab93ac0cd06dffb/src/Papper/FluentSyntax/ExecuteMappingFluentSyntax.php#L52-L56
|
222,374
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Migration.php
|
Migration.migrate
|
public function migrate($to = null)
{
if (null === $to) {
$to = $this->configuration->getLatestVersion();
}
$from = $this->configuration->getCurrentVersion();
$from = (string) $from;
$to = (string) $to;
$migrations = $this->configuration->getMigrations();
if (!isset($migrations[$to]) && $to > 0) {
throw new UnknownVersionException($to);
}
$direction = $from > $to ? 'down' : 'up';
$migrationsToExecute = $this->configuration->getMigrationsToExecute($direction, $to);
if ($from === $to && empty($migrationsToExecute) && $migrations) {
return;
}
$this->outputWriter->write(sprintf('Migrating <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>', $direction, $to, $from));
if (empty($migrationsToExecute)) {
throw new NoMigrationsToExecuteException('Could not find any migrations to execute.');
}
$time = 0;
foreach ($migrationsToExecute as $version) {
$version->execute($direction);
$time += $version->getTime();
}
$this->outputWriter->write("\n <comment>------------------------</comment>\n");
$this->outputWriter->write(sprintf(' <info>++</info> finished in %s', $time));
$this->outputWriter->write(sprintf(' <info>++</info> %s migrations executed', count($migrationsToExecute)));
}
|
php
|
public function migrate($to = null)
{
if (null === $to) {
$to = $this->configuration->getLatestVersion();
}
$from = $this->configuration->getCurrentVersion();
$from = (string) $from;
$to = (string) $to;
$migrations = $this->configuration->getMigrations();
if (!isset($migrations[$to]) && $to > 0) {
throw new UnknownVersionException($to);
}
$direction = $from > $to ? 'down' : 'up';
$migrationsToExecute = $this->configuration->getMigrationsToExecute($direction, $to);
if ($from === $to && empty($migrationsToExecute) && $migrations) {
return;
}
$this->outputWriter->write(sprintf('Migrating <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>', $direction, $to, $from));
if (empty($migrationsToExecute)) {
throw new NoMigrationsToExecuteException('Could not find any migrations to execute.');
}
$time = 0;
foreach ($migrationsToExecute as $version) {
$version->execute($direction);
$time += $version->getTime();
}
$this->outputWriter->write("\n <comment>------------------------</comment>\n");
$this->outputWriter->write(sprintf(' <info>++</info> finished in %s', $time));
$this->outputWriter->write(sprintf(' <info>++</info> %s migrations executed', count($migrationsToExecute)));
}
|
[
"public",
"function",
"migrate",
"(",
"$",
"to",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"to",
")",
"{",
"$",
"to",
"=",
"$",
"this",
"->",
"configuration",
"->",
"getLatestVersion",
"(",
")",
";",
"}",
"$",
"from",
"=",
"$",
"this",
"->",
"configuration",
"->",
"getCurrentVersion",
"(",
")",
";",
"$",
"from",
"=",
"(",
"string",
")",
"$",
"from",
";",
"$",
"to",
"=",
"(",
"string",
")",
"$",
"to",
";",
"$",
"migrations",
"=",
"$",
"this",
"->",
"configuration",
"->",
"getMigrations",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"migrations",
"[",
"$",
"to",
"]",
")",
"&&",
"$",
"to",
">",
"0",
")",
"{",
"throw",
"new",
"UnknownVersionException",
"(",
"$",
"to",
")",
";",
"}",
"$",
"direction",
"=",
"$",
"from",
">",
"$",
"to",
"?",
"'down'",
":",
"'up'",
";",
"$",
"migrationsToExecute",
"=",
"$",
"this",
"->",
"configuration",
"->",
"getMigrationsToExecute",
"(",
"$",
"direction",
",",
"$",
"to",
")",
";",
"if",
"(",
"$",
"from",
"===",
"$",
"to",
"&&",
"empty",
"(",
"$",
"migrationsToExecute",
")",
"&&",
"$",
"migrations",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"sprintf",
"(",
"'Migrating <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>'",
",",
"$",
"direction",
",",
"$",
"to",
",",
"$",
"from",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"migrationsToExecute",
")",
")",
"{",
"throw",
"new",
"NoMigrationsToExecuteException",
"(",
"'Could not find any migrations to execute.'",
")",
";",
"}",
"$",
"time",
"=",
"0",
";",
"foreach",
"(",
"$",
"migrationsToExecute",
"as",
"$",
"version",
")",
"{",
"$",
"version",
"->",
"execute",
"(",
"$",
"direction",
")",
";",
"$",
"time",
"+=",
"$",
"version",
"->",
"getTime",
"(",
")",
";",
"}",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"\"\\n <comment>------------------------</comment>\\n\"",
")",
";",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"sprintf",
"(",
"' <info>++</info> finished in %s'",
",",
"$",
"time",
")",
")",
";",
"$",
"this",
"->",
"outputWriter",
"->",
"write",
"(",
"sprintf",
"(",
"' <info>++</info> %s migrations executed'",
",",
"count",
"(",
"$",
"migrationsToExecute",
")",
")",
")",
";",
"}"
] |
Run a migration to the current version or the given target version.
@param string $to The version to migrate to
@throws AntiMattr\MongoDB\Migrations\Exception\UnknownVersionException
@throws AntiMattr\MongoDB\Migrations\Exception\NoMigrationsToExecuteException
|
[
"Run",
"a",
"migration",
"to",
"the",
"current",
"version",
"or",
"the",
"given",
"target",
"version",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Migration.php#L54-L91
|
222,375
|
rezaei121/yii2-jcrop
|
src/Jcrop.php
|
Jcrop.registerTranslations
|
public static function registerTranslations()
{
if (!isset(Yii::$app->i18n->translations['jcrop']) && !isset(Yii::$app->i18n->translations['jcrop/*'])) {
Yii::$app->i18n->translations['jcrop'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@developit/jcrop/messages',
'forceTranslation' => true,
'fileMap' => [
'jcrop' => 'jcrop.php'
]
];
}
}
|
php
|
public static function registerTranslations()
{
if (!isset(Yii::$app->i18n->translations['jcrop']) && !isset(Yii::$app->i18n->translations['jcrop/*'])) {
Yii::$app->i18n->translations['jcrop'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@developit/jcrop/messages',
'forceTranslation' => true,
'fileMap' => [
'jcrop' => 'jcrop.php'
]
];
}
}
|
[
"public",
"static",
"function",
"registerTranslations",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"Yii",
"::",
"$",
"app",
"->",
"i18n",
"->",
"translations",
"[",
"'jcrop'",
"]",
")",
"&&",
"!",
"isset",
"(",
"Yii",
"::",
"$",
"app",
"->",
"i18n",
"->",
"translations",
"[",
"'jcrop/*'",
"]",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"i18n",
"->",
"translations",
"[",
"'jcrop'",
"]",
"=",
"[",
"'class'",
"=>",
"'yii\\i18n\\PhpMessageSource'",
",",
"'basePath'",
"=>",
"'@developit/jcrop/messages'",
",",
"'forceTranslation'",
"=>",
"true",
",",
"'fileMap'",
"=>",
"[",
"'jcrop'",
"=>",
"'jcrop.php'",
"]",
"]",
";",
"}",
"}"
] |
Register widget translations.
|
[
"Register",
"widget",
"translations",
"."
] |
06e1b7e1c0403b9b0161b1e1e40a4ba8b4f9bb2a
|
https://github.com/rezaei121/yii2-jcrop/blob/06e1b7e1c0403b9b0161b1e1e40a4ba8b4f9bb2a/src/Jcrop.php#L71-L83
|
222,376
|
ADmad/cakephp-tree
|
src/View/Helper/TreeHelper.php
|
TreeHelper._markUnrelatedAsHidden
|
protected function _markUnrelatedAsHidden(&$tree, array $path, $level = 0)
{
extract($this->_config);
$siblingIsActive = false;
foreach ($tree as $key => &$subTree) {
if (is_object($subTree)) {
$subTree = $subTree->toArray();
}
if (!isset($subTree['children'])) {
throw new Exception('Only works with threaded (nested children) results');
}
if (!empty($path[$level]) && $subTree['id'] == $path[$level]['id']) {
$subTree['show'] = 1;
$siblingIsActive = true;
}
if (!empty($subTree['show'])) {
foreach ($subTree['children'] as &$v) {
$v['parent_show'] = 1;
}
}
if (is_numeric($hideUnrelated) && $hideUnrelated > $level) {
$siblingIsActive = true;
}
}
foreach ($tree as $key => &$subTree) {
if ($level && !$siblingIsActive && !isset($subTree['parent_show'])) {
$subTree['hide'] = 1;
}
$this->_markUnrelatedAsHidden($subTree['children'], $path, $level + 1);
}
}
|
php
|
protected function _markUnrelatedAsHidden(&$tree, array $path, $level = 0)
{
extract($this->_config);
$siblingIsActive = false;
foreach ($tree as $key => &$subTree) {
if (is_object($subTree)) {
$subTree = $subTree->toArray();
}
if (!isset($subTree['children'])) {
throw new Exception('Only works with threaded (nested children) results');
}
if (!empty($path[$level]) && $subTree['id'] == $path[$level]['id']) {
$subTree['show'] = 1;
$siblingIsActive = true;
}
if (!empty($subTree['show'])) {
foreach ($subTree['children'] as &$v) {
$v['parent_show'] = 1;
}
}
if (is_numeric($hideUnrelated) && $hideUnrelated > $level) {
$siblingIsActive = true;
}
}
foreach ($tree as $key => &$subTree) {
if ($level && !$siblingIsActive && !isset($subTree['parent_show'])) {
$subTree['hide'] = 1;
}
$this->_markUnrelatedAsHidden($subTree['children'], $path, $level + 1);
}
}
|
[
"protected",
"function",
"_markUnrelatedAsHidden",
"(",
"&",
"$",
"tree",
",",
"array",
"$",
"path",
",",
"$",
"level",
"=",
"0",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"_config",
")",
";",
"$",
"siblingIsActive",
"=",
"false",
";",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"key",
"=>",
"&",
"$",
"subTree",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"subTree",
")",
")",
"{",
"$",
"subTree",
"=",
"$",
"subTree",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"subTree",
"[",
"'children'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Only works with threaded (nested children) results'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"path",
"[",
"$",
"level",
"]",
")",
"&&",
"$",
"subTree",
"[",
"'id'",
"]",
"==",
"$",
"path",
"[",
"$",
"level",
"]",
"[",
"'id'",
"]",
")",
"{",
"$",
"subTree",
"[",
"'show'",
"]",
"=",
"1",
";",
"$",
"siblingIsActive",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"subTree",
"[",
"'show'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"subTree",
"[",
"'children'",
"]",
"as",
"&",
"$",
"v",
")",
"{",
"$",
"v",
"[",
"'parent_show'",
"]",
"=",
"1",
";",
"}",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"hideUnrelated",
")",
"&&",
"$",
"hideUnrelated",
">",
"$",
"level",
")",
"{",
"$",
"siblingIsActive",
"=",
"true",
";",
"}",
"}",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"key",
"=>",
"&",
"$",
"subTree",
")",
"{",
"if",
"(",
"$",
"level",
"&&",
"!",
"$",
"siblingIsActive",
"&&",
"!",
"isset",
"(",
"$",
"subTree",
"[",
"'parent_show'",
"]",
")",
")",
"{",
"$",
"subTree",
"[",
"'hide'",
"]",
"=",
"1",
";",
"}",
"$",
"this",
"->",
"_markUnrelatedAsHidden",
"(",
"$",
"subTree",
"[",
"'children'",
"]",
",",
"$",
"path",
",",
"$",
"level",
"+",
"1",
")",
";",
"}",
"}"
] |
Mark unrelated records as hidden using `'hide' => 1`.
In the callback or element you can then return early in this case.
@param array $tree Tree
@param array $path Tree path
@param int $level Level
@return void
@throws \Exception
|
[
"Mark",
"unrelated",
"records",
"as",
"hidden",
"using",
"hide",
"=",
">",
"1",
".",
"In",
"the",
"callback",
"or",
"element",
"you",
"can",
"then",
"return",
"early",
"in",
"this",
"case",
"."
] |
df6575d0c2134291441f6e487ae9126f9c678243
|
https://github.com/ADmad/cakephp-tree/blob/df6575d0c2134291441f6e487ae9126f9c678243/src/View/Helper/TreeHelper.php#L520-L551
|
222,377
|
wandersonwhcr/romans
|
src/Filter/RomanToInt.php
|
RomanToInt.filter
|
public function filter(string $value) : int
{
return $this->getParser()->parse($this->getLexer()->tokenize($value));
}
|
php
|
public function filter(string $value) : int
{
return $this->getParser()->parse($this->getLexer()->tokenize($value));
}
|
[
"public",
"function",
"filter",
"(",
"string",
"$",
"value",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"getParser",
"(",
")",
"->",
"parse",
"(",
"$",
"this",
"->",
"getLexer",
"(",
")",
"->",
"tokenize",
"(",
"$",
"value",
")",
")",
";",
"}"
] |
Filter Roman Number to Integer
@param string $value Roman Number
@return int Integer Result
|
[
"Filter",
"Roman",
"Number",
"to",
"Integer"
] |
cb076a6371abc6627a261157b856effc77784320
|
https://github.com/wandersonwhcr/romans/blob/cb076a6371abc6627a261157b856effc77784320/src/Filter/RomanToInt.php#L92-L95
|
222,378
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.formatVersion
|
public static function formatVersion($version)
{
return sprintf('%s-%s-%s %s:%s:%s',
substr($version, 0, 4),
substr($version, 4, 2),
substr($version, 6, 2),
substr($version, 8, 2),
substr($version, 10, 2),
substr($version, 12, 2)
);
}
|
php
|
public static function formatVersion($version)
{
return sprintf('%s-%s-%s %s:%s:%s',
substr($version, 0, 4),
substr($version, 4, 2),
substr($version, 6, 2),
substr($version, 8, 2),
substr($version, 10, 2),
substr($version, 12, 2)
);
}
|
[
"public",
"static",
"function",
"formatVersion",
"(",
"$",
"version",
")",
"{",
"return",
"sprintf",
"(",
"'%s-%s-%s %s:%s:%s'",
",",
"substr",
"(",
"$",
"version",
",",
"0",
",",
"4",
")",
",",
"substr",
"(",
"$",
"version",
",",
"4",
",",
"2",
")",
",",
"substr",
"(",
"$",
"version",
",",
"6",
",",
"2",
")",
",",
"substr",
"(",
"$",
"version",
",",
"8",
",",
"2",
")",
",",
"substr",
"(",
"$",
"version",
",",
"10",
",",
"2",
")",
",",
"substr",
"(",
"$",
"version",
",",
"12",
",",
"2",
")",
")",
";",
"}"
] |
Returns a timestamp version as a formatted date.
@param string $version
@return string The formatted version
|
[
"Returns",
"a",
"timestamp",
"version",
"as",
"a",
"formatted",
"date",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L131-L141
|
222,379
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.getAvailableVersions
|
public function getAvailableVersions()
{
$availableVersions = [];
foreach ($this->migrations as $migration) {
$availableVersions[] = $migration->getVersion();
}
return $availableVersions;
}
|
php
|
public function getAvailableVersions()
{
$availableVersions = [];
foreach ($this->migrations as $migration) {
$availableVersions[] = $migration->getVersion();
}
return $availableVersions;
}
|
[
"public",
"function",
"getAvailableVersions",
"(",
")",
"{",
"$",
"availableVersions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"migrations",
"as",
"$",
"migration",
")",
"{",
"$",
"availableVersions",
"[",
"]",
"=",
"$",
"migration",
"->",
"getVersion",
"(",
")",
";",
"}",
"return",
"$",
"availableVersions",
";",
"}"
] |
Returns an array of available migration version numbers.
@return array
|
[
"Returns",
"an",
"array",
"of",
"available",
"migration",
"version",
"numbers",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L148-L156
|
222,380
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.getMigratedVersions
|
public function getMigratedVersions()
{
$this->createMigrationCollection();
$cursor = $this->getCollection()->find();
$versions = [];
foreach ($cursor as $record) {
$versions[] = $record['v'];
}
return $versions;
}
|
php
|
public function getMigratedVersions()
{
$this->createMigrationCollection();
$cursor = $this->getCollection()->find();
$versions = [];
foreach ($cursor as $record) {
$versions[] = $record['v'];
}
return $versions;
}
|
[
"public",
"function",
"getMigratedVersions",
"(",
")",
"{",
"$",
"this",
"->",
"createMigrationCollection",
"(",
")",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"getCollection",
"(",
")",
"->",
"find",
"(",
")",
";",
"$",
"versions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"cursor",
"as",
"$",
"record",
")",
"{",
"$",
"versions",
"[",
"]",
"=",
"$",
"record",
"[",
"'v'",
"]",
";",
"}",
"return",
"$",
"versions",
";",
"}"
] |
Returns all migrated versions from the versions collection, in an array.
@return \AntiMattr\MongoDB\Migrations\Version[]
|
[
"Returns",
"all",
"migrated",
"versions",
"from",
"the",
"versions",
"collection",
"in",
"an",
"array",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L319-L330
|
222,381
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.getMigratedTimestamp
|
public function getMigratedTimestamp($version): int
{
$this->createMigrationCollection();
$cursor = $this->getCollection()->find(
['v' => $version]
);
if (!$cursor->count()) {
throw new UnknownVersionException($version);
}
if ($cursor->count() > 1) {
throw new \DomainException(
'Unexpected duplicate version records in the database'
);
}
$returnVersion = $cursor->getNext();
// Convert to normalised timestamp
$ts = new Timestamp($returnVersion['t']);
return $ts->getTimestamp();
}
|
php
|
public function getMigratedTimestamp($version): int
{
$this->createMigrationCollection();
$cursor = $this->getCollection()->find(
['v' => $version]
);
if (!$cursor->count()) {
throw new UnknownVersionException($version);
}
if ($cursor->count() > 1) {
throw new \DomainException(
'Unexpected duplicate version records in the database'
);
}
$returnVersion = $cursor->getNext();
// Convert to normalised timestamp
$ts = new Timestamp($returnVersion['t']);
return $ts->getTimestamp();
}
|
[
"public",
"function",
"getMigratedTimestamp",
"(",
"$",
"version",
")",
":",
"int",
"{",
"$",
"this",
"->",
"createMigrationCollection",
"(",
")",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"getCollection",
"(",
")",
"->",
"find",
"(",
"[",
"'v'",
"=>",
"$",
"version",
"]",
")",
";",
"if",
"(",
"!",
"$",
"cursor",
"->",
"count",
"(",
")",
")",
"{",
"throw",
"new",
"UnknownVersionException",
"(",
"$",
"version",
")",
";",
"}",
"if",
"(",
"$",
"cursor",
"->",
"count",
"(",
")",
">",
"1",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Unexpected duplicate version records in the database'",
")",
";",
"}",
"$",
"returnVersion",
"=",
"$",
"cursor",
"->",
"getNext",
"(",
")",
";",
"// Convert to normalised timestamp",
"$",
"ts",
"=",
"new",
"Timestamp",
"(",
"$",
"returnVersion",
"[",
"'t'",
"]",
")",
";",
"return",
"$",
"ts",
"->",
"getTimestamp",
"(",
")",
";",
"}"
] |
Returns the time a migration occurred.
@param string $version
@return int
@throws AntiMattr\MongoDB\Migrations\Exception\UnknownVersionException Throws exception if migration version does not exist
@throws DomainException If more than one version exists
|
[
"Returns",
"the",
"time",
"a",
"migration",
"occurred",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L342-L366
|
222,382
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.registerMigration
|
public function registerMigration($version, $class)
{
$version = (string) $version;
$class = (string) $class;
if (isset($this->migrations[$version])) {
$message = sprintf(
'Migration version %s already registered with class %s',
$version,
get_class($this->migrations[$version])
);
throw new DuplicateVersionException($message);
}
$version = new Version($this, $version, $class);
$this->migrations[$version->getVersion()] = $version;
ksort($this->migrations);
return $version;
}
|
php
|
public function registerMigration($version, $class)
{
$version = (string) $version;
$class = (string) $class;
if (isset($this->migrations[$version])) {
$message = sprintf(
'Migration version %s already registered with class %s',
$version,
get_class($this->migrations[$version])
);
throw new DuplicateVersionException($message);
}
$version = new Version($this, $version, $class);
$this->migrations[$version->getVersion()] = $version;
ksort($this->migrations);
return $version;
}
|
[
"public",
"function",
"registerMigration",
"(",
"$",
"version",
",",
"$",
"class",
")",
"{",
"$",
"version",
"=",
"(",
"string",
")",
"$",
"version",
";",
"$",
"class",
"=",
"(",
"string",
")",
"$",
"class",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"migrations",
"[",
"$",
"version",
"]",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Migration version %s already registered with class %s'",
",",
"$",
"version",
",",
"get_class",
"(",
"$",
"this",
"->",
"migrations",
"[",
"$",
"version",
"]",
")",
")",
";",
"throw",
"new",
"DuplicateVersionException",
"(",
"$",
"message",
")",
";",
"}",
"$",
"version",
"=",
"new",
"Version",
"(",
"$",
"this",
",",
"$",
"version",
",",
"$",
"class",
")",
";",
"$",
"this",
"->",
"migrations",
"[",
"$",
"version",
"->",
"getVersion",
"(",
")",
"]",
"=",
"$",
"version",
";",
"ksort",
"(",
"$",
"this",
"->",
"migrations",
")",
";",
"return",
"$",
"version",
";",
"}"
] |
Register a single migration version to be executed by a AbstractMigration
class.
@param string $version The version of the migration in the format YYYYMMDDHHMMSS
@param string $class The migration class to execute for the version
@return Version
@throws AntiMattr\MongoDB\Migrations\Exception\DuplicateVersionException
|
[
"Register",
"a",
"single",
"migration",
"version",
"to",
"be",
"executed",
"by",
"a",
"AbstractMigration",
"class",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L435-L452
|
222,383
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.registerMigrations
|
public function registerMigrations(array $migrations)
{
$versions = [];
foreach ($migrations as $version => $class) {
$versions[] = $this->registerMigration($version, $class);
}
return $versions;
}
|
php
|
public function registerMigrations(array $migrations)
{
$versions = [];
foreach ($migrations as $version => $class) {
$versions[] = $this->registerMigration($version, $class);
}
return $versions;
}
|
[
"public",
"function",
"registerMigrations",
"(",
"array",
"$",
"migrations",
")",
"{",
"$",
"versions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"migrations",
"as",
"$",
"version",
"=>",
"$",
"class",
")",
"{",
"$",
"versions",
"[",
"]",
"=",
"$",
"this",
"->",
"registerMigration",
"(",
"$",
"version",
",",
"$",
"class",
")",
";",
"}",
"return",
"$",
"versions",
";",
"}"
] |
Register an array of migrations. Each key of the array is the version and
the value is the migration class name.
@param array $migrations
@return Version[]
|
[
"Register",
"an",
"array",
"of",
"migrations",
".",
"Each",
"key",
"of",
"the",
"array",
"is",
"the",
"version",
"and",
"the",
"value",
"is",
"the",
"migration",
"class",
"name",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L463-L471
|
222,384
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.registerMigrationsFromDirectory
|
public function registerMigrationsFromDirectory($path)
{
$path = realpath($path);
$path = rtrim($path, '/');
$files = glob($path . '/Version*.php');
$versions = [];
if ($files) {
foreach ($files as $file) {
require_once $file;
$info = pathinfo($file);
$version = substr($info['filename'], 7);
$class = $this->migrationsNamespace . '\\' . $info['filename'];
$versions[] = $this->registerMigration($version, $class);
}
}
return $versions;
}
|
php
|
public function registerMigrationsFromDirectory($path)
{
$path = realpath($path);
$path = rtrim($path, '/');
$files = glob($path . '/Version*.php');
$versions = [];
if ($files) {
foreach ($files as $file) {
require_once $file;
$info = pathinfo($file);
$version = substr($info['filename'], 7);
$class = $this->migrationsNamespace . '\\' . $info['filename'];
$versions[] = $this->registerMigration($version, $class);
}
}
return $versions;
}
|
[
"public",
"function",
"registerMigrationsFromDirectory",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"$",
"files",
"=",
"glob",
"(",
"$",
"path",
".",
"'/Version*.php'",
")",
";",
"$",
"versions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"files",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"require_once",
"$",
"file",
";",
"$",
"info",
"=",
"pathinfo",
"(",
"$",
"file",
")",
";",
"$",
"version",
"=",
"substr",
"(",
"$",
"info",
"[",
"'filename'",
"]",
",",
"7",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"migrationsNamespace",
".",
"'\\\\'",
".",
"$",
"info",
"[",
"'filename'",
"]",
";",
"$",
"versions",
"[",
"]",
"=",
"$",
"this",
"->",
"registerMigration",
"(",
"$",
"version",
",",
"$",
"class",
")",
";",
"}",
"}",
"return",
"$",
"versions",
";",
"}"
] |
Register migrations from a given directory. Recursively finds all files
with the pattern VersionYYYYMMDDHHMMSS.php as the filename and registers
them as migrations.
@param string $path The root directory to where some migration classes live
@return Version[] The array of migrations registered
|
[
"Register",
"migrations",
"from",
"a",
"given",
"directory",
".",
"Recursively",
"finds",
"all",
"files",
"with",
"the",
"pattern",
"VersionYYYYMMDDHHMMSS",
".",
"php",
"as",
"the",
"filename",
"and",
"registers",
"them",
"as",
"migrations",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L482-L499
|
222,385
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.getVersion
|
public function getVersion($version)
{
if (!isset($this->migrations[$version])) {
throw new UnknownVersionException($version);
}
return $this->migrations[$version];
}
|
php
|
public function getVersion($version)
{
if (!isset($this->migrations[$version])) {
throw new UnknownVersionException($version);
}
return $this->migrations[$version];
}
|
[
"public",
"function",
"getVersion",
"(",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"migrations",
"[",
"$",
"version",
"]",
")",
")",
"{",
"throw",
"new",
"UnknownVersionException",
"(",
"$",
"version",
")",
";",
"}",
"return",
"$",
"this",
"->",
"migrations",
"[",
"$",
"version",
"]",
";",
"}"
] |
Returns the Version instance for a given version in the format YYYYMMDDHHMMSS.
@param string $version The version string in the format YYYYMMDDHHMMSS
@return \AntiMattr\MongoDB\Migrations\Version
@throws AntiMattr\MongoDB\Migrations\Exception\UnknownVersionException Throws exception if migration version does not exist
|
[
"Returns",
"the",
"Version",
"instance",
"for",
"a",
"given",
"version",
"in",
"the",
"format",
"YYYYMMDDHHMMSS",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L510-L517
|
222,386
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.hasVersionMigrated
|
public function hasVersionMigrated(Version $version)
{
$this->createMigrationCollection();
$record = $this->getCollection()->findOne(['v' => $version->getVersion()]);
return null !== $record;
}
|
php
|
public function hasVersionMigrated(Version $version)
{
$this->createMigrationCollection();
$record = $this->getCollection()->findOne(['v' => $version->getVersion()]);
return null !== $record;
}
|
[
"public",
"function",
"hasVersionMigrated",
"(",
"Version",
"$",
"version",
")",
"{",
"$",
"this",
"->",
"createMigrationCollection",
"(",
")",
";",
"$",
"record",
"=",
"$",
"this",
"->",
"getCollection",
"(",
")",
"->",
"findOne",
"(",
"[",
"'v'",
"=>",
"$",
"version",
"->",
"getVersion",
"(",
")",
"]",
")",
";",
"return",
"null",
"!==",
"$",
"record",
";",
"}"
] |
Check if a version has been migrated or not yet.
@param \AntiMattr\MongoDB\Migrations\Version $version
@return bool
|
[
"Check",
"if",
"a",
"version",
"has",
"been",
"migrated",
"or",
"not",
"yet",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L538-L545
|
222,387
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.createMigrationCollection
|
public function createMigrationCollection()
{
$this->validate();
if (true !== $this->migrationCollectionCreated) {
$collection = $this->getCollection();
$collection->ensureIndex(['v' => -1], ['name' => 'version', 'unique' => true]);
$this->migrationCollectionCreated = true;
}
return true;
}
|
php
|
public function createMigrationCollection()
{
$this->validate();
if (true !== $this->migrationCollectionCreated) {
$collection = $this->getCollection();
$collection->ensureIndex(['v' => -1], ['name' => 'version', 'unique' => true]);
$this->migrationCollectionCreated = true;
}
return true;
}
|
[
"public",
"function",
"createMigrationCollection",
"(",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"if",
"(",
"true",
"!==",
"$",
"this",
"->",
"migrationCollectionCreated",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"getCollection",
"(",
")",
";",
"$",
"collection",
"->",
"ensureIndex",
"(",
"[",
"'v'",
"=>",
"-",
"1",
"]",
",",
"[",
"'name'",
"=>",
"'version'",
",",
"'unique'",
"=>",
"true",
"]",
")",
";",
"$",
"this",
"->",
"migrationCollectionCreated",
"=",
"true",
";",
"}",
"return",
"true",
";",
"}"
] |
Create the migration collection to track migrations with.
@return bool Whether or not the collection was created
|
[
"Create",
"the",
"migration",
"collection",
"to",
"track",
"migrations",
"with",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L595-L606
|
222,388
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.getMigrationsToExecute
|
public function getMigrationsToExecute($direction, $to)
{
if ('down' === $direction) {
if (count($this->migrations)) {
$allVersions = array_reverse(array_keys($this->migrations));
$classes = array_reverse(array_values($this->migrations));
$allVersions = array_combine($allVersions, $classes);
} else {
$allVersions = [];
}
} else {
$allVersions = $this->migrations;
}
$versions = [];
$migrated = $this->getMigratedVersions();
foreach ($allVersions as $version) {
if ($this->shouldExecuteMigration($direction, $version, $to, $migrated)) {
$versions[$version->getVersion()] = $version;
}
}
return $versions;
}
|
php
|
public function getMigrationsToExecute($direction, $to)
{
if ('down' === $direction) {
if (count($this->migrations)) {
$allVersions = array_reverse(array_keys($this->migrations));
$classes = array_reverse(array_values($this->migrations));
$allVersions = array_combine($allVersions, $classes);
} else {
$allVersions = [];
}
} else {
$allVersions = $this->migrations;
}
$versions = [];
$migrated = $this->getMigratedVersions();
foreach ($allVersions as $version) {
if ($this->shouldExecuteMigration($direction, $version, $to, $migrated)) {
$versions[$version->getVersion()] = $version;
}
}
return $versions;
}
|
[
"public",
"function",
"getMigrationsToExecute",
"(",
"$",
"direction",
",",
"$",
"to",
")",
"{",
"if",
"(",
"'down'",
"===",
"$",
"direction",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"migrations",
")",
")",
"{",
"$",
"allVersions",
"=",
"array_reverse",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"migrations",
")",
")",
";",
"$",
"classes",
"=",
"array_reverse",
"(",
"array_values",
"(",
"$",
"this",
"->",
"migrations",
")",
")",
";",
"$",
"allVersions",
"=",
"array_combine",
"(",
"$",
"allVersions",
",",
"$",
"classes",
")",
";",
"}",
"else",
"{",
"$",
"allVersions",
"=",
"[",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"allVersions",
"=",
"$",
"this",
"->",
"migrations",
";",
"}",
"$",
"versions",
"=",
"[",
"]",
";",
"$",
"migrated",
"=",
"$",
"this",
"->",
"getMigratedVersions",
"(",
")",
";",
"foreach",
"(",
"$",
"allVersions",
"as",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldExecuteMigration",
"(",
"$",
"direction",
",",
"$",
"version",
",",
"$",
"to",
",",
"$",
"migrated",
")",
")",
"{",
"$",
"versions",
"[",
"$",
"version",
"->",
"getVersion",
"(",
")",
"]",
"=",
"$",
"version",
";",
"}",
"}",
"return",
"$",
"versions",
";",
"}"
] |
Returns the array of migrations to executed based on the given direction
and target version number.
@param string $direction The direction we are migrating
@param string $to The version to migrate to
@return Version[] $migrations The array of migrations we can execute
|
[
"Returns",
"the",
"array",
"of",
"migrations",
"to",
"executed",
"based",
"on",
"the",
"given",
"direction",
"and",
"target",
"version",
"number",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L617-L639
|
222,389
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.shouldExecuteMigration
|
private function shouldExecuteMigration($direction, Version $version, $to, $migrated)
{
if ('down' === $direction) {
if (!in_array($version->getVersion(), $migrated)) {
return false;
}
return $version->getVersion() > $to;
}
if ('up' === $direction) {
if (in_array($version->getVersion(), $migrated)) {
return false;
}
return $version->getVersion() <= $to;
}
}
|
php
|
private function shouldExecuteMigration($direction, Version $version, $to, $migrated)
{
if ('down' === $direction) {
if (!in_array($version->getVersion(), $migrated)) {
return false;
}
return $version->getVersion() > $to;
}
if ('up' === $direction) {
if (in_array($version->getVersion(), $migrated)) {
return false;
}
return $version->getVersion() <= $to;
}
}
|
[
"private",
"function",
"shouldExecuteMigration",
"(",
"$",
"direction",
",",
"Version",
"$",
"version",
",",
"$",
"to",
",",
"$",
"migrated",
")",
"{",
"if",
"(",
"'down'",
"===",
"$",
"direction",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"version",
"->",
"getVersion",
"(",
")",
",",
"$",
"migrated",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"version",
"->",
"getVersion",
"(",
")",
">",
"$",
"to",
";",
"}",
"if",
"(",
"'up'",
"===",
"$",
"direction",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"version",
"->",
"getVersion",
"(",
")",
",",
"$",
"migrated",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"version",
"->",
"getVersion",
"(",
")",
"<=",
"$",
"to",
";",
"}",
"}"
] |
Check if we should execute a migration for a given direction and target
migration version.
@param string $direction The direction we are migrating
@param Version $version The Version instance to check
@param string $to The version we are migrating to
@param array $migrated Migrated versions array
@return bool
|
[
"Check",
"if",
"we",
"should",
"execute",
"a",
"migration",
"for",
"a",
"given",
"direction",
"and",
"target",
"migration",
"version",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L652-L669
|
222,390
|
doesntmattr/mongodb-migrations
|
src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
|
Configuration.validate
|
public function validate()
{
if (!$this->migrationsDatabaseName) {
$message = 'Migrations Database Name must be configured in order to use AntiMattr migrations.';
throw new ConfigurationValidationException($message);
}
if (!$this->migrationsNamespace) {
$message = 'Migrations namespace must be configured in order to use AntiMattr migrations.';
throw new ConfigurationValidationException($message);
}
if (!$this->migrationsDirectory) {
$message = 'Migrations directory must be configured in order to use AntiMattr migrations.';
throw new ConfigurationValidationException($message);
}
}
|
php
|
public function validate()
{
if (!$this->migrationsDatabaseName) {
$message = 'Migrations Database Name must be configured in order to use AntiMattr migrations.';
throw new ConfigurationValidationException($message);
}
if (!$this->migrationsNamespace) {
$message = 'Migrations namespace must be configured in order to use AntiMattr migrations.';
throw new ConfigurationValidationException($message);
}
if (!$this->migrationsDirectory) {
$message = 'Migrations directory must be configured in order to use AntiMattr migrations.';
throw new ConfigurationValidationException($message);
}
}
|
[
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"migrationsDatabaseName",
")",
"{",
"$",
"message",
"=",
"'Migrations Database Name must be configured in order to use AntiMattr migrations.'",
";",
"throw",
"new",
"ConfigurationValidationException",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"migrationsNamespace",
")",
"{",
"$",
"message",
"=",
"'Migrations namespace must be configured in order to use AntiMattr migrations.'",
";",
"throw",
"new",
"ConfigurationValidationException",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"migrationsDirectory",
")",
"{",
"$",
"message",
"=",
"'Migrations directory must be configured in order to use AntiMattr migrations.'",
";",
"throw",
"new",
"ConfigurationValidationException",
"(",
"$",
"message",
")",
";",
"}",
"}"
] |
Validation that this instance has all the required properties configured.
@throws AntiMattr\MongoDB\Migrations\Exception\ConfigurationValidationException
|
[
"Validation",
"that",
"this",
"instance",
"has",
"all",
"the",
"required",
"properties",
"configured",
"."
] |
19ba9f04c1c346c6e17882840c209cfc4b000b93
|
https://github.com/doesntmattr/mongodb-migrations/blob/19ba9f04c1c346c6e17882840c209cfc4b000b93/src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php#L676-L690
|
222,391
|
php-soft/laravel-users
|
packages/Users/Controllers/RoleController.php
|
RoleController.store
|
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255|unique:roles',
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
$role = Role::create($request->all());
return response()->json(arrayView('phpsoft.users::role/read', [
'role' => $role
]), 201);
}
|
php
|
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255|unique:roles',
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
$role = Role::create($request->all());
return response()->json(arrayView('phpsoft.users::role/read', [
'role' => $role
]), 201);
}
|
[
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"[",
"'name'",
"=>",
"'required|string|max:255|unique:roles'",
",",
"'display_name'",
"=>",
"'string|max:255'",
",",
"'description'",
"=>",
"'max:1000'",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::errors/validation'",
",",
"[",
"'errors'",
"=>",
"$",
"validator",
"->",
"errors",
"(",
")",
"]",
")",
",",
"400",
")",
";",
"}",
"$",
"role",
"=",
"Role",
"::",
"create",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::role/read'",
",",
"[",
"'role'",
"=>",
"$",
"role",
"]",
")",
",",
"201",
")",
";",
"}"
] |
Create role action
@param Request $request
@return Response
|
[
"Create",
"role",
"action"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Controllers/RoleController.php#L17-L36
|
222,392
|
php-soft/laravel-users
|
packages/Users/Controllers/RoleController.php
|
RoleController.update
|
public function update(Request $request, $id = null)
{
// validate data
$validator = Validator::make($request->all(), [
'name' => 'sometimes|required|string|max:255|unique:roles,name,'.$id,
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
// check role
$role = Role::find($id);
if (!$role) {
return response()->json(null, 404);
}
// update role
$updateRole = $role->update($request->all());
if (!$updateRole) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(arrayView('phpsoft.users::role/read', [
'role' => $role
]), 200);
}
|
php
|
public function update(Request $request, $id = null)
{
// validate data
$validator = Validator::make($request->all(), [
'name' => 'sometimes|required|string|max:255|unique:roles,name,'.$id,
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
// check role
$role = Role::find($id);
if (!$role) {
return response()->json(null, 404);
}
// update role
$updateRole = $role->update($request->all());
if (!$updateRole) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(arrayView('phpsoft.users::role/read', [
'role' => $role
]), 200);
}
|
[
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
"=",
"null",
")",
"{",
"// validate data",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"[",
"'name'",
"=>",
"'sometimes|required|string|max:255|unique:roles,name,'",
".",
"$",
"id",
",",
"'display_name'",
"=>",
"'string|max:255'",
",",
"'description'",
"=>",
"'max:1000'",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::errors/validation'",
",",
"[",
"'errors'",
"=>",
"$",
"validator",
"->",
"errors",
"(",
")",
"]",
")",
",",
"400",
")",
";",
"}",
"// check role",
"$",
"role",
"=",
"Role",
"::",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"role",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"404",
")",
";",
"}",
"// update role",
"$",
"updateRole",
"=",
"$",
"role",
"->",
"update",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"updateRole",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"500",
")",
";",
"// @codeCoverageIgnore",
"}",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::role/read'",
",",
"[",
"'role'",
"=>",
"$",
"role",
"]",
")",
",",
"200",
")",
";",
"}"
] |
Update role action
@param Request $request
@return Response
|
[
"Update",
"role",
"action"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Controllers/RoleController.php#L43-L75
|
222,393
|
php-soft/laravel-users
|
packages/Users/Controllers/UserController.php
|
UserController.store
|
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|string|confirmed|min:6',
'username' => 'string|max:30',
'country' => 'string|max:100',
'location' => 'string|max:100',
'biography' => 'string|max:255',
'occupation' => 'string|max:255',
'website' => 'string|max:255',
'image' => 'string|max:255',
'gender' => 'integer',
'birthday' => 'date'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
$user = AppUser::create($request->all());
return response()->json(arrayView('phpsoft.users::user/read', [
'user' => $user
]), 201);
}
|
php
|
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|string|confirmed|min:6',
'username' => 'string|max:30',
'country' => 'string|max:100',
'location' => 'string|max:100',
'biography' => 'string|max:255',
'occupation' => 'string|max:255',
'website' => 'string|max:255',
'image' => 'string|max:255',
'gender' => 'integer',
'birthday' => 'date'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
$user = AppUser::create($request->all());
return response()->json(arrayView('phpsoft.users::user/read', [
'user' => $user
]), 201);
}
|
[
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"[",
"'name'",
"=>",
"'required|string|max:255'",
",",
"'email'",
"=>",
"'required|email|max:255|unique:users'",
",",
"'password'",
"=>",
"'required|string|confirmed|min:6'",
",",
"'username'",
"=>",
"'string|max:30'",
",",
"'country'",
"=>",
"'string|max:100'",
",",
"'location'",
"=>",
"'string|max:100'",
",",
"'biography'",
"=>",
"'string|max:255'",
",",
"'occupation'",
"=>",
"'string|max:255'",
",",
"'website'",
"=>",
"'string|max:255'",
",",
"'image'",
"=>",
"'string|max:255'",
",",
"'gender'",
"=>",
"'integer'",
",",
"'birthday'",
"=>",
"'date'",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::errors/validation'",
",",
"[",
"'errors'",
"=>",
"$",
"validator",
"->",
"errors",
"(",
")",
"]",
")",
",",
"400",
")",
";",
"}",
"$",
"user",
"=",
"AppUser",
"::",
"create",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::user/read'",
",",
"[",
"'user'",
"=>",
"$",
"user",
"]",
")",
",",
"201",
")",
";",
"}"
] |
Create user action
@param Request $request
@return Response
|
[
"Create",
"user",
"action"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Controllers/UserController.php#L65-L93
|
222,394
|
php-soft/laravel-users
|
packages/Users/Controllers/UserController.php
|
UserController.update
|
public function update(Request $request, $id = null)
{
// validate
$this->registerValidators();
// check auth if update me
if (!$id && !$this->checkAuth()) {
return response()->json(null, 401);
}
// check user
$user = $id ? AppUser::find($id) : Auth::user();
if (!$user) {
return response()->json(null, 404);
}
$request->id = $id;
// validate data
$validator = Validator::make($request->all(), [
'name' => 'sometimes|required|max:255',
'email' => 'sometimes|required|email|max:255|unique:users,email,'.$user->id,
'old_password' => 'sometimes|required|changePassword|min:6',
'password' => 'sometimes|required|changePassword|confirmed|min:6',
'username' => 'string|max:30',
'country' => 'string|max:100',
'location' => 'string|max:100',
'biography' => 'string|max:255',
'occupation' => 'string|max:255',
'website' => 'string|max:255',
'image' => 'string|max:255',
'gender' => 'integer',
'birthday' => 'date'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
// Update profile
$user = $user->update($request->all());
if (!$user) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(arrayView('phpsoft.users::user/read', [
'user' => $user
]), 200);
}
|
php
|
public function update(Request $request, $id = null)
{
// validate
$this->registerValidators();
// check auth if update me
if (!$id && !$this->checkAuth()) {
return response()->json(null, 401);
}
// check user
$user = $id ? AppUser::find($id) : Auth::user();
if (!$user) {
return response()->json(null, 404);
}
$request->id = $id;
// validate data
$validator = Validator::make($request->all(), [
'name' => 'sometimes|required|max:255',
'email' => 'sometimes|required|email|max:255|unique:users,email,'.$user->id,
'old_password' => 'sometimes|required|changePassword|min:6',
'password' => 'sometimes|required|changePassword|confirmed|min:6',
'username' => 'string|max:30',
'country' => 'string|max:100',
'location' => 'string|max:100',
'biography' => 'string|max:255',
'occupation' => 'string|max:255',
'website' => 'string|max:255',
'image' => 'string|max:255',
'gender' => 'integer',
'birthday' => 'date'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
// Update profile
$user = $user->update($request->all());
if (!$user) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(arrayView('phpsoft.users::user/read', [
'user' => $user
]), 200);
}
|
[
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
"=",
"null",
")",
"{",
"// validate",
"$",
"this",
"->",
"registerValidators",
"(",
")",
";",
"// check auth if update me",
"if",
"(",
"!",
"$",
"id",
"&&",
"!",
"$",
"this",
"->",
"checkAuth",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"401",
")",
";",
"}",
"// check user",
"$",
"user",
"=",
"$",
"id",
"?",
"AppUser",
"::",
"find",
"(",
"$",
"id",
")",
":",
"Auth",
"::",
"user",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"404",
")",
";",
"}",
"$",
"request",
"->",
"id",
"=",
"$",
"id",
";",
"// validate data",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"[",
"'name'",
"=>",
"'sometimes|required|max:255'",
",",
"'email'",
"=>",
"'sometimes|required|email|max:255|unique:users,email,'",
".",
"$",
"user",
"->",
"id",
",",
"'old_password'",
"=>",
"'sometimes|required|changePassword|min:6'",
",",
"'password'",
"=>",
"'sometimes|required|changePassword|confirmed|min:6'",
",",
"'username'",
"=>",
"'string|max:30'",
",",
"'country'",
"=>",
"'string|max:100'",
",",
"'location'",
"=>",
"'string|max:100'",
",",
"'biography'",
"=>",
"'string|max:255'",
",",
"'occupation'",
"=>",
"'string|max:255'",
",",
"'website'",
"=>",
"'string|max:255'",
",",
"'image'",
"=>",
"'string|max:255'",
",",
"'gender'",
"=>",
"'integer'",
",",
"'birthday'",
"=>",
"'date'",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::errors/validation'",
",",
"[",
"'errors'",
"=>",
"$",
"validator",
"->",
"errors",
"(",
")",
"]",
")",
",",
"400",
")",
";",
"}",
"// Update profile",
"$",
"user",
"=",
"$",
"user",
"->",
"update",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"500",
")",
";",
"// @codeCoverageIgnore",
"}",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::user/read'",
",",
"[",
"'user'",
"=>",
"$",
"user",
"]",
")",
",",
"200",
")",
";",
"}"
] |
Update profile action
@param Request $request
@return Response
|
[
"Update",
"profile",
"action"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Controllers/UserController.php#L100-L151
|
222,395
|
php-soft/laravel-users
|
packages/Users/Controllers/UserController.php
|
UserController.moveToTrash
|
public function moveToTrash($id)
{
$user = AppUser::find($id);
if (!$user) {
return response()->json(null, 404);
}
if (!$user->delete()) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(null, 204);
}
|
php
|
public function moveToTrash($id)
{
$user = AppUser::find($id);
if (!$user) {
return response()->json(null, 404);
}
if (!$user->delete()) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(null, 204);
}
|
[
"public",
"function",
"moveToTrash",
"(",
"$",
"id",
")",
"{",
"$",
"user",
"=",
"AppUser",
"::",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"404",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"->",
"delete",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"500",
")",
";",
"// @codeCoverageIgnore",
"}",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"204",
")",
";",
"}"
] |
move user to trash
@param int $id
@return Response
|
[
"move",
"user",
"to",
"trash"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Controllers/UserController.php#L304-L317
|
222,396
|
php-soft/laravel-users
|
packages/Users/Controllers/PermissionController.php
|
PermissionController.store
|
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255|unique:permissions',
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
$permission = Permission::create($request->all());
return response()->json(arrayView('phpsoft.users::permission/read', [
'permission' => $permission
]), 201);
}
|
php
|
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255|unique:permissions',
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
$permission = Permission::create($request->all());
return response()->json(arrayView('phpsoft.users::permission/read', [
'permission' => $permission
]), 201);
}
|
[
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"[",
"'name'",
"=>",
"'required|string|max:255|unique:permissions'",
",",
"'display_name'",
"=>",
"'string|max:255'",
",",
"'description'",
"=>",
"'max:1000'",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::errors/validation'",
",",
"[",
"'errors'",
"=>",
"$",
"validator",
"->",
"errors",
"(",
")",
"]",
")",
",",
"400",
")",
";",
"}",
"$",
"permission",
"=",
"Permission",
"::",
"create",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::permission/read'",
",",
"[",
"'permission'",
"=>",
"$",
"permission",
"]",
")",
",",
"201",
")",
";",
"}"
] |
Create permission action
@param Request $request
@return Response
|
[
"Create",
"permission",
"action"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Controllers/PermissionController.php#L17-L36
|
222,397
|
php-soft/laravel-users
|
packages/Users/Controllers/PermissionController.php
|
PermissionController.update
|
public function update(Request $request, $id = null)
{
// validate data
$validator = Validator::make($request->all(), [
'name' => 'sometimes|required|string|max:255|unique:permissions,name,'.$id,
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
// check permission
$permission = Permission::find($id);
if (!$permission) {
return response()->json(null, 404);
}
// update permission
$updatePermission = $permission->update($request->all());
if (!$updatePermission) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(arrayView('phpsoft.users::permission/read', [
'permission' => $permission
]), 200);
}
|
php
|
public function update(Request $request, $id = null)
{
// validate data
$validator = Validator::make($request->all(), [
'name' => 'sometimes|required|string|max:255|unique:permissions,name,'.$id,
'display_name' => 'string|max:255',
'description' => 'max:1000'
]);
if ($validator->fails()) {
return response()->json(arrayView('phpsoft.users::errors/validation', [
'errors' => $validator->errors()
]), 400);
}
// check permission
$permission = Permission::find($id);
if (!$permission) {
return response()->json(null, 404);
}
// update permission
$updatePermission = $permission->update($request->all());
if (!$updatePermission) {
return response()->json(null, 500); // @codeCoverageIgnore
}
return response()->json(arrayView('phpsoft.users::permission/read', [
'permission' => $permission
]), 200);
}
|
[
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
"=",
"null",
")",
"{",
"// validate data",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"[",
"'name'",
"=>",
"'sometimes|required|string|max:255|unique:permissions,name,'",
".",
"$",
"id",
",",
"'display_name'",
"=>",
"'string|max:255'",
",",
"'description'",
"=>",
"'max:1000'",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::errors/validation'",
",",
"[",
"'errors'",
"=>",
"$",
"validator",
"->",
"errors",
"(",
")",
"]",
")",
",",
"400",
")",
";",
"}",
"// check permission",
"$",
"permission",
"=",
"Permission",
"::",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"permission",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"404",
")",
";",
"}",
"// update permission",
"$",
"updatePermission",
"=",
"$",
"permission",
"->",
"update",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"updatePermission",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"null",
",",
"500",
")",
";",
"// @codeCoverageIgnore",
"}",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"arrayView",
"(",
"'phpsoft.users::permission/read'",
",",
"[",
"'permission'",
"=>",
"$",
"permission",
"]",
")",
",",
"200",
")",
";",
"}"
] |
Update permission action
@param Request $request
@return Response
|
[
"Update",
"permission",
"action"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Controllers/PermissionController.php#L43-L75
|
222,398
|
php-soft/laravel-users
|
packages/Users/Models/Role.php
|
Role.browseByUser
|
public static function browseByUser($options = [])
{
$find = $options['user']->roles();
$total = $find->count();
if (!empty($options['order'])) {
foreach ($options['order'] as $field => $direction) {
$find = $find->orderBy($field, $direction);
}
}
if (!empty($options['offset'])) {
$find = $find->skip($options['offset']);
}
if (!empty($options['limit'])) {
$find = $find->take($options['limit']);
}
return [
'total' => $total,
'offset' => empty($options['offset']) ? 0 : $options['offset'],
'limit' => empty($options['limit']) ? 0 : $options['limit'],
'data' => $find->get(),
];
}
|
php
|
public static function browseByUser($options = [])
{
$find = $options['user']->roles();
$total = $find->count();
if (!empty($options['order'])) {
foreach ($options['order'] as $field => $direction) {
$find = $find->orderBy($field, $direction);
}
}
if (!empty($options['offset'])) {
$find = $find->skip($options['offset']);
}
if (!empty($options['limit'])) {
$find = $find->take($options['limit']);
}
return [
'total' => $total,
'offset' => empty($options['offset']) ? 0 : $options['offset'],
'limit' => empty($options['limit']) ? 0 : $options['limit'],
'data' => $find->get(),
];
}
|
[
"public",
"static",
"function",
"browseByUser",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"find",
"=",
"$",
"options",
"[",
"'user'",
"]",
"->",
"roles",
"(",
")",
";",
"$",
"total",
"=",
"$",
"find",
"->",
"count",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'order'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"[",
"'order'",
"]",
"as",
"$",
"field",
"=>",
"$",
"direction",
")",
"{",
"$",
"find",
"=",
"$",
"find",
"->",
"orderBy",
"(",
"$",
"field",
",",
"$",
"direction",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'offset'",
"]",
")",
")",
"{",
"$",
"find",
"=",
"$",
"find",
"->",
"skip",
"(",
"$",
"options",
"[",
"'offset'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"find",
"=",
"$",
"find",
"->",
"take",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
";",
"}",
"return",
"[",
"'total'",
"=>",
"$",
"total",
",",
"'offset'",
"=>",
"empty",
"(",
"$",
"options",
"[",
"'offset'",
"]",
")",
"?",
"0",
":",
"$",
"options",
"[",
"'offset'",
"]",
",",
"'limit'",
"=>",
"empty",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
"?",
"0",
":",
"$",
"options",
"[",
"'limit'",
"]",
",",
"'data'",
"=>",
"$",
"find",
"->",
"get",
"(",
")",
",",
"]",
";",
"}"
] |
get all role of user
@return role
|
[
"get",
"all",
"role",
"of",
"user"
] |
cd8d696dbf7337002188576d8a143cbc19d86b40
|
https://github.com/php-soft/laravel-users/blob/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/Models/Role.php#L84-L110
|
222,399
|
loveorigami/yii2-bootstrap-toggle
|
Toggle.php
|
Toggle.registerClientScript
|
public function registerClientScript()
{
$view = $this->view;
ToggleAsset::register($view);
//$this->clientOptions['animate'] = ArrayHelper::getValue($this->clientOptions, 'animate', true);
$options = Json::encode($this->options);
$js[] = "jQuery('$this->selector').bootstrapToggle($options);";
if (!empty($this->clientEvents)) {
foreach ($this->clientEvents as $event => $handler) {
$js[] = "jQuery('$this->selector').on('$event', $handler);";
}
}
$view->registerJs(implode("\n", $js));
}
|
php
|
public function registerClientScript()
{
$view = $this->view;
ToggleAsset::register($view);
//$this->clientOptions['animate'] = ArrayHelper::getValue($this->clientOptions, 'animate', true);
$options = Json::encode($this->options);
$js[] = "jQuery('$this->selector').bootstrapToggle($options);";
if (!empty($this->clientEvents)) {
foreach ($this->clientEvents as $event => $handler) {
$js[] = "jQuery('$this->selector').on('$event', $handler);";
}
}
$view->registerJs(implode("\n", $js));
}
|
[
"public",
"function",
"registerClientScript",
"(",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
";",
"ToggleAsset",
"::",
"register",
"(",
"$",
"view",
")",
";",
"//$this->clientOptions['animate'] = ArrayHelper::getValue($this->clientOptions, 'animate', true);",
"$",
"options",
"=",
"Json",
"::",
"encode",
"(",
"$",
"this",
"->",
"options",
")",
";",
"$",
"js",
"[",
"]",
"=",
"\"jQuery('$this->selector').bootstrapToggle($options);\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"clientEvents",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"clientEvents",
"as",
"$",
"event",
"=>",
"$",
"handler",
")",
"{",
"$",
"js",
"[",
"]",
"=",
"\"jQuery('$this->selector').on('$event', $handler);\"",
";",
"}",
"}",
"$",
"view",
"->",
"registerJs",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"js",
")",
")",
";",
"}"
] |
Registers Bootstrap Switch plugin and related events
|
[
"Registers",
"Bootstrap",
"Switch",
"plugin",
"and",
"related",
"events"
] |
a55c359b2b67ba79e2276c44a78b3a22101d18ca
|
https://github.com/loveorigami/yii2-bootstrap-toggle/blob/a55c359b2b67ba79e2276c44a78b3a22101d18ca/Toggle.php#L76-L89
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.