repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.saveSnippet | public function saveSnippet(
string $outputFile,
string $format = self::FORMAT_NGINX
): bool {
if ($this->needsCompile) {
$this->compile();
}
// Are we doing a report-only header?
$which = $this->reportOnly
? 'Content-Security-Policy-Report-Only'
: 'Content-Security-Policy';
switch ($format) {
case self::FORMAT_NGINX:
// In PHP < 7, implode() is faster than concatenation
$output = \implode('', [
'add_header ',
$which,
' "',
\rtrim($this->compiled, ' '),
'" always;',
"\n"
]);
break;
case self::FORMAT_APACHE:
$output = \implode('', [
'Header add ',
$which,
' "',
\rtrim($this->compiled, ' '),
'"',
"\n"
]);
break;
default:
throw new \Exception('Unknown format: '.$format);
}
return \file_put_contents($outputFile, $output) !== false;
} | php | public function saveSnippet(
string $outputFile,
string $format = self::FORMAT_NGINX
): bool {
if ($this->needsCompile) {
$this->compile();
}
// Are we doing a report-only header?
$which = $this->reportOnly
? 'Content-Security-Policy-Report-Only'
: 'Content-Security-Policy';
switch ($format) {
case self::FORMAT_NGINX:
// In PHP < 7, implode() is faster than concatenation
$output = \implode('', [
'add_header ',
$which,
' "',
\rtrim($this->compiled, ' '),
'" always;',
"\n"
]);
break;
case self::FORMAT_APACHE:
$output = \implode('', [
'Header add ',
$which,
' "',
\rtrim($this->compiled, ' '),
'"',
"\n"
]);
break;
default:
throw new \Exception('Unknown format: '.$format);
}
return \file_put_contents($outputFile, $output) !== false;
} | [
"public",
"function",
"saveSnippet",
"(",
"string",
"$",
"outputFile",
",",
"string",
"$",
"format",
"=",
"self",
"::",
"FORMAT_NGINX",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"needsCompile",
")",
"{",
"$",
"this",
"->",
"compile",
"(",
")... | Save CSP to a snippet file
@param string $outputFile Output file name
@param string $format Which format are we saving in?
@return bool
@throws \Exception | [
"Save",
"CSP",
"to",
"a",
"snippet",
"file"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L470-L509 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.setDirective | public function setDirective(string $key, $value = []): self
{
$this->policies[$key] = $value;
return $this;
} | php | public function setDirective(string $key, $value = []): self
{
$this->policies[$key] = $value;
return $this;
} | [
"public",
"function",
"setDirective",
"(",
"string",
"$",
"key",
",",
"$",
"value",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"this",
"->",
"policies",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set a directive.
This lets you overwrite a complex directive entirely (e.g. script-src)
or set a top-level directive (e.g. report-uri).
@param string $key
@param mixed $value
@return self | [
"Set",
"a",
"directive",
"."
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L616-L620 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.setStrictDynamic | public function setStrictDynamic(string $directive = '', bool $allow = false): self
{
$this->policies[$directive]['strict-dynamic'] = $allow;
return $this;
} | php | public function setStrictDynamic(string $directive = '', bool $allow = false): self
{
$this->policies[$directive]['strict-dynamic'] = $allow;
return $this;
} | [
"public",
"function",
"setStrictDynamic",
"(",
"string",
"$",
"directive",
"=",
"''",
",",
"bool",
"$",
"allow",
"=",
"false",
")",
":",
"self",
"{",
"$",
"this",
"->",
"policies",
"[",
"$",
"directive",
"]",
"[",
"'strict-dynamic'",
"]",
"=",
"$",
"al... | Set strict-dynamic for a given directive.
@param string $directive
@param bool $allow
@return self
@throws \Exception | [
"Set",
"strict",
"-",
"dynamic",
"for",
"a",
"given",
"directive",
"."
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L708-L712 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.getHeaderKeys | protected function getHeaderKeys(bool $legacy = true): array
{
// We always want this
$return = [
$this->reportOnly
? 'Content-Security-Policy-Report-Only'
: 'Content-Security-Policy'
];
// If we're supporting legacy devices, include these too:
if ($legacy) {
$return []= $this->reportOnly
? 'X-Content-Security-Policy-Report-Only'
: 'X-Content-Security-Policy';
$return []= $this->reportOnly
? 'X-Webkit-CSP-Report-Only'
: 'X-Webkit-CSP';
}
return $return;
} | php | protected function getHeaderKeys(bool $legacy = true): array
{
// We always want this
$return = [
$this->reportOnly
? 'Content-Security-Policy-Report-Only'
: 'Content-Security-Policy'
];
// If we're supporting legacy devices, include these too:
if ($legacy) {
$return []= $this->reportOnly
? 'X-Content-Security-Policy-Report-Only'
: 'X-Content-Security-Policy';
$return []= $this->reportOnly
? 'X-Webkit-CSP-Report-Only'
: 'X-Webkit-CSP';
}
return $return;
} | [
"protected",
"function",
"getHeaderKeys",
"(",
"bool",
"$",
"legacy",
"=",
"true",
")",
":",
"array",
"{",
"// We always want this",
"$",
"return",
"=",
"[",
"$",
"this",
"->",
"reportOnly",
"?",
"'Content-Security-Policy-Report-Only'",
":",
"'Content-Security-Polic... | Get an array of header keys to return
@param bool $legacy
@return array | [
"Get",
"an",
"array",
"of",
"header",
"keys",
"to",
"return"
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L843-L862 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.disableHttpsTransformOnHttpsConnections | public function disableHttpsTransformOnHttpsConnections(): self
{
$this->needsCompile = ($this->needsCompile || $this->httpsTransformOnHttpsConnections !== false);
$this->httpsTransformOnHttpsConnections = false;
return $this;
} | php | public function disableHttpsTransformOnHttpsConnections(): self
{
$this->needsCompile = ($this->needsCompile || $this->httpsTransformOnHttpsConnections !== false);
$this->httpsTransformOnHttpsConnections = false;
return $this;
} | [
"public",
"function",
"disableHttpsTransformOnHttpsConnections",
"(",
")",
":",
"self",
"{",
"$",
"this",
"->",
"needsCompile",
"=",
"(",
"$",
"this",
"->",
"needsCompile",
"||",
"$",
"this",
"->",
"httpsTransformOnHttpsConnections",
"!==",
"false",
")",
";",
"$... | Disable that HTTP sources get converted to HTTPS if the connection is such.
@return self | [
"Disable",
"that",
"HTTP",
"sources",
"get",
"converted",
"to",
"HTTPS",
"if",
"the",
"connection",
"is",
"such",
"."
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L882-L888 | train |
paragonie/csp-builder | src/CSPBuilder.php | CSPBuilder.enableHttpsTransformOnHttpsConnections | public function enableHttpsTransformOnHttpsConnections(): self
{
$this->needsCompile = ($this->needsCompile || $this->httpsTransformOnHttpsConnections !== true);
$this->httpsTransformOnHttpsConnections = true;
return $this;
} | php | public function enableHttpsTransformOnHttpsConnections(): self
{
$this->needsCompile = ($this->needsCompile || $this->httpsTransformOnHttpsConnections !== true);
$this->httpsTransformOnHttpsConnections = true;
return $this;
} | [
"public",
"function",
"enableHttpsTransformOnHttpsConnections",
"(",
")",
":",
"self",
"{",
"$",
"this",
"->",
"needsCompile",
"=",
"(",
"$",
"this",
"->",
"needsCompile",
"||",
"$",
"this",
"->",
"httpsTransformOnHttpsConnections",
"!==",
"true",
")",
";",
"$",... | Enable that HTTP sources get converted to HTTPS if the connection is such.
This is enabled by default
@return self | [
"Enable",
"that",
"HTTP",
"sources",
"get",
"converted",
"to",
"HTTPS",
"if",
"the",
"connection",
"is",
"such",
"."
] | 3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e | https://github.com/paragonie/csp-builder/blob/3b05cbbe6307de7ce4d7ca1c96fad96e7619b92e/src/CSPBuilder.php#L897-L903 | train |
Nexmo/nexmo-laravel | src/NexmoServiceProvider.php | NexmoServiceProvider.createNexmoClient | protected function createNexmoClient(Config $config)
{
// Check for Nexmo config file.
if (! $this->hasNexmoConfigSection()) {
$this->raiseRunTimeException('Missing nexmo configuration section.');
}
// Get Client Options.
$options = array_diff_key($config->get('nexmo'), ['private_key', 'application_id', 'api_key', 'api_secret', 'shared_secret']);
// Do we have a private key?
$privateKeyCredentials = null;
if ($this->nexmoConfigHas('private_key')) {
if ($this->nexmoConfigHasNo('application_id')) {
$this->raiseRunTimeException('You must provide nexmo.application_id when using a private key');
}
$privateKeyCredentials = $this->createPrivateKeyCredentials($config->get('nexmo.private_key'), $config->get('nexmo.application_id'));
}
$basicCredentials = null;
if ($this->nexmoConfigHas('api_secret')) {
$basicCredentials = $this->createBasicCredentials($config->get('nexmo.api_key'), $config->get('nexmo.api_secret'));
}
$signatureCredentials = null;
if ($this->nexmoConfigHas('signature_secret')) {
$signatureCredentials = $this->createSignatureCredentials($config->get('nexmo.api_key'), $config->get('nexmo.signature_secret'));
}
// We can have basic only, signature only, private key only or
// we can have private key + basic/signature, so let's work out
// what's been provided
if ($basicCredentials && $signatureCredentials) {
$this->raiseRunTimeException('Provide either nexmo.api_secret or nexmo.signature_secret');
}
if ($privateKeyCredentials && $basicCredentials) {
$credentials = new Client\Credentials\Container(
$privateKeyCredentials,
$basicCredentials
);
} else if ($privateKeyCredentials && $signatureCredentials) {
$credentials = new Client\Credentials\Container(
$privateKeyCredentials,
$signatureCredentials
);
} else if ($privateKeyCredentials) {
$credentials = $privateKeyCredentials;
} else if ($signatureCredentials) {
$credentials = $signatureCredentials;
} else if ($basicCredentials) {
$credentials = $basicCredentials;
} else {
$possibleNexmoKeys = [
'api_key + api_secret',
'api_key + signature_secret',
'private_key + application_id',
'api_key + api_secret + private_key + application_id',
'api_key + signature_secret + private_key + application_id',
];
$this->raiseRunTimeException(
'Please provide Nexmo API credentials. Possible combinations: '
. join(", ", $possibleNexmoKeys)
);
}
return new Client($credentials, $options);
} | php | protected function createNexmoClient(Config $config)
{
// Check for Nexmo config file.
if (! $this->hasNexmoConfigSection()) {
$this->raiseRunTimeException('Missing nexmo configuration section.');
}
// Get Client Options.
$options = array_diff_key($config->get('nexmo'), ['private_key', 'application_id', 'api_key', 'api_secret', 'shared_secret']);
// Do we have a private key?
$privateKeyCredentials = null;
if ($this->nexmoConfigHas('private_key')) {
if ($this->nexmoConfigHasNo('application_id')) {
$this->raiseRunTimeException('You must provide nexmo.application_id when using a private key');
}
$privateKeyCredentials = $this->createPrivateKeyCredentials($config->get('nexmo.private_key'), $config->get('nexmo.application_id'));
}
$basicCredentials = null;
if ($this->nexmoConfigHas('api_secret')) {
$basicCredentials = $this->createBasicCredentials($config->get('nexmo.api_key'), $config->get('nexmo.api_secret'));
}
$signatureCredentials = null;
if ($this->nexmoConfigHas('signature_secret')) {
$signatureCredentials = $this->createSignatureCredentials($config->get('nexmo.api_key'), $config->get('nexmo.signature_secret'));
}
// We can have basic only, signature only, private key only or
// we can have private key + basic/signature, so let's work out
// what's been provided
if ($basicCredentials && $signatureCredentials) {
$this->raiseRunTimeException('Provide either nexmo.api_secret or nexmo.signature_secret');
}
if ($privateKeyCredentials && $basicCredentials) {
$credentials = new Client\Credentials\Container(
$privateKeyCredentials,
$basicCredentials
);
} else if ($privateKeyCredentials && $signatureCredentials) {
$credentials = new Client\Credentials\Container(
$privateKeyCredentials,
$signatureCredentials
);
} else if ($privateKeyCredentials) {
$credentials = $privateKeyCredentials;
} else if ($signatureCredentials) {
$credentials = $signatureCredentials;
} else if ($basicCredentials) {
$credentials = $basicCredentials;
} else {
$possibleNexmoKeys = [
'api_key + api_secret',
'api_key + signature_secret',
'private_key + application_id',
'api_key + api_secret + private_key + application_id',
'api_key + signature_secret + private_key + application_id',
];
$this->raiseRunTimeException(
'Please provide Nexmo API credentials. Possible combinations: '
. join(", ", $possibleNexmoKeys)
);
}
return new Client($credentials, $options);
} | [
"protected",
"function",
"createNexmoClient",
"(",
"Config",
"$",
"config",
")",
"{",
"// Check for Nexmo config file.",
"if",
"(",
"!",
"$",
"this",
"->",
"hasNexmoConfigSection",
"(",
")",
")",
"{",
"$",
"this",
"->",
"raiseRunTimeException",
"(",
"'Missing nexm... | Create a new Nexmo Client.
@param Config $config
@return Client
@throws \RuntimeException | [
"Create",
"a",
"new",
"Nexmo",
"Client",
"."
] | 98cdca5d89f537d27e96a3e6c4d5b22299523b56 | https://github.com/Nexmo/nexmo-laravel/blob/98cdca5d89f537d27e96a3e6c4d5b22299523b56/src/NexmoServiceProvider.php#L73-L141 | train |
Nexmo/nexmo-laravel | src/NexmoServiceProvider.php | NexmoServiceProvider.nexmoConfigHas | protected function nexmoConfigHas($key)
{
/** @var Config $config */
$config = $this->app->make(Config::class);
// Check for Nexmo config file.
if (! $config->has('nexmo')) {
return false;
}
return
$config->has('nexmo.'.$key) &&
! is_null($config->get('nexmo.'.$key)) &&
! empty($config->get('nexmo.'.$key));
} | php | protected function nexmoConfigHas($key)
{
/** @var Config $config */
$config = $this->app->make(Config::class);
// Check for Nexmo config file.
if (! $config->has('nexmo')) {
return false;
}
return
$config->has('nexmo.'.$key) &&
! is_null($config->get('nexmo.'.$key)) &&
! empty($config->get('nexmo.'.$key));
} | [
"protected",
"function",
"nexmoConfigHas",
"(",
"$",
"key",
")",
"{",
"/** @var Config $config */",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Config",
"::",
"class",
")",
";",
"// Check for Nexmo config file.",
"if",
"(",
"!",
"$",
"c... | Checks if Nexmo config has value for the
given key.
@param string $key
@return bool | [
"Checks",
"if",
"Nexmo",
"config",
"has",
"value",
"for",
"the",
"given",
"key",
"."
] | 98cdca5d89f537d27e96a3e6c4d5b22299523b56 | https://github.com/Nexmo/nexmo-laravel/blob/98cdca5d89f537d27e96a3e6c4d5b22299523b56/src/NexmoServiceProvider.php#L175-L189 | train |
Nexmo/nexmo-laravel | src/NexmoServiceProvider.php | NexmoServiceProvider.createPrivateKeyCredentials | protected function createPrivateKeyCredentials($key, $applicationId)
{
return new Client\Credentials\Keypair($this->loadPrivateKey($key), $applicationId);
} | php | protected function createPrivateKeyCredentials($key, $applicationId)
{
return new Client\Credentials\Keypair($this->loadPrivateKey($key), $applicationId);
} | [
"protected",
"function",
"createPrivateKeyCredentials",
"(",
"$",
"key",
",",
"$",
"applicationId",
")",
"{",
"return",
"new",
"Client",
"\\",
"Credentials",
"\\",
"Keypair",
"(",
"$",
"this",
"->",
"loadPrivateKey",
"(",
"$",
"key",
")",
",",
"$",
"applicat... | Create Keypair credentials for client.
@param string $key
@param string $applicationId
@return Client\Credentials\Keypair | [
"Create",
"Keypair",
"credentials",
"for",
"client",
"."
] | 98cdca5d89f537d27e96a3e6c4d5b22299523b56 | https://github.com/Nexmo/nexmo-laravel/blob/98cdca5d89f537d27e96a3e6c4d5b22299523b56/src/NexmoServiceProvider.php#L225-L228 | train |
Nexmo/nexmo-laravel | src/NexmoServiceProvider.php | NexmoServiceProvider.loadPrivateKey | protected function loadPrivateKey($key)
{
if (app()->runningUnitTests()) {
return '===FAKE-KEY===';
}
// If it's a relative path, start searching in the
// project root
if ($key[0] !== '/') {
$key = base_path().'/'.$key;
}
return file_get_contents($key);
} | php | protected function loadPrivateKey($key)
{
if (app()->runningUnitTests()) {
return '===FAKE-KEY===';
}
// If it's a relative path, start searching in the
// project root
if ($key[0] !== '/') {
$key = base_path().'/'.$key;
}
return file_get_contents($key);
} | [
"protected",
"function",
"loadPrivateKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"app",
"(",
")",
"->",
"runningUnitTests",
"(",
")",
")",
"{",
"return",
"'===FAKE-KEY==='",
";",
"}",
"// If it's a relative path, start searching in the",
"// project root",
"if",
"... | Load private key contents from root directory | [
"Load",
"private",
"key",
"contents",
"from",
"root",
"directory"
] | 98cdca5d89f537d27e96a3e6c4d5b22299523b56 | https://github.com/Nexmo/nexmo-laravel/blob/98cdca5d89f537d27e96a3e6c4d5b22299523b56/src/NexmoServiceProvider.php#L233-L246 | train |
php-enqueue/enqueue | Client/SpoolProducer.php | SpoolProducer.flush | public function flush(): void
{
while (false == $this->events->isEmpty()) {
list($topic, $message) = $this->events->dequeue();
$this->realProducer->sendEvent($topic, $message);
}
while (false == $this->commands->isEmpty()) {
list($command, $message) = $this->commands->dequeue();
$this->realProducer->sendCommand($command, $message);
}
} | php | public function flush(): void
{
while (false == $this->events->isEmpty()) {
list($topic, $message) = $this->events->dequeue();
$this->realProducer->sendEvent($topic, $message);
}
while (false == $this->commands->isEmpty()) {
list($command, $message) = $this->commands->dequeue();
$this->realProducer->sendCommand($command, $message);
}
} | [
"public",
"function",
"flush",
"(",
")",
":",
"void",
"{",
"while",
"(",
"false",
"==",
"$",
"this",
"->",
"events",
"->",
"isEmpty",
"(",
")",
")",
"{",
"list",
"(",
"$",
"topic",
",",
"$",
"message",
")",
"=",
"$",
"this",
"->",
"events",
"->",... | When it is called it sends all previously queued messages. | [
"When",
"it",
"is",
"called",
"it",
"sends",
"all",
"previously",
"queued",
"messages",
"."
] | 88df6be34fb9e9b98dcdacfdda88058517213927 | https://github.com/php-enqueue/enqueue/blob/88df6be34fb9e9b98dcdacfdda88058517213927/Client/SpoolProducer.php#L51-L64 | train |
php-enqueue/enqueue | Rpc/Promise.php | Promise.receive | public function receive($timeout = null)
{
if (null == $this->message) {
try {
if ($message = $this->doReceive($this->receiveCallback, $this, $timeout)) {
$this->message = $message;
}
} finally {
call_user_func($this->finallyCallback, $this);
}
}
return $this->message;
} | php | public function receive($timeout = null)
{
if (null == $this->message) {
try {
if ($message = $this->doReceive($this->receiveCallback, $this, $timeout)) {
$this->message = $message;
}
} finally {
call_user_func($this->finallyCallback, $this);
}
}
return $this->message;
} | [
"public",
"function",
"receive",
"(",
"$",
"timeout",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"message",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"message",
"=",
"$",
"this",
"->",
"doReceive",
"(",
"$",
"this",
"->",
"rec... | Blocks until message received or timeout expired.
@param int $timeout
@throws TimeoutException if the wait timeout is reached
@return InteropMessage | [
"Blocks",
"until",
"message",
"received",
"or",
"timeout",
"expired",
"."
] | 88df6be34fb9e9b98dcdacfdda88058517213927 | https://github.com/php-enqueue/enqueue/blob/88df6be34fb9e9b98dcdacfdda88058517213927/Rpc/Promise.php#L57-L70 | train |
php-enqueue/enqueue | Rpc/Promise.php | Promise.receiveNoWait | public function receiveNoWait()
{
if (null == $this->message) {
if ($message = $this->doReceive($this->receiveNoWaitCallback, $this)) {
$this->message = $message;
call_user_func($this->finallyCallback, $this);
}
}
return $this->message;
} | php | public function receiveNoWait()
{
if (null == $this->message) {
if ($message = $this->doReceive($this->receiveNoWaitCallback, $this)) {
$this->message = $message;
call_user_func($this->finallyCallback, $this);
}
}
return $this->message;
} | [
"public",
"function",
"receiveNoWait",
"(",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"message",
")",
"{",
"if",
"(",
"$",
"message",
"=",
"$",
"this",
"->",
"doReceive",
"(",
"$",
"this",
"->",
"receiveNoWaitCallback",
",",
"$",
"this",
... | Non blocking function. Returns message or null.
@return InteropMessage|null | [
"Non",
"blocking",
"function",
".",
"Returns",
"message",
"or",
"null",
"."
] | 88df6be34fb9e9b98dcdacfdda88058517213927 | https://github.com/php-enqueue/enqueue/blob/88df6be34fb9e9b98dcdacfdda88058517213927/Rpc/Promise.php#L77-L88 | train |
docusign/docusign-php-client | src/Model/FeatureSet.php | FeatureSet.offsetGet | public function offsetGet($offset)
{
return isset($this->container[$offset]) ? $this->container[$offset] : null;
} | php | public function offsetGet($offset)
{
return isset($this->container[$offset]) ? $this->container[$offset] : null;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"container",
"[",
"$",
"offset",
"]",
")",
"?",
"$",
"this",
"->",
"container",
"[",
"$",
"offset",
"]",
":",
"null",
";",
"}"
] | Gets offset.
@param integer $offset Offset
@return mixed | [
"Gets",
"offset",
"."
] | 968e7edafca6a7f01063aa126fe2fe6bad5609da | https://github.com/docusign/docusign-php-client/blob/968e7edafca6a7f01063aa126fe2fe6bad5609da/src/Model/FeatureSet.php#L391-L394 | train |
docusign/docusign-php-client | src/Configuration.php | Configuration.setCurlConnectTimeout | public function setCurlConnectTimeout($seconds)
{
if (!is_numeric($seconds) || $seconds < 0) {
throw new \InvalidArgumentException('Connect timeout value must be numeric and a non-negative number.');
}
$this->curlConnectTimeout = $seconds;
return $this;
} | php | public function setCurlConnectTimeout($seconds)
{
if (!is_numeric($seconds) || $seconds < 0) {
throw new \InvalidArgumentException('Connect timeout value must be numeric and a non-negative number.');
}
$this->curlConnectTimeout = $seconds;
return $this;
} | [
"public",
"function",
"setCurlConnectTimeout",
"(",
"$",
"seconds",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"seconds",
")",
"||",
"$",
"seconds",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Connect timeout value must ... | Sets the HTTP connect timeout value
@param integer $seconds Number of seconds before connection times out [set to 0 for no timeout]
@return Configuration | [
"Sets",
"the",
"HTTP",
"connect",
"timeout",
"value"
] | 968e7edafca6a7f01063aa126fe2fe6bad5609da | https://github.com/docusign/docusign-php-client/blob/968e7edafca6a7f01063aa126fe2fe6bad5609da/src/Configuration.php#L433-L441 | train |
andersondanilo/CnabPHP | src/Cnab/Retorno/Cnab400/Detalhe.php | Detalhe.getDataVencimento | public function getDataVencimento()
{
$data = $this->data_vencimento ? \DateTime::createFromFormat('dmy', sprintf('%06d', $this->data_vencimento)) : false;
if ($data) {
$data->setTime(0, 0, 0);
}
return $data;
} | php | public function getDataVencimento()
{
$data = $this->data_vencimento ? \DateTime::createFromFormat('dmy', sprintf('%06d', $this->data_vencimento)) : false;
if ($data) {
$data->setTime(0, 0, 0);
}
return $data;
} | [
"public",
"function",
"getDataVencimento",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"data_vencimento",
"?",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'dmy'",
",",
"sprintf",
"(",
"'%06d'",
",",
"$",
"this",
"->",
"data_vencimento",
")",
... | Retorna o objeto \DateTime da data de vencimento do boleto.
@return \DateTime | [
"Retorna",
"o",
"objeto",
"\\",
"DateTime",
"da",
"data",
"de",
"vencimento",
"do",
"boleto",
"."
] | 080f774005bbafd55b200b1af45177bebcdd0242 | https://github.com/andersondanilo/CnabPHP/blob/080f774005bbafd55b200b1af45177bebcdd0242/src/Cnab/Retorno/Cnab400/Detalhe.php#L170-L178 | train |
andersondanilo/CnabPHP | src/Cnab/Retorno/Cnab400/Detalhe.php | Detalhe.getDataCredito | public function getDataCredito()
{
$data = $this->data_credito ? \DateTime::createFromFormat('dmy', sprintf('%06d', $this->data_credito)) : false;
if ($data) {
$data->setTime(0, 0, 0);
}
return $data;
} | php | public function getDataCredito()
{
$data = $this->data_credito ? \DateTime::createFromFormat('dmy', sprintf('%06d', $this->data_credito)) : false;
if ($data) {
$data->setTime(0, 0, 0);
}
return $data;
} | [
"public",
"function",
"getDataCredito",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"data_credito",
"?",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'dmy'",
",",
"sprintf",
"(",
"'%06d'",
",",
"$",
"this",
"->",
"data_credito",
")",
")",
":... | Retorna a data em que o dinheiro caiu na conta.
@return \DateTime | [
"Retorna",
"a",
"data",
"em",
"que",
"o",
"dinheiro",
"caiu",
"na",
"conta",
"."
] | 080f774005bbafd55b200b1af45177bebcdd0242 | https://github.com/andersondanilo/CnabPHP/blob/080f774005bbafd55b200b1af45177bebcdd0242/src/Cnab/Retorno/Cnab400/Detalhe.php#L185-L193 | train |
andersondanilo/CnabPHP | src/Cnab/Retorno/Cnab400/Detalhe.php | Detalhe.getValorMoraMulta | public function getValorMoraMulta()
{
if (\Cnab\Banco::CEF == $this->_codigo_banco) {
return $this->valor_juros + $this->valor_multa;
} else {
return $this->valor_mora_multa;
}
} | php | public function getValorMoraMulta()
{
if (\Cnab\Banco::CEF == $this->_codigo_banco) {
return $this->valor_juros + $this->valor_multa;
} else {
return $this->valor_mora_multa;
}
} | [
"public",
"function",
"getValorMoraMulta",
"(",
")",
"{",
"if",
"(",
"\\",
"Cnab",
"\\",
"Banco",
"::",
"CEF",
"==",
"$",
"this",
"->",
"_codigo_banco",
")",
"{",
"return",
"$",
"this",
"->",
"valor_juros",
"+",
"$",
"this",
"->",
"valor_multa",
";",
"... | Retorna o valor de juros e mora. | [
"Retorna",
"o",
"valor",
"de",
"juros",
"e",
"mora",
"."
] | 080f774005bbafd55b200b1af45177bebcdd0242 | https://github.com/andersondanilo/CnabPHP/blob/080f774005bbafd55b200b1af45177bebcdd0242/src/Cnab/Retorno/Cnab400/Detalhe.php#L198-L205 | train |
andersondanilo/CnabPHP | src/Cnab/Factory.php | Factory.createRemessa | public function createRemessa($codigo_banco, $formato = 'cnab400', $layoutVersao = null)
{
if (empty($codigo_banco)) {
throw new \InvalidArgumentException('$codigo_banco cannot be empty');
}
switch ($formato) {
case 'cnab400':
return new Remessa\Cnab400\Arquivo($codigo_banco, $layoutVersao);
case 'cnab240':
return new Remessa\Cnab240\Arquivo($codigo_banco, $layoutVersao);
default:
throw new \InvalidArgumentException('Invalid cnab format: ' + $formato);
}
} | php | public function createRemessa($codigo_banco, $formato = 'cnab400', $layoutVersao = null)
{
if (empty($codigo_banco)) {
throw new \InvalidArgumentException('$codigo_banco cannot be empty');
}
switch ($formato) {
case 'cnab400':
return new Remessa\Cnab400\Arquivo($codigo_banco, $layoutVersao);
case 'cnab240':
return new Remessa\Cnab240\Arquivo($codigo_banco, $layoutVersao);
default:
throw new \InvalidArgumentException('Invalid cnab format: ' + $formato);
}
} | [
"public",
"function",
"createRemessa",
"(",
"$",
"codigo_banco",
",",
"$",
"formato",
"=",
"'cnab400'",
",",
"$",
"layoutVersao",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"codigo_banco",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentExce... | Cria um arquivo de remessa.
@return \Cnab\Remessa\IArquivo | [
"Cria",
"um",
"arquivo",
"de",
"remessa",
"."
] | 080f774005bbafd55b200b1af45177bebcdd0242 | https://github.com/andersondanilo/CnabPHP/blob/080f774005bbafd55b200b1af45177bebcdd0242/src/Cnab/Factory.php#L37-L50 | train |
andersondanilo/CnabPHP | src/Cnab/Remessa/Cnab240/Detalhe.php | Detalhe.getEncoded | public function getEncoded()
{
$text = array();
foreach ($this->listSegmento() as $segmento) {
$text[] = $segmento->getEncoded();
}
return implode(Arquivo::QUEBRA_LINHA, $text);
} | php | public function getEncoded()
{
$text = array();
foreach ($this->listSegmento() as $segmento) {
$text[] = $segmento->getEncoded();
}
return implode(Arquivo::QUEBRA_LINHA, $text);
} | [
"public",
"function",
"getEncoded",
"(",
")",
"{",
"$",
"text",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"listSegmento",
"(",
")",
"as",
"$",
"segmento",
")",
"{",
"$",
"text",
"[",
"]",
"=",
"$",
"segmento",
"->",
"getEncode... | Retorna todas as linhas destes detalhes.
@return string | [
"Retorna",
"todas",
"as",
"linhas",
"destes",
"detalhes",
"."
] | 080f774005bbafd55b200b1af45177bebcdd0242 | https://github.com/andersondanilo/CnabPHP/blob/080f774005bbafd55b200b1af45177bebcdd0242/src/Cnab/Remessa/Cnab240/Detalhe.php#L51-L59 | train |
themsaid/forge-sdk | src/Actions/ManagesMysqlDatabases.php | ManagesMysqlDatabases.createMysqlDatabase | public function createMysqlDatabase($serverId, array $data, $wait = true)
{
$database = $this->post("servers/$serverId/mysql", $data)['database'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $database) {
$database = $this->mysqlDatabase($serverId, $database['id']);
return $database->status == 'installed' ? $database : null;
});
}
return new MysqlDatabase($database + ['server_id' => $serverId], $this);
} | php | public function createMysqlDatabase($serverId, array $data, $wait = true)
{
$database = $this->post("servers/$serverId/mysql", $data)['database'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $database) {
$database = $this->mysqlDatabase($serverId, $database['id']);
return $database->status == 'installed' ? $database : null;
});
}
return new MysqlDatabase($database + ['server_id' => $serverId], $this);
} | [
"public",
"function",
"createMysqlDatabase",
"(",
"$",
"serverId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"database",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/mysql\"",
",",
"$",
"data",
")",
"[",
"'data... | Create a new MySQL Database.
@param integer $serverId
@param array $data
@param boolean $wait
@return MysqlDatabase | [
"Create",
"a",
"new",
"MySQL",
"Database",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesMysqlDatabases.php#L46-L59 | train |
themsaid/forge-sdk | src/Forge.php | Forge.setApiKey | public function setApiKey($apiKey, $guzzle)
{
$this->apiKey = $apiKey;
$this->guzzle = $guzzle ?: new HttpClient([
'base_uri' => 'https://forge.laravel.com/api/v1/',
'http_errors' => false,
'headers' => [
'Authorization' => 'Bearer '.$this->apiKey,
'Accept' => 'application/json',
'Content-Type' => 'application/json'
]
]);
return $this;
} | php | public function setApiKey($apiKey, $guzzle)
{
$this->apiKey = $apiKey;
$this->guzzle = $guzzle ?: new HttpClient([
'base_uri' => 'https://forge.laravel.com/api/v1/',
'http_errors' => false,
'headers' => [
'Authorization' => 'Bearer '.$this->apiKey,
'Accept' => 'application/json',
'Content-Type' => 'application/json'
]
]);
return $this;
} | [
"public",
"function",
"setApiKey",
"(",
"$",
"apiKey",
",",
"$",
"guzzle",
")",
"{",
"$",
"this",
"->",
"apiKey",
"=",
"$",
"apiKey",
";",
"$",
"this",
"->",
"guzzle",
"=",
"$",
"guzzle",
"?",
":",
"new",
"HttpClient",
"(",
"[",
"'base_uri'",
"=>",
... | Set the api key and setup the guzzle request object
@param string $apiKey
@return $this | [
"Set",
"the",
"api",
"key",
"and",
"setup",
"the",
"guzzle",
"request",
"object"
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Forge.php#L83-L98 | train |
themsaid/forge-sdk | src/Actions/ManagesJobs.php | ManagesJobs.createJob | public function createJob($serverId, array $data, $wait = true)
{
$job = $this->post("servers/$serverId/jobs", $data)['job'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $job) {
$job = $this->job($serverId, $job['id']);
return $job->status == 'installed' ? $job : null;
});
}
return new Job($job + ['server_id' => $serverId], $this);
} | php | public function createJob($serverId, array $data, $wait = true)
{
$job = $this->post("servers/$serverId/jobs", $data)['job'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $job) {
$job = $this->job($serverId, $job['id']);
return $job->status == 'installed' ? $job : null;
});
}
return new Job($job + ['server_id' => $serverId], $this);
} | [
"public",
"function",
"createJob",
"(",
"$",
"serverId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"job",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/jobs\"",
",",
"$",
"data",
")",
"[",
"'job'",
"]",
";",... | Create a new job.
@param integer $serverId
@param array $data
@param boolean $wait
@return Job | [
"Create",
"a",
"new",
"job",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesJobs.php#L46-L59 | train |
themsaid/forge-sdk | src/Resources/Site.php | Site.updateGitRepository | public function updateGitRepository(array $data)
{
return $this->forge->updateSiteGitRepository($this->serverId, $this->id, $data);
} | php | public function updateGitRepository(array $data)
{
return $this->forge->updateSiteGitRepository($this->serverId, $this->id, $data);
} | [
"public",
"function",
"updateGitRepository",
"(",
"array",
"$",
"data",
")",
"{",
"return",
"$",
"this",
"->",
"forge",
"->",
"updateSiteGitRepository",
"(",
"$",
"this",
"->",
"serverId",
",",
"$",
"this",
"->",
"id",
",",
"$",
"data",
")",
";",
"}"
] | Update the site's git repository parameters.
@param array $data
@return void | [
"Update",
"the",
"site",
"s",
"git",
"repository",
"parameters",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Site.php#L178-L181 | train |
themsaid/forge-sdk | src/Resources/Site.php | Site.updateDeploymentScript | public function updateDeploymentScript($content)
{
return $this->forge->updateSiteDeploymentScript($this->serverId, $this->id, $content);
} | php | public function updateDeploymentScript($content)
{
return $this->forge->updateSiteDeploymentScript($this->serverId, $this->id, $content);
} | [
"public",
"function",
"updateDeploymentScript",
"(",
"$",
"content",
")",
"{",
"return",
"$",
"this",
"->",
"forge",
"->",
"updateSiteDeploymentScript",
"(",
"$",
"this",
"->",
"serverId",
",",
"$",
"this",
"->",
"id",
",",
"$",
"content",
")",
";",
"}"
] | Update the content of the site's deployment script.
@param string $content
@return void | [
"Update",
"the",
"content",
"of",
"the",
"site",
"s",
"deployment",
"script",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Site.php#L210-L213 | train |
themsaid/forge-sdk | src/Resources/Site.php | Site.enableHipchatNotifications | public function enableHipchatNotifications(array $data)
{
return $this->forge->enableHipchatNotifications($this->serverId, $this->id, $data);
} | php | public function enableHipchatNotifications(array $data)
{
return $this->forge->enableHipchatNotifications($this->serverId, $this->id, $data);
} | [
"public",
"function",
"enableHipchatNotifications",
"(",
"array",
"$",
"data",
")",
"{",
"return",
"$",
"this",
"->",
"forge",
"->",
"enableHipchatNotifications",
"(",
"$",
"this",
"->",
"serverId",
",",
"$",
"this",
"->",
"id",
",",
"$",
"data",
")",
";",... | Enable Hipchat Notifications for the given site.
@param array $data
@return void | [
"Enable",
"Hipchat",
"Notifications",
"for",
"the",
"given",
"site",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Site.php#L252-L255 | train |
themsaid/forge-sdk | src/Resources/Site.php | Site.installWordPress | public function installWordPress($data)
{
return $this->forge->installWordPress($this->serverId, $this->id, $data);
} | php | public function installWordPress($data)
{
return $this->forge->installWordPress($this->serverId, $this->id, $data);
} | [
"public",
"function",
"installWordPress",
"(",
"$",
"data",
")",
"{",
"return",
"$",
"this",
"->",
"forge",
"->",
"installWordPress",
"(",
"$",
"this",
"->",
"serverId",
",",
"$",
"this",
"->",
"id",
",",
"$",
"data",
")",
";",
"}"
] | Install a new WordPress project.
@return void | [
"Install",
"a",
"new",
"WordPress",
"project",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Site.php#L272-L275 | train |
themsaid/forge-sdk | src/Actions/ManagesWorkers.php | ManagesWorkers.workers | public function workers($serverId, $siteId)
{
return $this->transformCollection(
$this->get("servers/$serverId/sites/$siteId/workers")['workers'],
Worker::class,
['server_id' => $serverId, 'site_id' => $siteId]
);
} | php | public function workers($serverId, $siteId)
{
return $this->transformCollection(
$this->get("servers/$serverId/sites/$siteId/workers")['workers'],
Worker::class,
['server_id' => $serverId, 'site_id' => $siteId]
);
} | [
"public",
"function",
"workers",
"(",
"$",
"serverId",
",",
"$",
"siteId",
")",
"{",
"return",
"$",
"this",
"->",
"transformCollection",
"(",
"$",
"this",
"->",
"get",
"(",
"\"servers/$serverId/sites/$siteId/workers\"",
")",
"[",
"'workers'",
"]",
",",
"Worker... | Get the collection of workers.
@param integer $serverId
@param integer $siteId
@return Worker[] | [
"Get",
"the",
"collection",
"of",
"workers",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesWorkers.php#L16-L23 | train |
themsaid/forge-sdk | src/Actions/ManagesWorkers.php | ManagesWorkers.worker | public function worker($serverId, $siteId, $workerId)
{
return new Worker(
$this->get("servers/$serverId/sites/$siteId/workers/$workerId")['worker']
+ ['server_id' => $serverId, 'site_id' => $siteId], $this
);
} | php | public function worker($serverId, $siteId, $workerId)
{
return new Worker(
$this->get("servers/$serverId/sites/$siteId/workers/$workerId")['worker']
+ ['server_id' => $serverId, 'site_id' => $siteId], $this
);
} | [
"public",
"function",
"worker",
"(",
"$",
"serverId",
",",
"$",
"siteId",
",",
"$",
"workerId",
")",
"{",
"return",
"new",
"Worker",
"(",
"$",
"this",
"->",
"get",
"(",
"\"servers/$serverId/sites/$siteId/workers/$workerId\"",
")",
"[",
"'worker'",
"]",
"+",
... | Get a worker instance.
@param integer $serverId
@param integer $siteId
@param integer $workerId
@return Worker | [
"Get",
"a",
"worker",
"instance",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesWorkers.php#L33-L39 | train |
themsaid/forge-sdk | src/Actions/ManagesCertificates.php | ManagesCertificates.certificates | public function certificates($serverId, $siteId)
{
return $this->transformCollection(
$this->get("servers/$serverId/sites/$siteId/certificates")['certificates'],
Certificate::class,
['server_id' => $serverId, 'site_id' => $siteId]
);
} | php | public function certificates($serverId, $siteId)
{
return $this->transformCollection(
$this->get("servers/$serverId/sites/$siteId/certificates")['certificates'],
Certificate::class,
['server_id' => $serverId, 'site_id' => $siteId]
);
} | [
"public",
"function",
"certificates",
"(",
"$",
"serverId",
",",
"$",
"siteId",
")",
"{",
"return",
"$",
"this",
"->",
"transformCollection",
"(",
"$",
"this",
"->",
"get",
"(",
"\"servers/$serverId/sites/$siteId/certificates\"",
")",
"[",
"'certificates'",
"]",
... | Get the collection of certificates.
@param integer $serverId
@param integer $siteId
@return Certificate[] | [
"Get",
"the",
"collection",
"of",
"certificates",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesCertificates.php#L16-L23 | train |
themsaid/forge-sdk | src/Actions/ManagesCertificates.php | ManagesCertificates.certificate | public function certificate($serverId, $siteId, $certificateId)
{
return new Certificate(
$this->get("servers/$serverId/sites/$siteId/certificates/$certificateId")['certificate']
+ ['server_id' => $serverId, 'site_id' => $siteId], $this
);
} | php | public function certificate($serverId, $siteId, $certificateId)
{
return new Certificate(
$this->get("servers/$serverId/sites/$siteId/certificates/$certificateId")['certificate']
+ ['server_id' => $serverId, 'site_id' => $siteId], $this
);
} | [
"public",
"function",
"certificate",
"(",
"$",
"serverId",
",",
"$",
"siteId",
",",
"$",
"certificateId",
")",
"{",
"return",
"new",
"Certificate",
"(",
"$",
"this",
"->",
"get",
"(",
"\"servers/$serverId/sites/$siteId/certificates/$certificateId\"",
")",
"[",
"'c... | Get a certificate instance.
@param integer $serverId
@param integer $siteId
@param integer $certificateId
@return Certificate | [
"Get",
"a",
"certificate",
"instance",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesCertificates.php#L33-L39 | train |
themsaid/forge-sdk | src/Actions/ManagesCertificates.php | ManagesCertificates.createCertificate | public function createCertificate($serverId, $siteId, array $data, $wait = true)
{
$certificate = $this->post("servers/$serverId/sites/$siteId/certificates", $data)['certificate'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $certificate) {
$certificate = $this->certificate($serverId, $siteId, $certificate['id']);
return $certificate->status == 'installed' ? $certificate : null;
});
}
return new Certificate($certificate + ['server_id' => $serverId, 'site_id' => $siteId], $this);
} | php | public function createCertificate($serverId, $siteId, array $data, $wait = true)
{
$certificate = $this->post("servers/$serverId/sites/$siteId/certificates", $data)['certificate'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $certificate) {
$certificate = $this->certificate($serverId, $siteId, $certificate['id']);
return $certificate->status == 'installed' ? $certificate : null;
});
}
return new Certificate($certificate + ['server_id' => $serverId, 'site_id' => $siteId], $this);
} | [
"public",
"function",
"createCertificate",
"(",
"$",
"serverId",
",",
"$",
"siteId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"certificate",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/sites/$siteId/certificates\""... | Create a new certificate.
@param integer $serverId
@param integer $siteId
@param array $data
@param boolean $wait
@return Certificate | [
"Create",
"a",
"new",
"certificate",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesCertificates.php#L50-L63 | train |
themsaid/forge-sdk | src/Actions/ManagesSites.php | ManagesSites.createSite | public function createSite($serverId, array $data, $wait = true)
{
$site = $this->post("servers/$serverId/sites", $data)['site'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $site) {
$site = $this->site($serverId, $site['id']);
return $site->status == 'installed' ? $site : null;
});
}
return new Site($site + ['server_id' => $serverId], $this);
} | php | public function createSite($serverId, array $data, $wait = true)
{
$site = $this->post("servers/$serverId/sites", $data)['site'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $site) {
$site = $this->site($serverId, $site['id']);
return $site->status == 'installed' ? $site : null;
});
}
return new Site($site + ['server_id' => $serverId], $this);
} | [
"public",
"function",
"createSite",
"(",
"$",
"serverId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"site",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/sites\"",
",",
"$",
"data",
")",
"[",
"'site'",
"]",
... | Create a new site.
@param integer $serverId
@param array $data
@param boolean $wait
@return Site | [
"Create",
"a",
"new",
"site",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesSites.php#L46-L59 | train |
themsaid/forge-sdk | src/Actions/ManagesSites.php | ManagesSites.updateSite | public function updateSite($serverId, $siteId, array $data)
{
return new Site(
$this->put("servers/$serverId/sites/$siteId", $data)['site']
+ ['server_id' => $serverId], $this
);
} | php | public function updateSite($serverId, $siteId, array $data)
{
return new Site(
$this->put("servers/$serverId/sites/$siteId", $data)['site']
+ ['server_id' => $serverId], $this
);
} | [
"public",
"function",
"updateSite",
"(",
"$",
"serverId",
",",
"$",
"siteId",
",",
"array",
"$",
"data",
")",
"{",
"return",
"new",
"Site",
"(",
"$",
"this",
"->",
"put",
"(",
"\"servers/$serverId/sites/$siteId\"",
",",
"$",
"data",
")",
"[",
"'site'",
"... | Update the given site.
@param integer $serverId
@param integer $siteId
@param array $data
@return Site | [
"Update",
"the",
"given",
"site",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesSites.php#L69-L75 | train |
themsaid/forge-sdk | src/Actions/ManagesServers.php | ManagesServers.createServer | public function createServer(array $data)
{
$response = $this->post('servers', $data);
$output = $response['server'];
$output['sudo_password'] = @$response['sudo_password'];
$output['database_password'] = @$response['database_password'];
$output['provision_command'] = @$response['provision_command'];
return new Server($output, $this);
} | php | public function createServer(array $data)
{
$response = $this->post('servers', $data);
$output = $response['server'];
$output['sudo_password'] = @$response['sudo_password'];
$output['database_password'] = @$response['database_password'];
$output['provision_command'] = @$response['provision_command'];
return new Server($output, $this);
} | [
"public",
"function",
"createServer",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"post",
"(",
"'servers'",
",",
"$",
"data",
")",
";",
"$",
"output",
"=",
"$",
"response",
"[",
"'server'",
"]",
";",
"$",
"output",
... | Create a new server.
@param array $data
@return Server | [
"Create",
"a",
"new",
"server",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesServers.php#L38-L48 | train |
themsaid/forge-sdk | src/Resources/Resource.php | Resource.fill | private function fill()
{
foreach ($this->attributes as $key => $value) {
$key = $this->camelCase($key);
$this->{$key} = $value;
}
} | php | private function fill()
{
foreach ($this->attributes as $key => $value) {
$key = $this->camelCase($key);
$this->{$key} = $value;
}
} | [
"private",
"function",
"fill",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"camelCase",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"{",
"... | Fill the resource with the array of attributes.
@return void | [
"Fill",
"the",
"resource",
"with",
"the",
"array",
"of",
"attributes",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Resource.php#L43-L50 | train |
themsaid/forge-sdk | src/Resources/Resource.php | Resource.camelCase | private function camelCase($key)
{
$parts = explode('_', $key);
foreach ($parts as $i => $part) {
if ($i !== 0) {
$parts[$i] = ucfirst($part);
}
}
return str_replace(' ', '', implode(' ', $parts));
} | php | private function camelCase($key)
{
$parts = explode('_', $key);
foreach ($parts as $i => $part) {
if ($i !== 0) {
$parts[$i] = ucfirst($part);
}
}
return str_replace(' ', '', implode(' ', $parts));
} | [
"private",
"function",
"camelCase",
"(",
"$",
"key",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'_'",
",",
"$",
"key",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"i",
"=>",
"$",
"part",
")",
"{",
"if",
"(",
"$",
"i",
"!==",
"0",
")... | Convert the key name to camel case.
@param $key | [
"Convert",
"the",
"key",
"name",
"to",
"camel",
"case",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Resource.php#L57-L68 | train |
themsaid/forge-sdk | src/Actions/ManagesFirewallRules.php | ManagesFirewallRules.createFirewallRule | public function createFirewallRule($serverId, array $data, $wait = true)
{
$rule = $this->post("servers/$serverId/firewall-rules", $data)['rule'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $rule) {
$rule = $this->firewallRule($serverId, $rule['id']);
return $rule->status == 'installed' ? $rule : null;
});
}
return new FirewallRule($rule + ['server_id' => $serverId], $this);
} | php | public function createFirewallRule($serverId, array $data, $wait = true)
{
$rule = $this->post("servers/$serverId/firewall-rules", $data)['rule'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $rule) {
$rule = $this->firewallRule($serverId, $rule['id']);
return $rule->status == 'installed' ? $rule : null;
});
}
return new FirewallRule($rule + ['server_id' => $serverId], $this);
} | [
"public",
"function",
"createFirewallRule",
"(",
"$",
"serverId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"rule",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/firewall-rules\"",
",",
"$",
"data",
")",
"[",
"'... | Create a new firewall rule.
@param integer $serverId
@param array $data
@param boolean $wait
@return FirewallRule | [
"Create",
"a",
"new",
"firewall",
"rule",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesFirewallRules.php#L46-L59 | train |
themsaid/forge-sdk | src/Resources/Worker.php | Worker.delete | public function delete()
{
return $this->forge->deleteWorker($this->serverId, $this->siteId, $this->id);
} | php | public function delete()
{
return $this->forge->deleteWorker($this->serverId, $this->siteId, $this->id);
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"forge",
"->",
"deleteWorker",
"(",
"$",
"this",
"->",
"serverId",
",",
"$",
"this",
"->",
"siteId",
",",
"$",
"this",
"->",
"id",
")",
";",
"}"
] | Delete the given worker.
@return void | [
"Delete",
"the",
"given",
"worker",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Worker.php#L103-L106 | train |
themsaid/forge-sdk | src/Actions/ManagesDaemons.php | ManagesDaemons.createDaemon | public function createDaemon($serverId, array $data, $wait = true)
{
$daemon = $this->post("servers/$serverId/daemons", $data)['daemon'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $daemon) {
$daemon = $this->daemon($serverId, $daemon['id']);
return $daemon->status == 'installed' ? $daemon : null;
});
}
return new Daemon($daemon + ['server_id' => $serverId], $this);
} | php | public function createDaemon($serverId, array $data, $wait = true)
{
$daemon = $this->post("servers/$serverId/daemons", $data)['daemon'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $daemon) {
$daemon = $this->daemon($serverId, $daemon['id']);
return $daemon->status == 'installed' ? $daemon : null;
});
}
return new Daemon($daemon + ['server_id' => $serverId], $this);
} | [
"public",
"function",
"createDaemon",
"(",
"$",
"serverId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"daemon",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/daemons\"",
",",
"$",
"data",
")",
"[",
"'daemon'",
... | Create a new daemon.
@param integer $serverId
@param array $data
@param boolean $wait
@return Daemon | [
"Create",
"a",
"new",
"daemon",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesDaemons.php#L46-L59 | train |
themsaid/forge-sdk | src/MakesHttpRequests.php | MakesHttpRequests.retry | public function retry($timeout, $callback)
{
$start = time();
beginning:
if ($output = $callback()) {
return $output;
}
if (time() - $start < $timeout) {
sleep(5);
goto beginning;
}
throw new TimeoutException($output);
} | php | public function retry($timeout, $callback)
{
$start = time();
beginning:
if ($output = $callback()) {
return $output;
}
if (time() - $start < $timeout) {
sleep(5);
goto beginning;
}
throw new TimeoutException($output);
} | [
"public",
"function",
"retry",
"(",
"$",
"timeout",
",",
"$",
"callback",
")",
"{",
"$",
"start",
"=",
"time",
"(",
")",
";",
"beginning",
":",
"if",
"(",
"$",
"output",
"=",
"$",
"callback",
"(",
")",
")",
"{",
"return",
"$",
"output",
";",
"}",... | Retry the callback or fail after x seconds.
@param integer $timeout
@param callable $callback
@return mixed | [
"Retry",
"the",
"callback",
"or",
"fail",
"after",
"x",
"seconds",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/MakesHttpRequests.php#L111-L128 | train |
themsaid/forge-sdk | src/Resources/Certificate.php | Certificate.delete | public function delete()
{
return $this->forge->deleteCertificate($this->serverId, $this->siteId, $this->id);
} | php | public function delete()
{
return $this->forge->deleteCertificate($this->serverId, $this->siteId, $this->id);
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"forge",
"->",
"deleteCertificate",
"(",
"$",
"this",
"->",
"serverId",
",",
"$",
"this",
"->",
"siteId",
",",
"$",
"this",
"->",
"id",
")",
";",
"}"
] | Delete the given certificate.
@return void | [
"Delete",
"the",
"given",
"certificate",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Certificate.php#L90-L93 | train |
themsaid/forge-sdk | src/Resources/Certificate.php | Certificate.getSigningRequest | public function getSigningRequest()
{
return $this->forge->getCertificateSigningRequest($this->serverId, $this->siteId, $this->id);
} | php | public function getSigningRequest()
{
return $this->forge->getCertificateSigningRequest($this->serverId, $this->siteId, $this->id);
} | [
"public",
"function",
"getSigningRequest",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"forge",
"->",
"getCertificateSigningRequest",
"(",
"$",
"this",
"->",
"serverId",
",",
"$",
"this",
"->",
"siteId",
",",
"$",
"this",
"->",
"id",
")",
";",
"}"
] | Get the SSL certificate signing request for the site.
@return string | [
"Get",
"the",
"SSL",
"certificate",
"signing",
"request",
"for",
"the",
"site",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Resources/Certificate.php#L100-L103 | train |
themsaid/forge-sdk | src/Actions/ManagesSSHKeys.php | ManagesSSHKeys.createSSHKey | public function createSSHKey($serverId, array $data, $wait = true)
{
$key = $this->post("servers/$serverId/keys", $data)['key'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $key) {
$key = $this->SSHKey($serverId, $key['id']);
return $key->status == 'installed' ? $key : null;
});
}
return new SSHKey($key + ['server_id' => $serverId], $this);
} | php | public function createSSHKey($serverId, array $data, $wait = true)
{
$key = $this->post("servers/$serverId/keys", $data)['key'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $key) {
$key = $this->SSHKey($serverId, $key['id']);
return $key->status == 'installed' ? $key : null;
});
}
return new SSHKey($key + ['server_id' => $serverId], $this);
} | [
"public",
"function",
"createSSHKey",
"(",
"$",
"serverId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/keys\"",
",",
"$",
"data",
")",
"[",
"'key'",
"]",
"... | Create a new SSH key.
@param integer $serverId
@param array $data
@param boolean $wait
@return SSHKey | [
"Create",
"a",
"new",
"SSH",
"key",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesSSHKeys.php#L46-L59 | train |
themsaid/forge-sdk | src/Actions/ManagesMysqlUsers.php | ManagesMysqlUsers.createMysqlUser | public function createMysqlUser($serverId, array $data, $wait = true)
{
$user = $this->post("servers/$serverId/mysql-users", $data)['user'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $user) {
$user = $this->mysqlUser($serverId, $user['id']);
return $user->status == 'installed' ? $user : null;
});
}
return new MysqlUser($user + ['server_id' => $serverId], $this);
} | php | public function createMysqlUser($serverId, array $data, $wait = true)
{
$user = $this->post("servers/$serverId/mysql-users", $data)['user'];
if ($wait) {
return $this->retry($this->getTimeout(), function () use ($serverId, $user) {
$user = $this->mysqlUser($serverId, $user['id']);
return $user->status == 'installed' ? $user : null;
});
}
return new MysqlUser($user + ['server_id' => $serverId], $this);
} | [
"public",
"function",
"createMysqlUser",
"(",
"$",
"serverId",
",",
"array",
"$",
"data",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"post",
"(",
"\"servers/$serverId/mysql-users\"",
",",
"$",
"data",
")",
"[",
"'user'"... | Create a new MySQL User.
@param integer $serverId
@param array $data
@param boolean $wait
@return MysqlUser | [
"Create",
"a",
"new",
"MySQL",
"User",
"."
] | 420053bf569b16a9f72dd6bfbd33d16354151cce | https://github.com/themsaid/forge-sdk/blob/420053bf569b16a9f72dd6bfbd33d16354151cce/src/Actions/ManagesMysqlUsers.php#L46-L59 | train |
Happyr/Doctrine-Specification | src/DBALTypesResolver.php | DBALTypesResolver.tryGetTypeForValue | public static function tryGetTypeForValue($value)
{
if (!is_object($value)) {
return null;
}
// maybe it's a ValueObject
// try get type name from types map
$className = get_class($value);
if (isset(self::$typesMap[$className])) {
return Type::getType(self::$typesMap[$className]);
}
// use class name as type name
$classNameParts = explode('\\', $className);
$typeName = array_pop($classNameParts);
if (array_key_exists($typeName, Type::getTypesMap())) {
return Type::getType($typeName);
}
return null;
} | php | public static function tryGetTypeForValue($value)
{
if (!is_object($value)) {
return null;
}
// maybe it's a ValueObject
// try get type name from types map
$className = get_class($value);
if (isset(self::$typesMap[$className])) {
return Type::getType(self::$typesMap[$className]);
}
// use class name as type name
$classNameParts = explode('\\', $className);
$typeName = array_pop($classNameParts);
if (array_key_exists($typeName, Type::getTypesMap())) {
return Type::getType($typeName);
}
return null;
} | [
"public",
"static",
"function",
"tryGetTypeForValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"// maybe it's a ValueObject",
"// try get type name from types map",
"$",
"className",
... | Try get type for value.
If type is not found return NULL.
@param mixed $value
@return Type|null | [
"Try",
"get",
"type",
"for",
"value",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/DBALTypesResolver.php#L25-L48 | train |
Happyr/Doctrine-Specification | src/Operand/ArgumentToOperandConverter.php | ArgumentToOperandConverter.convert | public static function convert(array $arguments)
{
if (!$arguments) {
return [];
}
// always try convert the first argument to the field operand
$field = self::toField(array_shift($arguments));
if (!$arguments) {
return [$field];
}
// always try convert the last argument to the value operand
$value = self::toValue(array_pop($arguments));
if (!$arguments) {
return [$field, $value];
}
if (!self::isAllOperands($arguments)) {
throw new NotConvertibleException('You passed arguments not all of which are operands.');
}
array_unshift($arguments, $field);
array_push($arguments, $value);
return $arguments;
} | php | public static function convert(array $arguments)
{
if (!$arguments) {
return [];
}
// always try convert the first argument to the field operand
$field = self::toField(array_shift($arguments));
if (!$arguments) {
return [$field];
}
// always try convert the last argument to the value operand
$value = self::toValue(array_pop($arguments));
if (!$arguments) {
return [$field, $value];
}
if (!self::isAllOperands($arguments)) {
throw new NotConvertibleException('You passed arguments not all of which are operands.');
}
array_unshift($arguments, $field);
array_push($arguments, $value);
return $arguments;
} | [
"public",
"static",
"function",
"convert",
"(",
"array",
"$",
"arguments",
")",
"{",
"if",
"(",
"!",
"$",
"arguments",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// always try convert the first argument to the field operand",
"$",
"field",
"=",
"self",
"::",
"to... | Convert all possible arguments to operands.
@param Operand[]|string[] $arguments
@throws NotConvertibleException
@return Operand[] | [
"Convert",
"all",
"possible",
"arguments",
"to",
"operands",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/Operand/ArgumentToOperandConverter.php#L71-L99 | train |
Happyr/Doctrine-Specification | src/EntitySpecificationRepositoryTrait.php | EntitySpecificationRepositoryTrait.match | public function match($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
return $query->execute();
} | php | public function match($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
return $query->execute();
} | [
"public",
"function",
"match",
"(",
"$",
"specification",
",",
"ResultModifier",
"$",
"modifier",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getQuery",
"(",
"$",
"specification",
",",
"$",
"modifier",
")",
";",
"return",
"$",
"query",
... | Get results when you match with a Specification.
@param Filter|QueryModifier $specification
@param ResultModifier|null $modifier
@return mixed[] | [
"Get",
"results",
"when",
"you",
"match",
"with",
"a",
"Specification",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/EntitySpecificationRepositoryTrait.php#L31-L36 | train |
Happyr/Doctrine-Specification | src/EntitySpecificationRepositoryTrait.php | EntitySpecificationRepositoryTrait.matchSingleResult | public function matchSingleResult($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
try {
return $query->getSingleResult();
} catch (NonUniqueResultException $e) {
throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
} catch (NoResultException $e) {
throw new Exception\NoResultException($e->getMessage(), $e->getCode(), $e);
}
} | php | public function matchSingleResult($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
try {
return $query->getSingleResult();
} catch (NonUniqueResultException $e) {
throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
} catch (NoResultException $e) {
throw new Exception\NoResultException($e->getMessage(), $e->getCode(), $e);
}
} | [
"public",
"function",
"matchSingleResult",
"(",
"$",
"specification",
",",
"ResultModifier",
"$",
"modifier",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getQuery",
"(",
"$",
"specification",
",",
"$",
"modifier",
")",
";",
"try",
"{",
... | Get single result when you match with a Specification.
@param Filter|QueryModifier $specification
@param ResultModifier|null $modifier
@throw Exception\NonUniqueException If more than one result is found
@throw Exception\NoResultException If no results found
@return mixed | [
"Get",
"single",
"result",
"when",
"you",
"match",
"with",
"a",
"Specification",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/EntitySpecificationRepositoryTrait.php#L49-L60 | train |
Happyr/Doctrine-Specification | src/EntitySpecificationRepositoryTrait.php | EntitySpecificationRepositoryTrait.matchOneOrNullResult | public function matchOneOrNullResult($specification, ResultModifier $modifier = null)
{
try {
return $this->matchSingleResult($specification, $modifier);
} catch (Exception\NoResultException $e) {
return;
}
} | php | public function matchOneOrNullResult($specification, ResultModifier $modifier = null)
{
try {
return $this->matchSingleResult($specification, $modifier);
} catch (Exception\NoResultException $e) {
return;
}
} | [
"public",
"function",
"matchOneOrNullResult",
"(",
"$",
"specification",
",",
"ResultModifier",
"$",
"modifier",
"=",
"null",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"matchSingleResult",
"(",
"$",
"specification",
",",
"$",
"modifier",
")",
";",
"... | Get single result or null when you match with a Specification.
@param Filter|QueryModifier $specification
@param ResultModifier|null $modifier
@throw Exception\NonUniqueException If more than one result is found
@return mixed|null | [
"Get",
"single",
"result",
"or",
"null",
"when",
"you",
"match",
"with",
"a",
"Specification",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/EntitySpecificationRepositoryTrait.php#L72-L79 | train |
Happyr/Doctrine-Specification | src/EntitySpecificationRepositoryTrait.php | EntitySpecificationRepositoryTrait.matchSingleScalarResult | public function matchSingleScalarResult($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
try {
return $query->getSingleScalarResult();
} catch (NonUniqueResultException $e) {
throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
}
} | php | public function matchSingleScalarResult($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
try {
return $query->getSingleScalarResult();
} catch (NonUniqueResultException $e) {
throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
}
} | [
"public",
"function",
"matchSingleScalarResult",
"(",
"$",
"specification",
",",
"ResultModifier",
"$",
"modifier",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getQuery",
"(",
"$",
"specification",
",",
"$",
"modifier",
")",
";",
"try",
"... | Get single scalar result when you match with a Specification.
@param Filter|QueryModifier $specification
@param ResultModifier|null $modifier
@throw Exception\NonUniqueException If more than one result is found
@throw Exception\NoResultException If no results found
@return mixed | [
"Get",
"single",
"scalar",
"result",
"when",
"you",
"match",
"with",
"a",
"Specification",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/EntitySpecificationRepositoryTrait.php#L92-L101 | train |
Happyr/Doctrine-Specification | src/EntitySpecificationRepositoryTrait.php | EntitySpecificationRepositoryTrait.matchScalarResult | public function matchScalarResult($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
return $query->getScalarResult();
} | php | public function matchScalarResult($specification, ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);
return $query->getScalarResult();
} | [
"public",
"function",
"matchScalarResult",
"(",
"$",
"specification",
",",
"ResultModifier",
"$",
"modifier",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getQuery",
"(",
"$",
"specification",
",",
"$",
"modifier",
")",
";",
"return",
"$",... | Get scalar result when you match with a Specification.
@param Filter|QueryModifier $specification
@param ResultModifier|null $modifier
@throw Exception\NonUniqueException If more than one result is found
@throw Exception\NoResultException If no results found
@return mixed | [
"Get",
"scalar",
"result",
"when",
"you",
"match",
"with",
"a",
"Specification",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/EntitySpecificationRepositoryTrait.php#L114-L119 | train |
Happyr/Doctrine-Specification | src/EntitySpecificationRepositoryTrait.php | EntitySpecificationRepositoryTrait.getQuery | public function getQuery($specification, ResultModifier $modifier = null)
{
$query = $this->getQueryBuilder($specification)->getQuery();
if (null !== $modifier) {
$modifier->modify($query);
}
return $query;
} | php | public function getQuery($specification, ResultModifier $modifier = null)
{
$query = $this->getQueryBuilder($specification)->getQuery();
if (null !== $modifier) {
$modifier->modify($query);
}
return $query;
} | [
"public",
"function",
"getQuery",
"(",
"$",
"specification",
",",
"ResultModifier",
"$",
"modifier",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getQueryBuilder",
"(",
"$",
"specification",
")",
"->",
"getQuery",
"(",
")",
";",
"if",
"(... | Prepare a Query with a Specification.
@param Filter|QueryModifier $specification
@param ResultModifier|null $modifier
@return Query | [
"Prepare",
"a",
"Query",
"with",
"a",
"Specification",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/EntitySpecificationRepositoryTrait.php#L129-L138 | train |
Happyr/Doctrine-Specification | src/EntitySpecificationRepositoryTrait.php | EntitySpecificationRepositoryTrait.iterate | public function iterate($specification, ResultModifier $modifier = null)
{
foreach ($this->getQuery($specification, $modifier)->iterate() as $row) {
yield current($row);
}
} | php | public function iterate($specification, ResultModifier $modifier = null)
{
foreach ($this->getQuery($specification, $modifier)->iterate() as $row) {
yield current($row);
}
} | [
"public",
"function",
"iterate",
"(",
"$",
"specification",
",",
"ResultModifier",
"$",
"modifier",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getQuery",
"(",
"$",
"specification",
",",
"$",
"modifier",
")",
"->",
"iterate",
"(",
")",
"as... | Iterate results when you match with a Specification.
@param Filter|QueryModifier $specification
@param ResultModifier|null $modifier
@return mixed[]|\Generator | [
"Iterate",
"results",
"when",
"you",
"match",
"with",
"a",
"Specification",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/EntitySpecificationRepositoryTrait.php#L162-L167 | train |
Happyr/Doctrine-Specification | src/Spec.php | Spec.fun | public static function fun($functionName, $arguments = [])
{
if (2 === func_num_args()) {
$arguments = (array) $arguments;
} else {
$arguments = func_get_args();
$functionName = array_shift($arguments);
}
return new PlatformFunction($functionName, $arguments);
} | php | public static function fun($functionName, $arguments = [])
{
if (2 === func_num_args()) {
$arguments = (array) $arguments;
} else {
$arguments = func_get_args();
$functionName = array_shift($arguments);
}
return new PlatformFunction($functionName, $arguments);
} | [
"public",
"static",
"function",
"fun",
"(",
"$",
"functionName",
",",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"2",
"===",
"func_num_args",
"(",
")",
")",
"{",
"$",
"arguments",
"=",
"(",
"array",
")",
"$",
"arguments",
";",
"}",
"else... | Call DQL function.
Usage:
Spec::fun('CURRENT_DATE')
Spec::fun('DATE_DIFF', $date1, $date2)
Spec::fun('DATE_DIFF', [$date1, $date2])
@param string $functionName
@param mixed $arguments
@return PlatformFunction | [
"Call",
"DQL",
"function",
"."
] | 0bc2a3838b7303d37874df3f2dd2c850daf8f7eb | https://github.com/Happyr/Doctrine-Specification/blob/0bc2a3838b7303d37874df3f2dd2c850daf8f7eb/src/Spec.php#L712-L722 | train |
overtrue/phplint | src/Cache.php | Cache.get | public static function get()
{
$content = file_get_contents(self::getFilename());
return $content ? json_decode($content, true) : null;
} | php | public static function get()
{
$content = file_get_contents(self::getFilename());
return $content ? json_decode($content, true) : null;
} | [
"public",
"static",
"function",
"get",
"(",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"self",
"::",
"getFilename",
"(",
")",
")",
";",
"return",
"$",
"content",
"?",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
":",
"null",
";",... | Fetch cache.
@return mixed | [
"Fetch",
"cache",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Cache.php#L29-L34 | train |
overtrue/phplint | src/Cache.php | Cache.getFilename | public static function getFilename()
{
if (\is_dir(\dirname(self::$filename))) {
return self::$filename;
}
return (getcwd() ?: './').'/'.self::$filename;
} | php | public static function getFilename()
{
if (\is_dir(\dirname(self::$filename))) {
return self::$filename;
}
return (getcwd() ?: './').'/'.self::$filename;
} | [
"public",
"static",
"function",
"getFilename",
"(",
")",
"{",
"if",
"(",
"\\",
"is_dir",
"(",
"\\",
"dirname",
"(",
"self",
"::",
"$",
"filename",
")",
")",
")",
"{",
"return",
"self",
"::",
"$",
"filename",
";",
"}",
"return",
"(",
"getcwd",
"(",
... | Return cache filename.
@return string | [
"Return",
"cache",
"filename",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Cache.php#L97-L104 | train |
overtrue/phplint | src/Process/Lint.php | Lint.parseError | public function parseError($message)
{
$pattern = '/^(PHP\s+)?(Parse|Fatal) error:\s*(?:\w+ error,\s*)?(?<error>.+?)\s+in\s+.+?\s*line\s+(?<line>\d+)/';
$matched = preg_match($pattern, $message, $match);
if (empty($message)) {
$message = 'Unknown';
}
return [
'error' => $matched ? "{$match['error']} in line {$match['line']}" : $message,
'line' => $matched ? abs($match['line']) : 0,
];
} | php | public function parseError($message)
{
$pattern = '/^(PHP\s+)?(Parse|Fatal) error:\s*(?:\w+ error,\s*)?(?<error>.+?)\s+in\s+.+?\s*line\s+(?<line>\d+)/';
$matched = preg_match($pattern, $message, $match);
if (empty($message)) {
$message = 'Unknown';
}
return [
'error' => $matched ? "{$match['error']} in line {$match['line']}" : $message,
'line' => $matched ? abs($match['line']) : 0,
];
} | [
"public",
"function",
"parseError",
"(",
"$",
"message",
")",
"{",
"$",
"pattern",
"=",
"'/^(PHP\\s+)?(Parse|Fatal) error:\\s*(?:\\w+ error,\\s*)?(?<error>.+?)\\s+in\\s+.+?\\s*line\\s+(?<line>\\d+)/'",
";",
"$",
"matched",
"=",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
... | Parse error message.
@param string $message
@return array | [
"Parse",
"error",
"message",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Process/Lint.php#L56-L70 | train |
overtrue/phplint | src/Linter.php | Linter.lint | public function lint($files = [], $cache = true)
{
if (empty($files)) {
$files = $this->getFiles();
}
$processCallback = is_callable($this->processCallback) ? $this->processCallback : function () {
};
$errors = [];
$running = [];
$newCache = [];
while (!empty($files) || !empty($running)) {
for ($i = count($running); !empty($files) && $i < $this->processLimit; ++$i) {
$file = array_shift($files);
$filename = $file->getRealPath();
$relativePathname = $file->getRelativePathname();
if (!isset($this->cache[$relativePathname]) || $this->cache[$relativePathname] !== md5_file($filename)) {
$lint = $this->createLintProcess($filename);
$running[$filename] = [
'process' => $lint,
'file' => $file,
'relativePath' => $relativePathname,
];
$lint->start();
} else {
$newCache[$relativePathname] = $this->cache[$relativePathname];
}
}
foreach ($running as $filename => $item) {
/** @var Lint $lint */
$lint = $item['process'];
if ($lint->isRunning()) {
continue;
}
unset($running[$filename]);
if ($lint->hasSyntaxError()) {
$processCallback('error', $item['file']);
$errors[$filename] = array_merge(['file' => $filename], $lint->getSyntaxError());
} else {
$newCache[$item['relativePath']] = md5_file($filename);
$processCallback('ok', $item['file']);
}
}
}
$cache && Cache::put($newCache);
return $errors;
} | php | public function lint($files = [], $cache = true)
{
if (empty($files)) {
$files = $this->getFiles();
}
$processCallback = is_callable($this->processCallback) ? $this->processCallback : function () {
};
$errors = [];
$running = [];
$newCache = [];
while (!empty($files) || !empty($running)) {
for ($i = count($running); !empty($files) && $i < $this->processLimit; ++$i) {
$file = array_shift($files);
$filename = $file->getRealPath();
$relativePathname = $file->getRelativePathname();
if (!isset($this->cache[$relativePathname]) || $this->cache[$relativePathname] !== md5_file($filename)) {
$lint = $this->createLintProcess($filename);
$running[$filename] = [
'process' => $lint,
'file' => $file,
'relativePath' => $relativePathname,
];
$lint->start();
} else {
$newCache[$relativePathname] = $this->cache[$relativePathname];
}
}
foreach ($running as $filename => $item) {
/** @var Lint $lint */
$lint = $item['process'];
if ($lint->isRunning()) {
continue;
}
unset($running[$filename]);
if ($lint->hasSyntaxError()) {
$processCallback('error', $item['file']);
$errors[$filename] = array_merge(['file' => $filename], $lint->getSyntaxError());
} else {
$newCache[$item['relativePath']] = md5_file($filename);
$processCallback('ok', $item['file']);
}
}
}
$cache && Cache::put($newCache);
return $errors;
} | [
"public",
"function",
"lint",
"(",
"$",
"files",
"=",
"[",
"]",
",",
"$",
"cache",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"getFiles",
"(",
")",
";",
"}",
"$",
"proces... | Check the files.
@param SplFileInfo[] $files
@param bool $cache
@return array | [
"Check",
"the",
"files",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Linter.php#L81-L133 | train |
overtrue/phplint | src/Linter.php | Linter.getFiles | public function getFiles()
{
if (empty($this->files)) {
foreach ($this->path as $path) {
if (is_dir($path)) {
$this->files = array_merge($this->files, $this->getFilesFromDir($path));
} elseif (is_file($path)) {
$this->files[$path] = new SplFileInfo($path, $path, $path);
}
}
}
return $this->files;
} | php | public function getFiles()
{
if (empty($this->files)) {
foreach ($this->path as $path) {
if (is_dir($path)) {
$this->files = array_merge($this->files, $this->getFilesFromDir($path));
} elseif (is_file($path)) {
$this->files[$path] = new SplFileInfo($path, $path, $path);
}
}
}
return $this->files;
} | [
"public",
"function",
"getFiles",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"files",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"path",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
... | Fetch files.
@return SplFileInfo[] | [
"Fetch",
"files",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Linter.php#L154-L167 | train |
overtrue/phplint | src/Linter.php | Linter.getFilesFromDir | protected function getFilesFromDir($dir)
{
$finder = new Finder();
$finder->files()->ignoreUnreadableDirs()->in(realpath($dir));
foreach ($this->excludes as $exclude) {
$finder->notPath($exclude);
}
foreach ($this->extensions as $extension) {
$finder->name('*.'.$extension);
}
return iterator_to_array($finder);
} | php | protected function getFilesFromDir($dir)
{
$finder = new Finder();
$finder->files()->ignoreUnreadableDirs()->in(realpath($dir));
foreach ($this->excludes as $exclude) {
$finder->notPath($exclude);
}
foreach ($this->extensions as $extension) {
$finder->name('*.'.$extension);
}
return iterator_to_array($finder);
} | [
"protected",
"function",
"getFilesFromDir",
"(",
"$",
"dir",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"ignoreUnreadableDirs",
"(",
")",
"->",
"in",
"(",
"realpath",
"(",
"$",
"dir",
"... | Get files from directory.
@param string $dir
@return SplFileInfo[] | [
"Get",
"files",
"from",
"directory",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Linter.php#L176-L190 | train |
overtrue/phplint | src/Linter.php | Linter.setFiles | public function setFiles(array $files)
{
foreach ($files as $file) {
if (is_file($file)) {
$file = new SplFileInfo($file, $file, $file);
}
if (!($file instanceof SplFileInfo)) {
throw new InvalidArgumentException("File $file not exists.");
}
$this->files[$file->getRealPath()] = $file;
}
return $this;
} | php | public function setFiles(array $files)
{
foreach ($files as $file) {
if (is_file($file)) {
$file = new SplFileInfo($file, $file, $file);
}
if (!($file instanceof SplFileInfo)) {
throw new InvalidArgumentException("File $file not exists.");
}
$this->files[$file->getRealPath()] = $file;
}
return $this;
} | [
"public",
"function",
"setFiles",
"(",
"array",
"$",
"files",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"$",
"file",
"=",
"new",
"SplFileInfo",
"(",
"$",
"file",
",... | Set Files.
@param string[] $files
@return \Overtrue\PHPLint\Linter | [
"Set",
"Files",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Linter.php#L199-L214 | train |
overtrue/phplint | src/Command/LintCommand.php | LintCommand.executeLint | protected function executeLint($linter, $input, $output, $fileCount)
{
$cache = !$input->getOption('no-cache');
$maxColumns = floor((new Terminal())->getWidth() / 2);
$verbosity = $output->getVerbosity();
$displayProgress = !$input->getOption('no-progress');
$displayProgress && $linter->setProcessCallback(function ($status, SplFileInfo $file) use ($output, $verbosity, $fileCount, $maxColumns) {
static $i = 1;
$percent = floor(($i / $fileCount) * 100);
$process = str_pad(" {$i} / {$fileCount} ({$percent}%)", 18, ' ', STR_PAD_LEFT);
if ($verbosity >= OutputInterface::VERBOSITY_VERBOSE) {
$filename = str_pad(" {$i}: ".$file->getRelativePathname(), $maxColumns - 10, ' ', \STR_PAD_RIGHT);
$status = \str_pad(('ok' === $status ? '<info>OK</info>' : '<error>Error</error>'), 20, ' ', \STR_PAD_RIGHT);
$output->writeln(\sprintf("%s\t%s\t%s", $filename, $status, $process));
} else {
if ($i && 0 === $i % $maxColumns) {
$output->writeln($process);
}
$output->write('ok' === $status ? '<info>.</info>' : '<error>E</error>');
}
++$i;
});
$displayProgress || $output->write('<info>Checking...</info>');
return $linter->lint([], $cache);
} | php | protected function executeLint($linter, $input, $output, $fileCount)
{
$cache = !$input->getOption('no-cache');
$maxColumns = floor((new Terminal())->getWidth() / 2);
$verbosity = $output->getVerbosity();
$displayProgress = !$input->getOption('no-progress');
$displayProgress && $linter->setProcessCallback(function ($status, SplFileInfo $file) use ($output, $verbosity, $fileCount, $maxColumns) {
static $i = 1;
$percent = floor(($i / $fileCount) * 100);
$process = str_pad(" {$i} / {$fileCount} ({$percent}%)", 18, ' ', STR_PAD_LEFT);
if ($verbosity >= OutputInterface::VERBOSITY_VERBOSE) {
$filename = str_pad(" {$i}: ".$file->getRelativePathname(), $maxColumns - 10, ' ', \STR_PAD_RIGHT);
$status = \str_pad(('ok' === $status ? '<info>OK</info>' : '<error>Error</error>'), 20, ' ', \STR_PAD_RIGHT);
$output->writeln(\sprintf("%s\t%s\t%s", $filename, $status, $process));
} else {
if ($i && 0 === $i % $maxColumns) {
$output->writeln($process);
}
$output->write('ok' === $status ? '<info>.</info>' : '<error>E</error>');
}
++$i;
});
$displayProgress || $output->write('<info>Checking...</info>');
return $linter->lint([], $cache);
} | [
"protected",
"function",
"executeLint",
"(",
"$",
"linter",
",",
"$",
"input",
",",
"$",
"output",
",",
"$",
"fileCount",
")",
"{",
"$",
"cache",
"=",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'no-cache'",
")",
";",
"$",
"maxColumns",
"=",
"floor",
... | Execute lint and return errors.
@param Linter $linter
@param InputInterface $input
@param OutputInterface $output
@param int $fileCount
@return array | [
"Execute",
"lint",
"and",
"return",
"errors",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Command/LintCommand.php#L252-L281 | train |
overtrue/phplint | src/Command/LintCommand.php | LintCommand.showErrors | protected function showErrors($errors)
{
$i = 0;
$this->output->writeln("\nThere was ".count($errors).' errors:');
foreach ($errors as $filename => $error) {
$this->output->writeln('<comment>'.++$i.". {$filename}:{$error['line']}".'</comment>');
$this->output->write($this->getHighlightedCodeSnippet($filename, $error['line']));
$this->output->writeln("<error> {$error['error']}</error>");
}
} | php | protected function showErrors($errors)
{
$i = 0;
$this->output->writeln("\nThere was ".count($errors).' errors:');
foreach ($errors as $filename => $error) {
$this->output->writeln('<comment>'.++$i.". {$filename}:{$error['line']}".'</comment>');
$this->output->write($this->getHighlightedCodeSnippet($filename, $error['line']));
$this->output->writeln("<error> {$error['error']}</error>");
}
} | [
"protected",
"function",
"showErrors",
"(",
"$",
"errors",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"\\nThere was \"",
".",
"count",
"(",
"$",
"errors",
")",
".",
"' errors:'",
")",
";",
"foreach",
"(",
... | Show errors detail.
@param array $errors
@throws \JakubOnderka\PhpConsoleColor\InvalidStyleException | [
"Show",
"errors",
"detail",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Command/LintCommand.php#L290-L302 | train |
overtrue/phplint | src/Command/LintCommand.php | LintCommand.getConfigFile | protected function getConfigFile()
{
$inputPath = $this->input->getArgument('path');
$dir = './';
if (1 == count($inputPath) && $first = reset($inputPath)) {
$dir = is_dir($first) ? $first : dirname($first);
}
$filename = rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'.phplint.yml';
return realpath($filename);
} | php | protected function getConfigFile()
{
$inputPath = $this->input->getArgument('path');
$dir = './';
if (1 == count($inputPath) && $first = reset($inputPath)) {
$dir = is_dir($first) ? $first : dirname($first);
}
$filename = rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'.phplint.yml';
return realpath($filename);
} | [
"protected",
"function",
"getConfigFile",
"(",
")",
"{",
"$",
"inputPath",
"=",
"$",
"this",
"->",
"input",
"->",
"getArgument",
"(",
"'path'",
")",
";",
"$",
"dir",
"=",
"'./'",
";",
"if",
"(",
"1",
"==",
"count",
"(",
"$",
"inputPath",
")",
"&&",
... | Get configuration file.
@return string|null | [
"Get",
"configuration",
"file",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Command/LintCommand.php#L399-L412 | train |
overtrue/phplint | src/Command/LintCommand.php | LintCommand.loadConfiguration | protected function loadConfiguration($path)
{
try {
$configuration = Yaml::parse(file_get_contents($path));
if (!is_array($configuration)) {
throw new ParseException('Invalid content.', 1);
}
return $configuration;
} catch (ParseException $e) {
$this->output->writeln(sprintf('<error>Unable to parse the YAML string: %s</error>', $e->getMessage()));
return [];
}
} | php | protected function loadConfiguration($path)
{
try {
$configuration = Yaml::parse(file_get_contents($path));
if (!is_array($configuration)) {
throw new ParseException('Invalid content.', 1);
}
return $configuration;
} catch (ParseException $e) {
$this->output->writeln(sprintf('<error>Unable to parse the YAML string: %s</error>', $e->getMessage()));
return [];
}
} | [
"protected",
"function",
"loadConfiguration",
"(",
"$",
"path",
")",
"{",
"try",
"{",
"$",
"configuration",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"path",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"configuration",
")",... | Load configuration from yaml.
@param string $path
@return array | [
"Load",
"configuration",
"from",
"yaml",
"."
] | e59158852b05db4f9e892ee84ef275ce7cdfc77b | https://github.com/overtrue/phplint/blob/e59158852b05db4f9e892ee84ef275ce7cdfc77b/src/Command/LintCommand.php#L421-L435 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.initMapper | public function initMapper() {
switch ($this->dbsType) {
case 'jig':
$this->mapper = new Jig\Mapper($this->db, $this->table);
break;
case 'sql':
// ensure to load full table schema, so we can work with it at runtime
$this->mapper = new SQL\Mapper($this->db, $this->table, null,
($this->fluid)?0:$this->ttl);
$this->applyWhitelist();
break;
case 'mongo':
$this->mapper = new Mongo\Mapper($this->db, $this->table);
break;
default:
trigger_error(sprintf(self::E_UNKNOWN_DB_ENGINE,$this->dbsType),E_USER_ERROR);
}
$this->queryParser = CortexQueryParser::instance();
$this->reset();
$this->clearFilter();
$f3 = \Base::instance();
$this->smartLoading = $f3->exists('CORTEX.smartLoading') ?
$f3->get('CORTEX.smartLoading') : TRUE;
$this->standardiseID = $f3->exists('CORTEX.standardiseID') ?
$f3->get('CORTEX.standardiseID') : TRUE;
if(!empty($this->fieldConf))
foreach($this->fieldConf as &$conf) {
$conf=static::resolveRelationConf($conf,$this->primary);
unset($conf);
}
} | php | public function initMapper() {
switch ($this->dbsType) {
case 'jig':
$this->mapper = new Jig\Mapper($this->db, $this->table);
break;
case 'sql':
// ensure to load full table schema, so we can work with it at runtime
$this->mapper = new SQL\Mapper($this->db, $this->table, null,
($this->fluid)?0:$this->ttl);
$this->applyWhitelist();
break;
case 'mongo':
$this->mapper = new Mongo\Mapper($this->db, $this->table);
break;
default:
trigger_error(sprintf(self::E_UNKNOWN_DB_ENGINE,$this->dbsType),E_USER_ERROR);
}
$this->queryParser = CortexQueryParser::instance();
$this->reset();
$this->clearFilter();
$f3 = \Base::instance();
$this->smartLoading = $f3->exists('CORTEX.smartLoading') ?
$f3->get('CORTEX.smartLoading') : TRUE;
$this->standardiseID = $f3->exists('CORTEX.standardiseID') ?
$f3->get('CORTEX.standardiseID') : TRUE;
if(!empty($this->fieldConf))
foreach($this->fieldConf as &$conf) {
$conf=static::resolveRelationConf($conf,$this->primary);
unset($conf);
}
} | [
"public",
"function",
"initMapper",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"dbsType",
")",
"{",
"case",
"'jig'",
":",
"$",
"this",
"->",
"mapper",
"=",
"new",
"Jig",
"\\",
"Mapper",
"(",
"$",
"this",
"->",
"db",
",",
"$",
"this",
"->",
... | create mapper instance | [
"create",
"mapper",
"instance"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L134-L164 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.applyWhitelist | protected function applyWhitelist() {
if ($this->dbsType == 'sql') {
// fetch full schema
if (!$this->fluid && isset(self::$schema_cache[$key=$this->table.$this->db->uuid()]))
$schema = self::$schema_cache[$key];
else {
$schema = $this->mapper->schema();
self::$schema_cache[$this->table.$this->db->uuid()] = $schema;
}
// apply reduced fields schema
if ($this->whitelist)
$schema = array_intersect_key($schema, array_flip($this->whitelist));
$this->mapper->schema($schema);
$this->mapper->reset();
}
} | php | protected function applyWhitelist() {
if ($this->dbsType == 'sql') {
// fetch full schema
if (!$this->fluid && isset(self::$schema_cache[$key=$this->table.$this->db->uuid()]))
$schema = self::$schema_cache[$key];
else {
$schema = $this->mapper->schema();
self::$schema_cache[$this->table.$this->db->uuid()] = $schema;
}
// apply reduced fields schema
if ($this->whitelist)
$schema = array_intersect_key($schema, array_flip($this->whitelist));
$this->mapper->schema($schema);
$this->mapper->reset();
}
} | [
"protected",
"function",
"applyWhitelist",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dbsType",
"==",
"'sql'",
")",
"{",
"// fetch full schema",
"if",
"(",
"!",
"$",
"this",
"->",
"fluid",
"&&",
"isset",
"(",
"self",
"::",
"$",
"schema_cache",
"[",
... | apply whitelist to active mapper schema | [
"apply",
"whitelist",
"to",
"active",
"mapper",
"schema"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L225-L240 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.resolveConfiguration | static public function resolveConfiguration() {
static::$init=true;
$self = new static();
static::$init=false;
$conf = array (
'table'=>$self->getTable(),
'fieldConf'=>$self->getFieldConfiguration(),
'db'=>$self->db,
'fluid'=>$self->fluid,
'primary'=>$self->primary,
'charset'=>$self->charset,
);
unset($self);
return $conf;
} | php | static public function resolveConfiguration() {
static::$init=true;
$self = new static();
static::$init=false;
$conf = array (
'table'=>$self->getTable(),
'fieldConf'=>$self->getFieldConfiguration(),
'db'=>$self->db,
'fluid'=>$self->fluid,
'primary'=>$self->primary,
'charset'=>$self->charset,
);
unset($self);
return $conf;
} | [
"static",
"public",
"function",
"resolveConfiguration",
"(",
")",
"{",
"static",
"::",
"$",
"init",
"=",
"true",
";",
"$",
"self",
"=",
"new",
"static",
"(",
")",
";",
"static",
"::",
"$",
"init",
"=",
"false",
";",
"$",
"conf",
"=",
"array",
"(",
... | kick start to just fetch the config
@return array | [
"kick",
"start",
"to",
"just",
"fetch",
"the",
"config"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L271-L285 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.getTable | public function getTable() {
if (!$this->table && ($this->fluid || static::$init))
$this->table = strtolower(get_class($this));
return $this->table;
} | php | public function getTable() {
if (!$this->table && ($this->fluid || static::$init))
$this->table = strtolower(get_class($this));
return $this->table;
} | [
"public",
"function",
"getTable",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"table",
"&&",
"(",
"$",
"this",
"->",
"fluid",
"||",
"static",
"::",
"$",
"init",
")",
")",
"$",
"this",
"->",
"table",
"=",
"strtolower",
"(",
"get_class",
"(",
... | returns model table name
@return string | [
"returns",
"model",
"table",
"name"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L308-L312 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.setdown | static public function setdown($db=null, $table=null) {
$self = get_called_class();
if (is_null($db) || is_null($table))
$df = $self::resolveConfiguration();
if (!is_object($db=(is_string($db=($db?:$df['db']))?\Base::instance()->get($db):$db)))
trigger_error(self::E_CONNECTION,E_USER_ERROR);
if (strlen($table=strtolower($table?:$df['table']))==0)
trigger_error(self::E_NO_TABLE,E_USER_ERROR);
if (isset($df) && !empty($df['fieldConf']))
$fields = $df['fieldConf'];
else
$fields = array();
$deletable = array();
$deletable[] = $table;
foreach ($fields as $key => $field) {
$field = static::resolveRelationConf($field);
if (array_key_exists('has-many',$field)) {
if (!is_array($relConf = $field['has-many']))
continue;
$rel = $relConf[0]::resolveConfiguration();
// check if foreign conf matches m:m
if (array_key_exists($relConf[1],$rel['fieldConf']) && !is_null($relConf[1])
&& key($rel['fieldConf'][$relConf[1]]) == 'has-many') {
// compute mm table name
$deletable[] = isset($relConf[2]) ? $relConf[2] :
static::getMMTableName(
$rel['table'], $relConf[1], $table, $key,
$rel['fieldConf'][$relConf[1]]['has-many']);
}
}
}
if($db instanceof Jig) {
/** @var Jig $db */
$dir = $db->dir();
foreach ($deletable as $item)
if(file_exists($dir.$item))
unlink($dir.$item);
} elseif($db instanceof SQL) {
/** @var SQL $db */
$schema = new Schema($db);
$tables = $schema->getTables();
foreach ($deletable as $item)
if(in_array($item, $tables))
$schema->dropTable($item);
} elseif($db instanceof Mongo) {
/** @var Mongo $db */
foreach ($deletable as $item)
$db->selectCollection($item)->drop();
}
} | php | static public function setdown($db=null, $table=null) {
$self = get_called_class();
if (is_null($db) || is_null($table))
$df = $self::resolveConfiguration();
if (!is_object($db=(is_string($db=($db?:$df['db']))?\Base::instance()->get($db):$db)))
trigger_error(self::E_CONNECTION,E_USER_ERROR);
if (strlen($table=strtolower($table?:$df['table']))==0)
trigger_error(self::E_NO_TABLE,E_USER_ERROR);
if (isset($df) && !empty($df['fieldConf']))
$fields = $df['fieldConf'];
else
$fields = array();
$deletable = array();
$deletable[] = $table;
foreach ($fields as $key => $field) {
$field = static::resolveRelationConf($field);
if (array_key_exists('has-many',$field)) {
if (!is_array($relConf = $field['has-many']))
continue;
$rel = $relConf[0]::resolveConfiguration();
// check if foreign conf matches m:m
if (array_key_exists($relConf[1],$rel['fieldConf']) && !is_null($relConf[1])
&& key($rel['fieldConf'][$relConf[1]]) == 'has-many') {
// compute mm table name
$deletable[] = isset($relConf[2]) ? $relConf[2] :
static::getMMTableName(
$rel['table'], $relConf[1], $table, $key,
$rel['fieldConf'][$relConf[1]]['has-many']);
}
}
}
if($db instanceof Jig) {
/** @var Jig $db */
$dir = $db->dir();
foreach ($deletable as $item)
if(file_exists($dir.$item))
unlink($dir.$item);
} elseif($db instanceof SQL) {
/** @var SQL $db */
$schema = new Schema($db);
$tables = $schema->getTables();
foreach ($deletable as $item)
if(in_array($item, $tables))
$schema->dropTable($item);
} elseif($db instanceof Mongo) {
/** @var Mongo $db */
foreach ($deletable as $item)
$db->selectCollection($item)->drop();
}
} | [
"static",
"public",
"function",
"setdown",
"(",
"$",
"db",
"=",
"null",
",",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"self",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"db",
")",
"||",
"is_null",
"(",
"$",
"table",
... | erase all model data, handle with care
@param null $db
@param null $table | [
"erase",
"all",
"model",
"data",
"handle",
"with",
"care"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L421-L471 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.mmTable | protected function mmTable($conf, $key, $fConf=null) {
if (!isset($conf['refTable'])) {
// compute mm table name
$mmTable = isset($conf[2]) ? $conf[2] :
static::getMMTableName($conf['relTable'],
$conf['relField'], $this->table, $key, $fConf);
$this->fieldConf[$key]['has-many']['refTable'] = $mmTable;
} else
$mmTable = $conf['refTable'];
return $mmTable;
} | php | protected function mmTable($conf, $key, $fConf=null) {
if (!isset($conf['refTable'])) {
// compute mm table name
$mmTable = isset($conf[2]) ? $conf[2] :
static::getMMTableName($conf['relTable'],
$conf['relField'], $this->table, $key, $fConf);
$this->fieldConf[$key]['has-many']['refTable'] = $mmTable;
} else
$mmTable = $conf['refTable'];
return $mmTable;
} | [
"protected",
"function",
"mmTable",
"(",
"$",
"conf",
",",
"$",
"key",
",",
"$",
"fConf",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"conf",
"[",
"'refTable'",
"]",
")",
")",
"{",
"// compute mm table name",
"$",
"mmTable",
"=",
"isset... | get mm table name from config
@param array $conf own relation config
@param string $key relation field
@param null|array $fConf optional foreign config
@return string | [
"get",
"mm",
"table",
"name",
"from",
"config"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L508-L518 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.afind | public function afind($filter = NULL, array $options = NULL, $ttl = 0, $rel_depths = 1) {
$result = $this->find($filter, $options, $ttl);
return $result ? $result->castAll($rel_depths): NULL;
} | php | public function afind($filter = NULL, array $options = NULL, $ttl = 0, $rel_depths = 1) {
$result = $this->find($filter, $options, $ttl);
return $result ? $result->castAll($rel_depths): NULL;
} | [
"public",
"function",
"afind",
"(",
"$",
"filter",
"=",
"NULL",
",",
"array",
"$",
"options",
"=",
"NULL",
",",
"$",
"ttl",
"=",
"0",
",",
"$",
"rel_depths",
"=",
"1",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"filter",
... | Return an array of result arrays matching criteria
@param null $filter
@param array $options
@param int $ttl
@param int $rel_depths
@return array | [
"Return",
"an",
"array",
"of",
"result",
"arrays",
"matching",
"criteria"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L588-L591 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.find | public function find($filter = NULL, array $options = NULL, $ttl = 0) {
$sort=false;
if ($this->dbsType!='sql') {
// see if reordering is needed
foreach($this->countFields?:[] as $counter) {
if ($options && isset($options['order']) &&
preg_match('/count_'.$counter.'\h+(asc|desc)/i',$options['order'],$match))
$sort=true;
}
if ($sort) {
// backup slice settings
if (isset($options['limit'])) {
$limit = $options['limit'];
unset($options['limit']);
}
if (isset($options['offset'])) {
$offset = $options['offset'];
unset($options['offset']);
}
}
}
$this->_ttl=$ttl?:$this->rel_ttl;
$result = $this->filteredFind($filter,$options,$ttl);
if (empty($result))
return false;
foreach($result as &$record) {
$record = $this->factory($record);
unset($record);
}
// add counter for NoSQL engines
foreach($this->countFields?:[] as $counter)
foreach($result as &$mapper) {
$cr=$mapper->get($counter);
$mapper->virtual('count_'.$counter,$cr?count($cr):null);
unset($mapper);
}
$cc = new CortexCollection();
$cc->setModels($result);
if($sort) {
$cc->orderBy($options['order']);
$cc->slice(isset($offset)?$offset:0,isset($limit)?$limit:NULL);
}
$this->clearFilter();
return $cc;
} | php | public function find($filter = NULL, array $options = NULL, $ttl = 0) {
$sort=false;
if ($this->dbsType!='sql') {
// see if reordering is needed
foreach($this->countFields?:[] as $counter) {
if ($options && isset($options['order']) &&
preg_match('/count_'.$counter.'\h+(asc|desc)/i',$options['order'],$match))
$sort=true;
}
if ($sort) {
// backup slice settings
if (isset($options['limit'])) {
$limit = $options['limit'];
unset($options['limit']);
}
if (isset($options['offset'])) {
$offset = $options['offset'];
unset($options['offset']);
}
}
}
$this->_ttl=$ttl?:$this->rel_ttl;
$result = $this->filteredFind($filter,$options,$ttl);
if (empty($result))
return false;
foreach($result as &$record) {
$record = $this->factory($record);
unset($record);
}
// add counter for NoSQL engines
foreach($this->countFields?:[] as $counter)
foreach($result as &$mapper) {
$cr=$mapper->get($counter);
$mapper->virtual('count_'.$counter,$cr?count($cr):null);
unset($mapper);
}
$cc = new CortexCollection();
$cc->setModels($result);
if($sort) {
$cc->orderBy($options['order']);
$cc->slice(isset($offset)?$offset:0,isset($limit)?$limit:NULL);
}
$this->clearFilter();
return $cc;
} | [
"public",
"function",
"find",
"(",
"$",
"filter",
"=",
"NULL",
",",
"array",
"$",
"options",
"=",
"NULL",
",",
"$",
"ttl",
"=",
"0",
")",
"{",
"$",
"sort",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"dbsType",
"!=",
"'sql'",
")",
"{",
"//... | Return an array of objects matching criteria
@param array|null $filter
@param array|null $options
@param int $ttl
@return CortexCollection | [
"Return",
"an",
"array",
"of",
"objects",
"matching",
"criteria"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L600-L644 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.load | public function load($filter = NULL, array $options = NULL, $ttl = 0) {
$this->reset();
$this->_ttl=$ttl?:$this->rel_ttl;
$res = $this->filteredFind($filter, $options, $ttl);
if ($res) {
$this->mapper->query = $res;
$this->first();
} else
$this->mapper->reset();
$this->emit('load');
return $this->valid();
} | php | public function load($filter = NULL, array $options = NULL, $ttl = 0) {
$this->reset();
$this->_ttl=$ttl?:$this->rel_ttl;
$res = $this->filteredFind($filter, $options, $ttl);
if ($res) {
$this->mapper->query = $res;
$this->first();
} else
$this->mapper->reset();
$this->emit('load');
return $this->valid();
} | [
"public",
"function",
"load",
"(",
"$",
"filter",
"=",
"NULL",
",",
"array",
"$",
"options",
"=",
"NULL",
",",
"$",
"ttl",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"this",
"->",
"_ttl",
"=",
"$",
"ttl",
"?",
":",
"$... | Retrieve first object that satisfies criteria
@param null $filter
@param array $options
@param int $ttl
@return bool | [
"Retrieve",
"first",
"object",
"that",
"satisfies",
"criteria"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L903-L914 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.has | public function has($key, $filter, $options = null) {
if (is_string($filter))
$filter=array($filter);
if (is_int(strpos($key,'.'))) {
list($key,$fkey) = explode('.',$key,2);
if (!isset($this->hasCond[$key.'.']))
$this->hasCond[$key.'.'] = array();
$this->hasCond[$key.'.'][$fkey] = array($filter,$options);
} else {
if (!isset($this->fieldConf[$key]))
trigger_error(sprintf(self::E_UNKNOWN_FIELD,$key,get_called_class()),E_USER_ERROR);
if (!isset($this->fieldConf[$key]['relType']))
trigger_error(self::E_HAS_COND,E_USER_ERROR);
$this->hasCond[$key] = array($filter,$options);
}
return $this;
} | php | public function has($key, $filter, $options = null) {
if (is_string($filter))
$filter=array($filter);
if (is_int(strpos($key,'.'))) {
list($key,$fkey) = explode('.',$key,2);
if (!isset($this->hasCond[$key.'.']))
$this->hasCond[$key.'.'] = array();
$this->hasCond[$key.'.'][$fkey] = array($filter,$options);
} else {
if (!isset($this->fieldConf[$key]))
trigger_error(sprintf(self::E_UNKNOWN_FIELD,$key,get_called_class()),E_USER_ERROR);
if (!isset($this->fieldConf[$key]['relType']))
trigger_error(self::E_HAS_COND,E_USER_ERROR);
$this->hasCond[$key] = array($filter,$options);
}
return $this;
} | [
"public",
"function",
"has",
"(",
"$",
"key",
",",
"$",
"filter",
",",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"filter",
")",
")",
"$",
"filter",
"=",
"array",
"(",
"$",
"filter",
")",
";",
"if",
"(",
"is_int",
... | add has-conditional filter to next find call
@param string $key
@param array $filter
@param null $options
@return $this | [
"add",
"has",
"-",
"conditional",
"filter",
"to",
"next",
"find",
"call"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L923-L939 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._hasRefsIn | protected function _hasRefsIn($key, $filter, $options, $ttl = 0) {
$type = $this->fieldConf[$key]['relType'];
$fieldConf = $this->fieldConf[$key][$type];
// one-to-many shortcut
$rel = $this->getRelFromConf($fieldConf,$key);
$hasSet = $rel->find($filter, $options, $ttl);
if (!$hasSet)
return false;
$hasSetByRelId = array_unique($hasSet->getAll($fieldConf[1], true));
return empty($hasSetByRelId) ? false : $hasSetByRelId;
} | php | protected function _hasRefsIn($key, $filter, $options, $ttl = 0) {
$type = $this->fieldConf[$key]['relType'];
$fieldConf = $this->fieldConf[$key][$type];
// one-to-many shortcut
$rel = $this->getRelFromConf($fieldConf,$key);
$hasSet = $rel->find($filter, $options, $ttl);
if (!$hasSet)
return false;
$hasSetByRelId = array_unique($hasSet->getAll($fieldConf[1], true));
return empty($hasSetByRelId) ? false : $hasSetByRelId;
} | [
"protected",
"function",
"_hasRefsIn",
"(",
"$",
"key",
",",
"$",
"filter",
",",
"$",
"options",
",",
"$",
"ttl",
"=",
"0",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"fieldConf",
"[",
"$",
"key",
"]",
"[",
"'relType'",
"]",
";",
"$",
"fieldC... | return IDs of records that has a linkage to this mapper
@param string $key relation field
@param array $filter condition for foreign records
@param array $options filter options for foreign records
@param int $ttl
@return array|false | [
"return",
"IDs",
"of",
"records",
"that",
"has",
"a",
"linkage",
"to",
"this",
"mapper"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L949-L959 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._refSubQuery | protected function _refSubQuery($key, $filter, $options,$fields=null) {
$type = $this->fieldConf[$key]['relType'];
$fieldConf = $this->fieldConf[$key][$type];
$rel = $this->getRelFromConf($fieldConf,$key);
$filter[0]=$this->queryParser->sql_quoteCondition($filter[0],$this->db);
return $rel->mapper->stringify(implode(',',array_map([$this->db,'quotekey'],
$fields?:[$rel->primary])),$filter,$options);
} | php | protected function _refSubQuery($key, $filter, $options,$fields=null) {
$type = $this->fieldConf[$key]['relType'];
$fieldConf = $this->fieldConf[$key][$type];
$rel = $this->getRelFromConf($fieldConf,$key);
$filter[0]=$this->queryParser->sql_quoteCondition($filter[0],$this->db);
return $rel->mapper->stringify(implode(',',array_map([$this->db,'quotekey'],
$fields?:[$rel->primary])),$filter,$options);
} | [
"protected",
"function",
"_refSubQuery",
"(",
"$",
"key",
",",
"$",
"filter",
",",
"$",
"options",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"fieldConf",
"[",
"$",
"key",
"]",
"[",
"'relType'",
"]",
";",
"$",
... | build sub query on relation
@param $key
@param $filter
@param $options
@return mixed | [
"build",
"sub",
"query",
"on",
"relation"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L968-L975 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._hasRefsInMM | protected function _hasRefsInMM($key, $filter, $options, $ttl=0) {
$fieldConf = $this->fieldConf[$key]['has-many'];
$rel = $this->getRelInstance($fieldConf[0],null,$key,true);
$hasSet = $rel->find($filter,$options,$ttl);
$result = false;
if ($hasSet) {
$hasIDs = $hasSet->getAll('_id',true);
$mmTable = $this->mmTable($fieldConf,$key);
$pivot = $this->getRelInstance(null,array('db'=>$this->db,'table'=>$mmTable));
$filter = [$key.' IN ?',$hasIDs];
if ($fieldConf['isSelf']) {
$filter[0].= ' OR '.$key.'_ref IN ?';
$filter[] = $hasIDs;
}
$pivotSet = $pivot->find($filter,null,$ttl);
if ($pivotSet) {
$result = $pivotSet->getAll($fieldConf['relField'],true);
if ($fieldConf['isSelf'])
$result = array_merge($result,
$pivotSet->getAll($fieldConf['relField'].'_ref',true));
$result = array_diff(array_unique($result),$hasIDs);
}
}
return $result;
} | php | protected function _hasRefsInMM($key, $filter, $options, $ttl=0) {
$fieldConf = $this->fieldConf[$key]['has-many'];
$rel = $this->getRelInstance($fieldConf[0],null,$key,true);
$hasSet = $rel->find($filter,$options,$ttl);
$result = false;
if ($hasSet) {
$hasIDs = $hasSet->getAll('_id',true);
$mmTable = $this->mmTable($fieldConf,$key);
$pivot = $this->getRelInstance(null,array('db'=>$this->db,'table'=>$mmTable));
$filter = [$key.' IN ?',$hasIDs];
if ($fieldConf['isSelf']) {
$filter[0].= ' OR '.$key.'_ref IN ?';
$filter[] = $hasIDs;
}
$pivotSet = $pivot->find($filter,null,$ttl);
if ($pivotSet) {
$result = $pivotSet->getAll($fieldConf['relField'],true);
if ($fieldConf['isSelf'])
$result = array_merge($result,
$pivotSet->getAll($fieldConf['relField'].'_ref',true));
$result = array_diff(array_unique($result),$hasIDs);
}
}
return $result;
} | [
"protected",
"function",
"_hasRefsInMM",
"(",
"$",
"key",
",",
"$",
"filter",
",",
"$",
"options",
",",
"$",
"ttl",
"=",
"0",
")",
"{",
"$",
"fieldConf",
"=",
"$",
"this",
"->",
"fieldConf",
"[",
"$",
"key",
"]",
"[",
"'has-many'",
"]",
";",
"$",
... | return IDs of own mappers that match the given relation filter on pivot tables
@param string $key
@param array $filter
@param array $options
@param int $ttl
@return array|false | [
"return",
"IDs",
"of",
"own",
"mappers",
"that",
"match",
"the",
"given",
"relation",
"filter",
"on",
"pivot",
"tables"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L985-L1009 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._hasJoinMM_sql | protected function _hasJoinMM_sql($key, $hasCond, &$filter, &$options) {
$fieldConf = $this->fieldConf[$key]['has-many'];
$relTable = $fieldConf['relTable'];
$hasJoin = array();
$mmTable = $this->mmTable($fieldConf,$key);
if ($fieldConf['isSelf']) {
$relTable .= '_ref';
$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'].'_ref',$mmTable);
$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],
[$fieldConf['relTable'],$relTable]);
// cross-linked
$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,
$fieldConf['relField'],[$mmTable,$mmTable.'_c']);
$hasJoin[] = $this->_sql_left_join($key.'_ref',$mmTable.'_c',$fieldConf['relPK'],
[$fieldConf['relTable'],$relTable.'_c']);
$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
$this->_sql_mergeRelCondition($hasCond,$relTable.'_c',$filter,$options,'OR');
} else {
$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'],$mmTable);
$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],$relTable);
$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
}
return $hasJoin;
} | php | protected function _hasJoinMM_sql($key, $hasCond, &$filter, &$options) {
$fieldConf = $this->fieldConf[$key]['has-many'];
$relTable = $fieldConf['relTable'];
$hasJoin = array();
$mmTable = $this->mmTable($fieldConf,$key);
if ($fieldConf['isSelf']) {
$relTable .= '_ref';
$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'].'_ref',$mmTable);
$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],
[$fieldConf['relTable'],$relTable]);
// cross-linked
$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,
$fieldConf['relField'],[$mmTable,$mmTable.'_c']);
$hasJoin[] = $this->_sql_left_join($key.'_ref',$mmTable.'_c',$fieldConf['relPK'],
[$fieldConf['relTable'],$relTable.'_c']);
$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
$this->_sql_mergeRelCondition($hasCond,$relTable.'_c',$filter,$options,'OR');
} else {
$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'],$mmTable);
$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],$relTable);
$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
}
return $hasJoin;
} | [
"protected",
"function",
"_hasJoinMM_sql",
"(",
"$",
"key",
",",
"$",
"hasCond",
",",
"&",
"$",
"filter",
",",
"&",
"$",
"options",
")",
"{",
"$",
"fieldConf",
"=",
"$",
"this",
"->",
"fieldConf",
"[",
"$",
"key",
"]",
"[",
"'has-many'",
"]",
";",
... | build query for SQL pivot table join and merge conditions | [
"build",
"query",
"for",
"SQL",
"pivot",
"table",
"join",
"and",
"merge",
"conditions"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1014-L1037 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._hasJoin_sql | protected function _hasJoin_sql($key, $table, $cond, &$filter, &$options) {
$relConf = $this->fieldConf[$key]['belongs-to-one'];
$relModel = is_array($relConf)?$relConf[0]:$relConf;
$rel = $this->getRelInstance($relModel,null,$key);
$fkey = is_array($this->fieldConf[$key]['belongs-to-one']) ?
$this->fieldConf[$key]['belongs-to-one'][1] : $rel->primary;
$alias = $table.'__'.$key;
$query = $this->_sql_left_join($key,$this->table,$fkey,[$table,$alias]);
$this->_sql_mergeRelCondition($cond,$alias,$filter,$options);
return $query;
} | php | protected function _hasJoin_sql($key, $table, $cond, &$filter, &$options) {
$relConf = $this->fieldConf[$key]['belongs-to-one'];
$relModel = is_array($relConf)?$relConf[0]:$relConf;
$rel = $this->getRelInstance($relModel,null,$key);
$fkey = is_array($this->fieldConf[$key]['belongs-to-one']) ?
$this->fieldConf[$key]['belongs-to-one'][1] : $rel->primary;
$alias = $table.'__'.$key;
$query = $this->_sql_left_join($key,$this->table,$fkey,[$table,$alias]);
$this->_sql_mergeRelCondition($cond,$alias,$filter,$options);
return $query;
} | [
"protected",
"function",
"_hasJoin_sql",
"(",
"$",
"key",
",",
"$",
"table",
",",
"$",
"cond",
",",
"&",
"$",
"filter",
",",
"&",
"$",
"options",
")",
"{",
"$",
"relConf",
"=",
"$",
"this",
"->",
"fieldConf",
"[",
"$",
"key",
"]",
"[",
"'belongs-to... | build query for single SQL table join and merge conditions | [
"build",
"query",
"for",
"single",
"SQL",
"table",
"join",
"and",
"merge",
"conditions"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1042-L1052 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._sql_left_join | protected function _sql_left_join($skey, $sTable, $fkey, $fTable) {
if (is_array($fTable))
list($fTable,$fTable_alias) = $fTable;
$skey = $this->db->quotekey($skey);
$sTable = $this->db->quotekey($sTable);
$fkey = $this->db->quotekey($fkey);
$fTable = $this->db->quotekey($fTable);
if (isset($fTable_alias)) {
$fTable_alias = $this->db->quotekey($fTable_alias);
return 'LEFT JOIN '.$fTable.' AS '.$fTable_alias.' ON '.$sTable.'.'.$skey.' = '.$fTable_alias.'.'.$fkey;
} else
return 'LEFT JOIN '.$fTable.' ON '.$sTable.'.'.$skey.' = '.$fTable.'.'.$fkey;
} | php | protected function _sql_left_join($skey, $sTable, $fkey, $fTable) {
if (is_array($fTable))
list($fTable,$fTable_alias) = $fTable;
$skey = $this->db->quotekey($skey);
$sTable = $this->db->quotekey($sTable);
$fkey = $this->db->quotekey($fkey);
$fTable = $this->db->quotekey($fTable);
if (isset($fTable_alias)) {
$fTable_alias = $this->db->quotekey($fTable_alias);
return 'LEFT JOIN '.$fTable.' AS '.$fTable_alias.' ON '.$sTable.'.'.$skey.' = '.$fTable_alias.'.'.$fkey;
} else
return 'LEFT JOIN '.$fTable.' ON '.$sTable.'.'.$skey.' = '.$fTable.'.'.$fkey;
} | [
"protected",
"function",
"_sql_left_join",
"(",
"$",
"skey",
",",
"$",
"sTable",
",",
"$",
"fkey",
",",
"$",
"fTable",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fTable",
")",
")",
"list",
"(",
"$",
"fTable",
",",
"$",
"fTable_alias",
")",
"=",
"$... | assemble SQL join query string
@param string $skey
@param string $sTable
@param string $fkey
@param string|array $fTable
@return string | [
"assemble",
"SQL",
"join",
"query",
"string"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1062-L1074 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._sql_mergeRelCondition | protected function _sql_mergeRelCondition($cond, $table, &$filter, &$options, $glue='AND') {
if (!empty($cond[0])) {
$whereClause = '('.array_shift($cond[0]).')';
$whereClause = $this->queryParser->sql_prependTableToFields($whereClause,$table);
if (!$filter)
$filter = array($whereClause);
elseif (!empty($filter[0]))
$filter[0] = '('.$this->queryParser->sql_prependTableToFields($filter[0],$this->table)
.') '.$glue.' '.$whereClause;
$filter = array_merge($filter, $cond[0]);
}
if ($cond[1] && isset($cond[1]['group'])) {
$hasGroup = preg_replace('/(\w+)/i', $table.'.$1', $cond[1]['group']);
$options['group'] .= ','.$hasGroup;
}
} | php | protected function _sql_mergeRelCondition($cond, $table, &$filter, &$options, $glue='AND') {
if (!empty($cond[0])) {
$whereClause = '('.array_shift($cond[0]).')';
$whereClause = $this->queryParser->sql_prependTableToFields($whereClause,$table);
if (!$filter)
$filter = array($whereClause);
elseif (!empty($filter[0]))
$filter[0] = '('.$this->queryParser->sql_prependTableToFields($filter[0],$this->table)
.') '.$glue.' '.$whereClause;
$filter = array_merge($filter, $cond[0]);
}
if ($cond[1] && isset($cond[1]['group'])) {
$hasGroup = preg_replace('/(\w+)/i', $table.'.$1', $cond[1]['group']);
$options['group'] .= ','.$hasGroup;
}
} | [
"protected",
"function",
"_sql_mergeRelCondition",
"(",
"$",
"cond",
",",
"$",
"table",
",",
"&",
"$",
"filter",
",",
"&",
"$",
"options",
",",
"$",
"glue",
"=",
"'AND'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"cond",
"[",
"0",
"]",
")",
")... | merge condition of relation with current condition
@param array $cond condition of related model
@param string $table table of related model
@param array $filter current filter to merge with
@param array $options current options to merge with
@param string $glue | [
"merge",
"condition",
"of",
"relation",
"with",
"current",
"condition"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1084-L1099 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.filter | public function filter($key, $filter=null, $option=null) {
if (is_int(strpos($key,'.'))) {
list($key,$fkey) = explode('.',$key,2);
if (!isset($this->relFilter[$key.'.']))
$this->relFilter[$key.'.'] = array();
$this->relFilter[$key.'.'][$fkey] = array($filter,$option);
} else
$this->relFilter[$key] = array($filter,$option);
return $this;
} | php | public function filter($key, $filter=null, $option=null) {
if (is_int(strpos($key,'.'))) {
list($key,$fkey) = explode('.',$key,2);
if (!isset($this->relFilter[$key.'.']))
$this->relFilter[$key.'.'] = array();
$this->relFilter[$key.'.'][$fkey] = array($filter,$option);
} else
$this->relFilter[$key] = array($filter,$option);
return $this;
} | [
"public",
"function",
"filter",
"(",
"$",
"key",
",",
"$",
"filter",
"=",
"null",
",",
"$",
"option",
"=",
"null",
")",
"{",
"if",
"(",
"is_int",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
")",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$... | add filter for loading related models
@param string $key
@param array $filter
@param array $option
@return $this | [
"add",
"filter",
"for",
"loading",
"related",
"models"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1108-L1117 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.clearFilter | public function clearFilter($key = null) {
if (!$key)
$this->relFilter = array();
elseif(isset($this->relFilter[$key]))
unset($this->relFilter[$key]);
} | php | public function clearFilter($key = null) {
if (!$key)
$this->relFilter = array();
elseif(isset($this->relFilter[$key]))
unset($this->relFilter[$key]);
} | [
"public",
"function",
"clearFilter",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"key",
")",
"$",
"this",
"->",
"relFilter",
"=",
"array",
"(",
")",
";",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"relFilter",
"[",
"$",
"key... | removes one or all relation filter
@param null|string $key | [
"removes",
"one",
"or",
"all",
"relation",
"filter"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1123-L1128 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.mergeWithRelFilter | protected function mergeWithRelFilter($key, $crit) {
if (array_key_exists($key, $this->relFilter) &&
!empty($this->relFilter[$key][0]))
$crit=$this->mergeFilter(array($this->relFilter[$key][0],$crit));
return $crit;
} | php | protected function mergeWithRelFilter($key, $crit) {
if (array_key_exists($key, $this->relFilter) &&
!empty($this->relFilter[$key][0]))
$crit=$this->mergeFilter(array($this->relFilter[$key][0],$crit));
return $crit;
} | [
"protected",
"function",
"mergeWithRelFilter",
"(",
"$",
"key",
",",
"$",
"crit",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"relFilter",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"relFilter",
"[",
"$",
"... | merge the relation filter to the query criteria if it exists
@param string $key
@param array $crit
@return array | [
"merge",
"the",
"relation",
"filter",
"to",
"the",
"query",
"criteria",
"if",
"it",
"exists"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1136-L1141 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.mergeFilter | public function mergeFilter($filters, $glue='and') {
$crit = array();
$params = array();
if ($filters) {
foreach($filters as $filter) {
$crit[] = array_shift($filter);
$params = array_merge($params,$filter);
}
array_unshift($params,'( '.implode(' ) '.$glue.' ( ',$crit).' )');
}
return $params;
} | php | public function mergeFilter($filters, $glue='and') {
$crit = array();
$params = array();
if ($filters) {
foreach($filters as $filter) {
$crit[] = array_shift($filter);
$params = array_merge($params,$filter);
}
array_unshift($params,'( '.implode(' ) '.$glue.' ( ',$crit).' )');
}
return $params;
} | [
"public",
"function",
"mergeFilter",
"(",
"$",
"filters",
",",
"$",
"glue",
"=",
"'and'",
")",
"{",
"$",
"crit",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"filters",
")",
"{",
"foreach",
"(",
"$",
... | merge multiple filters
@param array $filters
@param string $glue
@return array | [
"merge",
"multiple",
"filters"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1149-L1160 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.getRelFilterOption | protected function getRelFilterOption($key) {
return (array_key_exists($key, $this->relFilter) &&
!empty($this->relFilter[$key][1]))
? $this->relFilter[$key][1] : null;
} | php | protected function getRelFilterOption($key) {
return (array_key_exists($key, $this->relFilter) &&
!empty($this->relFilter[$key][1]))
? $this->relFilter[$key][1] : null;
} | [
"protected",
"function",
"getRelFilterOption",
"(",
"$",
"key",
")",
"{",
"return",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"relFilter",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"relFilter",
"[",
"$",
"key",
"]",
"[",
... | returns the option condition for a relation filter, if defined
@param string $key
@return array null | [
"returns",
"the",
"option",
"condition",
"for",
"a",
"relation",
"filter",
"if",
"defined"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1167-L1171 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex._mongo_addGroup | protected function _mongo_addGroup($opt) {
if (!$this->grp_stack)
$this->grp_stack = array('keys'=>array(),'initial'=>array(),'reduce'=>'','finalize'=>'');
if (isset($opt['keys']))
$this->grp_stack['keys']+=$opt['keys'];
if (isset($opt['reduce']))
$this->grp_stack['reduce'].=$opt['reduce'];
if (isset($opt['initial']))
$this->grp_stack['initial']+=$opt['initial'];
if (isset($opt['finalize']))
$this->grp_stack['finalize'].=$opt['finalize'];
} | php | protected function _mongo_addGroup($opt) {
if (!$this->grp_stack)
$this->grp_stack = array('keys'=>array(),'initial'=>array(),'reduce'=>'','finalize'=>'');
if (isset($opt['keys']))
$this->grp_stack['keys']+=$opt['keys'];
if (isset($opt['reduce']))
$this->grp_stack['reduce'].=$opt['reduce'];
if (isset($opt['initial']))
$this->grp_stack['initial']+=$opt['initial'];
if (isset($opt['finalize']))
$this->grp_stack['finalize'].=$opt['finalize'];
} | [
"protected",
"function",
"_mongo_addGroup",
"(",
"$",
"opt",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"grp_stack",
")",
"$",
"this",
"->",
"grp_stack",
"=",
"array",
"(",
"'keys'",
"=>",
"array",
"(",
")",
",",
"'initial'",
"=>",
"array",
"(",
")... | merge mongo group options array
@param $opt | [
"merge",
"mongo",
"group",
"options",
"array"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1425-L1436 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.touch | public function touch($key) {
if (isset($this->fieldConf[$key])
&& isset($this->fieldConf[$key]['type'])) {
$type = $this->fieldConf[$key]['type'];
$date = ($this->dbsType=='sql' && preg_match('/mssql|sybase|dblib|odbc|sqlsrv/',
$this->db->driver())) ? 'Ymd' : 'Y-m-d';
if ($type == Schema::DT_DATETIME || $type == Schema::DT_TIMESTAMP)
$this->set($key,date($date.' H:i:s'));
elseif ($type == Schema::DT_DATE)
$this->set($key,date($date));
elseif ($type == Schema::DT_INT4)
$this->set($key,time());
}
} | php | public function touch($key) {
if (isset($this->fieldConf[$key])
&& isset($this->fieldConf[$key]['type'])) {
$type = $this->fieldConf[$key]['type'];
$date = ($this->dbsType=='sql' && preg_match('/mssql|sybase|dblib|odbc|sqlsrv/',
$this->db->driver())) ? 'Ymd' : 'Y-m-d';
if ($type == Schema::DT_DATETIME || $type == Schema::DT_TIMESTAMP)
$this->set($key,date($date.' H:i:s'));
elseif ($type == Schema::DT_DATE)
$this->set($key,date($date));
elseif ($type == Schema::DT_INT4)
$this->set($key,time());
}
} | [
"public",
"function",
"touch",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fieldConf",
"[",
"$",
"key",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"fieldConf",
"[",
"$",
"key",
"]",
"[",
"'type'",
"]",
")",
")"... | update a given date or time field with the current time
@param string $key | [
"update",
"a",
"given",
"date",
"or",
"time",
"field",
"with",
"the",
"current",
"time"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1442-L1455 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.emit | protected function emit($event, $val=null) {
if (isset($this->trigger[$event])) {
if (preg_match('/^[sg]et_/',$event)) {
$val = (is_string($f=$this->trigger[$event])
&& preg_match('/^[sg]et_/',$f))
? call_user_func(array($this,$event),$val)
: \Base::instance()->call($f,array($this,$val));
} else
$val = \Base::instance()->call($this->trigger[$event],array($this,$val));
} elseif (preg_match('/^[sg]et_/',$event) && method_exists($this,$event)) {
$this->trigger[] = $event;
$val = call_user_func(array($this,$event),$val);
}
return $val;
} | php | protected function emit($event, $val=null) {
if (isset($this->trigger[$event])) {
if (preg_match('/^[sg]et_/',$event)) {
$val = (is_string($f=$this->trigger[$event])
&& preg_match('/^[sg]et_/',$f))
? call_user_func(array($this,$event),$val)
: \Base::instance()->call($f,array($this,$val));
} else
$val = \Base::instance()->call($this->trigger[$event],array($this,$val));
} elseif (preg_match('/^[sg]et_/',$event) && method_exists($this,$event)) {
$this->trigger[] = $event;
$val = call_user_func(array($this,$event),$val);
}
return $val;
} | [
"protected",
"function",
"emit",
"(",
"$",
"event",
",",
"$",
"val",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"trigger",
"[",
"$",
"event",
"]",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^[sg]et_/'",
",",
"$",
"eve... | call custom field handlers
@param $event
@param $val
@return mixed | [
"call",
"custom",
"field",
"handlers"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1604-L1618 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.virtual | public function virtual($key, $val) {
$this->vFields[$key]=$val;
if (!empty($this->whitelist)) {
$this->whitelist[] = $key;
$this->whitelist = array_unique($this->whitelist);
}
} | php | public function virtual($key, $val) {
$this->vFields[$key]=$val;
if (!empty($this->whitelist)) {
$this->whitelist[] = $key;
$this->whitelist = array_unique($this->whitelist);
}
} | [
"public",
"function",
"virtual",
"(",
"$",
"key",
",",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"vFields",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"whitelist",
")",
")",
"{",
"$",
"this",
"... | virtual mapper field setter
@param string $key
@param mixed|callback $val | [
"virtual",
"mapper",
"field",
"setter"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1643-L1649 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.getForeignKeysArray | protected function getForeignKeysArray($val, $rel_field, $key) {
if (is_null($val))
return NULL;
if (is_object($val) && $val instanceof CortexCollection)
$val = $val->getAll($rel_field,true);
elseif (is_string($val))
// split-able string of collection IDs
$val = \Base::instance()->split($val);
elseif (!is_array($val) && !(is_object($val)
&& ($val instanceof Cortex && !$val->dry())))
trigger_error(sprintf(self::E_MM_REL_VALUE, $key),E_USER_ERROR);
// hydrated mapper as collection
if (is_object($val)) {
$nval = array();
while (!$val->dry()) {
$nval[] = $val->get($rel_field,true);
$val->next();
}
$val = $nval;
}
elseif (is_array($val)) {
// array of single hydrated mappers, raw ID value or mixed
$isMongo = ($this->dbsType == 'mongo');
foreach ($val as &$item) {
if (is_object($item) &&
!($isMongo && (($this->db->legacy() && $item instanceof \MongoId) ||
(!$this->db->legacy() && $item instanceof \MongoDB\BSON\ObjectId)))) {
if (!$item instanceof Cortex || $item->dry())
trigger_error(self::E_INVALID_RELATION_OBJECT,E_USER_ERROR);
else $item = $item->get($rel_field,true);
}
if ($isMongo && $rel_field == '_id' && is_string($item))
$item = $this->db->legacy() ? new \MongoId($item) : new \MongoDB\BSON\ObjectId($item);
if (is_numeric($item))
$item = (int) $item;
unset($item);
}
}
return $val;
} | php | protected function getForeignKeysArray($val, $rel_field, $key) {
if (is_null($val))
return NULL;
if (is_object($val) && $val instanceof CortexCollection)
$val = $val->getAll($rel_field,true);
elseif (is_string($val))
// split-able string of collection IDs
$val = \Base::instance()->split($val);
elseif (!is_array($val) && !(is_object($val)
&& ($val instanceof Cortex && !$val->dry())))
trigger_error(sprintf(self::E_MM_REL_VALUE, $key),E_USER_ERROR);
// hydrated mapper as collection
if (is_object($val)) {
$nval = array();
while (!$val->dry()) {
$nval[] = $val->get($rel_field,true);
$val->next();
}
$val = $nval;
}
elseif (is_array($val)) {
// array of single hydrated mappers, raw ID value or mixed
$isMongo = ($this->dbsType == 'mongo');
foreach ($val as &$item) {
if (is_object($item) &&
!($isMongo && (($this->db->legacy() && $item instanceof \MongoId) ||
(!$this->db->legacy() && $item instanceof \MongoDB\BSON\ObjectId)))) {
if (!$item instanceof Cortex || $item->dry())
trigger_error(self::E_INVALID_RELATION_OBJECT,E_USER_ERROR);
else $item = $item->get($rel_field,true);
}
if ($isMongo && $rel_field == '_id' && is_string($item))
$item = $this->db->legacy() ? new \MongoId($item) : new \MongoDB\BSON\ObjectId($item);
if (is_numeric($item))
$item = (int) $item;
unset($item);
}
}
return $val;
} | [
"protected",
"function",
"getForeignKeysArray",
"(",
"$",
"val",
",",
"$",
"rel_field",
",",
"$",
"key",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"val",
")",
")",
"return",
"NULL",
";",
"if",
"(",
"is_object",
"(",
"$",
"val",
")",
"&&",
"$",
"val... | find the ID values of given relation collection
@param $val string|array|object|bool
@param $rel_field string
@param $key string
@return array|Cortex|null|object | [
"find",
"the",
"ID",
"values",
"of",
"given",
"relation",
"collection"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L1953-L1992 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.getRelInstance | protected function getRelInstance($model=null, $relConf=null, $key='', $pushFilter=false) {
if (!$model && !$relConf)
trigger_error(self::E_MISSING_REL_CONF,E_USER_ERROR);
$relConf = $model ? $model::resolveConfiguration() : $relConf;
$relName = ($model?:'Cortex').'\\'.$relConf['db']->uuid().
'\\'.$relConf['table'].'\\'.$key;
if (\Registry::exists($relName)) {
$rel = \Registry::get($relName);
$rel->reset();
} else {
$rel = $model ? new $model : new Cortex($relConf['db'], $relConf['table']);
if (!$rel instanceof Cortex)
trigger_error(self::E_WRONG_RELATION_CLASS,E_USER_ERROR);
\Registry::set($relName, $rel);
}
// restrict fields of related mapper
if(!empty($key) && isset($this->relWhitelist[$key])) {
if (isset($this->relWhitelist[$key][0]))
$rel->fields($this->relWhitelist[$key][0],false);
if (isset($this->relWhitelist[$key][1]))
$rel->fields($this->relWhitelist[$key][1],true);
}
if ($pushFilter && !empty($key)) {
if (isset($this->relFilter[$key.'.'])) {
foreach($this->relFilter[$key.'.'] as $fkey=>$conf)
$rel->filter($fkey,$conf[0],$conf[1]);
}
if (isset($this->hasCond[$key.'.'])) {
foreach($this->hasCond[$key.'.'] as $fkey=>$conf)
$rel->has($fkey,$conf[0],$conf[1]);
}
}
return $rel;
} | php | protected function getRelInstance($model=null, $relConf=null, $key='', $pushFilter=false) {
if (!$model && !$relConf)
trigger_error(self::E_MISSING_REL_CONF,E_USER_ERROR);
$relConf = $model ? $model::resolveConfiguration() : $relConf;
$relName = ($model?:'Cortex').'\\'.$relConf['db']->uuid().
'\\'.$relConf['table'].'\\'.$key;
if (\Registry::exists($relName)) {
$rel = \Registry::get($relName);
$rel->reset();
} else {
$rel = $model ? new $model : new Cortex($relConf['db'], $relConf['table']);
if (!$rel instanceof Cortex)
trigger_error(self::E_WRONG_RELATION_CLASS,E_USER_ERROR);
\Registry::set($relName, $rel);
}
// restrict fields of related mapper
if(!empty($key) && isset($this->relWhitelist[$key])) {
if (isset($this->relWhitelist[$key][0]))
$rel->fields($this->relWhitelist[$key][0],false);
if (isset($this->relWhitelist[$key][1]))
$rel->fields($this->relWhitelist[$key][1],true);
}
if ($pushFilter && !empty($key)) {
if (isset($this->relFilter[$key.'.'])) {
foreach($this->relFilter[$key.'.'] as $fkey=>$conf)
$rel->filter($fkey,$conf[0],$conf[1]);
}
if (isset($this->hasCond[$key.'.'])) {
foreach($this->hasCond[$key.'.'] as $fkey=>$conf)
$rel->has($fkey,$conf[0],$conf[1]);
}
}
return $rel;
} | [
"protected",
"function",
"getRelInstance",
"(",
"$",
"model",
"=",
"null",
",",
"$",
"relConf",
"=",
"null",
",",
"$",
"key",
"=",
"''",
",",
"$",
"pushFilter",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"&&",
"!",
"$",
"relConf",
")",
... | creates and caches related mapper objects
@param string $model
@param array $relConf
@param string $key
@param bool $pushFilter
@return Cortex | [
"creates",
"and",
"caches",
"related",
"mapper",
"objects"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L2002-L2035 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.getRelFromConf | protected function getRelFromConf(&$relConf, $key) {
if (!is_array($relConf))
$relConf = array($relConf, '_id');
$rel = $this->getRelInstance($relConf[0],null,$key,true);
if($this->dbsType=='sql' && $relConf[1] == '_id')
$relConf[1] = $rel->primary;
return $rel;
} | php | protected function getRelFromConf(&$relConf, $key) {
if (!is_array($relConf))
$relConf = array($relConf, '_id');
$rel = $this->getRelInstance($relConf[0],null,$key,true);
if($this->dbsType=='sql' && $relConf[1] == '_id')
$relConf[1] = $rel->primary;
return $rel;
} | [
"protected",
"function",
"getRelFromConf",
"(",
"&",
"$",
"relConf",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"relConf",
")",
")",
"$",
"relConf",
"=",
"array",
"(",
"$",
"relConf",
",",
"'_id'",
")",
";",
"$",
"rel",
"=",
... | get relation model from config
@param $relConf
@param $key
@return Cortex | [
"get",
"relation",
"model",
"from",
"config"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L2043-L2050 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.castField | function castField($key, $rel_depths=0) {
if (!$key)
return NULL;
$mapper_arr = $this->get($key);
if(!$mapper_arr)
return NULL;
$out = array();
foreach ($mapper_arr as $mp)
$out[] = $mp->cast(null,$rel_depths);
return $out;
} | php | function castField($key, $rel_depths=0) {
if (!$key)
return NULL;
$mapper_arr = $this->get($key);
if(!$mapper_arr)
return NULL;
$out = array();
foreach ($mapper_arr as $mp)
$out[] = $mp->cast(null,$rel_depths);
return $out;
} | [
"function",
"castField",
"(",
"$",
"key",
",",
"$",
"rel_depths",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"key",
")",
"return",
"NULL",
";",
"$",
"mapper_arr",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"m... | cast a related collection of mappers
@param string $key field name
@param int $rel_depths depths to resolve relations
@return array array of associative arrays | [
"cast",
"a",
"related",
"collection",
"of",
"mappers"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L2138-L2148 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.factory | protected function factory($mapper) {
if (is_array($mapper)) {
$mp = clone($this->mapper);
$mp->reset();
$cx = $this->factory($mp);
$cx->copyfrom($mapper);
} else {
$cx = clone($this);
$cx->reset(false);
$cx->mapper = $mapper;
}
$cx->emit('load');
return $cx;
} | php | protected function factory($mapper) {
if (is_array($mapper)) {
$mp = clone($this->mapper);
$mp->reset();
$cx = $this->factory($mp);
$cx->copyfrom($mapper);
} else {
$cx = clone($this);
$cx->reset(false);
$cx->mapper = $mapper;
}
$cx->emit('load');
return $cx;
} | [
"protected",
"function",
"factory",
"(",
"$",
"mapper",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mapper",
")",
")",
"{",
"$",
"mp",
"=",
"clone",
"(",
"$",
"this",
"->",
"mapper",
")",
";",
"$",
"mp",
"->",
"reset",
"(",
")",
";",
"$",
"cx",... | wrap result mapper
@param Cursor|array $mapper
@return Cortex | [
"wrap",
"result",
"mapper"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L2155-L2168 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.copyfrom | public function copyfrom($key, $fields = null) {
$f3 = \Base::instance();
$srcfields = is_array($key) ? $key : $f3->get($key);
if ($fields)
if (is_callable($fields))
$srcfields = $fields($srcfields);
else {
if (is_string($fields))
$fields = $f3->split($fields);
$srcfields = array_intersect_key($srcfields, array_flip($fields));
}
foreach ($srcfields as $key => $val) {
if (isset($this->fieldConf[$key]) && isset($this->fieldConf[$key]['type'])) {
if ($this->fieldConf[$key]['type'] == self::DT_JSON && is_string($val))
$val = json_decode($val);
elseif ($this->fieldConf[$key]['type'] == self::DT_SERIALIZED && is_string($val))
$val = unserialize($val);
}
$this->set($key, $val);
}
} | php | public function copyfrom($key, $fields = null) {
$f3 = \Base::instance();
$srcfields = is_array($key) ? $key : $f3->get($key);
if ($fields)
if (is_callable($fields))
$srcfields = $fields($srcfields);
else {
if (is_string($fields))
$fields = $f3->split($fields);
$srcfields = array_intersect_key($srcfields, array_flip($fields));
}
foreach ($srcfields as $key => $val) {
if (isset($this->fieldConf[$key]) && isset($this->fieldConf[$key]['type'])) {
if ($this->fieldConf[$key]['type'] == self::DT_JSON && is_string($val))
$val = json_decode($val);
elseif ($this->fieldConf[$key]['type'] == self::DT_SERIALIZED && is_string($val))
$val = unserialize($val);
}
$this->set($key, $val);
}
} | [
"public",
"function",
"copyfrom",
"(",
"$",
"key",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"f3",
"=",
"\\",
"Base",
"::",
"instance",
"(",
")",
";",
"$",
"srcfields",
"=",
"is_array",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"$",
"f3... | hydrate the mapper from hive key or given array
@param string|array $key
@param callback|array|string $fields
@return NULL | [
"hydrate",
"the",
"mapper",
"from",
"hive",
"key",
"or",
"given",
"array"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L2180-L2200 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.copyto | public function copyto($key, $relDepth=0) {
\Base::instance()->set($key, $this->cast(null,$relDepth));
} | php | public function copyto($key, $relDepth=0) {
\Base::instance()->set($key, $this->cast(null,$relDepth));
} | [
"public",
"function",
"copyto",
"(",
"$",
"key",
",",
"$",
"relDepth",
"=",
"0",
")",
"{",
"\\",
"Base",
"::",
"instance",
"(",
")",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"cast",
"(",
"null",
",",
"$",
"relDepth",
")",
")",
";",... | copy mapper values into hive key
@param string $key the hive key to copy into
@param int $relDepth the depth of relations to resolve
@return NULL|void | [
"copy",
"mapper",
"values",
"into",
"hive",
"key"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L2208-L2210 | train |
ikkez/f3-cortex | lib/db/cortex.php | Cortex.copyto_flat | function copyto_flat($key) {
/** @var \Base $f3 */
$f3 = \Base::instance();
$this->copyto($key);
foreach ($this->fields() as $field) {
if (isset($this->fieldConf[$field]) && isset($this->fieldConf[$field]['relType'])
&& $this->fieldConf[$field]['relType']=='has-many'
&& $f3->devoid($key.'.'.$field)) {
$val = $this->get($field);
if ($val instanceof CortexCollection)
$f3->set($key.'.'.$field,$val->getAll('_id'));
elseif (is_array($val))
$f3->set($key.'.'.$field,$val);
else
$f3->clear($key.'.'.$field);
}
}
} | php | function copyto_flat($key) {
/** @var \Base $f3 */
$f3 = \Base::instance();
$this->copyto($key);
foreach ($this->fields() as $field) {
if (isset($this->fieldConf[$field]) && isset($this->fieldConf[$field]['relType'])
&& $this->fieldConf[$field]['relType']=='has-many'
&& $f3->devoid($key.'.'.$field)) {
$val = $this->get($field);
if ($val instanceof CortexCollection)
$f3->set($key.'.'.$field,$val->getAll('_id'));
elseif (is_array($val))
$f3->set($key.'.'.$field,$val);
else
$f3->clear($key.'.'.$field);
}
}
} | [
"function",
"copyto_flat",
"(",
"$",
"key",
")",
"{",
"/** @var \\Base $f3 */",
"$",
"f3",
"=",
"\\",
"Base",
"::",
"instance",
"(",
")",
";",
"$",
"this",
"->",
"copyto",
"(",
"$",
"key",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"(",
... | copy to hive key with relations being simple arrays of keys
@param $key | [
"copy",
"to",
"hive",
"key",
"with",
"relations",
"being",
"simple",
"arrays",
"of",
"keys"
] | 48c1b90e84ada2d539125708f520b6814f54a308 | https://github.com/ikkez/f3-cortex/blob/48c1b90e84ada2d539125708f520b6814f54a308/lib/db/cortex.php#L2216-L2233 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.