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
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,600 | DevGroup-ru/yii2-data-structure-tools | src/models/StaticValue.php | StaticValue.beforeSave | public function beforeSave($insert)
{
if (!$this->sort_order) {
$property = Property::findById($this->property_id);
$this->sort_order = count(static::valuesForProperty($property));
}
return parent::beforeSave($insert);
} | php | public function beforeSave($insert)
{
if (!$this->sort_order) {
$property = Property::findById($this->property_id);
$this->sort_order = count(static::valuesForProperty($property));
}
return parent::beforeSave($insert);
} | [
"public",
"function",
"beforeSave",
"(",
"$",
"insert",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"sort_order",
")",
"{",
"$",
"property",
"=",
"Property",
"::",
"findById",
"(",
"$",
"this",
"->",
"property_id",
")",
";",
"$",
"this",
"->",
"sort_order",
"=",
"count",
"(",
"static",
"::",
"valuesForProperty",
"(",
"$",
"property",
")",
")",
";",
"}",
"return",
"parent",
"::",
"beforeSave",
"(",
"$",
"insert",
")",
";",
"}"
]
| Performs beforeSave event
@param bool $insert
@return bool | [
"Performs",
"beforeSave",
"event"
]
| a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/StaticValue.php#L127-L134 |
13,601 | DevGroup-ru/yii2-data-structure-tools | src/Properties/controllers/ManageController.php | ManageController.actions | public function actions()
{
return [
'add-model-property-group' => [
'class' => AddModelPropertyGroup::class,
],
'delete-model-property-group' => [
'class' => DeleteModelPropertyGroup::class,
],
'list-property-groups' => [
'class' => ListPropertyGroups::class,
],
'edit-property-group' => [
'class' => EditPropertyGroup::class,
],
'delete-property-group' => [
'class' => DeletePropertyGroup::class,
],
'list-group-properties' => [
'class' => ListGroupProperties::class,
],
'edit-property' => [
'class' => EditProperty::class,
],
'edit-static-value' => [
'class' => EditStaticValue::class,
],
'delete-static-value' => [
'class' => DeleteStaticValue::class,
],
'delete-property' => [
'class' => DeleteProperty::class,
],
'get-attributes-names' => [
'class' => GetAttributeNames::class,
],
'ajax-related-entities' => [
'class' => AjaxRelatedEntities::class,
],
'restore-property' => [
'class' => RestoreProperty::class
],
'restore-property-group' => [
'class' => RestorePropertyGroup::class
],
'restore-static-value' => [
'class' => RestoreStaticValue::class
]
];
} | php | public function actions()
{
return [
'add-model-property-group' => [
'class' => AddModelPropertyGroup::class,
],
'delete-model-property-group' => [
'class' => DeleteModelPropertyGroup::class,
],
'list-property-groups' => [
'class' => ListPropertyGroups::class,
],
'edit-property-group' => [
'class' => EditPropertyGroup::class,
],
'delete-property-group' => [
'class' => DeletePropertyGroup::class,
],
'list-group-properties' => [
'class' => ListGroupProperties::class,
],
'edit-property' => [
'class' => EditProperty::class,
],
'edit-static-value' => [
'class' => EditStaticValue::class,
],
'delete-static-value' => [
'class' => DeleteStaticValue::class,
],
'delete-property' => [
'class' => DeleteProperty::class,
],
'get-attributes-names' => [
'class' => GetAttributeNames::class,
],
'ajax-related-entities' => [
'class' => AjaxRelatedEntities::class,
],
'restore-property' => [
'class' => RestoreProperty::class
],
'restore-property-group' => [
'class' => RestorePropertyGroup::class
],
'restore-static-value' => [
'class' => RestoreStaticValue::class
]
];
} | [
"public",
"function",
"actions",
"(",
")",
"{",
"return",
"[",
"'add-model-property-group'",
"=>",
"[",
"'class'",
"=>",
"AddModelPropertyGroup",
"::",
"class",
",",
"]",
",",
"'delete-model-property-group'",
"=>",
"[",
"'class'",
"=>",
"DeleteModelPropertyGroup",
"::",
"class",
",",
"]",
",",
"'list-property-groups'",
"=>",
"[",
"'class'",
"=>",
"ListPropertyGroups",
"::",
"class",
",",
"]",
",",
"'edit-property-group'",
"=>",
"[",
"'class'",
"=>",
"EditPropertyGroup",
"::",
"class",
",",
"]",
",",
"'delete-property-group'",
"=>",
"[",
"'class'",
"=>",
"DeletePropertyGroup",
"::",
"class",
",",
"]",
",",
"'list-group-properties'",
"=>",
"[",
"'class'",
"=>",
"ListGroupProperties",
"::",
"class",
",",
"]",
",",
"'edit-property'",
"=>",
"[",
"'class'",
"=>",
"EditProperty",
"::",
"class",
",",
"]",
",",
"'edit-static-value'",
"=>",
"[",
"'class'",
"=>",
"EditStaticValue",
"::",
"class",
",",
"]",
",",
"'delete-static-value'",
"=>",
"[",
"'class'",
"=>",
"DeleteStaticValue",
"::",
"class",
",",
"]",
",",
"'delete-property'",
"=>",
"[",
"'class'",
"=>",
"DeleteProperty",
"::",
"class",
",",
"]",
",",
"'get-attributes-names'",
"=>",
"[",
"'class'",
"=>",
"GetAttributeNames",
"::",
"class",
",",
"]",
",",
"'ajax-related-entities'",
"=>",
"[",
"'class'",
"=>",
"AjaxRelatedEntities",
"::",
"class",
",",
"]",
",",
"'restore-property'",
"=>",
"[",
"'class'",
"=>",
"RestoreProperty",
"::",
"class",
"]",
",",
"'restore-property-group'",
"=>",
"[",
"'class'",
"=>",
"RestorePropertyGroup",
"::",
"class",
"]",
",",
"'restore-static-value'",
"=>",
"[",
"'class'",
"=>",
"RestoreStaticValue",
"::",
"class",
"]",
"]",
";",
"}"
]
| This controller just uses actions in extension
@return array | [
"This",
"controller",
"just",
"uses",
"actions",
"in",
"extension"
]
| a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/Properties/controllers/ManageController.php#L107-L156 |
13,602 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/AnalyticsDb.php | AnalyticsDb.setTimestamp | public function setTimestamp($unixTs)
{
$this->ts = strtotime(date('Y-m-d', $unixTs));
$this->month = date('n', $this->ts);
$this->year = date('Y', $this->ts);
$this->monthTs = strtotime(date('Y-m-01', $unixTs));
} | php | public function setTimestamp($unixTs)
{
$this->ts = strtotime(date('Y-m-d', $unixTs));
$this->month = date('n', $this->ts);
$this->year = date('Y', $this->ts);
$this->monthTs = strtotime(date('Y-m-01', $unixTs));
} | [
"public",
"function",
"setTimestamp",
"(",
"$",
"unixTs",
")",
"{",
"$",
"this",
"->",
"ts",
"=",
"strtotime",
"(",
"date",
"(",
"'Y-m-d'",
",",
"$",
"unixTs",
")",
")",
";",
"$",
"this",
"->",
"month",
"=",
"date",
"(",
"'n'",
",",
"$",
"this",
"->",
"ts",
")",
";",
"$",
"this",
"->",
"year",
"=",
"date",
"(",
"'Y'",
",",
"$",
"this",
"->",
"ts",
")",
";",
"$",
"this",
"->",
"monthTs",
"=",
"strtotime",
"(",
"date",
"(",
"'Y-m-01'",
",",
"$",
"unixTs",
")",
")",
";",
"}"
]
| Set the timestamp which will be used to store the data.
By default current time is used.
@param int $unixTs | [
"Set",
"the",
"timestamp",
"which",
"will",
"be",
"used",
"to",
"store",
"the",
"data",
".",
"By",
"default",
"current",
"time",
"is",
"used",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/AnalyticsDb.php#L65-L71 |
13,603 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/AnalyticsDb.php | AnalyticsDb.save | public function save()
{
$entries = $this->logBuffer->getEntries();
$entrySkeleton = [
'ts' => $this->ts,
'month' => $this->month,
'year' => $this->year
];
$dimensionSkeleton = [
'ts' => $this->ts,
'month' => $this->month,
'year' => $this->year
];
/**
* @var $e LogEntry
*/
foreach ($entries as $e) {
// build entry
$entry = $entrySkeleton;
$entry['entity'] = $e->getName();
$entry['ref'] = $e->getRef();
// check if we have attributes defined
if (count($e->getAttributes()) > 0) {
$entry['attributes'] = $e->getAttributes();
}
// insert or update the DAILY stat
$this->mongo->update(self::ADB_STATS_DAILY, // match
[
'entity' => $e->getName(),
'ref' => $e->getRef(),
'ts' => $this->ts
], // update
[
'$inc' => ['count' => $e->getIncrement()],
'$setOnInsert' => $entry
], // options
['upsert' => true]);
// insert or update the MONTHLY stat
unset($entry['ts']);
$entry['month'] = $this->month;
$entry['year'] = $this->year;
$this->mongo->update(self::ADB_STATS_MONTHLY, // match
[
'entity' => $e->getName(),
'ref' => $e->getRef(),
'ts' => $this->monthTs
], // update
[
'$inc' => ['count' => $e->getIncrement()],
'$setOnInsert' => $entry
], // options
['upsert' => true]);
// insert dimensions for the entry
$dimEntry = $dimensionSkeleton;
$dimEntry['entity'] = $e->getName();
/**
* @var $dim LogDimension
*/
foreach ($e->getDimensions() as $dim) {
$dimEntry['name'] = $dim->getName();
$dimEntry['value'] = $dim->getValue();
$this->mongo->update(self::ADB_DIMS, // match
[
'name' => $dim->getName(),
'value' => $dim->getValue(),
'entity' => $e->getName(),
'ts' => $this->ts
], // update
[
'$inc' => [
'count.' . $e->getRef() => $dim->getIncrement(),
'total' => $dim->getIncrement()
],
'$setOnInsert' => $dimEntry
], // options
['upsert' => true]);
}
}
// clear buffer
$this->logBuffer = new LogBuffer();
} | php | public function save()
{
$entries = $this->logBuffer->getEntries();
$entrySkeleton = [
'ts' => $this->ts,
'month' => $this->month,
'year' => $this->year
];
$dimensionSkeleton = [
'ts' => $this->ts,
'month' => $this->month,
'year' => $this->year
];
/**
* @var $e LogEntry
*/
foreach ($entries as $e) {
// build entry
$entry = $entrySkeleton;
$entry['entity'] = $e->getName();
$entry['ref'] = $e->getRef();
// check if we have attributes defined
if (count($e->getAttributes()) > 0) {
$entry['attributes'] = $e->getAttributes();
}
// insert or update the DAILY stat
$this->mongo->update(self::ADB_STATS_DAILY, // match
[
'entity' => $e->getName(),
'ref' => $e->getRef(),
'ts' => $this->ts
], // update
[
'$inc' => ['count' => $e->getIncrement()],
'$setOnInsert' => $entry
], // options
['upsert' => true]);
// insert or update the MONTHLY stat
unset($entry['ts']);
$entry['month'] = $this->month;
$entry['year'] = $this->year;
$this->mongo->update(self::ADB_STATS_MONTHLY, // match
[
'entity' => $e->getName(),
'ref' => $e->getRef(),
'ts' => $this->monthTs
], // update
[
'$inc' => ['count' => $e->getIncrement()],
'$setOnInsert' => $entry
], // options
['upsert' => true]);
// insert dimensions for the entry
$dimEntry = $dimensionSkeleton;
$dimEntry['entity'] = $e->getName();
/**
* @var $dim LogDimension
*/
foreach ($e->getDimensions() as $dim) {
$dimEntry['name'] = $dim->getName();
$dimEntry['value'] = $dim->getValue();
$this->mongo->update(self::ADB_DIMS, // match
[
'name' => $dim->getName(),
'value' => $dim->getValue(),
'entity' => $e->getName(),
'ts' => $this->ts
], // update
[
'$inc' => [
'count.' . $e->getRef() => $dim->getIncrement(),
'total' => $dim->getIncrement()
],
'$setOnInsert' => $dimEntry
], // options
['upsert' => true]);
}
}
// clear buffer
$this->logBuffer = new LogBuffer();
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"entries",
"=",
"$",
"this",
"->",
"logBuffer",
"->",
"getEntries",
"(",
")",
";",
"$",
"entrySkeleton",
"=",
"[",
"'ts'",
"=>",
"$",
"this",
"->",
"ts",
",",
"'month'",
"=>",
"$",
"this",
"->",
"month",
",",
"'year'",
"=>",
"$",
"this",
"->",
"year",
"]",
";",
"$",
"dimensionSkeleton",
"=",
"[",
"'ts'",
"=>",
"$",
"this",
"->",
"ts",
",",
"'month'",
"=>",
"$",
"this",
"->",
"month",
",",
"'year'",
"=>",
"$",
"this",
"->",
"year",
"]",
";",
"/**\n * @var $e LogEntry\n */",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"e",
")",
"{",
"// build entry",
"$",
"entry",
"=",
"$",
"entrySkeleton",
";",
"$",
"entry",
"[",
"'entity'",
"]",
"=",
"$",
"e",
"->",
"getName",
"(",
")",
";",
"$",
"entry",
"[",
"'ref'",
"]",
"=",
"$",
"e",
"->",
"getRef",
"(",
")",
";",
"// check if we have attributes defined",
"if",
"(",
"count",
"(",
"$",
"e",
"->",
"getAttributes",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"entry",
"[",
"'attributes'",
"]",
"=",
"$",
"e",
"->",
"getAttributes",
"(",
")",
";",
"}",
"// insert or update the DAILY stat",
"$",
"this",
"->",
"mongo",
"->",
"update",
"(",
"self",
"::",
"ADB_STATS_DAILY",
",",
"// match",
"[",
"'entity'",
"=>",
"$",
"e",
"->",
"getName",
"(",
")",
",",
"'ref'",
"=>",
"$",
"e",
"->",
"getRef",
"(",
")",
",",
"'ts'",
"=>",
"$",
"this",
"->",
"ts",
"]",
",",
"// update",
"[",
"'$inc'",
"=>",
"[",
"'count'",
"=>",
"$",
"e",
"->",
"getIncrement",
"(",
")",
"]",
",",
"'$setOnInsert'",
"=>",
"$",
"entry",
"]",
",",
"// options",
"[",
"'upsert'",
"=>",
"true",
"]",
")",
";",
"// insert or update the MONTHLY stat",
"unset",
"(",
"$",
"entry",
"[",
"'ts'",
"]",
")",
";",
"$",
"entry",
"[",
"'month'",
"]",
"=",
"$",
"this",
"->",
"month",
";",
"$",
"entry",
"[",
"'year'",
"]",
"=",
"$",
"this",
"->",
"year",
";",
"$",
"this",
"->",
"mongo",
"->",
"update",
"(",
"self",
"::",
"ADB_STATS_MONTHLY",
",",
"// match",
"[",
"'entity'",
"=>",
"$",
"e",
"->",
"getName",
"(",
")",
",",
"'ref'",
"=>",
"$",
"e",
"->",
"getRef",
"(",
")",
",",
"'ts'",
"=>",
"$",
"this",
"->",
"monthTs",
"]",
",",
"// update",
"[",
"'$inc'",
"=>",
"[",
"'count'",
"=>",
"$",
"e",
"->",
"getIncrement",
"(",
")",
"]",
",",
"'$setOnInsert'",
"=>",
"$",
"entry",
"]",
",",
"// options",
"[",
"'upsert'",
"=>",
"true",
"]",
")",
";",
"// insert dimensions for the entry",
"$",
"dimEntry",
"=",
"$",
"dimensionSkeleton",
";",
"$",
"dimEntry",
"[",
"'entity'",
"]",
"=",
"$",
"e",
"->",
"getName",
"(",
")",
";",
"/**\n * @var $dim LogDimension\n */",
"foreach",
"(",
"$",
"e",
"->",
"getDimensions",
"(",
")",
"as",
"$",
"dim",
")",
"{",
"$",
"dimEntry",
"[",
"'name'",
"]",
"=",
"$",
"dim",
"->",
"getName",
"(",
")",
";",
"$",
"dimEntry",
"[",
"'value'",
"]",
"=",
"$",
"dim",
"->",
"getValue",
"(",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"update",
"(",
"self",
"::",
"ADB_DIMS",
",",
"// match",
"[",
"'name'",
"=>",
"$",
"dim",
"->",
"getName",
"(",
")",
",",
"'value'",
"=>",
"$",
"dim",
"->",
"getValue",
"(",
")",
",",
"'entity'",
"=>",
"$",
"e",
"->",
"getName",
"(",
")",
",",
"'ts'",
"=>",
"$",
"this",
"->",
"ts",
"]",
",",
"// update",
"[",
"'$inc'",
"=>",
"[",
"'count.'",
".",
"$",
"e",
"->",
"getRef",
"(",
")",
"=>",
"$",
"dim",
"->",
"getIncrement",
"(",
")",
",",
"'total'",
"=>",
"$",
"dim",
"->",
"getIncrement",
"(",
")",
"]",
",",
"'$setOnInsert'",
"=>",
"$",
"dimEntry",
"]",
",",
"// options",
"[",
"'upsert'",
"=>",
"true",
"]",
")",
";",
"}",
"}",
"// clear buffer",
"$",
"this",
"->",
"logBuffer",
"=",
"new",
"LogBuffer",
"(",
")",
";",
"}"
]
| Save all the entries from the buffer. | [
"Save",
"all",
"the",
"entries",
"from",
"the",
"buffer",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/AnalyticsDb.php#L131-L221 |
13,604 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/AnalyticsDb.php | AnalyticsDb.query | public function query($entity, $ref = 0, array $dateRange)
{
return new Query($this->mongo, $entity, $ref, $dateRange);
} | php | public function query($entity, $ref = 0, array $dateRange)
{
return new Query($this->mongo, $entity, $ref, $dateRange);
} | [
"public",
"function",
"query",
"(",
"$",
"entity",
",",
"$",
"ref",
"=",
"0",
",",
"array",
"$",
"dateRange",
")",
"{",
"return",
"new",
"Query",
"(",
"$",
"this",
"->",
"mongo",
",",
"$",
"entity",
",",
"$",
"ref",
",",
"$",
"dateRange",
")",
";",
"}"
]
| Query the analytics data.
@param string $entity
@param string|int $ref
@param array $dateRange [fromTimestamp, toTimestamp]
@return Query | [
"Query",
"the",
"analytics",
"data",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/AnalyticsDb.php#L232-L235 |
13,605 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/AnalyticsDb.php | AnalyticsDb.createCollections | private function createCollections()
{
$collections = $this->mongo->listCollections();
$collectionsCreated = false;
foreach ($collections as $collection) {
/* @var $collection CollectionInfo */
if ($collection->getName() == self::ADB_STATS_DAILY) {
$collectionsCreated = true;
break;
}
}
if (!$collectionsCreated) {
// create collections
$this->mongo->createCollection(self::ADB_STATS_DAILY);
$this->mongo->createCollection(self::ADB_STATS_MONTHLY);
$this->mongo->createCollection(self::ADB_DIMS);
// ensure indexes
$this->mongo->createIndex(self::ADB_STATS_DAILY, new CompoundIndex('entityTsEntry', ['entity', 'ref', 'ts'], true, true));
$this->mongo->createIndex(self::ADB_STATS_DAILY,
new CompoundIndex('entityTsAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));
$this->mongo->createIndex(self::ADB_STATS_MONTHLY, new CompoundIndex('entityMonthEntry', ['entity', 'ref', 'ts'], true, true));
$this->mongo->createIndex(self::ADB_STATS_MONTHLY,
new CompoundIndex('entityMonthAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));
$this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension', ['name', 'value', 'entity', 'ts'], true, true));
$this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension_entity', ['entity', 'ts'], true));
}
} | php | private function createCollections()
{
$collections = $this->mongo->listCollections();
$collectionsCreated = false;
foreach ($collections as $collection) {
/* @var $collection CollectionInfo */
if ($collection->getName() == self::ADB_STATS_DAILY) {
$collectionsCreated = true;
break;
}
}
if (!$collectionsCreated) {
// create collections
$this->mongo->createCollection(self::ADB_STATS_DAILY);
$this->mongo->createCollection(self::ADB_STATS_MONTHLY);
$this->mongo->createCollection(self::ADB_DIMS);
// ensure indexes
$this->mongo->createIndex(self::ADB_STATS_DAILY, new CompoundIndex('entityTsEntry', ['entity', 'ref', 'ts'], true, true));
$this->mongo->createIndex(self::ADB_STATS_DAILY,
new CompoundIndex('entityTsAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));
$this->mongo->createIndex(self::ADB_STATS_MONTHLY, new CompoundIndex('entityMonthEntry', ['entity', 'ref', 'ts'], true, true));
$this->mongo->createIndex(self::ADB_STATS_MONTHLY,
new CompoundIndex('entityMonthAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));
$this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension', ['name', 'value', 'entity', 'ts'], true, true));
$this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension_entity', ['entity', 'ts'], true));
}
} | [
"private",
"function",
"createCollections",
"(",
")",
"{",
"$",
"collections",
"=",
"$",
"this",
"->",
"mongo",
"->",
"listCollections",
"(",
")",
";",
"$",
"collectionsCreated",
"=",
"false",
";",
"foreach",
"(",
"$",
"collections",
"as",
"$",
"collection",
")",
"{",
"/* @var $collection CollectionInfo */",
"if",
"(",
"$",
"collection",
"->",
"getName",
"(",
")",
"==",
"self",
"::",
"ADB_STATS_DAILY",
")",
"{",
"$",
"collectionsCreated",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"collectionsCreated",
")",
"{",
"// create collections",
"$",
"this",
"->",
"mongo",
"->",
"createCollection",
"(",
"self",
"::",
"ADB_STATS_DAILY",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"createCollection",
"(",
"self",
"::",
"ADB_STATS_MONTHLY",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"createCollection",
"(",
"self",
"::",
"ADB_DIMS",
")",
";",
"// ensure indexes",
"$",
"this",
"->",
"mongo",
"->",
"createIndex",
"(",
"self",
"::",
"ADB_STATS_DAILY",
",",
"new",
"CompoundIndex",
"(",
"'entityTsEntry'",
",",
"[",
"'entity'",
",",
"'ref'",
",",
"'ts'",
"]",
",",
"true",
",",
"true",
")",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"createIndex",
"(",
"self",
"::",
"ADB_STATS_DAILY",
",",
"new",
"CompoundIndex",
"(",
"'entityTsAttrEntry'",
",",
"[",
"'entity'",
",",
"'ts'",
",",
"'attributes.name'",
",",
"'attributes.value'",
"]",
",",
"false",
",",
"false",
")",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"createIndex",
"(",
"self",
"::",
"ADB_STATS_MONTHLY",
",",
"new",
"CompoundIndex",
"(",
"'entityMonthEntry'",
",",
"[",
"'entity'",
",",
"'ref'",
",",
"'ts'",
"]",
",",
"true",
",",
"true",
")",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"createIndex",
"(",
"self",
"::",
"ADB_STATS_MONTHLY",
",",
"new",
"CompoundIndex",
"(",
"'entityMonthAttrEntry'",
",",
"[",
"'entity'",
",",
"'ts'",
",",
"'attributes.name'",
",",
"'attributes.value'",
"]",
",",
"false",
",",
"false",
")",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"createIndex",
"(",
"self",
"::",
"ADB_DIMS",
",",
"new",
"CompoundIndex",
"(",
"'dimension'",
",",
"[",
"'name'",
",",
"'value'",
",",
"'entity'",
",",
"'ts'",
"]",
",",
"true",
",",
"true",
")",
")",
";",
"$",
"this",
"->",
"mongo",
"->",
"createIndex",
"(",
"self",
"::",
"ADB_DIMS",
",",
"new",
"CompoundIndex",
"(",
"'dimension_entity'",
",",
"[",
"'entity'",
",",
"'ts'",
"]",
",",
"true",
")",
")",
";",
"}",
"}"
]
| Creates the necessary indexes and collections if they don't exist. | [
"Creates",
"the",
"necessary",
"indexes",
"and",
"collections",
"if",
"they",
"don",
"t",
"exist",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/AnalyticsDb.php#L240-L273 |
13,606 | todstoychev/icr | src/Icr.php | Icr.uploadImage | public static function uploadImage(UploadedFile $uploadedFile, $context, $storage = 'local', $fileName = null)
{
$file = Facades\File::get($uploadedFile);
/** @var Processor $processor */
$processor = app('icr.processor');
return $processor->upload(
$context,
$file,
$uploadedFile->getClientOriginalExtension(),
Facades\Storage::disk($storage),
$fileName
);
} | php | public static function uploadImage(UploadedFile $uploadedFile, $context, $storage = 'local', $fileName = null)
{
$file = Facades\File::get($uploadedFile);
/** @var Processor $processor */
$processor = app('icr.processor');
return $processor->upload(
$context,
$file,
$uploadedFile->getClientOriginalExtension(),
Facades\Storage::disk($storage),
$fileName
);
} | [
"public",
"static",
"function",
"uploadImage",
"(",
"UploadedFile",
"$",
"uploadedFile",
",",
"$",
"context",
",",
"$",
"storage",
"=",
"'local'",
",",
"$",
"fileName",
"=",
"null",
")",
"{",
"$",
"file",
"=",
"Facades",
"\\",
"File",
"::",
"get",
"(",
"$",
"uploadedFile",
")",
";",
"/** @var Processor $processor */",
"$",
"processor",
"=",
"app",
"(",
"'icr.processor'",
")",
";",
"return",
"$",
"processor",
"->",
"upload",
"(",
"$",
"context",
",",
"$",
"file",
",",
"$",
"uploadedFile",
"->",
"getClientOriginalExtension",
"(",
")",
",",
"Facades",
"\\",
"Storage",
"::",
"disk",
"(",
"$",
"storage",
")",
",",
"$",
"fileName",
")",
";",
"}"
]
| Handles upload image. Returns exception instance on error or file name on success.
@param UploadedFile $uploadedFile
@param string $context
@param string $storage
@param null|string $fileName
@return \Exception|string
@throws \Exception | [
"Handles",
"upload",
"image",
".",
"Returns",
"exception",
"instance",
"on",
"error",
"or",
"file",
"name",
"on",
"success",
"."
]
| 0214c7bc76e44488e98758d55deb707b72e24000 | https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Icr.php#L28-L40 |
13,607 | todstoychev/icr | src/Icr.php | Icr.deleteImage | public static function deleteImage($fileName, $context, $storage = 'local')
{
/** @var Processor $processor */
$processor = app('icr.processor');
return $processor->delete($fileName, $context, Facades\Storage::disk($storage));
} | php | public static function deleteImage($fileName, $context, $storage = 'local')
{
/** @var Processor $processor */
$processor = app('icr.processor');
return $processor->delete($fileName, $context, Facades\Storage::disk($storage));
} | [
"public",
"static",
"function",
"deleteImage",
"(",
"$",
"fileName",
",",
"$",
"context",
",",
"$",
"storage",
"=",
"'local'",
")",
"{",
"/** @var Processor $processor */",
"$",
"processor",
"=",
"app",
"(",
"'icr.processor'",
")",
";",
"return",
"$",
"processor",
"->",
"delete",
"(",
"$",
"fileName",
",",
"$",
"context",
",",
"Facades",
"\\",
"Storage",
"::",
"disk",
"(",
"$",
"storage",
")",
")",
";",
"}"
]
| Handles delete image. Returns exception instance on error.
@param string $fileName
@param string $context
@param string $storage
@return mixed | [
"Handles",
"delete",
"image",
".",
"Returns",
"exception",
"instance",
"on",
"error",
"."
]
| 0214c7bc76e44488e98758d55deb707b72e24000 | https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Icr.php#L51-L57 |
13,608 | todstoychev/icr | src/Icr.php | Icr.renameImage | public static function renameImage($oldFileName, $newFileName, $context, $storage = 'local')
{
/** @var FilesystemAdapter $filesystemAdapter */
$filesystemAdapter = Facades\Storage::disk($storage);
/** @var Processor $processor */
$processor = app('icr.processor');
return $processor->rename($oldFileName, $newFileName, $context, $filesystemAdapter);
} | php | public static function renameImage($oldFileName, $newFileName, $context, $storage = 'local')
{
/** @var FilesystemAdapter $filesystemAdapter */
$filesystemAdapter = Facades\Storage::disk($storage);
/** @var Processor $processor */
$processor = app('icr.processor');
return $processor->rename($oldFileName, $newFileName, $context, $filesystemAdapter);
} | [
"public",
"static",
"function",
"renameImage",
"(",
"$",
"oldFileName",
",",
"$",
"newFileName",
",",
"$",
"context",
",",
"$",
"storage",
"=",
"'local'",
")",
"{",
"/** @var FilesystemAdapter $filesystemAdapter */",
"$",
"filesystemAdapter",
"=",
"Facades",
"\\",
"Storage",
"::",
"disk",
"(",
"$",
"storage",
")",
";",
"/** @var Processor $processor */",
"$",
"processor",
"=",
"app",
"(",
"'icr.processor'",
")",
";",
"return",
"$",
"processor",
"->",
"rename",
"(",
"$",
"oldFileName",
",",
"$",
"newFileName",
",",
"$",
"context",
",",
"$",
"filesystemAdapter",
")",
";",
"}"
]
| Renames existing image
@param string $oldFileName
@param string $newFileName
@param string $context
@param string $storage
@return boolean | [
"Renames",
"existing",
"image"
]
| 0214c7bc76e44488e98758d55deb707b72e24000 | https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Icr.php#L69-L77 |
13,609 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.handleProcedures | protected function handleProcedures(array $procedures)
{
/** @var Procedure $procedure */
foreach ($procedures as $procedure) {
$this->handleProcedureOuter($procedure);
if ($procedure->hasChildren()) {
$this->handleProcedures($procedure->getChildren());
}
}
} | php | protected function handleProcedures(array $procedures)
{
/** @var Procedure $procedure */
foreach ($procedures as $procedure) {
$this->handleProcedureOuter($procedure);
if ($procedure->hasChildren()) {
$this->handleProcedures($procedure->getChildren());
}
}
} | [
"protected",
"function",
"handleProcedures",
"(",
"array",
"$",
"procedures",
")",
"{",
"/** @var Procedure $procedure */",
"foreach",
"(",
"$",
"procedures",
"as",
"$",
"procedure",
")",
"{",
"$",
"this",
"->",
"handleProcedureOuter",
"(",
"$",
"procedure",
")",
";",
"if",
"(",
"$",
"procedure",
"->",
"hasChildren",
"(",
")",
")",
"{",
"$",
"this",
"->",
"handleProcedures",
"(",
"$",
"procedure",
"->",
"getChildren",
"(",
")",
")",
";",
"}",
"}",
"}"
]
| Handles procedures.
@param array $procedures Procedures to handle | [
"Handles",
"procedures",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L113-L123 |
13,610 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.handleSource | protected function handleSource(SourceAdapterInterface $adapter, Request $request)
{
$this->injectDependencies($adapter);
$response = $adapter->receive($request);
if ($response === null) {
throw new MissingResponseException($adapter);
}
return $response;
} | php | protected function handleSource(SourceAdapterInterface $adapter, Request $request)
{
$this->injectDependencies($adapter);
$response = $adapter->receive($request);
if ($response === null) {
throw new MissingResponseException($adapter);
}
return $response;
} | [
"protected",
"function",
"handleSource",
"(",
"SourceAdapterInterface",
"$",
"adapter",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"injectDependencies",
"(",
"$",
"adapter",
")",
";",
"$",
"response",
"=",
"$",
"adapter",
"->",
"receive",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"response",
"===",
"null",
")",
"{",
"throw",
"new",
"MissingResponseException",
"(",
"$",
"adapter",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Handles source.
@param SourceAdapterInterface $adapter Source adapter
@param Request $request Request to handle
@throws MissingResponseException
@return Response Source adapter response | [
"Handles",
"source",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L135-L146 |
13,611 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.handleSources | protected function handleSources(array $sources)
{
$responses = array();
foreach ($sources as $source) {
list($adapter, $request) = $source;
$responses[] = $this->handleSource($adapter, $request);
}
$iterator = new \AppendIterator();
/** @var Response $response */
foreach ($responses as $response) {
$iterator->append($response->getIterator());
}
return $iterator;
} | php | protected function handleSources(array $sources)
{
$responses = array();
foreach ($sources as $source) {
list($adapter, $request) = $source;
$responses[] = $this->handleSource($adapter, $request);
}
$iterator = new \AppendIterator();
/** @var Response $response */
foreach ($responses as $response) {
$iterator->append($response->getIterator());
}
return $iterator;
} | [
"protected",
"function",
"handleSources",
"(",
"array",
"$",
"sources",
")",
"{",
"$",
"responses",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"source",
")",
"{",
"list",
"(",
"$",
"adapter",
",",
"$",
"request",
")",
"=",
"$",
"source",
";",
"$",
"responses",
"[",
"]",
"=",
"$",
"this",
"->",
"handleSource",
"(",
"$",
"adapter",
",",
"$",
"request",
")",
";",
"}",
"$",
"iterator",
"=",
"new",
"\\",
"AppendIterator",
"(",
")",
";",
"/** @var Response $response */",
"foreach",
"(",
"$",
"responses",
"as",
"$",
"response",
")",
"{",
"$",
"iterator",
"->",
"append",
"(",
"$",
"response",
"->",
"getIterator",
"(",
")",
")",
";",
"}",
"return",
"$",
"iterator",
";",
"}"
]
| Handles sources.
@param array $sources Sources
@return \Iterator Iterator for all source response objects | [
"Handles",
"sources",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L155-L172 |
13,612 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.handleWorker | protected function handleWorker(WorkerInterface $worker, $object, StorageInterface $storage)
{
$this->injectDependencies($worker);
$modifiedObject = $worker->handle($object);
if ($modifiedObject === null && $object !== null) {
$storage->remove($object);
} elseif ($modifiedObject !== $object) {
$storage->remove($object);
$storage->add($modifiedObject);
}
return $modifiedObject;
} | php | protected function handleWorker(WorkerInterface $worker, $object, StorageInterface $storage)
{
$this->injectDependencies($worker);
$modifiedObject = $worker->handle($object);
if ($modifiedObject === null && $object !== null) {
$storage->remove($object);
} elseif ($modifiedObject !== $object) {
$storage->remove($object);
$storage->add($modifiedObject);
}
return $modifiedObject;
} | [
"protected",
"function",
"handleWorker",
"(",
"WorkerInterface",
"$",
"worker",
",",
"$",
"object",
",",
"StorageInterface",
"$",
"storage",
")",
"{",
"$",
"this",
"->",
"injectDependencies",
"(",
"$",
"worker",
")",
";",
"$",
"modifiedObject",
"=",
"$",
"worker",
"->",
"handle",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"modifiedObject",
"===",
"null",
"&&",
"$",
"object",
"!==",
"null",
")",
"{",
"$",
"storage",
"->",
"remove",
"(",
"$",
"object",
")",
";",
"}",
"elseif",
"(",
"$",
"modifiedObject",
"!==",
"$",
"object",
")",
"{",
"$",
"storage",
"->",
"remove",
"(",
"$",
"object",
")",
";",
"$",
"storage",
"->",
"add",
"(",
"$",
"modifiedObject",
")",
";",
"}",
"return",
"$",
"modifiedObject",
";",
"}"
]
| Handles worker.
@param WorkerInterface $worker Worker
@param mixed $object Object to handle
@param StorageInterface $storage Associated storage | [
"Handles",
"worker",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L181-L195 |
13,613 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.handleWorkers | protected function handleWorkers(array $workers, StorageInterface $storage)
{
foreach ($workers as $worker) {
foreach ($storage->all() as $element) {
$this->handleWorker($worker, $element, $storage);
}
}
} | php | protected function handleWorkers(array $workers, StorageInterface $storage)
{
foreach ($workers as $worker) {
foreach ($storage->all() as $element) {
$this->handleWorker($worker, $element, $storage);
}
}
} | [
"protected",
"function",
"handleWorkers",
"(",
"array",
"$",
"workers",
",",
"StorageInterface",
"$",
"storage",
")",
"{",
"foreach",
"(",
"$",
"workers",
"as",
"$",
"worker",
")",
"{",
"foreach",
"(",
"$",
"storage",
"->",
"all",
"(",
")",
"as",
"$",
"element",
")",
"{",
"$",
"this",
"->",
"handleWorker",
"(",
"$",
"worker",
",",
"$",
"element",
",",
"$",
"storage",
")",
";",
"}",
"}",
"}"
]
| Handles workers.
@param array $workers Workers
@param StorageInterface $storage Associated storage | [
"Handles",
"workers",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L203-L210 |
13,614 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.handleTarget | protected function handleTarget(TargetAdapterInterface $adapter, Request $request)
{
$this->injectDependencies($adapter);
$response = $adapter->send($request);
if ($response === null) {
throw new MissingResponseException($adapter);
}
return $response;
} | php | protected function handleTarget(TargetAdapterInterface $adapter, Request $request)
{
$this->injectDependencies($adapter);
$response = $adapter->send($request);
if ($response === null) {
throw new MissingResponseException($adapter);
}
return $response;
} | [
"protected",
"function",
"handleTarget",
"(",
"TargetAdapterInterface",
"$",
"adapter",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"injectDependencies",
"(",
"$",
"adapter",
")",
";",
"$",
"response",
"=",
"$",
"adapter",
"->",
"send",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"response",
"===",
"null",
")",
"{",
"throw",
"new",
"MissingResponseException",
"(",
"$",
"adapter",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Handles target.
@param TargetAdapterInterface $adapter Target adapter
@param Request $request Request to handle
@throws MissingResponseException
@return Response Target adapter response | [
"Handles",
"target",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L222-L233 |
13,615 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.handleTargets | protected function handleTargets(array $targets, Request $request)
{
$responses = array();
foreach ($targets as $target) {
$responses[] = $this->handleTarget($target, $request);
}
return $responses;
} | php | protected function handleTargets(array $targets, Request $request)
{
$responses = array();
foreach ($targets as $target) {
$responses[] = $this->handleTarget($target, $request);
}
return $responses;
} | [
"protected",
"function",
"handleTargets",
"(",
"array",
"$",
"targets",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"responses",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"targets",
"as",
"$",
"target",
")",
"{",
"$",
"responses",
"[",
"]",
"=",
"$",
"this",
"->",
"handleTarget",
"(",
"$",
"target",
",",
"$",
"request",
")",
";",
"}",
"return",
"$",
"responses",
";",
"}"
]
| Handles targets.
@param array $targets Targets
@param Request $request Request to handle
@return array Target responses | [
"Handles",
"targets",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L243-L252 |
13,616 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.nextObject | protected function nextObject(\Iterator $iterator)
{
if ($iterator->valid()) {
$object = $iterator->current();
$iterator->next();
return $object;
}
return false;
} | php | protected function nextObject(\Iterator $iterator)
{
if ($iterator->valid()) {
$object = $iterator->current();
$iterator->next();
return $object;
}
return false;
} | [
"protected",
"function",
"nextObject",
"(",
"\\",
"Iterator",
"$",
"iterator",
")",
"{",
"if",
"(",
"$",
"iterator",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"object",
"=",
"$",
"iterator",
"->",
"current",
"(",
")",
";",
"$",
"iterator",
"->",
"next",
"(",
")",
";",
"return",
"$",
"object",
";",
"}",
"return",
"false",
";",
"}"
]
| Returns next object for an iterator.
@param \Iterator $iterator Iterator to return the next object for
@return mixed|false Object or false, if no object can be returned | [
"Returns",
"next",
"object",
"for",
"an",
"iterator",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L261-L272 |
13,617 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.createStorage | protected function createStorage($scope)
{
$storage = new InMemoryStorage();
$this->stack->setScope($scope, $storage);
return $storage;
} | php | protected function createStorage($scope)
{
$storage = new InMemoryStorage();
$this->stack->setScope($scope, $storage);
return $storage;
} | [
"protected",
"function",
"createStorage",
"(",
"$",
"scope",
")",
"{",
"$",
"storage",
"=",
"new",
"InMemoryStorage",
"(",
")",
";",
"$",
"this",
"->",
"stack",
"->",
"setScope",
"(",
"$",
"scope",
",",
"$",
"storage",
")",
";",
"return",
"$",
"storage",
";",
"}"
]
| Creates scoped storage.
@param string $scope Scope name
@return InMemoryStorage Local storage | [
"Creates",
"scoped",
"storage",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L281-L288 |
13,618 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.injectDependencies | protected function injectDependencies($component)
{
if ($component instanceof StorageStackAwareInterface) {
$component->setStorageStack($this->stack);
}
if ($component instanceof LoggerAwareInterface && $this->logger instanceof LoggerInterface) {
$component->setLogger($this->logger);
}
} | php | protected function injectDependencies($component)
{
if ($component instanceof StorageStackAwareInterface) {
$component->setStorageStack($this->stack);
}
if ($component instanceof LoggerAwareInterface && $this->logger instanceof LoggerInterface) {
$component->setLogger($this->logger);
}
} | [
"protected",
"function",
"injectDependencies",
"(",
"$",
"component",
")",
"{",
"if",
"(",
"$",
"component",
"instanceof",
"StorageStackAwareInterface",
")",
"{",
"$",
"component",
"->",
"setStorageStack",
"(",
"$",
"this",
"->",
"stack",
")",
";",
"}",
"if",
"(",
"$",
"component",
"instanceof",
"LoggerAwareInterface",
"&&",
"$",
"this",
"->",
"logger",
"instanceof",
"LoggerInterface",
")",
"{",
"$",
"component",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"}"
]
| Injects dependencies.
@param object $component Component | [
"Injects",
"dependencies",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L295-L304 |
13,619 | transfer-framework/transfer | src/Transfer/Processor/Processor.php | Processor.mergeStorage | protected function mergeStorage(StorageInterface $storage)
{
foreach ($storage->all() as $id => $object) {
$this->stack->getScope('global')->add($object);
}
} | php | protected function mergeStorage(StorageInterface $storage)
{
foreach ($storage->all() as $id => $object) {
$this->stack->getScope('global')->add($object);
}
} | [
"protected",
"function",
"mergeStorage",
"(",
"StorageInterface",
"$",
"storage",
")",
"{",
"foreach",
"(",
"$",
"storage",
"->",
"all",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"object",
")",
"{",
"$",
"this",
"->",
"stack",
"->",
"getScope",
"(",
"'global'",
")",
"->",
"add",
"(",
"$",
"object",
")",
";",
"}",
"}"
]
| Merges local storage with global storage.
@param StorageInterface $storage Local storage | [
"Merges",
"local",
"storage",
"with",
"global",
"storage",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Processor/Processor.php#L326-L331 |
13,620 | dphn/ScContent | src/ScContent/Listener/Back/ContentListClean.php | ContentListClean.process | public function process(EventInterface $event)
{
$events = $this->getEventManager();
$mapper = $this->getMapper();
$optionsProvider = $this->getOptionsProvider();
$translator = $this->getTranslator();
$pane = $event->getParam('pane');
if (! $optionsProvider->hasIdentifier($pane)) {
return;
}
$options = $optionsProvider->getOptions($pane);
if ($options->getType() == 'search' || $options->getRoot() == 'site') {
return;
}
try {
$mapper->beginTransaction();
$tid = $mapper->getTransactionIdentifier();
$events->trigger(
__FUNCTION__ . '.clean.pre',
null,
[
'tid' => $tid,
]
);
$mapper->clean($tid);
$mapper->commit();
} catch (Exception $e) {
if (DEBUG_MODE) {
throw new DebugException(
$translator->translate('Error: ') . $e->getMessage(),
$e->getCode(),
$e
);
}
$meta = $mapper->findMetaById($id);
$name = isset($meta['title']) ? $meta['title'] : $id;
$this->setValue($name)->error(self::UnexpectedError);
}
return $this->redirect($event, 'sc-admin/file/delete');
} | php | public function process(EventInterface $event)
{
$events = $this->getEventManager();
$mapper = $this->getMapper();
$optionsProvider = $this->getOptionsProvider();
$translator = $this->getTranslator();
$pane = $event->getParam('pane');
if (! $optionsProvider->hasIdentifier($pane)) {
return;
}
$options = $optionsProvider->getOptions($pane);
if ($options->getType() == 'search' || $options->getRoot() == 'site') {
return;
}
try {
$mapper->beginTransaction();
$tid = $mapper->getTransactionIdentifier();
$events->trigger(
__FUNCTION__ . '.clean.pre',
null,
[
'tid' => $tid,
]
);
$mapper->clean($tid);
$mapper->commit();
} catch (Exception $e) {
if (DEBUG_MODE) {
throw new DebugException(
$translator->translate('Error: ') . $e->getMessage(),
$e->getCode(),
$e
);
}
$meta = $mapper->findMetaById($id);
$name = isset($meta['title']) ? $meta['title'] : $id;
$this->setValue($name)->error(self::UnexpectedError);
}
return $this->redirect($event, 'sc-admin/file/delete');
} | [
"public",
"function",
"process",
"(",
"EventInterface",
"$",
"event",
")",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"getEventManager",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"this",
"->",
"getMapper",
"(",
")",
";",
"$",
"optionsProvider",
"=",
"$",
"this",
"->",
"getOptionsProvider",
"(",
")",
";",
"$",
"translator",
"=",
"$",
"this",
"->",
"getTranslator",
"(",
")",
";",
"$",
"pane",
"=",
"$",
"event",
"->",
"getParam",
"(",
"'pane'",
")",
";",
"if",
"(",
"!",
"$",
"optionsProvider",
"->",
"hasIdentifier",
"(",
"$",
"pane",
")",
")",
"{",
"return",
";",
"}",
"$",
"options",
"=",
"$",
"optionsProvider",
"->",
"getOptions",
"(",
"$",
"pane",
")",
";",
"if",
"(",
"$",
"options",
"->",
"getType",
"(",
")",
"==",
"'search'",
"||",
"$",
"options",
"->",
"getRoot",
"(",
")",
"==",
"'site'",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"mapper",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"tid",
"=",
"$",
"mapper",
"->",
"getTransactionIdentifier",
"(",
")",
";",
"$",
"events",
"->",
"trigger",
"(",
"__FUNCTION__",
".",
"'.clean.pre'",
",",
"null",
",",
"[",
"'tid'",
"=>",
"$",
"tid",
",",
"]",
")",
";",
"$",
"mapper",
"->",
"clean",
"(",
"$",
"tid",
")",
";",
"$",
"mapper",
"->",
"commit",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"DEBUG_MODE",
")",
"{",
"throw",
"new",
"DebugException",
"(",
"$",
"translator",
"->",
"translate",
"(",
"'Error: '",
")",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"$",
"meta",
"=",
"$",
"mapper",
"->",
"findMetaById",
"(",
"$",
"id",
")",
";",
"$",
"name",
"=",
"isset",
"(",
"$",
"meta",
"[",
"'title'",
"]",
")",
"?",
"$",
"meta",
"[",
"'title'",
"]",
":",
"$",
"id",
";",
"$",
"this",
"->",
"setValue",
"(",
"$",
"name",
")",
"->",
"error",
"(",
"self",
"::",
"UnexpectedError",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"event",
",",
"'sc-admin/file/delete'",
")",
";",
"}"
]
| Emptying the trash
@param \Zend\EventManager\EventInterface $event
@return null|\Zend\Http\Response | [
"Emptying",
"the",
"trash"
]
| 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Listener/Back/ContentListClean.php#L50-L90 |
13,621 | yriveiro/php-fslock | src/FSLock.php | FSLock.acquire | public function acquire(bool $blocker = false): bool
{
if (!is_resource($this->lock)) {
return false;
}
return flock($this->lock, ($blocker) ? LOCK_EX : LOCK_EX | LOCK_NB);
} | php | public function acquire(bool $blocker = false): bool
{
if (!is_resource($this->lock)) {
return false;
}
return flock($this->lock, ($blocker) ? LOCK_EX : LOCK_EX | LOCK_NB);
} | [
"public",
"function",
"acquire",
"(",
"bool",
"$",
"blocker",
"=",
"false",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"lock",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"flock",
"(",
"$",
"this",
"->",
"lock",
",",
"(",
"$",
"blocker",
")",
"?",
"LOCK_EX",
":",
"LOCK_EX",
"|",
"LOCK_NB",
")",
";",
"}"
]
| Acquires the lock.
@param bool $blocker if the lock is acquire by other process before,
and we call acquire as blocker, this call blocks
after previous acquire release the lock
@return bool | [
"Acquires",
"the",
"lock",
"."
]
| ae12605403294d6f177395192c39baf118dae31c | https://github.com/yriveiro/php-fslock/blob/ae12605403294d6f177395192c39baf118dae31c/src/FSLock.php#L69-L76 |
13,622 | bariew/yii2-rbac-cms-module | controllers/AuthItemController.php | AuthItemController.actionTreeMove | public function actionTreeMove($id, $pid)
{
$child = $this->findModel($id);
$oldParent = $this->findModel($pid);
$newParent = $this->findModel(Yii::$app->request->post('pid'));
$child->move($oldParent, $newParent);
echo json_encode($child->nodeAttributes($child, $newParent->id, time()));
} | php | public function actionTreeMove($id, $pid)
{
$child = $this->findModel($id);
$oldParent = $this->findModel($pid);
$newParent = $this->findModel(Yii::$app->request->post('pid'));
$child->move($oldParent, $newParent);
echo json_encode($child->nodeAttributes($child, $newParent->id, time()));
} | [
"public",
"function",
"actionTreeMove",
"(",
"$",
"id",
",",
"$",
"pid",
")",
"{",
"$",
"child",
"=",
"$",
"this",
"->",
"findModel",
"(",
"$",
"id",
")",
";",
"$",
"oldParent",
"=",
"$",
"this",
"->",
"findModel",
"(",
"$",
"pid",
")",
";",
"$",
"newParent",
"=",
"$",
"this",
"->",
"findModel",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
"'pid'",
")",
")",
";",
"$",
"child",
"->",
"move",
"(",
"$",
"oldParent",
",",
"$",
"newParent",
")",
";",
"echo",
"json_encode",
"(",
"$",
"child",
"->",
"nodeAttributes",
"(",
"$",
"child",
",",
"$",
"newParent",
"->",
"id",
",",
"time",
"(",
")",
")",
")",
";",
"}"
]
| Detaches model from old parent.
And attaches to the new one.
@param integer $id mode id
@param integer $pid parent id
@return \yii\web\View action view | [
"Detaches",
"model",
"from",
"old",
"parent",
".",
"And",
"attaches",
"to",
"the",
"new",
"one",
"."
]
| c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262 | https://github.com/bariew/yii2-rbac-cms-module/blob/c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262/controllers/AuthItemController.php#L101-L108 |
13,623 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.addToken | public function addToken($name, $position) {
$token = new Token($name, $position);
$this->tokens[] = $token;
// Autoclose opened tokens
switch (substr($name, -4)) {
case AbstractBlockRule::OPEN:
$this->openedTokens[] = substr($name, 0, -5);
break;
case AbstractBlockRule::CLOSE:
while (count($this->openedTokens) > 0) {
$lastOpenToken = array_pop($this->openedTokens);
$this->tokens[] = new Token($lastOpenToken . AbstractBlockRule::CLOSE, $position);
if ($lastOpenToken == substr($name, 0, -5)) {
break;
}
}
break;
}
return $token;
} | php | public function addToken($name, $position) {
$token = new Token($name, $position);
$this->tokens[] = $token;
// Autoclose opened tokens
switch (substr($name, -4)) {
case AbstractBlockRule::OPEN:
$this->openedTokens[] = substr($name, 0, -5);
break;
case AbstractBlockRule::CLOSE:
while (count($this->openedTokens) > 0) {
$lastOpenToken = array_pop($this->openedTokens);
$this->tokens[] = new Token($lastOpenToken . AbstractBlockRule::CLOSE, $position);
if ($lastOpenToken == substr($name, 0, -5)) {
break;
}
}
break;
}
return $token;
} | [
"public",
"function",
"addToken",
"(",
"$",
"name",
",",
"$",
"position",
")",
"{",
"$",
"token",
"=",
"new",
"Token",
"(",
"$",
"name",
",",
"$",
"position",
")",
";",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"$",
"token",
";",
"// Autoclose opened tokens",
"switch",
"(",
"substr",
"(",
"$",
"name",
",",
"-",
"4",
")",
")",
"{",
"case",
"AbstractBlockRule",
"::",
"OPEN",
":",
"$",
"this",
"->",
"openedTokens",
"[",
"]",
"=",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"-",
"5",
")",
";",
"break",
";",
"case",
"AbstractBlockRule",
"::",
"CLOSE",
":",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"openedTokens",
")",
">",
"0",
")",
"{",
"$",
"lastOpenToken",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"openedTokens",
")",
";",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"new",
"Token",
"(",
"$",
"lastOpenToken",
".",
"AbstractBlockRule",
"::",
"CLOSE",
",",
"$",
"position",
")",
";",
"if",
"(",
"$",
"lastOpenToken",
"==",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"-",
"5",
")",
")",
"{",
"break",
";",
"}",
"}",
"break",
";",
"}",
"return",
"$",
"token",
";",
"}"
]
| Add token to token list
@param string $name token name
@param int $position token found at position
@return \ViKon\Parser\Token | [
"Add",
"token",
"to",
"token",
"list"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L30-L51 |
13,624 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.getTokenAt | public function getTokenAt($index) {
// Get token from behind
if ($index < 0) {
$index = count($this->tokens) + $index;
}
return $this->tokens[$index];
} | php | public function getTokenAt($index) {
// Get token from behind
if ($index < 0) {
$index = count($this->tokens) + $index;
}
return $this->tokens[$index];
} | [
"public",
"function",
"getTokenAt",
"(",
"$",
"index",
")",
"{",
"// Get token from behind",
"if",
"(",
"$",
"index",
"<",
"0",
")",
"{",
"$",
"index",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
"+",
"$",
"index",
";",
"}",
"return",
"$",
"this",
"->",
"tokens",
"[",
"$",
"index",
"]",
";",
"}"
]
| Get token at given position
@param int $index token index, if index is negative get token from behind (-1 is last element)
@return \ViKon\Parser\Token | [
"Get",
"token",
"at",
"given",
"position"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L60-L67 |
13,625 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.insertTokenAt | public function insertTokenAt($name, $position, $index) {
array_splice($this->tokens, $index, 0, [$token = new Token($name, $position)]);
return $token;
} | php | public function insertTokenAt($name, $position, $index) {
array_splice($this->tokens, $index, 0, [$token = new Token($name, $position)]);
return $token;
} | [
"public",
"function",
"insertTokenAt",
"(",
"$",
"name",
",",
"$",
"position",
",",
"$",
"index",
")",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"tokens",
",",
"$",
"index",
",",
"0",
",",
"[",
"$",
"token",
"=",
"new",
"Token",
"(",
"$",
"name",
",",
"$",
"position",
")",
"]",
")",
";",
"return",
"$",
"token",
";",
"}"
]
| Add token to specific index position
@param string $name
@param int $position
@param int $index
@return \ViKon\Parser\Token | [
"Add",
"token",
"to",
"specific",
"index",
"position"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L78-L82 |
13,626 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.removeTokenAt | public function removeTokenAt($index) {
// Remove token from behind
if ($index < 0) {
$index = count($this->tokens) + $index;
}
array_splice($this->tokens, $index, 1);
} | php | public function removeTokenAt($index) {
// Remove token from behind
if ($index < 0) {
$index = count($this->tokens) + $index;
}
array_splice($this->tokens, $index, 1);
} | [
"public",
"function",
"removeTokenAt",
"(",
"$",
"index",
")",
"{",
"// Remove token from behind",
"if",
"(",
"$",
"index",
"<",
"0",
")",
"{",
"$",
"index",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
"+",
"$",
"index",
";",
"}",
"array_splice",
"(",
"$",
"this",
"->",
"tokens",
",",
"$",
"index",
",",
"1",
")",
";",
"}"
]
| Remove token at specific index position
@param int $index token index, if index is negative get token from behind (-1 is last element) | [
"Remove",
"token",
"at",
"specific",
"index",
"position"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L89-L95 |
13,627 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.lastByName | public function lastByName($name) {
for ($i = count($this->tokens) - 1; $i >= 0; $i--) {
if ($this->tokens[$i]->getName() === $name) {
return $this->tokens[$i];
}
}
return null;
} | php | public function lastByName($name) {
for ($i = count($this->tokens) - 1; $i >= 0; $i--) {
if ($this->tokens[$i]->getName() === $name) {
return $this->tokens[$i];
}
}
return null;
} | [
"public",
"function",
"lastByName",
"(",
"$",
"name",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Get last token that match provided name
@param string $name token name
@return \ViKon\Parser\Token|null | [
"Get",
"last",
"token",
"that",
"match",
"provided",
"name"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L163-L171 |
13,628 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.lastIndexByName | public function lastIndexByName($name) {
for ($i = count($this->tokens) - 1; $i >= 0; $i--) {
if ($this->tokens[$i]->getName() === $name) {
return $i;
}
}
return null;
} | php | public function lastIndexByName($name) {
for ($i = count($this->tokens) - 1; $i >= 0; $i--) {
if ($this->tokens[$i]->getName() === $name) {
return $i;
}
}
return null;
} | [
"public",
"function",
"lastIndexByName",
"(",
"$",
"name",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"i",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Get last token index that match provided name
@param string $name token name
@return int|null | [
"Get",
"last",
"token",
"index",
"that",
"match",
"provided",
"name"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L180-L188 |
13,629 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.merge | public function merge(TokenList $tokenList) {
$tokenList->closeOpenTokens();
$lastTokenPosition = $this->last() === null ? 0 : $this->last()
->getPosition();
foreach ($tokenList->getTokens() as $token) {
$token->setPosition($token->getPosition() + $lastTokenPosition);
$this->tokens[] = $token;
}
} | php | public function merge(TokenList $tokenList) {
$tokenList->closeOpenTokens();
$lastTokenPosition = $this->last() === null ? 0 : $this->last()
->getPosition();
foreach ($tokenList->getTokens() as $token) {
$token->setPosition($token->getPosition() + $lastTokenPosition);
$this->tokens[] = $token;
}
} | [
"public",
"function",
"merge",
"(",
"TokenList",
"$",
"tokenList",
")",
"{",
"$",
"tokenList",
"->",
"closeOpenTokens",
"(",
")",
";",
"$",
"lastTokenPosition",
"=",
"$",
"this",
"->",
"last",
"(",
")",
"===",
"null",
"?",
"0",
":",
"$",
"this",
"->",
"last",
"(",
")",
"->",
"getPosition",
"(",
")",
";",
"foreach",
"(",
"$",
"tokenList",
"->",
"getTokens",
"(",
")",
"as",
"$",
"token",
")",
"{",
"$",
"token",
"->",
"setPosition",
"(",
"$",
"token",
"->",
"getPosition",
"(",
")",
"+",
"$",
"lastTokenPosition",
")",
";",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"}"
]
| Merge two token list
@param TokenList $tokenList | [
"Merge",
"two",
"token",
"list"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L195-L203 |
13,630 | vi-kon/laravel-parser | src/ViKon/Parser/TokenList.php | TokenList.closeOpenTokens | public function closeOpenTokens() {
$lastToken = $this->last();
while (count($this->openedTokens) > 0) {
$lastOpenToken = array_pop($this->openedTokens);
$this->tokens[] = new Token($lastOpenToken . AbstractBlockRule::CLOSE, $lastToken->getPosition());
}
} | php | public function closeOpenTokens() {
$lastToken = $this->last();
while (count($this->openedTokens) > 0) {
$lastOpenToken = array_pop($this->openedTokens);
$this->tokens[] = new Token($lastOpenToken . AbstractBlockRule::CLOSE, $lastToken->getPosition());
}
} | [
"public",
"function",
"closeOpenTokens",
"(",
")",
"{",
"$",
"lastToken",
"=",
"$",
"this",
"->",
"last",
"(",
")",
";",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"openedTokens",
")",
">",
"0",
")",
"{",
"$",
"lastOpenToken",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"openedTokens",
")",
";",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"new",
"Token",
"(",
"$",
"lastOpenToken",
".",
"AbstractBlockRule",
"::",
"CLOSE",
",",
"$",
"lastToken",
"->",
"getPosition",
"(",
")",
")",
";",
"}",
"}"
]
| Automatically close unclosed tags | [
"Automatically",
"close",
"unclosed",
"tags"
]
| 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/TokenList.php#L226-L232 |
13,631 | konsulting/laravel-editor-stamps | src/Schema.php | Schema.connection | public static function connection($name)
{
$schema = static::$app['db']->connection($name)->getSchemaBuilder();
$schema->blueprintResolver(function ($table, $callback) {
return new Blueprint($table, $callback);
});
return $schema;
} | php | public static function connection($name)
{
$schema = static::$app['db']->connection($name)->getSchemaBuilder();
$schema->blueprintResolver(function ($table, $callback) {
return new Blueprint($table, $callback);
});
return $schema;
} | [
"public",
"static",
"function",
"connection",
"(",
"$",
"name",
")",
"{",
"$",
"schema",
"=",
"static",
"::",
"$",
"app",
"[",
"'db'",
"]",
"->",
"connection",
"(",
"$",
"name",
")",
"->",
"getSchemaBuilder",
"(",
")",
";",
"$",
"schema",
"->",
"blueprintResolver",
"(",
"function",
"(",
"$",
"table",
",",
"$",
"callback",
")",
"{",
"return",
"new",
"Blueprint",
"(",
"$",
"table",
",",
"$",
"callback",
")",
";",
"}",
")",
";",
"return",
"$",
"schema",
";",
"}"
]
| Get a schema builder instance for a connection.
@param string $name
@return \Illuminate\Database\Schema\Builder | [
"Get",
"a",
"schema",
"builder",
"instance",
"for",
"a",
"connection",
"."
]
| 31d36382b55dde960438b5a55bfa7f824bfbd690 | https://github.com/konsulting/laravel-editor-stamps/blob/31d36382b55dde960438b5a55bfa7f824bfbd690/src/Schema.php#L18-L26 |
13,632 | bariew/yii2-rbac-cms-module | models/AuthAssignment.php | AuthAssignment.userAssignments | public static function userAssignments($user)
{
$names = self::find()->where(['user_id' => $user->id])->select('item_name')->column();
return AuthItem::find()->where(['in', 'name', $names]);
} | php | public static function userAssignments($user)
{
$names = self::find()->where(['user_id' => $user->id])->select('item_name')->column();
return AuthItem::find()->where(['in', 'name', $names]);
} | [
"public",
"static",
"function",
"userAssignments",
"(",
"$",
"user",
")",
"{",
"$",
"names",
"=",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"$",
"user",
"->",
"id",
"]",
")",
"->",
"select",
"(",
"'item_name'",
")",
"->",
"column",
"(",
")",
";",
"return",
"AuthItem",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'in'",
",",
"'name'",
",",
"$",
"names",
"]",
")",
";",
"}"
]
| Searches all user assignments.
@param object $user user instance
@return \yii\web\Query search object | [
"Searches",
"all",
"user",
"assignments",
"."
]
| c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262 | https://github.com/bariew/yii2-rbac-cms-module/blob/c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262/models/AuthAssignment.php#L85-L89 |
13,633 | christophe-brachet/aspi-framework | src/Framework/Form/Element/CheckboxSet.php | CheckboxSet.setCheckboxAttribute | public function setCheckboxAttribute($a, $v)
{
foreach ($this->checkboxes as $checkbox) {
$checkbox->setAttribute($a, $v);
if ($a == 'tabindex') {
$v++;
}
}
return $this;
} | php | public function setCheckboxAttribute($a, $v)
{
foreach ($this->checkboxes as $checkbox) {
$checkbox->setAttribute($a, $v);
if ($a == 'tabindex') {
$v++;
}
}
return $this;
} | [
"public",
"function",
"setCheckboxAttribute",
"(",
"$",
"a",
",",
"$",
"v",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"checkboxes",
"as",
"$",
"checkbox",
")",
"{",
"$",
"checkbox",
"->",
"setAttribute",
"(",
"$",
"a",
",",
"$",
"v",
")",
";",
"if",
"(",
"$",
"a",
"==",
"'tabindex'",
")",
"{",
"$",
"v",
"++",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set an attribute for the input checkbox elements
@param string $a
@param string $v
@return Child | [
"Set",
"an",
"attribute",
"for",
"the",
"input",
"checkbox",
"elements"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/CheckboxSet.php#L96-L105 |
13,634 | christophe-brachet/aspi-framework | src/Framework/Form/Element/CheckboxSet.php | CheckboxSet.setCheckboxAttributes | public function setCheckboxAttributes(array $a)
{
foreach ($this->checkboxes as $checkbox) {
$checkbox->setAttributes($a);
if (isset($a['tabindex'])) {
$a['tabindex']++;
}
}
return $this;
} | php | public function setCheckboxAttributes(array $a)
{
foreach ($this->checkboxes as $checkbox) {
$checkbox->setAttributes($a);
if (isset($a['tabindex'])) {
$a['tabindex']++;
}
}
return $this;
} | [
"public",
"function",
"setCheckboxAttributes",
"(",
"array",
"$",
"a",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"checkboxes",
"as",
"$",
"checkbox",
")",
"{",
"$",
"checkbox",
"->",
"setAttributes",
"(",
"$",
"a",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"a",
"[",
"'tabindex'",
"]",
")",
")",
"{",
"$",
"a",
"[",
"'tabindex'",
"]",
"++",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set an attribute or attributes for the input checkbox elements
@param array $a
@return Child | [
"Set",
"an",
"attribute",
"or",
"attributes",
"for",
"the",
"input",
"checkbox",
"elements"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/CheckboxSet.php#L112-L121 |
13,635 | christophe-brachet/aspi-framework | src/Framework/Form/Element/CheckboxSet.php | CheckboxSet.setValue | public function setValue($value)
{
$this->checked = (!is_array($value)) ? [$value] : $value;
if ((count($this->checked) > 0) && ($this->hasChildren())) {
foreach ($this->childNodes as $child) {
if ($child instanceof Input\Checkbox) {
if (in_array($child->getValue(), $this->checked)) {
$child->check();
} else {
$child->uncheck();
}
}
}
}
return $this;
} | php | public function setValue($value)
{
$this->checked = (!is_array($value)) ? [$value] : $value;
if ((count($this->checked) > 0) && ($this->hasChildren())) {
foreach ($this->childNodes as $child) {
if ($child instanceof Input\Checkbox) {
if (in_array($child->getValue(), $this->checked)) {
$child->check();
} else {
$child->uncheck();
}
}
}
}
return $this;
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"checked",
"=",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"?",
"[",
"$",
"value",
"]",
":",
"$",
"value",
";",
"if",
"(",
"(",
"count",
"(",
"$",
"this",
"->",
"checked",
")",
">",
"0",
")",
"&&",
"(",
"$",
"this",
"->",
"hasChildren",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"instanceof",
"Input",
"\\",
"Checkbox",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"child",
"->",
"getValue",
"(",
")",
",",
"$",
"this",
"->",
"checked",
")",
")",
"{",
"$",
"child",
"->",
"check",
"(",
")",
";",
"}",
"else",
"{",
"$",
"child",
"->",
"uncheck",
"(",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the checked value of the checkbox form elements
@param $value
@return CheckboxSet | [
"Set",
"the",
"checked",
"value",
"of",
"the",
"checkbox",
"form",
"elements"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/CheckboxSet.php#L128-L143 |
13,636 | christophe-brachet/aspi-framework | src/Framework/Form/Element/CheckboxSet.php | CheckboxSet.render | public function render($depth = 0, $indent = null, $inner = false)
{
if (!empty($this->legend)) {
$this->addChild(new Child('legend', $this->legend));
}
return parent::render($depth, $indent, $inner);
} | php | public function render($depth = 0, $indent = null, $inner = false)
{
if (!empty($this->legend)) {
$this->addChild(new Child('legend', $this->legend));
}
return parent::render($depth, $indent, $inner);
} | [
"public",
"function",
"render",
"(",
"$",
"depth",
"=",
"0",
",",
"$",
"indent",
"=",
"null",
",",
"$",
"inner",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"legend",
")",
")",
"{",
"$",
"this",
"->",
"addChild",
"(",
"new",
"Child",
"(",
"'legend'",
",",
"$",
"this",
"->",
"legend",
")",
")",
";",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"depth",
",",
"$",
"indent",
",",
"$",
"inner",
")",
";",
"}"
]
| Render the child and its child nodes
@param int $depth
@param string $indent
@param boolean $inner
@return string | [
"Render",
"the",
"child",
"and",
"its",
"child",
"nodes"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/CheckboxSet.php#L257-L263 |
13,637 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php | DWDHourlyCrawler.getDataInInterval | public function getDataInInterval($coordinatesRequest, DateTime $date, $timeMinuteLimit = 30, $sorted = true)
{
$parameters = [];
$queriedStations = [];
$date = Carbon::instance($date)->setTimezone('utc');
foreach ($this->services as $var => $hourlyService) {
$stations = $this->getStations($hourlyService, true);
if (isset($stations)) {
try {
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
} catch (DWDLibException $exception) {
DWDUtil::log(self::class, "Failed to retrieve any nearest active stations. Retrying after forcedownloading new station infos.", Logger::WARNING);
$stations = $this->getStations($hourlyService, true, true);
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
}
foreach ($nearestStations as $nearestStation) {
/* @var $nearestStation DWDStation */
$zipFilePath = $this->retrieveFile($hourlyService, $nearestStation);
$content = isset($zipFilePath)
? DWDUtil::getDataFromZip($zipFilePath, DWDConfiguration::getHourlyConfiguration()->zipExtractionPrefix)
: null;
//content can only be null if a station is listed as active but is not anymore.
if ($content == null) {
DWDUtil::log(self::class, 'file for station=' . $nearestStation . ' could not be loaded, trying next station');
continue;
}
$parameters[$var] = $this->retrieveData($content, $nearestStation, $coordinatesRequest, $hourlyService, $date, $timeMinuteLimit);
//addStation
if (count($parameters[$var]) > 0 && !isset($queriedStations['station-' . $nearestStation->getId()])) {
$queriedStations['station-' . $nearestStation->getId()] = $nearestStation;
}
if (count($parameters[$var])>0)
break;
}
}
}
if ($sorted && isset($parameters))
ksort($parameters);
return [$parameters, $queriedStations];
} | php | public function getDataInInterval($coordinatesRequest, DateTime $date, $timeMinuteLimit = 30, $sorted = true)
{
$parameters = [];
$queriedStations = [];
$date = Carbon::instance($date)->setTimezone('utc');
foreach ($this->services as $var => $hourlyService) {
$stations = $this->getStations($hourlyService, true);
if (isset($stations)) {
try {
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
} catch (DWDLibException $exception) {
DWDUtil::log(self::class, "Failed to retrieve any nearest active stations. Retrying after forcedownloading new station infos.", Logger::WARNING);
$stations = $this->getStations($hourlyService, true, true);
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
}
foreach ($nearestStations as $nearestStation) {
/* @var $nearestStation DWDStation */
$zipFilePath = $this->retrieveFile($hourlyService, $nearestStation);
$content = isset($zipFilePath)
? DWDUtil::getDataFromZip($zipFilePath, DWDConfiguration::getHourlyConfiguration()->zipExtractionPrefix)
: null;
//content can only be null if a station is listed as active but is not anymore.
if ($content == null) {
DWDUtil::log(self::class, 'file for station=' . $nearestStation . ' could not be loaded, trying next station');
continue;
}
$parameters[$var] = $this->retrieveData($content, $nearestStation, $coordinatesRequest, $hourlyService, $date, $timeMinuteLimit);
//addStation
if (count($parameters[$var]) > 0 && !isset($queriedStations['station-' . $nearestStation->getId()])) {
$queriedStations['station-' . $nearestStation->getId()] = $nearestStation;
}
if (count($parameters[$var])>0)
break;
}
}
}
if ($sorted && isset($parameters))
ksort($parameters);
return [$parameters, $queriedStations];
} | [
"public",
"function",
"getDataInInterval",
"(",
"$",
"coordinatesRequest",
",",
"DateTime",
"$",
"date",
",",
"$",
"timeMinuteLimit",
"=",
"30",
",",
"$",
"sorted",
"=",
"true",
")",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"$",
"queriedStations",
"=",
"[",
"]",
";",
"$",
"date",
"=",
"Carbon",
"::",
"instance",
"(",
"$",
"date",
")",
"->",
"setTimezone",
"(",
"'utc'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"services",
"as",
"$",
"var",
"=>",
"$",
"hourlyService",
")",
"{",
"$",
"stations",
"=",
"$",
"this",
"->",
"getStations",
"(",
"$",
"hourlyService",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"stations",
")",
")",
"{",
"try",
"{",
"$",
"nearestStations",
"=",
"DWDStationsController",
"::",
"getNearestStations",
"(",
"$",
"stations",
",",
"$",
"coordinatesRequest",
")",
";",
"}",
"catch",
"(",
"DWDLibException",
"$",
"exception",
")",
"{",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"Failed to retrieve any nearest active stations. Retrying after forcedownloading new station infos.\"",
",",
"Logger",
"::",
"WARNING",
")",
";",
"$",
"stations",
"=",
"$",
"this",
"->",
"getStations",
"(",
"$",
"hourlyService",
",",
"true",
",",
"true",
")",
";",
"$",
"nearestStations",
"=",
"DWDStationsController",
"::",
"getNearestStations",
"(",
"$",
"stations",
",",
"$",
"coordinatesRequest",
")",
";",
"}",
"foreach",
"(",
"$",
"nearestStations",
"as",
"$",
"nearestStation",
")",
"{",
"/* @var $nearestStation DWDStation */",
"$",
"zipFilePath",
"=",
"$",
"this",
"->",
"retrieveFile",
"(",
"$",
"hourlyService",
",",
"$",
"nearestStation",
")",
";",
"$",
"content",
"=",
"isset",
"(",
"$",
"zipFilePath",
")",
"?",
"DWDUtil",
"::",
"getDataFromZip",
"(",
"$",
"zipFilePath",
",",
"DWDConfiguration",
"::",
"getHourlyConfiguration",
"(",
")",
"->",
"zipExtractionPrefix",
")",
":",
"null",
";",
"//content can only be null if a station is listed as active but is not anymore.",
"if",
"(",
"$",
"content",
"==",
"null",
")",
"{",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"'file for station='",
".",
"$",
"nearestStation",
".",
"' could not be loaded, trying next station'",
")",
";",
"continue",
";",
"}",
"$",
"parameters",
"[",
"$",
"var",
"]",
"=",
"$",
"this",
"->",
"retrieveData",
"(",
"$",
"content",
",",
"$",
"nearestStation",
",",
"$",
"coordinatesRequest",
",",
"$",
"hourlyService",
",",
"$",
"date",
",",
"$",
"timeMinuteLimit",
")",
";",
"//addStation",
"if",
"(",
"count",
"(",
"$",
"parameters",
"[",
"$",
"var",
"]",
")",
">",
"0",
"&&",
"!",
"isset",
"(",
"$",
"queriedStations",
"[",
"'station-'",
".",
"$",
"nearestStation",
"->",
"getId",
"(",
")",
"]",
")",
")",
"{",
"$",
"queriedStations",
"[",
"'station-'",
".",
"$",
"nearestStation",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"nearestStation",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parameters",
"[",
"$",
"var",
"]",
")",
">",
"0",
")",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"sorted",
"&&",
"isset",
"(",
"$",
"parameters",
")",
")",
"ksort",
"(",
"$",
"parameters",
")",
";",
"return",
"[",
"$",
"parameters",
",",
"$",
"queriedStations",
"]",
";",
"}"
]
| Retrieve data from one of the nearest stations. This method retrieves all stations in a specific diameter around
the location. It then queries the stations one by one until one station's results could be found.
This is important if a station's files are missing on the ftp.
@param array $nearestStations
@param DateTime $date
@param int $timeMinuteLimit
@return array [params, stations] | [
"Retrieve",
"data",
"from",
"one",
"of",
"the",
"nearest",
"stations",
".",
"This",
"method",
"retrieves",
"all",
"stations",
"in",
"a",
"specific",
"diameter",
"around",
"the",
"location",
".",
"It",
"then",
"queries",
"the",
"stations",
"one",
"by",
"one",
"until",
"one",
"station",
"s",
"results",
"could",
"be",
"found",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php#L59-L108 |
13,638 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php | DWDHourlyCrawler.getDataByDay | public function getDataByDay(Coordinate $coordinatesRequest, DateTime $day)
{
$parameters = [];
$queriedStations = [];
$day = Carbon::instance($day)->setTimezone('utc');
foreach ($this->services as $var => $hourlyService) {
/* @var AbstractHourlyService $hourlyService */
$stations = $this->getStations($hourlyService, true);
if (isset($stations)) {
try {
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
} catch (DWDLibException $exception) {
$stations = $this->getStations($hourlyService, true, true);
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
}
foreach ($nearestStations as $nearestStation) {
/* @var $nearestStation DWDStation */
$zipFilePath = $this->retrieveFile($hourlyService, $nearestStation);
$content = isset($zipFilePath)
? DWDUtil::getDataFromZip($zipFilePath, DWDConfiguration::getHourlyConfiguration()->zipExtractionPrefix)
: null;
//content can only be null if a station is listed as active but is not anymore.
if ($content == null) {
DWDUtil::log(self::class, 'file for station=' . $nearestStation . ' could not be loaded, trying next station');
continue;
}
$start = Carbon::instance($day)->startOfDay();
$end = Carbon::instance($day)->endOfDay();
$parameters[$var] = $hourlyService->parseHourlyData($content, $nearestStation, $coordinatesRequest, $start, $end);//$this->retrieveData2($content, $hourlyService, $start, $end);
//addStation
if (count($parameters[$var]) > 0 && !isset($queriedStations['station-' . $nearestStation->getId()])) {
$queriedStations['station-' . $nearestStation->getId()] = $nearestStation;
}
if (isset($parameters[$var]))
break;
}
}
}
return [$parameters,$queriedStations];
} | php | public function getDataByDay(Coordinate $coordinatesRequest, DateTime $day)
{
$parameters = [];
$queriedStations = [];
$day = Carbon::instance($day)->setTimezone('utc');
foreach ($this->services as $var => $hourlyService) {
/* @var AbstractHourlyService $hourlyService */
$stations = $this->getStations($hourlyService, true);
if (isset($stations)) {
try {
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
} catch (DWDLibException $exception) {
$stations = $this->getStations($hourlyService, true, true);
$nearestStations = DWDStationsController::getNearestStations($stations, $coordinatesRequest);
}
foreach ($nearestStations as $nearestStation) {
/* @var $nearestStation DWDStation */
$zipFilePath = $this->retrieveFile($hourlyService, $nearestStation);
$content = isset($zipFilePath)
? DWDUtil::getDataFromZip($zipFilePath, DWDConfiguration::getHourlyConfiguration()->zipExtractionPrefix)
: null;
//content can only be null if a station is listed as active but is not anymore.
if ($content == null) {
DWDUtil::log(self::class, 'file for station=' . $nearestStation . ' could not be loaded, trying next station');
continue;
}
$start = Carbon::instance($day)->startOfDay();
$end = Carbon::instance($day)->endOfDay();
$parameters[$var] = $hourlyService->parseHourlyData($content, $nearestStation, $coordinatesRequest, $start, $end);//$this->retrieveData2($content, $hourlyService, $start, $end);
//addStation
if (count($parameters[$var]) > 0 && !isset($queriedStations['station-' . $nearestStation->getId()])) {
$queriedStations['station-' . $nearestStation->getId()] = $nearestStation;
}
if (isset($parameters[$var]))
break;
}
}
}
return [$parameters,$queriedStations];
} | [
"public",
"function",
"getDataByDay",
"(",
"Coordinate",
"$",
"coordinatesRequest",
",",
"DateTime",
"$",
"day",
")",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"$",
"queriedStations",
"=",
"[",
"]",
";",
"$",
"day",
"=",
"Carbon",
"::",
"instance",
"(",
"$",
"day",
")",
"->",
"setTimezone",
"(",
"'utc'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"services",
"as",
"$",
"var",
"=>",
"$",
"hourlyService",
")",
"{",
"/* @var AbstractHourlyService $hourlyService */",
"$",
"stations",
"=",
"$",
"this",
"->",
"getStations",
"(",
"$",
"hourlyService",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"stations",
")",
")",
"{",
"try",
"{",
"$",
"nearestStations",
"=",
"DWDStationsController",
"::",
"getNearestStations",
"(",
"$",
"stations",
",",
"$",
"coordinatesRequest",
")",
";",
"}",
"catch",
"(",
"DWDLibException",
"$",
"exception",
")",
"{",
"$",
"stations",
"=",
"$",
"this",
"->",
"getStations",
"(",
"$",
"hourlyService",
",",
"true",
",",
"true",
")",
";",
"$",
"nearestStations",
"=",
"DWDStationsController",
"::",
"getNearestStations",
"(",
"$",
"stations",
",",
"$",
"coordinatesRequest",
")",
";",
"}",
"foreach",
"(",
"$",
"nearestStations",
"as",
"$",
"nearestStation",
")",
"{",
"/* @var $nearestStation DWDStation */",
"$",
"zipFilePath",
"=",
"$",
"this",
"->",
"retrieveFile",
"(",
"$",
"hourlyService",
",",
"$",
"nearestStation",
")",
";",
"$",
"content",
"=",
"isset",
"(",
"$",
"zipFilePath",
")",
"?",
"DWDUtil",
"::",
"getDataFromZip",
"(",
"$",
"zipFilePath",
",",
"DWDConfiguration",
"::",
"getHourlyConfiguration",
"(",
")",
"->",
"zipExtractionPrefix",
")",
":",
"null",
";",
"//content can only be null if a station is listed as active but is not anymore.",
"if",
"(",
"$",
"content",
"==",
"null",
")",
"{",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"'file for station='",
".",
"$",
"nearestStation",
".",
"' could not be loaded, trying next station'",
")",
";",
"continue",
";",
"}",
"$",
"start",
"=",
"Carbon",
"::",
"instance",
"(",
"$",
"day",
")",
"->",
"startOfDay",
"(",
")",
";",
"$",
"end",
"=",
"Carbon",
"::",
"instance",
"(",
"$",
"day",
")",
"->",
"endOfDay",
"(",
")",
";",
"$",
"parameters",
"[",
"$",
"var",
"]",
"=",
"$",
"hourlyService",
"->",
"parseHourlyData",
"(",
"$",
"content",
",",
"$",
"nearestStation",
",",
"$",
"coordinatesRequest",
",",
"$",
"start",
",",
"$",
"end",
")",
";",
"//$this->retrieveData2($content, $hourlyService, $start, $end);",
"//addStation",
"if",
"(",
"count",
"(",
"$",
"parameters",
"[",
"$",
"var",
"]",
")",
">",
"0",
"&&",
"!",
"isset",
"(",
"$",
"queriedStations",
"[",
"'station-'",
".",
"$",
"nearestStation",
"->",
"getId",
"(",
")",
"]",
")",
")",
"{",
"$",
"queriedStations",
"[",
"'station-'",
".",
"$",
"nearestStation",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"nearestStation",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"$",
"var",
"]",
")",
")",
"break",
";",
"}",
"}",
"}",
"return",
"[",
"$",
"parameters",
",",
"$",
"queriedStations",
"]",
";",
"}"
]
| Get all data for the given day. The parameter day is converted to UTC!
@param Coordinate $coordinatesRequest
@param DateTime $day
@return array [params, stations] | [
"Get",
"all",
"data",
"for",
"the",
"given",
"day",
".",
"The",
"parameter",
"day",
"is",
"converted",
"to",
"UTC!"
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php#L115-L160 |
13,639 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php | DWDHourlyCrawler.getStations | public function getStations(AbstractHourlyService $controller, bool $activeOnly = false, bool $forceDownloadFile = false)
{
$downloadFile = false || $forceDownloadFile;
$stationsFTPPath = DWDConfiguration::getHourlyConfiguration()->parameters;
$stationsFTPPath = get_object_vars($stationsFTPPath)[$controller->getParameter()]->stations;
$filePath = $controller->getStationFTPPath($stationsFTPPath);
//Retrieve Stations
if (file_exists($filePath)) {
$lastModifiedStationFile = Carbon::createFromTimestamp(filemtime($filePath));
$diffInHours = Carbon::now()->diffInHours(Carbon::createFromTimestamp(filemtime($filePath)));
DWDUtil::log(self::class, "last modified? " . $lastModifiedStationFile
. "; difference to today (h)? " . $diffInHours);
$downloadFile = $diffInHours >= 12; //redownload every 12h.
} else
$downloadFile = true;
//todo: determine if this works - had a problem where this did not trigger redownloading of the file, which lead to the no active stations exception.
if ($downloadFile) {
DWDUtil::log(self::class, "Downloading station file=" . $filePath);
DWDStationsController::getStationFile($stationsFTPPath, $filePath);
}
$stations = DWDStationsController::parseStations($filePath);
DWDUtil::log(self::class, "Got stations... " . count($stations));
//todo 31.8.2017: rewrite the "active" part in a way that checks if the queried date is inside the "active" period of stations
if ($activeOnly && count($stations) > 0) {
$stations = array_filter($stations,
function (DWDStation $station) {
return $station->isActive();
});
}
DWDUtil::log(self::class, "Got stations after filtering... " . count($stations));
return $stations;
} | php | public function getStations(AbstractHourlyService $controller, bool $activeOnly = false, bool $forceDownloadFile = false)
{
$downloadFile = false || $forceDownloadFile;
$stationsFTPPath = DWDConfiguration::getHourlyConfiguration()->parameters;
$stationsFTPPath = get_object_vars($stationsFTPPath)[$controller->getParameter()]->stations;
$filePath = $controller->getStationFTPPath($stationsFTPPath);
//Retrieve Stations
if (file_exists($filePath)) {
$lastModifiedStationFile = Carbon::createFromTimestamp(filemtime($filePath));
$diffInHours = Carbon::now()->diffInHours(Carbon::createFromTimestamp(filemtime($filePath)));
DWDUtil::log(self::class, "last modified? " . $lastModifiedStationFile
. "; difference to today (h)? " . $diffInHours);
$downloadFile = $diffInHours >= 12; //redownload every 12h.
} else
$downloadFile = true;
//todo: determine if this works - had a problem where this did not trigger redownloading of the file, which lead to the no active stations exception.
if ($downloadFile) {
DWDUtil::log(self::class, "Downloading station file=" . $filePath);
DWDStationsController::getStationFile($stationsFTPPath, $filePath);
}
$stations = DWDStationsController::parseStations($filePath);
DWDUtil::log(self::class, "Got stations... " . count($stations));
//todo 31.8.2017: rewrite the "active" part in a way that checks if the queried date is inside the "active" period of stations
if ($activeOnly && count($stations) > 0) {
$stations = array_filter($stations,
function (DWDStation $station) {
return $station->isActive();
});
}
DWDUtil::log(self::class, "Got stations after filtering... " . count($stations));
return $stations;
} | [
"public",
"function",
"getStations",
"(",
"AbstractHourlyService",
"$",
"controller",
",",
"bool",
"$",
"activeOnly",
"=",
"false",
",",
"bool",
"$",
"forceDownloadFile",
"=",
"false",
")",
"{",
"$",
"downloadFile",
"=",
"false",
"||",
"$",
"forceDownloadFile",
";",
"$",
"stationsFTPPath",
"=",
"DWDConfiguration",
"::",
"getHourlyConfiguration",
"(",
")",
"->",
"parameters",
";",
"$",
"stationsFTPPath",
"=",
"get_object_vars",
"(",
"$",
"stationsFTPPath",
")",
"[",
"$",
"controller",
"->",
"getParameter",
"(",
")",
"]",
"->",
"stations",
";",
"$",
"filePath",
"=",
"$",
"controller",
"->",
"getStationFTPPath",
"(",
"$",
"stationsFTPPath",
")",
";",
"//Retrieve Stations",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"lastModifiedStationFile",
"=",
"Carbon",
"::",
"createFromTimestamp",
"(",
"filemtime",
"(",
"$",
"filePath",
")",
")",
";",
"$",
"diffInHours",
"=",
"Carbon",
"::",
"now",
"(",
")",
"->",
"diffInHours",
"(",
"Carbon",
"::",
"createFromTimestamp",
"(",
"filemtime",
"(",
"$",
"filePath",
")",
")",
")",
";",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"last modified? \"",
".",
"$",
"lastModifiedStationFile",
".",
"\"; difference to today (h)? \"",
".",
"$",
"diffInHours",
")",
";",
"$",
"downloadFile",
"=",
"$",
"diffInHours",
">=",
"12",
";",
"//redownload every 12h.",
"}",
"else",
"$",
"downloadFile",
"=",
"true",
";",
"//todo: determine if this works - had a problem where this did not trigger redownloading of the file, which lead to the no active stations exception.",
"if",
"(",
"$",
"downloadFile",
")",
"{",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"Downloading station file=\"",
".",
"$",
"filePath",
")",
";",
"DWDStationsController",
"::",
"getStationFile",
"(",
"$",
"stationsFTPPath",
",",
"$",
"filePath",
")",
";",
"}",
"$",
"stations",
"=",
"DWDStationsController",
"::",
"parseStations",
"(",
"$",
"filePath",
")",
";",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"Got stations... \"",
".",
"count",
"(",
"$",
"stations",
")",
")",
";",
"//todo 31.8.2017: rewrite the \"active\" part in a way that checks if the queried date is inside the \"active\" period of stations",
"if",
"(",
"$",
"activeOnly",
"&&",
"count",
"(",
"$",
"stations",
")",
">",
"0",
")",
"{",
"$",
"stations",
"=",
"array_filter",
"(",
"$",
"stations",
",",
"function",
"(",
"DWDStation",
"$",
"station",
")",
"{",
"return",
"$",
"station",
"->",
"isActive",
"(",
")",
";",
"}",
")",
";",
"}",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"Got stations after filtering... \"",
".",
"count",
"(",
"$",
"stations",
")",
")",
";",
"return",
"$",
"stations",
";",
"}"
]
| Retrieves the correct stations file, can be filtered to only show stations that are flagges as active. Conditions
for this can be
@param bool $activeOnly
@return array | [
"Retrieves",
"the",
"correct",
"stations",
"file",
"can",
"be",
"filtered",
"to",
"only",
"show",
"stations",
"that",
"are",
"flagges",
"as",
"active",
".",
"Conditions",
"for",
"this",
"can",
"be"
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php#L168-L203 |
13,640 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php | DWDHourlyCrawler.retrieveFile | public function retrieveFile(AbstractHourlyService $service, DWDStation $nearestStation, $forceDownloadFile = false)
{
$config = DWDConfiguration::getConfiguration();
$ftpConfig = $config->ftp;
$fileName = $service->getFileName($nearestStation->getId());
$ftpPath = $service->getFileFTPPath($nearestStation->getId());
$localPath = $service->getFilePath($fileName);
DWDUtil::log(self::class, '$fileName=' . $fileName);
DWDUtil::log(self::class, '$ftpPath=' . $ftpPath);
DWDUtil::log(self::class, '$localPath=' . $localPath);
//get file.
$ftp_connection = ftp_connect($ftpConfig->url);
//ftp_set_option($ftp_connection, FTP_TIMEOUT_SEC, 9000);
$files = array();
if (file_exists($localPath)) {
$lastModifiedStationFile = Carbon::createFromFormat('U', (filemtime($localPath)));
}
//check if the date on the old file is older than 1 day, else return the old path.
// download can be forced with the optional parameter.
if ($forceDownloadFile || !file_exists($localPath)
|| (isset($lastModifiedStationFile) && $lastModifiedStationFile->diffInDays(Carbon::now()) >= 1)
) {
//echo "<p>Controller::retrieveFile >> load new zip!</p>";
$path = pathinfo($localPath);
if (!is_dir($path['dirname'])) {
mkdir($path['dirname'], 0755, true);
}
if (ftp_login($ftp_connection, $ftpConfig->userName, $ftpConfig->userPassword)) {
// DWDUtil::log(self::class, 'File "' . $ftpPath . '"exists on server? ' . ftp_size($ftp_connection, $ftpPath));
if (ftp_size($ftp_connection, $ftpPath) > -1 && ftp_get($ftp_connection, $localPath, $ftpPath, FTP_BINARY)) {
$files[] = $localPath;
} else {
return null;
}
ftp_close($ftp_connection);
return $localPath;
}
}
return $localPath;
} | php | public function retrieveFile(AbstractHourlyService $service, DWDStation $nearestStation, $forceDownloadFile = false)
{
$config = DWDConfiguration::getConfiguration();
$ftpConfig = $config->ftp;
$fileName = $service->getFileName($nearestStation->getId());
$ftpPath = $service->getFileFTPPath($nearestStation->getId());
$localPath = $service->getFilePath($fileName);
DWDUtil::log(self::class, '$fileName=' . $fileName);
DWDUtil::log(self::class, '$ftpPath=' . $ftpPath);
DWDUtil::log(self::class, '$localPath=' . $localPath);
//get file.
$ftp_connection = ftp_connect($ftpConfig->url);
//ftp_set_option($ftp_connection, FTP_TIMEOUT_SEC, 9000);
$files = array();
if (file_exists($localPath)) {
$lastModifiedStationFile = Carbon::createFromFormat('U', (filemtime($localPath)));
}
//check if the date on the old file is older than 1 day, else return the old path.
// download can be forced with the optional parameter.
if ($forceDownloadFile || !file_exists($localPath)
|| (isset($lastModifiedStationFile) && $lastModifiedStationFile->diffInDays(Carbon::now()) >= 1)
) {
//echo "<p>Controller::retrieveFile >> load new zip!</p>";
$path = pathinfo($localPath);
if (!is_dir($path['dirname'])) {
mkdir($path['dirname'], 0755, true);
}
if (ftp_login($ftp_connection, $ftpConfig->userName, $ftpConfig->userPassword)) {
// DWDUtil::log(self::class, 'File "' . $ftpPath . '"exists on server? ' . ftp_size($ftp_connection, $ftpPath));
if (ftp_size($ftp_connection, $ftpPath) > -1 && ftp_get($ftp_connection, $localPath, $ftpPath, FTP_BINARY)) {
$files[] = $localPath;
} else {
return null;
}
ftp_close($ftp_connection);
return $localPath;
}
}
return $localPath;
} | [
"public",
"function",
"retrieveFile",
"(",
"AbstractHourlyService",
"$",
"service",
",",
"DWDStation",
"$",
"nearestStation",
",",
"$",
"forceDownloadFile",
"=",
"false",
")",
"{",
"$",
"config",
"=",
"DWDConfiguration",
"::",
"getConfiguration",
"(",
")",
";",
"$",
"ftpConfig",
"=",
"$",
"config",
"->",
"ftp",
";",
"$",
"fileName",
"=",
"$",
"service",
"->",
"getFileName",
"(",
"$",
"nearestStation",
"->",
"getId",
"(",
")",
")",
";",
"$",
"ftpPath",
"=",
"$",
"service",
"->",
"getFileFTPPath",
"(",
"$",
"nearestStation",
"->",
"getId",
"(",
")",
")",
";",
"$",
"localPath",
"=",
"$",
"service",
"->",
"getFilePath",
"(",
"$",
"fileName",
")",
";",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"'$fileName='",
".",
"$",
"fileName",
")",
";",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"'$ftpPath='",
".",
"$",
"ftpPath",
")",
";",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"'$localPath='",
".",
"$",
"localPath",
")",
";",
"//get file.",
"$",
"ftp_connection",
"=",
"ftp_connect",
"(",
"$",
"ftpConfig",
"->",
"url",
")",
";",
"//ftp_set_option($ftp_connection, FTP_TIMEOUT_SEC, 9000);",
"$",
"files",
"=",
"array",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"localPath",
")",
")",
"{",
"$",
"lastModifiedStationFile",
"=",
"Carbon",
"::",
"createFromFormat",
"(",
"'U'",
",",
"(",
"filemtime",
"(",
"$",
"localPath",
")",
")",
")",
";",
"}",
"//check if the date on the old file is older than 1 day, else return the old path.",
"// download can be forced with the optional parameter.",
"if",
"(",
"$",
"forceDownloadFile",
"||",
"!",
"file_exists",
"(",
"$",
"localPath",
")",
"||",
"(",
"isset",
"(",
"$",
"lastModifiedStationFile",
")",
"&&",
"$",
"lastModifiedStationFile",
"->",
"diffInDays",
"(",
"Carbon",
"::",
"now",
"(",
")",
")",
">=",
"1",
")",
")",
"{",
"//echo \"<p>Controller::retrieveFile >> load new zip!</p>\";",
"$",
"path",
"=",
"pathinfo",
"(",
"$",
"localPath",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
"[",
"'dirname'",
"]",
")",
")",
"{",
"mkdir",
"(",
"$",
"path",
"[",
"'dirname'",
"]",
",",
"0755",
",",
"true",
")",
";",
"}",
"if",
"(",
"ftp_login",
"(",
"$",
"ftp_connection",
",",
"$",
"ftpConfig",
"->",
"userName",
",",
"$",
"ftpConfig",
"->",
"userPassword",
")",
")",
"{",
"// DWDUtil::log(self::class, 'File \"' . $ftpPath . '\"exists on server? ' . ftp_size($ftp_connection, $ftpPath));",
"if",
"(",
"ftp_size",
"(",
"$",
"ftp_connection",
",",
"$",
"ftpPath",
")",
">",
"-",
"1",
"&&",
"ftp_get",
"(",
"$",
"ftp_connection",
",",
"$",
"localPath",
",",
"$",
"ftpPath",
",",
"FTP_BINARY",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"localPath",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"ftp_close",
"(",
"$",
"ftp_connection",
")",
";",
"return",
"$",
"localPath",
";",
"}",
"}",
"return",
"$",
"localPath",
";",
"}"
]
| Retrieves a file for the controller by querying the nearest station.
@param AbstractHourlyService $service
@param DWDStation $nearestStation
@param bool $forceDownloadFile
@return string filePath | [
"Retrieves",
"a",
"file",
"for",
"the",
"controller",
"by",
"querying",
"the",
"nearest",
"station",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php#L211-L257 |
13,641 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php | DWDHourlyCrawler.retrieveData | private function retrieveData($content, DWDStation $nearestStation, Coordinate $coordinate, AbstractHourlyService $hourlyController, DateTime $dateTime, $timeMinuteLimit)
{
//custom time limit
$timeBefore = Carbon::instance($dateTime);
$timeAfter = Carbon::instance($dateTime);
$timeBefore->addMinute($timeMinuteLimit);
$timeAfter->addMinute(-$timeMinuteLimit);
$data = $hourlyController->parseHourlyData($content, $nearestStation, $coordinate, $timeAfter, $timeBefore);
// 3 hour interval -> +- 90min if custom failed.
if (count($data) == 0 && $timeMinuteLimit < 90) {
DWDUtil::log(self::class, "retrieving data for a +-90min time limit...");
$data = $this->retrieveData($content, $nearestStation, $coordinate, $hourlyController, $dateTime, 90);
} else // 7 hour interval -> +-210min if custom and 3h limit failed.
if (count($data) == 0 && $timeMinuteLimit < 210) {
DWDUtil::log(self::class, "retrieving data for a +-210min time limit...");
$data = $this->retrieveData($content, $nearestStation, $coordinate, $hourlyController, $dateTime, 210);
}
return $data;
} | php | private function retrieveData($content, DWDStation $nearestStation, Coordinate $coordinate, AbstractHourlyService $hourlyController, DateTime $dateTime, $timeMinuteLimit)
{
//custom time limit
$timeBefore = Carbon::instance($dateTime);
$timeAfter = Carbon::instance($dateTime);
$timeBefore->addMinute($timeMinuteLimit);
$timeAfter->addMinute(-$timeMinuteLimit);
$data = $hourlyController->parseHourlyData($content, $nearestStation, $coordinate, $timeAfter, $timeBefore);
// 3 hour interval -> +- 90min if custom failed.
if (count($data) == 0 && $timeMinuteLimit < 90) {
DWDUtil::log(self::class, "retrieving data for a +-90min time limit...");
$data = $this->retrieveData($content, $nearestStation, $coordinate, $hourlyController, $dateTime, 90);
} else // 7 hour interval -> +-210min if custom and 3h limit failed.
if (count($data) == 0 && $timeMinuteLimit < 210) {
DWDUtil::log(self::class, "retrieving data for a +-210min time limit...");
$data = $this->retrieveData($content, $nearestStation, $coordinate, $hourlyController, $dateTime, 210);
}
return $data;
} | [
"private",
"function",
"retrieveData",
"(",
"$",
"content",
",",
"DWDStation",
"$",
"nearestStation",
",",
"Coordinate",
"$",
"coordinate",
",",
"AbstractHourlyService",
"$",
"hourlyController",
",",
"DateTime",
"$",
"dateTime",
",",
"$",
"timeMinuteLimit",
")",
"{",
"//custom time limit",
"$",
"timeBefore",
"=",
"Carbon",
"::",
"instance",
"(",
"$",
"dateTime",
")",
";",
"$",
"timeAfter",
"=",
"Carbon",
"::",
"instance",
"(",
"$",
"dateTime",
")",
";",
"$",
"timeBefore",
"->",
"addMinute",
"(",
"$",
"timeMinuteLimit",
")",
";",
"$",
"timeAfter",
"->",
"addMinute",
"(",
"-",
"$",
"timeMinuteLimit",
")",
";",
"$",
"data",
"=",
"$",
"hourlyController",
"->",
"parseHourlyData",
"(",
"$",
"content",
",",
"$",
"nearestStation",
",",
"$",
"coordinate",
",",
"$",
"timeAfter",
",",
"$",
"timeBefore",
")",
";",
"// 3 hour interval -> +- 90min if custom failed.",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"==",
"0",
"&&",
"$",
"timeMinuteLimit",
"<",
"90",
")",
"{",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"retrieving data for a +-90min time limit...\"",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"retrieveData",
"(",
"$",
"content",
",",
"$",
"nearestStation",
",",
"$",
"coordinate",
",",
"$",
"hourlyController",
",",
"$",
"dateTime",
",",
"90",
")",
";",
"}",
"else",
"// 7 hour interval -> +-210min if custom and 3h limit failed.",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"==",
"0",
"&&",
"$",
"timeMinuteLimit",
"<",
"210",
")",
"{",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"retrieving data for a +-210min time limit...\"",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"retrieveData",
"(",
"$",
"content",
",",
"$",
"nearestStation",
",",
"$",
"coordinate",
",",
"$",
"hourlyController",
",",
"$",
"dateTime",
",",
"210",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| DWD Hourly data is not really hourly, as such first try to query with the specified limit, then, if the limit is smaller than +-1.5h or +-3.5h
Query those values and return them.
@param $content - of the zip
@param AbstractHourlyService $hourlyController - the controller that should parse the data
@param DateTime $dateTime - the data for which we want to query
@param $timeMinuteLimit - limit in minutes that defines the range: currentDate+-limit = search range.
@return array of DWDAbstractParameter | [
"DWD",
"Hourly",
"data",
"is",
"not",
"really",
"hourly",
"as",
"such",
"first",
"try",
"to",
"query",
"with",
"the",
"specified",
"limit",
"then",
"if",
"the",
"limit",
"is",
"smaller",
"than",
"+",
"-",
"1",
".",
"5h",
"or",
"+",
"-",
"3",
".",
"5h",
"Query",
"those",
"values",
"and",
"return",
"them",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDHourlyCrawler.php#L269-L291 |
13,642 | redCOMPONENT-COM/robo | src/RoboFile.dist.php | RoboFile.sendCodeceptionOutputToSlack | public function sendCodeceptionOutputToSlack($slackChannel, $slackToken = null, $codeceptionOutputFolder = null)
{
if (is_null($slackToken)) {
$this->say('we are in Travis environment, getting token from ENV');
// Remind to set the token in repo Travis settings,
// see: http://docs.travis-ci.com/user/environment-variables/#Using-Settings
$slackToken = getenv('SLACK_ENCRYPTED_TOKEN');
}
$result = $this
->taskSendCodeceptionOutputToSlack(
$slackChannel,
$slackToken,
$codeceptionOutputFolder
)
->run();
return $result;
} | php | public function sendCodeceptionOutputToSlack($slackChannel, $slackToken = null, $codeceptionOutputFolder = null)
{
if (is_null($slackToken)) {
$this->say('we are in Travis environment, getting token from ENV');
// Remind to set the token in repo Travis settings,
// see: http://docs.travis-ci.com/user/environment-variables/#Using-Settings
$slackToken = getenv('SLACK_ENCRYPTED_TOKEN');
}
$result = $this
->taskSendCodeceptionOutputToSlack(
$slackChannel,
$slackToken,
$codeceptionOutputFolder
)
->run();
return $result;
} | [
"public",
"function",
"sendCodeceptionOutputToSlack",
"(",
"$",
"slackChannel",
",",
"$",
"slackToken",
"=",
"null",
",",
"$",
"codeceptionOutputFolder",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"slackToken",
")",
")",
"{",
"$",
"this",
"->",
"say",
"(",
"'we are in Travis environment, getting token from ENV'",
")",
";",
"// Remind to set the token in repo Travis settings,",
"// see: http://docs.travis-ci.com/user/environment-variables/#Using-Settings",
"$",
"slackToken",
"=",
"getenv",
"(",
"'SLACK_ENCRYPTED_TOKEN'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"taskSendCodeceptionOutputToSlack",
"(",
"$",
"slackChannel",
",",
"$",
"slackToken",
",",
"$",
"codeceptionOutputFolder",
")",
"->",
"run",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Sends Codeception errors to Slack
@param string $slackChannel The Slack Channel ID
@param string $slackToken Your Slack authentication token.
@param string $codeceptionOutputFolder Optional. By default tests/_output
@return mixed | [
"Sends",
"Codeception",
"errors",
"to",
"Slack"
]
| ee480b13a6e8a28ab72816406f84ce257c5b806a | https://github.com/redCOMPONENT-COM/robo/blob/ee480b13a6e8a28ab72816406f84ce257c5b806a/src/RoboFile.dist.php#L48-L67 |
13,643 | terdia/legato-framework | src/Request.php | Request.input | public function input($key, $default = false)
{
return $this->getRequestInputByType()->has($key) ?
$this->getRequestInputByType()->get($key) : $default;
} | php | public function input($key, $default = false)
{
return $this->getRequestInputByType()->has($key) ?
$this->getRequestInputByType()->get($key) : $default;
} | [
"public",
"function",
"input",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"getRequestInputByType",
"(",
")",
"->",
"has",
"(",
"$",
"key",
")",
"?",
"$",
"this",
"->",
"getRequestInputByType",
"(",
")",
"->",
"get",
"(",
"$",
"key",
")",
":",
"$",
"default",
";",
"}"
]
| Get a request parameter by key.
@param $key
@param bool $default
@return bool|mixed | [
"Get",
"a",
"request",
"parameter",
"by",
"key",
"."
]
| 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Request.php#L42-L46 |
13,644 | terdia/legato-framework | src/Request.php | Request.getRequestInputByType | public function getRequestInputByType()
{
$data = $this->instance->getRealMethod() == 'GET' ? HttpFoundation::createFromGlobals()->query :
HttpFoundation::createFromGlobals()->request;
if ($data) {
foreach ($data->all() as $key => $value) {
session()->createFlashMessage($key, $value);
}
session()->createFlashMessage('request', $data);
}
return $data;
} | php | public function getRequestInputByType()
{
$data = $this->instance->getRealMethod() == 'GET' ? HttpFoundation::createFromGlobals()->query :
HttpFoundation::createFromGlobals()->request;
if ($data) {
foreach ($data->all() as $key => $value) {
session()->createFlashMessage($key, $value);
}
session()->createFlashMessage('request', $data);
}
return $data;
} | [
"public",
"function",
"getRequestInputByType",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"instance",
"->",
"getRealMethod",
"(",
")",
"==",
"'GET'",
"?",
"HttpFoundation",
"::",
"createFromGlobals",
"(",
")",
"->",
"query",
":",
"HttpFoundation",
"::",
"createFromGlobals",
"(",
")",
"->",
"request",
";",
"if",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"->",
"all",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"session",
"(",
")",
"->",
"createFlashMessage",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"session",
"(",
")",
"->",
"createFlashMessage",
"(",
"'request'",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| get the request data base on request method.
@return \Symfony\Component\HttpFoundation\ParameterBag | [
"get",
"the",
"request",
"data",
"base",
"on",
"request",
"method",
"."
]
| 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Request.php#L83-L97 |
13,645 | terdia/legato-framework | src/Request.php | Request.getHeader | public function getHeader($key, $default = false)
{
return $this->headers->has($key) ? $this->headers->get($key) : $default;
} | php | public function getHeader($key, $default = false)
{
return $this->headers->has($key) ? $this->headers->get($key) : $default;
} | [
"public",
"function",
"getHeader",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"headers",
"->",
"has",
"(",
"$",
"key",
")",
"?",
"$",
"this",
"->",
"headers",
"->",
"get",
"(",
"$",
"key",
")",
":",
"$",
"default",
";",
"}"
]
| Get specific header.
@param $key
@param bool $default
@return bool|string|string[] | [
"Get",
"specific",
"header",
"."
]
| 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Request.php#L127-L130 |
13,646 | terdia/legato-framework | src/Request.php | Request.old | public static function old($key = null)
{
if (is_null($key)) {
return session()->getFlashMessage('request') ?: '';
}
return session()->getFlashMessage($key) ?: '';
} | php | public static function old($key = null)
{
if (is_null($key)) {
return session()->getFlashMessage('request') ?: '';
}
return session()->getFlashMessage($key) ?: '';
} | [
"public",
"static",
"function",
"old",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"return",
"session",
"(",
")",
"->",
"getFlashMessage",
"(",
"'request'",
")",
"?",
":",
"''",
";",
"}",
"return",
"session",
"(",
")",
"->",
"getFlashMessage",
"(",
"$",
"key",
")",
"?",
":",
"''",
";",
"}"
]
| Get old request value from session.
@param $key
@return string | [
"Get",
"old",
"request",
"value",
"from",
"session",
"."
]
| 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Request.php#L200-L207 |
13,647 | transfer-framework/transfer | src/Transfer/Procedure/Procedure.php | Procedure.createFromDefinition | public static function createFromDefinition(array $definition, Procedure $parent = null)
{
$procedure = new self(
$definition['name'],
$definition['sources'],
$definition['workers'],
$definition['targets'],
$parent
);
foreach ($definition['children'] as $child) {
$procedure->addChild(self::createFromDefinition($child, $procedure));
}
return $procedure;
} | php | public static function createFromDefinition(array $definition, Procedure $parent = null)
{
$procedure = new self(
$definition['name'],
$definition['sources'],
$definition['workers'],
$definition['targets'],
$parent
);
foreach ($definition['children'] as $child) {
$procedure->addChild(self::createFromDefinition($child, $procedure));
}
return $procedure;
} | [
"public",
"static",
"function",
"createFromDefinition",
"(",
"array",
"$",
"definition",
",",
"Procedure",
"$",
"parent",
"=",
"null",
")",
"{",
"$",
"procedure",
"=",
"new",
"self",
"(",
"$",
"definition",
"[",
"'name'",
"]",
",",
"$",
"definition",
"[",
"'sources'",
"]",
",",
"$",
"definition",
"[",
"'workers'",
"]",
",",
"$",
"definition",
"[",
"'targets'",
"]",
",",
"$",
"parent",
")",
";",
"foreach",
"(",
"$",
"definition",
"[",
"'children'",
"]",
"as",
"$",
"child",
")",
"{",
"$",
"procedure",
"->",
"addChild",
"(",
"self",
"::",
"createFromDefinition",
"(",
"$",
"child",
",",
"$",
"procedure",
")",
")",
";",
"}",
"return",
"$",
"procedure",
";",
"}"
]
| Creates a procedure from a definition.
Procedure definition must be an array consisting of following elements:
* name : string
* sources : array of source adapters
* workers : array of workers
* targets : array of target adapters
@param array $definition Procedure definition (how a procedure should be built)
@param Procedure $parent Parent procedure
@return Procedure | [
"Creates",
"a",
"procedure",
"from",
"a",
"definition",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Procedure/Procedure.php#L77-L92 |
13,648 | transfer-framework/transfer | src/Transfer/Procedure/Procedure.php | Procedure.getParentSettings | private function getParentSettings($type, $context = null)
{
$context = $this->normalizeContext($context);
$methods = array(
'source' => 'getSources',
'worker' => 'getWorkers',
'target' => 'getTargets',
);
if (!array_key_exists($type, $methods) || $context->getParent() === null) {
return array();
}
$settings = array_merge(
$this->getParentComponentSettings($context->getParent(), $methods[$type]),
$this->getParentSettings($type, $context->getParent())
);
return $settings;
} | php | private function getParentSettings($type, $context = null)
{
$context = $this->normalizeContext($context);
$methods = array(
'source' => 'getSources',
'worker' => 'getWorkers',
'target' => 'getTargets',
);
if (!array_key_exists($type, $methods) || $context->getParent() === null) {
return array();
}
$settings = array_merge(
$this->getParentComponentSettings($context->getParent(), $methods[$type]),
$this->getParentSettings($type, $context->getParent())
);
return $settings;
} | [
"private",
"function",
"getParentSettings",
"(",
"$",
"type",
",",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"normalizeContext",
"(",
"$",
"context",
")",
";",
"$",
"methods",
"=",
"array",
"(",
"'source'",
"=>",
"'getSources'",
",",
"'worker'",
"=>",
"'getWorkers'",
",",
"'target'",
"=>",
"'getTargets'",
",",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"methods",
")",
"||",
"$",
"context",
"->",
"getParent",
"(",
")",
"===",
"null",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"settings",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getParentComponentSettings",
"(",
"$",
"context",
"->",
"getParent",
"(",
")",
",",
"$",
"methods",
"[",
"$",
"type",
"]",
")",
",",
"$",
"this",
"->",
"getParentSettings",
"(",
"$",
"type",
",",
"$",
"context",
"->",
"getParent",
"(",
")",
")",
")",
";",
"return",
"$",
"settings",
";",
"}"
]
| Returns parent settings.
@param string $type Setting type (source, worker or target)
@param Procedure $context
@return array Setting collection
@internal | [
"Returns",
"parent",
"settings",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Procedure/Procedure.php#L213-L233 |
13,649 | attm2x/m2x-php | src/DeviceCollection.php | DeviceCollection.path | protected function path() {
if ($this->parent) {
return $this->parent->path() . '/devices';
}
$class = static::$resourceClass;
$path = $class::$path;
if ($this->catalog) {
$path .= '/catalog';
}
return $path;
} | php | protected function path() {
if ($this->parent) {
return $this->parent->path() . '/devices';
}
$class = static::$resourceClass;
$path = $class::$path;
if ($this->catalog) {
$path .= '/catalog';
}
return $path;
} | [
"protected",
"function",
"path",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parent",
")",
"{",
"return",
"$",
"this",
"->",
"parent",
"->",
"path",
"(",
")",
".",
"'/devices'",
";",
"}",
"$",
"class",
"=",
"static",
"::",
"$",
"resourceClass",
";",
"$",
"path",
"=",
"$",
"class",
"::",
"$",
"path",
";",
"if",
"(",
"$",
"this",
"->",
"catalog",
")",
"{",
"$",
"path",
".=",
"'/catalog'",
";",
"}",
"return",
"$",
"path",
";",
"}"
]
| Return the API path for the query
@return void | [
"Return",
"the",
"API",
"path",
"for",
"the",
"query"
]
| 4c2ff6d70af50538818855e648af24bf5cf16ead | https://github.com/attm2x/m2x-php/blob/4c2ff6d70af50538818855e648af24bf5cf16ead/src/DeviceCollection.php#L62-L73 |
13,650 | reinvanoyen/aegis | lib/Aegis/Node.php | Node.getAttribute | public function getAttribute(int $index) : ?Node
{
return isset($this->attributes[$index]) ? $this->attributes[$index] : null;
} | php | public function getAttribute(int $index) : ?Node
{
return isset($this->attributes[$index]) ? $this->attributes[$index] : null;
} | [
"public",
"function",
"getAttribute",
"(",
"int",
"$",
"index",
")",
":",
"?",
"Node",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"index",
"]",
")",
"?",
"$",
"this",
"->",
"attributes",
"[",
"$",
"index",
"]",
":",
"null",
";",
"}"
]
| Gets an attribute node
@param int $index
@return Node|null | [
"Gets",
"an",
"attribute",
"node"
]
| ecd831fd6f3ceb4fb20fb5af83483d73cad8e323 | https://github.com/reinvanoyen/aegis/blob/ecd831fd6f3ceb4fb20fb5af83483d73cad8e323/lib/Aegis/Node.php#L59-L62 |
13,651 | reinvanoyen/aegis | lib/Aegis/Node.php | Node.getChild | public function getChild(int $index) : Node
{
if (!isset($this->children[$index])) {
throw new AegisError('Could not get child from node, because there\'s no child at index '.$i);
}
return $this->children[$index];
} | php | public function getChild(int $index) : Node
{
if (!isset($this->children[$index])) {
throw new AegisError('Could not get child from node, because there\'s no child at index '.$i);
}
return $this->children[$index];
} | [
"public",
"function",
"getChild",
"(",
"int",
"$",
"index",
")",
":",
"Node",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"index",
"]",
")",
")",
"{",
"throw",
"new",
"AegisError",
"(",
"'Could not get child from node, because there\\'s no child at index '",
".",
"$",
"i",
")",
";",
"}",
"return",
"$",
"this",
"->",
"children",
"[",
"$",
"index",
"]",
";",
"}"
]
| Gets the child at the given index
@param int $index
@return Node
@throws AegisError | [
"Gets",
"the",
"child",
"at",
"the",
"given",
"index"
]
| ecd831fd6f3ceb4fb20fb5af83483d73cad8e323 | https://github.com/reinvanoyen/aegis/blob/ecd831fd6f3ceb4fb20fb5af83483d73cad8e323/lib/Aegis/Node.php#L116-L123 |
13,652 | reinvanoyen/aegis | lib/Aegis/Node.php | Node.removeChild | public function removeChild(int $index)
{
if (!isset($this->children[$index])) {
throw new AegisError('Could remove child from node, because there\'s no child at index '.$index);
}
unset($this->children[$index]);
} | php | public function removeChild(int $index)
{
if (!isset($this->children[$index])) {
throw new AegisError('Could remove child from node, because there\'s no child at index '.$index);
}
unset($this->children[$index]);
} | [
"public",
"function",
"removeChild",
"(",
"int",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"index",
"]",
")",
")",
"{",
"throw",
"new",
"AegisError",
"(",
"'Could remove child from node, because there\\'s no child at index '",
".",
"$",
"index",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"index",
"]",
")",
";",
"}"
]
| Removes the child node at the given index
@param int $index
@throws AegisError | [
"Removes",
"the",
"child",
"node",
"at",
"the",
"given",
"index"
]
| ecd831fd6f3ceb4fb20fb5af83483d73cad8e323 | https://github.com/reinvanoyen/aegis/blob/ecd831fd6f3ceb4fb20fb5af83483d73cad8e323/lib/Aegis/Node.php#L148-L155 |
13,653 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Input/Checkbox.php | Checkbox.setValue | public function setValue($value)
{
if ($value == $this->getAttribute('value')) {
$this->check();
} else {
$this->uncheck();
}
return $this;
} | php | public function setValue($value)
{
if ($value == $this->getAttribute('value')) {
$this->check();
} else {
$this->uncheck();
}
return $this;
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"$",
"this",
"->",
"getAttribute",
"(",
"'value'",
")",
")",
"{",
"$",
"this",
"->",
"check",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"uncheck",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the value of the form input element object
@param mixed $value
@return Checkbox | [
"Set",
"the",
"value",
"of",
"the",
"form",
"input",
"element",
"object"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Input/Checkbox.php#L39-L47 |
13,654 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.isSubmitted | public function isSubmitted()
{
$postParams = $this->request->getParsedBody();
if(count($postParams)> 0)
{
$this->setFieldValues($postParams);
}
return (count($postParams)> 0);
} | php | public function isSubmitted()
{
$postParams = $this->request->getParsedBody();
if(count($postParams)> 0)
{
$this->setFieldValues($postParams);
}
return (count($postParams)> 0);
} | [
"public",
"function",
"isSubmitted",
"(",
")",
"{",
"$",
"postParams",
"=",
"$",
"this",
"->",
"request",
"->",
"getParsedBody",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"postParams",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setFieldValues",
"(",
"$",
"postParams",
")",
";",
"}",
"return",
"(",
"count",
"(",
"$",
"postParams",
")",
">",
"0",
")",
";",
"}"
]
| Method to verify a form isSubmitted
@return boolean | [
"Method",
"to",
"verify",
"a",
"form",
"isSubmitted"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L88-L97 |
13,655 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.createFieldset | public function createFieldset($legend = null, $container = null)
{
$fieldset = new Fieldset();
if (null !== $legend) {
$fieldset->setLegend($legend);
}
if (null !== $container) {
$fieldset->setContainer($container);
}
$this->addFieldset($fieldset);
$id = (null !== $this->getAttribute('id')) ?
$this->getAttribute('id') . '-fieldset-' . ($this->current + 1) : 'pop-form-fieldset-' . ($this->current + 1);
$class = (null !== $this->getAttribute('class')) ?
$this->getAttribute('id') . '-fieldset' : 'pop-form-fieldset';
$fieldset->setAttribute('id', $id);
$fieldset->setAttribute('class', $class);
return $fieldset;
} | php | public function createFieldset($legend = null, $container = null)
{
$fieldset = new Fieldset();
if (null !== $legend) {
$fieldset->setLegend($legend);
}
if (null !== $container) {
$fieldset->setContainer($container);
}
$this->addFieldset($fieldset);
$id = (null !== $this->getAttribute('id')) ?
$this->getAttribute('id') . '-fieldset-' . ($this->current + 1) : 'pop-form-fieldset-' . ($this->current + 1);
$class = (null !== $this->getAttribute('class')) ?
$this->getAttribute('id') . '-fieldset' : 'pop-form-fieldset';
$fieldset->setAttribute('id', $id);
$fieldset->setAttribute('class', $class);
return $fieldset;
} | [
"public",
"function",
"createFieldset",
"(",
"$",
"legend",
"=",
"null",
",",
"$",
"container",
"=",
"null",
")",
"{",
"$",
"fieldset",
"=",
"new",
"Fieldset",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"legend",
")",
"{",
"$",
"fieldset",
"->",
"setLegend",
"(",
"$",
"legend",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"container",
")",
"{",
"$",
"fieldset",
"->",
"setContainer",
"(",
"$",
"container",
")",
";",
"}",
"$",
"this",
"->",
"addFieldset",
"(",
"$",
"fieldset",
")",
";",
"$",
"id",
"=",
"(",
"null",
"!==",
"$",
"this",
"->",
"getAttribute",
"(",
"'id'",
")",
")",
"?",
"$",
"this",
"->",
"getAttribute",
"(",
"'id'",
")",
".",
"'-fieldset-'",
".",
"(",
"$",
"this",
"->",
"current",
"+",
"1",
")",
":",
"'pop-form-fieldset-'",
".",
"(",
"$",
"this",
"->",
"current",
"+",
"1",
")",
";",
"$",
"class",
"=",
"(",
"null",
"!==",
"$",
"this",
"->",
"getAttribute",
"(",
"'class'",
")",
")",
"?",
"$",
"this",
"->",
"getAttribute",
"(",
"'id'",
")",
".",
"'-fieldset'",
":",
"'pop-form-fieldset'",
";",
"$",
"fieldset",
"->",
"setAttribute",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"$",
"fieldset",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"class",
")",
";",
"return",
"$",
"fieldset",
";",
"}"
]
| Method to create a new fieldset object
@param string $legend
@param string $container
@return Fieldset | [
"Method",
"to",
"create",
"a",
"new",
"fieldset",
"object"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L121-L138 |
13,656 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.setAttribute | public function setAttribute($a, $v)
{
parent::setAttribute($a, $v);
if ($a == 'id') {
foreach ($this->fieldsets as $i => $fieldset) {
$id = $v . '-fieldset-' . ($i + 1);
$fieldset->setAttribute('id', $id);
}
} else if ($a == 'class') {
foreach ($this->fieldsets as $i => $fieldset) {
$class = $v . '-fieldset';
$fieldset->setAttribute('class', $class);
}
}
return $this;
} | php | public function setAttribute($a, $v)
{
parent::setAttribute($a, $v);
if ($a == 'id') {
foreach ($this->fieldsets as $i => $fieldset) {
$id = $v . '-fieldset-' . ($i + 1);
$fieldset->setAttribute('id', $id);
}
} else if ($a == 'class') {
foreach ($this->fieldsets as $i => $fieldset) {
$class = $v . '-fieldset';
$fieldset->setAttribute('class', $class);
}
}
return $this;
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"a",
",",
"$",
"v",
")",
"{",
"parent",
"::",
"setAttribute",
"(",
"$",
"a",
",",
"$",
"v",
")",
";",
"if",
"(",
"$",
"a",
"==",
"'id'",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"i",
"=>",
"$",
"fieldset",
")",
"{",
"$",
"id",
"=",
"$",
"v",
".",
"'-fieldset-'",
".",
"(",
"$",
"i",
"+",
"1",
")",
";",
"$",
"fieldset",
"->",
"setAttribute",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"a",
"==",
"'class'",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"i",
"=>",
"$",
"fieldset",
")",
"{",
"$",
"class",
"=",
"$",
"v",
".",
"'-fieldset'",
";",
"$",
"fieldset",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"class",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to set an attribute
@param string $a
@param string $v
@return Form | [
"Method",
"to",
"set",
"an",
"attribute"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L186-L201 |
13,657 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.setAttributes | public function setAttributes(array $a)
{
foreach ($a as $name => $value) {
$this->setAttribute($name, $value);
}
return $this;
} | php | public function setAttributes(array $a)
{
foreach ($a as $name => $value) {
$this->setAttribute($name, $value);
}
return $this;
} | [
"public",
"function",
"setAttributes",
"(",
"array",
"$",
"a",
")",
"{",
"foreach",
"(",
"$",
"a",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to set attributes
@param array $a
@return Form | [
"Method",
"to",
"set",
"attributes"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L208-L214 |
13,658 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.addFieldset | public function addFieldset(Fieldset $fieldset)
{
$this->fieldsets[] = $fieldset;
$this->current = count($this->fieldsets) - 1;
return $this;
} | php | public function addFieldset(Fieldset $fieldset)
{
$this->fieldsets[] = $fieldset;
$this->current = count($this->fieldsets) - 1;
return $this;
} | [
"public",
"function",
"addFieldset",
"(",
"Fieldset",
"$",
"fieldset",
")",
"{",
"$",
"this",
"->",
"fieldsets",
"[",
"]",
"=",
"$",
"fieldset",
";",
"$",
"this",
"->",
"current",
"=",
"count",
"(",
"$",
"this",
"->",
"fieldsets",
")",
"-",
"1",
";",
"return",
"$",
"this",
";",
"}"
]
| Method to add fieldset
@param Fieldset $fieldset
@return Form | [
"Method",
"to",
"add",
"fieldset"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L221-L226 |
13,659 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.removeFieldset | public function removeFieldset($i)
{
if (isset($this->fieldsets[(int)$i])) {
unset($this->fieldsets[(int)$i]);
}
$this->fieldsets = array_values($this->fieldsets);
if (!isset($this->fieldsets[$this->current])) {
$this->current = (count($this->fieldsets) > 0) ? count($this->fieldsets) - 1 : 0;
}
return $this;
} | php | public function removeFieldset($i)
{
if (isset($this->fieldsets[(int)$i])) {
unset($this->fieldsets[(int)$i]);
}
$this->fieldsets = array_values($this->fieldsets);
if (!isset($this->fieldsets[$this->current])) {
$this->current = (count($this->fieldsets) > 0) ? count($this->fieldsets) - 1 : 0;
}
return $this;
} | [
"public",
"function",
"removeFieldset",
"(",
"$",
"i",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"(",
"int",
")",
"$",
"i",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"(",
"int",
")",
"$",
"i",
"]",
")",
";",
"}",
"$",
"this",
"->",
"fieldsets",
"=",
"array_values",
"(",
"$",
"this",
"->",
"fieldsets",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
")",
")",
"{",
"$",
"this",
"->",
"current",
"=",
"(",
"count",
"(",
"$",
"this",
"->",
"fieldsets",
")",
">",
"0",
")",
"?",
"count",
"(",
"$",
"this",
"->",
"fieldsets",
")",
"-",
"1",
":",
"0",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to remove fieldset
@param int $i
@return Form | [
"Method",
"to",
"remove",
"fieldset"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L233-L243 |
13,660 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.getFieldset | public function getFieldset()
{
return (isset($this->fieldsets[$this->current])) ? $this->fieldsets[$this->current] : null;
} | php | public function getFieldset()
{
return (isset($this->fieldsets[$this->current])) ? $this->fieldsets[$this->current] : null;
} | [
"public",
"function",
"getFieldset",
"(",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
")",
")",
"?",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
":",
"null",
";",
"}"
]
| Method to get current fieldset
@return Fieldset | [
"Method",
"to",
"get",
"current",
"fieldset"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L249-L252 |
13,661 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.addColumn | public function addColumn($fieldsets, $class = null)
{
if (!is_array($fieldsets)) {
$fieldsets = [$fieldsets];
}
foreach ($fieldsets as $i => $num) {
$fieldsets[$i] = (int)$num - 1;
}
if (null === $class) {
$class = 'pop-form-column-' . (count($this->columns) + 1);
}
$this->columns[$class] = $fieldsets;
return $this;
} | php | public function addColumn($fieldsets, $class = null)
{
if (!is_array($fieldsets)) {
$fieldsets = [$fieldsets];
}
foreach ($fieldsets as $i => $num) {
$fieldsets[$i] = (int)$num - 1;
}
if (null === $class) {
$class = 'pop-form-column-' . (count($this->columns) + 1);
}
$this->columns[$class] = $fieldsets;
return $this;
} | [
"public",
"function",
"addColumn",
"(",
"$",
"fieldsets",
",",
"$",
"class",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fieldsets",
")",
")",
"{",
"$",
"fieldsets",
"=",
"[",
"$",
"fieldsets",
"]",
";",
"}",
"foreach",
"(",
"$",
"fieldsets",
"as",
"$",
"i",
"=>",
"$",
"num",
")",
"{",
"$",
"fieldsets",
"[",
"$",
"i",
"]",
"=",
"(",
"int",
")",
"$",
"num",
"-",
"1",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"class",
")",
"{",
"$",
"class",
"=",
"'pop-form-column-'",
".",
"(",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
"+",
"1",
")",
";",
"}",
"$",
"this",
"->",
"columns",
"[",
"$",
"class",
"]",
"=",
"$",
"fieldsets",
";",
"return",
"$",
"this",
";",
"}"
]
| Method to add form column
@param mixed $fieldsets
@param string $class
@return Form | [
"Method",
"to",
"add",
"form",
"column"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L260-L273 |
13,662 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.setCurrent | public function setCurrent($i)
{
$this->current = (int)$i;
if (!isset($this->fieldsets[$this->current])) {
$this->fieldsets[$this->current] = $this->createFieldset();
}
return $this;
} | php | public function setCurrent($i)
{
$this->current = (int)$i;
if (!isset($this->fieldsets[$this->current])) {
$this->fieldsets[$this->current] = $this->createFieldset();
}
return $this;
} | [
"public",
"function",
"setCurrent",
"(",
"$",
"i",
")",
"{",
"$",
"this",
"->",
"current",
"=",
"(",
"int",
")",
"$",
"i",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
")",
")",
"{",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
"=",
"$",
"this",
"->",
"createFieldset",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to get current fieldset index
@param int $i
@return Form | [
"Method",
"to",
"get",
"current",
"fieldset",
"index"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L331-L338 |
13,663 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.getLegend | public function getLegend()
{
return (isset($this->fieldsets[$this->current])) ?
$this->fieldsets[$this->current]->getLegend() : null;
} | php | public function getLegend()
{
return (isset($this->fieldsets[$this->current])) ?
$this->fieldsets[$this->current]->getLegend() : null;
} | [
"public",
"function",
"getLegend",
"(",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
")",
")",
"?",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
"->",
"getLegend",
"(",
")",
":",
"null",
";",
"}"
]
| Method to get the legend of the current fieldset
@return string | [
"Method",
"to",
"get",
"the",
"legend",
"of",
"the",
"current",
"fieldset"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L344-L348 |
13,664 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.setLegend | public function setLegend($legend)
{
if (isset($this->fieldsets[$this->current])) {
$this->fieldsets[$this->current]->setLegend($legend);
}
return $this;
} | php | public function setLegend($legend)
{
if (isset($this->fieldsets[$this->current])) {
$this->fieldsets[$this->current]->setLegend($legend);
}
return $this;
} | [
"public",
"function",
"setLegend",
"(",
"$",
"legend",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
")",
")",
"{",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
"->",
"setLegend",
"(",
"$",
"legend",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to set the legend of the current fieldset
@param string $legend
@return Form | [
"Method",
"to",
"set",
"the",
"legend",
"of",
"the",
"current",
"fieldset"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L355-L361 |
13,665 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.addFieldFromConfig | public function addFieldFromConfig($name, $field)
{
$this->addField(Fields::create($name, $field));
return $this;
} | php | public function addFieldFromConfig($name, $field)
{
$this->addField(Fields::create($name, $field));
return $this;
} | [
"public",
"function",
"addFieldFromConfig",
"(",
"$",
"name",
",",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"addField",
"(",
"Fields",
"::",
"create",
"(",
"$",
"name",
",",
"$",
"field",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Method to add a form field from a config
@param string $name
@param array $field
@return Form | [
"Method",
"to",
"add",
"a",
"form",
"field",
"from",
"a",
"config"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L396-L400 |
13,666 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.addFieldsFromConfig | public function addFieldsFromConfig(array $config)
{
$i = 1;
foreach ($config as $name => $field) {
if (is_numeric($name) && !isset($field[$name]['type'])) {
$fields = [];
foreach ($field as $n => $f) {
$fields[$n] = Fields::create($n, $f);
}
if ($i > 1) {
$this->fieldsets[$this->current]->createGroup();
}
$this->fieldsets[$this->current]->addFields($fields);
$i++;
} else {
$this->addField(Fields::create($name, $field));
}
}
return $this;
} | php | public function addFieldsFromConfig(array $config)
{
$i = 1;
foreach ($config as $name => $field) {
if (is_numeric($name) && !isset($field[$name]['type'])) {
$fields = [];
foreach ($field as $n => $f) {
$fields[$n] = Fields::create($n, $f);
}
if ($i > 1) {
$this->fieldsets[$this->current]->createGroup();
}
$this->fieldsets[$this->current]->addFields($fields);
$i++;
} else {
$this->addField(Fields::create($name, $field));
}
}
return $this;
} | [
"public",
"function",
"addFieldsFromConfig",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"name",
")",
"&&",
"!",
"isset",
"(",
"$",
"field",
"[",
"$",
"name",
"]",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"field",
"as",
"$",
"n",
"=>",
"$",
"f",
")",
"{",
"$",
"fields",
"[",
"$",
"n",
"]",
"=",
"Fields",
"::",
"create",
"(",
"$",
"n",
",",
"$",
"f",
")",
";",
"}",
"if",
"(",
"$",
"i",
">",
"1",
")",
"{",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
"->",
"createGroup",
"(",
")",
";",
"}",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"this",
"->",
"current",
"]",
"->",
"addFields",
"(",
"$",
"fields",
")",
";",
"$",
"i",
"++",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addField",
"(",
"Fields",
"::",
"create",
"(",
"$",
"name",
",",
"$",
"field",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to add form fields from config
@param array $config
@return Form | [
"Method",
"to",
"add",
"form",
"fields",
"from",
"config"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L407-L426 |
13,667 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.addFieldsetsFromConfig | public function addFieldsetsFromConfig(array $fieldsets, $container = null)
{
foreach ($fieldsets as $legend => $config) {
if (!is_numeric($legend)) {
$this->createFieldset($legend, $container);
} else {
$this->createFieldset(null, $container);
}
$this->addFieldsFromConfig($config);
}
return $this;
} | php | public function addFieldsetsFromConfig(array $fieldsets, $container = null)
{
foreach ($fieldsets as $legend => $config) {
if (!is_numeric($legend)) {
$this->createFieldset($legend, $container);
} else {
$this->createFieldset(null, $container);
}
$this->addFieldsFromConfig($config);
}
return $this;
} | [
"public",
"function",
"addFieldsetsFromConfig",
"(",
"array",
"$",
"fieldsets",
",",
"$",
"container",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"fieldsets",
"as",
"$",
"legend",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"legend",
")",
")",
"{",
"$",
"this",
"->",
"createFieldset",
"(",
"$",
"legend",
",",
"$",
"container",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"createFieldset",
"(",
"null",
",",
"$",
"container",
")",
";",
"}",
"$",
"this",
"->",
"addFieldsFromConfig",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to add form fieldsets from config
@param array $fieldsets
@param string $container
@return Form | [
"Method",
"to",
"add",
"form",
"fieldsets",
"from",
"config"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L434-L445 |
13,668 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.insertFieldBefore | public function insertFieldBefore($name, Element\AbstractElement $field)
{
foreach ($this->fieldsets as $fieldset) {
if ($fieldset->hasField($name)) {
$fieldset->insertFieldBefore($name, $field);
break;
}
}
return $this;
} | php | public function insertFieldBefore($name, Element\AbstractElement $field)
{
foreach ($this->fieldsets as $fieldset) {
if ($fieldset->hasField($name)) {
$fieldset->insertFieldBefore($name, $field);
break;
}
}
return $this;
} | [
"public",
"function",
"insertFieldBefore",
"(",
"$",
"name",
",",
"Element",
"\\",
"AbstractElement",
"$",
"field",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"if",
"(",
"$",
"fieldset",
"->",
"hasField",
"(",
"$",
"name",
")",
")",
"{",
"$",
"fieldset",
"->",
"insertFieldBefore",
"(",
"$",
"name",
",",
"$",
"field",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to insert a field before another one
@param string $name
@param Element\AbstractElement $field
@return Form | [
"Method",
"to",
"insert",
"a",
"field",
"before",
"another",
"one"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L453-L462 |
13,669 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.count | public function count()
{
$count = 0;
foreach ($this->fieldsets as $fieldset) {
$count += $fieldset->count();
}
return $count;
} | php | public function count()
{
$count = 0;
foreach ($this->fieldsets as $fieldset) {
$count += $fieldset->count();
}
return $count;
} | [
"public",
"function",
"count",
"(",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"$",
"count",
"+=",
"$",
"fieldset",
"->",
"count",
"(",
")",
";",
"}",
"return",
"$",
"count",
";",
"}"
]
| Method to get the count of elements in the form
@return int | [
"Method",
"to",
"get",
"the",
"count",
"of",
"elements",
"in",
"the",
"form"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L485-L492 |
13,670 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.getFields | public function getFields()
{
$fields = [];
foreach ($this->fieldsets as $fieldset) {
$fields = array_merge($fields, $fieldset->getAllFields());
}
return $fields;
} | php | public function getFields()
{
$fields = [];
foreach ($this->fieldsets as $fieldset) {
$fields = array_merge($fields, $fieldset->getAllFields());
}
return $fields;
} | [
"public",
"function",
"getFields",
"(",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"$",
"fields",
"=",
"array_merge",
"(",
"$",
"fields",
",",
"$",
"fieldset",
"->",
"getAllFields",
"(",
")",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
]
| Method to get field element objects
@return array | [
"Method",
"to",
"get",
"field",
"element",
"objects"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L529-L536 |
13,671 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.removeField | public function removeField($field)
{
foreach ($this->fieldsets as $fieldset) {
if ($fieldset->hasField($field)) {
unset($fieldset[$field]);
}
}
return $this;
} | php | public function removeField($field)
{
foreach ($this->fieldsets as $fieldset) {
if ($fieldset->hasField($field)) {
unset($fieldset[$field]);
}
}
return $this;
} | [
"public",
"function",
"removeField",
"(",
"$",
"field",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"if",
"(",
"$",
"fieldset",
"->",
"hasField",
"(",
"$",
"field",
")",
")",
"{",
"unset",
"(",
"$",
"fieldset",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to remove a form field
@param string $field
@return Form | [
"Method",
"to",
"remove",
"a",
"form",
"field"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L543-L551 |
13,672 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.filterValue | public function filterValue($value)
{
if ($value instanceof Element\AbstractElement) {
$name = $value->getName();
$type = $value->getType();
$realValue = $value->getValue();
} else {
$type = null;
$name = null;
$realValue = $value;
}
foreach ($this->filters as $filter) {
if (((null === $type) || (!in_array($type, $filter['excludeByType']))) &&
((null === $name) || (!in_array($name, $filter['excludeByName'])))) {
if (is_array($realValue)) {
foreach ($realValue as $k => $v) {
$params = array_merge([$v], $filter['params']);
$realValue[$k] = call_user_func_array($filter['call'], $params);
}
} else {
$params = array_merge([$realValue], $filter['params']);
$realValue = call_user_func_array($filter['call'], $params);
}
}
}
if (($value instanceof Element\AbstractElement) && (null !== $realValue) && ($realValue != '')) {
$value->setValue($realValue);
}
return $realValue;
} | php | public function filterValue($value)
{
if ($value instanceof Element\AbstractElement) {
$name = $value->getName();
$type = $value->getType();
$realValue = $value->getValue();
} else {
$type = null;
$name = null;
$realValue = $value;
}
foreach ($this->filters as $filter) {
if (((null === $type) || (!in_array($type, $filter['excludeByType']))) &&
((null === $name) || (!in_array($name, $filter['excludeByName'])))) {
if (is_array($realValue)) {
foreach ($realValue as $k => $v) {
$params = array_merge([$v], $filter['params']);
$realValue[$k] = call_user_func_array($filter['call'], $params);
}
} else {
$params = array_merge([$realValue], $filter['params']);
$realValue = call_user_func_array($filter['call'], $params);
}
}
}
if (($value instanceof Element\AbstractElement) && (null !== $realValue) && ($realValue != '')) {
$value->setValue($realValue);
}
return $realValue;
} | [
"public",
"function",
"filterValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Element",
"\\",
"AbstractElement",
")",
"{",
"$",
"name",
"=",
"$",
"value",
"->",
"getName",
"(",
")",
";",
"$",
"type",
"=",
"$",
"value",
"->",
"getType",
"(",
")",
";",
"$",
"realValue",
"=",
"$",
"value",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"null",
";",
"$",
"name",
"=",
"null",
";",
"$",
"realValue",
"=",
"$",
"value",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"(",
"(",
"null",
"===",
"$",
"type",
")",
"||",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"$",
"filter",
"[",
"'excludeByType'",
"]",
")",
")",
")",
"&&",
"(",
"(",
"null",
"===",
"$",
"name",
")",
"||",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"filter",
"[",
"'excludeByName'",
"]",
")",
")",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"realValue",
")",
")",
"{",
"foreach",
"(",
"$",
"realValue",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"[",
"$",
"v",
"]",
",",
"$",
"filter",
"[",
"'params'",
"]",
")",
";",
"$",
"realValue",
"[",
"$",
"k",
"]",
"=",
"call_user_func_array",
"(",
"$",
"filter",
"[",
"'call'",
"]",
",",
"$",
"params",
")",
";",
"}",
"}",
"else",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"[",
"$",
"realValue",
"]",
",",
"$",
"filter",
"[",
"'params'",
"]",
")",
";",
"$",
"realValue",
"=",
"call_user_func_array",
"(",
"$",
"filter",
"[",
"'call'",
"]",
",",
"$",
"params",
")",
";",
"}",
"}",
"}",
"if",
"(",
"(",
"$",
"value",
"instanceof",
"Element",
"\\",
"AbstractElement",
")",
"&&",
"(",
"null",
"!==",
"$",
"realValue",
")",
"&&",
"(",
"$",
"realValue",
"!=",
"''",
")",
")",
"{",
"$",
"value",
"->",
"setValue",
"(",
"$",
"realValue",
")",
";",
"}",
"return",
"$",
"realValue",
";",
"}"
]
| Filter value with the filters in the form object
@param mixed $value
@return mixed | [
"Filter",
"value",
"with",
"the",
"filters",
"in",
"the",
"form",
"object"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L669-L698 |
13,673 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.filterValues | public function filterValues(array $values = null)
{
if (null === $values) {
$values = $this->getFields();
}
foreach ($values as $key => $value) {
$values[$key] = $this->filterValue($value);
}
return $values;
} | php | public function filterValues(array $values = null)
{
if (null === $values) {
$values = $this->getFields();
}
foreach ($values as $key => $value) {
$values[$key] = $this->filterValue($value);
}
return $values;
} | [
"public",
"function",
"filterValues",
"(",
"array",
"$",
"values",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"values",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"filterValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
]
| Filter values with the filters in the form object
@param array $values
@return mixed | [
"Filter",
"values",
"with",
"the",
"filters",
"in",
"the",
"form",
"object"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L705-L714 |
13,674 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.isValid | public function isValid()
{
$result = true;
$fields = $this->getFields();
// Check each element for validators, validate them and return the result.
foreach ($fields as $field) {
if ($field->validate() == false) {
$result = false;
}
}
return $result;
} | php | public function isValid()
{
$result = true;
$fields = $this->getFields();
// Check each element for validators, validate them and return the result.
foreach ($fields as $field) {
if ($field->validate() == false) {
$result = false;
}
}
return $result;
} | [
"public",
"function",
"isValid",
"(",
")",
"{",
"$",
"result",
"=",
"true",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"// Check each element for validators, validate them and return the result.",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"validate",
"(",
")",
"==",
"false",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Determine whether or not the form object is valid
@return boolean | [
"Determine",
"whether",
"or",
"not",
"the",
"form",
"object",
"is",
"valid"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L720-L731 |
13,675 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.getErrors | public function getErrors($name)
{
$field = $this->getField($name);
$errors = (null !== $field) ? $field->getErrors() : [];
return $errors;
} | php | public function getErrors($name)
{
$field = $this->getField($name);
$errors = (null !== $field) ? $field->getErrors() : [];
return $errors;
} | [
"public",
"function",
"getErrors",
"(",
"$",
"name",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"name",
")",
";",
"$",
"errors",
"=",
"(",
"null",
"!==",
"$",
"field",
")",
"?",
"$",
"field",
"->",
"getErrors",
"(",
")",
":",
"[",
"]",
";",
"return",
"$",
"errors",
";",
"}"
]
| Get form element errors for a field.
@param string $name
@return array | [
"Get",
"form",
"element",
"errors",
"for",
"a",
"field",
"."
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L738-L743 |
13,676 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.getAllErrors | public function getAllErrors()
{
$errors = [];
$fields = $this->getFields();
foreach ($fields as $name => $field) {
if ($field->hasErrors()) {
$errors[str_replace('[]', '', $field->getName())] = $field->getErrors();
}
}
return $errors;
} | php | public function getAllErrors()
{
$errors = [];
$fields = $this->getFields();
foreach ($fields as $name => $field) {
if ($field->hasErrors()) {
$errors[str_replace('[]', '', $field->getName())] = $field->getErrors();
}
}
return $errors;
} | [
"public",
"function",
"getAllErrors",
"(",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"errors",
"[",
"str_replace",
"(",
"'[]'",
",",
"''",
",",
"$",
"field",
"->",
"getName",
"(",
")",
")",
"]",
"=",
"$",
"field",
"->",
"getErrors",
"(",
")",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
]
| Get all form element errors
@return array | [
"Get",
"all",
"form",
"element",
"errors"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L749-L759 |
13,677 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.reset | public function reset()
{
$fields = $this->getFields();
foreach ($fields as $field) {
$field->resetValue();
}
return $this;
} | php | public function reset()
{
$fields = $this->getFields();
foreach ($fields as $field) {
$field->resetValue();
}
return $this;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"field",
"->",
"resetValue",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to reset and clear any form field values
@return Form | [
"Method",
"to",
"reset",
"and",
"clear",
"any",
"form",
"field",
"values"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L765-L772 |
13,678 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.clearTokens | public function clearTokens()
{
// Start a session.
if (session_id() == '') {
session_start();
}
if (isset($_SESSION['pop_csrf'])) {
unset($_SESSION['pop_csrf']);
}
if (isset($_SESSION['pop_captcha'])) {
unset($_SESSION['pop_captcha']);
}
return $this;
} | php | public function clearTokens()
{
// Start a session.
if (session_id() == '') {
session_start();
}
if (isset($_SESSION['pop_csrf'])) {
unset($_SESSION['pop_csrf']);
}
if (isset($_SESSION['pop_captcha'])) {
unset($_SESSION['pop_captcha']);
}
return $this;
} | [
"public",
"function",
"clearTokens",
"(",
")",
"{",
"// Start a session.",
"if",
"(",
"session_id",
"(",
")",
"==",
"''",
")",
"{",
"session_start",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"'pop_csrf'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"'pop_csrf'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"'pop_captcha'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"'pop_captcha'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method to clear any security tokens
@return Form | [
"Method",
"to",
"clear",
"any",
"security",
"tokens"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L778-L791 |
13,679 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.prepare | public function prepare()
{
if (null === $this->getAttribute('id')) {
$this->setAttribute('id', 'pop-form');
}
if (null === $this->getAttribute('class')) {
$this->setAttribute('class', 'pop-form');
}
if (count($this->columns) > 0) {
foreach ($this->columns as $class => $fieldsets) {
$column = new Child('div');
$column->setAttribute('class', $class);
foreach ($fieldsets as $i) {
if (isset($this->fieldsets[$i])) {
$fieldset = $this->fieldsets[$i];
$fieldset->prepare();
$column->addChild($fieldset);
}
}
$this->addChild($column);
}
} else {
foreach ($this->fieldsets as $fieldset) {
$fieldset->prepare();
$this->addChild($fieldset);
}
}
return $this;
} | php | public function prepare()
{
if (null === $this->getAttribute('id')) {
$this->setAttribute('id', 'pop-form');
}
if (null === $this->getAttribute('class')) {
$this->setAttribute('class', 'pop-form');
}
if (count($this->columns) > 0) {
foreach ($this->columns as $class => $fieldsets) {
$column = new Child('div');
$column->setAttribute('class', $class);
foreach ($fieldsets as $i) {
if (isset($this->fieldsets[$i])) {
$fieldset = $this->fieldsets[$i];
$fieldset->prepare();
$column->addChild($fieldset);
}
}
$this->addChild($column);
}
} else {
foreach ($this->fieldsets as $fieldset) {
$fieldset->prepare();
$this->addChild($fieldset);
}
}
return $this;
} | [
"public",
"function",
"prepare",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getAttribute",
"(",
"'id'",
")",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"'id'",
",",
"'pop-form'",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getAttribute",
"(",
"'class'",
")",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"'class'",
",",
"'pop-form'",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"class",
"=>",
"$",
"fieldsets",
")",
"{",
"$",
"column",
"=",
"new",
"Child",
"(",
"'div'",
")",
";",
"$",
"column",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"class",
")",
";",
"foreach",
"(",
"$",
"fieldsets",
"as",
"$",
"i",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"fieldset",
"=",
"$",
"this",
"->",
"fieldsets",
"[",
"$",
"i",
"]",
";",
"$",
"fieldset",
"->",
"prepare",
"(",
")",
";",
"$",
"column",
"->",
"addChild",
"(",
"$",
"fieldset",
")",
";",
"}",
"}",
"$",
"this",
"->",
"addChild",
"(",
"$",
"column",
")",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"$",
"fieldset",
"->",
"prepare",
"(",
")",
";",
"$",
"this",
"->",
"addChild",
"(",
"$",
"fieldset",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Prepare form object for rendering
@return Form | [
"Prepare",
"form",
"object",
"for",
"rendering"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L797-L825 |
13,680 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.prepareForView | public function prepareForView()
{
$formData = [];
foreach ($this->fieldsets as $fieldset) {
$formData = array_merge($formData, $fieldset->prepareForView());
}
return $formData;
} | php | public function prepareForView()
{
$formData = [];
foreach ($this->fieldsets as $fieldset) {
$formData = array_merge($formData, $fieldset->prepareForView());
}
return $formData;
} | [
"public",
"function",
"prepareForView",
"(",
")",
"{",
"$",
"formData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"$",
"formData",
"=",
"array_merge",
"(",
"$",
"formData",
",",
"$",
"fieldset",
"->",
"prepareForView",
"(",
")",
")",
";",
"}",
"return",
"$",
"formData",
";",
"}"
]
| Prepare form object for rendering with a view
@return array | [
"Prepare",
"form",
"object",
"for",
"rendering",
"with",
"a",
"view"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L831-L838 |
13,681 | christophe-brachet/aspi-framework | src/Framework/Form/AspiForm.php | AspiForm.render | public function render($depth = 0, $indent = null, $inner = false)
{
if (!($this->hasChildren())) {
$this->prepare();
}
foreach ($this->fieldsets as $fieldset) {
foreach ($fieldset->getAllFields() as $field) {
if ($field instanceof Element\Input\File) {
$this->setAttribute('enctype', 'multipart/form-data');
break;
}
}
}
return parent::render($depth, $indent, $inner);
} | php | public function render($depth = 0, $indent = null, $inner = false)
{
if (!($this->hasChildren())) {
$this->prepare();
}
foreach ($this->fieldsets as $fieldset) {
foreach ($fieldset->getAllFields() as $field) {
if ($field instanceof Element\Input\File) {
$this->setAttribute('enctype', 'multipart/form-data');
break;
}
}
}
return parent::render($depth, $indent, $inner);
} | [
"public",
"function",
"render",
"(",
"$",
"depth",
"=",
"0",
",",
"$",
"indent",
"=",
"null",
",",
"$",
"inner",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"hasChildren",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"foreach",
"(",
"$",
"fieldset",
"->",
"getAllFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Element",
"\\",
"Input",
"\\",
"File",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"'enctype'",
",",
"'multipart/form-data'",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"depth",
",",
"$",
"indent",
",",
"$",
"inner",
")",
";",
"}"
]
| Render the form object
@param int $depth
@param string $indent
@param boolean $inner
@return mixed | [
"Render",
"the",
"form",
"object"
]
| 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/AspiForm.php#L847-L861 |
13,682 | unimapper/unimapper | src/Entity/Filter.php | Filter.isGroup | public static function isGroup(array $value)
{
return $value === array_values($value)
|| (isset($value[self::_OR]) && count($value) === 1);
} | php | public static function isGroup(array $value)
{
return $value === array_values($value)
|| (isset($value[self::_OR]) && count($value) === 1);
} | [
"public",
"static",
"function",
"isGroup",
"(",
"array",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"===",
"array_values",
"(",
"$",
"value",
")",
"||",
"(",
"isset",
"(",
"$",
"value",
"[",
"self",
"::",
"_OR",
"]",
")",
"&&",
"count",
"(",
"$",
"value",
")",
"===",
"1",
")",
";",
"}"
]
| Is it filter with groups?
@param array $value
@return bool | [
"Is",
"it",
"filter",
"with",
"groups?"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Filter.php#L63-L67 |
13,683 | unimapper/unimapper | src/Entity/Filter.php | Filter.validate | public static function validate(Reflection $reflection, array $filter)
{
if (self::isGroup($filter)) {
// Filter group
foreach ($filter as $modifier => $item) {
if (!is_array($item) || empty($item)) {
throw new Exception\FilterException(
"Invalid filter group structure!"
);
}
self::validate($reflection, $item);
}
} else {
// Filter item
foreach ($filter as $name => $item) {
if (!is_array($item) || !is_string($name)) {
throw new Exception\FilterException(
"Invalid filter structure!"
);
}
if (!$reflection->hasProperty($name)) {
throw new Exception\FilterException(
"Undefined property name '" . $name . "' used in filter!"
);
}
$property = $reflection->getProperty($name);
foreach ($item as $modifier => $value) {
if (!in_array($modifier, self::$modifiers, true)) {
throw new Exception\FilterException(
"Invalid filter modifier '" . $modifier . "'!"
);
}
if ($property->hasOption(Assoc::KEY)
|| $property->hasOption(Computed::KEY)
|| ($property->hasOption(Reflection\Property\Option\Map::KEY)
&& !$property->getOption(Reflection\Property\Option\Map::KEY))
|| $property->getType() === Reflection\Property::TYPE_COLLECTION
|| $property->getType() === Reflection\Property::TYPE_ENTITY
) {
throw new Exception\FilterException(
"Filter can not be used with computed, collections, entities and disabled mapping!"
);
}
// Validate value type
try {
if (is_array($value)
&& $property->getType() !== Reflection\Property::TYPE_ARRAY
&& in_array($modifier, [self::EQUAL, self::NOT], true)
) {
// Array values
foreach ($value as $index => $valueItem) {
$property->validateValueType($valueItem);
}
} else {
$property->validateValueType($value);
}
} catch (Exception\InvalidArgumentException $e) {
throw new Exception\FilterException($e->getMessage());
}
}
}
}
} | php | public static function validate(Reflection $reflection, array $filter)
{
if (self::isGroup($filter)) {
// Filter group
foreach ($filter as $modifier => $item) {
if (!is_array($item) || empty($item)) {
throw new Exception\FilterException(
"Invalid filter group structure!"
);
}
self::validate($reflection, $item);
}
} else {
// Filter item
foreach ($filter as $name => $item) {
if (!is_array($item) || !is_string($name)) {
throw new Exception\FilterException(
"Invalid filter structure!"
);
}
if (!$reflection->hasProperty($name)) {
throw new Exception\FilterException(
"Undefined property name '" . $name . "' used in filter!"
);
}
$property = $reflection->getProperty($name);
foreach ($item as $modifier => $value) {
if (!in_array($modifier, self::$modifiers, true)) {
throw new Exception\FilterException(
"Invalid filter modifier '" . $modifier . "'!"
);
}
if ($property->hasOption(Assoc::KEY)
|| $property->hasOption(Computed::KEY)
|| ($property->hasOption(Reflection\Property\Option\Map::KEY)
&& !$property->getOption(Reflection\Property\Option\Map::KEY))
|| $property->getType() === Reflection\Property::TYPE_COLLECTION
|| $property->getType() === Reflection\Property::TYPE_ENTITY
) {
throw new Exception\FilterException(
"Filter can not be used with computed, collections, entities and disabled mapping!"
);
}
// Validate value type
try {
if (is_array($value)
&& $property->getType() !== Reflection\Property::TYPE_ARRAY
&& in_array($modifier, [self::EQUAL, self::NOT], true)
) {
// Array values
foreach ($value as $index => $valueItem) {
$property->validateValueType($valueItem);
}
} else {
$property->validateValueType($value);
}
} catch (Exception\InvalidArgumentException $e) {
throw new Exception\FilterException($e->getMessage());
}
}
}
}
} | [
"public",
"static",
"function",
"validate",
"(",
"Reflection",
"$",
"reflection",
",",
"array",
"$",
"filter",
")",
"{",
"if",
"(",
"self",
"::",
"isGroup",
"(",
"$",
"filter",
")",
")",
"{",
"// Filter group",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"modifier",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"item",
")",
"||",
"empty",
"(",
"$",
"item",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FilterException",
"(",
"\"Invalid filter group structure!\"",
")",
";",
"}",
"self",
"::",
"validate",
"(",
"$",
"reflection",
",",
"$",
"item",
")",
";",
"}",
"}",
"else",
"{",
"// Filter item",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"name",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"item",
")",
"||",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FilterException",
"(",
"\"Invalid filter structure!\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"reflection",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FilterException",
"(",
"\"Undefined property name '\"",
".",
"$",
"name",
".",
"\"' used in filter!\"",
")",
";",
"}",
"$",
"property",
"=",
"$",
"reflection",
"->",
"getProperty",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"item",
"as",
"$",
"modifier",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"modifier",
",",
"self",
"::",
"$",
"modifiers",
",",
"true",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FilterException",
"(",
"\"Invalid filter modifier '\"",
".",
"$",
"modifier",
".",
"\"'!\"",
")",
";",
"}",
"if",
"(",
"$",
"property",
"->",
"hasOption",
"(",
"Assoc",
"::",
"KEY",
")",
"||",
"$",
"property",
"->",
"hasOption",
"(",
"Computed",
"::",
"KEY",
")",
"||",
"(",
"$",
"property",
"->",
"hasOption",
"(",
"Reflection",
"\\",
"Property",
"\\",
"Option",
"\\",
"Map",
"::",
"KEY",
")",
"&&",
"!",
"$",
"property",
"->",
"getOption",
"(",
"Reflection",
"\\",
"Property",
"\\",
"Option",
"\\",
"Map",
"::",
"KEY",
")",
")",
"||",
"$",
"property",
"->",
"getType",
"(",
")",
"===",
"Reflection",
"\\",
"Property",
"::",
"TYPE_COLLECTION",
"||",
"$",
"property",
"->",
"getType",
"(",
")",
"===",
"Reflection",
"\\",
"Property",
"::",
"TYPE_ENTITY",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FilterException",
"(",
"\"Filter can not be used with computed, collections, entities and disabled mapping!\"",
")",
";",
"}",
"// Validate value type",
"try",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"$",
"property",
"->",
"getType",
"(",
")",
"!==",
"Reflection",
"\\",
"Property",
"::",
"TYPE_ARRAY",
"&&",
"in_array",
"(",
"$",
"modifier",
",",
"[",
"self",
"::",
"EQUAL",
",",
"self",
"::",
"NOT",
"]",
",",
"true",
")",
")",
"{",
"// Array values",
"foreach",
"(",
"$",
"value",
"as",
"$",
"index",
"=>",
"$",
"valueItem",
")",
"{",
"$",
"property",
"->",
"validateValueType",
"(",
"$",
"valueItem",
")",
";",
"}",
"}",
"else",
"{",
"$",
"property",
"->",
"validateValueType",
"(",
"$",
"value",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FilterException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| Merge two filters
@param Reflection $reflection
@param array $filter
@return array
@throws Exception\FilterException | [
"Merge",
"two",
"filters"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Filter.php#L79-L153 |
13,684 | transfer-framework/transfer | src/Transfer/Adapter/Transaction/DataAggregate.php | DataAggregate.setData | public function setData($data)
{
$this->originalData = $data;
if ($data instanceof \Iterator) {
$this->iterator = $data;
}
elseif (is_array($data)) {
$this->iterator = new \ArrayIterator($data);
}
else {
$this->iterator = new \ArrayIterator(array($data));
}
} | php | public function setData($data)
{
$this->originalData = $data;
if ($data instanceof \Iterator) {
$this->iterator = $data;
}
elseif (is_array($data)) {
$this->iterator = new \ArrayIterator($data);
}
else {
$this->iterator = new \ArrayIterator(array($data));
}
} | [
"public",
"function",
"setData",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"originalData",
"=",
"$",
"data",
";",
"if",
"(",
"$",
"data",
"instanceof",
"\\",
"Iterator",
")",
"{",
"$",
"this",
"->",
"iterator",
"=",
"$",
"data",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"iterator",
"=",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"iterator",
"=",
"new",
"\\",
"ArrayIterator",
"(",
"array",
"(",
"$",
"data",
")",
")",
";",
"}",
"}"
]
| Assigns data to the aggregate.
@param mixed $data | [
"Assigns",
"data",
"to",
"the",
"aggregate",
"."
]
| 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Adapter/Transaction/DataAggregate.php#L50-L63 |
13,685 | PandaPlatform/framework | src/Panda/Storage/Adapters/Filesystem.php | Filesystem.put | public function put($path, $contents, $lock = false)
{
// Check if folder exists
if (!$this->exists(dirname($path))) {
mkdir(dirname($path), 0775, true);
}
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
} | php | public function put($path, $contents, $lock = false)
{
// Check if folder exists
if (!$this->exists(dirname($path))) {
mkdir(dirname($path), 0775, true);
}
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
} | [
"public",
"function",
"put",
"(",
"$",
"path",
",",
"$",
"contents",
",",
"$",
"lock",
"=",
"false",
")",
"{",
"// Check if folder exists",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"dirname",
"(",
"$",
"path",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"path",
")",
",",
"0775",
",",
"true",
")",
";",
"}",
"return",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"contents",
",",
"$",
"lock",
"?",
"LOCK_EX",
":",
"0",
")",
";",
"}"
]
| Put contents to a given file. Create the file if doesn't exist.
@param string $path The file's path to put contents to.
@param string $contents The file's contents.
@param bool $lock Acquire an exclusive lock on the file while proceeding to the writing.
@return mixed The number of bytes that were written to the file, or False on failure. | [
"Put",
"contents",
"to",
"a",
"given",
"file",
".",
"Create",
"the",
"file",
"if",
"doesn",
"t",
"exist",
"."
]
| a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Storage/Adapters/Filesystem.php#L51-L59 |
13,686 | crysalead/net | src/Http/Message.php | Message.get | public function get($decodeOptions = [])
{
$media = $this->_classes['media'];
$format = $this->format();
return $format ? $media::decode($format, $this->_stream->toString(), $decodeOptions, $this) : $this->_stream->toString();
} | php | public function get($decodeOptions = [])
{
$media = $this->_classes['media'];
$format = $this->format();
return $format ? $media::decode($format, $this->_stream->toString(), $decodeOptions, $this) : $this->_stream->toString();
} | [
"public",
"function",
"get",
"(",
"$",
"decodeOptions",
"=",
"[",
"]",
")",
"{",
"$",
"media",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'media'",
"]",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"format",
"(",
")",
";",
"return",
"$",
"format",
"?",
"$",
"media",
"::",
"decode",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"_stream",
"->",
"toString",
"(",
")",
",",
"$",
"decodeOptions",
",",
"$",
"this",
")",
":",
"$",
"this",
"->",
"_stream",
"->",
"toString",
"(",
")",
";",
"}"
]
| Gets the body of this message.
@param array $decodeOptions The decoding options.
@return mixed The formatted body. | [
"Gets",
"the",
"body",
"of",
"this",
"message",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Message.php#L252-L257 |
13,687 | crysalead/net | src/Http/Message.php | Message.to | public function to($format, $options = [])
{
$media = $this->_classes['media'];
if (!$media::get($format)) {
throw new InvalidArgumentException("Unsupported format `{$format}`.");
}
return $media::decode($format, $this->body(), $options, $this);
} | php | public function to($format, $options = [])
{
$media = $this->_classes['media'];
if (!$media::get($format)) {
throw new InvalidArgumentException("Unsupported format `{$format}`.");
}
return $media::decode($format, $this->body(), $options, $this);
} | [
"public",
"function",
"to",
"(",
"$",
"format",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"media",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'media'",
"]",
";",
"if",
"(",
"!",
"$",
"media",
"::",
"get",
"(",
"$",
"format",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Unsupported format `{$format}`.\"",
")",
";",
"}",
"return",
"$",
"media",
"::",
"decode",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"body",
"(",
")",
",",
"$",
"options",
",",
"$",
"this",
")",
";",
"}"
]
| Exports a `Message` body to specific format.
The supported values of `$format` depend on the `Media` class example:
```php
$message->to('xml'); // exports the message body into XML
```
@param string $format By default the only supported value is `'array'`. However, additional
format handlers can be registered using the `formats()` method.
@param array $options Options for converting the collection.
@return mixed The converted collection. | [
"Exports",
"a",
"Message",
"body",
"to",
"specific",
"format",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Message.php#L319-L326 |
13,688 | crysalead/net | src/Http/Message.php | Message.toString | public function toString()
{
$headers = $this->headers();
if ($headers['Transfer-Encoding']->value() === 'chunked') {
return $this->toChunks();
}
return $this->_stream->toString();
} | php | public function toString()
{
$headers = $this->headers();
if ($headers['Transfer-Encoding']->value() === 'chunked') {
return $this->toChunks();
}
return $this->_stream->toString();
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"headers",
"(",
")",
";",
"if",
"(",
"$",
"headers",
"[",
"'Transfer-Encoding'",
"]",
"->",
"value",
"(",
")",
"===",
"'chunked'",
")",
"{",
"return",
"$",
"this",
"->",
"toChunks",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_stream",
"->",
"toString",
"(",
")",
";",
"}"
]
| Magic method convert the instance body into a string.
@return string | [
"Magic",
"method",
"convert",
"the",
"instance",
"body",
"into",
"a",
"string",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Message.php#L344-L351 |
13,689 | crysalead/net | src/Http/Message.php | Message.toChunks | public function toChunks($size = null)
{
$body = '';
$size = $size > 0 ? $size : $this->chunkSize();
$stream = $this->stream();
while($chunk = $stream->read($size)) {
$readed = strlen($chunk);
if (!$readed) {
break;
}
$body .= dechex($readed) . "\r\n" . $chunk . "\r\n";
}
$body .= "0\r\n\r\n";
if ($stream->isSeekable()) {
$stream->rewind();
}
return $body;
} | php | public function toChunks($size = null)
{
$body = '';
$size = $size > 0 ? $size : $this->chunkSize();
$stream = $this->stream();
while($chunk = $stream->read($size)) {
$readed = strlen($chunk);
if (!$readed) {
break;
}
$body .= dechex($readed) . "\r\n" . $chunk . "\r\n";
}
$body .= "0\r\n\r\n";
if ($stream->isSeekable()) {
$stream->rewind();
}
return $body;
} | [
"public",
"function",
"toChunks",
"(",
"$",
"size",
"=",
"null",
")",
"{",
"$",
"body",
"=",
"''",
";",
"$",
"size",
"=",
"$",
"size",
">",
"0",
"?",
"$",
"size",
":",
"$",
"this",
"->",
"chunkSize",
"(",
")",
";",
"$",
"stream",
"=",
"$",
"this",
"->",
"stream",
"(",
")",
";",
"while",
"(",
"$",
"chunk",
"=",
"$",
"stream",
"->",
"read",
"(",
"$",
"size",
")",
")",
"{",
"$",
"readed",
"=",
"strlen",
"(",
"$",
"chunk",
")",
";",
"if",
"(",
"!",
"$",
"readed",
")",
"{",
"break",
";",
"}",
"$",
"body",
".=",
"dechex",
"(",
"$",
"readed",
")",
".",
"\"\\r\\n\"",
".",
"$",
"chunk",
".",
"\"\\r\\n\"",
";",
"}",
"$",
"body",
".=",
"\"0\\r\\n\\r\\n\"",
";",
"if",
"(",
"$",
"stream",
"->",
"isSeekable",
"(",
")",
")",
"{",
"$",
"stream",
"->",
"rewind",
"(",
")",
";",
"}",
"return",
"$",
"body",
";",
"}"
]
| Flush the content of a Message chunk by chunk.
@param Closure $size The size of the chunks to process. | [
"Flush",
"the",
"content",
"of",
"a",
"Message",
"chunk",
"by",
"chunk",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Message.php#L368-L386 |
13,690 | crysalead/net | src/Http/Message.php | Message._setContentLength | protected function _setContentLength()
{
$headers = $this->headers();
if ($headers['Transfer-Encoding']->value() === 'chunked') {
return;
}
$length = $this->stream()->length();
if ($length === null) {
throw new NetException("A Content-Length header is required but the request stream has a `null` length.");
}
$headers['Content-Length'] = $this->stream()->length();
} | php | protected function _setContentLength()
{
$headers = $this->headers();
if ($headers['Transfer-Encoding']->value() === 'chunked') {
return;
}
$length = $this->stream()->length();
if ($length === null) {
throw new NetException("A Content-Length header is required but the request stream has a `null` length.");
}
$headers['Content-Length'] = $this->stream()->length();
} | [
"protected",
"function",
"_setContentLength",
"(",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"headers",
"(",
")",
";",
"if",
"(",
"$",
"headers",
"[",
"'Transfer-Encoding'",
"]",
"->",
"value",
"(",
")",
"===",
"'chunked'",
")",
"{",
"return",
";",
"}",
"$",
"length",
"=",
"$",
"this",
"->",
"stream",
"(",
")",
"->",
"length",
"(",
")",
";",
"if",
"(",
"$",
"length",
"===",
"null",
")",
"{",
"throw",
"new",
"NetException",
"(",
"\"A Content-Length header is required but the request stream has a `null` length.\"",
")",
";",
"}",
"$",
"headers",
"[",
"'Content-Length'",
"]",
"=",
"$",
"this",
"->",
"stream",
"(",
")",
"->",
"length",
"(",
")",
";",
"}"
]
| Auto adds a Content-Length header if necessary. | [
"Auto",
"adds",
"a",
"Content",
"-",
"Length",
"header",
"if",
"necessary",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Message.php#L391-L403 |
13,691 | arckinteractive/events_api | classes/Events/API/Util.php | Util.getTime | public static function getTime($ts = 'now', $format = 'U', $tz = null) {
if (!Util::isValidTimezone($tz)) {
$tz = Util::getClientTimezone();
}
$dt = new DateTime(null, new DateTimeZone($tz));
(is_int($ts)) ? $dt->setTimestamp($ts) : $dt->modify($ts);
$time = $dt->format('H') * self::SECONDS_IN_AN_HOUR;
$time += $dt->format('i') * self::SECONDS_IN_A_MINUTE;
$time += $dt->format('s');
return $dt->setTimestamp($time)->format($format);
} | php | public static function getTime($ts = 'now', $format = 'U', $tz = null) {
if (!Util::isValidTimezone($tz)) {
$tz = Util::getClientTimezone();
}
$dt = new DateTime(null, new DateTimeZone($tz));
(is_int($ts)) ? $dt->setTimestamp($ts) : $dt->modify($ts);
$time = $dt->format('H') * self::SECONDS_IN_AN_HOUR;
$time += $dt->format('i') * self::SECONDS_IN_A_MINUTE;
$time += $dt->format('s');
return $dt->setTimestamp($time)->format($format);
} | [
"public",
"static",
"function",
"getTime",
"(",
"$",
"ts",
"=",
"'now'",
",",
"$",
"format",
"=",
"'U'",
",",
"$",
"tz",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"Util",
"::",
"isValidTimezone",
"(",
"$",
"tz",
")",
")",
"{",
"$",
"tz",
"=",
"Util",
"::",
"getClientTimezone",
"(",
")",
";",
"}",
"$",
"dt",
"=",
"new",
"DateTime",
"(",
"null",
",",
"new",
"DateTimeZone",
"(",
"$",
"tz",
")",
")",
";",
"(",
"is_int",
"(",
"$",
"ts",
")",
")",
"?",
"$",
"dt",
"->",
"setTimestamp",
"(",
"$",
"ts",
")",
":",
"$",
"dt",
"->",
"modify",
"(",
"$",
"ts",
")",
";",
"$",
"time",
"=",
"$",
"dt",
"->",
"format",
"(",
"'H'",
")",
"*",
"self",
"::",
"SECONDS_IN_AN_HOUR",
";",
"$",
"time",
"+=",
"$",
"dt",
"->",
"format",
"(",
"'i'",
")",
"*",
"self",
"::",
"SECONDS_IN_A_MINUTE",
";",
"$",
"time",
"+=",
"$",
"dt",
"->",
"format",
"(",
"'s'",
")",
";",
"return",
"$",
"dt",
"->",
"setTimestamp",
"(",
"$",
"time",
")",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}"
]
| Extracts time of the day timestamp
@param mixed $ts Date/time value
@param string $format Format of the return value
@return string | [
"Extracts",
"time",
"of",
"the",
"day",
"timestamp"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L161-L174 |
13,692 | arckinteractive/events_api | classes/Events/API/Util.php | Util.getWeekdays | public static function getWeekdays() {
return array(
self::MONDAY,
self::TUESDAY,
self::WEDNESDAY,
self::THURSDAY,
self::FRIDAY,
self::SATURDAY,
self::SUNDAY,
);
} | php | public static function getWeekdays() {
return array(
self::MONDAY,
self::TUESDAY,
self::WEDNESDAY,
self::THURSDAY,
self::FRIDAY,
self::SATURDAY,
self::SUNDAY,
);
} | [
"public",
"static",
"function",
"getWeekdays",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"MONDAY",
",",
"self",
"::",
"TUESDAY",
",",
"self",
"::",
"WEDNESDAY",
",",
"self",
"::",
"THURSDAY",
",",
"self",
"::",
"FRIDAY",
",",
"self",
"::",
"SATURDAY",
",",
"self",
"::",
"SUNDAY",
",",
")",
";",
"}"
]
| Returns an array of weekdays
@return array | [
"Returns",
"an",
"array",
"of",
"weekdays"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L367-L377 |
13,693 | arckinteractive/events_api | classes/Events/API/Util.php | Util.getRepeatFrequencies | function getRepeatFrequencies() {
return array(
Util::FREQUENCY_DAILY => elgg_echo('events_ui:repeat:daily'),
Util::FREQUENCY_WEEKDAY => elgg_echo('events_ui:repeat:weekday'),
Util::FREQUENCY_WEEKDAY_ODD => elgg_echo('events_ui:repeat:dailymwf'),
Util::FREQUENCY_WEEKDAY_EVEN => elgg_echo('events_ui:repeat:dailytt'),
Util::FREQUENCY_WEEKLY => elgg_echo('events_ui:repeat:weekly'),
Util::FREQUENCY_MONTHLY => elgg_echo('events_ui:repeat:monthly'),
Util::FREQUENCY_YEARLY => elgg_echo('events_ui:repeat:yearly'),
);
} | php | function getRepeatFrequencies() {
return array(
Util::FREQUENCY_DAILY => elgg_echo('events_ui:repeat:daily'),
Util::FREQUENCY_WEEKDAY => elgg_echo('events_ui:repeat:weekday'),
Util::FREQUENCY_WEEKDAY_ODD => elgg_echo('events_ui:repeat:dailymwf'),
Util::FREQUENCY_WEEKDAY_EVEN => elgg_echo('events_ui:repeat:dailytt'),
Util::FREQUENCY_WEEKLY => elgg_echo('events_ui:repeat:weekly'),
Util::FREQUENCY_MONTHLY => elgg_echo('events_ui:repeat:monthly'),
Util::FREQUENCY_YEARLY => elgg_echo('events_ui:repeat:yearly'),
);
} | [
"function",
"getRepeatFrequencies",
"(",
")",
"{",
"return",
"array",
"(",
"Util",
"::",
"FREQUENCY_DAILY",
"=>",
"elgg_echo",
"(",
"'events_ui:repeat:daily'",
")",
",",
"Util",
"::",
"FREQUENCY_WEEKDAY",
"=>",
"elgg_echo",
"(",
"'events_ui:repeat:weekday'",
")",
",",
"Util",
"::",
"FREQUENCY_WEEKDAY_ODD",
"=>",
"elgg_echo",
"(",
"'events_ui:repeat:dailymwf'",
")",
",",
"Util",
"::",
"FREQUENCY_WEEKDAY_EVEN",
"=>",
"elgg_echo",
"(",
"'events_ui:repeat:dailytt'",
")",
",",
"Util",
"::",
"FREQUENCY_WEEKLY",
"=>",
"elgg_echo",
"(",
"'events_ui:repeat:weekly'",
")",
",",
"Util",
"::",
"FREQUENCY_MONTHLY",
"=>",
"elgg_echo",
"(",
"'events_ui:repeat:monthly'",
")",
",",
"Util",
"::",
"FREQUENCY_YEARLY",
"=>",
"elgg_echo",
"(",
"'events_ui:repeat:yearly'",
")",
",",
")",
";",
"}"
]
| Returns repeat frequencies
@return array | [
"Returns",
"repeat",
"frequencies"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L383-L393 |
13,694 | arckinteractive/events_api | classes/Events/API/Util.php | Util.getTimezonesByCountry | public static function getTimezonesByCountry() {
$timezones = array();
$tz_ids = array_keys(self::getTimezones(true, false, 'now', self::TIMEZONE_SORT_OFFSET));
foreach ($tz_ids as $tz_id) {
if ($tz_id == Util::UTC) {
continue;
}
$info = Util::getTimezoneInfo($tz_id);
$cc = $info->country_code;
$abbr = $info->abbr;
if (!isset($timezones[$cc])) {
$timezones[$cc] = array();
}
$timezones[$cc][] = $info;
}
ksort($timezones);
return $timezones;
} | php | public static function getTimezonesByCountry() {
$timezones = array();
$tz_ids = array_keys(self::getTimezones(true, false, 'now', self::TIMEZONE_SORT_OFFSET));
foreach ($tz_ids as $tz_id) {
if ($tz_id == Util::UTC) {
continue;
}
$info = Util::getTimezoneInfo($tz_id);
$cc = $info->country_code;
$abbr = $info->abbr;
if (!isset($timezones[$cc])) {
$timezones[$cc] = array();
}
$timezones[$cc][] = $info;
}
ksort($timezones);
return $timezones;
} | [
"public",
"static",
"function",
"getTimezonesByCountry",
"(",
")",
"{",
"$",
"timezones",
"=",
"array",
"(",
")",
";",
"$",
"tz_ids",
"=",
"array_keys",
"(",
"self",
"::",
"getTimezones",
"(",
"true",
",",
"false",
",",
"'now'",
",",
"self",
"::",
"TIMEZONE_SORT_OFFSET",
")",
")",
";",
"foreach",
"(",
"$",
"tz_ids",
"as",
"$",
"tz_id",
")",
"{",
"if",
"(",
"$",
"tz_id",
"==",
"Util",
"::",
"UTC",
")",
"{",
"continue",
";",
"}",
"$",
"info",
"=",
"Util",
"::",
"getTimezoneInfo",
"(",
"$",
"tz_id",
")",
";",
"$",
"cc",
"=",
"$",
"info",
"->",
"country_code",
";",
"$",
"abbr",
"=",
"$",
"info",
"->",
"abbr",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"timezones",
"[",
"$",
"cc",
"]",
")",
")",
"{",
"$",
"timezones",
"[",
"$",
"cc",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"timezones",
"[",
"$",
"cc",
"]",
"[",
"]",
"=",
"$",
"info",
";",
"}",
"ksort",
"(",
"$",
"timezones",
")",
";",
"return",
"$",
"timezones",
";",
"}"
]
| Returns an array of timezones by country
@return array | [
"Returns",
"an",
"array",
"of",
"timezones",
"by",
"country"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L463-L480 |
13,695 | arckinteractive/events_api | classes/Events/API/Util.php | Util.getTimezoneInfo | public static function getTimezoneInfo($tz_id) {
$tz = new \DateTimeZone($tz_id);
$location = $tz->getLocation();
$country_code = $location['country_code'];
$dt = new DateTime(null, $tz);
$region = explode('/', $tz_id);
if (sizeof($region) > 1) {
array_shift($region);
}
$region = str_replace('_', ' ', implode(', ', $region));
$tzinfo = new stdClass();
$tzinfo->id = $tz_id;
$tzinfo->abbr = $dt->format('T');
$tzinfo->country_code = $country_code;
$tzinfo->country = elgg_echo("timezone:country:$country_code");
$tzinfo->region = $region;
$tzinfo->offset = $dt->getOffset();
$tzinfo->gmt = $dt->format('\(\G\M\TP\)');
$name = "timezone:name:$tzinfo->country_code:$tzinfo->abbr";
$name_tr = elgg_echo($name);
$tzinfo->name = ($name == $name_tr) ? $tzinfo->abbr : $name_tr;
$tzinfo->label = "$tzinfo->gmt $tzinfo->name - $tzinfo->region";
return $tzinfo;
} | php | public static function getTimezoneInfo($tz_id) {
$tz = new \DateTimeZone($tz_id);
$location = $tz->getLocation();
$country_code = $location['country_code'];
$dt = new DateTime(null, $tz);
$region = explode('/', $tz_id);
if (sizeof($region) > 1) {
array_shift($region);
}
$region = str_replace('_', ' ', implode(', ', $region));
$tzinfo = new stdClass();
$tzinfo->id = $tz_id;
$tzinfo->abbr = $dt->format('T');
$tzinfo->country_code = $country_code;
$tzinfo->country = elgg_echo("timezone:country:$country_code");
$tzinfo->region = $region;
$tzinfo->offset = $dt->getOffset();
$tzinfo->gmt = $dt->format('\(\G\M\TP\)');
$name = "timezone:name:$tzinfo->country_code:$tzinfo->abbr";
$name_tr = elgg_echo($name);
$tzinfo->name = ($name == $name_tr) ? $tzinfo->abbr : $name_tr;
$tzinfo->label = "$tzinfo->gmt $tzinfo->name - $tzinfo->region";
return $tzinfo;
} | [
"public",
"static",
"function",
"getTimezoneInfo",
"(",
"$",
"tz_id",
")",
"{",
"$",
"tz",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"tz_id",
")",
";",
"$",
"location",
"=",
"$",
"tz",
"->",
"getLocation",
"(",
")",
";",
"$",
"country_code",
"=",
"$",
"location",
"[",
"'country_code'",
"]",
";",
"$",
"dt",
"=",
"new",
"DateTime",
"(",
"null",
",",
"$",
"tz",
")",
";",
"$",
"region",
"=",
"explode",
"(",
"'/'",
",",
"$",
"tz_id",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"region",
")",
">",
"1",
")",
"{",
"array_shift",
"(",
"$",
"region",
")",
";",
"}",
"$",
"region",
"=",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"implode",
"(",
"', '",
",",
"$",
"region",
")",
")",
";",
"$",
"tzinfo",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"tzinfo",
"->",
"id",
"=",
"$",
"tz_id",
";",
"$",
"tzinfo",
"->",
"abbr",
"=",
"$",
"dt",
"->",
"format",
"(",
"'T'",
")",
";",
"$",
"tzinfo",
"->",
"country_code",
"=",
"$",
"country_code",
";",
"$",
"tzinfo",
"->",
"country",
"=",
"elgg_echo",
"(",
"\"timezone:country:$country_code\"",
")",
";",
"$",
"tzinfo",
"->",
"region",
"=",
"$",
"region",
";",
"$",
"tzinfo",
"->",
"offset",
"=",
"$",
"dt",
"->",
"getOffset",
"(",
")",
";",
"$",
"tzinfo",
"->",
"gmt",
"=",
"$",
"dt",
"->",
"format",
"(",
"'\\(\\G\\M\\TP\\)'",
")",
";",
"$",
"name",
"=",
"\"timezone:name:$tzinfo->country_code:$tzinfo->abbr\"",
";",
"$",
"name_tr",
"=",
"elgg_echo",
"(",
"$",
"name",
")",
";",
"$",
"tzinfo",
"->",
"name",
"=",
"(",
"$",
"name",
"==",
"$",
"name_tr",
")",
"?",
"$",
"tzinfo",
"->",
"abbr",
":",
"$",
"name_tr",
";",
"$",
"tzinfo",
"->",
"label",
"=",
"\"$tzinfo->gmt $tzinfo->name - $tzinfo->region\"",
";",
"return",
"$",
"tzinfo",
";",
"}"
]
| Expands timezone ID into a usable source of data about the timezone
@param string $tz_id Timezone ID e.g. America\New_York
@return stdClass | [
"Expands",
"timezone",
"ID",
"into",
"a",
"usable",
"source",
"of",
"data",
"about",
"the",
"timezone"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L488-L517 |
13,696 | arckinteractive/events_api | classes/Events/API/Util.php | Util.getTimezoneLabel | public static function getTimezoneLabel($tz_id, $format = false, $ts = 'now') {
if (self::isValidTimezone($tz_id) && $format) {
$dt = new DateTime(null, new DateTimeZone($tz_id));
(is_int($ts)) ? $dt->setTimestamp($ts) : $dt->modify($ts);
return $dt->format($format);
}
return elgg_echo($tz_id);
} | php | public static function getTimezoneLabel($tz_id, $format = false, $ts = 'now') {
if (self::isValidTimezone($tz_id) && $format) {
$dt = new DateTime(null, new DateTimeZone($tz_id));
(is_int($ts)) ? $dt->setTimestamp($ts) : $dt->modify($ts);
return $dt->format($format);
}
return elgg_echo($tz_id);
} | [
"public",
"static",
"function",
"getTimezoneLabel",
"(",
"$",
"tz_id",
",",
"$",
"format",
"=",
"false",
",",
"$",
"ts",
"=",
"'now'",
")",
"{",
"if",
"(",
"self",
"::",
"isValidTimezone",
"(",
"$",
"tz_id",
")",
"&&",
"$",
"format",
")",
"{",
"$",
"dt",
"=",
"new",
"DateTime",
"(",
"null",
",",
"new",
"DateTimeZone",
"(",
"$",
"tz_id",
")",
")",
";",
"(",
"is_int",
"(",
"$",
"ts",
")",
")",
"?",
"$",
"dt",
"->",
"setTimestamp",
"(",
"$",
"ts",
")",
":",
"$",
"dt",
"->",
"modify",
"(",
"$",
"ts",
")",
";",
"return",
"$",
"dt",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}",
"return",
"elgg_echo",
"(",
"$",
"tz_id",
")",
";",
"}"
]
| Returns a label for a timezone
@param string $tz_id PHP timezone id
@param format $format Format
@param mixed $ts Optional timestamp
@return string | [
"Returns",
"a",
"label",
"for",
"a",
"timezone"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L547-L555 |
13,697 | arckinteractive/events_api | classes/Events/API/Util.php | Util.compareTimezonesByOffset | public static function compareTimezonesByOffset($a, $b) {
$dta = new DateTime(null, new DateTimeZone($a));
$dtb = new DateTime(null, new DateTimeZone($b));
if ($dta->getOffset() == $dtb->getOffset()) {
return (strcmp($a, $b) < 0) ? -1 : 1;
}
return ($dta->getOffset() < $dtb->getOffset()) ? -1 : 1;
} | php | public static function compareTimezonesByOffset($a, $b) {
$dta = new DateTime(null, new DateTimeZone($a));
$dtb = new DateTime(null, new DateTimeZone($b));
if ($dta->getOffset() == $dtb->getOffset()) {
return (strcmp($a, $b) < 0) ? -1 : 1;
}
return ($dta->getOffset() < $dtb->getOffset()) ? -1 : 1;
} | [
"public",
"static",
"function",
"compareTimezonesByOffset",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"dta",
"=",
"new",
"DateTime",
"(",
"null",
",",
"new",
"DateTimeZone",
"(",
"$",
"a",
")",
")",
";",
"$",
"dtb",
"=",
"new",
"DateTime",
"(",
"null",
",",
"new",
"DateTimeZone",
"(",
"$",
"b",
")",
")",
";",
"if",
"(",
"$",
"dta",
"->",
"getOffset",
"(",
")",
"==",
"$",
"dtb",
"->",
"getOffset",
"(",
")",
")",
"{",
"return",
"(",
"strcmp",
"(",
"$",
"a",
",",
"$",
"b",
")",
"<",
"0",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"return",
"(",
"$",
"dta",
"->",
"getOffset",
"(",
")",
"<",
"$",
"dtb",
"->",
"getOffset",
"(",
")",
")",
"?",
"-",
"1",
":",
"1",
";",
"}"
]
| Sorting callback function for comparing timezones by offset
@return int | [
"Sorting",
"callback",
"function",
"for",
"comparing",
"timezones",
"by",
"offset"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L561-L570 |
13,698 | arckinteractive/events_api | classes/Events/API/Util.php | Util.getClientTimezone | public static function getClientTimezone($user = null) {
if (isset(self::$timezone)) {
return self::$timezone;
}
$preferred = array();
$preferred[] = get_input('timezone');
if ($user == null) {
$user = elgg_get_logged_in_user_entity();
}
if ($user) {
$preferred[] = $user->timezone;
}
if (defined('ELGG_SITE_TIMEZONE')) {
$preferred[] = ELGG_SITE_TIMEZONE;
}
$preferred[] = date('e');
foreach ($preferred as $id) {
if (self::isValidTimezone($id)) {
self::$timezone = $id;
return $id;
}
}
return Util::UTC;
} | php | public static function getClientTimezone($user = null) {
if (isset(self::$timezone)) {
return self::$timezone;
}
$preferred = array();
$preferred[] = get_input('timezone');
if ($user == null) {
$user = elgg_get_logged_in_user_entity();
}
if ($user) {
$preferred[] = $user->timezone;
}
if (defined('ELGG_SITE_TIMEZONE')) {
$preferred[] = ELGG_SITE_TIMEZONE;
}
$preferred[] = date('e');
foreach ($preferred as $id) {
if (self::isValidTimezone($id)) {
self::$timezone = $id;
return $id;
}
}
return Util::UTC;
} | [
"public",
"static",
"function",
"getClientTimezone",
"(",
"$",
"user",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"timezone",
")",
")",
"{",
"return",
"self",
"::",
"$",
"timezone",
";",
"}",
"$",
"preferred",
"=",
"array",
"(",
")",
";",
"$",
"preferred",
"[",
"]",
"=",
"get_input",
"(",
"'timezone'",
")",
";",
"if",
"(",
"$",
"user",
"==",
"null",
")",
"{",
"$",
"user",
"=",
"elgg_get_logged_in_user_entity",
"(",
")",
";",
"}",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"preferred",
"[",
"]",
"=",
"$",
"user",
"->",
"timezone",
";",
"}",
"if",
"(",
"defined",
"(",
"'ELGG_SITE_TIMEZONE'",
")",
")",
"{",
"$",
"preferred",
"[",
"]",
"=",
"ELGG_SITE_TIMEZONE",
";",
"}",
"$",
"preferred",
"[",
"]",
"=",
"date",
"(",
"'e'",
")",
";",
"foreach",
"(",
"$",
"preferred",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"self",
"::",
"isValidTimezone",
"(",
"$",
"id",
")",
")",
"{",
"self",
"::",
"$",
"timezone",
"=",
"$",
"id",
";",
"return",
"$",
"id",
";",
"}",
"}",
"return",
"Util",
"::",
"UTC",
";",
"}"
]
| Returns display timezone
Returns first set value from the following:
1. Request query element
2. Timezone set by the user in their settings
3. Timezone set as site default
4. PHP timezone
@param ElggUser $user User
@return string | [
"Returns",
"display",
"timezone"
]
| 56c0f0ae403af1672a913db5dc259db9cb712491 | https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Util.php#L584-L616 |
13,699 | csun-metalab/laravel-directory-authentication | src/Authentication/MetaUser.php | MetaUser.masqueradeAsUser | public function masqueradeAsUser($user) {
// if this user is authenticated, then we can masquerade as the
// user that has been passed as the parameter
if(Auth::check()) {
// write the authenticated user into the session and then
// authenticate as the passed user instance
session(['masquerading_user' => Auth::user()]);
Auth::logout();
Auth::login($user);
// success!
return true;
}
return false;
} | php | public function masqueradeAsUser($user) {
// if this user is authenticated, then we can masquerade as the
// user that has been passed as the parameter
if(Auth::check()) {
// write the authenticated user into the session and then
// authenticate as the passed user instance
session(['masquerading_user' => Auth::user()]);
Auth::logout();
Auth::login($user);
// success!
return true;
}
return false;
} | [
"public",
"function",
"masqueradeAsUser",
"(",
"$",
"user",
")",
"{",
"// if this user is authenticated, then we can masquerade as the",
"// user that has been passed as the parameter",
"if",
"(",
"Auth",
"::",
"check",
"(",
")",
")",
"{",
"// write the authenticated user into the session and then",
"// authenticate as the passed user instance",
"session",
"(",
"[",
"'masquerading_user'",
"=>",
"Auth",
"::",
"user",
"(",
")",
"]",
")",
";",
"Auth",
"::",
"logout",
"(",
")",
";",
"Auth",
"::",
"login",
"(",
"$",
"user",
")",
";",
"// success!",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Allows a logged-in user to masquerade as the passed User. Returns true
on success or false otherwise.
@param MetaUser $user The user instance to become
@return boolean | [
"Allows",
"a",
"logged",
"-",
"in",
"user",
"to",
"masquerade",
"as",
"the",
"passed",
"User",
".",
"Returns",
"true",
"on",
"success",
"or",
"false",
"otherwise",
"."
]
| b8d4fa64dd646566e508cdf838d6a3d03b1d53ea | https://github.com/csun-metalab/laravel-directory-authentication/blob/b8d4fa64dd646566e508cdf838d6a3d03b1d53ea/src/Authentication/MetaUser.php#L127-L142 |
Subsets and Splits