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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
johnbillion/extended-cpts | src/class-extended-taxonomy-admin.php | Extended_Taxonomy_Admin.meta_boxes | public function meta_boxes( $object_type, $object ) {
if ( ! is_a( $object, 'WP_Post' ) ) {
return;
}
$post_type = $object_type;
$post = $object;
$taxos = get_post_taxonomies( $post );
if ( in_array( $this->taxo->taxonomy, $taxos, true ) ) {
$tax = get_taxonomy( $this->taxo->taxonomy );
# Remove default meta box:
if ( $this->taxo->args['hierarchical'] ) {
remove_meta_box( "{$this->taxo->taxonomy}div", $post_type, 'side' );
} else {
remove_meta_box( "tagsdiv-{$this->taxo->taxonomy}", $post_type, 'side' );
}
if ( ! current_user_can( $tax->cap->assign_terms ) ) {
return;
}
if ( $this->args['meta_box'] ) {
# Set the 'meta_box' argument to the actual meta box callback function name:
if ( 'simple' === $this->args['meta_box'] ) {
if ( $this->taxo->args['exclusive'] ) {
$this->args['meta_box'] = [ $this, 'meta_box_radio' ];
} else {
$this->args['meta_box'] = [ $this, 'meta_box_simple' ];
}
} elseif ( 'radio' === $this->args['meta_box'] ) {
$this->taxo->args['exclusive'] = true;
$this->args['meta_box'] = [ $this, 'meta_box_radio' ];
} elseif ( 'dropdown' === $this->args['meta_box'] ) {
$this->taxo->args['exclusive'] = true;
$this->args['meta_box'] = [ $this, 'meta_box_dropdown' ];
}
# Add the meta box, using the plural or singular taxonomy label where relevant:
if ( $this->taxo->args['exclusive'] ) {
add_meta_box( "{$this->taxo->taxonomy}div", $tax->labels->singular_name, $this->args['meta_box'], $post_type, 'side' );
} else {
add_meta_box( "{$this->taxo->taxonomy}div", $tax->labels->name, $this->args['meta_box'], $post_type, 'side' );
}
} elseif ( false !== $this->args['meta_box'] ) {
# This must be an 'exclusive' taxonomy. Add the radio meta box:
add_meta_box( "{$this->taxo->taxonomy}div", $tax->labels->singular_name, [ $this, 'meta_box_radio' ], $post_type, 'side' );
}
}
} | php | public function meta_boxes( $object_type, $object ) {
if ( ! is_a( $object, 'WP_Post' ) ) {
return;
}
$post_type = $object_type;
$post = $object;
$taxos = get_post_taxonomies( $post );
if ( in_array( $this->taxo->taxonomy, $taxos, true ) ) {
$tax = get_taxonomy( $this->taxo->taxonomy );
# Remove default meta box:
if ( $this->taxo->args['hierarchical'] ) {
remove_meta_box( "{$this->taxo->taxonomy}div", $post_type, 'side' );
} else {
remove_meta_box( "tagsdiv-{$this->taxo->taxonomy}", $post_type, 'side' );
}
if ( ! current_user_can( $tax->cap->assign_terms ) ) {
return;
}
if ( $this->args['meta_box'] ) {
# Set the 'meta_box' argument to the actual meta box callback function name:
if ( 'simple' === $this->args['meta_box'] ) {
if ( $this->taxo->args['exclusive'] ) {
$this->args['meta_box'] = [ $this, 'meta_box_radio' ];
} else {
$this->args['meta_box'] = [ $this, 'meta_box_simple' ];
}
} elseif ( 'radio' === $this->args['meta_box'] ) {
$this->taxo->args['exclusive'] = true;
$this->args['meta_box'] = [ $this, 'meta_box_radio' ];
} elseif ( 'dropdown' === $this->args['meta_box'] ) {
$this->taxo->args['exclusive'] = true;
$this->args['meta_box'] = [ $this, 'meta_box_dropdown' ];
}
# Add the meta box, using the plural or singular taxonomy label where relevant:
if ( $this->taxo->args['exclusive'] ) {
add_meta_box( "{$this->taxo->taxonomy}div", $tax->labels->singular_name, $this->args['meta_box'], $post_type, 'side' );
} else {
add_meta_box( "{$this->taxo->taxonomy}div", $tax->labels->name, $this->args['meta_box'], $post_type, 'side' );
}
} elseif ( false !== $this->args['meta_box'] ) {
# This must be an 'exclusive' taxonomy. Add the radio meta box:
add_meta_box( "{$this->taxo->taxonomy}div", $tax->labels->singular_name, [ $this, 'meta_box_radio' ], $post_type, 'side' );
}
}
} | [
"public",
"function",
"meta_boxes",
"(",
"$",
"object_type",
",",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"object",
",",
"'WP_Post'",
")",
")",
"{",
"return",
";",
"}",
"$",
"post_type",
"=",
"$",
"object_type",
";",
"$",
"post",
... | Remove the default meta box from the post editing screen and add our custom meta box.
@param string $object_type The object type (eg. the post type)
@param mixed $object The object (eg. a WP_Post object)
@return null | [
"Remove",
"the",
"default",
"meta",
"box",
"from",
"the",
"post",
"editing",
"screen",
"and",
"add",
"our",
"custom",
"meta",
"box",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-taxonomy-admin.php#L276-L332 | train |
johnbillion/extended-cpts | src/class-extended-taxonomy-admin.php | Extended_Taxonomy_Admin.meta_box_radio | public function meta_box_radio( WP_Post $post, array $meta_box ) {
require_once __DIR__ . '/class-walker-extendedtaxonomyradios.php';
$walker = new Walker_ExtendedTaxonomyRadios();
$this->do_meta_box( $post, $walker, true, 'checklist' );
} | php | public function meta_box_radio( WP_Post $post, array $meta_box ) {
require_once __DIR__ . '/class-walker-extendedtaxonomyradios.php';
$walker = new Walker_ExtendedTaxonomyRadios();
$this->do_meta_box( $post, $walker, true, 'checklist' );
} | [
"public",
"function",
"meta_box_radio",
"(",
"WP_Post",
"$",
"post",
",",
"array",
"$",
"meta_box",
")",
"{",
"require_once",
"__DIR__",
".",
"'/class-walker-extendedtaxonomyradios.php'",
";",
"$",
"walker",
"=",
"new",
"Walker_ExtendedTaxonomyRadios",
"(",
")",
";"... | Display the 'radio' meta box on the post editing screen.
Uses the Walker_ExtendedTaxonomyRadios class for the walker.
@param WP_Post $post The post object.
@param array $meta_box The meta box arguments.
@return null | [
"Display",
"the",
"radio",
"meta",
"box",
"on",
"the",
"post",
"editing",
"screen",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-taxonomy-admin.php#L343-L349 | train |
johnbillion/extended-cpts | src/class-extended-taxonomy-admin.php | Extended_Taxonomy_Admin.meta_box_dropdown | public function meta_box_dropdown( WP_Post $post, array $meta_box ) {
require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php';
$walker = new Walker_ExtendedTaxonomyDropdown();
$this->do_meta_box( $post, $walker, true, 'dropdown' );
} | php | public function meta_box_dropdown( WP_Post $post, array $meta_box ) {
require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php';
$walker = new Walker_ExtendedTaxonomyDropdown();
$this->do_meta_box( $post, $walker, true, 'dropdown' );
} | [
"public",
"function",
"meta_box_dropdown",
"(",
"WP_Post",
"$",
"post",
",",
"array",
"$",
"meta_box",
")",
"{",
"require_once",
"__DIR__",
".",
"'/class-walker-extendedtaxonomydropdown.php'",
";",
"$",
"walker",
"=",
"new",
"Walker_ExtendedTaxonomyDropdown",
"(",
")"... | Display the 'dropdown' meta box on the post editing screen.
Uses the Walker_ExtendedTaxonomyDropdown class for the walker.
@param WP_Post $post The post object.
@param array $meta_box The meta box arguments.
@return null | [
"Display",
"the",
"dropdown",
"meta",
"box",
"on",
"the",
"post",
"editing",
"screen",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-taxonomy-admin.php#L360-L366 | train |
johnbillion/extended-cpts | src/class-extended-taxonomy-admin.php | Extended_Taxonomy_Admin.glance_items | public function glance_items( array $items ) {
$taxonomy = get_taxonomy( $this->taxo->taxonomy );
if ( ! current_user_can( $taxonomy->cap->manage_terms ) ) {
return $items;
}
if ( $taxonomy->_builtin ) {
return $items;
}
# Get the labels and format the counts:
$count = wp_count_terms( $this->taxo->taxonomy );
$text = self::n( $taxonomy->labels->singular_name, $taxonomy->labels->name, $count );
$num = number_format_i18n( $count );
# This is absolutely not localisable. WordPress 3.8 didn't add a new taxonomy label.
$url = add_query_arg( [
'taxonomy' => $this->taxo->taxonomy,
'post_type' => reset( $taxonomy->object_type ),
], admin_url( 'edit-tags.php' ) );
$text = '<a href="' . esc_url( $url ) . '" class="taxo-' . esc_attr( $this->taxo->taxonomy ) . '-count">' . esc_html( $num . ' ' . $text ) . '</a>';
# Go!
$items[] = $text;
return $items;
} | php | public function glance_items( array $items ) {
$taxonomy = get_taxonomy( $this->taxo->taxonomy );
if ( ! current_user_can( $taxonomy->cap->manage_terms ) ) {
return $items;
}
if ( $taxonomy->_builtin ) {
return $items;
}
# Get the labels and format the counts:
$count = wp_count_terms( $this->taxo->taxonomy );
$text = self::n( $taxonomy->labels->singular_name, $taxonomy->labels->name, $count );
$num = number_format_i18n( $count );
# This is absolutely not localisable. WordPress 3.8 didn't add a new taxonomy label.
$url = add_query_arg( [
'taxonomy' => $this->taxo->taxonomy,
'post_type' => reset( $taxonomy->object_type ),
], admin_url( 'edit-tags.php' ) );
$text = '<a href="' . esc_url( $url ) . '" class="taxo-' . esc_attr( $this->taxo->taxonomy ) . '-count">' . esc_html( $num . ' ' . $text ) . '</a>';
# Go!
$items[] = $text;
return $items;
} | [
"public",
"function",
"glance_items",
"(",
"array",
"$",
"items",
")",
"{",
"$",
"taxonomy",
"=",
"get_taxonomy",
"(",
"$",
"this",
"->",
"taxo",
"->",
"taxonomy",
")",
";",
"if",
"(",
"!",
"current_user_can",
"(",
"$",
"taxonomy",
"->",
"cap",
"->",
"... | Add our taxonomy to the 'At a Glance' widget on the WordPress 3.8+ dashboard.
@param array $items Array of items to display on the widget.
@return array Updated array of items. | [
"Add",
"our",
"taxonomy",
"to",
"the",
"At",
"a",
"Glance",
"widget",
"on",
"the",
"WordPress",
"3",
".",
"8",
"+",
"dashboard",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-taxonomy-admin.php#L530-L558 | train |
johnbillion/extended-cpts | src/class-extended-taxonomy-admin.php | Extended_Taxonomy_Admin.term_updated_messages | public function term_updated_messages( array $messages ) {
$messages[ $this->taxo->taxonomy ] = [
1 => esc_html( sprintf( '%s added.', $this->taxo->tax_singular ) ),
2 => esc_html( sprintf( '%s deleted.', $this->taxo->tax_singular ) ),
3 => esc_html( sprintf( '%s updated.', $this->taxo->tax_singular ) ),
4 => esc_html( sprintf( '%s not added.', $this->taxo->tax_singular ) ),
5 => esc_html( sprintf( '%s not updated.', $this->taxo->tax_singular ) ),
6 => esc_html( sprintf( '%s deleted.', $this->taxo->tax_plural ) ),
];
return $messages;
} | php | public function term_updated_messages( array $messages ) {
$messages[ $this->taxo->taxonomy ] = [
1 => esc_html( sprintf( '%s added.', $this->taxo->tax_singular ) ),
2 => esc_html( sprintf( '%s deleted.', $this->taxo->tax_singular ) ),
3 => esc_html( sprintf( '%s updated.', $this->taxo->tax_singular ) ),
4 => esc_html( sprintf( '%s not added.', $this->taxo->tax_singular ) ),
5 => esc_html( sprintf( '%s not updated.', $this->taxo->tax_singular ) ),
6 => esc_html( sprintf( '%s deleted.', $this->taxo->tax_plural ) ),
];
return $messages;
} | [
"public",
"function",
"term_updated_messages",
"(",
"array",
"$",
"messages",
")",
"{",
"$",
"messages",
"[",
"$",
"this",
"->",
"taxo",
"->",
"taxonomy",
"]",
"=",
"[",
"1",
"=>",
"esc_html",
"(",
"sprintf",
"(",
"'%s added.'",
",",
"$",
"this",
"->",
... | Add our term updated messages.
The messages are as follows:
1 => "Term added."
2 => "Term deleted."
3 => "Term updated."
4 => "Term not added."
5 => "Term not updated."
6 => "Terms deleted."
@param string[] $messages An associative array of term updated messages with taxonomy name as keys.
@return array Updated array of term updated messages. | [
"Add",
"our",
"term",
"updated",
"messages",
"."
] | fb48e7905d81796ac9cf597988a0a52593356ad8 | https://github.com/johnbillion/extended-cpts/blob/fb48e7905d81796ac9cf597988a0a52593356ad8/src/class-extended-taxonomy-admin.php#L575-L588 | train |
mvdbos/php-spider | src/VDB/Spider/Discoverer/DiscovererSet.php | DiscovererSet.set | public function set(DiscovererInterface $discoverer, $alias = null)
{
$this->discoverers[$discoverer->getName()] = $discoverer;
if (null !== $alias) {
$this->discoverers[$alias] = $discoverer;
}
} | php | public function set(DiscovererInterface $discoverer, $alias = null)
{
$this->discoverers[$discoverer->getName()] = $discoverer;
if (null !== $alias) {
$this->discoverers[$alias] = $discoverer;
}
} | [
"public",
"function",
"set",
"(",
"DiscovererInterface",
"$",
"discoverer",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"discoverers",
"[",
"$",
"discoverer",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"discoverer",
";",
"if",
"(",
"nul... | Sets a discoverer.
@param discovererInterface $discoverer The discoverer instance
@param string|null $alias An alias | [
"Sets",
"a",
"discoverer",
"."
] | 8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c | https://github.com/mvdbos/php-spider/blob/8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c/src/VDB/Spider/Discoverer/DiscovererSet.php#L97-L103 | train |
mvdbos/php-spider | src/VDB/Spider/Resource.php | Resource.getCrawler | public function getCrawler()
{
if (!$this->crawler instanceof Crawler) {
$this->crawler = new Crawler('', $this->getUri()->toString());
$this->crawler->addContent(
$this->getResponse()->getBody()->__toString(),
$this->getResponse()->getHeaderLine('Content-Type')
);
}
return $this->crawler;
} | php | public function getCrawler()
{
if (!$this->crawler instanceof Crawler) {
$this->crawler = new Crawler('', $this->getUri()->toString());
$this->crawler->addContent(
$this->getResponse()->getBody()->__toString(),
$this->getResponse()->getHeaderLine('Content-Type')
);
}
return $this->crawler;
} | [
"public",
"function",
"getCrawler",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"crawler",
"instanceof",
"Crawler",
")",
"{",
"$",
"this",
"->",
"crawler",
"=",
"new",
"Crawler",
"(",
"''",
",",
"$",
"this",
"->",
"getUri",
"(",
")",
"->",
"t... | Lazy loads a Crawler object based on the ResponseInterface;
@return Crawler | [
"Lazy",
"loads",
"a",
"Crawler",
"object",
"based",
"on",
"the",
"ResponseInterface",
";"
] | 8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c | https://github.com/mvdbos/php-spider/blob/8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c/src/VDB/Spider/Resource.php#L41-L51 | train |
mvdbos/php-spider | src/VDB/Spider/Spider.php | Spider.crawl | public function crawl()
{
$this->getQueueManager()->addUri($this->seed);
$this->getDownloader()->getPersistenceHandler()->setSpiderId($this->spiderId);
$this->doCrawl();
} | php | public function crawl()
{
$this->getQueueManager()->addUri($this->seed);
$this->getDownloader()->getPersistenceHandler()->setSpiderId($this->spiderId);
$this->doCrawl();
} | [
"public",
"function",
"crawl",
"(",
")",
"{",
"$",
"this",
"->",
"getQueueManager",
"(",
")",
"->",
"addUri",
"(",
"$",
"this",
"->",
"seed",
")",
";",
"$",
"this",
"->",
"getDownloader",
"(",
")",
"->",
"getPersistenceHandler",
"(",
")",
"->",
"setSpi... | Starts crawling the URI provided on instantiation
@return void | [
"Starts",
"crawling",
"the",
"URI",
"provided",
"on",
"instantiation"
] | 8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c | https://github.com/mvdbos/php-spider/blob/8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c/src/VDB/Spider/Spider.php#L72-L78 | train |
mvdbos/php-spider | src/VDB/Spider/Spider.php | Spider.doCrawl | private function doCrawl()
{
while ($currentUri = $this->getQueueManager()->next()) {
if ($this->getDownloader()->isDownLoadLimitExceeded()) {
break;
}
if (!$resource = $this->getDownloader()->download($currentUri)) {
continue;
}
$this->dispatch(
SpiderEvents::SPIDER_CRAWL_RESOURCE_PERSISTED,
new GenericEvent($this, array('uri' => $currentUri))
);
// Once the document is enqueued, apply the discoverers to look for more links to follow
$discoveredUris = $this->getDiscovererSet()->discover($resource);
foreach ($discoveredUris as $uri) {
try {
$this->getQueueManager()->addUri($uri);
} catch (QueueException $e) {
// when the queue size is exceeded, we stop discovering
break;
}
}
}
} | php | private function doCrawl()
{
while ($currentUri = $this->getQueueManager()->next()) {
if ($this->getDownloader()->isDownLoadLimitExceeded()) {
break;
}
if (!$resource = $this->getDownloader()->download($currentUri)) {
continue;
}
$this->dispatch(
SpiderEvents::SPIDER_CRAWL_RESOURCE_PERSISTED,
new GenericEvent($this, array('uri' => $currentUri))
);
// Once the document is enqueued, apply the discoverers to look for more links to follow
$discoveredUris = $this->getDiscovererSet()->discover($resource);
foreach ($discoveredUris as $uri) {
try {
$this->getQueueManager()->addUri($uri);
} catch (QueueException $e) {
// when the queue size is exceeded, we stop discovering
break;
}
}
}
} | [
"private",
"function",
"doCrawl",
"(",
")",
"{",
"while",
"(",
"$",
"currentUri",
"=",
"$",
"this",
"->",
"getQueueManager",
"(",
")",
"->",
"next",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getDownloader",
"(",
")",
"->",
"isDownLoadLimitExce... | Function that crawls each provided URI
It applies all processors and listeners set on the Spider
This is a either depth first algorithm as explained here:
https://en.wikipedia.org/wiki/Depth-first_search#Example
Note that because we don't do it recursive, but iteratively,
results will be in a different order from the example, because
we always take the right-most child first, whereas a recursive
variant would always take the left-most child first
or
a breadth first algorithm
@return void | [
"Function",
"that",
"crawls",
"each",
"provided",
"URI",
"It",
"applies",
"all",
"processors",
"and",
"listeners",
"set",
"on",
"the",
"Spider"
] | 8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c | https://github.com/mvdbos/php-spider/blob/8227d9b38a7ca0c3e152aad133fd4cf73ffa9f0c/src/VDB/Spider/Spider.php#L192-L220 | train |
phpgearbox/pdf | src/Pdf/Html/Backend.php | Backend.generate | public function generate()
{
// Inject our print framework
if ($this->printFramework !== false)
{
$this->document->setContents
(
Str::s($this->document->getContents())->replace
(
'</head>',
$this->printFramework.'</head>'
)
);
}
// Create a new temp file for the generated pdf
$output_document = $this->tempFile();
// Build the cmd to run
$cmd =
$this->binary.' '.
$this->runner.' '.
'--url "file://'.$this->document->getPathname().'" '.
'--output "'.$output_document->getPathname().'" '
;
if (isset($this->paperSize['width']))
{
$cmd .= '--width "'.$this->paperSize['width'].'" ';
}
if (isset($this->paperSize['height']))
{
$cmd .= '--height "'.$this->paperSize['height'].'" ';
}
// Run the command
$process = $this->process($cmd);
$process->run();
// Check for errors
if (!$process->isSuccessful())
{
throw new RuntimeException
(
$process->getErrorOutput()
);
}
// Return the pdf
return $output_document->getContents();
} | php | public function generate()
{
// Inject our print framework
if ($this->printFramework !== false)
{
$this->document->setContents
(
Str::s($this->document->getContents())->replace
(
'</head>',
$this->printFramework.'</head>'
)
);
}
// Create a new temp file for the generated pdf
$output_document = $this->tempFile();
// Build the cmd to run
$cmd =
$this->binary.' '.
$this->runner.' '.
'--url "file://'.$this->document->getPathname().'" '.
'--output "'.$output_document->getPathname().'" '
;
if (isset($this->paperSize['width']))
{
$cmd .= '--width "'.$this->paperSize['width'].'" ';
}
if (isset($this->paperSize['height']))
{
$cmd .= '--height "'.$this->paperSize['height'].'" ';
}
// Run the command
$process = $this->process($cmd);
$process->run();
// Check for errors
if (!$process->isSuccessful())
{
throw new RuntimeException
(
$process->getErrorOutput()
);
}
// Return the pdf
return $output_document->getContents();
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"// Inject our print framework",
"if",
"(",
"$",
"this",
"->",
"printFramework",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"document",
"->",
"setContents",
"(",
"Str",
"::",
"s",
"(",
"$",
"this",
"->",
... | Generates the PDF from the HTML File
@return PDF Bytes | [
"Generates",
"the",
"PDF",
"from",
"the",
"HTML",
"File"
] | add85171a4c30861261b801c78ae66efebd854eb | https://github.com/phpgearbox/pdf/blob/add85171a4c30861261b801c78ae66efebd854eb/src/Pdf/Html/Backend.php#L129-L180 | train |
phpgearbox/pdf | src/Pdf/Html/Backend.php | Backend.setPaperSize | public function setPaperSize($size)
{
if (isset($size['format']))
{
switch (strtolower($size['format']))
{
case 'a0':
$size['width'] = '841mm';
$size['height'] = '1189mm';
break;
case 'a1':
$size['width'] = '594mm';
$size['height'] = '841mm';
break;
case 'a2':
$size['width'] = '420mm';
$size['height'] = '594mm';
break;
case 'a3':
$size['width'] = '297mm';
$size['height'] = '420mm';
break;
case 'a4':
$size['width'] = '210mm';
$size['height'] = '297mm';
break;
case 'a5':
$size['width'] = '148mm';
$size['height'] = '210mm';
break;
case 'a6':
$size['width'] = '105mm';
$size['height'] = '148mm';
break;
case 'a7':
$size['width'] = '74mm';
$size['height'] = '105mm';
break;
case 'a8':
$size['width'] = '52mm';
$size['height'] = '74mm';
break;
case 'a9':
$size['width'] = '37mm';
$size['height'] = '52mm';
break;
case 'a10':
$size['width'] = '27mm';
$size['height'] = '37mm';
break;
case 'letter':
$size['width'] = '216mm';
$size['height'] = '280mm';
break;
case 'legal':
$size['width'] = '215.9mm';
$size['height'] = '255.6mm';
break;
default:
throw new RuntimeException('Unregcognised Paper Size!');
break;
}
// Swap the dimensions around if landscape
if (isset($size['orientation']))
{
if ($size['orientation'] == 'landscape')
{
$width = $size['width'];
$height = $size['height'];
$size['width'] = $height;
$size['height'] = $width;
}
}
}
$this->paperSize = $size;
return $this;
} | php | public function setPaperSize($size)
{
if (isset($size['format']))
{
switch (strtolower($size['format']))
{
case 'a0':
$size['width'] = '841mm';
$size['height'] = '1189mm';
break;
case 'a1':
$size['width'] = '594mm';
$size['height'] = '841mm';
break;
case 'a2':
$size['width'] = '420mm';
$size['height'] = '594mm';
break;
case 'a3':
$size['width'] = '297mm';
$size['height'] = '420mm';
break;
case 'a4':
$size['width'] = '210mm';
$size['height'] = '297mm';
break;
case 'a5':
$size['width'] = '148mm';
$size['height'] = '210mm';
break;
case 'a6':
$size['width'] = '105mm';
$size['height'] = '148mm';
break;
case 'a7':
$size['width'] = '74mm';
$size['height'] = '105mm';
break;
case 'a8':
$size['width'] = '52mm';
$size['height'] = '74mm';
break;
case 'a9':
$size['width'] = '37mm';
$size['height'] = '52mm';
break;
case 'a10':
$size['width'] = '27mm';
$size['height'] = '37mm';
break;
case 'letter':
$size['width'] = '216mm';
$size['height'] = '280mm';
break;
case 'legal':
$size['width'] = '215.9mm';
$size['height'] = '255.6mm';
break;
default:
throw new RuntimeException('Unregcognised Paper Size!');
break;
}
// Swap the dimensions around if landscape
if (isset($size['orientation']))
{
if ($size['orientation'] == 'landscape')
{
$width = $size['width'];
$height = $size['height'];
$size['width'] = $height;
$size['height'] = $width;
}
}
}
$this->paperSize = $size;
return $this;
} | [
"public",
"function",
"setPaperSize",
"(",
"$",
"size",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"size",
"[",
"'format'",
"]",
")",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"size",
"[",
"'format'",
"]",
")",
")",
"{",
"case",
"'a0'",
":",
... | Paper Size Setter
It is easier to work with numbers, so while I understand phantomjs does
have it's own paper size format and orientation settings. Here we provide
a basic lookup table to convert A4, A3, Letter, etc...
Into their metric counterparts.
@param array $size
@return self | [
"Paper",
"Size",
"Setter"
] | add85171a4c30861261b801c78ae66efebd854eb | https://github.com/phpgearbox/pdf/blob/add85171a4c30861261b801c78ae66efebd854eb/src/Pdf/Html/Backend.php#L194-L286 | train |
phpgearbox/pdf | src/Pdf.php | Pdf.save | public function save($path = null)
{
$pdf = $this->backend->generate();
// If no output path has been supplied save the file
// in the same folder as the original template.
if (is_null($path))
{
if (is_null($this->originalDocument))
{
// This will be thrown when someone attemtps to use
// the save method when they have supplied a HTML string.
throw new RuntimeException
(
'You must supply a path for us to save the PDF!'
);
}
$ext = $this->originalDocument->getExtension();
$path = Str::s($this->originalDocument->getPathname());
$path = $path->replace('.'.$ext, '.pdf');
}
// Save the pdf to the output path
if (@file_put_contents($path, $pdf) === false)
{
throw new RuntimeException('Failed to write to file "'.$path.'".');
}
// Return the location of the saved pdf
return $this->file($path);
} | php | public function save($path = null)
{
$pdf = $this->backend->generate();
// If no output path has been supplied save the file
// in the same folder as the original template.
if (is_null($path))
{
if (is_null($this->originalDocument))
{
// This will be thrown when someone attemtps to use
// the save method when they have supplied a HTML string.
throw new RuntimeException
(
'You must supply a path for us to save the PDF!'
);
}
$ext = $this->originalDocument->getExtension();
$path = Str::s($this->originalDocument->getPathname());
$path = $path->replace('.'.$ext, '.pdf');
}
// Save the pdf to the output path
if (@file_put_contents($path, $pdf) === false)
{
throw new RuntimeException('Failed to write to file "'.$path.'".');
}
// Return the location of the saved pdf
return $this->file($path);
} | [
"public",
"function",
"save",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"$",
"pdf",
"=",
"$",
"this",
"->",
"backend",
"->",
"generate",
"(",
")",
";",
"// If no output path has been supplied save the file",
"// in the same folder as the original template.",
"if",
"(... | Saves the generated PDF.
We call the backend class to generate the PDF for us.
Then we attempt to save those bytes to a permanent location.
@param string $path If not supplied we will create the PDF in the name
folder as the source document with the same filename.
@return SplFileInfo | [
"Saves",
"the",
"generated",
"PDF",
"."
] | add85171a4c30861261b801c78ae66efebd854eb | https://github.com/phpgearbox/pdf/blob/add85171a4c30861261b801c78ae66efebd854eb/src/Pdf.php#L182-L213 | train |
phpgearbox/pdf | src/Pdf/TempFile.php | TempFile.setContents | public function setContents($data)
{
$level = error_reporting(0);
$result = file_put_contents($this->getPathname(), $data);
error_reporting($level);
if (false === $result)
{
$error = error_get_last();
throw new RuntimeException($error['message']);
}
return $result;
} | php | public function setContents($data)
{
$level = error_reporting(0);
$result = file_put_contents($this->getPathname(), $data);
error_reporting($level);
if (false === $result)
{
$error = error_get_last();
throw new RuntimeException($error['message']);
}
return $result;
} | [
"public",
"function",
"setContents",
"(",
"$",
"data",
")",
"{",
"$",
"level",
"=",
"error_reporting",
"(",
"0",
")",
";",
"$",
"result",
"=",
"file_put_contents",
"(",
"$",
"this",
"->",
"getPathname",
"(",
")",
",",
"$",
"data",
")",
";",
"error_repo... | Sets the contents of the temp file.
@param mixed $data Can be either a string, an array or a stream resource.
@return mixed This function returns the number of bytes that were
written to the file;
@throws RuntimeException | [
"Sets",
"the",
"contents",
"of",
"the",
"temp",
"file",
"."
] | add85171a4c30861261b801c78ae66efebd854eb | https://github.com/phpgearbox/pdf/blob/add85171a4c30861261b801c78ae66efebd854eb/src/Pdf/TempFile.php#L90-L103 | train |
neomerx/json-api | src/Representation/DocumentWriter.php | DocumentWriter.hasNotBeenAdded | protected function hasNotBeenAdded(ResourceInterface $resource): bool
{
return isset($this->addedResources[$resource->getId()][$resource->getType()]) === false;
} | php | protected function hasNotBeenAdded(ResourceInterface $resource): bool
{
return isset($this->addedResources[$resource->getId()][$resource->getType()]) === false;
} | [
"protected",
"function",
"hasNotBeenAdded",
"(",
"ResourceInterface",
"$",
"resource",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"addedResources",
"[",
"$",
"resource",
"->",
"getId",
"(",
")",
"]",
"[",
"$",
"resource",
"->",
"getT... | If full resource has not been added yet either to includes section.
@param ResourceInterface $resource
@return bool | [
"If",
"full",
"resource",
"has",
"not",
"been",
"added",
"yet",
"either",
"to",
"includes",
"section",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/Representation/DocumentWriter.php#L112-L115 | train |
neomerx/json-api | src/I18n/Messages.php | Messages.compose | public static function compose(string $message, ...$parameters): string
{
$translation = static::getTranslation($message);
$result = empty($parameters) === false ? \vsprintf($translation, $parameters) : $translation;
return $result;
} | php | public static function compose(string $message, ...$parameters): string
{
$translation = static::getTranslation($message);
$result = empty($parameters) === false ? \vsprintf($translation, $parameters) : $translation;
return $result;
} | [
"public",
"static",
"function",
"compose",
"(",
"string",
"$",
"message",
",",
"...",
"$",
"parameters",
")",
":",
"string",
"{",
"$",
"translation",
"=",
"static",
"::",
"getTranslation",
"(",
"$",
"message",
")",
";",
"$",
"result",
"=",
"empty",
"(",
... | Try to translate the message and format it with the given parameters.
@param string $message
@param mixed ...$parameters
@return string | [
"Try",
"to",
"translate",
"the",
"message",
"and",
"format",
"it",
"with",
"the",
"given",
"parameters",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/I18n/Messages.php#L39-L45 | train |
neomerx/json-api | src/Schema/SchemaContainer.php | SchemaContainer.register | public function register(string $type, $schema): void
{
if (empty($type) === true || \class_exists($type) === false) {
throw new InvalidArgumentException(_(static::MSG_INVALID_MODEL_TYPE));
}
$isOk = (
(
\is_string($schema) === true &&
empty($schema) === false &&
\class_exists($schema) === true &&
\in_array(SchemaInterface::class, \class_implements($schema)) === true
) ||
\is_callable($schema) ||
$schema instanceof SchemaInterface
);
if ($isOk === false) {
throw new InvalidArgumentException(_(static::MSG_INVALID_SCHEME, $type));
}
if ($this->hasProviderMapping($type) === true) {
throw new InvalidArgumentException(_(static::MSG_TYPE_REUSE_FORBIDDEN, $type));
}
if ($schema instanceof SchemaInterface) {
$this->setProviderMapping($type, \get_class($schema));
$this->setResourceToJsonTypeMapping($schema->getType(), $type);
$this->setCreatedProvider($type, $schema);
} else {
$this->setProviderMapping($type, $schema);
}
} | php | public function register(string $type, $schema): void
{
if (empty($type) === true || \class_exists($type) === false) {
throw new InvalidArgumentException(_(static::MSG_INVALID_MODEL_TYPE));
}
$isOk = (
(
\is_string($schema) === true &&
empty($schema) === false &&
\class_exists($schema) === true &&
\in_array(SchemaInterface::class, \class_implements($schema)) === true
) ||
\is_callable($schema) ||
$schema instanceof SchemaInterface
);
if ($isOk === false) {
throw new InvalidArgumentException(_(static::MSG_INVALID_SCHEME, $type));
}
if ($this->hasProviderMapping($type) === true) {
throw new InvalidArgumentException(_(static::MSG_TYPE_REUSE_FORBIDDEN, $type));
}
if ($schema instanceof SchemaInterface) {
$this->setProviderMapping($type, \get_class($schema));
$this->setResourceToJsonTypeMapping($schema->getType(), $type);
$this->setCreatedProvider($type, $schema);
} else {
$this->setProviderMapping($type, $schema);
}
} | [
"public",
"function",
"register",
"(",
"string",
"$",
"type",
",",
"$",
"schema",
")",
":",
"void",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
"===",
"true",
"||",
"\\",
"class_exists",
"(",
"$",
"type",
")",
"===",
"false",
")",
"{",
"throw",... | Register provider for resource type.
@param string $type
@param string|Closure $schema
@return void
@SuppressWarnings(PHPMD.StaticAccess)
@SuppressWarnings(PHPMD.ElseExpression)
@SuppressWarnings(PHPMD.CyclomaticComplexity) | [
"Register",
"provider",
"for",
"resource",
"type",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/Schema/SchemaContainer.php#L90-L121 | train |
neomerx/json-api | src/Schema/SchemaContainer.php | SchemaContainer.registerCollection | public function registerCollection(iterable $schemas): void
{
foreach ($schemas as $type => $schema) {
$this->register($type, $schema);
}
} | php | public function registerCollection(iterable $schemas): void
{
foreach ($schemas as $type => $schema) {
$this->register($type, $schema);
}
} | [
"public",
"function",
"registerCollection",
"(",
"iterable",
"$",
"schemas",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"schemas",
"as",
"$",
"type",
"=>",
"$",
"schema",
")",
"{",
"$",
"this",
"->",
"register",
"(",
"$",
"type",
",",
"$",
"schema",
... | Register providers for resource types.
@param iterable $schemas
@return void | [
"Register",
"providers",
"for",
"resource",
"types",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/Schema/SchemaContainer.php#L130-L135 | train |
neomerx/json-api | sample/Application/EncodeSamples.php | EncodeSamples.getBasicExample | public function getBasicExample(): string
{
$author = Author::instance('123', 'John', 'Dow');
$encoder = Encoder::instance([
Author::class => AuthorSchema::class,
])->withEncodeOptions(JSON_PRETTY_PRINT);
$result = $encoder->withUrlPrefix('http://example.com/api/v1')->encodeData($author);
return $result;
} | php | public function getBasicExample(): string
{
$author = Author::instance('123', 'John', 'Dow');
$encoder = Encoder::instance([
Author::class => AuthorSchema::class,
])->withEncodeOptions(JSON_PRETTY_PRINT);
$result = $encoder->withUrlPrefix('http://example.com/api/v1')->encodeData($author);
return $result;
} | [
"public",
"function",
"getBasicExample",
"(",
")",
":",
"string",
"{",
"$",
"author",
"=",
"Author",
"::",
"instance",
"(",
"'123'",
",",
"'John'",
",",
"'Dow'",
")",
";",
"$",
"encoder",
"=",
"Encoder",
"::",
"instance",
"(",
"[",
"Author",
"::",
"cla... | Get basic usage.
@return string | [
"Get",
"basic",
"usage",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/sample/Application/EncodeSamples.php#L41-L52 | train |
neomerx/json-api | sample/Application/EncodeSamples.php | EncodeSamples.getIncludedObjectsExample | public function getIncludedObjectsExample(): string
{
$author = Author::instance('123', 'John', 'Dow');
$comments = [
Comment::instance('456', 'Included objects work as easy as basic ones', $author),
Comment::instance('789', 'Let\'s try!', $author),
];
$post = Post::instance('321', 'Included objects', 'Yes, it is supported', $author, $comments);
$site = Site::instance('1', 'JSON API Samples', [$post]);
$encoder = Encoder::instance([
Author::class => AuthorSchema::class,
Comment::class => CommentSchema::class,
Post::class => PostSchema::class,
Site::class => SiteSchema::class
])->withEncodeOptions(JSON_PRETTY_PRINT);
$result = $encoder
->withUrlPrefix('http://example.com')
->withIncludedPaths([
'posts',
'posts.author',
'posts.comments',
])
->encodeData($site);
return $result;
} | php | public function getIncludedObjectsExample(): string
{
$author = Author::instance('123', 'John', 'Dow');
$comments = [
Comment::instance('456', 'Included objects work as easy as basic ones', $author),
Comment::instance('789', 'Let\'s try!', $author),
];
$post = Post::instance('321', 'Included objects', 'Yes, it is supported', $author, $comments);
$site = Site::instance('1', 'JSON API Samples', [$post]);
$encoder = Encoder::instance([
Author::class => AuthorSchema::class,
Comment::class => CommentSchema::class,
Post::class => PostSchema::class,
Site::class => SiteSchema::class
])->withEncodeOptions(JSON_PRETTY_PRINT);
$result = $encoder
->withUrlPrefix('http://example.com')
->withIncludedPaths([
'posts',
'posts.author',
'posts.comments',
])
->encodeData($site);
return $result;
} | [
"public",
"function",
"getIncludedObjectsExample",
"(",
")",
":",
"string",
"{",
"$",
"author",
"=",
"Author",
"::",
"instance",
"(",
"'123'",
",",
"'John'",
",",
"'Dow'",
")",
";",
"$",
"comments",
"=",
"[",
"Comment",
"::",
"instance",
"(",
"'456'",
",... | Get how objects are put to 'included'.
@return string | [
"Get",
"how",
"objects",
"are",
"put",
"to",
"included",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/sample/Application/EncodeSamples.php#L59-L86 | train |
neomerx/json-api | sample/Application/EncodeSamples.php | EncodeSamples.getDynamicSchemaExample | public function getDynamicSchemaExample(): array
{
$site = Site::instance('1', 'JSON API Samples', []);
$encoder = Encoder::instance([
Site::class => SiteSchema::class,
])->withEncodeOptions(JSON_PRETTY_PRINT);
SiteSchema::$isShowCustomLinks = false;
$noLinksResult = $encoder->encodeData($site);
SiteSchema::$isShowCustomLinks = true;
$withLinksResult = $encoder->encodeData($site);
return [
$noLinksResult,
$withLinksResult,
];
} | php | public function getDynamicSchemaExample(): array
{
$site = Site::instance('1', 'JSON API Samples', []);
$encoder = Encoder::instance([
Site::class => SiteSchema::class,
])->withEncodeOptions(JSON_PRETTY_PRINT);
SiteSchema::$isShowCustomLinks = false;
$noLinksResult = $encoder->encodeData($site);
SiteSchema::$isShowCustomLinks = true;
$withLinksResult = $encoder->encodeData($site);
return [
$noLinksResult,
$withLinksResult,
];
} | [
"public",
"function",
"getDynamicSchemaExample",
"(",
")",
":",
"array",
"{",
"$",
"site",
"=",
"Site",
"::",
"instance",
"(",
"'1'",
",",
"'JSON API Samples'",
",",
"[",
"]",
")",
";",
"$",
"encoder",
"=",
"Encoder",
"::",
"instance",
"(",
"[",
"Site",
... | Get how schema could change dynamically.
@return array | [
"Get",
"how",
"schema",
"could",
"change",
"dynamically",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/sample/Application/EncodeSamples.php#L172-L190 | train |
neomerx/json-api | sample/sample.php | Application.dynamicSchemaExample | private function dynamicSchemaExample(): void
{
echo 'Neomerx JSON API sample application (dynamic schema)' . PHP_EOL;
$results = $this->samples->getDynamicSchemaExample();
echo $results[0] . PHP_EOL;
echo $results[1] . PHP_EOL;
} | php | private function dynamicSchemaExample(): void
{
echo 'Neomerx JSON API sample application (dynamic schema)' . PHP_EOL;
$results = $this->samples->getDynamicSchemaExample();
echo $results[0] . PHP_EOL;
echo $results[1] . PHP_EOL;
} | [
"private",
"function",
"dynamicSchemaExample",
"(",
")",
":",
"void",
"{",
"echo",
"'Neomerx JSON API sample application (dynamic schema)'",
".",
"PHP_EOL",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"samples",
"->",
"getDynamicSchemaExample",
"(",
")",
";",
"echo... | Shows how schema could change dynamically.
@return void | [
"Shows",
"how",
"schema",
"could",
"change",
"dynamically",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/sample/sample.php#L90-L97 | train |
neomerx/json-api | src/Schema/BaseSchema.php | BaseSchema.getResourcesSubUrl | protected function getResourcesSubUrl(): string
{
if ($this->subUrl === null) {
$this->subUrl = '/' . $this->getType();
}
return $this->subUrl;
} | php | protected function getResourcesSubUrl(): string
{
if ($this->subUrl === null) {
$this->subUrl = '/' . $this->getType();
}
return $this->subUrl;
} | [
"protected",
"function",
"getResourcesSubUrl",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"subUrl",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"subUrl",
"=",
"'/'",
".",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"}",
"return",
... | Get resources sub-URL.
@return string | [
"Get",
"resources",
"sub",
"-",
"URL",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/Schema/BaseSchema.php#L157-L164 | train |
neomerx/json-api | src/Encoder/EncoderPropertiesTrait.php | EncoderPropertiesTrait.reset | public function reset(
string $urlPrefix = Encoder::DEFAULT_URL_PREFIX,
iterable $includePaths = Encoder::DEFAULT_INCLUDE_PATHS,
array $fieldSets = Encoder::DEFAULT_FIELD_SET_FILTERS,
int $encodeOptions = Encoder::DEFAULT_JSON_ENCODE_OPTIONS,
int $encodeDepth = Encoder::DEFAULT_JSON_ENCODE_DEPTH
): EncoderInterface {
$this->links = null;
$this->profile = null;
$this->hasMeta = false;
$this->meta = null;
$this->jsonApiVersion = null;
$this->jsonApiMeta = null;
$this->hasJsonApiMeta = false;
$this
->withUrlPrefix($urlPrefix)
->withIncludedPaths($includePaths)
->withFieldSets($fieldSets)
->withEncodeOptions($encodeOptions)
->withEncodeDepth($encodeDepth);
return $this;
} | php | public function reset(
string $urlPrefix = Encoder::DEFAULT_URL_PREFIX,
iterable $includePaths = Encoder::DEFAULT_INCLUDE_PATHS,
array $fieldSets = Encoder::DEFAULT_FIELD_SET_FILTERS,
int $encodeOptions = Encoder::DEFAULT_JSON_ENCODE_OPTIONS,
int $encodeDepth = Encoder::DEFAULT_JSON_ENCODE_DEPTH
): EncoderInterface {
$this->links = null;
$this->profile = null;
$this->hasMeta = false;
$this->meta = null;
$this->jsonApiVersion = null;
$this->jsonApiMeta = null;
$this->hasJsonApiMeta = false;
$this
->withUrlPrefix($urlPrefix)
->withIncludedPaths($includePaths)
->withFieldSets($fieldSets)
->withEncodeOptions($encodeOptions)
->withEncodeDepth($encodeDepth);
return $this;
} | [
"public",
"function",
"reset",
"(",
"string",
"$",
"urlPrefix",
"=",
"Encoder",
"::",
"DEFAULT_URL_PREFIX",
",",
"iterable",
"$",
"includePaths",
"=",
"Encoder",
"::",
"DEFAULT_INCLUDE_PATHS",
",",
"array",
"$",
"fieldSets",
"=",
"Encoder",
"::",
"DEFAULT_FIELD_SE... | Reset to initial state.
@param string $urlPrefix
@param iterable $includePaths
@param array $fieldSets
@param int $encodeOptions
@param int $encodeDepth
@return self|EncoderInterface | [
"Reset",
"to",
"initial",
"state",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/Encoder/EncoderPropertiesTrait.php#L113-L136 | train |
neomerx/json-api | src/Encoder/Encoder.php | Encoder.instance | public static function instance(array $schemas = []): EncoderInterface
{
$factory = static::createFactory();
$container = $factory->createSchemaContainer($schemas);
$encoder = $factory->createEncoder($container);
return $encoder;
} | php | public static function instance(array $schemas = []): EncoderInterface
{
$factory = static::createFactory();
$container = $factory->createSchemaContainer($schemas);
$encoder = $factory->createEncoder($container);
return $encoder;
} | [
"public",
"static",
"function",
"instance",
"(",
"array",
"$",
"schemas",
"=",
"[",
"]",
")",
":",
"EncoderInterface",
"{",
"$",
"factory",
"=",
"static",
"::",
"createFactory",
"(",
")",
";",
"$",
"container",
"=",
"$",
"factory",
"->",
"createSchemaConta... | Create encoder instance.
@param array $schemas Schema providers.
@return EncoderInterface | [
"Create",
"encoder",
"instance",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/Encoder/Encoder.php#L91-L98 | train |
neomerx/json-api | src/Parser/IdentifierAndResource.php | IdentifierAndResource.cacheLinks | private function cacheLinks(): void
{
if ($this->links === null) {
$this->links = [];
foreach ($this->schema->getLinks($this->data) as $name => $link) {
\assert(\is_string($name) === true && empty($name) === false);
\assert($link instanceof LinkInterface);
$this->links[$name] = $link;
}
}
} | php | private function cacheLinks(): void
{
if ($this->links === null) {
$this->links = [];
foreach ($this->schema->getLinks($this->data) as $name => $link) {
\assert(\is_string($name) === true && empty($name) === false);
\assert($link instanceof LinkInterface);
$this->links[$name] = $link;
}
}
} | [
"private",
"function",
"cacheLinks",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"links",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"links",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"->",
"getLinks",
"(",
"... | Read and parse links from schema. | [
"Read",
"and",
"parse",
"links",
"from",
"schema",
"."
] | 1807c3b6bebdfbec4690b8da2e6cdeb94048c94e | https://github.com/neomerx/json-api/blob/1807c3b6bebdfbec4690b8da2e6cdeb94048c94e/src/Parser/IdentifierAndResource.php#L258-L268 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Builders/Modules/BinariesBuilder.php | BinariesBuilder.buildBinary | public function buildBinary($binary)
{
$class = $this->modulable->findQualifiedName($binary, 'binaries');
// If there is a class by that name
if ($class) {
return new $class($this->container);
}
// Else wrap the command in an AnonymousBinary
$anonymous = new AnonymousBinary($this->container);
$anonymous->setBinary($this->bash->which($binary));
return $anonymous;
} | php | public function buildBinary($binary)
{
$class = $this->modulable->findQualifiedName($binary, 'binaries');
// If there is a class by that name
if ($class) {
return new $class($this->container);
}
// Else wrap the command in an AnonymousBinary
$anonymous = new AnonymousBinary($this->container);
$anonymous->setBinary($this->bash->which($binary));
return $anonymous;
} | [
"public",
"function",
"buildBinary",
"(",
"$",
"binary",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"modulable",
"->",
"findQualifiedName",
"(",
"$",
"binary",
",",
"'binaries'",
")",
";",
"// If there is a class by that name",
"if",
"(",
"$",
"class",
... | Build a binary.
@param string $binary
@return \Rocketeer\Binaries\AbstractBinary|\Rocketeer\Binaries\PackageManagers\AbstractPackageManager | [
"Build",
"a",
"binary",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Builders/Modules/BinariesBuilder.php#L29-L43 | train |
rocketeers/rocketeer | src/Rocketeer/Binaries/Php.php | Php.isHhvm | public function isHhvm()
{
$isHhvm = $this->getCommand(null, null, '-r "print defined(\'HHVM_VERSION\');"');
$isHhvm = $this->bash->runRaw($isHhvm);
$isHhvm = $isHhvm === '1';
return $isHhvm;
} | php | public function isHhvm()
{
$isHhvm = $this->getCommand(null, null, '-r "print defined(\'HHVM_VERSION\');"');
$isHhvm = $this->bash->runRaw($isHhvm);
$isHhvm = $isHhvm === '1';
return $isHhvm;
} | [
"public",
"function",
"isHhvm",
"(",
")",
"{",
"$",
"isHhvm",
"=",
"$",
"this",
"->",
"getCommand",
"(",
"null",
",",
"null",
",",
"'-r \"print defined(\\'HHVM_VERSION\\');\"'",
")",
";",
"$",
"isHhvm",
"=",
"$",
"this",
"->",
"bash",
"->",
"runRaw",
"(",
... | Whether this PHP installation is an HHVM one or not.
@return bool | [
"Whether",
"this",
"PHP",
"installation",
"is",
"an",
"HHVM",
"one",
"or",
"not",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Binaries/Php.php#L57-L64 | train |
rocketeers/rocketeer | src/Rocketeer/Tasks/Ignite.php | Ignite.exportConfiguration | protected function exportConfiguration()
{
$format = $this->command->choice('What format do you want your configuration in?', ConfigurationPublisher::$formats, 'php');
$consolidated = $this->command->confirm('Do you want it consolidated (one file instead of many?', false);
// Export configuration
$this->igniter->exportConfiguration($format, $consolidated);
$path = $this->paths->getRocketeerPath();
// Summary
$folder = basename(dirname($path)).'/'.basename($path);
$this->command->writeln('<info>Your configuration was exported at</info> <comment>'.$folder.'</comment>.');
return $path;
} | php | protected function exportConfiguration()
{
$format = $this->command->choice('What format do you want your configuration in?', ConfigurationPublisher::$formats, 'php');
$consolidated = $this->command->confirm('Do you want it consolidated (one file instead of many?', false);
// Export configuration
$this->igniter->exportConfiguration($format, $consolidated);
$path = $this->paths->getRocketeerPath();
// Summary
$folder = basename(dirname($path)).'/'.basename($path);
$this->command->writeln('<info>Your configuration was exported at</info> <comment>'.$folder.'</comment>.');
return $path;
} | [
"protected",
"function",
"exportConfiguration",
"(",
")",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"command",
"->",
"choice",
"(",
"'What format do you want your configuration in?'",
",",
"ConfigurationPublisher",
"::",
"$",
"formats",
",",
"'php'",
")",
";",
"... | Export the configuration to file.
@return string | [
"Export",
"the",
"configuration",
"to",
"file",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Tasks/Ignite.php#L80-L94 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Bash.php | Bash.getConnection | public function getConnection()
{
if ($this->rocketeer->isLocal()) {
return $this->connections->getConnection('local');
}
return $this->connections->getCurrentConnection();
} | php | public function getConnection()
{
if ($this->rocketeer->isLocal()) {
return $this->connections->getConnection('local');
}
return $this->connections->getCurrentConnection();
} | [
"public",
"function",
"getConnection",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"rocketeer",
"->",
"isLocal",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"connections",
"->",
"getConnection",
"(",
"'local'",
")",
";",
"}",
"return",
"$",
"this... | Get which Connection to call commands with.
@return \Rocketeer\Services\Connections\Connections\ConnectionInterface | [
"Get",
"which",
"Connection",
"to",
"call",
"commands",
"with",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Bash.php#L50-L57 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Bash.php | Bash.getStrategy | public function getStrategy($strategy, $concrete = null, $options = [])
{
// Try to build the strategy
$strategy = $this->builder->buildStrategy($strategy, $concrete);
if (!$strategy || !$strategy->isExecutable()) {
return;
}
// Configure strategy
if ($options || $this->options) {
$options = array_replace((array) $options, $strategy->getOptions(), $this->options);
$strategy = $strategy->setOptions($options);
}
return $this->explainer->displayBelow(function () use ($strategy) {
return $strategy->displayStatus();
});
} | php | public function getStrategy($strategy, $concrete = null, $options = [])
{
// Try to build the strategy
$strategy = $this->builder->buildStrategy($strategy, $concrete);
if (!$strategy || !$strategy->isExecutable()) {
return;
}
// Configure strategy
if ($options || $this->options) {
$options = array_replace((array) $options, $strategy->getOptions(), $this->options);
$strategy = $strategy->setOptions($options);
}
return $this->explainer->displayBelow(function () use ($strategy) {
return $strategy->displayStatus();
});
} | [
"public",
"function",
"getStrategy",
"(",
"$",
"strategy",
",",
"$",
"concrete",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"// Try to build the strategy",
"$",
"strategy",
"=",
"$",
"this",
"->",
"builder",
"->",
"buildStrategy",
"(",
"$",... | Get the implementation behind a strategy.
@param string $strategy
@param string|null $concrete
@param array $options
@return \Rocketeer\Strategies\AbstractStrategy | [
"Get",
"the",
"implementation",
"behind",
"a",
"strategy",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Bash.php#L89-L106 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Bash.php | Bash.executeTask | public function executeTask($tasks)
{
return $this->explainer->displayBelow(function () use ($tasks) {
return $this->builder->buildTask($tasks)->fire();
});
} | php | public function executeTask($tasks)
{
return $this->explainer->displayBelow(function () use ($tasks) {
return $this->builder->buildTask($tasks)->fire();
});
} | [
"public",
"function",
"executeTask",
"(",
"$",
"tasks",
")",
"{",
"return",
"$",
"this",
"->",
"explainer",
"->",
"displayBelow",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"tasks",
")",
"{",
"return",
"$",
"this",
"->",
"builder",
"->",
"buildTask",
... | Execute another task by name.
@param string $tasks
@return string|false | [
"Execute",
"another",
"task",
"by",
"name",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Bash.php#L115-L120 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Roles/HasRolesTrait.php | HasRolesTrait.isCompatibleWith | public function isCompatibleWith(HasRolesInterface $hasRoles)
{
$roles = $hasRoles->getRoles();
$filled = array_intersect($this->roles, $roles);
return is_null($roles) || count($filled) === count($roles);
} | php | public function isCompatibleWith(HasRolesInterface $hasRoles)
{
$roles = $hasRoles->getRoles();
$filled = array_intersect($this->roles, $roles);
return is_null($roles) || count($filled) === count($roles);
} | [
"public",
"function",
"isCompatibleWith",
"(",
"HasRolesInterface",
"$",
"hasRoles",
")",
"{",
"$",
"roles",
"=",
"$",
"hasRoles",
"->",
"getRoles",
"(",
")",
";",
"$",
"filled",
"=",
"array_intersect",
"(",
"$",
"this",
"->",
"roles",
",",
"$",
"roles",
... | Check if an entity is compatible with another.
@param HasRolesInterface $hasRoles
@return bool | [
"Check",
"if",
"an",
"entity",
"is",
"compatible",
"with",
"another",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Roles/HasRolesTrait.php#L60-L66 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/AbstractPolyglotStrategy.php | AbstractPolyglotStrategy.executeStrategiesMethod | protected function executeStrategiesMethod($method)
{
$this->onStrategies(function (AbstractStrategy $strategy) use ($method) {
return $strategy->$method();
});
return $this->passed();
} | php | protected function executeStrategiesMethod($method)
{
$this->onStrategies(function (AbstractStrategy $strategy) use ($method) {
return $strategy->$method();
});
return $this->passed();
} | [
"protected",
"function",
"executeStrategiesMethod",
"(",
"$",
"method",
")",
"{",
"$",
"this",
"->",
"onStrategies",
"(",
"function",
"(",
"AbstractStrategy",
"$",
"strategy",
")",
"use",
"(",
"$",
"method",
")",
"{",
"return",
"$",
"strategy",
"->",
"$",
... | Execute a method on all sub-strategies.
@param string $method
@return bool | [
"Execute",
"a",
"method",
"on",
"all",
"sub",
"-",
"strategies",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/AbstractPolyglotStrategy.php#L48-L55 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/AbstractPolyglotStrategy.php | AbstractPolyglotStrategy.checkStrategiesResults | protected function checkStrategiesResults($results)
{
$results = array_filter($results, function ($value) {
return $value !== false && (!is_string($value) || mb_strpos($value, 'not found') === false);
});
return count($results) === count($this->strategies);
} | php | protected function checkStrategiesResults($results)
{
$results = array_filter($results, function ($value) {
return $value !== false && (!is_string($value) || mb_strpos($value, 'not found') === false);
});
return count($results) === count($this->strategies);
} | [
"protected",
"function",
"checkStrategiesResults",
"(",
"$",
"results",
")",
"{",
"$",
"results",
"=",
"array_filter",
"(",
"$",
"results",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"false",
"&&",
"(",
"!",
"is_string",
... | Assert that the results of a command are all true.
@param bool[] $results
@return bool | [
"Assert",
"that",
"the",
"results",
"of",
"a",
"command",
"are",
"all",
"true",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/AbstractPolyglotStrategy.php#L115-L122 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.symlink | public function symlink($folder, $symlink)
{
if (!$this->fileExists($folder)) {
if (!$this->fileExists($symlink)) {
return false;
}
$this->move($symlink, $folder);
}
// Switch to relative if required
if ($this->config->getContextually('remote.symlink') === 'relative') {
$folder = $this->paths->computeRelativePathBetween($symlink, $folder);
}
switch ($this->environment->getOperatingSystem()) {
case 'Linux':
return $this->symlinkSwap($folder, $symlink);
default:
if ($this->fileExists($symlink)) {
$this->removeFolder($symlink);
}
return $this->modulable->run([
sprintf('ln -s %s %s', $folder, $symlink),
]);
}
} | php | public function symlink($folder, $symlink)
{
if (!$this->fileExists($folder)) {
if (!$this->fileExists($symlink)) {
return false;
}
$this->move($symlink, $folder);
}
// Switch to relative if required
if ($this->config->getContextually('remote.symlink') === 'relative') {
$folder = $this->paths->computeRelativePathBetween($symlink, $folder);
}
switch ($this->environment->getOperatingSystem()) {
case 'Linux':
return $this->symlinkSwap($folder, $symlink);
default:
if ($this->fileExists($symlink)) {
$this->removeFolder($symlink);
}
return $this->modulable->run([
sprintf('ln -s %s %s', $folder, $symlink),
]);
}
} | [
"public",
"function",
"symlink",
"(",
"$",
"folder",
",",
"$",
"symlink",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fileExists",
"(",
"$",
"folder",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fileExists",
"(",
"$",
"symlink",
")",
")"... | Symlinks two folders.
@param string $folder The folder in shared/
@param string $symlink The folder that will symlink to it
@return string | [
"Symlinks",
"two",
"folders",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L44-L71 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.symlinkSwap | protected function symlinkSwap($folder, $symlink)
{
if ($this->fileExists($symlink) && !$this->isSymlink($symlink)) {
$this->removeFolder($symlink);
}
// Define name of temporary link
$temporary = $symlink.'-temp';
return $this->modulable->run([
sprintf('ln -s %s %s', $folder, $temporary),
sprintf('mv -Tf %s %s', $temporary, $symlink),
]);
} | php | protected function symlinkSwap($folder, $symlink)
{
if ($this->fileExists($symlink) && !$this->isSymlink($symlink)) {
$this->removeFolder($symlink);
}
// Define name of temporary link
$temporary = $symlink.'-temp';
return $this->modulable->run([
sprintf('ln -s %s %s', $folder, $temporary),
sprintf('mv -Tf %s %s', $temporary, $symlink),
]);
} | [
"protected",
"function",
"symlinkSwap",
"(",
"$",
"folder",
",",
"$",
"symlink",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fileExists",
"(",
"$",
"symlink",
")",
"&&",
"!",
"$",
"this",
"->",
"isSymlink",
"(",
"$",
"symlink",
")",
")",
"{",
"$",
"th... | Swap a symlink if possible.
@param string $folder
@param string $symlink
@return string | [
"Swap",
"a",
"symlink",
"if",
"possible",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L81-L94 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.listContents | public function listContents($directory)
{
$files = $this->modulable->getConnection()->listContents($directory);
$files = array_pluck($files, 'path');
$files = array_map('basename', $files);
return $files;
} | php | public function listContents($directory)
{
$files = $this->modulable->getConnection()->listContents($directory);
$files = array_pluck($files, 'path');
$files = array_map('basename', $files);
return $files;
} | [
"public",
"function",
"listContents",
"(",
"$",
"directory",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"modulable",
"->",
"getConnection",
"(",
")",
"->",
"listContents",
"(",
"$",
"directory",
")",
";",
"$",
"files",
"=",
"array_pluck",
"(",
"$",
... | Get the contents of a directory.
@param string $directory
@return array | [
"Get",
"the",
"contents",
"of",
"a",
"directory",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L133-L140 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.setPermissions | public function setPermissions($folder)
{
// Get path to folder
$folder = $this->releasesManager->getCurrentReleasePath($folder);
$this->explainer->line('Setting permissions for '.$folder);
// Get permissions options
$callback = $this->config->getContextually('remote.permissions.callback');
$commands = (array) $callback($folder, $this);
// Cancel if setting of permissions is not configured
if (empty($commands)) {
return true;
}
return $this->modulable->runForCurrentRelease($commands);
} | php | public function setPermissions($folder)
{
// Get path to folder
$folder = $this->releasesManager->getCurrentReleasePath($folder);
$this->explainer->line('Setting permissions for '.$folder);
// Get permissions options
$callback = $this->config->getContextually('remote.permissions.callback');
$commands = (array) $callback($folder, $this);
// Cancel if setting of permissions is not configured
if (empty($commands)) {
return true;
}
return $this->modulable->runForCurrentRelease($commands);
} | [
"public",
"function",
"setPermissions",
"(",
"$",
"folder",
")",
"{",
"// Get path to folder",
"$",
"folder",
"=",
"$",
"this",
"->",
"releasesManager",
"->",
"getCurrentReleasePath",
"(",
"$",
"folder",
")",
";",
"$",
"this",
"->",
"explainer",
"->",
"line",
... | Execute permissions actions on a file with the provided callback.
@param string $folder
@return string | [
"Execute",
"permissions",
"actions",
"on",
"a",
"file",
"with",
"the",
"provided",
"callback",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L161-L177 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.upload | public function upload($file, $destination = null)
{
if (!file_exists($file)) {
return;
}
// Get contents and destination
$destination = $destination ?: basename($file);
$this->put($destination, file_get_contents($file));
} | php | public function upload($file, $destination = null)
{
if (!file_exists($file)) {
return;
}
// Get contents and destination
$destination = $destination ?: basename($file);
$this->put($destination, file_get_contents($file));
} | [
"public",
"function",
"upload",
"(",
"$",
"file",
",",
"$",
"destination",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
";",
"}",
"// Get contents and destination",
"$",
"destination",
"=",
"$",
"destin... | Upload a local file to remote.
@param string $file
@param string|null $destination | [
"Upload",
"a",
"local",
"file",
"to",
"remote",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L212-L222 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.tail | public function tail($file, $continuous = true)
{
$continuous = $continuous ? ' -f' : null;
$command = sprintf('tail %s %s', $file, $continuous);
return $this->modulable->run($command);
} | php | public function tail($file, $continuous = true)
{
$continuous = $continuous ? ' -f' : null;
$command = sprintf('tail %s %s', $file, $continuous);
return $this->modulable->run($command);
} | [
"public",
"function",
"tail",
"(",
"$",
"file",
",",
"$",
"continuous",
"=",
"true",
")",
"{",
"$",
"continuous",
"=",
"$",
"continuous",
"?",
"' -f'",
":",
"null",
";",
"$",
"command",
"=",
"sprintf",
"(",
"'tail %s %s'",
",",
"$",
"file",
",",
"$",... | Tail the contents of a file.
@param string $file
@param bool $continuous
@return string|null | [
"Tail",
"the",
"contents",
"of",
"a",
"file",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L232-L238 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.createFolder | public function createFolder($folder = null)
{
$folder = $this->paths->getFolder($folder);
$this->modulable->toHistory('mkdir '.$folder);
return $this->modulable->getConnection()->createDir($folder);
} | php | public function createFolder($folder = null)
{
$folder = $this->paths->getFolder($folder);
$this->modulable->toHistory('mkdir '.$folder);
return $this->modulable->getConnection()->createDir($folder);
} | [
"public",
"function",
"createFolder",
"(",
"$",
"folder",
"=",
"null",
")",
"{",
"$",
"folder",
"=",
"$",
"this",
"->",
"paths",
"->",
"getFolder",
"(",
"$",
"folder",
")",
";",
"$",
"this",
"->",
"modulable",
"->",
"toHistory",
"(",
"'mkdir '",
".",
... | Create a folder in the application's folder.
@param string|null $folder The folder to create
@return string The task | [
"Create",
"a",
"folder",
"in",
"the",
"application",
"s",
"folder",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L251-L257 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.removeFolder | public function removeFolder($folders = null)
{
$folders = (array) $folders;
$folders = array_map([$this->paths, 'getFolder'], $folders);
$folders = implode(' ', $folders);
return $this->modulable->run('rm -rf '.$folders);
} | php | public function removeFolder($folders = null)
{
$folders = (array) $folders;
$folders = array_map([$this->paths, 'getFolder'], $folders);
$folders = implode(' ', $folders);
return $this->modulable->run('rm -rf '.$folders);
} | [
"public",
"function",
"removeFolder",
"(",
"$",
"folders",
"=",
"null",
")",
"{",
"$",
"folders",
"=",
"(",
"array",
")",
"$",
"folders",
";",
"$",
"folders",
"=",
"array_map",
"(",
"[",
"$",
"this",
"->",
"paths",
",",
"'getFolder'",
"]",
",",
"$",
... | Remove a folder in the application's folder.
@param array|string|null $folders The folder to remove
@return string The task | [
"Remove",
"a",
"folder",
"in",
"the",
"application",
"s",
"folder",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L266-L273 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php | Filesystem.checkStatement | protected function checkStatement($condition)
{
$condition = '[ '.$condition.' ] && echo "true"';
$condition = $this->modulable->runRaw($condition);
return trim($condition) === 'true';
} | php | protected function checkStatement($condition)
{
$condition = '[ '.$condition.' ] && echo "true"';
$condition = $this->modulable->runRaw($condition);
return trim($condition) === 'true';
} | [
"protected",
"function",
"checkStatement",
"(",
"$",
"condition",
")",
"{",
"$",
"condition",
"=",
"'[ '",
".",
"$",
"condition",
".",
"' ] && echo \"true\"'",
";",
"$",
"condition",
"=",
"$",
"this",
"->",
"modulable",
"->",
"runRaw",
"(",
"$",
"condition",... | Check a condition via Bash.
@param string $condition
@return bool | [
"Check",
"a",
"condition",
"via",
"Bash",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Filesystem.php#L286-L292 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Config/ContextualConfiguration.php | ContextualConfiguration.getPluginOption | public function getPluginOption($plugin, $option = null)
{
$option = $option ? '.'.$option : '';
return $this->config->get('plugins.config.'.$plugin.$option);
} | php | public function getPluginOption($plugin, $option = null)
{
$option = $option ? '.'.$option : '';
return $this->config->get('plugins.config.'.$plugin.$option);
} | [
"public",
"function",
"getPluginOption",
"(",
"$",
"plugin",
",",
"$",
"option",
"=",
"null",
")",
"{",
"$",
"option",
"=",
"$",
"option",
"?",
"'.'",
".",
"$",
"option",
":",
"''",
";",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'pl... | Get an option for a plugin.
@param string $plugin
@param string|null $option
@return mixed | [
"Get",
"an",
"option",
"for",
"a",
"plugin",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Config/ContextualConfiguration.php#L92-L97 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Config/ContextualConfiguration.php | ContextualConfiguration.getContextually | public function getContextually($option, ConnectionKey $connectionKey = null)
{
$original = $this->configuration->get($option);
$connectionKey = $connectionKey ?: $this->connections->getCurrentConnectionKey();
$contexts = ['stages', 'connections', 'servers'];
foreach ($contexts as $context) {
if ($contextual = $this->getForContext($option, $context, $original, $connectionKey)) {
return $contextual;
}
}
return $original;
} | php | public function getContextually($option, ConnectionKey $connectionKey = null)
{
$original = $this->configuration->get($option);
$connectionKey = $connectionKey ?: $this->connections->getCurrentConnectionKey();
$contexts = ['stages', 'connections', 'servers'];
foreach ($contexts as $context) {
if ($contextual = $this->getForContext($option, $context, $original, $connectionKey)) {
return $contextual;
}
}
return $original;
} | [
"public",
"function",
"getContextually",
"(",
"$",
"option",
",",
"ConnectionKey",
"$",
"connectionKey",
"=",
"null",
")",
"{",
"$",
"original",
"=",
"$",
"this",
"->",
"configuration",
"->",
"get",
"(",
"$",
"option",
")",
";",
"$",
"connectionKey",
"=",
... | Get an option from Rocketeer's config file.
@param string $option
@param ConnectionKey|null $connectionKey
@return array|Closure|string | [
"Get",
"an",
"option",
"from",
"Rocketeer",
"s",
"config",
"file",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Config/ContextualConfiguration.php#L107-L120 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Config/ContextualConfiguration.php | ContextualConfiguration.getForContext | protected function getForContext($option, $type, $original, ConnectionKey $connectionKey)
{
// Switch context
switch ($type) {
case 'servers':
$contextual = sprintf('connections.%s.servers.%d.config.%s', $connectionKey->name, $connectionKey->server, $option);
break;
case 'stages':
$contextual = sprintf('on.stages.%s.%s', $connectionKey->stage, $option);
break;
case 'connections':
$contextual = sprintf('on.connections.%s.%s', $connectionKey->name, $option);
break;
default:
$contextual = $option;
break;
}
// Merge with defaults
$value = $this->configuration->get($contextual);
if (is_array($value) && $original) {
$value = array_replace($original, $value);
}
return $value;
} | php | protected function getForContext($option, $type, $original, ConnectionKey $connectionKey)
{
// Switch context
switch ($type) {
case 'servers':
$contextual = sprintf('connections.%s.servers.%d.config.%s', $connectionKey->name, $connectionKey->server, $option);
break;
case 'stages':
$contextual = sprintf('on.stages.%s.%s', $connectionKey->stage, $option);
break;
case 'connections':
$contextual = sprintf('on.connections.%s.%s', $connectionKey->name, $option);
break;
default:
$contextual = $option;
break;
}
// Merge with defaults
$value = $this->configuration->get($contextual);
if (is_array($value) && $original) {
$value = array_replace($original, $value);
}
return $value;
} | [
"protected",
"function",
"getForContext",
"(",
"$",
"option",
",",
"$",
"type",
",",
"$",
"original",
",",
"ConnectionKey",
"$",
"connectionKey",
")",
"{",
"// Switch context",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'servers'",
":",
"$",
"contextual"... | Get a contextual option.
@param string $option
@param string $type
@param string|array|null $original
@param ConnectionKey|null $connectionKey
@return array|Closure|string | [
"Get",
"a",
"contextual",
"option",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Config/ContextualConfiguration.php#L132-L160 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Binaries.php | Binaries.which | public function which($binary, $fallback = null, $prompt = true)
{
$locations = [
$this->paths->getPath($binary),
$this->localStorage->get($this->getBinaryStoragePath($binary)),
$binary,
];
// Add fallback if provided
if ($fallback) {
$locations[] = $fallback;
}
// Add command prompt if possible
if ($this->hasCommand() && $prompt) {
$prompt = 'Binary "'.$binary.'" could not be found, please enter the path to it';
$locations[] = [$this->command, 'ask', $prompt];
}
return $this->whichFrom($binary, $locations);
} | php | public function which($binary, $fallback = null, $prompt = true)
{
$locations = [
$this->paths->getPath($binary),
$this->localStorage->get($this->getBinaryStoragePath($binary)),
$binary,
];
// Add fallback if provided
if ($fallback) {
$locations[] = $fallback;
}
// Add command prompt if possible
if ($this->hasCommand() && $prompt) {
$prompt = 'Binary "'.$binary.'" could not be found, please enter the path to it';
$locations[] = [$this->command, 'ask', $prompt];
}
return $this->whichFrom($binary, $locations);
} | [
"public",
"function",
"which",
"(",
"$",
"binary",
",",
"$",
"fallback",
"=",
"null",
",",
"$",
"prompt",
"=",
"true",
")",
"{",
"$",
"locations",
"=",
"[",
"$",
"this",
"->",
"paths",
"->",
"getPath",
"(",
"$",
"binary",
")",
",",
"$",
"this",
"... | Get the path to a binary.
@param string $binary The name of the binary
@param string|null $fallback A fallback location
@param bool $prompt
@return string | [
"Get",
"the",
"path",
"to",
"a",
"binary",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Binaries.php#L82-L102 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Binaries.php | Binaries.whichFrom | protected function whichFrom($binary, array $locations)
{
$location = false;
// Look in all the locations
$tryout = 0;
while (!$location && array_key_exists($tryout, $locations)) {
// Execute method if required
$location = $locations[$tryout];
if (is_array($location)) {
list($object, $method, $argument) = $location;
$location = $object->$method($argument);
}
// Verify existence of returned path
if ($location && $location !== $this->paths->getPath($binary)) {
$location = $this->rawWhich($location);
}
++$tryout;
}
// Store found location or remove it if invalid
if (!$this->modulable->connections->is('local')) {
if ($location) {
$this->localStorage->set($this->getBinaryStoragePath($binary), $location);
} else {
$this->localStorage->forget($this->getBinaryStoragePath($binary));
}
}
return $location ?: $binary;
} | php | protected function whichFrom($binary, array $locations)
{
$location = false;
// Look in all the locations
$tryout = 0;
while (!$location && array_key_exists($tryout, $locations)) {
// Execute method if required
$location = $locations[$tryout];
if (is_array($location)) {
list($object, $method, $argument) = $location;
$location = $object->$method($argument);
}
// Verify existence of returned path
if ($location && $location !== $this->paths->getPath($binary)) {
$location = $this->rawWhich($location);
}
++$tryout;
}
// Store found location or remove it if invalid
if (!$this->modulable->connections->is('local')) {
if ($location) {
$this->localStorage->set($this->getBinaryStoragePath($binary), $location);
} else {
$this->localStorage->forget($this->getBinaryStoragePath($binary));
}
}
return $location ?: $binary;
} | [
"protected",
"function",
"whichFrom",
"(",
"$",
"binary",
",",
"array",
"$",
"locations",
")",
"{",
"$",
"location",
"=",
"false",
";",
"// Look in all the locations",
"$",
"tryout",
"=",
"0",
";",
"while",
"(",
"!",
"$",
"location",
"&&",
"array_key_exists"... | Scan an array of locations for a binary.
@param string $binary
@param array $locations
@return string | [
"Scan",
"an",
"array",
"of",
"locations",
"for",
"a",
"binary",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Binaries.php#L112-L144 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Binaries.php | Binaries.rawWhich | public function rawWhich($location)
{
$location = $this->modulable->runSilently('which '.$location);
if (mb_strpos($location, 'not found') !== false || mb_strpos($location, 'in (') !== false) {
return false;
}
return $location;
} | php | public function rawWhich($location)
{
$location = $this->modulable->runSilently('which '.$location);
if (mb_strpos($location, 'not found') !== false || mb_strpos($location, 'in (') !== false) {
return false;
}
return $location;
} | [
"public",
"function",
"rawWhich",
"(",
"$",
"location",
")",
"{",
"$",
"location",
"=",
"$",
"this",
"->",
"modulable",
"->",
"runSilently",
"(",
"'which '",
".",
"$",
"location",
")",
";",
"if",
"(",
"mb_strpos",
"(",
"$",
"location",
",",
"'not found'"... | Do a straight call to which.
@param string $location
@return string|false | [
"Do",
"a",
"straight",
"call",
"to",
"which",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Binaries.php#L153-L161 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/AbstractStrategy.php | AbstractStrategy.getType | public function getType()
{
$name = get_class($this);
$name = explode('\\', $name);
$name = $name[count($name) - 2];
return $name;
} | php | public function getType()
{
$name = get_class($this);
$name = explode('\\', $name);
$name = $name[count($name) - 2];
return $name;
} | [
"public",
"function",
"getType",
"(",
")",
"{",
"$",
"name",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"name",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"name",
")",
";",
"$",
"name",
"=",
"$",
"name",
"[",
"count",
"(",
"$",
"name",
")... | Get the type of strategy.
@return string | [
"Get",
"the",
"type",
"of",
"strategy",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/AbstractStrategy.php#L58-L65 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php | CredentialsGatherer.getRepositoryCredentials | public function getRepositoryCredentials()
{
$endpoint = $this->vcs->runLocally('currentEndpoint');
$user = $this->bash->runLocally('whoami');
return $this->askQuestions('vcs', [
'repository' => ['Where is your code located?', $endpoint],
'username' => ['What is the username for it?', $user],
'password' => 'And the password?',
]);
} | php | public function getRepositoryCredentials()
{
$endpoint = $this->vcs->runLocally('currentEndpoint');
$user = $this->bash->runLocally('whoami');
return $this->askQuestions('vcs', [
'repository' => ['Where is your code located?', $endpoint],
'username' => ['What is the username for it?', $user],
'password' => 'And the password?',
]);
} | [
"public",
"function",
"getRepositoryCredentials",
"(",
")",
"{",
"$",
"endpoint",
"=",
"$",
"this",
"->",
"vcs",
"->",
"runLocally",
"(",
"'currentEndpoint'",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"bash",
"->",
"runLocally",
"(",
"'whoami'",
")",
... | Get the Repository's credentials.
@return array | [
"Get",
"the",
"Repository",
"s",
"credentials",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php#L51-L61 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php | CredentialsGatherer.getConnectionsCredentials | public function getConnectionsCredentials()
{
$connectionName = null;
if ($this->connections) {
$this->presentConnections($this->connections);
if ($this->command->confirm('Do you want to add a connection to this?', false)) {
$connectionName = $this->command->ask('What do you want to name it?');
}
} else {
$connectionName = $this->command->ask('No connections have been set, let\'s create one, what do you want to name it?', 'production');
}
// If the user does not want to add any more connection
// then we can quit
if (!$connectionName) {
return $this->connections;
}
$this->getConnectionCredentials($connectionName);
return $this->getConnectionsCredentials();
} | php | public function getConnectionsCredentials()
{
$connectionName = null;
if ($this->connections) {
$this->presentConnections($this->connections);
if ($this->command->confirm('Do you want to add a connection to this?', false)) {
$connectionName = $this->command->ask('What do you want to name it?');
}
} else {
$connectionName = $this->command->ask('No connections have been set, let\'s create one, what do you want to name it?', 'production');
}
// If the user does not want to add any more connection
// then we can quit
if (!$connectionName) {
return $this->connections;
}
$this->getConnectionCredentials($connectionName);
return $this->getConnectionsCredentials();
} | [
"public",
"function",
"getConnectionsCredentials",
"(",
")",
"{",
"$",
"connectionName",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"connections",
")",
"{",
"$",
"this",
"->",
"presentConnections",
"(",
"$",
"this",
"->",
"connections",
")",
";",
"if"... | Get the credentials of all connections.
@return array | [
"Get",
"the",
"credentials",
"of",
"all",
"connections",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php#L68-L89 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php | CredentialsGatherer.getConnectionCredentials | public function getConnectionCredentials($connectionName)
{
$user = $this->bash->runLocally('whoami');
$usesPrivateKey = $this->command->confirm('Do you use an SSH key to connect to it?');
$questions = $usesPrivateKey ? [
'key' => ['Where can I find your key?', $this->paths->getDefaultKeyPath()],
'keyphrase' => 'If it needs a passphrase enter it',
'host' => 'Where is your server located? <comment>(eg. foobar.com)</comment>',
'username' => ['What is the username for it?', $user],
'root_directory' => ['Where do you want your application deployed?', '/home/www/'],
] : [
'host' => 'Where is your server located?',
'username' => ['What is the username for it?', $user],
'password' => 'And password?',
'root_directory' => ['Where do you want your application deployed?', '/home/www/'],
];
$this->connections[$connectionName] = $this->askQuestions($connectionName, $questions);
} | php | public function getConnectionCredentials($connectionName)
{
$user = $this->bash->runLocally('whoami');
$usesPrivateKey = $this->command->confirm('Do you use an SSH key to connect to it?');
$questions = $usesPrivateKey ? [
'key' => ['Where can I find your key?', $this->paths->getDefaultKeyPath()],
'keyphrase' => 'If it needs a passphrase enter it',
'host' => 'Where is your server located? <comment>(eg. foobar.com)</comment>',
'username' => ['What is the username for it?', $user],
'root_directory' => ['Where do you want your application deployed?', '/home/www/'],
] : [
'host' => 'Where is your server located?',
'username' => ['What is the username for it?', $user],
'password' => 'And password?',
'root_directory' => ['Where do you want your application deployed?', '/home/www/'],
];
$this->connections[$connectionName] = $this->askQuestions($connectionName, $questions);
} | [
"public",
"function",
"getConnectionCredentials",
"(",
"$",
"connectionName",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"bash",
"->",
"runLocally",
"(",
"'whoami'",
")",
";",
"$",
"usesPrivateKey",
"=",
"$",
"this",
"->",
"command",
"->",
"confirm",
"... | Get the credentials of a connection.
@param string $connectionName | [
"Get",
"the",
"credentials",
"of",
"a",
"connection",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php#L96-L115 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php | CredentialsGatherer.presentConnections | protected function presentConnections($connections)
{
$headers = [
'name' => 'Name',
'host' => 'Host',
'username' => 'Username',
'password' => 'Password',
'key' => 'Key',
'keyphrase' => 'Keyphrase',
'root_directory' => 'Root directory',
];
$rows = [];
foreach ($connections as $name => $connection) {
$connection[mb_strtoupper($name.'_NAME')] = $name;
$row = [];
foreach ($headers as $key => $value) {
$key = mb_strtoupper($name.'_'.$key);
$row[] = isset($connection[$key]) ? $connection[$key] : '';
}
$rows[] = $row;
}
$this->command->writeln('Here are the current connections defined:');
$this->command->table(array_values($headers), $rows);
} | php | protected function presentConnections($connections)
{
$headers = [
'name' => 'Name',
'host' => 'Host',
'username' => 'Username',
'password' => 'Password',
'key' => 'Key',
'keyphrase' => 'Keyphrase',
'root_directory' => 'Root directory',
];
$rows = [];
foreach ($connections as $name => $connection) {
$connection[mb_strtoupper($name.'_NAME')] = $name;
$row = [];
foreach ($headers as $key => $value) {
$key = mb_strtoupper($name.'_'.$key);
$row[] = isset($connection[$key]) ? $connection[$key] : '';
}
$rows[] = $row;
}
$this->command->writeln('Here are the current connections defined:');
$this->command->table(array_values($headers), $rows);
} | [
"protected",
"function",
"presentConnections",
"(",
"$",
"connections",
")",
"{",
"$",
"headers",
"=",
"[",
"'name'",
"=>",
"'Name'",
",",
"'host'",
"=>",
"'Host'",
",",
"'username'",
"=>",
"'Username'",
",",
"'password'",
"=>",
"'Password'",
",",
"'key'",
"... | Present the connections in a table-like manner.
@param array $connections | [
"Present",
"the",
"connections",
"in",
"a",
"table",
"-",
"like",
"manner",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Credentials/CredentialsGatherer.php#L209-L236 | train |
rocketeers/rocketeer | src/Rocketeer/Binaries/PackageManagers/Composer.php | Composer.setBinary | public function setBinary($binary)
{
parent::setBinary($binary);
// Prepend PHP command if executing from archive
if (mb_strpos($binary, 'composer.phar') !== false) {
$php = new Php($this->container);
$this->setParent($php);
}
} | php | public function setBinary($binary)
{
parent::setBinary($binary);
// Prepend PHP command if executing from archive
if (mb_strpos($binary, 'composer.phar') !== false) {
$php = new Php($this->container);
$this->setParent($php);
}
} | [
"public",
"function",
"setBinary",
"(",
"$",
"binary",
")",
"{",
"parent",
"::",
"setBinary",
"(",
"$",
"binary",
")",
";",
"// Prepend PHP command if executing from archive",
"if",
"(",
"mb_strpos",
"(",
"$",
"binary",
",",
"'composer.phar'",
")",
"!==",
"false... | Change Composer's binary.
@param string $binary | [
"Change",
"Composer",
"s",
"binary",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Binaries/PackageManagers/Composer.php#L48-L57 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Environment/Pathfinder.php | Pathfinder.replacePatterns | public function replacePatterns($path)
{
$base = $this->getBasePath();
// Replace folder patterns
return preg_replace_callback('/\{[a-z\.]+\}/', function ($match) use ($base) {
$folder = mb_substr($match[0], 1, -1);
// Replace paths from the container
if ($this->container->has($folder)) {
$path = $this->container->get($folder);
return str_replace($base, null, $this->unifySlashes($path));
}
// Replace paths from configuration
if ($custom = $this->getPath($folder)) {
return $custom;
}
return false;
}, $path);
} | php | public function replacePatterns($path)
{
$base = $this->getBasePath();
// Replace folder patterns
return preg_replace_callback('/\{[a-z\.]+\}/', function ($match) use ($base) {
$folder = mb_substr($match[0], 1, -1);
// Replace paths from the container
if ($this->container->has($folder)) {
$path = $this->container->get($folder);
return str_replace($base, null, $this->unifySlashes($path));
}
// Replace paths from configuration
if ($custom = $this->getPath($folder)) {
return $custom;
}
return false;
}, $path);
} | [
"public",
"function",
"replacePatterns",
"(",
"$",
"path",
")",
"{",
"$",
"base",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
";",
"// Replace folder patterns",
"return",
"preg_replace_callback",
"(",
"'/\\{[a-z\\.]+\\}/'",
",",
"function",
"(",
"$",
"match... | Replace patterns in a folder path.
@param string $path
@return string | [
"Replace",
"patterns",
"in",
"a",
"folder",
"path",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Environment/Pathfinder.php#L97-L119 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Environment/Pathfinder.php | Pathfinder.computeRelativePathBetween | public function computeRelativePathBetween($from, $to)
{
$from = $this->explodePath($from);
$to = $this->explodePath($to);
// Skip the common path prefix
foreach ($from as $key => $component) {
if (isset($to[$key]) && $to[$key] === $component) {
unset($from[$key], $to[$key]);
}
}
// Compute new realpath
$relativePath = implode('/', $to);
$relativePath = str_repeat('../', count($from) - 1).$relativePath;
$relativePath = trim($relativePath, '/');
return $relativePath;
} | php | public function computeRelativePathBetween($from, $to)
{
$from = $this->explodePath($from);
$to = $this->explodePath($to);
// Skip the common path prefix
foreach ($from as $key => $component) {
if (isset($to[$key]) && $to[$key] === $component) {
unset($from[$key], $to[$key]);
}
}
// Compute new realpath
$relativePath = implode('/', $to);
$relativePath = str_repeat('../', count($from) - 1).$relativePath;
$relativePath = trim($relativePath, '/');
return $relativePath;
} | [
"public",
"function",
"computeRelativePathBetween",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"$",
"from",
"=",
"$",
"this",
"->",
"explodePath",
"(",
"$",
"from",
")",
";",
"$",
"to",
"=",
"$",
"this",
"->",
"explodePath",
"(",
"$",
"to",
")",
"... | Get a relative path from one file or directory to another.
If $from is a path to a file (i.e. does not end with a "/"), the
returned path will be relative to its parent directory.
@param string $from
@param string $to
@return string | [
"Get",
"a",
"relative",
"path",
"from",
"one",
"file",
"or",
"directory",
"to",
"another",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Environment/Pathfinder.php#L132-L150 | train |
rocketeers/rocketeer | src/Rocketeer/Traits/Properties/HasHistoryTrait.php | HasHistoryTrait.getHistory | public function getHistory($type = null)
{
$handle = $this->getHistoryHandle();
$history = $this->history[$handle];
$history = Arr::get($history, $type);
return $history;
} | php | public function getHistory($type = null)
{
$handle = $this->getHistoryHandle();
$history = $this->history[$handle];
$history = Arr::get($history, $type);
return $history;
} | [
"public",
"function",
"getHistory",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"handle",
"=",
"$",
"this",
"->",
"getHistoryHandle",
"(",
")",
";",
"$",
"history",
"=",
"$",
"this",
"->",
"history",
"[",
"$",
"handle",
"]",
";",
"$",
"history",
... | Get the class's history.
@param string|null $type
@return array | [
"Get",
"the",
"class",
"s",
"history",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Traits/Properties/HasHistoryTrait.php#L31-L38 | train |
rocketeers/rocketeer | src/Rocketeer/Traits/Properties/HasHistoryTrait.php | HasHistoryTrait.getHistoryHandle | protected function getHistoryHandle()
{
$handle = get_called_class();
// Create entry if it doesn't exist yet
if (!isset($this->history[$handle])) {
$this->history[$handle] = [
'history' => [],
'output' => [],
];
}
return $handle;
} | php | protected function getHistoryHandle()
{
$handle = get_called_class();
// Create entry if it doesn't exist yet
if (!isset($this->history[$handle])) {
$this->history[$handle] = [
'history' => [],
'output' => [],
];
}
return $handle;
} | [
"protected",
"function",
"getHistoryHandle",
"(",
")",
"{",
"$",
"handle",
"=",
"get_called_class",
"(",
")",
";",
"// Create entry if it doesn't exist yet",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"history",
"[",
"$",
"handle",
"]",
")",
")",
"{",
... | Get the class's handle in the history.
@return string | [
"Get",
"the",
"class",
"s",
"handle",
"in",
"the",
"history",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Traits/Properties/HasHistoryTrait.php#L65-L78 | train |
rocketeers/rocketeer | src/Rocketeer/Traits/Properties/HasHistoryTrait.php | HasHistoryTrait.appendTo | protected function appendTo($type, $command)
{
// Flatten one-liners
$command = (array) $command;
$command = array_values($command);
$flattened = count($command) === 1 ? $command[0] : $command;
// Format commands
foreach ($command as $key => $entry) {
$command[$key] = $type === 'history' ? '$ '.$entry : $entry;
}
$this->logs->log($command);
// Get the various handles
$handle = $this->getHistoryHandle();
$history = $this->getHistory();
$timestamp = (string) microtime(true);
// Set new history on correct handle
$history[$type][$timestamp] = $flattened;
$this->history[$handle] = $history;
} | php | protected function appendTo($type, $command)
{
// Flatten one-liners
$command = (array) $command;
$command = array_values($command);
$flattened = count($command) === 1 ? $command[0] : $command;
// Format commands
foreach ($command as $key => $entry) {
$command[$key] = $type === 'history' ? '$ '.$entry : $entry;
}
$this->logs->log($command);
// Get the various handles
$handle = $this->getHistoryHandle();
$history = $this->getHistory();
$timestamp = (string) microtime(true);
// Set new history on correct handle
$history[$type][$timestamp] = $flattened;
$this->history[$handle] = $history;
} | [
"protected",
"function",
"appendTo",
"(",
"$",
"type",
",",
"$",
"command",
")",
"{",
"// Flatten one-liners",
"$",
"command",
"=",
"(",
"array",
")",
"$",
"command",
";",
"$",
"command",
"=",
"array_values",
"(",
"$",
"command",
")",
";",
"$",
"flattene... | Append something to the history.
@param string $type
@param string|array|bool $command | [
"Append",
"something",
"to",
"the",
"history",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Traits/Properties/HasHistoryTrait.php#L86-L109 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsHandler.php | ConnectionsHandler.getAvailableConnections | public function getAvailableConnections()
{
// Fetch stored credentials
$storage = $this->localStorage->get('connections');
$storage = $this->unifyMultiserversDeclarations($storage);
// Merge with defaults from config file
$configuration = $this->config->get('connections');
$configuration = $this->unifyMultiserversDeclarations($configuration);
// Merge configurations
$connections = array_replace_recursive($configuration, $storage);
return $connections;
} | php | public function getAvailableConnections()
{
// Fetch stored credentials
$storage = $this->localStorage->get('connections');
$storage = $this->unifyMultiserversDeclarations($storage);
// Merge with defaults from config file
$configuration = $this->config->get('connections');
$configuration = $this->unifyMultiserversDeclarations($configuration);
// Merge configurations
$connections = array_replace_recursive($configuration, $storage);
return $connections;
} | [
"public",
"function",
"getAvailableConnections",
"(",
")",
"{",
"// Fetch stored credentials",
"$",
"storage",
"=",
"$",
"this",
"->",
"localStorage",
"->",
"get",
"(",
"'connections'",
")",
";",
"$",
"storage",
"=",
"$",
"this",
"->",
"unifyMultiserversDeclaratio... | Get the available connections.
@return array | [
"Get",
"the",
"available",
"connections",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsHandler.php#L58-L72 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsHandler.php | ConnectionsHandler.isValidConnection | public function isValidConnection($connection)
{
$connection = $this->credentials->sanitizeConnection($connection);
$available = (array) $this->getAvailableConnections();
return (bool) Arr::get($available, $connection->name.'.servers');
} | php | public function isValidConnection($connection)
{
$connection = $this->credentials->sanitizeConnection($connection);
$available = (array) $this->getAvailableConnections();
return (bool) Arr::get($available, $connection->name.'.servers');
} | [
"public",
"function",
"isValidConnection",
"(",
"$",
"connection",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"credentials",
"->",
"sanitizeConnection",
"(",
"$",
"connection",
")",
";",
"$",
"available",
"=",
"(",
"array",
")",
"$",
"this",
"->"... | Check if a connection has credentials related to it.
@param ConnectionKey|string $connection
@return bool | [
"Check",
"if",
"a",
"connection",
"has",
"credentials",
"related",
"to",
"it",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsHandler.php#L163-L169 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsHandler.php | ConnectionsHandler.setActiveConnections | public function setActiveConnections($connections)
{
if (!is_array($connections)) {
$connections = explode(',', $connections);
}
// Sanitize and set connections
$filtered = array_filter($connections, [$this, 'isValidConnection']);
if (!$filtered) {
throw new ConnectionException('Invalid connection(s): '.implode(', ', $connections));
}
$this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connections) {
$connectionKey = $connection->getConnectionKey();
$handle = $connectionKey->toHandle();
$connection->setActive(in_array($handle, $connections, true) || in_array($connectionKey->name, $connections, true));
$connection->setCurrent(false);
return $connection;
});
} | php | public function setActiveConnections($connections)
{
if (!is_array($connections)) {
$connections = explode(',', $connections);
}
// Sanitize and set connections
$filtered = array_filter($connections, [$this, 'isValidConnection']);
if (!$filtered) {
throw new ConnectionException('Invalid connection(s): '.implode(', ', $connections));
}
$this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connections) {
$connectionKey = $connection->getConnectionKey();
$handle = $connectionKey->toHandle();
$connection->setActive(in_array($handle, $connections, true) || in_array($connectionKey->name, $connections, true));
$connection->setCurrent(false);
return $connection;
});
} | [
"public",
"function",
"setActiveConnections",
"(",
"$",
"connections",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"connections",
")",
")",
"{",
"$",
"connections",
"=",
"explode",
"(",
"','",
",",
"$",
"connections",
")",
";",
"}",
"// Sanitize and se... | Override the active connections.
@param string|string[] $connections
@throws ConnectionException | [
"Override",
"the",
"active",
"connections",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsHandler.php#L194-L215 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsHandler.php | ConnectionsHandler.getCurrentConnectionKey | public function getCurrentConnectionKey()
{
$current = $this->getCurrentConnection();
return $current ? $current->getConnectionKey() : $this->credentials->createConnectionKey();
} | php | public function getCurrentConnectionKey()
{
$current = $this->getCurrentConnection();
return $current ? $current->getConnectionKey() : $this->credentials->createConnectionKey();
} | [
"public",
"function",
"getCurrentConnectionKey",
"(",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"getCurrentConnection",
"(",
")",
";",
"return",
"$",
"current",
"?",
"$",
"current",
"->",
"getConnectionKey",
"(",
")",
":",
"$",
"this",
"->",
"crede... | Get the current connection.
@return ConnectionKey | [
"Get",
"the",
"current",
"connection",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsHandler.php#L263-L268 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsHandler.php | ConnectionsHandler.setCurrentConnection | public function setCurrentConnection($connection = null, $server = null)
{
$connectionKey = $connection instanceof ConnectionKey ? $connection : $this->credentials->createConnectionKey($connection, $server);
if ($this->current === $connectionKey->toHandle()) {
return;
}
$this->current = $connectionKey->toHandle();
$this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connectionKey) {
$isCurrent = $connectionKey->is($connection->getConnectionKey());
$connection->setCurrent($isCurrent);
return $connection;
});
// Update events
$this->bootstrapper->bootstrapUserCode();
} | php | public function setCurrentConnection($connection = null, $server = null)
{
$connectionKey = $connection instanceof ConnectionKey ? $connection : $this->credentials->createConnectionKey($connection, $server);
if ($this->current === $connectionKey->toHandle()) {
return;
}
$this->current = $connectionKey->toHandle();
$this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connectionKey) {
$isCurrent = $connectionKey->is($connection->getConnectionKey());
$connection->setCurrent($isCurrent);
return $connection;
});
// Update events
$this->bootstrapper->bootstrapUserCode();
} | [
"public",
"function",
"setCurrentConnection",
"(",
"$",
"connection",
"=",
"null",
",",
"$",
"server",
"=",
"null",
")",
"{",
"$",
"connectionKey",
"=",
"$",
"connection",
"instanceof",
"ConnectionKey",
"?",
"$",
"connection",
":",
"$",
"this",
"->",
"creden... | Set the current connection.
@param ConnectionKey|string $connection
@param int|null $server | [
"Set",
"the",
"current",
"connection",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsHandler.php#L276-L293 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsHandler.php | ConnectionsHandler.setStage | public function setStage($stage)
{
$connectionKey = $this->getCurrentConnectionKey();
if ($stage === $connectionKey->stage) {
return;
}
$connectionKey->stage = $stage;
$this->getConnections()->map(function (ConnectionInterface $connection) use ($connectionKey) {
if ($connection->isCurrent() || $connection->getConnectionKey()->is($connectionKey)) {
$connection->setConnectionKey($connectionKey);
}
return $connection;
});
// If we do have a stage, cleanup previous events
if ($stage) {
$this->bootstrapper->bootstrapUserCode();
}
} | php | public function setStage($stage)
{
$connectionKey = $this->getCurrentConnectionKey();
if ($stage === $connectionKey->stage) {
return;
}
$connectionKey->stage = $stage;
$this->getConnections()->map(function (ConnectionInterface $connection) use ($connectionKey) {
if ($connection->isCurrent() || $connection->getConnectionKey()->is($connectionKey)) {
$connection->setConnectionKey($connectionKey);
}
return $connection;
});
// If we do have a stage, cleanup previous events
if ($stage) {
$this->bootstrapper->bootstrapUserCode();
}
} | [
"public",
"function",
"setStage",
"(",
"$",
"stage",
")",
"{",
"$",
"connectionKey",
"=",
"$",
"this",
"->",
"getCurrentConnectionKey",
"(",
")",
";",
"if",
"(",
"$",
"stage",
"===",
"$",
"connectionKey",
"->",
"stage",
")",
"{",
"return",
";",
"}",
"$... | Set the stage on the current connection.
@param string|null $stage | [
"Set",
"the",
"stage",
"on",
"the",
"current",
"connection",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsHandler.php#L342-L362 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsHandler.php | ConnectionsHandler.unifyMultiserversDeclarations | protected function unifyMultiserversDeclarations($connection)
{
$connection = (array) $connection;
foreach ($connection as $key => $servers) {
$servers = Arr::get($servers, 'servers', [$servers]);
$servers = array_values($servers);
foreach ($servers as &$server) {
if (array_key_exists('key', $server)) {
$server['key'] = str_replace('~/', $this->paths->getUserHomeFolder().'/', $server['key']);
}
}
$connection[$key] = ['servers' => $servers];
}
return $connection;
} | php | protected function unifyMultiserversDeclarations($connection)
{
$connection = (array) $connection;
foreach ($connection as $key => $servers) {
$servers = Arr::get($servers, 'servers', [$servers]);
$servers = array_values($servers);
foreach ($servers as &$server) {
if (array_key_exists('key', $server)) {
$server['key'] = str_replace('~/', $this->paths->getUserHomeFolder().'/', $server['key']);
}
}
$connection[$key] = ['servers' => $servers];
}
return $connection;
} | [
"protected",
"function",
"unifyMultiserversDeclarations",
"(",
"$",
"connection",
")",
"{",
"$",
"connection",
"=",
"(",
"array",
")",
"$",
"connection",
";",
"foreach",
"(",
"$",
"connection",
"as",
"$",
"key",
"=>",
"$",
"servers",
")",
"{",
"$",
"server... | Unify a connection's declaration into the servers form.
@param array $connection
@return array | [
"Unify",
"a",
"connection",
"s",
"declaration",
"into",
"the",
"servers",
"form",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsHandler.php#L391-L407 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Roles/RolesManager.php | RolesManager.getConnectionRoles | public function getConnectionRoles($connection = null, $server = null)
{
$credentials = $this->credentials->getServerCredentials($connection, $server);
return Arr::get($credentials, 'roles', []);
} | php | public function getConnectionRoles($connection = null, $server = null)
{
$credentials = $this->credentials->getServerCredentials($connection, $server);
return Arr::get($credentials, 'roles', []);
} | [
"public",
"function",
"getConnectionRoles",
"(",
"$",
"connection",
"=",
"null",
",",
"$",
"server",
"=",
"null",
")",
"{",
"$",
"credentials",
"=",
"$",
"this",
"->",
"credentials",
"->",
"getServerCredentials",
"(",
"$",
"connection",
",",
"$",
"server",
... | Get the roles of a server.
@param string|null $connection
@param int|null $server
@return array | [
"Get",
"the",
"roles",
"of",
"a",
"server",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Roles/RolesManager.php#L36-L41 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Roles/RolesManager.php | RolesManager.assignTasksRoles | public function assignTasksRoles(array $roles)
{
foreach ($roles as $roles => $tasks) {
$tasks = (array) $tasks;
$roles = (array) $roles;
foreach ($tasks as $task) {
$this->builder->buildTask($task)->addRoles($roles);
}
}
} | php | public function assignTasksRoles(array $roles)
{
foreach ($roles as $roles => $tasks) {
$tasks = (array) $tasks;
$roles = (array) $roles;
foreach ($tasks as $task) {
$this->builder->buildTask($task)->addRoles($roles);
}
}
} | [
"public",
"function",
"assignTasksRoles",
"(",
"array",
"$",
"roles",
")",
"{",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"roles",
"=>",
"$",
"tasks",
")",
"{",
"$",
"tasks",
"=",
"(",
"array",
")",
"$",
"tasks",
";",
"$",
"roles",
"=",
"(",
"array"... | Assign roles to multiple tasks.
@param array $roles | [
"Assign",
"roles",
"to",
"multiple",
"tasks",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Roles/RolesManager.php#L48-L58 | train |
rocketeers/rocketeer | src/Rocketeer/Binaries/PackageManagers/Bower.php | Bower.getDependenciesFolder | public function getDependenciesFolder()
{
// Look for a configuration file
$paths = array_filter([
$this->paths->getBasePath().'.bowerrc',
$this->paths->getUserHomeFolder().'/.bowerrc',
], [$this->files, 'has']);
$file = head($paths);
if ($file) {
$file = $this->files->read($file);
$file = json_decode($file, true);
}
return array_get($file, 'directory', 'bower_components');
} | php | public function getDependenciesFolder()
{
// Look for a configuration file
$paths = array_filter([
$this->paths->getBasePath().'.bowerrc',
$this->paths->getUserHomeFolder().'/.bowerrc',
], [$this->files, 'has']);
$file = head($paths);
if ($file) {
$file = $this->files->read($file);
$file = json_decode($file, true);
}
return array_get($file, 'directory', 'bower_components');
} | [
"public",
"function",
"getDependenciesFolder",
"(",
")",
"{",
"// Look for a configuration file",
"$",
"paths",
"=",
"array_filter",
"(",
"[",
"$",
"this",
"->",
"paths",
"->",
"getBasePath",
"(",
")",
".",
"'.bowerrc'",
",",
"$",
"this",
"->",
"paths",
"->",
... | Get where dependencies are installed.
@return string | [
"Get",
"where",
"dependencies",
"are",
"installed",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Binaries/PackageManagers/Bower.php#L45-L60 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Config/Files/ConfigurationCache.php | ConfigurationCache.getContents | public function getContents()
{
$file = $this->getPath();
// Get an unserialize
$configuration = file_get_contents($file);
$configuration = unserialize($configuration);
return $configuration;
} | php | public function getContents()
{
$file = $this->getPath();
// Get an unserialize
$configuration = file_get_contents($file);
$configuration = unserialize($configuration);
return $configuration;
} | [
"public",
"function",
"getContents",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"// Get an unserialize",
"$",
"configuration",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"$",
"configuration",
"=",
"unserialize",
... | Get the contents of the cache.
@return array | [
"Get",
"the",
"contents",
"of",
"the",
"cache",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Config/Files/ConfigurationCache.php#L58-L67 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Bootstrapper/Modules/ConfigurationBootstrapper.php | ConfigurationBootstrapper.bootstrapDotenv | protected function bootstrapDotenv()
{
if (!$this->files->has($this->paths->getDotenvPath())) {
return;
}
$path = $this->files->getAdapter()->applyPathPrefix($this->paths->getBasePath());
$dotenv = new Dotenv($path);
$dotenv->load();
} | php | protected function bootstrapDotenv()
{
if (!$this->files->has($this->paths->getDotenvPath())) {
return;
}
$path = $this->files->getAdapter()->applyPathPrefix($this->paths->getBasePath());
$dotenv = new Dotenv($path);
$dotenv->load();
} | [
"protected",
"function",
"bootstrapDotenv",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"has",
"(",
"$",
"this",
"->",
"paths",
"->",
"getDotenvPath",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"path",
"=",
"$",
"this",
... | Load the .env file if necessary. | [
"Load",
"the",
".",
"env",
"file",
"if",
"necessary",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Bootstrapper/Modules/ConfigurationBootstrapper.php#L37-L46 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Check/AbstractCheckStrategy.php | AbstractCheckStrategy.manager | public function manager()
{
$manager = $this->getManager();
if (!$manager) {
return true;
}
// Check if we have a manifest to go from
// Else assume we're not using it on this project
$managerName = $manager->getName();
$hasManifest = $manager->hasManifest();
if (!$hasManifest) {
return true;
}
// Check if the server has the package manager
$hasManager = $manager->isExecutable();
if (!$hasManager) {
$this->explainer->error($managerName.' is not present (or executable)');
}
return $hasManager && $hasManifest;
} | php | public function manager()
{
$manager = $this->getManager();
if (!$manager) {
return true;
}
// Check if we have a manifest to go from
// Else assume we're not using it on this project
$managerName = $manager->getName();
$hasManifest = $manager->hasManifest();
if (!$hasManifest) {
return true;
}
// Check if the server has the package manager
$hasManager = $manager->isExecutable();
if (!$hasManager) {
$this->explainer->error($managerName.' is not present (or executable)');
}
return $hasManager && $hasManifest;
} | [
"public",
"function",
"manager",
"(",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
";",
"if",
"(",
"!",
"$",
"manager",
")",
"{",
"return",
"true",
";",
"}",
"// Check if we have a manifest to go from",
"// Else assume we're not us... | Check that the PM that'll install
the app's dependencies is present.
@return bool | [
"Check",
"that",
"the",
"PM",
"that",
"ll",
"install",
"the",
"app",
"s",
"dependencies",
"is",
"present",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Check/AbstractCheckStrategy.php#L78-L100 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Check/AbstractCheckStrategy.php | AbstractCheckStrategy.language | public function language()
{
$required = null;
// Get the minimum version of the application
if ($this->getManager() && $manifest = $this->getManager()->getManifestContents()) {
$required = $this->getLanguageConstraint($manifest);
}
// Cancel if no version constraint
if (!$required) {
return true;
}
$version = $this->getCurrentVersion();
$hasRequiredVersion = version_compare($version, $required, '>=');
if (!$hasRequiredVersion) {
$this->explainer->error(sprintf('%s is not at required version: %s instead of %s', $this->getLanguage(), $version, $required));
}
return $hasRequiredVersion;
} | php | public function language()
{
$required = null;
// Get the minimum version of the application
if ($this->getManager() && $manifest = $this->getManager()->getManifestContents()) {
$required = $this->getLanguageConstraint($manifest);
}
// Cancel if no version constraint
if (!$required) {
return true;
}
$version = $this->getCurrentVersion();
$hasRequiredVersion = version_compare($version, $required, '>=');
if (!$hasRequiredVersion) {
$this->explainer->error(sprintf('%s is not at required version: %s instead of %s', $this->getLanguage(), $version, $required));
}
return $hasRequiredVersion;
} | [
"public",
"function",
"language",
"(",
")",
"{",
"$",
"required",
"=",
"null",
";",
"// Get the minimum version of the application",
"if",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
"&&",
"$",
"manifest",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
... | Check that the language used by the
application is at the required version.
@return bool | [
"Check",
"that",
"the",
"language",
"used",
"by",
"the",
"application",
"is",
"at",
"the",
"required",
"version",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Check/AbstractCheckStrategy.php#L108-L129 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Check/AbstractCheckStrategy.php | AbstractCheckStrategy.extensions | public function extensions()
{
$extensions = $this->getRequiredExtensions();
$missing = array_filter($extensions, function ($extension) {
return !$this->checkExtension($extension);
});
if ($missing) {
$this->explainer->error('Extensions mission from server: '.implode(', ', $missing));
}
return count($missing) === 0;
} | php | public function extensions()
{
$extensions = $this->getRequiredExtensions();
$missing = array_filter($extensions, function ($extension) {
return !$this->checkExtension($extension);
});
if ($missing) {
$this->explainer->error('Extensions mission from server: '.implode(', ', $missing));
}
return count($missing) === 0;
} | [
"public",
"function",
"extensions",
"(",
")",
"{",
"$",
"extensions",
"=",
"$",
"this",
"->",
"getRequiredExtensions",
"(",
")",
";",
"$",
"missing",
"=",
"array_filter",
"(",
"$",
"extensions",
",",
"function",
"(",
"$",
"extension",
")",
"{",
"return",
... | Check for required extensions on the server.
@return bool | [
"Check",
"for",
"required",
"extensions",
"on",
"the",
"server",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Check/AbstractCheckStrategy.php#L136-L148 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.run | public function run($commands, $silent = false, $array = false)
{
$commands = $this->processCommands($commands);
$verbose = $this->getOption('verbose') && !$silent;
$pretend = $this->getOption('pretend');
// Gather any extra output of the server
// to be able to clean it up after
if ($this->extraOutput === null && !$pretend) {
$this->extraOutput = $this->getExtraOutput();
}
// Log the commands
if (!$silent) {
$this->modulable->toHistory($commands);
}
// Display the commands if necessary
if ($verbose || ($pretend && !$silent)) {
$this->modulable->toOutput($commands);
$this->displayCommands($commands);
if ($pretend) {
return count($commands) === 1 ? $commands[0] : $commands;
}
}
// Run commands
$output = null;
$this->modulable->getConnection()->run($commands, function ($results) use (&$output, $verbose) {
$output .= $results;
if ($verbose) {
$display = $this->cleanOutput($results);
$this->explainer->server(trim($display));
}
});
// Process and log the output and commands
$output = $this->processOutput($output, $array, true);
$this->modulable->toOutput($output);
return $output;
} | php | public function run($commands, $silent = false, $array = false)
{
$commands = $this->processCommands($commands);
$verbose = $this->getOption('verbose') && !$silent;
$pretend = $this->getOption('pretend');
// Gather any extra output of the server
// to be able to clean it up after
if ($this->extraOutput === null && !$pretend) {
$this->extraOutput = $this->getExtraOutput();
}
// Log the commands
if (!$silent) {
$this->modulable->toHistory($commands);
}
// Display the commands if necessary
if ($verbose || ($pretend && !$silent)) {
$this->modulable->toOutput($commands);
$this->displayCommands($commands);
if ($pretend) {
return count($commands) === 1 ? $commands[0] : $commands;
}
}
// Run commands
$output = null;
$this->modulable->getConnection()->run($commands, function ($results) use (&$output, $verbose) {
$output .= $results;
if ($verbose) {
$display = $this->cleanOutput($results);
$this->explainer->server(trim($display));
}
});
// Process and log the output and commands
$output = $this->processOutput($output, $array, true);
$this->modulable->toOutput($output);
return $output;
} | [
"public",
"function",
"run",
"(",
"$",
"commands",
",",
"$",
"silent",
"=",
"false",
",",
"$",
"array",
"=",
"false",
")",
"{",
"$",
"commands",
"=",
"$",
"this",
"->",
"processCommands",
"(",
"$",
"commands",
")",
";",
"$",
"verbose",
"=",
"$",
"t... | Run actions on the remote server and gather the ouput.
@param string|array $commands One or more commands
@param bool $silent Whether the command should stay silent no matter what
@param bool $array Whether the output should be returned as an array
@return string|null | [
"Run",
"actions",
"on",
"the",
"remote",
"server",
"and",
"gather",
"the",
"ouput",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L60-L103 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.runLast | public function runLast($commands)
{
$results = $this->runRaw($commands, true);
$results = end($results);
return $results;
} | php | public function runLast($commands)
{
$results = $this->runRaw($commands, true);
$results = end($results);
return $results;
} | [
"public",
"function",
"runLast",
"(",
"$",
"commands",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"runRaw",
"(",
"$",
"commands",
",",
"true",
")",
";",
"$",
"results",
"=",
"end",
"(",
"$",
"results",
")",
";",
"return",
"$",
"results",
";"... | Run a command get the last line output to
prevent noise.
@param string $commands
@return string | [
"Run",
"a",
"command",
"get",
"the",
"last",
"line",
"output",
"to",
"prevent",
"noise",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L113-L119 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.runRaw | public function runRaw($commands, $array = false, $trim = false)
{
$pretend = $this->getOption('pretend');
if ($pretend) {
return $array ? [$commands] : 'true';
}
$this->displayCommands($commands, OutputInterface::VERBOSITY_VERY_VERBOSE);
// Run commands
$output = null;
$this->modulable->getConnection()->run($commands, function ($results) use (&$output) {
$output .= $results;
});
// Process the output
$output = $this->processOutput($output, $array, $trim);
return $output;
} | php | public function runRaw($commands, $array = false, $trim = false)
{
$pretend = $this->getOption('pretend');
if ($pretend) {
return $array ? [$commands] : 'true';
}
$this->displayCommands($commands, OutputInterface::VERBOSITY_VERY_VERBOSE);
// Run commands
$output = null;
$this->modulable->getConnection()->run($commands, function ($results) use (&$output) {
$output .= $results;
});
// Process the output
$output = $this->processOutput($output, $array, $trim);
return $output;
} | [
"public",
"function",
"runRaw",
"(",
"$",
"commands",
",",
"$",
"array",
"=",
"false",
",",
"$",
"trim",
"=",
"false",
")",
"{",
"$",
"pretend",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'pretend'",
")",
";",
"if",
"(",
"$",
"pretend",
")",
"{",
... | Run a raw command, without any processing, and
get its output as a string or array.
@param string $commands
@param bool $array Whether the output should be returned as an array
@param bool $trim Whether the output should be trimmed
@return string|string[] | [
"Run",
"a",
"raw",
"command",
"without",
"any",
"processing",
"and",
"get",
"its",
"output",
"as",
"a",
"string",
"or",
"array",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L131-L150 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.runInFolder | public function runInFolder($folder = null, $tasks = [])
{
// Convert to array
if (!is_array($tasks)) {
$tasks = [$tasks];
}
// Prepend folder
array_unshift($tasks, 'cd '.$this->paths->getFolder($folder));
return $this->run($tasks);
} | php | public function runInFolder($folder = null, $tasks = [])
{
// Convert to array
if (!is_array($tasks)) {
$tasks = [$tasks];
}
// Prepend folder
array_unshift($tasks, 'cd '.$this->paths->getFolder($folder));
return $this->run($tasks);
} | [
"public",
"function",
"runInFolder",
"(",
"$",
"folder",
"=",
"null",
",",
"$",
"tasks",
"=",
"[",
"]",
")",
"{",
"// Convert to array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"tasks",
")",
")",
"{",
"$",
"tasks",
"=",
"[",
"$",
"tasks",
"]",
";",
... | Run commands in a folder.
@param string|null $folder
@param string|array $tasks
@return string|null | [
"Run",
"commands",
"in",
"a",
"folder",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L173-L184 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.getTimestamp | public function getTimestamp()
{
$timestamp = $this->runLast('date +"%Y%m%d%H%M%S"');
$timestamp = trim($timestamp);
$timestamp = preg_match('/^[0-9]{14}$/', $timestamp) ? $timestamp : date('YmdHis');
return $timestamp;
} | php | public function getTimestamp()
{
$timestamp = $this->runLast('date +"%Y%m%d%H%M%S"');
$timestamp = trim($timestamp);
$timestamp = preg_match('/^[0-9]{14}$/', $timestamp) ? $timestamp : date('YmdHis');
return $timestamp;
} | [
"public",
"function",
"getTimestamp",
"(",
")",
"{",
"$",
"timestamp",
"=",
"$",
"this",
"->",
"runLast",
"(",
"'date +\"%Y%m%d%H%M%S\"'",
")",
";",
"$",
"timestamp",
"=",
"trim",
"(",
"$",
"timestamp",
")",
";",
"$",
"timestamp",
"=",
"preg_match",
"(",
... | Get the current timestamp on the server.
@return string | [
"Get",
"the",
"current",
"timestamp",
"on",
"the",
"server",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L195-L202 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.displayCommands | protected function displayCommands($commands, $verbosity = 1)
{
// Print out command if verbosity level allows it
if ($verbosity && $this->hasCommand() && ($this->command->getVerbosity() >= $verbosity)) {
foreach ((array) $commands as $command) {
$this->explainer->line('$ '.$command, 'magenta');
}
}
} | php | protected function displayCommands($commands, $verbosity = 1)
{
// Print out command if verbosity level allows it
if ($verbosity && $this->hasCommand() && ($this->command->getVerbosity() >= $verbosity)) {
foreach ((array) $commands as $command) {
$this->explainer->line('$ '.$command, 'magenta');
}
}
} | [
"protected",
"function",
"displayCommands",
"(",
"$",
"commands",
",",
"$",
"verbosity",
"=",
"1",
")",
"{",
"// Print out command if verbosity level allows it",
"if",
"(",
"$",
"verbosity",
"&&",
"$",
"this",
"->",
"hasCommand",
"(",
")",
"&&",
"(",
"$",
"thi... | Display the passed commands.
@param string|array $commands
@param int $verbosity | [
"Display",
"the",
"passed",
"commands",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L228-L236 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.processCommands | public function processCommands($commands)
{
$separator = $this->environment->getSeparator();
$shell = $this->config->getContextually('remote.shell');
$shelled = $this->config->getContextually('remote.shelled');
$sudo = $this->config->getContextually('remote.sudo');
$sudoed = $this->config->getContextually('remote.sudoed');
// Prepare paths replacer
$pattern = sprintf('#\%s([\w\d\s])#', DS);
$replacement = sprintf('\%s$1', $separator);
// Cast commands to array
if (!is_array($commands)) {
$commands = [$commands];
}
// Flatten and process commands
$commands = Arr::flatten($commands);
foreach ($commands as &$command) {
// Replace directory separators
if (DS !== $separator) {
$command = preg_replace($pattern, $replacement, $command);
}
// Let framework process commands
if ($framework = $this->getFramework()) {
$command = $framework->processCommand($command);
}
// Create shell if asked
$forceShell = $this->modulable->getOption('shelled', true);
if ($forceShell || $shell && Str::contains($command, $shelled)) {
$command = $this->shellCommand($command);
}
if ($sudo && Str::contains($command, $sudoed)) {
$command = $this->sudoCommand($sudo, $command);
}
}
return $commands;
} | php | public function processCommands($commands)
{
$separator = $this->environment->getSeparator();
$shell = $this->config->getContextually('remote.shell');
$shelled = $this->config->getContextually('remote.shelled');
$sudo = $this->config->getContextually('remote.sudo');
$sudoed = $this->config->getContextually('remote.sudoed');
// Prepare paths replacer
$pattern = sprintf('#\%s([\w\d\s])#', DS);
$replacement = sprintf('\%s$1', $separator);
// Cast commands to array
if (!is_array($commands)) {
$commands = [$commands];
}
// Flatten and process commands
$commands = Arr::flatten($commands);
foreach ($commands as &$command) {
// Replace directory separators
if (DS !== $separator) {
$command = preg_replace($pattern, $replacement, $command);
}
// Let framework process commands
if ($framework = $this->getFramework()) {
$command = $framework->processCommand($command);
}
// Create shell if asked
$forceShell = $this->modulable->getOption('shelled', true);
if ($forceShell || $shell && Str::contains($command, $shelled)) {
$command = $this->shellCommand($command);
}
if ($sudo && Str::contains($command, $sudoed)) {
$command = $this->sudoCommand($sudo, $command);
}
}
return $commands;
} | [
"public",
"function",
"processCommands",
"(",
"$",
"commands",
")",
"{",
"$",
"separator",
"=",
"$",
"this",
"->",
"environment",
"->",
"getSeparator",
"(",
")",
";",
"$",
"shell",
"=",
"$",
"this",
"->",
"config",
"->",
"getContextually",
"(",
"'remote.sh... | Process an array of commands.
@param string|array $commands
@return array | [
"Process",
"an",
"array",
"of",
"commands",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L245-L287 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.cleanOutput | protected function cleanOutput($output)
{
$output = str_replace($this->extraOutput, null, $output);
return strtr($output, [
'stdin: is not a tty' => null,
]);
} | php | protected function cleanOutput($output)
{
$output = str_replace($this->extraOutput, null, $output);
return strtr($output, [
'stdin: is not a tty' => null,
]);
} | [
"protected",
"function",
"cleanOutput",
"(",
"$",
"output",
")",
"{",
"$",
"output",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"extraOutput",
",",
"null",
",",
"$",
"output",
")",
";",
"return",
"strtr",
"(",
"$",
"output",
",",
"[",
"'stdin: is not a ... | Clean the output of various intruding bits.
@param string $output
@return string | [
"Clean",
"the",
"output",
"of",
"various",
"intruding",
"bits",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L296-L303 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.sudoCommand | protected function sudoCommand($sudo, $command)
{
$sudo = is_bool($sudo) ? 'sudo' : 'sudo -u '.$sudo;
$command = $sudo.' '.$command;
return $command;
} | php | protected function sudoCommand($sudo, $command)
{
$sudo = is_bool($sudo) ? 'sudo' : 'sudo -u '.$sudo;
$command = $sudo.' '.$command;
return $command;
} | [
"protected",
"function",
"sudoCommand",
"(",
"$",
"sudo",
",",
"$",
"command",
")",
"{",
"$",
"sudo",
"=",
"is_bool",
"(",
"$",
"sudo",
")",
"?",
"'sudo'",
":",
"'sudo -u '",
".",
"$",
"sudo",
";",
"$",
"command",
"=",
"$",
"sudo",
".",
"' '",
".",... | Execute a command as a sudo user.
@param string|bool $sudo
@param string $command
@return string | [
"Execute",
"a",
"command",
"as",
"a",
"sudo",
"user",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L325-L331 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Shell/Modules/Core.php | Core.processOutput | protected function processOutput($output, $array = false, $trim = true)
{
// Remove polluting strings
$output = $this->cleanOutput($output);
// Explode output if necessary
if ($array) {
$delimiter = $this->environment->getLineEndings() ?: PHP_EOL;
$output = explode($delimiter, $output);
}
// Trim output
if ($trim) {
$output = is_array($output)
? array_filter($output)
: trim($output);
}
return $output;
} | php | protected function processOutput($output, $array = false, $trim = true)
{
// Remove polluting strings
$output = $this->cleanOutput($output);
// Explode output if necessary
if ($array) {
$delimiter = $this->environment->getLineEndings() ?: PHP_EOL;
$output = explode($delimiter, $output);
}
// Trim output
if ($trim) {
$output = is_array($output)
? array_filter($output)
: trim($output);
}
return $output;
} | [
"protected",
"function",
"processOutput",
"(",
"$",
"output",
",",
"$",
"array",
"=",
"false",
",",
"$",
"trim",
"=",
"true",
")",
"{",
"// Remove polluting strings",
"$",
"output",
"=",
"$",
"this",
"->",
"cleanOutput",
"(",
"$",
"output",
")",
";",
"//... | Process the output of a command.
@param string $output
@param bool $array Whether to return an array or a string
@param bool $trim Whether to trim the output or not
@return string|array | [
"Process",
"the",
"output",
"of",
"a",
"command",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Shell/Modules/Core.php#L342-L361 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Check/RubyStrategy.php | RubyStrategy.getLanguageConstraint | protected function getLanguageConstraint($manifest)
{
preg_match('/ruby \'(.+)\'/', $manifest, $matches);
$required = Arr::get((array) $matches, 1);
return $required;
} | php | protected function getLanguageConstraint($manifest)
{
preg_match('/ruby \'(.+)\'/', $manifest, $matches);
$required = Arr::get((array) $matches, 1);
return $required;
} | [
"protected",
"function",
"getLanguageConstraint",
"(",
"$",
"manifest",
")",
"{",
"preg_match",
"(",
"'/ruby \\'(.+)\\'/'",
",",
"$",
"manifest",
",",
"$",
"matches",
")",
";",
"$",
"required",
"=",
"Arr",
"::",
"get",
"(",
"(",
"array",
")",
"$",
"matches... | Get the version constraint which should be checked against.
@param string $manifest
@return string | [
"Get",
"the",
"version",
"constraint",
"which",
"should",
"be",
"checked",
"against",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Check/RubyStrategy.php#L55-L61 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Check/PhpStrategy.php | PhpStrategy.getRequiredExtensions | public function getRequiredExtensions()
{
$extensions = [];
if (!$manifest = $this->getManager()->getManifestContents()) {
return $extensions;
}
$data = json_decode($manifest, true);
$require = (array) array_get($data, 'require');
foreach ($require as $package => $version) {
if (mb_substr($package, 0, 4) === 'ext-') {
$extensions[] = mb_substr($package, 4);
}
}
return $extensions;
} | php | public function getRequiredExtensions()
{
$extensions = [];
if (!$manifest = $this->getManager()->getManifestContents()) {
return $extensions;
}
$data = json_decode($manifest, true);
$require = (array) array_get($data, 'require');
foreach ($require as $package => $version) {
if (mb_substr($package, 0, 4) === 'ext-') {
$extensions[] = mb_substr($package, 4);
}
}
return $extensions;
} | [
"public",
"function",
"getRequiredExtensions",
"(",
")",
"{",
"$",
"extensions",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"manifest",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getManifestContents",
"(",
")",
")",
"{",
"return",
"$",
"exten... | Check for the required extensions.
@return string[] | [
"Check",
"for",
"the",
"required",
"extensions",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Check/PhpStrategy.php#L84-L100 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Check/PhpStrategy.php | PhpStrategy.checkExtension | public function checkExtension($extension)
{
// Check for HHVM and built-in extensions
if ($this->php()->isHhvm()) {
$this->extensions = [
'_hhvm',
'apache',
'asio',
'bcmath',
'bz2',
'ctype',
'curl',
'debugger',
'fileinfo',
'filter',
'gd',
'hash',
'hh',
'iconv',
'icu',
'imagick',
'imap',
'json',
'mailparse',
'mcrypt',
'memcache',
'memcached',
'mysql',
'odbc',
'openssl',
'pcre',
'phar',
'reflection',
'session',
'soap',
'std',
'stream',
'thrift',
'url',
'wddx',
'xdebug',
'zip',
'zlib',
];
}
// Get the PHP extensions available
if (!$this->extensions) {
$this->extensions = (array) $this->bash->run($this->php()->extensions(), false, true);
}
return in_array($extension, $this->extensions, true);
} | php | public function checkExtension($extension)
{
// Check for HHVM and built-in extensions
if ($this->php()->isHhvm()) {
$this->extensions = [
'_hhvm',
'apache',
'asio',
'bcmath',
'bz2',
'ctype',
'curl',
'debugger',
'fileinfo',
'filter',
'gd',
'hash',
'hh',
'iconv',
'icu',
'imagick',
'imap',
'json',
'mailparse',
'mcrypt',
'memcache',
'memcached',
'mysql',
'odbc',
'openssl',
'pcre',
'phar',
'reflection',
'session',
'soap',
'std',
'stream',
'thrift',
'url',
'wddx',
'xdebug',
'zip',
'zlib',
];
}
// Get the PHP extensions available
if (!$this->extensions) {
$this->extensions = (array) $this->bash->run($this->php()->extensions(), false, true);
}
return in_array($extension, $this->extensions, true);
} | [
"public",
"function",
"checkExtension",
"(",
"$",
"extension",
")",
"{",
"// Check for HHVM and built-in extensions",
"if",
"(",
"$",
"this",
"->",
"php",
"(",
")",
"->",
"isHhvm",
"(",
")",
")",
"{",
"$",
"this",
"->",
"extensions",
"=",
"[",
"'_hhvm'",
"... | Check the presence of a PHP extension.
@param string $extension The extension
@return bool | [
"Check",
"the",
"presence",
"of",
"a",
"PHP",
"extension",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Check/PhpStrategy.php#L109-L161 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Check/NodeStrategy.php | NodeStrategy.getCurrentVersion | protected function getCurrentVersion()
{
$version = $this->getBinary()->run('--version');
$version = str_replace('v', null, $version);
return $version;
} | php | protected function getCurrentVersion()
{
$version = $this->getBinary()->run('--version');
$version = str_replace('v', null, $version);
return $version;
} | [
"protected",
"function",
"getCurrentVersion",
"(",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getBinary",
"(",
")",
"->",
"run",
"(",
"'--version'",
")",
";",
"$",
"version",
"=",
"str_replace",
"(",
"'v'",
",",
"null",
",",
"$",
"version",
")"... | Get the current version in use.
@return string | [
"Get",
"the",
"current",
"version",
"in",
"use",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Check/NodeStrategy.php#L59-L65 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/ConnectionsFactory.php | ConnectionsFactory.make | public function make(ConnectionKey $connectionKey)
{
$type = $connectionKey->host === 'localhost' ? LocalConnection::class : Connection::class;
return new $type($connectionKey);
} | php | public function make(ConnectionKey $connectionKey)
{
$type = $connectionKey->host === 'localhost' ? LocalConnection::class : Connection::class;
return new $type($connectionKey);
} | [
"public",
"function",
"make",
"(",
"ConnectionKey",
"$",
"connectionKey",
")",
"{",
"$",
"type",
"=",
"$",
"connectionKey",
"->",
"host",
"===",
"'localhost'",
"?",
"LocalConnection",
"::",
"class",
":",
"Connection",
"::",
"class",
";",
"return",
"new",
"$"... | Build a Connection instance from a ConnectionKey.
@param ConnectionKey $connectionKey
@return Connection | [
"Build",
"a",
"Connection",
"instance",
"from",
"a",
"ConnectionKey",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/ConnectionsFactory.php#L31-L36 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Filesystem/MountManager.php | MountManager.mountCurrentFilesystems | public function mountCurrentFilesystems()
{
$connections = $this->connections->getConnections()->all();
// Mount current connection as remote://
$current = $this->connections->getCurrentConnectionKey()->toHandle();
if (isset($connections[$current])) {
$connections['remote'] = $connections[$current];
}
$this->mountFilesystems($connections);
} | php | public function mountCurrentFilesystems()
{
$connections = $this->connections->getConnections()->all();
// Mount current connection as remote://
$current = $this->connections->getCurrentConnectionKey()->toHandle();
if (isset($connections[$current])) {
$connections['remote'] = $connections[$current];
}
$this->mountFilesystems($connections);
} | [
"public",
"function",
"mountCurrentFilesystems",
"(",
")",
"{",
"$",
"connections",
"=",
"$",
"this",
"->",
"connections",
"->",
"getConnections",
"(",
")",
"->",
"all",
"(",
")",
";",
"// Mount current connection as remote://",
"$",
"current",
"=",
"$",
"this",... | Gather the remote filesystems to mount.
@return Filesystem[] | [
"Gather",
"the",
"remote",
"filesystems",
"to",
"mount",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Filesystem/MountManager.php#L41-L52 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Credentials/Keys/ConnectionKey.php | ConnectionKey.getServerCredentials | public function getServerCredentials()
{
if (is_null($this->server)) {
return [];
}
return isset($this->servers[$this->server]) ? $this->servers[$this->server] : [];
} | php | public function getServerCredentials()
{
if (is_null($this->server)) {
return [];
}
return isset($this->servers[$this->server]) ? $this->servers[$this->server] : [];
} | [
"public",
"function",
"getServerCredentials",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"server",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"servers",
"[",
"$",
"this",
"->",
"server",
... | Get the credentials of the current server.
@return array | [
"Get",
"the",
"credentials",
"of",
"the",
"current",
"server",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Credentials/Keys/ConnectionKey.php#L81-L88 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Connections/Credentials/Keys/ConnectionKey.php | ConnectionKey.getServerCredential | public function getServerCredential($credential)
{
$credentials = $this->getServerCredentials();
return isset($credentials[$credential]) ? $credentials[$credential] : null;
} | php | public function getServerCredential($credential)
{
$credentials = $this->getServerCredentials();
return isset($credentials[$credential]) ? $credentials[$credential] : null;
} | [
"public",
"function",
"getServerCredential",
"(",
"$",
"credential",
")",
"{",
"$",
"credentials",
"=",
"$",
"this",
"->",
"getServerCredentials",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"credentials",
"[",
"$",
"credential",
"]",
")",
"?",
"$",
"crede... | Get a credential in particular.
@param string $credential
@return string|array | [
"Get",
"a",
"credential",
"in",
"particular",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Connections/Credentials/Keys/ConnectionKey.php#L97-L102 | train |
rocketeers/rocketeer | src/Rocketeer/Traits/HasLocatorTrait.php | HasLocatorTrait.getOption | public function getOption($option, $loose = false)
{
// Verbosity levels
if ($this->hasCommand() && $option === 'verbose') {
return $this->command->getVerbosity() > OutputInterface::VERBOSITY_NORMAL;
}
// Gather options
$options = isset($this->options) ? $this->options : [];
// If we have a command and a matching option, get it
if ($this->hasCommand()) {
if (!$loose) {
return $this->command->option($option);
}
$options = array_merge($options, (array) $this->command->option());
}
return Arr::get($options, $option);
} | php | public function getOption($option, $loose = false)
{
// Verbosity levels
if ($this->hasCommand() && $option === 'verbose') {
return $this->command->getVerbosity() > OutputInterface::VERBOSITY_NORMAL;
}
// Gather options
$options = isset($this->options) ? $this->options : [];
// If we have a command and a matching option, get it
if ($this->hasCommand()) {
if (!$loose) {
return $this->command->option($option);
}
$options = array_merge($options, (array) $this->command->option());
}
return Arr::get($options, $option);
} | [
"public",
"function",
"getOption",
"(",
"$",
"option",
",",
"$",
"loose",
"=",
"false",
")",
"{",
"// Verbosity levels",
"if",
"(",
"$",
"this",
"->",
"hasCommand",
"(",
")",
"&&",
"$",
"option",
"===",
"'verbose'",
")",
"{",
"return",
"$",
"this",
"->... | Get an option from the Command.
@param string $option
@param bool $loose
@return string | [
"Get",
"an",
"option",
"from",
"the",
"Command",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Traits/HasLocatorTrait.php#L186-L206 | train |
rocketeers/rocketeer | src/Rocketeer/Strategies/Dependencies/BowerStrategy.php | BowerStrategy.getInstallationOptions | protected function getInstallationOptions($command)
{
$flags = (array) $this->getFlags($command);
$credentials = $this->credentials->getServerCredentials();
if (Arr::get($credentials, 'username') === 'root') {
return array_merge($flags, ['--allow-root' => null]);
}
return $flags;
} | php | protected function getInstallationOptions($command)
{
$flags = (array) $this->getFlags($command);
$credentials = $this->credentials->getServerCredentials();
if (Arr::get($credentials, 'username') === 'root') {
return array_merge($flags, ['--allow-root' => null]);
}
return $flags;
} | [
"protected",
"function",
"getInstallationOptions",
"(",
"$",
"command",
")",
"{",
"$",
"flags",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getFlags",
"(",
"$",
"command",
")",
";",
"$",
"credentials",
"=",
"$",
"this",
"->",
"credentials",
"->",
"getSer... | Get the options to run Bower with.
@param string $command
@return array | [
"Get",
"the",
"options",
"to",
"run",
"Bower",
"with",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Strategies/Dependencies/BowerStrategy.php#L45-L54 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Tasks/TasksHandler.php | TasksHandler.add | public function add($task, $name = null, $description = null)
{
// Build task if necessary
$task = $this->builder->buildTask($task, $name, $description);
$this->container->add('rocketeer.'.$task->getIdentifier(), $task);
// Add related command
$bound = $this->command($task->getSlug(), new BaseTaskCommand($task));
return $bound;
} | php | public function add($task, $name = null, $description = null)
{
// Build task if necessary
$task = $this->builder->buildTask($task, $name, $description);
$this->container->add('rocketeer.'.$task->getIdentifier(), $task);
// Add related command
$bound = $this->command($task->getSlug(), new BaseTaskCommand($task));
return $bound;
} | [
"public",
"function",
"add",
"(",
"$",
"task",
",",
"$",
"name",
"=",
"null",
",",
"$",
"description",
"=",
"null",
")",
"{",
"// Build task if necessary",
"$",
"task",
"=",
"$",
"this",
"->",
"builder",
"->",
"buildTask",
"(",
"$",
"task",
",",
"$",
... | Register a custom task or command with Rocketeer.
@param string|Closure|AbstractTask $task
@param string|null $name
@param string|null $description
@return BaseTaskCommand | [
"Register",
"a",
"custom",
"task",
"or",
"command",
"with",
"Rocketeer",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Tasks/TasksHandler.php#L75-L85 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Tasks/TasksHandler.php | TasksHandler.task | public function task($name, $task = null, $description = null)
{
return $this->add($task, $name, $description)->getTask();
} | php | public function task($name, $task = null, $description = null)
{
return $this->add($task, $name, $description)->getTask();
} | [
"public",
"function",
"task",
"(",
"$",
"name",
",",
"$",
"task",
"=",
"null",
",",
"$",
"description",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"task",
",",
"$",
"name",
",",
"$",
"description",
")",
"->",
"getTask",
... | Register a task with Rocketeer.
@param string $name
@param string|Closure|\Rocketeer\Tasks\AbstractTask|null $task
@param string|null $description
@return BaseTaskCommand | [
"Register",
"a",
"task",
"with",
"Rocketeer",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Tasks/TasksHandler.php#L96-L99 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Tasks/TasksHandler.php | TasksHandler.listenTo | public function listenTo($event, $listeners, $priority = 0)
{
/** @var \Rocketeer\Tasks\AbstractTask[] $listeners */
$listeners = $this->builder->isCallable($listeners) ? [$listeners] : (array) $listeners;
$listeners = $this->builder->buildTasks($listeners);
$event = Str::contains($event, ['commands.', 'strategies.', 'tasks.']) ? $event : 'tasks.'.$event;
// Register events
foreach ($listeners as $key => $listener) {
$handle = $this->getEventHandle(null, $event);
$this->events->addListener($handle, $listener, $priority ?: -$key);
}
return $event;
} | php | public function listenTo($event, $listeners, $priority = 0)
{
/** @var \Rocketeer\Tasks\AbstractTask[] $listeners */
$listeners = $this->builder->isCallable($listeners) ? [$listeners] : (array) $listeners;
$listeners = $this->builder->buildTasks($listeners);
$event = Str::contains($event, ['commands.', 'strategies.', 'tasks.']) ? $event : 'tasks.'.$event;
// Register events
foreach ($listeners as $key => $listener) {
$handle = $this->getEventHandle(null, $event);
$this->events->addListener($handle, $listener, $priority ?: -$key);
}
return $event;
} | [
"public",
"function",
"listenTo",
"(",
"$",
"event",
",",
"$",
"listeners",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"/** @var \\Rocketeer\\Tasks\\AbstractTask[] $listeners */",
"$",
"listeners",
"=",
"$",
"this",
"->",
"builder",
"->",
"isCallable",
"(",
"$",
... | Register listeners for a particular event.
@param string $event
@param array|callable $listeners
@param int $priority
@return string | [
"Register",
"listeners",
"for",
"a",
"particular",
"event",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Tasks/TasksHandler.php#L169-L183 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Tasks/TasksHandler.php | TasksHandler.addTaskListeners | public function addTaskListeners($task, $event, $listeners, $priority = 0)
{
// Recursive call
if (is_array($task)) {
foreach ($task as $t) {
$this->addTaskListeners($t, $event, $listeners, $priority);
}
return;
}
// Cancel if no listeners
if (!$listeners) {
return;
}
// Prevent events on anonymous tasks
$task = $this->builder->buildTask($task);
if ($task->getSlug() === 'closure') {
return;
}
// Get event name and register listeners
$event = $this->getEventHandle($task, $event);
$event = $this->listenTo($event, $listeners, $priority);
return $event;
} | php | public function addTaskListeners($task, $event, $listeners, $priority = 0)
{
// Recursive call
if (is_array($task)) {
foreach ($task as $t) {
$this->addTaskListeners($t, $event, $listeners, $priority);
}
return;
}
// Cancel if no listeners
if (!$listeners) {
return;
}
// Prevent events on anonymous tasks
$task = $this->builder->buildTask($task);
if ($task->getSlug() === 'closure') {
return;
}
// Get event name and register listeners
$event = $this->getEventHandle($task, $event);
$event = $this->listenTo($event, $listeners, $priority);
return $event;
} | [
"public",
"function",
"addTaskListeners",
"(",
"$",
"task",
",",
"$",
"event",
",",
"$",
"listeners",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"// Recursive call",
"if",
"(",
"is_array",
"(",
"$",
"task",
")",
")",
"{",
"foreach",
"(",
"$",
"task",
... | Bind a listener to a task.
@param string|array $task
@param string $event
@param array|callable $listeners
@param int $priority
@throws \Rocketeer\Services\Builders\TaskCompositionException
@return string|null | [
"Bind",
"a",
"listener",
"to",
"a",
"task",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Tasks/TasksHandler.php#L197-L224 | train |
rocketeers/rocketeer | src/Rocketeer/Services/Tasks/TasksHandler.php | TasksHandler.getTasksListeners | public function getTasksListeners($task, $event, $flatten = false)
{
// Get events
$task = $this->builder->buildTaskFromClass($task);
$handle = $this->getEventHandle($task, $event);
$events = $this->events->getListeners($handle);
// Flatten the queue if requested
foreach ($events as $key => $listener) {
if ($flatten && $listener instanceof ClosureTask && $stringTask = $listener->getStringTask()) {
$events[$key] = $stringTask;
} elseif ($flatten && $listener instanceof AbstractTask) {
$events[$key] = $listener->getSlug();
}
}
return $events;
} | php | public function getTasksListeners($task, $event, $flatten = false)
{
// Get events
$task = $this->builder->buildTaskFromClass($task);
$handle = $this->getEventHandle($task, $event);
$events = $this->events->getListeners($handle);
// Flatten the queue if requested
foreach ($events as $key => $listener) {
if ($flatten && $listener instanceof ClosureTask && $stringTask = $listener->getStringTask()) {
$events[$key] = $stringTask;
} elseif ($flatten && $listener instanceof AbstractTask) {
$events[$key] = $listener->getSlug();
}
}
return $events;
} | [
"public",
"function",
"getTasksListeners",
"(",
"$",
"task",
",",
"$",
"event",
",",
"$",
"flatten",
"=",
"false",
")",
"{",
"// Get events",
"$",
"task",
"=",
"$",
"this",
"->",
"builder",
"->",
"buildTaskFromClass",
"(",
"$",
"task",
")",
";",
"$",
"... | Get all of a task's listeners.
@param string|AbstractTask $task
@param string $event
@param bool $flatten
@return array | [
"Get",
"all",
"of",
"a",
"task",
"s",
"listeners",
"."
] | 8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0 | https://github.com/rocketeers/rocketeer/blob/8a381d5b03a5554c2c0d466bd49c3bdf6a6e20c0/src/Rocketeer/Services/Tasks/TasksHandler.php#L235-L252 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.