repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
drupalwxt/wxt | src/Composer/ReleaseVersion.php | ReleaseVersion.updateMakeFile | protected static function updateMakeFile($version) {
$encoder = new IniEncoder();
$finder = (new Finder())
->name('build-wxt.make')
->in('.');
/** @var \Symfony\Component\Finder\SplFileInfo $make_file */
foreach ($finder as $make_file) {
$make = $encoder->parse($make_file->getContents());
$make['projects']['wxt']['download']['tag'] = $version;
file_put_contents($make_file->getPathname(), $encoder->encode($make));
}
} | php | protected static function updateMakeFile($version) {
$encoder = new IniEncoder();
$finder = (new Finder())
->name('build-wxt.make')
->in('.');
/** @var \Symfony\Component\Finder\SplFileInfo $make_file */
foreach ($finder as $make_file) {
$make = $encoder->parse($make_file->getContents());
$make['projects']['wxt']['download']['tag'] = $version;
file_put_contents($make_file->getPathname(), $encoder->encode($make));
}
} | [
"protected",
"static",
"function",
"updateMakeFile",
"(",
"$",
"version",
")",
"{",
"$",
"encoder",
"=",
"new",
"IniEncoder",
"(",
")",
";",
"$",
"finder",
"=",
"(",
"new",
"Finder",
"(",
")",
")",
"->",
"name",
"(",
"'build-wxt.make'",
")",
"->",
"in",
"(",
"'.'",
")",
";",
"/** @var \\Symfony\\Component\\Finder\\SplFileInfo $make_file */",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"make_file",
")",
"{",
"$",
"make",
"=",
"$",
"encoder",
"->",
"parse",
"(",
"$",
"make_file",
"->",
"getContents",
"(",
")",
")",
";",
"$",
"make",
"[",
"'projects'",
"]",
"[",
"'wxt'",
"]",
"[",
"'download'",
"]",
"[",
"'tag'",
"]",
"=",
"$",
"version",
";",
"file_put_contents",
"(",
"$",
"make_file",
"->",
"getPathname",
"(",
")",
",",
"$",
"encoder",
"->",
"encode",
"(",
"$",
"make",
")",
")",
";",
"}",
"}"
] | Updates the legacy Drush make file(s).
@param string $version
The target version. | [
"Updates",
"the",
"legacy",
"Drush",
"make",
"file",
"(",
"s",
")",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/src/Composer/ReleaseVersion.php#L56-L69 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_breadcrumb/src/Breadcrumb/BlogBreadcrumbBuilder.php | BlogBreadcrumbBuilder.build | public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$links = [];
// Add the url.path.parent cache context. This code ignores the last path
// part so the result only depends on the path parents.
$breadcrumb->addCacheContexts(['url.path.parent']);
$links[] = Link::createFromRoute($this->t('Home'), '<front>');
$breadcrumb->setLinks(array_reverse($links));
$route = $route_match->getRouteObject();
if ($route && !$route->getOption('_admin_route')) {
$links = $breadcrumb->getLinks();
if (!empty($links) && $links[0]->getText() == $this->t('Home')) {
$url = 'https://www.canada.ca/en.html';
if ($this->languageManager->getCurrentLanguage()->getId() == 'fr') {
$url = 'https://www.canada.ca/fr.html';
}
$link = array_shift($links);
$link->setUrl(Url::fromUri($url));
if (stripos($this->context->getPathInfo(), "blog") !== FALSE) {
$tbs = Url::fromUri('https://github.com/drupalwxt/wxt');
$linkTbs = Link::fromTextAndUrl("Drupal WxT", $tbs);
$linkTbsBlog = Link::createFromRoute($this->t('Blog'), '<front>');
if ($this->languageManager->getCurrentLanguage()->getId() == 'fr') {
$tbs = Url::fromUri('https://github.com/drupalwxt/wxt');
$linkTbs = Link::fromTextAndUrl("Drupal WxT", $tbs);
}
array_unshift($links, $linkTbs, $linkTbsBlog);
}
array_unshift($links, $link);
}
$breadcrumb = new Breadcrumb();
$breadcrumb->addCacheContexts(['url.path.parent']);
$breadcrumb->setLinks($links);
}
return $breadcrumb;
} | php | public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$links = [];
// Add the url.path.parent cache context. This code ignores the last path
// part so the result only depends on the path parents.
$breadcrumb->addCacheContexts(['url.path.parent']);
$links[] = Link::createFromRoute($this->t('Home'), '<front>');
$breadcrumb->setLinks(array_reverse($links));
$route = $route_match->getRouteObject();
if ($route && !$route->getOption('_admin_route')) {
$links = $breadcrumb->getLinks();
if (!empty($links) && $links[0]->getText() == $this->t('Home')) {
$url = 'https://www.canada.ca/en.html';
if ($this->languageManager->getCurrentLanguage()->getId() == 'fr') {
$url = 'https://www.canada.ca/fr.html';
}
$link = array_shift($links);
$link->setUrl(Url::fromUri($url));
if (stripos($this->context->getPathInfo(), "blog") !== FALSE) {
$tbs = Url::fromUri('https://github.com/drupalwxt/wxt');
$linkTbs = Link::fromTextAndUrl("Drupal WxT", $tbs);
$linkTbsBlog = Link::createFromRoute($this->t('Blog'), '<front>');
if ($this->languageManager->getCurrentLanguage()->getId() == 'fr') {
$tbs = Url::fromUri('https://github.com/drupalwxt/wxt');
$linkTbs = Link::fromTextAndUrl("Drupal WxT", $tbs);
}
array_unshift($links, $linkTbs, $linkTbsBlog);
}
array_unshift($links, $link);
}
$breadcrumb = new Breadcrumb();
$breadcrumb->addCacheContexts(['url.path.parent']);
$breadcrumb->setLinks($links);
}
return $breadcrumb;
} | [
"public",
"function",
"build",
"(",
"RouteMatchInterface",
"$",
"route_match",
")",
"{",
"$",
"breadcrumb",
"=",
"new",
"Breadcrumb",
"(",
")",
";",
"$",
"links",
"=",
"[",
"]",
";",
"// Add the url.path.parent cache context. This code ignores the last path",
"// part so the result only depends on the path parents.",
"$",
"breadcrumb",
"->",
"addCacheContexts",
"(",
"[",
"'url.path.parent'",
"]",
")",
";",
"$",
"links",
"[",
"]",
"=",
"Link",
"::",
"createFromRoute",
"(",
"$",
"this",
"->",
"t",
"(",
"'Home'",
")",
",",
"'<front>'",
")",
";",
"$",
"breadcrumb",
"->",
"setLinks",
"(",
"array_reverse",
"(",
"$",
"links",
")",
")",
";",
"$",
"route",
"=",
"$",
"route_match",
"->",
"getRouteObject",
"(",
")",
";",
"if",
"(",
"$",
"route",
"&&",
"!",
"$",
"route",
"->",
"getOption",
"(",
"'_admin_route'",
")",
")",
"{",
"$",
"links",
"=",
"$",
"breadcrumb",
"->",
"getLinks",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"links",
")",
"&&",
"$",
"links",
"[",
"0",
"]",
"->",
"getText",
"(",
")",
"==",
"$",
"this",
"->",
"t",
"(",
"'Home'",
")",
")",
"{",
"$",
"url",
"=",
"'https://www.canada.ca/en.html'",
";",
"if",
"(",
"$",
"this",
"->",
"languageManager",
"->",
"getCurrentLanguage",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"'fr'",
")",
"{",
"$",
"url",
"=",
"'https://www.canada.ca/fr.html'",
";",
"}",
"$",
"link",
"=",
"array_shift",
"(",
"$",
"links",
")",
";",
"$",
"link",
"->",
"setUrl",
"(",
"Url",
"::",
"fromUri",
"(",
"$",
"url",
")",
")",
";",
"if",
"(",
"stripos",
"(",
"$",
"this",
"->",
"context",
"->",
"getPathInfo",
"(",
")",
",",
"\"blog\"",
")",
"!==",
"FALSE",
")",
"{",
"$",
"tbs",
"=",
"Url",
"::",
"fromUri",
"(",
"'https://github.com/drupalwxt/wxt'",
")",
";",
"$",
"linkTbs",
"=",
"Link",
"::",
"fromTextAndUrl",
"(",
"\"Drupal WxT\"",
",",
"$",
"tbs",
")",
";",
"$",
"linkTbsBlog",
"=",
"Link",
"::",
"createFromRoute",
"(",
"$",
"this",
"->",
"t",
"(",
"'Blog'",
")",
",",
"'<front>'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"languageManager",
"->",
"getCurrentLanguage",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"'fr'",
")",
"{",
"$",
"tbs",
"=",
"Url",
"::",
"fromUri",
"(",
"'https://github.com/drupalwxt/wxt'",
")",
";",
"$",
"linkTbs",
"=",
"Link",
"::",
"fromTextAndUrl",
"(",
"\"Drupal WxT\"",
",",
"$",
"tbs",
")",
";",
"}",
"array_unshift",
"(",
"$",
"links",
",",
"$",
"linkTbs",
",",
"$",
"linkTbsBlog",
")",
";",
"}",
"array_unshift",
"(",
"$",
"links",
",",
"$",
"link",
")",
";",
"}",
"$",
"breadcrumb",
"=",
"new",
"Breadcrumb",
"(",
")",
";",
"$",
"breadcrumb",
"->",
"addCacheContexts",
"(",
"[",
"'url.path.parent'",
"]",
")",
";",
"$",
"breadcrumb",
"->",
"setLinks",
"(",
"$",
"links",
")",
";",
"}",
"return",
"$",
"breadcrumb",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_breadcrumb/src/Breadcrumb/BlogBreadcrumbBuilder.php#L169-L213 |
drupalwxt/wxt | modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php | Lightbox.settingsForm | public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$image_styles = image_style_options(FALSE);
$form['thumb_image_style'] = [
'#title' => $this->t('Thumbnail Image Style'),
'#type' => 'select',
'#default_value' => $this->getSetting('thumb_image_style'),
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles,
];
$form['lbx_image_style'] = [
'#title' => $this->t('Lightbox Image Style'),
'#type' => 'select',
'#default_value' => $this->getSetting('lbx_image_style'),
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles,
];
$form['lbx_gal'] = [
'#title' => $this->t('Gallery Options'),
'#type' => 'select',
'#default_value' => $this->getSetting('lbx_gal'),
'#options' => $this->getGalleryOptions(),
];
return $form;
} | php | public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$image_styles = image_style_options(FALSE);
$form['thumb_image_style'] = [
'#title' => $this->t('Thumbnail Image Style'),
'#type' => 'select',
'#default_value' => $this->getSetting('thumb_image_style'),
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles,
];
$form['lbx_image_style'] = [
'#title' => $this->t('Lightbox Image Style'),
'#type' => 'select',
'#default_value' => $this->getSetting('lbx_image_style'),
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles,
];
$form['lbx_gal'] = [
'#title' => $this->t('Gallery Options'),
'#type' => 'select',
'#default_value' => $this->getSetting('lbx_gal'),
'#options' => $this->getGalleryOptions(),
];
return $form;
} | [
"public",
"function",
"settingsForm",
"(",
"array",
"$",
"form",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"$",
"form",
"=",
"parent",
"::",
"settingsForm",
"(",
"$",
"form",
",",
"$",
"form_state",
")",
";",
"$",
"image_styles",
"=",
"image_style_options",
"(",
"FALSE",
")",
";",
"$",
"form",
"[",
"'thumb_image_style'",
"]",
"=",
"[",
"'#title'",
"=>",
"$",
"this",
"->",
"t",
"(",
"'Thumbnail Image Style'",
")",
",",
"'#type'",
"=>",
"'select'",
",",
"'#default_value'",
"=>",
"$",
"this",
"->",
"getSetting",
"(",
"'thumb_image_style'",
")",
",",
"'#empty_option'",
"=>",
"$",
"this",
"->",
"t",
"(",
"'None (original image)'",
")",
",",
"'#options'",
"=>",
"$",
"image_styles",
",",
"]",
";",
"$",
"form",
"[",
"'lbx_image_style'",
"]",
"=",
"[",
"'#title'",
"=>",
"$",
"this",
"->",
"t",
"(",
"'Lightbox Image Style'",
")",
",",
"'#type'",
"=>",
"'select'",
",",
"'#default_value'",
"=>",
"$",
"this",
"->",
"getSetting",
"(",
"'lbx_image_style'",
")",
",",
"'#empty_option'",
"=>",
"$",
"this",
"->",
"t",
"(",
"'None (original image)'",
")",
",",
"'#options'",
"=>",
"$",
"image_styles",
",",
"]",
";",
"$",
"form",
"[",
"'lbx_gal'",
"]",
"=",
"[",
"'#title'",
"=>",
"$",
"this",
"->",
"t",
"(",
"'Gallery Options'",
")",
",",
"'#type'",
"=>",
"'select'",
",",
"'#default_value'",
"=>",
"$",
"this",
"->",
"getSetting",
"(",
"'lbx_gal'",
")",
",",
"'#options'",
"=>",
"$",
"this",
"->",
"getGalleryOptions",
"(",
")",
",",
"]",
";",
"return",
"$",
"form",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php#L39-L67 |
drupalwxt/wxt | modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php | Lightbox.settingsSummary | public function settingsSummary() {
$image_styles = image_style_options(FALSE);
$thumb_image_style = $this->getSetting('thumb_image_style');
$lbx_image_style = $this->getSetting('lbx_image_style');
$summary[] = $this->t('Thumbnail image style: @thumb_style. Lightbox image style: @lbx_style', [
'@thumb_style' => isset($image_styles[$thumb_image_style]) ? $thumb_image_style : 'Original Image',
'@lbx_style' => isset($image_styles[$lbx_image_style]) ? $lbx_image_style : 'Original Image',
]);
return $summary;
} | php | public function settingsSummary() {
$image_styles = image_style_options(FALSE);
$thumb_image_style = $this->getSetting('thumb_image_style');
$lbx_image_style = $this->getSetting('lbx_image_style');
$summary[] = $this->t('Thumbnail image style: @thumb_style. Lightbox image style: @lbx_style', [
'@thumb_style' => isset($image_styles[$thumb_image_style]) ? $thumb_image_style : 'Original Image',
'@lbx_style' => isset($image_styles[$lbx_image_style]) ? $lbx_image_style : 'Original Image',
]);
return $summary;
} | [
"public",
"function",
"settingsSummary",
"(",
")",
"{",
"$",
"image_styles",
"=",
"image_style_options",
"(",
"FALSE",
")",
";",
"$",
"thumb_image_style",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'thumb_image_style'",
")",
";",
"$",
"lbx_image_style",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'lbx_image_style'",
")",
";",
"$",
"summary",
"[",
"]",
"=",
"$",
"this",
"->",
"t",
"(",
"'Thumbnail image style: @thumb_style. Lightbox image style: @lbx_style'",
",",
"[",
"'@thumb_style'",
"=>",
"isset",
"(",
"$",
"image_styles",
"[",
"$",
"thumb_image_style",
"]",
")",
"?",
"$",
"thumb_image_style",
":",
"'Original Image'",
",",
"'@lbx_style'",
"=>",
"isset",
"(",
"$",
"image_styles",
"[",
"$",
"lbx_image_style",
"]",
")",
"?",
"$",
"lbx_image_style",
":",
"'Original Image'",
",",
"]",
")",
";",
"return",
"$",
"summary",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php#L72-L83 |
drupalwxt/wxt | modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php | Lightbox.viewElements | public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$thumb_image_style = $this->getSetting('thumb_image_style');
$lbx_image_style = $this->getSetting('lbx_image_style');
$lbx_gal = $this->getSetting('lbx_gal');
$files = $this->getEntitiesToView($items, $langcode);
foreach ($files as $delta => $file) {
$image_uri = $file->getFileUri();
$lbx_image_path = !empty($lbx_image_style) ? ImageStyle::load($lbx_image_style)->buildUrl($image_uri) : $image_uri;
$url = Url::fromUri(file_create_url($lbx_image_path));
$item = $file->_referringItem;
$item_attributes = $file->_attributes;
unset($file->_attributes);
$item_attributes['class'][] = 'thumbnail';
if ($lbx_gal === 'first_item' && $delta > 0) {
$item_attributes['class'][] = 'visually-hidden';
}
$elements[$delta] = [
'#theme' => 'image_formatter',
'#item' => $item,
'#item_attributes' => $item_attributes,
'#image_style' => $thumb_image_style,
'#url' => $url,
];
}
return $elements;
} | php | public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$thumb_image_style = $this->getSetting('thumb_image_style');
$lbx_image_style = $this->getSetting('lbx_image_style');
$lbx_gal = $this->getSetting('lbx_gal');
$files = $this->getEntitiesToView($items, $langcode);
foreach ($files as $delta => $file) {
$image_uri = $file->getFileUri();
$lbx_image_path = !empty($lbx_image_style) ? ImageStyle::load($lbx_image_style)->buildUrl($image_uri) : $image_uri;
$url = Url::fromUri(file_create_url($lbx_image_path));
$item = $file->_referringItem;
$item_attributes = $file->_attributes;
unset($file->_attributes);
$item_attributes['class'][] = 'thumbnail';
if ($lbx_gal === 'first_item' && $delta > 0) {
$item_attributes['class'][] = 'visually-hidden';
}
$elements[$delta] = [
'#theme' => 'image_formatter',
'#item' => $item,
'#item_attributes' => $item_attributes,
'#image_style' => $thumb_image_style,
'#url' => $url,
];
}
return $elements;
} | [
"public",
"function",
"viewElements",
"(",
"FieldItemListInterface",
"$",
"items",
",",
"$",
"langcode",
")",
"{",
"$",
"elements",
"=",
"[",
"]",
";",
"$",
"thumb_image_style",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'thumb_image_style'",
")",
";",
"$",
"lbx_image_style",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'lbx_image_style'",
")",
";",
"$",
"lbx_gal",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'lbx_gal'",
")",
";",
"$",
"files",
"=",
"$",
"this",
"->",
"getEntitiesToView",
"(",
"$",
"items",
",",
"$",
"langcode",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"delta",
"=>",
"$",
"file",
")",
"{",
"$",
"image_uri",
"=",
"$",
"file",
"->",
"getFileUri",
"(",
")",
";",
"$",
"lbx_image_path",
"=",
"!",
"empty",
"(",
"$",
"lbx_image_style",
")",
"?",
"ImageStyle",
"::",
"load",
"(",
"$",
"lbx_image_style",
")",
"->",
"buildUrl",
"(",
"$",
"image_uri",
")",
":",
"$",
"image_uri",
";",
"$",
"url",
"=",
"Url",
"::",
"fromUri",
"(",
"file_create_url",
"(",
"$",
"lbx_image_path",
")",
")",
";",
"$",
"item",
"=",
"$",
"file",
"->",
"_referringItem",
";",
"$",
"item_attributes",
"=",
"$",
"file",
"->",
"_attributes",
";",
"unset",
"(",
"$",
"file",
"->",
"_attributes",
")",
";",
"$",
"item_attributes",
"[",
"'class'",
"]",
"[",
"]",
"=",
"'thumbnail'",
";",
"if",
"(",
"$",
"lbx_gal",
"===",
"'first_item'",
"&&",
"$",
"delta",
">",
"0",
")",
"{",
"$",
"item_attributes",
"[",
"'class'",
"]",
"[",
"]",
"=",
"'visually-hidden'",
";",
"}",
"$",
"elements",
"[",
"$",
"delta",
"]",
"=",
"[",
"'#theme'",
"=>",
"'image_formatter'",
",",
"'#item'",
"=>",
"$",
"item",
",",
"'#item_attributes'",
"=>",
"$",
"item_attributes",
",",
"'#image_style'",
"=>",
"$",
"thumb_image_style",
",",
"'#url'",
"=>",
"$",
"url",
",",
"]",
";",
"}",
"return",
"$",
"elements",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php#L88-L120 |
drupalwxt/wxt | modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php | Lightbox.view | public function view(FieldItemListInterface $items, $langcode = NULL) {
$elements = parent::view($items, $langcode);
$lbx_gal = $this->getSetting('lbx_gal');
$elements['#attributes']['class'][] = 'wb-lbx';
$elements['#attributes']['class'][] = 'lbx-gal';
$elements['#attributes']['class'][] = 'wxt-' . Html::cleanCssIdentifier($lbx_gal);
return $elements;
} | php | public function view(FieldItemListInterface $items, $langcode = NULL) {
$elements = parent::view($items, $langcode);
$lbx_gal = $this->getSetting('lbx_gal');
$elements['#attributes']['class'][] = 'wb-lbx';
$elements['#attributes']['class'][] = 'lbx-gal';
$elements['#attributes']['class'][] = 'wxt-' . Html::cleanCssIdentifier($lbx_gal);
return $elements;
} | [
"public",
"function",
"view",
"(",
"FieldItemListInterface",
"$",
"items",
",",
"$",
"langcode",
"=",
"NULL",
")",
"{",
"$",
"elements",
"=",
"parent",
"::",
"view",
"(",
"$",
"items",
",",
"$",
"langcode",
")",
";",
"$",
"lbx_gal",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'lbx_gal'",
")",
";",
"$",
"elements",
"[",
"'#attributes'",
"]",
"[",
"'class'",
"]",
"[",
"]",
"=",
"'wb-lbx'",
";",
"$",
"elements",
"[",
"'#attributes'",
"]",
"[",
"'class'",
"]",
"[",
"]",
"=",
"'lbx-gal'",
";",
"$",
"elements",
"[",
"'#attributes'",
"]",
"[",
"'class'",
"]",
"[",
"]",
"=",
"'wxt-'",
".",
"Html",
"::",
"cleanCssIdentifier",
"(",
"$",
"lbx_gal",
")",
";",
"return",
"$",
"elements",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_core/src/Plugin/Field/FieldFormatter/Lightbox.php#L125-L132 |
drupalwxt/wxt | modules/custom/wxt_admin/src/EventSubscriber/MenuRouterRebuildSubscriber.php | MenuRouterRebuildSubscriber.onKernelRequestMenuRouterRebuild | public function onKernelRequestMenuRouterRebuild(GetResponseEvent $event) {
if (file_exists("public://rebuild.dat")) {
$site_path = preg_replace('/^sites\//', '', $this->sitePath);
if (!file_exists('public://.drushrc') && file_exists('public://') && is_writable('public://') && file_put_contents('public:///.drushrc', "<?php\n\$options['l'] = 'http://${site_path}';")) {
drupal_chmod('public:///.drushrc', 0444);
}
if ($this->routerBuilder->rebuild()) {
file_unmanaged_delete("public://rebuild.dat");
}
}
} | php | public function onKernelRequestMenuRouterRebuild(GetResponseEvent $event) {
if (file_exists("public://rebuild.dat")) {
$site_path = preg_replace('/^sites\//', '', $this->sitePath);
if (!file_exists('public://.drushrc') && file_exists('public://') && is_writable('public://') && file_put_contents('public:///.drushrc', "<?php\n\$options['l'] = 'http://${site_path}';")) {
drupal_chmod('public:///.drushrc', 0444);
}
if ($this->routerBuilder->rebuild()) {
file_unmanaged_delete("public://rebuild.dat");
}
}
} | [
"public",
"function",
"onKernelRequestMenuRouterRebuild",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"if",
"(",
"file_exists",
"(",
"\"public://rebuild.dat\"",
")",
")",
"{",
"$",
"site_path",
"=",
"preg_replace",
"(",
"'/^sites\\//'",
",",
"''",
",",
"$",
"this",
"->",
"sitePath",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"'public://.drushrc'",
")",
"&&",
"file_exists",
"(",
"'public://'",
")",
"&&",
"is_writable",
"(",
"'public://'",
")",
"&&",
"file_put_contents",
"(",
"'public:///.drushrc'",
",",
"\"<?php\\n\\$options['l'] = 'http://${site_path}';\"",
")",
")",
"{",
"drupal_chmod",
"(",
"'public:///.drushrc'",
",",
"0444",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"routerBuilder",
"->",
"rebuild",
"(",
")",
")",
"{",
"file_unmanaged_delete",
"(",
"\"public://rebuild.dat\"",
")",
";",
"}",
"}",
"}"
] | Rebuilds the menu router if the rebuild.dat file is found.
@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
The Event to process. | [
"Rebuilds",
"the",
"menu",
"router",
"if",
"the",
"rebuild",
".",
"dat",
"file",
"is",
"found",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_admin/src/EventSubscriber/MenuRouterRebuildSubscriber.php#L48-L59 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php | MigrationSubscriber.onMigrationPostRowSave | public function onMigrationPostRowSave(MigratePostRowSaveEvent $event) {
// Landing Page logic.
if ($event->getMigration()->id() == 'gcweb_node_landing_page' ||
$event->getMigration()->id() == 'gcweb_node_landing_page_translation') {
// Set front page to panelized "homepage".
$name = $event->getRow()->getSourceProperty('name');
// Bug in homepage detection logic prevents using alias.
$destinationIds = $event->getDestinationIdValues();
if ($name == 'homepage') {
$this->config->getEditable('system.site')
->set('page.front', '/node/' . $destinationIds[0])
->save(TRUE);
}
}
// Block logic for queue assignment.
if ($event->getMigration()->id() == 'gcweb_block_spotlight') {
$sourceBid = $event->getRow()->getSourceProperty('bid');
$destBid = $event->getDestinationIdValues();
if (!empty($sourceBid)) {
switch ($sourceBid) {
case 'feature_block_1':
case 'feature_block_2':
case 'feature_block_3':
$this->entityQueueCreate('front_page', $destBid);
break;
}
}
}
} | php | public function onMigrationPostRowSave(MigratePostRowSaveEvent $event) {
// Landing Page logic.
if ($event->getMigration()->id() == 'gcweb_node_landing_page' ||
$event->getMigration()->id() == 'gcweb_node_landing_page_translation') {
// Set front page to panelized "homepage".
$name = $event->getRow()->getSourceProperty('name');
// Bug in homepage detection logic prevents using alias.
$destinationIds = $event->getDestinationIdValues();
if ($name == 'homepage') {
$this->config->getEditable('system.site')
->set('page.front', '/node/' . $destinationIds[0])
->save(TRUE);
}
}
// Block logic for queue assignment.
if ($event->getMigration()->id() == 'gcweb_block_spotlight') {
$sourceBid = $event->getRow()->getSourceProperty('bid');
$destBid = $event->getDestinationIdValues();
if (!empty($sourceBid)) {
switch ($sourceBid) {
case 'feature_block_1':
case 'feature_block_2':
case 'feature_block_3':
$this->entityQueueCreate('front_page', $destBid);
break;
}
}
}
} | [
"public",
"function",
"onMigrationPostRowSave",
"(",
"MigratePostRowSaveEvent",
"$",
"event",
")",
"{",
"// Landing Page logic.",
"if",
"(",
"$",
"event",
"->",
"getMigration",
"(",
")",
"->",
"id",
"(",
")",
"==",
"'gcweb_node_landing_page'",
"||",
"$",
"event",
"->",
"getMigration",
"(",
")",
"->",
"id",
"(",
")",
"==",
"'gcweb_node_landing_page_translation'",
")",
"{",
"// Set front page to panelized \"homepage\".",
"$",
"name",
"=",
"$",
"event",
"->",
"getRow",
"(",
")",
"->",
"getSourceProperty",
"(",
"'name'",
")",
";",
"// Bug in homepage detection logic prevents using alias.",
"$",
"destinationIds",
"=",
"$",
"event",
"->",
"getDestinationIdValues",
"(",
")",
";",
"if",
"(",
"$",
"name",
"==",
"'homepage'",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"getEditable",
"(",
"'system.site'",
")",
"->",
"set",
"(",
"'page.front'",
",",
"'/node/'",
".",
"$",
"destinationIds",
"[",
"0",
"]",
")",
"->",
"save",
"(",
"TRUE",
")",
";",
"}",
"}",
"// Block logic for queue assignment.",
"if",
"(",
"$",
"event",
"->",
"getMigration",
"(",
")",
"->",
"id",
"(",
")",
"==",
"'gcweb_block_spotlight'",
")",
"{",
"$",
"sourceBid",
"=",
"$",
"event",
"->",
"getRow",
"(",
")",
"->",
"getSourceProperty",
"(",
"'bid'",
")",
";",
"$",
"destBid",
"=",
"$",
"event",
"->",
"getDestinationIdValues",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sourceBid",
")",
")",
"{",
"switch",
"(",
"$",
"sourceBid",
")",
"{",
"case",
"'feature_block_1'",
":",
"case",
"'feature_block_2'",
":",
"case",
"'feature_block_3'",
":",
"$",
"this",
"->",
"entityQueueCreate",
"(",
"'front_page'",
",",
"$",
"destBid",
")",
";",
"break",
";",
"}",
"}",
"}",
"}"
] | Code to run after a migration row has been saved. | [
"Code",
"to",
"run",
"after",
"a",
"migration",
"row",
"has",
"been",
"saved",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php#L181-L211 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php | MigrationSubscriber.getSubscribedEvents | public static function getSubscribedEvents() {
$events[MigrateEvents::PRE_ROW_SAVE] = 'onMigrationPreRowSave';
$events[MigrateEvents::POST_ROW_SAVE] = 'onMigrationPostRowSave';
$events[MigrateEvents::POST_IMPORT] = 'onMigrationPostImport';
return $events;
} | php | public static function getSubscribedEvents() {
$events[MigrateEvents::PRE_ROW_SAVE] = 'onMigrationPreRowSave';
$events[MigrateEvents::POST_ROW_SAVE] = 'onMigrationPostRowSave';
$events[MigrateEvents::POST_IMPORT] = 'onMigrationPostImport';
return $events;
} | [
"public",
"static",
"function",
"getSubscribedEvents",
"(",
")",
"{",
"$",
"events",
"[",
"MigrateEvents",
"::",
"PRE_ROW_SAVE",
"]",
"=",
"'onMigrationPreRowSave'",
";",
"$",
"events",
"[",
"MigrateEvents",
"::",
"POST_ROW_SAVE",
"]",
"=",
"'onMigrationPostRowSave'",
";",
"$",
"events",
"[",
"MigrateEvents",
"::",
"POST_IMPORT",
"]",
"=",
"'onMigrationPostImport'",
";",
"return",
"$",
"events",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php#L216-L221 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php | MigrationSubscriber.entityQueueCreate | public function entityQueueCreate($queue, $destBid) {
$entity_subqueue = $this->entityManager->getStorage('entity_subqueue')->load($queue);
$items = $entity_subqueue->get('items')->getValue();
$items[] = ['target_id' => $destBid[0]];
$entity_subqueue->set('items', $items);
$entity_subqueue->save();
} | php | public function entityQueueCreate($queue, $destBid) {
$entity_subqueue = $this->entityManager->getStorage('entity_subqueue')->load($queue);
$items = $entity_subqueue->get('items')->getValue();
$items[] = ['target_id' => $destBid[0]];
$entity_subqueue->set('items', $items);
$entity_subqueue->save();
} | [
"public",
"function",
"entityQueueCreate",
"(",
"$",
"queue",
",",
"$",
"destBid",
")",
"{",
"$",
"entity_subqueue",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getStorage",
"(",
"'entity_subqueue'",
")",
"->",
"load",
"(",
"$",
"queue",
")",
";",
"$",
"items",
"=",
"$",
"entity_subqueue",
"->",
"get",
"(",
"'items'",
")",
"->",
"getValue",
"(",
")",
";",
"$",
"items",
"[",
"]",
"=",
"[",
"'target_id'",
"=>",
"$",
"destBid",
"[",
"0",
"]",
"]",
";",
"$",
"entity_subqueue",
"->",
"set",
"(",
"'items'",
",",
"$",
"items",
")",
";",
"$",
"entity_subqueue",
"->",
"save",
"(",
")",
";",
"}"
] | Add a specific entityqueue. | [
"Add",
"a",
"specific",
"entityqueue",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php#L226-L232 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php | MigrationSubscriber.menuLinkDependency | public function menuLinkDependency($title, $link, $translations, $destBid, $weight = 0, $menu = 'main') {
$menu_link_content = $this->entityManager->getStorage('menu_link_content')->create([
'title' => $title,
'link' => ['uri' => 'internal:/node/' . $destBid[0]],
'menu_name' => (!empty($translations)) ? $menu . '-fr' : $menu,
'langcode' => (!empty($translations)) ? 'fr' : 'en',
'parent' => $link,
'weight' => $weight,
]);
$menu_link_content->save();
$this->database->update('menu_link_content_data')
->fields(['link__uri' => 'entity:node/' . $destBid[0]])
->condition('id', $menu_link_content->id())
->execute();
return $menu_link_content;
} | php | public function menuLinkDependency($title, $link, $translations, $destBid, $weight = 0, $menu = 'main') {
$menu_link_content = $this->entityManager->getStorage('menu_link_content')->create([
'title' => $title,
'link' => ['uri' => 'internal:/node/' . $destBid[0]],
'menu_name' => (!empty($translations)) ? $menu . '-fr' : $menu,
'langcode' => (!empty($translations)) ? 'fr' : 'en',
'parent' => $link,
'weight' => $weight,
]);
$menu_link_content->save();
$this->database->update('menu_link_content_data')
->fields(['link__uri' => 'entity:node/' . $destBid[0]])
->condition('id', $menu_link_content->id())
->execute();
return $menu_link_content;
} | [
"public",
"function",
"menuLinkDependency",
"(",
"$",
"title",
",",
"$",
"link",
",",
"$",
"translations",
",",
"$",
"destBid",
",",
"$",
"weight",
"=",
"0",
",",
"$",
"menu",
"=",
"'main'",
")",
"{",
"$",
"menu_link_content",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getStorage",
"(",
"'menu_link_content'",
")",
"->",
"create",
"(",
"[",
"'title'",
"=>",
"$",
"title",
",",
"'link'",
"=>",
"[",
"'uri'",
"=>",
"'internal:/node/'",
".",
"$",
"destBid",
"[",
"0",
"]",
"]",
",",
"'menu_name'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"translations",
")",
")",
"?",
"$",
"menu",
".",
"'-fr'",
":",
"$",
"menu",
",",
"'langcode'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"translations",
")",
")",
"?",
"'fr'",
":",
"'en'",
",",
"'parent'",
"=>",
"$",
"link",
",",
"'weight'",
"=>",
"$",
"weight",
",",
"]",
")",
";",
"$",
"menu_link_content",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"database",
"->",
"update",
"(",
"'menu_link_content_data'",
")",
"->",
"fields",
"(",
"[",
"'link__uri'",
"=>",
"'entity:node/'",
".",
"$",
"destBid",
"[",
"0",
"]",
"]",
")",
"->",
"condition",
"(",
"'id'",
",",
"$",
"menu_link_content",
"->",
"id",
"(",
")",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"menu_link_content",
";",
"}"
] | Add a menu link with dependency support. | [
"Add",
"a",
"menu",
"link",
"with",
"dependency",
"support",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/EventSubscriber/MigrationSubscriber.php#L237-L252 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/TextToTerm.php | TextToTerm.transform | public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$field = empty($this->configuration['field']) ? 'value' : $this->configuration['field'];
$termName = FALSE;
/*
* Depending on the context (whether the plugin is called
* as a part of an Iterator process, a pipe, or takes its
* sources from multiple-input Get plugin), we have to check
* for all value placement variants.
*/
if (isset($value[$field])) {
$termName = $value[$field];
}
elseif (!empty($row->getSourceProperty($field))) {
$termName = $row->getSourceProperty($field);
}
elseif (is_string($value)) {
$termName = $value;
}
if (!$termName) {
return $termName;
}
// Getting a term by lookup (if it exists), or creating one.
$term = $this->getTerm($termName, $row, $this->configuration['vocabulary']);
// Save it.
$term->save();
// Yes, all we need is ID.
return $term->id();
} | php | public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$field = empty($this->configuration['field']) ? 'value' : $this->configuration['field'];
$termName = FALSE;
/*
* Depending on the context (whether the plugin is called
* as a part of an Iterator process, a pipe, or takes its
* sources from multiple-input Get plugin), we have to check
* for all value placement variants.
*/
if (isset($value[$field])) {
$termName = $value[$field];
}
elseif (!empty($row->getSourceProperty($field))) {
$termName = $row->getSourceProperty($field);
}
elseif (is_string($value)) {
$termName = $value;
}
if (!$termName) {
return $termName;
}
// Getting a term by lookup (if it exists), or creating one.
$term = $this->getTerm($termName, $row, $this->configuration['vocabulary']);
// Save it.
$term->save();
// Yes, all we need is ID.
return $term->id();
} | [
"public",
"function",
"transform",
"(",
"$",
"value",
",",
"MigrateExecutableInterface",
"$",
"migrate_executable",
",",
"Row",
"$",
"row",
",",
"$",
"destination_property",
")",
"{",
"$",
"field",
"=",
"empty",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'field'",
"]",
")",
"?",
"'value'",
":",
"$",
"this",
"->",
"configuration",
"[",
"'field'",
"]",
";",
"$",
"termName",
"=",
"FALSE",
";",
"/*\n * Depending on the context (whether the plugin is called\n * as a part of an Iterator process, a pipe, or takes its\n * sources from multiple-input Get plugin), we have to check\n * for all value placement variants.\n */",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"termName",
"=",
"$",
"value",
"[",
"$",
"field",
"]",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"row",
"->",
"getSourceProperty",
"(",
"$",
"field",
")",
")",
")",
"{",
"$",
"termName",
"=",
"$",
"row",
"->",
"getSourceProperty",
"(",
"$",
"field",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"termName",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"!",
"$",
"termName",
")",
"{",
"return",
"$",
"termName",
";",
"}",
"// Getting a term by lookup (if it exists), or creating one.",
"$",
"term",
"=",
"$",
"this",
"->",
"getTerm",
"(",
"$",
"termName",
",",
"$",
"row",
",",
"$",
"this",
"->",
"configuration",
"[",
"'vocabulary'",
"]",
")",
";",
"// Save it.",
"$",
"term",
"->",
"save",
"(",
")",
";",
"// Yes, all we need is ID.",
"return",
"$",
"term",
"->",
"id",
"(",
")",
";",
"}"
] | The main function for the plugin, actually doing the data conversion. | [
"The",
"main",
"function",
"for",
"the",
"plugin",
"actually",
"doing",
"the",
"data",
"conversion",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/TextToTerm.php#L23-L51 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/TextToTerm.php | TextToTerm.getTerm | protected function getTerm($name, Row $row, $vocabulary) {
// Attempt to fetch an existing term.
$properties = [];
if (!empty($name)) {
$properties['name'] = $name;
}
$vocabularies = taxonomy_vocabulary_get_names();
if (isset($vocabularies[$vocabulary])) {
$properties['vid'] = $vocabulary;
}
else {
// Return NULL when filtering by a non-existing vocabulary.
return NULL;
}
$terms = \Drupal::getContainer()->get('entity.manager')->getStorage('taxonomy_term')->loadByProperties($properties);
$term = reset($terms);
if (!empty($term)) {
if ($row->getDestinationProperty('langcode') && $row->getDestinationProperty('langcode') != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
if (!$term->hasTranslation($row->getDestinationProperty('langcode'))) {
$term->addTranslation($row->getDestinationProperty('langcode'));
}
$term = $term->getTranslation($row->getDestinationProperty('langcode'));
}
return $term;
}
// Fallback, create a new term.
$term = Term::create($properties);
if ($row->getDestinationProperty('langcode')) {
$term->langcode = $row->getDestinationProperty('langcode');
}
return $term;
} | php | protected function getTerm($name, Row $row, $vocabulary) {
// Attempt to fetch an existing term.
$properties = [];
if (!empty($name)) {
$properties['name'] = $name;
}
$vocabularies = taxonomy_vocabulary_get_names();
if (isset($vocabularies[$vocabulary])) {
$properties['vid'] = $vocabulary;
}
else {
// Return NULL when filtering by a non-existing vocabulary.
return NULL;
}
$terms = \Drupal::getContainer()->get('entity.manager')->getStorage('taxonomy_term')->loadByProperties($properties);
$term = reset($terms);
if (!empty($term)) {
if ($row->getDestinationProperty('langcode') && $row->getDestinationProperty('langcode') != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
if (!$term->hasTranslation($row->getDestinationProperty('langcode'))) {
$term->addTranslation($row->getDestinationProperty('langcode'));
}
$term = $term->getTranslation($row->getDestinationProperty('langcode'));
}
return $term;
}
// Fallback, create a new term.
$term = Term::create($properties);
if ($row->getDestinationProperty('langcode')) {
$term->langcode = $row->getDestinationProperty('langcode');
}
return $term;
} | [
"protected",
"function",
"getTerm",
"(",
"$",
"name",
",",
"Row",
"$",
"row",
",",
"$",
"vocabulary",
")",
"{",
"// Attempt to fetch an existing term.",
"$",
"properties",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"properties",
"[",
"'name'",
"]",
"=",
"$",
"name",
";",
"}",
"$",
"vocabularies",
"=",
"taxonomy_vocabulary_get_names",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"vocabularies",
"[",
"$",
"vocabulary",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"'vid'",
"]",
"=",
"$",
"vocabulary",
";",
"}",
"else",
"{",
"// Return NULL when filtering by a non-existing vocabulary.",
"return",
"NULL",
";",
"}",
"$",
"terms",
"=",
"\\",
"Drupal",
"::",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'entity.manager'",
")",
"->",
"getStorage",
"(",
"'taxonomy_term'",
")",
"->",
"loadByProperties",
"(",
"$",
"properties",
")",
";",
"$",
"term",
"=",
"reset",
"(",
"$",
"terms",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"term",
")",
")",
"{",
"if",
"(",
"$",
"row",
"->",
"getDestinationProperty",
"(",
"'langcode'",
")",
"&&",
"$",
"row",
"->",
"getDestinationProperty",
"(",
"'langcode'",
")",
"!=",
"LanguageInterface",
"::",
"LANGCODE_NOT_SPECIFIED",
")",
"{",
"if",
"(",
"!",
"$",
"term",
"->",
"hasTranslation",
"(",
"$",
"row",
"->",
"getDestinationProperty",
"(",
"'langcode'",
")",
")",
")",
"{",
"$",
"term",
"->",
"addTranslation",
"(",
"$",
"row",
"->",
"getDestinationProperty",
"(",
"'langcode'",
")",
")",
";",
"}",
"$",
"term",
"=",
"$",
"term",
"->",
"getTranslation",
"(",
"$",
"row",
"->",
"getDestinationProperty",
"(",
"'langcode'",
")",
")",
";",
"}",
"return",
"$",
"term",
";",
"}",
"// Fallback, create a new term.",
"$",
"term",
"=",
"Term",
"::",
"create",
"(",
"$",
"properties",
")",
";",
"if",
"(",
"$",
"row",
"->",
"getDestinationProperty",
"(",
"'langcode'",
")",
")",
"{",
"$",
"term",
"->",
"langcode",
"=",
"$",
"row",
"->",
"getDestinationProperty",
"(",
"'langcode'",
")",
";",
"}",
"return",
"$",
"term",
";",
"}"
] | Creates a new or returns an existing term for the target vocabulary. | [
"Creates",
"a",
"new",
"or",
"returns",
"an",
"existing",
"term",
"for",
"the",
"target",
"vocabulary",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/TextToTerm.php#L56-L88 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php | ReportProblemBlock.blockForm | public function blockForm($form, FormStateInterface $form_state) {
$form['webform_id'] = [
'#title' => $this->t('Webform'),
'#type' => 'entity_autocomplete',
'#target_type' => 'webform',
'#required' => TRUE,
'#default_value' => $this->getWebform(),
];
return $form;
} | php | public function blockForm($form, FormStateInterface $form_state) {
$form['webform_id'] = [
'#title' => $this->t('Webform'),
'#type' => 'entity_autocomplete',
'#target_type' => 'webform',
'#required' => TRUE,
'#default_value' => $this->getWebform(),
];
return $form;
} | [
"public",
"function",
"blockForm",
"(",
"$",
"form",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"$",
"form",
"[",
"'webform_id'",
"]",
"=",
"[",
"'#title'",
"=>",
"$",
"this",
"->",
"t",
"(",
"'Webform'",
")",
",",
"'#type'",
"=>",
"'entity_autocomplete'",
",",
"'#target_type'",
"=>",
"'webform'",
",",
"'#required'",
"=>",
"TRUE",
",",
"'#default_value'",
"=>",
"$",
"this",
"->",
"getWebform",
"(",
")",
",",
"]",
";",
"return",
"$",
"form",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php#L97-L108 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php | ReportProblemBlock.build | public function build() {
$url = $this->getWebform()->toUrl()
->setOption('query', $this->requestStack->getCurrentRequest()->query->all())
->toString();
$markup = '<a class="btn btn-default" href="' . $url . '">';
$markup .= '<span class="glyphicon glyphicon-play"> </span>';
$markup .= $this->t('Report a problem on this page');
$markup .= '</a>';
$build['#markup'] = $markup;
return $build;
} | php | public function build() {
$url = $this->getWebform()->toUrl()
->setOption('query', $this->requestStack->getCurrentRequest()->query->all())
->toString();
$markup = '<a class="btn btn-default" href="' . $url . '">';
$markup .= '<span class="glyphicon glyphicon-play"> </span>';
$markup .= $this->t('Report a problem on this page');
$markup .= '</a>';
$build['#markup'] = $markup;
return $build;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getWebform",
"(",
")",
"->",
"toUrl",
"(",
")",
"->",
"setOption",
"(",
"'query'",
",",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"query",
"->",
"all",
"(",
")",
")",
"->",
"toString",
"(",
")",
";",
"$",
"markup",
"=",
"'<a class=\"btn btn-default\" href=\"'",
".",
"$",
"url",
".",
"'\">'",
";",
"$",
"markup",
".=",
"'<span class=\"glyphicon glyphicon-play\"> </span>'",
";",
"$",
"markup",
".=",
"$",
"this",
"->",
"t",
"(",
"'Report a problem on this page'",
")",
";",
"$",
"markup",
".=",
"'</a>'",
";",
"$",
"build",
"[",
"'#markup'",
"]",
"=",
"$",
"markup",
";",
"return",
"$",
"build",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php#L120-L131 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php | ReportProblemBlock.blockAccess | protected function blockAccess(AccountInterface $account) {
$webform = $this->getWebform();
if (!$webform) {
return AccessResult::forbidden();
}
$access_result = $webform->access('submission_create', $account, TRUE);
if ($access_result->isAllowed()) {
return $access_result;
}
$has_access_denied_message = ($webform->getSetting('form_access_denied') !== WebformInterface::ACCESS_DENIED_DEFAULT);
return AccessResult::allowedIf($has_access_denied_message)
->addCacheableDependency($access_result);
} | php | protected function blockAccess(AccountInterface $account) {
$webform = $this->getWebform();
if (!$webform) {
return AccessResult::forbidden();
}
$access_result = $webform->access('submission_create', $account, TRUE);
if ($access_result->isAllowed()) {
return $access_result;
}
$has_access_denied_message = ($webform->getSetting('form_access_denied') !== WebformInterface::ACCESS_DENIED_DEFAULT);
return AccessResult::allowedIf($has_access_denied_message)
->addCacheableDependency($access_result);
} | [
"protected",
"function",
"blockAccess",
"(",
"AccountInterface",
"$",
"account",
")",
"{",
"$",
"webform",
"=",
"$",
"this",
"->",
"getWebform",
"(",
")",
";",
"if",
"(",
"!",
"$",
"webform",
")",
"{",
"return",
"AccessResult",
"::",
"forbidden",
"(",
")",
";",
"}",
"$",
"access_result",
"=",
"$",
"webform",
"->",
"access",
"(",
"'submission_create'",
",",
"$",
"account",
",",
"TRUE",
")",
";",
"if",
"(",
"$",
"access_result",
"->",
"isAllowed",
"(",
")",
")",
"{",
"return",
"$",
"access_result",
";",
"}",
"$",
"has_access_denied_message",
"=",
"(",
"$",
"webform",
"->",
"getSetting",
"(",
"'form_access_denied'",
")",
"!==",
"WebformInterface",
"::",
"ACCESS_DENIED_DEFAULT",
")",
";",
"return",
"AccessResult",
"::",
"allowedIf",
"(",
"$",
"has_access_denied_message",
")",
"->",
"addCacheableDependency",
"(",
"$",
"access_result",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php#L136-L150 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php | ReportProblemBlock.calculateDependencies | public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$webform = $this->getWebform();
$dependencies[$webform->getConfigDependencyKey()][] = $webform->getConfigDependencyName();
return $dependencies;
} | php | public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$webform = $this->getWebform();
$dependencies[$webform->getConfigDependencyKey()][] = $webform->getConfigDependencyName();
return $dependencies;
} | [
"public",
"function",
"calculateDependencies",
"(",
")",
"{",
"$",
"dependencies",
"=",
"parent",
"::",
"calculateDependencies",
"(",
")",
";",
"$",
"webform",
"=",
"$",
"this",
"->",
"getWebform",
"(",
")",
";",
"$",
"dependencies",
"[",
"$",
"webform",
"->",
"getConfigDependencyKey",
"(",
")",
"]",
"[",
"]",
"=",
"$",
"webform",
"->",
"getConfigDependencyName",
"(",
")",
";",
"return",
"$",
"dependencies",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php#L155-L162 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/MediaTags.php | MediaTags.replaceToken | private function replaceToken($match, $migrate_executable, $row, $destination_property) {
$settings = [];
$match = str_replace("[[", "", $match);
$match = str_replace("]]", "", $match);
$tag = $match[0];
$classes = '';
try {
if (!is_string($tag)) {
throw new MigrateException('Unable to find matching tag');
}
// Make it into a fancy array.
$tag_info = Json::decode($tag);
if (!isset($tag_info['fid'])) {
throw new MigrateException('No file Id');
}
// Lookup the correct fid.
$fid = $this->migrationPlugin
->transform($tag_info['fid'], $migrate_executable, $row, $destination_property);
// Load the file.
$media = Media::load($fid);
if (!$media) {
throw new MigrateException('Could not load media object');
}
// The class attributes is a string, but drupal requires it to be an
// array, so we fix it here.
if (!empty($tag_info['attributes']['class'])) {
$classes = $tag_info['attributes']['class'];
$tag_info['attributes']['class'] = explode(" ", $tag_info['attributes']['class']);
}
$settings['attributes'] = is_array($tag_info['attributes']) ? $tag_info['attributes'] : [];
// Many media formatters will want to apply width and height independently
// of the style attribute or the corresponding HTML attributes, so pull
// these two out into top-level settings. Different WYSIWYG editors have
// different behavior with respect to whether they store user-specified
// dimensions in the HTML attributes or the style attribute so check both.
// Per http://www.w3.org/TR/html5/the-map-element.html#attr-dim-width, the
// HTML attributes are merely hints: CSS takes precedence.
if (isset($settings['attributes']['style'])) {
$css_properties = $this->mediaParseCssDeclarations($settings['attributes']['style']);
foreach (['width', 'height'] as $dimension) {
if (isset($css_properties[$dimension]) && substr($css_properties[$dimension], -2) == 'px') {
$settings[$dimension] = substr($css_properties[$dimension], 0, -2);
}
elseif (isset($settings['attributes'][$dimension])) {
$settings[$dimension] = $settings['attributes'][$dimension];
}
}
}
}
catch (Exception $e) {
$msg = t('Unable to render media from %tag. Error: %error', ['%tag' => $tag, '%error' => $e->getMessage()]);
\Drupal::logger('Migration')->error($msg);
return '';
}
$alt = isset($settings['alt']) ? $settings['alt'] : '';
$uuid = $media->uuid();
$title = $media->get('name')->value;
$class = isset($classes) ? 'class="' . $classes . '"' : '';
// New media entity format.
$output = '
<drupal-entity
alt="' . $alt . '"
data-embed-button="media_browser"
data-entity-embed-display="media_image"
data-entity-embed-display-settings="{"image_style":"","image_link":""}"
data-entity-type="media"
data-entity-uuid="' . $uuid . '"
title="' . $title . '" ' . $class . '>
</drupal-entity>
';
return $output;
} | php | private function replaceToken($match, $migrate_executable, $row, $destination_property) {
$settings = [];
$match = str_replace("[[", "", $match);
$match = str_replace("]]", "", $match);
$tag = $match[0];
$classes = '';
try {
if (!is_string($tag)) {
throw new MigrateException('Unable to find matching tag');
}
// Make it into a fancy array.
$tag_info = Json::decode($tag);
if (!isset($tag_info['fid'])) {
throw new MigrateException('No file Id');
}
// Lookup the correct fid.
$fid = $this->migrationPlugin
->transform($tag_info['fid'], $migrate_executable, $row, $destination_property);
// Load the file.
$media = Media::load($fid);
if (!$media) {
throw new MigrateException('Could not load media object');
}
// The class attributes is a string, but drupal requires it to be an
// array, so we fix it here.
if (!empty($tag_info['attributes']['class'])) {
$classes = $tag_info['attributes']['class'];
$tag_info['attributes']['class'] = explode(" ", $tag_info['attributes']['class']);
}
$settings['attributes'] = is_array($tag_info['attributes']) ? $tag_info['attributes'] : [];
// Many media formatters will want to apply width and height independently
// of the style attribute or the corresponding HTML attributes, so pull
// these two out into top-level settings. Different WYSIWYG editors have
// different behavior with respect to whether they store user-specified
// dimensions in the HTML attributes or the style attribute so check both.
// Per http://www.w3.org/TR/html5/the-map-element.html#attr-dim-width, the
// HTML attributes are merely hints: CSS takes precedence.
if (isset($settings['attributes']['style'])) {
$css_properties = $this->mediaParseCssDeclarations($settings['attributes']['style']);
foreach (['width', 'height'] as $dimension) {
if (isset($css_properties[$dimension]) && substr($css_properties[$dimension], -2) == 'px') {
$settings[$dimension] = substr($css_properties[$dimension], 0, -2);
}
elseif (isset($settings['attributes'][$dimension])) {
$settings[$dimension] = $settings['attributes'][$dimension];
}
}
}
}
catch (Exception $e) {
$msg = t('Unable to render media from %tag. Error: %error', ['%tag' => $tag, '%error' => $e->getMessage()]);
\Drupal::logger('Migration')->error($msg);
return '';
}
$alt = isset($settings['alt']) ? $settings['alt'] : '';
$uuid = $media->uuid();
$title = $media->get('name')->value;
$class = isset($classes) ? 'class="' . $classes . '"' : '';
// New media entity format.
$output = '
<drupal-entity
alt="' . $alt . '"
data-embed-button="media_browser"
data-entity-embed-display="media_image"
data-entity-embed-display-settings="{"image_style":"","image_link":""}"
data-entity-type="media"
data-entity-uuid="' . $uuid . '"
title="' . $title . '" ' . $class . '>
</drupal-entity>
';
return $output;
} | [
"private",
"function",
"replaceToken",
"(",
"$",
"match",
",",
"$",
"migrate_executable",
",",
"$",
"row",
",",
"$",
"destination_property",
")",
"{",
"$",
"settings",
"=",
"[",
"]",
";",
"$",
"match",
"=",
"str_replace",
"(",
"\"[[\"",
",",
"\"\"",
",",
"$",
"match",
")",
";",
"$",
"match",
"=",
"str_replace",
"(",
"\"]]\"",
",",
"\"\"",
",",
"$",
"match",
")",
";",
"$",
"tag",
"=",
"$",
"match",
"[",
"0",
"]",
";",
"$",
"classes",
"=",
"''",
";",
"try",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"tag",
")",
")",
"{",
"throw",
"new",
"MigrateException",
"(",
"'Unable to find matching tag'",
")",
";",
"}",
"// Make it into a fancy array.",
"$",
"tag_info",
"=",
"Json",
"::",
"decode",
"(",
"$",
"tag",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"tag_info",
"[",
"'fid'",
"]",
")",
")",
"{",
"throw",
"new",
"MigrateException",
"(",
"'No file Id'",
")",
";",
"}",
"// Lookup the correct fid.",
"$",
"fid",
"=",
"$",
"this",
"->",
"migrationPlugin",
"->",
"transform",
"(",
"$",
"tag_info",
"[",
"'fid'",
"]",
",",
"$",
"migrate_executable",
",",
"$",
"row",
",",
"$",
"destination_property",
")",
";",
"// Load the file.",
"$",
"media",
"=",
"Media",
"::",
"load",
"(",
"$",
"fid",
")",
";",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"throw",
"new",
"MigrateException",
"(",
"'Could not load media object'",
")",
";",
"}",
"// The class attributes is a string, but drupal requires it to be an",
"// array, so we fix it here.",
"if",
"(",
"!",
"empty",
"(",
"$",
"tag_info",
"[",
"'attributes'",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"classes",
"=",
"$",
"tag_info",
"[",
"'attributes'",
"]",
"[",
"'class'",
"]",
";",
"$",
"tag_info",
"[",
"'attributes'",
"]",
"[",
"'class'",
"]",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"tag_info",
"[",
"'attributes'",
"]",
"[",
"'class'",
"]",
")",
";",
"}",
"$",
"settings",
"[",
"'attributes'",
"]",
"=",
"is_array",
"(",
"$",
"tag_info",
"[",
"'attributes'",
"]",
")",
"?",
"$",
"tag_info",
"[",
"'attributes'",
"]",
":",
"[",
"]",
";",
"// Many media formatters will want to apply width and height independently",
"// of the style attribute or the corresponding HTML attributes, so pull",
"// these two out into top-level settings. Different WYSIWYG editors have",
"// different behavior with respect to whether they store user-specified",
"// dimensions in the HTML attributes or the style attribute so check both.",
"// Per http://www.w3.org/TR/html5/the-map-element.html#attr-dim-width, the",
"// HTML attributes are merely hints: CSS takes precedence.",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'attributes'",
"]",
"[",
"'style'",
"]",
")",
")",
"{",
"$",
"css_properties",
"=",
"$",
"this",
"->",
"mediaParseCssDeclarations",
"(",
"$",
"settings",
"[",
"'attributes'",
"]",
"[",
"'style'",
"]",
")",
";",
"foreach",
"(",
"[",
"'width'",
",",
"'height'",
"]",
"as",
"$",
"dimension",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"css_properties",
"[",
"$",
"dimension",
"]",
")",
"&&",
"substr",
"(",
"$",
"css_properties",
"[",
"$",
"dimension",
"]",
",",
"-",
"2",
")",
"==",
"'px'",
")",
"{",
"$",
"settings",
"[",
"$",
"dimension",
"]",
"=",
"substr",
"(",
"$",
"css_properties",
"[",
"$",
"dimension",
"]",
",",
"0",
",",
"-",
"2",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'attributes'",
"]",
"[",
"$",
"dimension",
"]",
")",
")",
"{",
"$",
"settings",
"[",
"$",
"dimension",
"]",
"=",
"$",
"settings",
"[",
"'attributes'",
"]",
"[",
"$",
"dimension",
"]",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"t",
"(",
"'Unable to render media from %tag. Error: %error'",
",",
"[",
"'%tag'",
"=>",
"$",
"tag",
",",
"'%error'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
")",
";",
"\\",
"Drupal",
"::",
"logger",
"(",
"'Migration'",
")",
"->",
"error",
"(",
"$",
"msg",
")",
";",
"return",
"''",
";",
"}",
"$",
"alt",
"=",
"isset",
"(",
"$",
"settings",
"[",
"'alt'",
"]",
")",
"?",
"$",
"settings",
"[",
"'alt'",
"]",
":",
"''",
";",
"$",
"uuid",
"=",
"$",
"media",
"->",
"uuid",
"(",
")",
";",
"$",
"title",
"=",
"$",
"media",
"->",
"get",
"(",
"'name'",
")",
"->",
"value",
";",
"$",
"class",
"=",
"isset",
"(",
"$",
"classes",
")",
"?",
"'class=\"'",
".",
"$",
"classes",
".",
"'\"'",
":",
"''",
";",
"// New media entity format.",
"$",
"output",
"=",
"'\n <drupal-entity\n alt=\"'",
".",
"$",
"alt",
".",
"'\"\n data-embed-button=\"media_browser\"\n data-entity-embed-display=\"media_image\"\n data-entity-embed-display-settings=\"{"image_style":"","image_link":""}\"\n data-entity-type=\"media\"\n data-entity-uuid=\"'",
".",
"$",
"uuid",
".",
"'\"\n title=\"'",
".",
"$",
"title",
".",
"'\" '",
".",
"$",
"class",
".",
"'>\n </drupal-entity>\n '",
";",
"return",
"$",
"output",
";",
"}"
] | Replace callback to convert a media file tag into HTML markup.
Partially copied from 7.x media module media.filter.inc (media_filter).
@param string $match
Takes a match of tag code
@param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
The migrate executable helper class.
@param \Drupal\migrate\Row $row
The current row after processing.
@param string $destination_property
The destination propery. | [
"Replace",
"callback",
"to",
"convert",
"a",
"media",
"file",
"tag",
"into",
"HTML",
"markup",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/MediaTags.php#L105-L186 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/MediaTags.php | MediaTags.mediaParseCssDeclarations | private function mediaParseCssDeclarations($declarations) {
$properties = [];
foreach (array_map('trim', explode(";", $declarations)) as $declaration) {
if ($declaration != '') {
list($name, $value) = array_map('trim', explode(':', $declaration, 2));
$properties[strtolower($name)] = $value;
}
}
return $properties;
} | php | private function mediaParseCssDeclarations($declarations) {
$properties = [];
foreach (array_map('trim', explode(";", $declarations)) as $declaration) {
if ($declaration != '') {
list($name, $value) = array_map('trim', explode(':', $declaration, 2));
$properties[strtolower($name)] = $value;
}
}
return $properties;
} | [
"private",
"function",
"mediaParseCssDeclarations",
"(",
"$",
"declarations",
")",
"{",
"$",
"properties",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"\";\"",
",",
"$",
"declarations",
")",
")",
"as",
"$",
"declaration",
")",
"{",
"if",
"(",
"$",
"declaration",
"!=",
"''",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"':'",
",",
"$",
"declaration",
",",
"2",
")",
")",
";",
"$",
"properties",
"[",
"strtolower",
"(",
"$",
"name",
")",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"properties",
";",
"}"
] | Copied from 7.x media @ media.filter.inc (media_parse_css_declarations).
Parses the contents of a CSS declaration block and returns a keyed array
of property names and values.
@param $declarations
One or more CSS declarations delimited by a semicolon. The same as a CSS
declaration block (http://www.w3.org/TR/CSS21/syndata.html#rule-sets),
but without the opening and closing curly braces. Also the same as the
value of an inline HTML style attribute.
@return
A keyed array. The keys are CSS property names, and the values are CSS
property values. | [
"Copied",
"from",
"7",
".",
"x",
"media",
"@",
"media",
".",
"filter",
".",
"inc",
"(",
"media_parse_css_declarations",
")",
"."
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/MediaTags.php#L204-L213 |
drupalwxt/wxt | modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/PrivPath.php | PrivPath.transform | public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!$value) {
throw new MigrateSkipProcessException();
}
return $this->getPrivPath($value);
} | php | public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!$value) {
throw new MigrateSkipProcessException();
}
return $this->getPrivPath($value);
} | [
"public",
"function",
"transform",
"(",
"$",
"value",
",",
"MigrateExecutableInterface",
"$",
"migrate_executable",
",",
"Row",
"$",
"row",
",",
"$",
"destination_property",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"throw",
"new",
"MigrateSkipProcessException",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getPrivPath",
"(",
"$",
"value",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drupalwxt/wxt/blob/f0a3730065d9dba1ffb68237e329bf575da410d4/modules/custom/wxt_ext/wxt_ext_migration/src/Plugin/migrate/process/PrivPath.php#L23-L28 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.validateContentTypeHeader | public function validateContentTypeHeader(): void
{
if ($this->isValidMediaTypeHeader("content-type") === false) {
throw $this->exceptionFactory->createMediaTypeUnsupportedException(
$this,
$this->getHeaderLine("content-type")
);
}
} | php | public function validateContentTypeHeader(): void
{
if ($this->isValidMediaTypeHeader("content-type") === false) {
throw $this->exceptionFactory->createMediaTypeUnsupportedException(
$this,
$this->getHeaderLine("content-type")
);
}
} | [
"public",
"function",
"validateContentTypeHeader",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"isValidMediaTypeHeader",
"(",
"\"content-type\"",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"this",
"->",
"exceptionFactory",
"->",
"createMediaTypeUnsupportedException",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getHeaderLine",
"(",
"\"content-type\"",
")",
")",
";",
"}",
"}"
] | Validates if the current request's Content-Type header conforms to the JSON:API schema.
@throws MediaTypeUnsupported|JsonApiExceptionInterface | [
"Validates",
"if",
"the",
"current",
"request",
"s",
"Content",
"-",
"Type",
"header",
"conforms",
"to",
"the",
"JSON",
":",
"API",
"schema",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L83-L91 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.validateAcceptHeader | public function validateAcceptHeader(): void
{
if ($this->isValidMediaTypeHeader("accept") === false) {
throw $this->exceptionFactory->createMediaTypeUnacceptableException($this, $this->getHeaderLine("accept"));
}
} | php | public function validateAcceptHeader(): void
{
if ($this->isValidMediaTypeHeader("accept") === false) {
throw $this->exceptionFactory->createMediaTypeUnacceptableException($this, $this->getHeaderLine("accept"));
}
} | [
"public",
"function",
"validateAcceptHeader",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"isValidMediaTypeHeader",
"(",
"\"accept\"",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"this",
"->",
"exceptionFactory",
"->",
"createMediaTypeUnacceptableException",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getHeaderLine",
"(",
"\"accept\"",
")",
")",
";",
"}",
"}"
] | Validates if the current request's Accept header conforms to the JSON:API schema.
@throws MediaTypeUnacceptable|JsonApiExceptionInterface | [
"Validates",
"if",
"the",
"current",
"request",
"s",
"Accept",
"header",
"conforms",
"to",
"the",
"JSON",
":",
"API",
"schema",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L98-L103 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.validateQueryParams | public function validateQueryParams(): void
{
foreach ($this->getQueryParams() as $queryParamName => $queryParamValue) {
if (preg_match("/^([a-z]+)$/", $queryParamName) === 1 &&
in_array($queryParamName, ["fields", "include", "sort", "page", "filter", "profile"], true) === false
) {
throw $this->exceptionFactory->createQueryParamUnrecognizedException($this, $queryParamName);
}
}
} | php | public function validateQueryParams(): void
{
foreach ($this->getQueryParams() as $queryParamName => $queryParamValue) {
if (preg_match("/^([a-z]+)$/", $queryParamName) === 1 &&
in_array($queryParamName, ["fields", "include", "sort", "page", "filter", "profile"], true) === false
) {
throw $this->exceptionFactory->createQueryParamUnrecognizedException($this, $queryParamName);
}
}
} | [
"public",
"function",
"validateQueryParams",
"(",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getQueryParams",
"(",
")",
"as",
"$",
"queryParamName",
"=>",
"$",
"queryParamValue",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/^([a-z]+)$/\"",
",",
"$",
"queryParamName",
")",
"===",
"1",
"&&",
"in_array",
"(",
"$",
"queryParamName",
",",
"[",
"\"fields\"",
",",
"\"include\"",
",",
"\"sort\"",
",",
"\"page\"",
",",
"\"filter\"",
",",
"\"profile\"",
"]",
",",
"true",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"this",
"->",
"exceptionFactory",
"->",
"createQueryParamUnrecognizedException",
"(",
"$",
"this",
",",
"$",
"queryParamName",
")",
";",
"}",
"}",
"}"
] | Validates if the current request's query parameters conform to the JSON:API schema.
According to the JSON:API specification "Implementation specific query parameters MUST
adhere to the same constraints as member names with the additional requirement that they
MUST contain at least one non a-z character (U+0061 to U+007A)".
@throws QueryParamUnrecognized|JsonApiExceptionInterface | [
"Validates",
"if",
"the",
"current",
"request",
"s",
"query",
"parameters",
"conform",
"to",
"the",
"JSON",
":",
"API",
"schema",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L114-L123 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.getIncludedFields | public function getIncludedFields(string $resourceType): array
{
if ($this->includedFields === null) {
$this->includedFields = $this->setIncludedFields();
}
return isset($this->includedFields[$resourceType]) ? array_keys($this->includedFields[$resourceType]) : [];
} | php | public function getIncludedFields(string $resourceType): array
{
if ($this->includedFields === null) {
$this->includedFields = $this->setIncludedFields();
}
return isset($this->includedFields[$resourceType]) ? array_keys($this->includedFields[$resourceType]) : [];
} | [
"public",
"function",
"getIncludedFields",
"(",
"string",
"$",
"resourceType",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"includedFields",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"includedFields",
"=",
"$",
"this",
"->",
"setIncludedFields",
"(",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"includedFields",
"[",
"$",
"resourceType",
"]",
")",
"?",
"array_keys",
"(",
"$",
"this",
"->",
"includedFields",
"[",
"$",
"resourceType",
"]",
")",
":",
"[",
"]",
";",
"}"
] | Returns a list of field names for the given resource type which should be present in the response. | [
"Returns",
"a",
"list",
"of",
"field",
"names",
"for",
"the",
"given",
"resource",
"type",
"which",
"should",
"be",
"present",
"in",
"the",
"response",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L269-L276 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.isIncludedField | public function isIncludedField(string $resourceType, string $field): bool
{
if ($this->includedFields === null) {
$this->includedFields = $this->setIncludedFields();
}
if (array_key_exists($resourceType, $this->includedFields) === false) {
return true;
}
if (isset($this->includedFields[$resourceType][""])) {
return false;
}
return isset($this->includedFields[$resourceType][$field]);
} | php | public function isIncludedField(string $resourceType, string $field): bool
{
if ($this->includedFields === null) {
$this->includedFields = $this->setIncludedFields();
}
if (array_key_exists($resourceType, $this->includedFields) === false) {
return true;
}
if (isset($this->includedFields[$resourceType][""])) {
return false;
}
return isset($this->includedFields[$resourceType][$field]);
} | [
"public",
"function",
"isIncludedField",
"(",
"string",
"$",
"resourceType",
",",
"string",
"$",
"field",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"includedFields",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"includedFields",
"=",
"$",
"this",
"->",
"setIncludedFields",
"(",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"resourceType",
",",
"$",
"this",
"->",
"includedFields",
")",
"===",
"false",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"includedFields",
"[",
"$",
"resourceType",
"]",
"[",
"\"\"",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"includedFields",
"[",
"$",
"resourceType",
"]",
"[",
"$",
"field",
"]",
")",
";",
"}"
] | Determines if a given field for a given resource type should be present in the response or not. | [
"Determines",
"if",
"a",
"given",
"field",
"for",
"a",
"given",
"resource",
"type",
"should",
"be",
"present",
"in",
"the",
"response",
"or",
"not",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L281-L296 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.hasIncludedRelationships | public function hasIncludedRelationships(): bool
{
if ($this->includedRelationships === null) {
$this->setIncludedRelationships();
}
return empty($this->includedRelationships) === false;
} | php | public function hasIncludedRelationships(): bool
{
if ($this->includedRelationships === null) {
$this->setIncludedRelationships();
}
return empty($this->includedRelationships) === false;
} | [
"public",
"function",
"hasIncludedRelationships",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"includedRelationships",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setIncludedRelationships",
"(",
")",
";",
"}",
"return",
"empty",
"(",
"$",
"this",
"->",
"includedRelationships",
")",
"===",
"false",
";",
"}"
] | Determines if any relationship needs to be included. | [
"Determines",
"if",
"any",
"relationship",
"needs",
"to",
"be",
"included",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L337-L344 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.getIncludedRelationships | public function getIncludedRelationships(string $baseRelationshipPath): array
{
if ($this->includedRelationships === null) {
$this->setIncludedRelationships();
}
if (isset($this->includedRelationships[$baseRelationshipPath])) {
return array_values($this->includedRelationships[$baseRelationshipPath]);
}
return [];
} | php | public function getIncludedRelationships(string $baseRelationshipPath): array
{
if ($this->includedRelationships === null) {
$this->setIncludedRelationships();
}
if (isset($this->includedRelationships[$baseRelationshipPath])) {
return array_values($this->includedRelationships[$baseRelationshipPath]);
}
return [];
} | [
"public",
"function",
"getIncludedRelationships",
"(",
"string",
"$",
"baseRelationshipPath",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"includedRelationships",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setIncludedRelationships",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"includedRelationships",
"[",
"$",
"baseRelationshipPath",
"]",
")",
")",
"{",
"return",
"array_values",
"(",
"$",
"this",
"->",
"includedRelationships",
"[",
"$",
"baseRelationshipPath",
"]",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Returns a list of relationship paths for a given parent path which should be included in the response. | [
"Returns",
"a",
"list",
"of",
"relationship",
"paths",
"for",
"a",
"given",
"parent",
"path",
"which",
"should",
"be",
"included",
"in",
"the",
"response",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L349-L360 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.isIncludedRelationship | public function isIncludedRelationship(
string $baseRelationshipPath,
string $relationshipName,
array $defaultRelationships
): bool {
if ($this->includedRelationships === null) {
$this->setIncludedRelationships();
}
if ($this->getQueryParam("include") === "") {
return false;
}
if (empty($this->includedRelationships) && array_key_exists($relationshipName, $defaultRelationships)) {
return true;
}
return isset($this->includedRelationships[$baseRelationshipPath][$relationshipName]);
} | php | public function isIncludedRelationship(
string $baseRelationshipPath,
string $relationshipName,
array $defaultRelationships
): bool {
if ($this->includedRelationships === null) {
$this->setIncludedRelationships();
}
if ($this->getQueryParam("include") === "") {
return false;
}
if (empty($this->includedRelationships) && array_key_exists($relationshipName, $defaultRelationships)) {
return true;
}
return isset($this->includedRelationships[$baseRelationshipPath][$relationshipName]);
} | [
"public",
"function",
"isIncludedRelationship",
"(",
"string",
"$",
"baseRelationshipPath",
",",
"string",
"$",
"relationshipName",
",",
"array",
"$",
"defaultRelationships",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"includedRelationships",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setIncludedRelationships",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getQueryParam",
"(",
"\"include\"",
")",
"===",
"\"\"",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"includedRelationships",
")",
"&&",
"array_key_exists",
"(",
"$",
"relationshipName",
",",
"$",
"defaultRelationships",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"includedRelationships",
"[",
"$",
"baseRelationshipPath",
"]",
"[",
"$",
"relationshipName",
"]",
")",
";",
"}"
] | Determines if a given relationship name that is a child of the $baseRelationshipPath should be included
in the response. | [
"Determines",
"if",
"a",
"given",
"relationship",
"name",
"that",
"is",
"a",
"child",
"of",
"the",
"$baseRelationshipPath",
"should",
"be",
"included",
"in",
"the",
"response",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L366-L384 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.getSorting | public function getSorting(): array
{
if ($this->sorting === null) {
$this->sorting = $this->setSorting();
}
return $this->sorting;
} | php | public function getSorting(): array
{
if ($this->sorting === null) {
$this->sorting = $this->setSorting();
}
return $this->sorting;
} | [
"public",
"function",
"getSorting",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"sorting",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"sorting",
"=",
"$",
"this",
"->",
"setSorting",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sorting",
";",
"}"
] | Returns the "sort[]" query parameters. | [
"Returns",
"the",
"sort",
"[]",
"query",
"parameters",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L389-L396 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.getPagination | public function getPagination(): array
{
if ($this->pagination === null) {
$this->pagination = $this->setPagination();
}
return $this->pagination;
} | php | public function getPagination(): array
{
if ($this->pagination === null) {
$this->pagination = $this->setPagination();
}
return $this->pagination;
} | [
"public",
"function",
"getPagination",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"pagination",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"pagination",
"=",
"$",
"this",
"->",
"setPagination",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pagination",
";",
"}"
] | Returns the "page[]" query parameters. | [
"Returns",
"the",
"page",
"[]",
"query",
"parameters",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L415-L422 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.getFiltering | public function getFiltering(): array
{
if ($this->filtering === null) {
$this->filtering = $this->setFiltering();
}
return $this->filtering;
} | php | public function getFiltering(): array
{
if ($this->filtering === null) {
$this->filtering = $this->setFiltering();
}
return $this->filtering;
} | [
"public",
"function",
"getFiltering",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"filtering",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"filtering",
"=",
"$",
"this",
"->",
"setFiltering",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filtering",
";",
"}"
] | Returns the "filter[]" query parameters. | [
"Returns",
"the",
"filter",
"[]",
"query",
"parameters",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L438-L445 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.getToOneRelationship | public function getToOneRelationship(string $relationship): ToOneRelationship
{
$data = $this->getResource();
// The relationship has to exist in the request and have a data attribute to be valid
if (isset($data["relationships"][$relationship]) && array_key_exists("data", $data["relationships"][$relationship])) {
// If the data is null, this request is to clear the relationship, we return an empty relationship
if ($data["relationships"][$relationship]["data"] === null) {
return new ToOneRelationship();
}
// If the data is set and is not null, we create the relationship with a resource identifier from the request
return new ToOneRelationship(
ResourceIdentifier::fromArray($data["relationships"][$relationship]["data"], $this->exceptionFactory)
);
}
throw $this->exceptionFactory->createRelationshipNotExistsException($relationship);
} | php | public function getToOneRelationship(string $relationship): ToOneRelationship
{
$data = $this->getResource();
// The relationship has to exist in the request and have a data attribute to be valid
if (isset($data["relationships"][$relationship]) && array_key_exists("data", $data["relationships"][$relationship])) {
// If the data is null, this request is to clear the relationship, we return an empty relationship
if ($data["relationships"][$relationship]["data"] === null) {
return new ToOneRelationship();
}
// If the data is set and is not null, we create the relationship with a resource identifier from the request
return new ToOneRelationship(
ResourceIdentifier::fromArray($data["relationships"][$relationship]["data"], $this->exceptionFactory)
);
}
throw $this->exceptionFactory->createRelationshipNotExistsException($relationship);
} | [
"public",
"function",
"getToOneRelationship",
"(",
"string",
"$",
"relationship",
")",
":",
"ToOneRelationship",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getResource",
"(",
")",
";",
"// The relationship has to exist in the request and have a data attribute to be valid",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"\"relationships\"",
"]",
"[",
"$",
"relationship",
"]",
")",
"&&",
"array_key_exists",
"(",
"\"data\"",
",",
"$",
"data",
"[",
"\"relationships\"",
"]",
"[",
"$",
"relationship",
"]",
")",
")",
"{",
"// If the data is null, this request is to clear the relationship, we return an empty relationship",
"if",
"(",
"$",
"data",
"[",
"\"relationships\"",
"]",
"[",
"$",
"relationship",
"]",
"[",
"\"data\"",
"]",
"===",
"null",
")",
"{",
"return",
"new",
"ToOneRelationship",
"(",
")",
";",
"}",
"// If the data is set and is not null, we create the relationship with a resource identifier from the request",
"return",
"new",
"ToOneRelationship",
"(",
"ResourceIdentifier",
"::",
"fromArray",
"(",
"$",
"data",
"[",
"\"relationships\"",
"]",
"[",
"$",
"relationship",
"]",
"[",
"\"data\"",
"]",
",",
"$",
"this",
"->",
"exceptionFactory",
")",
")",
";",
"}",
"throw",
"$",
"this",
"->",
"exceptionFactory",
"->",
"createRelationshipNotExistsException",
"(",
"$",
"relationship",
")",
";",
"}"
] | Returns the $relationship to-one relationship of the primary resource if it is present, or null otherwise. | [
"Returns",
"the",
"$relationship",
"to",
"-",
"one",
"relationship",
"of",
"the",
"primary",
"resource",
"if",
"it",
"is",
"present",
"or",
"null",
"otherwise",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L541-L558 |
woohoolabs/yin | src/JsonApi/Request/JsonApiRequest.php | JsonApiRequest.getToManyRelationship | public function getToManyRelationship(string $relationship): ToManyRelationship
{
$data = $this->getResource();
if (isset($data["relationships"][$relationship]["data"]) === false) {
throw $this->exceptionFactory->createRelationshipNotExistsException($relationship);
}
$resourceIdentifiers = [];
foreach ($data["relationships"][$relationship]["data"] as $item) {
$resourceIdentifiers[] = ResourceIdentifier::fromArray($item, $this->exceptionFactory);
}
return new ToManyRelationship($resourceIdentifiers);
} | php | public function getToManyRelationship(string $relationship): ToManyRelationship
{
$data = $this->getResource();
if (isset($data["relationships"][$relationship]["data"]) === false) {
throw $this->exceptionFactory->createRelationshipNotExistsException($relationship);
}
$resourceIdentifiers = [];
foreach ($data["relationships"][$relationship]["data"] as $item) {
$resourceIdentifiers[] = ResourceIdentifier::fromArray($item, $this->exceptionFactory);
}
return new ToManyRelationship($resourceIdentifiers);
} | [
"public",
"function",
"getToManyRelationship",
"(",
"string",
"$",
"relationship",
")",
":",
"ToManyRelationship",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getResource",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"\"relationships\"",
"]",
"[",
"$",
"relationship",
"]",
"[",
"\"data\"",
"]",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"this",
"->",
"exceptionFactory",
"->",
"createRelationshipNotExistsException",
"(",
"$",
"relationship",
")",
";",
"}",
"$",
"resourceIdentifiers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"\"relationships\"",
"]",
"[",
"$",
"relationship",
"]",
"[",
"\"data\"",
"]",
"as",
"$",
"item",
")",
"{",
"$",
"resourceIdentifiers",
"[",
"]",
"=",
"ResourceIdentifier",
"::",
"fromArray",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"exceptionFactory",
")",
";",
"}",
"return",
"new",
"ToManyRelationship",
"(",
"$",
"resourceIdentifiers",
")",
";",
"}"
] | Returns the $relationship to-many relationship of the primary resource if it is present, or null otherwise. | [
"Returns",
"the",
"$relationship",
"to",
"-",
"many",
"relationship",
"of",
"the",
"primary",
"resource",
"if",
"it",
"is",
"present",
"or",
"null",
"otherwise",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/JsonApiRequest.php#L570-L584 |
woohoolabs/yin | examples/Book/JsonApi/Hydrator/BookHydator.php | BookHydator.validateClientGeneratedId | protected function validateClientGeneratedId(
string $clientGeneratedId,
JsonApiRequestInterface $request,
ExceptionFactoryInterface $exceptionFactory
) {
if ($clientGeneratedId !== null) {
throw $exceptionFactory->createClientGeneratedIdNotSupportedException($request, $clientGeneratedId);
}
} | php | protected function validateClientGeneratedId(
string $clientGeneratedId,
JsonApiRequestInterface $request,
ExceptionFactoryInterface $exceptionFactory
) {
if ($clientGeneratedId !== null) {
throw $exceptionFactory->createClientGeneratedIdNotSupportedException($request, $clientGeneratedId);
}
} | [
"protected",
"function",
"validateClientGeneratedId",
"(",
"string",
"$",
"clientGeneratedId",
",",
"JsonApiRequestInterface",
"$",
"request",
",",
"ExceptionFactoryInterface",
"$",
"exceptionFactory",
")",
"{",
"if",
"(",
"$",
"clientGeneratedId",
"!==",
"null",
")",
"{",
"throw",
"$",
"exceptionFactory",
"->",
"createClientGeneratedIdNotSupportedException",
"(",
"$",
"request",
",",
"$",
"clientGeneratedId",
")",
";",
"}",
"}"
] | Validates a client-generated ID.
If the $clientGeneratedId is not a valid ID for the domain object, then
the appropriate exception should be thrown: if it is not well-formed then
a ClientGeneratedIdNotSupported exception can be raised, if the ID already
exists then a ClientGeneratedIdAlreadyExists exception can be thrown.
@throws ClientGeneratedIdNotSupported|JsonApiExceptionInterface
@throws ClientGeneratedIdAlreadyExists|JsonApiExceptionInterface | [
"Validates",
"a",
"client",
"-",
"generated",
"ID",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/examples/Book/JsonApi/Hydrator/BookHydator.php#L45-L53 |
woohoolabs/yin | examples/Book/JsonApi/Hydrator/BookHydator.php | BookHydator.getAttributeHydrator | protected function getAttributeHydrator($book): array
{
return [
"title" => function (array $book, $attribute, $data) {
$book["title"] = $attribute;
return $book;
},
"pages" => function (array &$book, $attribute, $data) {
$book["pages"] = $attribute;
}
];
} | php | protected function getAttributeHydrator($book): array
{
return [
"title" => function (array $book, $attribute, $data) {
$book["title"] = $attribute;
return $book;
},
"pages" => function (array &$book, $attribute, $data) {
$book["pages"] = $attribute;
}
];
} | [
"protected",
"function",
"getAttributeHydrator",
"(",
"$",
"book",
")",
":",
"array",
"{",
"return",
"[",
"\"title\"",
"=>",
"function",
"(",
"array",
"$",
"book",
",",
"$",
"attribute",
",",
"$",
"data",
")",
"{",
"$",
"book",
"[",
"\"title\"",
"]",
"=",
"$",
"attribute",
";",
"return",
"$",
"book",
";",
"}",
",",
"\"pages\"",
"=>",
"function",
"(",
"array",
"&",
"$",
"book",
",",
"$",
"attribute",
",",
"$",
"data",
")",
"{",
"$",
"book",
"[",
"\"pages\"",
"]",
"=",
"$",
"attribute",
";",
"}",
"]",
";",
"}"
] | Provides the attribute hydrators.
The method returns an array of attribute hydrators, where a hydrator is a key-value pair:
the key is the specific attribute name which comes from the request and the value is a
callable which hydrates the given attribute.
These callables receive the domain object (which will be hydrated), the value of the
currently processed attribute, the "data" part of the request and the name of the attribute
to be hydrated as their arguments, and they should mutate the state of the domain object.
If it is an immutable object or an array (and passing by reference isn't used),
the callable should return the domain object.
@param array $book
@return callable[] | [
"Provides",
"the",
"attribute",
"hydrators",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/examples/Book/JsonApi/Hydrator/BookHydator.php#L110-L121 |
woohoolabs/yin | examples/Book/JsonApi/Hydrator/BookHydator.php | BookHydator.getRelationshipHydrator | protected function getRelationshipHydrator($book): array
{
return [
"authors" => function (array $book, ToManyRelationship $authors, $data, $relationshipName) {
if ($authors->isEmpty()) {
$book["authors"] = [];
} else {
$book["authors"] = BookRepository::getAuthors($authors->getResourceIdentifierIds());
}
return $book;
},
"publisher" => function (array &$book, ToOneRelationship $publisher, $data, $relationshipName) {
if ($publisher->isEmpty()) {
$book["publisher"] = null;
} else {
$book["publisher"] = BookRepository::getPublisher((int) $publisher->getResourceIdentifier()->getId());
}
}
];
} | php | protected function getRelationshipHydrator($book): array
{
return [
"authors" => function (array $book, ToManyRelationship $authors, $data, $relationshipName) {
if ($authors->isEmpty()) {
$book["authors"] = [];
} else {
$book["authors"] = BookRepository::getAuthors($authors->getResourceIdentifierIds());
}
return $book;
},
"publisher" => function (array &$book, ToOneRelationship $publisher, $data, $relationshipName) {
if ($publisher->isEmpty()) {
$book["publisher"] = null;
} else {
$book["publisher"] = BookRepository::getPublisher((int) $publisher->getResourceIdentifier()->getId());
}
}
];
} | [
"protected",
"function",
"getRelationshipHydrator",
"(",
"$",
"book",
")",
":",
"array",
"{",
"return",
"[",
"\"authors\"",
"=>",
"function",
"(",
"array",
"$",
"book",
",",
"ToManyRelationship",
"$",
"authors",
",",
"$",
"data",
",",
"$",
"relationshipName",
")",
"{",
"if",
"(",
"$",
"authors",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"book",
"[",
"\"authors\"",
"]",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"book",
"[",
"\"authors\"",
"]",
"=",
"BookRepository",
"::",
"getAuthors",
"(",
"$",
"authors",
"->",
"getResourceIdentifierIds",
"(",
")",
")",
";",
"}",
"return",
"$",
"book",
";",
"}",
",",
"\"publisher\"",
"=>",
"function",
"(",
"array",
"&",
"$",
"book",
",",
"ToOneRelationship",
"$",
"publisher",
",",
"$",
"data",
",",
"$",
"relationshipName",
")",
"{",
"if",
"(",
"$",
"publisher",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"book",
"[",
"\"publisher\"",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"book",
"[",
"\"publisher\"",
"]",
"=",
"BookRepository",
"::",
"getPublisher",
"(",
"(",
"int",
")",
"$",
"publisher",
"->",
"getResourceIdentifier",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"}",
"}",
"]",
";",
"}"
] | Provides the relationship hydrators.
The method returns an array of relationship hydrators, where a hydrator is a key-value pair:
the key is the specific relationship name which comes from the request and the value is a
callable which hydrate the previous relationship.
These callables receive the domain object (which will be hydrated), an object representing the
currently processed relationship (it can be a ToOneRelationship or a ToManyRelationship
object), the "data" part of the request and the relationship name as their arguments, and
they should mutate the state of the domain object.
If it is an immutable object or an array (and passing by reference isn't used),
the callable should return the domain object.
@param array $book
@return callable[] | [
"Provides",
"the",
"relationship",
"hydrators",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/examples/Book/JsonApi/Hydrator/BookHydator.php#L139-L159 |
woohoolabs/yin | examples/User/JsonApi/Document/UsersDocument.php | UsersDocument.getLinks | public function getLinks(): ?DocumentLinks
{
return DocumentLinks::createWithoutBaseUri()
->setPagination("/users", $this->object, $this->request->getUri()->getQuery());
} | php | public function getLinks(): ?DocumentLinks
{
return DocumentLinks::createWithoutBaseUri()
->setPagination("/users", $this->object, $this->request->getUri()->getQuery());
} | [
"public",
"function",
"getLinks",
"(",
")",
":",
"?",
"DocumentLinks",
"{",
"return",
"DocumentLinks",
"::",
"createWithoutBaseUri",
"(",
")",
"->",
"setPagination",
"(",
"\"/users\"",
",",
"$",
"this",
"->",
"object",
",",
"$",
"this",
"->",
"request",
"->",
"getUri",
"(",
")",
"->",
"getQuery",
"(",
")",
")",
";",
"}"
] | Provides information about the "links" member of the current document.
The method returns a new DocumentLinks object if you want to provide linkage data
for the document or null if the section should be omitted from the response. | [
"Provides",
"information",
"about",
"the",
"links",
"member",
"of",
"the",
"current",
"document",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/examples/User/JsonApi/Document/UsersDocument.php#L46-L50 |
woohoolabs/yin | src/JsonApi/JsonApi.php | JsonApi.disableIncludes | public function disableIncludes(): void
{
if ($this->request->getQueryParam("include") !== null) {
throw $this->exceptionFactory->createInclusionUnsupportedException($this->request);
}
} | php | public function disableIncludes(): void
{
if ($this->request->getQueryParam("include") !== null) {
throw $this->exceptionFactory->createInclusionUnsupportedException($this->request);
}
} | [
"public",
"function",
"disableIncludes",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"getQueryParam",
"(",
"\"include\"",
")",
"!==",
"null",
")",
"{",
"throw",
"$",
"this",
"->",
"exceptionFactory",
"->",
"createInclusionUnsupportedException",
"(",
"$",
"this",
"->",
"request",
")",
";",
"}",
"}"
] | Disables inclusion of related resources.
If the current request asks for inclusion of related resources, it throws an InclusionNotSupported exception.
@throws InclusionUnsupported|JsonApiExceptionInterface | [
"Disables",
"inclusion",
"of",
"related",
"resources",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/JsonApi.php#L122-L127 |
woohoolabs/yin | src/JsonApi/JsonApi.php | JsonApi.disableSorting | public function disableSorting(): void
{
if ($this->request->getQueryParam("sort") !== null) {
throw $this->exceptionFactory->createSortingUnsupportedException($this->request);
}
} | php | public function disableSorting(): void
{
if ($this->request->getQueryParam("sort") !== null) {
throw $this->exceptionFactory->createSortingUnsupportedException($this->request);
}
} | [
"public",
"function",
"disableSorting",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"getQueryParam",
"(",
"\"sort\"",
")",
"!==",
"null",
")",
"{",
"throw",
"$",
"this",
"->",
"exceptionFactory",
"->",
"createSortingUnsupportedException",
"(",
"$",
"this",
"->",
"request",
")",
";",
"}",
"}"
] | Disables sorting.
If the current request contains sorting criteria, it throws a SortingNotSupported exception.
@throws SortingUnsupported|JsonApiExceptionInterface | [
"Disables",
"sorting",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/JsonApi.php#L136-L141 |
woohoolabs/yin | src/JsonApi/Request/Pagination/PaginationFactory.php | PaginationFactory.createFixedPageBasedPagination | public function createFixedPageBasedPagination(int $defaultPage = 0): FixedPageBasedPagination
{
return FixedPageBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultPage);
} | php | public function createFixedPageBasedPagination(int $defaultPage = 0): FixedPageBasedPagination
{
return FixedPageBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultPage);
} | [
"public",
"function",
"createFixedPageBasedPagination",
"(",
"int",
"$",
"defaultPage",
"=",
"0",
")",
":",
"FixedPageBasedPagination",
"{",
"return",
"FixedPageBasedPagination",
"::",
"fromPaginationQueryParams",
"(",
"$",
"this",
"->",
"request",
"->",
"getPagination",
"(",
")",
",",
"$",
"defaultPage",
")",
";",
"}"
] | Returns a FixedPageBasedPagination class in order to be used for fixed page-based pagination.
The FixedPageBasedPagination class stores the value of the "page[number]" query parameter if present
or the $defaultPage otherwise. | [
"Returns",
"a",
"FixedPageBasedPagination",
"class",
"in",
"order",
"to",
"be",
"used",
"for",
"fixed",
"page",
"-",
"based",
"pagination",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/Pagination/PaginationFactory.php#L26-L29 |
woohoolabs/yin | src/JsonApi/Request/Pagination/PaginationFactory.php | PaginationFactory.createPageBasedPagination | public function createPageBasedPagination(int $defaultPage = 0, int $defaultSize = 0): PageBasedPagination
{
return PageBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultPage, $defaultSize);
} | php | public function createPageBasedPagination(int $defaultPage = 0, int $defaultSize = 0): PageBasedPagination
{
return PageBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultPage, $defaultSize);
} | [
"public",
"function",
"createPageBasedPagination",
"(",
"int",
"$",
"defaultPage",
"=",
"0",
",",
"int",
"$",
"defaultSize",
"=",
"0",
")",
":",
"PageBasedPagination",
"{",
"return",
"PageBasedPagination",
"::",
"fromPaginationQueryParams",
"(",
"$",
"this",
"->",
"request",
"->",
"getPagination",
"(",
")",
",",
"$",
"defaultPage",
",",
"$",
"defaultSize",
")",
";",
"}"
] | Returns a PageBasedPagination class in order to be used for page-based pagination.
The PageBasedPagination class stores the value of the "page[number]" and "page[size]" query parameters
if present or the $defaultPage and $defaultSize otherwise. | [
"Returns",
"a",
"PageBasedPagination",
"class",
"in",
"order",
"to",
"be",
"used",
"for",
"page",
"-",
"based",
"pagination",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/Pagination/PaginationFactory.php#L37-L40 |
woohoolabs/yin | src/JsonApi/Request/Pagination/PaginationFactory.php | PaginationFactory.createOffsetBasedPagination | public function createOffsetBasedPagination(int $defaultOffset = 0, int $defaultLimit = 0): OffsetBasedPagination
{
return OffsetBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultOffset, $defaultLimit);
} | php | public function createOffsetBasedPagination(int $defaultOffset = 0, int $defaultLimit = 0): OffsetBasedPagination
{
return OffsetBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultOffset, $defaultLimit);
} | [
"public",
"function",
"createOffsetBasedPagination",
"(",
"int",
"$",
"defaultOffset",
"=",
"0",
",",
"int",
"$",
"defaultLimit",
"=",
"0",
")",
":",
"OffsetBasedPagination",
"{",
"return",
"OffsetBasedPagination",
"::",
"fromPaginationQueryParams",
"(",
"$",
"this",
"->",
"request",
"->",
"getPagination",
"(",
")",
",",
"$",
"defaultOffset",
",",
"$",
"defaultLimit",
")",
";",
"}"
] | Returns a OffsetBasedPagination class in order to be used for offset-based pagination.
The OffsetBasedPagination class stores the value of the "page[offset]" and "page[limit]" query parameters
if present or the $defaultOffset and $defaultLimit otherwise. | [
"Returns",
"a",
"OffsetBasedPagination",
"class",
"in",
"order",
"to",
"be",
"used",
"for",
"offset",
"-",
"based",
"pagination",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/Pagination/PaginationFactory.php#L48-L51 |
woohoolabs/yin | src/JsonApi/Request/Pagination/PaginationFactory.php | PaginationFactory.createFixedCursorBasedPagination | public function createFixedCursorBasedPagination($defaultCursor = null): FixedCursorBasedPagination
{
return FixedCursorBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultCursor);
} | php | public function createFixedCursorBasedPagination($defaultCursor = null): FixedCursorBasedPagination
{
return FixedCursorBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultCursor);
} | [
"public",
"function",
"createFixedCursorBasedPagination",
"(",
"$",
"defaultCursor",
"=",
"null",
")",
":",
"FixedCursorBasedPagination",
"{",
"return",
"FixedCursorBasedPagination",
"::",
"fromPaginationQueryParams",
"(",
"$",
"this",
"->",
"request",
"->",
"getPagination",
"(",
")",
",",
"$",
"defaultCursor",
")",
";",
"}"
] | Returns a FixedCursorBasedPagination class in order to be used for cursor-based pagination.
The FixedCursorBasedPagination class stores the value of the "page[cursor]" query parameter if present
or the $defaultCursor otherwise.
@param mixed $defaultCursor | [
"Returns",
"a",
"FixedCursorBasedPagination",
"class",
"in",
"order",
"to",
"be",
"used",
"for",
"cursor",
"-",
"based",
"pagination",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/Pagination/PaginationFactory.php#L60-L63 |
woohoolabs/yin | src/JsonApi/Request/Pagination/PaginationFactory.php | PaginationFactory.createCursorBasedPagination | public function createCursorBasedPagination($defaultCursor = null, int $defaultSize = 0): CursorBasedPagination
{
return CursorBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultCursor, $defaultSize);
} | php | public function createCursorBasedPagination($defaultCursor = null, int $defaultSize = 0): CursorBasedPagination
{
return CursorBasedPagination::fromPaginationQueryParams($this->request->getPagination(), $defaultCursor, $defaultSize);
} | [
"public",
"function",
"createCursorBasedPagination",
"(",
"$",
"defaultCursor",
"=",
"null",
",",
"int",
"$",
"defaultSize",
"=",
"0",
")",
":",
"CursorBasedPagination",
"{",
"return",
"CursorBasedPagination",
"::",
"fromPaginationQueryParams",
"(",
"$",
"this",
"->",
"request",
"->",
"getPagination",
"(",
")",
",",
"$",
"defaultCursor",
",",
"$",
"defaultSize",
")",
";",
"}"
] | Returns a CursorBasedPagination class in order to be used for cursor-based pagination.
The CursorBasedPagination class stores the value of the "page[cursor]" and "page[size]" query parameters if present
or the $defaultCursor and $defaultSize otherwise.
@param mixed $defaultCursor | [
"Returns",
"a",
"CursorBasedPagination",
"class",
"in",
"order",
"to",
"be",
"used",
"for",
"cursor",
"-",
"based",
"pagination",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Request/Pagination/PaginationFactory.php#L72-L75 |
woohoolabs/yin | examples/User/JsonApi/Resource/UserResource.php | UserResource.getRelationships | public function getRelationships($user): array
{
return [
"contacts" => function (array $user) {
return
ToManyRelationship::create()
->setLinks(
RelationshipLinks::createWithoutBaseUri(
new Link("/users/" . $user["id"] . "/contacts"),
new Link("/users/" . $user["id"] . "/relationships/contacts")
)
)
->setDataAsCallable(function () use ($user) {
return $user["contacts"];
}, $this->contactTransformer)
->omitDataWhenNotIncluded()
;
}
];
} | php | public function getRelationships($user): array
{
return [
"contacts" => function (array $user) {
return
ToManyRelationship::create()
->setLinks(
RelationshipLinks::createWithoutBaseUri(
new Link("/users/" . $user["id"] . "/contacts"),
new Link("/users/" . $user["id"] . "/relationships/contacts")
)
)
->setDataAsCallable(function () use ($user) {
return $user["contacts"];
}, $this->contactTransformer)
->omitDataWhenNotIncluded()
;
}
];
} | [
"public",
"function",
"getRelationships",
"(",
"$",
"user",
")",
":",
"array",
"{",
"return",
"[",
"\"contacts\"",
"=>",
"function",
"(",
"array",
"$",
"user",
")",
"{",
"return",
"ToManyRelationship",
"::",
"create",
"(",
")",
"->",
"setLinks",
"(",
"RelationshipLinks",
"::",
"createWithoutBaseUri",
"(",
"new",
"Link",
"(",
"\"/users/\"",
".",
"$",
"user",
"[",
"\"id\"",
"]",
".",
"\"/contacts\"",
")",
",",
"new",
"Link",
"(",
"\"/users/\"",
".",
"$",
"user",
"[",
"\"id\"",
"]",
".",
"\"/relationships/contacts\"",
")",
")",
")",
"->",
"setDataAsCallable",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"user",
")",
"{",
"return",
"$",
"user",
"[",
"\"contacts\"",
"]",
";",
"}",
",",
"$",
"this",
"->",
"contactTransformer",
")",
"->",
"omitDataWhenNotIncluded",
"(",
")",
";",
"}",
"]",
";",
"}"
] | Provides information about the "relationships" member of the current resource.
The method returns an array where the keys signify the relationship names,
while the values are callables receiving the domain object as an argument,
and they should return a new relationship instance (to-one or to-many).
@param array $user
@return callable[] | [
"Provides",
"information",
"about",
"the",
"relationships",
"member",
"of",
"the",
"current",
"resource",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/examples/User/JsonApi/Resource/UserResource.php#L116-L135 |
woohoolabs/yin | src/JsonApi/Hydrator/UpdateHydratorTrait.php | UpdateHydratorTrait.hydrateForUpdate | public function hydrateForUpdate(
JsonApiRequestInterface $request,
ExceptionFactoryInterface $exceptionFactory,
$domainObject
) {
$data = $request->getResource();
if ($data === null) {
throw $exceptionFactory->createDataMemberMissingException($request);
}
$this->validateType($data, $exceptionFactory);
$domainObject = $this->hydrateIdForUpdate($domainObject, $data, $exceptionFactory);
$this->validateRequest($request);
$domainObject = $this->hydrateAttributes($domainObject, $data);
$domainObject = $this->hydrateRelationships($domainObject, $data, $exceptionFactory);
return $domainObject;
} | php | public function hydrateForUpdate(
JsonApiRequestInterface $request,
ExceptionFactoryInterface $exceptionFactory,
$domainObject
) {
$data = $request->getResource();
if ($data === null) {
throw $exceptionFactory->createDataMemberMissingException($request);
}
$this->validateType($data, $exceptionFactory);
$domainObject = $this->hydrateIdForUpdate($domainObject, $data, $exceptionFactory);
$this->validateRequest($request);
$domainObject = $this->hydrateAttributes($domainObject, $data);
$domainObject = $this->hydrateRelationships($domainObject, $data, $exceptionFactory);
return $domainObject;
} | [
"public",
"function",
"hydrateForUpdate",
"(",
"JsonApiRequestInterface",
"$",
"request",
",",
"ExceptionFactoryInterface",
"$",
"exceptionFactory",
",",
"$",
"domainObject",
")",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"getResource",
"(",
")",
";",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"throw",
"$",
"exceptionFactory",
"->",
"createDataMemberMissingException",
"(",
"$",
"request",
")",
";",
"}",
"$",
"this",
"->",
"validateType",
"(",
"$",
"data",
",",
"$",
"exceptionFactory",
")",
";",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateIdForUpdate",
"(",
"$",
"domainObject",
",",
"$",
"data",
",",
"$",
"exceptionFactory",
")",
";",
"$",
"this",
"->",
"validateRequest",
"(",
"$",
"request",
")",
";",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateAttributes",
"(",
"$",
"domainObject",
",",
"$",
"data",
")",
";",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateRelationships",
"(",
"$",
"domainObject",
",",
"$",
"data",
",",
"$",
"exceptionFactory",
")",
";",
"return",
"$",
"domainObject",
";",
"}"
] | Hydrates the domain object from the updating request.
The domain object's attributes and relationships are hydrated
according to the JSON:API specification.
@param mixed $domainObject
@return mixed
@throws JsonApiExceptionInterface | [
"Hydrates",
"the",
"domain",
"object",
"from",
"the",
"updating",
"request",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Hydrator/UpdateHydratorTrait.php#L94-L111 |
woohoolabs/yin | src/JsonApi/Response/Responder.php | Responder.ok | public function ok(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
return $this->getResourceResponse($document, $object, 200, $additionalMeta);
} | php | public function ok(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
return $this->getResourceResponse($document, $object, 200, $additionalMeta);
} | [
"public",
"function",
"ok",
"(",
"ResourceDocumentInterface",
"$",
"document",
",",
"$",
"object",
",",
"array",
"$",
"additionalMeta",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"getResourceResponse",
"(",
"$",
"document",
",",
"$",
"object",
",",
"200",
",",
"$",
"additionalMeta",
")",
";",
"}"
] | Returns a "200 Ok" response, containing a document in the body with the resource.
@param mixed $object | [
"Returns",
"a",
"200",
"Ok",
"response",
"containing",
"a",
"document",
"in",
"the",
"body",
"with",
"the",
"resource",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Response/Responder.php#L42-L45 |
woohoolabs/yin | src/JsonApi/Response/Responder.php | Responder.okWithMeta | public function okWithMeta(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
return $this->getMetaResponse($document, $object, 200, $additionalMeta);
} | php | public function okWithMeta(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
return $this->getMetaResponse($document, $object, 200, $additionalMeta);
} | [
"public",
"function",
"okWithMeta",
"(",
"ResourceDocumentInterface",
"$",
"document",
",",
"$",
"object",
",",
"array",
"$",
"additionalMeta",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"getMetaResponse",
"(",
"$",
"document",
",",
"$",
"object",
",",
"200",
",",
"$",
"additionalMeta",
")",
";",
"}"
] | Returns a "200 Ok" response, containing a document in the body with the resource metadata.
@param mixed $object | [
"Returns",
"a",
"200",
"Ok",
"response",
"containing",
"a",
"document",
"in",
"the",
"body",
"with",
"the",
"resource",
"metadata",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Response/Responder.php#L51-L54 |
woohoolabs/yin | src/JsonApi/Response/Responder.php | Responder.created | public function created(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
$response = $this->getResourceResponse($document, $object, 201, $additionalMeta);
return $this->getResponseWithLocationHeader($document, $response);
} | php | public function created(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
$response = $this->getResourceResponse($document, $object, 201, $additionalMeta);
return $this->getResponseWithLocationHeader($document, $response);
} | [
"public",
"function",
"created",
"(",
"ResourceDocumentInterface",
"$",
"document",
",",
"$",
"object",
",",
"array",
"$",
"additionalMeta",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getResourceResponse",
"(",
"$",
"document",
",",
"$",
"object",
",",
"201",
",",
"$",
"additionalMeta",
")",
";",
"return",
"$",
"this",
"->",
"getResponseWithLocationHeader",
"(",
"$",
"document",
",",
"$",
"response",
")",
";",
"}"
] | Returns a "201 Created" response, containing a document in the body with the newly created resource. You can also
pass additional meta information for the document in the $additionalMeta argument.
@param mixed $object | [
"Returns",
"a",
"201",
"Created",
"response",
"containing",
"a",
"document",
"in",
"the",
"body",
"with",
"the",
"newly",
"created",
"resource",
".",
"You",
"can",
"also",
"pass",
"additional",
"meta",
"information",
"for",
"the",
"document",
"in",
"the",
"$additionalMeta",
"argument",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Response/Responder.php#L81-L86 |
woohoolabs/yin | src/JsonApi/Response/Responder.php | Responder.createdWithMeta | public function createdWithMeta(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
$response = $this->getMetaResponse($document, $object, 201, $additionalMeta);
return $this->getResponseWithLocationHeader($document, $response);
} | php | public function createdWithMeta(ResourceDocumentInterface $document, $object, array $additionalMeta = []): ResponseInterface
{
$response = $this->getMetaResponse($document, $object, 201, $additionalMeta);
return $this->getResponseWithLocationHeader($document, $response);
} | [
"public",
"function",
"createdWithMeta",
"(",
"ResourceDocumentInterface",
"$",
"document",
",",
"$",
"object",
",",
"array",
"$",
"additionalMeta",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getMetaResponse",
"(",
"$",
"document",
",",
"$",
"object",
",",
"201",
",",
"$",
"additionalMeta",
")",
";",
"return",
"$",
"this",
"->",
"getResponseWithLocationHeader",
"(",
"$",
"document",
",",
"$",
"response",
")",
";",
"}"
] | Returns a "201 Created" response, containing a document in the body with the newly created resource metadata.
You can also pass additional meta information for the document in the $additionalMeta argument.
@param mixed $object | [
"Returns",
"a",
"201",
"Created",
"response",
"containing",
"a",
"document",
"in",
"the",
"body",
"with",
"the",
"newly",
"created",
"resource",
"metadata",
".",
"You",
"can",
"also",
"pass",
"additional",
"meta",
"information",
"for",
"the",
"document",
"in",
"the",
"$additionalMeta",
"argument",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Response/Responder.php#L93-L98 |
woohoolabs/yin | src/JsonApi/Response/Responder.php | Responder.createdWithRelationship | public function createdWithRelationship(
string $relationshipName,
ResourceDocumentInterface $document,
$object,
array $additionalMeta = []
): ResponseInterface {
return $this->getRelationshipResponse(
$relationshipName,
$document,
$object,
201,
$additionalMeta
);
} | php | public function createdWithRelationship(
string $relationshipName,
ResourceDocumentInterface $document,
$object,
array $additionalMeta = []
): ResponseInterface {
return $this->getRelationshipResponse(
$relationshipName,
$document,
$object,
201,
$additionalMeta
);
} | [
"public",
"function",
"createdWithRelationship",
"(",
"string",
"$",
"relationshipName",
",",
"ResourceDocumentInterface",
"$",
"document",
",",
"$",
"object",
",",
"array",
"$",
"additionalMeta",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"getRelationshipResponse",
"(",
"$",
"relationshipName",
",",
"$",
"document",
",",
"$",
"object",
",",
"201",
",",
"$",
"additionalMeta",
")",
";",
"}"
] | Returns a "200 Ok" response, containing a document in the body with the relationship. You can also
pass additional meta information for the document in the $additionalMeta argument.
@param mixed $object | [
"Returns",
"a",
"200",
"Ok",
"response",
"containing",
"a",
"document",
"in",
"the",
"body",
"with",
"the",
"relationship",
".",
"You",
"can",
"also",
"pass",
"additional",
"meta",
"information",
"for",
"the",
"document",
"in",
"the",
"$additionalMeta",
"argument",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Response/Responder.php#L105-L118 |
woohoolabs/yin | src/JsonApi/Response/Responder.php | Responder.genericError | public function genericError(ErrorDocumentInterface $document, ?int $statusCode = null, array $additionalMeta = []): ResponseInterface
{
return $this->getErrorResponse($document, $statusCode, $additionalMeta);
} | php | public function genericError(ErrorDocumentInterface $document, ?int $statusCode = null, array $additionalMeta = []): ResponseInterface
{
return $this->getErrorResponse($document, $statusCode, $additionalMeta);
} | [
"public",
"function",
"genericError",
"(",
"ErrorDocumentInterface",
"$",
"document",
",",
"?",
"int",
"$",
"statusCode",
"=",
"null",
",",
"array",
"$",
"additionalMeta",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"getErrorResponse",
"(",
"$",
"document",
",",
"$",
"statusCode",
",",
"$",
"additionalMeta",
")",
";",
"}"
] | Returns an error response, containing a document in the body with the errors. You can also pass additional
meta information to the document in the $additionalMeta argument. | [
"Returns",
"an",
"error",
"response",
"containing",
"a",
"document",
"in",
"the",
"body",
"with",
"the",
"errors",
".",
"You",
"can",
"also",
"pass",
"additional",
"meta",
"information",
"to",
"the",
"document",
"in",
"the",
"$additionalMeta",
"argument",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Response/Responder.php#L175-L178 |
woohoolabs/yin | src/JsonApi/Hydrator/CreateHydratorTrait.php | CreateHydratorTrait.hydrateForCreate | public function hydrateForCreate(
JsonApiRequestInterface $request,
ExceptionFactoryInterface $exceptionFactory,
$domainObject
) {
$data = $request->getResource();
if ($data === null) {
throw $exceptionFactory->createDataMemberMissingException($request);
}
$this->validateType($data, $exceptionFactory);
$domainObject = $this->hydrateIdForCreate($domainObject, $data, $request, $exceptionFactory);
$this->validateRequest($request);
$domainObject = $this->hydrateAttributes($domainObject, $data);
$domainObject = $this->hydrateRelationships($domainObject, $data, $exceptionFactory);
return $domainObject;
} | php | public function hydrateForCreate(
JsonApiRequestInterface $request,
ExceptionFactoryInterface $exceptionFactory,
$domainObject
) {
$data = $request->getResource();
if ($data === null) {
throw $exceptionFactory->createDataMemberMissingException($request);
}
$this->validateType($data, $exceptionFactory);
$domainObject = $this->hydrateIdForCreate($domainObject, $data, $request, $exceptionFactory);
$this->validateRequest($request);
$domainObject = $this->hydrateAttributes($domainObject, $data);
$domainObject = $this->hydrateRelationships($domainObject, $data, $exceptionFactory);
return $domainObject;
} | [
"public",
"function",
"hydrateForCreate",
"(",
"JsonApiRequestInterface",
"$",
"request",
",",
"ExceptionFactoryInterface",
"$",
"exceptionFactory",
",",
"$",
"domainObject",
")",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"getResource",
"(",
")",
";",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"throw",
"$",
"exceptionFactory",
"->",
"createDataMemberMissingException",
"(",
"$",
"request",
")",
";",
"}",
"$",
"this",
"->",
"validateType",
"(",
"$",
"data",
",",
"$",
"exceptionFactory",
")",
";",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateIdForCreate",
"(",
"$",
"domainObject",
",",
"$",
"data",
",",
"$",
"request",
",",
"$",
"exceptionFactory",
")",
";",
"$",
"this",
"->",
"validateRequest",
"(",
"$",
"request",
")",
";",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateAttributes",
"(",
"$",
"domainObject",
",",
"$",
"data",
")",
";",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateRelationships",
"(",
"$",
"domainObject",
",",
"$",
"data",
",",
"$",
"exceptionFactory",
")",
";",
"return",
"$",
"domainObject",
";",
"}"
] | Hydrates the domain object from the creating request.
The domain object's attributes and relationships are hydrated
according to the JSON:API specification.
@param mixed $domainObject
@return mixed
@throws JsonApiExceptionInterface | [
"Hydrates",
"the",
"domain",
"object",
"from",
"the",
"creating",
"request",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Hydrator/CreateHydratorTrait.php#L86-L103 |
woohoolabs/yin | examples/Book/JsonApi/Resource/BookResource.php | BookResource.getAttributes | public function getAttributes($book): array
{
return [
"title" => function (array $book) {
return $book["title"];
},
"isbn13" => function (array $book) {
return $book["isbn13"];
},
"releaseDate" => function (array $book) {
return $book["release_date"];
},
"hardCover" => function (array $book) {
return $book["hard_cover"];
},
"pages" => function (array $book) {
return (int) $book["pages"];
},
];
} | php | public function getAttributes($book): array
{
return [
"title" => function (array $book) {
return $book["title"];
},
"isbn13" => function (array $book) {
return $book["isbn13"];
},
"releaseDate" => function (array $book) {
return $book["release_date"];
},
"hardCover" => function (array $book) {
return $book["hard_cover"];
},
"pages" => function (array $book) {
return (int) $book["pages"];
},
];
} | [
"public",
"function",
"getAttributes",
"(",
"$",
"book",
")",
":",
"array",
"{",
"return",
"[",
"\"title\"",
"=>",
"function",
"(",
"array",
"$",
"book",
")",
"{",
"return",
"$",
"book",
"[",
"\"title\"",
"]",
";",
"}",
",",
"\"isbn13\"",
"=>",
"function",
"(",
"array",
"$",
"book",
")",
"{",
"return",
"$",
"book",
"[",
"\"isbn13\"",
"]",
";",
"}",
",",
"\"releaseDate\"",
"=>",
"function",
"(",
"array",
"$",
"book",
")",
"{",
"return",
"$",
"book",
"[",
"\"release_date\"",
"]",
";",
"}",
",",
"\"hardCover\"",
"=>",
"function",
"(",
"array",
"$",
"book",
")",
"{",
"return",
"$",
"book",
"[",
"\"hard_cover\"",
"]",
";",
"}",
",",
"\"pages\"",
"=>",
"function",
"(",
"array",
"$",
"book",
")",
"{",
"return",
"(",
"int",
")",
"$",
"book",
"[",
"\"pages\"",
"]",
";",
"}",
",",
"]",
";",
"}"
] | Provides information about the "attributes" member of the current resource.
The method returns an array of attributes if you want the section to
appear in the response or null if it should be omitted. In the returned array,
the keys signify the attribute names, while the values are callables receiving the
domain object as an argument, and they should return the value of the corresponding
attribute.
@param array $book
@return callable[] | [
"Provides",
"information",
"about",
"the",
"attributes",
"member",
"of",
"the",
"current",
"resource",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/examples/Book/JsonApi/Resource/BookResource.php#L100-L119 |
woohoolabs/yin | examples/Book/JsonApi/Resource/BookResource.php | BookResource.getRelationships | public function getRelationships($book): array
{
return [
"authors" => function (array $book) {
return
ToManyRelationship::create()
->setLinks(
new RelationshipLinks($this->getSelfLinkHref($book), new Link("/relationships/authors"))
)
->setData($book["authors"], $this->authorTransformer)
;
},
"publisher" => function ($book) {
return
ToOneRelationship::create()
->setLinks(
RelationshipLinks::createWithoutBaseUri()
->setBaseUri($this->getSelfLinkHref($book))
->setSelf(new Link("/relationships/publisher"))
)
->setData($book["publisher"], $this->publisherTransformer)
->omitDataWhenNotIncluded()
;
}
];
} | php | public function getRelationships($book): array
{
return [
"authors" => function (array $book) {
return
ToManyRelationship::create()
->setLinks(
new RelationshipLinks($this->getSelfLinkHref($book), new Link("/relationships/authors"))
)
->setData($book["authors"], $this->authorTransformer)
;
},
"publisher" => function ($book) {
return
ToOneRelationship::create()
->setLinks(
RelationshipLinks::createWithoutBaseUri()
->setBaseUri($this->getSelfLinkHref($book))
->setSelf(new Link("/relationships/publisher"))
)
->setData($book["publisher"], $this->publisherTransformer)
->omitDataWhenNotIncluded()
;
}
];
} | [
"public",
"function",
"getRelationships",
"(",
"$",
"book",
")",
":",
"array",
"{",
"return",
"[",
"\"authors\"",
"=>",
"function",
"(",
"array",
"$",
"book",
")",
"{",
"return",
"ToManyRelationship",
"::",
"create",
"(",
")",
"->",
"setLinks",
"(",
"new",
"RelationshipLinks",
"(",
"$",
"this",
"->",
"getSelfLinkHref",
"(",
"$",
"book",
")",
",",
"new",
"Link",
"(",
"\"/relationships/authors\"",
")",
")",
")",
"->",
"setData",
"(",
"$",
"book",
"[",
"\"authors\"",
"]",
",",
"$",
"this",
"->",
"authorTransformer",
")",
";",
"}",
",",
"\"publisher\"",
"=>",
"function",
"(",
"$",
"book",
")",
"{",
"return",
"ToOneRelationship",
"::",
"create",
"(",
")",
"->",
"setLinks",
"(",
"RelationshipLinks",
"::",
"createWithoutBaseUri",
"(",
")",
"->",
"setBaseUri",
"(",
"$",
"this",
"->",
"getSelfLinkHref",
"(",
"$",
"book",
")",
")",
"->",
"setSelf",
"(",
"new",
"Link",
"(",
"\"/relationships/publisher\"",
")",
")",
")",
"->",
"setData",
"(",
"$",
"book",
"[",
"\"publisher\"",
"]",
",",
"$",
"this",
"->",
"publisherTransformer",
")",
"->",
"omitDataWhenNotIncluded",
"(",
")",
";",
"}",
"]",
";",
"}"
] | Provides information about the "relationships" member of the current resource.
The method returns an array where the keys signify the relationship names,
while the values are callables receiving the domain object as an argument,
and they should return a new relationship instance (to-one or to-many).
@param array $book
@return callable[] | [
"Provides",
"information",
"about",
"the",
"relationships",
"member",
"of",
"the",
"current",
"resource",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/examples/Book/JsonApi/Resource/BookResource.php#L141-L166 |
woohoolabs/yin | src/JsonApi/Hydrator/AbstractUpdateHydrator.php | AbstractUpdateHydrator.hydrate | public function hydrate(JsonApiRequestInterface $request, ExceptionFactoryInterface $exceptionFactory, $domainObject)
{
return $this->hydrateForUpdate($request, $exceptionFactory, $domainObject);
} | php | public function hydrate(JsonApiRequestInterface $request, ExceptionFactoryInterface $exceptionFactory, $domainObject)
{
return $this->hydrateForUpdate($request, $exceptionFactory, $domainObject);
} | [
"public",
"function",
"hydrate",
"(",
"JsonApiRequestInterface",
"$",
"request",
",",
"ExceptionFactoryInterface",
"$",
"exceptionFactory",
",",
"$",
"domainObject",
")",
"{",
"return",
"$",
"this",
"->",
"hydrateForUpdate",
"(",
"$",
"request",
",",
"$",
"exceptionFactory",
",",
"$",
"domainObject",
")",
";",
"}"
] | Alias for UpdateHydratorTrait::hydrateForUpdate()
@see UpdateHydratorTrait::hydrateForUpdate()
@param mixed $domainObject
@return mixed
@throws ResourceTypeMissing|JsonApiExceptionInterface | [
"Alias",
"for",
"UpdateHydratorTrait",
"::",
"hydrateForUpdate",
"()"
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Hydrator/AbstractUpdateHydrator.php#L24-L27 |
woohoolabs/yin | src/JsonApi/Transformer/ResourceTransformer.php | ResourceTransformer.transformToResourceObject | public function transformToResourceObject(ResourceTransformation $transformation, DataInterface $data): ?array
{
if ($transformation->object === null || $transformation->resource === null) {
return null;
}
$transformation->resource->initializeTransformation(
$transformation->request,
$transformation->object,
$transformation->exceptionFactory
);
$this->transformResourceIdentifier($transformation);
$this->transformLinksObject($transformation);
$this->transformAttributesObject($transformation);
$this->transformRelationshipsObject($transformation, $data);
$transformation->resource->clearTransformation();
return $transformation->result;
} | php | public function transformToResourceObject(ResourceTransformation $transformation, DataInterface $data): ?array
{
if ($transformation->object === null || $transformation->resource === null) {
return null;
}
$transformation->resource->initializeTransformation(
$transformation->request,
$transformation->object,
$transformation->exceptionFactory
);
$this->transformResourceIdentifier($transformation);
$this->transformLinksObject($transformation);
$this->transformAttributesObject($transformation);
$this->transformRelationshipsObject($transformation, $data);
$transformation->resource->clearTransformation();
return $transformation->result;
} | [
"public",
"function",
"transformToResourceObject",
"(",
"ResourceTransformation",
"$",
"transformation",
",",
"DataInterface",
"$",
"data",
")",
":",
"?",
"array",
"{",
"if",
"(",
"$",
"transformation",
"->",
"object",
"===",
"null",
"||",
"$",
"transformation",
"->",
"resource",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"transformation",
"->",
"resource",
"->",
"initializeTransformation",
"(",
"$",
"transformation",
"->",
"request",
",",
"$",
"transformation",
"->",
"object",
",",
"$",
"transformation",
"->",
"exceptionFactory",
")",
";",
"$",
"this",
"->",
"transformResourceIdentifier",
"(",
"$",
"transformation",
")",
";",
"$",
"this",
"->",
"transformLinksObject",
"(",
"$",
"transformation",
")",
";",
"$",
"this",
"->",
"transformAttributesObject",
"(",
"$",
"transformation",
")",
";",
"$",
"this",
"->",
"transformRelationshipsObject",
"(",
"$",
"transformation",
",",
"$",
"data",
")",
";",
"$",
"transformation",
"->",
"resource",
"->",
"clearTransformation",
"(",
")",
";",
"return",
"$",
"transformation",
"->",
"result",
";",
"}"
] | Transforms the original resource to a JSON:API resource object. | [
"Transforms",
"the",
"original",
"resource",
"to",
"a",
"JSON",
":",
"API",
"resource",
"object",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Transformer/ResourceTransformer.php#L20-L40 |
woohoolabs/yin | src/JsonApi/Transformer/ResourceTransformer.php | ResourceTransformer.transformToResourceIdentifier | public function transformToResourceIdentifier(ResourceTransformation $transformation): ?array
{
if ($transformation->object === null || $transformation->resource === null) {
return null;
}
$transformation->resource->initializeTransformation(
$transformation->request,
$transformation->object,
$transformation->exceptionFactory
);
$this->transformResourceIdentifier($transformation);
$transformation->resource->clearTransformation();
return $transformation->result;
} | php | public function transformToResourceIdentifier(ResourceTransformation $transformation): ?array
{
if ($transformation->object === null || $transformation->resource === null) {
return null;
}
$transformation->resource->initializeTransformation(
$transformation->request,
$transformation->object,
$transformation->exceptionFactory
);
$this->transformResourceIdentifier($transformation);
$transformation->resource->clearTransformation();
return $transformation->result;
} | [
"public",
"function",
"transformToResourceIdentifier",
"(",
"ResourceTransformation",
"$",
"transformation",
")",
":",
"?",
"array",
"{",
"if",
"(",
"$",
"transformation",
"->",
"object",
"===",
"null",
"||",
"$",
"transformation",
"->",
"resource",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"transformation",
"->",
"resource",
"->",
"initializeTransformation",
"(",
"$",
"transformation",
"->",
"request",
",",
"$",
"transformation",
"->",
"object",
",",
"$",
"transformation",
"->",
"exceptionFactory",
")",
";",
"$",
"this",
"->",
"transformResourceIdentifier",
"(",
"$",
"transformation",
")",
";",
"$",
"transformation",
"->",
"resource",
"->",
"clearTransformation",
"(",
")",
";",
"return",
"$",
"transformation",
"->",
"result",
";",
"}"
] | Transforms the original resource to a JSON:API resource identifier. | [
"Transforms",
"the",
"original",
"resource",
"to",
"a",
"JSON",
":",
"API",
"resource",
"identifier",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Transformer/ResourceTransformer.php#L45-L62 |
woohoolabs/yin | src/JsonApi/Transformer/ResourceTransformer.php | ResourceTransformer.transformToRelationshipObject | public function transformToRelationshipObject(ResourceTransformation $transformation, DataInterface $data): ?array
{
if ($transformation->object === null || $transformation->resource === null) {
return null;
}
$relationships = $transformation->resource->getRelationships($transformation->object);
if (isset($relationships[$transformation->requestedRelationshipName]) === false) {
throw $transformation->exceptionFactory->createRelationshipNotExistsException($transformation->requestedRelationshipName);
}
$defaultRelationships = $transformation->resource->getDefaultIncludedRelationships($transformation->object);
$transformation->result = $this->transformRelationshipObject(
$transformation,
$data,
$relationships[$transformation->currentRelationshipName],
$defaultRelationships
);
return $transformation->result;
} | php | public function transformToRelationshipObject(ResourceTransformation $transformation, DataInterface $data): ?array
{
if ($transformation->object === null || $transformation->resource === null) {
return null;
}
$relationships = $transformation->resource->getRelationships($transformation->object);
if (isset($relationships[$transformation->requestedRelationshipName]) === false) {
throw $transformation->exceptionFactory->createRelationshipNotExistsException($transformation->requestedRelationshipName);
}
$defaultRelationships = $transformation->resource->getDefaultIncludedRelationships($transformation->object);
$transformation->result = $this->transformRelationshipObject(
$transformation,
$data,
$relationships[$transformation->currentRelationshipName],
$defaultRelationships
);
return $transformation->result;
} | [
"public",
"function",
"transformToRelationshipObject",
"(",
"ResourceTransformation",
"$",
"transformation",
",",
"DataInterface",
"$",
"data",
")",
":",
"?",
"array",
"{",
"if",
"(",
"$",
"transformation",
"->",
"object",
"===",
"null",
"||",
"$",
"transformation",
"->",
"resource",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"relationships",
"=",
"$",
"transformation",
"->",
"resource",
"->",
"getRelationships",
"(",
"$",
"transformation",
"->",
"object",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"relationships",
"[",
"$",
"transformation",
"->",
"requestedRelationshipName",
"]",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"transformation",
"->",
"exceptionFactory",
"->",
"createRelationshipNotExistsException",
"(",
"$",
"transformation",
"->",
"requestedRelationshipName",
")",
";",
"}",
"$",
"defaultRelationships",
"=",
"$",
"transformation",
"->",
"resource",
"->",
"getDefaultIncludedRelationships",
"(",
"$",
"transformation",
"->",
"object",
")",
";",
"$",
"transformation",
"->",
"result",
"=",
"$",
"this",
"->",
"transformRelationshipObject",
"(",
"$",
"transformation",
",",
"$",
"data",
",",
"$",
"relationships",
"[",
"$",
"transformation",
"->",
"currentRelationshipName",
"]",
",",
"$",
"defaultRelationships",
")",
";",
"return",
"$",
"transformation",
"->",
"result",
";",
"}"
] | Transforms a relationship of the original resource to a JSON:API relationship. | [
"Transforms",
"a",
"relationship",
"of",
"the",
"original",
"resource",
"to",
"a",
"JSON",
":",
"API",
"relationship",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Transformer/ResourceTransformer.php#L67-L88 |
woohoolabs/yin | src/TransformerTrait.php | TransformerTrait.toDecimal | public function toDecimal($value, int $precision = 12): float
{
if (is_numeric($value) === false) {
return 0.0;
}
return round((float) $value, $precision);
} | php | public function toDecimal($value, int $precision = 12): float
{
if (is_numeric($value) === false) {
return 0.0;
}
return round((float) $value, $precision);
} | [
"public",
"function",
"toDecimal",
"(",
"$",
"value",
",",
"int",
"$",
"precision",
"=",
"12",
")",
":",
"float",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"===",
"false",
")",
"{",
"return",
"0.0",
";",
"}",
"return",
"round",
"(",
"(",
"float",
")",
"$",
"value",
",",
"$",
"precision",
")",
";",
"}"
] | Transforms a value to a decimal with a precision of $precision.
@param mixed $value | [
"Transforms",
"a",
"value",
"to",
"a",
"decimal",
"with",
"a",
"precision",
"of",
"$precision",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/TransformerTrait.php#L19-L26 |
woohoolabs/yin | src/TransformerTrait.php | TransformerTrait.toIso8601Date | public function toIso8601Date(DateTimeInterface $dateTime, ?DateTimeZone $displayedTimeZone = null): string
{
if ($displayedTimeZone !== null && ($dateTime instanceof DateTime || $dateTime instanceof DateTimeImmutable)) {
$dateTime = $dateTime->setTimezone($displayedTimeZone);
}
return $dateTime->format("Y-m-d");
} | php | public function toIso8601Date(DateTimeInterface $dateTime, ?DateTimeZone $displayedTimeZone = null): string
{
if ($displayedTimeZone !== null && ($dateTime instanceof DateTime || $dateTime instanceof DateTimeImmutable)) {
$dateTime = $dateTime->setTimezone($displayedTimeZone);
}
return $dateTime->format("Y-m-d");
} | [
"public",
"function",
"toIso8601Date",
"(",
"DateTimeInterface",
"$",
"dateTime",
",",
"?",
"DateTimeZone",
"$",
"displayedTimeZone",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"displayedTimeZone",
"!==",
"null",
"&&",
"(",
"$",
"dateTime",
"instanceof",
"DateTime",
"||",
"$",
"dateTime",
"instanceof",
"DateTimeImmutable",
")",
")",
"{",
"$",
"dateTime",
"=",
"$",
"dateTime",
"->",
"setTimezone",
"(",
"$",
"displayedTimeZone",
")",
";",
"}",
"return",
"$",
"dateTime",
"->",
"format",
"(",
"\"Y-m-d\"",
")",
";",
"}"
] | Transforms a DateTime object to an ISO 8601 compatible date-time string.
If the $displayedTimeZone parameter is present then $dateTime will be converted to that time zone. | [
"Transforms",
"a",
"DateTime",
"object",
"to",
"an",
"ISO",
"8601",
"compatible",
"date",
"-",
"time",
"string",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/TransformerTrait.php#L33-L40 |
woohoolabs/yin | src/TransformerTrait.php | TransformerTrait.toIso8601DateTime | public function toIso8601DateTime(DateTimeInterface $dateTime, ?DateTimeZone $displayedTimeZone = null): string
{
if ($displayedTimeZone !== null && ($dateTime instanceof DateTime || $dateTime instanceof DateTimeImmutable)) {
$dateTime = $dateTime->setTimezone($displayedTimeZone);
}
return $dateTime->format(DateTime::ATOM);
} | php | public function toIso8601DateTime(DateTimeInterface $dateTime, ?DateTimeZone $displayedTimeZone = null): string
{
if ($displayedTimeZone !== null && ($dateTime instanceof DateTime || $dateTime instanceof DateTimeImmutable)) {
$dateTime = $dateTime->setTimezone($displayedTimeZone);
}
return $dateTime->format(DateTime::ATOM);
} | [
"public",
"function",
"toIso8601DateTime",
"(",
"DateTimeInterface",
"$",
"dateTime",
",",
"?",
"DateTimeZone",
"$",
"displayedTimeZone",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"displayedTimeZone",
"!==",
"null",
"&&",
"(",
"$",
"dateTime",
"instanceof",
"DateTime",
"||",
"$",
"dateTime",
"instanceof",
"DateTimeImmutable",
")",
")",
"{",
"$",
"dateTime",
"=",
"$",
"dateTime",
"->",
"setTimezone",
"(",
"$",
"displayedTimeZone",
")",
";",
"}",
"return",
"$",
"dateTime",
"->",
"format",
"(",
"DateTime",
"::",
"ATOM",
")",
";",
"}"
] | Transforms a DateTime object to an ISO 8601 compatible date-time string.
If the $displayedTimeZone parameter is present then $dateTime will be converted to that time zone. | [
"Transforms",
"a",
"DateTime",
"object",
"to",
"an",
"ISO",
"8601",
"compatible",
"date",
"-",
"time",
"string",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/TransformerTrait.php#L47-L54 |
woohoolabs/yin | src/TransformerTrait.php | TransformerTrait.fromSqlToIso8601Time | public function fromSqlToIso8601Time(string $string, ?DateTimeZone $displayedTimeZone = null): string
{
$dateTime = DateTime::createFromFormat(
"Y-m-d H:i:s",
$string,
$displayedTimeZone
);
if ($dateTime === false) {
return "";
}
return $dateTime->format(DateTime::ATOM);
} | php | public function fromSqlToIso8601Time(string $string, ?DateTimeZone $displayedTimeZone = null): string
{
$dateTime = DateTime::createFromFormat(
"Y-m-d H:i:s",
$string,
$displayedTimeZone
);
if ($dateTime === false) {
return "";
}
return $dateTime->format(DateTime::ATOM);
} | [
"public",
"function",
"fromSqlToIso8601Time",
"(",
"string",
"$",
"string",
",",
"?",
"DateTimeZone",
"$",
"displayedTimeZone",
"=",
"null",
")",
":",
"string",
"{",
"$",
"dateTime",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"\"Y-m-d H:i:s\"",
",",
"$",
"string",
",",
"$",
"displayedTimeZone",
")",
";",
"if",
"(",
"$",
"dateTime",
"===",
"false",
")",
"{",
"return",
"\"\"",
";",
"}",
"return",
"$",
"dateTime",
"->",
"format",
"(",
"DateTime",
"::",
"ATOM",
")",
";",
"}"
] | Transforms an SQL compatible date-time string to an ISO 8601 compatible date-time string. | [
"Transforms",
"an",
"SQL",
"compatible",
"date",
"-",
"time",
"string",
"to",
"an",
"ISO",
"8601",
"compatible",
"date",
"-",
"time",
"string",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/TransformerTrait.php#L59-L72 |
woohoolabs/yin | src/JsonApi/Hydrator/AbstractHydrator.php | AbstractHydrator.hydrate | public function hydrate(JsonApiRequestInterface $request, ExceptionFactoryInterface $exceptionFactory, $domainObject)
{
if ($request->getMethod() === "POST") {
$domainObject = $this->hydrateForCreate($request, $exceptionFactory, $domainObject);
} elseif ($request->getMethod() === "PATCH") {
$domainObject = $this->hydrateForUpdate($request, $exceptionFactory, $domainObject);
}
return $domainObject;
} | php | public function hydrate(JsonApiRequestInterface $request, ExceptionFactoryInterface $exceptionFactory, $domainObject)
{
if ($request->getMethod() === "POST") {
$domainObject = $this->hydrateForCreate($request, $exceptionFactory, $domainObject);
} elseif ($request->getMethod() === "PATCH") {
$domainObject = $this->hydrateForUpdate($request, $exceptionFactory, $domainObject);
}
return $domainObject;
} | [
"public",
"function",
"hydrate",
"(",
"JsonApiRequestInterface",
"$",
"request",
",",
"ExceptionFactoryInterface",
"$",
"exceptionFactory",
",",
"$",
"domainObject",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"===",
"\"POST\"",
")",
"{",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateForCreate",
"(",
"$",
"request",
",",
"$",
"exceptionFactory",
",",
"$",
"domainObject",
")",
";",
"}",
"elseif",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"===",
"\"PATCH\"",
")",
"{",
"$",
"domainObject",
"=",
"$",
"this",
"->",
"hydrateForUpdate",
"(",
"$",
"request",
",",
"$",
"exceptionFactory",
",",
"$",
"domainObject",
")",
";",
"}",
"return",
"$",
"domainObject",
";",
"}"
] | Hydrates the domain object from the request based on the request method.
If the request method is POST then the domain object is hydrated
as a create. If it is a PATCH request then the domain object is
hydrated as an update.
@param mixed $domainObject
@return mixed
@throws ResourceTypeMissing|JsonApiExceptionInterface | [
"Hydrates",
"the",
"domain",
"object",
"from",
"the",
"request",
"based",
"on",
"the",
"request",
"method",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Hydrator/AbstractHydrator.php#L28-L37 |
woohoolabs/yin | src/JsonApi/Transformer/DocumentTransformer.php | DocumentTransformer.transformErrors | private function transformErrors(ErrorDocumentTransformation $transformation): void
{
foreach ($transformation->document->getErrors() as $error) {
$transformation->result["errors"][] = $error->transform();
}
} | php | private function transformErrors(ErrorDocumentTransformation $transformation): void
{
foreach ($transformation->document->getErrors() as $error) {
$transformation->result["errors"][] = $error->transform();
}
} | [
"private",
"function",
"transformErrors",
"(",
"ErrorDocumentTransformation",
"$",
"transformation",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"transformation",
"->",
"document",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"transformation",
"->",
"result",
"[",
"\"errors\"",
"]",
"[",
"]",
"=",
"$",
"error",
"->",
"transform",
"(",
")",
";",
"}",
"}"
] | Returns the content as an array with all the provided members of the error document. You can also pass
additional meta information for the document in the $additionalMeta argument. | [
"Returns",
"the",
"content",
"as",
"an",
"array",
"with",
"all",
"the",
"provided",
"members",
"of",
"the",
"error",
"document",
".",
"You",
"can",
"also",
"pass",
"additional",
"meta",
"information",
"for",
"the",
"document",
"in",
"the",
"$additionalMeta",
"argument",
"."
] | train | https://github.com/woohoolabs/yin/blob/e445fa999c7e8676f6cc3c7ee8e5c139315ab242/src/JsonApi/Transformer/DocumentTransformer.php#L115-L120 |
phly/keep-a-changelog | src/AddEntry.php | AddEntry.locateInjectionIndex | private function locateInjectionIndex(array $contents, string $type) : stdClass
{
$action = (object) [
'index' => null,
'type' => self::ACTION_NOT_FOUND,
];
foreach ($contents as $index => $line) {
if (! preg_match('/^### ' . $type . '/i', $line)) {
continue;
}
$action->index = $index + 2;
$action->type = preg_match('/^- Nothing/', $contents[$action->index])
? self::ACTION_REPLACE
: self::ACTION_INJECT;
break;
}
return $action;
} | php | private function locateInjectionIndex(array $contents, string $type) : stdClass
{
$action = (object) [
'index' => null,
'type' => self::ACTION_NOT_FOUND,
];
foreach ($contents as $index => $line) {
if (! preg_match('/^### ' . $type . '/i', $line)) {
continue;
}
$action->index = $index + 2;
$action->type = preg_match('/^- Nothing/', $contents[$action->index])
? self::ACTION_REPLACE
: self::ACTION_INJECT;
break;
}
return $action;
} | [
"private",
"function",
"locateInjectionIndex",
"(",
"array",
"$",
"contents",
",",
"string",
"$",
"type",
")",
":",
"stdClass",
"{",
"$",
"action",
"=",
"(",
"object",
")",
"[",
"'index'",
"=>",
"null",
",",
"'type'",
"=>",
"self",
"::",
"ACTION_NOT_FOUND",
",",
"]",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"index",
"=>",
"$",
"line",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^### '",
".",
"$",
"type",
".",
"'/i'",
",",
"$",
"line",
")",
")",
"{",
"continue",
";",
"}",
"$",
"action",
"->",
"index",
"=",
"$",
"index",
"+",
"2",
";",
"$",
"action",
"->",
"type",
"=",
"preg_match",
"(",
"'/^- Nothing/'",
",",
"$",
"contents",
"[",
"$",
"action",
"->",
"index",
"]",
")",
"?",
"self",
"::",
"ACTION_REPLACE",
":",
"self",
"::",
"ACTION_INJECT",
";",
"break",
";",
"}",
"return",
"$",
"action",
";",
"}"
] | Locates the location within the changelog where the injection should occur.
Also determines if the injection is a replacement or an addition. | [
"Locates",
"the",
"location",
"within",
"the",
"changelog",
"where",
"the",
"injection",
"should",
"occur",
".",
"Also",
"determines",
"if",
"the",
"injection",
"is",
"a",
"replacement",
"or",
"an",
"addition",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/AddEntry.php#L76-L96 |
phly/keep-a-changelog | src/AddEntry.php | AddEntry.injectEntry | private function injectEntry(array $contents, stdClass $action, string $entry) : array
{
switch ($action->type) {
case self::ACTION_REPLACE:
array_splice($contents, $action->index, 1, $this->formatEntry($entry));
break;
case self::ACTION_INJECT:
array_splice($contents, $action->index, 0, $this->formatEntry($entry, self::APPEND_NEWLINE));
break;
default:
break;
}
return $contents;
} | php | private function injectEntry(array $contents, stdClass $action, string $entry) : array
{
switch ($action->type) {
case self::ACTION_REPLACE:
array_splice($contents, $action->index, 1, $this->formatEntry($entry));
break;
case self::ACTION_INJECT:
array_splice($contents, $action->index, 0, $this->formatEntry($entry, self::APPEND_NEWLINE));
break;
default:
break;
}
return $contents;
} | [
"private",
"function",
"injectEntry",
"(",
"array",
"$",
"contents",
",",
"stdClass",
"$",
"action",
",",
"string",
"$",
"entry",
")",
":",
"array",
"{",
"switch",
"(",
"$",
"action",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"ACTION_REPLACE",
":",
"array_splice",
"(",
"$",
"contents",
",",
"$",
"action",
"->",
"index",
",",
"1",
",",
"$",
"this",
"->",
"formatEntry",
"(",
"$",
"entry",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"ACTION_INJECT",
":",
"array_splice",
"(",
"$",
"contents",
",",
"$",
"action",
"->",
"index",
",",
"0",
",",
"$",
"this",
"->",
"formatEntry",
"(",
"$",
"entry",
",",
"self",
"::",
"APPEND_NEWLINE",
")",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"return",
"$",
"contents",
";",
"}"
] | Injects the new entry at the detected index, replacing the line if required. | [
"Injects",
"the",
"new",
"entry",
"at",
"the",
"detected",
"index",
"replacing",
"the",
"line",
"if",
"required",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/AddEntry.php#L101-L114 |
phly/keep-a-changelog | src/AddEntry.php | AddEntry.formatEntry | private function formatEntry(string $entry, bool $withExtraLine = false) : string
{
$entry = sprintf('- %s', $entry);
$entry = preg_replace("/\n(?!\s{2}|$)/s", "\n ", $entry);
if ("\n" !== $entry[-1]) {
// All entries need to end with a new line.
$entry .= "\n";
}
if ($withExtraLine) {
// If an extra line is requested, append it
$entry .= "\n";
}
return $entry;
} | php | private function formatEntry(string $entry, bool $withExtraLine = false) : string
{
$entry = sprintf('- %s', $entry);
$entry = preg_replace("/\n(?!\s{2}|$)/s", "\n ", $entry);
if ("\n" !== $entry[-1]) {
// All entries need to end with a new line.
$entry .= "\n";
}
if ($withExtraLine) {
// If an extra line is requested, append it
$entry .= "\n";
}
return $entry;
} | [
"private",
"function",
"formatEntry",
"(",
"string",
"$",
"entry",
",",
"bool",
"$",
"withExtraLine",
"=",
"false",
")",
":",
"string",
"{",
"$",
"entry",
"=",
"sprintf",
"(",
"'- %s'",
",",
"$",
"entry",
")",
";",
"$",
"entry",
"=",
"preg_replace",
"(",
"\"/\\n(?!\\s{2}|$)/s\"",
",",
"\"\\n \"",
",",
"$",
"entry",
")",
";",
"if",
"(",
"\"\\n\"",
"!==",
"$",
"entry",
"[",
"-",
"1",
"]",
")",
"{",
"// All entries need to end with a new line.",
"$",
"entry",
".=",
"\"\\n\"",
";",
"}",
"if",
"(",
"$",
"withExtraLine",
")",
"{",
"// If an extra line is requested, append it",
"$",
"entry",
".=",
"\"\\n\"",
";",
"}",
"return",
"$",
"entry",
";",
"}"
] | Formats the entry for use in the changelog.
Prepends the string '- ', and appends a newline if none is present.
If $withExtraLine is true, an extra newline is appended.
If the string spans multiple lines, it ensures all additional lines are
indented two characters. | [
"Formats",
"the",
"entry",
"for",
"use",
"in",
"the",
"changelog",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/AddEntry.php#L126-L139 |
phly/keep-a-changelog | src/ConfigFileTrait.php | ConfigFileTrait.createNewConfig | private function createNewConfig() : Config
{
$globalPath = $this->globalPath ?: getenv('HOME');
$tokenFile = sprintf('%s/.keep-a-changelog/token', $globalPath);
$token = is_readable($tokenFile)
? trim(file_get_contents($tokenFile))
: '';
return new Config($token);
} | php | private function createNewConfig() : Config
{
$globalPath = $this->globalPath ?: getenv('HOME');
$tokenFile = sprintf('%s/.keep-a-changelog/token', $globalPath);
$token = is_readable($tokenFile)
? trim(file_get_contents($tokenFile))
: '';
return new Config($token);
} | [
"private",
"function",
"createNewConfig",
"(",
")",
":",
"Config",
"{",
"$",
"globalPath",
"=",
"$",
"this",
"->",
"globalPath",
"?",
":",
"getenv",
"(",
"'HOME'",
")",
";",
"$",
"tokenFile",
"=",
"sprintf",
"(",
"'%s/.keep-a-changelog/token'",
",",
"$",
"globalPath",
")",
";",
"$",
"token",
"=",
"is_readable",
"(",
"$",
"tokenFile",
")",
"?",
"trim",
"(",
"file_get_contents",
"(",
"$",
"tokenFile",
")",
")",
":",
"''",
";",
"return",
"new",
"Config",
"(",
"$",
"token",
")",
";",
"}"
] | Create a new Config instance.
If the config file does not exist, this creates empty configuration,
optionally using an existing tokenfile ($HOME/.keep-a-changelog/token)
if it exists. | [
"Create",
"a",
"new",
"Config",
"instance",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/ConfigFileTrait.php#L70-L78 |
phly/keep-a-changelog | src/ConfigFileTrait.php | ConfigFileTrait.createConfigFromFile | private function createConfigFromFile(string $configFile) : Config
{
$ini = parse_ini_file($configFile);
return new Config($ini['token'] ?? '', $ini['provider'] ?? Config::PROVIDER_GITHUB);
} | php | private function createConfigFromFile(string $configFile) : Config
{
$ini = parse_ini_file($configFile);
return new Config($ini['token'] ?? '', $ini['provider'] ?? Config::PROVIDER_GITHUB);
} | [
"private",
"function",
"createConfigFromFile",
"(",
"string",
"$",
"configFile",
")",
":",
"Config",
"{",
"$",
"ini",
"=",
"parse_ini_file",
"(",
"$",
"configFile",
")",
";",
"return",
"new",
"Config",
"(",
"$",
"ini",
"[",
"'token'",
"]",
"??",
"''",
",",
"$",
"ini",
"[",
"'provider'",
"]",
"??",
"Config",
"::",
"PROVIDER_GITHUB",
")",
";",
"}"
] | Parses the config file and returns a populated Config instance. | [
"Parses",
"the",
"config",
"file",
"and",
"returns",
"a",
"populated",
"Config",
"instance",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/ConfigFileTrait.php#L83-L87 |
phly/keep-a-changelog | src/ChangelogBump.php | ChangelogBump.updateChangelog | public function updateChangelog(string $version)
{
$changelog = sprintf(self::TEMPLATE, $version);
$contents = file_get_contents($this->changelogFile);
$contents = preg_replace(
"/^(\# Changelog\n\n.*?)(\n\n\#\# )/s",
'$1' . $changelog . '## ',
$contents
);
file_put_contents($this->changelogFile, $contents);
} | php | public function updateChangelog(string $version)
{
$changelog = sprintf(self::TEMPLATE, $version);
$contents = file_get_contents($this->changelogFile);
$contents = preg_replace(
"/^(\# Changelog\n\n.*?)(\n\n\#\# )/s",
'$1' . $changelog . '## ',
$contents
);
file_put_contents($this->changelogFile, $contents);
} | [
"public",
"function",
"updateChangelog",
"(",
"string",
"$",
"version",
")",
"{",
"$",
"changelog",
"=",
"sprintf",
"(",
"self",
"::",
"TEMPLATE",
",",
"$",
"version",
")",
";",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"changelogFile",
")",
";",
"$",
"contents",
"=",
"preg_replace",
"(",
"\"/^(\\# Changelog\\n\\n.*?)(\\n\\n\\#\\# )/s\"",
",",
"'$1'",
".",
"$",
"changelog",
".",
"'## '",
",",
"$",
"contents",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"changelogFile",
",",
"$",
"contents",
")",
";",
"}"
] | Update the CHANGELOG with the new version information.
@param string $version | [
"Update",
"the",
"CHANGELOG",
"with",
"the",
"new",
"version",
"information",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/ChangelogBump.php#L97-L107 |
phly/keep-a-changelog | src/Edit.php | Edit.getChangelogEntry | private function getChangelogEntry($filename) : ?stdClass
{
$contents = file($filename);
if (false === $contents) {
throw Exception\ChangelogFileNotFoundException::at($filename);
}
$data = (object) [
'contents' => '',
'index' => null,
'length' => 0,
];
foreach ($contents as $index => $line) {
if (preg_match('/^## \d+\.\d+\.\d+/', $line)) {
if ($data->index) {
break;
}
$data->contents = $line;
$data->index = $index;
$data->length = 1;
continue;
}
if (! $data->index) {
continue;
}
$data->contents .= $line;
$data->length += 1;
}
return $data->index !== null ? $data : null;
} | php | private function getChangelogEntry($filename) : ?stdClass
{
$contents = file($filename);
if (false === $contents) {
throw Exception\ChangelogFileNotFoundException::at($filename);
}
$data = (object) [
'contents' => '',
'index' => null,
'length' => 0,
];
foreach ($contents as $index => $line) {
if (preg_match('/^## \d+\.\d+\.\d+/', $line)) {
if ($data->index) {
break;
}
$data->contents = $line;
$data->index = $index;
$data->length = 1;
continue;
}
if (! $data->index) {
continue;
}
$data->contents .= $line;
$data->length += 1;
}
return $data->index !== null ? $data : null;
} | [
"private",
"function",
"getChangelogEntry",
"(",
"$",
"filename",
")",
":",
"?",
"stdClass",
"{",
"$",
"contents",
"=",
"file",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"false",
"===",
"$",
"contents",
")",
"{",
"throw",
"Exception",
"\\",
"ChangelogFileNotFoundException",
"::",
"at",
"(",
"$",
"filename",
")",
";",
"}",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"'contents'",
"=>",
"''",
",",
"'index'",
"=>",
"null",
",",
"'length'",
"=>",
"0",
",",
"]",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"index",
"=>",
"$",
"line",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^## \\d+\\.\\d+\\.\\d+/'",
",",
"$",
"line",
")",
")",
"{",
"if",
"(",
"$",
"data",
"->",
"index",
")",
"{",
"break",
";",
"}",
"$",
"data",
"->",
"contents",
"=",
"$",
"line",
";",
"$",
"data",
"->",
"index",
"=",
"$",
"index",
";",
"$",
"data",
"->",
"length",
"=",
"1",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"data",
"->",
"index",
")",
"{",
"continue",
";",
"}",
"$",
"data",
"->",
"contents",
".=",
"$",
"line",
";",
"$",
"data",
"->",
"length",
"+=",
"1",
";",
"}",
"return",
"$",
"data",
"->",
"index",
"!==",
"null",
"?",
"$",
"data",
":",
"null",
";",
"}"
] | Retrieves the first changelog entry in the file.
If no changelog entry is found, returns null. Otherwise, returns an
anonymous object with the keys:
- index, indicating the line number where the contents began
- length, the number of lines in the contents
- contents, a string representing the changelog entry found in its entierty | [
"Retrieves",
"the",
"first",
"changelog",
"entry",
"in",
"the",
"file",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/Edit.php#L59-L92 |
phly/keep-a-changelog | src/Edit.php | Edit.createTempFileWithContents | private function createTempFileWithContents(string $contents) : string
{
$filename = sprintf('%s.md', uniqid('KAC', true));
$path = sprintf('%s/%s', sys_get_temp_dir(), $filename);
file_put_contents($path, $contents);
return $path;
} | php | private function createTempFileWithContents(string $contents) : string
{
$filename = sprintf('%s.md', uniqid('KAC', true));
$path = sprintf('%s/%s', sys_get_temp_dir(), $filename);
file_put_contents($path, $contents);
return $path;
} | [
"private",
"function",
"createTempFileWithContents",
"(",
"string",
"$",
"contents",
")",
":",
"string",
"{",
"$",
"filename",
"=",
"sprintf",
"(",
"'%s.md'",
",",
"uniqid",
"(",
"'KAC'",
",",
"true",
")",
")",
";",
"$",
"path",
"=",
"sprintf",
"(",
"'%s/%s'",
",",
"sys_get_temp_dir",
"(",
")",
",",
"$",
"filename",
")",
";",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"contents",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Creates a temporary file with the changelog contents. | [
"Creates",
"a",
"temporary",
"file",
"with",
"the",
"changelog",
"contents",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/Edit.php#L97-L103 |
phly/keep-a-changelog | src/Edit.php | Edit.discoverEditor | private function discoverEditor() : string
{
$editor = getenv('EDITOR');
if ($editor) {
return $editor;
}
return isset($_SERVER['OS']) && false !== strpos($_SERVER['OS'], 'indows')
? 'notepad'
: 'vi';
} | php | private function discoverEditor() : string
{
$editor = getenv('EDITOR');
if ($editor) {
return $editor;
}
return isset($_SERVER['OS']) && false !== strpos($_SERVER['OS'], 'indows')
? 'notepad'
: 'vi';
} | [
"private",
"function",
"discoverEditor",
"(",
")",
":",
"string",
"{",
"$",
"editor",
"=",
"getenv",
"(",
"'EDITOR'",
")",
";",
"if",
"(",
"$",
"editor",
")",
"{",
"return",
"$",
"editor",
";",
"}",
"return",
"isset",
"(",
"$",
"_SERVER",
"[",
"'OS'",
"]",
")",
"&&",
"false",
"!==",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'OS'",
"]",
",",
"'indows'",
")",
"?",
"'notepad'",
":",
"'vi'",
";",
"}"
] | Determines the system editor command and returns it.
Checks for the $EDITOR env variable, returning its value if present.
If not, it checks to see if we are on a Windows or other type of system,
returning "notepad" or "vi", respecively. | [
"Determines",
"the",
"system",
"editor",
"command",
"and",
"returns",
"it",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/Edit.php#L113-L124 |
phly/keep-a-changelog | src/Edit.php | Edit.spawnEditor | public function spawnEditor(OutputInterface $output, string $editor, string $filename) : int
{
$descriptorspec = [STDIN, STDOUT, STDERR];
$command = sprintf('%s %s', $editor, escapeshellarg($filename));
$output->writeln(sprintf('<info>Executing "%s"</info>', $command));
$process = proc_open($command, $descriptorspec, $pipes);
return proc_close($process);
} | php | public function spawnEditor(OutputInterface $output, string $editor, string $filename) : int
{
$descriptorspec = [STDIN, STDOUT, STDERR];
$command = sprintf('%s %s', $editor, escapeshellarg($filename));
$output->writeln(sprintf('<info>Executing "%s"</info>', $command));
$process = proc_open($command, $descriptorspec, $pipes);
return proc_close($process);
} | [
"public",
"function",
"spawnEditor",
"(",
"OutputInterface",
"$",
"output",
",",
"string",
"$",
"editor",
",",
"string",
"$",
"filename",
")",
":",
"int",
"{",
"$",
"descriptorspec",
"=",
"[",
"STDIN",
",",
"STDOUT",
",",
"STDERR",
"]",
";",
"$",
"command",
"=",
"sprintf",
"(",
"'%s %s'",
",",
"$",
"editor",
",",
"escapeshellarg",
"(",
"$",
"filename",
")",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Executing \"%s\"</info>'",
",",
"$",
"command",
")",
")",
";",
"$",
"process",
"=",
"proc_open",
"(",
"$",
"command",
",",
"$",
"descriptorspec",
",",
"$",
"pipes",
")",
";",
"return",
"proc_close",
"(",
"$",
"process",
")",
";",
"}"
] | Spawn an editor to edit the given filename. | [
"Spawn",
"an",
"editor",
"to",
"edit",
"the",
"given",
"filename",
"."
] | train | https://github.com/phly/keep-a-changelog/blob/8585813060576fc939772a7b1e37b8b6a7ff438d/src/Edit.php#L129-L138 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchEditor.php | PatchEditor.openBuffer | public function openBuffer(File $file)
{
if ( ! isset($this->builders[$file->getRelativePath()])) {
$this->builders[$file->getRelativePath()] = new PatchBuilder(
$file->getCode(), $file->getRelativePath()
);
}
return new PatchBuffer($this->builders[$file->getRelativePath()]);
} | php | public function openBuffer(File $file)
{
if ( ! isset($this->builders[$file->getRelativePath()])) {
$this->builders[$file->getRelativePath()] = new PatchBuilder(
$file->getCode(), $file->getRelativePath()
);
}
return new PatchBuffer($this->builders[$file->getRelativePath()]);
} | [
"public",
"function",
"openBuffer",
"(",
"File",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"builders",
"[",
"$",
"file",
"->",
"getRelativePath",
"(",
")",
"]",
")",
")",
"{",
"$",
"this",
"->",
"builders",
"[",
"$",
"file",
"->",
"getRelativePath",
"(",
")",
"]",
"=",
"new",
"PatchBuilder",
"(",
"$",
"file",
"->",
"getCode",
"(",
")",
",",
"$",
"file",
"->",
"getRelativePath",
"(",
")",
")",
";",
"}",
"return",
"new",
"PatchBuffer",
"(",
"$",
"this",
"->",
"builders",
"[",
"$",
"file",
"->",
"getRelativePath",
"(",
")",
"]",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchEditor.php#L37-L46 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchEditor.php | PatchEditor.save | public function save()
{
foreach ($this->builders as $builder) {
$this->command->apply($builder->generateUnifiedDiff());
}
} | php | public function save()
{
foreach ($this->builders as $builder) {
$this->command->apply($builder->generateUnifiedDiff());
}
} | [
"public",
"function",
"save",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"builders",
"as",
"$",
"builder",
")",
"{",
"$",
"this",
"->",
"command",
"->",
"apply",
"(",
"$",
"builder",
"->",
"generateUnifiedDiff",
"(",
")",
")",
";",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchEditor.php#L51-L56 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Domain/Model/File.php | File.createFromPath | public static function createFromPath($path, $workingDirectory)
{
if ( ! file_exists($path) || ! is_file($path)) {
throw new \InvalidArgumentException("Not a valid file: " . $path);
}
$code = file_get_contents($path);
$workingDirectory = rtrim($workingDirectory, '/\\');
$relativePath = ltrim(str_replace($workingDirectory, "", $path), "/\\");
// converted mixed, wrapped, absolute paths on windows
if (DIRECTORY_SEPARATOR === '\\' && strpos($relativePath, '://') !== FALSE) {
$relativePath = str_replace('\\', '/', $relativePath);
}
return new self($relativePath, $code);
} | php | public static function createFromPath($path, $workingDirectory)
{
if ( ! file_exists($path) || ! is_file($path)) {
throw new \InvalidArgumentException("Not a valid file: " . $path);
}
$code = file_get_contents($path);
$workingDirectory = rtrim($workingDirectory, '/\\');
$relativePath = ltrim(str_replace($workingDirectory, "", $path), "/\\");
// converted mixed, wrapped, absolute paths on windows
if (DIRECTORY_SEPARATOR === '\\' && strpos($relativePath, '://') !== FALSE) {
$relativePath = str_replace('\\', '/', $relativePath);
}
return new self($relativePath, $code);
} | [
"public",
"static",
"function",
"createFromPath",
"(",
"$",
"path",
",",
"$",
"workingDirectory",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
"||",
"!",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Not a valid file: \"",
".",
"$",
"path",
")",
";",
"}",
"$",
"code",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"$",
"workingDirectory",
"=",
"rtrim",
"(",
"$",
"workingDirectory",
",",
"'/\\\\'",
")",
";",
"$",
"relativePath",
"=",
"ltrim",
"(",
"str_replace",
"(",
"$",
"workingDirectory",
",",
"\"\"",
",",
"$",
"path",
")",
",",
"\"/\\\\\"",
")",
";",
"// converted mixed, wrapped, absolute paths on windows",
"if",
"(",
"DIRECTORY_SEPARATOR",
"===",
"'\\\\'",
"&&",
"strpos",
"(",
"$",
"relativePath",
",",
"'://'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"relativePath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"relativePath",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"relativePath",
",",
"$",
"code",
")",
";",
"}"
] | @param string $path
@param string $workingDirectory
@return File | [
"@param",
"string",
"$path",
"@param",
"string",
"$workingDirectory"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Domain/Model/File.php#L30-L46 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Domain/Model/File.php | File.extractPsr0ClassName | public function extractPsr0ClassName()
{
$shortName = $this->parseFileForPsr0ClassShortName();
return new PhpName(
ltrim($this->parseFileForPsr0NamespaceName() . '\\' . $shortName, '\\'),
$shortName
);
} | php | public function extractPsr0ClassName()
{
$shortName = $this->parseFileForPsr0ClassShortName();
return new PhpName(
ltrim($this->parseFileForPsr0NamespaceName() . '\\' . $shortName, '\\'),
$shortName
);
} | [
"public",
"function",
"extractPsr0ClassName",
"(",
")",
"{",
"$",
"shortName",
"=",
"$",
"this",
"->",
"parseFileForPsr0ClassShortName",
"(",
")",
";",
"return",
"new",
"PhpName",
"(",
"ltrim",
"(",
"$",
"this",
"->",
"parseFileForPsr0NamespaceName",
"(",
")",
".",
"'\\\\'",
".",
"$",
"shortName",
",",
"'\\\\'",
")",
",",
"$",
"shortName",
")",
";",
"}"
] | Extract the PhpName for the class contained in this file assuming PSR-0 naming.
@return PhpName | [
"Extract",
"the",
"PhpName",
"for",
"the",
"class",
"contained",
"in",
"this",
"file",
"assuming",
"PSR",
"-",
"0",
"naming",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Domain/Model/File.php#L83-L91 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php | PatchBuilder.changeToken | public function changeToken($originalLine, $oldToken, $newToken)
{
$newLine = $this->buffer->getLine($this->createLineNumber($originalLine));
$newLine = preg_replace(
'!(^|[^a-z0-9])(' . preg_quote($oldToken) . ')([^a-z0-9]|$)!',
'\1' . $newToken . '\3',
$newLine
);
$this->buffer->replace(
$this->createSingleLineRange($originalLine),
array($newLine)
);
} | php | public function changeToken($originalLine, $oldToken, $newToken)
{
$newLine = $this->buffer->getLine($this->createLineNumber($originalLine));
$newLine = preg_replace(
'!(^|[^a-z0-9])(' . preg_quote($oldToken) . ')([^a-z0-9]|$)!',
'\1' . $newToken . '\3',
$newLine
);
$this->buffer->replace(
$this->createSingleLineRange($originalLine),
array($newLine)
);
} | [
"public",
"function",
"changeToken",
"(",
"$",
"originalLine",
",",
"$",
"oldToken",
",",
"$",
"newToken",
")",
"{",
"$",
"newLine",
"=",
"$",
"this",
"->",
"buffer",
"->",
"getLine",
"(",
"$",
"this",
"->",
"createLineNumber",
"(",
"$",
"originalLine",
")",
")",
";",
"$",
"newLine",
"=",
"preg_replace",
"(",
"'!(^|[^a-z0-9])('",
".",
"preg_quote",
"(",
"$",
"oldToken",
")",
".",
"')([^a-z0-9]|$)!'",
",",
"'\\1'",
".",
"$",
"newToken",
".",
"'\\3'",
",",
"$",
"newLine",
")",
";",
"$",
"this",
"->",
"buffer",
"->",
"replace",
"(",
"$",
"this",
"->",
"createSingleLineRange",
"(",
"$",
"originalLine",
")",
",",
"array",
"(",
"$",
"newLine",
")",
")",
";",
"}"
] | Change Token in given line from old to new.
@param int $originalLine
@param string $oldToken
@param string $newToken
@return void | [
"Change",
"Token",
"in",
"given",
"line",
"from",
"old",
"to",
"new",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php#L71-L85 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php | PatchBuilder.appendToLine | public function appendToLine($originalLine, array $lines)
{
// Why is this one method different to the rest?
$originalLine++;
$this->buffer->insert($this->createLineNumber($originalLine), $lines);
} | php | public function appendToLine($originalLine, array $lines)
{
// Why is this one method different to the rest?
$originalLine++;
$this->buffer->insert($this->createLineNumber($originalLine), $lines);
} | [
"public",
"function",
"appendToLine",
"(",
"$",
"originalLine",
",",
"array",
"$",
"lines",
")",
"{",
"// Why is this one method different to the rest?",
"$",
"originalLine",
"++",
";",
"$",
"this",
"->",
"buffer",
"->",
"insert",
"(",
"$",
"this",
"->",
"createLineNumber",
"(",
"$",
"originalLine",
")",
",",
"$",
"lines",
")",
";",
"}"
] | Append new lines to an original line of the file.
@param int $originalLine
@param array $lines
@return void | [
"Append",
"new",
"lines",
"to",
"an",
"original",
"line",
"of",
"the",
"file",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php#L95-L101 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php | PatchBuilder.changeLines | public function changeLines($originalLine, array $newLines)
{
$this->buffer->replace($this->createSingleLineRange($originalLine), $newLines);
} | php | public function changeLines($originalLine, array $newLines)
{
$this->buffer->replace($this->createSingleLineRange($originalLine), $newLines);
} | [
"public",
"function",
"changeLines",
"(",
"$",
"originalLine",
",",
"array",
"$",
"newLines",
")",
"{",
"$",
"this",
"->",
"buffer",
"->",
"replace",
"(",
"$",
"this",
"->",
"createSingleLineRange",
"(",
"$",
"originalLine",
")",
",",
"$",
"newLines",
")",
";",
"}"
] | Change one line by replacing it with one or many new lines.
@param int $originalLine
@param array $newLines
@return void | [
"Change",
"one",
"line",
"by",
"replacing",
"it",
"with",
"one",
"or",
"many",
"new",
"lines",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php#L111-L114 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php | PatchBuilder.replaceLines | public function replaceLines($startOriginalLine, $endOriginalLine, array $newLines)
{
$this->buffer->replace($this->createLineRange($startOriginalLine, $endOriginalLine), $newLines);
} | php | public function replaceLines($startOriginalLine, $endOriginalLine, array $newLines)
{
$this->buffer->replace($this->createLineRange($startOriginalLine, $endOriginalLine), $newLines);
} | [
"public",
"function",
"replaceLines",
"(",
"$",
"startOriginalLine",
",",
"$",
"endOriginalLine",
",",
"array",
"$",
"newLines",
")",
"{",
"$",
"this",
"->",
"buffer",
"->",
"replace",
"(",
"$",
"this",
"->",
"createLineRange",
"(",
"$",
"startOriginalLine",
",",
"$",
"endOriginalLine",
")",
",",
"$",
"newLines",
")",
";",
"}"
] | Replace a range of lines with a set of new lines.
@param int $startOriginalLine
@param int $endOriginalLine
@param array $newLines
@return void | [
"Replace",
"a",
"range",
"of",
"lines",
"with",
"a",
"set",
"of",
"new",
"lines",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php#L137-L140 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php | PatchBuilder.generateUnifiedDiff | public function generateUnifiedDiff()
{
$builder = new PhpDiffBuilder();
return $builder->buildPatch(
'a/' . $this->path,
'b/' . $this->path,
$this->buffer
);
} | php | public function generateUnifiedDiff()
{
$builder = new PhpDiffBuilder();
return $builder->buildPatch(
'a/' . $this->path,
'b/' . $this->path,
$this->buffer
);
} | [
"public",
"function",
"generateUnifiedDiff",
"(",
")",
"{",
"$",
"builder",
"=",
"new",
"PhpDiffBuilder",
"(",
")",
";",
"return",
"$",
"builder",
"->",
"buildPatch",
"(",
"'a/'",
".",
"$",
"this",
"->",
"path",
",",
"'b/'",
".",
"$",
"this",
"->",
"path",
",",
"$",
"this",
"->",
"buffer",
")",
";",
"}"
] | Generate a unified diff of all operations performed on the current file.
@return string | [
"Generate",
"a",
"unified",
"diff",
"of",
"all",
"operations",
"performed",
"on",
"the",
"current",
"file",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/PatchBuilder/PatchBuilder.php#L147-L156 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Adapters/Symfony/Compiler.php | Compiler.compile | public function compile()
{
$pharFile = 'refactor.phar';
if (file_exists($pharFile)) {
unlink($pharFile);
}
$process = new Process('git log --pretty="%H" -n1 HEAD', $this->directory);
if ($process->run() != 0) {
throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.');
}
$this->version = trim($process->getOutput());
$process = new Process('git describe --tags HEAD');
if ($process->run() == 0) {
$this->version = trim($process->getOutput());
}
$phar = new \Phar($pharFile, 0, 'refactor.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->name('*.php')
->notName('Compiler.php')
->in($this->directory.'/src/main')
;
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->name('*.php')
->exclude('test')
->exclude('features')
->in($this->directory . '/vendor/')
;
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$this->addRefactorBin($phar);
// Stubs
$phar->setStub($this->getStub());
$phar->stopBuffering();
unset($phar);
} | php | public function compile()
{
$pharFile = 'refactor.phar';
if (file_exists($pharFile)) {
unlink($pharFile);
}
$process = new Process('git log --pretty="%H" -n1 HEAD', $this->directory);
if ($process->run() != 0) {
throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.');
}
$this->version = trim($process->getOutput());
$process = new Process('git describe --tags HEAD');
if ($process->run() == 0) {
$this->version = trim($process->getOutput());
}
$phar = new \Phar($pharFile, 0, 'refactor.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->name('*.php')
->notName('Compiler.php')
->in($this->directory.'/src/main')
;
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->name('*.php')
->exclude('test')
->exclude('features')
->in($this->directory . '/vendor/')
;
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$this->addRefactorBin($phar);
// Stubs
$phar->setStub($this->getStub());
$phar->stopBuffering();
unset($phar);
} | [
"public",
"function",
"compile",
"(",
")",
"{",
"$",
"pharFile",
"=",
"'refactor.phar'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"pharFile",
")",
")",
"{",
"unlink",
"(",
"$",
"pharFile",
")",
";",
"}",
"$",
"process",
"=",
"new",
"Process",
"(",
"'git log --pretty=\"%H\" -n1 HEAD'",
",",
"$",
"this",
"->",
"directory",
")",
";",
"if",
"(",
"$",
"process",
"->",
"run",
"(",
")",
"!=",
"0",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Can\\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.'",
")",
";",
"}",
"$",
"this",
"->",
"version",
"=",
"trim",
"(",
"$",
"process",
"->",
"getOutput",
"(",
")",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"'git describe --tags HEAD'",
")",
";",
"if",
"(",
"$",
"process",
"->",
"run",
"(",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"version",
"=",
"trim",
"(",
"$",
"process",
"->",
"getOutput",
"(",
")",
")",
";",
"}",
"$",
"phar",
"=",
"new",
"\\",
"Phar",
"(",
"$",
"pharFile",
",",
"0",
",",
"'refactor.phar'",
")",
";",
"$",
"phar",
"->",
"setSignatureAlgorithm",
"(",
"\\",
"Phar",
"::",
"SHA1",
")",
";",
"$",
"phar",
"->",
"startBuffering",
"(",
")",
";",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"ignoreVCS",
"(",
"true",
")",
"->",
"name",
"(",
"'*.php'",
")",
"->",
"notName",
"(",
"'Compiler.php'",
")",
"->",
"in",
"(",
"$",
"this",
"->",
"directory",
".",
"'/src/main'",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"addFile",
"(",
"$",
"phar",
",",
"$",
"file",
")",
";",
"}",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"ignoreVCS",
"(",
"true",
")",
"->",
"name",
"(",
"'*.php'",
")",
"->",
"exclude",
"(",
"'test'",
")",
"->",
"exclude",
"(",
"'features'",
")",
"->",
"in",
"(",
"$",
"this",
"->",
"directory",
".",
"'/vendor/'",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"addFile",
"(",
"$",
"phar",
",",
"$",
"file",
")",
";",
"}",
"$",
"this",
"->",
"addRefactorBin",
"(",
"$",
"phar",
")",
";",
"// Stubs",
"$",
"phar",
"->",
"setStub",
"(",
"$",
"this",
"->",
"getStub",
"(",
")",
")",
";",
"$",
"phar",
"->",
"stopBuffering",
"(",
")",
";",
"unset",
"(",
"$",
"phar",
")",
";",
"}"
] | Compiles composer into a single phar file
@throws \RuntimeException | [
"Compiles",
"composer",
"into",
"a",
"single",
"phar",
"file"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Adapters/Symfony/Compiler.php#L42-L99 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Domain/Model/EditingAction/ReplaceWithMethodCall.php | ReplaceWithMethodCall.getIndent | private function getIndent(array $lines)
{
$detector = new IndentationDetector(
LineCollection::createFromArray($lines)
);
return str_repeat(' ', $detector->getFirstLineIndentation());
} | php | private function getIndent(array $lines)
{
$detector = new IndentationDetector(
LineCollection::createFromArray($lines)
);
return str_repeat(' ', $detector->getFirstLineIndentation());
} | [
"private",
"function",
"getIndent",
"(",
"array",
"$",
"lines",
")",
"{",
"$",
"detector",
"=",
"new",
"IndentationDetector",
"(",
"LineCollection",
"::",
"createFromArray",
"(",
"$",
"lines",
")",
")",
";",
"return",
"str_repeat",
"(",
"' '",
",",
"$",
"detector",
"->",
"getFirstLineIndentation",
"(",
")",
")",
";",
"}"
] | @param string[] $lines
@return string | [
"@param",
"string",
"[]",
"$lines"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Domain/Model/EditingAction/ReplaceWithMethodCall.php#L42-L49 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Domain/Model/DefinedVariables.php | DefinedVariables.contains | public function contains(Variable $variable)
{
return (
isset($this->readAccess[$variable->getName()]) ||
isset($this->changeAccess[$variable->getName()])
);
} | php | public function contains(Variable $variable)
{
return (
isset($this->readAccess[$variable->getName()]) ||
isset($this->changeAccess[$variable->getName()])
);
} | [
"public",
"function",
"contains",
"(",
"Variable",
"$",
"variable",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"readAccess",
"[",
"$",
"variable",
"->",
"getName",
"(",
")",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"changeAccess",
"[",
"$",
"variable",
"->",
"getName",
"(",
")",
"]",
")",
")",
";",
"}"
] | Does list contain the given variable?
@return bool | [
"Does",
"list",
"contain",
"the",
"given",
"variable?"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Domain/Model/DefinedVariables.php#L76-L82 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Domain/Model/PhpNames/NoImportedUsagesFilter.php | NoImportedUsagesFilter.filter | public function filter(array $phpNames)
{
$fileUseOccurances = array_flip(
array_map(
function ($useOccurance) {
return $useOccurance->name()->fullyQualifiedName();
},
array_filter(
$phpNames,
function ($occurance) {
return $occurance->name()->type() === PhpName::TYPE_USE;
}
)
)
);
return array_filter(
$phpNames,
function ($occurance) use ($fileUseOccurances) {
return (
$occurance->name()->type() !== PhpName::TYPE_USAGE ||
!isset($fileUseOccurances[$occurance->name()->fullyQualifiedName()])
);
}
);
} | php | public function filter(array $phpNames)
{
$fileUseOccurances = array_flip(
array_map(
function ($useOccurance) {
return $useOccurance->name()->fullyQualifiedName();
},
array_filter(
$phpNames,
function ($occurance) {
return $occurance->name()->type() === PhpName::TYPE_USE;
}
)
)
);
return array_filter(
$phpNames,
function ($occurance) use ($fileUseOccurances) {
return (
$occurance->name()->type() !== PhpName::TYPE_USAGE ||
!isset($fileUseOccurances[$occurance->name()->fullyQualifiedName()])
);
}
);
} | [
"public",
"function",
"filter",
"(",
"array",
"$",
"phpNames",
")",
"{",
"$",
"fileUseOccurances",
"=",
"array_flip",
"(",
"array_map",
"(",
"function",
"(",
"$",
"useOccurance",
")",
"{",
"return",
"$",
"useOccurance",
"->",
"name",
"(",
")",
"->",
"fullyQualifiedName",
"(",
")",
";",
"}",
",",
"array_filter",
"(",
"$",
"phpNames",
",",
"function",
"(",
"$",
"occurance",
")",
"{",
"return",
"$",
"occurance",
"->",
"name",
"(",
")",
"->",
"type",
"(",
")",
"===",
"PhpName",
"::",
"TYPE_USE",
";",
"}",
")",
")",
")",
";",
"return",
"array_filter",
"(",
"$",
"phpNames",
",",
"function",
"(",
"$",
"occurance",
")",
"use",
"(",
"$",
"fileUseOccurances",
")",
"{",
"return",
"(",
"$",
"occurance",
"->",
"name",
"(",
")",
"->",
"type",
"(",
")",
"!==",
"PhpName",
"::",
"TYPE_USAGE",
"||",
"!",
"isset",
"(",
"$",
"fileUseOccurances",
"[",
"$",
"occurance",
"->",
"name",
"(",
")",
"->",
"fullyQualifiedName",
"(",
")",
"]",
")",
")",
";",
"}",
")",
";",
"}"
] | @param array<PhpNameOccurance>
@return array<PhpNameOccurance> | [
"@param",
"array<PhpNameOccurance",
">"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Domain/Model/PhpNames/NoImportedUsagesFilter.php#L17-L42 |
QafooLabs/php-refactoring-browser | features/bootstrap/FeatureContext.php | FeatureContext.formatExpectedPatch | protected function formatExpectedPatch($patch)
{
if ('\\' === DIRECTORY_SEPARATOR) {
$formatLine = function ($line) {
// replace lines for diff-path-files starting with --- or +++
$line = preg_replace_callback('~^((?:---|\+\+\+)\s*(?:a|b)/)(.*)~', function ($match) {
list($all, $diff, $path) = $match;
// dont replace wrapped path separators
if (! preg_match('~^[a-z]+://~i', $path)) {
$path = str_replace('/', '\\', $path);
}
return $diff.$path;
}, $line);
return trim($line);
};
} else {
$formatLine = function ($line) {
return trim($line);
};
}
return array_map($formatLine, explode("\n", rtrim($patch)));
} | php | protected function formatExpectedPatch($patch)
{
if ('\\' === DIRECTORY_SEPARATOR) {
$formatLine = function ($line) {
// replace lines for diff-path-files starting with --- or +++
$line = preg_replace_callback('~^((?:---|\+\+\+)\s*(?:a|b)/)(.*)~', function ($match) {
list($all, $diff, $path) = $match;
// dont replace wrapped path separators
if (! preg_match('~^[a-z]+://~i', $path)) {
$path = str_replace('/', '\\', $path);
}
return $diff.$path;
}, $line);
return trim($line);
};
} else {
$formatLine = function ($line) {
return trim($line);
};
}
return array_map($formatLine, explode("\n", rtrim($patch)));
} | [
"protected",
"function",
"formatExpectedPatch",
"(",
"$",
"patch",
")",
"{",
"if",
"(",
"'\\\\'",
"===",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"formatLine",
"=",
"function",
"(",
"$",
"line",
")",
"{",
"// replace lines for diff-path-files starting with --- or +++",
"$",
"line",
"=",
"preg_replace_callback",
"(",
"'~^((?:---|\\+\\+\\+)\\s*(?:a|b)/)(.*)~'",
",",
"function",
"(",
"$",
"match",
")",
"{",
"list",
"(",
"$",
"all",
",",
"$",
"diff",
",",
"$",
"path",
")",
"=",
"$",
"match",
";",
"// dont replace wrapped path separators",
"if",
"(",
"!",
"preg_match",
"(",
"'~^[a-z]+://~i'",
",",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"diff",
".",
"$",
"path",
";",
"}",
",",
"$",
"line",
")",
";",
"return",
"trim",
"(",
"$",
"line",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
"formatLine",
"=",
"function",
"(",
"$",
"line",
")",
"{",
"return",
"trim",
"(",
"$",
"line",
")",
";",
"}",
";",
"}",
"return",
"array_map",
"(",
"$",
"formatLine",
",",
"explode",
"(",
"\"\\n\"",
",",
"rtrim",
"(",
"$",
"patch",
")",
")",
")",
";",
"}"
] | converts / paths in expectedPatch text to \ paths
leaves the a/ b/ slashes untouched
returns an array of lines
@return array | [
"converts",
"/",
"paths",
"in",
"expectedPatch",
"text",
"to",
"\\",
"paths"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/features/bootstrap/FeatureContext.php#L119-L146 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Domain/Model/PhpName.php | PhpName.isAffectedByChangesTo | public function isAffectedByChangesTo(PhpName $other)
{
return
$this->fullyQualifiedName === $other->fullyQualifiedName ||
$this->overlaps($other)
;
} | php | public function isAffectedByChangesTo(PhpName $other)
{
return
$this->fullyQualifiedName === $other->fullyQualifiedName ||
$this->overlaps($other)
;
} | [
"public",
"function",
"isAffectedByChangesTo",
"(",
"PhpName",
"$",
"other",
")",
"{",
"return",
"$",
"this",
"->",
"fullyQualifiedName",
"===",
"$",
"other",
"->",
"fullyQualifiedName",
"||",
"$",
"this",
"->",
"overlaps",
"(",
"$",
"other",
")",
";",
"}"
] | Would this name be affected by a change to the given name?
@param PhpName $other
@return bool | [
"Would",
"this",
"name",
"be",
"affected",
"by",
"a",
"change",
"to",
"the",
"given",
"name?"
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Domain/Model/PhpName.php#L56-L62 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Collections/Set.php | Set.add | public function add($item)
{
if ($item instanceof Hashable) {
$this->items[$item->hashCode()] = $item;
return;
}
$this->items[(string)$item] = $item;
} | php | public function add($item)
{
if ($item instanceof Hashable) {
$this->items[$item->hashCode()] = $item;
return;
}
$this->items[(string)$item] = $item;
} | [
"public",
"function",
"add",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"Hashable",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"$",
"item",
"->",
"hashCode",
"(",
")",
"]",
"=",
"$",
"item",
";",
"return",
";",
"}",
"$",
"this",
"->",
"items",
"[",
"(",
"string",
")",
"$",
"item",
"]",
"=",
"$",
"item",
";",
"}"
] | Add a new item to the set.
Overrides values that were previously set that have the same value
or hashCode. If you pass an object make sure it implements either
{__toString()} or the {@see Hashable} interface.
@param mixed $item
@return void | [
"Add",
"a",
"new",
"item",
"to",
"the",
"set",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Collections/Set.php#L26-L35 |
QafooLabs/php-refactoring-browser | src/main/QafooLabs/Refactoring/Domain/Services/CodeAnalysis.php | CodeAnalysis.findMethodRange | public function findMethodRange(File $file, LineRange $range)
{
$methodStartLine = $this->getMethodStartLine($file, $range);
$methodEndLine = $this->getMethodEndLine($file, $range);
return LineRange::fromLines($methodStartLine, $methodEndLine);
} | php | public function findMethodRange(File $file, LineRange $range)
{
$methodStartLine = $this->getMethodStartLine($file, $range);
$methodEndLine = $this->getMethodEndLine($file, $range);
return LineRange::fromLines($methodStartLine, $methodEndLine);
} | [
"public",
"function",
"findMethodRange",
"(",
"File",
"$",
"file",
",",
"LineRange",
"$",
"range",
")",
"{",
"$",
"methodStartLine",
"=",
"$",
"this",
"->",
"getMethodStartLine",
"(",
"$",
"file",
",",
"$",
"range",
")",
";",
"$",
"methodEndLine",
"=",
"$",
"this",
"->",
"getMethodEndLine",
"(",
"$",
"file",
",",
"$",
"range",
")",
";",
"return",
"LineRange",
"::",
"fromLines",
"(",
"$",
"methodStartLine",
",",
"$",
"methodEndLine",
")",
";",
"}"
] | From a range within a method, find the start and end range of that method.
@param File $file
@param LineRange $range
@return LineRange | [
"From",
"a",
"range",
"within",
"a",
"method",
"find",
"the",
"start",
"and",
"end",
"range",
"of",
"that",
"method",
"."
] | train | https://github.com/QafooLabs/php-refactoring-browser/blob/3ff0f7bc955ec253ad7fa1bfaf44cc02604aaa1d/src/main/QafooLabs/Refactoring/Domain/Services/CodeAnalysis.php#L75-L81 |
lexxyungcarter/laravel-5-messenger | src/ChatMessengerServiceProvider.php | ChatMessengerServiceProvider.setMessengerModels | protected function setMessengerModels()
{
$config = $this->app->make('config');
Models::setMessageModel($config->get('chatmessenger.message_model', Message::class));
Models::setThreadModel($config->get('chatmessenger.thread_model', Thread::class));
Models::setParticipantModel($config->get('chatmessenger.participant_model', Participant::class));
Models::setTables([
'messages' => $config->get('chatmessenger.messages_table', Models::message()->getTable()),
'participants' => $config->get('chatmessenger.participants_table', Models::participant()->getTable()),
'threads' => $config->get('chatmessenger.threads_table', Models::thread()->getTable()),
]);
} | php | protected function setMessengerModels()
{
$config = $this->app->make('config');
Models::setMessageModel($config->get('chatmessenger.message_model', Message::class));
Models::setThreadModel($config->get('chatmessenger.thread_model', Thread::class));
Models::setParticipantModel($config->get('chatmessenger.participant_model', Participant::class));
Models::setTables([
'messages' => $config->get('chatmessenger.messages_table', Models::message()->getTable()),
'participants' => $config->get('chatmessenger.participants_table', Models::participant()->getTable()),
'threads' => $config->get('chatmessenger.threads_table', Models::thread()->getTable()),
]);
} | [
"protected",
"function",
"setMessengerModels",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'config'",
")",
";",
"Models",
"::",
"setMessageModel",
"(",
"$",
"config",
"->",
"get",
"(",
"'chatmessenger.message_model'",
",",
"Message",
"::",
"class",
")",
")",
";",
"Models",
"::",
"setThreadModel",
"(",
"$",
"config",
"->",
"get",
"(",
"'chatmessenger.thread_model'",
",",
"Thread",
"::",
"class",
")",
")",
";",
"Models",
"::",
"setParticipantModel",
"(",
"$",
"config",
"->",
"get",
"(",
"'chatmessenger.participant_model'",
",",
"Participant",
"::",
"class",
")",
")",
";",
"Models",
"::",
"setTables",
"(",
"[",
"'messages'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'chatmessenger.messages_table'",
",",
"Models",
"::",
"message",
"(",
")",
"->",
"getTable",
"(",
")",
")",
",",
"'participants'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'chatmessenger.participants_table'",
",",
"Models",
"::",
"participant",
"(",
")",
"->",
"getTable",
"(",
")",
")",
",",
"'threads'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'chatmessenger.threads_table'",
",",
"Models",
"::",
"thread",
"(",
")",
"->",
"getTable",
"(",
")",
")",
",",
"]",
")",
";",
"}"
] | Define Messenger's models in registry
@return void | [
"Define",
"Messenger",
"s",
"models",
"in",
"registry"
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/src/ChatMessengerServiceProvider.php#L74-L87 |
lexxyungcarter/laravel-5-messenger | src/ChatMessengerServiceProvider.php | ChatMessengerServiceProvider.setUserModel | protected function setUserModel()
{
$config = $this->app->make('config');
$model = $config->get('auth.providers.users.model', function () use ($config) {
return $config->get('auth.model', $config->get('chatmessenger.user_model'));
});
Models::setUserModel($model);
Models::setTables([
'users' => (new $model)->getTable(),
]);
} | php | protected function setUserModel()
{
$config = $this->app->make('config');
$model = $config->get('auth.providers.users.model', function () use ($config) {
return $config->get('auth.model', $config->get('chatmessenger.user_model'));
});
Models::setUserModel($model);
Models::setTables([
'users' => (new $model)->getTable(),
]);
} | [
"protected",
"function",
"setUserModel",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'config'",
")",
";",
"$",
"model",
"=",
"$",
"config",
"->",
"get",
"(",
"'auth.providers.users.model'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"$",
"config",
"->",
"get",
"(",
"'auth.model'",
",",
"$",
"config",
"->",
"get",
"(",
"'chatmessenger.user_model'",
")",
")",
";",
"}",
")",
";",
"Models",
"::",
"setUserModel",
"(",
"$",
"model",
")",
";",
"Models",
"::",
"setTables",
"(",
"[",
"'users'",
"=>",
"(",
"new",
"$",
"model",
")",
"->",
"getTable",
"(",
")",
",",
"]",
")",
";",
"}"
] | Define User model in Messenger's model registry.
@return void | [
"Define",
"User",
"model",
"in",
"Messenger",
"s",
"model",
"registry",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/src/ChatMessengerServiceProvider.php#L94-L107 |
lexxyungcarter/laravel-5-messenger | migrations/2017_11_08_063801_create_threads_table.php | CreateThreadsTable.up | public function up()
{
Schema::create(Models::table('threads'), function (Blueprint $table) {
$table->increments('id');
$table->boolean('starred')->default(0);
$table->string('subject');
$table->string('slug')->nullable()->comment('Unique slug for social media sharing. MD5 hashed string');
$table->integer('max_participants')->nullable()->comment('Max number of participants allowed');
$table->timestamp('start_date')->nullable();
$table->timestamp('end_date')->nullable();
$table->string('avatar')->nullable()->comment('Profile picture for the conversation');
$table->timestamps();
});
} | php | public function up()
{
Schema::create(Models::table('threads'), function (Blueprint $table) {
$table->increments('id');
$table->boolean('starred')->default(0);
$table->string('subject');
$table->string('slug')->nullable()->comment('Unique slug for social media sharing. MD5 hashed string');
$table->integer('max_participants')->nullable()->comment('Max number of participants allowed');
$table->timestamp('start_date')->nullable();
$table->timestamp('end_date')->nullable();
$table->string('avatar')->nullable()->comment('Profile picture for the conversation');
$table->timestamps();
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"create",
"(",
"Models",
"::",
"table",
"(",
"'threads'",
")",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"increments",
"(",
"'id'",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'starred'",
")",
"->",
"default",
"(",
"0",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'subject'",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'slug'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
"'Unique slug for social media sharing. MD5 hashed string'",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'max_participants'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
"'Max number of participants allowed'",
")",
";",
"$",
"table",
"->",
"timestamp",
"(",
"'start_date'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"timestamp",
"(",
"'end_date'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'avatar'",
")",
"->",
"nullable",
"(",
")",
"->",
"comment",
"(",
"'Profile picture for the conversation'",
")",
";",
"$",
"table",
"->",
"timestamps",
"(",
")",
";",
"}",
")",
";",
"}"
] | Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/migrations/2017_11_08_063801_create_threads_table.php#L15-L28 |
lexxyungcarter/laravel-5-messenger | src/Models/Thread.php | Thread.participantsUserIds | public function participantsUserIds($userId = null)
{
$users = $this->participants()->select('user_id')->get()->map(function ($participant) {
return $participant->user_id;
});
if ($userId) {
$users->push($userId);
}
return $users->toArray();
} | php | public function participantsUserIds($userId = null)
{
$users = $this->participants()->select('user_id')->get()->map(function ($participant) {
return $participant->user_id;
});
if ($userId) {
$users->push($userId);
}
return $users->toArray();
} | [
"public",
"function",
"participantsUserIds",
"(",
"$",
"userId",
"=",
"null",
")",
"{",
"$",
"users",
"=",
"$",
"this",
"->",
"participants",
"(",
")",
"->",
"select",
"(",
"'user_id'",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"participant",
")",
"{",
"return",
"$",
"participant",
"->",
"user_id",
";",
"}",
")",
";",
"if",
"(",
"$",
"userId",
")",
"{",
"$",
"users",
"->",
"push",
"(",
"$",
"userId",
")",
";",
"}",
"return",
"$",
"users",
"->",
"toArray",
"(",
")",
";",
"}"
] | Returns an array of user ids that are associated with the thread.
Deleted participants from a thread will not be returned
@param null $userId
@return array | [
"Returns",
"an",
"array",
"of",
"user",
"ids",
"that",
"are",
"associated",
"with",
"the",
"thread",
".",
"Deleted",
"participants",
"from",
"a",
"thread",
"will",
"not",
"be",
"returned"
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/src/Models/Thread.php#L143-L154 |
lexxyungcarter/laravel-5-messenger | src/Models/Thread.php | Thread.hasMaxParticipants | public function hasMaxParticipants()
{
$participants = $this->participants();
if ($participants->count() > $this->max_participants) {
// max number of participants reached
return true;
}
return false;
} | php | public function hasMaxParticipants()
{
$participants = $this->participants();
if ($participants->count() > $this->max_participants) {
// max number of participants reached
return true;
}
return false;
} | [
"public",
"function",
"hasMaxParticipants",
"(",
")",
"{",
"$",
"participants",
"=",
"$",
"this",
"->",
"participants",
"(",
")",
";",
"if",
"(",
"$",
"participants",
"->",
"count",
"(",
")",
">",
"$",
"this",
"->",
"max_participants",
")",
"{",
"// max number of participants reached",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the max number of participants in a thread has been reached.
@return boolean | [
"Checks",
"if",
"the",
"max",
"number",
"of",
"participants",
"in",
"a",
"thread",
"has",
"been",
"reached",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/src/Models/Thread.php#L466-L474 |
lexxyungcarter/laravel-5-messenger | examples/MessagesController.php | MessagesController.store | public function store()
{
$input = Input::all();
$thread = Thread::create([
'subject' => $input['subject'],
]);
// Message
$message = Message::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'body' => $input['message'],
]);
// Sender
Participant::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'last_read' => new Carbon,
]);
// Recipients
if (Input::has('recipients')) {
// add code logic here to check if a thread has max participants set
// utilize either $thread->getMaxParticipants() or $thread->hasMaxParticipants()
$thread->addParticipant($input['recipients']);
}
// check if pusher is allowed
if(config('chatmessenger.use_pusher')) {
$this->oooPushIt($message);
}
if(request()->ajax()) {
return response()->json([
'status' => 'OK',
'message' => $message,
'thread' => $thread,
]);
}
return redirect()->route('messages');
} | php | public function store()
{
$input = Input::all();
$thread = Thread::create([
'subject' => $input['subject'],
]);
// Message
$message = Message::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'body' => $input['message'],
]);
// Sender
Participant::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'last_read' => new Carbon,
]);
// Recipients
if (Input::has('recipients')) {
// add code logic here to check if a thread has max participants set
// utilize either $thread->getMaxParticipants() or $thread->hasMaxParticipants()
$thread->addParticipant($input['recipients']);
}
// check if pusher is allowed
if(config('chatmessenger.use_pusher')) {
$this->oooPushIt($message);
}
if(request()->ajax()) {
return response()->json([
'status' => 'OK',
'message' => $message,
'thread' => $thread,
]);
}
return redirect()->route('messages');
} | [
"public",
"function",
"store",
"(",
")",
"{",
"$",
"input",
"=",
"Input",
"::",
"all",
"(",
")",
";",
"$",
"thread",
"=",
"Thread",
"::",
"create",
"(",
"[",
"'subject'",
"=>",
"$",
"input",
"[",
"'subject'",
"]",
",",
"]",
")",
";",
"// Message",
"$",
"message",
"=",
"Message",
"::",
"create",
"(",
"[",
"'thread_id'",
"=>",
"$",
"thread",
"->",
"id",
",",
"'user_id'",
"=>",
"Auth",
"::",
"id",
"(",
")",
",",
"'body'",
"=>",
"$",
"input",
"[",
"'message'",
"]",
",",
"]",
")",
";",
"// Sender",
"Participant",
"::",
"create",
"(",
"[",
"'thread_id'",
"=>",
"$",
"thread",
"->",
"id",
",",
"'user_id'",
"=>",
"Auth",
"::",
"id",
"(",
")",
",",
"'last_read'",
"=>",
"new",
"Carbon",
",",
"]",
")",
";",
"// Recipients",
"if",
"(",
"Input",
"::",
"has",
"(",
"'recipients'",
")",
")",
"{",
"// add code logic here to check if a thread has max participants set",
"// utilize either $thread->getMaxParticipants() or $thread->hasMaxParticipants()",
"$",
"thread",
"->",
"addParticipant",
"(",
"$",
"input",
"[",
"'recipients'",
"]",
")",
";",
"}",
"// check if pusher is allowed",
"if",
"(",
"config",
"(",
"'chatmessenger.use_pusher'",
")",
")",
"{",
"$",
"this",
"->",
"oooPushIt",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"request",
"(",
")",
"->",
"ajax",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"'status'",
"=>",
"'OK'",
",",
"'message'",
"=>",
"$",
"message",
",",
"'thread'",
"=>",
"$",
"thread",
",",
"]",
")",
";",
"}",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'messages'",
")",
";",
"}"
] | Stores a new message thread.
@return mixed | [
"Stores",
"a",
"new",
"message",
"thread",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/examples/MessagesController.php#L90-L134 |
lexxyungcarter/laravel-5-messenger | examples/MessagesController.php | MessagesController.update | public function update($id)
{
try {
$thread = Thread::findOrFail($id);
} catch (ModelNotFoundException $e) {
Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
return redirect()->route('messages');
}
// Restore all participants within a thread that has a new message.
// we do not need it since when we remove a participant we do not wish the user to receive the message.
// uncomment in case you need to activate all thread participants
// $thread->activateAllParticipants();
// Message
$message = Message::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'body' => Input::get('message'),
]);
// Add replier as a participant
$participant = Participant::firstOrCreate([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
]);
$participant->last_read = new Carbon;
$participant->save();
// Recipients
if (Input::has('recipients')) {
// add code logic here to check if a thread has max participants set
// utilize either $thread->getMaxParticipants() or $thread->hasMaxParticipants()
$thread->addParticipant(Input::get('recipients'));
}
$html = view('messenger.partials.html-message', compact('message'))->render();
// check if pusher is allowed
if(config('chatmessenger.use_pusher')) {
$this->oooPushIt($message);
}
if(request()->ajax()) {
return response()->json([
'status' => 'OK',
'message' => $message,
'html' => $html,
'thread_subject' => $message->thread->subject,
]);
}
return redirect()->route('messages.show', $id);
} | php | public function update($id)
{
try {
$thread = Thread::findOrFail($id);
} catch (ModelNotFoundException $e) {
Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
return redirect()->route('messages');
}
// Restore all participants within a thread that has a new message.
// we do not need it since when we remove a participant we do not wish the user to receive the message.
// uncomment in case you need to activate all thread participants
// $thread->activateAllParticipants();
// Message
$message = Message::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'body' => Input::get('message'),
]);
// Add replier as a participant
$participant = Participant::firstOrCreate([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
]);
$participant->last_read = new Carbon;
$participant->save();
// Recipients
if (Input::has('recipients')) {
// add code logic here to check if a thread has max participants set
// utilize either $thread->getMaxParticipants() or $thread->hasMaxParticipants()
$thread->addParticipant(Input::get('recipients'));
}
$html = view('messenger.partials.html-message', compact('message'))->render();
// check if pusher is allowed
if(config('chatmessenger.use_pusher')) {
$this->oooPushIt($message);
}
if(request()->ajax()) {
return response()->json([
'status' => 'OK',
'message' => $message,
'html' => $html,
'thread_subject' => $message->thread->subject,
]);
}
return redirect()->route('messages.show', $id);
} | [
"public",
"function",
"update",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"thread",
"=",
"Thread",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"ModelNotFoundException",
"$",
"e",
")",
"{",
"Session",
"::",
"flash",
"(",
"'error_message'",
",",
"'The thread with ID: '",
".",
"$",
"id",
".",
"' was not found.'",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'messages'",
")",
";",
"}",
"// Restore all participants within a thread that has a new message.",
"// we do not need it since when we remove a participant we do not wish the user to receive the message.",
"// uncomment in case you need to activate all thread participants",
"// $thread->activateAllParticipants();",
"// Message",
"$",
"message",
"=",
"Message",
"::",
"create",
"(",
"[",
"'thread_id'",
"=>",
"$",
"thread",
"->",
"id",
",",
"'user_id'",
"=>",
"Auth",
"::",
"id",
"(",
")",
",",
"'body'",
"=>",
"Input",
"::",
"get",
"(",
"'message'",
")",
",",
"]",
")",
";",
"// Add replier as a participant",
"$",
"participant",
"=",
"Participant",
"::",
"firstOrCreate",
"(",
"[",
"'thread_id'",
"=>",
"$",
"thread",
"->",
"id",
",",
"'user_id'",
"=>",
"Auth",
"::",
"id",
"(",
")",
",",
"]",
")",
";",
"$",
"participant",
"->",
"last_read",
"=",
"new",
"Carbon",
";",
"$",
"participant",
"->",
"save",
"(",
")",
";",
"// Recipients",
"if",
"(",
"Input",
"::",
"has",
"(",
"'recipients'",
")",
")",
"{",
"// add code logic here to check if a thread has max participants set",
"// utilize either $thread->getMaxParticipants() or $thread->hasMaxParticipants()",
"$",
"thread",
"->",
"addParticipant",
"(",
"Input",
"::",
"get",
"(",
"'recipients'",
")",
")",
";",
"}",
"$",
"html",
"=",
"view",
"(",
"'messenger.partials.html-message'",
",",
"compact",
"(",
"'message'",
")",
")",
"->",
"render",
"(",
")",
";",
"// check if pusher is allowed",
"if",
"(",
"config",
"(",
"'chatmessenger.use_pusher'",
")",
")",
"{",
"$",
"this",
"->",
"oooPushIt",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"request",
"(",
")",
"->",
"ajax",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"'status'",
"=>",
"'OK'",
",",
"'message'",
"=>",
"$",
"message",
",",
"'html'",
"=>",
"$",
"html",
",",
"'thread_subject'",
"=>",
"$",
"message",
"->",
"thread",
"->",
"subject",
",",
"]",
")",
";",
"}",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'messages.show'",
",",
"$",
"id",
")",
";",
"}"
] | Adds a new message to a current thread.
@param $id
@return mixed | [
"Adds",
"a",
"new",
"message",
"to",
"a",
"current",
"thread",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/examples/MessagesController.php#L142-L197 |
lexxyungcarter/laravel-5-messenger | examples/MessagesController.php | MessagesController.oooPushIt | protected function oooPushIt(Message $message, $html = '')
{
$thread = $message->thread;
$sender = $message->user;
$data = [
'thread_id' => $thread->id,
'div_id' => 'thread_' . $thread->id,
'sender_name' => $sender->name,
'thread_url' => route('messages.show', ['id' => $thread->id]),
'thread_subject' => $thread->subject,
'message' => $message->body,
'html' => $html,
'text' => str_limit($message->body, 50),
];
$recipients = $thread->participantsUserIds();
if (count($recipients) > 0) {
foreach ($recipients as $recipient) {
if ($recipient == $sender->id) {
continue;
}
$pusher_resp = Pusher::trigger(['for_user_' . $recipient], 'new_message', $data);
// We're done here - how easy was that, it just works!
}
}
return $pusher_resp;
} | php | protected function oooPushIt(Message $message, $html = '')
{
$thread = $message->thread;
$sender = $message->user;
$data = [
'thread_id' => $thread->id,
'div_id' => 'thread_' . $thread->id,
'sender_name' => $sender->name,
'thread_url' => route('messages.show', ['id' => $thread->id]),
'thread_subject' => $thread->subject,
'message' => $message->body,
'html' => $html,
'text' => str_limit($message->body, 50),
];
$recipients = $thread->participantsUserIds();
if (count($recipients) > 0) {
foreach ($recipients as $recipient) {
if ($recipient == $sender->id) {
continue;
}
$pusher_resp = Pusher::trigger(['for_user_' . $recipient], 'new_message', $data);
// We're done here - how easy was that, it just works!
}
}
return $pusher_resp;
} | [
"protected",
"function",
"oooPushIt",
"(",
"Message",
"$",
"message",
",",
"$",
"html",
"=",
"''",
")",
"{",
"$",
"thread",
"=",
"$",
"message",
"->",
"thread",
";",
"$",
"sender",
"=",
"$",
"message",
"->",
"user",
";",
"$",
"data",
"=",
"[",
"'thread_id'",
"=>",
"$",
"thread",
"->",
"id",
",",
"'div_id'",
"=>",
"'thread_'",
".",
"$",
"thread",
"->",
"id",
",",
"'sender_name'",
"=>",
"$",
"sender",
"->",
"name",
",",
"'thread_url'",
"=>",
"route",
"(",
"'messages.show'",
",",
"[",
"'id'",
"=>",
"$",
"thread",
"->",
"id",
"]",
")",
",",
"'thread_subject'",
"=>",
"$",
"thread",
"->",
"subject",
",",
"'message'",
"=>",
"$",
"message",
"->",
"body",
",",
"'html'",
"=>",
"$",
"html",
",",
"'text'",
"=>",
"str_limit",
"(",
"$",
"message",
"->",
"body",
",",
"50",
")",
",",
"]",
";",
"$",
"recipients",
"=",
"$",
"thread",
"->",
"participantsUserIds",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"recipients",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"recipients",
"as",
"$",
"recipient",
")",
"{",
"if",
"(",
"$",
"recipient",
"==",
"$",
"sender",
"->",
"id",
")",
"{",
"continue",
";",
"}",
"$",
"pusher_resp",
"=",
"Pusher",
"::",
"trigger",
"(",
"[",
"'for_user_'",
".",
"$",
"recipient",
"]",
",",
"'new_message'",
",",
"$",
"data",
")",
";",
"// We're done here - how easy was that, it just works!",
"}",
"}",
"return",
"$",
"pusher_resp",
";",
"}"
] | Send the new message to Pusher in order to notify users.
@param Message $message | [
"Send",
"the",
"new",
"message",
"to",
"Pusher",
"in",
"order",
"to",
"notify",
"users",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/examples/MessagesController.php#L204-L233 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.