repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
php-lug/lug | src/Component/Resource/Domain/DomainManager.php | DomainManager.doCreate | protected function doCreate($object, $flush = true)
{
$this->manager->persist($object);
if ($flush) {
$this->flush($object);
}
} | php | protected function doCreate($object, $flush = true)
{
$this->manager->persist($object);
if ($flush) {
$this->flush($object);
}
} | [
"protected",
"function",
"doCreate",
"(",
"$",
"object",
",",
"$",
"flush",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"persist",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"flush",
")",
"{",
"$",
"this",
"->",
"flush",
"(",
"$",
"object",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Domain/DomainManager.php#L63-L70 |
php-lug/lug | src/Component/Resource/Domain/DomainManager.php | DomainManager.doUpdate | protected function doUpdate($object, $flush = true)
{
if (!$this->manager->contains($object)) {
$this->manager->persist($object);
}
if ($flush) {
$this->flush($object);
}
} | php | protected function doUpdate($object, $flush = true)
{
if (!$this->manager->contains($object)) {
$this->manager->persist($object);
}
if ($flush) {
$this->flush($object);
}
} | [
"protected",
"function",
"doUpdate",
"(",
"$",
"object",
",",
"$",
"flush",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"manager",
"->",
"contains",
"(",
"$",
"object",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"persist",
"(",
"$",
"object",
")",
";",
"}",
"if",
"(",
"$",
"flush",
")",
"{",
"$",
"this",
"->",
"flush",
"(",
"$",
"object",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Domain/DomainManager.php#L75-L84 |
php-lug/lug | src/Component/Resource/Domain/DomainManager.php | DomainManager.doDelete | protected function doDelete($object, $flush = true)
{
$this->manager->remove($object);
if ($flush) {
$this->flush($object);
}
} | php | protected function doDelete($object, $flush = true)
{
$this->manager->remove($object);
if ($flush) {
$this->flush($object);
}
} | [
"protected",
"function",
"doDelete",
"(",
"$",
"object",
",",
"$",
"flush",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"remove",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"flush",
")",
"{",
"$",
"this",
"->",
"flush",
"(",
"$",
"object",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Domain/DomainManager.php#L89-L96 |
heidelpay/PhpDoc | src/phpDocumentor/Configuration/Merger.php | Merger.run | public function run($destination, $source, $default = null)
{
$result = null;
if (is_object($destination) && is_object($source) && get_class($destination) == get_class($source)) {
$result = $this->mergeObject($destination, $source);
} elseif (is_array($source) && is_array($destination)) {
$result = $this->mergeArray($destination, $source);
} elseif (!is_null($source) && $source !== $default) {
$result = $source;
}
return $result;
} | php | public function run($destination, $source, $default = null)
{
$result = null;
if (is_object($destination) && is_object($source) && get_class($destination) == get_class($source)) {
$result = $this->mergeObject($destination, $source);
} elseif (is_array($source) && is_array($destination)) {
$result = $this->mergeArray($destination, $source);
} elseif (!is_null($source) && $source !== $default) {
$result = $source;
}
return $result;
} | [
"public",
"function",
"run",
"(",
"$",
"destination",
",",
"$",
"source",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"is_object",
"(",
"$",
"destination",
")",
"&&",
"is_object",
"(",
"$",
"source",
")",
"&&",
"get_class",
"(",
"$",
"destination",
")",
"==",
"get_class",
"(",
"$",
"source",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"mergeObject",
"(",
"$",
"destination",
",",
"$",
"source",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"source",
")",
"&&",
"is_array",
"(",
"$",
"destination",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"mergeArray",
"(",
"$",
"destination",
",",
"$",
"source",
")",
";",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"source",
")",
"&&",
"$",
"source",
"!==",
"$",
"default",
")",
"{",
"$",
"result",
"=",
"$",
"source",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Merges the source on top of the destination and returns the result.
@param mixed $destination The destination variable that will be overwritten with the data from the source.
@param mixed $source The source variable that should be merged over the destination.
@param mixed $default For normal variables; only replace that variable if the provided source does
not equal this value.
@return mixed the merged variable. | [
"Merges",
"the",
"source",
"on",
"top",
"of",
"the",
"destination",
"and",
"returns",
"the",
"result",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Configuration/Merger.php#L48-L61 |
heidelpay/PhpDoc | src/phpDocumentor/Configuration/Merger.php | Merger.mergeObject | private function mergeObject($destinationObject, $sourceObject)
{
$reflectedDestination = new \ReflectionObject($destinationObject);
$reflectedSource = new \ReflectionObject($sourceObject);
$defaultPropertyValues = $reflectedDestination->getDefaultProperties();
foreach ($reflectedSource->getProperties() as $sourceProperty) {
$destinationObject = $this->mergeProperty(
$destinationObject,
$reflectedDestination->getProperty($sourceProperty->getName()),
$sourceObject,
$sourceProperty,
$defaultPropertyValues
);
}
return $destinationObject;
} | php | private function mergeObject($destinationObject, $sourceObject)
{
$reflectedDestination = new \ReflectionObject($destinationObject);
$reflectedSource = new \ReflectionObject($sourceObject);
$defaultPropertyValues = $reflectedDestination->getDefaultProperties();
foreach ($reflectedSource->getProperties() as $sourceProperty) {
$destinationObject = $this->mergeProperty(
$destinationObject,
$reflectedDestination->getProperty($sourceProperty->getName()),
$sourceObject,
$sourceProperty,
$defaultPropertyValues
);
}
return $destinationObject;
} | [
"private",
"function",
"mergeObject",
"(",
"$",
"destinationObject",
",",
"$",
"sourceObject",
")",
"{",
"$",
"reflectedDestination",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"destinationObject",
")",
";",
"$",
"reflectedSource",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"sourceObject",
")",
";",
"$",
"defaultPropertyValues",
"=",
"$",
"reflectedDestination",
"->",
"getDefaultProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"reflectedSource",
"->",
"getProperties",
"(",
")",
"as",
"$",
"sourceProperty",
")",
"{",
"$",
"destinationObject",
"=",
"$",
"this",
"->",
"mergeProperty",
"(",
"$",
"destinationObject",
",",
"$",
"reflectedDestination",
"->",
"getProperty",
"(",
"$",
"sourceProperty",
"->",
"getName",
"(",
")",
")",
",",
"$",
"sourceObject",
",",
"$",
"sourceProperty",
",",
"$",
"defaultPropertyValues",
")",
";",
"}",
"return",
"$",
"destinationObject",
";",
"}"
] | Deep-merge the source object over the destination object and return the results.
@param object $destinationObject
@param object $sourceObject
@return object | [
"Deep",
"-",
"merge",
"the",
"source",
"object",
"over",
"the",
"destination",
"object",
"and",
"return",
"the",
"results",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Configuration/Merger.php#L71-L88 |
heidelpay/PhpDoc | src/phpDocumentor/Configuration/Merger.php | Merger.mergeArray | private function mergeArray($destinationArray, $sourceArray)
{
$result = array();
foreach ($destinationArray as $key => $destinationArrayItem) {
if (is_int($key)) {
$result[] = $destinationArrayItem;
} else {
$result[$key] = $destinationArrayItem;
}
}
foreach ($sourceArray as $key => $sourceArrayItem) {
if (is_int($key)) {
$result[] = $sourceArrayItem;
} else {
$result[$key] = $this->run($result[$key], $sourceArrayItem);
}
}
return $result;
} | php | private function mergeArray($destinationArray, $sourceArray)
{
$result = array();
foreach ($destinationArray as $key => $destinationArrayItem) {
if (is_int($key)) {
$result[] = $destinationArrayItem;
} else {
$result[$key] = $destinationArrayItem;
}
}
foreach ($sourceArray as $key => $sourceArrayItem) {
if (is_int($key)) {
$result[] = $sourceArrayItem;
} else {
$result[$key] = $this->run($result[$key], $sourceArrayItem);
}
}
return $result;
} | [
"private",
"function",
"mergeArray",
"(",
"$",
"destinationArray",
",",
"$",
"sourceArray",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"destinationArray",
"as",
"$",
"key",
"=>",
"$",
"destinationArrayItem",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"destinationArrayItem",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"destinationArrayItem",
";",
"}",
"}",
"foreach",
"(",
"$",
"sourceArray",
"as",
"$",
"key",
"=>",
"$",
"sourceArrayItem",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"sourceArrayItem",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"run",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
",",
"$",
"sourceArrayItem",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Deep-merges the source array over the destination array.
@param array $destinationArray
@param array $sourceArray
@return array | [
"Deep",
"-",
"merges",
"the",
"source",
"array",
"over",
"the",
"destination",
"array",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Configuration/Merger.php#L98-L118 |
heidelpay/PhpDoc | src/phpDocumentor/Configuration/Merger.php | Merger.mergeProperty | private function mergeProperty(
$destinationObject,
\ReflectionProperty $destinationProperty,
$sourceObject,
\ReflectionProperty $sourceProperty,
array $defaultPropertyValues
) {
// Allow the source and destination properties to be readable
$sourceProperty->setAccessible(true);
$destinationProperty->setAccessible(true);
// Retrieve the current value for both the destination and source
$destinationValue = $destinationProperty->getValue($destinationObject);
$sourceValue = $sourceProperty->getValue($sourceObject);
// Find out what the default value for this property is
$sourcePropertyDefaultValue = isset($defaultPropertyValues[$sourceProperty->getName()])
? $defaultPropertyValues[$sourceProperty->getName()]
: null;
// if a property is annotated with the 'Replace' annotation then we null the destination location,
// causing the value from source to be copied as-is to the destination object instead of merging it.
// but only if the value that is to-be-copied is actually copied
if ($this->shouldPropertyBeReplaced($destinationProperty)) {
$destinationValue = null;
}
// Merge the values of the two properties!
$result = $this->run($destinationValue, $sourceValue, $sourcePropertyDefaultValue);
// No result? No save. We only update the destination if the resulting merge is a value
if ($result !== null) {
$destinationProperty->setValue($destinationObject, $result);
}
// Make protected and private properties inaccessible again
$destinationProperty->setAccessible($destinationProperty->isPublic());
$sourceProperty->setAccessible($sourceProperty->isPublic());
return $destinationObject;
} | php | private function mergeProperty(
$destinationObject,
\ReflectionProperty $destinationProperty,
$sourceObject,
\ReflectionProperty $sourceProperty,
array $defaultPropertyValues
) {
// Allow the source and destination properties to be readable
$sourceProperty->setAccessible(true);
$destinationProperty->setAccessible(true);
// Retrieve the current value for both the destination and source
$destinationValue = $destinationProperty->getValue($destinationObject);
$sourceValue = $sourceProperty->getValue($sourceObject);
// Find out what the default value for this property is
$sourcePropertyDefaultValue = isset($defaultPropertyValues[$sourceProperty->getName()])
? $defaultPropertyValues[$sourceProperty->getName()]
: null;
// if a property is annotated with the 'Replace' annotation then we null the destination location,
// causing the value from source to be copied as-is to the destination object instead of merging it.
// but only if the value that is to-be-copied is actually copied
if ($this->shouldPropertyBeReplaced($destinationProperty)) {
$destinationValue = null;
}
// Merge the values of the two properties!
$result = $this->run($destinationValue, $sourceValue, $sourcePropertyDefaultValue);
// No result? No save. We only update the destination if the resulting merge is a value
if ($result !== null) {
$destinationProperty->setValue($destinationObject, $result);
}
// Make protected and private properties inaccessible again
$destinationProperty->setAccessible($destinationProperty->isPublic());
$sourceProperty->setAccessible($sourceProperty->isPublic());
return $destinationObject;
} | [
"private",
"function",
"mergeProperty",
"(",
"$",
"destinationObject",
",",
"\\",
"ReflectionProperty",
"$",
"destinationProperty",
",",
"$",
"sourceObject",
",",
"\\",
"ReflectionProperty",
"$",
"sourceProperty",
",",
"array",
"$",
"defaultPropertyValues",
")",
"{",
"// Allow the source and destination properties to be readable",
"$",
"sourceProperty",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"destinationProperty",
"->",
"setAccessible",
"(",
"true",
")",
";",
"// Retrieve the current value for both the destination and source",
"$",
"destinationValue",
"=",
"$",
"destinationProperty",
"->",
"getValue",
"(",
"$",
"destinationObject",
")",
";",
"$",
"sourceValue",
"=",
"$",
"sourceProperty",
"->",
"getValue",
"(",
"$",
"sourceObject",
")",
";",
"// Find out what the default value for this property is",
"$",
"sourcePropertyDefaultValue",
"=",
"isset",
"(",
"$",
"defaultPropertyValues",
"[",
"$",
"sourceProperty",
"->",
"getName",
"(",
")",
"]",
")",
"?",
"$",
"defaultPropertyValues",
"[",
"$",
"sourceProperty",
"->",
"getName",
"(",
")",
"]",
":",
"null",
";",
"// if a property is annotated with the 'Replace' annotation then we null the destination location,",
"// causing the value from source to be copied as-is to the destination object instead of merging it.",
"// but only if the value that is to-be-copied is actually copied",
"if",
"(",
"$",
"this",
"->",
"shouldPropertyBeReplaced",
"(",
"$",
"destinationProperty",
")",
")",
"{",
"$",
"destinationValue",
"=",
"null",
";",
"}",
"// Merge the values of the two properties!",
"$",
"result",
"=",
"$",
"this",
"->",
"run",
"(",
"$",
"destinationValue",
",",
"$",
"sourceValue",
",",
"$",
"sourcePropertyDefaultValue",
")",
";",
"// No result? No save. We only update the destination if the resulting merge is a value",
"if",
"(",
"$",
"result",
"!==",
"null",
")",
"{",
"$",
"destinationProperty",
"->",
"setValue",
"(",
"$",
"destinationObject",
",",
"$",
"result",
")",
";",
"}",
"// Make protected and private properties inaccessible again",
"$",
"destinationProperty",
"->",
"setAccessible",
"(",
"$",
"destinationProperty",
"->",
"isPublic",
"(",
")",
")",
";",
"$",
"sourceProperty",
"->",
"setAccessible",
"(",
"$",
"sourceProperty",
"->",
"isPublic",
"(",
")",
")",
";",
"return",
"$",
"destinationObject",
";",
"}"
] | Merges the two properties over eachother.
@param object $destinationObject
@param \ReflectionProperty $destinationProperty
@param object $sourceObject
@param \ReflectionProperty $sourceProperty
@param mixed[] $defaultPropertyValues
@return object | [
"Merges",
"the",
"two",
"properties",
"over",
"eachother",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Configuration/Merger.php#L131-L171 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/fileparts/stream_file.php | ezcMailStreamFile.generateBody | public function generateBody()
{
$contents = stream_get_contents( $this->stream );
return chunk_split( base64_encode( $contents ), 76, ezcMailTools::lineBreak() );
} | php | public function generateBody()
{
$contents = stream_get_contents( $this->stream );
return chunk_split( base64_encode( $contents ), 76, ezcMailTools::lineBreak() );
} | [
"public",
"function",
"generateBody",
"(",
")",
"{",
"$",
"contents",
"=",
"stream_get_contents",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"return",
"chunk_split",
"(",
"base64_encode",
"(",
"$",
"contents",
")",
",",
"76",
",",
"ezcMailTools",
"::",
"lineBreak",
"(",
")",
")",
";",
"}"
] | Returns the contents of the file with the correct encoding.
The stream might become unusable after this if it doesn't support seek.
@return string | [
"Returns",
"the",
"contents",
"of",
"the",
"file",
"with",
"the",
"correct",
"encoding",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/fileparts/stream_file.php#L123-L127 |
bobfridley/laravel-vonage | src/Authenticators/PasswordAuthenticator.php | PasswordAuthenticator.authenticate | public function authenticate(array $config)
{
if (!$this->client) {
throw new InvalidArgumentException('The client instance was not given to the password authenticator.');
}
if (!array_key_exists('username', $config) || !array_key_exists('password', $config)) {
throw new InvalidArgumentException('The password authenticator requires a username and password.');
}
$this->client->authenticate($config['username'], $config['password'], 'http_password');
return $this->client;
} | php | public function authenticate(array $config)
{
if (!$this->client) {
throw new InvalidArgumentException('The client instance was not given to the password authenticator.');
}
if (!array_key_exists('username', $config) || !array_key_exists('password', $config)) {
throw new InvalidArgumentException('The password authenticator requires a username and password.');
}
$this->client->authenticate($config['username'], $config['password'], 'http_password');
return $this->client;
} | [
"public",
"function",
"authenticate",
"(",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"client",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The client instance was not given to the password authenticator.'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'username'",
",",
"$",
"config",
")",
"||",
"!",
"array_key_exists",
"(",
"'password'",
",",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The password authenticator requires a username and password.'",
")",
";",
"}",
"$",
"this",
"->",
"client",
"->",
"authenticate",
"(",
"$",
"config",
"[",
"'username'",
"]",
",",
"$",
"config",
"[",
"'password'",
"]",
",",
"'http_password'",
")",
";",
"return",
"$",
"this",
"->",
"client",
";",
"}"
] | Authenticate the client, and return it.
@param string[] $config
@throws \InvalidArgumentException
@return \GuzzleHttp\Client | [
"Authenticate",
"the",
"client",
"and",
"return",
"it",
"."
] | train | https://github.com/bobfridley/laravel-vonage/blob/e422af44a449c3147878c317b865508b1afa50e6/src/Authenticators/PasswordAuthenticator.php#L32-L45 |
NuclearCMS/Hierarchy | src/Node.php | Node.boot | protected static function boot()
{
parent::boot();
static::addGlobalScope(new MailingScope);
static::creating(function ($node)
{
if (empty($node->published_at))
{
$node->published_at = Carbon::now();
}
$node->fireNodeEvent('creating');
});
static::created(function ($node)
{
$node->propagateIdToSources(false);
$node->fireNodeEvent('created');
});
static::saving(function ($node)
{
$node->validateCanHaveParentOfType();
$node->fireNodeEvent('saving');
});
foreach (['updating', 'updated', 'deleting', 'deleted', 'saved'] as $event)
{
static::$event(function ($node) use ($event)
{
$node->fireNodeEvent($event);
});
}
} | php | protected static function boot()
{
parent::boot();
static::addGlobalScope(new MailingScope);
static::creating(function ($node)
{
if (empty($node->published_at))
{
$node->published_at = Carbon::now();
}
$node->fireNodeEvent('creating');
});
static::created(function ($node)
{
$node->propagateIdToSources(false);
$node->fireNodeEvent('created');
});
static::saving(function ($node)
{
$node->validateCanHaveParentOfType();
$node->fireNodeEvent('saving');
});
foreach (['updating', 'updated', 'deleting', 'deleted', 'saved'] as $event)
{
static::$event(function ($node) use ($event)
{
$node->fireNodeEvent($event);
});
}
} | [
"protected",
"static",
"function",
"boot",
"(",
")",
"{",
"parent",
"::",
"boot",
"(",
")",
";",
"static",
"::",
"addGlobalScope",
"(",
"new",
"MailingScope",
")",
";",
"static",
"::",
"creating",
"(",
"function",
"(",
"$",
"node",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"node",
"->",
"published_at",
")",
")",
"{",
"$",
"node",
"->",
"published_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"}",
"$",
"node",
"->",
"fireNodeEvent",
"(",
"'creating'",
")",
";",
"}",
")",
";",
"static",
"::",
"created",
"(",
"function",
"(",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"propagateIdToSources",
"(",
"false",
")",
";",
"$",
"node",
"->",
"fireNodeEvent",
"(",
"'created'",
")",
";",
"}",
")",
";",
"static",
"::",
"saving",
"(",
"function",
"(",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"validateCanHaveParentOfType",
"(",
")",
";",
"$",
"node",
"->",
"fireNodeEvent",
"(",
"'saving'",
")",
";",
"}",
")",
";",
"foreach",
"(",
"[",
"'updating'",
",",
"'updated'",
",",
"'deleting'",
",",
"'deleted'",
",",
"'saved'",
"]",
"as",
"$",
"event",
")",
"{",
"static",
"::",
"$",
"event",
"(",
"function",
"(",
"$",
"node",
")",
"use",
"(",
"$",
"event",
")",
"{",
"$",
"node",
"->",
"fireNodeEvent",
"(",
"$",
"event",
")",
";",
"}",
")",
";",
"}",
"}"
] | Boot model events | [
"Boot",
"model",
"events"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L184-L221 |
NuclearCMS/Hierarchy | src/Node.php | Node.propagateIdToSources | public function propagateIdToSources($save = true)
{
foreach ($this->translations as $source)
{
$source->setExtensionNodeId($this->getKey(), $save);
}
} | php | public function propagateIdToSources($save = true)
{
foreach ($this->translations as $source)
{
$source->setExtensionNodeId($this->getKey(), $save);
}
} | [
"public",
"function",
"propagateIdToSources",
"(",
"$",
"save",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"source",
")",
"{",
"$",
"source",
"->",
"setExtensionNodeId",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"$",
"save",
")",
";",
"}",
"}"
] | Propagates self id to sources
The save parameter is to prevent saving sources prematurely
@param bool $save | [
"Propagates",
"self",
"id",
"to",
"sources"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L239-L245 |
NuclearCMS/Hierarchy | src/Node.php | Node.validateCanHaveParentOfType | public function validateCanHaveParentOfType()
{
if (is_null($this->parent))
{
return;
}
$allowedNodeTypes = json_decode($this->parent->getNodeType()->allowed_children);
if (empty($allowedNodeTypes) || in_array($this->getNodeTypeKey(), $allowedNodeTypes))
{
return;
}
throw new InvalidParentNodeTypeException('Parent does not allow node type of name "' . $this->getNodeTypeName() . '" as child.');
} | php | public function validateCanHaveParentOfType()
{
if (is_null($this->parent))
{
return;
}
$allowedNodeTypes = json_decode($this->parent->getNodeType()->allowed_children);
if (empty($allowedNodeTypes) || in_array($this->getNodeTypeKey(), $allowedNodeTypes))
{
return;
}
throw new InvalidParentNodeTypeException('Parent does not allow node type of name "' . $this->getNodeTypeName() . '" as child.');
} | [
"public",
"function",
"validateCanHaveParentOfType",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"parent",
")",
")",
"{",
"return",
";",
"}",
"$",
"allowedNodeTypes",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"parent",
"->",
"getNodeType",
"(",
")",
"->",
"allowed_children",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"allowedNodeTypes",
")",
"||",
"in_array",
"(",
"$",
"this",
"->",
"getNodeTypeKey",
"(",
")",
",",
"$",
"allowedNodeTypes",
")",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"InvalidParentNodeTypeException",
"(",
"'Parent does not allow node type of name \"'",
".",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
".",
"'\" as child.'",
")",
";",
"}"
] | Validates parent type | [
"Validates",
"parent",
"type"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L251-L266 |
NuclearCMS/Hierarchy | src/Node.php | Node.getNodeType | public function getNodeType()
{
$bag = hierarchy_bag('nodetype');
if ($this->relationLoaded('nodeType'))
{
$nodeType = $this->getRelation('nodeType');
} elseif ($nodeType = $bag->getNodeType($this->getNodeTypeKey()))
{
$this->setRelation('nodeType', $nodeType);
} else
{
$nodeType = $this->load('nodeType')->getRelation('nodeType');
}
if ($nodeType)
{
$bag->addNodeType($nodeType);
return $nodeType;
}
return null;
} | php | public function getNodeType()
{
$bag = hierarchy_bag('nodetype');
if ($this->relationLoaded('nodeType'))
{
$nodeType = $this->getRelation('nodeType');
} elseif ($nodeType = $bag->getNodeType($this->getNodeTypeKey()))
{
$this->setRelation('nodeType', $nodeType);
} else
{
$nodeType = $this->load('nodeType')->getRelation('nodeType');
}
if ($nodeType)
{
$bag->addNodeType($nodeType);
return $nodeType;
}
return null;
} | [
"public",
"function",
"getNodeType",
"(",
")",
"{",
"$",
"bag",
"=",
"hierarchy_bag",
"(",
"'nodetype'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"relationLoaded",
"(",
"'nodeType'",
")",
")",
"{",
"$",
"nodeType",
"=",
"$",
"this",
"->",
"getRelation",
"(",
"'nodeType'",
")",
";",
"}",
"elseif",
"(",
"$",
"nodeType",
"=",
"$",
"bag",
"->",
"getNodeType",
"(",
"$",
"this",
"->",
"getNodeTypeKey",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"setRelation",
"(",
"'nodeType'",
",",
"$",
"nodeType",
")",
";",
"}",
"else",
"{",
"$",
"nodeType",
"=",
"$",
"this",
"->",
"load",
"(",
"'nodeType'",
")",
"->",
"getRelation",
"(",
"'nodeType'",
")",
";",
"}",
"if",
"(",
"$",
"nodeType",
")",
"{",
"$",
"bag",
"->",
"addNodeType",
"(",
"$",
"nodeType",
")",
";",
"return",
"$",
"nodeType",
";",
"}",
"return",
"null",
";",
"}"
] | Getter for node type
@return NodeType | [
"Getter",
"for",
"node",
"type"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L295-L318 |
NuclearCMS/Hierarchy | src/Node.php | Node.getNodeTypeName | public function getNodeTypeName()
{
return $this->nodeTypeName ?:
(is_null($this->getNodeType()) ? null : $this->getNodeType()->getName());
} | php | public function getNodeTypeName()
{
return $this->nodeTypeName ?:
(is_null($this->getNodeType()) ? null : $this->getNodeType()->getName());
} | [
"public",
"function",
"getNodeTypeName",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"nodeTypeName",
"?",
":",
"(",
"is_null",
"(",
"$",
"this",
"->",
"getNodeType",
"(",
")",
")",
"?",
"null",
":",
"$",
"this",
"->",
"getNodeType",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"}"
] | Gets the node type name
@return int $id | [
"Gets",
"the",
"node",
"type",
"name"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L335-L339 |
NuclearCMS/Hierarchy | src/Node.php | Node.setNodeTypeByKey | public function setNodeTypeByKey($id)
{
$nodeType = NodeType::findOrFail($id);
$this->nodeType()->associate($nodeType);
$this->mailing = $nodeType->isTypeMailing();
} | php | public function setNodeTypeByKey($id)
{
$nodeType = NodeType::findOrFail($id);
$this->nodeType()->associate($nodeType);
$this->mailing = $nodeType->isTypeMailing();
} | [
"public",
"function",
"setNodeTypeByKey",
"(",
"$",
"id",
")",
"{",
"$",
"nodeType",
"=",
"NodeType",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"nodeType",
"(",
")",
"->",
"associate",
"(",
"$",
"nodeType",
")",
";",
"$",
"this",
"->",
"mailing",
"=",
"$",
"nodeType",
"->",
"isTypeMailing",
"(",
")",
";",
"}"
] | Sets the node type by key and validates it
@param int $id
@return NodeType | [
"Sets",
"the",
"node",
"type",
"by",
"key",
"and",
"validates",
"it"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L367-L374 |
NuclearCMS/Hierarchy | src/Node.php | Node.isTranslationAttribute | public function isTranslationAttribute($key)
{
if ($this->isSpecialAttribute($key))
{
return false;
}
// When there is no node type we exclude source attributes
return $this->_isTranslationAttribute($key) ||
(is_null($this->getNodeTypeName()) ? false : $this->isSourceAttribute($key));
} | php | public function isTranslationAttribute($key)
{
if ($this->isSpecialAttribute($key))
{
return false;
}
// When there is no node type we exclude source attributes
return $this->_isTranslationAttribute($key) ||
(is_null($this->getNodeTypeName()) ? false : $this->isSourceAttribute($key));
} | [
"public",
"function",
"isTranslationAttribute",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSpecialAttribute",
"(",
"$",
"key",
")",
")",
"{",
"return",
"false",
";",
"}",
"// When there is no node type we exclude source attributes",
"return",
"$",
"this",
"->",
"_isTranslationAttribute",
"(",
"$",
"key",
")",
"||",
"(",
"is_null",
"(",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
")",
"?",
"false",
":",
"$",
"this",
"->",
"isSourceAttribute",
"(",
"$",
"key",
")",
")",
";",
"}"
] | Checks if key is a translation attribute
@param string $key
@return bool | [
"Checks",
"if",
"key",
"is",
"a",
"translation",
"attribute"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L382-L392 |
NuclearCMS/Hierarchy | src/Node.php | Node.isSourceAttribute | protected function isSourceAttribute($key)
{
$modelName = source_model_name($this->getNodeTypeName(), true);
return in_array($key, call_user_func([$modelName, 'getSourceFields']));
} | php | protected function isSourceAttribute($key)
{
$modelName = source_model_name($this->getNodeTypeName(), true);
return in_array($key, call_user_func([$modelName, 'getSourceFields']));
} | [
"protected",
"function",
"isSourceAttribute",
"(",
"$",
"key",
")",
"{",
"$",
"modelName",
"=",
"source_model_name",
"(",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
",",
"true",
")",
";",
"return",
"in_array",
"(",
"$",
"key",
",",
"call_user_func",
"(",
"[",
"$",
"modelName",
",",
"'getSourceFields'",
"]",
")",
")",
";",
"}"
] | Checks if a key is a node source attribute
@param $key
@return bool | [
"Checks",
"if",
"a",
"key",
"is",
"a",
"node",
"source",
"attribute"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L417-L422 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeWhereExtensionAttribute | public function scopeWhereExtensionAttribute(Builder $query, $type, $key, $value)
{
// We do this for querying, searching and sorting with source attributes
$this->setNodeTypeName($type);
return $query->whereHas('nodeSourceExtensions', function (Builder $query) use ($key, $value)
{
$query->where(source_table_name($this->getNodeTypeName()) . '.' . $key, $value);
});
} | php | public function scopeWhereExtensionAttribute(Builder $query, $type, $key, $value)
{
// We do this for querying, searching and sorting with source attributes
$this->setNodeTypeName($type);
return $query->whereHas('nodeSourceExtensions', function (Builder $query) use ($key, $value)
{
$query->where(source_table_name($this->getNodeTypeName()) . '.' . $key, $value);
});
} | [
"public",
"function",
"scopeWhereExtensionAttribute",
"(",
"Builder",
"$",
"query",
",",
"$",
"type",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"// We do this for querying, searching and sorting with source attributes",
"$",
"this",
"->",
"setNodeTypeName",
"(",
"$",
"type",
")",
";",
"return",
"$",
"query",
"->",
"whereHas",
"(",
"'nodeSourceExtensions'",
",",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"source_table_name",
"(",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
")",
".",
"'.'",
".",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
")",
";",
"}"
] | This scope filters results by checking the translation fields.
@param \Illuminate\Database\Eloquent\Builder $query
@param string $type
@param string $key
@param string $value
@return \Illuminate\Database\Eloquent\Builder|static | [
"This",
"scope",
"filters",
"results",
"by",
"checking",
"the",
"translation",
"fields",
"."
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L434-L443 |
NuclearCMS/Hierarchy | src/Node.php | Node.getNewTranslation | public function getNewTranslation($locale)
{
$nodeSource = NodeSource::newWithType(
$locale,
$this->getNodeTypeName()
);
$this->translations->add($nodeSource);
return $nodeSource;
} | php | public function getNewTranslation($locale)
{
$nodeSource = NodeSource::newWithType(
$locale,
$this->getNodeTypeName()
);
$this->translations->add($nodeSource);
return $nodeSource;
} | [
"public",
"function",
"getNewTranslation",
"(",
"$",
"locale",
")",
"{",
"$",
"nodeSource",
"=",
"NodeSource",
"::",
"newWithType",
"(",
"$",
"locale",
",",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
")",
";",
"$",
"this",
"->",
"translations",
"->",
"add",
"(",
"$",
"nodeSource",
")",
";",
"return",
"$",
"nodeSource",
";",
"}"
] | Overloading default Translatable functionality for
creating a new translation
@param string $locale
@return Model | [
"Overloading",
"default",
"Translatable",
"functionality",
"for",
"creating",
"a",
"new",
"translation"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L477-L487 |
NuclearCMS/Hierarchy | src/Node.php | Node.getTranslationAttribute | public function getTranslationAttribute($key, $locale = null, $fallback = true, $unmutated = false)
{
if ($this->isTranslationAttribute($key))
{
$translation = $this->translate($locale);
$attribute = ($translation) ?
($unmutated ? $translation->getUnmutatedAttribute($key) : $translation->{$key}) :
null;
if (empty($attribute) && $fallback)
{
$translation = $this->translate($this->getFallbackLocale());
if ($translation)
{
return $unmutated ? $translation->getUnmutatedAttribute($key) : $translation->{$key};
}
}
return $attribute;
}
return null;
} | php | public function getTranslationAttribute($key, $locale = null, $fallback = true, $unmutated = false)
{
if ($this->isTranslationAttribute($key))
{
$translation = $this->translate($locale);
$attribute = ($translation) ?
($unmutated ? $translation->getUnmutatedAttribute($key) : $translation->{$key}) :
null;
if (empty($attribute) && $fallback)
{
$translation = $this->translate($this->getFallbackLocale());
if ($translation)
{
return $unmutated ? $translation->getUnmutatedAttribute($key) : $translation->{$key};
}
}
return $attribute;
}
return null;
} | [
"public",
"function",
"getTranslationAttribute",
"(",
"$",
"key",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"fallback",
"=",
"true",
",",
"$",
"unmutated",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isTranslationAttribute",
"(",
"$",
"key",
")",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"locale",
")",
";",
"$",
"attribute",
"=",
"(",
"$",
"translation",
")",
"?",
"(",
"$",
"unmutated",
"?",
"$",
"translation",
"->",
"getUnmutatedAttribute",
"(",
"$",
"key",
")",
":",
"$",
"translation",
"->",
"{",
"$",
"key",
"}",
")",
":",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"attribute",
")",
"&&",
"$",
"fallback",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"this",
"->",
"getFallbackLocale",
"(",
")",
")",
";",
"if",
"(",
"$",
"translation",
")",
"{",
"return",
"$",
"unmutated",
"?",
"$",
"translation",
"->",
"getUnmutatedAttribute",
"(",
"$",
"key",
")",
":",
"$",
"translation",
"->",
"{",
"$",
"key",
"}",
";",
"}",
"}",
"return",
"$",
"attribute",
";",
"}",
"return",
"null",
";",
"}"
] | Returns a translation attribute
(optionally with fallback)
@param string $key
@param string $locale
@param bool $fallback
@param bool $unmutated
@return string|null | [
"Returns",
"a",
"translation",
"attribute",
"(",
"optionally",
"with",
"fallback",
")"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L499-L523 |
NuclearCMS/Hierarchy | src/Node.php | Node.translateOrFirst | public function translateOrFirst($locale = null)
{
$translation = $this->translate($locale, true);
if ( ! $translation)
{
$translation = $this->translations->first();
}
return $translation;
} | php | public function translateOrFirst($locale = null)
{
$translation = $this->translate($locale, true);
if ( ! $translation)
{
$translation = $this->translations->first();
}
return $translation;
} | [
"public",
"function",
"translateOrFirst",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"locale",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"translation",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"translations",
"->",
"first",
"(",
")",
";",
"}",
"return",
"$",
"translation",
";",
"}"
] | Get source or fallback to first found translation
@param string|null $locale
@return NodeSource | [
"Get",
"source",
"or",
"fallback",
"to",
"first",
"found",
"translation"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L531-L541 |
NuclearCMS/Hierarchy | src/Node.php | Node.determineSortableKey | protected function determineSortableKey($key)
{
// We need to allow source attributes here
if (in_array($key, $this->sortableColumns) || $this->isTranslationAttribute($key))
{
return $key;
}
return $this->getDefaultSortableKey();
} | php | protected function determineSortableKey($key)
{
// We need to allow source attributes here
if (in_array($key, $this->sortableColumns) || $this->isTranslationAttribute($key))
{
return $key;
}
return $this->getDefaultSortableKey();
} | [
"protected",
"function",
"determineSortableKey",
"(",
"$",
"key",
")",
"{",
"// We need to allow source attributes here",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"sortableColumns",
")",
"||",
"$",
"this",
"->",
"isTranslationAttribute",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"key",
";",
"}",
"return",
"$",
"this",
"->",
"getDefaultSortableKey",
"(",
")",
";",
"}"
] | Determines the sortable key from the map
@param string $key
@return string | [
"Determines",
"the",
"sortable",
"key",
"from",
"the",
"map"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L569-L578 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeSortedBySourceAttribute | public function scopeSortedBySourceAttribute(Builder $query, $attribute, $direction = 'ASC')
{
return $this->orderQueryBySourceAttribute($query, $attribute, $direction);
} | php | public function scopeSortedBySourceAttribute(Builder $query, $attribute, $direction = 'ASC')
{
return $this->orderQueryBySourceAttribute($query, $attribute, $direction);
} | [
"public",
"function",
"scopeSortedBySourceAttribute",
"(",
"Builder",
"$",
"query",
",",
"$",
"attribute",
",",
"$",
"direction",
"=",
"'ASC'",
")",
"{",
"return",
"$",
"this",
"->",
"orderQueryBySourceAttribute",
"(",
"$",
"query",
",",
"$",
"attribute",
",",
"$",
"direction",
")",
";",
"}"
] | Sorts by source attribute
@param Builder $query
@param string $attribute
@param string $direction
@return Builder | [
"Sorts",
"by",
"source",
"attribute"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L588-L591 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeWithName | public function scopeWithName(Builder $query, $name, $locale = null)
{
return $this->scopeWhereTranslation($query, 'node_name', $name, $locale);
} | php | public function scopeWithName(Builder $query, $name, $locale = null)
{
return $this->scopeWhereTranslation($query, 'node_name', $name, $locale);
} | [
"public",
"function",
"scopeWithName",
"(",
"Builder",
"$",
"query",
",",
"$",
"name",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"scopeWhereTranslation",
"(",
"$",
"query",
",",
"'node_name'",
",",
"$",
"name",
",",
"$",
"locale",
")",
";",
"}"
] | Scope for selecting with name
@param Builder $query
@param string $name
@param string|null $locale
@return Builder | [
"Scope",
"for",
"selecting",
"with",
"name"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L621-L624 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeWithType | public function scopeWithType(Builder $query, $type)
{
// We do this for querying, searching and sorting with source attributes
$this->setNodeTypeName($type);
return $this->scopeWhereTranslation($query, 'source_type', $type, null);
} | php | public function scopeWithType(Builder $query, $type)
{
// We do this for querying, searching and sorting with source attributes
$this->setNodeTypeName($type);
return $this->scopeWhereTranslation($query, 'source_type', $type, null);
} | [
"public",
"function",
"scopeWithType",
"(",
"Builder",
"$",
"query",
",",
"$",
"type",
")",
"{",
"// We do this for querying, searching and sorting with source attributes",
"$",
"this",
"->",
"setNodeTypeName",
"(",
"$",
"type",
")",
";",
"return",
"$",
"this",
"->",
"scopeWhereTranslation",
"(",
"$",
"query",
",",
"'source_type'",
",",
"$",
"type",
",",
"null",
")",
";",
"}"
] | Scope for selecting with type
@param Builder $query
@param string $type
@return Builder | [
"Scope",
"for",
"selecting",
"with",
"type"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L633-L639 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeFilteredByStatus | public function scopeFilteredByStatus(Builder $query, $status = null)
{
$status = is_null($status) ? request('f', 'all') : $status;
if (in_array($status, ['published', 'withheld', 'draft', 'pending', 'archived', 'invisible', 'locked']))
{
$query->{$status}();
}
return $query;
} | php | public function scopeFilteredByStatus(Builder $query, $status = null)
{
$status = is_null($status) ? request('f', 'all') : $status;
if (in_array($status, ['published', 'withheld', 'draft', 'pending', 'archived', 'invisible', 'locked']))
{
$query->{$status}();
}
return $query;
} | [
"public",
"function",
"scopeFilteredByStatus",
"(",
"Builder",
"$",
"query",
",",
"$",
"status",
"=",
"null",
")",
"{",
"$",
"status",
"=",
"is_null",
"(",
"$",
"status",
")",
"?",
"request",
"(",
"'f'",
",",
"'all'",
")",
":",
"$",
"status",
";",
"if",
"(",
"in_array",
"(",
"$",
"status",
",",
"[",
"'published'",
",",
"'withheld'",
",",
"'draft'",
",",
"'pending'",
",",
"'archived'",
",",
"'invisible'",
",",
"'locked'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"{",
"$",
"status",
"}",
"(",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Status filter scope
@param Builder $query
@param string $status
@return Builder | [
"Status",
"filter",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L648-L658 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopePublished | public function scopePublished(Builder $query)
{
return $query->where(function ($query)
{
$query->where('status', '>=', Node::PUBLISHED)
->orWhere(function ($query)
{
$query->where('status', '>=', Node::PENDING)
->where('published_at', '<=', Carbon::now());
});
});
} | php | public function scopePublished(Builder $query)
{
return $query->where(function ($query)
{
$query->where('status', '>=', Node::PUBLISHED)
->orWhere(function ($query)
{
$query->where('status', '>=', Node::PENDING)
->where('published_at', '<=', Carbon::now());
});
});
} | [
"public",
"function",
"scopePublished",
"(",
"Builder",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'status'",
",",
"'>='",
",",
"Node",
"::",
"PUBLISHED",
")",
"->",
"orWhere",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'status'",
",",
"'>='",
",",
"Node",
"::",
"PENDING",
")",
"->",
"where",
"(",
"'published_at'",
",",
"'<='",
",",
"Carbon",
"::",
"now",
"(",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Published scope
@param Builder $query
@return Builder | [
"Published",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L667-L678 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeWithheld | public function scopeWithheld(Builder $query)
{
return $query->where(function ($query)
{
$query->where('status', '<=', Node::DRAFT)
->orWhere(function ($query)
{
$query->where('status', '<=', Node::PENDING)
->where('published_at', '>', Carbon::now());
});
});
} | php | public function scopeWithheld(Builder $query)
{
return $query->where(function ($query)
{
$query->where('status', '<=', Node::DRAFT)
->orWhere(function ($query)
{
$query->where('status', '<=', Node::PENDING)
->where('published_at', '>', Carbon::now());
});
});
} | [
"public",
"function",
"scopeWithheld",
"(",
"Builder",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'status'",
",",
"'<='",
",",
"Node",
"::",
"DRAFT",
")",
"->",
"orWhere",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'status'",
",",
"'<='",
",",
"Node",
"::",
"PENDING",
")",
"->",
"where",
"(",
"'published_at'",
",",
"'>'",
",",
"Carbon",
"::",
"now",
"(",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Withheld scope
@param Builder $query
@return Builder | [
"Withheld",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L686-L697 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopePending | public function scopePending(Builder $query)
{
return $query->where('status', Node::PENDING)
->where('published_at', '>', Carbon::now());
} | php | public function scopePending(Builder $query)
{
return $query->where('status', Node::PENDING)
->where('published_at', '>', Carbon::now());
} | [
"public",
"function",
"scopePending",
"(",
"Builder",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"'status'",
",",
"Node",
"::",
"PENDING",
")",
"->",
"where",
"(",
"'published_at'",
",",
"'>'",
",",
"Carbon",
"::",
"now",
"(",
")",
")",
";",
"}"
] | Pending scope
@param Builder $query
@return Builder | [
"Pending",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L716-L720 |
NuclearCMS/Hierarchy | src/Node.php | Node.getOrderedChildren | public function getOrderedChildren($perPage = null)
{
$children = $this->children();
$this->determineChildrenSorting($children);
return $this->determineChildrenPagination($perPage, $children);
} | php | public function getOrderedChildren($perPage = null)
{
$children = $this->children();
$this->determineChildrenSorting($children);
return $this->determineChildrenPagination($perPage, $children);
} | [
"public",
"function",
"getOrderedChildren",
"(",
"$",
"perPage",
"=",
"null",
")",
"{",
"$",
"children",
"=",
"$",
"this",
"->",
"children",
"(",
")",
";",
"$",
"this",
"->",
"determineChildrenSorting",
"(",
"$",
"children",
")",
";",
"return",
"$",
"this",
"->",
"determineChildrenPagination",
"(",
"$",
"perPage",
",",
"$",
"children",
")",
";",
"}"
] | Get ordered children
@param int|null $perPage
@return Collection|LengthAwarePaginator | [
"Get",
"ordered",
"children"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L772-L779 |
NuclearCMS/Hierarchy | src/Node.php | Node.getPublishedOrderedChildren | public function getPublishedOrderedChildren($perPage = null)
{
$children = $this->children()
->published();
$this->determineChildrenSorting($children);
return $this->determineChildrenPagination($perPage, $children);
} | php | public function getPublishedOrderedChildren($perPage = null)
{
$children = $this->children()
->published();
$this->determineChildrenSorting($children);
return $this->determineChildrenPagination($perPage, $children);
} | [
"public",
"function",
"getPublishedOrderedChildren",
"(",
"$",
"perPage",
"=",
"null",
")",
"{",
"$",
"children",
"=",
"$",
"this",
"->",
"children",
"(",
")",
"->",
"published",
"(",
")",
";",
"$",
"this",
"->",
"determineChildrenSorting",
"(",
"$",
"children",
")",
";",
"return",
"$",
"this",
"->",
"determineChildrenPagination",
"(",
"$",
"perPage",
",",
"$",
"children",
")",
";",
"}"
] | Returns all published children with parameter ordered
@param int|null $perPage
@return Collection|LengthAwarePaginator | [
"Returns",
"all",
"published",
"children",
"with",
"parameter",
"ordered"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L787-L795 |
NuclearCMS/Hierarchy | src/Node.php | Node.determineChildrenSorting | public function determineChildrenSorting(HasMany $children)
{
if (in_array($this->children_order, $this->translatedAttributes))
{
$children->sortedBySourceAttribute(
$this->children_order,
$this->children_order_direction
);
} else
{
$children->orderBy(
$this->children_order, $this->children_order_direction
);
};
} | php | public function determineChildrenSorting(HasMany $children)
{
if (in_array($this->children_order, $this->translatedAttributes))
{
$children->sortedBySourceAttribute(
$this->children_order,
$this->children_order_direction
);
} else
{
$children->orderBy(
$this->children_order, $this->children_order_direction
);
};
} | [
"public",
"function",
"determineChildrenSorting",
"(",
"HasMany",
"$",
"children",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"children_order",
",",
"$",
"this",
"->",
"translatedAttributes",
")",
")",
"{",
"$",
"children",
"->",
"sortedBySourceAttribute",
"(",
"$",
"this",
"->",
"children_order",
",",
"$",
"this",
"->",
"children_order_direction",
")",
";",
"}",
"else",
"{",
"$",
"children",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"children_order",
",",
"$",
"this",
"->",
"children_order_direction",
")",
";",
"}",
";",
"}"
] | Determines the children sorting
@param HasMany $children | [
"Determines",
"the",
"children",
"sorting"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L802-L816 |
NuclearCMS/Hierarchy | src/Node.php | Node.determineChildrenPagination | public function determineChildrenPagination($perPage, HasMany $children)
{
if ($perPage === false)
{
return $children;
}
return is_null($perPage) ?
$children->get() :
$children->paginate($perPage);
} | php | public function determineChildrenPagination($perPage, HasMany $children)
{
if ($perPage === false)
{
return $children;
}
return is_null($perPage) ?
$children->get() :
$children->paginate($perPage);
} | [
"public",
"function",
"determineChildrenPagination",
"(",
"$",
"perPage",
",",
"HasMany",
"$",
"children",
")",
"{",
"if",
"(",
"$",
"perPage",
"===",
"false",
")",
"{",
"return",
"$",
"children",
";",
"}",
"return",
"is_null",
"(",
"$",
"perPage",
")",
"?",
"$",
"children",
"->",
"get",
"(",
")",
":",
"$",
"children",
"->",
"paginate",
"(",
"$",
"perPage",
")",
";",
"}"
] | Determines the pagination of children
@param mixed $perPage
@param HasMany $children
@return mixed | [
"Determines",
"the",
"pagination",
"of",
"children"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L825-L835 |
NuclearCMS/Hierarchy | src/Node.php | Node.getPositionOrderedChildren | public function getPositionOrderedChildren($perPage = null)
{
$children = $this->children()
->defaultOrder();
return $this->determineChildrenPagination($perPage, $children);
} | php | public function getPositionOrderedChildren($perPage = null)
{
$children = $this->children()
->defaultOrder();
return $this->determineChildrenPagination($perPage, $children);
} | [
"public",
"function",
"getPositionOrderedChildren",
"(",
"$",
"perPage",
"=",
"null",
")",
"{",
"$",
"children",
"=",
"$",
"this",
"->",
"children",
"(",
")",
"->",
"defaultOrder",
"(",
")",
";",
"return",
"$",
"this",
"->",
"determineChildrenPagination",
"(",
"$",
"perPage",
",",
"$",
"children",
")",
";",
"}"
] | Returns all children ordered by position
@param int|null $perPage
@return Collection|LengthAwarePaginator | [
"Returns",
"all",
"children",
"ordered",
"by",
"position"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L843-L849 |
NuclearCMS/Hierarchy | src/Node.php | Node.getPublishedPositionOrderedChildren | public function getPublishedPositionOrderedChildren($perPage = null)
{
$children = $this->children()
->published()
->defaultOrder();
return $this->determineChildrenPagination($perPage, $children);
} | php | public function getPublishedPositionOrderedChildren($perPage = null)
{
$children = $this->children()
->published()
->defaultOrder();
return $this->determineChildrenPagination($perPage, $children);
} | [
"public",
"function",
"getPublishedPositionOrderedChildren",
"(",
"$",
"perPage",
"=",
"null",
")",
"{",
"$",
"children",
"=",
"$",
"this",
"->",
"children",
"(",
")",
"->",
"published",
"(",
")",
"->",
"defaultOrder",
"(",
")",
";",
"return",
"$",
"this",
"->",
"determineChildrenPagination",
"(",
"$",
"perPage",
",",
"$",
"children",
")",
";",
"}"
] | Returns all published children position ordered
@param int|null $perPage
@return Collection|LengthAwarePaginator | [
"Returns",
"all",
"published",
"children",
"position",
"ordered"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L857-L864 |
NuclearCMS/Hierarchy | src/Node.php | Node.hasTranslatedChildren | public function hasTranslatedChildren($locale = null)
{
foreach ($this->getChildren() as $child)
{
if ($child->hasTranslation($locale))
{
return true;
}
}
return false;
} | php | public function hasTranslatedChildren($locale = null)
{
foreach ($this->getChildren() as $child)
{
if ($child->hasTranslation($locale))
{
return true;
}
}
return false;
} | [
"public",
"function",
"hasTranslatedChildren",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"hasTranslation",
"(",
"$",
"locale",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Filters children by locale
@param string $locale
@return Collection | [
"Filters",
"children",
"by",
"locale"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L872-L883 |
NuclearCMS/Hierarchy | src/Node.php | Node.deleteTranslation | public function deleteTranslation($locale)
{
if ($this->hasTranslation($locale))
{
if ($deleted = $this->getTranslation($locale)->delete())
{
$this->load('translations');
return true;
}
}
return false;
} | php | public function deleteTranslation($locale)
{
if ($this->hasTranslation($locale))
{
if ($deleted = $this->getTranslation($locale)->delete())
{
$this->load('translations');
return true;
}
}
return false;
} | [
"public",
"function",
"deleteTranslation",
"(",
"$",
"locale",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasTranslation",
"(",
"$",
"locale",
")",
")",
"{",
"if",
"(",
"$",
"deleted",
"=",
"$",
"this",
"->",
"getTranslation",
"(",
"$",
"locale",
")",
"->",
"delete",
"(",
")",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"'translations'",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Deletes a translation
@param string $locale
@return bool | [
"Deletes",
"a",
"translation"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L891-L904 |
NuclearCMS/Hierarchy | src/Node.php | Node.getLocaleForNodeName | public function getLocaleForNodeName($name)
{
foreach ($this->translations as $translation)
{
if ($translation->node_name === $name)
{
return $translation->locale;
}
}
return null;
} | php | public function getLocaleForNodeName($name)
{
foreach ($this->translations as $translation)
{
if ($translation->node_name === $name)
{
return $translation->locale;
}
}
return null;
} | [
"public",
"function",
"getLocaleForNodeName",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"if",
"(",
"$",
"translation",
"->",
"node_name",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"translation",
"->",
"locale",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns locale for name
@param string $name
@return string | [
"Returns",
"locale",
"for",
"name"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L912-L923 |
NuclearCMS/Hierarchy | src/Node.php | Node.isPublished | public function isPublished()
{
return ($this->status >= Node::PUBLISHED)
|| ($this->status >= Node::PENDING && $this->published_at <= Carbon::now());
} | php | public function isPublished()
{
return ($this->status >= Node::PUBLISHED)
|| ($this->status >= Node::PENDING && $this->published_at <= Carbon::now());
} | [
"public",
"function",
"isPublished",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"status",
">=",
"Node",
"::",
"PUBLISHED",
")",
"||",
"(",
"$",
"this",
"->",
"status",
">=",
"Node",
"::",
"PENDING",
"&&",
"$",
"this",
"->",
"published_at",
"<=",
"Carbon",
"::",
"now",
"(",
")",
")",
";",
"}"
] | Checks if the node is published
@return bool | [
"Checks",
"if",
"the",
"node",
"is",
"published"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1034-L1038 |
NuclearCMS/Hierarchy | src/Node.php | Node.transformInto | public function transformInto($id)
{
$newType = NodeType::find($id);
if (is_null($newType))
{
throw new \RuntimeException('Node type does not exist');
}
$sourceAttributes = $this->parseSourceAttributes();
$this->flushSources();
$this->transformNodeType($newType);
$this->remakeSources($newType);
$this->fill($sourceAttributes);
$this->save();
} | php | public function transformInto($id)
{
$newType = NodeType::find($id);
if (is_null($newType))
{
throw new \RuntimeException('Node type does not exist');
}
$sourceAttributes = $this->parseSourceAttributes();
$this->flushSources();
$this->transformNodeType($newType);
$this->remakeSources($newType);
$this->fill($sourceAttributes);
$this->save();
} | [
"public",
"function",
"transformInto",
"(",
"$",
"id",
")",
"{",
"$",
"newType",
"=",
"NodeType",
"::",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"newType",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Node type does not exist'",
")",
";",
"}",
"$",
"sourceAttributes",
"=",
"$",
"this",
"->",
"parseSourceAttributes",
"(",
")",
";",
"$",
"this",
"->",
"flushSources",
"(",
")",
";",
"$",
"this",
"->",
"transformNodeType",
"(",
"$",
"newType",
")",
";",
"$",
"this",
"->",
"remakeSources",
"(",
"$",
"newType",
")",
";",
"$",
"this",
"->",
"fill",
"(",
"$",
"sourceAttributes",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Transforms the node type with to given type
@param int $id
@throws \RuntimeException | [
"Transforms",
"the",
"node",
"type",
"with",
"to",
"given",
"type"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1086-L1106 |
NuclearCMS/Hierarchy | src/Node.php | Node.parseSourceAttributes | public function parseSourceAttributes()
{
$attributes = [];
foreach ($this->translations as $translation)
{
$attributes[$translation->locale] = $translation->source->toArray();
}
return $attributes;
} | php | public function parseSourceAttributes()
{
$attributes = [];
foreach ($this->translations as $translation)
{
$attributes[$translation->locale] = $translation->source->toArray();
}
return $attributes;
} | [
"public",
"function",
"parseSourceAttributes",
"(",
")",
"{",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"$",
"attributes",
"[",
"$",
"translation",
"->",
"locale",
"]",
"=",
"$",
"translation",
"->",
"source",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Parses source attributes
@return array | [
"Parses",
"source",
"attributes"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1113-L1123 |
NuclearCMS/Hierarchy | src/Node.php | Node.flushSources | protected function flushSources()
{
foreach ($this->translations as $translation)
{
$translation->source->delete();
$translation->flushTemporarySource();
unset($translation->relations['source']);
}
} | php | protected function flushSources()
{
foreach ($this->translations as $translation)
{
$translation->source->delete();
$translation->flushTemporarySource();
unset($translation->relations['source']);
}
} | [
"protected",
"function",
"flushSources",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"$",
"translation",
"->",
"source",
"->",
"delete",
"(",
")",
";",
"$",
"translation",
"->",
"flushTemporarySource",
"(",
")",
";",
"unset",
"(",
"$",
"translation",
"->",
"relations",
"[",
"'source'",
"]",
")",
";",
"}",
"}"
] | Flushes the source attributes | [
"Flushes",
"the",
"source",
"attributes"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1128-L1137 |
NuclearCMS/Hierarchy | src/Node.php | Node.transformNodeType | protected function transformNodeType(NodeType $nodeType)
{
$this->setNodeTypeByKey($nodeType->getKey());
foreach ($this->translations as $translation)
{
$translation->source_type = $nodeType->getName();
}
} | php | protected function transformNodeType(NodeType $nodeType)
{
$this->setNodeTypeByKey($nodeType->getKey());
foreach ($this->translations as $translation)
{
$translation->source_type = $nodeType->getName();
}
} | [
"protected",
"function",
"transformNodeType",
"(",
"NodeType",
"$",
"nodeType",
")",
"{",
"$",
"this",
"->",
"setNodeTypeByKey",
"(",
"$",
"nodeType",
"->",
"getKey",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"$",
"translation",
"->",
"source_type",
"=",
"$",
"nodeType",
"->",
"getName",
"(",
")",
";",
"}",
"}"
] | Transforms the node type
@param NodeType $nodeType | [
"Transforms",
"the",
"node",
"type"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1144-L1152 |
NuclearCMS/Hierarchy | src/Node.php | Node.remakeSources | protected function remakeSources(NodeType $nodeType)
{
foreach ($this->translations as $translation)
{
$source = $translation->getNewSourceModel($nodeType->getName());
$source->id = $translation->getKey();
$translation->relations['source'] = $source;
}
$this->propagateIdToSources();
} | php | protected function remakeSources(NodeType $nodeType)
{
foreach ($this->translations as $translation)
{
$source = $translation->getNewSourceModel($nodeType->getName());
$source->id = $translation->getKey();
$translation->relations['source'] = $source;
}
$this->propagateIdToSources();
} | [
"protected",
"function",
"remakeSources",
"(",
"NodeType",
"$",
"nodeType",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"$",
"source",
"=",
"$",
"translation",
"->",
"getNewSourceModel",
"(",
"$",
"nodeType",
"->",
"getName",
"(",
")",
")",
";",
"$",
"source",
"->",
"id",
"=",
"$",
"translation",
"->",
"getKey",
"(",
")",
";",
"$",
"translation",
"->",
"relations",
"[",
"'source'",
"]",
"=",
"$",
"source",
";",
"}",
"$",
"this",
"->",
"propagateIdToSources",
"(",
")",
";",
"}"
] | Remakes sources | [
"Remakes",
"sources"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1157-L1168 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeMostVisited | public function scopeMostVisited(Builder $query, $limit = null)
{
$query->select(\DB::raw('nodes.*, count(*) as `aggregate`'))
->join('node_site_view', 'nodes.id', '=', 'node_site_view.node_id')
->groupBy('nodes.id')
->orderBy('aggregate', 'desc');
if ($limit)
{
$query->limit($limit);
}
return $query;
} | php | public function scopeMostVisited(Builder $query, $limit = null)
{
$query->select(\DB::raw('nodes.*, count(*) as `aggregate`'))
->join('node_site_view', 'nodes.id', '=', 'node_site_view.node_id')
->groupBy('nodes.id')
->orderBy('aggregate', 'desc');
if ($limit)
{
$query->limit($limit);
}
return $query;
} | [
"public",
"function",
"scopeMostVisited",
"(",
"Builder",
"$",
"query",
",",
"$",
"limit",
"=",
"null",
")",
"{",
"$",
"query",
"->",
"select",
"(",
"\\",
"DB",
"::",
"raw",
"(",
"'nodes.*, count(*) as `aggregate`'",
")",
")",
"->",
"join",
"(",
"'node_site_view'",
",",
"'nodes.id'",
",",
"'='",
",",
"'node_site_view.node_id'",
")",
"->",
"groupBy",
"(",
"'nodes.id'",
")",
"->",
"orderBy",
"(",
"'aggregate'",
",",
"'desc'",
")",
";",
"if",
"(",
"$",
"limit",
")",
"{",
"$",
"query",
"->",
"limit",
"(",
"$",
"limit",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Most visited scope
@param Builder $query
@param int|null $limit
@return Builder | [
"Most",
"visited",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1177-L1190 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeRecentlyEdited | public function scopeRecentlyEdited(Builder $query, $limit = null)
{
$query->orderBy('updated_at', 'desc');
if ($limit)
{
$query->limit($limit);
}
return $query;
} | php | public function scopeRecentlyEdited(Builder $query, $limit = null)
{
$query->orderBy('updated_at', 'desc');
if ($limit)
{
$query->limit($limit);
}
return $query;
} | [
"public",
"function",
"scopeRecentlyEdited",
"(",
"Builder",
"$",
"query",
",",
"$",
"limit",
"=",
"null",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"'updated_at'",
",",
"'desc'",
")",
";",
"if",
"(",
"$",
"limit",
")",
"{",
"$",
"query",
"->",
"limit",
"(",
"$",
"limit",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Recently edited scope
@param Builder $query
@param int|null $limit
@return Builder | [
"Recently",
"edited",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1222-L1232 |
NuclearCMS/Hierarchy | src/Node.php | Node.scopeRecentlyCreated | public function scopeRecentlyCreated(Builder $query, $limit = null)
{
$query->orderBy('created_at', 'desc');
if ($limit)
{
$query->limit($limit);
}
return $query;
} | php | public function scopeRecentlyCreated(Builder $query, $limit = null)
{
$query->orderBy('created_at', 'desc');
if ($limit)
{
$query->limit($limit);
}
return $query;
} | [
"public",
"function",
"scopeRecentlyCreated",
"(",
"Builder",
"$",
"query",
",",
"$",
"limit",
"=",
"null",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"'created_at'",
",",
"'desc'",
")",
";",
"if",
"(",
"$",
"limit",
")",
"{",
"$",
"query",
"->",
"limit",
"(",
"$",
"limit",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Recently created scope
@param Builder $query
@param int|null $limit
@return Builder | [
"Recently",
"created",
"scope"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1241-L1251 |
NuclearCMS/Hierarchy | src/Node.php | Node.getSiteURL | public function getSiteURL($locale = null)
{
$node = $this;
$uri = '';
do
{
$uri = '/' . $node->getTranslationAttribute('node_name', $locale) . $uri;
$node = is_null($node->parent_id) ? null : node_bag($node->parent_id, false);
} while ( ! is_null($node) && $node->home != '1');
return url($uri);
} | php | public function getSiteURL($locale = null)
{
$node = $this;
$uri = '';
do
{
$uri = '/' . $node->getTranslationAttribute('node_name', $locale) . $uri;
$node = is_null($node->parent_id) ? null : node_bag($node->parent_id, false);
} while ( ! is_null($node) && $node->home != '1');
return url($uri);
} | [
"public",
"function",
"getSiteURL",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"node",
"=",
"$",
"this",
";",
"$",
"uri",
"=",
"''",
";",
"do",
"{",
"$",
"uri",
"=",
"'/'",
".",
"$",
"node",
"->",
"getTranslationAttribute",
"(",
"'node_name'",
",",
"$",
"locale",
")",
".",
"$",
"uri",
";",
"$",
"node",
"=",
"is_null",
"(",
"$",
"node",
"->",
"parent_id",
")",
"?",
"null",
":",
"node_bag",
"(",
"$",
"node",
"->",
"parent_id",
",",
"false",
")",
";",
"}",
"while",
"(",
"!",
"is_null",
"(",
"$",
"node",
")",
"&&",
"$",
"node",
"->",
"home",
"!=",
"'1'",
")",
";",
"return",
"url",
"(",
"$",
"uri",
")",
";",
"}"
] | Gets the full url for node
@param string $locale
@return string | [
"Gets",
"the",
"full",
"url",
"for",
"node"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1270-L1282 |
NuclearCMS/Hierarchy | src/Node.php | Node.getPreviewURL | public function getPreviewURL($locale = null)
{
$token = app()->make(TokenManager::class)
->makeNewToken('preview_nodes');
$url = $this->getSiteURL($locale);
return $url . '?preview_nodes=' . $token;
} | php | public function getPreviewURL($locale = null)
{
$token = app()->make(TokenManager::class)
->makeNewToken('preview_nodes');
$url = $this->getSiteURL($locale);
return $url . '?preview_nodes=' . $token;
} | [
"public",
"function",
"getPreviewURL",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"token",
"=",
"app",
"(",
")",
"->",
"make",
"(",
"TokenManager",
"::",
"class",
")",
"->",
"makeNewToken",
"(",
"'preview_nodes'",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"getSiteURL",
"(",
"$",
"locale",
")",
";",
"return",
"$",
"url",
".",
"'?preview_nodes='",
".",
"$",
"token",
";",
"}"
] | Returns the preview url
@param string $locale
@return string | [
"Returns",
"the",
"preview",
"url"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1290-L1298 |
NuclearCMS/Hierarchy | src/Node.php | Node.getDefaultEditUrl | public function getDefaultEditUrl($locale = null)
{
$parameters = [
$this->getKey(),
$this->translateOrFirst($locale)->getKey()
];
if ($this->hidesChildren())
{
if ($this->children_display_mode === 'tree')
{
$parameters = current($parameters);
}
return route('reactor.nodes.children.' . $this->children_display_mode,
$parameters);
}
return route('reactor.nodes.edit',
$parameters);
} | php | public function getDefaultEditUrl($locale = null)
{
$parameters = [
$this->getKey(),
$this->translateOrFirst($locale)->getKey()
];
if ($this->hidesChildren())
{
if ($this->children_display_mode === 'tree')
{
$parameters = current($parameters);
}
return route('reactor.nodes.children.' . $this->children_display_mode,
$parameters);
}
return route('reactor.nodes.edit',
$parameters);
} | [
"public",
"function",
"getDefaultEditUrl",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"parameters",
"=",
"[",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"$",
"this",
"->",
"translateOrFirst",
"(",
"$",
"locale",
")",
"->",
"getKey",
"(",
")",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"hidesChildren",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"children_display_mode",
"===",
"'tree'",
")",
"{",
"$",
"parameters",
"=",
"current",
"(",
"$",
"parameters",
")",
";",
"}",
"return",
"route",
"(",
"'reactor.nodes.children.'",
".",
"$",
"this",
"->",
"children_display_mode",
",",
"$",
"parameters",
")",
";",
"}",
"return",
"route",
"(",
"'reactor.nodes.edit'",
",",
"$",
"parameters",
")",
";",
"}"
] | Determines the default edit link for node
@param null|string $locale
@return string | [
"Determines",
"the",
"default",
"edit",
"link",
"for",
"node"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1306-L1326 |
NuclearCMS/Hierarchy | src/Node.php | Node.getSearchable | public function getSearchable()
{
// When there is no node type we exclude source attributes
if (is_null($this->getNodeTypeName()))
{
return $this->searchable;
}
$modelName = source_model_name($this->getNodeTypeName(), true);
return array_merge_recursive(
$this->searchable,
call_user_func([$modelName, 'getSearchable'])
);
} | php | public function getSearchable()
{
// When there is no node type we exclude source attributes
if (is_null($this->getNodeTypeName()))
{
return $this->searchable;
}
$modelName = source_model_name($this->getNodeTypeName(), true);
return array_merge_recursive(
$this->searchable,
call_user_func([$modelName, 'getSearchable'])
);
} | [
"public",
"function",
"getSearchable",
"(",
")",
"{",
"// When there is no node type we exclude source attributes",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"searchable",
";",
"}",
"$",
"modelName",
"=",
"source_model_name",
"(",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
",",
"true",
")",
";",
"return",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"searchable",
",",
"call_user_func",
"(",
"[",
"$",
"modelName",
",",
"'getSearchable'",
"]",
")",
")",
";",
"}"
] | It returns the searchable
@return array | [
"It",
"returns",
"the",
"searchable"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1333-L1347 |
NuclearCMS/Hierarchy | src/Node.php | Node.getMetaImage | public function getMetaImage()
{
$metaImage = $this->getTranslationAttribute('meta_image');
if ($metaImage = get_nuclear_cover($metaImage))
{
return $metaImage;
}
if ($coverImage = $this->getCoverImage())
{
return $coverImage;
}
return null;
} | php | public function getMetaImage()
{
$metaImage = $this->getTranslationAttribute('meta_image');
if ($metaImage = get_nuclear_cover($metaImage))
{
return $metaImage;
}
if ($coverImage = $this->getCoverImage())
{
return $coverImage;
}
return null;
} | [
"public",
"function",
"getMetaImage",
"(",
")",
"{",
"$",
"metaImage",
"=",
"$",
"this",
"->",
"getTranslationAttribute",
"(",
"'meta_image'",
")",
";",
"if",
"(",
"$",
"metaImage",
"=",
"get_nuclear_cover",
"(",
"$",
"metaImage",
")",
")",
"{",
"return",
"$",
"metaImage",
";",
"}",
"if",
"(",
"$",
"coverImage",
"=",
"$",
"this",
"->",
"getCoverImage",
"(",
")",
")",
"{",
"return",
"$",
"coverImage",
";",
"}",
"return",
"null",
";",
"}"
] | Meta image getter
@return Image|null | [
"Meta",
"image",
"getter"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1414-L1429 |
NuclearCMS/Hierarchy | src/Node.php | Node.getCoverImage | public function getCoverImage()
{
if ($this->coverImage)
{
return $this->coverImage;
}
$modelName = source_model_name($this->getNodeTypeName(), true);
$mutatables = call_user_func([$modelName, 'getMutatables']);
foreach ($mutatables as $mutatable => $type)
{
if ($type === 'gallery' && ($images = $this->getTranslationAttribute($mutatable, null, true, true)))
{
if ($cover = get_nuclear_cover($images))
{
$this->coverImage = $cover;
return $cover;
}
}
if ($type === 'document' && ($document = $this->getTranslationAttribute($mutatable, null, true, true)))
{
if ($document = get_nuclear_cover($document))
{
$this->coverImage = $document;
return $document;
}
}
}
return null;
} | php | public function getCoverImage()
{
if ($this->coverImage)
{
return $this->coverImage;
}
$modelName = source_model_name($this->getNodeTypeName(), true);
$mutatables = call_user_func([$modelName, 'getMutatables']);
foreach ($mutatables as $mutatable => $type)
{
if ($type === 'gallery' && ($images = $this->getTranslationAttribute($mutatable, null, true, true)))
{
if ($cover = get_nuclear_cover($images))
{
$this->coverImage = $cover;
return $cover;
}
}
if ($type === 'document' && ($document = $this->getTranslationAttribute($mutatable, null, true, true)))
{
if ($document = get_nuclear_cover($document))
{
$this->coverImage = $document;
return $document;
}
}
}
return null;
} | [
"public",
"function",
"getCoverImage",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"coverImage",
")",
"{",
"return",
"$",
"this",
"->",
"coverImage",
";",
"}",
"$",
"modelName",
"=",
"source_model_name",
"(",
"$",
"this",
"->",
"getNodeTypeName",
"(",
")",
",",
"true",
")",
";",
"$",
"mutatables",
"=",
"call_user_func",
"(",
"[",
"$",
"modelName",
",",
"'getMutatables'",
"]",
")",
";",
"foreach",
"(",
"$",
"mutatables",
"as",
"$",
"mutatable",
"=>",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'gallery'",
"&&",
"(",
"$",
"images",
"=",
"$",
"this",
"->",
"getTranslationAttribute",
"(",
"$",
"mutatable",
",",
"null",
",",
"true",
",",
"true",
")",
")",
")",
"{",
"if",
"(",
"$",
"cover",
"=",
"get_nuclear_cover",
"(",
"$",
"images",
")",
")",
"{",
"$",
"this",
"->",
"coverImage",
"=",
"$",
"cover",
";",
"return",
"$",
"cover",
";",
"}",
"}",
"if",
"(",
"$",
"type",
"===",
"'document'",
"&&",
"(",
"$",
"document",
"=",
"$",
"this",
"->",
"getTranslationAttribute",
"(",
"$",
"mutatable",
",",
"null",
",",
"true",
",",
"true",
")",
")",
")",
"{",
"if",
"(",
"$",
"document",
"=",
"get_nuclear_cover",
"(",
"$",
"document",
")",
")",
"{",
"$",
"this",
"->",
"coverImage",
"=",
"$",
"document",
";",
"return",
"$",
"document",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Gets the cover image
@return Image|null | [
"Gets",
"the",
"cover",
"image"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Node.php#L1436-L1471 |
Jimdo/jimphle-data-structure | src/Jimphle/DataStructure/Map.php | Map.setIn | public function setIn($keys, $value)
{
$lastKey = array_shift($keys);
if (count($keys) > 0 && !isset($this->$lastKey->{$keys[0]})) {
throw new \RuntimeException(sprintf("Key '%s->%s' does not exist.", $lastKey, $keys[0]));
}
if (count($keys) > 0 && $this->$lastKey instanceof Map) {
return $this->merge(new self(array($lastKey => $this->$lastKey->setIn($keys, $value))));
}
return $this->merge(new self(array($lastKey => $value)));
} | php | public function setIn($keys, $value)
{
$lastKey = array_shift($keys);
if (count($keys) > 0 && !isset($this->$lastKey->{$keys[0]})) {
throw new \RuntimeException(sprintf("Key '%s->%s' does not exist.", $lastKey, $keys[0]));
}
if (count($keys) > 0 && $this->$lastKey instanceof Map) {
return $this->merge(new self(array($lastKey => $this->$lastKey->setIn($keys, $value))));
}
return $this->merge(new self(array($lastKey => $value)));
} | [
"public",
"function",
"setIn",
"(",
"$",
"keys",
",",
"$",
"value",
")",
"{",
"$",
"lastKey",
"=",
"array_shift",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"count",
"(",
"$",
"keys",
")",
">",
"0",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"$",
"lastKey",
"->",
"{",
"$",
"keys",
"[",
"0",
"]",
"}",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"\"Key '%s->%s' does not exist.\"",
",",
"$",
"lastKey",
",",
"$",
"keys",
"[",
"0",
"]",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"keys",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"$",
"lastKey",
"instanceof",
"Map",
")",
"{",
"return",
"$",
"this",
"->",
"merge",
"(",
"new",
"self",
"(",
"array",
"(",
"$",
"lastKey",
"=>",
"$",
"this",
"->",
"$",
"lastKey",
"->",
"setIn",
"(",
"$",
"keys",
",",
"$",
"value",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"merge",
"(",
"new",
"self",
"(",
"array",
"(",
"$",
"lastKey",
"=>",
"$",
"value",
")",
")",
")",
";",
"}"
] | set a value in a nested map
@param array $keys
@param mixed $value
@return Map | [
"set",
"a",
"value",
"in",
"a",
"nested",
"map"
] | train | https://github.com/Jimdo/jimphle-data-structure/blob/15f784e4af48520079f8639748ab68b074dbc005/src/Jimphle/DataStructure/Map.php#L74-L84 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_update.php | ezcQueryUpdate.update | public function update( $table )
{
$table = $this->getIdentifier( $table );
$table = $this->getPrefixedTableNames($table);
$this->table = $table;
return $this;
} | php | public function update( $table )
{
$table = $this->getIdentifier( $table );
$table = $this->getPrefixedTableNames($table);
$this->table = $table;
return $this;
} | [
"public",
"function",
"update",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"table",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"getPrefixedTableNames",
"(",
"$",
"table",
")",
";",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"return",
"$",
"this",
";",
"}"
] | Opens the query and sets the target table to $table.
update() returns a pointer to $this.
@param string $table
@return ezcQueryUpdate | [
"Opens",
"the",
"query",
"and",
"sets",
"the",
"target",
"table",
"to",
"$table",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_update.php#L88-L94 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_update.php | ezcQueryUpdate.set | public function set( $column, $expression )
{
$column = $this->getIdentifier( $column );
$expression = $this->getIdentifier( $expression );
$this->values[$column] = $expression;
return $this;
} | php | public function set( $column, $expression )
{
$column = $this->getIdentifier( $column );
$expression = $this->getIdentifier( $expression );
$this->values[$column] = $expression;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"column",
",",
"$",
"expression",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"column",
")",
";",
"$",
"expression",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"expression",
")",
";",
"$",
"this",
"->",
"values",
"[",
"$",
"column",
"]",
"=",
"$",
"expression",
";",
"return",
"$",
"this",
";",
"}"
] | The update query will set the column $column to the value $expression.
@param string $column
@param string $expression
@return ezcQueryUpdate | [
"The",
"update",
"query",
"will",
"set",
"the",
"column",
"$column",
"to",
"the",
"value",
"$expression",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_update.php#L103-L109 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_update.php | ezcQueryUpdate.getQuery | public function getQuery()
{
if ( $this->table == null || empty( $this->values ) )
{
$problem = $this->table == null ? 'table' : 'values';
throw new ezcQueryInvalidException( "UPDATE", "No " . $problem . " set." );
}
$query = "UPDATE {$this->table} SET ";
// build an append set part
$setString = null;
foreach ( $this->values as $key => $value )
{
if ( $setString === null )
{
$setString = "{$key} = {$value}";
}
else
{
$setString .= ", {$key} = {$value}";
}
}
$query .= $setString;
// append where part.
if ( $this->whereString !== null )
{
$query .= " {$this->whereString}";
}
return $query;
} | php | public function getQuery()
{
if ( $this->table == null || empty( $this->values ) )
{
$problem = $this->table == null ? 'table' : 'values';
throw new ezcQueryInvalidException( "UPDATE", "No " . $problem . " set." );
}
$query = "UPDATE {$this->table} SET ";
// build an append set part
$setString = null;
foreach ( $this->values as $key => $value )
{
if ( $setString === null )
{
$setString = "{$key} = {$value}";
}
else
{
$setString .= ", {$key} = {$value}";
}
}
$query .= $setString;
// append where part.
if ( $this->whereString !== null )
{
$query .= " {$this->whereString}";
}
return $query;
} | [
"public",
"function",
"getQuery",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"table",
"==",
"null",
"||",
"empty",
"(",
"$",
"this",
"->",
"values",
")",
")",
"{",
"$",
"problem",
"=",
"$",
"this",
"->",
"table",
"==",
"null",
"?",
"'table'",
":",
"'values'",
";",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"\"UPDATE\"",
",",
"\"No \"",
".",
"$",
"problem",
".",
"\" set.\"",
")",
";",
"}",
"$",
"query",
"=",
"\"UPDATE {$this->table} SET \"",
";",
"// build an append set part",
"$",
"setString",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"setString",
"===",
"null",
")",
"{",
"$",
"setString",
"=",
"\"{$key} = {$value}\"",
";",
"}",
"else",
"{",
"$",
"setString",
".=",
"\", {$key} = {$value}\"",
";",
"}",
"}",
"$",
"query",
".=",
"$",
"setString",
";",
"// append where part.",
"if",
"(",
"$",
"this",
"->",
"whereString",
"!==",
"null",
")",
"{",
"$",
"query",
".=",
"\" {$this->whereString}\"",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Returns the query string for this query object.
@todo wrong exception
@throws ezcQueryInvalidException if no table or no values have been set.
@return string | [
"Returns",
"the",
"query",
"string",
"for",
"this",
"query",
"object",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_update.php#L164-L195 |
maestroprog/saw-php | src/Standalone/Controller/WorkerBalance.php | WorkerBalance.work | public function work()
{
$workerNeed = self::WORKER_MIN * $this->workerMultiplier;
$workerCount = count($this->workerPool);
if (
($workerCount < $workerNeed && $workerCount < $this->workerMaxCount)
&& !$this->running
) {
// run new worker
$this->workerRun = $this->workerStarter->start();
$this->running = time();
} elseif ($this->running && $this->running < time() - 10) {
// timeout 10 sec - не удалось запустить воркер
$this->running = 0;
if ($this->workerRun->isRunning()) {
// убиваем запущенный процесс, если он ещё работает
$this->workerRun->kill();
}
}
} | php | public function work()
{
$workerNeed = self::WORKER_MIN * $this->workerMultiplier;
$workerCount = count($this->workerPool);
if (
($workerCount < $workerNeed && $workerCount < $this->workerMaxCount)
&& !$this->running
) {
// run new worker
$this->workerRun = $this->workerStarter->start();
$this->running = time();
} elseif ($this->running && $this->running < time() - 10) {
// timeout 10 sec - не удалось запустить воркер
$this->running = 0;
if ($this->workerRun->isRunning()) {
// убиваем запущенный процесс, если он ещё работает
$this->workerRun->kill();
}
}
} | [
"public",
"function",
"work",
"(",
")",
"{",
"$",
"workerNeed",
"=",
"self",
"::",
"WORKER_MIN",
"*",
"$",
"this",
"->",
"workerMultiplier",
";",
"$",
"workerCount",
"=",
"count",
"(",
"$",
"this",
"->",
"workerPool",
")",
";",
"if",
"(",
"(",
"$",
"workerCount",
"<",
"$",
"workerNeed",
"&&",
"$",
"workerCount",
"<",
"$",
"this",
"->",
"workerMaxCount",
")",
"&&",
"!",
"$",
"this",
"->",
"running",
")",
"{",
"// run new worker",
"$",
"this",
"->",
"workerRun",
"=",
"$",
"this",
"->",
"workerStarter",
"->",
"start",
"(",
")",
";",
"$",
"this",
"->",
"running",
"=",
"time",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"running",
"&&",
"$",
"this",
"->",
"running",
"<",
"time",
"(",
")",
"-",
"10",
")",
"{",
"// timeout 10 sec - не удалось запустить воркер",
"$",
"this",
"->",
"running",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"workerRun",
"->",
"isRunning",
"(",
")",
")",
"{",
"// убиваем запущенный процесс, если он ещё работает",
"$",
"this",
"->",
"workerRun",
"->",
"kill",
"(",
")",
";",
"}",
"}",
"}"
] | Предполагается, что этот метод будет запускать новые воркеры, когда это нужно.
Воркеры запускаются по одному, после запуска контроллер ждёт новый воркер до 10 секунд. | [
"Предполагается",
"что",
"этот",
"метод",
"будет",
"запускать",
"новые",
"воркеры",
"когда",
"это",
"нужно",
".",
"Воркеры",
"запускаются",
"по",
"одному",
"после",
"запуска",
"контроллер",
"ждёт",
"новый",
"воркер",
"до",
"10",
"секунд",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Standalone/Controller/WorkerBalance.php#L85-L105 |
maestroprog/saw-php | src/Standalone/Controller/WorkerBalance.php | WorkerBalance.addWorker | public function addWorker(Worker $worker): bool
{
if (!$this->running) {
return false;
}
$this->running = 0;
$this->workerPool->add($worker);
return true;
} | php | public function addWorker(Worker $worker): bool
{
if (!$this->running) {
return false;
}
$this->running = 0;
$this->workerPool->add($worker);
return true;
} | [
"public",
"function",
"addWorker",
"(",
"Worker",
"$",
"worker",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"running",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"running",
"=",
"0",
";",
"$",
"this",
"->",
"workerPool",
"->",
"add",
"(",
"$",
"worker",
")",
";",
"return",
"true",
";",
"}"
] | Добавляет воркер в балансировщик,
когда тот успешно стартует.
@param Worker $worker
@return bool | [
"Добавляет",
"воркер",
"в",
"балансировщик",
"когда",
"тот",
"успешно",
"стартует",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Standalone/Controller/WorkerBalance.php#L114-L123 |
maestroprog/saw-php | src/Standalone/Controller/WorkerBalance.php | WorkerBalance.removeWorker | public function removeWorker(Worker $worker)
{
$this->commander->runSync(new WorkerDelete($worker->getClient()), 5);
$this->workerPool->remove($worker);
// TODO
// нужно запилить механизм перехвата невыполненных задач
/*foreach ($this->tasks as $name => $workers) {
if (isset($workers[$dsc])) {
unset($this->tasks[$name][$dsc]);
}
}*/
} | php | public function removeWorker(Worker $worker)
{
$this->commander->runSync(new WorkerDelete($worker->getClient()), 5);
$this->workerPool->remove($worker);
// TODO
// нужно запилить механизм перехвата невыполненных задач
/*foreach ($this->tasks as $name => $workers) {
if (isset($workers[$dsc])) {
unset($this->tasks[$name][$dsc]);
}
}*/
} | [
"public",
"function",
"removeWorker",
"(",
"Worker",
"$",
"worker",
")",
"{",
"$",
"this",
"->",
"commander",
"->",
"runSync",
"(",
"new",
"WorkerDelete",
"(",
"$",
"worker",
"->",
"getClient",
"(",
")",
")",
",",
"5",
")",
";",
"$",
"this",
"->",
"workerPool",
"->",
"remove",
"(",
"$",
"worker",
")",
";",
"// TODO",
"// нужно запилить механизм перехвата невыполненных задач",
"/*foreach ($this->tasks as $name => $workers) {\n if (isset($workers[$dsc])) {\n unset($this->tasks[$name][$dsc]);\n }\n }*/",
"}"
] | Удаляет воркер из балансировщика.
@param Worker $worker | [
"Удаляет",
"воркер",
"из",
"балансировщика",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Standalone/Controller/WorkerBalance.php#L130-L141 |
maestroprog/saw-php | src/Standalone/Controller/WorkerBalance.php | WorkerBalance.getLowLoadedWorker | public function getLowLoadedWorker(AbstractThread $thread): Worker
{
$selectedWorker = null;
foreach ($this->workerPool as $worker) {
/**
* @var $worker Worker
*/
if ($worker->getState() === Worker::STOP || !$worker->isThreadKnow($thread)) {
// не знает такую задачу
continue;
}
if (!isset($count)) {
$count = $worker->getCountRunThreads();
$selectedWorker = $worker;
} elseif ($count > ($newCount = $worker->getCountRunThreads())) {
$count = $newCount;
$selectedWorker = $worker;
}
}
if (is_null($selectedWorker)) {
throw new \RuntimeException('Cannot select worker.');
}
return $selectedWorker;
} | php | public function getLowLoadedWorker(AbstractThread $thread): Worker
{
$selectedWorker = null;
foreach ($this->workerPool as $worker) {
/**
* @var $worker Worker
*/
if ($worker->getState() === Worker::STOP || !$worker->isThreadKnow($thread)) {
// не знает такую задачу
continue;
}
if (!isset($count)) {
$count = $worker->getCountRunThreads();
$selectedWorker = $worker;
} elseif ($count > ($newCount = $worker->getCountRunThreads())) {
$count = $newCount;
$selectedWorker = $worker;
}
}
if (is_null($selectedWorker)) {
throw new \RuntimeException('Cannot select worker.');
}
return $selectedWorker;
} | [
"public",
"function",
"getLowLoadedWorker",
"(",
"AbstractThread",
"$",
"thread",
")",
":",
"Worker",
"{",
"$",
"selectedWorker",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"workerPool",
"as",
"$",
"worker",
")",
"{",
"/**\n * @var $worker Worker\n */",
"if",
"(",
"$",
"worker",
"->",
"getState",
"(",
")",
"===",
"Worker",
"::",
"STOP",
"||",
"!",
"$",
"worker",
"->",
"isThreadKnow",
"(",
"$",
"thread",
")",
")",
"{",
"// не знает такую задачу",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"count",
")",
")",
"{",
"$",
"count",
"=",
"$",
"worker",
"->",
"getCountRunThreads",
"(",
")",
";",
"$",
"selectedWorker",
"=",
"$",
"worker",
";",
"}",
"elseif",
"(",
"$",
"count",
">",
"(",
"$",
"newCount",
"=",
"$",
"worker",
"->",
"getCountRunThreads",
"(",
")",
")",
")",
"{",
"$",
"count",
"=",
"$",
"newCount",
";",
"$",
"selectedWorker",
"=",
"$",
"worker",
";",
"}",
"}",
"if",
"(",
"is_null",
"(",
"$",
"selectedWorker",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot select worker.'",
")",
";",
"}",
"return",
"$",
"selectedWorker",
";",
"}"
] | Получить одного из слабо нагруженных воркеров.
@param AbstractThread $thread Поток для выполнения которого необходимо найти воркера.
@return Worker
@throws \RuntimeException | [
"Получить",
"одного",
"из",
"слабо",
"нагруженных",
"воркеров",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Standalone/Controller/WorkerBalance.php#L150-L174 |
oroinc/OroLayoutComponent | AliasCollection.php | AliasCollection.getId | public function getId($alias)
{
if (!isset($this->aliases[$alias])) {
return null;
}
$id = $this->aliases[$alias];
while (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
return $id;
} | php | public function getId($alias)
{
if (!isset($this->aliases[$alias])) {
return null;
}
$id = $this->aliases[$alias];
while (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
return $id;
} | [
"public",
"function",
"getId",
"(",
"$",
"alias",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"id",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
";",
"while",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
";",
"}",
"return",
"$",
"id",
";",
"}"
] | Returns the identifier of the item which has the given alias
@param string $alias The item alias
@return string|null The item identifier or null if no one item has the given alias | [
"Returns",
"the",
"identifier",
"of",
"the",
"item",
"which",
"has",
"the",
"given",
"alias"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/AliasCollection.php#L50-L62 |
oroinc/OroLayoutComponent | AliasCollection.php | AliasCollection.add | public function add($alias, $id)
{
if (isset($this->aliases[$alias])) {
if ($this->aliases[$alias] === $id) {
// exactly the same alias for the specified item is already exists
return $this;
}
throw new Exception\AliasAlreadyExistsException(
sprintf(
'The "%s" sting cannot be used as an alias for "%s" item'
. ' because it is already used for "%s" item.',
$alias,
$id,
$this->aliases[$alias]
)
);
}
$this->aliases[$alias] = $id;
$id = $this->getId($alias);
$this->ids[$id][] = $alias;
return $this;
} | php | public function add($alias, $id)
{
if (isset($this->aliases[$alias])) {
if ($this->aliases[$alias] === $id) {
// exactly the same alias for the specified item is already exists
return $this;
}
throw new Exception\AliasAlreadyExistsException(
sprintf(
'The "%s" sting cannot be used as an alias for "%s" item'
. ' because it is already used for "%s" item.',
$alias,
$id,
$this->aliases[$alias]
)
);
}
$this->aliases[$alias] = $id;
$id = $this->getId($alias);
$this->ids[$id][] = $alias;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"alias",
",",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
"===",
"$",
"id",
")",
"{",
"// exactly the same alias for the specified item is already exists",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"AliasAlreadyExistsException",
"(",
"sprintf",
"(",
"'The \"%s\" sting cannot be used as an alias for \"%s\" item'",
".",
"' because it is already used for \"%s\" item.'",
",",
"$",
"alias",
",",
"$",
"id",
",",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"id",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
"$",
"alias",
")",
";",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
"[",
"]",
"=",
"$",
"alias",
";",
"return",
"$",
"this",
";",
"}"
] | Registers an alias for the specified identifier
@param string $alias A string that can be used as an alias for the item id
@param string $id The item identifier or already registered item alias
@return self
@throws Exception\AliasAlreadyExistsException if the alias is used for another item | [
"Registers",
"an",
"alias",
"for",
"the",
"specified",
"identifier"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/AliasCollection.php#L88-L113 |
oroinc/OroLayoutComponent | AliasCollection.php | AliasCollection.remove | public function remove($alias)
{
$id = $this->getId($alias);
if ($id) {
unset($this->aliases[$alias]);
$aliases = &$this->ids[$id];
unset($aliases[array_search($alias, $aliases, true)]);
if (!empty($aliases)) {
$this->removeDependedAliases($alias, $id);
} else {
unset($this->ids[$id]);
}
}
return $this;
} | php | public function remove($alias)
{
$id = $this->getId($alias);
if ($id) {
unset($this->aliases[$alias]);
$aliases = &$this->ids[$id];
unset($aliases[array_search($alias, $aliases, true)]);
if (!empty($aliases)) {
$this->removeDependedAliases($alias, $id);
} else {
unset($this->ids[$id]);
}
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"alias",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
"$",
"alias",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
")",
";",
"$",
"aliases",
"=",
"&",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
";",
"unset",
"(",
"$",
"aliases",
"[",
"array_search",
"(",
"$",
"alias",
",",
"$",
"aliases",
",",
"true",
")",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aliases",
")",
")",
"{",
"$",
"this",
"->",
"removeDependedAliases",
"(",
"$",
"alias",
",",
"$",
"id",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes the alias
@param string $alias The item alias
@return self | [
"Removes",
"the",
"alias"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/AliasCollection.php#L122-L137 |
oroinc/OroLayoutComponent | AliasCollection.php | AliasCollection.removeById | public function removeById($id)
{
if (isset($this->ids[$id])) {
foreach ($this->ids[$id] as $alias) {
unset($this->aliases[$alias]);
}
unset($this->ids[$id]);
}
return $this;
} | php | public function removeById($id)
{
if (isset($this->ids[$id])) {
foreach ($this->ids[$id] as $alias) {
unset($this->aliases[$alias]);
}
unset($this->ids[$id]);
}
return $this;
} | [
"public",
"function",
"removeById",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
"as",
"$",
"alias",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes all aliases for the specified item
@param string $id The identifier of item which aliases should be removed
@return self | [
"Removes",
"all",
"aliases",
"for",
"the",
"specified",
"item"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/AliasCollection.php#L146-L156 |
oroinc/OroLayoutComponent | AliasCollection.php | AliasCollection.removeDependedAliases | protected function removeDependedAliases($alias, $id)
{
foreach ($this->ids[$id] as $otherAlias) {
if (isset($this->aliases[$otherAlias]) && $this->aliases[$otherAlias] === $alias) {
unset($this->aliases[$otherAlias]);
$aliases = &$this->ids[$id];
unset($aliases[array_search($otherAlias, $aliases, true)]);
if (!empty($aliases)) {
$this->removeDependedAliases($otherAlias, $id);
} else {
unset($this->ids[$id]);
}
}
}
} | php | protected function removeDependedAliases($alias, $id)
{
foreach ($this->ids[$id] as $otherAlias) {
if (isset($this->aliases[$otherAlias]) && $this->aliases[$otherAlias] === $alias) {
unset($this->aliases[$otherAlias]);
$aliases = &$this->ids[$id];
unset($aliases[array_search($otherAlias, $aliases, true)]);
if (!empty($aliases)) {
$this->removeDependedAliases($otherAlias, $id);
} else {
unset($this->ids[$id]);
}
}
}
} | [
"protected",
"function",
"removeDependedAliases",
"(",
"$",
"alias",
",",
"$",
"id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
"as",
"$",
"otherAlias",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"otherAlias",
"]",
")",
"&&",
"$",
"this",
"->",
"aliases",
"[",
"$",
"otherAlias",
"]",
"===",
"$",
"alias",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"otherAlias",
"]",
")",
";",
"$",
"aliases",
"=",
"&",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
";",
"unset",
"(",
"$",
"aliases",
"[",
"array_search",
"(",
"$",
"otherAlias",
",",
"$",
"aliases",
",",
"true",
")",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aliases",
")",
")",
"{",
"$",
"this",
"->",
"removeDependedAliases",
"(",
"$",
"otherAlias",
",",
"$",
"id",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"ids",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Removes all depended aliases
For example if "alias3" is removed in alias chain like "alias1 -> alias2 -> alias3 -> id"
than both "alias1" and "alias2" are removed as well
@param string $alias
@param string $id | [
"Removes",
"all",
"depended",
"aliases",
"For",
"example",
"if",
"alias3",
"is",
"removed",
"in",
"alias",
"chain",
"like",
"alias1",
"-",
">",
"alias2",
"-",
">",
"alias3",
"-",
">",
"id",
"than",
"both",
"alias1",
"and",
"alias2",
"are",
"removed",
"as",
"well"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/AliasCollection.php#L185-L199 |
CupOfTea696/WordPress-Composer | src/Plugin.php | Plugin.activate | public function activate(Composer $composer, IOInterface $io)
{
$installer = new Installer($io, $composer, $this);
$composer->getInstallationManager()->addInstaller($installer);
$this->composer = $composer;
$this->io = $io;
include_once dirname(__FILE__) . '/helpers.php';
if (file_exists($this->getVendorDirectory() . '/autoload.php')) {
include_once $this->getVendorDirectory() . '/autoload.php';
if (class_exists('\Dotenv\Dotenv')) {
$this->env = new \Dotenv\Dotenv($this->getRootDirectory());
$this->env->overload();
}
}
EventSubscriber::setPlugin($this);
} | php | public function activate(Composer $composer, IOInterface $io)
{
$installer = new Installer($io, $composer, $this);
$composer->getInstallationManager()->addInstaller($installer);
$this->composer = $composer;
$this->io = $io;
include_once dirname(__FILE__) . '/helpers.php';
if (file_exists($this->getVendorDirectory() . '/autoload.php')) {
include_once $this->getVendorDirectory() . '/autoload.php';
if (class_exists('\Dotenv\Dotenv')) {
$this->env = new \Dotenv\Dotenv($this->getRootDirectory());
$this->env->overload();
}
}
EventSubscriber::setPlugin($this);
} | [
"public",
"function",
"activate",
"(",
"Composer",
"$",
"composer",
",",
"IOInterface",
"$",
"io",
")",
"{",
"$",
"installer",
"=",
"new",
"Installer",
"(",
"$",
"io",
",",
"$",
"composer",
",",
"$",
"this",
")",
";",
"$",
"composer",
"->",
"getInstallationManager",
"(",
")",
"->",
"addInstaller",
"(",
"$",
"installer",
")",
";",
"$",
"this",
"->",
"composer",
"=",
"$",
"composer",
";",
"$",
"this",
"->",
"io",
"=",
"$",
"io",
";",
"include_once",
"dirname",
"(",
"__FILE__",
")",
".",
"'/helpers.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"getVendorDirectory",
"(",
")",
".",
"'/autoload.php'",
")",
")",
"{",
"include_once",
"$",
"this",
"->",
"getVendorDirectory",
"(",
")",
".",
"'/autoload.php'",
";",
"if",
"(",
"class_exists",
"(",
"'\\Dotenv\\Dotenv'",
")",
")",
"{",
"$",
"this",
"->",
"env",
"=",
"new",
"\\",
"Dotenv",
"\\",
"Dotenv",
"(",
"$",
"this",
"->",
"getRootDirectory",
"(",
")",
")",
";",
"$",
"this",
"->",
"env",
"->",
"overload",
"(",
")",
";",
"}",
"}",
"EventSubscriber",
"::",
"setPlugin",
"(",
"$",
"this",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Plugin.php#L75-L96 |
CupOfTea696/WordPress-Composer | src/Plugin.php | Plugin.getSubscribedEvents | public static function getSubscribedEvents()
{
$eventMap = [];
$events = EventSubscriber::getSubscribedEvents();
foreach ($events as $event => $params) {
if (is_string($params)) {
$eventMap[$event] = 'forwardEventTo' . ucfirst($params);
} elseif (is_array($params)) {
if (count($params) == 2 && is_int($params[1])) {
$eventMap[$event] = ['forwardEventTo' . ucfirst($params[0]), $params[1]];
} else {
foreach ($params as $listener) {
if (is_string($listener) || (is_array($listener) && count($listener) == 1)) {
$listener = is_array($listener) ? $listener[0] : $listener;
$eventMap[$event][] = ['forwardEventTo' . ucfirst($listener), 0];
} else {
$eventMap[$event][] = ['forwardEventTo' . ucfirst($listener[0]), $listener[1]];
}
}
}
}
}
return $eventMap;
} | php | public static function getSubscribedEvents()
{
$eventMap = [];
$events = EventSubscriber::getSubscribedEvents();
foreach ($events as $event => $params) {
if (is_string($params)) {
$eventMap[$event] = 'forwardEventTo' . ucfirst($params);
} elseif (is_array($params)) {
if (count($params) == 2 && is_int($params[1])) {
$eventMap[$event] = ['forwardEventTo' . ucfirst($params[0]), $params[1]];
} else {
foreach ($params as $listener) {
if (is_string($listener) || (is_array($listener) && count($listener) == 1)) {
$listener = is_array($listener) ? $listener[0] : $listener;
$eventMap[$event][] = ['forwardEventTo' . ucfirst($listener), 0];
} else {
$eventMap[$event][] = ['forwardEventTo' . ucfirst($listener[0]), $listener[1]];
}
}
}
}
}
return $eventMap;
} | [
"public",
"static",
"function",
"getSubscribedEvents",
"(",
")",
"{",
"$",
"eventMap",
"=",
"[",
"]",
";",
"$",
"events",
"=",
"EventSubscriber",
"::",
"getSubscribedEvents",
"(",
")",
";",
"foreach",
"(",
"$",
"events",
"as",
"$",
"event",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"params",
")",
")",
"{",
"$",
"eventMap",
"[",
"$",
"event",
"]",
"=",
"'forwardEventTo'",
".",
"ucfirst",
"(",
"$",
"params",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"==",
"2",
"&&",
"is_int",
"(",
"$",
"params",
"[",
"1",
"]",
")",
")",
"{",
"$",
"eventMap",
"[",
"$",
"event",
"]",
"=",
"[",
"'forwardEventTo'",
".",
"ucfirst",
"(",
"$",
"params",
"[",
"0",
"]",
")",
",",
"$",
"params",
"[",
"1",
"]",
"]",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"listener",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"listener",
")",
"||",
"(",
"is_array",
"(",
"$",
"listener",
")",
"&&",
"count",
"(",
"$",
"listener",
")",
"==",
"1",
")",
")",
"{",
"$",
"listener",
"=",
"is_array",
"(",
"$",
"listener",
")",
"?",
"$",
"listener",
"[",
"0",
"]",
":",
"$",
"listener",
";",
"$",
"eventMap",
"[",
"$",
"event",
"]",
"[",
"]",
"=",
"[",
"'forwardEventTo'",
".",
"ucfirst",
"(",
"$",
"listener",
")",
",",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"eventMap",
"[",
"$",
"event",
"]",
"[",
"]",
"=",
"[",
"'forwardEventTo'",
".",
"ucfirst",
"(",
"$",
"listener",
"[",
"0",
"]",
")",
",",
"$",
"listener",
"[",
"1",
"]",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"eventMap",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Plugin.php#L101-L127 |
CupOfTea696/WordPress-Composer | src/Plugin.php | Plugin.getRootDirectory | public function getRootDirectory()
{
$config = $this->composer->getConfig();
return str_replace($config->get('vendor-dir', Config::RELATIVE_PATHS), '', $config->get('vendor-dir'));
} | php | public function getRootDirectory()
{
$config = $this->composer->getConfig();
return str_replace($config->get('vendor-dir', Config::RELATIVE_PATHS), '', $config->get('vendor-dir'));
} | [
"public",
"function",
"getRootDirectory",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"composer",
"->",
"getConfig",
"(",
")",
";",
"return",
"str_replace",
"(",
"$",
"config",
"->",
"get",
"(",
"'vendor-dir'",
",",
"Config",
"::",
"RELATIVE_PATHS",
")",
",",
"''",
",",
"$",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
")",
";",
"}"
] | Get the root directory.
@return string | [
"Get",
"the",
"root",
"directory",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Plugin.php#L165-L170 |
CupOfTea696/WordPress-Composer | src/Plugin.php | Plugin.getPublicDirectory | public function getPublicDirectory()
{
if (isset($this->publicDirectory)) {
return $this->publicDirectory;
}
$rootPkg = $this->composer->getPackage();
if ($rootPkg) {
$extra = $rootPkg->getExtra();
if ($extra && ! empty($extra['public-dir'])) {
return $this->publicDirectory = $extra['public-dir'];
}
}
$common_public_dirs = [
'public',
'public_html',
'htdocs',
'httpdocs',
'html',
'web',
'www',
];
$public = null;
foreach ($common_public_dirs as $dir) {
if (file_exists($dir)) {
$public = $dir;
break;
}
}
$publicDirQuestion = 'What is the public directory (web root) for this project?';
if (! $public) {
if ($this->io->isInteractive()) {
return $this->publicDirectory = trim($this->ask($publicDirQuestion, $common_public_dirs[0]), '/');
}
return $this->publicDirectory = $common_public_dirs[0];
}
if ($this->io->isInteractive()) {
return $this->publicDirectory = trim($this->ask($publicDirQuestion, $public), '/');
}
return $this->publicDirectory = $public;
} | php | public function getPublicDirectory()
{
if (isset($this->publicDirectory)) {
return $this->publicDirectory;
}
$rootPkg = $this->composer->getPackage();
if ($rootPkg) {
$extra = $rootPkg->getExtra();
if ($extra && ! empty($extra['public-dir'])) {
return $this->publicDirectory = $extra['public-dir'];
}
}
$common_public_dirs = [
'public',
'public_html',
'htdocs',
'httpdocs',
'html',
'web',
'www',
];
$public = null;
foreach ($common_public_dirs as $dir) {
if (file_exists($dir)) {
$public = $dir;
break;
}
}
$publicDirQuestion = 'What is the public directory (web root) for this project?';
if (! $public) {
if ($this->io->isInteractive()) {
return $this->publicDirectory = trim($this->ask($publicDirQuestion, $common_public_dirs[0]), '/');
}
return $this->publicDirectory = $common_public_dirs[0];
}
if ($this->io->isInteractive()) {
return $this->publicDirectory = trim($this->ask($publicDirQuestion, $public), '/');
}
return $this->publicDirectory = $public;
} | [
"public",
"function",
"getPublicDirectory",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"publicDirectory",
")",
")",
"{",
"return",
"$",
"this",
"->",
"publicDirectory",
";",
"}",
"$",
"rootPkg",
"=",
"$",
"this",
"->",
"composer",
"->",
"getPackage",
"(",
")",
";",
"if",
"(",
"$",
"rootPkg",
")",
"{",
"$",
"extra",
"=",
"$",
"rootPkg",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"$",
"extra",
"&&",
"!",
"empty",
"(",
"$",
"extra",
"[",
"'public-dir'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"publicDirectory",
"=",
"$",
"extra",
"[",
"'public-dir'",
"]",
";",
"}",
"}",
"$",
"common_public_dirs",
"=",
"[",
"'public'",
",",
"'public_html'",
",",
"'htdocs'",
",",
"'httpdocs'",
",",
"'html'",
",",
"'web'",
",",
"'www'",
",",
"]",
";",
"$",
"public",
"=",
"null",
";",
"foreach",
"(",
"$",
"common_public_dirs",
"as",
"$",
"dir",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"public",
"=",
"$",
"dir",
";",
"break",
";",
"}",
"}",
"$",
"publicDirQuestion",
"=",
"'What is the public directory (web root) for this project?'",
";",
"if",
"(",
"!",
"$",
"public",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"io",
"->",
"isInteractive",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"publicDirectory",
"=",
"trim",
"(",
"$",
"this",
"->",
"ask",
"(",
"$",
"publicDirQuestion",
",",
"$",
"common_public_dirs",
"[",
"0",
"]",
")",
",",
"'/'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"publicDirectory",
"=",
"$",
"common_public_dirs",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"io",
"->",
"isInteractive",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"publicDirectory",
"=",
"trim",
"(",
"$",
"this",
"->",
"ask",
"(",
"$",
"publicDirQuestion",
",",
"$",
"public",
")",
",",
"'/'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"publicDirectory",
"=",
"$",
"public",
";",
"}"
] | Get the public directory.
@return string | [
"Get",
"the",
"public",
"directory",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Plugin.php#L187-L238 |
CupOfTea696/WordPress-Composer | src/Plugin.php | Plugin.ask | protected function ask($question, $default = null)
{
$defaultComment = '';
if ($default !== null) {
$defaultComment = ' [<comment>' . $default . '</comment>]';
}
$question = preg_replace('/(?:(\?)\s*$|(\?)?\s+$)|(?<!\s|\?)$/', $defaultComment . '$1 ', $question);
return $this->io->ask($question, $default);
} | php | protected function ask($question, $default = null)
{
$defaultComment = '';
if ($default !== null) {
$defaultComment = ' [<comment>' . $default . '</comment>]';
}
$question = preg_replace('/(?:(\?)\s*$|(\?)?\s+$)|(?<!\s|\?)$/', $defaultComment . '$1 ', $question);
return $this->io->ask($question, $default);
} | [
"protected",
"function",
"ask",
"(",
"$",
"question",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"defaultComment",
"=",
"''",
";",
"if",
"(",
"$",
"default",
"!==",
"null",
")",
"{",
"$",
"defaultComment",
"=",
"' [<comment>'",
".",
"$",
"default",
".",
"'</comment>]'",
";",
"}",
"$",
"question",
"=",
"preg_replace",
"(",
"'/(?:(\\?)\\s*$|(\\?)?\\s+$)|(?<!\\s|\\?)$/'",
",",
"$",
"defaultComment",
".",
"'$1 '",
",",
"$",
"question",
")",
";",
"return",
"$",
"this",
"->",
"io",
"->",
"ask",
"(",
"$",
"question",
",",
"$",
"default",
")",
";",
"}"
] | Add default value to IOInterface::ask question.
@param string $question
@param mixed $default = null
@return mixed | [
"Add",
"default",
"value",
"to",
"IOInterface",
"::",
"ask",
"question",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Plugin.php#L247-L258 |
dreamfactorysoftware/df-cache | src/Services/BaseService.php | BaseService.handleGET | protected function handleGET()
{
$key = str_replace('/', '.', $this->resourcePath);
if (empty($key)) {
throw new BadRequestException('No key/resource provide. Please provide a cache key to retrieve.');
}
$default = $this->request->getParameter('default');
if (false === $this->store->has($key) && empty($default)) {
throw new NotFoundException("No value found for key '$key'.");
}
$pull = $this->request->getParameterAsBool('clear', $this->request->getParameterAsBool('pull'));
if ($pull) {
$result = $this->store->pull($key, $default);
} else {
$result = $this->store->get($key, $default);
}
return $result;
} | php | protected function handleGET()
{
$key = str_replace('/', '.', $this->resourcePath);
if (empty($key)) {
throw new BadRequestException('No key/resource provide. Please provide a cache key to retrieve.');
}
$default = $this->request->getParameter('default');
if (false === $this->store->has($key) && empty($default)) {
throw new NotFoundException("No value found for key '$key'.");
}
$pull = $this->request->getParameterAsBool('clear', $this->request->getParameterAsBool('pull'));
if ($pull) {
$result = $this->store->pull($key, $default);
} else {
$result = $this->store->get($key, $default);
}
return $result;
} | [
"protected",
"function",
"handleGET",
"(",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'/'",
",",
"'.'",
",",
"$",
"this",
"->",
"resourcePath",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"'No key/resource provide. Please provide a cache key to retrieve.'",
")",
";",
"}",
"$",
"default",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameter",
"(",
"'default'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"store",
"->",
"has",
"(",
"$",
"key",
")",
"&&",
"empty",
"(",
"$",
"default",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"No value found for key '$key'.\"",
")",
";",
"}",
"$",
"pull",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'clear'",
",",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'pull'",
")",
")",
";",
"if",
"(",
"$",
"pull",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"store",
"->",
"pull",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"store",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dreamfactorysoftware/df-cache/blob/6a2aa5dc2fc7963ce89fd7e8f3d51483d2499451/src/Services/BaseService.php#L52-L72 |
dreamfactorysoftware/df-cache | src/Services/BaseService.php | BaseService.handlePUT | protected function handlePUT()
{
$key = str_replace('/', '.', $this->resourcePath);
$payload = $this->getPayloadData();
$this->ttl = $this->request->getParameter('ttl', $this->ttl);
$forever = $this->request->getParameterAsBool('forever');
if (empty($payload)) {
throw new BadRequestException('No value/payload provided to store in cache.');
}
if (!empty($key)) {
if ($forever) {
$this->store->forever($key, $payload);
} else {
$this->store->put($key, $payload, $this->ttl);
}
return [$key => $payload];
} else {
if (!is_array($payload)) {
throw new BadRequestException('Invalid payload provided. Please provide a key/value pair.');
}
foreach ($payload as $k => $v) {
if ($forever) {
$this->store->forever($k, $v);
} else {
$this->store->put($k, $v, $this->ttl);
}
}
return ['success' => true];
}
} | php | protected function handlePUT()
{
$key = str_replace('/', '.', $this->resourcePath);
$payload = $this->getPayloadData();
$this->ttl = $this->request->getParameter('ttl', $this->ttl);
$forever = $this->request->getParameterAsBool('forever');
if (empty($payload)) {
throw new BadRequestException('No value/payload provided to store in cache.');
}
if (!empty($key)) {
if ($forever) {
$this->store->forever($key, $payload);
} else {
$this->store->put($key, $payload, $this->ttl);
}
return [$key => $payload];
} else {
if (!is_array($payload)) {
throw new BadRequestException('Invalid payload provided. Please provide a key/value pair.');
}
foreach ($payload as $k => $v) {
if ($forever) {
$this->store->forever($k, $v);
} else {
$this->store->put($k, $v, $this->ttl);
}
}
return ['success' => true];
}
} | [
"protected",
"function",
"handlePUT",
"(",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'/'",
",",
"'.'",
",",
"$",
"this",
"->",
"resourcePath",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"getPayloadData",
"(",
")",
";",
"$",
"this",
"->",
"ttl",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameter",
"(",
"'ttl'",
",",
"$",
"this",
"->",
"ttl",
")",
";",
"$",
"forever",
"=",
"$",
"this",
"->",
"request",
"->",
"getParameterAsBool",
"(",
"'forever'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"payload",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"'No value/payload provided to store in cache.'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"$",
"forever",
")",
"{",
"$",
"this",
"->",
"store",
"->",
"forever",
"(",
"$",
"key",
",",
"$",
"payload",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"store",
"->",
"put",
"(",
"$",
"key",
",",
"$",
"payload",
",",
"$",
"this",
"->",
"ttl",
")",
";",
"}",
"return",
"[",
"$",
"key",
"=>",
"$",
"payload",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"payload",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"'Invalid payload provided. Please provide a key/value pair.'",
")",
";",
"}",
"foreach",
"(",
"$",
"payload",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"forever",
")",
"{",
"$",
"this",
"->",
"store",
"->",
"forever",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"store",
"->",
"put",
"(",
"$",
"k",
",",
"$",
"v",
",",
"$",
"this",
"->",
"ttl",
")",
";",
"}",
"}",
"return",
"[",
"'success'",
"=>",
"true",
"]",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dreamfactorysoftware/df-cache/blob/6a2aa5dc2fc7963ce89fd7e8f3d51483d2499451/src/Services/BaseService.php#L75-L109 |
dreamfactorysoftware/df-cache | src/Services/BaseService.php | BaseService.handlePOST | protected function handlePOST()
{
$key = str_replace('/', '.', $this->resourcePath);
$payload = $this->getPayloadData();
if (!empty($key) && true === $this->store->has($key)) {
throw new BadRequestException("Key '$key' already exists in cache. Use PUT to update existing key.");
}
if (is_array($payload) && empty($key)) {
$badKeys = [];
foreach ($payload as $k => $v) {
if (true === $this->store->has($k)) {
$badKeys[] = $k;
}
}
if (!empty($badKeys)) {
throw new BadRequestException(
'Nothing was stored in cache. ' .
'One or more key(s) already exists (' . implode(',', $badKeys) . ')'
);
}
}
$result = $this->handlePUT();
return ResponseFactory::create($result, null, ServiceResponseInterface::HTTP_CREATED);
} | php | protected function handlePOST()
{
$key = str_replace('/', '.', $this->resourcePath);
$payload = $this->getPayloadData();
if (!empty($key) && true === $this->store->has($key)) {
throw new BadRequestException("Key '$key' already exists in cache. Use PUT to update existing key.");
}
if (is_array($payload) && empty($key)) {
$badKeys = [];
foreach ($payload as $k => $v) {
if (true === $this->store->has($k)) {
$badKeys[] = $k;
}
}
if (!empty($badKeys)) {
throw new BadRequestException(
'Nothing was stored in cache. ' .
'One or more key(s) already exists (' . implode(',', $badKeys) . ')'
);
}
}
$result = $this->handlePUT();
return ResponseFactory::create($result, null, ServiceResponseInterface::HTTP_CREATED);
} | [
"protected",
"function",
"handlePOST",
"(",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'/'",
",",
"'.'",
",",
"$",
"this",
"->",
"resourcePath",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"getPayloadData",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"key",
")",
"&&",
"true",
"===",
"$",
"this",
"->",
"store",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Key '$key' already exists in cache. Use PUT to update existing key.\"",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"payload",
")",
"&&",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"badKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"payload",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"store",
"->",
"has",
"(",
"$",
"k",
")",
")",
"{",
"$",
"badKeys",
"[",
"]",
"=",
"$",
"k",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"badKeys",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"'Nothing was stored in cache. '",
".",
"'One or more key(s) already exists ('",
".",
"implode",
"(",
"','",
",",
"$",
"badKeys",
")",
".",
"')'",
")",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"handlePUT",
"(",
")",
";",
"return",
"ResponseFactory",
"::",
"create",
"(",
"$",
"result",
",",
"null",
",",
"ServiceResponseInterface",
"::",
"HTTP_CREATED",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dreamfactorysoftware/df-cache/blob/6a2aa5dc2fc7963ce89fd7e8f3d51483d2499451/src/Services/BaseService.php#L112-L140 |
dreamfactorysoftware/df-cache | src/Services/BaseService.php | BaseService.handleDELETE | protected function handleDELETE()
{
$key = str_replace('/', '.', $this->resourcePath);
if (empty($key)) {
throw new BadRequestException('No key/resource provide. Please provide a cache key to delete.');
}
$result = $this->store->forget($key);
return ['success' => $result];
} | php | protected function handleDELETE()
{
$key = str_replace('/', '.', $this->resourcePath);
if (empty($key)) {
throw new BadRequestException('No key/resource provide. Please provide a cache key to delete.');
}
$result = $this->store->forget($key);
return ['success' => $result];
} | [
"protected",
"function",
"handleDELETE",
"(",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'/'",
",",
"'.'",
",",
"$",
"this",
"->",
"resourcePath",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"'No key/resource provide. Please provide a cache key to delete.'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"store",
"->",
"forget",
"(",
"$",
"key",
")",
";",
"return",
"[",
"'success'",
"=>",
"$",
"result",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dreamfactorysoftware/df-cache/blob/6a2aa5dc2fc7963ce89fd7e8f3d51483d2499451/src/Services/BaseService.php#L143-L153 |
dreamfactorysoftware/df-cache | src/Services/BaseService.php | BaseService.getPayloadData | protected function getPayloadData($key = null, $default = null)
{
$content = $this->request->getContent();
$contentType = $this->request->getContentType();
switch ($contentType) {
case 'txt':
case 'text/plain':
return $content;
case 'json':
case 'application/json':
case 'application/x-json':
if (!in_array(substr($content, 0, 1), ['{', '[']) &&
!in_array(substr($content, strlen($content) - 1), ['}', ']'])
) {
return $content;
} else {
return $this->request->getPayloadData();
}
break;
default:
return $this->request->getPayloadData();
}
} | php | protected function getPayloadData($key = null, $default = null)
{
$content = $this->request->getContent();
$contentType = $this->request->getContentType();
switch ($contentType) {
case 'txt':
case 'text/plain':
return $content;
case 'json':
case 'application/json':
case 'application/x-json':
if (!in_array(substr($content, 0, 1), ['{', '[']) &&
!in_array(substr($content, strlen($content) - 1), ['}', ']'])
) {
return $content;
} else {
return $this->request->getPayloadData();
}
break;
default:
return $this->request->getPayloadData();
}
} | [
"protected",
"function",
"getPayloadData",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"request",
"->",
"getContent",
"(",
")",
";",
"$",
"contentType",
"=",
"$",
"this",
"->",
"request",
"->",
"getContentType",
"(",
")",
";",
"switch",
"(",
"$",
"contentType",
")",
"{",
"case",
"'txt'",
":",
"case",
"'text/plain'",
":",
"return",
"$",
"content",
";",
"case",
"'json'",
":",
"case",
"'application/json'",
":",
"case",
"'application/x-json'",
":",
"if",
"(",
"!",
"in_array",
"(",
"substr",
"(",
"$",
"content",
",",
"0",
",",
"1",
")",
",",
"[",
"'{'",
",",
"'['",
"]",
")",
"&&",
"!",
"in_array",
"(",
"substr",
"(",
"$",
"content",
",",
"strlen",
"(",
"$",
"content",
")",
"-",
"1",
")",
",",
"[",
"'}'",
",",
"']'",
"]",
")",
")",
"{",
"return",
"$",
"content",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"getPayloadData",
"(",
")",
";",
"}",
"break",
";",
"default",
":",
"return",
"$",
"this",
"->",
"request",
"->",
"getPayloadData",
"(",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dreamfactorysoftware/df-cache/blob/6a2aa5dc2fc7963ce89fd7e8f3d51483d2499451/src/Services/BaseService.php#L162-L185 |
dreamfactorysoftware/df-cache | src/Services/BaseService.php | BaseService.getApiDocPaths | protected function getApiDocPaths()
{
$capitalized = camelize($this->name);
$base = [
'/' => [
'post' => [
'summary' => 'Create one or more keys in cache storage',
'description' => 'No keys will be created if any of the supplied keys exist in cache. ' .
'Use PUT to replace an existing key(s). ' .
'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'create' . $capitalized . 'Keys',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' => 'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheRequest'
],
'responses' => [
'201' => ['$ref' => '#/components/responses/Success']
],
],
'put' => [
'summary' => 'Replace one or more keys in cache storage',
'description' => 'All existing keys will be replaced by supplied keys. ' .
'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'replace' . $capitalized . 'Keys',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' => 'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/Success']
],
]
],
'/{key_name}' => [
'parameters' => [
[
'name' => 'key_name',
'description' => 'The name of the key you want to retrieve from cache storage',
'schema' => ['type' => 'string'],
'in' => 'path',
'required' => true,
],
],
'get' => [
'summary' => 'Retrieve one key from cache.',
'description' => 'Use the \'clear\' parameter to retrieve and forget a key from cache. ' .
'Use the \'default\' parameter to return a default value if key is not found.',
'operationId' => 'get' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'default',
'schema' => ['type' => 'string'],
'in' => 'query',
'description' => 'A default value to return if key is not found in cache storage.',
],
[
'name' => 'clear',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' =>
'Setting this to true will delete the key/value pair from cache storage upon reading it.',
]
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'post' => [
'summary' => 'Create one key in cache.',
'description' => 'You can only create a key if the key does not exist in cache. ' .
'Use PUT to replace an existing key. ' .
'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'create' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' =>
'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheKeyRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'put' => [
'summary' => 'Replace one key from cache.',
'description' => 'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'replace' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' =>
'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheKeyRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'patch' => [
'summary' => 'Update one key in cache.',
'description' => 'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'update' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' => 'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheKeyRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'delete' => [
'summary' => 'Delete one key from cache.',
'description' => 'You can only delete one key at a time.',
'operationId' => 'delete' . $capitalized . 'Key',
'responses' => [
'200' => ['$ref' => '#/components/responses/Success']
],
],
],
];
return $base;
} | php | protected function getApiDocPaths()
{
$capitalized = camelize($this->name);
$base = [
'/' => [
'post' => [
'summary' => 'Create one or more keys in cache storage',
'description' => 'No keys will be created if any of the supplied keys exist in cache. ' .
'Use PUT to replace an existing key(s). ' .
'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'create' . $capitalized . 'Keys',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' => 'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheRequest'
],
'responses' => [
'201' => ['$ref' => '#/components/responses/Success']
],
],
'put' => [
'summary' => 'Replace one or more keys in cache storage',
'description' => 'All existing keys will be replaced by supplied keys. ' .
'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'replace' . $capitalized . 'Keys',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' => 'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/Success']
],
]
],
'/{key_name}' => [
'parameters' => [
[
'name' => 'key_name',
'description' => 'The name of the key you want to retrieve from cache storage',
'schema' => ['type' => 'string'],
'in' => 'path',
'required' => true,
],
],
'get' => [
'summary' => 'Retrieve one key from cache.',
'description' => 'Use the \'clear\' parameter to retrieve and forget a key from cache. ' .
'Use the \'default\' parameter to return a default value if key is not found.',
'operationId' => 'get' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'default',
'schema' => ['type' => 'string'],
'in' => 'query',
'description' => 'A default value to return if key is not found in cache storage.',
],
[
'name' => 'clear',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' =>
'Setting this to true will delete the key/value pair from cache storage upon reading it.',
]
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'post' => [
'summary' => 'Create one key in cache.',
'description' => 'You can only create a key if the key does not exist in cache. ' .
'Use PUT to replace an existing key. ' .
'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'create' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' =>
'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheKeyRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'put' => [
'summary' => 'Replace one key from cache.',
'description' => 'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'replace' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' =>
'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheKeyRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'patch' => [
'summary' => 'Update one key in cache.',
'description' => 'Use the \'ttl\' parameter to set a Time to Live value in minutes. ' .
'Use the \'forever\' parameter to store a key/value pair for indefinite time.',
'operationId' => 'update' . $capitalized . 'Key',
'parameters' => [
[
'name' => 'ttl',
'schema' => ['type' => 'integer'],
'in' => 'query',
'description' => 'A TTL (Time To Live) value in minutes for your cache.',
],
[
'name' => 'forever',
'schema' => ['type' => 'boolean'],
'in' => 'query',
'description' => 'Setting this to true will never expire your key/value pair from cache storage.',
],
],
'requestBody' => [
'$ref' => '#/components/requestBodies/CacheKeyRequest'
],
'responses' => [
'200' => ['$ref' => '#/components/responses/CacheKeyResponse'],
],
],
'delete' => [
'summary' => 'Delete one key from cache.',
'description' => 'You can only delete one key at a time.',
'operationId' => 'delete' . $capitalized . 'Key',
'responses' => [
'200' => ['$ref' => '#/components/responses/Success']
],
],
],
];
return $base;
} | [
"protected",
"function",
"getApiDocPaths",
"(",
")",
"{",
"$",
"capitalized",
"=",
"camelize",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"base",
"=",
"[",
"'/'",
"=>",
"[",
"'post'",
"=>",
"[",
"'summary'",
"=>",
"'Create one or more keys in cache storage'",
",",
"'description'",
"=>",
"'No keys will be created if any of the supplied keys exist in cache. '",
".",
"'Use PUT to replace an existing key(s). '",
".",
"'Use the \\'ttl\\' parameter to set a Time to Live value in minutes. '",
".",
"'Use the \\'forever\\' parameter to store a key/value pair for indefinite time.'",
",",
"'operationId'",
"=>",
"'create'",
".",
"$",
"capitalized",
".",
"'Keys'",
",",
"'parameters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'ttl'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'integer'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'A TTL (Time To Live) value in minutes for your cache.'",
",",
"]",
",",
"[",
"'name'",
"=>",
"'forever'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'boolean'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'Setting this to true will never expire your key/value pair from cache storage.'",
",",
"]",
",",
"]",
",",
"'requestBody'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/requestBodies/CacheRequest'",
"]",
",",
"'responses'",
"=>",
"[",
"'201'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/responses/Success'",
"]",
"]",
",",
"]",
",",
"'put'",
"=>",
"[",
"'summary'",
"=>",
"'Replace one or more keys in cache storage'",
",",
"'description'",
"=>",
"'All existing keys will be replaced by supplied keys. '",
".",
"'Use the \\'ttl\\' parameter to set a Time to Live value in minutes. '",
".",
"'Use the \\'forever\\' parameter to store a key/value pair for indefinite time.'",
",",
"'operationId'",
"=>",
"'replace'",
".",
"$",
"capitalized",
".",
"'Keys'",
",",
"'parameters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'ttl'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'integer'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'A TTL (Time To Live) value in minutes for your cache.'",
",",
"]",
",",
"[",
"'name'",
"=>",
"'forever'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'boolean'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'Setting this to true will never expire your key/value pair from cache storage.'",
",",
"]",
",",
"]",
",",
"'requestBody'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/requestBodies/CacheRequest'",
"]",
",",
"'responses'",
"=>",
"[",
"'200'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/responses/Success'",
"]",
"]",
",",
"]",
"]",
",",
"'/{key_name}'",
"=>",
"[",
"'parameters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'key_name'",
",",
"'description'",
"=>",
"'The name of the key you want to retrieve from cache storage'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'string'",
"]",
",",
"'in'",
"=>",
"'path'",
",",
"'required'",
"=>",
"true",
",",
"]",
",",
"]",
",",
"'get'",
"=>",
"[",
"'summary'",
"=>",
"'Retrieve one key from cache.'",
",",
"'description'",
"=>",
"'Use the \\'clear\\' parameter to retrieve and forget a key from cache. '",
".",
"'Use the \\'default\\' parameter to return a default value if key is not found.'",
",",
"'operationId'",
"=>",
"'get'",
".",
"$",
"capitalized",
".",
"'Key'",
",",
"'parameters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'default'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'string'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'A default value to return if key is not found in cache storage.'",
",",
"]",
",",
"[",
"'name'",
"=>",
"'clear'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'boolean'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'Setting this to true will delete the key/value pair from cache storage upon reading it.'",
",",
"]",
"]",
",",
"'responses'",
"=>",
"[",
"'200'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/responses/CacheKeyResponse'",
"]",
",",
"]",
",",
"]",
",",
"'post'",
"=>",
"[",
"'summary'",
"=>",
"'Create one key in cache.'",
",",
"'description'",
"=>",
"'You can only create a key if the key does not exist in cache. '",
".",
"'Use PUT to replace an existing key. '",
".",
"'Use the \\'ttl\\' parameter to set a Time to Live value in minutes. '",
".",
"'Use the \\'forever\\' parameter to store a key/value pair for indefinite time.'",
",",
"'operationId'",
"=>",
"'create'",
".",
"$",
"capitalized",
".",
"'Key'",
",",
"'parameters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'ttl'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'integer'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'A TTL (Time To Live) value in minutes for your cache.'",
",",
"]",
",",
"[",
"'name'",
"=>",
"'forever'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'boolean'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'Setting this to true will never expire your key/value pair from cache storage.'",
",",
"]",
",",
"]",
",",
"'requestBody'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/requestBodies/CacheKeyRequest'",
"]",
",",
"'responses'",
"=>",
"[",
"'200'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/responses/CacheKeyResponse'",
"]",
",",
"]",
",",
"]",
",",
"'put'",
"=>",
"[",
"'summary'",
"=>",
"'Replace one key from cache.'",
",",
"'description'",
"=>",
"'Use the \\'ttl\\' parameter to set a Time to Live value in minutes. '",
".",
"'Use the \\'forever\\' parameter to store a key/value pair for indefinite time.'",
",",
"'operationId'",
"=>",
"'replace'",
".",
"$",
"capitalized",
".",
"'Key'",
",",
"'parameters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'ttl'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'integer'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'A TTL (Time To Live) value in minutes for your cache.'",
",",
"]",
",",
"[",
"'name'",
"=>",
"'forever'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'boolean'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'Setting this to true will never expire your key/value pair from cache storage.'",
",",
"]",
",",
"]",
",",
"'requestBody'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/requestBodies/CacheKeyRequest'",
"]",
",",
"'responses'",
"=>",
"[",
"'200'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/responses/CacheKeyResponse'",
"]",
",",
"]",
",",
"]",
",",
"'patch'",
"=>",
"[",
"'summary'",
"=>",
"'Update one key in cache.'",
",",
"'description'",
"=>",
"'Use the \\'ttl\\' parameter to set a Time to Live value in minutes. '",
".",
"'Use the \\'forever\\' parameter to store a key/value pair for indefinite time.'",
",",
"'operationId'",
"=>",
"'update'",
".",
"$",
"capitalized",
".",
"'Key'",
",",
"'parameters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'ttl'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'integer'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'A TTL (Time To Live) value in minutes for your cache.'",
",",
"]",
",",
"[",
"'name'",
"=>",
"'forever'",
",",
"'schema'",
"=>",
"[",
"'type'",
"=>",
"'boolean'",
"]",
",",
"'in'",
"=>",
"'query'",
",",
"'description'",
"=>",
"'Setting this to true will never expire your key/value pair from cache storage.'",
",",
"]",
",",
"]",
",",
"'requestBody'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/requestBodies/CacheKeyRequest'",
"]",
",",
"'responses'",
"=>",
"[",
"'200'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/responses/CacheKeyResponse'",
"]",
",",
"]",
",",
"]",
",",
"'delete'",
"=>",
"[",
"'summary'",
"=>",
"'Delete one key from cache.'",
",",
"'description'",
"=>",
"'You can only delete one key at a time.'",
",",
"'operationId'",
"=>",
"'delete'",
".",
"$",
"capitalized",
".",
"'Key'",
",",
"'responses'",
"=>",
"[",
"'200'",
"=>",
"[",
"'$ref'",
"=>",
"'#/components/responses/Success'",
"]",
"]",
",",
"]",
",",
"]",
",",
"]",
";",
"return",
"$",
"base",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dreamfactorysoftware/df-cache/blob/6a2aa5dc2fc7963ce89fd7e8f3d51483d2499451/src/Services/BaseService.php#L188-L378 |
mothership-ec/composer | src/Composer/Util/Filesystem.php | Filesystem.removeDirectoryPhp | public function removeDirectoryPhp($directory)
{
$it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ri as $file) {
if ($file->isDir()) {
$this->rmdir($file->getPathname());
} else {
$this->unlink($file->getPathname());
}
}
return $this->rmdir($directory);
} | php | public function removeDirectoryPhp($directory)
{
$it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ri as $file) {
if ($file->isDir()) {
$this->rmdir($file->getPathname());
} else {
$this->unlink($file->getPathname());
}
}
return $this->rmdir($directory);
} | [
"public",
"function",
"removeDirectoryPhp",
"(",
"$",
"directory",
")",
"{",
"$",
"it",
"=",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"directory",
",",
"RecursiveDirectoryIterator",
"::",
"SKIP_DOTS",
")",
";",
"$",
"ri",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"$",
"it",
",",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"foreach",
"(",
"$",
"ri",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"this",
"->",
"rmdir",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"unlink",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"rmdir",
"(",
"$",
"directory",
")",
";",
"}"
] | Recursively delete directory using PHP iterators.
Uses a CHILD_FIRST RecursiveIteratorIterator to sort files
before directories, creating a single non-recursive loop
to delete files/directories in the correct order.
@param string $directory
@return bool | [
"Recursively",
"delete",
"directory",
"using",
"PHP",
"iterators",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Util/Filesystem.php#L142-L156 |
php-lug/lug | src/Bundle/GridBundle/Form/Type/Batch/GridBatchTypeType.php | GridBatchTypeType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'choices' => function (Options $options) {
return array_combine(
array_map(function (BatchInterface $batch) {
return $batch->getLabel();
}, $batches = $options['grid']->getDefinition()->getBatches()),
array_map(function (BatchInterface $batch) {
return $batch->getName();
}, $batches)
);
},
'constraints' => new NotBlank(['message' => 'lug.batch.type.empty']),
'choices_as_values' => true,
'label' => false,
])
->setRequired('grid')
->setAllowedTypes('grid', GridViewInterface::class);
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'choices' => function (Options $options) {
return array_combine(
array_map(function (BatchInterface $batch) {
return $batch->getLabel();
}, $batches = $options['grid']->getDefinition()->getBatches()),
array_map(function (BatchInterface $batch) {
return $batch->getName();
}, $batches)
);
},
'constraints' => new NotBlank(['message' => 'lug.batch.type.empty']),
'choices_as_values' => true,
'label' => false,
])
->setRequired('grid')
->setAllowedTypes('grid', GridViewInterface::class);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'choices'",
"=>",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"array_combine",
"(",
"array_map",
"(",
"function",
"(",
"BatchInterface",
"$",
"batch",
")",
"{",
"return",
"$",
"batch",
"->",
"getLabel",
"(",
")",
";",
"}",
",",
"$",
"batches",
"=",
"$",
"options",
"[",
"'grid'",
"]",
"->",
"getDefinition",
"(",
")",
"->",
"getBatches",
"(",
")",
")",
",",
"array_map",
"(",
"function",
"(",
"BatchInterface",
"$",
"batch",
")",
"{",
"return",
"$",
"batch",
"->",
"getName",
"(",
")",
";",
"}",
",",
"$",
"batches",
")",
")",
";",
"}",
",",
"'constraints'",
"=>",
"new",
"NotBlank",
"(",
"[",
"'message'",
"=>",
"'lug.batch.type.empty'",
"]",
")",
",",
"'choices_as_values'",
"=>",
"true",
",",
"'label'",
"=>",
"false",
",",
"]",
")",
"->",
"setRequired",
"(",
"'grid'",
")",
"->",
"setAllowedTypes",
"(",
"'grid'",
",",
"GridViewInterface",
"::",
"class",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Form/Type/Batch/GridBatchTypeType.php#L30-L50 |
tttptd/laravel-responder | src/Traits/HandlesApiErrors.php | HandlesApiErrors.transformException | protected function transformException(Exception $exception)
{
if (Request::capture()->wantsJson()) {
$this->transformAuthException($exception);
$this->transformEloquentException($exception);
$this->transformValidationException($exception);
}
} | php | protected function transformException(Exception $exception)
{
if (Request::capture()->wantsJson()) {
$this->transformAuthException($exception);
$this->transformEloquentException($exception);
$this->transformValidationException($exception);
}
} | [
"protected",
"function",
"transformException",
"(",
"Exception",
"$",
"exception",
")",
"{",
"if",
"(",
"Request",
"::",
"capture",
"(",
")",
"->",
"wantsJson",
"(",
")",
")",
"{",
"$",
"this",
"->",
"transformAuthException",
"(",
"$",
"exception",
")",
";",
"$",
"this",
"->",
"transformEloquentException",
"(",
"$",
"exception",
")",
";",
"$",
"this",
"->",
"transformValidationException",
"(",
"$",
"exception",
")",
";",
"}",
"}"
] | Transform a Laravel exception into an API exception.
@param Exception $exception
@return void | [
"Transform",
"a",
"Laravel",
"exception",
"into",
"an",
"API",
"exception",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Traits/HandlesApiErrors.php#L36-L43 |
tttptd/laravel-responder | src/Traits/HandlesApiErrors.php | HandlesApiErrors.renderApiError | protected function renderApiError(ApiException $exception):JsonResponse
{
return app('responder.error')
->setError($exception->getErrorCode(), $exception->getMessage())
->addData($exception->getData() ?: [])
->respond($exception->getStatusCode());
} | php | protected function renderApiError(ApiException $exception):JsonResponse
{
return app('responder.error')
->setError($exception->getErrorCode(), $exception->getMessage())
->addData($exception->getData() ?: [])
->respond($exception->getStatusCode());
} | [
"protected",
"function",
"renderApiError",
"(",
"ApiException",
"$",
"exception",
")",
":",
"JsonResponse",
"{",
"return",
"app",
"(",
"'responder.error'",
")",
"->",
"setError",
"(",
"$",
"exception",
"->",
"getErrorCode",
"(",
")",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
"->",
"addData",
"(",
"$",
"exception",
"->",
"getData",
"(",
")",
"?",
":",
"[",
"]",
")",
"->",
"respond",
"(",
"$",
"exception",
"->",
"getStatusCode",
"(",
")",
")",
";",
"}"
] | Renders any API exception into a JSON error response.
@param ApiException $exception
@return JsonResponse | [
"Renders",
"any",
"API",
"exception",
"into",
"a",
"JSON",
"error",
"response",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Traits/HandlesApiErrors.php#L103-L109 |
thecodingmachine/mvc.splash-common | src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php | ExceptionUtils.getHTMLBackTrace | private static function getHTMLBackTrace($backtrace)
{
$str = '';
foreach ($backtrace as $step) {
if ($step['function'] != 'getHTMLBackTrace' && $step['function'] != 'handle_error') {
$str .= '<tr><td style="border-bottom: 1px solid #EEEEEE">';
$str .= ((isset($step['class'])) ? htmlspecialchars($step['class'], ENT_NOQUOTES, 'UTF-8') : '').
((isset($step['type'])) ? htmlspecialchars($step['type'], ENT_NOQUOTES, 'UTF-8') : '').htmlspecialchars($step['function'], ENT_NOQUOTES, 'UTF-8').'(';
if (is_array($step['args'])) {
$drawn = false;
$params = '';
foreach ($step['args'] as $param) {
$params .= self::getPhpVariableAsText($param);
//$params .= var_export($param, true);
$params .= ', ';
$drawn = true;
}
$str .= htmlspecialchars($params, ENT_NOQUOTES, 'UTF-8');
if ($drawn == true) {
$str = substr($str, 0, strlen($str) - 2);
}
}
$str .= ')';
$str .= '</td><td style="border-bottom: 1px solid #EEEEEE">';
$str .= ((isset($step['file'])) ? htmlspecialchars(self::displayFile($step['file']), ENT_NOQUOTES, 'UTF-8') : '');
$str .= '</td><td style="border-bottom: 1px solid #EEEEEE">';
$str .= ((isset($step['line'])) ? $step['line'] : '');
$str .= '</td></tr>';
}
}
return $str;
} | php | private static function getHTMLBackTrace($backtrace)
{
$str = '';
foreach ($backtrace as $step) {
if ($step['function'] != 'getHTMLBackTrace' && $step['function'] != 'handle_error') {
$str .= '<tr><td style="border-bottom: 1px solid #EEEEEE">';
$str .= ((isset($step['class'])) ? htmlspecialchars($step['class'], ENT_NOQUOTES, 'UTF-8') : '').
((isset($step['type'])) ? htmlspecialchars($step['type'], ENT_NOQUOTES, 'UTF-8') : '').htmlspecialchars($step['function'], ENT_NOQUOTES, 'UTF-8').'(';
if (is_array($step['args'])) {
$drawn = false;
$params = '';
foreach ($step['args'] as $param) {
$params .= self::getPhpVariableAsText($param);
//$params .= var_export($param, true);
$params .= ', ';
$drawn = true;
}
$str .= htmlspecialchars($params, ENT_NOQUOTES, 'UTF-8');
if ($drawn == true) {
$str = substr($str, 0, strlen($str) - 2);
}
}
$str .= ')';
$str .= '</td><td style="border-bottom: 1px solid #EEEEEE">';
$str .= ((isset($step['file'])) ? htmlspecialchars(self::displayFile($step['file']), ENT_NOQUOTES, 'UTF-8') : '');
$str .= '</td><td style="border-bottom: 1px solid #EEEEEE">';
$str .= ((isset($step['line'])) ? $step['line'] : '');
$str .= '</td></tr>';
}
}
return $str;
} | [
"private",
"static",
"function",
"getHTMLBackTrace",
"(",
"$",
"backtrace",
")",
"{",
"$",
"str",
"=",
"''",
";",
"foreach",
"(",
"$",
"backtrace",
"as",
"$",
"step",
")",
"{",
"if",
"(",
"$",
"step",
"[",
"'function'",
"]",
"!=",
"'getHTMLBackTrace'",
"&&",
"$",
"step",
"[",
"'function'",
"]",
"!=",
"'handle_error'",
")",
"{",
"$",
"str",
".=",
"'<tr><td style=\"border-bottom: 1px solid #EEEEEE\">'",
";",
"$",
"str",
".=",
"(",
"(",
"isset",
"(",
"$",
"step",
"[",
"'class'",
"]",
")",
")",
"?",
"htmlspecialchars",
"(",
"$",
"step",
"[",
"'class'",
"]",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
":",
"''",
")",
".",
"(",
"(",
"isset",
"(",
"$",
"step",
"[",
"'type'",
"]",
")",
")",
"?",
"htmlspecialchars",
"(",
"$",
"step",
"[",
"'type'",
"]",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
":",
"''",
")",
".",
"htmlspecialchars",
"(",
"$",
"step",
"[",
"'function'",
"]",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
".",
"'('",
";",
"if",
"(",
"is_array",
"(",
"$",
"step",
"[",
"'args'",
"]",
")",
")",
"{",
"$",
"drawn",
"=",
"false",
";",
"$",
"params",
"=",
"''",
";",
"foreach",
"(",
"$",
"step",
"[",
"'args'",
"]",
"as",
"$",
"param",
")",
"{",
"$",
"params",
".=",
"self",
"::",
"getPhpVariableAsText",
"(",
"$",
"param",
")",
";",
"//$params .= var_export($param, true);",
"$",
"params",
".=",
"', '",
";",
"$",
"drawn",
"=",
"true",
";",
"}",
"$",
"str",
".=",
"htmlspecialchars",
"(",
"$",
"params",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
";",
"if",
"(",
"$",
"drawn",
"==",
"true",
")",
"{",
"$",
"str",
"=",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"strlen",
"(",
"$",
"str",
")",
"-",
"2",
")",
";",
"}",
"}",
"$",
"str",
".=",
"')'",
";",
"$",
"str",
".=",
"'</td><td style=\"border-bottom: 1px solid #EEEEEE\">'",
";",
"$",
"str",
".=",
"(",
"(",
"isset",
"(",
"$",
"step",
"[",
"'file'",
"]",
")",
")",
"?",
"htmlspecialchars",
"(",
"self",
"::",
"displayFile",
"(",
"$",
"step",
"[",
"'file'",
"]",
")",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
":",
"''",
")",
";",
"$",
"str",
".=",
"'</td><td style=\"border-bottom: 1px solid #EEEEEE\">'",
";",
"$",
"str",
".=",
"(",
"(",
"isset",
"(",
"$",
"step",
"[",
"'line'",
"]",
")",
")",
"?",
"$",
"step",
"[",
"'line'",
"]",
":",
"''",
")",
";",
"$",
"str",
".=",
"'</td></tr>'",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] | Returns the Exception Backtrace as a nice HTML view.
@param array $backtrace
@return string | [
"Returns",
"the",
"Exception",
"Backtrace",
"as",
"a",
"nice",
"HTML",
"view",
"."
] | train | https://github.com/thecodingmachine/mvc.splash-common/blob/eed0269ceda4d7d090a330a220490906a7aa60bd/src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php#L14-L48 |
thecodingmachine/mvc.splash-common | src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php | ExceptionUtils.getHtmlForException | public static function getHtmlForException(\Throwable $exception)
{
//global $sys_error_reporting_mail;
//global $sys_error_messages;
$msg = '';
$msg = '<table>';
$display_errors = ini_get('display_errors');
$color = '#FF0000';
$type = 'Uncaught '.get_class($exception);
if ($exception->getCode() != null) {
$type .= ' with error code '.$exception->getCode();
}
$msg .= "<tr><td colspan='3' style='background-color:$color; color:white; text-align:center'><b>$type</b></td></tr>";
$msg .= "<tr><td style='background-color:#AAAAAA; color:white; text-align:center'>Context/Message</td>";
$msg .= "<td style='background-color:#AAAAAA; color:white; text-align:center'>File</td>";
$msg .= "<td style='background-color:#AAAAAA; color:white; text-align:center'>Line</td></tr>";
$msg .= "<tr><td style='background-color:#EEEEEE; color:black'><b>".nl2br($exception->getMessage()).'</b></td>';
$msg .= "<td style='background-color:#EEEEEE; color:black'>".self::displayFile($exception->getFile()).'</td>';
$msg .= "<td style='background-color:#EEEEEE; color:black'>".$exception->getLine().'</td></tr>';
$msg .= self::getHTMLBackTrace($exception->getTrace());
$msg .= '</table>';
return $msg;
} | php | public static function getHtmlForException(\Throwable $exception)
{
//global $sys_error_reporting_mail;
//global $sys_error_messages;
$msg = '';
$msg = '<table>';
$display_errors = ini_get('display_errors');
$color = '#FF0000';
$type = 'Uncaught '.get_class($exception);
if ($exception->getCode() != null) {
$type .= ' with error code '.$exception->getCode();
}
$msg .= "<tr><td colspan='3' style='background-color:$color; color:white; text-align:center'><b>$type</b></td></tr>";
$msg .= "<tr><td style='background-color:#AAAAAA; color:white; text-align:center'>Context/Message</td>";
$msg .= "<td style='background-color:#AAAAAA; color:white; text-align:center'>File</td>";
$msg .= "<td style='background-color:#AAAAAA; color:white; text-align:center'>Line</td></tr>";
$msg .= "<tr><td style='background-color:#EEEEEE; color:black'><b>".nl2br($exception->getMessage()).'</b></td>';
$msg .= "<td style='background-color:#EEEEEE; color:black'>".self::displayFile($exception->getFile()).'</td>';
$msg .= "<td style='background-color:#EEEEEE; color:black'>".$exception->getLine().'</td></tr>';
$msg .= self::getHTMLBackTrace($exception->getTrace());
$msg .= '</table>';
return $msg;
} | [
"public",
"static",
"function",
"getHtmlForException",
"(",
"\\",
"Throwable",
"$",
"exception",
")",
"{",
"//global $sys_error_reporting_mail;",
"//global $sys_error_messages;",
"$",
"msg",
"=",
"''",
";",
"$",
"msg",
"=",
"'<table>'",
";",
"$",
"display_errors",
"=",
"ini_get",
"(",
"'display_errors'",
")",
";",
"$",
"color",
"=",
"'#FF0000'",
";",
"$",
"type",
"=",
"'Uncaught '",
".",
"get_class",
"(",
"$",
"exception",
")",
";",
"if",
"(",
"$",
"exception",
"->",
"getCode",
"(",
")",
"!=",
"null",
")",
"{",
"$",
"type",
".=",
"' with error code '",
".",
"$",
"exception",
"->",
"getCode",
"(",
")",
";",
"}",
"$",
"msg",
".=",
"\"<tr><td colspan='3' style='background-color:$color; color:white; text-align:center'><b>$type</b></td></tr>\"",
";",
"$",
"msg",
".=",
"\"<tr><td style='background-color:#AAAAAA; color:white; text-align:center'>Context/Message</td>\"",
";",
"$",
"msg",
".=",
"\"<td style='background-color:#AAAAAA; color:white; text-align:center'>File</td>\"",
";",
"$",
"msg",
".=",
"\"<td style='background-color:#AAAAAA; color:white; text-align:center'>Line</td></tr>\"",
";",
"$",
"msg",
".=",
"\"<tr><td style='background-color:#EEEEEE; color:black'><b>\"",
".",
"nl2br",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
".",
"'</b></td>'",
";",
"$",
"msg",
".=",
"\"<td style='background-color:#EEEEEE; color:black'>\"",
".",
"self",
"::",
"displayFile",
"(",
"$",
"exception",
"->",
"getFile",
"(",
")",
")",
".",
"'</td>'",
";",
"$",
"msg",
".=",
"\"<td style='background-color:#EEEEEE; color:black'>\"",
".",
"$",
"exception",
"->",
"getLine",
"(",
")",
".",
"'</td></tr>'",
";",
"$",
"msg",
".=",
"self",
"::",
"getHTMLBackTrace",
"(",
"$",
"exception",
"->",
"getTrace",
"(",
")",
")",
";",
"$",
"msg",
".=",
"'</table>'",
";",
"return",
"$",
"msg",
";",
"}"
] | Function called to display an exception if it occurs.
It will make sure to purge anything in the buffer before calling the exception displayer.
@param \Throwable $exception | [
"Function",
"called",
"to",
"display",
"an",
"exception",
"if",
"it",
"occurs",
".",
"It",
"will",
"make",
"sure",
"to",
"purge",
"anything",
"in",
"the",
"buffer",
"before",
"calling",
"the",
"exception",
"displayer",
"."
] | train | https://github.com/thecodingmachine/mvc.splash-common/blob/eed0269ceda4d7d090a330a220490906a7aa60bd/src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php#L56-L84 |
thecodingmachine/mvc.splash-common | src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php | ExceptionUtils.getPhpVariableAsText | private static function getPhpVariableAsText($var)
{
if (is_string($var)) {
return('"'.str_replace(array("\x00", "\x0a", "\x0d", "\x1a", "\x09"), array('\0', '\n', '\r', '\Z', '\t'), $var).'"');
} elseif (is_int($var) || is_float($var)) {
return($var);
} elseif (is_bool($var)) {
if ($var) {
return('true');
} else {
return('false');
}
} elseif (is_array($var)) {
$result = 'array( ';
$comma = '';
foreach ($var as $key => $val) {
$result .= $comma.self::getPhpVariableAsText($key).' => '.self::getPhpVariableAsText($val);
$comma = ', ';
}
$result .= ' )';
return($result);
} elseif (is_object($var)) {
return 'Object '.get_class($var);
} elseif (is_resource($var)) {
return 'Resource '.get_resource_type($var);
}
return 'Unknown type variable';
} | php | private static function getPhpVariableAsText($var)
{
if (is_string($var)) {
return('"'.str_replace(array("\x00", "\x0a", "\x0d", "\x1a", "\x09"), array('\0', '\n', '\r', '\Z', '\t'), $var).'"');
} elseif (is_int($var) || is_float($var)) {
return($var);
} elseif (is_bool($var)) {
if ($var) {
return('true');
} else {
return('false');
}
} elseif (is_array($var)) {
$result = 'array( ';
$comma = '';
foreach ($var as $key => $val) {
$result .= $comma.self::getPhpVariableAsText($key).' => '.self::getPhpVariableAsText($val);
$comma = ', ';
}
$result .= ' )';
return($result);
} elseif (is_object($var)) {
return 'Object '.get_class($var);
} elseif (is_resource($var)) {
return 'Resource '.get_resource_type($var);
}
return 'Unknown type variable';
} | [
"private",
"static",
"function",
"getPhpVariableAsText",
"(",
"$",
"var",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"var",
")",
")",
"{",
"return",
"(",
"'\"'",
".",
"str_replace",
"(",
"array",
"(",
"\"\\x00\"",
",",
"\"\\x0a\"",
",",
"\"\\x0d\"",
",",
"\"\\x1a\"",
",",
"\"\\x09\"",
")",
",",
"array",
"(",
"'\\0'",
",",
"'\\n'",
",",
"'\\r'",
",",
"'\\Z'",
",",
"'\\t'",
")",
",",
"$",
"var",
")",
".",
"'\"'",
")",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"var",
")",
"||",
"is_float",
"(",
"$",
"var",
")",
")",
"{",
"return",
"(",
"$",
"var",
")",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"var",
")",
")",
"{",
"if",
"(",
"$",
"var",
")",
"{",
"return",
"(",
"'true'",
")",
";",
"}",
"else",
"{",
"return",
"(",
"'false'",
")",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"var",
")",
")",
"{",
"$",
"result",
"=",
"'array( '",
";",
"$",
"comma",
"=",
"''",
";",
"foreach",
"(",
"$",
"var",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"result",
".=",
"$",
"comma",
".",
"self",
"::",
"getPhpVariableAsText",
"(",
"$",
"key",
")",
".",
"' => '",
".",
"self",
"::",
"getPhpVariableAsText",
"(",
"$",
"val",
")",
";",
"$",
"comma",
"=",
"', '",
";",
"}",
"$",
"result",
".=",
"' )'",
";",
"return",
"(",
"$",
"result",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'Object '",
".",
"get_class",
"(",
"$",
"var",
")",
";",
"}",
"elseif",
"(",
"is_resource",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'Resource '",
".",
"get_resource_type",
"(",
"$",
"var",
")",
";",
"}",
"return",
"'Unknown type variable'",
";",
"}"
] | Used by the debug function to display a nice view of the parameters.
@param mixed $var
@return string | [
"Used",
"by",
"the",
"debug",
"function",
"to",
"display",
"a",
"nice",
"view",
"of",
"the",
"parameters",
"."
] | train | https://github.com/thecodingmachine/mvc.splash-common/blob/eed0269ceda4d7d090a330a220490906a7aa60bd/src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php#L152-L181 |
thecodingmachine/mvc.splash-common | src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php | ExceptionUtils.getRelativePath | private static function getRelativePath($from, $to)
{
$from = explode('/', $from);
$to = explode('/', $to);
$relPath = $to;
foreach ($from as $depth => $dir) {
// find first non-matching dir
if (isset($to[$depth]) && $dir === $to[$depth]) {
// ignore this directory
array_shift($relPath);
} else {
// get number of remaining dirs to $from
$remaining = count($from) - $depth;
if ($remaining > 1) {
// add traversals up to first matching dir
$padLength = (count($relPath) + $remaining - 1) * -1;
$relPath = array_pad($relPath, $padLength, '..');
break;
} else {
$relPath[0] = './'.$relPath[0];
}
}
}
return implode('/', $relPath);
} | php | private static function getRelativePath($from, $to)
{
$from = explode('/', $from);
$to = explode('/', $to);
$relPath = $to;
foreach ($from as $depth => $dir) {
// find first non-matching dir
if (isset($to[$depth]) && $dir === $to[$depth]) {
// ignore this directory
array_shift($relPath);
} else {
// get number of remaining dirs to $from
$remaining = count($from) - $depth;
if ($remaining > 1) {
// add traversals up to first matching dir
$padLength = (count($relPath) + $remaining - 1) * -1;
$relPath = array_pad($relPath, $padLength, '..');
break;
} else {
$relPath[0] = './'.$relPath[0];
}
}
}
return implode('/', $relPath);
} | [
"private",
"static",
"function",
"getRelativePath",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"$",
"from",
"=",
"explode",
"(",
"'/'",
",",
"$",
"from",
")",
";",
"$",
"to",
"=",
"explode",
"(",
"'/'",
",",
"$",
"to",
")",
";",
"$",
"relPath",
"=",
"$",
"to",
";",
"foreach",
"(",
"$",
"from",
"as",
"$",
"depth",
"=>",
"$",
"dir",
")",
"{",
"// find first non-matching dir",
"if",
"(",
"isset",
"(",
"$",
"to",
"[",
"$",
"depth",
"]",
")",
"&&",
"$",
"dir",
"===",
"$",
"to",
"[",
"$",
"depth",
"]",
")",
"{",
"// ignore this directory",
"array_shift",
"(",
"$",
"relPath",
")",
";",
"}",
"else",
"{",
"// get number of remaining dirs to $from",
"$",
"remaining",
"=",
"count",
"(",
"$",
"from",
")",
"-",
"$",
"depth",
";",
"if",
"(",
"$",
"remaining",
">",
"1",
")",
"{",
"// add traversals up to first matching dir",
"$",
"padLength",
"=",
"(",
"count",
"(",
"$",
"relPath",
")",
"+",
"$",
"remaining",
"-",
"1",
")",
"*",
"-",
"1",
";",
"$",
"relPath",
"=",
"array_pad",
"(",
"$",
"relPath",
",",
"$",
"padLength",
",",
"'..'",
")",
";",
"break",
";",
"}",
"else",
"{",
"$",
"relPath",
"[",
"0",
"]",
"=",
"'./'",
".",
"$",
"relPath",
"[",
"0",
"]",
";",
"}",
"}",
"}",
"return",
"implode",
"(",
"'/'",
",",
"$",
"relPath",
")",
";",
"}"
] | Returns a relative path based on 2 absolute paths.
@param string $from
@param string $to
@return string | [
"Returns",
"a",
"relative",
"path",
"based",
"on",
"2",
"absolute",
"paths",
"."
] | train | https://github.com/thecodingmachine/mvc.splash-common/blob/eed0269ceda4d7d090a330a220490906a7aa60bd/src/Mouf/Mvc/Splash/Utils/ExceptionUtils.php#L204-L230 |
tequila/mongodb-odm | src/DocumentManager.php | DocumentManager.getBulkWriteBuilder | public function getBulkWriteBuilder(string $documentClass): BulkWriteBuilder
{
$metadata = $this->metadataFactory->getClassMetadata($documentClass);
return $this->bulkWriteBuilderFactory->getBulkWriteBuilder($this, $metadata->getCollectionName());
} | php | public function getBulkWriteBuilder(string $documentClass): BulkWriteBuilder
{
$metadata = $this->metadataFactory->getClassMetadata($documentClass);
return $this->bulkWriteBuilderFactory->getBulkWriteBuilder($this, $metadata->getCollectionName());
} | [
"public",
"function",
"getBulkWriteBuilder",
"(",
"string",
"$",
"documentClass",
")",
":",
"BulkWriteBuilder",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getClassMetadata",
"(",
"$",
"documentClass",
")",
";",
"return",
"$",
"this",
"->",
"bulkWriteBuilderFactory",
"->",
"getBulkWriteBuilder",
"(",
"$",
"this",
",",
"$",
"metadata",
"->",
"getCollectionName",
"(",
")",
")",
";",
"}"
] | @param string $documentClass
@return BulkWriteBuilder | [
"@param",
"string",
"$documentClass"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/DocumentManager.php#L86-L91 |
tequila/mongodb-odm | src/DocumentManager.php | DocumentManager.getCollection | public function getCollection($collectionName, array $options = []): Collection
{
$cacheKey = $collectionName.$this->getCollectionOptionsHash($options);
if (!array_key_exists($cacheKey, $this->collectionsCache)) {
$this->collectionsCache[$cacheKey] = $this->database->selectCollection(
$collectionName,
$options
);
}
return $this->collectionsCache[$cacheKey];
} | php | public function getCollection($collectionName, array $options = []): Collection
{
$cacheKey = $collectionName.$this->getCollectionOptionsHash($options);
if (!array_key_exists($cacheKey, $this->collectionsCache)) {
$this->collectionsCache[$cacheKey] = $this->database->selectCollection(
$collectionName,
$options
);
}
return $this->collectionsCache[$cacheKey];
} | [
"public",
"function",
"getCollection",
"(",
"$",
"collectionName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"Collection",
"{",
"$",
"cacheKey",
"=",
"$",
"collectionName",
".",
"$",
"this",
"->",
"getCollectionOptionsHash",
"(",
"$",
"options",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"cacheKey",
",",
"$",
"this",
"->",
"collectionsCache",
")",
")",
"{",
"$",
"this",
"->",
"collectionsCache",
"[",
"$",
"cacheKey",
"]",
"=",
"$",
"this",
"->",
"database",
"->",
"selectCollection",
"(",
"$",
"collectionName",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"collectionsCache",
"[",
"$",
"cacheKey",
"]",
";",
"}"
] | @param string $collectionName
@param array $options
@return Collection | [
"@param",
"string",
"$collectionName",
"@param",
"array",
"$options"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/DocumentManager.php#L99-L110 |
tequila/mongodb-odm | src/DocumentManager.php | DocumentManager.getCollectionByDocumentClass | public function getCollectionByDocumentClass($documentClass): Collection
{
$metadata = $this->metadataFactory->getClassMetadata($documentClass);
return $this->getCollection($metadata->getCollectionName(), $metadata->getCollectionOptions());
} | php | public function getCollectionByDocumentClass($documentClass): Collection
{
$metadata = $this->metadataFactory->getClassMetadata($documentClass);
return $this->getCollection($metadata->getCollectionName(), $metadata->getCollectionOptions());
} | [
"public",
"function",
"getCollectionByDocumentClass",
"(",
"$",
"documentClass",
")",
":",
"Collection",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getClassMetadata",
"(",
"$",
"documentClass",
")",
";",
"return",
"$",
"this",
"->",
"getCollection",
"(",
"$",
"metadata",
"->",
"getCollectionName",
"(",
")",
",",
"$",
"metadata",
"->",
"getCollectionOptions",
"(",
")",
")",
";",
"}"
] | @param string $documentClass
@return Collection | [
"@param",
"string",
"$documentClass"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/DocumentManager.php#L117-L122 |
tequila/mongodb-odm | src/DocumentManager.php | DocumentManager.getRepository | public function getRepository(string $documentClass): Repository
{
$metadata = $this->getMetadata($documentClass);
if ($metadata->isNested()) {
throw new InvalidArgumentException(
sprintf('Cannot get repository for nested document class "%s".', $documentClass)
);
}
return $this->repositoryFactory->getRepository($this, $documentClass);
} | php | public function getRepository(string $documentClass): Repository
{
$metadata = $this->getMetadata($documentClass);
if ($metadata->isNested()) {
throw new InvalidArgumentException(
sprintf('Cannot get repository for nested document class "%s".', $documentClass)
);
}
return $this->repositoryFactory->getRepository($this, $documentClass);
} | [
"public",
"function",
"getRepository",
"(",
"string",
"$",
"documentClass",
")",
":",
"Repository",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
"$",
"documentClass",
")",
";",
"if",
"(",
"$",
"metadata",
"->",
"isNested",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot get repository for nested document class \"%s\".'",
",",
"$",
"documentClass",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"repositoryFactory",
"->",
"getRepository",
"(",
"$",
"this",
",",
"$",
"documentClass",
")",
";",
"}"
] | @param string $documentClass
@return Repository | [
"@param",
"string",
"$documentClass"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/DocumentManager.php#L149-L159 |
tequila/mongodb-odm | src/DocumentManager.php | DocumentManager.getCollectionOptionsHash | private function getCollectionOptionsHash(array $options)
{
ksort($options);
$str = '';
foreach ($options as $option) {
if (!$option instanceof Serializable) {
// All valid Collection options are BSON serializable
continue;
}
$str .= serialize($option->bsonSerialize());
}
return md5($str);
} | php | private function getCollectionOptionsHash(array $options)
{
ksort($options);
$str = '';
foreach ($options as $option) {
if (!$option instanceof Serializable) {
// All valid Collection options are BSON serializable
continue;
}
$str .= serialize($option->bsonSerialize());
}
return md5($str);
} | [
"private",
"function",
"getCollectionOptionsHash",
"(",
"array",
"$",
"options",
")",
"{",
"ksort",
"(",
"$",
"options",
")",
";",
"$",
"str",
"=",
"''",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"$",
"option",
"instanceof",
"Serializable",
")",
"{",
"// All valid Collection options are BSON serializable",
"continue",
";",
"}",
"$",
"str",
".=",
"serialize",
"(",
"$",
"option",
"->",
"bsonSerialize",
"(",
")",
")",
";",
"}",
"return",
"md5",
"(",
"$",
"str",
")",
";",
"}"
] | @param array $options
@return string | [
"@param",
"array",
"$options"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/DocumentManager.php#L239-L252 |
tequila/mongodb-odm | src/DocumentManager.php | DocumentManager.getDocumentClass | private static function getDocumentClass(DocumentInterface $document): string
{
return $document instanceof ProxyInterface ? $document->getRealClass() : get_class($document);
} | php | private static function getDocumentClass(DocumentInterface $document): string
{
return $document instanceof ProxyInterface ? $document->getRealClass() : get_class($document);
} | [
"private",
"static",
"function",
"getDocumentClass",
"(",
"DocumentInterface",
"$",
"document",
")",
":",
"string",
"{",
"return",
"$",
"document",
"instanceof",
"ProxyInterface",
"?",
"$",
"document",
"->",
"getRealClass",
"(",
")",
":",
"get_class",
"(",
"$",
"document",
")",
";",
"}"
] | @param DocumentInterface $document
@return string | [
"@param",
"DocumentInterface",
"$document"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/DocumentManager.php#L259-L262 |
comodojo/daemon | src/Comodojo/Daemon/Socket/SocketTransport.php | SocketTransport.performCall | public function performCall(
LoggerInterface $logger,
$data,
$content_type,
$encrypt = false
) {
try {
$logger->debug("Connecting to socket");
$this->connect();
$logger->debug("Sending RPC data");
$data = $this->can($data, $encrypt);
$response = $this->send($content_type, $data);
$this->close();
$logger->debug("Decoding RPC response");
$return = $this->uncan($response, $encrypt);
} catch (SocketException $se) {
$logger->error("Socket Transport error: ".$se->getMessage());
throw $se;
} catch (RpcException $re) {
$logger->error("RPC Client error: ".$re->getMessage());
throw $re;
} catch (Exception $e) {
$logger->critical("Generic Client error: ".$e->getMessage());
throw $e;
}
return $return;
} | php | public function performCall(
LoggerInterface $logger,
$data,
$content_type,
$encrypt = false
) {
try {
$logger->debug("Connecting to socket");
$this->connect();
$logger->debug("Sending RPC data");
$data = $this->can($data, $encrypt);
$response = $this->send($content_type, $data);
$this->close();
$logger->debug("Decoding RPC response");
$return = $this->uncan($response, $encrypt);
} catch (SocketException $se) {
$logger->error("Socket Transport error: ".$se->getMessage());
throw $se;
} catch (RpcException $re) {
$logger->error("RPC Client error: ".$re->getMessage());
throw $re;
} catch (Exception $e) {
$logger->critical("Generic Client error: ".$e->getMessage());
throw $e;
}
return $return;
} | [
"public",
"function",
"performCall",
"(",
"LoggerInterface",
"$",
"logger",
",",
"$",
"data",
",",
"$",
"content_type",
",",
"$",
"encrypt",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"logger",
"->",
"debug",
"(",
"\"Connecting to socket\"",
")",
";",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"\"Sending RPC data\"",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"can",
"(",
"$",
"data",
",",
"$",
"encrypt",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"send",
"(",
"$",
"content_type",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"close",
"(",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"\"Decoding RPC response\"",
")",
";",
"$",
"return",
"=",
"$",
"this",
"->",
"uncan",
"(",
"$",
"response",
",",
"$",
"encrypt",
")",
";",
"}",
"catch",
"(",
"SocketException",
"$",
"se",
")",
"{",
"$",
"logger",
"->",
"error",
"(",
"\"Socket Transport error: \"",
".",
"$",
"se",
"->",
"getMessage",
"(",
")",
")",
";",
"throw",
"$",
"se",
";",
"}",
"catch",
"(",
"RpcException",
"$",
"re",
")",
"{",
"$",
"logger",
"->",
"error",
"(",
"\"RPC Client error: \"",
".",
"$",
"re",
"->",
"getMessage",
"(",
")",
")",
";",
"throw",
"$",
"re",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"logger",
"->",
"critical",
"(",
"\"Generic Client error: \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/comodojo/daemon/blob/361b0a3a91dc7720dd3bec448bb4ca47d0ef0292/src/Comodojo/Daemon/Socket/SocketTransport.php#L18-L65 |
rafalkot/yii2-settings | Settings.php | Settings.get | public function get($category, $key = null, $default = null)
{
$this->load($category);
if ($key === null) {
return isset($this->items[$category]) && !empty($this->items[$category]) ? $this->items[$category] : $default;
}
if (is_string($key)) {
return isset($this->items[$category][$key]) ? $this->items[$category][$key] : $default;
}
if (is_array($key)) {
$result = [];
foreach ($key as $val) {
$result[$val] = isset($this->items[$category][$val]) ? $this->items[$category][$val] : (is_array($default) && isset($default[$val]) ? $default[$val] : null);
}
return $result;
}
return $default;
} | php | public function get($category, $key = null, $default = null)
{
$this->load($category);
if ($key === null) {
return isset($this->items[$category]) && !empty($this->items[$category]) ? $this->items[$category] : $default;
}
if (is_string($key)) {
return isset($this->items[$category][$key]) ? $this->items[$category][$key] : $default;
}
if (is_array($key)) {
$result = [];
foreach ($key as $val) {
$result[$val] = isset($this->items[$category][$val]) ? $this->items[$category][$val] : (is_array($default) && isset($default[$val]) ? $default[$val] : null);
}
return $result;
}
return $default;
} | [
"public",
"function",
"get",
"(",
"$",
"category",
",",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"category",
")",
";",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
")",
"?",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
":",
"$",
"default",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"[",
"$",
"key",
"]",
":",
"$",
"default",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"key",
"as",
"$",
"val",
")",
"{",
"$",
"result",
"[",
"$",
"val",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"[",
"$",
"val",
"]",
")",
"?",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"[",
"$",
"val",
"]",
":",
"(",
"is_array",
"(",
"$",
"default",
")",
"&&",
"isset",
"(",
"$",
"default",
"[",
"$",
"val",
"]",
")",
"?",
"$",
"default",
"[",
"$",
"val",
"]",
":",
"null",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Returns settings.
@param string $category Category name
@param string|array $key Single or multiple keys in array
@param mixed $default Default value when setting does not exist
@return mixed Setting value
@throws Exception | [
"Returns",
"settings",
"."
] | train | https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/Settings.php#L56-L77 |
rafalkot/yii2-settings | Settings.php | Settings.set | public function set($category, $key, $value = null)
{
if (is_string($key)) {
$encodedVal = Json::encode($value);
$this->get($category, $key, null);
if (array_key_exists($key, $this->items[$category])) {
$this->dbUpdate($category, $key, $encodedVal);
} else {
$this->dbInsert($category, $key, $encodedVal);
}
$this->items[$category][$key] = $value;
}
if (is_array($key)) {
foreach ($key as $idx => $val) {
$this->set($category, $idx, $val);
}
}
} | php | public function set($category, $key, $value = null)
{
if (is_string($key)) {
$encodedVal = Json::encode($value);
$this->get($category, $key, null);
if (array_key_exists($key, $this->items[$category])) {
$this->dbUpdate($category, $key, $encodedVal);
} else {
$this->dbInsert($category, $key, $encodedVal);
}
$this->items[$category][$key] = $value;
}
if (is_array($key)) {
foreach ($key as $idx => $val) {
$this->set($category, $idx, $val);
}
}
} | [
"public",
"function",
"set",
"(",
"$",
"category",
",",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"encodedVal",
"=",
"Json",
"::",
"encode",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"get",
"(",
"$",
"category",
",",
"$",
"key",
",",
"null",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
")",
")",
"{",
"$",
"this",
"->",
"dbUpdate",
"(",
"$",
"category",
",",
"$",
"key",
",",
"$",
"encodedVal",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"dbInsert",
"(",
"$",
"category",
",",
"$",
"key",
",",
"$",
"encodedVal",
")",
";",
"}",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"foreach",
"(",
"$",
"key",
"as",
"$",
"idx",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"category",
",",
"$",
"idx",
",",
"$",
"val",
")",
";",
"}",
"}",
"}"
] | Saves settings
@param string $category Category name
@param mixed $key Setting key or array of settings ie.: ['key' => value'', 'key2' => 'value2']
@param mixed $value Setting value
@throws Exception | [
"Saves",
"settings"
] | train | https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/Settings.php#L87-L107 |
rafalkot/yii2-settings | Settings.php | Settings.remove | public function remove($category, $key = null)
{
if ($key === null) {
$this->dbDelete($category);
if (isset($this->items[$category])) {
unset($this->items[$category]);
}
}
if (is_string($key)) {
$this->dbDelete($category, $key);
if (isset($this->items[$category][$key])) {
unset($this->items[$category][$key]);
}
}
if (is_array($key)) {
foreach ($key as $idx => $val) {
$this->remove($category, $key);
}
}
} | php | public function remove($category, $key = null)
{
if ($key === null) {
$this->dbDelete($category);
if (isset($this->items[$category])) {
unset($this->items[$category]);
}
}
if (is_string($key)) {
$this->dbDelete($category, $key);
if (isset($this->items[$category][$key])) {
unset($this->items[$category][$key]);
}
}
if (is_array($key)) {
foreach ($key as $idx => $val) {
$this->remove($category, $key);
}
}
} | [
"public",
"function",
"remove",
"(",
"$",
"category",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"dbDelete",
"(",
"$",
"category",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
")",
";",
"}",
"}",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"dbDelete",
"(",
"$",
"category",
",",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"foreach",
"(",
"$",
"key",
"as",
"$",
"idx",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"category",
",",
"$",
"key",
")",
";",
"}",
"}",
"}"
] | Removes settings
@param string $category Category name
@param array|string|null $key Setting key, keys array or null to delete all settings from category
@throws Exception | [
"Removes",
"settings"
] | train | https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/Settings.php#L116-L140 |
rafalkot/yii2-settings | Settings.php | Settings.load | public function load($categories)
{
if (is_string($categories)) {
$categories = [$categories];
}
foreach ($categories as $idx => $category) {
if (isset($this->items[$category])) {
unset($categories[$idx]);
} else {
$this->items[$category] = [];
}
}
if (empty($categories)) {
return;
}
$result = (new Query())->select(['category', 'key', 'value'])->from('setting')->where([
'category' => $categories
])->all();
foreach ($result as $row) {
try {
$this->items[$row['category']][$row['key']] = Json::decode($row['value']);
} catch (InvalidParamException $ex) {
$this->items[$row['category']][$row['key']] = $row['value'];
}
}
} | php | public function load($categories)
{
if (is_string($categories)) {
$categories = [$categories];
}
foreach ($categories as $idx => $category) {
if (isset($this->items[$category])) {
unset($categories[$idx]);
} else {
$this->items[$category] = [];
}
}
if (empty($categories)) {
return;
}
$result = (new Query())->select(['category', 'key', 'value'])->from('setting')->where([
'category' => $categories
])->all();
foreach ($result as $row) {
try {
$this->items[$row['category']][$row['key']] = Json::decode($row['value']);
} catch (InvalidParamException $ex) {
$this->items[$row['category']][$row['key']] = $row['value'];
}
}
} | [
"public",
"function",
"load",
"(",
"$",
"categories",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"categories",
")",
")",
"{",
"$",
"categories",
"=",
"[",
"$",
"categories",
"]",
";",
"}",
"foreach",
"(",
"$",
"categories",
"as",
"$",
"idx",
"=>",
"$",
"category",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"categories",
"[",
"$",
"idx",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"items",
"[",
"$",
"category",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"categories",
")",
")",
"{",
"return",
";",
"}",
"$",
"result",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'category'",
",",
"'key'",
",",
"'value'",
"]",
")",
"->",
"from",
"(",
"'setting'",
")",
"->",
"where",
"(",
"[",
"'category'",
"=>",
"$",
"categories",
"]",
")",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"row",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"items",
"[",
"$",
"row",
"[",
"'category'",
"]",
"]",
"[",
"$",
"row",
"[",
"'key'",
"]",
"]",
"=",
"Json",
"::",
"decode",
"(",
"$",
"row",
"[",
"'value'",
"]",
")",
";",
"}",
"catch",
"(",
"InvalidParamException",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"$",
"row",
"[",
"'category'",
"]",
"]",
"[",
"$",
"row",
"[",
"'key'",
"]",
"]",
"=",
"$",
"row",
"[",
"'value'",
"]",
";",
"}",
"}",
"}"
] | Loads settings from category or multiple categories
@param array|string $categories Category name | [
"Loads",
"settings",
"from",
"category",
"or",
"multiple",
"categories"
] | train | https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/Settings.php#L147-L176 |
rafalkot/yii2-settings | Settings.php | Settings.dbInsert | protected function dbInsert($category, $key, $value)
{
$created_by = \Yii::$app->user->getId();
$this->getDb()->createCommand('
INSERT INTO
{{setting}} (`category`, `key`, `value`, `created_at`, `created_by`)
VALUES
(:category, :key, :value, NOW(), :created_by)
', compact('category', 'key', 'value', 'created_by'))->execute();
} | php | protected function dbInsert($category, $key, $value)
{
$created_by = \Yii::$app->user->getId();
$this->getDb()->createCommand('
INSERT INTO
{{setting}} (`category`, `key`, `value`, `created_at`, `created_by`)
VALUES
(:category, :key, :value, NOW(), :created_by)
', compact('category', 'key', 'value', 'created_by'))->execute();
} | [
"protected",
"function",
"dbInsert",
"(",
"$",
"category",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"created_by",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"getId",
"(",
")",
";",
"$",
"this",
"->",
"getDb",
"(",
")",
"->",
"createCommand",
"(",
"'\n INSERT INTO\n {{setting}} (`category`, `key`, `value`, `created_at`, `created_by`)\n VALUES\n (:category, :key, :value, NOW(), :created_by)\n '",
",",
"compact",
"(",
"'category'",
",",
"'key'",
",",
"'value'",
",",
"'created_by'",
")",
")",
"->",
"execute",
"(",
")",
";",
"}"
] | Stores settings in database
@param string $category Category name
@param string $key Setting key
@param string $value Setting value
@throws \yii\db\Exception | [
"Stores",
"settings",
"in",
"database"
] | train | https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/Settings.php#L194-L203 |
rafalkot/yii2-settings | Settings.php | Settings.dbUpdate | protected function dbUpdate($category, $key, $value)
{
$updated_by = \Yii::$app->user->getId();
$this->getDb()->createCommand('
UPDATE
{{setting}}
SET
`value` = :value,
`updated_at` = NOW(),
`updated_by` = :updated_by
WHERE
category = :category
AND `key` = :key
', compact('category', 'key', 'value', 'updated_by'))->execute();
} | php | protected function dbUpdate($category, $key, $value)
{
$updated_by = \Yii::$app->user->getId();
$this->getDb()->createCommand('
UPDATE
{{setting}}
SET
`value` = :value,
`updated_at` = NOW(),
`updated_by` = :updated_by
WHERE
category = :category
AND `key` = :key
', compact('category', 'key', 'value', 'updated_by'))->execute();
} | [
"protected",
"function",
"dbUpdate",
"(",
"$",
"category",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"updated_by",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"getId",
"(",
")",
";",
"$",
"this",
"->",
"getDb",
"(",
")",
"->",
"createCommand",
"(",
"'\n UPDATE\n {{setting}}\n SET\n `value` = :value,\n `updated_at` = NOW(),\n `updated_by` = :updated_by\n WHERE\n category = :category\n AND `key` = :key\n '",
",",
"compact",
"(",
"'category'",
",",
"'key'",
",",
"'value'",
",",
"'updated_by'",
")",
")",
"->",
"execute",
"(",
")",
";",
"}"
] | Updates setting in database
@param string $category Category name
@param string $key Setting key
@param string $value Setting value
@throws \yii\db\Exception | [
"Updates",
"setting",
"in",
"database"
] | train | https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/Settings.php#L213-L227 |
rafalkot/yii2-settings | Settings.php | Settings.dbDelete | protected function dbDelete($category, $key = null)
{
if ($key === null) {
$this->getDb()->createCommand('
DELETE FROM
{{setting}}
WHERE
`category` = :category
', compact('category'))->execute();
}
if (is_string($key)) {
$this->getDb()->createCommand('
DELETE FROM
{{setting}}
WHERE
`category` = :category
AND `key` = :key
', compact('category', 'key'))->execute();
}
if (is_array($key)) {
foreach ($key as $val) {
$this->dbDelete($category, $val);
}
}
} | php | protected function dbDelete($category, $key = null)
{
if ($key === null) {
$this->getDb()->createCommand('
DELETE FROM
{{setting}}
WHERE
`category` = :category
', compact('category'))->execute();
}
if (is_string($key)) {
$this->getDb()->createCommand('
DELETE FROM
{{setting}}
WHERE
`category` = :category
AND `key` = :key
', compact('category', 'key'))->execute();
}
if (is_array($key)) {
foreach ($key as $val) {
$this->dbDelete($category, $val);
}
}
} | [
"protected",
"function",
"dbDelete",
"(",
"$",
"category",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"getDb",
"(",
")",
"->",
"createCommand",
"(",
"'\n DELETE FROM\n {{setting}}\n WHERE\n `category` = :category\n '",
",",
"compact",
"(",
"'category'",
")",
")",
"->",
"execute",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"getDb",
"(",
")",
"->",
"createCommand",
"(",
"'\n DELETE FROM\n {{setting}}\n WHERE\n `category` = :category\n AND `key` = :key\n '",
",",
"compact",
"(",
"'category'",
",",
"'key'",
")",
")",
"->",
"execute",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"foreach",
"(",
"$",
"key",
"as",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"dbDelete",
"(",
"$",
"category",
",",
"$",
"val",
")",
";",
"}",
"}",
"}"
] | Deletes setting from database
@param string|array $category Category name(s)
@param string|array|null $key Setting key(s) or null to delete all values from category
@throws \yii\db\Exception | [
"Deletes",
"setting",
"from",
"database"
] | train | https://github.com/rafalkot/yii2-settings/blob/b601b58809322f617273093766dc28c08e74d566/Settings.php#L236-L262 |
antaresproject/notifications | src/Repository/StackRepository.php | StackRepository.push | public function push($type, $name, $value)
{
$typeModel = NotificationTypes::where('name', $type)->first();
if (is_null($typeModel)) {
return false;
}
$tId = $typeModel->id;
$model = $this->makeModel()->getModel()->newInstance([
'type_id' => $tId,
'name' => $name,
'value' => $value
]);
$model->save();
return $model;
} | php | public function push($type, $name, $value)
{
$typeModel = NotificationTypes::where('name', $type)->first();
if (is_null($typeModel)) {
return false;
}
$tId = $typeModel->id;
$model = $this->makeModel()->getModel()->newInstance([
'type_id' => $tId,
'name' => $name,
'value' => $value
]);
$model->save();
return $model;
} | [
"public",
"function",
"push",
"(",
"$",
"type",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"typeModel",
"=",
"NotificationTypes",
"::",
"where",
"(",
"'name'",
",",
"$",
"type",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"typeModel",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tId",
"=",
"$",
"typeModel",
"->",
"id",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"makeModel",
"(",
")",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
"[",
"'type_id'",
"=>",
"$",
"tId",
",",
"'name'",
"=>",
"$",
"name",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"return",
"$",
"model",
";",
"}"
] | push notification to database
@param String $type
@param String $name
@param array $value
@return boolean | [
"push",
"notification",
"to",
"database"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L58-L72 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.