repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
soberwp/controller | src/Module/Acf.php | Acf.setDataReturnFormat | public function setDataReturnFormat()
{
if ($this->returnArrayFormat) {
return;
}
if ($this->data) {
foreach ($this->data as $key => $item) {
$this->data[$key] = json_decode(json_encode($item));
}
}
} | php | public function setDataReturnFormat()
{
if ($this->returnArrayFormat) {
return;
}
if ($this->data) {
foreach ($this->data as $key => $item) {
$this->data[$key] = json_decode(json_encode($item));
}
}
} | [
"public",
"function",
"setDataReturnFormat",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"returnArrayFormat",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"data",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
... | Set Data Return Format
Return object from array if acf/array filter is not set to true | [
"Set",
"Data",
"Return",
"Format"
] | 6b1e77991bfec1242d5d1d03db6f024981680c6e | https://github.com/soberwp/controller/blob/6b1e77991bfec1242d5d1d03db6f024981680c6e/src/Module/Acf.php#L40-L51 | train |
soberwp/controller | src/Blade/Coder.php | Coder.renderArrIndexed | private function renderArrIndexed($name, $val)
{
if ($this->codeif) {
// Echo if
echo "{$this->indentation}@if (\${$this->code}$name)<br>";
// Increase indentation
$this->increaseIndentation();
}
// Start foreach
echo "{$this->indentation}@foreach (\${$this->code}$name as \$item)<br>";
// Clear $this->code
$this->code = '';
// Increase indentation
$this->increaseIndentation();
// Route next value
foreach ($val as $key_index => $key_val) {
if (count($val) > 1) {
echo "{$this->indentation}<strong>[{$key_index}]</strong><br>";
}
$this->router('item', $key_val);
}
// Decrease indentation
$this->decreaseIndentation();
// End foreach
echo "{$this->indentation}@endforeach<br>";
if ($this->codeif) {
// Decrease indentation
$this->decreaseIndentation();
// Echo endif
echo "{$this->indentation}@endif<br>";
}
} | php | private function renderArrIndexed($name, $val)
{
if ($this->codeif) {
// Echo if
echo "{$this->indentation}@if (\${$this->code}$name)<br>";
// Increase indentation
$this->increaseIndentation();
}
// Start foreach
echo "{$this->indentation}@foreach (\${$this->code}$name as \$item)<br>";
// Clear $this->code
$this->code = '';
// Increase indentation
$this->increaseIndentation();
// Route next value
foreach ($val as $key_index => $key_val) {
if (count($val) > 1) {
echo "{$this->indentation}<strong>[{$key_index}]</strong><br>";
}
$this->router('item', $key_val);
}
// Decrease indentation
$this->decreaseIndentation();
// End foreach
echo "{$this->indentation}@endforeach<br>";
if ($this->codeif) {
// Decrease indentation
$this->decreaseIndentation();
// Echo endif
echo "{$this->indentation}@endif<br>";
}
} | [
"private",
"function",
"renderArrIndexed",
"(",
"$",
"name",
",",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"codeif",
")",
"{",
"// Echo if",
"echo",
"\"{$this->indentation}@if (\\${$this->code}$name)<br>\"",
";",
"// Increase indentation",
"$",
"this",
... | Render Indexed Array
Render an indexed array | [
"Render",
"Indexed",
"Array"
] | 6b1e77991bfec1242d5d1d03db6f024981680c6e | https://github.com/soberwp/controller/blob/6b1e77991bfec1242d5d1d03db6f024981680c6e/src/Blade/Coder.php#L167-L207 | train |
soberwp/controller | src/Blade/Coder.php | Coder.renderArrKeys | private function renderArrKeys($name, $val)
{
// Foreach value add key
foreach ($val as $key_name => $key_val) {
$this->router("{$this->code}{$name}['{$key_name}']", $key_val);
}
} | php | private function renderArrKeys($name, $val)
{
// Foreach value add key
foreach ($val as $key_name => $key_val) {
$this->router("{$this->code}{$name}['{$key_name}']", $key_val);
}
} | [
"private",
"function",
"renderArrKeys",
"(",
"$",
"name",
",",
"$",
"val",
")",
"{",
"// Foreach value add key",
"foreach",
"(",
"$",
"val",
"as",
"$",
"key_name",
"=>",
"$",
"key_val",
")",
"{",
"$",
"this",
"->",
"router",
"(",
"\"{$this->code}{$name}['{$k... | Render Array Keys
Render an array with keys | [
"Render",
"Array",
"Keys"
] | 6b1e77991bfec1242d5d1d03db6f024981680c6e | https://github.com/soberwp/controller/blob/6b1e77991bfec1242d5d1d03db6f024981680c6e/src/Blade/Coder.php#L214-L220 | train |
giansalex/peru-consult | src/Peru/Http/ContextClient.php | ContextClient.post | public function post(string $url, $data, array $headers = [])
{
if (is_array($data)) {
$headers['Content-type'] = self::FORM_CONTENT_TYPE;
}
$ctx = $this->getContext('POST', $data, $headers);
$response = file_get_contents($url, false, $ctx);
$this->saveCookies($http_response_header);
return $response;
} | php | public function post(string $url, $data, array $headers = [])
{
if (is_array($data)) {
$headers['Content-type'] = self::FORM_CONTENT_TYPE;
}
$ctx = $this->getContext('POST', $data, $headers);
$response = file_get_contents($url, false, $ctx);
$this->saveCookies($http_response_header);
return $response;
} | [
"public",
"function",
"post",
"(",
"string",
"$",
"url",
",",
"$",
"data",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"headers",
"[",
"'Content-type'",
"]",
"=",
"self",
"::... | Post Request.
@param string $url
@param mixed $data
@param array $headers
@return string|false | [
"Post",
"Request",
"."
] | fcbda130fd99d664dd9e6fc26fb890e5f2d20304 | https://github.com/giansalex/peru-consult/blob/fcbda130fd99d664dd9e6fc26fb890e5f2d20304/src/Peru/Http/ContextClient.php#L59-L70 | train |
giansalex/peru-consult | src/Peru/Reniec/Dni.php | Dni.getCaptchaImage | private function getCaptchaImage()
{
$image = $this->client->get(self::URL_CAPTCHA);
if (false === $image) {
$this->error = 'No se pudo cargar el captcha image';
return false;
}
return $image;
} | php | private function getCaptchaImage()
{
$image = $this->client->get(self::URL_CAPTCHA);
if (false === $image) {
$this->error = 'No se pudo cargar el captcha image';
return false;
}
return $image;
} | [
"private",
"function",
"getCaptchaImage",
"(",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
"self",
"::",
"URL_CAPTCHA",
")",
";",
"if",
"(",
"false",
"===",
"$",
"image",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"'... | Get Captcha image.
@return bool|mixed | [
"Get",
"Captcha",
"image",
"."
] | fcbda130fd99d664dd9e6fc26fb890e5f2d20304 | https://github.com/giansalex/peru-consult/blob/fcbda130fd99d664dd9e6fc26fb890e5f2d20304/src/Peru/Reniec/Dni.php#L140-L151 | train |
giansalex/peru-consult | src/Peru/Reniec/Dni.php | Dni.getCatpchaValue | private function getCatpchaValue()
{
$captcha = $this->getCaptchaImage();
if (false === $captcha) {
return false;
}
$image = @imagecreatefromstring($captcha);
if (!$image) {
$this->error = 'No se pudo crear imagen desde el captcha';
return false;
}
return $this->getValueCaptchaFromImage($image);
} | php | private function getCatpchaValue()
{
$captcha = $this->getCaptchaImage();
if (false === $captcha) {
return false;
}
$image = @imagecreatefromstring($captcha);
if (!$image) {
$this->error = 'No se pudo crear imagen desde el captcha';
return false;
}
return $this->getValueCaptchaFromImage($image);
} | [
"private",
"function",
"getCatpchaValue",
"(",
")",
"{",
"$",
"captcha",
"=",
"$",
"this",
"->",
"getCaptchaImage",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"captcha",
")",
"{",
"return",
"false",
";",
"}",
"$",
"image",
"=",
"@",
"imagecreatefro... | Get Captcha from String.
@return bool|string | [
"Get",
"Captcha",
"from",
"String",
"."
] | fcbda130fd99d664dd9e6fc26fb890e5f2d20304 | https://github.com/giansalex/peru-consult/blob/fcbda130fd99d664dd9e6fc26fb890e5f2d20304/src/Peru/Reniec/Dni.php#L158-L174 | train |
giansalex/peru-consult | src/Peru/Reniec/Dni.php | Dni.getText | private function getText($image)
{
$rtn = '';
$w = imagesx($image);
$h = imagesy($image);
for ($y = 0; $y < $h; ++$y) {
for ($x = 0; $x < $w; ++$x) {
$rgb = imagecolorat($image, $x, $y);
$rtn .= $this->getDotFromRgb($rgb);
}
}
return $rtn;
} | php | private function getText($image)
{
$rtn = '';
$w = imagesx($image);
$h = imagesy($image);
for ($y = 0; $y < $h; ++$y) {
for ($x = 0; $x < $w; ++$x) {
$rgb = imagecolorat($image, $x, $y);
$rtn .= $this->getDotFromRgb($rgb);
}
}
return $rtn;
} | [
"private",
"function",
"getText",
"(",
"$",
"image",
")",
"{",
"$",
"rtn",
"=",
"''",
";",
"$",
"w",
"=",
"imagesx",
"(",
"$",
"image",
")",
";",
"$",
"h",
"=",
"imagesy",
"(",
"$",
"image",
")",
";",
"for",
"(",
"$",
"y",
"=",
"0",
";",
"$... | Retorna 1 o 0.
@param $image
@return string | [
"Retorna",
"1",
"o",
"0",
"."
] | fcbda130fd99d664dd9e6fc26fb890e5f2d20304 | https://github.com/giansalex/peru-consult/blob/fcbda130fd99d664dd9e6fc26fb890e5f2d20304/src/Peru/Reniec/Dni.php#L207-L220 | train |
giansalex/peru-consult | src/Peru/Reniec/CaptchaCodes.php | CaptchaCodes.getLetter | public function getLetter($data, $position)
{
foreach ($this->codes as $code) {
if ($code[$position] == $data) {
return $code[0];
}
}
return null;
} | php | public function getLetter($data, $position)
{
foreach ($this->codes as $code) {
if ($code[$position] == $data) {
return $code[0];
}
}
return null;
} | [
"public",
"function",
"getLetter",
"(",
"$",
"data",
",",
"$",
"position",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"codes",
"as",
"$",
"code",
")",
"{",
"if",
"(",
"$",
"code",
"[",
"$",
"position",
"]",
"==",
"$",
"data",
")",
"{",
"return"... | Get letter.
@param $data
@param int $position
@return string|null | [
"Get",
"letter",
"."
] | fcbda130fd99d664dd9e6fc26fb890e5f2d20304 | https://github.com/giansalex/peru-consult/blob/fcbda130fd99d664dd9e6fc26fb890e5f2d20304/src/Peru/Reniec/CaptchaCodes.php#L57-L66 | train |
giansalex/peru-consult | src/Peru/Sunat/HtmlParser.php | HtmlParser.parse | public function parse($html)
{
$xp = $this->getXpathFromHtml($html);
$table = $xp->query('./html/body/table[1]');
if (0 == $table->length) {
return false;
}
$nodes = $table->item(0)->childNodes;
$dic = $this->getKeyValues($nodes, $xp);
return $dic;
} | php | public function parse($html)
{
$xp = $this->getXpathFromHtml($html);
$table = $xp->query('./html/body/table[1]');
if (0 == $table->length) {
return false;
}
$nodes = $table->item(0)->childNodes;
$dic = $this->getKeyValues($nodes, $xp);
return $dic;
} | [
"public",
"function",
"parse",
"(",
"$",
"html",
")",
"{",
"$",
"xp",
"=",
"$",
"this",
"->",
"getXpathFromHtml",
"(",
"$",
"html",
")",
";",
"$",
"table",
"=",
"$",
"xp",
"->",
"query",
"(",
"'./html/body/table[1]'",
")",
";",
"if",
"(",
"0",
"=="... | Parse html to dictionary.
@param $html
@return array|false | [
"Parse",
"html",
"to",
"dictionary",
"."
] | fcbda130fd99d664dd9e6fc26fb890e5f2d20304 | https://github.com/giansalex/peru-consult/blob/fcbda130fd99d664dd9e6fc26fb890e5f2d20304/src/Peru/Sunat/HtmlParser.php#L23-L36 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.resetInternal | protected function resetInternal()
{
$this->xmlDocument = new DOMDocument();
$this->xmlDocument->preserveWhiteSpace = false;
$this->xmlDocument->strictErrorChecking = false;
$this->xmlDocument->formatOutput = !$this->minifyXML;
} | php | protected function resetInternal()
{
$this->xmlDocument = new DOMDocument();
$this->xmlDocument->preserveWhiteSpace = false;
$this->xmlDocument->strictErrorChecking = false;
$this->xmlDocument->formatOutput = !$this->minifyXML;
} | [
"protected",
"function",
"resetInternal",
"(",
")",
"{",
"$",
"this",
"->",
"xmlDocument",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"this",
"->",
"xmlDocument",
"->",
"preserveWhiteSpace",
"=",
"false",
";",
"$",
"this",
"->",
"xmlDocument",
"->",
"s... | Set up the DOMDocument | [
"Set",
"up",
"the",
"DOMDocument"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L82-L88 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.sanitize | public function sanitize($dirty)
{
// Don't run on an empty string
if (empty($dirty)) {
return '';
}
// Strip php tags
$dirty = preg_replace('/<\?(=|php)(.+?)\?>/i', '', $dirty);
$this->resetInternal();
$this->setUpBefore();
$loaded = $this->xmlDocument->loadXML($dirty);
// If we couldn't parse the XML then we go no further. Reset and return false
if (!$loaded) {
$this->resetAfter();
return false;
}
$this->removeDoctype();
// Grab all the elements
$allElements = $this->xmlDocument->getElementsByTagName("*");
// Start the cleaning proccess
$this->startClean($allElements);
// Save cleaned XML to a variable
if ($this->removeXMLTag) {
$clean = $this->xmlDocument->saveXML($this->xmlDocument->documentElement, $this->xmlOptions);
} else {
$clean = $this->xmlDocument->saveXML($this->xmlDocument, $this->xmlOptions);
}
$this->resetAfter();
// Remove any extra whitespaces when minifying
if ($this->minifyXML) {
$clean = preg_replace('/\s+/', ' ', $clean);
}
// Return result
return $clean;
} | php | public function sanitize($dirty)
{
// Don't run on an empty string
if (empty($dirty)) {
return '';
}
// Strip php tags
$dirty = preg_replace('/<\?(=|php)(.+?)\?>/i', '', $dirty);
$this->resetInternal();
$this->setUpBefore();
$loaded = $this->xmlDocument->loadXML($dirty);
// If we couldn't parse the XML then we go no further. Reset and return false
if (!$loaded) {
$this->resetAfter();
return false;
}
$this->removeDoctype();
// Grab all the elements
$allElements = $this->xmlDocument->getElementsByTagName("*");
// Start the cleaning proccess
$this->startClean($allElements);
// Save cleaned XML to a variable
if ($this->removeXMLTag) {
$clean = $this->xmlDocument->saveXML($this->xmlDocument->documentElement, $this->xmlOptions);
} else {
$clean = $this->xmlDocument->saveXML($this->xmlDocument, $this->xmlOptions);
}
$this->resetAfter();
// Remove any extra whitespaces when minifying
if ($this->minifyXML) {
$clean = preg_replace('/\s+/', ' ', $clean);
}
// Return result
return $clean;
} | [
"public",
"function",
"sanitize",
"(",
"$",
"dirty",
")",
"{",
"// Don't run on an empty string",
"if",
"(",
"empty",
"(",
"$",
"dirty",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Strip php tags",
"$",
"dirty",
"=",
"preg_replace",
"(",
"'/<\\?(=|php)(.+?)\\... | Sanitize the passed string
@param string $dirty
@return string | [
"Sanitize",
"the",
"passed",
"string"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L178-L223 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.removeDoctype | protected function removeDoctype()
{
foreach ($this->xmlDocument->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
$child->parentNode->removeChild($child);
}
}
} | php | protected function removeDoctype()
{
foreach ($this->xmlDocument->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
$child->parentNode->removeChild($child);
}
}
} | [
"protected",
"function",
"removeDoctype",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"xmlDocument",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"nodeType",
"===",
"XML_DOCUMENT_TYPE_NODE",
")",
"{",
"$",
"child",... | Remove the XML Doctype
It may be caught later on output but that seems to be buggy, so we need to make sure it's gone | [
"Remove",
"the",
"XML",
"Doctype",
"It",
"may",
"be",
"caught",
"later",
"on",
"output",
"but",
"that",
"seems",
"to",
"be",
"buggy",
"so",
"we",
"need",
"to",
"make",
"sure",
"it",
"s",
"gone"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L253-L260 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.startClean | protected function startClean(\DOMNodeList $elements)
{
// loop through all elements
// we do this backwards so we don't skip anything if we delete a node
// see comments at: http://php.net/manual/en/class.domnamednodemap.php
for ($i = $elements->length - 1; $i >= 0; $i--) {
$currentElement = $elements->item($i);
// If the tag isn't in the whitelist, remove it and continue with next iteration
if (!in_array(strtolower($currentElement->tagName), $this->allowedTags)) {
$currentElement->parentNode->removeChild($currentElement);
$this->xmlIssues[] = array(
'message' => 'Suspicious tag \'' . $currentElement->tagName . '\'',
'line' => $currentElement->getLineNo(),
);
continue;
}
$this->cleanAttributesOnWhitelist($currentElement);
$this->cleanXlinkHrefs($currentElement);
$this->cleanHrefs($currentElement);
if (strtolower($currentElement->tagName) === 'use') {
if ($this->isUseTagDirty($currentElement)) {
$currentElement->parentNode->removeChild($currentElement);
$this->xmlIssues[] = array(
'message' => 'Suspicious \'' . $currentElement->tagName . '\'',
'line' => $currentElement->getLineNo(),
);
continue;
}
}
}
} | php | protected function startClean(\DOMNodeList $elements)
{
// loop through all elements
// we do this backwards so we don't skip anything if we delete a node
// see comments at: http://php.net/manual/en/class.domnamednodemap.php
for ($i = $elements->length - 1; $i >= 0; $i--) {
$currentElement = $elements->item($i);
// If the tag isn't in the whitelist, remove it and continue with next iteration
if (!in_array(strtolower($currentElement->tagName), $this->allowedTags)) {
$currentElement->parentNode->removeChild($currentElement);
$this->xmlIssues[] = array(
'message' => 'Suspicious tag \'' . $currentElement->tagName . '\'',
'line' => $currentElement->getLineNo(),
);
continue;
}
$this->cleanAttributesOnWhitelist($currentElement);
$this->cleanXlinkHrefs($currentElement);
$this->cleanHrefs($currentElement);
if (strtolower($currentElement->tagName) === 'use') {
if ($this->isUseTagDirty($currentElement)) {
$currentElement->parentNode->removeChild($currentElement);
$this->xmlIssues[] = array(
'message' => 'Suspicious \'' . $currentElement->tagName . '\'',
'line' => $currentElement->getLineNo(),
);
continue;
}
}
}
} | [
"protected",
"function",
"startClean",
"(",
"\\",
"DOMNodeList",
"$",
"elements",
")",
"{",
"// loop through all elements",
"// we do this backwards so we don't skip anything if we delete a node",
"// see comments at: http://php.net/manual/en/class.domnamednodemap.php",
"for",
"(",
"$"... | Start the cleaning with tags, then we move onto attributes and hrefs later
@param \DOMNodeList $elements | [
"Start",
"the",
"cleaning",
"with",
"tags",
"then",
"we",
"move",
"onto",
"attributes",
"and",
"hrefs",
"later"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L267-L302 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.cleanAttributesOnWhitelist | protected function cleanAttributesOnWhitelist(\DOMElement $element)
{
for ($x = $element->attributes->length - 1; $x >= 0; $x--) {
// get attribute name
$attrName = $element->attributes->item($x)->name;
// Remove attribute if not in whitelist
if (!in_array(strtolower($attrName), $this->allowedAttrs) && !$this->isAriaAttribute(strtolower($attrName)) && !$this->isDataAttribute(strtolower($attrName))) {
$element->removeAttribute($attrName);
$this->xmlIssues[] = array(
'message' => 'Suspicious attribute \'' . $attrName . '\'',
'line' => $element->getLineNo(),
);
}
// Do we want to strip remote references?
if($this->removeRemoteReferences) {
// Remove attribute if it has a remote reference
if (isset($element->attributes->item($x)->value) && $this->hasRemoteReference($element->attributes->item($x)->value)) {
$element->removeAttribute($attrName);
$this->xmlIssues[] = array(
'message' => 'Suspicious attribute \'' . $attrName . '\'',
'line' => $element->getLineNo(),
);
}
}
}
} | php | protected function cleanAttributesOnWhitelist(\DOMElement $element)
{
for ($x = $element->attributes->length - 1; $x >= 0; $x--) {
// get attribute name
$attrName = $element->attributes->item($x)->name;
// Remove attribute if not in whitelist
if (!in_array(strtolower($attrName), $this->allowedAttrs) && !$this->isAriaAttribute(strtolower($attrName)) && !$this->isDataAttribute(strtolower($attrName))) {
$element->removeAttribute($attrName);
$this->xmlIssues[] = array(
'message' => 'Suspicious attribute \'' . $attrName . '\'',
'line' => $element->getLineNo(),
);
}
// Do we want to strip remote references?
if($this->removeRemoteReferences) {
// Remove attribute if it has a remote reference
if (isset($element->attributes->item($x)->value) && $this->hasRemoteReference($element->attributes->item($x)->value)) {
$element->removeAttribute($attrName);
$this->xmlIssues[] = array(
'message' => 'Suspicious attribute \'' . $attrName . '\'',
'line' => $element->getLineNo(),
);
}
}
}
} | [
"protected",
"function",
"cleanAttributesOnWhitelist",
"(",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"for",
"(",
"$",
"x",
"=",
"$",
"element",
"->",
"attributes",
"->",
"length",
"-",
"1",
";",
"$",
"x",
">=",
"0",
";",
"$",
"x",
"--",
")",
"{"... | Only allow attributes that are on the whitelist
@param \DOMElement $element | [
"Only",
"allow",
"attributes",
"that",
"are",
"on",
"the",
"whitelist"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L309-L337 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.cleanHrefs | protected function cleanHrefs(\DOMElement $element)
{
$href = $element->getAttribute('href');
if (preg_match(self::SCRIPT_REGEX, $href) === 1) {
$element->removeAttribute('href');
$this->xmlIssues[] = array(
'message' => 'Suspicious attribute \'href\'',
'line' => $element->getLineNo(),
);
}
} | php | protected function cleanHrefs(\DOMElement $element)
{
$href = $element->getAttribute('href');
if (preg_match(self::SCRIPT_REGEX, $href) === 1) {
$element->removeAttribute('href');
$this->xmlIssues[] = array(
'message' => 'Suspicious attribute \'href\'',
'line' => $element->getLineNo(),
);
}
} | [
"protected",
"function",
"cleanHrefs",
"(",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"href",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"'href'",
")",
";",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"SCRIPT_REGEX",
",",
"$",
"href",
")",
... | Clean the hrefs of script and data embeds
@param \DOMElement $element | [
"Clean",
"the",
"hrefs",
"of",
"script",
"and",
"data",
"embeds"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L371-L381 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.hasRemoteReference | protected function hasRemoteReference($value)
{
$value = $this->removeNonPrintableCharacters($value);
$wrapped_in_url = preg_match('~^url\(\s*[\'"]\s*(.*)\s*[\'"]\s*\)$~xi', $value, $match);
if (!$wrapped_in_url){
return false;
}
$value = trim($match[1], '\'"');
return preg_match('~^((https?|ftp|file):)?//~xi', $value);
} | php | protected function hasRemoteReference($value)
{
$value = $this->removeNonPrintableCharacters($value);
$wrapped_in_url = preg_match('~^url\(\s*[\'"]\s*(.*)\s*[\'"]\s*\)$~xi', $value, $match);
if (!$wrapped_in_url){
return false;
}
$value = trim($match[1], '\'"');
return preg_match('~^((https?|ftp|file):)?//~xi', $value);
} | [
"protected",
"function",
"hasRemoteReference",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"removeNonPrintableCharacters",
"(",
"$",
"value",
")",
";",
"$",
"wrapped_in_url",
"=",
"preg_match",
"(",
"'~^url\\(\\s*[\\'\"]\\s*(.*)\\s*[\\'\"]\\s*... | Does this attribute value have a remote reference?
@param $value
@return bool | [
"Does",
"this",
"attribute",
"value",
"have",
"a",
"remote",
"reference?"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L400-L412 | train |
darylldoyle/svg-sanitizer | src/Sanitizer.php | Sanitizer.isUseTagDirty | protected function isUseTagDirty(\DOMElement $element)
{
$xlinks = $element->getAttributeNS('http://www.w3.org/1999/xlink', 'href');
if ($xlinks && substr($xlinks, 0, 1) !== '#') {
return true;
}
return false;
} | php | protected function isUseTagDirty(\DOMElement $element)
{
$xlinks = $element->getAttributeNS('http://www.w3.org/1999/xlink', 'href');
if ($xlinks && substr($xlinks, 0, 1) !== '#') {
return true;
}
return false;
} | [
"protected",
"function",
"isUseTagDirty",
"(",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"xlinks",
"=",
"$",
"element",
"->",
"getAttributeNS",
"(",
"'http://www.w3.org/1999/xlink'",
",",
"'href'",
")",
";",
"if",
"(",
"$",
"xlinks",
"&&",
"substr",
... | Make sure our use tag is only referencing internal resources
@param \DOMElement $element
@return bool | [
"Make",
"sure",
"our",
"use",
"tag",
"is",
"only",
"referencing",
"internal",
"resources"
] | 5344d8511e494adf160f71f4b34024d3a3c66c82 | https://github.com/darylldoyle/svg-sanitizer/blob/5344d8511e494adf160f71f4b34024d3a3c66c82/src/Sanitizer.php#L464-L472 | train |
toin0u/DigitalOceanV2 | src/Api/Volume.php | Volume.snapshot | public function snapshot($id, $name)
{
$data = [
'name' => $name,
];
$snapshot = $this->adapter->post(sprintf('%s/volumes/%s/snapshots', $this->endpoint, $id), $data);
$snapshot = json_decode($snapshot);
return new SnapshotEntity($snapshot->snapshot);
} | php | public function snapshot($id, $name)
{
$data = [
'name' => $name,
];
$snapshot = $this->adapter->post(sprintf('%s/volumes/%s/snapshots', $this->endpoint, $id), $data);
$snapshot = json_decode($snapshot);
return new SnapshotEntity($snapshot->snapshot);
} | [
"public",
"function",
"snapshot",
"(",
"$",
"id",
",",
"$",
"name",
")",
"{",
"$",
"data",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"]",
";",
"$",
"snapshot",
"=",
"$",
"this",
"->",
"adapter",
"->",
"post",
"(",
"sprintf",
"(",
"'%s/volumes/%s/... | Create a new snapshot of the volume.
@param string $id the id of the volume
@param string $name a human-readable name for the volume snapshot
@throws HttpException
@return SnapshotEntity | [
"Create",
"a",
"new",
"snapshot",
"of",
"the",
"volume",
"."
] | aa3fbe5efba26632665230829aef5ada4fa415cb | https://github.com/toin0u/DigitalOceanV2/blob/aa3fbe5efba26632665230829aef5ada4fa415cb/src/Api/Volume.php#L223-L234 | train |
ARCANEDEV/SEO-Helper | src/Entities/Title.php | Title.checkTitle | private function checkTitle(&$title)
{
if ( ! is_string($title)) {
$type = gettype($title);
throw new InvalidArgumentException("The title must be a string value, [$type] is given.");
}
$title = trim($title);
if (empty($title)) {
throw new InvalidArgumentException('The title is required and must not be empty.');
}
} | php | private function checkTitle(&$title)
{
if ( ! is_string($title)) {
$type = gettype($title);
throw new InvalidArgumentException("The title must be a string value, [$type] is given.");
}
$title = trim($title);
if (empty($title)) {
throw new InvalidArgumentException('The title is required and must not be empty.');
}
} | [
"private",
"function",
"checkTitle",
"(",
"&",
"$",
"title",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"title",
")",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"title",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The titl... | Check title.
@param string $title
@throws \Arcanedev\SeoHelper\Exceptions\InvalidArgumentException | [
"Check",
"title",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Title.php#L368-L381 | train |
ARCANEDEV/SEO-Helper | src/Entities/Title.php | Title.renderTitleFirst | private function renderTitleFirst($separator)
{
$output = [];
$output[] = $this->getTitleOnly();
if ($this->hasSiteName()) {
$output[] = $separator;
$output[] = $this->getSiteName();
}
return implode('', $output);
} | php | private function renderTitleFirst($separator)
{
$output = [];
$output[] = $this->getTitleOnly();
if ($this->hasSiteName()) {
$output[] = $separator;
$output[] = $this->getSiteName();
}
return implode('', $output);
} | [
"private",
"function",
"renderTitleFirst",
"(",
"$",
"separator",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"getTitleOnly",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasSiteName",
"(",
")",
")... | Render title first.
@param string $separator
@return string | [
"Render",
"title",
"first",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Title.php#L413-L424 | train |
ARCANEDEV/SEO-Helper | src/Entities/Title.php | Title.renderTitleLast | private function renderTitleLast($separator)
{
$output = [];
if ($this->hasSiteName()) {
$output[] = $this->getSiteName();
$output[] = $separator;
}
$output[] = $this->getTitleOnly();
return implode('', $output);
} | php | private function renderTitleLast($separator)
{
$output = [];
if ($this->hasSiteName()) {
$output[] = $this->getSiteName();
$output[] = $separator;
}
$output[] = $this->getTitleOnly();
return implode('', $output);
} | [
"private",
"function",
"renderTitleLast",
"(",
"$",
"separator",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"hasSiteName",
"(",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"getSiteName",
"(",
")",... | Render title last.
@param string $separator
@return string | [
"Render",
"title",
"last",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Title.php#L433-L445 | train |
ARCANEDEV/SEO-Helper | src/Entities/Title.php | Title.prepareTitleOutput | private function prepareTitleOutput($output)
{
return htmlspecialchars(
Str::limit(strip_tags($output), $this->getMax()), ENT_QUOTES, 'UTF-8', false
);
} | php | private function prepareTitleOutput($output)
{
return htmlspecialchars(
Str::limit(strip_tags($output), $this->getMax()), ENT_QUOTES, 'UTF-8', false
);
} | [
"private",
"function",
"prepareTitleOutput",
"(",
"$",
"output",
")",
"{",
"return",
"htmlspecialchars",
"(",
"Str",
"::",
"limit",
"(",
"strip_tags",
"(",
"$",
"output",
")",
",",
"$",
"this",
"->",
"getMax",
"(",
")",
")",
",",
"ENT_QUOTES",
",",
"'UTF... | Prepare the title output.
@param string $output
@return string | [
"Prepare",
"the",
"title",
"output",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Title.php#L454-L459 | train |
ARCANEDEV/SEO-Helper | src/SeoHelper.php | SeoHelper.setSiteName | public function setSiteName($siteName)
{
$this->meta()->setSiteName($siteName);
$this->openGraph()->setSiteName($siteName);
return $this;
} | php | public function setSiteName($siteName)
{
$this->meta()->setSiteName($siteName);
$this->openGraph()->setSiteName($siteName);
return $this;
} | [
"public",
"function",
"setSiteName",
"(",
"$",
"siteName",
")",
"{",
"$",
"this",
"->",
"meta",
"(",
")",
"->",
"setSiteName",
"(",
"$",
"siteName",
")",
";",
"$",
"this",
"->",
"openGraph",
"(",
")",
"->",
"setSiteName",
"(",
"$",
"siteName",
")",
"... | Set the site name.
@param string $siteName
@return self | [
"Set",
"the",
"site",
"name",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/SeoHelper.php#L179-L185 | train |
ARCANEDEV/SEO-Helper | src/SeoHelper.php | SeoHelper.setDescription | public function setDescription($description)
{
$this->meta()->setDescription($description);
$this->openGraph()->setDescription($description);
$this->twitter()->setDescription($description);
return $this;
} | php | public function setDescription($description)
{
$this->meta()->setDescription($description);
$this->openGraph()->setDescription($description);
$this->twitter()->setDescription($description);
return $this;
} | [
"public",
"function",
"setDescription",
"(",
"$",
"description",
")",
"{",
"$",
"this",
"->",
"meta",
"(",
")",
"->",
"setDescription",
"(",
"$",
"description",
")",
";",
"$",
"this",
"->",
"openGraph",
"(",
")",
"->",
"setDescription",
"(",
"$",
"descri... | Set description.
@param string $description
@return \Arcanedev\SeoHelper\Contracts\SeoHelper | [
"Set",
"description",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/SeoHelper.php#L218-L225 | train |
ARCANEDEV/SEO-Helper | src/SeoHelper.php | SeoHelper.setImage | public function setImage($imageUrl)
{
$this->openGraph()->setImage($imageUrl);
$this->twitter()->addImage($imageUrl);
return $this;
} | php | public function setImage($imageUrl)
{
$this->openGraph()->setImage($imageUrl);
$this->twitter()->addImage($imageUrl);
return $this;
} | [
"public",
"function",
"setImage",
"(",
"$",
"imageUrl",
")",
"{",
"$",
"this",
"->",
"openGraph",
"(",
")",
"->",
"setImage",
"(",
"$",
"imageUrl",
")",
";",
"$",
"this",
"->",
"twitter",
"(",
")",
"->",
"addImage",
"(",
"$",
"imageUrl",
")",
";",
... | Set Image.
@param string $imageUrl
@return \Arcanedev\SeoHelper\SeoHelper | [
"Set",
"Image",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/SeoHelper.php#L248-L254 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.getName | private function getName($prefixed = true)
{
return $this->clean(
$prefixed ? $this->prefix.$this->name : $this->name
);
} | php | private function getName($prefixed = true)
{
return $this->clean(
$prefixed ? $this->prefix.$this->name : $this->name
);
} | [
"private",
"function",
"getName",
"(",
"$",
"prefixed",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"clean",
"(",
"$",
"prefixed",
"?",
"$",
"this",
"->",
"prefix",
".",
"$",
"this",
"->",
"name",
":",
"$",
"this",
"->",
"name",
")",
";",
... | Get the meta name.
@param bool $prefixed
@return string | [
"Get",
"the",
"meta",
"name",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L123-L128 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.setName | private function setName($name)
{
$name = trim(strip_tags($name));
$this->name = str_replace([' '], '-', $name);
return $this;
} | php | private function setName($name)
{
$name = trim(strip_tags($name));
$this->name = str_replace([' '], '-', $name);
return $this;
} | [
"private",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"strip_tags",
"(",
"$",
"name",
")",
")",
";",
"$",
"this",
"->",
"name",
"=",
"str_replace",
"(",
"[",
"' '",
"]",
",",
"'-'",
",",
"$",
"name",
")",
... | Set the meta name.
@param string $name
@return \Arcanedev\SeoHelper\Helpers\Meta | [
"Set",
"the",
"meta",
"name",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L137-L143 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.getContent | private function getContent()
{
return is_array($this->content)
? array_map(function ($content) { return $this->clean($content); }, $this->content)
: $this->clean($this->content);
} | php | private function getContent()
{
return is_array($this->content)
? array_map(function ($content) { return $this->clean($content); }, $this->content)
: $this->clean($this->content);
} | [
"private",
"function",
"getContent",
"(",
")",
"{",
"return",
"is_array",
"(",
"$",
"this",
"->",
"content",
")",
"?",
"array_map",
"(",
"function",
"(",
"$",
"content",
")",
"{",
"return",
"$",
"this",
"->",
"clean",
"(",
"$",
"content",
")",
";",
"... | Get the meta content.
@return string|array | [
"Get",
"the",
"meta",
"content",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L150-L155 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.setContent | private function setContent($content)
{
if (is_array($content))
$this->content = $content;
elseif (is_string($content))
$this->content = trim($content);
return $this;
} | php | private function setContent($content)
{
if (is_array($content))
$this->content = $content;
elseif (is_string($content))
$this->content = trim($content);
return $this;
} | [
"private",
"function",
"setContent",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"$",
"this",
"->",
"content",
"=",
"$",
"content",
";",
"elseif",
"(",
"is_string",
"(",
"$",
"content",
")",
")",
"$",
"this",
... | Set the meta content.
@param string|array $content
@return \Arcanedev\SeoHelper\Helpers\Meta | [
"Set",
"the",
"meta",
"content",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L164-L172 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.make | public static function make($name, $content, $propertyName = 'name', $prefix = '')
{
return new self($name, $content, $propertyName, $prefix);
} | php | public static function make($name, $content, $propertyName = 'name', $prefix = '')
{
return new self($name, $content, $propertyName, $prefix);
} | [
"public",
"static",
"function",
"make",
"(",
"$",
"name",
",",
"$",
"content",
",",
"$",
"propertyName",
"=",
"'name'",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"name",
",",
"$",
"content",
",",
"$",
"propertyName",... | Make Meta instance.
@param string $name
@param string|array $content
@param string $propertyName
@param string $prefix
@return \Arcanedev\SeoHelper\Helpers\Meta | [
"Make",
"Meta",
"instance",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L188-L191 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.renderLink | private function renderLink()
{
return Element::withTag('link')
->attributes([
'rel' => $this->getName(false),
'href' => $this->getContent(),
])
->toHtml();
} | php | private function renderLink()
{
return Element::withTag('link')
->attributes([
'rel' => $this->getName(false),
'href' => $this->getContent(),
])
->toHtml();
} | [
"private",
"function",
"renderLink",
"(",
")",
"{",
"return",
"Element",
"::",
"withTag",
"(",
"'link'",
")",
"->",
"attributes",
"(",
"[",
"'rel'",
"=>",
"$",
"this",
"->",
"getName",
"(",
"false",
")",
",",
"'href'",
"=>",
"$",
"this",
"->",
"getCont... | Render the link tag.
@return string | [
"Render",
"the",
"link",
"tag",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L210-L218 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.renderMeta | private function renderMeta()
{
$content = Arr::wrap($this->getContent());
return implode(PHP_EOL, array_map(function ($content) {
return HtmlMeta::make()->attributes([
$this->nameProperty => $this->getName(),
'content' => $content,
])->toHtml();
}, $content));
} | php | private function renderMeta()
{
$content = Arr::wrap($this->getContent());
return implode(PHP_EOL, array_map(function ($content) {
return HtmlMeta::make()->attributes([
$this->nameProperty => $this->getName(),
'content' => $content,
])->toHtml();
}, $content));
} | [
"private",
"function",
"renderMeta",
"(",
")",
"{",
"$",
"content",
"=",
"Arr",
"::",
"wrap",
"(",
"$",
"this",
"->",
"getContent",
"(",
")",
")",
";",
"return",
"implode",
"(",
"PHP_EOL",
",",
"array_map",
"(",
"function",
"(",
"$",
"content",
")",
... | Render the meta tag.
@return string | [
"Render",
"the",
"meta",
"tag",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L225-L235 | train |
ARCANEDEV/SEO-Helper | src/Helpers/Meta.php | Meta.checkNameProperty | private function checkNameProperty(&$nameProperty)
{
if ( ! is_string($nameProperty)) {
throw new InvalidArgumentException(
'The meta name property is must be a string value, '.gettype($nameProperty).' is given.'
);
}
$name = Str::slug($nameProperty);
$allowed = ['charset', 'http-equiv', 'itemprop', 'name', 'property'];
if ( ! in_array($name, $allowed)) {
throw new InvalidArgumentException(
"The meta name property [$name] is not supported, ".
"the allowed name properties are ['".implode("', '", $allowed)."']."
);
}
$nameProperty = $name;
} | php | private function checkNameProperty(&$nameProperty)
{
if ( ! is_string($nameProperty)) {
throw new InvalidArgumentException(
'The meta name property is must be a string value, '.gettype($nameProperty).' is given.'
);
}
$name = Str::slug($nameProperty);
$allowed = ['charset', 'http-equiv', 'itemprop', 'name', 'property'];
if ( ! in_array($name, $allowed)) {
throw new InvalidArgumentException(
"The meta name property [$name] is not supported, ".
"the allowed name properties are ['".implode("', '", $allowed)."']."
);
}
$nameProperty = $name;
} | [
"private",
"function",
"checkNameProperty",
"(",
"&",
"$",
"nameProperty",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"nameProperty",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The meta name property is must be a string value, '",
".",
"... | Check the name property.
@param string $nameProperty
@throws InvalidArgumentException | [
"Check",
"the",
"name",
"property",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Helpers/Meta.php#L282-L301 | train |
ARCANEDEV/SEO-Helper | src/Entities/Webmasters.php | Webmasters.add | public function add($webmaster, $content)
{
if ( ! is_null($name = $this->getWebmasterName($webmaster))) {
$this->metas->addOne($name, $content);
}
return $this;
} | php | public function add($webmaster, $content)
{
if ( ! is_null($name = $this->getWebmasterName($webmaster))) {
$this->metas->addOne($name, $content);
}
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"webmaster",
",",
"$",
"content",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"name",
"=",
"$",
"this",
"->",
"getWebmasterName",
"(",
"$",
"webmaster",
")",
")",
")",
"{",
"$",
"this",
"->",
"metas",
"->",... | Add a webmaster to collection.
@param string $webmaster
@param string $content
@return \Arcanedev\SeoHelper\Entities\Webmasters | [
"Add",
"a",
"webmaster",
"to",
"collection",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Webmasters.php#L127-L134 | train |
ARCANEDEV/SEO-Helper | src/Entities/Keywords.php | Keywords.set | public function set($content)
{
if (is_string($content))
$content = explode(',', $content);
if ( ! is_array($content))
$content = (array) $content;
$this->content = array_map(function ($keyword) {
return $this->clean($keyword);
}, $content);
return $this;
} | php | public function set($content)
{
if (is_string($content))
$content = explode(',', $content);
if ( ! is_array($content))
$content = (array) $content;
$this->content = array_map(function ($keyword) {
return $this->clean($keyword);
}, $content);
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"content",
")",
")",
"$",
"content",
"=",
"explode",
"(",
"','",
",",
"$",
"content",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"content",
")",
")... | Set keywords content.
@param array|string $content
@return self | [
"Set",
"keywords",
"content",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Keywords.php#L89-L102 | train |
ARCANEDEV/SEO-Helper | src/Entities/MiscTags.php | MiscTags.addCanonical | private function addCanonical()
{
if ($this->isCanonicalEnabled() && $this->hasUrl())
$this->add('canonical', $this->currentUrl);
return $this;
} | php | private function addCanonical()
{
if ($this->isCanonicalEnabled() && $this->hasUrl())
$this->add('canonical', $this->currentUrl);
return $this;
} | [
"private",
"function",
"addCanonical",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCanonicalEnabled",
"(",
")",
"&&",
"$",
"this",
"->",
"hasUrl",
"(",
")",
")",
"$",
"this",
"->",
"add",
"(",
"'canonical'",
",",
"$",
"this",
"->",
"currentUrl",
... | Add the canonical link.
@return \Arcanedev\SeoHelper\Entities\MiscTags | [
"Add",
"the",
"canonical",
"link",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/MiscTags.php#L258-L264 | train |
ARCANEDEV/SEO-Helper | src/Entities/Twitter/Card.php | Card.setType | public function setType($type)
{
if (empty($type)) return $this;
$this->checkType($type);
$this->type = $type;
return $this->addMeta('card', $type);
} | php | public function setType($type)
{
if (empty($type)) return $this;
$this->checkType($type);
$this->type = $type;
return $this->addMeta('card', $type);
} | [
"public",
"function",
"setType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"return",
"$",
"this",
";",
"$",
"this",
"->",
"checkType",
"(",
"$",
"type",
")",
";",
"$",
"this",
"->",
"type",
"=",
"$",
"type",
";... | Set the card type.
@param string $type
@return \Arcanedev\SeoHelper\Entities\Twitter\Card | [
"Set",
"the",
"card",
"type",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Twitter/Card.php#L109-L117 | train |
ARCANEDEV/SEO-Helper | src/Entities/Twitter/Card.php | Card.setSite | public function setSite($site)
{
if (empty($site)) return $this;
$this->checkSite($site);
return $this->addMeta('site', $site);
} | php | public function setSite($site)
{
if (empty($site)) return $this;
$this->checkSite($site);
return $this->addMeta('site', $site);
} | [
"public",
"function",
"setSite",
"(",
"$",
"site",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"site",
")",
")",
"return",
"$",
"this",
";",
"$",
"this",
"->",
"checkSite",
"(",
"$",
"site",
")",
";",
"return",
"$",
"this",
"->",
"addMeta",
"(",
"'si... | Set card site.
@param string $site
@return \Arcanedev\SeoHelper\Entities\Twitter\Card | [
"Set",
"card",
"site",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Twitter/Card.php#L126-L133 | train |
ARCANEDEV/SEO-Helper | src/Entities/Twitter/Card.php | Card.loadImages | private function loadImages()
{
if (count($this->images) == 1) {
$this->addMeta('image', $this->images[0]);
return;
}
foreach ($this->images as $number => $url) {
$this->addMeta("image{$number}", $url);
}
} | php | private function loadImages()
{
if (count($this->images) == 1) {
$this->addMeta('image', $this->images[0]);
return;
}
foreach ($this->images as $number => $url) {
$this->addMeta("image{$number}", $url);
}
} | [
"private",
"function",
"loadImages",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"images",
")",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"addMeta",
"(",
"'image'",
",",
"$",
"this",
"->",
"images",
"[",
"0",
"]",
")",
";",
"return",... | Render card images. | [
"Render",
"card",
"images",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Twitter/Card.php#L230-L241 | train |
ARCANEDEV/SEO-Helper | src/Entities/Twitter/Card.php | Card.checkType | private function checkType(&$type)
{
if ( ! is_string($type)) {
throw new InvalidTwitterCardException(
'The Twitter card type must be a string value, [' . gettype($type) . '] was given.'
);
}
$type = strtolower(trim($type));
if ( ! in_array($type, $this->types())) {
throw new InvalidTwitterCardException("The Twitter card type [$type] is not supported.");
}
} | php | private function checkType(&$type)
{
if ( ! is_string($type)) {
throw new InvalidTwitterCardException(
'The Twitter card type must be a string value, [' . gettype($type) . '] was given.'
);
}
$type = strtolower(trim($type));
if ( ! in_array($type, $this->types())) {
throw new InvalidTwitterCardException("The Twitter card type [$type] is not supported.");
}
} | [
"private",
"function",
"checkType",
"(",
"&",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidTwitterCardException",
"(",
"'The Twitter card type must be a string value, ['",
".",
"gettype",
"(",
"$",
... | Check the card type.
@param string $type
@throws \Arcanedev\SeoHelper\Exceptions\InvalidTwitterCardException | [
"Check",
"the",
"card",
"type",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Entities/Twitter/Card.php#L292-L305 | train |
ARCANEDEV/SEO-Helper | src/Bases/MetaCollection.php | MetaCollection.addMany | public function addMany(array $metas)
{
foreach ($metas as $name => $content) {
$this->addOne($name, $content);
}
return $this;
} | php | public function addMany(array $metas)
{
foreach ($metas as $name => $content) {
$this->addOne($name, $content);
}
return $this;
} | [
"public",
"function",
"addMany",
"(",
"array",
"$",
"metas",
")",
"{",
"foreach",
"(",
"$",
"metas",
"as",
"$",
"name",
"=>",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"addOne",
"(",
"$",
"name",
",",
"$",
"content",
")",
";",
"}",
"return",
"... | Add many meta tags.
@param array $metas
@return \Arcanedev\SeoHelper\Bases\MetaCollection | [
"Add",
"many",
"meta",
"tags",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Bases/MetaCollection.php#L81-L88 | train |
ARCANEDEV/SEO-Helper | src/Bases/MetaCollection.php | MetaCollection.addMeta | protected function addMeta($name, $content)
{
$meta = Meta::make($name, $content, $this->nameProperty, $this->prefix);
return $this->put($meta->key(), $meta);
} | php | protected function addMeta($name, $content)
{
$meta = Meta::make($name, $content, $this->nameProperty, $this->prefix);
return $this->put($meta->key(), $meta);
} | [
"protected",
"function",
"addMeta",
"(",
"$",
"name",
",",
"$",
"content",
")",
"{",
"$",
"meta",
"=",
"Meta",
"::",
"make",
"(",
"$",
"name",
",",
"$",
"content",
",",
"$",
"this",
"->",
"nameProperty",
",",
"$",
"this",
"->",
"prefix",
")",
";",
... | Make a meta and add it to collection.
@param string $name
@param string|array $content
@return \Arcanedev\SeoHelper\Bases\MetaCollection | [
"Make",
"a",
"meta",
"and",
"add",
"it",
"to",
"collection",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Bases/MetaCollection.php#L114-L119 | train |
ARCANEDEV/SEO-Helper | src/Providers/UtilityServiceProvider.php | UtilityServiceProvider.registerSeoMetaService | private function registerSeoMetaService()
{
$this->singleton(Contracts\SeoMeta::class, function ($app) {
/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app['config'];
return new SeoMeta($config->get('seo-helper'));
});
} | php | private function registerSeoMetaService()
{
$this->singleton(Contracts\SeoMeta::class, function ($app) {
/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app['config'];
return new SeoMeta($config->get('seo-helper'));
});
} | [
"private",
"function",
"registerSeoMetaService",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"SeoMeta",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"/** @var \\Illuminate\\Contracts\\Config\\Repository $config */",
"$",
"c... | Register SeoMeta service. | [
"Register",
"SeoMeta",
"service",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Providers/UtilityServiceProvider.php#L70-L78 | train |
ARCANEDEV/SEO-Helper | src/Providers/UtilityServiceProvider.php | UtilityServiceProvider.registerSeoOpenGraphService | private function registerSeoOpenGraphService()
{
$this->singleton(Contracts\SeoOpenGraph::class, function ($app) {
/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app['config'];
return new SeoOpenGraph($config->get('seo-helper'));
});
} | php | private function registerSeoOpenGraphService()
{
$this->singleton(Contracts\SeoOpenGraph::class, function ($app) {
/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app['config'];
return new SeoOpenGraph($config->get('seo-helper'));
});
} | [
"private",
"function",
"registerSeoOpenGraphService",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"SeoOpenGraph",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"/** @var \\Illuminate\\Contracts\\Config\\Repository $config */",
... | Register SeoOpenGraph service. | [
"Register",
"SeoOpenGraph",
"service",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Providers/UtilityServiceProvider.php#L83-L91 | train |
ARCANEDEV/SEO-Helper | src/Providers/UtilityServiceProvider.php | UtilityServiceProvider.registerSeoTwitterService | private function registerSeoTwitterService()
{
$this->singleton(Contracts\SeoTwitter::class, function ($app) {
/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app['config'];
return new SeoTwitter($config->get('seo-helper'));
});
} | php | private function registerSeoTwitterService()
{
$this->singleton(Contracts\SeoTwitter::class, function ($app) {
/** @var \Illuminate\Contracts\Config\Repository $config */
$config = $app['config'];
return new SeoTwitter($config->get('seo-helper'));
});
} | [
"private",
"function",
"registerSeoTwitterService",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"Contracts",
"\\",
"SeoTwitter",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"/** @var \\Illuminate\\Contracts\\Config\\Repository $config */",
"$"... | Register SeoTwitter service. | [
"Register",
"SeoTwitter",
"service",
"."
] | 93080fd320666c8dfe5850f21e45e9ed9e6aee88 | https://github.com/ARCANEDEV/SEO-Helper/blob/93080fd320666c8dfe5850f21e45e9ed9e6aee88/src/Providers/UtilityServiceProvider.php#L96-L104 | train |
clarkeash/doorman | src/Drivers/UuidDriver.php | UuidDriver.code | public function code(): string
{
$version = config('doorman.uuid.version', 4);
$method = 'createVersion' . $version . 'Uuid';
if (method_exists($this, $method)) {
return $this->$method();
}
throw new InvalidArgumentException("Version [$version] not supported.");
} | php | public function code(): string
{
$version = config('doorman.uuid.version', 4);
$method = 'createVersion' . $version . 'Uuid';
if (method_exists($this, $method)) {
return $this->$method();
}
throw new InvalidArgumentException("Version [$version] not supported.");
} | [
"public",
"function",
"code",
"(",
")",
":",
"string",
"{",
"$",
"version",
"=",
"config",
"(",
"'doorman.uuid.version'",
",",
"4",
")",
";",
"$",
"method",
"=",
"'createVersion'",
".",
"$",
"version",
".",
"'Uuid'",
";",
"if",
"(",
"method_exists",
"(",... | Create an invite code.
@return string | [
"Create",
"an",
"invite",
"code",
"."
] | 7ff68aca12e80029281a1514eca6699d63b7e119 | https://github.com/clarkeash/doorman/blob/7ff68aca12e80029281a1514eca6699d63b7e119/src/Drivers/UuidDriver.php#L20-L31 | train |
clarkeash/doorman | src/Models/Invite.php | Invite.scopeUseless | public function scopeUseless($query)
{
return $query
->where(function ($q) {
$this->scopeExpired($q);
})
->orWhere(function ($q) {
$this->scopeFull($q);
});
} | php | public function scopeUseless($query)
{
return $query
->where(function ($q) {
$this->scopeExpired($q);
})
->orWhere(function ($q) {
$this->scopeFull($q);
});
} | [
"public",
"function",
"scopeUseless",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"$",
"q",
")",
"{",
"$",
"this",
"->",
"scopeExpired",
"(",
"$",
"q",
")",
";",
"}",
")",
"->",
"orWhere",
"(",
"functio... | Scope a query to only include useless invites.
@param \Illuminate\Database\Eloquent\Builder $query
@return \Illuminate\Database\Eloquent\Builder | [
"Scope",
"a",
"query",
"to",
"only",
"include",
"useless",
"invites",
"."
] | 7ff68aca12e80029281a1514eca6699d63b7e119 | https://github.com/clarkeash/doorman/blob/7ff68aca12e80029281a1514eca6699d63b7e119/src/Models/Invite.php#L120-L129 | train |
omnilight/yii2-scheduling | src/Event.php | Event.runCommandInBackground | protected function runCommandInBackground(Application $app)
{
chdir(dirname($app->request->getScriptFile()));
exec($this->buildCommand());
} | php | protected function runCommandInBackground(Application $app)
{
chdir(dirname($app->request->getScriptFile()));
exec($this->buildCommand());
} | [
"protected",
"function",
"runCommandInBackground",
"(",
"Application",
"$",
"app",
")",
"{",
"chdir",
"(",
"dirname",
"(",
"$",
"app",
"->",
"request",
"->",
"getScriptFile",
"(",
")",
")",
")",
";",
"exec",
"(",
"$",
"this",
"->",
"buildCommand",
"(",
"... | Run the command in the background using exec.
@param Application $app | [
"Run",
"the",
"command",
"in",
"the",
"background",
"using",
"exec",
"."
] | b1a9292bb4ab4c02ab26eca2ba7c4c4c2aee914f | https://github.com/omnilight/yii2-scheduling/blob/b1a9292bb4ab4c02ab26eca2ba7c4c4c2aee914f/src/Event.php#L171-L175 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PropertiesValidateTask.php | PropertiesValidateTask.setRequired | public function setRequired($required)
{
if (is_string($required)) {
$this->_required = new PhingFile($required);
} else {
$this->_required = $required;
}
} | php | public function setRequired($required)
{
if (is_string($required)) {
$this->_required = new PhingFile($required);
} else {
$this->_required = $required;
}
} | [
"public",
"function",
"setRequired",
"(",
"$",
"required",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"required",
")",
")",
"{",
"$",
"this",
"->",
"_required",
"=",
"new",
"PhingFile",
"(",
"$",
"required",
")",
";",
"}",
"else",
"{",
"$",
"this",
... | Set a file to get the required properties.
@param string|PhingFile $required file to compare with
@return void | [
"Set",
"a",
"file",
"to",
"get",
"the",
"required",
"properties",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PropertiesValidateTask.php#L96-L103 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PropertiesValidateTask.php | PropertiesValidateTask.setForbidden | public function setForbidden($forbidden)
{
if (is_string($forbidden)) {
$this->_forbidden = new PhingFile($forbidden);
} else {
$this->_forbidden = $forbidden;
}
} | php | public function setForbidden($forbidden)
{
if (is_string($forbidden)) {
$this->_forbidden = new PhingFile($forbidden);
} else {
$this->_forbidden = $forbidden;
}
} | [
"public",
"function",
"setForbidden",
"(",
"$",
"forbidden",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"forbidden",
")",
")",
"{",
"$",
"this",
"->",
"_forbidden",
"=",
"new",
"PhingFile",
"(",
"$",
"forbidden",
")",
";",
"}",
"else",
"{",
"$",
"th... | Set a file to get the forbidden properties.
@param string|PhingFile $forbidden file to compare with
@return void | [
"Set",
"a",
"file",
"to",
"get",
"the",
"forbidden",
"properties",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PropertiesValidateTask.php#L112-L120 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PropertiesValidateTask.php | PropertiesValidateTask._haltOnErrorAction | private function _haltOnErrorAction(Exception $exception = null, $message = '', $level = Project::MSG_INFO)
{
if ($this->_haltonerror) {
throw new BuildException(
$exception !== null ? $exception : $message,
$this->getLocation()
);
} else {
$this->log(
$exception !== null && $message === '' ? $exception->getMessage() : $message,
$level
);
}
} | php | private function _haltOnErrorAction(Exception $exception = null, $message = '', $level = Project::MSG_INFO)
{
if ($this->_haltonerror) {
throw new BuildException(
$exception !== null ? $exception : $message,
$this->getLocation()
);
} else {
$this->log(
$exception !== null && $message === '' ? $exception->getMessage() : $message,
$level
);
}
} | [
"private",
"function",
"_haltOnErrorAction",
"(",
"Exception",
"$",
"exception",
"=",
"null",
",",
"$",
"message",
"=",
"''",
",",
"$",
"level",
"=",
"Project",
"::",
"MSG_INFO",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_haltonerror",
")",
"{",
"throw",
... | Halt execution on error.
@param Exception $exception Exception to be throwed
@param string $message Message to be displayed
@param int $level Exception level
@throws BuildException
@return void | [
"Halt",
"execution",
"on",
"error",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PropertiesValidateTask.php#L221-L235 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PropertiesValidateTask.php | PropertiesValidateTask.checkLoadProperties | protected function checkLoadProperties($propertiesFile, $propertyType)
{
if ($propertiesFile->exists() && $propertiesFile->isDirectory()) {
$message = $propertyType." is a directory!";
$this->_haltOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
if ($propertiesFile->exists() && !$propertiesFile->canRead()) {
$message = "Can not read from the specified ".$propertyType."!";
$this->_haltOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
$fileParserFactory = new FileParserFactory();
$fileParser = $fileParserFactory->createParser($propertiesFile->getFileExtension());
$properties = new Properties(null, $fileParser);
$properties->load($propertiesFile);
return $properties->getProperties();
} | php | protected function checkLoadProperties($propertiesFile, $propertyType)
{
if ($propertiesFile->exists() && $propertiesFile->isDirectory()) {
$message = $propertyType." is a directory!";
$this->_haltOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
if ($propertiesFile->exists() && !$propertiesFile->canRead()) {
$message = "Can not read from the specified ".$propertyType."!";
$this->_haltOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
$fileParserFactory = new FileParserFactory();
$fileParser = $fileParserFactory->createParser($propertiesFile->getFileExtension());
$properties = new Properties(null, $fileParser);
$properties->load($propertiesFile);
return $properties->getProperties();
} | [
"protected",
"function",
"checkLoadProperties",
"(",
"$",
"propertiesFile",
",",
"$",
"propertyType",
")",
"{",
"if",
"(",
"$",
"propertiesFile",
"->",
"exists",
"(",
")",
"&&",
"$",
"propertiesFile",
"->",
"isDirectory",
"(",
")",
")",
"{",
"$",
"message",
... | Check if we can load the file and return the properties.
@param phingFile $propertiesFile Properties file
@param string $propertyType Type of file
@throws BuildException
@return array | [
"Check",
"if",
"we",
"can",
"load",
"the",
"file",
"and",
"return",
"the",
"properties",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PropertiesValidateTask.php#L247-L270 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php | PhpCodeSnifferConfigurationTask.main | public function main()
{
// Check if all required data is present.
$this->checkRequirements();
$document = new \DOMDocument('1.0', 'UTF-8');
$document->formatOutput = true;
// Create the root 'ruleset' element.
$root_element = $document->createElement('ruleset');
$root_element->setAttribute('name', 'NextEuropa_default');
$document->appendChild($root_element);
// Add the description.
$element = $document->createElement(
'description',
'Default PHP CodeSniffer configuration for NextEuropa subsites.'
);
$root_element->appendChild($element);
// Add the coding standards.
foreach ($this->_standards as $standard) {
if (substr($standard, -4) === '.xml') {
if (file_exists($standard)) {
$element = $document->createElement('rule');
$element->setAttribute('ref', $standard);
$root_element->appendChild($element);
}
}
else {
$element = $document->createElement('rule');
$element->setAttribute('ref', $standard);
$root_element->appendChild($element);
}
}
// Add the files to check.
foreach ($this->_files as $file) {
$element = $document->createElement('file', $file);
$root_element->appendChild($element);
}
// Add file extensions.
if (!empty($this->_extensions)) {
$extensions = implode(',', $this->_extensions);
$this->appendArgument(
$document,
$root_element,
$extensions,
'extensions'
);
}
// Add ignore patterns.
foreach ($this->_ignorePatterns as $pattern) {
$element = $document->createElement('exclude-pattern', $pattern);
$root_element->appendChild($element);
}
// Add the requested Reports..
foreach ($this->_reports as $report) {
// Add the report type.
$this->appendArgument($document, $root_element, $report, 'report');
}
// Add the shorthand options.
$shorthand_options = array(
'p' => '_showProgress',
's' => '_showSniffCodes',
);
$options = array_filter(
$shorthand_options,
function ($value) {
return $this->$value;
}
);
if (!empty($options)) {
$this->appendArgument(
$document,
$root_element,
implode('', array_flip($options))
);
}
// Save the file.
$configSaved = file_put_contents(
$this->_configFile,
$document->saveXML()
);
} | php | public function main()
{
// Check if all required data is present.
$this->checkRequirements();
$document = new \DOMDocument('1.0', 'UTF-8');
$document->formatOutput = true;
// Create the root 'ruleset' element.
$root_element = $document->createElement('ruleset');
$root_element->setAttribute('name', 'NextEuropa_default');
$document->appendChild($root_element);
// Add the description.
$element = $document->createElement(
'description',
'Default PHP CodeSniffer configuration for NextEuropa subsites.'
);
$root_element->appendChild($element);
// Add the coding standards.
foreach ($this->_standards as $standard) {
if (substr($standard, -4) === '.xml') {
if (file_exists($standard)) {
$element = $document->createElement('rule');
$element->setAttribute('ref', $standard);
$root_element->appendChild($element);
}
}
else {
$element = $document->createElement('rule');
$element->setAttribute('ref', $standard);
$root_element->appendChild($element);
}
}
// Add the files to check.
foreach ($this->_files as $file) {
$element = $document->createElement('file', $file);
$root_element->appendChild($element);
}
// Add file extensions.
if (!empty($this->_extensions)) {
$extensions = implode(',', $this->_extensions);
$this->appendArgument(
$document,
$root_element,
$extensions,
'extensions'
);
}
// Add ignore patterns.
foreach ($this->_ignorePatterns as $pattern) {
$element = $document->createElement('exclude-pattern', $pattern);
$root_element->appendChild($element);
}
// Add the requested Reports..
foreach ($this->_reports as $report) {
// Add the report type.
$this->appendArgument($document, $root_element, $report, 'report');
}
// Add the shorthand options.
$shorthand_options = array(
'p' => '_showProgress',
's' => '_showSniffCodes',
);
$options = array_filter(
$shorthand_options,
function ($value) {
return $this->$value;
}
);
if (!empty($options)) {
$this->appendArgument(
$document,
$root_element,
implode('', array_flip($options))
);
}
// Save the file.
$configSaved = file_put_contents(
$this->_configFile,
$document->saveXML()
);
} | [
"public",
"function",
"main",
"(",
")",
"{",
"// Check if all required data is present.",
"$",
"this",
"->",
"checkRequirements",
"(",
")",
";",
"$",
"document",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
")",
";",
"$",
"document",
"->",
... | Configures PHP CodeSniffer.
@return void | [
"Configures",
"PHP",
"CodeSniffer",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php#L94-L186 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php | PhpCodeSnifferConfigurationTask.appendArgument | protected function appendArgument(
\DOMDocument $document,
\DOMElement $element,
$value,
$name = ''
) {
$argument = $document->createElement('arg');
if (!empty($name)) {
$argument->setAttribute('name', $name);
}
if (!empty($value)) {
$argument->setAttribute('value', $value);
}
$element->appendChild($argument);
} | php | protected function appendArgument(
\DOMDocument $document,
\DOMElement $element,
$value,
$name = ''
) {
$argument = $document->createElement('arg');
if (!empty($name)) {
$argument->setAttribute('name', $name);
}
if (!empty($value)) {
$argument->setAttribute('value', $value);
}
$element->appendChild($argument);
} | [
"protected",
"function",
"appendArgument",
"(",
"\\",
"DOMDocument",
"$",
"document",
",",
"\\",
"DOMElement",
"$",
"element",
",",
"$",
"value",
",",
"$",
"name",
"=",
"''",
")",
"{",
"$",
"argument",
"=",
"$",
"document",
"->",
"createElement",
"(",
"'... | Appends an argument element to the XML document.
This will append an XML element in the following format:
<arg name="name" value="value" />
@param \DOMDocument $document The document that will contain the argument
to append.
@param \DOMElement $element The parent element of the argument
to append.
@param string $value The argument value.
@param string $name Optional argument name.
@return void | [
"Appends",
"an",
"argument",
"element",
"to",
"the",
"XML",
"document",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php#L204-L221 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php | PhpCodeSnifferConfigurationTask.setExtensions | public function setExtensions($extensions)
{
$this->_extensions = array();
$token = ' ,;';
$extension = strtok($extensions, $token);
while ($extension !== false) {
$this->_extensions[] = $extension;
$extension = strtok($token);
}
} | php | public function setExtensions($extensions)
{
$this->_extensions = array();
$token = ' ,;';
$extension = strtok($extensions, $token);
while ($extension !== false) {
$this->_extensions[] = $extension;
$extension = strtok($token);
}
} | [
"public",
"function",
"setExtensions",
"(",
"$",
"extensions",
")",
"{",
"$",
"this",
"->",
"_extensions",
"=",
"array",
"(",
")",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"extension",
"=",
"strtok",
"(",
"$",
"extensions",
",",
"$",
"token",
")",
... | Sets the file extensions to scan.
@param string $extensions A string containing file extensions, delimited
by spaces, commas or semicolons.
@return void | [
"Sets",
"the",
"file",
"extensions",
"to",
"scan",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php#L272-L283 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php | PhpCodeSnifferConfigurationTask.setFiles | public function setFiles($files)
{
$this->_files = array();
$token = ' ,;';
$file = strtok($files, $token);
while ($file !== false) {
$this->_files[] = $file;
$file = strtok($token);
}
} | php | public function setFiles($files)
{
$this->_files = array();
$token = ' ,;';
$file = strtok($files, $token);
while ($file !== false) {
$this->_files[] = $file;
$file = strtok($token);
}
} | [
"public",
"function",
"setFiles",
"(",
"$",
"files",
")",
"{",
"$",
"this",
"->",
"_files",
"=",
"array",
"(",
")",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"file",
"=",
"strtok",
"(",
"$",
"files",
",",
"$",
"token",
")",
";",
"while",
"(",
... | Sets the list of files and folders to scan.
@param string $files A list of paths, delimited by spaces, commas or
semicolons.
@return void | [
"Sets",
"the",
"list",
"of",
"files",
"and",
"folders",
"to",
"scan",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php#L294-L305 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php | PhpCodeSnifferConfigurationTask.setIgnorePatterns | public function setIgnorePatterns($ignorePatterns)
{
$this->_ignorePatterns = array();
$token = ' ,;';
$pattern = strtok($ignorePatterns, $token);
while ($pattern !== false) {
$this->_ignorePatterns[] = $pattern;
$pattern = strtok($token);
}
} | php | public function setIgnorePatterns($ignorePatterns)
{
$this->_ignorePatterns = array();
$token = ' ,;';
$pattern = strtok($ignorePatterns, $token);
while ($pattern !== false) {
$this->_ignorePatterns[] = $pattern;
$pattern = strtok($token);
}
} | [
"public",
"function",
"setIgnorePatterns",
"(",
"$",
"ignorePatterns",
")",
"{",
"$",
"this",
"->",
"_ignorePatterns",
"=",
"array",
"(",
")",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"pattern",
"=",
"strtok",
"(",
"$",
"ignorePatterns",
",",
"$",
"tok... | Sets the list of patterns to ignore.
@param string $ignorePatterns The list of patterns, delimited by spaces,
commas or semicolons.
@return void | [
"Sets",
"the",
"list",
"of",
"patterns",
"to",
"ignore",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php#L316-L327 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php | PhpCodeSnifferConfigurationTask.setReports | public function setReports($reports)
{
$this->_reports = array();
$token = ' ,;';
$report = strtok($reports, $token);
while ($report !== false) {
$this->_reports[] = $reports;
$report = strtok($token);
}
} | php | public function setReports($reports)
{
$this->_reports = array();
$token = ' ,;';
$report = strtok($reports, $token);
while ($report !== false) {
$this->_reports[] = $reports;
$report = strtok($token);
}
} | [
"public",
"function",
"setReports",
"(",
"$",
"reports",
")",
"{",
"$",
"this",
"->",
"_reports",
"=",
"array",
"(",
")",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"report",
"=",
"strtok",
"(",
"$",
"reports",
",",
"$",
"token",
")",
";",
"while",... | Sets the report formats to use.
@param string $reports A list of report types, delimited by spaces,
commas or semicolons.
@return void | [
"Sets",
"the",
"report",
"formats",
"to",
"use",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php#L338-L349 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php | PhpCodeSnifferConfigurationTask.setStandards | public function setStandards($standards)
{
$this->_standards = array();
$token = ' ,;';
$standard = strtok($standards, $token);
while ($standard !== false) {
$this->_standards[] = $standard;
$standard = strtok($token);
}
} | php | public function setStandards($standards)
{
$this->_standards = array();
$token = ' ,;';
$standard = strtok($standards, $token);
while ($standard !== false) {
$this->_standards[] = $standard;
$standard = strtok($token);
}
} | [
"public",
"function",
"setStandards",
"(",
"$",
"standards",
")",
"{",
"$",
"this",
"->",
"_standards",
"=",
"array",
"(",
")",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"standard",
"=",
"strtok",
"(",
"$",
"standards",
",",
"$",
"token",
")",
";",
... | Sets the coding standards to use.
@param string $standards A list of paths, delimited by spaces, commas or
semicolons.
@return void | [
"Sets",
"the",
"coding",
"standards",
"to",
"use",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhpCodeSnifferConfigurationTask.php#L388-L399 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DrushMakeFileTask.php | DrushMakeFileTask.setProjects | public function setProjects($projects)
{
$this->_projects = [];
$token = ' ,;';
$project = strtok($projects, $token);
while ($project !== false) {
$this->_projects[] = $project;
$project = strtok($token);
}
} | php | public function setProjects($projects)
{
$this->_projects = [];
$token = ' ,;';
$project = strtok($projects, $token);
while ($project !== false) {
$this->_projects[] = $project;
$project = strtok($token);
}
} | [
"public",
"function",
"setProjects",
"(",
"$",
"projects",
")",
"{",
"$",
"this",
"->",
"_projects",
"=",
"[",
"]",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"project",
"=",
"strtok",
"(",
"$",
"projects",
",",
"$",
"token",
")",
";",
"while",
"("... | Sets the list of projects to download.
@param string $projects A string containing a list of projects, delimited
by spaces, commas or semicolons.
@return void | [
"Sets",
"the",
"list",
"of",
"projects",
"to",
"download",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DrushMakeFileTask.php#L176-L187 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DocGeneratorTask.php | DocGeneratorTask.main | public function main()
{
$this->checkRequirements();
$this->getBuildList($this->_buildFile);
$this->parseTargets();
$this->buildMarkup();
$this->buildMarkupFull();
} | php | public function main()
{
$this->checkRequirements();
$this->getBuildList($this->_buildFile);
$this->parseTargets();
$this->buildMarkup();
$this->buildMarkupFull();
} | [
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"checkRequirements",
"(",
")",
";",
"$",
"this",
"->",
"getBuildList",
"(",
"$",
"this",
"->",
"_buildFile",
")",
";",
"$",
"this",
"->",
"parseTargets",
"(",
")",
";",
"$",
"this",
"->"... | Inherits documentation.
@return void | [
"Inherits",
"documentation",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DocGeneratorTask.php#L53-L60 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DocGeneratorTask.php | DocGeneratorTask.checkRequirements | protected function checkRequirements()
{
$required_properties = array('_buildFile');
foreach ($required_properties as $required_property) {
if (empty($this->$required_property)) {
throw new \BuildException(
"Missing required property '" . $required_property . "'."
);
}
}
} | php | protected function checkRequirements()
{
$required_properties = array('_buildFile');
foreach ($required_properties as $required_property) {
if (empty($this->$required_property)) {
throw new \BuildException(
"Missing required property '" . $required_property . "'."
);
}
}
} | [
"protected",
"function",
"checkRequirements",
"(",
")",
"{",
"$",
"required_properties",
"=",
"array",
"(",
"'_buildFile'",
")",
";",
"foreach",
"(",
"$",
"required_properties",
"as",
"$",
"required_property",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
... | Checks target requirements.
@throws \BuildException
Thrown when a required property is not present.
@return void | [
"Checks",
"target",
"requirements",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DocGeneratorTask.php#L70-L80 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DocGeneratorTask.php | DocGeneratorTask.buildMarkupFull | protected function buildMarkupFull()
{
$output = "# Toolkit Phing Targets\n";
$output .= "This is the list of targets provided by toolkit, please note that this is a auto-generated list.\n\n";
$targetsCount = 0;
foreach ($this->targets as $target) {
$detail = $target['description'] ."\n";
$detail .= "\n##### Example:\n";
$detail .= "`toolkit\phing " . $target['name'] . "'\n'";
if (isset($target['properties']) && count($target['properties']) > 0) {
$detail .= "\n##### Properties:\n";
foreach ($target['properties'] as $property) {
$detail .= "* " . $property['name'] . "\n";
}
}
if (isset($target['dependencies']) && count($target['dependencies']) > 0) {
$detail .= "\n##### Dependencies: \n";
foreach ($target['dependencies'] as $callback) {
$detail .= "* " . $callback . "\n";
}
}
$output .= "<details><p><summary>" . $target['name'] . "</summary></p>\n";
if (isset($detail)) {
$output .= $detail;
}
$output .= "\n</details>\n";
$targetsCount++;
}
$this->markup = $output;
$this->exportMarkup('targets-list.md');
echo "Generated documentation for " . $targetsCount . " targets in the full list.\n";
} | php | protected function buildMarkupFull()
{
$output = "# Toolkit Phing Targets\n";
$output .= "This is the list of targets provided by toolkit, please note that this is a auto-generated list.\n\n";
$targetsCount = 0;
foreach ($this->targets as $target) {
$detail = $target['description'] ."\n";
$detail .= "\n##### Example:\n";
$detail .= "`toolkit\phing " . $target['name'] . "'\n'";
if (isset($target['properties']) && count($target['properties']) > 0) {
$detail .= "\n##### Properties:\n";
foreach ($target['properties'] as $property) {
$detail .= "* " . $property['name'] . "\n";
}
}
if (isset($target['dependencies']) && count($target['dependencies']) > 0) {
$detail .= "\n##### Dependencies: \n";
foreach ($target['dependencies'] as $callback) {
$detail .= "* " . $callback . "\n";
}
}
$output .= "<details><p><summary>" . $target['name'] . "</summary></p>\n";
if (isset($detail)) {
$output .= $detail;
}
$output .= "\n</details>\n";
$targetsCount++;
}
$this->markup = $output;
$this->exportMarkup('targets-list.md');
echo "Generated documentation for " . $targetsCount . " targets in the full list.\n";
} | [
"protected",
"function",
"buildMarkupFull",
"(",
")",
"{",
"$",
"output",
"=",
"\"# Toolkit Phing Targets\\n\"",
";",
"$",
"output",
".=",
"\"This is the list of targets provided by toolkit, please note that this is a auto-generated list.\\n\\n\"",
";",
"$",
"targetsCount",
"=",
... | Generate full list markup.
@return void | [
"Generate",
"full",
"list",
"markup",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DocGeneratorTask.php#L153-L191 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DocGeneratorTask.php | DocGeneratorTask.exportMarkup | protected function exportMarkup($filename)
{
$file = $this->getProject()->getProperty('project.basedir') . "/docs/" . $filename;
file_put_contents($file, $this->markup);
} | php | protected function exportMarkup($filename)
{
$file = $this->getProject()->getProperty('project.basedir') . "/docs/" . $filename;
file_put_contents($file, $this->markup);
} | [
"protected",
"function",
"exportMarkup",
"(",
"$",
"filename",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getProject",
"(",
")",
"->",
"getProperty",
"(",
"'project.basedir'",
")",
".",
"\"/docs/\"",
".",
"$",
"filename",
";",
"file_put_contents",
"(",
... | Export results to .md file inside docs folder.
@param string $filename Name of the file to store information.
@return void | [
"Export",
"results",
"to",
".",
"md",
"file",
"inside",
"docs",
"folder",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DocGeneratorTask.php#L200-L204 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DocGeneratorTask.php | DocGeneratorTask.parseTargets | protected function parseTargets()
{
$targetsArray = array();
$wrapperTargets = array();
$buildTargets = array();
$callbackTargets = array();
$deprecatedTargets = array();
$helperTargets = array();
$buildList = $this->buildList;
foreach ($buildList as $buildFile => $info) {
$xml = simplexml_load_file($buildFile);
foreach ($xml->xpath('//target') as $target) {
$targetName = (string) $target->attributes()->name;
$targetVisibility = (string) $target->attributes()->hidden == 'true' ? 'hidden' : 'visible';
$targetDescription = (string) $target->attributes()->description;
$targetArray = array(
'name' => $targetName,
'description' => $targetDescription,
'visibility' => $targetVisibility,
'buildfile' => $buildFile,
);
if (strpos($targetName, "build-") === 0) {
$targetDependenciesString = (string) $target->xpath(
'./@depends'
)[0];
$targetDependencies = explode(
',',
str_replace(
' ',
'',
$targetDependenciesString
)
);
$targetDependencies = array_filter($targetDependencies);
sort($targetDependencies);
$callbackTargets = array_merge(
$callbackTargets,
array_values($targetDependencies)
);
$targetArray += array(
'dependencies' => $targetDependencies,
'type' => 'build',
);
if (count($targetDependencies) > 1) {
$targetArray['type'] = 'build';
$buildTargets[] = $targetName;
}
}
if (count($target->xpath('./replacedby')) == 1) {
$replacedBy = (string) $target->xpath(
'./replacedby[1]/@target'
)[0];
$deprecatedTargets[] = $targetName;
$targetArray = array_merge(
$targetArray,
array(
'type' => 'deprecated',
'description' => $replacedBy,
)
);
}
$callbackTargets = array_unique($callbackTargets);
$targetsArray[] = $targetArray;
}//end foreach
}//end foreach
foreach ($targetsArray as $key => $targetArray) {
if (in_array($targetArray['name'], $callbackTargets)
&& !in_array($targetArray['name'], $buildTargets)
) {
$targetsArray[$key]['type'] = 'callback';
} elseif (!isset($targetArray['type'])) {
$targetsArray[$key]['type'] = 'helper';
}
}
sort($targetsArray);
$this->targets = $targetsArray;
} | php | protected function parseTargets()
{
$targetsArray = array();
$wrapperTargets = array();
$buildTargets = array();
$callbackTargets = array();
$deprecatedTargets = array();
$helperTargets = array();
$buildList = $this->buildList;
foreach ($buildList as $buildFile => $info) {
$xml = simplexml_load_file($buildFile);
foreach ($xml->xpath('//target') as $target) {
$targetName = (string) $target->attributes()->name;
$targetVisibility = (string) $target->attributes()->hidden == 'true' ? 'hidden' : 'visible';
$targetDescription = (string) $target->attributes()->description;
$targetArray = array(
'name' => $targetName,
'description' => $targetDescription,
'visibility' => $targetVisibility,
'buildfile' => $buildFile,
);
if (strpos($targetName, "build-") === 0) {
$targetDependenciesString = (string) $target->xpath(
'./@depends'
)[0];
$targetDependencies = explode(
',',
str_replace(
' ',
'',
$targetDependenciesString
)
);
$targetDependencies = array_filter($targetDependencies);
sort($targetDependencies);
$callbackTargets = array_merge(
$callbackTargets,
array_values($targetDependencies)
);
$targetArray += array(
'dependencies' => $targetDependencies,
'type' => 'build',
);
if (count($targetDependencies) > 1) {
$targetArray['type'] = 'build';
$buildTargets[] = $targetName;
}
}
if (count($target->xpath('./replacedby')) == 1) {
$replacedBy = (string) $target->xpath(
'./replacedby[1]/@target'
)[0];
$deprecatedTargets[] = $targetName;
$targetArray = array_merge(
$targetArray,
array(
'type' => 'deprecated',
'description' => $replacedBy,
)
);
}
$callbackTargets = array_unique($callbackTargets);
$targetsArray[] = $targetArray;
}//end foreach
}//end foreach
foreach ($targetsArray as $key => $targetArray) {
if (in_array($targetArray['name'], $callbackTargets)
&& !in_array($targetArray['name'], $buildTargets)
) {
$targetsArray[$key]['type'] = 'callback';
} elseif (!isset($targetArray['type'])) {
$targetsArray[$key]['type'] = 'helper';
}
}
sort($targetsArray);
$this->targets = $targetsArray;
} | [
"protected",
"function",
"parseTargets",
"(",
")",
"{",
"$",
"targetsArray",
"=",
"array",
"(",
")",
";",
"$",
"wrapperTargets",
"=",
"array",
"(",
")",
";",
"$",
"buildTargets",
"=",
"array",
"(",
")",
";",
"$",
"callbackTargets",
"=",
"array",
"(",
"... | Parse .xml files and build target array.
@return void | [
"Parse",
".",
"xml",
"files",
"and",
"build",
"target",
"array",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DocGeneratorTask.php#L266-L349 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhingHelpTask.php | PhingHelpTask.printBuildTargets | protected function printBuildTargets($targets, $buildFile, $buildList)
{
$output = new ConsoleOutput();
$table = new Table($output);
$table->setHeaders(
array(
array(
'Target name',
'Visibility',
'Description',
),
),
array(
new TableCell(
$buildList[$buildFile]['name'],
array('colspan' => 3)
)
)
);
foreach ($targets as $file => $target) {
$hiddenTargets = [
'deprecated',
];
if (!in_array($buildList[$file]['name'], $hiddenTargets)) {
// Clean up target list.
foreach ($target as $key => $value) {
if ($value['visibility'] == 'hidden') {
unset($target[$key]);
}
}
if (count($target) > 0) {
$table->addRows($target);
}
}
}
$table->render();
} | php | protected function printBuildTargets($targets, $buildFile, $buildList)
{
$output = new ConsoleOutput();
$table = new Table($output);
$table->setHeaders(
array(
array(
'Target name',
'Visibility',
'Description',
),
),
array(
new TableCell(
$buildList[$buildFile]['name'],
array('colspan' => 3)
)
)
);
foreach ($targets as $file => $target) {
$hiddenTargets = [
'deprecated',
];
if (!in_array($buildList[$file]['name'], $hiddenTargets)) {
// Clean up target list.
foreach ($target as $key => $value) {
if ($value['visibility'] == 'hidden') {
unset($target[$key]);
}
}
if (count($target) > 0) {
$table->addRows($target);
}
}
}
$table->render();
} | [
"protected",
"function",
"printBuildTargets",
"(",
"$",
"targets",
",",
"$",
"buildFile",
",",
"$",
"buildList",
")",
"{",
"$",
"output",
"=",
"new",
"ConsoleOutput",
"(",
")",
";",
"$",
"table",
"=",
"new",
"Table",
"(",
"$",
"output",
")",
";",
"$",
... | Print Build Targets
@param array $targets Targets
@param array $buildFile Build file name
@param array $buildList Build list
@return void | [
"Print",
"Build",
"Targets"
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhingHelpTask.php#L149-L190 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhingHelpTask.php | PhingHelpTask.getBuildTargets | protected function getBuildTargets($importFile)
{
$targets = array();
// Replace tokens.
if (preg_match_all('/\$\{(.*?)\}/s', $importFile, $matches)) {
foreach ($matches[0] as $key => $match) {
$tokenText = $this->getProject()->getProperty(
$matches[1][$key]
);
$importFile = str_replace($match, $tokenText, $importFile);
}
}
$importFileXml = simplexml_load_file($importFile);
foreach ($importFileXml->xpath('//target') as $target) {
$targetName = (string) $target->attributes()->name;
$targetVisibility = (string) $target->attributes()->hidden == 'true' ? 'hidden' : 'visible';
$targetDescription = (string) $target->attributes()->description;
$targets[$importFile][] = array(
'name' => $targetName,
'visibility' => $targetVisibility,
'description' => $targetDescription,
);
}
return $targets;
} | php | protected function getBuildTargets($importFile)
{
$targets = array();
// Replace tokens.
if (preg_match_all('/\$\{(.*?)\}/s', $importFile, $matches)) {
foreach ($matches[0] as $key => $match) {
$tokenText = $this->getProject()->getProperty(
$matches[1][$key]
);
$importFile = str_replace($match, $tokenText, $importFile);
}
}
$importFileXml = simplexml_load_file($importFile);
foreach ($importFileXml->xpath('//target') as $target) {
$targetName = (string) $target->attributes()->name;
$targetVisibility = (string) $target->attributes()->hidden == 'true' ? 'hidden' : 'visible';
$targetDescription = (string) $target->attributes()->description;
$targets[$importFile][] = array(
'name' => $targetName,
'visibility' => $targetVisibility,
'description' => $targetDescription,
);
}
return $targets;
} | [
"protected",
"function",
"getBuildTargets",
"(",
"$",
"importFile",
")",
"{",
"$",
"targets",
"=",
"array",
"(",
")",
";",
"// Replace tokens.",
"if",
"(",
"preg_match_all",
"(",
"'/\\$\\{(.*?)\\}/s'",
",",
"$",
"importFile",
",",
"$",
"matches",
")",
")",
"... | Helper function to get the targets out of file.
@param string $importFile File to import
@return array | [
"Helper",
"function",
"to",
"get",
"the",
"targets",
"out",
"of",
"file",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhingHelpTask.php#L200-L231 | train |
ec-europa/toolkit | includes/phing/src/Tasks/PhingHelpTask.php | PhingHelpTask.getBuildList | public function getBuildList(
$buildFile,
$level = 0,
$parent = '',
&$buildList = array()
) {
if (is_file($buildFile)) {
$buildFileXml = simplexml_load_file($buildFile);
$buildFileName = $buildFileXml->xpath('//project/@name');
$buildFileDescription = $buildFileXml->xpath('//project/@description');
if (isset($buildFileName[0]) && isset($buildFileDescription[0])) {
$buildList[$buildFile] = array(
'level' => $level,
'parent' => $parent,
'name' => (string) $buildFileName[0],
'description' => (string) $buildFileDescription[0],
);
foreach ($buildFileXml->xpath('//import[@file]') as $import) {
$importFile = (string) $import->attributes()->file;
// Replace tokens.
if (preg_match_all('/\$\{(.*?)\}/s', $importFile, $matches)) {
foreach ($matches[0] as $key => $match) {
if (is_object($this->getProject())) {
$tokenText = $this->getProject()->getProperty(
$matches[1][$key]
);
$importFile = str_replace(
$match,
$tokenText,
$importFile
);
}
}
}
PhingHelpTask::getBuildList(
$importFile,
($level + 1),
$buildFile,
$buildList
);
}
}//end if
return $buildList;
}//end if
} | php | public function getBuildList(
$buildFile,
$level = 0,
$parent = '',
&$buildList = array()
) {
if (is_file($buildFile)) {
$buildFileXml = simplexml_load_file($buildFile);
$buildFileName = $buildFileXml->xpath('//project/@name');
$buildFileDescription = $buildFileXml->xpath('//project/@description');
if (isset($buildFileName[0]) && isset($buildFileDescription[0])) {
$buildList[$buildFile] = array(
'level' => $level,
'parent' => $parent,
'name' => (string) $buildFileName[0],
'description' => (string) $buildFileDescription[0],
);
foreach ($buildFileXml->xpath('//import[@file]') as $import) {
$importFile = (string) $import->attributes()->file;
// Replace tokens.
if (preg_match_all('/\$\{(.*?)\}/s', $importFile, $matches)) {
foreach ($matches[0] as $key => $match) {
if (is_object($this->getProject())) {
$tokenText = $this->getProject()->getProperty(
$matches[1][$key]
);
$importFile = str_replace(
$match,
$tokenText,
$importFile
);
}
}
}
PhingHelpTask::getBuildList(
$importFile,
($level + 1),
$buildFile,
$buildList
);
}
}//end if
return $buildList;
}//end if
} | [
"public",
"function",
"getBuildList",
"(",
"$",
"buildFile",
",",
"$",
"level",
"=",
"0",
",",
"$",
"parent",
"=",
"''",
",",
"&",
"$",
"buildList",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"buildFile",
")",
")",
"{",
"$"... | Helper function to get the full list of buildfiles through imports.
@param string $buildFile Build file
@param int $level Level
@param string $parent Parent
@param array $buildList Build list
@return array | [
"Helper",
"function",
"to",
"get",
"the",
"full",
"list",
"of",
"buildfiles",
"through",
"imports",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/PhingHelpTask.php#L244-L295 | train |
ec-europa/toolkit | includes/phing/src/Tasks/SymlinkPropertyContentTask.php | SymlinkPropertyContentTask.symlink | protected function symlink($targetPath, $link, $logShort = false)
{
parent::symlink($targetPath, $link, $logShort);
} | php | protected function symlink($targetPath, $link, $logShort = false)
{
parent::symlink($targetPath, $link, $logShort);
} | [
"protected",
"function",
"symlink",
"(",
"$",
"targetPath",
",",
"$",
"link",
",",
"$",
"logShort",
"=",
"false",
")",
"{",
"parent",
"::",
"symlink",
"(",
"$",
"targetPath",
",",
"$",
"link",
",",
"$",
"logShort",
")",
";",
"}"
] | Create symlink for a specified target and text.
@param string $targetPath Target of symlink
@param string $link Symlink
@param bool $logShort Log short
@return void | [
"Create",
"symlink",
"for",
"a",
"specified",
"target",
"and",
"text",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/SymlinkPropertyContentTask.php#L308-L311 | train |
ec-europa/toolkit | includes/phing/src/Tasks/SymlinkPropertyContentTask.php | SymlinkPropertyContentTask._failOnErrorAction | private function _failOnErrorAction(Exception $exception = null, $message = '', $level = Project::MSG_INFO)
{
if ($this->_failonerror) {
throw new BuildException(
$exception !== null ? $exception : $message,
$this->getLocation()
);
} else {
$this->log(
$exception !== null && $message === '' ? $exception->getMessage() : $message,
$level
);
}
} | php | private function _failOnErrorAction(Exception $exception = null, $message = '', $level = Project::MSG_INFO)
{
if ($this->_failonerror) {
throw new BuildException(
$exception !== null ? $exception : $message,
$this->getLocation()
);
} else {
$this->log(
$exception !== null && $message === '' ? $exception->getMessage() : $message,
$level
);
}
} | [
"private",
"function",
"_failOnErrorAction",
"(",
"Exception",
"$",
"exception",
"=",
"null",
",",
"$",
"message",
"=",
"''",
",",
"$",
"level",
"=",
"Project",
"::",
"MSG_INFO",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_failonerror",
")",
"{",
"throw",
... | Throw exception if error found.
@param Exception $exception Exception to throw
@param string $message Message to display
@param int $level Exception level
@throws BuildException
@return void | [
"Throw",
"exception",
"if",
"error",
"found",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/SymlinkPropertyContentTask.php#L368-L381 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DrushGenerateAliasTask.php | DrushGenerateAliasTask.main | public function main()
{
// Check if all required data is present.
$this->checkRequirements();
if ($this->_drushDir == '/sites/all/drush') {
$drushDir = $this->_siteRoot.$this->_drushDir;
} else {
$drushDir = $this->_drushDir;
}
$aliasesFile = $drushDir.'/aliases.drushrc.php';
$aliases = array(
'default' => array(
'uri' => $this->_siteUrl,
'root' => $this->_siteRoot,
),
'docker' => array(
'uri' => $this->_siteUrl,
'root' => $this->_siteRoot,
),
);
if (empty($this->_aliasName)) {
$sites = new Finder();
$sites
->directories()
->depth('== 0')
->exclude('all')
->in($this->_siteRoot.'/sites');
foreach ($sites as $site) {
$aliases[$site->getBasename()] = array(
'uri' => $this->_siteUrl,
'root' => $aliases['default']['root'],
);
}
} else {
$aliases += $this->loadAliases($aliasesFile);
$aliases[$this->_aliasName] = array(
'uri' => $this->_siteUrl,
'root' => $aliases['default']['root'],
);
}//end if
$aliasesArray = "<?php \n\n\$aliases = ".var_export($aliases, true).";";
if (file_put_contents($aliasesFile, $aliasesArray)) {
$this->log(
"Succesfully wrote aliases to file '".$aliasesFile."'",
Project::MSG_INFO
);
} else {
$this->log(
"Was unable to write aliases to file '".$aliasesFile."'",
Project::MSG_WARN
);
}
} | php | public function main()
{
// Check if all required data is present.
$this->checkRequirements();
if ($this->_drushDir == '/sites/all/drush') {
$drushDir = $this->_siteRoot.$this->_drushDir;
} else {
$drushDir = $this->_drushDir;
}
$aliasesFile = $drushDir.'/aliases.drushrc.php';
$aliases = array(
'default' => array(
'uri' => $this->_siteUrl,
'root' => $this->_siteRoot,
),
'docker' => array(
'uri' => $this->_siteUrl,
'root' => $this->_siteRoot,
),
);
if (empty($this->_aliasName)) {
$sites = new Finder();
$sites
->directories()
->depth('== 0')
->exclude('all')
->in($this->_siteRoot.'/sites');
foreach ($sites as $site) {
$aliases[$site->getBasename()] = array(
'uri' => $this->_siteUrl,
'root' => $aliases['default']['root'],
);
}
} else {
$aliases += $this->loadAliases($aliasesFile);
$aliases[$this->_aliasName] = array(
'uri' => $this->_siteUrl,
'root' => $aliases['default']['root'],
);
}//end if
$aliasesArray = "<?php \n\n\$aliases = ".var_export($aliases, true).";";
if (file_put_contents($aliasesFile, $aliasesArray)) {
$this->log(
"Succesfully wrote aliases to file '".$aliasesFile."'",
Project::MSG_INFO
);
} else {
$this->log(
"Was unable to write aliases to file '".$aliasesFile."'",
Project::MSG_WARN
);
}
} | [
"public",
"function",
"main",
"(",
")",
"{",
"// Check if all required data is present.",
"$",
"this",
"->",
"checkRequirements",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_drushDir",
"==",
"'/sites/all/drush'",
")",
"{",
"$",
"drushDir",
"=",
"$",
"this",... | Generates an aliases.drushrc.php file.
Either generates a file for:
- all sites in the sites directory.
- a single site to be added to the aliases file (appending).
@return void | [
"Generates",
"an",
"aliases",
".",
"drushrc",
".",
"php",
"file",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DrushGenerateAliasTask.php#L79-L138 | train |
ec-europa/toolkit | includes/phing/src/Tasks/GitignoreMergerTask.php | GitignoreMergerTask.setGitignoreFiles | public function setGitignoreFiles($gitignoreFiles)
{
$this->gitignoreFiles = array();
$token = ' ,;';
$file = strtok($gitignoreFiles, $token);
while ($file !== false) {
$this->gitignoreFiles[] = $file;
$file = strtok($token);
}
} | php | public function setGitignoreFiles($gitignoreFiles)
{
$this->gitignoreFiles = array();
$token = ' ,;';
$file = strtok($gitignoreFiles, $token);
while ($file !== false) {
$this->gitignoreFiles[] = $file;
$file = strtok($token);
}
} | [
"public",
"function",
"setGitignoreFiles",
"(",
"$",
"gitignoreFiles",
")",
"{",
"$",
"this",
"->",
"gitignoreFiles",
"=",
"array",
"(",
")",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"file",
"=",
"strtok",
"(",
"$",
"gitignoreFiles",
",",
"$",
"token",... | Sets the list gitignore gitignoreFiles to merge.
@param string $gitignoreFiles list of ignore files to be merged
@return void | [
"Sets",
"the",
"list",
"gitignore",
"gitignoreFiles",
"to",
"merge",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/GitignoreMergerTask.php#L46-L57 | train |
ec-europa/toolkit | includes/phing/src/Tasks/DrushMakeSecureTask.php | DrushMakeSecureTask.setFailOn | public function setFailOn($failOn)
{
$this->_failOn = [];
$token = ' ,;';
$fail = strtok($failOn, $token);
while ($fail !== false) {
$this->_failOn[] = $fail;
$fail = strtok($token);
}
} | php | public function setFailOn($failOn)
{
$this->_failOn = [];
$token = ' ,;';
$fail = strtok($failOn, $token);
while ($fail !== false) {
$this->_failOn[] = $fail;
$fail = strtok($token);
}
} | [
"public",
"function",
"setFailOn",
"(",
"$",
"failOn",
")",
"{",
"$",
"this",
"->",
"_failOn",
"=",
"[",
"]",
";",
"$",
"token",
"=",
"' ,;'",
";",
"$",
"fail",
"=",
"strtok",
"(",
"$",
"failOn",
",",
"$",
"token",
")",
";",
"while",
"(",
"$",
... | Fail on insecure projects. Can be revoked or not-covered.
@param bool $failOn Flag
@return void | [
"Fail",
"on",
"insecure",
"projects",
".",
"Can",
"be",
"revoked",
"or",
"not",
"-",
"covered",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/DrushMakeSecureTask.php#L207-L218 | train |
ec-europa/toolkit | includes/phing/src/Tasks/RelativeSymlinkTask.php | RelativeSymlinkTask.symlink | protected function symlink($target, $link, $logShort = false)
{
$fs = FileSystem::getFileSystem();
// Convert target to relative path.
$absolutePath = (new PhingFile($link))->getAbsolutePath();
$link = $absolutePath;
if ($logShort) {
$relativePath = str_replace(
$this->getProject()->getBaseDir(),
"", $absolutePath
);
$linkName = basename($absolutePath);
} else {
$linkName = $link;
}
// @codingStandardsIgnoreLine: MULTISITE-17111
$target = rtrim(
$this->makePathRelative($target, dirname($link)),
'/'
);
if (is_link($link) && @readlink($link) == $target) {
$this->log('Link exists: '.$linkName, Project::MSG_INFO);
return true;
}
if (file_exists($link) || is_link($link)) {
if (!$this->getOverwrite()) {
$this->log(
'Not overwriting existing link '.$link,
Project::MSG_ERR
);
return false;
}
if (is_link($link) || is_file($link)) {
$fs->unlink($link);
$this->log(
'Link removed: '.$linkName,
Project::MSG_INFO
);
} else {
$fs->rmdir($link, true);
$this->log(
'Directory removed: '.$linkName,
Project::MSG_INFO
);
}
}
$this->log('Linking: '.$linkName.' to '.$target, Project::MSG_INFO);
return $fs->symlink($target, $link);
} | php | protected function symlink($target, $link, $logShort = false)
{
$fs = FileSystem::getFileSystem();
// Convert target to relative path.
$absolutePath = (new PhingFile($link))->getAbsolutePath();
$link = $absolutePath;
if ($logShort) {
$relativePath = str_replace(
$this->getProject()->getBaseDir(),
"", $absolutePath
);
$linkName = basename($absolutePath);
} else {
$linkName = $link;
}
// @codingStandardsIgnoreLine: MULTISITE-17111
$target = rtrim(
$this->makePathRelative($target, dirname($link)),
'/'
);
if (is_link($link) && @readlink($link) == $target) {
$this->log('Link exists: '.$linkName, Project::MSG_INFO);
return true;
}
if (file_exists($link) || is_link($link)) {
if (!$this->getOverwrite()) {
$this->log(
'Not overwriting existing link '.$link,
Project::MSG_ERR
);
return false;
}
if (is_link($link) || is_file($link)) {
$fs->unlink($link);
$this->log(
'Link removed: '.$linkName,
Project::MSG_INFO
);
} else {
$fs->rmdir($link, true);
$this->log(
'Directory removed: '.$linkName,
Project::MSG_INFO
);
}
}
$this->log('Linking: '.$linkName.' to '.$target, Project::MSG_INFO);
return $fs->symlink($target, $link);
} | [
"protected",
"function",
"symlink",
"(",
"$",
"target",
",",
"$",
"link",
",",
"$",
"logShort",
"=",
"false",
")",
"{",
"$",
"fs",
"=",
"FileSystem",
"::",
"getFileSystem",
"(",
")",
";",
"// Convert target to relative path.",
"$",
"absolutePath",
"=",
"(",
... | Create the Symlink.
@param string $target Symlink target
@param string $link Symlink name
@param string bool $logShort Control type of link
@return bool | [
"Create",
"the",
"Symlink",
"."
] | 8048cbd8925b31dfb49fe4d35caa011ad34fe758 | https://github.com/ec-europa/toolkit/blob/8048cbd8925b31dfb49fe4d35caa011ad34fe758/includes/phing/src/Tasks/RelativeSymlinkTask.php#L91-L150 | train |
Freemius/wordpress-sdk | includes/entities/class-fs-entity.php | FS_Entity.update | function update( $key, $val = false ) {
if ( ! is_array( $key ) ) {
$key = array( $key => $val );
}
$is_updated = false;
foreach ( $key as $k => $v ) {
if ( $this->{$k} === $v ) {
continue;
}
if ( ( is_string( $this->{$k} ) && is_numeric( $v ) ||
( is_numeric( $this->{$k} ) && is_string( $v ) ) ) &&
$this->{$k} == $v
) {
continue;
}
// Update value.
$this->{$k} = $v;
$is_updated = true;
}
$this->_is_updated = $is_updated;
return $is_updated;
} | php | function update( $key, $val = false ) {
if ( ! is_array( $key ) ) {
$key = array( $key => $val );
}
$is_updated = false;
foreach ( $key as $k => $v ) {
if ( $this->{$k} === $v ) {
continue;
}
if ( ( is_string( $this->{$k} ) && is_numeric( $v ) ||
( is_numeric( $this->{$k} ) && is_string( $v ) ) ) &&
$this->{$k} == $v
) {
continue;
}
// Update value.
$this->{$k} = $v;
$is_updated = true;
}
$this->_is_updated = $is_updated;
return $is_updated;
} | [
"function",
"update",
"(",
"$",
"key",
",",
"$",
"val",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"array",
"(",
"$",
"key",
"=>",
"$",
"val",
")",
";",
"}",
"$",
"is_updated",
"=",
... | Update object property.
@author Vova Feldman (@svovaf)
@since 1.0.9
@param string|array[string]mixed $key
@param string|bool $val
@return bool | [
"Update",
"object",
"property",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/entities/class-fs-entity.php#L96-L124 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-gdpr-manager.php | FS_GDPR_Manager.update_option | private function update_option( $name, $value ) {
$this->_data[ $name ] = $value;
$this->_storage->set_option( $this->_option_name, $this->_data, true );
} | php | private function update_option( $name, $value ) {
$this->_data[ $name ] = $value;
$this->_storage->set_option( $this->_option_name, $this->_data, true );
} | [
"private",
"function",
"update_option",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_data",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"_storage",
"->",
"set_option",
"(",
"$",
"this",
"->",
"_option_name... | Update a GDPR option for the current admin and store it.
@author Vova Feldman (@svovaf)
@since 2.1.0
@param string $name
@param mixed $value | [
"Update",
"a",
"GDPR",
"option",
"for",
"the",
"current",
"admin",
"and",
"store",
"it",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-gdpr-manager.php#L82-L86 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-plugin-manager.php | FS_Plugin_Manager.store | function store( $module = false, $flush = true ) {
if ( false !== $module ) {
$this->_module = $module;
}
$all_modules = $this->get_all_modules( $this->_module->type );
$all_modules[ $this->_module->slug ] = $this->_module;
$options_manager = $this->get_option_manager();
$options_manager->set_option( $this->_module->type . 's', $all_modules, $flush );
return $this->_module;
} | php | function store( $module = false, $flush = true ) {
if ( false !== $module ) {
$this->_module = $module;
}
$all_modules = $this->get_all_modules( $this->_module->type );
$all_modules[ $this->_module->slug ] = $this->_module;
$options_manager = $this->get_option_manager();
$options_manager->set_option( $this->_module->type . 's', $all_modules, $flush );
return $this->_module;
} | [
"function",
"store",
"(",
"$",
"module",
"=",
"false",
",",
"$",
"flush",
"=",
"true",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"module",
")",
"{",
"$",
"this",
"->",
"_module",
"=",
"$",
"module",
";",
"}",
"$",
"all_modules",
"=",
"$",
"this",... | Store plugin on local DB.
@author Vova Feldman (@svovaf)
@since 1.0.6
@param bool|FS_Plugin $module
@param bool $flush
@return bool|\FS_Plugin | [
"Store",
"plugin",
"on",
"local",
"DB",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-plugin-manager.php#L151-L163 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-plugin-manager.php | FS_Plugin_Manager.update | function update( FS_Plugin $plugin, $store = true ) {
if ( ! ($this->_module instanceof FS_Plugin ) ||
$this->_module->slug != $plugin->slug ||
$this->_module->public_key != $plugin->public_key ||
$this->_module->secret_key != $plugin->secret_key ||
$this->_module->parent_plugin_id != $plugin->parent_plugin_id ||
$this->_module->title != $plugin->title
) {
$this->store( $plugin, $store );
return true;
}
return false;
} | php | function update( FS_Plugin $plugin, $store = true ) {
if ( ! ($this->_module instanceof FS_Plugin ) ||
$this->_module->slug != $plugin->slug ||
$this->_module->public_key != $plugin->public_key ||
$this->_module->secret_key != $plugin->secret_key ||
$this->_module->parent_plugin_id != $plugin->parent_plugin_id ||
$this->_module->title != $plugin->title
) {
$this->store( $plugin, $store );
return true;
}
return false;
} | [
"function",
"update",
"(",
"FS_Plugin",
"$",
"plugin",
",",
"$",
"store",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"_module",
"instanceof",
"FS_Plugin",
")",
"||",
"$",
"this",
"->",
"_module",
"->",
"slug",
"!=",
"$",
"plugin",... | Update local plugin data if different.
@author Vova Feldman (@svovaf)
@since 1.0.6
@param \FS_Plugin $plugin
@param bool $store
@return bool True if plugin was updated. | [
"Update",
"local",
"plugin",
"data",
"if",
"different",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-plugin-manager.php#L176-L190 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-key-value-storage.php | FS_Key_Value_Storage.delete | function delete() {
$this->_data = array();
$all_data = $this->get_all_data();
unset( $all_data[ $this->_secondary_id ] );
$options_manager = $this->get_option_manager();
$options_manager->set_option( $this->_id, $all_data, true );
} | php | function delete() {
$this->_data = array();
$all_data = $this->get_all_data();
unset( $all_data[ $this->_secondary_id ] );
$options_manager = $this->get_option_manager();
$options_manager->set_option( $this->_id, $all_data, true );
} | [
"function",
"delete",
"(",
")",
"{",
"$",
"this",
"->",
"_data",
"=",
"array",
"(",
")",
";",
"$",
"all_data",
"=",
"$",
"this",
"->",
"get_all_data",
"(",
")",
";",
"unset",
"(",
"$",
"all_data",
"[",
"$",
"this",
"->",
"_secondary_id",
"]",
")",
... | Delete key-value storage.
@author Vova Feldman (@svovaf)
@since 1.0.9 | [
"Delete",
"key",
"-",
"value",
"storage",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-key-value-storage.php#L226-L233 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-cache-manager.php | FS_Cache_Manager.has | function has( $key ) {
$cache_entry = $this->_options->get_option( $key, false );
return ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
);
} | php | function has( $key ) {
$cache_entry = $this->_options->get_option( $key, false );
return ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
);
} | [
"function",
"has",
"(",
"$",
"key",
")",
"{",
"$",
"cache_entry",
"=",
"$",
"this",
"->",
"_options",
"->",
"get_option",
"(",
"$",
"key",
",",
"false",
")",
";",
"return",
"(",
"is_object",
"(",
"$",
"cache_entry",
")",
"&&",
"isset",
"(",
"$",
"c... | Check if there's a cached item.
@author Vova Feldman (@svovaf)
@since 1.1.6
@param string $key
@return bool | [
"Check",
"if",
"there",
"s",
"a",
"cached",
"item",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-cache-manager.php#L103-L110 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-cache-manager.php | FS_Cache_Manager.has_valid | function has_valid( $key, $expiration = null ) {
$cache_entry = $this->_options->get_option( $key, false );
$is_valid = ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp ) &&
$cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
);
if ( $is_valid &&
is_numeric( $expiration ) &&
isset( $cache_entry->created ) &&
is_numeric( $cache_entry->created ) &&
$cache_entry->created + $expiration < WP_FS__SCRIPT_START_TIME
) {
/**
* Even if the cache is still valid, since we are checking for validity
* with an explicit expiration period, if the period has past, return
* `false` as if the cache is invalid.
*
* @since 1.2.2.7
*/
$is_valid = false;
}
return $is_valid;
} | php | function has_valid( $key, $expiration = null ) {
$cache_entry = $this->_options->get_option( $key, false );
$is_valid = ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp ) &&
$cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
);
if ( $is_valid &&
is_numeric( $expiration ) &&
isset( $cache_entry->created ) &&
is_numeric( $cache_entry->created ) &&
$cache_entry->created + $expiration < WP_FS__SCRIPT_START_TIME
) {
/**
* Even if the cache is still valid, since we are checking for validity
* with an explicit expiration period, if the period has past, return
* `false` as if the cache is invalid.
*
* @since 1.2.2.7
*/
$is_valid = false;
}
return $is_valid;
} | [
"function",
"has_valid",
"(",
"$",
"key",
",",
"$",
"expiration",
"=",
"null",
")",
"{",
"$",
"cache_entry",
"=",
"$",
"this",
"->",
"_options",
"->",
"get_option",
"(",
"$",
"key",
",",
"false",
")",
";",
"$",
"is_valid",
"=",
"(",
"is_object",
"(",... | Check if there's a valid cached item.
@author Vova Feldman (@svovaf)
@since 1.1.6
@param string $key
@param null|int $expiration Since 1.2.2.7
@return bool | [
"Check",
"if",
"there",
"s",
"a",
"valid",
"cached",
"item",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-cache-manager.php#L123-L149 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-cache-manager.php | FS_Cache_Manager.get_record_expiration | function get_record_expiration( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp ) &&
$cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
) {
return $cache_entry->timestamp;
}
return false;
} | php | function get_record_expiration( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp ) &&
$cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
) {
return $cache_entry->timestamp;
}
return false;
} | [
"function",
"get_record_expiration",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
"'key = '",
".",
"$",
"key",
")",
";",
"$",
"cache_entry",
"=",
"$",
"this",
"->",
"_options",
"->",
"get_option",
"(",
"$",
"key",
","... | Get cached record expiration, or false if not cached or expired.
@author Vova Feldman (@svovaf)
@since 1.1.7.3
@param string $key
@return bool|int | [
"Get",
"cached",
"record",
"expiration",
"or",
"false",
"if",
"not",
"cached",
"or",
"expired",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-cache-manager.php#L230-L244 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-cache-manager.php | FS_Cache_Manager.purge | function purge( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$this->_options->unset_option( $key, true );
} | php | function purge( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$this->_options->unset_option( $key, true );
} | [
"function",
"purge",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
"'key = '",
".",
"$",
"key",
")",
";",
"$",
"this",
"->",
"_options",
"->",
"unset_option",
"(",
"$",
"key",
",",
"true",
")",
";",
"}"
] | Purge cached item.
@author Vova Feldman (@svovaf)
@since 1.1.6
@param string $key | [
"Purge",
"cached",
"item",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-cache-manager.php#L254-L258 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-cache-manager.php | FS_Cache_Manager.update_expiration | function update_expiration( $key, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( ! is_object( $cache_entry ) ||
! isset( $cache_entry->timestamp ) ||
! is_numeric( $cache_entry->timestamp )
) {
return false;
}
$this->set( $key, $cache_entry->result, $expiration, $cache_entry->created );
return true;
} | php | function update_expiration( $key, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( ! is_object( $cache_entry ) ||
! isset( $cache_entry->timestamp ) ||
! is_numeric( $cache_entry->timestamp )
) {
return false;
}
$this->set( $key, $cache_entry->result, $expiration, $cache_entry->created );
return true;
} | [
"function",
"update_expiration",
"(",
"$",
"key",
",",
"$",
"expiration",
"=",
"WP_FS__TIME_24_HOURS_IN_SEC",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
"'key = '",
".",
"$",
"key",
")",
";",
"$",
"cache_entry",
"=",
"$",
"this",
"->",
... | Extend cached item caching period.
@author Vova Feldman (@svovaf)
@since 2.0.0
@param string $key
@param int $expiration
@return bool | [
"Extend",
"cached",
"item",
"caching",
"period",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-cache-manager.php#L271-L286 | train |
Freemius/wordpress-sdk | includes/managers/class-fs-cache-manager.php | FS_Cache_Manager.expire | function expire( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
) {
// Set to expired.
$cache_entry->timestamp = WP_FS__SCRIPT_START_TIME;
$this->_options->set_option( $key, $cache_entry, true );
}
} | php | function expire( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
) {
// Set to expired.
$cache_entry->timestamp = WP_FS__SCRIPT_START_TIME;
$this->_options->set_option( $key, $cache_entry, true );
}
} | [
"function",
"expire",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
"'key = '",
".",
"$",
"key",
")",
";",
"$",
"cache_entry",
"=",
"$",
"this",
"->",
"_options",
"->",
"get_option",
"(",
"$",
"key",
",",
"false",
... | Set cached item as expired.
@author Vova Feldman (@svovaf)
@since 1.2.2.7
@param string $key | [
"Set",
"cached",
"item",
"as",
"expired",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/managers/class-fs-cache-manager.php#L296-L309 | train |
Freemius/wordpress-sdk | includes/sdk/FreemiusWordPress.php | Freemius_Api_WordPress.FindClockDiff | public static function FindClockDiff() {
$time = time();
$pong = self::Ping();
return ( $time - strtotime( $pong->timestamp ) );
} | php | public static function FindClockDiff() {
$time = time();
$pong = self::Ping();
return ( $time - strtotime( $pong->timestamp ) );
} | [
"public",
"static",
"function",
"FindClockDiff",
"(",
")",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"pong",
"=",
"self",
"::",
"Ping",
"(",
")",
";",
"return",
"(",
"$",
"time",
"-",
"strtotime",
"(",
"$",
"pong",
"->",
"timestamp",
")",
... | Find clock diff between current server to API server.
@since 1.0.2
@return int Clock diff in seconds. | [
"Find",
"clock",
"diff",
"between",
"current",
"server",
"to",
"API",
"server",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/sdk/FreemiusWordPress.php#L140-L145 | train |
Freemius/wordpress-sdk | includes/sdk/FreemiusWordPress.php | Freemius_Api_WordPress.GetSignedUrl | function GetSignedUrl( $pPath ) {
$resource = explode( '?', $this->CanonizePath( $pPath ) );
$pResourceUrl = $resource[0];
$auth = $this->GenerateAuthorizationParams( $pResourceUrl );
return Freemius_Api_WordPress::GetUrl(
$pResourceUrl . '?' .
( 1 < count( $resource ) && ! empty( $resource[1] ) ? $resource[1] . '&' : '' ) .
'authorization=' . urlencode( $auth['authorization'] ) .
'&auth_date=' . urlencode( $auth['date'] )
, $this->_isSandbox );
} | php | function GetSignedUrl( $pPath ) {
$resource = explode( '?', $this->CanonizePath( $pPath ) );
$pResourceUrl = $resource[0];
$auth = $this->GenerateAuthorizationParams( $pResourceUrl );
return Freemius_Api_WordPress::GetUrl(
$pResourceUrl . '?' .
( 1 < count( $resource ) && ! empty( $resource[1] ) ? $resource[1] . '&' : '' ) .
'authorization=' . urlencode( $auth['authorization'] ) .
'&auth_date=' . urlencode( $auth['date'] )
, $this->_isSandbox );
} | [
"function",
"GetSignedUrl",
"(",
"$",
"pPath",
")",
"{",
"$",
"resource",
"=",
"explode",
"(",
"'?'",
",",
"$",
"this",
"->",
"CanonizePath",
"(",
"$",
"pPath",
")",
")",
";",
"$",
"pResourceUrl",
"=",
"$",
"resource",
"[",
"0",
"]",
";",
"$",
"aut... | Get API request URL signed via query string.
@since 1.2.3 Stopped using http_build_query(). Instead, use urlencode(). In some environments the encoding of http_build_query() can generate a URL that once used with a redirect, the `&` querystring separator is escaped to `&` which breaks the URL (Added by @svovaf).
@param string $pPath
@throws Freemius_Exception
@return string | [
"Get",
"API",
"request",
"URL",
"signed",
"via",
"query",
"string",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/sdk/FreemiusWordPress.php#L275-L287 | train |
Freemius/wordpress-sdk | includes/sdk/FreemiusWordPress.php | Freemius_Api_WordPress.Ping | public static function Ping() {
try {
$result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
} catch ( Freemius_Exception $e ) {
// Map to error object.
$result = (object) $e->getResult();
} catch ( Exception $e ) {
// Map to error object.
$result = (object) array(
'error' => array(
'type' => 'Unknown',
'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
'code' => 'unknown',
'http' => 402
)
);
}
return $result;
} | php | public static function Ping() {
try {
$result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
} catch ( Freemius_Exception $e ) {
// Map to error object.
$result = (object) $e->getResult();
} catch ( Exception $e ) {
// Map to error object.
$result = (object) array(
'error' => array(
'type' => 'Unknown',
'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
'code' => 'unknown',
'http' => 402
)
);
}
return $result;
} | [
"public",
"static",
"function",
"Ping",
"(",
")",
"{",
"try",
"{",
"$",
"result",
"=",
"self",
"::",
"MakeStaticRequest",
"(",
"'/v'",
".",
"FS_API__VERSION",
".",
"'/ping.json'",
")",
";",
"}",
"catch",
"(",
"Freemius_Exception",
"$",
"e",
")",
"{",
"//... | Ping API to test connectivity.
@return object | [
"Ping",
"API",
"to",
"test",
"connectivity",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/sdk/FreemiusWordPress.php#L564-L583 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api._sync_clock_diff | private function _sync_clock_diff( $diff = false ) {
$this->_logger->entrance();
// Sync clock and store.
$new_clock_diff = ( false === $diff ) ?
Freemius_Api_WordPress::FindClockDiff() :
$diff;
if ( $new_clock_diff === self::$_clock_diff ) {
return false;
}
self::$_clock_diff = $new_clock_diff;
// Update API clock's diff.
Freemius_Api_WordPress::SetClockDiff( self::$_clock_diff );
// Store new clock diff in storage.
self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
return $new_clock_diff;
} | php | private function _sync_clock_diff( $diff = false ) {
$this->_logger->entrance();
// Sync clock and store.
$new_clock_diff = ( false === $diff ) ?
Freemius_Api_WordPress::FindClockDiff() :
$diff;
if ( $new_clock_diff === self::$_clock_diff ) {
return false;
}
self::$_clock_diff = $new_clock_diff;
// Update API clock's diff.
Freemius_Api_WordPress::SetClockDiff( self::$_clock_diff );
// Store new clock diff in storage.
self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
return $new_clock_diff;
} | [
"private",
"function",
"_sync_clock_diff",
"(",
"$",
"diff",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"// Sync clock and store.\r",
"$",
"new_clock_diff",
"=",
"(",
"false",
"===",
"$",
"diff",
")",
"?",
"Freem... | Find clock diff between server and API server, and store the diff locally.
@param bool|int $diff
@return bool|int False if clock diff didn't change, otherwise returns the clock diff in seconds. | [
"Find",
"clock",
"diff",
"between",
"server",
"and",
"API",
"server",
"and",
"store",
"the",
"diff",
"locally",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L123-L144 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api._call | private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
$this->_logger->entrance( $method . ':' . $path );
if ( self::is_temporary_down() ) {
$result = $this->get_temporary_unavailable_error();
} else {
$result = $this->_api->Api( $path, $method, $params );
if ( null !== $result &&
isset( $result->error ) &&
isset( $result->error->code ) &&
'request_expired' === $result->error->code
) {
if ( ! $retry ) {
$diff = isset( $result->error->timestamp ) ?
( time() - strtotime( $result->error->timestamp ) ) :
false;
// Try to sync clock diff.
if ( false !== $this->_sync_clock_diff( $diff ) ) {
// Retry call with new synced clock.
return $this->_call( $path, $method, $params, true );
}
}
}
}
if ( $this->_logger->is_on() && self::is_api_error( $result ) ) {
// Log API errors.
$this->_logger->api_error( $result );
}
return $result;
} | php | private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
$this->_logger->entrance( $method . ':' . $path );
if ( self::is_temporary_down() ) {
$result = $this->get_temporary_unavailable_error();
} else {
$result = $this->_api->Api( $path, $method, $params );
if ( null !== $result &&
isset( $result->error ) &&
isset( $result->error->code ) &&
'request_expired' === $result->error->code
) {
if ( ! $retry ) {
$diff = isset( $result->error->timestamp ) ?
( time() - strtotime( $result->error->timestamp ) ) :
false;
// Try to sync clock diff.
if ( false !== $this->_sync_clock_diff( $diff ) ) {
// Retry call with new synced clock.
return $this->_call( $path, $method, $params, true );
}
}
}
}
if ( $this->_logger->is_on() && self::is_api_error( $result ) ) {
// Log API errors.
$this->_logger->api_error( $result );
}
return $result;
} | [
"private",
"function",
"_call",
"(",
"$",
"path",
",",
"$",
"method",
"=",
"'GET'",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"retry",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
"$",
"method",
".",
"'... | Override API call to enable retry with servers' clock auto sync method.
@param string $path
@param string $method
@param array $params
@param bool $retry Is in retry or first call attempt.
@return array|mixed|string|void | [
"Override",
"API",
"call",
"to",
"enable",
"retry",
"with",
"servers",
"clock",
"auto",
"sync",
"method",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L156-L189 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api.is_cached | function is_cached( $path, $method = 'GET', $params = array() ) {
$cache_key = $this->get_cache_key( $path, $method, $params );
return self::$_cache->has_valid( $cache_key );
} | php | function is_cached( $path, $method = 'GET', $params = array() ) {
$cache_key = $this->get_cache_key( $path, $method, $params );
return self::$_cache->has_valid( $cache_key );
} | [
"function",
"is_cached",
"(",
"$",
"path",
",",
"$",
"method",
"=",
"'GET'",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"cache_key",
"=",
"$",
"this",
"->",
"get_cache_key",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"params",
... | Check if there's a cached version of the API request.
@author Vova Feldman (@svovaf)
@since 1.2.1
@param string $path
@param string $method
@param array $params
@return bool | [
"Check",
"if",
"there",
"s",
"a",
"cached",
"version",
"of",
"the",
"API",
"request",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L289-L293 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api.is_temporary_down | static function is_temporary_down() {
self::_init();
$test = self::$_cache->get_valid( 'ping_test', null );
return ( false === $test );
} | php | static function is_temporary_down() {
self::_init();
$test = self::$_cache->get_valid( 'ping_test', null );
return ( false === $test );
} | [
"static",
"function",
"is_temporary_down",
"(",
")",
"{",
"self",
"::",
"_init",
"(",
")",
";",
"$",
"test",
"=",
"self",
"::",
"$",
"_cache",
"->",
"get_valid",
"(",
"'ping_test'",
",",
"null",
")",
";",
"return",
"(",
"false",
"===",
"$",
"test",
"... | Check if API is temporary down.
@author Vova Feldman (@svovaf)
@since 1.1.6
@return bool | [
"Check",
"if",
"API",
"is",
"temporary",
"down",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L400-L406 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api.ping | function ping( $unique_anonymous_id = null, $params = array() ) {
$this->_logger->entrance();
if ( self::is_temporary_down() ) {
return $this->get_temporary_unavailable_error();
}
$pong = is_null( $unique_anonymous_id ) ?
Freemius_Api_WordPress::Ping() :
$this->_call( 'ping.json?' . http_build_query( array_merge(
array( 'uid' => $unique_anonymous_id ),
$params
) ) );
if ( $this->is_valid_ping( $pong ) ) {
return $pong;
}
if ( self::should_try_with_http( $pong ) ) {
// Fallback to HTTP, since HTTPS fails.
Freemius_Api_WordPress::SetHttp();
self::$_options->set_option( 'api_force_http', true, true );
$pong = is_null( $unique_anonymous_id ) ?
Freemius_Api_WordPress::Ping() :
$this->_call( 'ping.json?' . http_build_query( array_merge(
array( 'uid' => $unique_anonymous_id ),
$params
) ) );
if ( ! $this->is_valid_ping( $pong ) ) {
self::$_options->set_option( 'api_force_http', false, true );
}
}
return $pong;
} | php | function ping( $unique_anonymous_id = null, $params = array() ) {
$this->_logger->entrance();
if ( self::is_temporary_down() ) {
return $this->get_temporary_unavailable_error();
}
$pong = is_null( $unique_anonymous_id ) ?
Freemius_Api_WordPress::Ping() :
$this->_call( 'ping.json?' . http_build_query( array_merge(
array( 'uid' => $unique_anonymous_id ),
$params
) ) );
if ( $this->is_valid_ping( $pong ) ) {
return $pong;
}
if ( self::should_try_with_http( $pong ) ) {
// Fallback to HTTP, since HTTPS fails.
Freemius_Api_WordPress::SetHttp();
self::$_options->set_option( 'api_force_http', true, true );
$pong = is_null( $unique_anonymous_id ) ?
Freemius_Api_WordPress::Ping() :
$this->_call( 'ping.json?' . http_build_query( array_merge(
array( 'uid' => $unique_anonymous_id ),
$params
) ) );
if ( ! $this->is_valid_ping( $pong ) ) {
self::$_options->set_option( 'api_force_http', false, true );
}
}
return $pong;
} | [
"function",
"ping",
"(",
"$",
"unique_anonymous_id",
"=",
"null",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"if",
"(",
"self",
"::",
"is_temporary_down",
"(",
")",
")",
"{",
... | Ping API for connectivity test, and return result object.
@author Vova Feldman (@svovaf)
@since 1.0.9
@param null|string $unique_anonymous_id
@param array $params
@return object | [
"Ping",
"API",
"for",
"connectivity",
"test",
"and",
"return",
"result",
"object",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L436-L473 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api.should_try_with_http | private static function should_try_with_http( $result ) {
if ( ! Freemius_Api_WordPress::IsHttps() ) {
return false;
}
return ( ! is_object( $result ) ||
! isset( $result->error ) ||
! isset( $result->error->code ) ||
! in_array( $result->error->code, array(
'curl_missing',
'cloudflare_ddos_protection',
'maintenance_mode',
'squid_cache_block',
'too_many_requests',
) ) );
} | php | private static function should_try_with_http( $result ) {
if ( ! Freemius_Api_WordPress::IsHttps() ) {
return false;
}
return ( ! is_object( $result ) ||
! isset( $result->error ) ||
! isset( $result->error->code ) ||
! in_array( $result->error->code, array(
'curl_missing',
'cloudflare_ddos_protection',
'maintenance_mode',
'squid_cache_block',
'too_many_requests',
) ) );
} | [
"private",
"static",
"function",
"should_try_with_http",
"(",
"$",
"result",
")",
"{",
"if",
"(",
"!",
"Freemius_Api_WordPress",
"::",
"IsHttps",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"!",
"is_object",
"(",
"$",
"result",
")",
"... | Check if based on the API result we should try
to re-run the same request with HTTP instead of HTTPS.
@author Vova Feldman (@svovaf)
@since 1.1.6
@param $result
@return bool | [
"Check",
"if",
"based",
"on",
"the",
"API",
"result",
"we",
"should",
"try",
"to",
"re",
"-",
"run",
"the",
"same",
"request",
"with",
"HTTP",
"instead",
"of",
"HTTPS",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L486-L502 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api.clear_cache | static function clear_cache() {
self::_init();
self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
self::$_cache->clear();
} | php | static function clear_cache() {
self::_init();
self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
self::$_cache->clear();
} | [
"static",
"function",
"clear_cache",
"(",
")",
"{",
"self",
"::",
"_init",
"(",
")",
";",
"self",
"::",
"$",
"_cache",
"=",
"FS_Cache_Manager",
"::",
"get_manager",
"(",
"WP_FS__API_CACHE_OPTION_NAME",
")",
";",
"self",
"::",
"$",
"_cache",
"->",
"clear",
... | Clear API cache.
@author Vova Feldman (@svovaf)
@since 1.0.9 | [
"Clear",
"API",
"cache",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L528-L533 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api.is_api_result_object | static function is_api_result_object( $result, $required_property = null ) {
return (
is_object( $result ) &&
! isset( $result->error ) &&
( empty( $required_property ) || isset( $result->{$required_property} ) )
);
} | php | static function is_api_result_object( $result, $required_property = null ) {
return (
is_object( $result ) &&
! isset( $result->error ) &&
( empty( $required_property ) || isset( $result->{$required_property} ) )
);
} | [
"static",
"function",
"is_api_result_object",
"(",
"$",
"result",
",",
"$",
"required_property",
"=",
"null",
")",
"{",
"return",
"(",
"is_object",
"(",
"$",
"result",
")",
"&&",
"!",
"isset",
"(",
"$",
"result",
"->",
"error",
")",
"&&",
"(",
"empty",
... | Checks if given API result is a non-empty and not an error object.
@author Vova Feldman (@svovaf)
@since 1.2.1.5
@param mixed $result
@param string|null $required_property Optional property we want to verify that is set.
@return bool | [
"Checks",
"if",
"given",
"API",
"result",
"is",
"a",
"non",
"-",
"empty",
"and",
"not",
"an",
"error",
"object",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L579-L585 | train |
Freemius/wordpress-sdk | includes/class-fs-api.php | FS_Api.get_error_code | static function get_error_code( $result ) {
if ( is_object( $result ) &&
isset( $result->error ) &&
is_object( $result->error ) &&
! empty( $result->error->code )
) {
return $result->error->code;
}
return '';
} | php | static function get_error_code( $result ) {
if ( is_object( $result ) &&
isset( $result->error ) &&
is_object( $result->error ) &&
! empty( $result->error->code )
) {
return $result->error->code;
}
return '';
} | [
"static",
"function",
"get_error_code",
"(",
"$",
"result",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"result",
")",
"&&",
"isset",
"(",
"$",
"result",
"->",
"error",
")",
"&&",
"is_object",
"(",
"$",
"result",
"->",
"error",
")",
"&&",
"!",
"empty... | Get API result error code. If failed to get code, returns an empty string.
@author Vova Feldman (@svovaf)
@since 2.0.0
@param mixed $result
@return string | [
"Get",
"API",
"result",
"error",
"code",
".",
"If",
"failed",
"to",
"get",
"code",
"returns",
"an",
"empty",
"string",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-api.php#L612-L622 | train |
Freemius/wordpress-sdk | includes/class-freemius-abstract.php | Freemius_Abstract.is_plan__premium_only | function is_plan__premium_only( $plan, $exact = false ) {
return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
} | php | function is_plan__premium_only( $plan, $exact = false ) {
return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
} | [
"function",
"is_plan__premium_only",
"(",
"$",
"plan",
",",
"$",
"exact",
"=",
"false",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"is_premium",
"(",
")",
"&&",
"$",
"this",
"->",
"is_plan",
"(",
"$",
"plan",
",",
"$",
"exact",
")",
")",
";",
"}"
... | All code wrapped in this statement will be only included in the premium code.
@since 1.0.9
@param string $plan Plan name.
@param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
@return bool | [
"All",
"code",
"wrapped",
"in",
"this",
"statement",
"will",
"be",
"only",
"included",
"in",
"the",
"premium",
"code",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius-abstract.php#L270-L272 | train |
Freemius/wordpress-sdk | includes/entities/class-fs-plugin-license.php | FS_Plugin_License.left | function left() {
if ( ! $this->is_active() || $this->is_expired() ) {
return 0;
}
if ( $this->is_unlimited() ) {
return 999;
}
return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
} | php | function left() {
if ( ! $this->is_active() || $this->is_expired() ) {
return 0;
}
if ( $this->is_unlimited() ) {
return 999;
}
return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
} | [
"function",
"left",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_active",
"(",
")",
"||",
"$",
"this",
"->",
"is_expired",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_unlimited",
"(",
")",
")",
"{",
... | Check how many site activations left.
@author Vova Feldman (@svovaf)
@since 1.0.5
@return int | [
"Check",
"how",
"many",
"site",
"activations",
"left",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/entities/class-fs-plugin-license.php#L97-L107 | train |
Freemius/wordpress-sdk | includes/entities/class-fs-plugin-license.php | FS_Plugin_License.is_utilized | function is_utilized( $is_localhost = null ) {
if ( is_null( $is_localhost ) ) {
$is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
}
if ( $this->is_unlimited() ) {
return false;
}
return ! ( $this->is_free_localhost && $is_localhost ) &&
( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
} | php | function is_utilized( $is_localhost = null ) {
if ( is_null( $is_localhost ) ) {
$is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
}
if ( $this->is_unlimited() ) {
return false;
}
return ! ( $this->is_free_localhost && $is_localhost ) &&
( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
} | [
"function",
"is_utilized",
"(",
"$",
"is_localhost",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"is_localhost",
")",
")",
"{",
"$",
"is_localhost",
"=",
"WP_FS__IS_LOCALHOST_FOR_SERVER",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_unlimited",
"... | Check if license is fully utilized.
@author Vova Feldman (@svovaf)
@since 1.0.6
@param bool|null $is_localhost
@return bool | [
"Check",
"if",
"license",
"is",
"fully",
"utilized",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/entities/class-fs-plugin-license.php#L173-L184 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.