repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.dontHaveAttachmentInDatabase | public function dontHaveAttachmentInDatabase(array $criteria, $purgeMeta = true, $removeFiles = false)
{
$mergedCriteria = array_merge($criteria, ['post_type' => 'attachment']);
if ((bool)$removeFiles) {
$posts = $this->grabPostsTableName();
$attachmentIds = $this->grabColumnFromDatabase($posts, 'ID', $mergedCriteria);
$this->dontHaveAttachmentFilesInDatabase($attachmentIds);
}
$this->dontHavePostInDatabase($mergedCriteria, $purgeMeta);
} | php | public function dontHaveAttachmentInDatabase(array $criteria, $purgeMeta = true, $removeFiles = false)
{
$mergedCriteria = array_merge($criteria, ['post_type' => 'attachment']);
if ((bool)$removeFiles) {
$posts = $this->grabPostsTableName();
$attachmentIds = $this->grabColumnFromDatabase($posts, 'ID', $mergedCriteria);
$this->dontHaveAttachmentFilesInDatabase($attachmentIds);
}
$this->dontHavePostInDatabase($mergedCriteria, $purgeMeta);
} | [
"public",
"function",
"dontHaveAttachmentInDatabase",
"(",
"array",
"$",
"criteria",
",",
"$",
"purgeMeta",
"=",
"true",
",",
"$",
"removeFiles",
"=",
"false",
")",
"{",
"$",
"mergedCriteria",
"=",
"array_merge",
"(",
"$",
"criteria",
",",
"[",
"'post_type'",
... | Removes an attachment from the posts table.
@example
```
$postmeta = $I->grabpostmetatablename();
$thumbnailId = $I->grabFromDatabase($postmeta, 'meta_value', [
'post_id' => $id,
'meta_key'=>'thumbnail_id'
]);
// Remove only the database entry (including postmeta) but not the files.
$I->dontHaveAttachmentInDatabase($thumbnailId);
// Remove the database entry (including postmeta) and the files.
$I->dontHaveAttachmentInDatabase($thumbnailId, true, true);
```
@param array $criteria An array of search criteria to find the attachment post in the posts table.
@param bool $purgeMeta If set to `true` then the meta for the attachment will be purged too.
@param bool $removeFiles Remove all files too, requires the `WPFilesystem` module to be loaded in the suite.
@throws \Codeception\Exception\ModuleException If the WPFilesystem module is not loaded in the suite
and the `$removeFiles` argument is `true`. | [
"Removes",
"an",
"attachment",
"from",
"the",
"posts",
"table",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3327-L3338 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.dontHaveAttachmentFilesInDatabase | public function dontHaveAttachmentFilesInDatabase($attachmentIds)
{
$postmeta = $this->grabPostmetaTableName();
foreach ((array)$attachmentIds as $attachmentId) {
$attachedFile = $this->grabAttachmentAttachedFile($attachmentId);
$attachmentMetadata = $this->grabAttachmentMetadata($attachmentId);
$fs = $this->getWpFilesystemModule();
$filesPath = Utils::untrailslashit($fs->getUploadsPath(dirname($attachedFile)));
if (!isset($attachmentMetadata['sizes']) && is_array($attachmentMetadata['sizes'])) {
continue;
}
foreach ($attachmentMetadata['sizes'] as $size => $sizeData) {
$filePath = $filesPath . '/' . $sizeData['file'];
$fs->deleteUploadedFile($filePath);
}
$fs->deleteUploadedFile($attachedFile);
}
} | php | public function dontHaveAttachmentFilesInDatabase($attachmentIds)
{
$postmeta = $this->grabPostmetaTableName();
foreach ((array)$attachmentIds as $attachmentId) {
$attachedFile = $this->grabAttachmentAttachedFile($attachmentId);
$attachmentMetadata = $this->grabAttachmentMetadata($attachmentId);
$fs = $this->getWpFilesystemModule();
$filesPath = Utils::untrailslashit($fs->getUploadsPath(dirname($attachedFile)));
if (!isset($attachmentMetadata['sizes']) && is_array($attachmentMetadata['sizes'])) {
continue;
}
foreach ($attachmentMetadata['sizes'] as $size => $sizeData) {
$filePath = $filesPath . '/' . $sizeData['file'];
$fs->deleteUploadedFile($filePath);
}
$fs->deleteUploadedFile($attachedFile);
}
} | [
"public",
"function",
"dontHaveAttachmentFilesInDatabase",
"(",
"$",
"attachmentIds",
")",
"{",
"$",
"postmeta",
"=",
"$",
"this",
"->",
"grabPostmetaTableName",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"attachmentIds",
"as",
"$",
"attachmentId",
... | Removes all the files attached with an attachment post, it will not remove the database entries.
Requires the `WPFilesystem` module to be loaded in the suite.
@example
```php
$posts = $I->grabPostsTableName();
$attachmentIds = $I->grabColumnFromDatabase($posts, 'ID', ['post_type' => 'attachment']);
// This will only remove the files, not the database entries.
$I->dontHaveAttachmentFilesInDatabase($attachmentIds);
```
@param array|int $attachmentIds An attachment post ID or an array of attachment post IDs.
@throws \Codeception\Exception\ModuleException If the `WPFilesystem` module is not loaded in the suite. | [
"Removes",
"all",
"the",
"files",
"attached",
"with",
"an",
"attachment",
"post",
"it",
"will",
"not",
"remove",
"the",
"database",
"entries",
".",
"Requires",
"the",
"WPFilesystem",
"module",
"to",
"be",
"loaded",
"in",
"the",
"suite",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3356-L3377 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.grabAttachmentAttachedFile | public function grabAttachmentAttachedFile($attachmentPostId)
{
$attachedFile = $this->grabFromDatabase(
$this->grabPostmetaTableName(),
'meta_value',
['meta_key' => '_wp_attached_file', 'post_id' => $attachmentPostId]
);
return (string)$attachedFile;
} | php | public function grabAttachmentAttachedFile($attachmentPostId)
{
$attachedFile = $this->grabFromDatabase(
$this->grabPostmetaTableName(),
'meta_value',
['meta_key' => '_wp_attached_file', 'post_id' => $attachmentPostId]
);
return (string)$attachedFile;
} | [
"public",
"function",
"grabAttachmentAttachedFile",
"(",
"$",
"attachmentPostId",
")",
"{",
"$",
"attachedFile",
"=",
"$",
"this",
"->",
"grabFromDatabase",
"(",
"$",
"this",
"->",
"grabPostmetaTableName",
"(",
")",
",",
"'meta_value'",
",",
"[",
"'meta_key'",
"... | Returns the path, as stored in the database, of an attachment `_wp_attached_file` meta.
The attached file is, usually, an attachment origal file.
@example
```php
$file = $I->grabAttachmentAttachedFile($attachmentId);
$fileInfo = new SplFileInfo($file);
$I->assertEquals('jpg', $fileInfo->getExtension());
```
@param int $attachmentPostId The attachment post ID.
@return string The attachment attached file path or an empt string if not set. | [
"Returns",
"the",
"path",
"as",
"stored",
"in",
"the",
"database",
"of",
"an",
"attachment",
"_wp_attached_file",
"meta",
".",
"The",
"attached",
"file",
"is",
"usually",
"an",
"attachment",
"origal",
"file",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3394-L3403 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.grabAttachmentMetadata | public function grabAttachmentMetadata($attachmentPostId)
{
$serializedData = $this->grabFromDatabase(
$this->grabPostmetaTableName(),
'meta_value',
['meta_key' => '_wp_attachment_metadata', 'post_id' => $attachmentPostId]
);
return !empty($serializedData) ?
unserialize($serializedData)
: [];
} | php | public function grabAttachmentMetadata($attachmentPostId)
{
$serializedData = $this->grabFromDatabase(
$this->grabPostmetaTableName(),
'meta_value',
['meta_key' => '_wp_attachment_metadata', 'post_id' => $attachmentPostId]
);
return !empty($serializedData) ?
unserialize($serializedData)
: [];
} | [
"public",
"function",
"grabAttachmentMetadata",
"(",
"$",
"attachmentPostId",
")",
"{",
"$",
"serializedData",
"=",
"$",
"this",
"->",
"grabFromDatabase",
"(",
"$",
"this",
"->",
"grabPostmetaTableName",
"(",
")",
",",
"'meta_value'",
",",
"[",
"'meta_key'",
"=>... | Returns the metadata array for an attachment post.
This is the value of the `_wp_attachment_metadata` meta.
@example
```php
$metadata = $I->grabAttachmentMetadata($attachmentId);
$I->assertEquals(['thumbnail', 'medium', 'medium_large'], array_keys($metadata['sizes']);
```
@param int $attachmentPostId The attachment post ID.
@return array The unserialized contents of the attachment `_wp_attachment_metadata` meta or an empty array. | [
"Returns",
"the",
"metadata",
"array",
"for",
"an",
"attachment",
"post",
".",
"This",
"is",
"the",
"value",
"of",
"the",
"_wp_attachment_metadata",
"meta",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3419-L3430 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.dontHavePostInDatabase | public function dontHavePostInDatabase(array $criteria, $purgeMeta = true)
{
$postsTable = $this->grabPrefixedTableNameFor('posts');
if ($purgeMeta) {
$id = $this->grabFromDatabase($postsTable, 'ID', $criteria);
if (!empty($id)) {
$this->dontHavePostMetaInDatabase(['post_id' => $id]);
}
}
$this->dontHaveInDatabase($postsTable, $criteria);
} | php | public function dontHavePostInDatabase(array $criteria, $purgeMeta = true)
{
$postsTable = $this->grabPrefixedTableNameFor('posts');
if ($purgeMeta) {
$id = $this->grabFromDatabase($postsTable, 'ID', $criteria);
if (!empty($id)) {
$this->dontHavePostMetaInDatabase(['post_id' => $id]);
}
}
$this->dontHaveInDatabase($postsTable, $criteria);
} | [
"public",
"function",
"dontHavePostInDatabase",
"(",
"array",
"$",
"criteria",
",",
"$",
"purgeMeta",
"=",
"true",
")",
"{",
"$",
"postsTable",
"=",
"$",
"this",
"->",
"grabPrefixedTableNameFor",
"(",
"'posts'",
")",
";",
"if",
"(",
"$",
"purgeMeta",
")",
... | Removes an entry from the posts table.
@example
```php
$posts = $I->haveManyPostsInDatabase(3, ['post_title' => 'Test {{n}}']);
$I->dontHavePostInDatabase(['post_title' => 'Test 2']);
```
@param array $criteria An array of search criteria.
@param bool $purgeMeta If set to `true` then the meta for the post will be purged too. | [
"Removes",
"an",
"entry",
"from",
"the",
"posts",
"table",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3444-L3455 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.dontHaveUserInDatabase | public function dontHaveUserInDatabase($userIdOrLogin, $purgeMeta = true)
{
$userId = is_numeric($userIdOrLogin) ? intval($userIdOrLogin) : $this->grabUserIdFromDatabase($userIdOrLogin);
$this->dontHaveInDatabase($this->grabPrefixedTableNameFor('users'), ['ID' => $userId]);
if ($purgeMeta) {
$this->dontHaveInDatabase($this->grabPrefixedTableNameFor('usermeta'), ['user_id' => $userId]);
}
} | php | public function dontHaveUserInDatabase($userIdOrLogin, $purgeMeta = true)
{
$userId = is_numeric($userIdOrLogin) ? intval($userIdOrLogin) : $this->grabUserIdFromDatabase($userIdOrLogin);
$this->dontHaveInDatabase($this->grabPrefixedTableNameFor('users'), ['ID' => $userId]);
if ($purgeMeta) {
$this->dontHaveInDatabase($this->grabPrefixedTableNameFor('usermeta'), ['user_id' => $userId]);
}
} | [
"public",
"function",
"dontHaveUserInDatabase",
"(",
"$",
"userIdOrLogin",
",",
"$",
"purgeMeta",
"=",
"true",
")",
"{",
"$",
"userId",
"=",
"is_numeric",
"(",
"$",
"userIdOrLogin",
")",
"?",
"intval",
"(",
"$",
"userIdOrLogin",
")",
":",
"$",
"this",
"->"... | Removes a user from the database.
@example
```php
$bob = $I->haveUserInDatabase('bob');
$alice = $I->haveUserInDatabase('alice');
// Remove Bob's user and meta.
$I->dontHaveUserInDatabase('bob');
// Remove Alice's user but not meta.
$I->dontHaveUserInDatabase($alice);
```
@param int|string $userIdOrLogin The user ID or login name.
@param bool $purgeMeta Whether the user meta should be purged alongside the user or not. | [
"Removes",
"a",
"user",
"from",
"the",
"database",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3539-L3546 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.grabPostMetaFromDatabase | public function grabPostMetaFromDatabase($postId, $metaKey, $single = false)
{
$postmeta = $this->grabPostmetaTableName();
$grabbed = (array)$this->grabColumnFromDatabase(
$postmeta,
'meta_value',
['post_id' => $postId, 'meta_key' => $metaKey]
);
$values = array_reduce($grabbed, function (array $metaValues, $value) {
$values = (array)$this->maybeUnserialize($value);
array_push($metaValues, ...$values);
return $metaValues;
}, []);
return (bool)$single ? $values[0] : $values;
} | php | public function grabPostMetaFromDatabase($postId, $metaKey, $single = false)
{
$postmeta = $this->grabPostmetaTableName();
$grabbed = (array)$this->grabColumnFromDatabase(
$postmeta,
'meta_value',
['post_id' => $postId, 'meta_key' => $metaKey]
);
$values = array_reduce($grabbed, function (array $metaValues, $value) {
$values = (array)$this->maybeUnserialize($value);
array_push($metaValues, ...$values);
return $metaValues;
}, []);
return (bool)$single ? $values[0] : $values;
} | [
"public",
"function",
"grabPostMetaFromDatabase",
"(",
"$",
"postId",
",",
"$",
"metaKey",
",",
"$",
"single",
"=",
"false",
")",
"{",
"$",
"postmeta",
"=",
"$",
"this",
"->",
"grabPostmetaTableName",
"(",
")",
";",
"$",
"grabbed",
"=",
"(",
"array",
")"... | Gets the value of one or more post meta values from the database.
@example
```php
$thumbnail_id = $I->grabPostMetaFromDatabase($postId, '_thumbnail_id', true);
```
@param int $postId The post ID.
@param string $metaKey The key of the meta to retrieve.
@param bool $single Whether to return a single meta value or an arrya of all available meta values.
@return mixed|array Either a single meta value or an array of all the available meta values. | [
"Gets",
"the",
"value",
"of",
"one",
"or",
"more",
"post",
"meta",
"values",
"from",
"the",
"database",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3579-L3594 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.grabBlogTableName | public function grabBlogTableName($blogId, $table)
{
$blogTableNames = $this->grabBlogTableNames($blogId);
if (!count($blogTableNames)) {
throw new ModuleException($this, 'No tables found for blog with ID ' . $blogId);
}
foreach ($blogTableNames as $candidate) {
if (strpos($candidate, $table) === false) {
continue;
}
return $candidate;
}
return '';
} | php | public function grabBlogTableName($blogId, $table)
{
$blogTableNames = $this->grabBlogTableNames($blogId);
if (!count($blogTableNames)) {
throw new ModuleException($this, 'No tables found for blog with ID ' . $blogId);
}
foreach ($blogTableNames as $candidate) {
if (strpos($candidate, $table) === false) {
continue;
}
return $candidate;
}
return '';
} | [
"public",
"function",
"grabBlogTableName",
"(",
"$",
"blogId",
",",
"$",
"table",
")",
"{",
"$",
"blogTableNames",
"=",
"$",
"this",
"->",
"grabBlogTableNames",
"(",
"$",
"blogId",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"blogTableNames",
")",
")",
... | Returns the full name of a table for a blog from a multisite installation database.
@example
```php
$blogOptionTable = $I->grabBlogTableName($blogId, 'option');
```
@param int $blogId The blog ID.
@param string $table The table name, without table prefix.
@return string The full blog table name, including the table prefix or an empty string
if the table does not exist.
@throws \Codeception\Exception\ModuleException If no tables are found for the blog. | [
"Returns",
"the",
"full",
"name",
"of",
"a",
"table",
"for",
"a",
"blog",
"from",
"a",
"multisite",
"installation",
"database",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3612-L3628 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb._replaceUrlInDump | public function _replaceUrlInDump($sql)
{
if ($this->config['urlReplacement'] === false) {
return $sql;
}
$this->dbDump->setTablePrefix($this->config['tablePrefix']);
$this->dbDump->setUrl($this->config['url']);
if (\is_array($sql)) {
$sql = $this->dbDump->replaceSiteDomainInSqlArray($sql);
$sql = $this->dbDump->replaceSiteDomainInMultisiteSqlArray($sql);
} else {
$sql = $this->dbDump->replaceSiteDomainInSqlString($sql, true);
$sql = $this->dbDump->replaceSiteDomainInMultisiteSqlString($sql, true);
}
return $sql;
} | php | public function _replaceUrlInDump($sql)
{
if ($this->config['urlReplacement'] === false) {
return $sql;
}
$this->dbDump->setTablePrefix($this->config['tablePrefix']);
$this->dbDump->setUrl($this->config['url']);
if (\is_array($sql)) {
$sql = $this->dbDump->replaceSiteDomainInSqlArray($sql);
$sql = $this->dbDump->replaceSiteDomainInMultisiteSqlArray($sql);
} else {
$sql = $this->dbDump->replaceSiteDomainInSqlString($sql, true);
$sql = $this->dbDump->replaceSiteDomainInMultisiteSqlString($sql, true);
}
return $sql;
} | [
"public",
"function",
"_replaceUrlInDump",
"(",
"$",
"sql",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'urlReplacement'",
"]",
"===",
"false",
")",
"{",
"return",
"$",
"sql",
";",
"}",
"$",
"this",
"->",
"dbDump",
"->",
"setTablePrefix",
"... | Replaces the URL hard-coded in the database with the one set in the the config if required.
@param string|array $sql The SQL dump string or strings.
@return array|string The SQL dump string, or strings, with the hard-coded URL replaced. | [
"Replaces",
"the",
"URL",
"hard",
"-",
"coded",
"in",
"the",
"database",
"with",
"the",
"one",
"set",
"in",
"the",
"the",
"config",
"if",
"required",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3729-L3747 | train |
lucatume/wp-browser | src/Codeception/Module/WPDb.php | WPDb.maybeCheckTermExistsInDatabase | protected function maybeCheckTermExistsInDatabase($term_id)
{
if (!isset($this->config['checkExistence']) or false == $this->config['checkExistence']) {
return;
}
$tableName = $this->grabPrefixedTableNameFor('terms');
if (!$this->grabFromDatabase($tableName, 'term_id', ['term_id' => $term_id])) {
throw new \RuntimeException("A term with an id of $term_id does not exist", 1);
}
} | php | protected function maybeCheckTermExistsInDatabase($term_id)
{
if (!isset($this->config['checkExistence']) or false == $this->config['checkExistence']) {
return;
}
$tableName = $this->grabPrefixedTableNameFor('terms');
if (!$this->grabFromDatabase($tableName, 'term_id', ['term_id' => $term_id])) {
throw new \RuntimeException("A term with an id of $term_id does not exist", 1);
}
} | [
"protected",
"function",
"maybeCheckTermExistsInDatabase",
"(",
"$",
"term_id",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'checkExistence'",
"]",
")",
"or",
"false",
"==",
"$",
"this",
"->",
"config",
"[",
"'checkExistence'",... | Conditionally checks that a term exists in the database.
Will look up the "terms" table, will throw if not found.
@param int $term_id The term ID. | [
"Conditionally",
"checks",
"that",
"a",
"term",
"exists",
"in",
"the",
"database",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPDb.php#L3756-L3765 | train |
lucatume/wp-browser | src/includes/utils.php | MockAction.get_call_count | function get_call_count($tag='') {
if ($tag) {
$count = 0;
foreach ($this->events as $e)
if ($e['action'] == $tag)
++$count;
return $count;
}
return count($this->events);
} | php | function get_call_count($tag='') {
if ($tag) {
$count = 0;
foreach ($this->events as $e)
if ($e['action'] == $tag)
++$count;
return $count;
}
return count($this->events);
} | [
"function",
"get_call_count",
"(",
"$",
"tag",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"tag",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"events",
"as",
"$",
"e",
")",
"if",
"(",
"$",
"e",
"[",
"'action'",
"]",
"==... | return a count of the number of times the action was called since the last reset | [
"return",
"a",
"count",
"of",
"the",
"number",
"of",
"times",
"the",
"action",
"was",
"called",
"since",
"the",
"last",
"reset"
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/includes/utils.php#L112-L121 | train |
lucatume/wp-browser | src/includes/speed-trap-listener.php | SpeedTrapListener.getHiddenCount | protected function getHiddenCount()
{
$total = count($this->slow);
$showing = $this->getReportLength($this->slow);
$hidden = 0;
if ($total > $showing) {
$hidden = $total - $showing;
}
return $hidden;
} | php | protected function getHiddenCount()
{
$total = count($this->slow);
$showing = $this->getReportLength($this->slow);
$hidden = 0;
if ($total > $showing) {
$hidden = $total - $showing;
}
return $hidden;
} | [
"protected",
"function",
"getHiddenCount",
"(",
")",
"{",
"$",
"total",
"=",
"count",
"(",
"$",
"this",
"->",
"slow",
")",
";",
"$",
"showing",
"=",
"$",
"this",
"->",
"getReportLength",
"(",
"$",
"this",
"->",
"slow",
")",
";",
"$",
"hidden",
"=",
... | Find how many slow tests occurred that won't be shown due to list length.
@return int Number of hidden slow tests | [
"Find",
"how",
"many",
"slow",
"tests",
"occurred",
"that",
"won",
"t",
"be",
"shown",
"due",
"to",
"list",
"length",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/includes/speed-trap-listener.php#L246-L257 | train |
lucatume/wp-browser | src/includes/speed-trap-listener.php | SpeedTrapListener.renderBody | protected function renderBody()
{
$slowTests = $this->slow;
$length = $this->getReportLength($slowTests);
for ($i = 1; $i <= $length; ++$i) {
$label = key($slowTests);
$time = array_shift($slowTests);
echo sprintf(" %s. %sms to run %s\n", $i, $time, $label);
}
} | php | protected function renderBody()
{
$slowTests = $this->slow;
$length = $this->getReportLength($slowTests);
for ($i = 1; $i <= $length; ++$i) {
$label = key($slowTests);
$time = array_shift($slowTests);
echo sprintf(" %s. %sms to run %s\n", $i, $time, $label);
}
} | [
"protected",
"function",
"renderBody",
"(",
")",
"{",
"$",
"slowTests",
"=",
"$",
"this",
"->",
"slow",
";",
"$",
"length",
"=",
"$",
"this",
"->",
"getReportLength",
"(",
"$",
"slowTests",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
... | Renders slow test report body. | [
"Renders",
"slow",
"test",
"report",
"body",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/includes/speed-trap-listener.php#L270-L281 | train |
lucatume/wp-browser | src/includes/speed-trap-listener.php | SpeedTrapListener.loadOptions | protected function loadOptions(array $options)
{
$this->slowThreshold = isset($options['slowThreshold']) ? $options['slowThreshold'] : 500;
$this->reportLength = isset($options['reportLength']) ? $options['reportLength'] : 10;
} | php | protected function loadOptions(array $options)
{
$this->slowThreshold = isset($options['slowThreshold']) ? $options['slowThreshold'] : 500;
$this->reportLength = isset($options['reportLength']) ? $options['reportLength'] : 10;
} | [
"protected",
"function",
"loadOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"slowThreshold",
"=",
"isset",
"(",
"$",
"options",
"[",
"'slowThreshold'",
"]",
")",
"?",
"$",
"options",
"[",
"'slowThreshold'",
"]",
":",
"500",
";",
"$... | Populate options into class internals.
@param array $options | [
"Populate",
"options",
"into",
"class",
"internals",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/includes/speed-trap-listener.php#L298-L302 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowser.php | WPBrowser._initialize | public function _initialize()
{
parent::_initialize();
$this->configBackCompat();
$adminPath = $this->config['adminPath'];
$this->loginUrl = str_replace('wp-admin', 'wp-login.php', $adminPath);
$this->adminPath = rtrim($adminPath, '/');
$this->pluginsPath = $this->adminPath . '/plugins.php';
} | php | public function _initialize()
{
parent::_initialize();
$this->configBackCompat();
$adminPath = $this->config['adminPath'];
$this->loginUrl = str_replace('wp-admin', 'wp-login.php', $adminPath);
$this->adminPath = rtrim($adminPath, '/');
$this->pluginsPath = $this->adminPath . '/plugins.php';
} | [
"public",
"function",
"_initialize",
"(",
")",
"{",
"parent",
"::",
"_initialize",
"(",
")",
";",
"$",
"this",
"->",
"configBackCompat",
"(",
")",
";",
"$",
"adminPath",
"=",
"$",
"this",
"->",
"config",
"[",
"'adminPath'",
"]",
";",
"$",
"this",
"->",... | Initializes the module setting the properties values. | [
"Initializes",
"the",
"module",
"setting",
"the",
"properties",
"values",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowser.php#L42-L52 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowser.php | WPBrowser.activatePlugin | public function activatePlugin($pluginSlug)
{
foreach ((array)$pluginSlug as $plugin) {
$this->checkOption('//*[@data-slug="' . $plugin . '"]/th/input');
}
$this->selectOption('action', 'activate-selected');
$this->click("#doaction");
} | php | public function activatePlugin($pluginSlug)
{
foreach ((array)$pluginSlug as $plugin) {
$this->checkOption('//*[@data-slug="' . $plugin . '"]/th/input');
}
$this->selectOption('action', 'activate-selected');
$this->click("#doaction");
} | [
"public",
"function",
"activatePlugin",
"(",
"$",
"pluginSlug",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"pluginSlug",
"as",
"$",
"plugin",
")",
"{",
"$",
"this",
"->",
"checkOption",
"(",
"'//*[@data-slug=\"'",
".",
"$",
"plugin",
".",
"'\"]/th/i... | In the plugin administration screen activates a plugin clicking the "Activate" link.
The method will **not** handle authentication to the admin area.
@example
```php
// Activate a plugin.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->activatePlugin('hello-dolly');
// Activate a list of plugins.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->activatePlugin(['hello-dolly','another-plugin']);
```
@param string|array $pluginSlug The plugin slug, like "hello-dolly" or a list of plugin slugs. | [
"In",
"the",
"plugin",
"administration",
"screen",
"activates",
"a",
"plugin",
"clicking",
"the",
"Activate",
"link",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowser.php#L116-L123 | train |
lucatume/wp-browser | src/includes/spy-rest-server.php | Spy_REST_Server.register_route | public function register_route( $namespace, $route, $route_args, $override = false ) {
parent::register_route( $namespace, $route, $route_args, $override || $this->override_by_default );
} | php | public function register_route( $namespace, $route, $route_args, $override = false ) {
parent::register_route( $namespace, $route, $route_args, $override || $this->override_by_default );
} | [
"public",
"function",
"register_route",
"(",
"$",
"namespace",
",",
"$",
"route",
",",
"$",
"route_args",
",",
"$",
"override",
"=",
"false",
")",
"{",
"parent",
"::",
"register_route",
"(",
"$",
"namespace",
",",
"$",
"route",
",",
"$",
"route_args",
",... | Override the register_route method so we can re-register routes internally if needed.
@param string $namespace Namespace.
@param string $route The REST route.
@param array $route_args Route arguments.
@param bool $override Optional. Whether the route should be overridden if it already exists.
Default false. Also set $GLOBALS['wp_rest_server']->override_by_default = true
to set overrides when you don't have access to the caller context. | [
"Override",
"the",
"register_route",
"method",
"so",
"we",
"can",
"re",
"-",
"register",
"routes",
"internally",
"if",
"needed",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/includes/spy-rest-server.php#L55-L57 | train |
lucatume/wp-browser | src/Codeception/Module/WPWebDriver.php | WPWebDriver.loginAsAdmin | public function loginAsAdmin($timeout = 10, $maxAttempts = 5)
{
$this->loginAs($this->config['adminUsername'], $this->config['adminPassword'], $timeout, $maxAttempts);
} | php | public function loginAsAdmin($timeout = 10, $maxAttempts = 5)
{
$this->loginAs($this->config['adminUsername'], $this->config['adminPassword'], $timeout, $maxAttempts);
} | [
"public",
"function",
"loginAsAdmin",
"(",
"$",
"timeout",
"=",
"10",
",",
"$",
"maxAttempts",
"=",
"5",
")",
"{",
"$",
"this",
"->",
"loginAs",
"(",
"$",
"this",
"->",
"config",
"[",
"'adminUsername'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'a... | Login as the administrator user using the credentials specified in the module configuration.
The method will **not** follow redirection, after the login, to any page.
@example
```php
$I->loginAsAdmin();
$I->amOnAdminPage('/');
$I->see('Dashboard');
```
@param int $timeout The max time, in seconds, to try to login.
@param int $maxAttempts The max number of attempts to try to login.
@throws \Codeception\Exception\ModuleException If all the attempts of obtaining the cookie fail. | [
"Login",
"as",
"the",
"administrator",
"user",
"using",
"the",
"credentials",
"specified",
"in",
"the",
"module",
"configuration",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPWebDriver.php#L82-L85 | train |
lucatume/wp-browser | src/Codeception/Module/WPCLI.php | WPCLI.cli | public function cli($userCommand = 'core version')
{
// Set an environment variable to let client code know the request is coming from the host machine.
putenv('WPBROWSER_HOST_REQUEST=1');
$this->initPaths();
$command = $this->buildCommand($userCommand);
$output = [];
$this->debugSection('command', $command);
$status = $this->executor->exec($command, $output);
$this->debugSection('output', implode("\n", $output));
$this->evaluateStatus($output, $status);
return $status;
} | php | public function cli($userCommand = 'core version')
{
// Set an environment variable to let client code know the request is coming from the host machine.
putenv('WPBROWSER_HOST_REQUEST=1');
$this->initPaths();
$command = $this->buildCommand($userCommand);
$output = [];
$this->debugSection('command', $command);
$status = $this->executor->exec($command, $output);
$this->debugSection('output', implode("\n", $output));
$this->evaluateStatus($output, $status);
return $status;
} | [
"public",
"function",
"cli",
"(",
"$",
"userCommand",
"=",
"'core version'",
")",
"{",
"// Set an environment variable to let client code know the request is coming from the host machine.",
"putenv",
"(",
"'WPBROWSER_HOST_REQUEST=1'",
")",
";",
"$",
"this",
"->",
"initPaths",
... | Executes a wp-cli command targeting the test WordPress installation.
@example
```php
// Activate a plugin via wp-cli in the test WordPress site.
$I->cli('plugin activate my-plugin');
// Change a user password.
$I->cli('user update luca --user_pass=newpassword');
```
@param string $userCommand The string of command and parameters as it would be passed to wp-cli minus `wp`.
@return int The command exit value; `0` usually means success.
@throws \Codeception\Exception\ModuleException If the status evaluates to non-zero and the `throw` configuration
parameter is set to `true`. | [
"Executes",
"a",
"wp",
"-",
"cli",
"command",
"targeting",
"the",
"test",
"WordPress",
"installation",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPCLI.php#L98-L115 | train |
lucatume/wp-browser | src/Codeception/Module/WPCLI.php | WPCLI.initWpCliPaths | protected function initWpCliPaths()
{
try {
$ref = new \ReflectionClass(Configurator::class);
} catch (\ReflectionException $e) {
throw new ModuleException(__CLASS__, 'could not find the path to embedded WPCLI Configurator class');
}
$this->wpCliRoot = dirname($ref->getFileName()) . '/../../';
$this->bootPath = $this->wpCliRoot . '/php/boot-fs.php';
} | php | protected function initWpCliPaths()
{
try {
$ref = new \ReflectionClass(Configurator::class);
} catch (\ReflectionException $e) {
throw new ModuleException(__CLASS__, 'could not find the path to embedded WPCLI Configurator class');
}
$this->wpCliRoot = dirname($ref->getFileName()) . '/../../';
$this->bootPath = $this->wpCliRoot . '/php/boot-fs.php';
} | [
"protected",
"function",
"initWpCliPaths",
"(",
")",
"{",
"try",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"Configurator",
"::",
"class",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"throw",
"new",
"Modu... | Initializes the wp-cli root location.
The way the location works is an ugly hack that assumes the folder structure
of the code to climb the tree and find the root folder.
@throws \Codeception\Exception\ModuleException If the embedded WPCLI Configurator class file
could not be found. | [
"Initializes",
"the",
"wp",
"-",
"cli",
"root",
"location",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPCLI.php#L133-L142 | train |
lucatume/wp-browser | src/Codeception/Module/WPCLI.php | WPCLI.cliToArray | public function cliToArray($userCommand = 'post list --format=ids', callable $splitCallback = null)
{
$this->initPaths();
$command = $this->buildCommand($userCommand);
$this->debugSection('command', $command);
$output = $this->executor->execAndOutput($command, $status);
$this->debugSection('output', $output);
$this->evaluateStatus($output, $status);
if (empty($output)) {
return [];
}
$hasSplitCallback = null !== $splitCallback;
$originalOutput = $output;
if (!is_array($output) || (is_array($output) && $hasSplitCallback)) {
if (is_array($output)) {
$output = implode(PHP_EOL, $output);
}
if (!$hasSplitCallback) {
if (!preg_match('/[\\n]+/', $output)) {
$output = preg_split('/\\s+/', $output);
} else {
$output = preg_split('/\\s*\\n+\\s*/', $output);
}
} else {
$output = $splitCallback($output, $userCommand, $this);
}
}
if (!is_array($output) && $hasSplitCallback) {
throw new ModuleException(
__CLASS__,
"Split callback must return an array, it returned: \n" . print_r(
$output,
true
) . "\nfor original output:\n" . print_r(
$originalOutput,
true
)
);
}
return empty($output) ? [] : array_map('trim', $output);
} | php | public function cliToArray($userCommand = 'post list --format=ids', callable $splitCallback = null)
{
$this->initPaths();
$command = $this->buildCommand($userCommand);
$this->debugSection('command', $command);
$output = $this->executor->execAndOutput($command, $status);
$this->debugSection('output', $output);
$this->evaluateStatus($output, $status);
if (empty($output)) {
return [];
}
$hasSplitCallback = null !== $splitCallback;
$originalOutput = $output;
if (!is_array($output) || (is_array($output) && $hasSplitCallback)) {
if (is_array($output)) {
$output = implode(PHP_EOL, $output);
}
if (!$hasSplitCallback) {
if (!preg_match('/[\\n]+/', $output)) {
$output = preg_split('/\\s+/', $output);
} else {
$output = preg_split('/\\s*\\n+\\s*/', $output);
}
} else {
$output = $splitCallback($output, $userCommand, $this);
}
}
if (!is_array($output) && $hasSplitCallback) {
throw new ModuleException(
__CLASS__,
"Split callback must return an array, it returned: \n" . print_r(
$output,
true
) . "\nfor original output:\n" . print_r(
$originalOutput,
true
)
);
}
return empty($output) ? [] : array_map('trim', $output);
} | [
"public",
"function",
"cliToArray",
"(",
"$",
"userCommand",
"=",
"'post list --format=ids'",
",",
"callable",
"$",
"splitCallback",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"initPaths",
"(",
")",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"buildCommand",... | Returns the output of a wp-cli command as an array optionally allowing a callback to process the output.
@example
```php
// Return a list of inactive themes, like ['twentyfourteen', 'twentyfifteen'].
$inactiveThemes = $I->cliToArray('theme list --status=inactive --field=name');
// Get the list of installed plugins and only keep the ones starting with "foo".
$fooPlugins = $I->cliToArray('plugin list --field=name', function($output){
return array_filter(explode(PHP_EOL, $output), function($name){
return strpos(trim($name), 'foo') === 0;
});
});
```
@param string $userCommand The string of command and parameters as it would be passed to wp-cli minus `wp`.
@param callable $splitCallback An optional callback function in charge of splitting the results array.
@return array An array containing the output of wp-cli split into single elements.
@throws \Codeception\Exception\ModuleException If the $splitCallback function does not return an array. | [
"Returns",
"the",
"output",
"of",
"a",
"wp",
"-",
"cli",
"command",
"as",
"an",
"array",
"optionally",
"allowing",
"a",
"callback",
"to",
"process",
"the",
"output",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPCLI.php#L236-L283 | train |
lucatume/wp-browser | src/Codeception/Module/WordPress.php | WordPress.amOnAdminPage | public function amOnAdminPage($page)
{
$preparedPage = $this->preparePage(ltrim($page, '/'));
if ($preparedPage === '/') {
$preparedPage = 'index.php';
}
$page = $this->adminPath . '/' . $preparedPage;
return $this->amOnPage($page);
} | php | public function amOnAdminPage($page)
{
$preparedPage = $this->preparePage(ltrim($page, '/'));
if ($preparedPage === '/') {
$preparedPage = 'index.php';
}
$page = $this->adminPath . '/' . $preparedPage;
return $this->amOnPage($page);
} | [
"public",
"function",
"amOnAdminPage",
"(",
"$",
"page",
")",
"{",
"$",
"preparedPage",
"=",
"$",
"this",
"->",
"preparePage",
"(",
"ltrim",
"(",
"$",
"page",
",",
"'/'",
")",
")",
";",
"if",
"(",
"$",
"preparedPage",
"===",
"'/'",
")",
"{",
"$",
"... | Go to a page in the admininstration area of the site.
@example
Will this comment show up in the output?
And can I use <code>HTML</code> tags? Like <em>this</em> <stron>one</strong>?
Or **Markdown** tags? *Please...*
```php
$I->loginAs('user', 'password');
// Go to the plugins management screen.
$I->amOnAdminPage('/plugins.php');
```
@param string $page The path, relative to the admin area URL, to the page. | [
"Go",
"to",
"a",
"page",
"in",
"the",
"admininstration",
"area",
"of",
"the",
"site",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WordPress.php#L219-L227 | train |
lucatume/wp-browser | src/Codeception/Module/WordPress.php | WordPress.amOnPage | public function amOnPage($page)
{
$this->setRequestType($page);
$parts = parse_url($page);
$parameters = [];
if (!empty($parts['query'])) {
parse_str($parts['query'], $parameters);
}
$this->client->setHeaders($this->headers);
if ($this->isMockRequest) {
return $page;
}
$this->setCookie('wordpress_test_cookie', 'WP Cookie check');
$this->_loadPage('GET', $page, $parameters);
return null;
} | php | public function amOnPage($page)
{
$this->setRequestType($page);
$parts = parse_url($page);
$parameters = [];
if (!empty($parts['query'])) {
parse_str($parts['query'], $parameters);
}
$this->client->setHeaders($this->headers);
if ($this->isMockRequest) {
return $page;
}
$this->setCookie('wordpress_test_cookie', 'WP Cookie check');
$this->_loadPage('GET', $page, $parameters);
return null;
} | [
"public",
"function",
"amOnPage",
"(",
"$",
"page",
")",
"{",
"$",
"this",
"->",
"setRequestType",
"(",
"$",
"page",
")",
";",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"page",
")",
";",
"$",
"parameters",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"emp... | Go to a page on the site.
The module will try to reach the page, relative to the URL specified in the module configuration, without
applying any permalink resolution.
@example
```php
// Go the the homepage.
$I->amOnPage('/');
// Go to the single page of post with ID 23.
$I->amOnPage('/?p=23');
// Go to search page for the string "foo".
$I->amOnPage('/?s=foo');
```
@param string $page The path to the page, relative to the the root URL. | [
"Go",
"to",
"a",
"page",
"on",
"the",
"site",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WordPress.php#L261-L281 | train |
lucatume/wp-browser | src/Codeception/Module/WordPress.php | WordPress.getWpRootFolder | public function getWpRootFolder()
{
if (empty($this->wpRootFolder)) {
// allow me not to bother with trailing slashes
$wpRootFolder = Utils::untrailslashit($this->config['wpRootFolder']) . DIRECTORY_SEPARATOR;
// maybe the user is using the `~` symbol for home?
$this->wpRootFolder = Utils::homeify($wpRootFolder);
// remove `\ ` spaces in folder paths
$this->wpRootFolder = str_replace('\ ', ' ', $this->wpRootFolder);
}
return $this->wpRootFolder;
} | php | public function getWpRootFolder()
{
if (empty($this->wpRootFolder)) {
// allow me not to bother with trailing slashes
$wpRootFolder = Utils::untrailslashit($this->config['wpRootFolder']) . DIRECTORY_SEPARATOR;
// maybe the user is using the `~` symbol for home?
$this->wpRootFolder = Utils::homeify($wpRootFolder);
// remove `\ ` spaces in folder paths
$this->wpRootFolder = str_replace('\ ', ' ', $this->wpRootFolder);
}
return $this->wpRootFolder;
} | [
"public",
"function",
"getWpRootFolder",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"wpRootFolder",
")",
")",
"{",
"// allow me not to bother with trailing slashes",
"$",
"wpRootFolder",
"=",
"Utils",
"::",
"untrailslashit",
"(",
"$",
"this",
"->... | Returns the absolute path to the WordPress root folder.
@example
```php
$root = $I->getWpRootFolder();
$this->assertFileExists($root . '/someFile.txt');
```
@return string The absolute path to the WordPress root folder, without a trailing slash. | [
"Returns",
"the",
"absolute",
"path",
"to",
"the",
"WordPress",
"root",
"folder",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WordPress.php#L323-L337 | train |
lucatume/wp-browser | src/Codeception/Lib/Driver/ExtendedMySql.php | ExtendedMySql.insertOrUpdate | public function insertOrUpdate($tableName, array $data)
{
$this->executeQuery("SET SESSION sql_mode='ALLOW_INVALID_DATES'", []);
$columns = array_map(
array($this, 'getQuotedName'),
array_keys($data)
);
$updateAssignments = $this->getAssignmentsFor($data);
return sprintf(
"INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s",
$this->getQuotedName($tableName),
implode(', ', $columns),
implode(', ', array_fill(0, count($data), '?')),
$updateAssignments
);
} | php | public function insertOrUpdate($tableName, array $data)
{
$this->executeQuery("SET SESSION sql_mode='ALLOW_INVALID_DATES'", []);
$columns = array_map(
array($this, 'getQuotedName'),
array_keys($data)
);
$updateAssignments = $this->getAssignmentsFor($data);
return sprintf(
"INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s",
$this->getQuotedName($tableName),
implode(', ', $columns),
implode(', ', array_fill(0, count($data), '?')),
$updateAssignments
);
} | [
"public",
"function",
"insertOrUpdate",
"(",
"$",
"tableName",
",",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"executeQuery",
"(",
"\"SET SESSION sql_mode='ALLOW_INVALID_DATES'\"",
",",
"[",
"]",
")",
";",
"$",
"columns",
"=",
"array_map",
"(",
"array... | Returns the statement to insert or update an entry in the database.
@param string $tableName The table name to use
@param array $data Key/value pairs of the data to insert/update.
@return string The query string ready to be prepared. | [
"Returns",
"the",
"statement",
"to",
"insert",
"or",
"update",
"an",
"entry",
"in",
"the",
"database",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Lib/Driver/ExtendedMySql.php#L18-L34 | train |
lucatume/wp-browser | src/includes/mock-mailer.php | MockPHPMailer.get_sent | public function get_sent( $index = 0 ) {
$retval = false;
if ( isset( $this->mock_sent[ $index ] ) ) {
$retval = (object) $this->mock_sent[ $index ];
}
return $retval;
} | php | public function get_sent( $index = 0 ) {
$retval = false;
if ( isset( $this->mock_sent[ $index ] ) ) {
$retval = (object) $this->mock_sent[ $index ];
}
return $retval;
} | [
"public",
"function",
"get_sent",
"(",
"$",
"index",
"=",
"0",
")",
"{",
"$",
"retval",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mock_sent",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"retval",
"=",
"(",
"object",
")",
"... | Decorator to return the information for a sent mock.
@since 4.5.0
@param int $index Optional. Array index of mock_sent value.
@return object | [
"Decorator",
"to",
"return",
"the",
"information",
"for",
"a",
"sent",
"mock",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/includes/mock-mailer.php#L36-L42 | train |
lucatume/wp-browser | src/includes/mock-mailer.php | MockPHPMailer.get_recipient | public function get_recipient( $address_type, $mock_sent_index = 0, $recipient_index = 0 ) {
$retval = false;
$mock = $this->get_sent( $mock_sent_index );
if ( $mock ) {
if ( isset( $mock->{$address_type}[ $recipient_index ] ) ) {
$address_index = $mock->{$address_type}[ $recipient_index ];
$recipient_data = array(
'address' => ( isset( $address_index[0] ) && ! empty( $address_index[0] ) ) ? $address_index[0] : 'No address set',
'name' => ( isset( $address_index[1] ) && ! empty( $address_index[1] ) ) ? $address_index[1] : 'No name set',
);
$retval = (object) $recipient_data;
}
}
return $retval;
} | php | public function get_recipient( $address_type, $mock_sent_index = 0, $recipient_index = 0 ) {
$retval = false;
$mock = $this->get_sent( $mock_sent_index );
if ( $mock ) {
if ( isset( $mock->{$address_type}[ $recipient_index ] ) ) {
$address_index = $mock->{$address_type}[ $recipient_index ];
$recipient_data = array(
'address' => ( isset( $address_index[0] ) && ! empty( $address_index[0] ) ) ? $address_index[0] : 'No address set',
'name' => ( isset( $address_index[1] ) && ! empty( $address_index[1] ) ) ? $address_index[1] : 'No name set',
);
$retval = (object) $recipient_data;
}
}
return $retval;
} | [
"public",
"function",
"get_recipient",
"(",
"$",
"address_type",
",",
"$",
"mock_sent_index",
"=",
"0",
",",
"$",
"recipient_index",
"=",
"0",
")",
"{",
"$",
"retval",
"=",
"false",
";",
"$",
"mock",
"=",
"$",
"this",
"->",
"get_sent",
"(",
"$",
"mock_... | Get a recipient for a sent mock.
@since 4.5.0
@param string $address_type The type of address for the email such as to, cc or bcc.
@param int $mock_sent_index Optional. The sent_mock index we want to get the recipient for.
@param int $recipient_index Optional. The recipient index in the array.
@return bool|object Returns object on success, or false if any of the indices don't exist. | [
"Get",
"a",
"recipient",
"for",
"a",
"sent",
"mock",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/includes/mock-mailer.php#L54-L70 | train |
lucatume/wp-browser | src/tad/WPBrowser/Module/WPLoader/FactoryStore.php | FactoryStore.setupFactories | public function setupFactories()
{
require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/includes/factory.php';
$this->post = new \WP_UnitTest_Factory_For_Post();
$this->bookmark = new \WP_UnitTest_Factory_For_Bookmark();
$this->attachment = new \WP_UnitTest_Factory_For_Attachment();
$this->user = new \WP_UnitTest_Factory_For_User();
$this->comment = new \WP_UnitTest_Factory_For_Comment();
$this->blog = new \WP_UnitTest_Factory_For_Blog();
$this->network = new \WP_UnitTest_Factory_For_Network();
$this->term = new \WP_UnitTest_Factory_For_Term();
} | php | public function setupFactories()
{
require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/includes/factory.php';
$this->post = new \WP_UnitTest_Factory_For_Post();
$this->bookmark = new \WP_UnitTest_Factory_For_Bookmark();
$this->attachment = new \WP_UnitTest_Factory_For_Attachment();
$this->user = new \WP_UnitTest_Factory_For_User();
$this->comment = new \WP_UnitTest_Factory_For_Comment();
$this->blog = new \WP_UnitTest_Factory_For_Blog();
$this->network = new \WP_UnitTest_Factory_For_Network();
$this->term = new \WP_UnitTest_Factory_For_Term();
} | [
"public",
"function",
"setupFactories",
"(",
")",
"{",
"require_once",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"__DIR__",
")",
")",
")",
")",
".",
"'/includes/factory.php'",
";",
"$",
"this",
"->",
"post",
"=",
"new",
"\\",
"WP_Unit... | Sets up and instantiates the factories. | [
"Sets",
"up",
"and",
"instantiates",
"the",
"factories",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/tad/WPBrowser/Module/WPLoader/FactoryStore.php#L52-L64 | train |
lucatume/wp-browser | src/Codeception/Lib/Driver/ExtendedDbDriver.php | ExtendedDbDriver.create | public static function create($dsn, $user, $password, $options = null)
{
$provider = self::getProvider($dsn);
switch ($provider) {
case 'sqlite':
return new Sqlite($dsn, $user, $password, $options);
case 'mysql':
return new ExtendedMySql($dsn, $user, $password, $options);
case 'pgsql':
return new PostgreSql($dsn, $user, $password, $options);
case 'mssql':
case 'dblib':
case 'sqlsrv':
return new SqlSrv($dsn, $user, $password, $options);
case 'oci':
return new Oci($dsn, $user, $password, $options);
default:
return new Db($dsn, $user, $password, $options);
}
} | php | public static function create($dsn, $user, $password, $options = null)
{
$provider = self::getProvider($dsn);
switch ($provider) {
case 'sqlite':
return new Sqlite($dsn, $user, $password, $options);
case 'mysql':
return new ExtendedMySql($dsn, $user, $password, $options);
case 'pgsql':
return new PostgreSql($dsn, $user, $password, $options);
case 'mssql':
case 'dblib':
case 'sqlsrv':
return new SqlSrv($dsn, $user, $password, $options);
case 'oci':
return new Oci($dsn, $user, $password, $options);
default:
return new Db($dsn, $user, $password, $options);
}
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"dsn",
",",
"$",
"user",
",",
"$",
"password",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"provider",
"=",
"self",
"::",
"getProvider",
"(",
"$",
"dsn",
")",
";",
"switch",
"(",
"$",
"provid... | Identical to the original method but changing the MySQL driver.
@static
@param $dsn
@param $user
@param $password
@param [optional] $options
@see http://php.net/manual/en/pdo.construct.php
@see http://php.net/manual/de/ref.pdo-mysql.php#pdo-mysql.constants
@return Db|SqlSrv|MySql|Oci|PostgreSql|Sqlite | [
"Identical",
"to",
"the",
"original",
"method",
"but",
"changing",
"the",
"MySQL",
"driver",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Lib/Driver/ExtendedDbDriver.php#L26-L46 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowserMethods.php | WPBrowserMethods.activatePlugin | public function activatePlugin($pluginSlug)
{
$plugins = (array)$pluginSlug;
foreach ($plugins as $plugin) {
$option = '//*[@data-slug="' . $plugin . '"]/th/input';
$this->scrollTo($option, 0, -40);
$this->checkOption($option);
}
$this->scrollTo('select[name="action"]', 0, -40);
$this->selectOption('action', 'activate-selected');
$this->click("#doaction");
} | php | public function activatePlugin($pluginSlug)
{
$plugins = (array)$pluginSlug;
foreach ($plugins as $plugin) {
$option = '//*[@data-slug="' . $plugin . '"]/th/input';
$this->scrollTo($option, 0, -40);
$this->checkOption($option);
}
$this->scrollTo('select[name="action"]', 0, -40);
$this->selectOption('action', 'activate-selected');
$this->click("#doaction");
} | [
"public",
"function",
"activatePlugin",
"(",
"$",
"pluginSlug",
")",
"{",
"$",
"plugins",
"=",
"(",
"array",
")",
"$",
"pluginSlug",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"$",
"option",
"=",
"'//*[@data-slug=\"'",
".",
"$",
... | In the plugin administration screen activates one or more plugins clicking the "Activate" link.
The method will **not** handle authentication and navigation to the plugins administration page.
@example
```php
// Activate a plugin.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->activatePlugin('hello-dolly');
// Activate a list of plugins.
$I->loginAsAdmin();
$I->amOnPluginsPage();
$I->activatePlugin(['hello-dolly','another-plugin']);
```
@param string|array $pluginSlug The plugin slug, like "hello-dolly" or a list of plugin slugs. | [
"In",
"the",
"plugin",
"administration",
"screen",
"activates",
"one",
"or",
"more",
"plugins",
"clicking",
"the",
"Activate",
"link",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowserMethods.php#L89-L100 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowserMethods.php | WPBrowserMethods.seeErrorMessage | public function seeErrorMessage($classes = '')
{
$classes = (array)$classes;
$classes = implode('.', $classes);
$this->seeElement('.notice.notice-error' . ($classes ?: ''));
} | php | public function seeErrorMessage($classes = '')
{
$classes = (array)$classes;
$classes = implode('.', $classes);
$this->seeElement('.notice.notice-error' . ($classes ?: ''));
} | [
"public",
"function",
"seeErrorMessage",
"(",
"$",
"classes",
"=",
"''",
")",
"{",
"$",
"classes",
"=",
"(",
"array",
")",
"$",
"classes",
";",
"$",
"classes",
"=",
"implode",
"(",
"'.'",
",",
"$",
"classes",
")",
";",
"$",
"this",
"->",
"seeElement"... | In an administration screen look for an error admin notice.
The check is class-based to decouple from internationalization.
The method will **not** handle authentication and navigation the administration area.
@example
```php
$I->loginAsAdmin()ja
$I->amOnAdminPage('/');
$I->seeErrorMessage('.my-plugin');
```
@param array|string $classes A list of classes the notice should have other than the `.notice.notice-error` ones. | [
"In",
"an",
"administration",
"screen",
"look",
"for",
"an",
"error",
"admin",
"notice",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowserMethods.php#L260-L266 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowserMethods.php | WPBrowserMethods.seeMessage | public function seeMessage($classes = '')
{
$classes = (array)$classes;
$classes = implode('.', $classes);
$this->seeElement('.notice' . ($classes ?: ''));
} | php | public function seeMessage($classes = '')
{
$classes = (array)$classes;
$classes = implode('.', $classes);
$this->seeElement('.notice' . ($classes ?: ''));
} | [
"public",
"function",
"seeMessage",
"(",
"$",
"classes",
"=",
"''",
")",
"{",
"$",
"classes",
"=",
"(",
"array",
")",
"$",
"classes",
";",
"$",
"classes",
"=",
"implode",
"(",
"'.'",
",",
"$",
"classes",
")",
";",
"$",
"this",
"->",
"seeElement",
"... | In an administration screen look for an admin notice.
The check is class-based to decouple from internationalization.
The method will **not** handle authentication and navigation the administration area.
@example
```php
$I->loginAsAdmin()ja
$I->amOnAdminPage('/');
$I->seeMessage('.missing-api-token.my-plugin');
```
@param array|string $classes A list of classes the message should have in addition to the `.notice` one. | [
"In",
"an",
"administration",
"screen",
"look",
"for",
"an",
"admin",
"notice",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowserMethods.php#L300-L306 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowserMethods.php | WPBrowserMethods.amOnAdminAjaxPage | public function amOnAdminAjaxPage($queryVars = null)
{
$path = 'admin-ajax.php';
if ($queryVars !== null) {
$path = '/' . (is_array($queryVars) ? build_query($queryVars) : ltrim($queryVars, '/'));
}
return $this->amOnAdminPage($path);
} | php | public function amOnAdminAjaxPage($queryVars = null)
{
$path = 'admin-ajax.php';
if ($queryVars !== null) {
$path = '/' . (is_array($queryVars) ? build_query($queryVars) : ltrim($queryVars, '/'));
}
return $this->amOnAdminPage($path);
} | [
"public",
"function",
"amOnAdminAjaxPage",
"(",
"$",
"queryVars",
"=",
"null",
")",
"{",
"$",
"path",
"=",
"'admin-ajax.php'",
";",
"if",
"(",
"$",
"queryVars",
"!==",
"null",
")",
"{",
"$",
"path",
"=",
"'/'",
".",
"(",
"is_array",
"(",
"$",
"queryVar... | Go to the `admin-ajax.php` page to start a synchronous, and blocking, `GET` AJAX request.
The method will **not** handle authentication, nonces or authorization.
@example
```php
$I->amOnAdminAjaxPage(['action' => 'my-action', 'data' => ['id' => 23], 'nonce' => $nonce]);
```
@param array|string $queryVars A string or array of query variables to append to the AJAX path. | [
"Go",
"to",
"the",
"admin",
"-",
"ajax",
".",
"php",
"page",
"to",
"start",
"a",
"synchronous",
"and",
"blocking",
"GET",
"AJAX",
"request",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowserMethods.php#L362-L369 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowserMethods.php | WPBrowserMethods.amOnCronPage | public function amOnCronPage($queryVars = null)
{
$path = '/wp-cron.php';
if ($queryVars !== null) {
$path = '/' . (is_array($queryVars) ? build_query($queryVars) : ltrim($queryVars, '/'));
}
return $this->amOnPage($path);
} | php | public function amOnCronPage($queryVars = null)
{
$path = '/wp-cron.php';
if ($queryVars !== null) {
$path = '/' . (is_array($queryVars) ? build_query($queryVars) : ltrim($queryVars, '/'));
}
return $this->amOnPage($path);
} | [
"public",
"function",
"amOnCronPage",
"(",
"$",
"queryVars",
"=",
"null",
")",
"{",
"$",
"path",
"=",
"'/wp-cron.php'",
";",
"if",
"(",
"$",
"queryVars",
"!==",
"null",
")",
"{",
"$",
"path",
"=",
"'/'",
".",
"(",
"is_array",
"(",
"$",
"queryVars",
"... | Go to the cron page to start a synchronous, and blocking, `GET` request to the cron script.
@example
```php
// Triggers the cron job with an optional query argument.
$I->amOnCronPage('/?some-query-var=some-value');
```
@param array|string $queryVars A string or array of query variables to append to the AJAX path. | [
"Go",
"to",
"the",
"cron",
"page",
"to",
"start",
"a",
"synchronous",
"and",
"blocking",
"GET",
"request",
"to",
"the",
"cron",
"script",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowserMethods.php#L382-L389 | train |
lucatume/wp-browser | src/Codeception/Module/WPBrowserMethods.php | WPBrowserMethods.amEditingPostWithId | public function amEditingPostWithId($id)
{
if (!is_numeric($id) && intval($id) == $id) {
throw new \InvalidArgumentException('ID must be an int value');
}
$this->amOnAdminPage('/post.php?post=' . $id . '&action=edit');
} | php | public function amEditingPostWithId($id)
{
if (!is_numeric($id) && intval($id) == $id) {
throw new \InvalidArgumentException('ID must be an int value');
}
$this->amOnAdminPage('/post.php?post=' . $id . '&action=edit');
} | [
"public",
"function",
"amEditingPostWithId",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"id",
")",
"&&",
"intval",
"(",
"$",
"id",
")",
"==",
"$",
"id",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'ID must b... | Go to the admin page to edit the post with the specified ID.
The method will **not** handle authentication the admin area.
@example
```php
$I->loginAsAdmin();
$postId = $I->havePostInDatabase();
$I->amEditingPostWithId($postId);
$I->fillField('post_title', 'Post title');
```
@param int $id The post ID. | [
"Go",
"to",
"the",
"admin",
"page",
"to",
"edit",
"the",
"post",
"with",
"the",
"specified",
"ID",
"."
] | 1bf32090a0ab97385a6cf654643967c4abf30c7d | https://github.com/lucatume/wp-browser/blob/1bf32090a0ab97385a6cf654643967c4abf30c7d/src/Codeception/Module/WPBrowserMethods.php#L406-L413 | train |
chrisboulton/php-resque-scheduler | lib/ResqueScheduler.php | ResqueScheduler.removeDelayed | public static function removeDelayed($queue, $class, $args)
{
$destroyed=0;
$item=json_encode(self::jobToHash($queue, $class, $args));
$redis=Resque::redis();
foreach($redis->keys('delayed:*') as $key)
{
$key=$redis->removePrefix($key);
$destroyed+=$redis->lrem($key,0,$item);
}
return $destroyed;
} | php | public static function removeDelayed($queue, $class, $args)
{
$destroyed=0;
$item=json_encode(self::jobToHash($queue, $class, $args));
$redis=Resque::redis();
foreach($redis->keys('delayed:*') as $key)
{
$key=$redis->removePrefix($key);
$destroyed+=$redis->lrem($key,0,$item);
}
return $destroyed;
} | [
"public",
"static",
"function",
"removeDelayed",
"(",
"$",
"queue",
",",
"$",
"class",
",",
"$",
"args",
")",
"{",
"$",
"destroyed",
"=",
"0",
";",
"$",
"item",
"=",
"json_encode",
"(",
"self",
"::",
"jobToHash",
"(",
"$",
"queue",
",",
"$",
"class",... | Remove a delayed job from the queue
note: you must specify exactly the same
queue, class and arguments that you used when you added
to the delayed queue
also, this is an expensive operation because all delayed keys have tobe
searched
@param $queue
@param $class
@param $args
@return int number of jobs that were removed | [
"Remove",
"a",
"delayed",
"job",
"from",
"the",
"queue"
] | 5954c989026f1bbc6443c02078a655333e152242 | https://github.com/chrisboulton/php-resque-scheduler/blob/5954c989026f1bbc6443c02078a655333e152242/lib/ResqueScheduler.php#L109-L122 | train |
chrisboulton/php-resque-scheduler | lib/ResqueScheduler/Worker.php | ResqueScheduler_Worker.handleDelayedItems | public function handleDelayedItems($timestamp = null)
{
while (($oldestJobTimestamp = ResqueScheduler::nextDelayedTimestamp($timestamp)) !== false) {
$this->updateProcLine('Processing Delayed Items');
$this->enqueueDelayedItemsForTimestamp($oldestJobTimestamp);
}
} | php | public function handleDelayedItems($timestamp = null)
{
while (($oldestJobTimestamp = ResqueScheduler::nextDelayedTimestamp($timestamp)) !== false) {
$this->updateProcLine('Processing Delayed Items');
$this->enqueueDelayedItemsForTimestamp($oldestJobTimestamp);
}
} | [
"public",
"function",
"handleDelayedItems",
"(",
"$",
"timestamp",
"=",
"null",
")",
"{",
"while",
"(",
"(",
"$",
"oldestJobTimestamp",
"=",
"ResqueScheduler",
"::",
"nextDelayedTimestamp",
"(",
"$",
"timestamp",
")",
")",
"!==",
"false",
")",
"{",
"$",
"thi... | Handle delayed items for the next scheduled timestamp.
Searches for any items that are due to be scheduled in Resque
and adds them to the appropriate job queue in Resque.
@param DateTime|int $timestamp Search for any items up to this timestamp to schedule. | [
"Handle",
"delayed",
"items",
"for",
"the",
"next",
"scheduled",
"timestamp",
"."
] | 5954c989026f1bbc6443c02078a655333e152242 | https://github.com/chrisboulton/php-resque-scheduler/blob/5954c989026f1bbc6443c02078a655333e152242/lib/ResqueScheduler/Worker.php#L56-L62 | train |
gstt/laravel-achievements | src/EntityRelationsAchievements.php | EntityRelationsAchievements.achievementStatus | public function achievementStatus(Achievement $achievement)
{
return $this->achievements()->where('achievement_id', $achievement->getModel()->id)->first();
} | php | public function achievementStatus(Achievement $achievement)
{
return $this->achievements()->where('achievement_id', $achievement->getModel()->id)->first();
} | [
"public",
"function",
"achievementStatus",
"(",
"Achievement",
"$",
"achievement",
")",
"{",
"return",
"$",
"this",
"->",
"achievements",
"(",
")",
"->",
"where",
"(",
"'achievement_id'",
",",
"$",
"achievement",
"->",
"getModel",
"(",
")",
"->",
"id",
")",
... | Retrieves the status for the specified achievement
@param Achievement $achievement
@return AchievementProgress | [
"Retrieves",
"the",
"status",
"for",
"the",
"specified",
"achievement"
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/EntityRelationsAchievements.php#L37-L40 | train |
gstt/laravel-achievements | src/EntityRelationsAchievements.php | EntityRelationsAchievements.hasUnlocked | public function hasUnlocked(Achievement $achievement)
{
$status = $this->achievementStatus($achievement);
if (is_null($status) || is_null($status->unlocked_at)) {
return false;
}
return true;
} | php | public function hasUnlocked(Achievement $achievement)
{
$status = $this->achievementStatus($achievement);
if (is_null($status) || is_null($status->unlocked_at)) {
return false;
}
return true;
} | [
"public",
"function",
"hasUnlocked",
"(",
"Achievement",
"$",
"achievement",
")",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"achievementStatus",
"(",
"$",
"achievement",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"status",
")",
"||",
"is_null",
"(",
"$"... | Return true if the user has unlocked this achievement, false otherwise.
@param Achievement $achievement
@return bool | [
"Return",
"true",
"if",
"the",
"user",
"has",
"unlocked",
"this",
"achievement",
"false",
"otherwise",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/EntityRelationsAchievements.php#L47-L54 | train |
gstt/laravel-achievements | src/EntityRelationsAchievements.php | EntityRelationsAchievements.lockedAchievements | public function lockedAchievements()
{
if (config('achievements.locked_sync')) {
// Relationships should be synced. Just return relationship data.
return $this->achievements()->whereNull('unlocked_at')->get();
} else {
// Query all unsynced
$unsynced = AchievementDetails::getUnsyncedByAchiever($this)->get();
$self = $this;
$unsynced = $unsynced->map(function ($el) use ($self) {
$progress = new AchievementProgress();
$progress->details()->associate($el);
$progress->achiever()->associate($this);
$progress->points = 0;
$progress->created_at = null;
$progress->updated_at = null;
return $progress;
});
// Merge with progressed, but not yet unlocked
$lockedProgressed = $this->achievements()->whereNull('unlocked_at')->get();
$locked = $lockedProgressed->merge($unsynced);
return $locked;
}
} | php | public function lockedAchievements()
{
if (config('achievements.locked_sync')) {
// Relationships should be synced. Just return relationship data.
return $this->achievements()->whereNull('unlocked_at')->get();
} else {
// Query all unsynced
$unsynced = AchievementDetails::getUnsyncedByAchiever($this)->get();
$self = $this;
$unsynced = $unsynced->map(function ($el) use ($self) {
$progress = new AchievementProgress();
$progress->details()->associate($el);
$progress->achiever()->associate($this);
$progress->points = 0;
$progress->created_at = null;
$progress->updated_at = null;
return $progress;
});
// Merge with progressed, but not yet unlocked
$lockedProgressed = $this->achievements()->whereNull('unlocked_at')->get();
$locked = $lockedProgressed->merge($unsynced);
return $locked;
}
} | [
"public",
"function",
"lockedAchievements",
"(",
")",
"{",
"if",
"(",
"config",
"(",
"'achievements.locked_sync'",
")",
")",
"{",
"// Relationships should be synced. Just return relationship data.",
"return",
"$",
"this",
"->",
"achievements",
"(",
")",
"->",
"whereNull... | Get the entity's locked achievements. | [
"Get",
"the",
"entity",
"s",
"locked",
"achievements",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/EntityRelationsAchievements.php#L79-L104 | train |
gstt/laravel-achievements | src/EntityRelationsAchievements.php | EntityRelationsAchievements.syncAchievements | public function syncAchievements()
{
/** @var Collection $locked */
$locked = AchievementDetails::getUnsyncedByAchiever($this);
$self = $this;
$locked->each(function ($el) use ($self) {
$progress = new AchievementProgress();
$progress->details()->associate($el);
$progress->achiever()->associate($this);
$progress->points = 0;
$progress->save();
});
} | php | public function syncAchievements()
{
/** @var Collection $locked */
$locked = AchievementDetails::getUnsyncedByAchiever($this);
$self = $this;
$locked->each(function ($el) use ($self) {
$progress = new AchievementProgress();
$progress->details()->associate($el);
$progress->achiever()->associate($this);
$progress->points = 0;
$progress->save();
});
} | [
"public",
"function",
"syncAchievements",
"(",
")",
"{",
"/** @var Collection $locked */",
"$",
"locked",
"=",
"AchievementDetails",
"::",
"getUnsyncedByAchiever",
"(",
"$",
"this",
")",
";",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"locked",
"->",
"each",
"("... | Syncs achievement data. | [
"Syncs",
"achievement",
"data",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/EntityRelationsAchievements.php#L109-L121 | train |
gstt/laravel-achievements | src/Model/AchievementDetails.php | AchievementDetails.getUnsyncedByAchiever | public static function getUnsyncedByAchiever($achiever)
{
$className = (new static)->getAchieverClassName($achiever);
$achievements = AchievementProgress::where('achiever_type', $className)
->where('achiever_id', $achiever->id)->get();
$synced_ids = $achievements->map(function ($el) {
return $el->achievement_id;
})->toArray();
return self::whereNotIn('id', $synced_ids);
} | php | public static function getUnsyncedByAchiever($achiever)
{
$className = (new static)->getAchieverClassName($achiever);
$achievements = AchievementProgress::where('achiever_type', $className)
->where('achiever_id', $achiever->id)->get();
$synced_ids = $achievements->map(function ($el) {
return $el->achievement_id;
})->toArray();
return self::whereNotIn('id', $synced_ids);
} | [
"public",
"static",
"function",
"getUnsyncedByAchiever",
"(",
"$",
"achiever",
")",
"{",
"$",
"className",
"=",
"(",
"new",
"static",
")",
"->",
"getAchieverClassName",
"(",
"$",
"achiever",
")",
";",
"$",
"achievements",
"=",
"AchievementProgress",
"::",
"whe... | Gets all AchievementDetails that have no correspondence on the Progress table.
@param \Illuminate\Database\Eloquent\Model $achiever | [
"Gets",
"all",
"AchievementDetails",
"that",
"have",
"no",
"correspondence",
"on",
"the",
"Progress",
"table",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/Model/AchievementDetails.php#L62-L73 | train |
gstt/laravel-achievements | src/Model/AchievementDetails.php | AchievementDetails.getAchieverClassName | protected function getAchieverClassName($achiever)
{
if ($achiever instanceof \Illuminate\Database\Eloquent\Model) {
return $achiever->getMorphClass();
}
return get_class($achiever);
} | php | protected function getAchieverClassName($achiever)
{
if ($achiever instanceof \Illuminate\Database\Eloquent\Model) {
return $achiever->getMorphClass();
}
return get_class($achiever);
} | [
"protected",
"function",
"getAchieverClassName",
"(",
"$",
"achiever",
")",
"{",
"if",
"(",
"$",
"achiever",
"instanceof",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Model",
")",
"{",
"return",
"$",
"achiever",
"->",
"getMorphClass",
"(",
... | Gets model morph name
@param \Illuminate\Database\Eloquent\Model $achiever
@return string | [
"Gets",
"model",
"morph",
"name"
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/Model/AchievementDetails.php#L81-L88 | train |
gstt/laravel-achievements | src/Achievement.php | Achievement.getModel | public function getModel()
{
if(!is_null($this->modelAttr)){
return $this->modelAttr;
}
$model = AchievementDetails::where('class_name', $this->getClassName())->first();
if (is_null($model)) {
$model = new AchievementDetails();
$model->class_name = $this->getClassName();
}
if(config('achievements.auto_sync') || is_null($model->name)) {
$model->name = $this->name;
$model->description = $this->description;
$model->points = $this->points;
$model->secret = $this->secret;
// Syncs
$model->save();
}
$this->modelAttr = $model;
return $model;
} | php | public function getModel()
{
if(!is_null($this->modelAttr)){
return $this->modelAttr;
}
$model = AchievementDetails::where('class_name', $this->getClassName())->first();
if (is_null($model)) {
$model = new AchievementDetails();
$model->class_name = $this->getClassName();
}
if(config('achievements.auto_sync') || is_null($model->name)) {
$model->name = $this->name;
$model->description = $this->description;
$model->points = $this->points;
$model->secret = $this->secret;
// Syncs
$model->save();
}
$this->modelAttr = $model;
return $model;
} | [
"public",
"function",
"getModel",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"modelAttr",
")",
")",
"{",
"return",
"$",
"this",
"->",
"modelAttr",
";",
"}",
"$",
"model",
"=",
"AchievementDetails",
"::",
"where",
"(",
"'class_nam... | Gets the details class for this achievement.
@return AchievementDetails | [
"Gets",
"the",
"details",
"class",
"for",
"this",
"achievement",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/Achievement.php#L88-L113 | train |
gstt/laravel-achievements | src/Achievement.php | Achievement.addProgressToAchiever | public function addProgressToAchiever($achiever, $points = 1)
{
$progress = $this->getOrCreateProgressForAchiever($achiever);
if (!$progress->isUnlocked()) {
$progress->points = $progress->points + $points;
$progress->save();
}
} | php | public function addProgressToAchiever($achiever, $points = 1)
{
$progress = $this->getOrCreateProgressForAchiever($achiever);
if (!$progress->isUnlocked()) {
$progress->points = $progress->points + $points;
$progress->save();
}
} | [
"public",
"function",
"addProgressToAchiever",
"(",
"$",
"achiever",
",",
"$",
"points",
"=",
"1",
")",
"{",
"$",
"progress",
"=",
"$",
"this",
"->",
"getOrCreateProgressForAchiever",
"(",
"$",
"achiever",
")",
";",
"if",
"(",
"!",
"$",
"progress",
"->",
... | Adds a specified amount of points to the achievement.
@param mixed $achiever The entity that will add progress to this achievement
@param int $points The amount of points to be added to this achievement | [
"Adds",
"a",
"specified",
"amount",
"of",
"points",
"to",
"the",
"achievement",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/Achievement.php#L121-L128 | train |
gstt/laravel-achievements | src/Achievement.php | Achievement.setProgressToAchiever | public function setProgressToAchiever($achiever, $points)
{
$progress = $this->getOrCreateProgressForAchiever($achiever);
if (!$progress->isUnlocked()) {
$progress->points = $points;
$progress->save();
}
} | php | public function setProgressToAchiever($achiever, $points)
{
$progress = $this->getOrCreateProgressForAchiever($achiever);
if (!$progress->isUnlocked()) {
$progress->points = $points;
$progress->save();
}
} | [
"public",
"function",
"setProgressToAchiever",
"(",
"$",
"achiever",
",",
"$",
"points",
")",
"{",
"$",
"progress",
"=",
"$",
"this",
"->",
"getOrCreateProgressForAchiever",
"(",
"$",
"achiever",
")",
";",
"if",
"(",
"!",
"$",
"progress",
"->",
"isUnlocked",... | Sets a specified amount of points to the achievement.
@param mixed $achiever The entity that will add progress to this achievement
@param int $points The amount of points to be added to this achievement | [
"Sets",
"a",
"specified",
"amount",
"of",
"points",
"to",
"the",
"achievement",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/Achievement.php#L136-L144 | train |
gstt/laravel-achievements | src/Model/AchievementProgress.php | AchievementProgress.isUnlocked | public function isUnlocked()
{
if (!is_null($this->unlockedAt)) {
return true;
}
if ($this->points >= $this->details->points) {
return true;
}
return false;
} | php | public function isUnlocked()
{
if (!is_null($this->unlockedAt)) {
return true;
}
if ($this->points >= $this->details->points) {
return true;
}
return false;
} | [
"public",
"function",
"isUnlocked",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"unlockedAt",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"points",
">=",
"$",
"this",
"->",
"details",
"->",
"points... | Checks if the achievement has been unlocked.
@return bool | [
"Checks",
"if",
"the",
"achievement",
"has",
"been",
"unlocked",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/Model/AchievementProgress.php#L80-L89 | train |
gstt/laravel-achievements | src/Model/AchievementProgress.php | AchievementProgress.save | public function save(array $options = [])
{
if (is_null($this->id)) {
$this->id = Uuid::uuid4()->toString();
}
$recently_unlocked = false;
if (is_null($this->unlockedAt) && $this->isUnlocked()) {
$recently_unlocked = true;
$this->points = $this->details->points;
$this->unlocked_at = Carbon::now();
}
$result = parent::save($options);
// Gets the achievement class for this progress
$class = $this->details->getClass();
if ($recently_unlocked) {
// Runs the callback set to run when the achievement is unlocked.
$class->triggerUnlocked($this);
} elseif ($this->points >= 0) {
// Runs the callback set to run when progress has been made on the achievement.
$class->triggerProgress($this);
}
return $result;
} | php | public function save(array $options = [])
{
if (is_null($this->id)) {
$this->id = Uuid::uuid4()->toString();
}
$recently_unlocked = false;
if (is_null($this->unlockedAt) && $this->isUnlocked()) {
$recently_unlocked = true;
$this->points = $this->details->points;
$this->unlocked_at = Carbon::now();
}
$result = parent::save($options);
// Gets the achievement class for this progress
$class = $this->details->getClass();
if ($recently_unlocked) {
// Runs the callback set to run when the achievement is unlocked.
$class->triggerUnlocked($this);
} elseif ($this->points >= 0) {
// Runs the callback set to run when progress has been made on the achievement.
$class->triggerProgress($this);
}
return $result;
} | [
"public",
"function",
"save",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"id",
")",
")",
"{",
"$",
"this",
"->",
"id",
"=",
"Uuid",
"::",
"uuid4",
"(",
")",
"->",
"toString",
"(",
")",
... | Overloads save method.
@param array $options
@return bool | [
"Overloads",
"save",
"method",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/Model/AchievementProgress.php#L107-L133 | train |
gstt/laravel-achievements | src/AchievementChain.php | AchievementChain.highestOnChain | public function highestOnChain($achiever)
{
$latestUnlocked = null;
foreach($this->chain() as $instance) {
/** @var Achievement $instance */
/** @var Achiever $achiever */
if($achiever->hasUnlocked($instance)){
$latestUnlocked = $achiever->achievementStatus($instance);
} else {
return $latestUnlocked;
}
}
return $latestUnlocked;
} | php | public function highestOnChain($achiever)
{
$latestUnlocked = null;
foreach($this->chain() as $instance) {
/** @var Achievement $instance */
/** @var Achiever $achiever */
if($achiever->hasUnlocked($instance)){
$latestUnlocked = $achiever->achievementStatus($instance);
} else {
return $latestUnlocked;
}
}
return $latestUnlocked;
} | [
"public",
"function",
"highestOnChain",
"(",
"$",
"achiever",
")",
"{",
"$",
"latestUnlocked",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"chain",
"(",
")",
"as",
"$",
"instance",
")",
"{",
"/** @var Achievement $instance */",
"/** @var Achiever $achie... | For an Achiever, return the highest achievement on the chain that is unlocked.
@param $achiever
@return null|AchievementProgress | [
"For",
"an",
"Achiever",
"return",
"the",
"highest",
"achievement",
"on",
"the",
"chain",
"that",
"is",
"unlocked",
"."
] | 04f32660d502ef7b2a24a9a65ecbd7abbacc29ef | https://github.com/gstt/laravel-achievements/blob/04f32660d502ef7b2a24a9a65ecbd7abbacc29ef/src/AchievementChain.php#L25-L38 | train |
thephpleague/climate | src/Argument/Parser.php | Parser.removeTrailingArguments | protected function removeTrailingArguments(array $arguments)
{
$trailing = array_splice($arguments, array_search('--', $arguments));
array_shift($trailing);
$this->trailing = implode(' ', $trailing);
return $arguments;
} | php | protected function removeTrailingArguments(array $arguments)
{
$trailing = array_splice($arguments, array_search('--', $arguments));
array_shift($trailing);
$this->trailing = implode(' ', $trailing);
return $arguments;
} | [
"protected",
"function",
"removeTrailingArguments",
"(",
"array",
"$",
"arguments",
")",
"{",
"$",
"trailing",
"=",
"array_splice",
"(",
"$",
"arguments",
",",
"array_search",
"(",
"'--'",
",",
"$",
"arguments",
")",
")",
";",
"array_shift",
"(",
"$",
"trail... | Remove the trailing arguments from the parser and set them aside
@param array $arguments
@return array | [
"Remove",
"the",
"trailing",
"arguments",
"from",
"the",
"parser",
"and",
"set",
"them",
"aside"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Parser.php#L117-L124 | train |
thephpleague/climate | src/Argument/Parser.php | Parser.prefixedArguments | protected function prefixedArguments(array $argv = [])
{
foreach ($argv as $key => $passed_argument) {
$argv = $this->trySettingArgumentValue($argv, $key, $passed_argument);
}
// Send un-parsed arguments back upstream.
return array_values($argv);
} | php | protected function prefixedArguments(array $argv = [])
{
foreach ($argv as $key => $passed_argument) {
$argv = $this->trySettingArgumentValue($argv, $key, $passed_argument);
}
// Send un-parsed arguments back upstream.
return array_values($argv);
} | [
"protected",
"function",
"prefixedArguments",
"(",
"array",
"$",
"argv",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"argv",
"as",
"$",
"key",
"=>",
"$",
"passed_argument",
")",
"{",
"$",
"argv",
"=",
"$",
"this",
"->",
"trySettingArgumentValue",
"(",
... | Parse command line options into prefixed CLImate arguments.
Prefixed arguments are arguments with a prefix (-) or a long prefix (--)
on the command line.
Return the arguments passed on the command line that didn't match up with
prefixed arguments so they can be assigned to non-prefixed arguments.
@param array $argv
@return array | [
"Parse",
"command",
"line",
"options",
"into",
"prefixed",
"CLImate",
"arguments",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Parser.php#L138-L146 | train |
thephpleague/climate | src/Argument/Parser.php | Parser.nonPrefixedArguments | protected function nonPrefixedArguments(array $unParsedArguments = [])
{
foreach ($this->filter->withoutPrefix() as $key => $argument) {
if (isset($unParsedArguments[$key])) {
$argument->setValue($unParsedArguments[$key]);
}
}
} | php | protected function nonPrefixedArguments(array $unParsedArguments = [])
{
foreach ($this->filter->withoutPrefix() as $key => $argument) {
if (isset($unParsedArguments[$key])) {
$argument->setValue($unParsedArguments[$key]);
}
}
} | [
"protected",
"function",
"nonPrefixedArguments",
"(",
"array",
"$",
"unParsedArguments",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filter",
"->",
"withoutPrefix",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"argument",
")",
"{",
"if",
"(",
... | Parse unset command line options into non-prefixed CLImate arguments.
Non-prefixed arguments are parsed after the prefixed arguments on the
command line, in the order that they're defined in the script.
@param array $unParsedArguments | [
"Parse",
"unset",
"command",
"line",
"options",
"into",
"non",
"-",
"prefixed",
"CLImate",
"arguments",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Parser.php#L156-L163 | train |
thephpleague/climate | src/Argument/Parser.php | Parser.trySettingArgumentValue | protected function trySettingArgumentValue($argv, $key, $passed_argument)
{
list($name, $value) = $this->getNameAndValue($passed_argument);
// Look for the argument in our defined $arguments
// and assign their value.
if (!($argument = $this->findPrefixedArgument($name))) {
return $argv;
}
// We found an argument key, so take it out of the array.
unset($argv[$key]);
return $this->setArgumentValue($argv, $argument, $key, $value);
} | php | protected function trySettingArgumentValue($argv, $key, $passed_argument)
{
list($name, $value) = $this->getNameAndValue($passed_argument);
// Look for the argument in our defined $arguments
// and assign their value.
if (!($argument = $this->findPrefixedArgument($name))) {
return $argv;
}
// We found an argument key, so take it out of the array.
unset($argv[$key]);
return $this->setArgumentValue($argv, $argument, $key, $value);
} | [
"protected",
"function",
"trySettingArgumentValue",
"(",
"$",
"argv",
",",
"$",
"key",
",",
"$",
"passed_argument",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"$",
"this",
"->",
"getNameAndValue",
"(",
"$",
"passed_argument",
")",
"... | Attempt to set the an argument's value and remove applicable
arguments from array
@param array $argv
@param int $key
@param string $passed_argument
@return array The new $argv | [
"Attempt",
"to",
"set",
"the",
"an",
"argument",
"s",
"value",
"and",
"remove",
"applicable",
"arguments",
"from",
"array"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Parser.php#L194-L208 | train |
thephpleague/climate | src/Argument/Parser.php | Parser.setArgumentValue | protected function setArgumentValue($argv, $argument, $key, $value)
{
// Arguments are given the value true if they only need to
// be defined on the command line to be set.
if ($argument->noValue()) {
$argument->setValue(true);
return $argv;
}
if (is_null($value)) {
if (count($argv) === 0) {
return $argv;
}
// If the value wasn't previously defined in "key=value"
// format then define it from the next command argument.
$nextArgvValue = $argv[$key + 1];
if ($this->isValidArgumentValue($nextArgvValue)) {
$argument->setValue($nextArgvValue);
unset($argv[$key + 1]);
return $argv;
}
}
$argument->setValue($value);
return $argv;
} | php | protected function setArgumentValue($argv, $argument, $key, $value)
{
// Arguments are given the value true if they only need to
// be defined on the command line to be set.
if ($argument->noValue()) {
$argument->setValue(true);
return $argv;
}
if (is_null($value)) {
if (count($argv) === 0) {
return $argv;
}
// If the value wasn't previously defined in "key=value"
// format then define it from the next command argument.
$nextArgvValue = $argv[$key + 1];
if ($this->isValidArgumentValue($nextArgvValue)) {
$argument->setValue($nextArgvValue);
unset($argv[$key + 1]);
return $argv;
}
}
$argument->setValue($value);
return $argv;
} | [
"protected",
"function",
"setArgumentValue",
"(",
"$",
"argv",
",",
"$",
"argument",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"// Arguments are given the value true if they only need to",
"// be defined on the command line to be set.",
"if",
"(",
"$",
"argument",
"... | Set the argument's value
@param array $argv
@param Argument $argument
@param int $key
@param string|null $value
@return array The new $argv | [
"Set",
"the",
"argument",
"s",
"value"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Parser.php#L220-L247 | train |
thephpleague/climate | src/Argument/Parser.php | Parser.findPrefixedArgument | protected function findPrefixedArgument($name)
{
foreach ($this->filter->withPrefix() as $argument) {
if (in_array($name, ["-{$argument->prefix()}", "--{$argument->longPrefix()}"])) {
return $argument;
}
}
return false;
} | php | protected function findPrefixedArgument($name)
{
foreach ($this->filter->withPrefix() as $argument) {
if (in_array($name, ["-{$argument->prefix()}", "--{$argument->longPrefix()}"])) {
return $argument;
}
}
return false;
} | [
"protected",
"function",
"findPrefixedArgument",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filter",
"->",
"withPrefix",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"[",
"\"-{$argument->pr... | Search for argument in defined prefix arguments
@param string $name
@return Argument|false | [
"Search",
"for",
"argument",
"in",
"defined",
"prefix",
"arguments"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Parser.php#L267-L276 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Input.php | Input.accept | public function accept($acceptable, $show = false)
{
$this->acceptable = $acceptable;
$this->show_acceptable = $show;
return $this;
} | php | public function accept($acceptable, $show = false)
{
$this->acceptable = $acceptable;
$this->show_acceptable = $show;
return $this;
} | [
"public",
"function",
"accept",
"(",
"$",
"acceptable",
",",
"$",
"show",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"acceptable",
"=",
"$",
"acceptable",
";",
"$",
"this",
"->",
"show_acceptable",
"=",
"$",
"show",
";",
"return",
"$",
"this",
";",
"... | Define the acceptable responses and whether or not to
display them to the user
@param array|object $acceptable
@param boolean $show
@return \League\CLImate\TerminalObject\Dynamic\Input | [
"Define",
"the",
"acceptable",
"responses",
"and",
"whether",
"or",
"not",
"to",
"display",
"them",
"to",
"the",
"user"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Input.php#L81-L87 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Input.php | Input.writePrompt | protected function writePrompt()
{
$prompt = $this->parser->apply($this->promptFormatted());
$this->output->sameLine()->write($prompt);
} | php | protected function writePrompt()
{
$prompt = $this->parser->apply($this->promptFormatted());
$this->output->sameLine()->write($prompt);
} | [
"protected",
"function",
"writePrompt",
"(",
")",
"{",
"$",
"prompt",
"=",
"$",
"this",
"->",
"parser",
"->",
"apply",
"(",
"$",
"this",
"->",
"promptFormatted",
"(",
")",
")",
";",
"$",
"this",
"->",
"output",
"->",
"sameLine",
"(",
")",
"->",
"writ... | Write out the formatted prompt | [
"Write",
"out",
"the",
"formatted",
"prompt"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Input.php#L142-L147 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Input.php | Input.acceptableFormatted | protected function acceptableFormatted()
{
if (!is_array($this->acceptable)) {
return '';
}
$acceptable = array_map([$this, 'acceptableItemFormatted'], $this->acceptable);
return '[' . implode('/', $acceptable) . ']';
} | php | protected function acceptableFormatted()
{
if (!is_array($this->acceptable)) {
return '';
}
$acceptable = array_map([$this, 'acceptableItemFormatted'], $this->acceptable);
return '[' . implode('/', $acceptable) . ']';
} | [
"protected",
"function",
"acceptableFormatted",
"(",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"acceptable",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"acceptable",
"=",
"array_map",
"(",
"[",
"$",
"this",
",",
"'acceptableItemFor... | Format the acceptable responses as options
@return string | [
"Format",
"the",
"acceptable",
"responses",
"as",
"options"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Input.php#L171-L180 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Input.php | Input.promptFormatted | protected function promptFormatted()
{
$prompt = $this->prompt . ' ';
if ($this->show_acceptable) {
$prompt .= $this->acceptableFormatted() . ' ';
}
return $prompt;
} | php | protected function promptFormatted()
{
$prompt = $this->prompt . ' ';
if ($this->show_acceptable) {
$prompt .= $this->acceptableFormatted() . ' ';
}
return $prompt;
} | [
"protected",
"function",
"promptFormatted",
"(",
")",
"{",
"$",
"prompt",
"=",
"$",
"this",
"->",
"prompt",
".",
"' '",
";",
"if",
"(",
"$",
"this",
"->",
"show_acceptable",
")",
"{",
"$",
"prompt",
".=",
"$",
"this",
"->",
"acceptableFormatted",
"(",
... | Format the prompt incorporating spacing and any acceptable options
@return string | [
"Format",
"the",
"prompt",
"incorporating",
"spacing",
"and",
"any",
"acceptable",
"options"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Input.php#L203-L212 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Input.php | Input.isAcceptableResponse | protected function isAcceptableResponse($response)
{
if ($this->strict) {
return in_array($response, $this->acceptable);
}
$acceptable = $this->levelPlayingField($this->acceptable);
$response = $this->levelPlayingField($response);
return in_array($response, $acceptable);
} | php | protected function isAcceptableResponse($response)
{
if ($this->strict) {
return in_array($response, $this->acceptable);
}
$acceptable = $this->levelPlayingField($this->acceptable);
$response = $this->levelPlayingField($response);
return in_array($response, $acceptable);
} | [
"protected",
"function",
"isAcceptableResponse",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"strict",
")",
"{",
"return",
"in_array",
"(",
"$",
"response",
",",
"$",
"this",
"->",
"acceptable",
")",
";",
"}",
"$",
"acceptable",
"=",
... | Determine if the user's response is in the acceptable responses array
@param string $response
@return boolean $response | [
"Determine",
"if",
"the",
"user",
"s",
"response",
"is",
"in",
"the",
"acceptable",
"responses",
"array"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Input.php#L252-L262 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Input.php | Input.isValidResponse | protected function isValidResponse($response)
{
if (empty($this->acceptable)) {
return true;
}
if ($this->acceptableIsClosure()) {
return call_user_func($this->acceptable, $response);
}
return $this->isAcceptableResponse($response);
} | php | protected function isValidResponse($response)
{
if (empty($this->acceptable)) {
return true;
}
if ($this->acceptableIsClosure()) {
return call_user_func($this->acceptable, $response);
}
return $this->isAcceptableResponse($response);
} | [
"protected",
"function",
"isValidResponse",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"acceptable",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"acceptableIsClosure",
"(",
")",
")",
"{",
... | Determine if the user's response is valid based on the current settings
@param string $response
@return boolean $response | [
"Determine",
"if",
"the",
"user",
"s",
"response",
"is",
"valid",
"based",
"on",
"the",
"current",
"settings"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Input.php#L271-L282 | train |
thephpleague/climate | src/Argument/Argument.php | Argument.createFromArray | public static function createFromArray($name, array $params)
{
$argument = new Argument($name);
$params = self::getSettableArgumentParams($params);
foreach ($params as $key => $value) {
$method = 'set' . ucwords($key);
$argument->{$method}($value);
}
return $argument;
} | php | public static function createFromArray($name, array $params)
{
$argument = new Argument($name);
$params = self::getSettableArgumentParams($params);
foreach ($params as $key => $value) {
$method = 'set' . ucwords($key);
$argument->{$method}($value);
}
return $argument;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"$",
"name",
",",
"array",
"$",
"params",
")",
"{",
"$",
"argument",
"=",
"new",
"Argument",
"(",
"$",
"name",
")",
";",
"$",
"params",
"=",
"self",
"::",
"getSettableArgumentParams",
"(",
"$",
"par... | Build a new command argument from an array.
@param string $name
@param array $params
@return Argument | [
"Build",
"a",
"new",
"command",
"argument",
"from",
"an",
"array",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Argument.php#L98-L109 | train |
thephpleague/climate | src/Argument/Argument.php | Argument.setCastTo | protected function setCastTo($castTo)
{
if (!in_array($castTo, ['string', 'int', 'float', 'bool'])) {
throw new UnexpectedValueException(
"An argument may only be cast to the data type "
. "'string', 'int', 'float', or 'bool'."
);
}
$this->castTo = $this->noValue() ? 'bool' : $castTo;
} | php | protected function setCastTo($castTo)
{
if (!in_array($castTo, ['string', 'int', 'float', 'bool'])) {
throw new UnexpectedValueException(
"An argument may only be cast to the data type "
. "'string', 'int', 'float', or 'bool'."
);
}
$this->castTo = $this->noValue() ? 'bool' : $castTo;
} | [
"protected",
"function",
"setCastTo",
"(",
"$",
"castTo",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"castTo",
",",
"[",
"'string'",
",",
"'int'",
",",
"'float'",
",",
"'bool'",
"]",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
... | Set the data type to cast an argument's value to.
Valid data types are "string", "int", "float", and "bool".
@param string $castTo
@return void
@throws UnexpectedValueException if $castTo is not a valid data type. | [
"Set",
"the",
"data",
"type",
"to",
"cast",
"an",
"argument",
"s",
"value",
"to",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Argument.php#L289-L299 | train |
thephpleague/climate | src/Argument/Argument.php | Argument.value | public function value()
{
if ($this->values) {
return end($this->values);
}
$cast_method = 'castTo' . ucwords($this->castTo);
return $this->{$cast_method}(current($this->defaultValue()));
} | php | public function value()
{
if ($this->values) {
return end($this->values);
}
$cast_method = 'castTo' . ucwords($this->castTo);
return $this->{$cast_method}(current($this->defaultValue()));
} | [
"public",
"function",
"value",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"values",
")",
"{",
"return",
"end",
"(",
"$",
"this",
"->",
"values",
")",
";",
"}",
"$",
"cast_method",
"=",
"'castTo'",
".",
"ucwords",
"(",
"$",
"this",
"->",
"castTo",... | Retrieve an argument's value.
Argument values are type cast based on the value of $castTo.
@return string|int|float|bool | [
"Retrieve",
"an",
"argument",
"s",
"value",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Argument.php#L331-L338 | train |
thephpleague/climate | src/Argument/Argument.php | Argument.values | public function values()
{
if ($this->values) {
return $this->values;
}
$cast_method = 'castTo' . ucwords($this->castTo);
return array_map([$this, $cast_method], $this->defaultValue());
} | php | public function values()
{
if ($this->values) {
return $this->values;
}
$cast_method = 'castTo' . ucwords($this->castTo);
return array_map([$this, $cast_method], $this->defaultValue());
} | [
"public",
"function",
"values",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"values",
")",
"{",
"return",
"$",
"this",
"->",
"values",
";",
"}",
"$",
"cast_method",
"=",
"'castTo'",
".",
"ucwords",
"(",
"$",
"this",
"->",
"castTo",
")",
";",
"retu... | Retrieve an argument's values.
Argument values are type cast based on the value of $castTo.
@return string[]|int[]|float[]|bool[] | [
"Retrieve",
"an",
"argument",
"s",
"values",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Argument.php#L347-L354 | train |
thephpleague/climate | src/Argument/Argument.php | Argument.setValue | public function setValue($value)
{
$cast_method = 'castTo' . ucwords($this->castTo);
$this->values[] = $this->{$cast_method}($value);
} | php | public function setValue($value)
{
$cast_method = 'castTo' . ucwords($this->castTo);
$this->values[] = $this->{$cast_method}($value);
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"$",
"cast_method",
"=",
"'castTo'",
".",
"ucwords",
"(",
"$",
"this",
"->",
"castTo",
")",
";",
"$",
"this",
"->",
"values",
"[",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"cast_method",
... | Set an argument's value based on its command line entry.
Argument values are type cast based on the value of $castTo.
@param string|bool $value | [
"Set",
"an",
"argument",
"s",
"value",
"based",
"on",
"its",
"command",
"line",
"entry",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Argument.php#L371-L375 | train |
thephpleague/climate | src/Logger.php | Logger.convertLevel | private function convertLevel($level)
{
# If this is one of the defined string log levels then return it's numeric value
if (!array_key_exists($level, $this->levels)) {
throw new InvalidArgumentException("Unknown log level: {$level}");
}
return $this->levels[$level];
} | php | private function convertLevel($level)
{
# If this is one of the defined string log levels then return it's numeric value
if (!array_key_exists($level, $this->levels)) {
throw new InvalidArgumentException("Unknown log level: {$level}");
}
return $this->levels[$level];
} | [
"private",
"function",
"convertLevel",
"(",
"$",
"level",
")",
"{",
"# If this is one of the defined string log levels then return it's numeric value",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"level",
",",
"$",
"this",
"->",
"levels",
")",
")",
"{",
"throw",
"... | Get a numeric log level for the passed parameter.
@param string $level One of the LogLevel constants
@return int | [
"Get",
"a",
"numeric",
"log",
"level",
"for",
"the",
"passed",
"parameter",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Logger.php#L85-L93 | train |
thephpleague/climate | src/Logger.php | Logger.withLogLevel | public function withLogLevel($level)
{
$logger = clone $this;
$logger->level = $this->convertLevel($level);
return $logger;
} | php | public function withLogLevel($level)
{
$logger = clone $this;
$logger->level = $this->convertLevel($level);
return $logger;
} | [
"public",
"function",
"withLogLevel",
"(",
"$",
"level",
")",
"{",
"$",
"logger",
"=",
"clone",
"$",
"this",
";",
"$",
"logger",
"->",
"level",
"=",
"$",
"this",
"->",
"convertLevel",
"(",
"$",
"level",
")",
";",
"return",
"$",
"logger",
";",
"}"
] | Get a new instance logging at a different level
@param string $level One of the LogLevel constants
@return Logger | [
"Get",
"a",
"new",
"instance",
"logging",
"at",
"a",
"different",
"level"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Logger.php#L103-L108 | train |
thephpleague/climate | src/Logger.php | Logger.log | public function log($level, $message, array $context = [])
{
if ($this->convertLevel($level) > $this->level) {
return;
}
# Handle objects implementing __toString
$message = (string)$message;
# Handle any placeholders in the $context array
foreach ($context as $key => $val) {
$placeholder = "{" . $key . "}";
# If this context key is used as a placeholder, then replace it, and remove it from the $context array
if (strpos($message, $placeholder) !== false) {
$val = (string)$val;
$message = str_replace($placeholder, $val, $message);
unset($context[$key]);
}
}
# Send the message to the climate instance
$this->climate->{$level}($message);
# Append any context information not used as placeholders
$this->outputRecursiveContext($level, $context, 1);
} | php | public function log($level, $message, array $context = [])
{
if ($this->convertLevel($level) > $this->level) {
return;
}
# Handle objects implementing __toString
$message = (string)$message;
# Handle any placeholders in the $context array
foreach ($context as $key => $val) {
$placeholder = "{" . $key . "}";
# If this context key is used as a placeholder, then replace it, and remove it from the $context array
if (strpos($message, $placeholder) !== false) {
$val = (string)$val;
$message = str_replace($placeholder, $val, $message);
unset($context[$key]);
}
}
# Send the message to the climate instance
$this->climate->{$level}($message);
# Append any context information not used as placeholders
$this->outputRecursiveContext($level, $context, 1);
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"convertLevel",
"(",
"$",
"level",
")",
">",
"$",
"this",
"->",
"level",
")",
"{",
"return",... | Log messages to a CLImate instance.
@param string $level One of the LogLevel constants
@param string|object $message If an object is passed it must implement __toString()
@param array $context Placeholders to be substituted in the message
@return void | [
"Log",
"messages",
"to",
"a",
"CLImate",
"instance",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Logger.php#L120-L146 | train |
thephpleague/climate | src/Logger.php | Logger.outputRecursiveContext | private function outputRecursiveContext($level, array $context, $indent)
{
foreach ($context as $key => $val) {
$this->climate->tab($indent);
$this->climate->{$level}()->inline("{$key}: ");
if (is_array($val)) {
$this->climate->{$level}("[");
$this->outputRecursiveContext($level, $val, $indent + 1);
$this->climate->tab($indent)->{$level}("]");
} else {
$this->climate->{$level}((string)$val);
}
}
} | php | private function outputRecursiveContext($level, array $context, $indent)
{
foreach ($context as $key => $val) {
$this->climate->tab($indent);
$this->climate->{$level}()->inline("{$key}: ");
if (is_array($val)) {
$this->climate->{$level}("[");
$this->outputRecursiveContext($level, $val, $indent + 1);
$this->climate->tab($indent)->{$level}("]");
} else {
$this->climate->{$level}((string)$val);
}
}
} | [
"private",
"function",
"outputRecursiveContext",
"(",
"$",
"level",
",",
"array",
"$",
"context",
",",
"$",
"indent",
")",
"{",
"foreach",
"(",
"$",
"context",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"climate",
"->",
"tab",
"... | Handle recursive arrays in the logging context.
@param string $level One of the LogLevel constants
@param array $context The array of context to output
@param int $indent The current level of indentation to be used
@return void | [
"Handle",
"recursive",
"arrays",
"in",
"the",
"logging",
"context",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Logger.php#L158-L173 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.result | public function result()
{
$keys = array_keys($this->data);
$first_key = reset($keys);
return (!is_int($first_key)) ? $this->associativeColumns() : $this->columns();
} | php | public function result()
{
$keys = array_keys($this->data);
$first_key = reset($keys);
return (!is_int($first_key)) ? $this->associativeColumns() : $this->columns();
} | [
"public",
"function",
"result",
"(",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"first_key",
"=",
"reset",
"(",
"$",
"keys",
")",
";",
"return",
"(",
"!",
"is_int",
"(",
"$",
"first_key",
")",
")",
"?... | Calculate the number of columns organize data
@return array | [
"Calculate",
"the",
"number",
"of",
"columns",
"organize",
"data"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L36-L42 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.columns | protected function columns()
{
$this->data = $this->setData();
$column_widths = $this->getColumnWidths();
$output = [];
$count = count(reset($this->data));
for ($i = 0; $i < $count; $i++) {
$output[] = $this->getRow($i, $column_widths);
}
return $output;
} | php | protected function columns()
{
$this->data = $this->setData();
$column_widths = $this->getColumnWidths();
$output = [];
$count = count(reset($this->data));
for ($i = 0; $i < $count; $i++) {
$output[] = $this->getRow($i, $column_widths);
}
return $output;
} | [
"protected",
"function",
"columns",
"(",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"this",
"->",
"setData",
"(",
")",
";",
"$",
"column_widths",
"=",
"$",
"this",
"->",
"getColumnWidths",
"(",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"$",
... | Get columns for a regular array
@return array | [
"Get",
"columns",
"for",
"a",
"regular",
"array"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L49-L61 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.setData | protected function setData()
{
// If it's already an array of arrays, we're good to go
if (is_array(reset($this->data))) {
return $this->setArrayOfArraysData();
}
$column_width = $this->getColumnWidth($this->data);
$row_count = $this->getMaxRows($column_width);
return array_chunk($this->data, $row_count);
} | php | protected function setData()
{
// If it's already an array of arrays, we're good to go
if (is_array(reset($this->data))) {
return $this->setArrayOfArraysData();
}
$column_width = $this->getColumnWidth($this->data);
$row_count = $this->getMaxRows($column_width);
return array_chunk($this->data, $row_count);
} | [
"protected",
"function",
"setData",
"(",
")",
"{",
"// If it's already an array of arrays, we're good to go",
"if",
"(",
"is_array",
"(",
"reset",
"(",
"$",
"this",
"->",
"data",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setArrayOfArraysData",
"(",
")",
... | Re-configure the data into it's final form | [
"Re",
"-",
"configure",
"the",
"data",
"into",
"it",
"s",
"final",
"form"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L66-L77 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.setArrayOfArraysData | protected function setArrayOfArraysData()
{
$this->setColumnCountViaArray($this->data);
$new_data = array_fill(0, $this->column_count, []);
foreach ($this->data as $items) {
for ($i = 0; $i < $this->column_count; $i++) {
$new_data[$i][] = (array_key_exists($i, $items)) ? $items[$i] : null;
}
}
return $new_data;
} | php | protected function setArrayOfArraysData()
{
$this->setColumnCountViaArray($this->data);
$new_data = array_fill(0, $this->column_count, []);
foreach ($this->data as $items) {
for ($i = 0; $i < $this->column_count; $i++) {
$new_data[$i][] = (array_key_exists($i, $items)) ? $items[$i] : null;
}
}
return $new_data;
} | [
"protected",
"function",
"setArrayOfArraysData",
"(",
")",
"{",
"$",
"this",
"->",
"setColumnCountViaArray",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"new_data",
"=",
"array_fill",
"(",
"0",
",",
"$",
"this",
"->",
"column_count",
",",
"[",
"]",
")... | Re-configure an array of arrays into column arrays | [
"Re",
"-",
"configure",
"an",
"array",
"of",
"arrays",
"into",
"column",
"arrays"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L82-L95 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.associativeColumns | protected function associativeColumns()
{
$column_width = $this->getColumnWidth(array_keys($this->data));
$output = [];
foreach ($this->data as $key => $value) {
$output[] = $this->pad($key, $column_width) . $value;
}
return $output;
} | php | protected function associativeColumns()
{
$column_width = $this->getColumnWidth(array_keys($this->data));
$output = [];
foreach ($this->data as $key => $value) {
$output[] = $this->pad($key, $column_width) . $value;
}
return $output;
} | [
"protected",
"function",
"associativeColumns",
"(",
")",
"{",
"$",
"column_width",
"=",
"$",
"this",
"->",
"getColumnWidth",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"data",
")",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this... | Get columns for an associative array
@return array | [
"Get",
"columns",
"for",
"an",
"associative",
"array"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L102-L112 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.getRow | protected function getRow($key, $column_widths)
{
$row = [];
for ($j = 0; $j < $this->column_count; $j++) {
if (isset($this->data[$j]) && array_key_exists($key, $this->data[$j])) {
$row[] = $this->pad($this->data[$j][$key], $column_widths[$j]);
}
}
return trim(implode('', $row));
} | php | protected function getRow($key, $column_widths)
{
$row = [];
for ($j = 0; $j < $this->column_count; $j++) {
if (isset($this->data[$j]) && array_key_exists($key, $this->data[$j])) {
$row[] = $this->pad($this->data[$j][$key], $column_widths[$j]);
}
}
return trim(implode('', $row));
} | [
"protected",
"function",
"getRow",
"(",
"$",
"key",
",",
"$",
"column_widths",
")",
"{",
"$",
"row",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"this",
"->",
"column_count",
";",
"$",
"j",
"++",
")",
"{",
"if... | Get the row of data
@param integer $key
@param array $column_widths
@return string | [
"Get",
"the",
"row",
"of",
"data"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L122-L133 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.getColumnWidths | protected function getColumnWidths()
{
$column_widths = [];
for ($i = 0; $i < $this->column_count; $i++) {
if (!isset($this->data[$i])) {
$column_widths[] = 0;
continue;
}
$column_widths[] = $this->getColumnWidth($this->data[$i]);
}
return $column_widths;
} | php | protected function getColumnWidths()
{
$column_widths = [];
for ($i = 0; $i < $this->column_count; $i++) {
if (!isset($this->data[$i])) {
$column_widths[] = 0;
continue;
}
$column_widths[] = $this->getColumnWidth($this->data[$i]);
}
return $column_widths;
} | [
"protected",
"function",
"getColumnWidths",
"(",
")",
"{",
"$",
"column_widths",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"column_count",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isset",
... | Get an array of each column's width
@return array | [
"Get",
"an",
"array",
"of",
"each",
"column",
"s",
"width"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L153-L166 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.setColumnCount | protected function setColumnCount($column_width)
{
$this->column_count = (int) floor($this->util->width() / $column_width);
} | php | protected function setColumnCount($column_width)
{
$this->column_count = (int) floor($this->util->width() / $column_width);
} | [
"protected",
"function",
"setColumnCount",
"(",
"$",
"column_width",
")",
"{",
"$",
"this",
"->",
"column_count",
"=",
"(",
"int",
")",
"floor",
"(",
"$",
"this",
"->",
"util",
"->",
"width",
"(",
")",
"/",
"$",
"column_width",
")",
";",
"}"
] | Set the count property
@param integer $column_width | [
"Set",
"the",
"count",
"property"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L173-L176 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.setColumnCountViaArray | protected function setColumnCountViaArray($items)
{
$counts = array_map(function ($arr) {
return count($arr);
}, $items);
$this->column_count = max($counts);
} | php | protected function setColumnCountViaArray($items)
{
$counts = array_map(function ($arr) {
return count($arr);
}, $items);
$this->column_count = max($counts);
} | [
"protected",
"function",
"setColumnCountViaArray",
"(",
"$",
"items",
")",
"{",
"$",
"counts",
"=",
"array_map",
"(",
"function",
"(",
"$",
"arr",
")",
"{",
"return",
"count",
"(",
"$",
"arr",
")",
";",
"}",
",",
"$",
"items",
")",
";",
"$",
"this",
... | Set the count property via an array
@param array $items | [
"Set",
"the",
"count",
"property",
"via",
"an",
"array"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L183-L190 | train |
thephpleague/climate | src/TerminalObject/Basic/Columns.php | Columns.getMaxRows | protected function getMaxRows($column_width)
{
if (!$this->column_count) {
$this->setColumnCount($column_width);
}
return ceil(count($this->data) / $this->column_count);
} | php | protected function getMaxRows($column_width)
{
if (!$this->column_count) {
$this->setColumnCount($column_width);
}
return ceil(count($this->data) / $this->column_count);
} | [
"protected",
"function",
"getMaxRows",
"(",
"$",
"column_width",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"column_count",
")",
"{",
"$",
"this",
"->",
"setColumnCount",
"(",
"$",
"column_width",
")",
";",
"}",
"return",
"ceil",
"(",
"count",
"(",
"... | Get the number of rows per column
@param integer $column_width
@return integer | [
"Get",
"the",
"number",
"of",
"rows",
"per",
"column"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Columns.php#L199-L206 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkbox/RadioGroup.php | RadioGroup.toggleCurrent | public function toggleCurrent()
{
list($checkbox, $checkbox_key) = $this->getCurrent();
$checkbox->setChecked(!$checkbox->isChecked());
foreach ($this->checkboxes as $key => $checkbox) {
if ($key == $checkbox_key) {
continue;
}
$checkbox->setChecked(false);
}
} | php | public function toggleCurrent()
{
list($checkbox, $checkbox_key) = $this->getCurrent();
$checkbox->setChecked(!$checkbox->isChecked());
foreach ($this->checkboxes as $key => $checkbox) {
if ($key == $checkbox_key) {
continue;
}
$checkbox->setChecked(false);
}
} | [
"public",
"function",
"toggleCurrent",
"(",
")",
"{",
"list",
"(",
"$",
"checkbox",
",",
"$",
"checkbox_key",
")",
"=",
"$",
"this",
"->",
"getCurrent",
"(",
")",
";",
"$",
"checkbox",
"->",
"setChecked",
"(",
"!",
"$",
"checkbox",
"->",
"isChecked",
"... | Toggle the currently selected option, uncheck all of the others | [
"Toggle",
"the",
"currently",
"selected",
"option",
"uncheck",
"all",
"of",
"the",
"others"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkbox/RadioGroup.php#L10-L23 | train |
thephpleague/climate | src/TerminalObject/Router/BaseRouter.php | BaseRouter.getExtension | protected function getExtension($key)
{
if (array_key_exists($key, $this->extensions)) {
return $this->extensions[$key];
}
return false;
} | php | protected function getExtension($key)
{
if (array_key_exists($key, $this->extensions)) {
return $this->extensions[$key];
}
return false;
} | [
"protected",
"function",
"getExtension",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"extensions",
")",
")",
"{",
"return",
"$",
"this",
"->",
"extensions",
"[",
"$",
"key",
"]",
";",
"}",
"retur... | Get an extension by its key
@param string $key
@return string|false Full class path to extension | [
"Get",
"an",
"extension",
"by",
"its",
"key"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/BaseRouter.php#L66-L73 | train |
thephpleague/climate | src/TerminalObject/Router/BaseRouter.php | BaseRouter.shortName | protected function shortName($name)
{
$name = str_replace('_', ' ', $name);
$name = ucwords($name);
return str_replace(' ', '', $name);
} | php | protected function shortName($name)
{
$name = str_replace('_', ' ', $name);
$name = ucwords($name);
return str_replace(' ', '', $name);
} | [
"protected",
"function",
"shortName",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"name",
")",
";",
"$",
"name",
"=",
"ucwords",
"(",
"$",
"name",
")",
";",
"return",
"str_replace",
"(",
"' '",
","... | Get the class short name
@param string $name
@return string | [
"Get",
"the",
"class",
"short",
"name"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/BaseRouter.php#L82-L88 | train |
thephpleague/climate | src/Settings/Art.php | Art.add | public function add()
{
$this->dirs = array_merge($this->dirs, func_get_args());
$this->dirs = array_filter($this->dirs);
$this->dirs = array_values($this->dirs);
} | php | public function add()
{
$this->dirs = array_merge($this->dirs, func_get_args());
$this->dirs = array_filter($this->dirs);
$this->dirs = array_values($this->dirs);
} | [
"public",
"function",
"add",
"(",
")",
"{",
"$",
"this",
"->",
"dirs",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dirs",
",",
"func_get_args",
"(",
")",
")",
";",
"$",
"this",
"->",
"dirs",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"dirs",
")"... | Add directories of art | [
"Add",
"directories",
"of",
"art"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Settings/Art.php#L16-L21 | train |
thephpleague/climate | src/TerminalObject/Helper/Art.php | Art.addDir | protected function addDir($dir)
{
// Add any additional directories to the top of the array
// so that the user can override art
array_unshift($this->art_dirs, rtrim($dir, '/'));
// Keep the array clean
$this->art_dirs = array_unique($this->art_dirs);
$this->art_dirs = array_filter($this->art_dirs);
$this->art_dirs = array_values($this->art_dirs);
} | php | protected function addDir($dir)
{
// Add any additional directories to the top of the array
// so that the user can override art
array_unshift($this->art_dirs, rtrim($dir, '/'));
// Keep the array clean
$this->art_dirs = array_unique($this->art_dirs);
$this->art_dirs = array_filter($this->art_dirs);
$this->art_dirs = array_values($this->art_dirs);
} | [
"protected",
"function",
"addDir",
"(",
"$",
"dir",
")",
"{",
"// Add any additional directories to the top of the array",
"// so that the user can override art",
"array_unshift",
"(",
"$",
"this",
"->",
"art_dirs",
",",
"rtrim",
"(",
"$",
"dir",
",",
"'/'",
")",
")",... | Add a directory to search for art in
@param string $dir | [
"Add",
"a",
"directory",
"to",
"search",
"for",
"art",
"in"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Helper/Art.php#L57-L67 | train |
thephpleague/climate | src/TerminalObject/Helper/Art.php | Art.artFile | protected function artFile($art)
{
$files = $this->fileSearch($art, '[^' . \DIRECTORY_SEPARATOR . ']*$');
if (count($files) === 0) {
$this->addDir(__DIR__ . '/../../ASCII');
$files = $this->fileSearch($this->default_art, '.*');
}
if (count($files) === 0) {
throw new UnexpectedValueException("Unable to find an art file with the name '{$art}'");
}
return reset($files);
} | php | protected function artFile($art)
{
$files = $this->fileSearch($art, '[^' . \DIRECTORY_SEPARATOR . ']*$');
if (count($files) === 0) {
$this->addDir(__DIR__ . '/../../ASCII');
$files = $this->fileSearch($this->default_art, '.*');
}
if (count($files) === 0) {
throw new UnexpectedValueException("Unable to find an art file with the name '{$art}'");
}
return reset($files);
} | [
"protected",
"function",
"artFile",
"(",
"$",
"art",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"fileSearch",
"(",
"$",
"art",
",",
"'[^'",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"']*$'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"files",
")",
"... | Find a valid art path
@param string $art
@return string | [
"Find",
"a",
"valid",
"art",
"path"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Helper/Art.php#L88-L102 | train |
thephpleague/climate | src/TerminalObject/Helper/Art.php | Art.fileSearch | protected function fileSearch($art, $pattern)
{
foreach ($this->art_dirs as $dir) {
$directory_iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
$paths = [];
$regex = '~' . preg_quote($art) . $pattern . '~';
foreach ($directory_iterator as $file) {
if ($file->isDir()) {
continue;
}
// Look for anything that has the $art filename
if (preg_match($regex, $file)) {
$paths[] = $file->getPathname();
}
}
asort($paths);
// If we've got one, no need to look any further
if (!empty($paths)) {
return $paths;
}
}
return [];
} | php | protected function fileSearch($art, $pattern)
{
foreach ($this->art_dirs as $dir) {
$directory_iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
$paths = [];
$regex = '~' . preg_quote($art) . $pattern . '~';
foreach ($directory_iterator as $file) {
if ($file->isDir()) {
continue;
}
// Look for anything that has the $art filename
if (preg_match($regex, $file)) {
$paths[] = $file->getPathname();
}
}
asort($paths);
// If we've got one, no need to look any further
if (!empty($paths)) {
return $paths;
}
}
return [];
} | [
"protected",
"function",
"fileSearch",
"(",
"$",
"art",
",",
"$",
"pattern",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"art_dirs",
"as",
"$",
"dir",
")",
"{",
"$",
"directory_iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
... | Find a set of files in the current art directories
based on a pattern
@param string $art
@param string $pattern
@return array | [
"Find",
"a",
"set",
"of",
"files",
"in",
"the",
"current",
"art",
"directories",
"based",
"on",
"a",
"pattern"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Helper/Art.php#L113-L141 | train |
thephpleague/climate | src/TerminalObject/Helper/Art.php | Art.parse | protected function parse($path)
{
$output = file_get_contents($path);
$output = explode("\n", $output);
$output = array_map('rtrim', $output);
return $output;
} | php | protected function parse($path)
{
$output = file_get_contents($path);
$output = explode("\n", $output);
$output = array_map('rtrim', $output);
return $output;
} | [
"protected",
"function",
"parse",
"(",
"$",
"path",
")",
"{",
"$",
"output",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"$",
"output",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"output",
")",
";",
"$",
"output",
"=",
"array_map",
"(",
"'rt... | Parse the contents of the file and return each line
@param string $path
@return array | [
"Parse",
"the",
"contents",
"of",
"the",
"file",
"and",
"return",
"each",
"line"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Helper/Art.php#L150-L157 | train |
thephpleague/climate | src/Argument/Filter.php | Filter.filterArguments | protected function filterArguments($filters = [])
{
$arguments = $this->arguments;
foreach ($filters as $filter) {
$arguments = array_filter($arguments, [$this, $filter]);
}
if (in_array('hasPrefix', $filters)) {
usort($arguments, [$this, 'compareByPrefix']);
}
return array_values($arguments);
} | php | protected function filterArguments($filters = [])
{
$arguments = $this->arguments;
foreach ($filters as $filter) {
$arguments = array_filter($arguments, [$this, $filter]);
}
if (in_array('hasPrefix', $filters)) {
usort($arguments, [$this, 'compareByPrefix']);
}
return array_values($arguments);
} | [
"protected",
"function",
"filterArguments",
"(",
"$",
"filters",
"=",
"[",
"]",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"arguments",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"arguments",
"=",
"array_filter",
... | Filter defined arguments as to whether they are required or not
@param string[] $filters
@return Argument[] | [
"Filter",
"defined",
"arguments",
"as",
"to",
"whether",
"they",
"are",
"required",
"or",
"not"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Filter.php#L78-L91 | train |
thephpleague/climate | src/Argument/Filter.php | Filter.compareByPrefix | public function compareByPrefix(Argument $a, Argument $b)
{
if ($this->prefixCompareString($a) < $this->prefixCompareString($b)) {
return -1;
}
return 1;
} | php | public function compareByPrefix(Argument $a, Argument $b)
{
if ($this->prefixCompareString($a) < $this->prefixCompareString($b)) {
return -1;
}
return 1;
} | [
"public",
"function",
"compareByPrefix",
"(",
"Argument",
"$",
"a",
",",
"Argument",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"prefixCompareString",
"(",
"$",
"a",
")",
"<",
"$",
"this",
"->",
"prefixCompareString",
"(",
"$",
"b",
")",
")",
... | Compare two arguments by their short and long prefixes.
@see usort()
@param Argument $a
@param Argument $b
@return int | [
"Compare",
"two",
"arguments",
"by",
"their",
"short",
"and",
"long",
"prefixes",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Filter.php#L163-L170 | train |
thephpleague/climate | src/Settings/SettingsImporter.php | SettingsImporter.importSetting | public function importSetting($setting)
{
$short_name = basename(str_replace('\\', '/', get_class($setting)));
$method = 'importSetting' . $short_name;
if (method_exists($this, $method)) {
$this->$method($setting);
}
} | php | public function importSetting($setting)
{
$short_name = basename(str_replace('\\', '/', get_class($setting)));
$method = 'importSetting' . $short_name;
if (method_exists($this, $method)) {
$this->$method($setting);
}
} | [
"public",
"function",
"importSetting",
"(",
"$",
"setting",
")",
"{",
"$",
"short_name",
"=",
"basename",
"(",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"get_class",
"(",
"$",
"setting",
")",
")",
")",
";",
"$",
"method",
"=",
"'importSetting'",
"."... | Import the setting into the class
@param \League\CLImate\Settings\SettingsInterface $setting | [
"Import",
"the",
"setting",
"into",
"the",
"class"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Settings/SettingsImporter.php#L22-L31 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Padding.php | Padding.getLength | protected function getLength()
{
if (!$this->length) {
$this->length = $this->util->width();
}
return $this->length;
} | php | protected function getLength()
{
if (!$this->length) {
$this->length = $this->util->width();
}
return $this->length;
} | [
"protected",
"function",
"getLength",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"length",
")",
"{",
"$",
"this",
"->",
"length",
"=",
"$",
"this",
"->",
"util",
"->",
"width",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"length",
";"... | Get the length of the line based on the width of the terminal window
@return integer | [
"Get",
"the",
"length",
"of",
"the",
"line",
"based",
"on",
"the",
"width",
"of",
"the",
"terminal",
"window"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Padding.php#L72-L79 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Padding.php | Padding.padContent | protected function padContent($content)
{
if (strlen($this->char) > 0) {
$length = $this->getLength();
$padding_length = ceil($length / mb_strlen($this->char));
$padding = str_repeat($this->char, $padding_length);
$content .= mb_substr($padding, 0, $length - mb_strlen($content));
}
return $content;
} | php | protected function padContent($content)
{
if (strlen($this->char) > 0) {
$length = $this->getLength();
$padding_length = ceil($length / mb_strlen($this->char));
$padding = str_repeat($this->char, $padding_length);
$content .= mb_substr($padding, 0, $length - mb_strlen($content));
}
return $content;
} | [
"protected",
"function",
"padContent",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"char",
")",
">",
"0",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"getLength",
"(",
")",
";",
"$",
"padding_length",
"=",
"ceil... | Pad the content with the characters
@param string $content
@return string | [
"Pad",
"the",
"content",
"with",
"the",
"characters"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Padding.php#L88-L99 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Padding.php | Padding.label | public function label($content)
{
// Handle long labels by splitting them across several lines
$lines = [];
$stop = mb_strlen($content);
$width = $this->util->width();
for ($i = 0; $i < $stop; $i += $width) {
$lines[] = mb_substr($content, $i, $width);
}
$content = array_pop($lines);
foreach ($lines as $line) {
$this->output->write($this->parser->apply($line));
}
$content = $this->padContent($content);
$content = $this->parser->apply($content);
$this->output->sameLine();
$this->output->write($content);
return $this;
} | php | public function label($content)
{
// Handle long labels by splitting them across several lines
$lines = [];
$stop = mb_strlen($content);
$width = $this->util->width();
for ($i = 0; $i < $stop; $i += $width) {
$lines[] = mb_substr($content, $i, $width);
}
$content = array_pop($lines);
foreach ($lines as $line) {
$this->output->write($this->parser->apply($line));
}
$content = $this->padContent($content);
$content = $this->parser->apply($content);
$this->output->sameLine();
$this->output->write($content);
return $this;
} | [
"public",
"function",
"label",
"(",
"$",
"content",
")",
"{",
"// Handle long labels by splitting them across several lines",
"$",
"lines",
"=",
"[",
"]",
";",
"$",
"stop",
"=",
"mb_strlen",
"(",
"$",
"content",
")",
";",
"$",
"width",
"=",
"$",
"this",
"->"... | Output the content and pad to the previously defined length
@param string $content
@return \League\CLImate\TerminalObject\Dynamic\Padding | [
"Output",
"the",
"content",
"and",
"pad",
"to",
"the",
"previously",
"defined",
"length"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Padding.php#L108-L130 | train |
thephpleague/climate | src/Decorator/Parser/ParserFactory.php | ParserFactory.getInstance | public static function getInstance(System $system, array $current, Tags $tags)
{
if ($system->hasAnsiSupport()) {
return new Ansi($current, $tags);
}
return new NonAnsi($current, $tags);
} | php | public static function getInstance(System $system, array $current, Tags $tags)
{
if ($system->hasAnsiSupport()) {
return new Ansi($current, $tags);
}
return new NonAnsi($current, $tags);
} | [
"public",
"static",
"function",
"getInstance",
"(",
"System",
"$",
"system",
",",
"array",
"$",
"current",
",",
"Tags",
"$",
"tags",
")",
"{",
"if",
"(",
"$",
"system",
"->",
"hasAnsiSupport",
"(",
")",
")",
"{",
"return",
"new",
"Ansi",
"(",
"$",
"c... | Get an instance of the appropriate Parser class
@param System $system
@param array $current
@param Tags $tags
@return Parser | [
"Get",
"an",
"instance",
"of",
"the",
"appropriate",
"Parser",
"class"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Parser/ParserFactory.php#L18-L25 | train |
thephpleague/climate | src/Decorator/Component/BaseDecorator.php | BaseDecorator.defaults | public function defaults()
{
foreach ($this->defaults as $name => $code) {
$this->add($name, $code);
}
} | php | public function defaults()
{
foreach ($this->defaults as $name => $code) {
$this->add($name, $code);
}
} | [
"public",
"function",
"defaults",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"defaults",
"as",
"$",
"name",
"=>",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"code",
")",
";",
"}",
"}"
] | Load up the defaults for this decorator | [
"Load",
"up",
"the",
"defaults",
"for",
"this",
"decorator"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Component/BaseDecorator.php#L29-L34 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.run | public function run()
{
$files = $this->artDir($this->art);
$animation = [];
foreach ($files as $file) {
$animation[] = $this->parse($file);
}
$this->animate($animation);
} | php | public function run()
{
$files = $this->artDir($this->art);
$animation = [];
foreach ($files as $file) {
$animation[] = $this->parse($file);
}
$this->animate($animation);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"artDir",
"(",
"$",
"this",
"->",
"art",
")",
";",
"$",
"animation",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"animatio... | Run a basic animation | [
"Run",
"a",
"basic",
"animation"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L37-L47 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.scroll | public function scroll($direction = 'right')
{
$this->setupKeyframes();
$mapping = $this->getScrollDirectionMapping();
if (!array_key_exists($direction, $mapping)) {
return false;
}
$lines = $this->getLines();
$enter_from = $mapping[$direction];
$exit_to = $mapping[$enter_from];
$this->animate($this->keyframes->scroll($lines, $enter_from, $exit_to));
} | php | public function scroll($direction = 'right')
{
$this->setupKeyframes();
$mapping = $this->getScrollDirectionMapping();
if (!array_key_exists($direction, $mapping)) {
return false;
}
$lines = $this->getLines();
$enter_from = $mapping[$direction];
$exit_to = $mapping[$enter_from];
$this->animate($this->keyframes->scroll($lines, $enter_from, $exit_to));
} | [
"public",
"function",
"scroll",
"(",
"$",
"direction",
"=",
"'right'",
")",
"{",
"$",
"this",
"->",
"setupKeyframes",
"(",
")",
";",
"$",
"mapping",
"=",
"$",
"this",
"->",
"getScrollDirectionMapping",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"... | Scroll the art
@param string $direction
@return bool | [
"Scroll",
"the",
"art"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L70-L85 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.exitTo | public function exitTo($direction)
{
$this->setupKeyframes();
$this->animate($this->keyframes->exitTo($this->getLines(), $direction));
} | php | public function exitTo($direction)
{
$this->setupKeyframes();
$this->animate($this->keyframes->exitTo($this->getLines(), $direction));
} | [
"public",
"function",
"exitTo",
"(",
"$",
"direction",
")",
"{",
"$",
"this",
"->",
"setupKeyframes",
"(",
")",
";",
"$",
"this",
"->",
"animate",
"(",
"$",
"this",
"->",
"keyframes",
"->",
"exitTo",
"(",
"$",
"this",
"->",
"getLines",
"(",
")",
",",... | Animate the art exiting the screen
@param string $direction top|bottom|right|left | [
"Animate",
"the",
"art",
"exiting",
"the",
"screen"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L92-L97 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.enterFrom | public function enterFrom($direction)
{
$this->setupKeyframes();
$this->animate($this->keyframes->enterFrom($this->getLines(), $direction));
} | php | public function enterFrom($direction)
{
$this->setupKeyframes();
$this->animate($this->keyframes->enterFrom($this->getLines(), $direction));
} | [
"public",
"function",
"enterFrom",
"(",
"$",
"direction",
")",
"{",
"$",
"this",
"->",
"setupKeyframes",
"(",
")",
";",
"$",
"this",
"->",
"animate",
"(",
"$",
"this",
"->",
"keyframes",
"->",
"enterFrom",
"(",
"$",
"this",
"->",
"getLines",
"(",
")",
... | Animate the art entering the screen
@param string $direction top|bottom|right|left | [
"Animate",
"the",
"art",
"entering",
"the",
"screen"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L104-L109 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.