id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
237,100
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.delete
|
public function delete($configurationIdentifier)
{
/**
* Checks if the value is defined in the configuration elements.
*/
if (!array_key_exists($configurationIdentifier, $this->configurationElements)) {
throw new ConfigurationParameterNotFoundException();
}
/**
* Checks if the configuration element is read-only.
*/
if (
is_array($this->configurationElements[$configurationIdentifier]) &&
$this->configurationElements[$configurationIdentifier]['read_only'] === true
) {
throw new ConfigurationNotEditableException();
}
$valueIsCached = $this
->cache
->contains($configurationIdentifier);
/**
* The value is cached, so first we have to remove it.
*/
if (false !== $valueIsCached) {
$this
->cache
->delete($configurationIdentifier);
}
list($configurationNamespace, $configurationKey) = $this->splitConfigurationKey($configurationIdentifier);
$configurationLoaded = $this->loadConfiguration(
$configurationNamespace,
$configurationKey
);
if ($configurationLoaded instanceof ConfigurationInterface) {
/*
* Configuration is found, delete it
*/
$this->deleteConfiguration($configurationLoaded);
return true;
}
/*
* Configuration instance was not found
*/
return false;
}
|
php
|
public function delete($configurationIdentifier)
{
/**
* Checks if the value is defined in the configuration elements.
*/
if (!array_key_exists($configurationIdentifier, $this->configurationElements)) {
throw new ConfigurationParameterNotFoundException();
}
/**
* Checks if the configuration element is read-only.
*/
if (
is_array($this->configurationElements[$configurationIdentifier]) &&
$this->configurationElements[$configurationIdentifier]['read_only'] === true
) {
throw new ConfigurationNotEditableException();
}
$valueIsCached = $this
->cache
->contains($configurationIdentifier);
/**
* The value is cached, so first we have to remove it.
*/
if (false !== $valueIsCached) {
$this
->cache
->delete($configurationIdentifier);
}
list($configurationNamespace, $configurationKey) = $this->splitConfigurationKey($configurationIdentifier);
$configurationLoaded = $this->loadConfiguration(
$configurationNamespace,
$configurationKey
);
if ($configurationLoaded instanceof ConfigurationInterface) {
/*
* Configuration is found, delete it
*/
$this->deleteConfiguration($configurationLoaded);
return true;
}
/*
* Configuration instance was not found
*/
return false;
}
|
[
"public",
"function",
"delete",
"(",
"$",
"configurationIdentifier",
")",
"{",
"/**\n * Checks if the value is defined in the configuration elements.\n */",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"configurationIdentifier",
",",
"$",
"this",
"->",
"configurationElements",
")",
")",
"{",
"throw",
"new",
"ConfigurationParameterNotFoundException",
"(",
")",
";",
"}",
"/**\n * Checks if the configuration element is read-only.\n */",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"configurationElements",
"[",
"$",
"configurationIdentifier",
"]",
")",
"&&",
"$",
"this",
"->",
"configurationElements",
"[",
"$",
"configurationIdentifier",
"]",
"[",
"'read_only'",
"]",
"===",
"true",
")",
"{",
"throw",
"new",
"ConfigurationNotEditableException",
"(",
")",
";",
"}",
"$",
"valueIsCached",
"=",
"$",
"this",
"->",
"cache",
"->",
"contains",
"(",
"$",
"configurationIdentifier",
")",
";",
"/**\n * The value is cached, so first we have to remove it.\n */",
"if",
"(",
"false",
"!==",
"$",
"valueIsCached",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"delete",
"(",
"$",
"configurationIdentifier",
")",
";",
"}",
"list",
"(",
"$",
"configurationNamespace",
",",
"$",
"configurationKey",
")",
"=",
"$",
"this",
"->",
"splitConfigurationKey",
"(",
"$",
"configurationIdentifier",
")",
";",
"$",
"configurationLoaded",
"=",
"$",
"this",
"->",
"loadConfiguration",
"(",
"$",
"configurationNamespace",
",",
"$",
"configurationKey",
")",
";",
"if",
"(",
"$",
"configurationLoaded",
"instanceof",
"ConfigurationInterface",
")",
"{",
"/*\n * Configuration is found, delete it\n */",
"$",
"this",
"->",
"deleteConfiguration",
"(",
"$",
"configurationLoaded",
")",
";",
"return",
"true",
";",
"}",
"/*\n * Configuration instance was not found\n */",
"return",
"false",
";",
"}"
] |
Deletes a parameter given the format "namespace.key".
@param string $configurationIdentifier
@return bool
@throws ConfigurationNotEditableException Configuration parameter is read-only
@throws ConfigurationParameterNotFoundException Configuration parameter not found
|
[
"Deletes",
"a",
"parameter",
"given",
"the",
"format",
"namespace",
".",
"key",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L246-L298
|
237,101
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.loadConfiguration
|
private function loadConfiguration(
$configurationNamespace,
$configurationKey
) {
$configurationEntity = $this
->configurationRepository
->find([
'namespace' => $configurationNamespace,
'key' => $configurationKey,
]);
return $configurationEntity;
}
|
php
|
private function loadConfiguration(
$configurationNamespace,
$configurationKey
) {
$configurationEntity = $this
->configurationRepository
->find([
'namespace' => $configurationNamespace,
'key' => $configurationKey,
]);
return $configurationEntity;
}
|
[
"private",
"function",
"loadConfiguration",
"(",
"$",
"configurationNamespace",
",",
"$",
"configurationKey",
")",
"{",
"$",
"configurationEntity",
"=",
"$",
"this",
"->",
"configurationRepository",
"->",
"find",
"(",
"[",
"'namespace'",
"=>",
"$",
"configurationNamespace",
",",
"'key'",
"=>",
"$",
"configurationKey",
",",
"]",
")",
";",
"return",
"$",
"configurationEntity",
";",
"}"
] |
Loads a configuration.
@param string $configurationNamespace Configuration namespace
@param string $configurationKey Configuration key
@return ConfigurationInterface|null Object saved
|
[
"Loads",
"a",
"configuration",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L308-L320
|
237,102
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.flushConfiguration
|
private function flushConfiguration(ConfigurationInterface $configuration)
{
$this
->configurationObjectManager
->persist($configuration);
$this
->configurationObjectManager
->flush($configuration);
return $this;
}
|
php
|
private function flushConfiguration(ConfigurationInterface $configuration)
{
$this
->configurationObjectManager
->persist($configuration);
$this
->configurationObjectManager
->flush($configuration);
return $this;
}
|
[
"private",
"function",
"flushConfiguration",
"(",
"ConfigurationInterface",
"$",
"configuration",
")",
"{",
"$",
"this",
"->",
"configurationObjectManager",
"->",
"persist",
"(",
"$",
"configuration",
")",
";",
"$",
"this",
"->",
"configurationObjectManager",
"->",
"flush",
"(",
"$",
"configuration",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Flushes a configuration instance.
@param ConfigurationInterface $configuration Configuration instance
@return ConfigurationManager Self object
|
[
"Flushes",
"a",
"configuration",
"instance",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L329-L340
|
237,103
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.deleteConfiguration
|
private function deleteConfiguration(ConfigurationInterface $configuration)
{
$this
->configurationObjectManager
->remove($configuration);
$this
->configurationObjectManager
->flush($configuration);
return $this;
}
|
php
|
private function deleteConfiguration(ConfigurationInterface $configuration)
{
$this
->configurationObjectManager
->remove($configuration);
$this
->configurationObjectManager
->flush($configuration);
return $this;
}
|
[
"private",
"function",
"deleteConfiguration",
"(",
"ConfigurationInterface",
"$",
"configuration",
")",
"{",
"$",
"this",
"->",
"configurationObjectManager",
"->",
"remove",
"(",
"$",
"configuration",
")",
";",
"$",
"this",
"->",
"configurationObjectManager",
"->",
"flush",
"(",
"$",
"configuration",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Deletes a configuration instance.
@param ConfigurationInterface $configuration Configuration instance
@return $this Self object
|
[
"Deletes",
"a",
"configuration",
"instance",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L349-L360
|
237,104
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.createConfigurationInstance
|
private function createConfigurationInstance(
$configurationIdentifier,
$configurationNamespace,
$configurationKey,
$configurationValue
) {
/**
* Value is not found on database. We can just check if the value is
* defined in the configuration elements, and we can generate new entry
* for our database.
*/
if (!$this->configurationElements[$configurationIdentifier]) {
throw new ConfigurationParameterNotFoundException();
}
$configurationType = $this->configurationElements[$configurationIdentifier]['type'];
$configurationValue = $this
->serializeValue(
$configurationValue,
$configurationType
);
$configurationEntity = $this
->configurationFactory
->create()
->setKey($configurationKey)
->setNamespace($configurationNamespace)
->setName($this->configurationElements[$configurationIdentifier]['name'])
->setType($configurationType)
->setValue($configurationValue);
return $configurationEntity;
}
|
php
|
private function createConfigurationInstance(
$configurationIdentifier,
$configurationNamespace,
$configurationKey,
$configurationValue
) {
/**
* Value is not found on database. We can just check if the value is
* defined in the configuration elements, and we can generate new entry
* for our database.
*/
if (!$this->configurationElements[$configurationIdentifier]) {
throw new ConfigurationParameterNotFoundException();
}
$configurationType = $this->configurationElements[$configurationIdentifier]['type'];
$configurationValue = $this
->serializeValue(
$configurationValue,
$configurationType
);
$configurationEntity = $this
->configurationFactory
->create()
->setKey($configurationKey)
->setNamespace($configurationNamespace)
->setName($this->configurationElements[$configurationIdentifier]['name'])
->setType($configurationType)
->setValue($configurationValue);
return $configurationEntity;
}
|
[
"private",
"function",
"createConfigurationInstance",
"(",
"$",
"configurationIdentifier",
",",
"$",
"configurationNamespace",
",",
"$",
"configurationKey",
",",
"$",
"configurationValue",
")",
"{",
"/**\n * Value is not found on database. We can just check if the value is\n * defined in the configuration elements, and we can generate new entry\n * for our database.\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"configurationElements",
"[",
"$",
"configurationIdentifier",
"]",
")",
"{",
"throw",
"new",
"ConfigurationParameterNotFoundException",
"(",
")",
";",
"}",
"$",
"configurationType",
"=",
"$",
"this",
"->",
"configurationElements",
"[",
"$",
"configurationIdentifier",
"]",
"[",
"'type'",
"]",
";",
"$",
"configurationValue",
"=",
"$",
"this",
"->",
"serializeValue",
"(",
"$",
"configurationValue",
",",
"$",
"configurationType",
")",
";",
"$",
"configurationEntity",
"=",
"$",
"this",
"->",
"configurationFactory",
"->",
"create",
"(",
")",
"->",
"setKey",
"(",
"$",
"configurationKey",
")",
"->",
"setNamespace",
"(",
"$",
"configurationNamespace",
")",
"->",
"setName",
"(",
"$",
"this",
"->",
"configurationElements",
"[",
"$",
"configurationIdentifier",
"]",
"[",
"'name'",
"]",
")",
"->",
"setType",
"(",
"$",
"configurationType",
")",
"->",
"setValue",
"(",
"$",
"configurationValue",
")",
";",
"return",
"$",
"configurationEntity",
";",
"}"
] |
Creates a new configuration instance and serializes.
@param string $configurationIdentifier Configuration identifier
@param string $configurationNamespace Configuration namespace
@param string $configurationKey Configuration key
@param mixed $configurationValue Configuration value
@return ConfigurationInterface New Configuration created
@throws ConfigurationParameterNotFoundException Configuration parameter not found
|
[
"Creates",
"a",
"new",
"configuration",
"instance",
"and",
"serializes",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L374-L407
|
237,105
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.flushConfigurationToCache
|
private function flushConfigurationToCache(
ConfigurationInterface $configuration,
$configurationIdentifier
) {
$configurationValue = $this->unserializeValue(
$configuration->getValue(),
$configuration->getType()
);
$this
->cache
->save(
$configurationIdentifier,
$configurationValue
);
return $configurationValue;
}
|
php
|
private function flushConfigurationToCache(
ConfigurationInterface $configuration,
$configurationIdentifier
) {
$configurationValue = $this->unserializeValue(
$configuration->getValue(),
$configuration->getType()
);
$this
->cache
->save(
$configurationIdentifier,
$configurationValue
);
return $configurationValue;
}
|
[
"private",
"function",
"flushConfigurationToCache",
"(",
"ConfigurationInterface",
"$",
"configuration",
",",
"$",
"configurationIdentifier",
")",
"{",
"$",
"configurationValue",
"=",
"$",
"this",
"->",
"unserializeValue",
"(",
"$",
"configuration",
"->",
"getValue",
"(",
")",
",",
"$",
"configuration",
"->",
"getType",
"(",
")",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"configurationIdentifier",
",",
"$",
"configurationValue",
")",
";",
"return",
"$",
"configurationValue",
";",
"}"
] |
Saves configuration into cache.
@param ConfigurationInterface $configuration Configuration
@param string $configurationIdentifier Configuration identifier
@return mixed flushed value
|
[
"Saves",
"configuration",
"into",
"cache",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L417-L434
|
237,106
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.splitConfigurationKey
|
private function splitConfigurationKey($configurationIdentifier)
{
$configurationIdentifier = explode('.', $configurationIdentifier, 2);
if (count($configurationIdentifier) === 1) {
array_unshift($configurationIdentifier, '');
}
return $configurationIdentifier;
}
|
php
|
private function splitConfigurationKey($configurationIdentifier)
{
$configurationIdentifier = explode('.', $configurationIdentifier, 2);
if (count($configurationIdentifier) === 1) {
array_unshift($configurationIdentifier, '');
}
return $configurationIdentifier;
}
|
[
"private",
"function",
"splitConfigurationKey",
"(",
"$",
"configurationIdentifier",
")",
"{",
"$",
"configurationIdentifier",
"=",
"explode",
"(",
"'.'",
",",
"$",
"configurationIdentifier",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"configurationIdentifier",
")",
"===",
"1",
")",
"{",
"array_unshift",
"(",
"$",
"configurationIdentifier",
",",
"''",
")",
";",
"}",
"return",
"$",
"configurationIdentifier",
";",
"}"
] |
Split the configuration identifier and return each part.
@param string $configurationIdentifier Configuration identifier
@return string[] Identifier splitted
|
[
"Split",
"the",
"configuration",
"identifier",
"and",
"return",
"each",
"part",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L443-L452
|
237,107
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.unserializeValue
|
private function unserializeValue($configurationValue, $configurationType)
{
switch ($configurationType) {
case ElcodiConfigurationTypes::TYPE_BOOLEAN:
$configurationValue = (boolean) $configurationValue;
break;
case ElcodiConfigurationTypes::TYPE_ARRAY:
$configurationValue = json_decode($configurationValue, true);
break;
}
return $configurationValue;
}
|
php
|
private function unserializeValue($configurationValue, $configurationType)
{
switch ($configurationType) {
case ElcodiConfigurationTypes::TYPE_BOOLEAN:
$configurationValue = (boolean) $configurationValue;
break;
case ElcodiConfigurationTypes::TYPE_ARRAY:
$configurationValue = json_decode($configurationValue, true);
break;
}
return $configurationValue;
}
|
[
"private",
"function",
"unserializeValue",
"(",
"$",
"configurationValue",
",",
"$",
"configurationType",
")",
"{",
"switch",
"(",
"$",
"configurationType",
")",
"{",
"case",
"ElcodiConfigurationTypes",
"::",
"TYPE_BOOLEAN",
":",
"$",
"configurationValue",
"=",
"(",
"boolean",
")",
"$",
"configurationValue",
";",
"break",
";",
"case",
"ElcodiConfigurationTypes",
"::",
"TYPE_ARRAY",
":",
"$",
"configurationValue",
"=",
"json_decode",
"(",
"$",
"configurationValue",
",",
"true",
")",
";",
"break",
";",
"}",
"return",
"$",
"configurationValue",
";",
"}"
] |
Unserialize configuration value.
@param string $configurationValue Configuration value
@param string $configurationType Configuration type
@return mixed Configuration value unserialized
|
[
"Unserialize",
"configuration",
"value",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L462-L476
|
237,108
|
elcodi/Configuration
|
Services/ConfigurationManager.php
|
ConfigurationManager.serializeValue
|
private function serializeValue($configurationValue, $configurationType)
{
switch ($configurationType) {
case ElcodiConfigurationTypes::TYPE_ARRAY:
$configurationValue = json_encode($configurationValue);
break;
}
return $configurationValue;
}
|
php
|
private function serializeValue($configurationValue, $configurationType)
{
switch ($configurationType) {
case ElcodiConfigurationTypes::TYPE_ARRAY:
$configurationValue = json_encode($configurationValue);
break;
}
return $configurationValue;
}
|
[
"private",
"function",
"serializeValue",
"(",
"$",
"configurationValue",
",",
"$",
"configurationType",
")",
"{",
"switch",
"(",
"$",
"configurationType",
")",
"{",
"case",
"ElcodiConfigurationTypes",
"::",
"TYPE_ARRAY",
":",
"$",
"configurationValue",
"=",
"json_encode",
"(",
"$",
"configurationValue",
")",
";",
"break",
";",
"}",
"return",
"$",
"configurationValue",
";",
"}"
] |
Serialize configuration value.
@param string $configurationValue Configuration value
@param string $configurationType Configuration type
@return string Configuration value serialized
|
[
"Serialize",
"configuration",
"value",
"."
] |
1e416269c2e1bd957f98c6b1845dffb218794c55
|
https://github.com/elcodi/Configuration/blob/1e416269c2e1bd957f98c6b1845dffb218794c55/Services/ConfigurationManager.php#L486-L496
|
237,109
|
chilimatic/transformer-component
|
src/Time/DateDiffToDecimalTime.php
|
DateDiffToDecimalTime.transform
|
public function transform($content, $options = [])
{
if (!$content instanceof \DateInterval) {
return 0;
}
$decTime = 0;
$decTime += ($content->d ? $content->d * 60 * 24 : 0);
$decTime += ($content->h ? $content->h * 60 : 0);
$decTime += $content->i;
$decTime += ($content->s ? $content->s / 60 : 0);
return $decTime;
}
|
php
|
public function transform($content, $options = [])
{
if (!$content instanceof \DateInterval) {
return 0;
}
$decTime = 0;
$decTime += ($content->d ? $content->d * 60 * 24 : 0);
$decTime += ($content->h ? $content->h * 60 : 0);
$decTime += $content->i;
$decTime += ($content->s ? $content->s / 60 : 0);
return $decTime;
}
|
[
"public",
"function",
"transform",
"(",
"$",
"content",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"content",
"instanceof",
"\\",
"DateInterval",
")",
"{",
"return",
"0",
";",
"}",
"$",
"decTime",
"=",
"0",
";",
"$",
"decTime",
"+=",
"(",
"$",
"content",
"->",
"d",
"?",
"$",
"content",
"->",
"d",
"*",
"60",
"*",
"24",
":",
"0",
")",
";",
"$",
"decTime",
"+=",
"(",
"$",
"content",
"->",
"h",
"?",
"$",
"content",
"->",
"h",
"*",
"60",
":",
"0",
")",
";",
"$",
"decTime",
"+=",
"$",
"content",
"->",
"i",
";",
"$",
"decTime",
"+=",
"(",
"$",
"content",
"->",
"s",
"?",
"$",
"content",
"->",
"s",
"/",
"60",
":",
"0",
")",
";",
"return",
"$",
"decTime",
";",
"}"
] |
calculates the time down to the minutes
@param \DateInterval $content
@param array $options
@return string
|
[
"calculates",
"the",
"time",
"down",
"to",
"the",
"minutes"
] |
1d20cda19531bb3d3476666793906680ee523363
|
https://github.com/chilimatic/transformer-component/blob/1d20cda19531bb3d3476666793906680ee523363/src/Time/DateDiffToDecimalTime.php#L22-L35
|
237,110
|
tenside/core
|
src/Task/Composer/DumpAutoloadTask.php
|
DumpAutoloadTask.prepareInput
|
protected function prepareInput()
{
$arguments = [
'--optimize' => (bool) $this->file->get(self::SETTING_OPTIMIZE),
'--no-dev' => true,
];
$input = new ArrayInput($arguments);
$input->setInteractive(false);
return $input;
}
|
php
|
protected function prepareInput()
{
$arguments = [
'--optimize' => (bool) $this->file->get(self::SETTING_OPTIMIZE),
'--no-dev' => true,
];
$input = new ArrayInput($arguments);
$input->setInteractive(false);
return $input;
}
|
[
"protected",
"function",
"prepareInput",
"(",
")",
"{",
"$",
"arguments",
"=",
"[",
"'--optimize'",
"=>",
"(",
"bool",
")",
"$",
"this",
"->",
"file",
"->",
"get",
"(",
"self",
"::",
"SETTING_OPTIMIZE",
")",
",",
"'--no-dev'",
"=>",
"true",
",",
"]",
";",
"$",
"input",
"=",
"new",
"ArrayInput",
"(",
"$",
"arguments",
")",
";",
"$",
"input",
"->",
"setInteractive",
"(",
"false",
")",
";",
"return",
"$",
"input",
";",
"}"
] |
Prepare the input interface for the command.
@return InputInterface
|
[
"Prepare",
"the",
"input",
"interface",
"for",
"the",
"command",
"."
] |
56422fa8cdecf03cb431bb6654c2942ade39bf7b
|
https://github.com/tenside/core/blob/56422fa8cdecf03cb431bb6654c2942ade39bf7b/src/Task/Composer/DumpAutoloadTask.php#L67-L78
|
237,111
|
mxc-commons/mxc-servicemanager
|
src/AbstractFactory/ReflectionBasedAbstractFactory.php
|
ReflectionBasedAbstractFactory.resolveParameterWithoutConfigService
|
private function resolveParameterWithoutConfigService(ContainerInterface $container, $requestedName)
{
/**
* @param ReflectionParameter $parameter
* @return mixed
* @throws ServiceNotFoundException If type-hinted parameter cannot be
* resolved to a service in the container.
*/
return function (ReflectionParameter $parameter) use ($container, $requestedName) {
return $this->resolveParameter($parameter, $container, $requestedName);
};
}
|
php
|
private function resolveParameterWithoutConfigService(ContainerInterface $container, $requestedName)
{
/**
* @param ReflectionParameter $parameter
* @return mixed
* @throws ServiceNotFoundException If type-hinted parameter cannot be
* resolved to a service in the container.
*/
return function (ReflectionParameter $parameter) use ($container, $requestedName) {
return $this->resolveParameter($parameter, $container, $requestedName);
};
}
|
[
"private",
"function",
"resolveParameterWithoutConfigService",
"(",
"ContainerInterface",
"$",
"container",
",",
"$",
"requestedName",
")",
"{",
"/**\n * @param ReflectionParameter $parameter\n * @return mixed\n * @throws ServiceNotFoundException If type-hinted parameter cannot be\n * resolved to a service in the container.\n */",
"return",
"function",
"(",
"ReflectionParameter",
"$",
"parameter",
")",
"use",
"(",
"$",
"container",
",",
"$",
"requestedName",
")",
"{",
"return",
"$",
"this",
"->",
"resolveParameter",
"(",
"$",
"parameter",
",",
"$",
"container",
",",
"$",
"requestedName",
")",
";",
"}",
";",
"}"
] |
Resolve a parameter to a value.
Returns a callback for resolving a parameter to a value, but without
allowing mapping array `$config` arguments to the `config` service.
@param ContainerInterface $container
@param string $requestedName
@return callable
|
[
"Resolve",
"a",
"parameter",
"to",
"a",
"value",
"."
] |
547a9ed579b96d32cb54db5723510d75fcad71be
|
https://github.com/mxc-commons/mxc-servicemanager/blob/547a9ed579b96d32cb54db5723510d75fcad71be/src/AbstractFactory/ReflectionBasedAbstractFactory.php#L151-L162
|
237,112
|
mxc-commons/mxc-servicemanager
|
src/AbstractFactory/ReflectionBasedAbstractFactory.php
|
ReflectionBasedAbstractFactory.resolveParameterWithConfigService
|
private function resolveParameterWithConfigService(ContainerInterface $container, $requestedName)
{
/**
* @param ReflectionParameter $parameter
* @return mixed
* @throws ServiceNotFoundException If type-hinted parameter cannot be
* resolved to a service in the container.
*/
return function (ReflectionParameter $parameter) use ($container, $requestedName) {
if ($parameter->isArray() && $parameter->getName() === 'config') {
return $container->get('config');
}
return $this->resolveParameter($parameter, $container, $requestedName);
};
}
|
php
|
private function resolveParameterWithConfigService(ContainerInterface $container, $requestedName)
{
/**
* @param ReflectionParameter $parameter
* @return mixed
* @throws ServiceNotFoundException If type-hinted parameter cannot be
* resolved to a service in the container.
*/
return function (ReflectionParameter $parameter) use ($container, $requestedName) {
if ($parameter->isArray() && $parameter->getName() === 'config') {
return $container->get('config');
}
return $this->resolveParameter($parameter, $container, $requestedName);
};
}
|
[
"private",
"function",
"resolveParameterWithConfigService",
"(",
"ContainerInterface",
"$",
"container",
",",
"$",
"requestedName",
")",
"{",
"/**\n * @param ReflectionParameter $parameter\n * @return mixed\n * @throws ServiceNotFoundException If type-hinted parameter cannot be\n * resolved to a service in the container.\n */",
"return",
"function",
"(",
"ReflectionParameter",
"$",
"parameter",
")",
"use",
"(",
"$",
"container",
",",
"$",
"requestedName",
")",
"{",
"if",
"(",
"$",
"parameter",
"->",
"isArray",
"(",
")",
"&&",
"$",
"parameter",
"->",
"getName",
"(",
")",
"===",
"'config'",
")",
"{",
"return",
"$",
"container",
"->",
"get",
"(",
"'config'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolveParameter",
"(",
"$",
"parameter",
",",
"$",
"container",
",",
"$",
"requestedName",
")",
";",
"}",
";",
"}"
] |
Returns a callback for resolving a parameter to a value, including mapping 'config' arguments.
Unlike resolveParameter(), this version will detect `$config` array
arguments and have them return the 'config' service.
@param ContainerInterface $container
@param string $requestedName
@return callable
|
[
"Returns",
"a",
"callback",
"for",
"resolving",
"a",
"parameter",
"to",
"a",
"value",
"including",
"mapping",
"config",
"arguments",
"."
] |
547a9ed579b96d32cb54db5723510d75fcad71be
|
https://github.com/mxc-commons/mxc-servicemanager/blob/547a9ed579b96d32cb54db5723510d75fcad71be/src/AbstractFactory/ReflectionBasedAbstractFactory.php#L174-L188
|
237,113
|
mxc-commons/mxc-servicemanager
|
src/AbstractFactory/ReflectionBasedAbstractFactory.php
|
ReflectionBasedAbstractFactory.resolveParameter
|
private function resolveParameter(ReflectionParameter $parameter, ContainerInterface $container, $requestedName)
{
if ($parameter->isArray()) {
return [];
}
if (! $parameter->getClass()) {
if (! $parameter->isDefaultValueAvailable()) {
throw new ServiceNotFoundException(sprintf(
'Unable to create service "%s"; unable to resolve parameter "%s" '
. 'to a class, interface, or array type',
$requestedName,
$parameter->getName()
));
}
return $parameter->getDefaultValue();
}
$type = $parameter->getClass()->getName();
$type = isset($this->aliases[$type]) ? $this->aliases[$type] : $type;
if ($container->has($type)) {
return $container->get($type);
}
if (! $parameter->isOptional()) {
throw new ServiceNotFoundException(sprintf(
'Unable to create service "%s"; unable to resolve parameter "%s" using type hint "%s"',
$requestedName,
$parameter->getName(),
$type
));
}
// Type not available in container, but the value is optional and has a
// default defined.
return $parameter->getDefaultValue();
}
|
php
|
private function resolveParameter(ReflectionParameter $parameter, ContainerInterface $container, $requestedName)
{
if ($parameter->isArray()) {
return [];
}
if (! $parameter->getClass()) {
if (! $parameter->isDefaultValueAvailable()) {
throw new ServiceNotFoundException(sprintf(
'Unable to create service "%s"; unable to resolve parameter "%s" '
. 'to a class, interface, or array type',
$requestedName,
$parameter->getName()
));
}
return $parameter->getDefaultValue();
}
$type = $parameter->getClass()->getName();
$type = isset($this->aliases[$type]) ? $this->aliases[$type] : $type;
if ($container->has($type)) {
return $container->get($type);
}
if (! $parameter->isOptional()) {
throw new ServiceNotFoundException(sprintf(
'Unable to create service "%s"; unable to resolve parameter "%s" using type hint "%s"',
$requestedName,
$parameter->getName(),
$type
));
}
// Type not available in container, but the value is optional and has a
// default defined.
return $parameter->getDefaultValue();
}
|
[
"private",
"function",
"resolveParameter",
"(",
"ReflectionParameter",
"$",
"parameter",
",",
"ContainerInterface",
"$",
"container",
",",
"$",
"requestedName",
")",
"{",
"if",
"(",
"$",
"parameter",
"->",
"isArray",
"(",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"parameter",
"->",
"getClass",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"parameter",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"throw",
"new",
"ServiceNotFoundException",
"(",
"sprintf",
"(",
"'Unable to create service \"%s\"; unable to resolve parameter \"%s\" '",
".",
"'to a class, interface, or array type'",
",",
"$",
"requestedName",
",",
"$",
"parameter",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"$",
"type",
"=",
"$",
"parameter",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"type",
"=",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"type",
"]",
")",
"?",
"$",
"this",
"->",
"aliases",
"[",
"$",
"type",
"]",
":",
"$",
"type",
";",
"if",
"(",
"$",
"container",
"->",
"has",
"(",
"$",
"type",
")",
")",
"{",
"return",
"$",
"container",
"->",
"get",
"(",
"$",
"type",
")",
";",
"}",
"if",
"(",
"!",
"$",
"parameter",
"->",
"isOptional",
"(",
")",
")",
"{",
"throw",
"new",
"ServiceNotFoundException",
"(",
"sprintf",
"(",
"'Unable to create service \"%s\"; unable to resolve parameter \"%s\" using type hint \"%s\"'",
",",
"$",
"requestedName",
",",
"$",
"parameter",
"->",
"getName",
"(",
")",
",",
"$",
"type",
")",
")",
";",
"}",
"// Type not available in container, but the value is optional and has a",
"// default defined.",
"return",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
";",
"}"
] |
Logic common to all parameter resolution.
@param ReflectionParameter $parameter
@param ContainerInterface $container
@param string $requestedName
@return mixed
@throws ServiceNotFoundException If type-hinted parameter cannot be
resolved to a service in the container.
|
[
"Logic",
"common",
"to",
"all",
"parameter",
"resolution",
"."
] |
547a9ed579b96d32cb54db5723510d75fcad71be
|
https://github.com/mxc-commons/mxc-servicemanager/blob/547a9ed579b96d32cb54db5723510d75fcad71be/src/AbstractFactory/ReflectionBasedAbstractFactory.php#L200-L238
|
237,114
|
mandango/MandangoBundle
|
DependencyInjection/MandangoExtension.php
|
MandangoExtension.load
|
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('mandango.xml');
$processor = new Processor();
$configuration = new Configuration($container->getParameter('kernel.debug'));
$config = $processor->process($configuration->getConfigTree(), $configs);
// model_dir
if (isset($config['model_dir'])) {
$container->setParameter('mandango.model_dir', $config['model_dir']);
}
// logging
if (isset($config['logging']) && $config['logging']) {
$container->getDefinition('mandango')->addArgument(array(new Reference('mandango.logger'), 'logQuery'));
}
// default_connection
if (isset($config['default_connection'])) {
$container->getDefinition('mandango')->addMethodCall('setDefaultConnectionName', array($config['default_connection']));
}
// extra config classes dirs
$container->setParameter('mandango.extra_config_classes_dirs', $config['extra_config_classes_dirs']);
// connections
foreach ($config['connections'] as $name => $connection) {
$definition = new Definition($connection['class'], array(
$connection['server'],
$connection['database'],
$connection['options'],
));
$connectionDefinitionName = sprintf('mandango.%s_connection', $name);
$container->setDefinition($connectionDefinitionName, $definition);
// ->setConnection
$container->getDefinition('mandango')->addMethodCall('setConnection', array(
$name,
new Reference($connectionDefinitionName),
));
}
}
|
php
|
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('mandango.xml');
$processor = new Processor();
$configuration = new Configuration($container->getParameter('kernel.debug'));
$config = $processor->process($configuration->getConfigTree(), $configs);
// model_dir
if (isset($config['model_dir'])) {
$container->setParameter('mandango.model_dir', $config['model_dir']);
}
// logging
if (isset($config['logging']) && $config['logging']) {
$container->getDefinition('mandango')->addArgument(array(new Reference('mandango.logger'), 'logQuery'));
}
// default_connection
if (isset($config['default_connection'])) {
$container->getDefinition('mandango')->addMethodCall('setDefaultConnectionName', array($config['default_connection']));
}
// extra config classes dirs
$container->setParameter('mandango.extra_config_classes_dirs', $config['extra_config_classes_dirs']);
// connections
foreach ($config['connections'] as $name => $connection) {
$definition = new Definition($connection['class'], array(
$connection['server'],
$connection['database'],
$connection['options'],
));
$connectionDefinitionName = sprintf('mandango.%s_connection', $name);
$container->setDefinition($connectionDefinitionName, $definition);
// ->setConnection
$container->getDefinition('mandango')->addMethodCall('setConnection', array(
$name,
new Reference($connectionDefinitionName),
));
}
}
|
[
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"loader",
"=",
"new",
"XmlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'mandango.xml'",
")",
";",
"$",
"processor",
"=",
"new",
"Processor",
"(",
")",
";",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.debug'",
")",
")",
";",
"$",
"config",
"=",
"$",
"processor",
"->",
"process",
"(",
"$",
"configuration",
"->",
"getConfigTree",
"(",
")",
",",
"$",
"configs",
")",
";",
"// model_dir",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'model_dir'",
"]",
")",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"'mandango.model_dir'",
",",
"$",
"config",
"[",
"'model_dir'",
"]",
")",
";",
"}",
"// logging",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'logging'",
"]",
")",
"&&",
"$",
"config",
"[",
"'logging'",
"]",
")",
"{",
"$",
"container",
"->",
"getDefinition",
"(",
"'mandango'",
")",
"->",
"addArgument",
"(",
"array",
"(",
"new",
"Reference",
"(",
"'mandango.logger'",
")",
",",
"'logQuery'",
")",
")",
";",
"}",
"// default_connection",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'default_connection'",
"]",
")",
")",
"{",
"$",
"container",
"->",
"getDefinition",
"(",
"'mandango'",
")",
"->",
"addMethodCall",
"(",
"'setDefaultConnectionName'",
",",
"array",
"(",
"$",
"config",
"[",
"'default_connection'",
"]",
")",
")",
";",
"}",
"// extra config classes dirs",
"$",
"container",
"->",
"setParameter",
"(",
"'mandango.extra_config_classes_dirs'",
",",
"$",
"config",
"[",
"'extra_config_classes_dirs'",
"]",
")",
";",
"// connections",
"foreach",
"(",
"$",
"config",
"[",
"'connections'",
"]",
"as",
"$",
"name",
"=>",
"$",
"connection",
")",
"{",
"$",
"definition",
"=",
"new",
"Definition",
"(",
"$",
"connection",
"[",
"'class'",
"]",
",",
"array",
"(",
"$",
"connection",
"[",
"'server'",
"]",
",",
"$",
"connection",
"[",
"'database'",
"]",
",",
"$",
"connection",
"[",
"'options'",
"]",
",",
")",
")",
";",
"$",
"connectionDefinitionName",
"=",
"sprintf",
"(",
"'mandango.%s_connection'",
",",
"$",
"name",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"$",
"connectionDefinitionName",
",",
"$",
"definition",
")",
";",
"// ->setConnection",
"$",
"container",
"->",
"getDefinition",
"(",
"'mandango'",
")",
"->",
"addMethodCall",
"(",
"'setConnection'",
",",
"array",
"(",
"$",
"name",
",",
"new",
"Reference",
"(",
"$",
"connectionDefinitionName",
")",
",",
")",
")",
";",
"}",
"}"
] |
Responds to the "mandango" configuration parameter.
@param array $configs
@param ContainerBuilder $container
|
[
"Responds",
"to",
"the",
"mandango",
"configuration",
"parameter",
"."
] |
36e2ff4cc43989abbb3bd2f84cd7909c0f39d5b9
|
https://github.com/mandango/MandangoBundle/blob/36e2ff4cc43989abbb3bd2f84cd7909c0f39d5b9/DependencyInjection/MandangoExtension.php#L35-L79
|
237,115
|
tekkla/core-html
|
Core/Html/FormDesigner/FormElement.php
|
FormElement.&
|
public function &setContent($content)
{
// Set element type by analyzing the element
switch (true) {
case ($content instanceof FormGroup):
$this->type = 'group';
break;
case ($content instanceof ControlsCollectionInterface):
$this->type = 'collection';
break;
case ($content instanceof AbstractForm):
$this->type = 'control';
break;
case ($content instanceof AbstractHtml):
$this->type = 'factory';
break;
default:
$this->type = 'html';
}
$this->content = $content;
return $content;
}
|
php
|
public function &setContent($content)
{
// Set element type by analyzing the element
switch (true) {
case ($content instanceof FormGroup):
$this->type = 'group';
break;
case ($content instanceof ControlsCollectionInterface):
$this->type = 'collection';
break;
case ($content instanceof AbstractForm):
$this->type = 'control';
break;
case ($content instanceof AbstractHtml):
$this->type = 'factory';
break;
default:
$this->type = 'html';
}
$this->content = $content;
return $content;
}
|
[
"public",
"function",
"&",
"setContent",
"(",
"$",
"content",
")",
"{",
"// Set element type by analyzing the element",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"$",
"content",
"instanceof",
"FormGroup",
")",
":",
"$",
"this",
"->",
"type",
"=",
"'group'",
";",
"break",
";",
"case",
"(",
"$",
"content",
"instanceof",
"ControlsCollectionInterface",
")",
":",
"$",
"this",
"->",
"type",
"=",
"'collection'",
";",
"break",
";",
"case",
"(",
"$",
"content",
"instanceof",
"AbstractForm",
")",
":",
"$",
"this",
"->",
"type",
"=",
"'control'",
";",
"break",
";",
"case",
"(",
"$",
"content",
"instanceof",
"AbstractHtml",
")",
":",
"$",
"this",
"->",
"type",
"=",
"'factory'",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"type",
"=",
"'html'",
";",
"}",
"$",
"this",
"->",
"content",
"=",
"$",
"content",
";",
"return",
"$",
"content",
";",
"}"
] |
Sets the element.
@param sting|AbstractForm|AbstractHtml $element
@return Ambigous <\Core\Html\AbstractForm, \Core\Html\AbstractHtml, \Core\Html\FormDesigner\FormGroup>
|
[
"Sets",
"the",
"element",
"."
] |
00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3
|
https://github.com/tekkla/core-html/blob/00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3/Core/Html/FormDesigner/FormElement.php#L75-L103
|
237,116
|
atelierspierrot/library
|
src/Library/HttpFundamental/Response.php
|
Response.download
|
public function download($file = null, $type = null, $file_name = null)
{
if (!empty($file) && @file_exists($file)) {
if (is_null($file_name)) {
$file_name_parts = explode('/', $file);
$file_name = end( $file_name_parts );
}
$this->addHeader('Content-disposition', 'attachment; filename='.$file_name);
$this->addHeader('Content-Type', 'application/force-download');
$this->addHeader('Content-Transfer-Encoding', $type);
$this->addHeader('Content-Length', filesize($file));
$this->addHeader('Pragma', 'no-cache');
$this->addHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0, public');
$this->addHeader('Expires', '0');
$this->renderHeaders();
readfile( $file );
exit;
}
return;
}
|
php
|
public function download($file = null, $type = null, $file_name = null)
{
if (!empty($file) && @file_exists($file)) {
if (is_null($file_name)) {
$file_name_parts = explode('/', $file);
$file_name = end( $file_name_parts );
}
$this->addHeader('Content-disposition', 'attachment; filename='.$file_name);
$this->addHeader('Content-Type', 'application/force-download');
$this->addHeader('Content-Transfer-Encoding', $type);
$this->addHeader('Content-Length', filesize($file));
$this->addHeader('Pragma', 'no-cache');
$this->addHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0, public');
$this->addHeader('Expires', '0');
$this->renderHeaders();
readfile( $file );
exit;
}
return;
}
|
[
"public",
"function",
"download",
"(",
"$",
"file",
"=",
"null",
",",
"$",
"type",
"=",
"null",
",",
"$",
"file_name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"@",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"file_name",
")",
")",
"{",
"$",
"file_name_parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"file",
")",
";",
"$",
"file_name",
"=",
"end",
"(",
"$",
"file_name_parts",
")",
";",
"}",
"$",
"this",
"->",
"addHeader",
"(",
"'Content-disposition'",
",",
"'attachment; filename='",
".",
"$",
"file_name",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"'Content-Type'",
",",
"'application/force-download'",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"'Content-Transfer-Encoding'",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"'Content-Length'",
",",
"filesize",
"(",
"$",
"file",
")",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"'Pragma'",
",",
"'no-cache'",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"'Cache-Control'",
",",
"'must-revalidate, post-check=0, pre-check=0, public'",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"'Expires'",
",",
"'0'",
")",
";",
"$",
"this",
"->",
"renderHeaders",
"(",
")",
";",
"readfile",
"(",
"$",
"file",
")",
";",
"exit",
";",
"}",
"return",
";",
"}"
] |
Force client to download a file
@param null $file
@param null $type
@param null $file_name
|
[
"Force",
"client",
"to",
"download",
"a",
"file"
] |
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
|
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/HttpFundamental/Response.php#L360-L379
|
237,117
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.UserModel_BeforeDeleteUser_Handler
|
public function UserModel_BeforeDeleteUser_Handler($Sender) {
$UserID = GetValue('UserID', $Sender->EventArguments);
$Options = GetValue('Options', $Sender->EventArguments, array());
$Options = is_array($Options) ? $Options : array();
$Content =& $Sender->EventArguments['Content'];
$this->DeleteUserData($UserID, $Options, $Content);
}
|
php
|
public function UserModel_BeforeDeleteUser_Handler($Sender) {
$UserID = GetValue('UserID', $Sender->EventArguments);
$Options = GetValue('Options', $Sender->EventArguments, array());
$Options = is_array($Options) ? $Options : array();
$Content =& $Sender->EventArguments['Content'];
$this->DeleteUserData($UserID, $Options, $Content);
}
|
[
"public",
"function",
"UserModel_BeforeDeleteUser_Handler",
"(",
"$",
"Sender",
")",
"{",
"$",
"UserID",
"=",
"GetValue",
"(",
"'UserID'",
",",
"$",
"Sender",
"->",
"EventArguments",
")",
";",
"$",
"Options",
"=",
"GetValue",
"(",
"'Options'",
",",
"$",
"Sender",
"->",
"EventArguments",
",",
"array",
"(",
")",
")",
";",
"$",
"Options",
"=",
"is_array",
"(",
"$",
"Options",
")",
"?",
"$",
"Options",
":",
"array",
"(",
")",
";",
"$",
"Content",
"=",
"&",
"$",
"Sender",
"->",
"EventArguments",
"[",
"'Content'",
"]",
";",
"$",
"this",
"->",
"DeleteUserData",
"(",
"$",
"UserID",
",",
"$",
"Options",
",",
"$",
"Content",
")",
";",
"}"
] |
Remove Vanilla data when deleting a user.
@since 2.0.0
@package Vanilla
@param UserModel $Sender UserModel.
|
[
"Remove",
"Vanilla",
"data",
"when",
"deleting",
"a",
"user",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L158-L165
|
237,118
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.UserModel_GetCategoryViewPermission_Create
|
public function UserModel_GetCategoryViewPermission_Create($Sender) {
static $PermissionModel = NULL;
$UserID = ArrayValue(0, $Sender->EventArguments, '');
$CategoryID = ArrayValue(1, $Sender->EventArguments, '');
$Permission = GetValue(2, $Sender->EventArguments, 'Vanilla.Discussions.View');
if ($UserID && $CategoryID) {
if ($PermissionModel === NULL)
$PermissionModel = new PermissionModel();
$Category = CategoryModel::Categories($CategoryID);
if ($Category)
$PermissionCategoryID = $Category['PermissionCategoryID'];
else
$PermissionCategoryID = -1;
$Result = $PermissionModel->GetUserPermissions($UserID, $Permission, 'Category', 'PermissionCategoryID', 'CategoryID', $PermissionCategoryID);
return (GetValue($Permission, GetValue(0, $Result), FALSE)) ? TRUE : FALSE;
}
return FALSE;
}
|
php
|
public function UserModel_GetCategoryViewPermission_Create($Sender) {
static $PermissionModel = NULL;
$UserID = ArrayValue(0, $Sender->EventArguments, '');
$CategoryID = ArrayValue(1, $Sender->EventArguments, '');
$Permission = GetValue(2, $Sender->EventArguments, 'Vanilla.Discussions.View');
if ($UserID && $CategoryID) {
if ($PermissionModel === NULL)
$PermissionModel = new PermissionModel();
$Category = CategoryModel::Categories($CategoryID);
if ($Category)
$PermissionCategoryID = $Category['PermissionCategoryID'];
else
$PermissionCategoryID = -1;
$Result = $PermissionModel->GetUserPermissions($UserID, $Permission, 'Category', 'PermissionCategoryID', 'CategoryID', $PermissionCategoryID);
return (GetValue($Permission, GetValue(0, $Result), FALSE)) ? TRUE : FALSE;
}
return FALSE;
}
|
[
"public",
"function",
"UserModel_GetCategoryViewPermission_Create",
"(",
"$",
"Sender",
")",
"{",
"static",
"$",
"PermissionModel",
"=",
"NULL",
";",
"$",
"UserID",
"=",
"ArrayValue",
"(",
"0",
",",
"$",
"Sender",
"->",
"EventArguments",
",",
"''",
")",
";",
"$",
"CategoryID",
"=",
"ArrayValue",
"(",
"1",
",",
"$",
"Sender",
"->",
"EventArguments",
",",
"''",
")",
";",
"$",
"Permission",
"=",
"GetValue",
"(",
"2",
",",
"$",
"Sender",
"->",
"EventArguments",
",",
"'Vanilla.Discussions.View'",
")",
";",
"if",
"(",
"$",
"UserID",
"&&",
"$",
"CategoryID",
")",
"{",
"if",
"(",
"$",
"PermissionModel",
"===",
"NULL",
")",
"$",
"PermissionModel",
"=",
"new",
"PermissionModel",
"(",
")",
";",
"$",
"Category",
"=",
"CategoryModel",
"::",
"Categories",
"(",
"$",
"CategoryID",
")",
";",
"if",
"(",
"$",
"Category",
")",
"$",
"PermissionCategoryID",
"=",
"$",
"Category",
"[",
"'PermissionCategoryID'",
"]",
";",
"else",
"$",
"PermissionCategoryID",
"=",
"-",
"1",
";",
"$",
"Result",
"=",
"$",
"PermissionModel",
"->",
"GetUserPermissions",
"(",
"$",
"UserID",
",",
"$",
"Permission",
",",
"'Category'",
",",
"'PermissionCategoryID'",
",",
"'CategoryID'",
",",
"$",
"PermissionCategoryID",
")",
";",
"return",
"(",
"GetValue",
"(",
"$",
"Permission",
",",
"GetValue",
"(",
"0",
",",
"$",
"Result",
")",
",",
"FALSE",
")",
")",
"?",
"TRUE",
":",
"FALSE",
";",
"}",
"return",
"FALSE",
";",
"}"
] |
Check whether a user has access to view discussions in a particular category.
@since 2.0.18
@example $UserModel->GetCategoryViewPermission($UserID, $CategoryID).
@param $Sender UserModel.
@return bool Whether user has permission.
|
[
"Check",
"whether",
"a",
"user",
"has",
"access",
"to",
"view",
"discussions",
"in",
"a",
"particular",
"category",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L176-L197
|
237,119
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.Base_Render_Before
|
public function Base_Render_Before($Sender) {
$Session = Gdn::Session();
if ($Sender->Menu)
$Sender->Menu->AddLink('Discussions', T('Discussions'), '/discussions', FALSE, array('Standard' => TRUE));
}
|
php
|
public function Base_Render_Before($Sender) {
$Session = Gdn::Session();
if ($Sender->Menu)
$Sender->Menu->AddLink('Discussions', T('Discussions'), '/discussions', FALSE, array('Standard' => TRUE));
}
|
[
"public",
"function",
"Base_Render_Before",
"(",
"$",
"Sender",
")",
"{",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"if",
"(",
"$",
"Sender",
"->",
"Menu",
")",
"$",
"Sender",
"->",
"Menu",
"->",
"AddLink",
"(",
"'Discussions'",
",",
"T",
"(",
"'Discussions'",
")",
",",
"'/discussions'",
",",
"FALSE",
",",
"array",
"(",
"'Standard'",
"=>",
"TRUE",
")",
")",
";",
"}"
] |
Adds 'Discussion' item to menu.
'Base_Render_Before' will trigger before every pageload across apps.
If you abuse this hook, Tim with throw a Coke can at your head.
@since 2.0.0
@package Vanilla
@param object $Sender DashboardController.
|
[
"Adds",
"Discussion",
"item",
"to",
"menu",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L210-L214
|
237,120
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.ProfileController_AddProfileTabs_Handler
|
public function ProfileController_AddProfileTabs_Handler($Sender) {
if (is_object($Sender->User) && $Sender->User->UserID > 0) {
$UserID = $Sender->User->UserID;
// Add the discussion tab
$DiscussionsLabel = Sprite('SpDiscussions').' '.T('Discussions');
$CommentsLabel = Sprite('SpComments').' '.T('Comments');
if (C('Vanilla.Profile.ShowCounts', TRUE)) {
$DiscussionsLabel .= '<span class="Aside">'.CountString(GetValueR('User.CountDiscussions', $Sender, NULL), "/profile/count/discussions?userid=$UserID").'</span>';
$CommentsLabel .= '<span class="Aside">'.CountString(GetValueR('User.CountComments', $Sender, NULL), "/profile/count/comments?userid=$UserID").'</span>';
}
$Sender->AddProfileTab(T('Discussions'), 'profile/discussions/'.$Sender->User->UserID.'/'.rawurlencode($Sender->User->Name), 'Discussions', $DiscussionsLabel);
$Sender->AddProfileTab(T('Comments'), 'profile/comments/'.$Sender->User->UserID.'/'.rawurlencode($Sender->User->Name), 'Comments', $CommentsLabel);
// Add the discussion tab's CSS and Javascript.
$Sender->AddJsFile('jquery.gardenmorepager.js');
$Sender->AddJsFile('discussions.js');
}
}
|
php
|
public function ProfileController_AddProfileTabs_Handler($Sender) {
if (is_object($Sender->User) && $Sender->User->UserID > 0) {
$UserID = $Sender->User->UserID;
// Add the discussion tab
$DiscussionsLabel = Sprite('SpDiscussions').' '.T('Discussions');
$CommentsLabel = Sprite('SpComments').' '.T('Comments');
if (C('Vanilla.Profile.ShowCounts', TRUE)) {
$DiscussionsLabel .= '<span class="Aside">'.CountString(GetValueR('User.CountDiscussions', $Sender, NULL), "/profile/count/discussions?userid=$UserID").'</span>';
$CommentsLabel .= '<span class="Aside">'.CountString(GetValueR('User.CountComments', $Sender, NULL), "/profile/count/comments?userid=$UserID").'</span>';
}
$Sender->AddProfileTab(T('Discussions'), 'profile/discussions/'.$Sender->User->UserID.'/'.rawurlencode($Sender->User->Name), 'Discussions', $DiscussionsLabel);
$Sender->AddProfileTab(T('Comments'), 'profile/comments/'.$Sender->User->UserID.'/'.rawurlencode($Sender->User->Name), 'Comments', $CommentsLabel);
// Add the discussion tab's CSS and Javascript.
$Sender->AddJsFile('jquery.gardenmorepager.js');
$Sender->AddJsFile('discussions.js');
}
}
|
[
"public",
"function",
"ProfileController_AddProfileTabs_Handler",
"(",
"$",
"Sender",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"Sender",
"->",
"User",
")",
"&&",
"$",
"Sender",
"->",
"User",
"->",
"UserID",
">",
"0",
")",
"{",
"$",
"UserID",
"=",
"$",
"Sender",
"->",
"User",
"->",
"UserID",
";",
"// Add the discussion tab",
"$",
"DiscussionsLabel",
"=",
"Sprite",
"(",
"'SpDiscussions'",
")",
".",
"' '",
".",
"T",
"(",
"'Discussions'",
")",
";",
"$",
"CommentsLabel",
"=",
"Sprite",
"(",
"'SpComments'",
")",
".",
"' '",
".",
"T",
"(",
"'Comments'",
")",
";",
"if",
"(",
"C",
"(",
"'Vanilla.Profile.ShowCounts'",
",",
"TRUE",
")",
")",
"{",
"$",
"DiscussionsLabel",
".=",
"'<span class=\"Aside\">'",
".",
"CountString",
"(",
"GetValueR",
"(",
"'User.CountDiscussions'",
",",
"$",
"Sender",
",",
"NULL",
")",
",",
"\"/profile/count/discussions?userid=$UserID\"",
")",
".",
"'</span>'",
";",
"$",
"CommentsLabel",
".=",
"'<span class=\"Aside\">'",
".",
"CountString",
"(",
"GetValueR",
"(",
"'User.CountComments'",
",",
"$",
"Sender",
",",
"NULL",
")",
",",
"\"/profile/count/comments?userid=$UserID\"",
")",
".",
"'</span>'",
";",
"}",
"$",
"Sender",
"->",
"AddProfileTab",
"(",
"T",
"(",
"'Discussions'",
")",
",",
"'profile/discussions/'",
".",
"$",
"Sender",
"->",
"User",
"->",
"UserID",
".",
"'/'",
".",
"rawurlencode",
"(",
"$",
"Sender",
"->",
"User",
"->",
"Name",
")",
",",
"'Discussions'",
",",
"$",
"DiscussionsLabel",
")",
";",
"$",
"Sender",
"->",
"AddProfileTab",
"(",
"T",
"(",
"'Comments'",
")",
",",
"'profile/comments/'",
".",
"$",
"Sender",
"->",
"User",
"->",
"UserID",
".",
"'/'",
".",
"rawurlencode",
"(",
"$",
"Sender",
"->",
"User",
"->",
"Name",
")",
",",
"'Comments'",
",",
"$",
"CommentsLabel",
")",
";",
"// Add the discussion tab's CSS and Javascript.",
"$",
"Sender",
"->",
"AddJsFile",
"(",
"'jquery.gardenmorepager.js'",
")",
";",
"$",
"Sender",
"->",
"AddJsFile",
"(",
"'discussions.js'",
")",
";",
"}",
"}"
] |
Adds 'Discussions' tab to profiles and adds CSS & JS files to their head.
@since 2.0.0
@package Vanilla
@param object $Sender ProfileController.
|
[
"Adds",
"Discussions",
"tab",
"to",
"profiles",
"and",
"adds",
"CSS",
"&",
"JS",
"files",
"to",
"their",
"head",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L224-L240
|
237,121
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.ProfileController_AfterPreferencesDefined_Handler
|
public function ProfileController_AfterPreferencesDefined_Handler($Sender) {
$Sender->Preferences['Notifications']['Email.DiscussionComment'] = T('Notify me when people comment on my discussions.');
$Sender->Preferences['Notifications']['Email.BookmarkComment'] = T('Notify me when people comment on my bookmarked discussions.');
$Sender->Preferences['Notifications']['Email.Mention'] = T('Notify me when people mention me.');
$Sender->Preferences['Notifications']['Popup.DiscussionComment'] = T('Notify me when people comment on my discussions.');
$Sender->Preferences['Notifications']['Popup.BookmarkComment'] = T('Notify me when people comment on my bookmarked discussions.');
$Sender->Preferences['Notifications']['Popup.Mention'] = T('Notify me when people mention me.');
// if (Gdn::Session()->CheckPermission('Garden.AdvancedNotifications.Allow')) {
// $Sender->Preferences['Notifications']['Email.NewDiscussion'] = array(T('Notify me when people start new discussions.'), 'Meta');
// $Sender->Preferences['Notifications']['Email.NewComment'] = array(T('Notify me when people comment on a discussion.'), 'Meta');
//// $Sender->Preferences['Notifications']['Popup.NewDiscussion'] = T('Notify me when people start new discussions.');
// }
if (Gdn::Session()->CheckPermission('Garden.AdvancedNotifications.Allow')) {
$PostBack = $Sender->Form->IsPostBack();
$Set = array();
// Add the category definitions to for the view to pick up.
$DoHeadings = C('Vanilla.Categories.DoHeadings');
// Grab all of the categories.
$Categories = array();
$Prefixes = array('Email.NewDiscussion', 'Popup.NewDiscussion', 'Email.NewComment', 'Popup.NewComment');
foreach (CategoryModel::Categories() as $Category) {
if (!$Category['PermsDiscussionsView'] || $Category['Depth'] <= 0 || $Category['Depth'] > 2 || $Category['Archived'])
continue;
$Category['Heading'] = ($DoHeadings && $Category['Depth'] <= 1);
$Categories[] = $Category;
if ($PostBack) {
foreach ($Prefixes as $Prefix) {
$FieldName = "$Prefix.{$Category['CategoryID']}";
$Value = $Sender->Form->GetFormValue($FieldName, NULL);
if (!$Value)
$Value = NULL;
$Set[$FieldName] = $Value;
}
}
}
$Sender->SetData('CategoryNotifications', $Categories);
if ($PostBack) {
UserModel::SetMeta($Sender->User->UserID, $Set, 'Preferences.');
}
}
}
|
php
|
public function ProfileController_AfterPreferencesDefined_Handler($Sender) {
$Sender->Preferences['Notifications']['Email.DiscussionComment'] = T('Notify me when people comment on my discussions.');
$Sender->Preferences['Notifications']['Email.BookmarkComment'] = T('Notify me when people comment on my bookmarked discussions.');
$Sender->Preferences['Notifications']['Email.Mention'] = T('Notify me when people mention me.');
$Sender->Preferences['Notifications']['Popup.DiscussionComment'] = T('Notify me when people comment on my discussions.');
$Sender->Preferences['Notifications']['Popup.BookmarkComment'] = T('Notify me when people comment on my bookmarked discussions.');
$Sender->Preferences['Notifications']['Popup.Mention'] = T('Notify me when people mention me.');
// if (Gdn::Session()->CheckPermission('Garden.AdvancedNotifications.Allow')) {
// $Sender->Preferences['Notifications']['Email.NewDiscussion'] = array(T('Notify me when people start new discussions.'), 'Meta');
// $Sender->Preferences['Notifications']['Email.NewComment'] = array(T('Notify me when people comment on a discussion.'), 'Meta');
//// $Sender->Preferences['Notifications']['Popup.NewDiscussion'] = T('Notify me when people start new discussions.');
// }
if (Gdn::Session()->CheckPermission('Garden.AdvancedNotifications.Allow')) {
$PostBack = $Sender->Form->IsPostBack();
$Set = array();
// Add the category definitions to for the view to pick up.
$DoHeadings = C('Vanilla.Categories.DoHeadings');
// Grab all of the categories.
$Categories = array();
$Prefixes = array('Email.NewDiscussion', 'Popup.NewDiscussion', 'Email.NewComment', 'Popup.NewComment');
foreach (CategoryModel::Categories() as $Category) {
if (!$Category['PermsDiscussionsView'] || $Category['Depth'] <= 0 || $Category['Depth'] > 2 || $Category['Archived'])
continue;
$Category['Heading'] = ($DoHeadings && $Category['Depth'] <= 1);
$Categories[] = $Category;
if ($PostBack) {
foreach ($Prefixes as $Prefix) {
$FieldName = "$Prefix.{$Category['CategoryID']}";
$Value = $Sender->Form->GetFormValue($FieldName, NULL);
if (!$Value)
$Value = NULL;
$Set[$FieldName] = $Value;
}
}
}
$Sender->SetData('CategoryNotifications', $Categories);
if ($PostBack) {
UserModel::SetMeta($Sender->User->UserID, $Set, 'Preferences.');
}
}
}
|
[
"public",
"function",
"ProfileController_AfterPreferencesDefined_Handler",
"(",
"$",
"Sender",
")",
"{",
"$",
"Sender",
"->",
"Preferences",
"[",
"'Notifications'",
"]",
"[",
"'Email.DiscussionComment'",
"]",
"=",
"T",
"(",
"'Notify me when people comment on my discussions.'",
")",
";",
"$",
"Sender",
"->",
"Preferences",
"[",
"'Notifications'",
"]",
"[",
"'Email.BookmarkComment'",
"]",
"=",
"T",
"(",
"'Notify me when people comment on my bookmarked discussions.'",
")",
";",
"$",
"Sender",
"->",
"Preferences",
"[",
"'Notifications'",
"]",
"[",
"'Email.Mention'",
"]",
"=",
"T",
"(",
"'Notify me when people mention me.'",
")",
";",
"$",
"Sender",
"->",
"Preferences",
"[",
"'Notifications'",
"]",
"[",
"'Popup.DiscussionComment'",
"]",
"=",
"T",
"(",
"'Notify me when people comment on my discussions.'",
")",
";",
"$",
"Sender",
"->",
"Preferences",
"[",
"'Notifications'",
"]",
"[",
"'Popup.BookmarkComment'",
"]",
"=",
"T",
"(",
"'Notify me when people comment on my bookmarked discussions.'",
")",
";",
"$",
"Sender",
"->",
"Preferences",
"[",
"'Notifications'",
"]",
"[",
"'Popup.Mention'",
"]",
"=",
"T",
"(",
"'Notify me when people mention me.'",
")",
";",
"// if (Gdn::Session()->CheckPermission('Garden.AdvancedNotifications.Allow')) {",
"// $Sender->Preferences['Notifications']['Email.NewDiscussion'] = array(T('Notify me when people start new discussions.'), 'Meta');",
"// $Sender->Preferences['Notifications']['Email.NewComment'] = array(T('Notify me when people comment on a discussion.'), 'Meta');",
"//// $Sender->Preferences['Notifications']['Popup.NewDiscussion'] = T('Notify me when people start new discussions.');",
"// }",
"if",
"(",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"CheckPermission",
"(",
"'Garden.AdvancedNotifications.Allow'",
")",
")",
"{",
"$",
"PostBack",
"=",
"$",
"Sender",
"->",
"Form",
"->",
"IsPostBack",
"(",
")",
";",
"$",
"Set",
"=",
"array",
"(",
")",
";",
"// Add the category definitions to for the view to pick up.",
"$",
"DoHeadings",
"=",
"C",
"(",
"'Vanilla.Categories.DoHeadings'",
")",
";",
"// Grab all of the categories.",
"$",
"Categories",
"=",
"array",
"(",
")",
";",
"$",
"Prefixes",
"=",
"array",
"(",
"'Email.NewDiscussion'",
",",
"'Popup.NewDiscussion'",
",",
"'Email.NewComment'",
",",
"'Popup.NewComment'",
")",
";",
"foreach",
"(",
"CategoryModel",
"::",
"Categories",
"(",
")",
"as",
"$",
"Category",
")",
"{",
"if",
"(",
"!",
"$",
"Category",
"[",
"'PermsDiscussionsView'",
"]",
"||",
"$",
"Category",
"[",
"'Depth'",
"]",
"<=",
"0",
"||",
"$",
"Category",
"[",
"'Depth'",
"]",
">",
"2",
"||",
"$",
"Category",
"[",
"'Archived'",
"]",
")",
"continue",
";",
"$",
"Category",
"[",
"'Heading'",
"]",
"=",
"(",
"$",
"DoHeadings",
"&&",
"$",
"Category",
"[",
"'Depth'",
"]",
"<=",
"1",
")",
";",
"$",
"Categories",
"[",
"]",
"=",
"$",
"Category",
";",
"if",
"(",
"$",
"PostBack",
")",
"{",
"foreach",
"(",
"$",
"Prefixes",
"as",
"$",
"Prefix",
")",
"{",
"$",
"FieldName",
"=",
"\"$Prefix.{$Category['CategoryID']}\"",
";",
"$",
"Value",
"=",
"$",
"Sender",
"->",
"Form",
"->",
"GetFormValue",
"(",
"$",
"FieldName",
",",
"NULL",
")",
";",
"if",
"(",
"!",
"$",
"Value",
")",
"$",
"Value",
"=",
"NULL",
";",
"$",
"Set",
"[",
"$",
"FieldName",
"]",
"=",
"$",
"Value",
";",
"}",
"}",
"}",
"$",
"Sender",
"->",
"SetData",
"(",
"'CategoryNotifications'",
",",
"$",
"Categories",
")",
";",
"if",
"(",
"$",
"PostBack",
")",
"{",
"UserModel",
"::",
"SetMeta",
"(",
"$",
"Sender",
"->",
"User",
"->",
"UserID",
",",
"$",
"Set",
",",
"'Preferences.'",
")",
";",
"}",
"}",
"}"
] |
Adds email notification options to profiles.
@since 2.0.0
@package Vanilla
@param ProfileController $Sender
|
[
"Adds",
"email",
"notification",
"options",
"to",
"profiles",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L250-L297
|
237,122
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.ProfileController_Comments_Create
|
public function ProfileController_Comments_Create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '') {
$Sender->EditMode(FALSE);
$View = $Sender->View;
// Tell the ProfileController what tab to load
$Sender->GetUserInfo($UserReference, $Username, $UserID);
$Sender->_SetBreadcrumbs(T('Comments'), UserUrl($Sender->User, '', 'comments'));
$Sender->SetTabView('Comments', 'profile', 'Discussion', 'Vanilla');
$PageSize = Gdn::Config('Vanilla.Discussions.PerPage', 30);
list($Offset, $Limit) = OffsetLimit($Page, $PageSize);
$CommentModel = new CommentModel();
$Comments = $CommentModel->GetByUser2($Sender->User->UserID, $Limit, $Offset, $Sender->Request->Get('lid'));
$TotalRecords = $Offset + $CommentModel->LastCommentCount + 1;
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
$Sender->Pager->MoreCode = 'More Comments';
$Sender->Pager->LessCode = 'Newer Comments';
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure(
$Offset,
$Limit,
$TotalRecords,
UserUrl($Sender->User, '', 'comments').'?page={Page}' //?lid='.$CommentModel->LastCommentID
);
// Deliver JSON data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'profilecomments';
}
$Sender->SetData('Comments', $Comments);
// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
$Sender->HandlerType = HANDLER_TYPE_NORMAL;
// Do not show discussion options
$Sender->ShowOptions = FALSE;
if ($Sender->Head) {
$Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
}
// Render the ProfileController
$Sender->Render();
}
|
php
|
public function ProfileController_Comments_Create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '') {
$Sender->EditMode(FALSE);
$View = $Sender->View;
// Tell the ProfileController what tab to load
$Sender->GetUserInfo($UserReference, $Username, $UserID);
$Sender->_SetBreadcrumbs(T('Comments'), UserUrl($Sender->User, '', 'comments'));
$Sender->SetTabView('Comments', 'profile', 'Discussion', 'Vanilla');
$PageSize = Gdn::Config('Vanilla.Discussions.PerPage', 30);
list($Offset, $Limit) = OffsetLimit($Page, $PageSize);
$CommentModel = new CommentModel();
$Comments = $CommentModel->GetByUser2($Sender->User->UserID, $Limit, $Offset, $Sender->Request->Get('lid'));
$TotalRecords = $Offset + $CommentModel->LastCommentCount + 1;
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
$Sender->Pager->MoreCode = 'More Comments';
$Sender->Pager->LessCode = 'Newer Comments';
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure(
$Offset,
$Limit,
$TotalRecords,
UserUrl($Sender->User, '', 'comments').'?page={Page}' //?lid='.$CommentModel->LastCommentID
);
// Deliver JSON data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'profilecomments';
}
$Sender->SetData('Comments', $Comments);
// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
$Sender->HandlerType = HANDLER_TYPE_NORMAL;
// Do not show discussion options
$Sender->ShowOptions = FALSE;
if ($Sender->Head) {
$Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
}
// Render the ProfileController
$Sender->Render();
}
|
[
"public",
"function",
"ProfileController_Comments_Create",
"(",
"$",
"Sender",
",",
"$",
"UserReference",
"=",
"''",
",",
"$",
"Username",
"=",
"''",
",",
"$",
"Page",
"=",
"''",
",",
"$",
"UserID",
"=",
"''",
")",
"{",
"$",
"Sender",
"->",
"EditMode",
"(",
"FALSE",
")",
";",
"$",
"View",
"=",
"$",
"Sender",
"->",
"View",
";",
"// Tell the ProfileController what tab to load",
"$",
"Sender",
"->",
"GetUserInfo",
"(",
"$",
"UserReference",
",",
"$",
"Username",
",",
"$",
"UserID",
")",
";",
"$",
"Sender",
"->",
"_SetBreadcrumbs",
"(",
"T",
"(",
"'Comments'",
")",
",",
"UserUrl",
"(",
"$",
"Sender",
"->",
"User",
",",
"''",
",",
"'comments'",
")",
")",
";",
"$",
"Sender",
"->",
"SetTabView",
"(",
"'Comments'",
",",
"'profile'",
",",
"'Discussion'",
",",
"'Vanilla'",
")",
";",
"$",
"PageSize",
"=",
"Gdn",
"::",
"Config",
"(",
"'Vanilla.Discussions.PerPage'",
",",
"30",
")",
";",
"list",
"(",
"$",
"Offset",
",",
"$",
"Limit",
")",
"=",
"OffsetLimit",
"(",
"$",
"Page",
",",
"$",
"PageSize",
")",
";",
"$",
"CommentModel",
"=",
"new",
"CommentModel",
"(",
")",
";",
"$",
"Comments",
"=",
"$",
"CommentModel",
"->",
"GetByUser2",
"(",
"$",
"Sender",
"->",
"User",
"->",
"UserID",
",",
"$",
"Limit",
",",
"$",
"Offset",
",",
"$",
"Sender",
"->",
"Request",
"->",
"Get",
"(",
"'lid'",
")",
")",
";",
"$",
"TotalRecords",
"=",
"$",
"Offset",
"+",
"$",
"CommentModel",
"->",
"LastCommentCount",
"+",
"1",
";",
"// Build a pager",
"$",
"PagerFactory",
"=",
"new",
"Gdn_PagerFactory",
"(",
")",
";",
"$",
"Sender",
"->",
"Pager",
"=",
"$",
"PagerFactory",
"->",
"GetPager",
"(",
"'MorePager'",
",",
"$",
"Sender",
")",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"MoreCode",
"=",
"'More Comments'",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"LessCode",
"=",
"'Newer Comments'",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"ClientID",
"=",
"'Pager'",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"Configure",
"(",
"$",
"Offset",
",",
"$",
"Limit",
",",
"$",
"TotalRecords",
",",
"UserUrl",
"(",
"$",
"Sender",
"->",
"User",
",",
"''",
",",
"'comments'",
")",
".",
"'?page={Page}'",
"//?lid='.$CommentModel->LastCommentID",
")",
";",
"// Deliver JSON data if necessary",
"if",
"(",
"$",
"Sender",
"->",
"DeliveryType",
"(",
")",
"!=",
"DELIVERY_TYPE_ALL",
"&&",
"$",
"Offset",
">",
"0",
")",
"{",
"$",
"Sender",
"->",
"SetJson",
"(",
"'LessRow'",
",",
"$",
"Sender",
"->",
"Pager",
"->",
"ToString",
"(",
"'less'",
")",
")",
";",
"$",
"Sender",
"->",
"SetJson",
"(",
"'MoreRow'",
",",
"$",
"Sender",
"->",
"Pager",
"->",
"ToString",
"(",
"'more'",
")",
")",
";",
"$",
"Sender",
"->",
"View",
"=",
"'profilecomments'",
";",
"}",
"$",
"Sender",
"->",
"SetData",
"(",
"'Comments'",
",",
"$",
"Comments",
")",
";",
"// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views",
"$",
"Sender",
"->",
"HandlerType",
"=",
"HANDLER_TYPE_NORMAL",
";",
"// Do not show discussion options",
"$",
"Sender",
"->",
"ShowOptions",
"=",
"FALSE",
";",
"if",
"(",
"$",
"Sender",
"->",
"Head",
")",
"{",
"$",
"Sender",
"->",
"Head",
"->",
"AddTag",
"(",
"'meta'",
",",
"array",
"(",
"'name'",
"=>",
"'robots'",
",",
"'content'",
"=>",
"'noindex,noarchive'",
")",
")",
";",
"}",
"// Render the ProfileController",
"$",
"Sender",
"->",
"Render",
"(",
")",
";",
"}"
] |
Creates virtual 'Comments' method in ProfileController.
@since 2.0.0
@package Vanilla
@param ProfileController $Sender ProfileController.
|
[
"Creates",
"virtual",
"Comments",
"method",
"in",
"ProfileController",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L362-L410
|
237,123
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.ProfileController_Discussions_Create
|
public function ProfileController_Discussions_Create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '') {
$Sender->EditMode(FALSE);
// Tell the ProfileController what tab to load
$Sender->GetUserInfo($UserReference, $Username, $UserID);
$Sender->_SetBreadcrumbs(T('Discussions'), UserUrl($Sender->User, '', 'discussions'));
$Sender->SetTabView('Discussions', 'Profile', 'Discussions', 'Vanilla');
$Sender->CountCommentsPerPage = C('Vanilla.Comments.PerPage', 30);
list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
$DiscussionModel = new DiscussionModel();
$Discussions = $DiscussionModel->GetByUser($Sender->User->UserID, $Limit, $Offset);
$CountDiscussions = $Offset + $DiscussionModel->LastDiscussionCount + 1;
$Sender->DiscussionData = $Sender->SetData('Discussions', $Discussions);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
$Sender->Pager->MoreCode = 'More Discussions';
$Sender->Pager->LessCode = 'Newer Discussions';
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure(
$Offset,
$Limit,
$CountDiscussions,
UserUrl($Sender->User, '', 'discussions').'?page={Page}'
);
// Deliver JSON data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'discussions';
}
// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
$Sender->HandlerType = HANDLER_TYPE_NORMAL;
// Do not show discussion options
$Sender->ShowOptions = FALSE;
if ($Sender->Head) {
// These pages offer only duplicate content to search engines and are a bit slow.
$Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
}
// Render the ProfileController
$Sender->Render();
}
|
php
|
public function ProfileController_Discussions_Create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '') {
$Sender->EditMode(FALSE);
// Tell the ProfileController what tab to load
$Sender->GetUserInfo($UserReference, $Username, $UserID);
$Sender->_SetBreadcrumbs(T('Discussions'), UserUrl($Sender->User, '', 'discussions'));
$Sender->SetTabView('Discussions', 'Profile', 'Discussions', 'Vanilla');
$Sender->CountCommentsPerPage = C('Vanilla.Comments.PerPage', 30);
list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
$DiscussionModel = new DiscussionModel();
$Discussions = $DiscussionModel->GetByUser($Sender->User->UserID, $Limit, $Offset);
$CountDiscussions = $Offset + $DiscussionModel->LastDiscussionCount + 1;
$Sender->DiscussionData = $Sender->SetData('Discussions', $Discussions);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
$Sender->Pager->MoreCode = 'More Discussions';
$Sender->Pager->LessCode = 'Newer Discussions';
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure(
$Offset,
$Limit,
$CountDiscussions,
UserUrl($Sender->User, '', 'discussions').'?page={Page}'
);
// Deliver JSON data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'discussions';
}
// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
$Sender->HandlerType = HANDLER_TYPE_NORMAL;
// Do not show discussion options
$Sender->ShowOptions = FALSE;
if ($Sender->Head) {
// These pages offer only duplicate content to search engines and are a bit slow.
$Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
}
// Render the ProfileController
$Sender->Render();
}
|
[
"public",
"function",
"ProfileController_Discussions_Create",
"(",
"$",
"Sender",
",",
"$",
"UserReference",
"=",
"''",
",",
"$",
"Username",
"=",
"''",
",",
"$",
"Page",
"=",
"''",
",",
"$",
"UserID",
"=",
"''",
")",
"{",
"$",
"Sender",
"->",
"EditMode",
"(",
"FALSE",
")",
";",
"// Tell the ProfileController what tab to load",
"$",
"Sender",
"->",
"GetUserInfo",
"(",
"$",
"UserReference",
",",
"$",
"Username",
",",
"$",
"UserID",
")",
";",
"$",
"Sender",
"->",
"_SetBreadcrumbs",
"(",
"T",
"(",
"'Discussions'",
")",
",",
"UserUrl",
"(",
"$",
"Sender",
"->",
"User",
",",
"''",
",",
"'discussions'",
")",
")",
";",
"$",
"Sender",
"->",
"SetTabView",
"(",
"'Discussions'",
",",
"'Profile'",
",",
"'Discussions'",
",",
"'Vanilla'",
")",
";",
"$",
"Sender",
"->",
"CountCommentsPerPage",
"=",
"C",
"(",
"'Vanilla.Comments.PerPage'",
",",
"30",
")",
";",
"list",
"(",
"$",
"Offset",
",",
"$",
"Limit",
")",
"=",
"OffsetLimit",
"(",
"$",
"Page",
",",
"Gdn",
"::",
"Config",
"(",
"'Vanilla.Discussions.PerPage'",
",",
"30",
")",
")",
";",
"$",
"DiscussionModel",
"=",
"new",
"DiscussionModel",
"(",
")",
";",
"$",
"Discussions",
"=",
"$",
"DiscussionModel",
"->",
"GetByUser",
"(",
"$",
"Sender",
"->",
"User",
"->",
"UserID",
",",
"$",
"Limit",
",",
"$",
"Offset",
")",
";",
"$",
"CountDiscussions",
"=",
"$",
"Offset",
"+",
"$",
"DiscussionModel",
"->",
"LastDiscussionCount",
"+",
"1",
";",
"$",
"Sender",
"->",
"DiscussionData",
"=",
"$",
"Sender",
"->",
"SetData",
"(",
"'Discussions'",
",",
"$",
"Discussions",
")",
";",
"// Build a pager",
"$",
"PagerFactory",
"=",
"new",
"Gdn_PagerFactory",
"(",
")",
";",
"$",
"Sender",
"->",
"Pager",
"=",
"$",
"PagerFactory",
"->",
"GetPager",
"(",
"'MorePager'",
",",
"$",
"Sender",
")",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"MoreCode",
"=",
"'More Discussions'",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"LessCode",
"=",
"'Newer Discussions'",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"ClientID",
"=",
"'Pager'",
";",
"$",
"Sender",
"->",
"Pager",
"->",
"Configure",
"(",
"$",
"Offset",
",",
"$",
"Limit",
",",
"$",
"CountDiscussions",
",",
"UserUrl",
"(",
"$",
"Sender",
"->",
"User",
",",
"''",
",",
"'discussions'",
")",
".",
"'?page={Page}'",
")",
";",
"// Deliver JSON data if necessary",
"if",
"(",
"$",
"Sender",
"->",
"DeliveryType",
"(",
")",
"!=",
"DELIVERY_TYPE_ALL",
"&&",
"$",
"Offset",
">",
"0",
")",
"{",
"$",
"Sender",
"->",
"SetJson",
"(",
"'LessRow'",
",",
"$",
"Sender",
"->",
"Pager",
"->",
"ToString",
"(",
"'less'",
")",
")",
";",
"$",
"Sender",
"->",
"SetJson",
"(",
"'MoreRow'",
",",
"$",
"Sender",
"->",
"Pager",
"->",
"ToString",
"(",
"'more'",
")",
")",
";",
"$",
"Sender",
"->",
"View",
"=",
"'discussions'",
";",
"}",
"// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views",
"$",
"Sender",
"->",
"HandlerType",
"=",
"HANDLER_TYPE_NORMAL",
";",
"// Do not show discussion options",
"$",
"Sender",
"->",
"ShowOptions",
"=",
"FALSE",
";",
"if",
"(",
"$",
"Sender",
"->",
"Head",
")",
"{",
"// These pages offer only duplicate content to search engines and are a bit slow.",
"$",
"Sender",
"->",
"Head",
"->",
"AddTag",
"(",
"'meta'",
",",
"array",
"(",
"'name'",
"=>",
"'robots'",
",",
"'content'",
"=>",
"'noindex,noarchive'",
")",
")",
";",
"}",
"// Render the ProfileController",
"$",
"Sender",
"->",
"Render",
"(",
")",
";",
"}"
] |
Creates virtual 'Discussions' method in ProfileController.
@since 2.0.0
@package Vanilla
@param ProfileController $Sender ProfileController.
|
[
"Creates",
"virtual",
"Discussions",
"method",
"in",
"ProfileController",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L420-L469
|
237,124
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.Base_GetAppSettingsMenuItems_Handler
|
public function Base_GetAppSettingsMenuItems_Handler($Sender) {
$Menu = &$Sender->EventArguments['SideMenu'];
$Menu->AddLink('Moderation', T('Flood Control'), 'vanilla/settings/floodcontrol', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Categories'), 'vanilla/settings/managecategories', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Advanced'), 'vanilla/settings/advanced', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Blog Comments'), 'dashboard/embed/comments', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Embed Forum'), 'dashboard/embed/forum', 'Garden.Settings.Manage');
}
|
php
|
public function Base_GetAppSettingsMenuItems_Handler($Sender) {
$Menu = &$Sender->EventArguments['SideMenu'];
$Menu->AddLink('Moderation', T('Flood Control'), 'vanilla/settings/floodcontrol', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Categories'), 'vanilla/settings/managecategories', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Advanced'), 'vanilla/settings/advanced', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Blog Comments'), 'dashboard/embed/comments', 'Garden.Settings.Manage');
$Menu->AddLink('Forum', T('Embed Forum'), 'dashboard/embed/forum', 'Garden.Settings.Manage');
}
|
[
"public",
"function",
"Base_GetAppSettingsMenuItems_Handler",
"(",
"$",
"Sender",
")",
"{",
"$",
"Menu",
"=",
"&",
"$",
"Sender",
"->",
"EventArguments",
"[",
"'SideMenu'",
"]",
";",
"$",
"Menu",
"->",
"AddLink",
"(",
"'Moderation'",
",",
"T",
"(",
"'Flood Control'",
")",
",",
"'vanilla/settings/floodcontrol'",
",",
"'Garden.Settings.Manage'",
")",
";",
"$",
"Menu",
"->",
"AddLink",
"(",
"'Forum'",
",",
"T",
"(",
"'Categories'",
")",
",",
"'vanilla/settings/managecategories'",
",",
"'Garden.Settings.Manage'",
")",
";",
"$",
"Menu",
"->",
"AddLink",
"(",
"'Forum'",
",",
"T",
"(",
"'Advanced'",
")",
",",
"'vanilla/settings/advanced'",
",",
"'Garden.Settings.Manage'",
")",
";",
"$",
"Menu",
"->",
"AddLink",
"(",
"'Forum'",
",",
"T",
"(",
"'Blog Comments'",
")",
",",
"'dashboard/embed/comments'",
",",
"'Garden.Settings.Manage'",
")",
";",
"$",
"Menu",
"->",
"AddLink",
"(",
"'Forum'",
",",
"T",
"(",
"'Embed Forum'",
")",
",",
"'dashboard/embed/forum'",
",",
"'Garden.Settings.Manage'",
")",
";",
"}"
] |
Adds items to dashboard menu.
@since 2.0.0
@package Vanilla
@param object $Sender DashboardController.
|
[
"Adds",
"items",
"to",
"dashboard",
"menu",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L539-L546
|
237,125
|
bishopb/vanilla
|
applications/vanilla/settings/class.hooks.php
|
VanillaHooks.Setup
|
public function Setup() {
$Database = Gdn::Database();
$Config = Gdn::Factory(Gdn::AliasConfig);
$Drop = Gdn::Config('Vanilla.Version') === FALSE ? TRUE : FALSE;
$Explicit = TRUE;
// Call structure.php to update database
$Validation = new Gdn_Validation(); // Needed by structure.php to validate permission names
include(PATH_APPLICATIONS . DS . 'vanilla' . DS . 'settings' . DS . 'structure.php');
SaveToConfig('Routes.DefaultController', 'discussions');
}
|
php
|
public function Setup() {
$Database = Gdn::Database();
$Config = Gdn::Factory(Gdn::AliasConfig);
$Drop = Gdn::Config('Vanilla.Version') === FALSE ? TRUE : FALSE;
$Explicit = TRUE;
// Call structure.php to update database
$Validation = new Gdn_Validation(); // Needed by structure.php to validate permission names
include(PATH_APPLICATIONS . DS . 'vanilla' . DS . 'settings' . DS . 'structure.php');
SaveToConfig('Routes.DefaultController', 'discussions');
}
|
[
"public",
"function",
"Setup",
"(",
")",
"{",
"$",
"Database",
"=",
"Gdn",
"::",
"Database",
"(",
")",
";",
"$",
"Config",
"=",
"Gdn",
"::",
"Factory",
"(",
"Gdn",
"::",
"AliasConfig",
")",
";",
"$",
"Drop",
"=",
"Gdn",
"::",
"Config",
"(",
"'Vanilla.Version'",
")",
"===",
"FALSE",
"?",
"TRUE",
":",
"FALSE",
";",
"$",
"Explicit",
"=",
"TRUE",
";",
"// Call structure.php to update database",
"$",
"Validation",
"=",
"new",
"Gdn_Validation",
"(",
")",
";",
"// Needed by structure.php to validate permission names",
"include",
"(",
"PATH_APPLICATIONS",
".",
"DS",
".",
"'vanilla'",
".",
"DS",
".",
"'settings'",
".",
"DS",
".",
"'structure.php'",
")",
";",
"SaveToConfig",
"(",
"'Routes.DefaultController'",
",",
"'discussions'",
")",
";",
"}"
] |
Automatically executed when application is enabled.
@since 2.0.0
@package Vanilla
|
[
"Automatically",
"executed",
"when",
"application",
"is",
"enabled",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/settings/class.hooks.php#L554-L565
|
237,126
|
phossa2/libs
|
src/Phossa2/Di/Traits/InstanceFactoryTrait.php
|
InstanceFactoryTrait.getInstance
|
protected function getInstance(/*# string */ $id, array $args)
{
// get id & scope info
list($rawId, $scopedId, $scope) = $this->realScopeInfo($id);
// get from the pool
if (isset($this->pool[$scopedId])) {
return $this->pool[$scopedId];
}
// create instance
$instance = $this->createInstance($rawId, $args);
// save in the pool
if (empty($args) && ScopeInterface::SCOPE_SINGLE !== $scope) {
$this->pool[$scopedId] = $instance;
}
return $instance;
}
|
php
|
protected function getInstance(/*# string */ $id, array $args)
{
// get id & scope info
list($rawId, $scopedId, $scope) = $this->realScopeInfo($id);
// get from the pool
if (isset($this->pool[$scopedId])) {
return $this->pool[$scopedId];
}
// create instance
$instance = $this->createInstance($rawId, $args);
// save in the pool
if (empty($args) && ScopeInterface::SCOPE_SINGLE !== $scope) {
$this->pool[$scopedId] = $instance;
}
return $instance;
}
|
[
"protected",
"function",
"getInstance",
"(",
"/*# string */",
"$",
"id",
",",
"array",
"$",
"args",
")",
"{",
"// get id & scope info",
"list",
"(",
"$",
"rawId",
",",
"$",
"scopedId",
",",
"$",
"scope",
")",
"=",
"$",
"this",
"->",
"realScopeInfo",
"(",
"$",
"id",
")",
";",
"// get from the pool",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"pool",
"[",
"$",
"scopedId",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"pool",
"[",
"$",
"scopedId",
"]",
";",
"}",
"// create instance",
"$",
"instance",
"=",
"$",
"this",
"->",
"createInstance",
"(",
"$",
"rawId",
",",
"$",
"args",
")",
";",
"// save in the pool",
"if",
"(",
"empty",
"(",
"$",
"args",
")",
"&&",
"ScopeInterface",
"::",
"SCOPE_SINGLE",
"!==",
"$",
"scope",
")",
"{",
"$",
"this",
"->",
"pool",
"[",
"$",
"scopedId",
"]",
"=",
"$",
"instance",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Get the instance either from the pool or create it
@param string $id service id with or without the scope
@param array $args arguments for the constructor
@return object
@throws LogicException if instantiation goes wrong
@throws RuntimeException if method execution goes wrong
@access protected
|
[
"Get",
"the",
"instance",
"either",
"from",
"the",
"pool",
"or",
"create",
"it"
] |
921e485c8cc29067f279da2cdd06f47a9bddd115
|
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Di/Traits/InstanceFactoryTrait.php#L68-L87
|
237,127
|
phossa2/libs
|
src/Phossa2/Di/Traits/InstanceFactoryTrait.php
|
InstanceFactoryTrait.realScopeInfo
|
protected function realScopeInfo(/*# string */ $id)/*# : array */
{
list($rawId, $scope) = $this->scopedInfo($id);
// special treatment if $scope is a '#service_id'
if (isset($this->loop[$scope])) {
$scope .= '_' . $this->loop[$scope];
}
return [$rawId, $this->scopedId($rawId, $scope), $scope];
}
|
php
|
protected function realScopeInfo(/*# string */ $id)/*# : array */
{
list($rawId, $scope) = $this->scopedInfo($id);
// special treatment if $scope is a '#service_id'
if (isset($this->loop[$scope])) {
$scope .= '_' . $this->loop[$scope];
}
return [$rawId, $this->scopedId($rawId, $scope), $scope];
}
|
[
"protected",
"function",
"realScopeInfo",
"(",
"/*# string */",
"$",
"id",
")",
"/*# : array */",
"{",
"list",
"(",
"$",
"rawId",
",",
"$",
"scope",
")",
"=",
"$",
"this",
"->",
"scopedInfo",
"(",
"$",
"id",
")",
";",
"// special treatment if $scope is a '#service_id'",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"loop",
"[",
"$",
"scope",
"]",
")",
")",
"{",
"$",
"scope",
".=",
"'_'",
".",
"$",
"this",
"->",
"loop",
"[",
"$",
"scope",
"]",
";",
"}",
"return",
"[",
"$",
"rawId",
",",
"$",
"this",
"->",
"scopedId",
"(",
"$",
"rawId",
",",
"$",
"scope",
")",
",",
"$",
"scope",
"]",
";",
"}"
] |
Full scope info with consideration of ancestor instances
@param string $id
@return array
@access protected
|
[
"Full",
"scope",
"info",
"with",
"consideration",
"of",
"ancestor",
"instances"
] |
921e485c8cc29067f279da2cdd06f47a9bddd115
|
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Di/Traits/InstanceFactoryTrait.php#L96-L106
|
237,128
|
phossa2/libs
|
src/Phossa2/Di/Traits/InstanceFactoryTrait.php
|
InstanceFactoryTrait.createInstance
|
protected function createInstance(/*# string */ $rawId, array $args)
{
// conver 'service_id' to '#service_id'
$serviceId = ObjectResolver::getServiceId($rawId);
if (isset($this->loop[$serviceId])) {
throw new LogicException(
Message::get(Message::DI_LOOP_DETECTED, $rawId),
Message::DI_LOOP_DETECTED
);
} else {
$this->loop[$serviceId] = ++$this->counter;
$obj = $this->getFactory()->createInstance($rawId, $args);
unset($this->loop[$serviceId]);
return $obj;
}
}
|
php
|
protected function createInstance(/*# string */ $rawId, array $args)
{
// conver 'service_id' to '#service_id'
$serviceId = ObjectResolver::getServiceId($rawId);
if (isset($this->loop[$serviceId])) {
throw new LogicException(
Message::get(Message::DI_LOOP_DETECTED, $rawId),
Message::DI_LOOP_DETECTED
);
} else {
$this->loop[$serviceId] = ++$this->counter;
$obj = $this->getFactory()->createInstance($rawId, $args);
unset($this->loop[$serviceId]);
return $obj;
}
}
|
[
"protected",
"function",
"createInstance",
"(",
"/*# string */",
"$",
"rawId",
",",
"array",
"$",
"args",
")",
"{",
"// conver 'service_id' to '#service_id'",
"$",
"serviceId",
"=",
"ObjectResolver",
"::",
"getServiceId",
"(",
"$",
"rawId",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"loop",
"[",
"$",
"serviceId",
"]",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"DI_LOOP_DETECTED",
",",
"$",
"rawId",
")",
",",
"Message",
"::",
"DI_LOOP_DETECTED",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"loop",
"[",
"$",
"serviceId",
"]",
"=",
"++",
"$",
"this",
"->",
"counter",
";",
"$",
"obj",
"=",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"createInstance",
"(",
"$",
"rawId",
",",
"$",
"args",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"loop",
"[",
"$",
"serviceId",
"]",
")",
";",
"return",
"$",
"obj",
";",
"}",
"}"
] |
Create the instance with loop detection
Loop: an instance depends on itself in the creation chain.
@param string $rawId
@param array $args arguments for the constructor if any
@return object
@throws LogicException if instantiation goes wrong or loop detected
@access protected
|
[
"Create",
"the",
"instance",
"with",
"loop",
"detection"
] |
921e485c8cc29067f279da2cdd06f47a9bddd115
|
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Di/Traits/InstanceFactoryTrait.php#L119-L135
|
237,129
|
phossa2/libs
|
src/Phossa2/Di/Traits/InstanceFactoryTrait.php
|
InstanceFactoryTrait.initContainer
|
protected function initContainer()
{
$initNode = $this->getResolver()->getSectionId('', 'init');
if ($this->getResolver()->has($initNode)) {
$this->getFactory()->executeMethodBatch(
$this->getResolver()->get($initNode)
);
}
return $this;
}
|
php
|
protected function initContainer()
{
$initNode = $this->getResolver()->getSectionId('', 'init');
if ($this->getResolver()->has($initNode)) {
$this->getFactory()->executeMethodBatch(
$this->getResolver()->get($initNode)
);
}
return $this;
}
|
[
"protected",
"function",
"initContainer",
"(",
")",
"{",
"$",
"initNode",
"=",
"$",
"this",
"->",
"getResolver",
"(",
")",
"->",
"getSectionId",
"(",
"''",
",",
"'init'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getResolver",
"(",
")",
"->",
"has",
"(",
"$",
"initNode",
")",
")",
"{",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"executeMethodBatch",
"(",
"$",
"this",
"->",
"getResolver",
"(",
")",
"->",
"get",
"(",
"$",
"initNode",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
execute init methods defined in 'di.init' node
@return $this
@throws RuntimeException if anything goes wrong
@access protected
|
[
"execute",
"init",
"methods",
"defined",
"in",
"di",
".",
"init",
"node"
] |
921e485c8cc29067f279da2cdd06f47a9bddd115
|
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Di/Traits/InstanceFactoryTrait.php#L144-L154
|
237,130
|
easy-system/es-http
|
src/Response/SapiEmitter.php
|
SapiEmitter.emit
|
public function emit(ResponseInterface $response)
{
$filename = $linenum = null;
if (headers_sent($filename, $linenum)) {
throw new RuntimeException(sprintf(
'Unable to emit response; headers already sent in "%s" '
. 'on line "%s".',
$filename,
$linenum
));
}
$this
->emitStatusLine($response)
->emitHeaders($response)
->emitBody($response);
}
|
php
|
public function emit(ResponseInterface $response)
{
$filename = $linenum = null;
if (headers_sent($filename, $linenum)) {
throw new RuntimeException(sprintf(
'Unable to emit response; headers already sent in "%s" '
. 'on line "%s".',
$filename,
$linenum
));
}
$this
->emitStatusLine($response)
->emitHeaders($response)
->emitBody($response);
}
|
[
"public",
"function",
"emit",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"filename",
"=",
"$",
"linenum",
"=",
"null",
";",
"if",
"(",
"headers_sent",
"(",
"$",
"filename",
",",
"$",
"linenum",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to emit response; headers already sent in \"%s\" '",
".",
"'on line \"%s\".'",
",",
"$",
"filename",
",",
"$",
"linenum",
")",
")",
";",
"}",
"$",
"this",
"->",
"emitStatusLine",
"(",
"$",
"response",
")",
"->",
"emitHeaders",
"(",
"$",
"response",
")",
"->",
"emitBody",
"(",
"$",
"response",
")",
";",
"}"
] |
Emits the response.
@param \Psr\Http\Message\ResponseInterface $response The response
@throws \RuntimeException If headers is already sent
|
[
"Emits",
"the",
"response",
"."
] |
dd5852e94901e147a7546a8715133408ece767a1
|
https://github.com/easy-system/es-http/blob/dd5852e94901e147a7546a8715133408ece767a1/src/Response/SapiEmitter.php#L27-L42
|
237,131
|
easy-system/es-http
|
src/Response/SapiEmitter.php
|
SapiEmitter.emitStatusLine
|
protected function emitStatusLine(ResponseInterface $response)
{
$reasonPhrase = $response->getReasonPhrase();
header(sprintf(
'HTTP/%s %d%s',
$response->getProtocolVersion(),
$response->getStatusCode(),
($reasonPhrase ? ' ' . $reasonPhrase : '')
));
return $this;
}
|
php
|
protected function emitStatusLine(ResponseInterface $response)
{
$reasonPhrase = $response->getReasonPhrase();
header(sprintf(
'HTTP/%s %d%s',
$response->getProtocolVersion(),
$response->getStatusCode(),
($reasonPhrase ? ' ' . $reasonPhrase : '')
));
return $this;
}
|
[
"protected",
"function",
"emitStatusLine",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"reasonPhrase",
"=",
"$",
"response",
"->",
"getReasonPhrase",
"(",
")",
";",
"header",
"(",
"sprintf",
"(",
"'HTTP/%s %d%s'",
",",
"$",
"response",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"(",
"$",
"reasonPhrase",
"?",
"' '",
".",
"$",
"reasonPhrase",
":",
"''",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Emits the status line.
@param \Psr\Http\Message\ResponseInterface $response The response
@return self
|
[
"Emits",
"the",
"status",
"line",
"."
] |
dd5852e94901e147a7546a8715133408ece767a1
|
https://github.com/easy-system/es-http/blob/dd5852e94901e147a7546a8715133408ece767a1/src/Response/SapiEmitter.php#L51-L62
|
237,132
|
easy-system/es-http
|
src/Response/SapiEmitter.php
|
SapiEmitter.emitHeaders
|
protected function emitHeaders(ResponseInterface $response)
{
$normalize = function ($headerName) {
$name = str_replace('-', ' ', $headerName);
$filtered = str_replace(' ', '-', ucwords($name));
return $filtered;
};
foreach ($response->getHeaders() as $headerName => $values) {
$name = $normalize($headerName);
$first = true;
foreach ($values as $value) {
header(sprintf(
'%s: %s',
$name,
$value
), $first);
$first = false;
}
}
return $this;
}
|
php
|
protected function emitHeaders(ResponseInterface $response)
{
$normalize = function ($headerName) {
$name = str_replace('-', ' ', $headerName);
$filtered = str_replace(' ', '-', ucwords($name));
return $filtered;
};
foreach ($response->getHeaders() as $headerName => $values) {
$name = $normalize($headerName);
$first = true;
foreach ($values as $value) {
header(sprintf(
'%s: %s',
$name,
$value
), $first);
$first = false;
}
}
return $this;
}
|
[
"protected",
"function",
"emitHeaders",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"normalize",
"=",
"function",
"(",
"$",
"headerName",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'-'",
",",
"' '",
",",
"$",
"headerName",
")",
";",
"$",
"filtered",
"=",
"str_replace",
"(",
"' '",
",",
"'-'",
",",
"ucwords",
"(",
"$",
"name",
")",
")",
";",
"return",
"$",
"filtered",
";",
"}",
";",
"foreach",
"(",
"$",
"response",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"headerName",
"=>",
"$",
"values",
")",
"{",
"$",
"name",
"=",
"$",
"normalize",
"(",
"$",
"headerName",
")",
";",
"$",
"first",
"=",
"true",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"header",
"(",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"name",
",",
"$",
"value",
")",
",",
"$",
"first",
")",
";",
"$",
"first",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Emits headers.
@param \Psr\Http\Message\ResponseInterface $response The response
@return self
|
[
"Emits",
"headers",
"."
] |
dd5852e94901e147a7546a8715133408ece767a1
|
https://github.com/easy-system/es-http/blob/dd5852e94901e147a7546a8715133408ece767a1/src/Response/SapiEmitter.php#L71-L93
|
237,133
|
easy-system/es-http
|
src/Response/SapiEmitter.php
|
SapiEmitter.emitBody
|
protected function emitBody(ResponseInterface $response)
{
while (ob_get_level()) {
ob_end_flush();
}
$body = $response->getBody();
if ($body->getSize()) {
echo $body;
}
return $this;
}
|
php
|
protected function emitBody(ResponseInterface $response)
{
while (ob_get_level()) {
ob_end_flush();
}
$body = $response->getBody();
if ($body->getSize()) {
echo $body;
}
return $this;
}
|
[
"protected",
"function",
"emitBody",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"while",
"(",
"ob_get_level",
"(",
")",
")",
"{",
"ob_end_flush",
"(",
")",
";",
"}",
"$",
"body",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"$",
"body",
"->",
"getSize",
"(",
")",
")",
"{",
"echo",
"$",
"body",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Emits body.
@param \Psr\Http\Message\ResponseInterface $response The response
@return self
|
[
"Emits",
"body",
"."
] |
dd5852e94901e147a7546a8715133408ece767a1
|
https://github.com/easy-system/es-http/blob/dd5852e94901e147a7546a8715133408ece767a1/src/Response/SapiEmitter.php#L102-L114
|
237,134
|
reflex-php/lockdown
|
src/Reflex/Lockdown/Roles/Eloquent/Provider.php
|
Provider.findWithPermission
|
public function findWithPermission($permission)
{
return array_filter(
$this->findAll(),
function ($role) use ($permission) {
return $role->has($permission);
}
);
}
|
php
|
public function findWithPermission($permission)
{
return array_filter(
$this->findAll(),
function ($role) use ($permission) {
return $role->has($permission);
}
);
}
|
[
"public",
"function",
"findWithPermission",
"(",
"$",
"permission",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"findAll",
"(",
")",
",",
"function",
"(",
"$",
"role",
")",
"use",
"(",
"$",
"permission",
")",
"{",
"return",
"$",
"role",
"->",
"has",
"(",
"$",
"permission",
")",
";",
"}",
")",
";",
"}"
] |
Find roles with permission
@param \Reflex\Lockdown\Permissions\PermissionInterface $permission
Permission instance
@return mixed
|
[
"Find",
"roles",
"with",
"permission"
] |
2798e448608eef469f2924d75013deccfd6aca44
|
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Roles/Eloquent/Provider.php#L128-L136
|
237,135
|
reflex-php/lockdown
|
src/Reflex/Lockdown/Roles/Eloquent/Provider.php
|
Provider.findWithoutPermission
|
public function findWithoutPermission($permission)
{
return array_filter(
$this->findAll(),
function ($role) use ($permission) {
return $role->hasnt($permission);
}
);
}
|
php
|
public function findWithoutPermission($permission)
{
return array_filter(
$this->findAll(),
function ($role) use ($permission) {
return $role->hasnt($permission);
}
);
}
|
[
"public",
"function",
"findWithoutPermission",
"(",
"$",
"permission",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"findAll",
"(",
")",
",",
"function",
"(",
"$",
"role",
")",
"use",
"(",
"$",
"permission",
")",
"{",
"return",
"$",
"role",
"->",
"hasnt",
"(",
"$",
"permission",
")",
";",
"}",
")",
";",
"}"
] |
Find roles without permission
@param \Reflex\Lockdown\Permissions\PermissionInterface $permission
Permission instance
@return mixed
|
[
"Find",
"roles",
"without",
"permission"
] |
2798e448608eef469f2924d75013deccfd6aca44
|
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Roles/Eloquent/Provider.php#L144-L152
|
237,136
|
monomelodies/ornament
|
src/Adapter/Pdo.php
|
Pdo.load
|
public function load(Container $object)
{
$pks = [];
$values = $this->parameters;
$identifier = $this->identifier;
foreach ($this->primaryKey as $key) {
if (isset($object->$key)) {
$pks[$key] = sprintf('%s.%s = ?', $identifier, $key);
$values[] = $object->$key;
} else {
throw new Exception\PrimaryKey($identifier, $key);
}
}
$fields = $this->fields;
foreach ($fields as &$field) {
$field = "$identifier.$field";
}
$identifier .= $this->generateJoin($fields);
$sql = "SELECT %s FROM %s WHERE %s";
$stmt = $this->getStatement(sprintf(
$sql,
implode(', ', $fields),
$identifier,
implode(' AND ', $pks)
));
$stmt->setFetchMode(Base::FETCH_INTO, $object);
$stmt->execute($values);
$stmt->fetch();
$object->markClean();
}
|
php
|
public function load(Container $object)
{
$pks = [];
$values = $this->parameters;
$identifier = $this->identifier;
foreach ($this->primaryKey as $key) {
if (isset($object->$key)) {
$pks[$key] = sprintf('%s.%s = ?', $identifier, $key);
$values[] = $object->$key;
} else {
throw new Exception\PrimaryKey($identifier, $key);
}
}
$fields = $this->fields;
foreach ($fields as &$field) {
$field = "$identifier.$field";
}
$identifier .= $this->generateJoin($fields);
$sql = "SELECT %s FROM %s WHERE %s";
$stmt = $this->getStatement(sprintf(
$sql,
implode(', ', $fields),
$identifier,
implode(' AND ', $pks)
));
$stmt->setFetchMode(Base::FETCH_INTO, $object);
$stmt->execute($values);
$stmt->fetch();
$object->markClean();
}
|
[
"public",
"function",
"load",
"(",
"Container",
"$",
"object",
")",
"{",
"$",
"pks",
"=",
"[",
"]",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"parameters",
";",
"$",
"identifier",
"=",
"$",
"this",
"->",
"identifier",
";",
"foreach",
"(",
"$",
"this",
"->",
"primaryKey",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"object",
"->",
"$",
"key",
")",
")",
"{",
"$",
"pks",
"[",
"$",
"key",
"]",
"=",
"sprintf",
"(",
"'%s.%s = ?'",
",",
"$",
"identifier",
",",
"$",
"key",
")",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"object",
"->",
"$",
"key",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"PrimaryKey",
"(",
"$",
"identifier",
",",
"$",
"key",
")",
";",
"}",
"}",
"$",
"fields",
"=",
"$",
"this",
"->",
"fields",
";",
"foreach",
"(",
"$",
"fields",
"as",
"&",
"$",
"field",
")",
"{",
"$",
"field",
"=",
"\"$identifier.$field\"",
";",
"}",
"$",
"identifier",
".=",
"$",
"this",
"->",
"generateJoin",
"(",
"$",
"fields",
")",
";",
"$",
"sql",
"=",
"\"SELECT %s FROM %s WHERE %s\"",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"getStatement",
"(",
"sprintf",
"(",
"$",
"sql",
",",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
",",
"$",
"identifier",
",",
"implode",
"(",
"' AND '",
",",
"$",
"pks",
")",
")",
")",
";",
"$",
"stmt",
"->",
"setFetchMode",
"(",
"Base",
"::",
"FETCH_INTO",
",",
"$",
"object",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"values",
")",
";",
"$",
"stmt",
"->",
"fetch",
"(",
")",
";",
"$",
"object",
"->",
"markClean",
"(",
")",
";",
"}"
] |
Load data into a single model.
@param Container $object A container object.
@return void
@throws Ornament\Exception\PrimaryKey if no primary key was set or could
be determined, and loading would inevitably fail.
|
[
"Load",
"data",
"into",
"a",
"single",
"model",
"."
] |
d7d070ad11f5731be141cf55c2756accaaf51402
|
https://github.com/monomelodies/ornament/blob/d7d070ad11f5731be141cf55c2756accaaf51402/src/Adapter/Pdo.php#L107-L136
|
237,137
|
monomelodies/ornament
|
src/Adapter/Pdo.php
|
Pdo.generateJoin
|
protected function generateJoin(array &$fields)
{
$annotations = $this->annotations['class'];
$props = $this->annotations['properties'];
$table = '';
foreach (['Require' => '', 'Include' => 'LEFT '] as $type => $join) {
if (isset($annotations[$type])) {
foreach ($annotations[$type] as $local => $joinCond) {
if (is_numeric($local)) {
foreach ($joinCond as $local => $joinCond) {
}
}
// Hack to make the annotationParser recurse.
$joinCond = AnnotationParser::getAnnotations(
'/** @joinCond '.implode(', ', $joinCond).' */'
)['joincond'];
$table .= sprintf(
' %1$sJOIN %2$s ON ',
$join,
$local
);
$conds = [];
foreach ($joinCond as $ref => $me) {
if ($me == '?') {
$conds[] = sprintf(
"%s.%s = $me",
$local,
$ref
);
} else {
$conds[] = sprintf(
"%s.%s = %s.%s",
$local,
$ref,
$this->identifier,
$me
);
}
}
$table .= implode(" AND ", $conds);
}
}
}
foreach ($fields as &$field) {
$name = str_replace("{$this->identifier}.", '', $field);
if (isset($props[$name]['From'])) {
$field = sprintf(
'%s %s',
$props[$name]['From'],
$name
);
}
}
return $table;
}
|
php
|
protected function generateJoin(array &$fields)
{
$annotations = $this->annotations['class'];
$props = $this->annotations['properties'];
$table = '';
foreach (['Require' => '', 'Include' => 'LEFT '] as $type => $join) {
if (isset($annotations[$type])) {
foreach ($annotations[$type] as $local => $joinCond) {
if (is_numeric($local)) {
foreach ($joinCond as $local => $joinCond) {
}
}
// Hack to make the annotationParser recurse.
$joinCond = AnnotationParser::getAnnotations(
'/** @joinCond '.implode(', ', $joinCond).' */'
)['joincond'];
$table .= sprintf(
' %1$sJOIN %2$s ON ',
$join,
$local
);
$conds = [];
foreach ($joinCond as $ref => $me) {
if ($me == '?') {
$conds[] = sprintf(
"%s.%s = $me",
$local,
$ref
);
} else {
$conds[] = sprintf(
"%s.%s = %s.%s",
$local,
$ref,
$this->identifier,
$me
);
}
}
$table .= implode(" AND ", $conds);
}
}
}
foreach ($fields as &$field) {
$name = str_replace("{$this->identifier}.", '', $field);
if (isset($props[$name]['From'])) {
$field = sprintf(
'%s %s',
$props[$name]['From'],
$name
);
}
}
return $table;
}
|
[
"protected",
"function",
"generateJoin",
"(",
"array",
"&",
"$",
"fields",
")",
"{",
"$",
"annotations",
"=",
"$",
"this",
"->",
"annotations",
"[",
"'class'",
"]",
";",
"$",
"props",
"=",
"$",
"this",
"->",
"annotations",
"[",
"'properties'",
"]",
";",
"$",
"table",
"=",
"''",
";",
"foreach",
"(",
"[",
"'Require'",
"=>",
"''",
",",
"'Include'",
"=>",
"'LEFT '",
"]",
"as",
"$",
"type",
"=>",
"$",
"join",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"annotations",
"[",
"$",
"type",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"annotations",
"[",
"$",
"type",
"]",
"as",
"$",
"local",
"=>",
"$",
"joinCond",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"local",
")",
")",
"{",
"foreach",
"(",
"$",
"joinCond",
"as",
"$",
"local",
"=>",
"$",
"joinCond",
")",
"{",
"}",
"}",
"// Hack to make the annotationParser recurse.",
"$",
"joinCond",
"=",
"AnnotationParser",
"::",
"getAnnotations",
"(",
"'/** @joinCond '",
".",
"implode",
"(",
"', '",
",",
"$",
"joinCond",
")",
".",
"' */'",
")",
"[",
"'joincond'",
"]",
";",
"$",
"table",
".=",
"sprintf",
"(",
"' %1$sJOIN %2$s ON '",
",",
"$",
"join",
",",
"$",
"local",
")",
";",
"$",
"conds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"joinCond",
"as",
"$",
"ref",
"=>",
"$",
"me",
")",
"{",
"if",
"(",
"$",
"me",
"==",
"'?'",
")",
"{",
"$",
"conds",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s.%s = $me\"",
",",
"$",
"local",
",",
"$",
"ref",
")",
";",
"}",
"else",
"{",
"$",
"conds",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s.%s = %s.%s\"",
",",
"$",
"local",
",",
"$",
"ref",
",",
"$",
"this",
"->",
"identifier",
",",
"$",
"me",
")",
";",
"}",
"}",
"$",
"table",
".=",
"implode",
"(",
"\" AND \"",
",",
"$",
"conds",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"&",
"$",
"field",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"\"{$this->identifier}.\"",
",",
"''",
",",
"$",
"field",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"props",
"[",
"$",
"name",
"]",
"[",
"'From'",
"]",
")",
")",
"{",
"$",
"field",
"=",
"sprintf",
"(",
"'%s %s'",
",",
"$",
"props",
"[",
"$",
"name",
"]",
"[",
"'From'",
"]",
",",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"table",
";",
"}"
] |
Internal helper to generate a JOIN statement.
@param array $fields Array of fields to extend.
@return string The JOIN statement to append to the query string.
|
[
"Internal",
"helper",
"to",
"generate",
"a",
"JOIN",
"statement",
"."
] |
d7d070ad11f5731be141cf55c2756accaaf51402
|
https://github.com/monomelodies/ornament/blob/d7d070ad11f5731be141cf55c2756accaaf51402/src/Adapter/Pdo.php#L144-L198
|
237,138
|
monomelodies/ornament
|
src/Adapter/Pdo.php
|
Pdo.getStatement
|
protected function getStatement($sql)
{
if (!isset($this->statements[$sql])) {
$this->statements[$sql] = $this->adapter->prepare($sql);
}
return $this->statements[$sql];
}
|
php
|
protected function getStatement($sql)
{
if (!isset($this->statements[$sql])) {
$this->statements[$sql] = $this->adapter->prepare($sql);
}
return $this->statements[$sql];
}
|
[
"protected",
"function",
"getStatement",
"(",
"$",
"sql",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"statements",
"[",
"$",
"sql",
"]",
")",
")",
"{",
"$",
"this",
"->",
"statements",
"[",
"$",
"sql",
"]",
"=",
"$",
"this",
"->",
"adapter",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"}",
"return",
"$",
"this",
"->",
"statements",
"[",
"$",
"sql",
"]",
";",
"}"
] |
Protected helper to either get or create a PDOStatement.
@param string $sql SQL to prepare the statement with.
@return PDOStatement A PDOStatement.
|
[
"Protected",
"helper",
"to",
"either",
"get",
"or",
"create",
"a",
"PDOStatement",
"."
] |
d7d070ad11f5731be141cf55c2756accaaf51402
|
https://github.com/monomelodies/ornament/blob/d7d070ad11f5731be141cf55c2756accaaf51402/src/Adapter/Pdo.php#L206-L212
|
237,139
|
thunderwolf/twAdminPlugin
|
lib/twAdmin.class.php
|
twAdmin.routeExists
|
public static function routeExists($route, sfContext $context)
{
try {
if ($route{0} == '@') {
$context->getRouting()->generate(substr($route, 1));
}
return true;
} catch (Exception $e) {
return false;
}
}
|
php
|
public static function routeExists($route, sfContext $context)
{
try {
if ($route{0} == '@') {
$context->getRouting()->generate(substr($route, 1));
}
return true;
} catch (Exception $e) {
return false;
}
}
|
[
"public",
"static",
"function",
"routeExists",
"(",
"$",
"route",
",",
"sfContext",
"$",
"context",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"route",
"{",
"0",
"}",
"==",
"'@'",
")",
"{",
"$",
"context",
"->",
"getRouting",
"(",
")",
"->",
"generate",
"(",
"substr",
"(",
"$",
"route",
",",
"1",
")",
")",
";",
"}",
"return",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] |
Check if the supplied route exists
@param string $route
@param sfContext $context
@return boolean
|
[
"Check",
"if",
"the",
"supplied",
"route",
"exists"
] |
85a4af0f49a535b6c8327567524f770f805d6454
|
https://github.com/thunderwolf/twAdminPlugin/blob/85a4af0f49a535b6c8327567524f770f805d6454/lib/twAdmin.class.php#L44-L54
|
237,140
|
agalbourdin/agl-core
|
src/Mysql/Query/Raw.php
|
Raw.query
|
public function query($pQuery, array $pParams = array())
{
$this->_stm = Agl::app()->getDb()->getConnection()->prepare($pQuery);
if (! $this->_stm->execute($pParams)) {
$error = $this->_stm->errorInfo();
throw new Exception("The query failed with message '" . $error[2] . "'");
}
if (Agl::app()->isDebugMode()) {
Agl::app()->getDb()->incrementCounter();
}
return $this->_stm->fetchAll(PDO::FETCH_ASSOC);
}
|
php
|
public function query($pQuery, array $pParams = array())
{
$this->_stm = Agl::app()->getDb()->getConnection()->prepare($pQuery);
if (! $this->_stm->execute($pParams)) {
$error = $this->_stm->errorInfo();
throw new Exception("The query failed with message '" . $error[2] . "'");
}
if (Agl::app()->isDebugMode()) {
Agl::app()->getDb()->incrementCounter();
}
return $this->_stm->fetchAll(PDO::FETCH_ASSOC);
}
|
[
"public",
"function",
"query",
"(",
"$",
"pQuery",
",",
"array",
"$",
"pParams",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_stm",
"=",
"Agl",
"::",
"app",
"(",
")",
"->",
"getDb",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"prepare",
"(",
"$",
"pQuery",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_stm",
"->",
"execute",
"(",
"$",
"pParams",
")",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"_stm",
"->",
"errorInfo",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"The query failed with message '\"",
".",
"$",
"error",
"[",
"2",
"]",
".",
"\"'\"",
")",
";",
"}",
"if",
"(",
"Agl",
"::",
"app",
"(",
")",
"->",
"isDebugMode",
"(",
")",
")",
"{",
"Agl",
"::",
"app",
"(",
")",
"->",
"getDb",
"(",
")",
"->",
"incrementCounter",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_stm",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] |
Commit the query to the database and return the result.
@return Select
|
[
"Commit",
"the",
"query",
"to",
"the",
"database",
"and",
"return",
"the",
"result",
"."
] |
1db556f9a49488aa9fab6887fefb7141a79ad97d
|
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mysql/Query/Raw.php#L34-L48
|
237,141
|
halimonalexander/sid
|
src/Sid.php
|
Sid.extractConstants
|
private static function extractConstants()
{
$oClass = new \ReflectionClass(get_called_class());
$constants = $oClass->getConstants();
unset(
$constants['IS_IMPLICIT_ABSTRACT'],
$constants['IS_EXPLICIT_ABSTRACT'],
$constants['IS_FINAL']
);
return $constants;
}
|
php
|
private static function extractConstants()
{
$oClass = new \ReflectionClass(get_called_class());
$constants = $oClass->getConstants();
unset(
$constants['IS_IMPLICIT_ABSTRACT'],
$constants['IS_EXPLICIT_ABSTRACT'],
$constants['IS_FINAL']
);
return $constants;
}
|
[
"private",
"static",
"function",
"extractConstants",
"(",
")",
"{",
"$",
"oClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"get_called_class",
"(",
")",
")",
";",
"$",
"constants",
"=",
"$",
"oClass",
"->",
"getConstants",
"(",
")",
";",
"unset",
"(",
"$",
"constants",
"[",
"'IS_IMPLICIT_ABSTRACT'",
"]",
",",
"$",
"constants",
"[",
"'IS_EXPLICIT_ABSTRACT'",
"]",
",",
"$",
"constants",
"[",
"'IS_FINAL'",
"]",
")",
";",
"return",
"$",
"constants",
";",
"}"
] |
Extract constants using ReflectionClass
|
[
"Extract",
"constants",
"using",
"ReflectionClass"
] |
7bfa551af1b941c95e9be81812e5edecd9d9bd16
|
https://github.com/halimonalexander/sid/blob/7bfa551af1b941c95e9be81812e5edecd9d9bd16/src/Sid.php#L56-L67
|
237,142
|
halimonalexander/sid
|
src/Sid.php
|
Sid.updateHiddenValue
|
protected static function updateHiddenValue($list, $name)
{
$sid = $list[$name];
unset($list[$name]);
preg_match("/" . self::$hiddenSidNamePattern . "/", $name, $match);
$list[$match[1]] = $sid;
return $list;
}
|
php
|
protected static function updateHiddenValue($list, $name)
{
$sid = $list[$name];
unset($list[$name]);
preg_match("/" . self::$hiddenSidNamePattern . "/", $name, $match);
$list[$match[1]] = $sid;
return $list;
}
|
[
"protected",
"static",
"function",
"updateHiddenValue",
"(",
"$",
"list",
",",
"$",
"name",
")",
"{",
"$",
"sid",
"=",
"$",
"list",
"[",
"$",
"name",
"]",
";",
"unset",
"(",
"$",
"list",
"[",
"$",
"name",
"]",
")",
";",
"preg_match",
"(",
"\"/\"",
".",
"self",
"::",
"$",
"hiddenSidNamePattern",
".",
"\"/\"",
",",
"$",
"name",
",",
"$",
"match",
")",
";",
"$",
"list",
"[",
"$",
"match",
"[",
"1",
"]",
"]",
"=",
"$",
"sid",
";",
"return",
"$",
"list",
";",
"}"
] |
Update hidden value's name by removing leading _
@param $list
@param $name
@return mixed
|
[
"Update",
"hidden",
"value",
"s",
"name",
"by",
"removing",
"leading",
"_"
] |
7bfa551af1b941c95e9be81812e5edecd9d9bd16
|
https://github.com/halimonalexander/sid/blob/7bfa551af1b941c95e9be81812e5edecd9d9bd16/src/Sid.php#L134-L143
|
237,143
|
halimonalexander/sid
|
src/Sid.php
|
Sid.getList
|
public static function getList(bool $full = false)
{
$class = get_called_class();
if (empty(self::$list[$class])) {
self::$list[$class] = self::loadList();
}
$list = self::$list[$class];
foreach ($list as $name => $sid) {
if (static::isHidden($name)) {
if (!$full)
unset($list[$name]);
else
$list = self::updateHiddenValue($list, $name);
}
}
return $list;
}
|
php
|
public static function getList(bool $full = false)
{
$class = get_called_class();
if (empty(self::$list[$class])) {
self::$list[$class] = self::loadList();
}
$list = self::$list[$class];
foreach ($list as $name => $sid) {
if (static::isHidden($name)) {
if (!$full)
unset($list[$name]);
else
$list = self::updateHiddenValue($list, $name);
}
}
return $list;
}
|
[
"public",
"static",
"function",
"getList",
"(",
"bool",
"$",
"full",
"=",
"false",
")",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"list",
"[",
"$",
"class",
"]",
")",
")",
"{",
"self",
"::",
"$",
"list",
"[",
"$",
"class",
"]",
"=",
"self",
"::",
"loadList",
"(",
")",
";",
"}",
"$",
"list",
"=",
"self",
"::",
"$",
"list",
"[",
"$",
"class",
"]",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"name",
"=>",
"$",
"sid",
")",
"{",
"if",
"(",
"static",
"::",
"isHidden",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"!",
"$",
"full",
")",
"unset",
"(",
"$",
"list",
"[",
"$",
"name",
"]",
")",
";",
"else",
"$",
"list",
"=",
"self",
"::",
"updateHiddenValue",
"(",
"$",
"list",
",",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
] |
Get full sid list
@param bool $full
@return array List of values as: Name => Sid
|
[
"Get",
"full",
"sid",
"list"
] |
7bfa551af1b941c95e9be81812e5edecd9d9bd16
|
https://github.com/halimonalexander/sid/blob/7bfa551af1b941c95e9be81812e5edecd9d9bd16/src/Sid.php#L199-L218
|
237,144
|
halimonalexander/sid
|
src/Sid.php
|
Sid.getNameById
|
public static function getNameById($sid)
{
$list = self::getList(true);
$key = array_search($sid, $list);
if ($key === false)
throw new SidItemNotFound('Sid not exists');
return $key;
}
|
php
|
public static function getNameById($sid)
{
$list = self::getList(true);
$key = array_search($sid, $list);
if ($key === false)
throw new SidItemNotFound('Sid not exists');
return $key;
}
|
[
"public",
"static",
"function",
"getNameById",
"(",
"$",
"sid",
")",
"{",
"$",
"list",
"=",
"self",
"::",
"getList",
"(",
"true",
")",
";",
"$",
"key",
"=",
"array_search",
"(",
"$",
"sid",
",",
"$",
"list",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"throw",
"new",
"SidItemNotFound",
"(",
"'Sid not exists'",
")",
";",
"return",
"$",
"key",
";",
"}"
] |
Return constant name from SID.
@param int $id SID to find
@return string Name of constant.
@throws SidItemNotFound
|
[
"Return",
"constant",
"name",
"from",
"SID",
"."
] |
7bfa551af1b941c95e9be81812e5edecd9d9bd16
|
https://github.com/halimonalexander/sid/blob/7bfa551af1b941c95e9be81812e5edecd9d9bd16/src/Sid.php#L239-L247
|
237,145
|
halimonalexander/sid
|
src/Sid.php
|
Sid.getTitle
|
public static function getTitle($id, $lang, $context = 'default')
{
$name = self::getNameById($id);
$class = self::getClassWithoutNamespace();
return call_user_func(self::getCallback($lang), $name, $class, $context);
}
|
php
|
public static function getTitle($id, $lang, $context = 'default')
{
$name = self::getNameById($id);
$class = self::getClassWithoutNamespace();
return call_user_func(self::getCallback($lang), $name, $class, $context);
}
|
[
"public",
"static",
"function",
"getTitle",
"(",
"$",
"id",
",",
"$",
"lang",
",",
"$",
"context",
"=",
"'default'",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"getNameById",
"(",
"$",
"id",
")",
";",
"$",
"class",
"=",
"self",
"::",
"getClassWithoutNamespace",
"(",
")",
";",
"return",
"call_user_func",
"(",
"self",
"::",
"getCallback",
"(",
"$",
"lang",
")",
",",
"$",
"name",
",",
"$",
"class",
",",
"$",
"context",
")",
";",
"}"
] |
Get Sid title from vocabulary
@param int $id
@param string $lang
@param string $context
@return mixed
|
[
"Get",
"Sid",
"title",
"from",
"vocabulary"
] |
7bfa551af1b941c95e9be81812e5edecd9d9bd16
|
https://github.com/halimonalexander/sid/blob/7bfa551af1b941c95e9be81812e5edecd9d9bd16/src/Sid.php#L258-L264
|
237,146
|
setrun/setrun-component-sys
|
src/behaviors/TimeAgoBehavior.php
|
TimeAgoBehavior.getTimeAgo
|
public function getTimeAgo($field = null, $options = []){
$attribute = $this->attribute;
if ($field !== null) {
$attribute = $field;
}
$year = $options['year'] ?? 'full:{day} {month} {year}';
$month = $options['month'] ?? 'full:{day} {month}';
if ($this->owner->hasAttribute($attribute)) {
$value = $this->owner{$attribute};
if (!is_numeric($this->owner{$attribute})) {
$value = strtotime($this->owner{$attribute});
}
$updatedM = date('m', $value);
$currM = date('m', time());
$updatedY = date('Y', $value);
$currY = date('Y', time());
if ($updatedY !== $currY) {
return Html::tag('time', Yii::$app->formatter->asDate($value, 'long'));
}
if ($updatedM < $currM) {
return Html::tag('time', Yii::$app->formatter->asDate($value, 'medium'));
}
return TimeAgo::widget(['timestamp' => $value, 'language' => Yii::$app->language]);
}
return null;
}
|
php
|
public function getTimeAgo($field = null, $options = []){
$attribute = $this->attribute;
if ($field !== null) {
$attribute = $field;
}
$year = $options['year'] ?? 'full:{day} {month} {year}';
$month = $options['month'] ?? 'full:{day} {month}';
if ($this->owner->hasAttribute($attribute)) {
$value = $this->owner{$attribute};
if (!is_numeric($this->owner{$attribute})) {
$value = strtotime($this->owner{$attribute});
}
$updatedM = date('m', $value);
$currM = date('m', time());
$updatedY = date('Y', $value);
$currY = date('Y', time());
if ($updatedY !== $currY) {
return Html::tag('time', Yii::$app->formatter->asDate($value, 'long'));
}
if ($updatedM < $currM) {
return Html::tag('time', Yii::$app->formatter->asDate($value, 'medium'));
}
return TimeAgo::widget(['timestamp' => $value, 'language' => Yii::$app->language]);
}
return null;
}
|
[
"public",
"function",
"getTimeAgo",
"(",
"$",
"field",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"attribute",
";",
"if",
"(",
"$",
"field",
"!==",
"null",
")",
"{",
"$",
"attribute",
"=",
"$",
"field",
";",
"}",
"$",
"year",
"=",
"$",
"options",
"[",
"'year'",
"]",
"??",
"'full:{day} {month} {year}'",
";",
"$",
"month",
"=",
"$",
"options",
"[",
"'month'",
"]",
"??",
"'full:{day} {month}'",
";",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"hasAttribute",
"(",
"$",
"attribute",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"owner",
"{",
"$",
"attribute",
"}",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"owner",
"{",
"$",
"attribute",
"}",
")",
")",
"{",
"$",
"value",
"=",
"strtotime",
"(",
"$",
"this",
"->",
"owner",
"{",
"$",
"attribute",
"}",
")",
";",
"}",
"$",
"updatedM",
"=",
"date",
"(",
"'m'",
",",
"$",
"value",
")",
";",
"$",
"currM",
"=",
"date",
"(",
"'m'",
",",
"time",
"(",
")",
")",
";",
"$",
"updatedY",
"=",
"date",
"(",
"'Y'",
",",
"$",
"value",
")",
";",
"$",
"currY",
"=",
"date",
"(",
"'Y'",
",",
"time",
"(",
")",
")",
";",
"if",
"(",
"$",
"updatedY",
"!==",
"$",
"currY",
")",
"{",
"return",
"Html",
"::",
"tag",
"(",
"'time'",
",",
"Yii",
"::",
"$",
"app",
"->",
"formatter",
"->",
"asDate",
"(",
"$",
"value",
",",
"'long'",
")",
")",
";",
"}",
"if",
"(",
"$",
"updatedM",
"<",
"$",
"currM",
")",
"{",
"return",
"Html",
"::",
"tag",
"(",
"'time'",
",",
"Yii",
"::",
"$",
"app",
"->",
"formatter",
"->",
"asDate",
"(",
"$",
"value",
",",
"'medium'",
")",
")",
";",
"}",
"return",
"TimeAgo",
"::",
"widget",
"(",
"[",
"'timestamp'",
"=>",
"$",
"value",
",",
"'language'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"language",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get a date in the time ago format
@return string
@throws \Exception
|
[
"Get",
"a",
"date",
"in",
"the",
"time",
"ago",
"format"
] |
ad9a6442a2921e0f061ed4e455b050c56029d565
|
https://github.com/setrun/setrun-component-sys/blob/ad9a6442a2921e0f061ed4e455b050c56029d565/src/behaviors/TimeAgoBehavior.php#L31-L59
|
237,147
|
PsyduckMans/PHPX-Propel
|
src/PHPX/Propel/Util/Ext/Direct/Criteria.php
|
Criteria.bindSort
|
public static function bindSort(\Criteria $criteria, $sort) {
$direction = $sort['direction'];
switch($direction) {
case self::SORT_DIRECTION_DESC:
$criteria->addDescendingOrderByColumn($sort['column']);
break;
case self::SORT_DIRECTION_ASC:
$criteria->addAscendingOrderByColumn($sort['column']);
break;
default:
throw new RuntimeException('Unsupport Ext direct sort direction:'.$direction);
}
}
|
php
|
public static function bindSort(\Criteria $criteria, $sort) {
$direction = $sort['direction'];
switch($direction) {
case self::SORT_DIRECTION_DESC:
$criteria->addDescendingOrderByColumn($sort['column']);
break;
case self::SORT_DIRECTION_ASC:
$criteria->addAscendingOrderByColumn($sort['column']);
break;
default:
throw new RuntimeException('Unsupport Ext direct sort direction:'.$direction);
}
}
|
[
"public",
"static",
"function",
"bindSort",
"(",
"\\",
"Criteria",
"$",
"criteria",
",",
"$",
"sort",
")",
"{",
"$",
"direction",
"=",
"$",
"sort",
"[",
"'direction'",
"]",
";",
"switch",
"(",
"$",
"direction",
")",
"{",
"case",
"self",
"::",
"SORT_DIRECTION_DESC",
":",
"$",
"criteria",
"->",
"addDescendingOrderByColumn",
"(",
"$",
"sort",
"[",
"'column'",
"]",
")",
";",
"break",
";",
"case",
"self",
"::",
"SORT_DIRECTION_ASC",
":",
"$",
"criteria",
"->",
"addAscendingOrderByColumn",
"(",
"$",
"sort",
"[",
"'column'",
"]",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"'Unsupport Ext direct sort direction:'",
".",
"$",
"direction",
")",
";",
"}",
"}"
] |
bind Ext direct sort to Propel Criteria
@param \Criteria $criteria
@param $sort
array(
'direction' => 'DESC',
'column' => UserPeer::ID
)
@throws RuntimeException
@return void
|
[
"bind",
"Ext",
"direct",
"sort",
"to",
"Propel",
"Criteria"
] |
5d251d577d47352c568cf04576b94104754dd7da
|
https://github.com/PsyduckMans/PHPX-Propel/blob/5d251d577d47352c568cf04576b94104754dd7da/src/PHPX/Propel/Util/Ext/Direct/Criteria.php#L38-L50
|
237,148
|
zoopcommerce/shard
|
lib/Zoop/Shard/AccessControl/AccessController.php
|
AccessController.areAllowed
|
public function areAllowed(array $actions, ClassMetadata $metadata, $document = null, ChangeSet $changeSet = null)
{
if (!$metadata->hasProperty('permissions')) {
return new AllowedResult(false);
}
//first check the generic 'guest' role
$result = $this->checkRolesAgainstActions(['guest'], $actions, $metadata);
if (!$result->getAllowed() || $result->hasCriteria()) {
//now load the user roles if the generic 'guest' role failed
$roles = $this->getRoles($metadata, $document);
$result = $this->checkRolesAgainstActions($roles, $actions, $metadata);
}
if (isset($document)) {
return $this->testCritieraAgainstDocument($metadata, $document, $changeSet, $result);
}
return $result;
}
|
php
|
public function areAllowed(array $actions, ClassMetadata $metadata, $document = null, ChangeSet $changeSet = null)
{
if (!$metadata->hasProperty('permissions')) {
return new AllowedResult(false);
}
//first check the generic 'guest' role
$result = $this->checkRolesAgainstActions(['guest'], $actions, $metadata);
if (!$result->getAllowed() || $result->hasCriteria()) {
//now load the user roles if the generic 'guest' role failed
$roles = $this->getRoles($metadata, $document);
$result = $this->checkRolesAgainstActions($roles, $actions, $metadata);
}
if (isset($document)) {
return $this->testCritieraAgainstDocument($metadata, $document, $changeSet, $result);
}
return $result;
}
|
[
"public",
"function",
"areAllowed",
"(",
"array",
"$",
"actions",
",",
"ClassMetadata",
"$",
"metadata",
",",
"$",
"document",
"=",
"null",
",",
"ChangeSet",
"$",
"changeSet",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"metadata",
"->",
"hasProperty",
"(",
"'permissions'",
")",
")",
"{",
"return",
"new",
"AllowedResult",
"(",
"false",
")",
";",
"}",
"//first check the generic 'guest' role",
"$",
"result",
"=",
"$",
"this",
"->",
"checkRolesAgainstActions",
"(",
"[",
"'guest'",
"]",
",",
"$",
"actions",
",",
"$",
"metadata",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"getAllowed",
"(",
")",
"||",
"$",
"result",
"->",
"hasCriteria",
"(",
")",
")",
"{",
"//now load the user roles if the generic 'guest' role failed",
"$",
"roles",
"=",
"$",
"this",
"->",
"getRoles",
"(",
"$",
"metadata",
",",
"$",
"document",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"checkRolesAgainstActions",
"(",
"$",
"roles",
",",
"$",
"actions",
",",
"$",
"metadata",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"document",
")",
")",
"{",
"return",
"$",
"this",
"->",
"testCritieraAgainstDocument",
"(",
"$",
"metadata",
",",
"$",
"document",
",",
"$",
"changeSet",
",",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Determines if an action can be done by the current User
@param array $action
@param \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata
@param type $document
@return \Zoop\Shard\AccessControl\IsAllowedResult
|
[
"Determines",
"if",
"an",
"action",
"can",
"be",
"done",
"by",
"the",
"current",
"User"
] |
14dde6ff25bc3125ad35667c8ff65cb755750b27
|
https://github.com/zoopcommerce/shard/blob/14dde6ff25bc3125ad35667c8ff65cb755750b27/lib/Zoop/Shard/AccessControl/AccessController.php#L37-L57
|
237,149
|
webignition/html-document-link-url-finder
|
src/HtmlDocumentLinkUrlFinder.php
|
HtmlDocumentLinkUrlFinder.looksLikeConcatenatedJsString
|
private function looksLikeConcatenatedJsString(string $url): bool
{
$patternBody = "^'\s+\+\s+.*\s+\+\s+'$";
$pattern = '/'.$patternBody.'/i';
return preg_match($pattern, $url) > 0;
}
|
php
|
private function looksLikeConcatenatedJsString(string $url): bool
{
$patternBody = "^'\s+\+\s+.*\s+\+\s+'$";
$pattern = '/'.$patternBody.'/i';
return preg_match($pattern, $url) > 0;
}
|
[
"private",
"function",
"looksLikeConcatenatedJsString",
"(",
"string",
"$",
"url",
")",
":",
"bool",
"{",
"$",
"patternBody",
"=",
"\"^'\\s+\\+\\s+.*\\s+\\+\\s+'$\"",
";",
"$",
"pattern",
"=",
"'/'",
".",
"$",
"patternBody",
".",
"'/i'",
";",
"return",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"url",
")",
">",
"0",
";",
"}"
] |
Determine if the URL value from an element attribute looks like a concatenated JS string
Some documents contain script elements which concatenate JS values together to make URLs for elements that
are inserted into the DOM. This is all fine.
e.g. VimeoList.push('<img src="' + value['ListImage'] + '" />');
A subset of such documents are badly-formed such that the script contents are not recognised by the DOM parser
and end up as element nodes in the DOM
e.g. the above would result in a <img src="' + value['ListImage'] + '" /> element present in the DOM.
This applies to both the \DOMDocument parser and the W3C HTML validation parser. It is assumed both parsers
are not identically buggy.
We need to check if a URL value looks like a concatenated JS string so that we can exclude them.
Example URL value: ' + value['ListImage'] + '
Pseudopattern: START'<whitespace?><plus char><whitespace?><anything><whitespace?><plus char><whitespace?>'END
@param string $url
@return bool
|
[
"Determine",
"if",
"the",
"URL",
"value",
"from",
"an",
"element",
"attribute",
"looks",
"like",
"a",
"concatenated",
"JS",
"string"
] |
247820dd8c7d68ddd7f61c21dfc51fa7ed46bfbf
|
https://github.com/webignition/html-document-link-url-finder/blob/247820dd8c7d68ddd7f61c21dfc51fa7ed46bfbf/src/HtmlDocumentLinkUrlFinder.php#L130-L136
|
237,150
|
diatem-net/jin-dataformat
|
src/DataFormat/Csv.php
|
Csv.fputcsv
|
protected function fputcsv($filePointer, $dataArray, $delimiter = ",", $enclosure = "\"")
{
// Build the string
$string = "";
// No leading delimiter
$writeDelimiter = false;
foreach ($dataArray as $dataElement) {
// Replaces a double quote with two double quotes
$dataElement = str_replace("\"", "\"\"", $dataElement);
// Adds a delimiter before each field (except the first)
if ($writeDelimiter) {
$string .= $delimiter;
}
// Encloses each field with $enclosure and adds it to the string
if ($enclosure) {
$string .= $enclosure . $dataElement . $enclosure;
} else {
$string .= $dataElement;
}
// Delimiters are used every time except the first.
$writeDelimiter = true;
}
// Append new line
$string .= "\n";
// Write the string to the file
fwrite($filePointer, $string);
}
|
php
|
protected function fputcsv($filePointer, $dataArray, $delimiter = ",", $enclosure = "\"")
{
// Build the string
$string = "";
// No leading delimiter
$writeDelimiter = false;
foreach ($dataArray as $dataElement) {
// Replaces a double quote with two double quotes
$dataElement = str_replace("\"", "\"\"", $dataElement);
// Adds a delimiter before each field (except the first)
if ($writeDelimiter) {
$string .= $delimiter;
}
// Encloses each field with $enclosure and adds it to the string
if ($enclosure) {
$string .= $enclosure . $dataElement . $enclosure;
} else {
$string .= $dataElement;
}
// Delimiters are used every time except the first.
$writeDelimiter = true;
}
// Append new line
$string .= "\n";
// Write the string to the file
fwrite($filePointer, $string);
}
|
[
"protected",
"function",
"fputcsv",
"(",
"$",
"filePointer",
",",
"$",
"dataArray",
",",
"$",
"delimiter",
"=",
"\",\"",
",",
"$",
"enclosure",
"=",
"\"\\\"\"",
")",
"{",
"// Build the string\r",
"$",
"string",
"=",
"\"\"",
";",
"// No leading delimiter\r",
"$",
"writeDelimiter",
"=",
"false",
";",
"foreach",
"(",
"$",
"dataArray",
"as",
"$",
"dataElement",
")",
"{",
"// Replaces a double quote with two double quotes\r",
"$",
"dataElement",
"=",
"str_replace",
"(",
"\"\\\"\"",
",",
"\"\\\"\\\"\"",
",",
"$",
"dataElement",
")",
";",
"// Adds a delimiter before each field (except the first)\r",
"if",
"(",
"$",
"writeDelimiter",
")",
"{",
"$",
"string",
".=",
"$",
"delimiter",
";",
"}",
"// Encloses each field with $enclosure and adds it to the string\r",
"if",
"(",
"$",
"enclosure",
")",
"{",
"$",
"string",
".=",
"$",
"enclosure",
".",
"$",
"dataElement",
".",
"$",
"enclosure",
";",
"}",
"else",
"{",
"$",
"string",
".=",
"$",
"dataElement",
";",
"}",
"// Delimiters are used every time except the first.\r",
"$",
"writeDelimiter",
"=",
"true",
";",
"}",
"// Append new line\r",
"$",
"string",
".=",
"\"\\n\"",
";",
"// Write the string to the file\r",
"fwrite",
"(",
"$",
"filePointer",
",",
"$",
"string",
")",
";",
"}"
] |
Write a line to a file
@param string $filePointer File resource to write in
@param array $dataArray Data to write out
@param string $delimiter Field separator
@param string $enclosure Enclosure
|
[
"Write",
"a",
"line",
"to",
"a",
"file"
] |
3d8b0aeb8dcf0b81dc319faf79006ddea9cfa6dd
|
https://github.com/diatem-net/jin-dataformat/blob/3d8b0aeb8dcf0b81dc319faf79006ddea9cfa6dd/src/DataFormat/Csv.php#L177-L203
|
237,151
|
diatem-net/jin-dataformat
|
src/DataFormat/Csv.php
|
Csv.writeDataInIO
|
protected function writeDataInIO($fp)
{
// Écriture des données
if ($this->useAssociativeArray) {
foreach ($this->data as $donnee) {
foreach ($donnee as &$champ) {
$champ = (is_string($champ)) ? iconv("UTF-8", "Windows-1252//TRANSLIT", $champ) : $champ;
}
$this->fputcsv($fp, $donnee, ';', $this->enclosures);
}
} else {
for ($i = 0; $i < count($this->data); $i++) {
for ($j = 0; $j < count($this->data[$i]); $j++) {
$this->fputcsv($fp, $this->data[$i][$j], ';', $this->enclosures);
}
}
}
}
|
php
|
protected function writeDataInIO($fp)
{
// Écriture des données
if ($this->useAssociativeArray) {
foreach ($this->data as $donnee) {
foreach ($donnee as &$champ) {
$champ = (is_string($champ)) ? iconv("UTF-8", "Windows-1252//TRANSLIT", $champ) : $champ;
}
$this->fputcsv($fp, $donnee, ';', $this->enclosures);
}
} else {
for ($i = 0; $i < count($this->data); $i++) {
for ($j = 0; $j < count($this->data[$i]); $j++) {
$this->fputcsv($fp, $this->data[$i][$j], ';', $this->enclosures);
}
}
}
}
|
[
"protected",
"function",
"writeDataInIO",
"(",
"$",
"fp",
")",
"{",
"// Écriture des données\r",
"if",
"(",
"$",
"this",
"->",
"useAssociativeArray",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"donnee",
")",
"{",
"foreach",
"(",
"$",
"donnee",
"as",
"&",
"$",
"champ",
")",
"{",
"$",
"champ",
"=",
"(",
"is_string",
"(",
"$",
"champ",
")",
")",
"?",
"iconv",
"(",
"\"UTF-8\"",
",",
"\"Windows-1252//TRANSLIT\"",
",",
"$",
"champ",
")",
":",
"$",
"champ",
";",
"}",
"$",
"this",
"->",
"fputcsv",
"(",
"$",
"fp",
",",
"$",
"donnee",
",",
"';'",
",",
"$",
"this",
"->",
"enclosures",
")",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"i",
"++",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"count",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"i",
"]",
")",
";",
"$",
"j",
"++",
")",
"{",
"$",
"this",
"->",
"fputcsv",
"(",
"$",
"fp",
",",
"$",
"this",
"->",
"data",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
",",
"';'",
",",
"$",
"this",
"->",
"enclosures",
")",
";",
"}",
"}",
"}",
"}"
] |
Ecrit dans le flux de sortie
@param ressource $fp
|
[
"Ecrit",
"dans",
"le",
"flux",
"de",
"sortie"
] |
3d8b0aeb8dcf0b81dc319faf79006ddea9cfa6dd
|
https://github.com/diatem-net/jin-dataformat/blob/3d8b0aeb8dcf0b81dc319faf79006ddea9cfa6dd/src/DataFormat/Csv.php#L210-L227
|
237,152
|
seeren/application
|
src/Application.php
|
Application.sendErrorDocument
|
private function sendErrorDocument(
ResponseInterface $response): ResponseInterface
{
if ($this->errorDocument && preg_match(
"/^(4|5){1}[0-2]{1}[0-9]{1}$/", $response->getStatusCode())
) {
$this->errorDocument = str_replace(
"{status}", $response->getStatusCode(), $this->errorDocument
);
if ($this->errorDocument !== filter_input(INPUT_SERVER, "REQUEST_URI")) {
$response = $response->withHeader(
Response::HEADER_REFRESH,
"0; " . $this->errorDocument
);
}
}
return $response;
}
|
php
|
private function sendErrorDocument(
ResponseInterface $response): ResponseInterface
{
if ($this->errorDocument && preg_match(
"/^(4|5){1}[0-2]{1}[0-9]{1}$/", $response->getStatusCode())
) {
$this->errorDocument = str_replace(
"{status}", $response->getStatusCode(), $this->errorDocument
);
if ($this->errorDocument !== filter_input(INPUT_SERVER, "REQUEST_URI")) {
$response = $response->withHeader(
Response::HEADER_REFRESH,
"0; " . $this->errorDocument
);
}
}
return $response;
}
|
[
"private",
"function",
"sendErrorDocument",
"(",
"ResponseInterface",
"$",
"response",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"errorDocument",
"&&",
"preg_match",
"(",
"\"/^(4|5){1}[0-2]{1}[0-9]{1}$/\"",
",",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorDocument",
"=",
"str_replace",
"(",
"\"{status}\"",
",",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"this",
"->",
"errorDocument",
")",
";",
"if",
"(",
"$",
"this",
"->",
"errorDocument",
"!==",
"filter_input",
"(",
"INPUT_SERVER",
",",
"\"REQUEST_URI\"",
")",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"Response",
"::",
"HEADER_REFRESH",
",",
"\"0; \"",
".",
"$",
"this",
"->",
"errorDocument",
")",
";",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] |
Send error document
@param ResponseInterface $response psr-7 response
@return ResponseInterface psr-7 response
|
[
"Send",
"error",
"document"
] |
bd36ec219fa24f33cd8686f3aaae70deb9cf61ea
|
https://github.com/seeren/application/blob/bd36ec219fa24f33cd8686f3aaae70deb9cf61ea/src/Application.php#L54-L71
|
237,153
|
vakata/router
|
src/Router.php
|
Router.setPrefix
|
public function setPrefix(string $prefix) : RouterInterface {
$prefix = trim($prefix, '/');
$this->prefix = $prefix.(strlen($prefix) ? '/' : '');
return $this;
}
|
php
|
public function setPrefix(string $prefix) : RouterInterface {
$prefix = trim($prefix, '/');
$this->prefix = $prefix.(strlen($prefix) ? '/' : '');
return $this;
}
|
[
"public",
"function",
"setPrefix",
"(",
"string",
"$",
"prefix",
")",
":",
"RouterInterface",
"{",
"$",
"prefix",
"=",
"trim",
"(",
"$",
"prefix",
",",
"'/'",
")",
";",
"$",
"this",
"->",
"prefix",
"=",
"$",
"prefix",
".",
"(",
"strlen",
"(",
"$",
"prefix",
")",
"?",
"'/'",
":",
"''",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the prefix for all future URLs, used mainly internally.
@param string $prefix the prefix to prepend
@return self
|
[
"Set",
"the",
"prefix",
"for",
"all",
"future",
"URLs",
"used",
"mainly",
"internally",
"."
] |
de392bdc8ed1353a59529c3bcf78574e1ad72545
|
https://github.com/vakata/router/blob/de392bdc8ed1353a59529c3bcf78574e1ad72545/src/Router.php#L130-L134
|
237,154
|
vakata/router
|
src/Router.php
|
Router.add
|
public function add($method, $url = null, $handler = null) : RouterInterface
{
$temp = [ 'method' => [ 'GET', 'POST' ], 'url' => '', 'handler' => null ];
foreach (func_get_args() as $arg) {
if (is_callable($arg)) {
$temp['handler'] = $arg;
} else if (in_array($arg, ['GET', 'HEAD', 'POST', 'PATCH', 'DELETE', 'PUT', 'OPTIONS', 'REPORT'])) {
$temp['method'] = $arg;
} else {
$temp['url'] = $arg;
}
}
list($method, $url, $handler) = array_values($temp);
if (!$url && $this->prefix) {
$url = $this->prefix;
} else {
if (!$url) {
$url = '{**}';
}
$url = $this->prefix.$url;
}
if (!$method) {
$method = ['GET','POST'];
}
if (!is_array($method)) {
$method = [$method];
}
if (!is_callable($handler)) {
throw new RouterException('No valid handler found');
}
foreach ($method as $m) {
if (!isset($this->routes[$m])) {
$this->routes[$m] = [];
}
$this->routes[$m][$url] = $handler;
}
return $this;
}
|
php
|
public function add($method, $url = null, $handler = null) : RouterInterface
{
$temp = [ 'method' => [ 'GET', 'POST' ], 'url' => '', 'handler' => null ];
foreach (func_get_args() as $arg) {
if (is_callable($arg)) {
$temp['handler'] = $arg;
} else if (in_array($arg, ['GET', 'HEAD', 'POST', 'PATCH', 'DELETE', 'PUT', 'OPTIONS', 'REPORT'])) {
$temp['method'] = $arg;
} else {
$temp['url'] = $arg;
}
}
list($method, $url, $handler) = array_values($temp);
if (!$url && $this->prefix) {
$url = $this->prefix;
} else {
if (!$url) {
$url = '{**}';
}
$url = $this->prefix.$url;
}
if (!$method) {
$method = ['GET','POST'];
}
if (!is_array($method)) {
$method = [$method];
}
if (!is_callable($handler)) {
throw new RouterException('No valid handler found');
}
foreach ($method as $m) {
if (!isset($this->routes[$m])) {
$this->routes[$m] = [];
}
$this->routes[$m][$url] = $handler;
}
return $this;
}
|
[
"public",
"function",
"add",
"(",
"$",
"method",
",",
"$",
"url",
"=",
"null",
",",
"$",
"handler",
"=",
"null",
")",
":",
"RouterInterface",
"{",
"$",
"temp",
"=",
"[",
"'method'",
"=>",
"[",
"'GET'",
",",
"'POST'",
"]",
",",
"'url'",
"=>",
"''",
",",
"'handler'",
"=>",
"null",
"]",
";",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"temp",
"[",
"'handler'",
"]",
"=",
"$",
"arg",
";",
"}",
"else",
"if",
"(",
"in_array",
"(",
"$",
"arg",
",",
"[",
"'GET'",
",",
"'HEAD'",
",",
"'POST'",
",",
"'PATCH'",
",",
"'DELETE'",
",",
"'PUT'",
",",
"'OPTIONS'",
",",
"'REPORT'",
"]",
")",
")",
"{",
"$",
"temp",
"[",
"'method'",
"]",
"=",
"$",
"arg",
";",
"}",
"else",
"{",
"$",
"temp",
"[",
"'url'",
"]",
"=",
"$",
"arg",
";",
"}",
"}",
"list",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"handler",
")",
"=",
"array_values",
"(",
"$",
"temp",
")",
";",
"if",
"(",
"!",
"$",
"url",
"&&",
"$",
"this",
"->",
"prefix",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"prefix",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"'{**}'",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"prefix",
".",
"$",
"url",
";",
"}",
"if",
"(",
"!",
"$",
"method",
")",
"{",
"$",
"method",
"=",
"[",
"'GET'",
",",
"'POST'",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"method",
")",
")",
"{",
"$",
"method",
"=",
"[",
"$",
"method",
"]",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"handler",
")",
")",
"{",
"throw",
"new",
"RouterException",
"(",
"'No valid handler found'",
")",
";",
"}",
"foreach",
"(",
"$",
"method",
"as",
"$",
"m",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"m",
"]",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"[",
"$",
"m",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"routes",
"[",
"$",
"m",
"]",
"[",
"$",
"url",
"]",
"=",
"$",
"handler",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add a route. All params are optional and each of them can be omitted independently.
@param array|string $method HTTP verbs for which this route is valid
@param string $url the route URL (check the usage docs for information on supported formats)
@param callable $handler the handler to execute when the route is matched
@return self
|
[
"Add",
"a",
"route",
".",
"All",
"params",
"are",
"optional",
"and",
"each",
"of",
"them",
"can",
"be",
"omitted",
"independently",
"."
] |
de392bdc8ed1353a59529c3bcf78574e1ad72545
|
https://github.com/vakata/router/blob/de392bdc8ed1353a59529c3bcf78574e1ad72545/src/Router.php#L155-L196
|
237,155
|
WaddlingCo/streamperk-bundle
|
ServerBundle/Entity/Server.php
|
Server.userHasAccess
|
public function userHasAccess(User $user)
{
if ($this->getWhitelisted() === false) {
return true;
}
$criteria = Criteria::create()
->where(Criteria::expr()->eq('user', $user))
->setMaxResults(1);
$serverUsers = $this->users->matching($criteria);
if ($serverUsers->count() === 0) {
return false;
}
$serverUser = $serverUsers->first();
if ($serverUser->getBanned() === true) {
return false;
}
if ($this->getRequiresApproval() === true && $serverUser->getApproved() === false) {
return false;
}
return true;
}
|
php
|
public function userHasAccess(User $user)
{
if ($this->getWhitelisted() === false) {
return true;
}
$criteria = Criteria::create()
->where(Criteria::expr()->eq('user', $user))
->setMaxResults(1);
$serverUsers = $this->users->matching($criteria);
if ($serverUsers->count() === 0) {
return false;
}
$serverUser = $serverUsers->first();
if ($serverUser->getBanned() === true) {
return false;
}
if ($this->getRequiresApproval() === true && $serverUser->getApproved() === false) {
return false;
}
return true;
}
|
[
"public",
"function",
"userHasAccess",
"(",
"User",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getWhitelisted",
"(",
")",
"===",
"false",
")",
"{",
"return",
"true",
";",
"}",
"$",
"criteria",
"=",
"Criteria",
"::",
"create",
"(",
")",
"->",
"where",
"(",
"Criteria",
"::",
"expr",
"(",
")",
"->",
"eq",
"(",
"'user'",
",",
"$",
"user",
")",
")",
"->",
"setMaxResults",
"(",
"1",
")",
";",
"$",
"serverUsers",
"=",
"$",
"this",
"->",
"users",
"->",
"matching",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"serverUsers",
"->",
"count",
"(",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"serverUser",
"=",
"$",
"serverUsers",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"serverUser",
"->",
"getBanned",
"(",
")",
"===",
"true",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getRequiresApproval",
"(",
")",
"===",
"true",
"&&",
"$",
"serverUser",
"->",
"getApproved",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Get whether the user has access
@return boolean
|
[
"Get",
"whether",
"the",
"user",
"has",
"access"
] |
bb930778690a9a5e0f0a7308d9449c03239c5e35
|
https://github.com/WaddlingCo/streamperk-bundle/blob/bb930778690a9a5e0f0a7308d9449c03239c5e35/ServerBundle/Entity/Server.php#L635-L661
|
237,156
|
bruery/platform-core
|
src/bundles/UserBundle/Form/Type/ProfileType.php
|
ProfileType.buildUserForm
|
protected function buildUserForm(FormBuilderInterface $builder, array $options)
{
$now = new \DateTime();
$builder
->add('username', null, array('label' => 'form.label_username', 'translation_domain' => 'SonataUserBundle'))
->add('email', 'email', array('label' => 'form.label_email', 'translation_domain' => 'SonataUserBundle', 'read_only'=>true, 'attr'=>array('class'=>'span12')))
->add('firstname', null, array('label' => 'form.label_firstname', 'translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('lastname', null, array('label' => 'form.label_lastname','translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('website', null, array('label' => 'form.label_website', 'translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('phone', null, array('required' => false, 'label' => 'form.label_phone', 'translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('dateOfBirth', 'sonata_type_date_picker', array(
'years' => range(1900, $now->format('Y')),
'dp_min_date' => '1-1-1900',
'dp_max_date' => $now->format('c'),
'required' => false,
))
->add('gender', 'choice', array(
'label' => 'form.label_gender',
'choices' => array(
UserInterface::GENDER_UNKNOWN => 'gender_unknown',
UserInterface::GENDER_FEMALE => 'gender_female',
UserInterface::GENDER_MAN => 'gender_male',
),
'required' => true,
'translation_domain' => 'SonataUserBundle',
'attr'=>array('class'=>'span12')
));
}
|
php
|
protected function buildUserForm(FormBuilderInterface $builder, array $options)
{
$now = new \DateTime();
$builder
->add('username', null, array('label' => 'form.label_username', 'translation_domain' => 'SonataUserBundle'))
->add('email', 'email', array('label' => 'form.label_email', 'translation_domain' => 'SonataUserBundle', 'read_only'=>true, 'attr'=>array('class'=>'span12')))
->add('firstname', null, array('label' => 'form.label_firstname', 'translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('lastname', null, array('label' => 'form.label_lastname','translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('website', null, array('label' => 'form.label_website', 'translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('phone', null, array('required' => false, 'label' => 'form.label_phone', 'translation_domain' => 'SonataUserBundle', 'attr'=>array('class'=>'span12')))
->add('dateOfBirth', 'sonata_type_date_picker', array(
'years' => range(1900, $now->format('Y')),
'dp_min_date' => '1-1-1900',
'dp_max_date' => $now->format('c'),
'required' => false,
))
->add('gender', 'choice', array(
'label' => 'form.label_gender',
'choices' => array(
UserInterface::GENDER_UNKNOWN => 'gender_unknown',
UserInterface::GENDER_FEMALE => 'gender_female',
UserInterface::GENDER_MAN => 'gender_male',
),
'required' => true,
'translation_domain' => 'SonataUserBundle',
'attr'=>array('class'=>'span12')
));
}
|
[
"protected",
"function",
"buildUserForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'username'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'form.label_username'",
",",
"'translation_domain'",
"=>",
"'SonataUserBundle'",
")",
")",
"->",
"add",
"(",
"'email'",
",",
"'email'",
",",
"array",
"(",
"'label'",
"=>",
"'form.label_email'",
",",
"'translation_domain'",
"=>",
"'SonataUserBundle'",
",",
"'read_only'",
"=>",
"true",
",",
"'attr'",
"=>",
"array",
"(",
"'class'",
"=>",
"'span12'",
")",
")",
")",
"->",
"add",
"(",
"'firstname'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'form.label_firstname'",
",",
"'translation_domain'",
"=>",
"'SonataUserBundle'",
",",
"'attr'",
"=>",
"array",
"(",
"'class'",
"=>",
"'span12'",
")",
")",
")",
"->",
"add",
"(",
"'lastname'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'form.label_lastname'",
",",
"'translation_domain'",
"=>",
"'SonataUserBundle'",
",",
"'attr'",
"=>",
"array",
"(",
"'class'",
"=>",
"'span12'",
")",
")",
")",
"->",
"add",
"(",
"'website'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'form.label_website'",
",",
"'translation_domain'",
"=>",
"'SonataUserBundle'",
",",
"'attr'",
"=>",
"array",
"(",
"'class'",
"=>",
"'span12'",
")",
")",
")",
"->",
"add",
"(",
"'phone'",
",",
"null",
",",
"array",
"(",
"'required'",
"=>",
"false",
",",
"'label'",
"=>",
"'form.label_phone'",
",",
"'translation_domain'",
"=>",
"'SonataUserBundle'",
",",
"'attr'",
"=>",
"array",
"(",
"'class'",
"=>",
"'span12'",
")",
")",
")",
"->",
"add",
"(",
"'dateOfBirth'",
",",
"'sonata_type_date_picker'",
",",
"array",
"(",
"'years'",
"=>",
"range",
"(",
"1900",
",",
"$",
"now",
"->",
"format",
"(",
"'Y'",
")",
")",
",",
"'dp_min_date'",
"=>",
"'1-1-1900'",
",",
"'dp_max_date'",
"=>",
"$",
"now",
"->",
"format",
"(",
"'c'",
")",
",",
"'required'",
"=>",
"false",
",",
")",
")",
"->",
"add",
"(",
"'gender'",
",",
"'choice'",
",",
"array",
"(",
"'label'",
"=>",
"'form.label_gender'",
",",
"'choices'",
"=>",
"array",
"(",
"UserInterface",
"::",
"GENDER_UNKNOWN",
"=>",
"'gender_unknown'",
",",
"UserInterface",
"::",
"GENDER_FEMALE",
"=>",
"'gender_female'",
",",
"UserInterface",
"::",
"GENDER_MAN",
"=>",
"'gender_male'",
",",
")",
",",
"'required'",
"=>",
"true",
",",
"'translation_domain'",
"=>",
"'SonataUserBundle'",
",",
"'attr'",
"=>",
"array",
"(",
"'class'",
"=>",
"'span12'",
")",
")",
")",
";",
"}"
] |
Builds the embedded form representing the user.
@param FormBuilderInterface $builder
@param array $options
|
[
"Builds",
"the",
"embedded",
"form",
"representing",
"the",
"user",
"."
] |
46153c181b2d852763afa30f7378bcbc1b2f4ef3
|
https://github.com/bruery/platform-core/blob/46153c181b2d852763afa30f7378bcbc1b2f4ef3/src/bundles/UserBundle/Form/Type/ProfileType.php#L90-L118
|
237,157
|
crysalead/validator
|
src/Validator.php
|
Validator.set
|
public function set($name, $rule = null)
{
if (!is_array($name)) {
$name = [$name => $rule];
}
$this->_handlers = $name + $this->_handlers;
}
|
php
|
public function set($name, $rule = null)
{
if (!is_array($name)) {
$name = [$name => $rule];
}
$this->_handlers = $name + $this->_handlers;
}
|
[
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"rule",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"[",
"$",
"name",
"=>",
"$",
"rule",
"]",
";",
"}",
"$",
"this",
"->",
"_handlers",
"=",
"$",
"name",
"+",
"$",
"this",
"->",
"_handlers",
";",
"}"
] |
Sets one or several validation rules.
For example:
{{{
$validator = new Validator();
$validator->set('zeroToNine', '/^[0-9]$/');
$isValid = $validator->isZeroToNine('5'); // true
$isValid = $validator->isZeroToNine('20'); // false
}}}
Alternatively, the first parameter may be an array of rules expressed as key/value pairs,
as in the following:
{{{
$validator = new Validator();
$validator->set([
'zeroToNine' => '/^[0-9]$/',
'tenToNineteen' => '/^1[0-9]$/',
]);
}}}
In addition to regular expressions, validation rules can also be defined as full anonymous
functions:
{{{
use app\model\Account;
$validator = new Validator();
$validator->set('accountActive', function($value, $options = []) {
$value = is_int($value) ? Account::id($value) : $value;
return (boolean) $value->is_active;
});
$testAccount = Account::create(['is_active' => false]);
$validator->isAccountActive($testAccount); // returns false
}}}
These functions can take up to 3 parameters:
- `$value` _mixed_ : This is the actual value to be validated (as in the above example).
- `$options` _array_: This parameter allows a validation rule to implement custom options.
- `'format'` _string_: Often, validation rules come in multiple "formats", for example:
postal codes, which vary by country or region. Defining multiple formats allows you to
retain flexibility in how you validate data. In cases where a user's country of origin
is known, the appropriate validation rule may be selected. In cases where it is not
known, the value of `$format` may be `'any'`, which should pass if any format matches.
In cases where validation rule formats are not mutually exclusive, the value may be
`'all'`, in which case all must match.
@param mixed $name The name of the validation rule (string), or an array of key/value pairs
of names and rules.
@param string $rule If $name is a string, this should be a string regular expression, or a
closure that returns a boolean indicating success. Should be left blank if
`$name` is an array.
|
[
"Sets",
"one",
"or",
"several",
"validation",
"rules",
"."
] |
37070c0753351f250096c8495874544fbb6620cb
|
https://github.com/crysalead/validator/blob/37070c0753351f250096c8495874544fbb6620cb/src/Validator.php#L157-L163
|
237,158
|
crysalead/validator
|
src/Validator.php
|
Validator.has
|
public function has($name)
{
$checker = $this->_classes['checker'];
return isset($this->_handlers[$name]) || $checker::has($name);
}
|
php
|
public function has($name)
{
$checker = $this->_classes['checker'];
return isset($this->_handlers[$name]) || $checker::has($name);
}
|
[
"public",
"function",
"has",
"(",
"$",
"name",
")",
"{",
"$",
"checker",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'checker'",
"]",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"_handlers",
"[",
"$",
"name",
"]",
")",
"||",
"$",
"checker",
"::",
"has",
"(",
"$",
"name",
")",
";",
"}"
] |
Checks if a validation handler exists.
@param string $name A validation handler name.
|
[
"Checks",
"if",
"a",
"validation",
"handler",
"exists",
"."
] |
37070c0753351f250096c8495874544fbb6620cb
|
https://github.com/crysalead/validator/blob/37070c0753351f250096c8495874544fbb6620cb/src/Validator.php#L170-L174
|
237,159
|
crysalead/validator
|
src/Validator.php
|
Validator.get
|
public function get($name)
{
if (isset($this->_handlers[$name])) {
return $this->_handlers[$name];
}
$checker = $this->_classes['checker'];
if ($checker::has($name)) {
return $checker::get($name);
}
throw new InvalidArgumentException("Unexisting `{$name}` as validation handler.");
}
|
php
|
public function get($name)
{
if (isset($this->_handlers[$name])) {
return $this->_handlers[$name];
}
$checker = $this->_classes['checker'];
if ($checker::has($name)) {
return $checker::get($name);
}
throw new InvalidArgumentException("Unexisting `{$name}` as validation handler.");
}
|
[
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_handlers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_handlers",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"checker",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'checker'",
"]",
";",
"if",
"(",
"$",
"checker",
"::",
"has",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"checker",
"::",
"get",
"(",
"$",
"name",
")",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Unexisting `{$name}` as validation handler.\"",
")",
";",
"}"
] |
Returns a validation handler.
@param string $name A validation handler name.
|
[
"Returns",
"a",
"validation",
"handler",
"."
] |
37070c0753351f250096c8495874544fbb6620cb
|
https://github.com/crysalead/validator/blob/37070c0753351f250096c8495874544fbb6620cb/src/Validator.php#L181-L191
|
237,160
|
crysalead/validator
|
src/Validator.php
|
Validator.rule
|
public function rule($field, $rules = [])
{
$defaults = [
'message' => null,
'required' => true,
'skipEmpty' => false,
'format' => 'any',
'not' => false,
'on' => null
];
$rules = $rules ? (array) $rules : [];
foreach ($rules as $name => $options) {
if (is_numeric($name)) {
$name = $options;
$options = [];
}
if (is_string($options)) {
$options = ['message' => $options];
}
$options += $defaults;
$this->_rules[$field][$name] = $options;
}
}
|
php
|
public function rule($field, $rules = [])
{
$defaults = [
'message' => null,
'required' => true,
'skipEmpty' => false,
'format' => 'any',
'not' => false,
'on' => null
];
$rules = $rules ? (array) $rules : [];
foreach ($rules as $name => $options) {
if (is_numeric($name)) {
$name = $options;
$options = [];
}
if (is_string($options)) {
$options = ['message' => $options];
}
$options += $defaults;
$this->_rules[$field][$name] = $options;
}
}
|
[
"public",
"function",
"rule",
"(",
"$",
"field",
",",
"$",
"rules",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'message'",
"=>",
"null",
",",
"'required'",
"=>",
"true",
",",
"'skipEmpty'",
"=>",
"false",
",",
"'format'",
"=>",
"'any'",
",",
"'not'",
"=>",
"false",
",",
"'on'",
"=>",
"null",
"]",
";",
"$",
"rules",
"=",
"$",
"rules",
"?",
"(",
"array",
")",
"$",
"rules",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"name",
"=>",
"$",
"options",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"options",
";",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'message'",
"=>",
"$",
"options",
"]",
";",
"}",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"this",
"->",
"_rules",
"[",
"$",
"field",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"options",
";",
"}",
"}"
] |
Sets a rule.
@param mixed $name A fieldname.
@param string $handler A validation handler name.
|
[
"Sets",
"a",
"rule",
"."
] |
37070c0753351f250096c8495874544fbb6620cb
|
https://github.com/crysalead/validator/blob/37070c0753351f250096c8495874544fbb6620cb/src/Validator.php#L220-L244
|
237,161
|
crysalead/validator
|
src/Validator.php
|
Validator.validates
|
public function validates($data, $options = [])
{
$events = (array) (isset($options['events']) ? $options['events'] : null);
$this->_errors = [];
$error = $this->_error;
foreach ($this->_rules as $field => $rules) {
$values = static::values($data, explode('.', $field));
foreach ($rules as $name => $rule) {
$rule += $options;
$rule['field'] = $field;
if ($events && $rule['on'] && !array_intersect($events, (array) $rule['on'])) {
continue;
}
if (!$values && $rule['required']) {
$rule['message'] = null;
$this->_errors[$field][] = $error('required', $rule, $this->_meta);
break;
} else {
foreach ($values as $key => $value) {
if (empty($value) && $rule['skipEmpty']) {
continue;
}
if (!$this->is($name, $value, $rule + compact('data'), $params)) {
$this->_errors[$key][] = $error($name, $params + $rule, $this->_meta);
}
}
}
}
}
return !$this->_errors;
}
|
php
|
public function validates($data, $options = [])
{
$events = (array) (isset($options['events']) ? $options['events'] : null);
$this->_errors = [];
$error = $this->_error;
foreach ($this->_rules as $field => $rules) {
$values = static::values($data, explode('.', $field));
foreach ($rules as $name => $rule) {
$rule += $options;
$rule['field'] = $field;
if ($events && $rule['on'] && !array_intersect($events, (array) $rule['on'])) {
continue;
}
if (!$values && $rule['required']) {
$rule['message'] = null;
$this->_errors[$field][] = $error('required', $rule, $this->_meta);
break;
} else {
foreach ($values as $key => $value) {
if (empty($value) && $rule['skipEmpty']) {
continue;
}
if (!$this->is($name, $value, $rule + compact('data'), $params)) {
$this->_errors[$key][] = $error($name, $params + $rule, $this->_meta);
}
}
}
}
}
return !$this->_errors;
}
|
[
"public",
"function",
"validates",
"(",
"$",
"data",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"events",
"=",
"(",
"array",
")",
"(",
"isset",
"(",
"$",
"options",
"[",
"'events'",
"]",
")",
"?",
"$",
"options",
"[",
"'events'",
"]",
":",
"null",
")",
";",
"$",
"this",
"->",
"_errors",
"=",
"[",
"]",
";",
"$",
"error",
"=",
"$",
"this",
"->",
"_error",
";",
"foreach",
"(",
"$",
"this",
"->",
"_rules",
"as",
"$",
"field",
"=>",
"$",
"rules",
")",
"{",
"$",
"values",
"=",
"static",
"::",
"values",
"(",
"$",
"data",
",",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"name",
"=>",
"$",
"rule",
")",
"{",
"$",
"rule",
"+=",
"$",
"options",
";",
"$",
"rule",
"[",
"'field'",
"]",
"=",
"$",
"field",
";",
"if",
"(",
"$",
"events",
"&&",
"$",
"rule",
"[",
"'on'",
"]",
"&&",
"!",
"array_intersect",
"(",
"$",
"events",
",",
"(",
"array",
")",
"$",
"rule",
"[",
"'on'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"values",
"&&",
"$",
"rule",
"[",
"'required'",
"]",
")",
"{",
"$",
"rule",
"[",
"'message'",
"]",
"=",
"null",
";",
"$",
"this",
"->",
"_errors",
"[",
"$",
"field",
"]",
"[",
"]",
"=",
"$",
"error",
"(",
"'required'",
",",
"$",
"rule",
",",
"$",
"this",
"->",
"_meta",
")",
";",
"break",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"rule",
"[",
"'skipEmpty'",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"is",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"rule",
"+",
"compact",
"(",
"'data'",
")",
",",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"error",
"(",
"$",
"name",
",",
"$",
"params",
"+",
"$",
"rule",
",",
"$",
"this",
"->",
"_meta",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"!",
"$",
"this",
"->",
"_errors",
";",
"}"
] |
Validates a set of values against a specified rules list. This method may be used to validate
any arbitrary array of data against a set of validation rules.
@param array $data An array of key/value pairs, where the values are to be checked.
@param array $rules An array of rules to check the values in `$values` against. Each key in
`$rules` should match a key contained in `$values`, and each value should be a
validation rule in one of the allowable formats. For example, if you are
validating a data set containing a `'credit_card'` key, possible values for
`$rules` would be as follows:
- `['credit_card' => 'You must include a credit card number']`: This is the
simplest form of validation rule, in which the value is simply a message to
display if the rule fails. Using this format, all other validation settings
inherit from the defaults, including the validation rule itself, which only
checks to see that the corresponding key in `$values` is present and contains
a value that is not empty. _Please note when globalizing validation messages:_
When specifying messages, it may be preferable to use a code string (i.e.
`'ERR_NO_TITLE'`) instead of the full text of the validation error. These code
strings may then be translated by the appropriate tools in the templating layer.
- `['credit_card' => ['creditCard', 'message' => 'Invalid CC #']]`:
In the second format, the validation rule (in this case `creditCard`) and
associated configuration are specified as an array, where the rule to use is
the first value in the array (no key), and additional settings are specified
as other keys in the array. Please see the list below for more information on
allowed keys.
- The final format allows you to apply multiple validation rules to a single
value, and it is specified as follows:
`['credit_card' => [
['not:empty', 'message' => 'You must include credit card number'],
['creditCard', 'message' => 'Your credit card number must be valid']
]];`
@param array $options Validator-specific options.
Each rule defined as an array can contain any of the following settings
(in addition to the first value, which represents the rule to be used):
- `'message'` _string_: The error message to be returned if the validation
rule fails. See the note above regarding globalization of error messages.
- `'required`' _boolean_: Represents whether the value is required to be
present in `$values`. If `'required'` is set to `false`, the validation rule
will be skipped if the corresponding key is not present. Defaults to `true`.
- `'skipEmpty'` _boolean_: Similar to `'required'`, this setting (if `true`)
will cause the validation rule to be skipped if the corresponding value
is empty (an empty string or `null`). Defaults to `false`.
- `'format'` _string_: If the validation rule has multiple format definitions
(see the `add()` or `init()` methods), the name of the format to be used
can be specified here. Additionally, two special values can be used:
either `'any'`, which means that all formats will be checked and the rule
will pass if any format passes, or `'all'`, which requires all formats to
pass in order for the rule check to succeed.
@return array Returns an array containing all validation failures for data in `$values`,
where each key matches a key in `$values`, and each value is an array of
that element's validation errors.
|
[
"Validates",
"a",
"set",
"of",
"values",
"against",
"a",
"specified",
"rules",
"list",
".",
"This",
"method",
"may",
"be",
"used",
"to",
"validate",
"any",
"arbitrary",
"array",
"of",
"data",
"against",
"a",
"set",
"of",
"validation",
"rules",
"."
] |
37070c0753351f250096c8495874544fbb6620cb
|
https://github.com/crysalead/validator/blob/37070c0753351f250096c8495874544fbb6620cb/src/Validator.php#L298-L333
|
237,162
|
crysalead/validator
|
src/Validator.php
|
Validator.is
|
public function is($name, $value, $options = [], &$params = [])
{
$not = false;
if (strncmp($name, 'not:', 4) === 0) {
$name = substr($name, 4);
$not = true;
}
$handlers = $this->get($name);
$handlers = is_array($handlers) ? $handlers : [$handlers];
$checker = $this->_classes['checker'];
return $checker::check($value, $handlers, $options, $params) !== $not;
}
|
php
|
public function is($name, $value, $options = [], &$params = [])
{
$not = false;
if (strncmp($name, 'not:', 4) === 0) {
$name = substr($name, 4);
$not = true;
}
$handlers = $this->get($name);
$handlers = is_array($handlers) ? $handlers : [$handlers];
$checker = $this->_classes['checker'];
return $checker::check($value, $handlers, $options, $params) !== $not;
}
|
[
"public",
"function",
"is",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"options",
"=",
"[",
"]",
",",
"&",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"not",
"=",
"false",
";",
"if",
"(",
"strncmp",
"(",
"$",
"name",
",",
"'not:'",
",",
"4",
")",
"===",
"0",
")",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"name",
",",
"4",
")",
";",
"$",
"not",
"=",
"true",
";",
"}",
"$",
"handlers",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"name",
")",
";",
"$",
"handlers",
"=",
"is_array",
"(",
"$",
"handlers",
")",
"?",
"$",
"handlers",
":",
"[",
"$",
"handlers",
"]",
";",
"$",
"checker",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'checker'",
"]",
";",
"return",
"$",
"checker",
"::",
"check",
"(",
"$",
"value",
",",
"$",
"handlers",
",",
"$",
"options",
",",
"$",
"params",
")",
"!==",
"$",
"not",
";",
"}"
] |
Checks a single value against a validation handler.
@param string $rule The validation handler name.
@param mixed $value The value to check.
@param array $options The options array.
@return boolean Returns `true` or `false` indicating whether the validation rule check
succeeded or failed.
|
[
"Checks",
"a",
"single",
"value",
"against",
"a",
"validation",
"handler",
"."
] |
37070c0753351f250096c8495874544fbb6620cb
|
https://github.com/crysalead/validator/blob/37070c0753351f250096c8495874544fbb6620cb/src/Validator.php#L354-L366
|
237,163
|
crysalead/validator
|
src/Validator.php
|
Validator.values
|
public static function values($data, $path = [], $base = null)
{
if (!$path) {
$base = $base ?: 0;
return [$base => $data];
}
$field = array_shift($path);
if ($field === '*') {
$values = [];
foreach ($data as $key => $value) {
$values = array_merge($values, static::values($value, $path, $base . '.' . $key));
}
return $values;
} elseif (!isset($data[$field])) {
return [];
} elseif (!$path) {
return [$base ? $base . '.' . $field : $field => $data[$field]];
} else {
return static::values($data[$field], $path, $base ? $base . '.' . $field : $field);
}
}
|
php
|
public static function values($data, $path = [], $base = null)
{
if (!$path) {
$base = $base ?: 0;
return [$base => $data];
}
$field = array_shift($path);
if ($field === '*') {
$values = [];
foreach ($data as $key => $value) {
$values = array_merge($values, static::values($value, $path, $base . '.' . $key));
}
return $values;
} elseif (!isset($data[$field])) {
return [];
} elseif (!$path) {
return [$base ? $base . '.' . $field : $field => $data[$field]];
} else {
return static::values($data[$field], $path, $base ? $base . '.' . $field : $field);
}
}
|
[
"public",
"static",
"function",
"values",
"(",
"$",
"data",
",",
"$",
"path",
"=",
"[",
"]",
",",
"$",
"base",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"base",
"=",
"$",
"base",
"?",
":",
"0",
";",
"return",
"[",
"$",
"base",
"=>",
"$",
"data",
"]",
";",
"}",
"$",
"field",
"=",
"array_shift",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"field",
"===",
"'*'",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"values",
",",
"static",
"::",
"values",
"(",
"$",
"value",
",",
"$",
"path",
",",
"$",
"base",
".",
"'.'",
".",
"$",
"key",
")",
")",
";",
"}",
"return",
"$",
"values",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"elseif",
"(",
"!",
"$",
"path",
")",
"{",
"return",
"[",
"$",
"base",
"?",
"$",
"base",
".",
"'.'",
".",
"$",
"field",
":",
"$",
"field",
"=>",
"$",
"data",
"[",
"$",
"field",
"]",
"]",
";",
"}",
"else",
"{",
"return",
"static",
"::",
"values",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
",",
"$",
"path",
",",
"$",
"base",
"?",
"$",
"base",
".",
"'.'",
".",
"$",
"field",
":",
"$",
"field",
")",
";",
"}",
"}"
] |
Extracts all values corresponding to a field names path.
@param array $data The data.
@param array $path An array of field names.
@param array $base The dotted fielname path of the data.
@return array The extracted values.
|
[
"Extracts",
"all",
"values",
"corresponding",
"to",
"a",
"field",
"names",
"path",
"."
] |
37070c0753351f250096c8495874544fbb6620cb
|
https://github.com/crysalead/validator/blob/37070c0753351f250096c8495874544fbb6620cb/src/Validator.php#L397-L419
|
237,164
|
kherge-abandoned/Wisdom
|
src/lib/KevinGH/Wisdom/Wisdom.php
|
Wisdom.addLoader
|
public function addLoader(Loader $loader)
{
$loader->setLocator($this->locator);
$this->resolver->addLoader($loader);
}
|
php
|
public function addLoader(Loader $loader)
{
$loader->setLocator($this->locator);
$this->resolver->addLoader($loader);
}
|
[
"public",
"function",
"addLoader",
"(",
"Loader",
"$",
"loader",
")",
"{",
"$",
"loader",
"->",
"setLocator",
"(",
"$",
"this",
"->",
"locator",
")",
";",
"$",
"this",
"->",
"resolver",
"->",
"addLoader",
"(",
"$",
"loader",
")",
";",
"}"
] |
Adds the loader.
@param Loader $loader The loader.
|
[
"Adds",
"the",
"loader",
"."
] |
eb5b1dadde0729f2ccd1b241c2cecebc778e22f3
|
https://github.com/kherge-abandoned/Wisdom/blob/eb5b1dadde0729f2ccd1b241c2cecebc778e22f3/src/lib/KevinGH/Wisdom/Wisdom.php#L98-L103
|
237,165
|
kherge-abandoned/Wisdom
|
src/lib/KevinGH/Wisdom/Wisdom.php
|
Wisdom.get
|
public function get($file, $values = null, array &$imported = array())
{
if ((null !== $values) && (false === is_array($values))) {
if (false === ($values instanceof ArrayAccess)) {
throw new InvalidArgumentException(
'The value of $values is not an array or an instance of ArrayAccess.'
);
}
}
if (null !== $values) {
$values = $this->mergeValues($this->values, $values);
} else {
$values = $this->values;
}
$new = dirname($file) . DIRECTORY_SEPARATOR . $this->prefix . basename($file);
try {
$found = $this->locator->locate($new);
} catch (InvalidArgumentException $first) {
if (empty($this->prefix)) {
throw $first;
}
try {
$found = $this->locator->locate($file);
} catch (InvalidArgumentException $second) {
throw $first;
}
}
if (in_array($found, $imported)) {
throw new LogicException(sprintf(
'Circular dependency detected for: %s',
$found
));
}
$imported[] = $found;
if (false === empty($this->cache)) {
$cache = new ConfigCache(
$this->cache . DIRECTORY_SEPARATOR . $file . '.php',
$this->debug
);
if ($cache->isFresh()) {
return $this->import(require $cache, $values, $imported);
}
}
if (false === ($loader = $this->resolver->resolve($file))) {
throw new InvalidArgumentException(sprintf(
'No loader available for file: %s',
$file
));
}
$loader->setValues($values);
$data = $loader->load($found);
if (isset($cache)) {
$cache->write(
'<?php return ' . var_export($data, true) . ';',
array(new FileResource($found))
);
}
return $this->import($data, $values, $imported);
}
|
php
|
public function get($file, $values = null, array &$imported = array())
{
if ((null !== $values) && (false === is_array($values))) {
if (false === ($values instanceof ArrayAccess)) {
throw new InvalidArgumentException(
'The value of $values is not an array or an instance of ArrayAccess.'
);
}
}
if (null !== $values) {
$values = $this->mergeValues($this->values, $values);
} else {
$values = $this->values;
}
$new = dirname($file) . DIRECTORY_SEPARATOR . $this->prefix . basename($file);
try {
$found = $this->locator->locate($new);
} catch (InvalidArgumentException $first) {
if (empty($this->prefix)) {
throw $first;
}
try {
$found = $this->locator->locate($file);
} catch (InvalidArgumentException $second) {
throw $first;
}
}
if (in_array($found, $imported)) {
throw new LogicException(sprintf(
'Circular dependency detected for: %s',
$found
));
}
$imported[] = $found;
if (false === empty($this->cache)) {
$cache = new ConfigCache(
$this->cache . DIRECTORY_SEPARATOR . $file . '.php',
$this->debug
);
if ($cache->isFresh()) {
return $this->import(require $cache, $values, $imported);
}
}
if (false === ($loader = $this->resolver->resolve($file))) {
throw new InvalidArgumentException(sprintf(
'No loader available for file: %s',
$file
));
}
$loader->setValues($values);
$data = $loader->load($found);
if (isset($cache)) {
$cache->write(
'<?php return ' . var_export($data, true) . ';',
array(new FileResource($found))
);
}
return $this->import($data, $values, $imported);
}
|
[
"public",
"function",
"get",
"(",
"$",
"file",
",",
"$",
"values",
"=",
"null",
",",
"array",
"&",
"$",
"imported",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"(",
"null",
"!==",
"$",
"values",
")",
"&&",
"(",
"false",
"===",
"is_array",
"(",
"$",
"values",
")",
")",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"values",
"instanceof",
"ArrayAccess",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The value of $values is not an array or an instance of ArrayAccess.'",
")",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"values",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"mergeValues",
"(",
"$",
"this",
"->",
"values",
",",
"$",
"values",
")",
";",
"}",
"else",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"values",
";",
"}",
"$",
"new",
"=",
"dirname",
"(",
"$",
"file",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"prefix",
".",
"basename",
"(",
"$",
"file",
")",
";",
"try",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"locator",
"->",
"locate",
"(",
"$",
"new",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"first",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"prefix",
")",
")",
"{",
"throw",
"$",
"first",
";",
"}",
"try",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"locator",
"->",
"locate",
"(",
"$",
"file",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"second",
")",
"{",
"throw",
"$",
"first",
";",
"}",
"}",
"if",
"(",
"in_array",
"(",
"$",
"found",
",",
"$",
"imported",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'Circular dependency detected for: %s'",
",",
"$",
"found",
")",
")",
";",
"}",
"$",
"imported",
"[",
"]",
"=",
"$",
"found",
";",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"this",
"->",
"cache",
")",
")",
"{",
"$",
"cache",
"=",
"new",
"ConfigCache",
"(",
"$",
"this",
"->",
"cache",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
".",
"'.php'",
",",
"$",
"this",
"->",
"debug",
")",
";",
"if",
"(",
"$",
"cache",
"->",
"isFresh",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"import",
"(",
"require",
"$",
"cache",
",",
"$",
"values",
",",
"$",
"imported",
")",
";",
"}",
"}",
"if",
"(",
"false",
"===",
"(",
"$",
"loader",
"=",
"$",
"this",
"->",
"resolver",
"->",
"resolve",
"(",
"$",
"file",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No loader available for file: %s'",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"loader",
"->",
"setValues",
"(",
"$",
"values",
")",
";",
"$",
"data",
"=",
"$",
"loader",
"->",
"load",
"(",
"$",
"found",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"cache",
")",
")",
"{",
"$",
"cache",
"->",
"write",
"(",
"'<?php return '",
".",
"var_export",
"(",
"$",
"data",
",",
"true",
")",
".",
"';'",
",",
"array",
"(",
"new",
"FileResource",
"(",
"$",
"found",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"import",
"(",
"$",
"data",
",",
"$",
"values",
",",
"$",
"imported",
")",
";",
"}"
] |
Returns the data for the configuration file.
@param string $file The file name.
@param array|object $values The new replacement values.
@param array &$imported The list of imported resources.
@return array The configuration data.
@throws InvalidArgumentException If the value is not supported.
@throws LogicException If a circular dependency is detected.
|
[
"Returns",
"the",
"data",
"for",
"the",
"configuration",
"file",
"."
] |
eb5b1dadde0729f2ccd1b241c2cecebc778e22f3
|
https://github.com/kherge-abandoned/Wisdom/blob/eb5b1dadde0729f2ccd1b241c2cecebc778e22f3/src/lib/KevinGH/Wisdom/Wisdom.php#L117-L188
|
237,166
|
kherge-abandoned/Wisdom
|
src/lib/KevinGH/Wisdom/Wisdom.php
|
Wisdom.import
|
public function import(array $data, $values = null, array &$imported = array())
{
if (false === isset($data['imports'])) {
return $data;
}
$imports = $data['imports'];
unset($data['imports']);
foreach ($imports as $resource) {
$data = array_replace_recursive(
$this->get($resource, $values, $imported),
$data
);
}
return $data;
}
|
php
|
public function import(array $data, $values = null, array &$imported = array())
{
if (false === isset($data['imports'])) {
return $data;
}
$imports = $data['imports'];
unset($data['imports']);
foreach ($imports as $resource) {
$data = array_replace_recursive(
$this->get($resource, $values, $imported),
$data
);
}
return $data;
}
|
[
"public",
"function",
"import",
"(",
"array",
"$",
"data",
",",
"$",
"values",
"=",
"null",
",",
"array",
"&",
"$",
"imported",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"data",
"[",
"'imports'",
"]",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"imports",
"=",
"$",
"data",
"[",
"'imports'",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"'imports'",
"]",
")",
";",
"foreach",
"(",
"$",
"imports",
"as",
"$",
"resource",
")",
"{",
"$",
"data",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"resource",
",",
"$",
"values",
",",
"$",
"imported",
")",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Manages the "imports" directive in configuration files.
@param array $data The current data.
@param array|object $values The new replacement values.
@param array &$imported The list of imported resources.
@return array The data merged with the imported resources.
@throws LogicException If a circular reference is detected.
|
[
"Manages",
"the",
"imports",
"directive",
"in",
"configuration",
"files",
"."
] |
eb5b1dadde0729f2ccd1b241c2cecebc778e22f3
|
https://github.com/kherge-abandoned/Wisdom/blob/eb5b1dadde0729f2ccd1b241c2cecebc778e22f3/src/lib/KevinGH/Wisdom/Wisdom.php#L201-L219
|
237,167
|
kherge-abandoned/Wisdom
|
src/lib/KevinGH/Wisdom/Wisdom.php
|
Wisdom.setValues
|
public function setValues($values)
{
if ((null !== $values) && (false === is_array($values))) {
if (false === ($values instanceof ArrayAccess)) {
throw new InvalidArgumentException(
'The value of $values is not an array or an instance of ArrayAccess.'
);
}
}
$this->values = $values;
}
|
php
|
public function setValues($values)
{
if ((null !== $values) && (false === is_array($values))) {
if (false === ($values instanceof ArrayAccess)) {
throw new InvalidArgumentException(
'The value of $values is not an array or an instance of ArrayAccess.'
);
}
}
$this->values = $values;
}
|
[
"public",
"function",
"setValues",
"(",
"$",
"values",
")",
"{",
"if",
"(",
"(",
"null",
"!==",
"$",
"values",
")",
"&&",
"(",
"false",
"===",
"is_array",
"(",
"$",
"values",
")",
")",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"values",
"instanceof",
"ArrayAccess",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The value of $values is not an array or an instance of ArrayAccess.'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"values",
"=",
"$",
"values",
";",
"}"
] |
Sets the default replacement values.
@param array|object The replacement values.
@throws InvalidArgumentException If the value is not supported.
|
[
"Sets",
"the",
"default",
"replacement",
"values",
"."
] |
eb5b1dadde0729f2ccd1b241c2cecebc778e22f3
|
https://github.com/kherge-abandoned/Wisdom/blob/eb5b1dadde0729f2ccd1b241c2cecebc778e22f3/src/lib/KevinGH/Wisdom/Wisdom.php#L258-L269
|
237,168
|
kherge-abandoned/Wisdom
|
src/lib/KevinGH/Wisdom/Wisdom.php
|
Wisdom.mergeValues
|
private function mergeValues($a, $b)
{
$x = array();
$y = array();
if (is_array($a)) {
$x = $a;
}
foreach ($b as $key => $value) {
$x[$key] = $value;
}
return $x;
}
|
php
|
private function mergeValues($a, $b)
{
$x = array();
$y = array();
if (is_array($a)) {
$x = $a;
}
foreach ($b as $key => $value) {
$x[$key] = $value;
}
return $x;
}
|
[
"private",
"function",
"mergeValues",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"x",
"=",
"array",
"(",
")",
";",
"$",
"y",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"a",
")",
")",
"{",
"$",
"x",
"=",
"$",
"a",
";",
"}",
"foreach",
"(",
"$",
"b",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"x",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"x",
";",
"}"
] |
Merges two sets of replacement values.
@param array|object $a The replacement values.
@param array|object $b The replacement values.
@return array The merged values.
|
[
"Merges",
"two",
"sets",
"of",
"replacement",
"values",
"."
] |
eb5b1dadde0729f2ccd1b241c2cecebc778e22f3
|
https://github.com/kherge-abandoned/Wisdom/blob/eb5b1dadde0729f2ccd1b241c2cecebc778e22f3/src/lib/KevinGH/Wisdom/Wisdom.php#L279-L293
|
237,169
|
Softpampa/moip-sdk-php
|
src/Subscriptions/Resources/Subscriptions.php
|
Subscriptions.suspend
|
public function suspend($code = null)
{
if (! $code) {
$code = $this->data->code;
}
$response = $this->client->put('/{code}/suspend', [$code]);
if (! $response->hasErrors()) {
$this->event->dispatch('SUBSCRIPTION.SUSPENDED', new SubscriptionsEvent($this->data));
}
return $this;
}
|
php
|
public function suspend($code = null)
{
if (! $code) {
$code = $this->data->code;
}
$response = $this->client->put('/{code}/suspend', [$code]);
if (! $response->hasErrors()) {
$this->event->dispatch('SUBSCRIPTION.SUSPENDED', new SubscriptionsEvent($this->data));
}
return $this;
}
|
[
"public",
"function",
"suspend",
"(",
"$",
"code",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"code",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"data",
"->",
"code",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"put",
"(",
"'/{code}/suspend'",
",",
"[",
"$",
"code",
"]",
")",
";",
"if",
"(",
"!",
"$",
"response",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"event",
"->",
"dispatch",
"(",
"'SUBSCRIPTION.SUSPENDED'",
",",
"new",
"SubscriptionsEvent",
"(",
"$",
"this",
"->",
"data",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Suspend a subscription
@param string $code
@return $this
|
[
"Suspend",
"a",
"subscription"
] |
621a71bd2ef1f9b690cd3431507af608152f6ad2
|
https://github.com/Softpampa/moip-sdk-php/blob/621a71bd2ef1f9b690cd3431507af608152f6ad2/src/Subscriptions/Resources/Subscriptions.php#L85-L98
|
237,170
|
Softpampa/moip-sdk-php
|
src/Subscriptions/Resources/Subscriptions.php
|
Subscriptions.setNextInvoiceDate
|
public function setNextInvoiceDate($date)
{
$date = DateTime::createFromFormat('Y-m-d', $date);
$this->next_invoice_date = new stdClass();
$this->next_invoice_date->day = $date->format('d');
$this->next_invoice_date->month = $date->format('m');
$this->next_invoice_date->year = $date->format('Y');
return $this;
}
|
php
|
public function setNextInvoiceDate($date)
{
$date = DateTime::createFromFormat('Y-m-d', $date);
$this->next_invoice_date = new stdClass();
$this->next_invoice_date->day = $date->format('d');
$this->next_invoice_date->month = $date->format('m');
$this->next_invoice_date->year = $date->format('Y');
return $this;
}
|
[
"public",
"function",
"setNextInvoiceDate",
"(",
"$",
"date",
")",
"{",
"$",
"date",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"'Y-m-d'",
",",
"$",
"date",
")",
";",
"$",
"this",
"->",
"next_invoice_date",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"this",
"->",
"next_invoice_date",
"->",
"day",
"=",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
";",
"$",
"this",
"->",
"next_invoice_date",
"->",
"month",
"=",
"$",
"date",
"->",
"format",
"(",
"'m'",
")",
";",
"$",
"this",
"->",
"next_invoice_date",
"->",
"year",
"=",
"$",
"date",
"->",
"format",
"(",
"'Y'",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set next invoice date
@param string $date
@return $this
|
[
"Set",
"next",
"invoice",
"date"
] |
621a71bd2ef1f9b690cd3431507af608152f6ad2
|
https://github.com/Softpampa/moip-sdk-php/blob/621a71bd2ef1f9b690cd3431507af608152f6ad2/src/Subscriptions/Resources/Subscriptions.php#L202-L212
|
237,171
|
Softpampa/moip-sdk-php
|
src/Subscriptions/Resources/Subscriptions.php
|
Subscriptions.setNewCustomer
|
public function setNewCustomer(Customers $customer)
{
$this->client->addQueryString('new_customer', true);
$this->data->customer = $customer->jsonSerialize();
return $this;
}
|
php
|
public function setNewCustomer(Customers $customer)
{
$this->client->addQueryString('new_customer', true);
$this->data->customer = $customer->jsonSerialize();
return $this;
}
|
[
"public",
"function",
"setNewCustomer",
"(",
"Customers",
"$",
"customer",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"addQueryString",
"(",
"'new_customer'",
",",
"true",
")",
";",
"$",
"this",
"->",
"data",
"->",
"customer",
"=",
"$",
"customer",
"->",
"jsonSerialize",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set New Customer
@param Customers $customer
@return $this
|
[
"Set",
"New",
"Customer"
] |
621a71bd2ef1f9b690cd3431507af608152f6ad2
|
https://github.com/Softpampa/moip-sdk-php/blob/621a71bd2ef1f9b690cd3431507af608152f6ad2/src/Subscriptions/Resources/Subscriptions.php#L267-L274
|
237,172
|
fazland/elastica-odm
|
src/Configuration.php
|
Configuration.getRepositoryFactory
|
public function getRepositoryFactory(): RepositoryFactoryInterface
{
if (null !== $this->repositoryFactory) {
return $this->repositoryFactory;
}
$factory = new DefaultRepositoryFactory();
$factory->setDefaultRepositoryClassName($this->getDefaultRepositoryClassName());
return $factory;
}
|
php
|
public function getRepositoryFactory(): RepositoryFactoryInterface
{
if (null !== $this->repositoryFactory) {
return $this->repositoryFactory;
}
$factory = new DefaultRepositoryFactory();
$factory->setDefaultRepositoryClassName($this->getDefaultRepositoryClassName());
return $factory;
}
|
[
"public",
"function",
"getRepositoryFactory",
"(",
")",
":",
"RepositoryFactoryInterface",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"repositoryFactory",
")",
"{",
"return",
"$",
"this",
"->",
"repositoryFactory",
";",
"}",
"$",
"factory",
"=",
"new",
"DefaultRepositoryFactory",
"(",
")",
";",
"$",
"factory",
"->",
"setDefaultRepositoryClassName",
"(",
"$",
"this",
"->",
"getDefaultRepositoryClassName",
"(",
")",
")",
";",
"return",
"$",
"factory",
";",
"}"
] |
Sets the repository factory.
@return RepositoryFactoryInterface
|
[
"Sets",
"the",
"repository",
"factory",
"."
] |
9d7276ea9ea9103c670f13f889bf59568ff35274
|
https://github.com/fazland/elastica-odm/blob/9d7276ea9ea9103c670f13f889bf59568ff35274/src/Configuration.php#L195-L205
|
237,173
|
marando/phpSOFA
|
src/Marando/IAU/iauUtctai.php
|
iauUtctai.Utctai
|
public static function Utctai($utc1, $utc2, &$tai1, &$tai2) {
$big1;
$iy;
$im;
$id;
$j;
$iyt;
$imt;
$idt;
$u1;
$u2;
$fd;
$dat0;
$dat12;
$w;
$dat24;
$dlod;
$dleap;
$z1;
$z2;
$a2;
/* Put the two parts of the UTC into big-first order. */
$big1 = ( $utc1 >= $utc2 );
if ($big1) {
$u1 = $utc1;
$u2 = $utc2;
}
else {
$u1 = $utc2;
$u2 = $utc1;
}
/* Get TAI-UTC at 0h today. */
$j = IAU::Jd2cal($u1, $u2, $iy, $im, $id, $fd);
if ($j !=0 )
return j;
$j = IAU::Dat($iy, $im, $id, 0.0, $dat0);
if ($j < 0)
return $j;
/* Get TAI-UTC at 12h today (to detect drift). */
$j = IAU::Dat($iy, $im, $id, 0.5, $dat12);
if ($j < 0)
return $j;
/* Get TAI-UTC at 0h tomorrow (to detect jumps). */
$j = IAU::Jd2cal($u1 + 1.5, $u2 - $fd, $iyt, $imt, $idt, $w);
if ($j!=0)
return $j;
$j = IAU::Dat($iyt, $imt, $idt, 0.0, $dat24);
if ($j < 0)
return $j;
/* Separate TAI-UTC change into per-day (DLOD) and any jump (DLEAP). */
$dlod = 2.0 * ($dat12 - $dat0);
$dleap = $dat24 - ($dat0 + $dlod);
/* Remove any scaling applied to spread leap into preceding day. */
$fd *= (DAYSEC + $dleap) / DAYSEC;
/* Scale from (pre-1972) UTC seconds to SI seconds. */
$fd *= (DAYSEC + $dlod) / DAYSEC;
/* Today's calendar date to 2-part JD. */
if (IAU::Cal2jd($iy, $im, $id, $z1, $z2))
return -1;
/* Assemble the TAI result, preserving the UTC split and order. */
$a2 = $z1 - $u1;
$a2 += $z2;
$a2 += $fd + $dat0 / DAYSEC;
if ($big1) {
$tai1 = $u1;
$tai2 = $a2;
}
else {
$tai1 = $a2;
$tai2 = $u1;
}
/* Status. */
return $j;
}
|
php
|
public static function Utctai($utc1, $utc2, &$tai1, &$tai2) {
$big1;
$iy;
$im;
$id;
$j;
$iyt;
$imt;
$idt;
$u1;
$u2;
$fd;
$dat0;
$dat12;
$w;
$dat24;
$dlod;
$dleap;
$z1;
$z2;
$a2;
/* Put the two parts of the UTC into big-first order. */
$big1 = ( $utc1 >= $utc2 );
if ($big1) {
$u1 = $utc1;
$u2 = $utc2;
}
else {
$u1 = $utc2;
$u2 = $utc1;
}
/* Get TAI-UTC at 0h today. */
$j = IAU::Jd2cal($u1, $u2, $iy, $im, $id, $fd);
if ($j !=0 )
return j;
$j = IAU::Dat($iy, $im, $id, 0.0, $dat0);
if ($j < 0)
return $j;
/* Get TAI-UTC at 12h today (to detect drift). */
$j = IAU::Dat($iy, $im, $id, 0.5, $dat12);
if ($j < 0)
return $j;
/* Get TAI-UTC at 0h tomorrow (to detect jumps). */
$j = IAU::Jd2cal($u1 + 1.5, $u2 - $fd, $iyt, $imt, $idt, $w);
if ($j!=0)
return $j;
$j = IAU::Dat($iyt, $imt, $idt, 0.0, $dat24);
if ($j < 0)
return $j;
/* Separate TAI-UTC change into per-day (DLOD) and any jump (DLEAP). */
$dlod = 2.0 * ($dat12 - $dat0);
$dleap = $dat24 - ($dat0 + $dlod);
/* Remove any scaling applied to spread leap into preceding day. */
$fd *= (DAYSEC + $dleap) / DAYSEC;
/* Scale from (pre-1972) UTC seconds to SI seconds. */
$fd *= (DAYSEC + $dlod) / DAYSEC;
/* Today's calendar date to 2-part JD. */
if (IAU::Cal2jd($iy, $im, $id, $z1, $z2))
return -1;
/* Assemble the TAI result, preserving the UTC split and order. */
$a2 = $z1 - $u1;
$a2 += $z2;
$a2 += $fd + $dat0 / DAYSEC;
if ($big1) {
$tai1 = $u1;
$tai2 = $a2;
}
else {
$tai1 = $a2;
$tai2 = $u1;
}
/* Status. */
return $j;
}
|
[
"public",
"static",
"function",
"Utctai",
"(",
"$",
"utc1",
",",
"$",
"utc2",
",",
"&",
"$",
"tai1",
",",
"&",
"$",
"tai2",
")",
"{",
"$",
"big1",
";",
"$",
"iy",
";",
"$",
"im",
";",
"$",
"id",
";",
"$",
"j",
";",
"$",
"iyt",
";",
"$",
"imt",
";",
"$",
"idt",
";",
"$",
"u1",
";",
"$",
"u2",
";",
"$",
"fd",
";",
"$",
"dat0",
";",
"$",
"dat12",
";",
"$",
"w",
";",
"$",
"dat24",
";",
"$",
"dlod",
";",
"$",
"dleap",
";",
"$",
"z1",
";",
"$",
"z2",
";",
"$",
"a2",
";",
"/* Put the two parts of the UTC into big-first order. */",
"$",
"big1",
"=",
"(",
"$",
"utc1",
">=",
"$",
"utc2",
")",
";",
"if",
"(",
"$",
"big1",
")",
"{",
"$",
"u1",
"=",
"$",
"utc1",
";",
"$",
"u2",
"=",
"$",
"utc2",
";",
"}",
"else",
"{",
"$",
"u1",
"=",
"$",
"utc2",
";",
"$",
"u2",
"=",
"$",
"utc1",
";",
"}",
"/* Get TAI-UTC at 0h today. */",
"$",
"j",
"=",
"IAU",
"::",
"Jd2cal",
"(",
"$",
"u1",
",",
"$",
"u2",
",",
"$",
"iy",
",",
"$",
"im",
",",
"$",
"id",
",",
"$",
"fd",
")",
";",
"if",
"(",
"$",
"j",
"!=",
"0",
")",
"return",
"j",
";",
"$",
"j",
"=",
"IAU",
"::",
"Dat",
"(",
"$",
"iy",
",",
"$",
"im",
",",
"$",
"id",
",",
"0.0",
",",
"$",
"dat0",
")",
";",
"if",
"(",
"$",
"j",
"<",
"0",
")",
"return",
"$",
"j",
";",
"/* Get TAI-UTC at 12h today (to detect drift). */",
"$",
"j",
"=",
"IAU",
"::",
"Dat",
"(",
"$",
"iy",
",",
"$",
"im",
",",
"$",
"id",
",",
"0.5",
",",
"$",
"dat12",
")",
";",
"if",
"(",
"$",
"j",
"<",
"0",
")",
"return",
"$",
"j",
";",
"/* Get TAI-UTC at 0h tomorrow (to detect jumps). */",
"$",
"j",
"=",
"IAU",
"::",
"Jd2cal",
"(",
"$",
"u1",
"+",
"1.5",
",",
"$",
"u2",
"-",
"$",
"fd",
",",
"$",
"iyt",
",",
"$",
"imt",
",",
"$",
"idt",
",",
"$",
"w",
")",
";",
"if",
"(",
"$",
"j",
"!=",
"0",
")",
"return",
"$",
"j",
";",
"$",
"j",
"=",
"IAU",
"::",
"Dat",
"(",
"$",
"iyt",
",",
"$",
"imt",
",",
"$",
"idt",
",",
"0.0",
",",
"$",
"dat24",
")",
";",
"if",
"(",
"$",
"j",
"<",
"0",
")",
"return",
"$",
"j",
";",
"/* Separate TAI-UTC change into per-day (DLOD) and any jump (DLEAP). */",
"$",
"dlod",
"=",
"2.0",
"*",
"(",
"$",
"dat12",
"-",
"$",
"dat0",
")",
";",
"$",
"dleap",
"=",
"$",
"dat24",
"-",
"(",
"$",
"dat0",
"+",
"$",
"dlod",
")",
";",
"/* Remove any scaling applied to spread leap into preceding day. */",
"$",
"fd",
"*=",
"(",
"DAYSEC",
"+",
"$",
"dleap",
")",
"/",
"DAYSEC",
";",
"/* Scale from (pre-1972) UTC seconds to SI seconds. */",
"$",
"fd",
"*=",
"(",
"DAYSEC",
"+",
"$",
"dlod",
")",
"/",
"DAYSEC",
";",
"/* Today's calendar date to 2-part JD. */",
"if",
"(",
"IAU",
"::",
"Cal2jd",
"(",
"$",
"iy",
",",
"$",
"im",
",",
"$",
"id",
",",
"$",
"z1",
",",
"$",
"z2",
")",
")",
"return",
"-",
"1",
";",
"/* Assemble the TAI result, preserving the UTC split and order. */",
"$",
"a2",
"=",
"$",
"z1",
"-",
"$",
"u1",
";",
"$",
"a2",
"+=",
"$",
"z2",
";",
"$",
"a2",
"+=",
"$",
"fd",
"+",
"$",
"dat0",
"/",
"DAYSEC",
";",
"if",
"(",
"$",
"big1",
")",
"{",
"$",
"tai1",
"=",
"$",
"u1",
";",
"$",
"tai2",
"=",
"$",
"a2",
";",
"}",
"else",
"{",
"$",
"tai1",
"=",
"$",
"a2",
";",
"$",
"tai2",
"=",
"$",
"u1",
";",
"}",
"/* Status. */",
"return",
"$",
"j",
";",
"}"
] |
- - - - - - - - - -
i a u U t c t a i
- - - - - - - - - -
Time scale transformation: Coordinated Universal Time, UTC, to
International Atomic Time, TAI.
This function is part of the International Astronomical Union's
SOFA (Standards of Fundamental Astronomy) software collection.
Status: canonical.
Given:
utc1,utc2 double UTC as a 2-part quasi Julian Date (Notes 1-4)
Returned:
tai1,tai2 double TAI as a 2-part Julian Date (Note 5)
Returned (function value):
int status: +1 = dubious year (Note 3)
0 = OK
-1 = unacceptable date
Notes:
1) utc1+utc2 is quasi Julian Date (see Note 2), apportioned in any
convenient way between the two arguments, for example where utc1
is the Julian Day Number and utc2 is the fraction of a day.
2) JD cannot unambiguously represent UTC during a leap second unless
special measures are taken. The convention in the present
function is that the JD day represents UTC days whether the
length is 86399, 86400 or 86401 SI seconds. In the 1960-1972 era
there were smaller jumps (in either direction) each time the
linear UTC(TAI) expression was changed, and these "mini-leaps"
are also included in the SOFA convention.
3) The warning status "dubious year" flags UTCs that predate the
introduction of the time scale or that are too far in the future
to be trusted. See iauDat for further details.
4) The function iauDtf2d converts from calendar date and time of day
into 2-part Julian Date, and in the case of UTC implements the
leap-second-ambiguity convention described above.
5) The returned TAI1,TAI2 are such that their sum is the TAI Julian
Date.
Called:
iauJd2cal JD to Gregorian calendar
iauDat delta(AT) = TAI-UTC
iauCal2jd Gregorian calendar to JD
References:
McCarthy, D. D., Petit, G. (eds.), IERS Conventions (2003),
IERS Technical Note No. 32, BKG (2004)
Explanatory Supplement to the Astronomical Almanac,
P. Kenneth Seidelmann (ed), University Science Books (1992)
This revision: 2013 July 26
SOFA release 2015-02-09
Copyright (C) 2015 IAU SOFA Board. See notes at end.
|
[
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"i",
"a",
"u",
"U",
"t",
"c",
"t",
"a",
"i",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
] |
757fa49fe335ae1210eaa7735473fd4388b13f07
|
https://github.com/marando/phpSOFA/blob/757fa49fe335ae1210eaa7735473fd4388b13f07/src/Marando/IAU/iauUtctai.php#L76-L159
|
237,174
|
slickframework/mvc
|
src/Router/Builder/RouteFactory.php
|
RouteFactory.simpleRoute
|
protected function simpleRoute($name, $data)
{
if (is_string($data)) {
return $this->map->get($name, $data);
}
return $this->createRoute($name, $data);
}
|
php
|
protected function simpleRoute($name, $data)
{
if (is_string($data)) {
return $this->map->get($name, $data);
}
return $this->createRoute($name, $data);
}
|
[
"protected",
"function",
"simpleRoute",
"(",
"$",
"name",
",",
"$",
"data",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"map",
"->",
"get",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createRoute",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"}"
] |
Check if the data is a simple string, create a get with it
If not a string pass the data to the construction chain where the route
will be set with the data array passed
@param string $name The route name
@param string|array $data Meta data fo the route
@return Route
|
[
"Check",
"if",
"the",
"data",
"is",
"a",
"simple",
"string",
"create",
"a",
"get",
"with",
"it"
] |
91a6c512f8aaa5a7fb9c1a96f8012d2274dc30ab
|
https://github.com/slickframework/mvc/blob/91a6c512f8aaa5a7fb9c1a96f8012d2274dc30ab/src/Router/Builder/RouteFactory.php#L55-L61
|
237,175
|
slickframework/mvc
|
src/Router/Builder/RouteFactory.php
|
RouteFactory.setRouteProperties
|
protected function setRouteProperties(Route $route, array $data)
{
$methods = get_class_methods(Route::class);
$methods = array_diff($methods, ["allows", "path"]);
foreach($data as $method => $args) {
if (in_array($method, $methods)) {
$route->$method($args);
}
}
return $route;
}
|
php
|
protected function setRouteProperties(Route $route, array $data)
{
$methods = get_class_methods(Route::class);
$methods = array_diff($methods, ["allows", "path"]);
foreach($data as $method => $args) {
if (in_array($method, $methods)) {
$route->$method($args);
}
}
return $route;
}
|
[
"protected",
"function",
"setRouteProperties",
"(",
"Route",
"$",
"route",
",",
"array",
"$",
"data",
")",
"{",
"$",
"methods",
"=",
"get_class_methods",
"(",
"Route",
"::",
"class",
")",
";",
"$",
"methods",
"=",
"array_diff",
"(",
"$",
"methods",
",",
"[",
"\"allows\"",
",",
"\"path\"",
"]",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"method",
"=>",
"$",
"args",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"$",
"methods",
")",
")",
"{",
"$",
"route",
"->",
"$",
"method",
"(",
"$",
"args",
")",
";",
"}",
"}",
"return",
"$",
"route",
";",
"}"
] |
Parses data array to set route properties
@param Route $route
@param array $data
@return Route
|
[
"Parses",
"data",
"array",
"to",
"set",
"route",
"properties"
] |
91a6c512f8aaa5a7fb9c1a96f8012d2274dc30ab
|
https://github.com/slickframework/mvc/blob/91a6c512f8aaa5a7fb9c1a96f8012d2274dc30ab/src/Router/Builder/RouteFactory.php#L93-L103
|
237,176
|
wollanup/php-api-rest
|
src/Service/Request/QueryModifier/Modifier/Base/ModifierBase.php
|
ModifierBase.apply
|
public function apply(ModelCriteria $query)
{
if (!empty($this->modifiers)) {
foreach ($this->modifiers as $modifier) {
if ($this->hasAllRequiredData($modifier)) {
$modifier['property'] = str_replace('/', '.', $modifier['property']);
# Check if the filter is occurring on a related model
if (strpos($modifier['property'], '.') !== false) {
$propertyParts = explode('.', $modifier['property']);
# The last part is the related property we want to filter with, so remove it from the parts and store into a variable
$propertyField = array_pop($propertyParts);
# The new last part is the relation name
$relationName = array_pop($propertyParts);
# Apply the modifier
$this->applyModifier($query, $this->buildClause($propertyField, $relationName), $modifier);
} else {
# Apply the modifier
$this->applyModifier($query,
$this->buildClause($modifier['property'], $query->getModelShortName()),
$modifier);
}
}
}
}
}
|
php
|
public function apply(ModelCriteria $query)
{
if (!empty($this->modifiers)) {
foreach ($this->modifiers as $modifier) {
if ($this->hasAllRequiredData($modifier)) {
$modifier['property'] = str_replace('/', '.', $modifier['property']);
# Check if the filter is occurring on a related model
if (strpos($modifier['property'], '.') !== false) {
$propertyParts = explode('.', $modifier['property']);
# The last part is the related property we want to filter with, so remove it from the parts and store into a variable
$propertyField = array_pop($propertyParts);
# The new last part is the relation name
$relationName = array_pop($propertyParts);
# Apply the modifier
$this->applyModifier($query, $this->buildClause($propertyField, $relationName), $modifier);
} else {
# Apply the modifier
$this->applyModifier($query,
$this->buildClause($modifier['property'], $query->getModelShortName()),
$modifier);
}
}
}
}
}
|
[
"public",
"function",
"apply",
"(",
"ModelCriteria",
"$",
"query",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"modifiers",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modifiers",
"as",
"$",
"modifier",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasAllRequiredData",
"(",
"$",
"modifier",
")",
")",
"{",
"$",
"modifier",
"[",
"'property'",
"]",
"=",
"str_replace",
"(",
"'/'",
",",
"'.'",
",",
"$",
"modifier",
"[",
"'property'",
"]",
")",
";",
"# Check if the filter is occurring on a related model",
"if",
"(",
"strpos",
"(",
"$",
"modifier",
"[",
"'property'",
"]",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"propertyParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"modifier",
"[",
"'property'",
"]",
")",
";",
"# The last part is the related property we want to filter with, so remove it from the parts and store into a variable",
"$",
"propertyField",
"=",
"array_pop",
"(",
"$",
"propertyParts",
")",
";",
"# The new last part is the relation name",
"$",
"relationName",
"=",
"array_pop",
"(",
"$",
"propertyParts",
")",
";",
"# Apply the modifier",
"$",
"this",
"->",
"applyModifier",
"(",
"$",
"query",
",",
"$",
"this",
"->",
"buildClause",
"(",
"$",
"propertyField",
",",
"$",
"relationName",
")",
",",
"$",
"modifier",
")",
";",
"}",
"else",
"{",
"# Apply the modifier",
"$",
"this",
"->",
"applyModifier",
"(",
"$",
"query",
",",
"$",
"this",
"->",
"buildClause",
"(",
"$",
"modifier",
"[",
"'property'",
"]",
",",
"$",
"query",
"->",
"getModelShortName",
"(",
")",
")",
",",
"$",
"modifier",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Apply the filter to the ModelQuery
@param \Propel\Runtime\ActiveQuery\ModelCriteria $query
|
[
"Apply",
"the",
"filter",
"to",
"the",
"ModelQuery"
] |
185eac8a8412e5997d8e292ebd0e38787ae4b949
|
https://github.com/wollanup/php-api-rest/blob/185eac8a8412e5997d8e292ebd0e38787ae4b949/src/Service/Request/QueryModifier/Modifier/Base/ModifierBase.php#L76-L102
|
237,177
|
CatLabInteractive/Neuron
|
src/Neuron/Tools/Text.php
|
Text.get
|
public static function get ($message1, $message2 = null, $n = null)
{
$in = self::getInstance ();
return $in->getText ($message1, $message2, $n);
}
|
php
|
public static function get ($message1, $message2 = null, $n = null)
{
$in = self::getInstance ();
return $in->getText ($message1, $message2, $n);
}
|
[
"public",
"static",
"function",
"get",
"(",
"$",
"message1",
",",
"$",
"message2",
"=",
"null",
",",
"$",
"n",
"=",
"null",
")",
"{",
"$",
"in",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"return",
"$",
"in",
"->",
"getText",
"(",
"$",
"message1",
",",
"$",
"message2",
",",
"$",
"n",
")",
";",
"}"
] |
Little helper method.
@param string $message1
@param string|null $message2
@param string|null $n
@return string
|
[
"Little",
"helper",
"method",
"."
] |
67dca5349891e23b31a96dcdead893b9491a1b8b
|
https://github.com/CatLabInteractive/Neuron/blob/67dca5349891e23b31a96dcdead893b9491a1b8b/src/Neuron/Tools/Text.php#L70-L74
|
237,178
|
digipolisgent/openbib-id-api
|
src/Value/UserActivities/ExpenseCollection.php
|
ExpenseCollection.fromXml
|
public static function fromXml(\DOMNodeList $xml)
{
$items = array();
foreach ($xml as $xmlTag) {
$items[] = Expense::fromXml($xmlTag);
}
return new static($items);
}
|
php
|
public static function fromXml(\DOMNodeList $xml)
{
$items = array();
foreach ($xml as $xmlTag) {
$items[] = Expense::fromXml($xmlTag);
}
return new static($items);
}
|
[
"public",
"static",
"function",
"fromXml",
"(",
"\\",
"DOMNodeList",
"$",
"xml",
")",
"{",
"$",
"items",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"xml",
"as",
"$",
"xmlTag",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"Expense",
"::",
"fromXml",
"(",
"$",
"xmlTag",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"items",
")",
";",
"}"
] |
Builds a ExpenseCollection object from XML.
@param \DOMNodeList $xml
The list of xml tags representing the expenses.
@return ExpenseCollection
A ExpenseCollection object
|
[
"Builds",
"a",
"ExpenseCollection",
"object",
"from",
"XML",
"."
] |
79f58dec53a91f44333d10fa4ef79f85f31fc2de
|
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Value/UserActivities/ExpenseCollection.php#L18-L25
|
237,179
|
easy-system/es-http
|
src/Factory/UriQueryFactory.php
|
UriQueryFactory.make
|
public static function make(array $server = null)
{
if (empty($server)) {
$server = $_SERVER;
}
if (isset($server['REQUEST_URI'])) {
return parse_url($server['REQUEST_URI'], PHP_URL_QUERY);
}
}
|
php
|
public static function make(array $server = null)
{
if (empty($server)) {
$server = $_SERVER;
}
if (isset($server['REQUEST_URI'])) {
return parse_url($server['REQUEST_URI'], PHP_URL_QUERY);
}
}
|
[
"public",
"static",
"function",
"make",
"(",
"array",
"$",
"server",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"server",
")",
")",
"{",
"$",
"server",
"=",
"$",
"_SERVER",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"{",
"return",
"parse_url",
"(",
"$",
"server",
"[",
"'REQUEST_URI'",
"]",
",",
"PHP_URL_QUERY",
")",
";",
"}",
"}"
] |
Makes a string with Uri query.
@param array $server Optional; null by default or empty array means
global $_SERVER. The source data
@return string|null Returns the Uri query if any, null otherwise
|
[
"Makes",
"a",
"string",
"with",
"Uri",
"query",
"."
] |
dd5852e94901e147a7546a8715133408ece767a1
|
https://github.com/easy-system/es-http/blob/dd5852e94901e147a7546a8715133408ece767a1/src/Factory/UriQueryFactory.php#L25-L34
|
237,180
|
harmony-project/modular-routing
|
source/EventListener/RoutingSubscriber.php
|
RoutingSubscriber.onKernelRequest
|
public function onKernelRequest(GetResponseEvent $event)
{
if (null === $module = $event->getRequest()->get('module')) {
return;
}
if (!$module instanceof ModuleInterface) {
$module = $this->getModularRouter()->getModuleByRequest($event->getRequest());
}
// todo remove current module functionality, as it can lead to unexpected behavior
$this->getModuleManager()->setCurrentModule($module);
}
|
php
|
public function onKernelRequest(GetResponseEvent $event)
{
if (null === $module = $event->getRequest()->get('module')) {
return;
}
if (!$module instanceof ModuleInterface) {
$module = $this->getModularRouter()->getModuleByRequest($event->getRequest());
}
// todo remove current module functionality, as it can lead to unexpected behavior
$this->getModuleManager()->setCurrentModule($module);
}
|
[
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"module",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'module'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"module",
"instanceof",
"ModuleInterface",
")",
"{",
"$",
"module",
"=",
"$",
"this",
"->",
"getModularRouter",
"(",
")",
"->",
"getModuleByRequest",
"(",
"$",
"event",
"->",
"getRequest",
"(",
")",
")",
";",
"}",
"// todo remove current module functionality, as it can lead to unexpected behavior",
"$",
"this",
"->",
"getModuleManager",
"(",
")",
"->",
"setCurrentModule",
"(",
"$",
"module",
")",
";",
"}"
] |
Handles actions before the kernel matches the controller.
@param GetResponseEvent $event
|
[
"Handles",
"actions",
"before",
"the",
"kernel",
"matches",
"the",
"controller",
"."
] |
399bb427678ddc17c67295c738b96faea485e2d8
|
https://github.com/harmony-project/modular-routing/blob/399bb427678ddc17c67295c738b96faea485e2d8/source/EventListener/RoutingSubscriber.php#L78-L90
|
237,181
|
kevindierkx/elicit
|
src/Connector/AbstractConnector.php
|
AbstractConnector.createConnection
|
public function createConnection(array $config)
{
if (! isset($config['host'])) {
throw new InvalidArgumentException("No host provided.");
}
$this->setHost($config['host']);
// We check the configuration for request headers. Some API's require
// certain headers for all requests. Providing them in the configuration
// makes it easier to provide these headers on each request.
if (isset($config['headers'])) {
$this->setHeaders($config['headers']);
}
return $this;
}
|
php
|
public function createConnection(array $config)
{
if (! isset($config['host'])) {
throw new InvalidArgumentException("No host provided.");
}
$this->setHost($config['host']);
// We check the configuration for request headers. Some API's require
// certain headers for all requests. Providing them in the configuration
// makes it easier to provide these headers on each request.
if (isset($config['headers'])) {
$this->setHeaders($config['headers']);
}
return $this;
}
|
[
"public",
"function",
"createConnection",
"(",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'host'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"No host provided.\"",
")",
";",
"}",
"$",
"this",
"->",
"setHost",
"(",
"$",
"config",
"[",
"'host'",
"]",
")",
";",
"// We check the configuration for request headers. Some API's require",
"// certain headers for all requests. Providing them in the configuration",
"// makes it easier to provide these headers on each request.",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'headers'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setHeaders",
"(",
"$",
"config",
"[",
"'headers'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Initialize connector.
@param array $config
@return self
@throws InvalidArgumentException
|
[
"Initialize",
"connector",
"."
] |
c277942f5f5f63b175bc37e9d392faa946888f65
|
https://github.com/kevindierkx/elicit/blob/c277942f5f5f63b175bc37e9d392faa946888f65/src/Connector/AbstractConnector.php#L56-L72
|
237,182
|
kevindierkx/elicit
|
src/Connector/AbstractConnector.php
|
AbstractConnector.prepare
|
public function prepare(array $query)
{
$client = new Client;
$this->client = $client;
$this->request = $client->createRequest(
$this->prepareMethod($query),
$this->prepareRequestUrl($query),
[
'headers' => $this->prepareHeaders($query),
'body' => $this->prepareBody($query),
]
);
return $this;
}
|
php
|
public function prepare(array $query)
{
$client = new Client;
$this->client = $client;
$this->request = $client->createRequest(
$this->prepareMethod($query),
$this->prepareRequestUrl($query),
[
'headers' => $this->prepareHeaders($query),
'body' => $this->prepareBody($query),
]
);
return $this;
}
|
[
"public",
"function",
"prepare",
"(",
"array",
"$",
"query",
")",
"{",
"$",
"client",
"=",
"new",
"Client",
";",
"$",
"this",
"->",
"client",
"=",
"$",
"client",
";",
"$",
"this",
"->",
"request",
"=",
"$",
"client",
"->",
"createRequest",
"(",
"$",
"this",
"->",
"prepareMethod",
"(",
"$",
"query",
")",
",",
"$",
"this",
"->",
"prepareRequestUrl",
"(",
"$",
"query",
")",
",",
"[",
"'headers'",
"=>",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"query",
")",
",",
"'body'",
"=>",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"query",
")",
",",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Prepare a new request for execution.
@param array $query
@return self
|
[
"Prepare",
"a",
"new",
"request",
"for",
"execution",
"."
] |
c277942f5f5f63b175bc37e9d392faa946888f65
|
https://github.com/kevindierkx/elicit/blob/c277942f5f5f63b175bc37e9d392faa946888f65/src/Connector/AbstractConnector.php#L80-L95
|
237,183
|
kevindierkx/elicit
|
src/Connector/AbstractConnector.php
|
AbstractConnector.prepareRequestUrl
|
protected function prepareRequestUrl(array $query)
{
$path = isset($query['from']['path']) ? $query['from']['path'] : null;
$wheres = isset($query['wheres']) ? $query['wheres'] : null;
$baseUrl = $this->host.$path;
// Here we validate that there are any wheres in the
// request. When none are provided we will return the
// Request Url without the question mark.
if (! is_null($wheres)) {
return $baseUrl.'?'.$wheres;
}
return $baseUrl;
}
|
php
|
protected function prepareRequestUrl(array $query)
{
$path = isset($query['from']['path']) ? $query['from']['path'] : null;
$wheres = isset($query['wheres']) ? $query['wheres'] : null;
$baseUrl = $this->host.$path;
// Here we validate that there are any wheres in the
// request. When none are provided we will return the
// Request Url without the question mark.
if (! is_null($wheres)) {
return $baseUrl.'?'.$wheres;
}
return $baseUrl;
}
|
[
"protected",
"function",
"prepareRequestUrl",
"(",
"array",
"$",
"query",
")",
"{",
"$",
"path",
"=",
"isset",
"(",
"$",
"query",
"[",
"'from'",
"]",
"[",
"'path'",
"]",
")",
"?",
"$",
"query",
"[",
"'from'",
"]",
"[",
"'path'",
"]",
":",
"null",
";",
"$",
"wheres",
"=",
"isset",
"(",
"$",
"query",
"[",
"'wheres'",
"]",
")",
"?",
"$",
"query",
"[",
"'wheres'",
"]",
":",
"null",
";",
"$",
"baseUrl",
"=",
"$",
"this",
"->",
"host",
".",
"$",
"path",
";",
"// Here we validate that there are any wheres in the",
"// request. When none are provided we will return the",
"// Request Url without the question mark.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"wheres",
")",
")",
"{",
"return",
"$",
"baseUrl",
".",
"'?'",
".",
"$",
"wheres",
";",
"}",
"return",
"$",
"baseUrl",
";",
"}"
] |
Prepare request URL from query.
@param array $query
@return string
|
[
"Prepare",
"request",
"URL",
"from",
"query",
"."
] |
c277942f5f5f63b175bc37e9d392faa946888f65
|
https://github.com/kevindierkx/elicit/blob/c277942f5f5f63b175bc37e9d392faa946888f65/src/Connector/AbstractConnector.php#L114-L130
|
237,184
|
kevindierkx/elicit
|
src/Connector/AbstractConnector.php
|
AbstractConnector.prepareBody
|
protected function prepareBody(array $query)
{
$method = isset($query['from']['method']) ? $query['from']['method'] : null;
if ($method === 'POST') {
// The query grammar already parsed the body for us.
// We return the value of the query and guzzle does the rest.
return isset($query['body']) ? $query['body'] : null;
}
}
|
php
|
protected function prepareBody(array $query)
{
$method = isset($query['from']['method']) ? $query['from']['method'] : null;
if ($method === 'POST') {
// The query grammar already parsed the body for us.
// We return the value of the query and guzzle does the rest.
return isset($query['body']) ? $query['body'] : null;
}
}
|
[
"protected",
"function",
"prepareBody",
"(",
"array",
"$",
"query",
")",
"{",
"$",
"method",
"=",
"isset",
"(",
"$",
"query",
"[",
"'from'",
"]",
"[",
"'method'",
"]",
")",
"?",
"$",
"query",
"[",
"'from'",
"]",
"[",
"'method'",
"]",
":",
"null",
";",
"if",
"(",
"$",
"method",
"===",
"'POST'",
")",
"{",
"// The query grammar already parsed the body for us.",
"// We return the value of the query and guzzle does the rest.",
"return",
"isset",
"(",
"$",
"query",
"[",
"'body'",
"]",
")",
"?",
"$",
"query",
"[",
"'body'",
"]",
":",
"null",
";",
"}",
"}"
] |
Prepare body from query.
@param array $query
@return string|array|null
|
[
"Prepare",
"body",
"from",
"query",
"."
] |
c277942f5f5f63b175bc37e9d392faa946888f65
|
https://github.com/kevindierkx/elicit/blob/c277942f5f5f63b175bc37e9d392faa946888f65/src/Connector/AbstractConnector.php#L156-L165
|
237,185
|
kevindierkx/elicit
|
src/Connector/AbstractConnector.php
|
AbstractConnector.parseResponse
|
protected function parseResponse(Response $response)
{
$contentType = explode(';', $response->getHeader('content-type'))[0];
switch ($contentType) {
case 'application/json':
case 'application/vnd.api+json':
return $response->json();
case 'application/xml':
return $response->xml();
}
throw new RuntimeException("Unsupported returned content-type [$contentType]");
}
|
php
|
protected function parseResponse(Response $response)
{
$contentType = explode(';', $response->getHeader('content-type'))[0];
switch ($contentType) {
case 'application/json':
case 'application/vnd.api+json':
return $response->json();
case 'application/xml':
return $response->xml();
}
throw new RuntimeException("Unsupported returned content-type [$contentType]");
}
|
[
"protected",
"function",
"parseResponse",
"(",
"Response",
"$",
"response",
")",
"{",
"$",
"contentType",
"=",
"explode",
"(",
"';'",
",",
"$",
"response",
"->",
"getHeader",
"(",
"'content-type'",
")",
")",
"[",
"0",
"]",
";",
"switch",
"(",
"$",
"contentType",
")",
"{",
"case",
"'application/json'",
":",
"case",
"'application/vnd.api+json'",
":",
"return",
"$",
"response",
"->",
"json",
"(",
")",
";",
"case",
"'application/xml'",
":",
"return",
"$",
"response",
"->",
"xml",
"(",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"Unsupported returned content-type [$contentType]\"",
")",
";",
"}"
] |
Parse the returned response.
@param \GuzzleHttp\Message\Response $response
@return array
@throws RuntimeException
|
[
"Parse",
"the",
"returned",
"response",
"."
] |
c277942f5f5f63b175bc37e9d392faa946888f65
|
https://github.com/kevindierkx/elicit/blob/c277942f5f5f63b175bc37e9d392faa946888f65/src/Connector/AbstractConnector.php#L190-L204
|
237,186
|
phPoirot/Module-Authorization
|
src/Authorization/Guard/GuardRestrictIP.php
|
GuardRestrictIP.attachToEvent
|
function attachToEvent(iEvent $event)
{
if ( \Poirot\isCommandLine() )
// Restriction IP Only Work With Http Sapi
return $this;
$self = $this;
$event->on(EventHeapOfSapi::EVENT_APP_MATCH_REQUEST, function() use ($self) {
$self->_assertAccess();
});
return $this;
}
|
php
|
function attachToEvent(iEvent $event)
{
if ( \Poirot\isCommandLine() )
// Restriction IP Only Work With Http Sapi
return $this;
$self = $this;
$event->on(EventHeapOfSapi::EVENT_APP_MATCH_REQUEST, function() use ($self) {
$self->_assertAccess();
});
return $this;
}
|
[
"function",
"attachToEvent",
"(",
"iEvent",
"$",
"event",
")",
"{",
"if",
"(",
"\\",
"Poirot",
"\\",
"isCommandLine",
"(",
")",
")",
"// Restriction IP Only Work With Http Sapi",
"return",
"$",
"this",
";",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"event",
"->",
"on",
"(",
"EventHeapOfSapi",
"::",
"EVENT_APP_MATCH_REQUEST",
",",
"function",
"(",
")",
"use",
"(",
"$",
"self",
")",
"{",
"$",
"self",
"->",
"_assertAccess",
"(",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Attach To Event
note: not throw any exception if event type is unknown!
@param iEvent|EventHeapOfSapi $event
@return $this
|
[
"Attach",
"To",
"Event"
] |
1adcb85d01bb7cfaa6cc6b0cbcb9907ef4778e06
|
https://github.com/phPoirot/Module-Authorization/blob/1adcb85d01bb7cfaa6cc6b0cbcb9907ef4778e06/src/Authorization/Guard/GuardRestrictIP.php#L59-L72
|
237,187
|
phPoirot/Module-Authorization
|
src/Authorization/Guard/GuardRestrictIP.php
|
GuardRestrictIP.setBlockList
|
function setBlockList($list)
{
if ($list instanceof \Traversable)
$list = \Poirot\Std\cast($list)->toArray();
if (! is_array($list) )
throw new \InvalidArgumentException(sprintf(
'List must instanceof Traversable or array; given (%s).'
, \Poirot\Std\flatten($list)
));
$this->blockList = $list;
return $this;
}
|
php
|
function setBlockList($list)
{
if ($list instanceof \Traversable)
$list = \Poirot\Std\cast($list)->toArray();
if (! is_array($list) )
throw new \InvalidArgumentException(sprintf(
'List must instanceof Traversable or array; given (%s).'
, \Poirot\Std\flatten($list)
));
$this->blockList = $list;
return $this;
}
|
[
"function",
"setBlockList",
"(",
"$",
"list",
")",
"{",
"if",
"(",
"$",
"list",
"instanceof",
"\\",
"Traversable",
")",
"$",
"list",
"=",
"\\",
"Poirot",
"\\",
"Std",
"\\",
"cast",
"(",
"$",
"list",
")",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"list",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'List must instanceof Traversable or array; given (%s).'",
",",
"\\",
"Poirot",
"\\",
"Std",
"\\",
"flatten",
"(",
"$",
"list",
")",
")",
")",
";",
"$",
"this",
"->",
"blockList",
"=",
"$",
"list",
";",
"return",
"$",
"this",
";",
"}"
] |
Set IP Block List
@param array|\Traversable $list
@return $this
|
[
"Set",
"IP",
"Block",
"List"
] |
1adcb85d01bb7cfaa6cc6b0cbcb9907ef4778e06
|
https://github.com/phPoirot/Module-Authorization/blob/1adcb85d01bb7cfaa6cc6b0cbcb9907ef4778e06/src/Authorization/Guard/GuardRestrictIP.php#L98-L111
|
237,188
|
tekkla/core-framework
|
Core/Framework/Page/Head/Meta.php
|
Meta.setViewport
|
public function setViewport($width = 'device-width', $initial_scale = '1', $user_scalable = '', $minimum_scale = '', $maximum_scale = '')
{
$tag = [
'name' => 'viewport',
'content' => 'width=' . $width . ', initial-scale=' . $initial_scale
];
if ($user_scalable) {
$tag['content'] .= ', user-scalable=' . $user_scalable;
}
if ($minimum_scale) {
$tag['content'] .= ', minimum-scale=' . $minimum_scale;
}
if ($maximum_scale) {
$tag['content'] .= ', maximum_scale=' . $maximum_scale;
}
$this->tags['viewport'] = $tag;
}
|
php
|
public function setViewport($width = 'device-width', $initial_scale = '1', $user_scalable = '', $minimum_scale = '', $maximum_scale = '')
{
$tag = [
'name' => 'viewport',
'content' => 'width=' . $width . ', initial-scale=' . $initial_scale
];
if ($user_scalable) {
$tag['content'] .= ', user-scalable=' . $user_scalable;
}
if ($minimum_scale) {
$tag['content'] .= ', minimum-scale=' . $minimum_scale;
}
if ($maximum_scale) {
$tag['content'] .= ', maximum_scale=' . $maximum_scale;
}
$this->tags['viewport'] = $tag;
}
|
[
"public",
"function",
"setViewport",
"(",
"$",
"width",
"=",
"'device-width'",
",",
"$",
"initial_scale",
"=",
"'1'",
",",
"$",
"user_scalable",
"=",
"''",
",",
"$",
"minimum_scale",
"=",
"''",
",",
"$",
"maximum_scale",
"=",
"''",
")",
"{",
"$",
"tag",
"=",
"[",
"'name'",
"=>",
"'viewport'",
",",
"'content'",
"=>",
"'width='",
".",
"$",
"width",
".",
"', initial-scale='",
".",
"$",
"initial_scale",
"]",
";",
"if",
"(",
"$",
"user_scalable",
")",
"{",
"$",
"tag",
"[",
"'content'",
"]",
".=",
"', user-scalable='",
".",
"$",
"user_scalable",
";",
"}",
"if",
"(",
"$",
"minimum_scale",
")",
"{",
"$",
"tag",
"[",
"'content'",
"]",
".=",
"', minimum-scale='",
".",
"$",
"minimum_scale",
";",
"}",
"if",
"(",
"$",
"maximum_scale",
")",
"{",
"$",
"tag",
"[",
"'content'",
"]",
".=",
"', maximum_scale='",
".",
"$",
"maximum_scale",
";",
"}",
"$",
"this",
"->",
"tags",
"[",
"'viewport'",
"]",
"=",
"$",
"tag",
";",
"}"
] |
Sets vieport tag
@param string $width
Description of used device width
@param string $initial_scale
Initial scale factor (Default: '1')
@param string $user_scalable
@param string $minimum_scale
@param string $maximum_scale
|
[
"Sets",
"vieport",
"tag"
] |
ad69e9f15ee3644b6ca376edc30d8f5555399892
|
https://github.com/tekkla/core-framework/blob/ad69e9f15ee3644b6ca376edc30d8f5555399892/Core/Framework/Page/Head/Meta.php#L50-L70
|
237,189
|
morrelinko/simple-photo
|
src/DataStore/MySqlDataStore.php
|
MySqlDataStore.createConnection
|
public function createConnection($parameters)
{
$connection = new \PDO(
'mysql:host=' . $parameters['host'] . ';dbname=' . $parameters['database'],
$parameters['username'],
$parameters['password']
);
if (isset($parameters['charset'])) {
$connection->exec('SET CHARACTER SET ' . $parameters['charset']);
}
return $connection;
}
|
php
|
public function createConnection($parameters)
{
$connection = new \PDO(
'mysql:host=' . $parameters['host'] . ';dbname=' . $parameters['database'],
$parameters['username'],
$parameters['password']
);
if (isset($parameters['charset'])) {
$connection->exec('SET CHARACTER SET ' . $parameters['charset']);
}
return $connection;
}
|
[
"public",
"function",
"createConnection",
"(",
"$",
"parameters",
")",
"{",
"$",
"connection",
"=",
"new",
"\\",
"PDO",
"(",
"'mysql:host='",
".",
"$",
"parameters",
"[",
"'host'",
"]",
".",
"';dbname='",
".",
"$",
"parameters",
"[",
"'database'",
"]",
",",
"$",
"parameters",
"[",
"'username'",
"]",
",",
"$",
"parameters",
"[",
"'password'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"'charset'",
"]",
")",
")",
"{",
"$",
"connection",
"->",
"exec",
"(",
"'SET CHARACTER SET '",
".",
"$",
"parameters",
"[",
"'charset'",
"]",
")",
";",
"}",
"return",
"$",
"connection",
";",
"}"
] |
Creates a MySql Connection
@param array $parameters Connection parameters
<pre>
host: eg. localhost
database: eg. my_app
username: eg. root
password: eg. 123456
charset: (Optional)
</pre>
@return \PDO
|
[
"Creates",
"a",
"MySql",
"Connection"
] |
be1fbe3139d32eb39e88cff93f847154bb6a8cb2
|
https://github.com/morrelinko/simple-photo/blob/be1fbe3139d32eb39e88cff93f847154bb6a8cb2/src/DataStore/MySqlDataStore.php#L33-L46
|
237,190
|
MehrAlsNix/Notifier
|
src/Notify.php
|
Notify.fetch
|
protected static function fetch()
{
$command = array(
'LINUX' => new Commands\Linux(),
'MAC' => new Commands\Mac(),
'WIN' => new Commands\Windows()
);
$instance = 'No valid desktop notifier found.';
if ($command['WIN']->isAvailable()) {
$instance = $command['WIN'];
} elseif($command['LINUX']->isAvailable()) {
$instance = $command['LINUX'];
} elseif($command['MAC']->isAvailable()) {
$instance = $command['MAC'];
}
if (is_string($instance)) {
throw new \RuntimeException($instance);
}
return $instance;
}
|
php
|
protected static function fetch()
{
$command = array(
'LINUX' => new Commands\Linux(),
'MAC' => new Commands\Mac(),
'WIN' => new Commands\Windows()
);
$instance = 'No valid desktop notifier found.';
if ($command['WIN']->isAvailable()) {
$instance = $command['WIN'];
} elseif($command['LINUX']->isAvailable()) {
$instance = $command['LINUX'];
} elseif($command['MAC']->isAvailable()) {
$instance = $command['MAC'];
}
if (is_string($instance)) {
throw new \RuntimeException($instance);
}
return $instance;
}
|
[
"protected",
"static",
"function",
"fetch",
"(",
")",
"{",
"$",
"command",
"=",
"array",
"(",
"'LINUX'",
"=>",
"new",
"Commands",
"\\",
"Linux",
"(",
")",
",",
"'MAC'",
"=>",
"new",
"Commands",
"\\",
"Mac",
"(",
")",
",",
"'WIN'",
"=>",
"new",
"Commands",
"\\",
"Windows",
"(",
")",
")",
";",
"$",
"instance",
"=",
"'No valid desktop notifier found.'",
";",
"if",
"(",
"$",
"command",
"[",
"'WIN'",
"]",
"->",
"isAvailable",
"(",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"command",
"[",
"'WIN'",
"]",
";",
"}",
"elseif",
"(",
"$",
"command",
"[",
"'LINUX'",
"]",
"->",
"isAvailable",
"(",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"command",
"[",
"'LINUX'",
"]",
";",
"}",
"elseif",
"(",
"$",
"command",
"[",
"'MAC'",
"]",
"->",
"isAvailable",
"(",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"command",
"[",
"'MAC'",
"]",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"instance",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Fetches an instance by checking for ability.
@return Commands\Linux|Commands\Mac|Commands\Windows
@throws \RuntimeException
|
[
"Fetches",
"an",
"instance",
"by",
"checking",
"for",
"ability",
"."
] |
9ac9fed8880537157091ac0607965b30dab20bca
|
https://github.com/MehrAlsNix/Notifier/blob/9ac9fed8880537157091ac0607965b30dab20bca/src/Notify.php#L63-L86
|
237,191
|
tenside/core
|
src/Task/Composer/WrappedCommand/WrappedCommandTrait.php
|
WrappedCommandTrait.getComposer
|
public function getComposer($required = true, $disablePlugins = false)
{
if (null === $this->composer) {
if ($this->composerFactory) {
$this->composer = call_user_func($this->composerFactory, $required, $disablePlugins);
}
if ($required && !$this->composer) {
throw new \RuntimeException(
'You must define a factory closure for wrapped commands to retrieve the ' .
'composer instance.'
);
}
}
return $this->composer;
}
|
php
|
public function getComposer($required = true, $disablePlugins = false)
{
if (null === $this->composer) {
if ($this->composerFactory) {
$this->composer = call_user_func($this->composerFactory, $required, $disablePlugins);
}
if ($required && !$this->composer) {
throw new \RuntimeException(
'You must define a factory closure for wrapped commands to retrieve the ' .
'composer instance.'
);
}
}
return $this->composer;
}
|
[
"public",
"function",
"getComposer",
"(",
"$",
"required",
"=",
"true",
",",
"$",
"disablePlugins",
"=",
"false",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"composer",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"composerFactory",
")",
"{",
"$",
"this",
"->",
"composer",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"composerFactory",
",",
"$",
"required",
",",
"$",
"disablePlugins",
")",
";",
"}",
"if",
"(",
"$",
"required",
"&&",
"!",
"$",
"this",
"->",
"composer",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'You must define a factory closure for wrapped commands to retrieve the '",
".",
"'composer instance.'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"composer",
";",
"}"
] |
Retrieve the composer instance.
@param bool $required Flag if the instance is required.
@param bool $disablePlugins Flag if plugins shall get disabled.
@return Composer|null
@throws \RuntimeException When no factory closure has been set.
|
[
"Retrieve",
"the",
"composer",
"instance",
"."
] |
56422fa8cdecf03cb431bb6654c2942ade39bf7b
|
https://github.com/tenside/core/blob/56422fa8cdecf03cb431bb6654c2942ade39bf7b/src/Task/Composer/WrappedCommand/WrappedCommandTrait.php#L55-L71
|
237,192
|
flipbox/skeleton
|
src/Collections/AbstractModelCollection.php
|
AbstractModelCollection.getErrors
|
public function getErrors($attribute = null)
{
$itemErrors = [];
foreach ($this->getItems() as $item) {
if ($item->hasErrors($attribute)) {
$itemErrors[$this->getItemId($item)] = $item->getErrors($attribute);
}
}
return array_merge(
$this->_traitGetErrors($attribute),
$itemErrors
);
}
|
php
|
public function getErrors($attribute = null)
{
$itemErrors = [];
foreach ($this->getItems() as $item) {
if ($item->hasErrors($attribute)) {
$itemErrors[$this->getItemId($item)] = $item->getErrors($attribute);
}
}
return array_merge(
$this->_traitGetErrors($attribute),
$itemErrors
);
}
|
[
"public",
"function",
"getErrors",
"(",
"$",
"attribute",
"=",
"null",
")",
"{",
"$",
"itemErrors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getItems",
"(",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"hasErrors",
"(",
"$",
"attribute",
")",
")",
"{",
"$",
"itemErrors",
"[",
"$",
"this",
"->",
"getItemId",
"(",
"$",
"item",
")",
"]",
"=",
"$",
"item",
"->",
"getErrors",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"_traitGetErrors",
"(",
"$",
"attribute",
")",
",",
"$",
"itemErrors",
")",
";",
"}"
] |
Merge errors from all
@inheritdoc
|
[
"Merge",
"errors",
"from",
"all"
] |
98ed2a8f4c201f34135e6573f3071b2a75a67907
|
https://github.com/flipbox/skeleton/blob/98ed2a8f4c201f34135e6573f3071b2a75a67907/src/Collections/AbstractModelCollection.php#L42-L56
|
237,193
|
webriq/core
|
module/Paragraph/src/Grid/Paragraph/Model/Snippet/Rpc.php
|
Rpc.isNameAvailable
|
public function isNameAvailable( $name, $fields = array() )
{
$fields = (object) $fields;
return ! $this->getMapper()
->isNameExists(
$name .
( empty( $fields->type ) ? '' : '.' . $fields->type )
);
}
|
php
|
public function isNameAvailable( $name, $fields = array() )
{
$fields = (object) $fields;
return ! $this->getMapper()
->isNameExists(
$name .
( empty( $fields->type ) ? '' : '.' . $fields->type )
);
}
|
[
"public",
"function",
"isNameAvailable",
"(",
"$",
"name",
",",
"$",
"fields",
"=",
"array",
"(",
")",
")",
"{",
"$",
"fields",
"=",
"(",
"object",
")",
"$",
"fields",
";",
"return",
"!",
"$",
"this",
"->",
"getMapper",
"(",
")",
"->",
"isNameExists",
"(",
"$",
"name",
".",
"(",
"empty",
"(",
"$",
"fields",
"->",
"type",
")",
"?",
"''",
":",
"'.'",
".",
"$",
"fields",
"->",
"type",
")",
")",
";",
"}"
] |
Find a structure is available
@param string $name
@param array|object $fields [optional]
@return bool
|
[
"Find",
"a",
"structure",
"is",
"available"
] |
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
|
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Paragraph/src/Grid/Paragraph/Model/Snippet/Rpc.php#L39-L48
|
237,194
|
rezzza/jobflow
|
src/Rezzza/Jobflow/JobFactory.php
|
JobFactory.createBuilder
|
public function createBuilder($type = 'job', array $initOptions = array(), array $execOptions = array())
{
$name = $type instanceof JobTypeInterface || $type instanceof ResolvedJob
? $type->getName()
: $type;
return $this->createNamedBuilder($name, $type, $initOptions, $execOptions);
}
|
php
|
public function createBuilder($type = 'job', array $initOptions = array(), array $execOptions = array())
{
$name = $type instanceof JobTypeInterface || $type instanceof ResolvedJob
? $type->getName()
: $type;
return $this->createNamedBuilder($name, $type, $initOptions, $execOptions);
}
|
[
"public",
"function",
"createBuilder",
"(",
"$",
"type",
"=",
"'job'",
",",
"array",
"$",
"initOptions",
"=",
"array",
"(",
")",
",",
"array",
"$",
"execOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"name",
"=",
"$",
"type",
"instanceof",
"JobTypeInterface",
"||",
"$",
"type",
"instanceof",
"ResolvedJob",
"?",
"$",
"type",
"->",
"getName",
"(",
")",
":",
"$",
"type",
";",
"return",
"$",
"this",
"->",
"createNamedBuilder",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"initOptions",
",",
"$",
"execOptions",
")",
";",
"}"
] |
Create a builder
@param mixed $type The JobTypeInterface or the alias of the job type registered as a service
@return JobBuilder
|
[
"Create",
"a",
"builder"
] |
80ded8ac6ed6a2f4500b8f86e2958701ec84fd65
|
https://github.com/rezzza/jobflow/blob/80ded8ac6ed6a2f4500b8f86e2958701ec84fd65/src/Rezzza/Jobflow/JobFactory.php#L45-L52
|
237,195
|
rezzza/jobflow
|
src/Rezzza/Jobflow/JobFactory.php
|
JobFactory.resolveType
|
public function resolveType(JobTypeInterface $type)
{
$parentType = $type->getParent();
if ($parentType instanceof JobTypeInterface) {
$parentType = $this->resolveType($parentType);
} elseif (null !== $parentType) {
$parentType = $this->registry->getType($parentType);
}
return $this->createResolvedType($type, $parentType);
}
|
php
|
public function resolveType(JobTypeInterface $type)
{
$parentType = $type->getParent();
if ($parentType instanceof JobTypeInterface) {
$parentType = $this->resolveType($parentType);
} elseif (null !== $parentType) {
$parentType = $this->registry->getType($parentType);
}
return $this->createResolvedType($type, $parentType);
}
|
[
"public",
"function",
"resolveType",
"(",
"JobTypeInterface",
"$",
"type",
")",
"{",
"$",
"parentType",
"=",
"$",
"type",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"$",
"parentType",
"instanceof",
"JobTypeInterface",
")",
"{",
"$",
"parentType",
"=",
"$",
"this",
"->",
"resolveType",
"(",
"$",
"parentType",
")",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"parentType",
")",
"{",
"$",
"parentType",
"=",
"$",
"this",
"->",
"registry",
"->",
"getType",
"(",
"$",
"parentType",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createResolvedType",
"(",
"$",
"type",
",",
"$",
"parentType",
")",
";",
"}"
] |
Creates wrapper for combination of JobType and JobConnector
@param JobTypeInterface $type
@return ResolvedJob
|
[
"Creates",
"wrapper",
"for",
"combination",
"of",
"JobType",
"and",
"JobConnector"
] |
80ded8ac6ed6a2f4500b8f86e2958701ec84fd65
|
https://github.com/rezzza/jobflow/blob/80ded8ac6ed6a2f4500b8f86e2958701ec84fd65/src/Rezzza/Jobflow/JobFactory.php#L82-L93
|
237,196
|
vinala/kernel
|
src/Processes/Command.php
|
Command.set
|
public static function set($file, $command, $database)
{
$database = $database ? 'true' : 'false';
//
$txt = "<?php\n\nnamespace Vinala\App\Support\Lumos;\n\n";
$txt .= "use Vinala\Kernel\Console\Command\Commands;\n\n";
$txt .= self::docs("$file Command");
$txt .= " class $file extends Commands\n{\n\t";
$txt .= "\n\t/**\n\t * The key of the console command.\n\t *\n\t * @var string\n\t */\n\tprotected ".'$key = '."'$command';\n\n";
$txt .= "\n\t/**\n\t * The console command description.\n\t *\n\t * @var string\n\t */\n\tprotected ".'$description = '."'say hello to the world';\n\n";
$txt .= "\n\t/**\n\t * True if the command will use database.\n\t *\n\t * @var bool\n\t */\n\tprotected ".'$database = '."$database ;\n\n";
$txt .= "\n\t/**\n\t * Execute the console command.\n\t *\n\t * @return mixed\n\t */\n\tpublic function handle()\n\t{\n\t\t ".'$this->line("What\'s up!"); '."\n\t}";
$txt .= "\n}";
return $txt;
}
|
php
|
public static function set($file, $command, $database)
{
$database = $database ? 'true' : 'false';
//
$txt = "<?php\n\nnamespace Vinala\App\Support\Lumos;\n\n";
$txt .= "use Vinala\Kernel\Console\Command\Commands;\n\n";
$txt .= self::docs("$file Command");
$txt .= " class $file extends Commands\n{\n\t";
$txt .= "\n\t/**\n\t * The key of the console command.\n\t *\n\t * @var string\n\t */\n\tprotected ".'$key = '."'$command';\n\n";
$txt .= "\n\t/**\n\t * The console command description.\n\t *\n\t * @var string\n\t */\n\tprotected ".'$description = '."'say hello to the world';\n\n";
$txt .= "\n\t/**\n\t * True if the command will use database.\n\t *\n\t * @var bool\n\t */\n\tprotected ".'$database = '."$database ;\n\n";
$txt .= "\n\t/**\n\t * Execute the console command.\n\t *\n\t * @return mixed\n\t */\n\tpublic function handle()\n\t{\n\t\t ".'$this->line("What\'s up!"); '."\n\t}";
$txt .= "\n}";
return $txt;
}
|
[
"public",
"static",
"function",
"set",
"(",
"$",
"file",
",",
"$",
"command",
",",
"$",
"database",
")",
"{",
"$",
"database",
"=",
"$",
"database",
"?",
"'true'",
":",
"'false'",
";",
"//",
"$",
"txt",
"=",
"\"<?php\\n\\nnamespace Vinala\\App\\Support\\Lumos;\\n\\n\"",
";",
"$",
"txt",
".=",
"\"use Vinala\\Kernel\\Console\\Command\\Commands;\\n\\n\"",
";",
"$",
"txt",
".=",
"self",
"::",
"docs",
"(",
"\"$file Command\"",
")",
";",
"$",
"txt",
".=",
"\" class $file extends Commands\\n{\\n\\t\"",
";",
"$",
"txt",
".=",
"\"\\n\\t/**\\n\\t * The key of the console command.\\n\\t *\\n\\t * @var string\\n\\t */\\n\\tprotected \"",
".",
"'$key = '",
".",
"\"'$command';\\n\\n\"",
";",
"$",
"txt",
".=",
"\"\\n\\t/**\\n\\t * The console command description.\\n\\t *\\n\\t * @var string\\n\\t */\\n\\tprotected \"",
".",
"'$description = '",
".",
"\"'say hello to the world';\\n\\n\"",
";",
"$",
"txt",
".=",
"\"\\n\\t/**\\n\\t * True if the command will use database.\\n\\t *\\n\\t * @var bool\\n\\t */\\n\\tprotected \"",
".",
"'$database = '",
".",
"\"$database ;\\n\\n\"",
";",
"$",
"txt",
".=",
"\"\\n\\t/**\\n\\t * Execute the console command.\\n\\t *\\n\\t * @return mixed\\n\\t */\\n\\tpublic function handle()\\n\\t{\\n\\t\\t \"",
".",
"'$this->line(\"What\\'s up!\"); '",
".",
"\"\\n\\t}\"",
";",
"$",
"txt",
".=",
"\"\\n}\"",
";",
"return",
"$",
"txt",
";",
"}"
] |
prepare the text to put in command file.
|
[
"prepare",
"the",
"text",
"to",
"put",
"in",
"command",
"file",
"."
] |
346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a
|
https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Processes/Command.php#L31-L49
|
237,197
|
wasabi-cms/core
|
src/MenuItem.php
|
MenuItem.alias
|
public function alias($alias = null)
{
if ($alias === null) {
return $this->_alias;
}
$this->_alias = $alias;
return $this;
}
|
php
|
public function alias($alias = null)
{
if ($alias === null) {
return $this->_alias;
}
$this->_alias = $alias;
return $this;
}
|
[
"public",
"function",
"alias",
"(",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"alias",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_alias",
";",
"}",
"$",
"this",
"->",
"_alias",
"=",
"$",
"alias",
";",
"return",
"$",
"this",
";",
"}"
] |
Get or set the alias.
@param null|string $alias
@return MenuItem|string
|
[
"Get",
"or",
"set",
"the",
"alias",
"."
] |
0eadbb64d2fc201bacc63c93814adeca70e08f90
|
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/MenuItem.php#L83-L91
|
237,198
|
wasabi-cms/core
|
src/MenuItem.php
|
MenuItem.name
|
public function name($name = null)
{
if ($name === null) {
return $name;
}
$this->_name = $name;
return $this;
}
|
php
|
public function name($name = null)
{
if ($name === null) {
return $name;
}
$this->_name = $name;
return $this;
}
|
[
"public",
"function",
"name",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"return",
"$",
"name",
";",
"}",
"$",
"this",
"->",
"_name",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] |
Get or set the name.
@param string $name
@return MenuItem|string
|
[
"Get",
"or",
"set",
"the",
"name",
"."
] |
0eadbb64d2fc201bacc63c93814adeca70e08f90
|
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/MenuItem.php#L99-L107
|
237,199
|
wasabi-cms/core
|
src/MenuItem.php
|
MenuItem.shortName
|
public function shortName($name = null)
{
if ($name === null) {
return $this->_nameShort;
}
$this->_nameShort = $name;
return $this;
}
|
php
|
public function shortName($name = null)
{
if ($name === null) {
return $this->_nameShort;
}
$this->_nameShort = $name;
return $this;
}
|
[
"public",
"function",
"shortName",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_nameShort",
";",
"}",
"$",
"this",
"->",
"_nameShort",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] |
Get or set the short name.
@param null|string $name
@return MenuItem|string
|
[
"Get",
"or",
"set",
"the",
"short",
"name",
"."
] |
0eadbb64d2fc201bacc63c93814adeca70e08f90
|
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/MenuItem.php#L115-L123
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.