id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
39,800 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Factory.php | Factory.getFilter | public function getFilter($name)
{
if (!array_key_exists($name, $this->filters)) {
throw new \RuntimeException('There is no filter for the name "' . $name . '" registered.');
}
return $this->filters[$name];
} | php | public function getFilter($name)
{
if (!array_key_exists($name, $this->filters)) {
throw new \RuntimeException('There is no filter for the name "' . $name . '" registered.');
}
return $this->filters[$name];
} | [
"public",
"function",
"getFilter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"filters",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'There is no filter for the name \"'",
".",... | Get a filter.
@param string $name
@return \DotsUnited\BundleFu\Filter\FilterInterface $filter | [
"Get",
"a",
"filter",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Factory.php#L89-L96 |
39,801 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Factory.php | Factory.createBundle | public function createBundle($options = null)
{
if (!is_array($options)) {
if (null !== $options) {
$options = array('name' => $options);
} else {
$options = array();
}
}
$options = array_merge($this->options, $options);
if (isset($options['css_filter']) && is_string($options['css_filter'])) {
$options['css_filter'] = $this->getFilter($options['css_filter']);
}
if (isset($options['js_filter']) && is_string($options['js_filter'])) {
$options['js_filter'] = $this->getFilter($options['js_filter']);
}
return new Bundle($options);
} | php | public function createBundle($options = null)
{
if (!is_array($options)) {
if (null !== $options) {
$options = array('name' => $options);
} else {
$options = array();
}
}
$options = array_merge($this->options, $options);
if (isset($options['css_filter']) && is_string($options['css_filter'])) {
$options['css_filter'] = $this->getFilter($options['css_filter']);
}
if (isset($options['js_filter']) && is_string($options['js_filter'])) {
$options['js_filter'] = $this->getFilter($options['js_filter']);
}
return new Bundle($options);
} | [
"public",
"function",
"createBundle",
"(",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'name'",
"=>",... | Create a Bundle instance.
@param string|array $options An array of options or a bundle name as string
@return \DotsUnited\BundleFu\Bundle
@throws \RuntimeException | [
"Create",
"a",
"Bundle",
"instance",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Factory.php#L105-L126 |
39,802 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.setOptions | public function setOptions(array $options)
{
foreach ($options as $key => $val) {
switch ($key) {
case 'name':
$this->setName($val);
break;
case 'doc_root':
$this->setDocRoot($val);
break;
case 'bypass':
$this->setBypass($val);
break;
case 'force':
$this->setForce($val);
break;
case 'render_as_xhtml':
$this->setRenderAsXhtml($val);
break;
case 'css_filter':
$this->setCssFilter($val);
break;
case 'js_filter':
$this->setJsFilter($val);
break;
case 'css_cache_path':
$this->setCssCachePath($val);
break;
case 'js_cache_path':
$this->setJsCachePath($val);
break;
case 'css_cache_url':
$this->setCssCacheUrl($val);
break;
case 'js_cache_url':
$this->setJsCacheUrl($val);
break;
case 'css_template':
$this->setCssTemplate($val);
break;
case 'js_template':
$this->setJsTemplate($val);
break;
}
}
return $this;
} | php | public function setOptions(array $options)
{
foreach ($options as $key => $val) {
switch ($key) {
case 'name':
$this->setName($val);
break;
case 'doc_root':
$this->setDocRoot($val);
break;
case 'bypass':
$this->setBypass($val);
break;
case 'force':
$this->setForce($val);
break;
case 'render_as_xhtml':
$this->setRenderAsXhtml($val);
break;
case 'css_filter':
$this->setCssFilter($val);
break;
case 'js_filter':
$this->setJsFilter($val);
break;
case 'css_cache_path':
$this->setCssCachePath($val);
break;
case 'js_cache_path':
$this->setJsCachePath($val);
break;
case 'css_cache_url':
$this->setCssCacheUrl($val);
break;
case 'js_cache_url':
$this->setJsCacheUrl($val);
break;
case 'css_template':
$this->setCssTemplate($val);
break;
case 'js_template':
$this->setJsTemplate($val);
break;
}
}
return $this;
} | [
"public",
"function",
"setOptions",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'name'",
":",
"$",
"this",
"->",
"setName",
"(",... | Allows to pass options as array.
@param array $options
@return Bundle | [
"Allows",
"to",
"pass",
"options",
"as",
"array",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L156-L203 |
39,803 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.getCssBundlePath | public function getCssBundlePath()
{
$cacheDir = $this->getCssCachePath();
if ($this->isRelativePath($cacheDir)) {
$cacheDir = $this->getDocRoot() . DIRECTORY_SEPARATOR . $cacheDir;
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getCssFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getCssFileList()->getHash());
}
return sprintf(
"%s%s%s.css",
$cacheDir,
DIRECTORY_SEPARATOR,
$name
);
} | php | public function getCssBundlePath()
{
$cacheDir = $this->getCssCachePath();
if ($this->isRelativePath($cacheDir)) {
$cacheDir = $this->getDocRoot() . DIRECTORY_SEPARATOR . $cacheDir;
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getCssFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getCssFileList()->getHash());
}
return sprintf(
"%s%s%s.css",
$cacheDir,
DIRECTORY_SEPARATOR,
$name
);
} | [
"public",
"function",
"getCssBundlePath",
"(",
")",
"{",
"$",
"cacheDir",
"=",
"$",
"this",
"->",
"getCssCachePath",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRelativePath",
"(",
"$",
"cacheDir",
")",
")",
"{",
"$",
"cacheDir",
"=",
"$",
"this",
... | Get css bundle path.
@return string | [
"Get",
"css",
"bundle",
"path",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L537-L559 |
39,804 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.getJsBundlePath | public function getJsBundlePath()
{
$cacheDir = $this->getJsCachePath();
if ($this->isRelativePath($cacheDir)) {
$cacheDir = $this->getDocRoot() . DIRECTORY_SEPARATOR . $cacheDir;
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getJsFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getJsFileList()->getHash());
}
return sprintf(
"%s%s%s.js",
$cacheDir,
DIRECTORY_SEPARATOR,
$name
);
} | php | public function getJsBundlePath()
{
$cacheDir = $this->getJsCachePath();
if ($this->isRelativePath($cacheDir)) {
$cacheDir = $this->getDocRoot() . DIRECTORY_SEPARATOR . $cacheDir;
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getJsFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getJsFileList()->getHash());
}
return sprintf(
"%s%s%s.js",
$cacheDir,
DIRECTORY_SEPARATOR,
$name
);
} | [
"public",
"function",
"getJsBundlePath",
"(",
")",
"{",
"$",
"cacheDir",
"=",
"$",
"this",
"->",
"getJsCachePath",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRelativePath",
"(",
"$",
"cacheDir",
")",
")",
"{",
"$",
"cacheDir",
"=",
"$",
"this",
... | Get javascript bundle path.
@return string | [
"Get",
"javascript",
"bundle",
"path",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L566-L588 |
39,805 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.getCssBundleUrl | public function getCssBundleUrl()
{
$url = $this->getCssCacheUrl();
if (!$url) {
$url = $this->getCssCachePath();
if (!$this->isRelativePath($url)) {
throw new \RuntimeException('If you do not provide a css cache url, css cache path must be a relative local path...');
}
$url = '/' . str_replace(DIRECTORY_SEPARATOR, '/', $url);
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getCssFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getCssFileList()->getHash());
}
return sprintf(
"%s/%s.css",
$url,
$name
);
} | php | public function getCssBundleUrl()
{
$url = $this->getCssCacheUrl();
if (!$url) {
$url = $this->getCssCachePath();
if (!$this->isRelativePath($url)) {
throw new \RuntimeException('If you do not provide a css cache url, css cache path must be a relative local path...');
}
$url = '/' . str_replace(DIRECTORY_SEPARATOR, '/', $url);
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getCssFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getCssFileList()->getHash());
}
return sprintf(
"%s/%s.css",
$url,
$name
);
} | [
"public",
"function",
"getCssBundleUrl",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getCssCacheUrl",
"(",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getCssCachePath",
"(",
")",
";",
"if",
"(",
"!... | Get css bundle url.
@return string | [
"Get",
"css",
"bundle",
"url",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L595-L622 |
39,806 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.getJsBundleUrl | public function getJsBundleUrl()
{
$url = $this->getJsCacheUrl();
if (!$url) {
$url = $this->getJsCachePath();
if (!$this->isRelativePath($url)) {
throw new \RuntimeException('If you do not provide a js cache url, js cache path must be a relative local path...');
}
$url = '/' . str_replace(DIRECTORY_SEPARATOR, '/', $url);
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getJsFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getJsFileList()->getHash());
}
return sprintf(
"%s/%s.js",
$url,
$name
);
} | php | public function getJsBundleUrl()
{
$url = $this->getJsCacheUrl();
if (!$url) {
$url = $this->getJsCachePath();
if (!$this->isRelativePath($url)) {
throw new \RuntimeException('If you do not provide a js cache url, js cache path must be a relative local path...');
}
$url = '/' . str_replace(DIRECTORY_SEPARATOR, '/', $url);
}
$name = $this->getName();
if (null === $name) {
$name = sprintf('bundle_%s', $this->getJsFileList()->getHash());
} elseif (strpos($name, '%s') !== false) {
$name = sprintf($name, $this->getJsFileList()->getHash());
}
return sprintf(
"%s/%s.js",
$url,
$name
);
} | [
"public",
"function",
"getJsBundleUrl",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getJsCacheUrl",
"(",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getJsCachePath",
"(",
")",
";",
"if",
"(",
"!",
... | Get javascript bundle url.
@return string | [
"Get",
"javascript",
"bundle",
"url",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L629-L656 |
39,807 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.addCssFile | public function addCssFile($file, $docRoot = null)
{
if (null === $docRoot) {
$docRoot = $this->getDocRoot();
}
$docRoot = (string) $docRoot;
if ('' !== $docRoot) {
$docRoot .= DIRECTORY_SEPARATOR;
}
$file = preg_replace('/^https?:\/\/[^\/]+/i', '', $file);
$abspath = $docRoot . $file;
$this->getCssFileList()->addFile($file, $abspath);
return $this;
} | php | public function addCssFile($file, $docRoot = null)
{
if (null === $docRoot) {
$docRoot = $this->getDocRoot();
}
$docRoot = (string) $docRoot;
if ('' !== $docRoot) {
$docRoot .= DIRECTORY_SEPARATOR;
}
$file = preg_replace('/^https?:\/\/[^\/]+/i', '', $file);
$abspath = $docRoot . $file;
$this->getCssFileList()->addFile($file, $abspath);
return $this;
} | [
"public",
"function",
"addCssFile",
"(",
"$",
"file",
",",
"$",
"docRoot",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"docRoot",
")",
"{",
"$",
"docRoot",
"=",
"$",
"this",
"->",
"getDocRoot",
"(",
")",
";",
"}",
"$",
"docRoot",
"=",
"... | Add a CSS file.
@param string $file
@param string $docRoot
@return Bundle | [
"Add",
"a",
"CSS",
"file",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L665-L683 |
39,808 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.addJsFile | public function addJsFile($file, $docRoot = null)
{
if (null === $docRoot) {
$docRoot = $this->getDocRoot();
}
$docRoot = (string) $docRoot;
if ('' !== $docRoot) {
$docRoot .= DIRECTORY_SEPARATOR;
}
$file = preg_replace('/^https?:\/\/[^\/]+/i', '', $file);
$abspath = $docRoot . $file;
$this->getJsFileList()->addFile($file, $abspath);
return $this;
} | php | public function addJsFile($file, $docRoot = null)
{
if (null === $docRoot) {
$docRoot = $this->getDocRoot();
}
$docRoot = (string) $docRoot;
if ('' !== $docRoot) {
$docRoot .= DIRECTORY_SEPARATOR;
}
$file = preg_replace('/^https?:\/\/[^\/]+/i', '', $file);
$abspath = $docRoot . $file;
$this->getJsFileList()->addFile($file, $abspath);
return $this;
} | [
"public",
"function",
"addJsFile",
"(",
"$",
"file",
",",
"$",
"docRoot",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"docRoot",
")",
"{",
"$",
"docRoot",
"=",
"$",
"this",
"->",
"getDocRoot",
"(",
")",
";",
"}",
"$",
"docRoot",
"=",
"(... | Add a javascript file.
@param string $file
@param string $docRoot
@return Bundle | [
"Add",
"a",
"javascript",
"file",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L692-L710 |
39,809 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.start | public function start(array $options = array())
{
$currentBundleOptions = array(
'docroot' => $this->getDocRoot(),
'bypass' => $this->getBypass()
);
$this->currentBundleOptions = array_merge($currentBundleOptions, $options);
ob_start();
return $this;
} | php | public function start(array $options = array())
{
$currentBundleOptions = array(
'docroot' => $this->getDocRoot(),
'bypass' => $this->getBypass()
);
$this->currentBundleOptions = array_merge($currentBundleOptions, $options);
ob_start();
return $this;
} | [
"public",
"function",
"start",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"currentBundleOptions",
"=",
"array",
"(",
"'docroot'",
"=>",
"$",
"this",
"->",
"getDocRoot",
"(",
")",
",",
"'bypass'",
"=>",
"$",
"this",
"->",
"getB... | Start capturing and bundling current output.
@param array $options
@return Bundle | [
"Start",
"capturing",
"and",
"bundling",
"current",
"output",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L718-L729 |
39,810 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.end | public function end(array $options = array())
{
if (null === $this->currentBundleOptions) {
throw new \RuntimeException('end() is called without a start() call.');
}
$options = array_merge($this->currentBundleOptions, $options);
$captured = ob_get_clean();
if ($options['bypass']) {
echo $captured;
} else {
$this->extractFiles($captured, $options['docroot']);
}
$this->currentBundleOptions = null;
return $this;
} | php | public function end(array $options = array())
{
if (null === $this->currentBundleOptions) {
throw new \RuntimeException('end() is called without a start() call.');
}
$options = array_merge($this->currentBundleOptions, $options);
$captured = ob_get_clean();
if ($options['bypass']) {
echo $captured;
} else {
$this->extractFiles($captured, $options['docroot']);
}
$this->currentBundleOptions = null;
return $this;
} | [
"public",
"function",
"end",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"currentBundleOptions",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'end() is called without a start() call.... | End capturing and bundling current output.
@param array $options
@return Bundle | [
"End",
"capturing",
"and",
"bundling",
"current",
"output",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L737-L756 |
39,811 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.extractFiles | public function extractFiles($html, $docRoot = null)
{
if (null === $docRoot) {
$docRoot = $this->getDocRoot();
}
preg_match_all('/(href|src) *= *["\']([^"^\'^\?]+)/i', $html, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
if (strtolower($match[1]) == 'src') {
$this->addJsFile($match[2], $docRoot);
} else {
$this->addCssFile($match[2], $docRoot);
}
}
return $this;
} | php | public function extractFiles($html, $docRoot = null)
{
if (null === $docRoot) {
$docRoot = $this->getDocRoot();
}
preg_match_all('/(href|src) *= *["\']([^"^\'^\?]+)/i', $html, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
if (strtolower($match[1]) == 'src') {
$this->addJsFile($match[2], $docRoot);
} else {
$this->addCssFile($match[2], $docRoot);
}
}
return $this;
} | [
"public",
"function",
"extractFiles",
"(",
"$",
"html",
",",
"$",
"docRoot",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"docRoot",
")",
"{",
"$",
"docRoot",
"=",
"$",
"this",
"->",
"getDocRoot",
"(",
")",
";",
"}",
"preg_match_all",
"(",
... | Extract files from HTML.
@param string $html
@param string $docRoot
@return Bundle | [
"Extract",
"files",
"from",
"HTML",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L765-L782 |
39,812 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.renderCss | public function renderCss()
{
$cssFileList = $this->getCssFileList();
if ($cssFileList->count() == 0) {
return '';
}
$generate = true;
$bundlePath = $this->getCssBundlePath();
if (!$this->getForce() && file_exists($bundlePath)) {
$cacheTime = filemtime($bundlePath);
if (false !== $cacheTime && $cacheTime >= $cssFileList->getMaxMTime()) {
$generate = false;
}
}
$bundleUrl = $this->getCssBundleUrl();
if ($generate) {
$data = '';
$filter = $this->getCssFilter();
foreach ($cssFileList as $file => $fileInfo) {
$data .= '/* --------- ' . $file . ' --------- */' . PHP_EOL;
$contents = @file_get_contents($fileInfo->getPathname());
if (!$contents) {
$data .= '/* FILE READ ERROR! */' . PHP_EOL;
} else {
if (null !== $filter) {
$contents = $filter->filterFile($contents, $file, $fileInfo, $bundleUrl, $bundlePath);
}
$data .= $contents . PHP_EOL;
}
}
if (null !== $filter) {
$data = $filter->filter($data);
}
$cacheTime = $this->writeBundleFile($bundlePath, $data);
}
$template = $this->getCssTemplate();
if (is_callable($template)) {
return call_user_func($template, $bundleUrl, $cacheTime, $this->getRenderAsXhtml());
}
return sprintf(
$template,
$bundleUrl,
$cacheTime,
$this->getRenderAsXhtml() ? ' /' : ''
);
} | php | public function renderCss()
{
$cssFileList = $this->getCssFileList();
if ($cssFileList->count() == 0) {
return '';
}
$generate = true;
$bundlePath = $this->getCssBundlePath();
if (!$this->getForce() && file_exists($bundlePath)) {
$cacheTime = filemtime($bundlePath);
if (false !== $cacheTime && $cacheTime >= $cssFileList->getMaxMTime()) {
$generate = false;
}
}
$bundleUrl = $this->getCssBundleUrl();
if ($generate) {
$data = '';
$filter = $this->getCssFilter();
foreach ($cssFileList as $file => $fileInfo) {
$data .= '/* --------- ' . $file . ' --------- */' . PHP_EOL;
$contents = @file_get_contents($fileInfo->getPathname());
if (!$contents) {
$data .= '/* FILE READ ERROR! */' . PHP_EOL;
} else {
if (null !== $filter) {
$contents = $filter->filterFile($contents, $file, $fileInfo, $bundleUrl, $bundlePath);
}
$data .= $contents . PHP_EOL;
}
}
if (null !== $filter) {
$data = $filter->filter($data);
}
$cacheTime = $this->writeBundleFile($bundlePath, $data);
}
$template = $this->getCssTemplate();
if (is_callable($template)) {
return call_user_func($template, $bundleUrl, $cacheTime, $this->getRenderAsXhtml());
}
return sprintf(
$template,
$bundleUrl,
$cacheTime,
$this->getRenderAsXhtml() ? ' /' : ''
);
} | [
"public",
"function",
"renderCss",
"(",
")",
"{",
"$",
"cssFileList",
"=",
"$",
"this",
"->",
"getCssFileList",
"(",
")",
";",
"if",
"(",
"$",
"cssFileList",
"->",
"count",
"(",
")",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"generate",
"... | Render out the css bundle.
@return string | [
"Render",
"out",
"the",
"css",
"bundle",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L828-L886 |
39,813 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.renderJs | public function renderJs()
{
$jsFileList = $this->getJsFileList();
if ($jsFileList->count() == 0) {
return '';
}
$generate = true;
$bundlePath = $this->getJsBundlePath();
if (!$this->getForce() && file_exists($bundlePath)) {
$cacheTime = filemtime($bundlePath);
if (false !== $cacheTime && $cacheTime >= $jsFileList->getMaxMTime()) {
$generate = false;
}
}
$bundleUrl = $this->getJsBundleUrl();
if ($generate) {
$data = '';
$filter = $this->getJsFilter();
foreach ($jsFileList as $file => $fileInfo) {
$data .= '/* --------- ' . $file . ' --------- */' . PHP_EOL;
$contents = @file_get_contents($fileInfo->getPathname());
if (!$contents) {
$data .= '/* FILE READ ERROR! */' . PHP_EOL;
} else {
if (null !== $filter) {
$contents = $filter->filterFile($contents, $file, $fileInfo, $bundleUrl, $bundlePath);
}
$data .= $contents . PHP_EOL;
}
}
if (null !== $filter) {
$data = $filter->filter($data);
}
$cacheTime = $this->writeBundleFile($bundlePath, $data);
}
$template = $this->getJsTemplate();
if (is_callable($template)) {
return call_user_func($template, $bundleUrl, $cacheTime);
}
return sprintf(
$template,
$bundleUrl,
$cacheTime
);
} | php | public function renderJs()
{
$jsFileList = $this->getJsFileList();
if ($jsFileList->count() == 0) {
return '';
}
$generate = true;
$bundlePath = $this->getJsBundlePath();
if (!$this->getForce() && file_exists($bundlePath)) {
$cacheTime = filemtime($bundlePath);
if (false !== $cacheTime && $cacheTime >= $jsFileList->getMaxMTime()) {
$generate = false;
}
}
$bundleUrl = $this->getJsBundleUrl();
if ($generate) {
$data = '';
$filter = $this->getJsFilter();
foreach ($jsFileList as $file => $fileInfo) {
$data .= '/* --------- ' . $file . ' --------- */' . PHP_EOL;
$contents = @file_get_contents($fileInfo->getPathname());
if (!$contents) {
$data .= '/* FILE READ ERROR! */' . PHP_EOL;
} else {
if (null !== $filter) {
$contents = $filter->filterFile($contents, $file, $fileInfo, $bundleUrl, $bundlePath);
}
$data .= $contents . PHP_EOL;
}
}
if (null !== $filter) {
$data = $filter->filter($data);
}
$cacheTime = $this->writeBundleFile($bundlePath, $data);
}
$template = $this->getJsTemplate();
if (is_callable($template)) {
return call_user_func($template, $bundleUrl, $cacheTime);
}
return sprintf(
$template,
$bundleUrl,
$cacheTime
);
} | [
"public",
"function",
"renderJs",
"(",
")",
"{",
"$",
"jsFileList",
"=",
"$",
"this",
"->",
"getJsFileList",
"(",
")",
";",
"if",
"(",
"$",
"jsFileList",
"->",
"count",
"(",
")",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"generate",
"=",
... | Render out the javascript bundle.
@return string | [
"Render",
"out",
"the",
"javascript",
"bundle",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L893-L950 |
39,814 | dotsunited/BundleFu | src/DotsUnited/BundleFu/Bundle.php | Bundle.writeBundleFile | protected function writeBundleFile($bundlePath, $data)
{
$dir = dirname($bundlePath);
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
if (false === file_put_contents($bundlePath, $data, LOCK_EX)) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Cannot write cache file to "' . $bundlePath . '"');
// @codeCoverageIgnoreEnd
}
return filemtime($bundlePath);
} | php | protected function writeBundleFile($bundlePath, $data)
{
$dir = dirname($bundlePath);
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
if (false === file_put_contents($bundlePath, $data, LOCK_EX)) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Cannot write cache file to "' . $bundlePath . '"');
// @codeCoverageIgnoreEnd
}
return filemtime($bundlePath);
} | [
"protected",
"function",
"writeBundleFile",
"(",
"$",
"bundlePath",
",",
"$",
"data",
")",
"{",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"bundlePath",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"mkdir",
"(",
"$",
"dir",
"... | Write a bundle file to disk.
@param string $bundlePath
@param string $data
@return integer | [
"Write",
"a",
"bundle",
"file",
"to",
"disk",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Bundle.php#L970-L985 |
39,815 | erikgall/eloquent-phpunit | src/Database/Table.php | Table.hasTimestamps | public function hasTimestamps()
{
$this->column('created_at')->dateTime()->nullable();
$this->column('updated_at')->dateTime()->nullable();
return $this;
} | php | public function hasTimestamps()
{
$this->column('created_at')->dateTime()->nullable();
$this->column('updated_at')->dateTime()->nullable();
return $this;
} | [
"public",
"function",
"hasTimestamps",
"(",
")",
"{",
"$",
"this",
"->",
"column",
"(",
"'created_at'",
")",
"->",
"dateTime",
"(",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"column",
"(",
"'updated_at'",
")",
"->",
"dateTime",
"(",
")",... | Assert the table has timestamp columns.
@return $this | [
"Assert",
"the",
"table",
"has",
"timestamp",
"columns",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Table.php#L86-L92 |
39,816 | erikgall/eloquent-phpunit | src/Database/Table.php | Table.tableColumn | protected function tableColumn($column)
{
if (is_null($this->table)) {
$this->setTable();
}
return new Column($this->context, $this->table, $column);
} | php | protected function tableColumn($column)
{
if (is_null($this->table)) {
$this->setTable();
}
return new Column($this->context, $this->table, $column);
} | [
"protected",
"function",
"tableColumn",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"table",
")",
")",
"{",
"$",
"this",
"->",
"setTable",
"(",
")",
";",
"}",
"return",
"new",
"Column",
"(",
"$",
"this",
"->",
"conte... | Get a column's test case instance.
@param $column
@return \EGALL\EloquentPHPUnit\Database\TableColumnTestCase | [
"Get",
"a",
"column",
"s",
"test",
"case",
"instance",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Table.php#L100-L107 |
39,817 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.foreign | public function foreign($table, $column = 'id', $onUpdate = 'cascade', $onDelete = 'cascade')
{
if (DB::connection() instanceof \Illuminate\Database\SQLiteConnection) {
$this->context->markTestIncomplete('Foreign keys cannot be tested with a SQLite database.');
return $this;
}
$name = $this->getIndexName('foreign');
$this->assertTrue($this->table->hasForeignKey($name), "The foreign key {$name} does not exist.");
$key = $this->table->getForeignKey($name);
$onUpdate && $this->context->assertEquals(strtoupper($onUpdate), $key->onUpdate());
$onDelete && $this->context->assertEquals(strtoupper($onDelete), $key->onDelete());
$this->context->assertEquals($table, $key->getForeignTableName());
$this->context->assertContains($column, $key->getForeignColumns());
return $this;
} | php | public function foreign($table, $column = 'id', $onUpdate = 'cascade', $onDelete = 'cascade')
{
if (DB::connection() instanceof \Illuminate\Database\SQLiteConnection) {
$this->context->markTestIncomplete('Foreign keys cannot be tested with a SQLite database.');
return $this;
}
$name = $this->getIndexName('foreign');
$this->assertTrue($this->table->hasForeignKey($name), "The foreign key {$name} does not exist.");
$key = $this->table->getForeignKey($name);
$onUpdate && $this->context->assertEquals(strtoupper($onUpdate), $key->onUpdate());
$onDelete && $this->context->assertEquals(strtoupper($onDelete), $key->onDelete());
$this->context->assertEquals($table, $key->getForeignTableName());
$this->context->assertContains($column, $key->getForeignColumns());
return $this;
} | [
"public",
"function",
"foreign",
"(",
"$",
"table",
",",
"$",
"column",
"=",
"'id'",
",",
"$",
"onUpdate",
"=",
"'cascade'",
",",
"$",
"onDelete",
"=",
"'cascade'",
")",
"{",
"if",
"(",
"DB",
"::",
"connection",
"(",
")",
"instanceof",
"\\",
"Illuminat... | Assert that the table has a foreign key relationship.
@param string $table
@param string $column
@param string $onUpdate
@param string $onDelete
@return $this | [
"Assert",
"that",
"the",
"table",
"has",
"a",
"foreign",
"key",
"relationship",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L85-L104 |
39,818 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.get | public function get($key)
{
if (is_null($this->data)) {
$this->data = $this->table->getColumn($this->name)->toArray();
}
return $this->data[$key];
} | php | public function get($key)
{
if (is_null($this->data)) {
$this->data = $this->table->getColumn($this->name)->toArray();
}
return $this->data[$key];
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"this",
"->",
"table",
"->",
"getColumn",
"(",
"$",
"this",
"->",
"name",
")",
"->... | Get a data key by name.
@param string $key
@return mixed | [
"Get",
"a",
"data",
"key",
"by",
"name",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L112-L119 |
39,819 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.index | public function index()
{
$index = $this->getIndexName();
$this->assertTrue(
$this->table->hasIndex($index), "The {$this->name} column is not indexed."
);
$this->assertTrue(
$this->table->getIndex($index)->isSimpleIndex(), "The {$this->name} column is not a simple index."
);
} | php | public function index()
{
$index = $this->getIndexName();
$this->assertTrue(
$this->table->hasIndex($index), "The {$this->name} column is not indexed."
);
$this->assertTrue(
$this->table->getIndex($index)->isSimpleIndex(), "The {$this->name} column is not a simple index."
);
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexName",
"(",
")",
";",
"$",
"this",
"->",
"assertTrue",
"(",
"$",
"this",
"->",
"table",
"->",
"hasIndex",
"(",
"$",
"index",
")",
",",
"\"The {$this->name} col... | Assert that the column is indexed.
@return $this | [
"Assert",
"that",
"the",
"column",
"is",
"indexed",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L167-L178 |
39,820 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.primary | public function primary()
{
$key = $this->tableHasPrimary()->getPrimaryKey();
$message = "The column {$this->name} is not a primary key.";
return $this->assertTrue(in_array($this->name, $key->getColumns()), $message)
->assertTrue($key->isPrimary())
->assertTrue($key->isUnique());
} | php | public function primary()
{
$key = $this->tableHasPrimary()->getPrimaryKey();
$message = "The column {$this->name} is not a primary key.";
return $this->assertTrue(in_array($this->name, $key->getColumns()), $message)
->assertTrue($key->isPrimary())
->assertTrue($key->isUnique());
} | [
"public",
"function",
"primary",
"(",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"tableHasPrimary",
"(",
")",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"message",
"=",
"\"The column {$this->name} is not a primary key.\"",
";",
"return",
"$",
"this",
"->",
... | Assert that the column is a primary key.
@return $this | [
"Assert",
"that",
"the",
"column",
"is",
"a",
"primary",
"key",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L199-L207 |
39,821 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.assertNullable | protected function assertNullable($negate = false)
{
if ($negate) {
return $this->assertTrue($this->get('notnull'), "The table column `{$this->name}` is nullable");
}
return $this->assertFalse($this->get('notnull'), "The table column `{$this->name}` is not nullable");
} | php | protected function assertNullable($negate = false)
{
if ($negate) {
return $this->assertTrue($this->get('notnull'), "The table column `{$this->name}` is nullable");
}
return $this->assertFalse($this->get('notnull'), "The table column `{$this->name}` is not nullable");
} | [
"protected",
"function",
"assertNullable",
"(",
"$",
"negate",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"negate",
")",
"{",
"return",
"$",
"this",
"->",
"assertTrue",
"(",
"$",
"this",
"->",
"get",
"(",
"'notnull'",
")",
",",
"\"The table column `{$this->na... | Assert the column is nullable.
@param bool $negate
@return $this | [
"Assert",
"the",
"column",
"is",
"nullable",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L234-L241 |
39,822 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.assertColumn | protected function assertColumn($method, $args)
{
if (array_key_exists($method, $this->types)) {
return $this->ofType($this->types[$method]);
}
if (str_contains($method, ['default', 'Default'])) {
return $this->defaults($args[0]);
}
if (str_contains($method, ['null', 'Null'])) {
return $this->assertNullable(str_contains($method, 'not'));
}
throw new \Exception("The database table column assertion {$method} does not exist.");
} | php | protected function assertColumn($method, $args)
{
if (array_key_exists($method, $this->types)) {
return $this->ofType($this->types[$method]);
}
if (str_contains($method, ['default', 'Default'])) {
return $this->defaults($args[0]);
}
if (str_contains($method, ['null', 'Null'])) {
return $this->assertNullable(str_contains($method, 'not'));
}
throw new \Exception("The database table column assertion {$method} does not exist.");
} | [
"protected",
"function",
"assertColumn",
"(",
"$",
"method",
",",
"$",
"args",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"types",
")",
")",
"{",
"return",
"$",
"this",
"->",
"ofType",
"(",
"$",
"this",
"->",... | Call a column assertion method.
@param string $method
@param array $args
@return $this | [
"Call",
"a",
"column",
"assertion",
"method",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L250-L265 |
39,823 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.assertFalse | protected function assertFalse($condition, $message = null)
{
$this->context->assertFalse($condition, $message);
return $this;
} | php | protected function assertFalse($condition, $message = null)
{
$this->context->assertFalse($condition, $message);
return $this;
} | [
"protected",
"function",
"assertFalse",
"(",
"$",
"condition",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"context",
"->",
"assertFalse",
"(",
"$",
"condition",
",",
"$",
"message",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Assert a condition is false alias.
@param bool $condition
@param string|null $message
@return $this | [
"Assert",
"a",
"condition",
"is",
"false",
"alias",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L274-L279 |
39,824 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.assertTrue | protected function assertTrue($condition, $message = null)
{
$this->context->assertTrue($condition, $message);
return $this;
} | php | protected function assertTrue($condition, $message = null)
{
$this->context->assertTrue($condition, $message);
return $this;
} | [
"protected",
"function",
"assertTrue",
"(",
"$",
"condition",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"context",
"->",
"assertTrue",
"(",
"$",
"condition",
",",
"$",
"message",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Assert a condition is true alias.
@param bool $condition
@param string|null $message
@return $this | [
"Assert",
"a",
"condition",
"is",
"true",
"alias",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L288-L293 |
39,825 | erikgall/eloquent-phpunit | src/Database/Column.php | Column.assertUniqueIndex | protected function assertUniqueIndex($key, $indexes)
{
$this->context->assertArrayHasKey($key, $indexes, "The {$this->name} column is not indexed.");
$this->assertTrue($indexes[$key]->isUnique(), "The {$this->name} is not a unique index.");
} | php | protected function assertUniqueIndex($key, $indexes)
{
$this->context->assertArrayHasKey($key, $indexes, "The {$this->name} column is not indexed.");
$this->assertTrue($indexes[$key]->isUnique(), "The {$this->name} is not a unique index.");
} | [
"protected",
"function",
"assertUniqueIndex",
"(",
"$",
"key",
",",
"$",
"indexes",
")",
"{",
"$",
"this",
"->",
"context",
"->",
"assertArrayHasKey",
"(",
"$",
"key",
",",
"$",
"indexes",
",",
"\"The {$this->name} column is not indexed.\"",
")",
";",
"$",
"th... | Assert a key is a unique index.
@param string $key
@param array $indexes
@return void | [
"Assert",
"a",
"key",
"is",
"a",
"unique",
"index",
"."
] | bb3eb18098c967ec0398af6b3e2d6865e387e3bb | https://github.com/erikgall/eloquent-phpunit/blob/bb3eb18098c967ec0398af6b3e2d6865e387e3bb/src/Database/Column.php#L302-L306 |
39,826 | dotsunited/BundleFu | src/DotsUnited/BundleFu/FileList.php | FileList.addFile | public function addFile($file, $fileInfo)
{
if (!($fileInfo instanceof \SplFileInfo)) {
$fileInfo = new \SplFileInfo($fileInfo);
}
$this->files[$file] = $fileInfo;
try {
$mTime = $fileInfo->getMTime();
} catch (\Exception $e) {
$mTime = 0;
}
if ($mTime > $this->maxMTime) {
$this->maxMTime = $mTime;
}
return $this;
} | php | public function addFile($file, $fileInfo)
{
if (!($fileInfo instanceof \SplFileInfo)) {
$fileInfo = new \SplFileInfo($fileInfo);
}
$this->files[$file] = $fileInfo;
try {
$mTime = $fileInfo->getMTime();
} catch (\Exception $e) {
$mTime = 0;
}
if ($mTime > $this->maxMTime) {
$this->maxMTime = $mTime;
}
return $this;
} | [
"public",
"function",
"addFile",
"(",
"$",
"file",
",",
"$",
"fileInfo",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"fileInfo",
"instanceof",
"\\",
"SplFileInfo",
")",
")",
"{",
"$",
"fileInfo",
"=",
"new",
"\\",
"SplFileInfo",
"(",
"$",
"fileInfo",
")",
";... | Add a file to the list.
@param string $file The file
@param \SplFileInfo $fileInfo
@return FileList | [
"Add",
"a",
"file",
"to",
"the",
"list",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/FileList.php#L39-L58 |
39,827 | linkprofit-cpa/amocrm-api | src/RequestHandler.php | RequestHandler.encodeResponse | protected function encodeResponse()
{
try {
if (!in_array($this->httpCode, $this->successHttpCodes)) {
throw new Exception(isset($this->httpErrors[$this->httpCode]) ? $this->httpErrors[$this->httpCode] : 'Undescribed error', $this->httpCode);
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL . 'Error code: ' . $e->getCode();
}
$this->response = json_decode($this->response, true);
} | php | protected function encodeResponse()
{
try {
if (!in_array($this->httpCode, $this->successHttpCodes)) {
throw new Exception(isset($this->httpErrors[$this->httpCode]) ? $this->httpErrors[$this->httpCode] : 'Undescribed error', $this->httpCode);
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL . 'Error code: ' . $e->getCode();
}
$this->response = json_decode($this->response, true);
} | [
"protected",
"function",
"encodeResponse",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"httpCode",
",",
"$",
"this",
"->",
"successHttpCodes",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"isset",
"(",
"$",
"this"... | Encoding response from json, throw exception in case of wrong http code | [
"Encoding",
"response",
"from",
"json",
"throw",
"exception",
"in",
"case",
"of",
"wrong",
"http",
"code"
] | 13f91ac53373ad5861c160530ce3dbb19aa7df74 | https://github.com/linkprofit-cpa/amocrm-api/blob/13f91ac53373ad5861c160530ce3dbb19aa7df74/src/RequestHandler.php#L110-L121 |
39,828 | linkprofit-cpa/amocrm-api | src/services/TaskTypeService.php | TaskTypeService.composeFields | protected function composeFields()
{
$addFields = [];
$updateFields = [];
foreach ($this->entities as $entity) {
if ($entity->id) {
$updateFields[] = $entity->get();
} else {
$addFields[] = $entity->get();
}
}
$this->fields['ACTION'] = 'ALL_EDIT';
$fields = array_merge($addFields, $updateFields);
if (count($fields)) {
$this->fields['task_types'] = $fields;
}
} | php | protected function composeFields()
{
$addFields = [];
$updateFields = [];
foreach ($this->entities as $entity) {
if ($entity->id) {
$updateFields[] = $entity->get();
} else {
$addFields[] = $entity->get();
}
}
$this->fields['ACTION'] = 'ALL_EDIT';
$fields = array_merge($addFields, $updateFields);
if (count($fields)) {
$this->fields['task_types'] = $fields;
}
} | [
"protected",
"function",
"composeFields",
"(",
")",
"{",
"$",
"addFields",
"=",
"[",
"]",
";",
"$",
"updateFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"entities",
"as",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"i... | Fill fields for save request | [
"Fill",
"fields",
"for",
"save",
"request"
] | 13f91ac53373ad5861c160530ce3dbb19aa7df74 | https://github.com/linkprofit-cpa/amocrm-api/blob/13f91ac53373ad5861c160530ce3dbb19aa7df74/src/services/TaskTypeService.php#L72-L92 |
39,829 | akeneo/php-coupling-detector | src/Console/Command/DetectCommand.php | DetectCommand.initEventDispatcher | private function initEventDispatcher(
OutputInterface $output,
string $formatterName,
bool $verbose
): EventDispatcherInterface {
if ('dot' === $formatterName) {
$formatter = new DotFormatter($output);
} elseif ('pretty' === $formatterName) {
$formatter = new PrettyFormatter($output, $verbose);
} elseif ('simple' === $formatterName) {
$formatter = new SimpleFormatter();
} else {
throw new \RuntimeException(
sprintf('Format "%s" is unknown. Available formats: %s.', $formatterName, implode(', ', $this->formats))
);
}
$eventDispatcher = new EventDispatcher();
$eventDispatcher->addSubscriber($formatter);
return $eventDispatcher;
} | php | private function initEventDispatcher(
OutputInterface $output,
string $formatterName,
bool $verbose
): EventDispatcherInterface {
if ('dot' === $formatterName) {
$formatter = new DotFormatter($output);
} elseif ('pretty' === $formatterName) {
$formatter = new PrettyFormatter($output, $verbose);
} elseif ('simple' === $formatterName) {
$formatter = new SimpleFormatter();
} else {
throw new \RuntimeException(
sprintf('Format "%s" is unknown. Available formats: %s.', $formatterName, implode(', ', $this->formats))
);
}
$eventDispatcher = new EventDispatcher();
$eventDispatcher->addSubscriber($formatter);
return $eventDispatcher;
} | [
"private",
"function",
"initEventDispatcher",
"(",
"OutputInterface",
"$",
"output",
",",
"string",
"$",
"formatterName",
",",
"bool",
"$",
"verbose",
")",
":",
"EventDispatcherInterface",
"{",
"if",
"(",
"'dot'",
"===",
"$",
"formatterName",
")",
"{",
"$",
"f... | Init the event dispatcher by attaching the output formatters. | [
"Init",
"the",
"event",
"dispatcher",
"by",
"attaching",
"the",
"output",
"formatters",
"."
] | 3687510c8bd9d6dc23be0f39d832f4b3be7973c1 | https://github.com/akeneo/php-coupling-detector/blob/3687510c8bd9d6dc23be0f39d832f4b3be7973c1/src/Console/Command/DetectCommand.php#L166-L187 |
39,830 | akeneo/php-coupling-detector | src/CouplingDetector.php | CouplingDetector.detect | public function detect(Finder $finder, array $rules): array
{
$nodes = $this->parseNodes($finder);
$violations = array();
$this->eventDispatcher->dispatch(Events::PRE_RULES_CHECKED, new PreRulesCheckedEvent($rules));
foreach ($rules as $rule) {
$ruleViolations = array();
foreach ($nodes as $node) {
$violation = $this->ruleChecker->check($rule, $node);
if (null !== $violation) {
$ruleViolations[] = $violation;
}
$this->eventDispatcher->dispatch(
Events::NODE_CHECKED,
new NodeChecked($node, $rule, $violation)
);
}
$this->eventDispatcher->dispatch(
Events::RULE_CHECKED,
new RuleCheckedEvent($rule, $ruleViolations)
);
$violations = array_merge($violations, $ruleViolations);
}
$this->eventDispatcher->dispatch(Events::POST_RULES_CHECKED, new PostRulesCheckedEvent($violations));
return $violations;
} | php | public function detect(Finder $finder, array $rules): array
{
$nodes = $this->parseNodes($finder);
$violations = array();
$this->eventDispatcher->dispatch(Events::PRE_RULES_CHECKED, new PreRulesCheckedEvent($rules));
foreach ($rules as $rule) {
$ruleViolations = array();
foreach ($nodes as $node) {
$violation = $this->ruleChecker->check($rule, $node);
if (null !== $violation) {
$ruleViolations[] = $violation;
}
$this->eventDispatcher->dispatch(
Events::NODE_CHECKED,
new NodeChecked($node, $rule, $violation)
);
}
$this->eventDispatcher->dispatch(
Events::RULE_CHECKED,
new RuleCheckedEvent($rule, $ruleViolations)
);
$violations = array_merge($violations, $ruleViolations);
}
$this->eventDispatcher->dispatch(Events::POST_RULES_CHECKED, new PostRulesCheckedEvent($violations));
return $violations;
} | [
"public",
"function",
"detect",
"(",
"Finder",
"$",
"finder",
",",
"array",
"$",
"rules",
")",
":",
"array",
"{",
"$",
"nodes",
"=",
"$",
"this",
"->",
"parseNodes",
"(",
"$",
"finder",
")",
";",
"$",
"violations",
"=",
"array",
"(",
")",
";",
"$",... | Detect the coupling errors of the nodes that are found among a set of rules.
@param Finder $finder
@param RuleInterface[] $rules
@return ViolationInterface[] | [
"Detect",
"the",
"coupling",
"errors",
"of",
"the",
"nodes",
"that",
"are",
"found",
"among",
"a",
"set",
"of",
"rules",
"."
] | 3687510c8bd9d6dc23be0f39d832f4b3be7973c1 | https://github.com/akeneo/php-coupling-detector/blob/3687510c8bd9d6dc23be0f39d832f4b3be7973c1/src/CouplingDetector.php#L67-L100 |
39,831 | akeneo/php-coupling-detector | src/RuleChecker.php | RuleChecker.match | public function match(RuleInterface $rule, NodeInterface $node): bool
{
if (false !== strpos($node->getSubject(), $rule->getSubject())) {
return true;
}
return false;
} | php | public function match(RuleInterface $rule, NodeInterface $node): bool
{
if (false !== strpos($node->getSubject(), $rule->getSubject())) {
return true;
}
return false;
} | [
"public",
"function",
"match",
"(",
"RuleInterface",
"$",
"rule",
",",
"NodeInterface",
"$",
"node",
")",
":",
"bool",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"node",
"->",
"getSubject",
"(",
")",
",",
"$",
"rule",
"->",
"getSubject",
"(",
... | Does a node match a rule? | [
"Does",
"a",
"node",
"match",
"a",
"rule?"
] | 3687510c8bd9d6dc23be0f39d832f4b3be7973c1 | https://github.com/akeneo/php-coupling-detector/blob/3687510c8bd9d6dc23be0f39d832f4b3be7973c1/src/RuleChecker.php#L31-L38 |
39,832 | akeneo/php-coupling-detector | src/RuleChecker.php | RuleChecker.check | public function check(RuleInterface $rule, NodeInterface $node): ?ViolationInterface
{
if (!$this->match($rule, $node)) {
return null;
}
switch ($rule->getType()) {
case RuleInterface::TYPE_FORBIDDEN:
case RuleInterface::TYPE_DISCOURAGED:
$violation = $this->checkForbiddenOrDiscouragedRule($rule, $node);
break;
case RuleInterface::TYPE_ONLY:
$violation = $this->checkOnlyRule($rule, $node);
break;
default:
throw new \RuntimeException(sprintf('Unknown rule type "%s".', $rule->getType()));
}
return $violation;
} | php | public function check(RuleInterface $rule, NodeInterface $node): ?ViolationInterface
{
if (!$this->match($rule, $node)) {
return null;
}
switch ($rule->getType()) {
case RuleInterface::TYPE_FORBIDDEN:
case RuleInterface::TYPE_DISCOURAGED:
$violation = $this->checkForbiddenOrDiscouragedRule($rule, $node);
break;
case RuleInterface::TYPE_ONLY:
$violation = $this->checkOnlyRule($rule, $node);
break;
default:
throw new \RuntimeException(sprintf('Unknown rule type "%s".', $rule->getType()));
}
return $violation;
} | [
"public",
"function",
"check",
"(",
"RuleInterface",
"$",
"rule",
",",
"NodeInterface",
"$",
"node",
")",
":",
"?",
"ViolationInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"match",
"(",
"$",
"rule",
",",
"$",
"node",
")",
")",
"{",
"return",
"n... | Checks if a node respect a rule. | [
"Checks",
"if",
"a",
"node",
"respect",
"a",
"rule",
"."
] | 3687510c8bd9d6dc23be0f39d832f4b3be7973c1 | https://github.com/akeneo/php-coupling-detector/blob/3687510c8bd9d6dc23be0f39d832f4b3be7973c1/src/RuleChecker.php#L43-L62 |
39,833 | akeneo/php-coupling-detector | src/RuleChecker.php | RuleChecker.checkForbiddenOrDiscouragedRule | private function checkForbiddenOrDiscouragedRule(RuleInterface $rule, NodeInterface $node): ?ViolationInterface
{
$errors = array();
foreach ($node->getTokens() as $token) {
if (!$this->checkTokenForForbiddenOrDiscouragedRule($rule, $token) &&
!in_array($token, $errors)) {
$errors[] = $token;
}
}
if (count($errors)) {
$type = $rule->getType() === RuleInterface::TYPE_FORBIDDEN ?
ViolationInterface::TYPE_ERROR :
ViolationInterface::TYPE_WARNING
;
return new Violation($node, $rule, $errors, $type);
}
return null;
} | php | private function checkForbiddenOrDiscouragedRule(RuleInterface $rule, NodeInterface $node): ?ViolationInterface
{
$errors = array();
foreach ($node->getTokens() as $token) {
if (!$this->checkTokenForForbiddenOrDiscouragedRule($rule, $token) &&
!in_array($token, $errors)) {
$errors[] = $token;
}
}
if (count($errors)) {
$type = $rule->getType() === RuleInterface::TYPE_FORBIDDEN ?
ViolationInterface::TYPE_ERROR :
ViolationInterface::TYPE_WARNING
;
return new Violation($node, $rule, $errors, $type);
}
return null;
} | [
"private",
"function",
"checkForbiddenOrDiscouragedRule",
"(",
"RuleInterface",
"$",
"rule",
",",
"NodeInterface",
"$",
"node",
")",
":",
"?",
"ViolationInterface",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"getTokens"... | Checks if a node respects a "forbidden" or "discouraged" rule.
A node respects such a rule if no rule token is present in the node. | [
"Checks",
"if",
"a",
"node",
"respects",
"a",
"forbidden",
"or",
"discouraged",
"rule",
".",
"A",
"node",
"respects",
"such",
"a",
"rule",
"if",
"no",
"rule",
"token",
"is",
"present",
"in",
"the",
"node",
"."
] | 3687510c8bd9d6dc23be0f39d832f4b3be7973c1 | https://github.com/akeneo/php-coupling-detector/blob/3687510c8bd9d6dc23be0f39d832f4b3be7973c1/src/RuleChecker.php#L68-L89 |
39,834 | akeneo/php-coupling-detector | src/RuleChecker.php | RuleChecker.checkOnlyRule | private function checkOnlyRule(RuleInterface $rule, NodeInterface $node): ?Violation
{
$errors = array();
foreach ($node->getTokens() as $token) {
if (!$this->checkTokenForOnlyRule($rule, $token) &&
!in_array($token, $errors)) {
$errors[] = $token;
}
}
if (count($errors)) {
return new Violation($node, $rule, $errors, ViolationInterface::TYPE_ERROR);
}
return null;
} | php | private function checkOnlyRule(RuleInterface $rule, NodeInterface $node): ?Violation
{
$errors = array();
foreach ($node->getTokens() as $token) {
if (!$this->checkTokenForOnlyRule($rule, $token) &&
!in_array($token, $errors)) {
$errors[] = $token;
}
}
if (count($errors)) {
return new Violation($node, $rule, $errors, ViolationInterface::TYPE_ERROR);
}
return null;
} | [
"private",
"function",
"checkOnlyRule",
"(",
"RuleInterface",
"$",
"rule",
",",
"NodeInterface",
"$",
"node",
")",
":",
"?",
"Violation",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"getTokens",
"(",
")",
"as",
"... | Checks if a node respects a "only" rule.
A node respects such a rule if the node contains only tokens defined in the rule. | [
"Checks",
"if",
"a",
"node",
"respects",
"a",
"only",
"rule",
".",
"A",
"node",
"respects",
"such",
"a",
"rule",
"if",
"the",
"node",
"contains",
"only",
"tokens",
"defined",
"in",
"the",
"rule",
"."
] | 3687510c8bd9d6dc23be0f39d832f4b3be7973c1 | https://github.com/akeneo/php-coupling-detector/blob/3687510c8bd9d6dc23be0f39d832f4b3be7973c1/src/RuleChecker.php#L109-L125 |
39,835 | akeneo/php-coupling-detector | src/RuleChecker.php | RuleChecker.checkTokenForOnlyRule | private function checkTokenForOnlyRule(RuleInterface $rule, $token): bool
{
$fitRuleRequirements = false;
foreach ($rule->getRequirements() as $req) {
if (false !== strpos($token, $req)) {
$fitRuleRequirements = true;
}
}
return $fitRuleRequirements;
} | php | private function checkTokenForOnlyRule(RuleInterface $rule, $token): bool
{
$fitRuleRequirements = false;
foreach ($rule->getRequirements() as $req) {
if (false !== strpos($token, $req)) {
$fitRuleRequirements = true;
}
}
return $fitRuleRequirements;
} | [
"private",
"function",
"checkTokenForOnlyRule",
"(",
"RuleInterface",
"$",
"rule",
",",
"$",
"token",
")",
":",
"bool",
"{",
"$",
"fitRuleRequirements",
"=",
"false",
";",
"foreach",
"(",
"$",
"rule",
"->",
"getRequirements",
"(",
")",
"as",
"$",
"req",
")... | Checks if a token fits a "only" rule or not. | [
"Checks",
"if",
"a",
"token",
"fits",
"a",
"only",
"rule",
"or",
"not",
"."
] | 3687510c8bd9d6dc23be0f39d832f4b3be7973c1 | https://github.com/akeneo/php-coupling-detector/blob/3687510c8bd9d6dc23be0f39d832f4b3be7973c1/src/RuleChecker.php#L130-L140 |
39,836 | czim/file-handling | src/Support/Content/UploadedContentInterpreter.php | UploadedContentInterpreter.interpret | public function interpret(RawContentInterface $content)
{
// Treat any string longer than 2048 characters as full data
if ( $content->size() <= static::FULL_DATA_THRESHOLD
&& filter_var($content->content(), FILTER_VALIDATE_URL)
) {
return ContentTypes::URI;
}
// Detect data uri
if (preg_match(static::DATAURI_REGEX, $content->chunk(0, static::DATAURI_TEST_CHUNK))) {
return ContentTypes::DATAURI;
}
return ContentTypes::RAW;
} | php | public function interpret(RawContentInterface $content)
{
// Treat any string longer than 2048 characters as full data
if ( $content->size() <= static::FULL_DATA_THRESHOLD
&& filter_var($content->content(), FILTER_VALIDATE_URL)
) {
return ContentTypes::URI;
}
// Detect data uri
if (preg_match(static::DATAURI_REGEX, $content->chunk(0, static::DATAURI_TEST_CHUNK))) {
return ContentTypes::DATAURI;
}
return ContentTypes::RAW;
} | [
"public",
"function",
"interpret",
"(",
"RawContentInterface",
"$",
"content",
")",
"{",
"// Treat any string longer than 2048 characters as full data",
"if",
"(",
"$",
"content",
"->",
"size",
"(",
")",
"<=",
"static",
"::",
"FULL_DATA_THRESHOLD",
"&&",
"filter_var",
... | Returns which type the given content is deemed to be.
@param RawContentInterface $content
@return string
@see ContentTypes | [
"Returns",
"which",
"type",
"the",
"given",
"content",
"is",
"deemed",
"to",
"be",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Content/UploadedContentInterpreter.php#L23-L38 |
39,837 | czim/file-handling | src/Support/Content/MimeTypeHelper.php | MimeTypeHelper.guessMimeTypeForContent | public function guessMimeTypeForContent($content)
{
$finfo = new finfo(FILEINFO_MIME);
// Strip charset and other potential data, keep only the base type
$parts = explode(' ', $finfo->buffer($content));
return trim($parts[0], '; ');
} | php | public function guessMimeTypeForContent($content)
{
$finfo = new finfo(FILEINFO_MIME);
// Strip charset and other potential data, keep only the base type
$parts = explode(' ', $finfo->buffer($content));
return trim($parts[0], '; ');
} | [
"public",
"function",
"guessMimeTypeForContent",
"(",
"$",
"content",
")",
"{",
"$",
"finfo",
"=",
"new",
"finfo",
"(",
"FILEINFO_MIME",
")",
";",
"// Strip charset and other potential data, keep only the base type",
"$",
"parts",
"=",
"explode",
"(",
"' '",
",",
"$... | Returns the mime type for given raw file content.
@param string $content
@return string | [
"Returns",
"the",
"mime",
"type",
"for",
"given",
"raw",
"file",
"content",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Content/MimeTypeHelper.php#L40-L48 |
39,838 | czim/file-handling | src/Support/Download/UrlDownloader.php | UrlDownloader.download | public function download($url)
{
$localPath = $this->makeLocalTemporaryPath();
$url = $this->normalizeUrl($url);
$this->downloadToTempLocalPath($url, $localPath);
// Remove the query string if it exists, to make sure the extension is valid
if (false !== strpos($url, '?')) {
$url = explode('?', $url)[0];
}
$pathinfo = pathinfo($url);
// If the file has no extension, rename the local instance with a guessed extension added.
if (empty($pathinfo['extension'])) {
$localPath = $this->renameLocalTemporaryFileWithAddedExtension($localPath, $pathinfo['basename']);
}
return $localPath;
} | php | public function download($url)
{
$localPath = $this->makeLocalTemporaryPath();
$url = $this->normalizeUrl($url);
$this->downloadToTempLocalPath($url, $localPath);
// Remove the query string if it exists, to make sure the extension is valid
if (false !== strpos($url, '?')) {
$url = explode('?', $url)[0];
}
$pathinfo = pathinfo($url);
// If the file has no extension, rename the local instance with a guessed extension added.
if (empty($pathinfo['extension'])) {
$localPath = $this->renameLocalTemporaryFileWithAddedExtension($localPath, $pathinfo['basename']);
}
return $localPath;
} | [
"public",
"function",
"download",
"(",
"$",
"url",
")",
"{",
"$",
"localPath",
"=",
"$",
"this",
"->",
"makeLocalTemporaryPath",
"(",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"normalizeUrl",
"(",
"$",
"url",
")",
";",
"$",
"this",
"->",
"downloa... | Downloads from a URL and returns locally stored temporary file.
@param string $url
@return string
@throws CouldNotRetrieveRemoteFileException | [
"Downloads",
"from",
"a",
"URL",
"and",
"returns",
"locally",
"stored",
"temporary",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Download/UrlDownloader.php#L34-L55 |
39,839 | czim/file-handling | src/Support/Download/UrlDownloader.php | UrlDownloader.downloadToTempLocalPath | protected function downloadToTempLocalPath($url, $localPath)
{
try {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$rawFile = curl_exec($ch);
curl_close($ch);
if (false === $rawFile) {
throw new CouldNotRetrieveRemoteFileException(
"curl_exec failed while downloading '{$url}': " . curl_error($ch)
);
}
} catch (Exception $e) {
throw new CouldNotRetrieveRemoteFileException(
"Failed to download file content from '{$url}': ",
$e->getCode(),
$e
);
}
try {
if (false === file_put_contents($localPath, $rawFile)) {
throw new CouldNotRetrieveRemoteFileException('file_put_contents call failed');
}
} catch (Exception $e) {
throw new CouldNotRetrieveRemoteFileException(
'file_put_contents call threw an exception',
$e->getCode(),
$e
);
}
} | php | protected function downloadToTempLocalPath($url, $localPath)
{
try {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$rawFile = curl_exec($ch);
curl_close($ch);
if (false === $rawFile) {
throw new CouldNotRetrieveRemoteFileException(
"curl_exec failed while downloading '{$url}': " . curl_error($ch)
);
}
} catch (Exception $e) {
throw new CouldNotRetrieveRemoteFileException(
"Failed to download file content from '{$url}': ",
$e->getCode(),
$e
);
}
try {
if (false === file_put_contents($localPath, $rawFile)) {
throw new CouldNotRetrieveRemoteFileException('file_put_contents call failed');
}
} catch (Exception $e) {
throw new CouldNotRetrieveRemoteFileException(
'file_put_contents call threw an exception',
$e->getCode(),
$e
);
}
} | [
"protected",
"function",
"downloadToTempLocalPath",
"(",
"$",
"url",
",",
"$",
"localPath",
")",
"{",
"try",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HEADER",
",",
"0",
")",
";",
"curl_se... | Downloads raw file content from a URL to a local path.
@param string $url
@param string $localPath
@throws CouldNotRetrieveRemoteFileException
@codeCoverageIgnore | [
"Downloads",
"raw",
"file",
"content",
"from",
"a",
"URL",
"to",
"a",
"local",
"path",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Download/UrlDownloader.php#L65-L103 |
39,840 | czim/file-handling | src/Storage/File/ProcessableFile.php | ProcessableFile.setDerivedFileProperties | protected function setDerivedFileProperties()
{
if ( ! $this->file || ! file_exists($this->file->getRealPath())) {
throw new RuntimeException("Local file not found at {$this->file->getPath()}");
}
$this->size = $this->file->getSize();
if (null === $this->name) {
$this->name = $this->file->getBasename();
}
} | php | protected function setDerivedFileProperties()
{
if ( ! $this->file || ! file_exists($this->file->getRealPath())) {
throw new RuntimeException("Local file not found at {$this->file->getPath()}");
}
$this->size = $this->file->getSize();
if (null === $this->name) {
$this->name = $this->file->getBasename();
}
} | [
"protected",
"function",
"setDerivedFileProperties",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
"||",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"file",
"->",
"getRealPath",
"(",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"("... | Sets properties based on the given data. | [
"Sets",
"properties",
"based",
"on",
"the",
"given",
"data",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/ProcessableFile.php#L46-L57 |
39,841 | czim/file-handling | src/Support/Image/OrientationFixer.php | OrientationFixer.fixFile | public function fixFile(SplFileInfo $file)
{
$filePath = $file->getRealPath();
$image = $this->imagine->open($file->getRealPath());
$image = $this->fixImage($filePath, $image);
$image->save();
return true;
} | php | public function fixFile(SplFileInfo $file)
{
$filePath = $file->getRealPath();
$image = $this->imagine->open($file->getRealPath());
$image = $this->fixImage($filePath, $image);
$image->save();
return true;
} | [
"public",
"function",
"fixFile",
"(",
"SplFileInfo",
"$",
"file",
")",
"{",
"$",
"filePath",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"$",
"image",
"=",
"$",
"this",
"->",
"imagine",
"->",
"open",
"(",
"$",
"file",
"->",
"getRealPath",
"... | Fixes the orientation in a local file.
This overwrites the current file.
@param SplFileInfo $file
@return bool
@throws ErrorException | [
"Fixes",
"the",
"orientation",
"in",
"a",
"local",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/OrientationFixer.php#L84-L94 |
39,842 | czim/file-handling | src/Support/Image/OrientationFixer.php | OrientationFixer.fixImage | public function fixImage($path, ImageInterface $image)
{
// @codeCoverageIgnoreStart
if ( ! function_exists('exif_read_data')) {
return $image;
}
// @codeCoverageIgnoreEnd
try {
$exif = exif_read_data($path);
// @codeCoverageIgnoreStart
} catch (ErrorException $e) {
if ($this->quiet) {
return $image;
}
throw $e;
// @codeCoverageIgnoreEnd
}
if ( ! isset($exif['Orientation']) || $exif['Orientation'] == static::ORIENTATION_TOPLEFT) {
return $image;
}
switch ($exif['Orientation']) {
case static::ORIENTATION_TOPRIGHT:
$image->flipHorizontally();
break;
case static::ORIENTATION_BOTTOMRIGHT:
$image->rotate(180);
break;
case static::ORIENTATION_BOTTOMLEFT:
$image->flipVertically();
break;
case static::ORIENTATION_LEFTTOP:
$image->flipVertically()->rotate(90);
break;
case static::ORIENTATION_RIGHTTOP:
$image->rotate(90);
break;
case static::ORIENTATION_RIGHTBOTTOM:
$image->flipHorizontally()->rotate(90);
break;
case static::ORIENTATION_LEFTBOTTOM:
$image->rotate(-90);
break;
}
return $image->strip();
} | php | public function fixImage($path, ImageInterface $image)
{
// @codeCoverageIgnoreStart
if ( ! function_exists('exif_read_data')) {
return $image;
}
// @codeCoverageIgnoreEnd
try {
$exif = exif_read_data($path);
// @codeCoverageIgnoreStart
} catch (ErrorException $e) {
if ($this->quiet) {
return $image;
}
throw $e;
// @codeCoverageIgnoreEnd
}
if ( ! isset($exif['Orientation']) || $exif['Orientation'] == static::ORIENTATION_TOPLEFT) {
return $image;
}
switch ($exif['Orientation']) {
case static::ORIENTATION_TOPRIGHT:
$image->flipHorizontally();
break;
case static::ORIENTATION_BOTTOMRIGHT:
$image->rotate(180);
break;
case static::ORIENTATION_BOTTOMLEFT:
$image->flipVertically();
break;
case static::ORIENTATION_LEFTTOP:
$image->flipVertically()->rotate(90);
break;
case static::ORIENTATION_RIGHTTOP:
$image->rotate(90);
break;
case static::ORIENTATION_RIGHTBOTTOM:
$image->flipHorizontally()->rotate(90);
break;
case static::ORIENTATION_LEFTBOTTOM:
$image->rotate(-90);
break;
}
return $image->strip();
} | [
"public",
"function",
"fixImage",
"(",
"$",
"path",
",",
"ImageInterface",
"$",
"image",
")",
"{",
"// @codeCoverageIgnoreStart",
"if",
"(",
"!",
"function_exists",
"(",
"'exif_read_data'",
")",
")",
"{",
"return",
"$",
"image",
";",
"}",
"// @codeCoverageIgnore... | Re-orient an image using its embedded Exif profile orientation.
1. Attempt to read the embedded exif data inside the image to determine it's orientation.
if there is no exif data (i.e an exeption is thrown when trying to read it) then we'll
just return the image as is.
2. If there is exif data, we'll rotate and flip the image accordingly to re-orient it.
3. Finally, we'll strip the exif data from the image so that there can be no
attempt to 'correct' it again.
@param string $path
@param ImageInterface $image
@return ImageInterface $image
@throws ErrorException | [
"Re",
"-",
"orient",
"an",
"image",
"using",
"its",
"embedded",
"Exif",
"profile",
"orientation",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/OrientationFixer.php#L111-L166 |
39,843 | czim/file-handling | src/Variant/VariantProcessor.php | VariantProcessor.setConfig | public function setConfig(array $config)
{
$this->config = $config;
if (array_key_exists(static::CONFIG_VARIANT_FACTORY, $config)) {
$this->strategyFactory->setConfig(
$config[ static::CONFIG_VARIANT_FACTORY ]
);
}
return $this;
} | php | public function setConfig(array $config)
{
$this->config = $config;
if (array_key_exists(static::CONFIG_VARIANT_FACTORY, $config)) {
$this->strategyFactory->setConfig(
$config[ static::CONFIG_VARIANT_FACTORY ]
);
}
return $this;
} | [
"public",
"function",
"setConfig",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
";",
"if",
"(",
"array_key_exists",
"(",
"static",
"::",
"CONFIG_VARIANT_FACTORY",
",",
"$",
"config",
")",
")",
"{",
"$",
"this",
... | Sets configuration for the processor.
@param array $config
@return $this | [
"Sets",
"configuration",
"for",
"the",
"processor",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Variant/VariantProcessor.php#L60-L71 |
39,844 | czim/file-handling | src/Variant/VariantProcessor.php | VariantProcessor.process | public function process(StorableFileInterface $source, $variant, array $strategies)
{
$file = $this->makeTemporaryCopy($source);
foreach ($strategies as $strategy => $options) {
$instance = $this->strategyFactory->make($strategy)->setOptions($options);
// The file returned by the strategy step may have altered the path,
// name, extension and/or mime type of the file being processed.
// This information is present in the returned ProcessableFile instance.
try {
$newFile = $instance->apply($file);
} catch (VariantStrategyShouldNotBeAppliedException $e) {
if ($this->shouldThrowExceptionForUnappliedStrategy()) {
throw new VariantStrategyNotAppliedException(
"Strategy '{$strategy}' not applied to '{$source->path()}'"
);
}
continue;
}
if (false === $newFile) {
throw new VariantStrategyNotAppliedException(
"Failed to apply '{$strategy}' to '{$source->path()}'"
);
}
$file = $newFile;
}
return $file;
} | php | public function process(StorableFileInterface $source, $variant, array $strategies)
{
$file = $this->makeTemporaryCopy($source);
foreach ($strategies as $strategy => $options) {
$instance = $this->strategyFactory->make($strategy)->setOptions($options);
// The file returned by the strategy step may have altered the path,
// name, extension and/or mime type of the file being processed.
// This information is present in the returned ProcessableFile instance.
try {
$newFile = $instance->apply($file);
} catch (VariantStrategyShouldNotBeAppliedException $e) {
if ($this->shouldThrowExceptionForUnappliedStrategy()) {
throw new VariantStrategyNotAppliedException(
"Strategy '{$strategy}' not applied to '{$source->path()}'"
);
}
continue;
}
if (false === $newFile) {
throw new VariantStrategyNotAppliedException(
"Failed to apply '{$strategy}' to '{$source->path()}'"
);
}
$file = $newFile;
}
return $file;
} | [
"public",
"function",
"process",
"(",
"StorableFileInterface",
"$",
"source",
",",
"$",
"variant",
",",
"array",
"$",
"strategies",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"makeTemporaryCopy",
"(",
"$",
"source",
")",
";",
"foreach",
"(",
"$",
"st... | Returns a processed variant for a given source file.
@param StorableFileInterface $source
@param string $variant the name/prefix name of the variant
@param array[] $strategies associative, ordered set of strategies to apply
@return StorableFileInterface
@throws VariantStrategyNotAppliedException
@throws CouldNotProcessDataException | [
"Returns",
"a",
"processed",
"variant",
"for",
"a",
"given",
"source",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Variant/VariantProcessor.php#L83-L119 |
39,845 | czim/file-handling | src/Variant/VariantProcessor.php | VariantProcessor.shouldThrowExceptionForUnappliedStrategy | protected function shouldThrowExceptionForUnappliedStrategy()
{
if ( ! array_key_exists(static::CONFIG_FORCE_APPLY, $this->config)) {
return false;
}
return (bool) $this->config[ static::CONFIG_FORCE_APPLY ];
} | php | protected function shouldThrowExceptionForUnappliedStrategy()
{
if ( ! array_key_exists(static::CONFIG_FORCE_APPLY, $this->config)) {
return false;
}
return (bool) $this->config[ static::CONFIG_FORCE_APPLY ];
} | [
"protected",
"function",
"shouldThrowExceptionForUnappliedStrategy",
"(",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"static",
"::",
"CONFIG_FORCE_APPLY",
",",
"$",
"this",
"->",
"config",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"boo... | Returns whether exceptions should be thrown if a strategy was not applied.
@return bool | [
"Returns",
"whether",
"exceptions",
"should",
"be",
"thrown",
"if",
"a",
"strategy",
"was",
"not",
"applied",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Variant/VariantProcessor.php#L126-L133 |
39,846 | czim/file-handling | src/Variant/VariantProcessor.php | VariantProcessor.makeTemporaryCopy | protected function makeTemporaryCopy(StorableFileInterface $source)
{
$path = $this->makeLocalTemporaryPath($source->extension());
try {
$success = $source->copy($path);
// @codeCoverageIgnoreStart
} catch (Exception $e) {
throw new CouldNotProcessDataException("Failed to make variant copy to '{$path}'", $e->getCode(), $e);
// @codeCoverageIgnoreEnd
}
// @codeCoverageIgnoreStart
if ( ! $success) {
throw new CouldNotProcessDataException("Failed to make variant copy to '{$path}'");
}
// @codeCoverageIgnoreEnd
$file = new ProcessableFile;
$file->setName($source->name());
$file->setMimeType($source->mimeType());
$file->setData($path);
return $file;
} | php | protected function makeTemporaryCopy(StorableFileInterface $source)
{
$path = $this->makeLocalTemporaryPath($source->extension());
try {
$success = $source->copy($path);
// @codeCoverageIgnoreStart
} catch (Exception $e) {
throw new CouldNotProcessDataException("Failed to make variant copy to '{$path}'", $e->getCode(), $e);
// @codeCoverageIgnoreEnd
}
// @codeCoverageIgnoreStart
if ( ! $success) {
throw new CouldNotProcessDataException("Failed to make variant copy to '{$path}'");
}
// @codeCoverageIgnoreEnd
$file = new ProcessableFile;
$file->setName($source->name());
$file->setMimeType($source->mimeType());
$file->setData($path);
return $file;
} | [
"protected",
"function",
"makeTemporaryCopy",
"(",
"StorableFileInterface",
"$",
"source",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"makeLocalTemporaryPath",
"(",
"$",
"source",
"->",
"extension",
"(",
")",
")",
";",
"try",
"{",
"$",
"success",
"=",
... | Makes a copy of the original file info that will be manipulated into the variant.
@param StorableFileInterface $source
@return ProcessableFileInterface
@throws CouldNotProcessDataException | [
"Makes",
"a",
"copy",
"of",
"the",
"original",
"file",
"info",
"that",
"will",
"be",
"manipulated",
"into",
"the",
"variant",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Variant/VariantProcessor.php#L142-L168 |
39,847 | czim/file-handling | src/Variant/Strategies/AbstractVariantStrategy.php | AbstractVariantStrategy.apply | public function apply(ProcessableFileInterface $file)
{
$this->file = $file;
if ( ! $this->shouldBeApplied()) {
throw new VariantStrategyShouldNotBeAppliedException;
}
$result = $this->perform();
return ($result || null === $result) ? $this->file : false;
} | php | public function apply(ProcessableFileInterface $file)
{
$this->file = $file;
if ( ! $this->shouldBeApplied()) {
throw new VariantStrategyShouldNotBeAppliedException;
}
$result = $this->perform();
return ($result || null === $result) ? $this->file : false;
} | [
"public",
"function",
"apply",
"(",
"ProcessableFileInterface",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"file",
"=",
"$",
"file",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"shouldBeApplied",
"(",
")",
")",
"{",
"throw",
"new",
"VariantStrategyShouldNotBeAp... | Applies strategy to a file.
@param ProcessableFileInterface $file
@return ProcessableFileInterface|false
@throws VariantStrategyShouldNotBeAppliedException | [
"Applies",
"strategy",
"to",
"a",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Variant/Strategies/AbstractVariantStrategy.php#L32-L43 |
39,848 | czim/file-handling | src/Handler/FileHandler.php | FileHandler.process | public function process(StorableFileInterface $source, TargetInterface $target, array $options = [])
{
$stored = [
static::ORIGINAL => $this->storage->store($source, $target->original()),
];
if (array_key_exists(static::CONFIG_VARIANTS, $options)) {
foreach ($options[ static::CONFIG_VARIANTS ] as $variant => $variantOptions) {
$stored[ $variant ] = $this->processVariant($source, $target, $variant, $variantOptions);
}
}
return $stored;
} | php | public function process(StorableFileInterface $source, TargetInterface $target, array $options = [])
{
$stored = [
static::ORIGINAL => $this->storage->store($source, $target->original()),
];
if (array_key_exists(static::CONFIG_VARIANTS, $options)) {
foreach ($options[ static::CONFIG_VARIANTS ] as $variant => $variantOptions) {
$stored[ $variant ] = $this->processVariant($source, $target, $variant, $variantOptions);
}
}
return $stored;
} | [
"public",
"function",
"process",
"(",
"StorableFileInterface",
"$",
"source",
",",
"TargetInterface",
"$",
"target",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"stored",
"=",
"[",
"static",
"::",
"ORIGINAL",
"=>",
"$",
"this",
"->",
"sto... | Processes and stores a storable file.
@param StorableFileInterface $source
@param TargetInterface $target
@param array $options
@return StoredFileInterface[] keyed by variant name (or 'original') | [
"Processes",
"and",
"stores",
"a",
"storable",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Handler/FileHandler.php#L61-L75 |
39,849 | czim/file-handling | src/Handler/FileHandler.php | FileHandler.processVariant | public function processVariant(StorableFileInterface $source, TargetInterface $target, $variant, array $options = [])
{
$storableVariant = $this->processor->process($source, $variant, $options);
return $this->storage->store($storableVariant, $target->variant($variant));
} | php | public function processVariant(StorableFileInterface $source, TargetInterface $target, $variant, array $options = [])
{
$storableVariant = $this->processor->process($source, $variant, $options);
return $this->storage->store($storableVariant, $target->variant($variant));
} | [
"public",
"function",
"processVariant",
"(",
"StorableFileInterface",
"$",
"source",
",",
"TargetInterface",
"$",
"target",
",",
"$",
"variant",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"storableVariant",
"=",
"$",
"this",
"->",
"processor... | Processes and stores a single variant for a storable file.
@param StorableFileInterface $source
@param TargetInterface $target
@param string $variant
@param array $options
@return StoredFileInterface | [
"Processes",
"and",
"stores",
"a",
"single",
"variant",
"for",
"a",
"storable",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Handler/FileHandler.php#L86-L91 |
39,850 | czim/file-handling | src/Handler/FileHandler.php | FileHandler.variantUrlsForTarget | public function variantUrlsForTarget(TargetInterface $target, array $variants = [])
{
$urls = [
static::ORIGINAL => $this->storage->url($target->original()),
];
if (in_array(static::ORIGINAL, $variants)) {
$variants = array_diff($variants, [ static::ORIGINAL ]);
}
foreach ($variants as $variant) {
$urls[ $variant ] = $this->storage->url($target->variant($variant));
}
return $urls;
} | php | public function variantUrlsForTarget(TargetInterface $target, array $variants = [])
{
$urls = [
static::ORIGINAL => $this->storage->url($target->original()),
];
if (in_array(static::ORIGINAL, $variants)) {
$variants = array_diff($variants, [ static::ORIGINAL ]);
}
foreach ($variants as $variant) {
$urls[ $variant ] = $this->storage->url($target->variant($variant));
}
return $urls;
} | [
"public",
"function",
"variantUrlsForTarget",
"(",
"TargetInterface",
"$",
"target",
",",
"array",
"$",
"variants",
"=",
"[",
"]",
")",
"{",
"$",
"urls",
"=",
"[",
"static",
"::",
"ORIGINAL",
"=>",
"$",
"this",
"->",
"storage",
"->",
"url",
"(",
"$",
"... | Returns the URLs keyed by the variant keys requested.
@param TargetInterface $target
@param string[] $variants keys for variants to include
@return string[] | [
"Returns",
"the",
"URLs",
"keyed",
"by",
"the",
"variant",
"keys",
"requested",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Handler/FileHandler.php#L100-L115 |
39,851 | czim/file-handling | src/Handler/FileHandler.php | FileHandler.delete | public function delete(TargetInterface $target, array $variants = [])
{
$success = true;
if ( ! in_array(static::ORIGINAL, $variants)) {
$variants[] = static::ORIGINAL;
}
foreach ($variants as $variant) {
if ( ! $this->deleteVariant($target, $variant)) {
$success = false;
}
}
return $success;
} | php | public function delete(TargetInterface $target, array $variants = [])
{
$success = true;
if ( ! in_array(static::ORIGINAL, $variants)) {
$variants[] = static::ORIGINAL;
}
foreach ($variants as $variant) {
if ( ! $this->deleteVariant($target, $variant)) {
$success = false;
}
}
return $success;
} | [
"public",
"function",
"delete",
"(",
"TargetInterface",
"$",
"target",
",",
"array",
"$",
"variants",
"=",
"[",
"]",
")",
"{",
"$",
"success",
"=",
"true",
";",
"if",
"(",
"!",
"in_array",
"(",
"static",
"::",
"ORIGINAL",
",",
"$",
"variants",
")",
"... | Deletes a file and all indicated variants.
@param TargetInterface $target
@param string[] $variants variant keys
@return bool | [
"Deletes",
"a",
"file",
"and",
"all",
"indicated",
"variants",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Handler/FileHandler.php#L124-L139 |
39,852 | czim/file-handling | src/Handler/FileHandler.php | FileHandler.deleteVariant | public function deleteVariant(TargetInterface $target, $variant)
{
if ($variant == static::ORIGINAL) {
$path = $target->original();
} else {
$path = $target->variant($variant);
}
// If the file does not exist, consider 'deletion' a success
if ( ! $this->storage->exists($path)) {
return true;
}
return $this->storage->delete($path);
} | php | public function deleteVariant(TargetInterface $target, $variant)
{
if ($variant == static::ORIGINAL) {
$path = $target->original();
} else {
$path = $target->variant($variant);
}
// If the file does not exist, consider 'deletion' a success
if ( ! $this->storage->exists($path)) {
return true;
}
return $this->storage->delete($path);
} | [
"public",
"function",
"deleteVariant",
"(",
"TargetInterface",
"$",
"target",
",",
"$",
"variant",
")",
"{",
"if",
"(",
"$",
"variant",
"==",
"static",
"::",
"ORIGINAL",
")",
"{",
"$",
"path",
"=",
"$",
"target",
"->",
"original",
"(",
")",
";",
"}",
... | Deletes a single variant.
@param TargetInterface $target may be a full file path, or a base path
@param string $variant 'original' refers to the original file
@return bool | [
"Deletes",
"a",
"single",
"variant",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Handler/FileHandler.php#L148-L162 |
39,853 | czim/file-handling | src/Support/Image/Resizer.php | Resizer.resize | public function resize(SplFileInfo $file, array $options)
{
$filePath = $file->getRealPath();
list($width, $height, $option) = $this->parseOptionDimensions($options);
$method = 'resize' . ucfirst($option);
// Custom resize (that still expects imagine to be used)
if ($method == 'resizeCustom') {
$callable = $options['dimensions'];
$this
->resizeCustom($file, $callable)
->save($filePath, $this->getConvertOptions($options));
return true;
}
$image = $this->imagine->open($file->getRealPath());
$this->$method($image, $width, $height)
->save($filePath, $this->getConvertOptions($options));
return true;
} | php | public function resize(SplFileInfo $file, array $options)
{
$filePath = $file->getRealPath();
list($width, $height, $option) = $this->parseOptionDimensions($options);
$method = 'resize' . ucfirst($option);
// Custom resize (that still expects imagine to be used)
if ($method == 'resizeCustom') {
$callable = $options['dimensions'];
$this
->resizeCustom($file, $callable)
->save($filePath, $this->getConvertOptions($options));
return true;
}
$image = $this->imagine->open($file->getRealPath());
$this->$method($image, $width, $height)
->save($filePath, $this->getConvertOptions($options));
return true;
} | [
"public",
"function",
"resize",
"(",
"SplFileInfo",
"$",
"file",
",",
"array",
"$",
"options",
")",
"{",
"$",
"filePath",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"list",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"option",
")",
... | Resize an image using given options.
@param SplFileInfo $file
@param array $options
@return bool | [
"Resize",
"an",
"image",
"using",
"given",
"options",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/Resizer.php#L41-L67 |
39,854 | czim/file-handling | src/Support/Image/Resizer.php | Resizer.getConvertOptions | protected function getConvertOptions(array $options)
{
if ($this->arrHas($options, 'convertOptions')) {
return $this->arrGet($options, 'convertOptions', []);
}
return $this->arrGet($options, 'convert_options', []);
} | php | protected function getConvertOptions(array $options)
{
if ($this->arrHas($options, 'convertOptions')) {
return $this->arrGet($options, 'convertOptions', []);
}
return $this->arrGet($options, 'convert_options', []);
} | [
"protected",
"function",
"getConvertOptions",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"arrHas",
"(",
"$",
"options",
",",
"'convertOptions'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"arrGet",
"(",
"$",
"options",
",",
... | Returns the convert options for image manipulation.
@param array $options
@return array | [
"Returns",
"the",
"convert",
"options",
"for",
"image",
"manipulation",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/Resizer.php#L76-L83 |
39,855 | czim/file-handling | src/Support/Image/Resizer.php | Resizer.parseOptionDimensions | protected function parseOptionDimensions(array $options)
{
$sourceDimensions = $this->arrGet($options, 'dimensions');
if (is_callable($sourceDimensions)) {
return [null, null, 'custom'];
}
if (strpos($sourceDimensions, 'x') === false) {
// Width given, height automagically selected to preserve aspect ratio (landscape).
$width = $sourceDimensions;
return [$width, null, 'landscape'];
}
$dimensions = explode('x', $sourceDimensions);
$width = $dimensions[0];
$height = $dimensions[1];
if (empty($width)) {
// Height given, width matched to preserve aspect ratio (portrait)
return [null, $height, 'portrait'];
}
$resizingOption = substr($height, -1, 1);
if ($resizingOption == '#') {
// Resize, then crop
$height = rtrim($height, '#');
return [$width, $height, 'crop'];
}
if ($resizingOption == '!') {
// Resize by exact width/height (ignore ratio)
$height = rtrim($height, '!');
return [$width, $height, 'exact'];
}
return [$width, $height, 'auto'];
} | php | protected function parseOptionDimensions(array $options)
{
$sourceDimensions = $this->arrGet($options, 'dimensions');
if (is_callable($sourceDimensions)) {
return [null, null, 'custom'];
}
if (strpos($sourceDimensions, 'x') === false) {
// Width given, height automagically selected to preserve aspect ratio (landscape).
$width = $sourceDimensions;
return [$width, null, 'landscape'];
}
$dimensions = explode('x', $sourceDimensions);
$width = $dimensions[0];
$height = $dimensions[1];
if (empty($width)) {
// Height given, width matched to preserve aspect ratio (portrait)
return [null, $height, 'portrait'];
}
$resizingOption = substr($height, -1, 1);
if ($resizingOption == '#') {
// Resize, then crop
$height = rtrim($height, '#');
return [$width, $height, 'crop'];
}
if ($resizingOption == '!') {
// Resize by exact width/height (ignore ratio)
$height = rtrim($height, '!');
return [$width, $height, 'exact'];
}
return [$width, $height, 'auto'];
} | [
"protected",
"function",
"parseOptionDimensions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"sourceDimensions",
"=",
"$",
"this",
"->",
"arrGet",
"(",
"$",
"options",
",",
"'dimensions'",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"sourceDimensions",
"... | Parses the dimensions given in the options.
Parse the given style dimensions to extract out the file processing options,
perform any necessary image resizing for a given style.
@param array $options
@return array | [
"Parses",
"the",
"dimensions",
"given",
"in",
"the",
"options",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/Resizer.php#L95-L137 |
39,856 | czim/file-handling | src/Support/Image/Resizer.php | Resizer.resizeAuto | protected function resizeAuto(ImageInterface $image, $width, $height)
{
$size = $image->getSize();
$originalWidth = $size->getWidth();
$originalHeight = $size->getHeight();
if ($originalHeight < $originalWidth) {
return $this->resizeLandscape($image, $width, $height);
}
if ($originalHeight > $originalWidth) {
return $this->resizePortrait($image, $width, $height);
}
if ($height < $width) {
return $this->resizeLandscape($image, $width, $height);
}
if ($height > $width) {
return $this->resizePortrait($image, $width, $height);
}
return $this->resizeExact($image, $width, $height);
} | php | protected function resizeAuto(ImageInterface $image, $width, $height)
{
$size = $image->getSize();
$originalWidth = $size->getWidth();
$originalHeight = $size->getHeight();
if ($originalHeight < $originalWidth) {
return $this->resizeLandscape($image, $width, $height);
}
if ($originalHeight > $originalWidth) {
return $this->resizePortrait($image, $width, $height);
}
if ($height < $width) {
return $this->resizeLandscape($image, $width, $height);
}
if ($height > $width) {
return $this->resizePortrait($image, $width, $height);
}
return $this->resizeExact($image, $width, $height);
} | [
"protected",
"function",
"resizeAuto",
"(",
"ImageInterface",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"$",
"size",
"=",
"$",
"image",
"->",
"getSize",
"(",
")",
";",
"$",
"originalWidth",
"=",
"$",
"size",
"->",
"getWidth",
"(",
... | Resize an image as closely as possible to a given width and height while still maintaining aspect ratio
This method is really just a proxy to other resize methods:.
If the current image is wider than it is tall, we'll resize landscape.
If the current image is taller than it is wide, we'll resize portrait.
If the image is as tall as it is wide (it's a squarey) then we'll
apply the same process using the new dimensions (we'll resize exact if
the new dimensions are both equal since at this point we'll have a square
image being resized to a square).
@param ImageInterface $image
@param string $width new width
@param string $height new height
@return ImageInterface | [
"Resize",
"an",
"image",
"as",
"closely",
"as",
"possible",
"to",
"a",
"given",
"width",
"and",
"height",
"while",
"still",
"maintaining",
"aspect",
"ratio"
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/Resizer.php#L157-L180 |
39,857 | czim/file-handling | src/Support/Image/Resizer.php | Resizer.resizeCrop | protected function resizeCrop(ImageInterface $image, $width, $height)
{
list($optimalWidth, $optimalHeight) = $this->getOptimalCrop($image->getSize(), $width, $height);
// Find center - this will be used for the crop
$centerX = ($optimalWidth / 2) - ($width / 2);
$centerY = ($optimalHeight / 2) - ($height / 2);
return $image->resize(new Box($optimalWidth, $optimalHeight))
->crop(new Point($centerX, $centerY), new Box($width, $height));
} | php | protected function resizeCrop(ImageInterface $image, $width, $height)
{
list($optimalWidth, $optimalHeight) = $this->getOptimalCrop($image->getSize(), $width, $height);
// Find center - this will be used for the crop
$centerX = ($optimalWidth / 2) - ($width / 2);
$centerY = ($optimalHeight / 2) - ($height / 2);
return $image->resize(new Box($optimalWidth, $optimalHeight))
->crop(new Point($centerX, $centerY), new Box($width, $height));
} | [
"protected",
"function",
"resizeCrop",
"(",
"ImageInterface",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"list",
"(",
"$",
"optimalWidth",
",",
"$",
"optimalHeight",
")",
"=",
"$",
"this",
"->",
"getOptimalCrop",
"(",
"$",
"image",
"-... | Resize an image and then center crop it
@param ImageInterface $image
@param string $width new width
@param string $height new height
@return ImageInterface | [
"Resize",
"an",
"image",
"and",
"then",
"center",
"crop",
"it"
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/Resizer.php#L248-L258 |
39,858 | czim/file-handling | src/Support/Image/Resizer.php | Resizer.getSizeByFixedHeight | private function getSizeByFixedHeight(ImageInterface $image, $newHeight)
{
$box = $image->getSize();
$ratio = $box->getWidth() / $box->getHeight();
$newWidth = $newHeight * $ratio;
return $newWidth;
} | php | private function getSizeByFixedHeight(ImageInterface $image, $newHeight)
{
$box = $image->getSize();
$ratio = $box->getWidth() / $box->getHeight();
$newWidth = $newHeight * $ratio;
return $newWidth;
} | [
"private",
"function",
"getSizeByFixedHeight",
"(",
"ImageInterface",
"$",
"image",
",",
"$",
"newHeight",
")",
"{",
"$",
"box",
"=",
"$",
"image",
"->",
"getSize",
"(",
")",
";",
"$",
"ratio",
"=",
"$",
"box",
"->",
"getWidth",
"(",
")",
"/",
"$",
"... | Returns the width based on the new image height.
@param ImageInterface $image
@param int $newHeight - The image's new height.
@return int | [
"Returns",
"the",
"width",
"based",
"on",
"the",
"new",
"image",
"height",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Support/Image/Resizer.php#L293-L301 |
39,859 | czim/file-handling | src/Storage/Laravel/LaravelStorage.php | LaravelStorage.get | public function get($path)
{
$raw = new RawStorableFile;
$raw->setName(pathinfo($path, PATHINFO_BASENAME));
$raw->setData($this->filesystem->get($path));
$stored = new DecoratorStoredFile($raw);
$stored->setUrl($this->prefixBaseUrl($path));
return $stored;
} | php | public function get($path)
{
$raw = new RawStorableFile;
$raw->setName(pathinfo($path, PATHINFO_BASENAME));
$raw->setData($this->filesystem->get($path));
$stored = new DecoratorStoredFile($raw);
$stored->setUrl($this->prefixBaseUrl($path));
return $stored;
} | [
"public",
"function",
"get",
"(",
"$",
"path",
")",
"{",
"$",
"raw",
"=",
"new",
"RawStorableFile",
";",
"$",
"raw",
"->",
"setName",
"(",
"pathinfo",
"(",
"$",
"path",
",",
"PATHINFO_BASENAME",
")",
")",
";",
"$",
"raw",
"->",
"setData",
"(",
"$",
... | Returns the file from storage.
Note that the mimetype is not filled in here. Tackle this manually if it is required.
@param string $path
@return StoredFileInterface | [
"Returns",
"the",
"file",
"from",
"storage",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/Laravel/LaravelStorage.php#L79-L90 |
39,860 | czim/file-handling | src/Storage/Laravel/LaravelStorage.php | LaravelStorage.store | public function store(StorableFileInterface $file, $path)
{
if ( ! $this->filesystem->put($path, $file->content())) {
throw new FileStorageException("Failed to store '{$file->name()}' to '{$path}'");
}
$stored = new DecoratorStoredFile($file);
$stored->setUrl($this->prefixBaseUrl($path));
return $stored;
} | php | public function store(StorableFileInterface $file, $path)
{
if ( ! $this->filesystem->put($path, $file->content())) {
throw new FileStorageException("Failed to store '{$file->name()}' to '{$path}'");
}
$stored = new DecoratorStoredFile($file);
$stored->setUrl($this->prefixBaseUrl($path));
return $stored;
} | [
"public",
"function",
"store",
"(",
"StorableFileInterface",
"$",
"file",
",",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"$",
"path",
",",
"$",
"file",
"->",
"content",
"(",
")",
")",
")",
"{",
"throw... | Stores a file.
@param StorableFileInterface $file mixed content to store
@param string $path where the file should be stored, including the filename
@return StoredFileInterface
@throws FileStorageException | [
"Stores",
"a",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/Laravel/LaravelStorage.php#L100-L110 |
39,861 | czim/file-handling | src/Storage/File/StorableFileFactory.php | StorableFileFactory.makeFromAny | public function makeFromAny($data, $name = null, $mimeType = null)
{
// If the data is already a storable file, return it as-is.
if ($data instanceof StorableFileInterface) {
return $this->getReturnPreparedFile($data);
}
if (null === $name && is_a($data, \Symfony\Component\HttpFoundation\File\UploadedFile::class)) {
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $data */
$name = $data->getClientOriginalName();
}
if ($data instanceof SplFileInfo) {
return $this->makeFromFileInfo($data, $name, $mimeType);
}
// Fallback: expect raw or string data, and attempt to interpret it.
if (is_string($data)) {
$data = new RawContent($data);
}
if ( ! ($data instanceof RawContentInterface)) {
throw new UnexpectedValueException('Could not interpret given data, string value expected');
}
return $this->interpretFromRawContent($data, $name, $mimeType);
} | php | public function makeFromAny($data, $name = null, $mimeType = null)
{
// If the data is already a storable file, return it as-is.
if ($data instanceof StorableFileInterface) {
return $this->getReturnPreparedFile($data);
}
if (null === $name && is_a($data, \Symfony\Component\HttpFoundation\File\UploadedFile::class)) {
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $data */
$name = $data->getClientOriginalName();
}
if ($data instanceof SplFileInfo) {
return $this->makeFromFileInfo($data, $name, $mimeType);
}
// Fallback: expect raw or string data, and attempt to interpret it.
if (is_string($data)) {
$data = new RawContent($data);
}
if ( ! ($data instanceof RawContentInterface)) {
throw new UnexpectedValueException('Could not interpret given data, string value expected');
}
return $this->interpretFromRawContent($data, $name, $mimeType);
} | [
"public",
"function",
"makeFromAny",
"(",
"$",
"data",
",",
"$",
"name",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"// If the data is already a storable file, return it as-is.",
"if",
"(",
"$",
"data",
"instanceof",
"StorableFileInterface",
")",
"{... | Makes a storable file instance from an unknown source type.
@param mixed $data
@param string|null $name
@param string|null $mimeType
@return StorableFileInterface
@throws CouldNotReadDataException
@throws CouldNotRetrieveRemoteFileException | [
"Makes",
"a",
"storable",
"file",
"instance",
"from",
"an",
"unknown",
"source",
"type",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/StorableFileFactory.php#L80-L108 |
39,862 | czim/file-handling | src/Storage/File/StorableFileFactory.php | StorableFileFactory.makeFromFileInfo | public function makeFromFileInfo(SplFileInfo $data, $name = null, $mimeType = null)
{
$file = new SplFileInfoStorableFile;
$file->setData($data);
if (null !== $mimeType) {
$file->setMimeType($mimeType);
} else {
$file->setMimeType(
$this->mimeTypeHelper->guessMimeTypeForPath($data->getRealPath())
);
}
if (empty($name)) {
$name = pathinfo($data->getRealPath(), PATHINFO_BASENAME);
}
if (null !== $name) {
$file->setName($name);
}
return $this->getReturnPreparedFile($file);
} | php | public function makeFromFileInfo(SplFileInfo $data, $name = null, $mimeType = null)
{
$file = new SplFileInfoStorableFile;
$file->setData($data);
if (null !== $mimeType) {
$file->setMimeType($mimeType);
} else {
$file->setMimeType(
$this->mimeTypeHelper->guessMimeTypeForPath($data->getRealPath())
);
}
if (empty($name)) {
$name = pathinfo($data->getRealPath(), PATHINFO_BASENAME);
}
if (null !== $name) {
$file->setName($name);
}
return $this->getReturnPreparedFile($file);
} | [
"public",
"function",
"makeFromFileInfo",
"(",
"SplFileInfo",
"$",
"data",
",",
"$",
"name",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"$",
"file",
"=",
"new",
"SplFileInfoStorableFile",
";",
"$",
"file",
"->",
"setData",
"(",
"$",
"data"... | Makes a storable file instance from an SplFileInfo instance.
@param SplFileInfo $data
@param string|null $name
@param string|null $mimeType
@return StorableFileInterface | [
"Makes",
"a",
"storable",
"file",
"instance",
"from",
"an",
"SplFileInfo",
"instance",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/StorableFileFactory.php#L118-L140 |
39,863 | czim/file-handling | src/Storage/File/StorableFileFactory.php | StorableFileFactory.makeFromLocalPath | public function makeFromLocalPath($path, $name = null, $mimeType = null)
{
$info = new SplFileInfo($path);
return $this->makeFromFileInfo($info, $name, $mimeType);
} | php | public function makeFromLocalPath($path, $name = null, $mimeType = null)
{
$info = new SplFileInfo($path);
return $this->makeFromFileInfo($info, $name, $mimeType);
} | [
"public",
"function",
"makeFromLocalPath",
"(",
"$",
"path",
",",
"$",
"name",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"$",
"info",
"=",
"new",
"SplFileInfo",
"(",
"$",
"path",
")",
";",
"return",
"$",
"this",
"->",
"makeFromFileInfo"... | Makes a normalized storable file instance from a local file path.
@param string $path
@param string|null $name
@param string|null $mimeType
@return StorableFileInterface | [
"Makes",
"a",
"normalized",
"storable",
"file",
"instance",
"from",
"a",
"local",
"file",
"path",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/StorableFileFactory.php#L150-L155 |
39,864 | czim/file-handling | src/Storage/File/StorableFileFactory.php | StorableFileFactory.makeFromUrl | public function makeFromUrl($url, $name = null, $mimeType = null)
{
try {
$localPath = $this->downloader->download($url);
} catch (Exception $e) {
throw new CouldNotRetrieveRemoteFileException(
"Could not retrieve file from '{$url}'",
$e->getcode(),
$e
);
}
if (null === $name) {
$name = $this->getBaseNameFromUrl($url);
}
// Always flag as uploaded, since we downloaded to a local path
return $this->uploaded()->makeFromLocalPath($localPath, $name, $mimeType);
} | php | public function makeFromUrl($url, $name = null, $mimeType = null)
{
try {
$localPath = $this->downloader->download($url);
} catch (Exception $e) {
throw new CouldNotRetrieveRemoteFileException(
"Could not retrieve file from '{$url}'",
$e->getcode(),
$e
);
}
if (null === $name) {
$name = $this->getBaseNameFromUrl($url);
}
// Always flag as uploaded, since we downloaded to a local path
return $this->uploaded()->makeFromLocalPath($localPath, $name, $mimeType);
} | [
"public",
"function",
"makeFromUrl",
"(",
"$",
"url",
",",
"$",
"name",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"localPath",
"=",
"$",
"this",
"->",
"downloader",
"->",
"download",
"(",
"$",
"url",
")",
";",
"}",
... | Makes a normalized storable file instance from a URI.
@param string $url
@param string|null $name
@param string|null $mimeType
@return StorableFileInterface
@throws CouldNotRetrieveRemoteFileException | [
"Makes",
"a",
"normalized",
"storable",
"file",
"instance",
"from",
"a",
"URI",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/StorableFileFactory.php#L166-L186 |
39,865 | czim/file-handling | src/Storage/File/StorableFileFactory.php | StorableFileFactory.makeFromDataUri | public function makeFromDataUri($data, $name = null, $mimeType = null)
{
if ($data instanceof RawContentInterface) {
$data = $data->content();
}
$resource = @fopen($data, 'r');
if ( ! $resource) {
throw new CouldNotReadDataException('Invalid data URI');
}
try {
$meta = stream_get_meta_data($resource);
// @codeCoverageIgnoreStart
} catch (Exception $e) {
throw new CouldNotReadDataException('Failed to interpret Data URI as stream', $e->getCode(), $e);
// @codeCoverageIgnoreEnd
}
if (null === $mimeType) {
$mimeType = $meta['mediatype'];
}
$extension = $this->mimeTypeHelper->guessExtensionForMimeType($mimeType);
$localPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5($meta['uri']) . '.' . $extension;
if (null === $name) {
$name = pathinfo($localPath, PATHINFO_BASENAME);
}
try {
file_put_contents($localPath, stream_get_contents($resource));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
throw new CouldNotReadDataException('Failed to make local file from Data URI', $e->getCode(), $e);
// @codeCoverageIgnoreEnd
}
// Always flag as uploaded, since a temp file was created
return $this->uploaded()->makeFromLocalPath($localPath, $name);
} | php | public function makeFromDataUri($data, $name = null, $mimeType = null)
{
if ($data instanceof RawContentInterface) {
$data = $data->content();
}
$resource = @fopen($data, 'r');
if ( ! $resource) {
throw new CouldNotReadDataException('Invalid data URI');
}
try {
$meta = stream_get_meta_data($resource);
// @codeCoverageIgnoreStart
} catch (Exception $e) {
throw new CouldNotReadDataException('Failed to interpret Data URI as stream', $e->getCode(), $e);
// @codeCoverageIgnoreEnd
}
if (null === $mimeType) {
$mimeType = $meta['mediatype'];
}
$extension = $this->mimeTypeHelper->guessExtensionForMimeType($mimeType);
$localPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5($meta['uri']) . '.' . $extension;
if (null === $name) {
$name = pathinfo($localPath, PATHINFO_BASENAME);
}
try {
file_put_contents($localPath, stream_get_contents($resource));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
throw new CouldNotReadDataException('Failed to make local file from Data URI', $e->getCode(), $e);
// @codeCoverageIgnoreEnd
}
// Always flag as uploaded, since a temp file was created
return $this->uploaded()->makeFromLocalPath($localPath, $name);
} | [
"public",
"function",
"makeFromDataUri",
"(",
"$",
"data",
",",
"$",
"name",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"RawContentInterface",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"->",
"content"... | Makes a normalized storable file instance from a data URI.
@param string|RawContentInterface $data
@param string|null $name
@param string|null $mimeType
@return StorableFileInterface
@throws CouldNotReadDataException | [
"Makes",
"a",
"normalized",
"storable",
"file",
"instance",
"from",
"a",
"data",
"URI",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/StorableFileFactory.php#L197-L238 |
39,866 | czim/file-handling | src/Storage/File/StorableFileFactory.php | StorableFileFactory.makeFromRawData | public function makeFromRawData($data, $name = null, $mimeType = null)
{
$file = new RawStorableFile;
if ($data instanceof RawContentInterface) {
$data = $data->content();
}
// Guess the mimetype directly from the content
if (null === $mimeType) {
$mimeType = $this->mimeTypeHelper->guessMimeTypeForContent($data);
}
if (empty($name)) {
$name = $this->makeRandomName(
$this->mimeTypeHelper->guessExtensionForMimeType($mimeType)
);
}
$file->setName($name);
$file->setData($data);
$file->setMimeType($mimeType);
return $this->getReturnPreparedFile($file);
} | php | public function makeFromRawData($data, $name = null, $mimeType = null)
{
$file = new RawStorableFile;
if ($data instanceof RawContentInterface) {
$data = $data->content();
}
// Guess the mimetype directly from the content
if (null === $mimeType) {
$mimeType = $this->mimeTypeHelper->guessMimeTypeForContent($data);
}
if (empty($name)) {
$name = $this->makeRandomName(
$this->mimeTypeHelper->guessExtensionForMimeType($mimeType)
);
}
$file->setName($name);
$file->setData($data);
$file->setMimeType($mimeType);
return $this->getReturnPreparedFile($file);
} | [
"public",
"function",
"makeFromRawData",
"(",
"$",
"data",
",",
"$",
"name",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"$",
"file",
"=",
"new",
"RawStorableFile",
";",
"if",
"(",
"$",
"data",
"instanceof",
"RawContentInterface",
")",
"{",... | Makes a normalized storable file instance from raw content data.
@param string|RawContentInterface $data
@param string|null $name
@param string|null $mimeType
@return StorableFileInterface | [
"Makes",
"a",
"normalized",
"storable",
"file",
"instance",
"from",
"raw",
"content",
"data",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/StorableFileFactory.php#L248-L272 |
39,867 | czim/file-handling | src/Storage/File/StorableFileFactory.php | StorableFileFactory.interpretFromRawContent | protected function interpretFromRawContent(RawContentInterface $data, $name, $mimeType)
{
switch ($this->interpreter->interpret($data)) {
case ContentTypes::URI:
return $this->makeFromUrl($data->content(), $name, $mimeType);
case ContentTypes::DATAURI:
return $this->makeFromDataUri($data, $name, $mimeType);
case ContentTypes::RAW:
default:
return $this->makeFromRawData($data, $name, $mimeType);
}
} | php | protected function interpretFromRawContent(RawContentInterface $data, $name, $mimeType)
{
switch ($this->interpreter->interpret($data)) {
case ContentTypes::URI:
return $this->makeFromUrl($data->content(), $name, $mimeType);
case ContentTypes::DATAURI:
return $this->makeFromDataUri($data, $name, $mimeType);
case ContentTypes::RAW:
default:
return $this->makeFromRawData($data, $name, $mimeType);
}
} | [
"protected",
"function",
"interpretFromRawContent",
"(",
"RawContentInterface",
"$",
"data",
",",
"$",
"name",
",",
"$",
"mimeType",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"interpreter",
"->",
"interpret",
"(",
"$",
"data",
")",
")",
"{",
"case",
"Con... | Interprets given raw content as a storable file.
@param RawContentInterface $data
@param string|null $name
@param string|null $mimeType
@return StorableFileInterface
@throws CouldNotReadDataException
@throws CouldNotRetrieveRemoteFileException | [
"Interprets",
"given",
"raw",
"content",
"as",
"a",
"storable",
"file",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Storage/File/StorableFileFactory.php#L284-L298 |
39,868 | czim/file-handling | src/Variant/VariantStrategyFactory.php | VariantStrategyFactory.make | public function make($strategy, array $options = [])
{
$instance = $this->instantiateClass(
$this->resolveStrategyClassName($strategy)
);
if ( ! ($instance instanceof VariantStrategyInterface)) {
throw new RuntimeException("Variant strategy created for '{$strategy}' is of incorrect type");
}
return $instance->setOptions($options);
} | php | public function make($strategy, array $options = [])
{
$instance = $this->instantiateClass(
$this->resolveStrategyClassName($strategy)
);
if ( ! ($instance instanceof VariantStrategyInterface)) {
throw new RuntimeException("Variant strategy created for '{$strategy}' is of incorrect type");
}
return $instance->setOptions($options);
} | [
"public",
"function",
"make",
"(",
"$",
"strategy",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"instantiateClass",
"(",
"$",
"this",
"->",
"resolveStrategyClassName",
"(",
"$",
"strategy",
")",
")",
... | Returns strategy instance.
@param string $strategy strategy class or alias
@param array $options options for the strategy
@return VariantStrategyInterface | [
"Returns",
"strategy",
"instance",
"."
] | eeca2954d30fee0122468ed4c74ed74fe6eed27f | https://github.com/czim/file-handling/blob/eeca2954d30fee0122468ed4c74ed74fe6eed27f/src/Variant/VariantStrategyFactory.php#L58-L69 |
39,869 | netgen/NetgenSiteAccessRoutesBundle | bundle/EventListener/RequestListener.php | RequestListener.onKernelRequest | public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
$requestAttributes = $event->getRequest()->attributes;
$currentSiteAccess = $requestAttributes->get('siteaccess');
$allowedSiteAccesses = $requestAttributes->get(self::ALLOWED_SITEACCESSES_KEY);
// We allow the route if no current siteaccess is set or
// no allowed siteaccesses (meaning all are allowed) are defined
if (!$currentSiteAccess instanceof SiteAccess || empty($allowedSiteAccesses)) {
return;
}
if (!is_array($allowedSiteAccesses)) {
$allowedSiteAccesses = array($allowedSiteAccesses);
}
if ($this->matcher->isAllowed($currentSiteAccess->name, $allowedSiteAccesses)) {
return;
}
throw new NotFoundHttpException('Route is not allowed in current siteaccess');
} | php | public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
$requestAttributes = $event->getRequest()->attributes;
$currentSiteAccess = $requestAttributes->get('siteaccess');
$allowedSiteAccesses = $requestAttributes->get(self::ALLOWED_SITEACCESSES_KEY);
// We allow the route if no current siteaccess is set or
// no allowed siteaccesses (meaning all are allowed) are defined
if (!$currentSiteAccess instanceof SiteAccess || empty($allowedSiteAccesses)) {
return;
}
if (!is_array($allowedSiteAccesses)) {
$allowedSiteAccesses = array($allowedSiteAccesses);
}
if ($this->matcher->isAllowed($currentSiteAccess->name, $allowedSiteAccesses)) {
return;
}
throw new NotFoundHttpException('Route is not allowed in current siteaccess');
} | [
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"getRequestType",
"(",
")",
"!==",
"HttpKernelInterface",
"::",
"MASTER_REQUEST",
")",
"{",
"return",
";",
"}",
"$",
"requestAttributes",
"... | Throws an exception if current route is not allowed in current siteaccess.
@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event | [
"Throws",
"an",
"exception",
"if",
"current",
"route",
"is",
"not",
"allowed",
"in",
"current",
"siteaccess",
"."
] | dbc6bec2d7ba06737cc09411c7677fcc1b703c4b | https://github.com/netgen/NetgenSiteAccessRoutesBundle/blob/dbc6bec2d7ba06737cc09411c7677fcc1b703c4b/bundle/EventListener/RequestListener.php#L50-L76 |
39,870 | zofe/burp | src/Burp.php | Burp.fixParams | private static function fixParams($method, $params)
{
if (! in_array(strtolower($method), array('get','post','patch','put','delete','any','head')))
throw new \BadMethodCallException("valid methods are 'get','post','patch','put','delete','any','head'");
//fix closures / controllers
if (is_array($params) && isset($params[2]) && is_array($params[2])) {
//controller@method
if (isset($params[2]['uses']) && is_string($params[2]['uses']) && strpos($params[2]['uses'], '@'))
{
$callback = explode('@', $params[2]['uses']);
$params[2] = array('as'=>$params[2]['as'], 'uses'=> $callback);
}
//closure fix
if (isset($params[2]['as']) && isset($params[2][0]) && ($params[2][0] instanceof \Closure))
{
$params[2] = array('as'=>$params[2]['as'], 'uses'=> $params[2][0]);
}
}
//no route name given, so route_name will be the first parameter
if (is_array($params) && isset($params[2]) && ($params[2] instanceof \Closure)) {
$params[2] = array('as'=>$params[0], 'uses'=>$params[2]);
}
if (count($params)<3 ||
!is_array($params[2]) ||
!array_key_exists('as', $params[2]) ||
!array_key_exists('uses', $params[2]) ||
!($params[2]['uses'] instanceof \Closure || is_array($params[2]['uses'])) )
throw new \InvalidArgumentException('third parameter should be an array containing a
valid callback : array(\'as\'=>\'routename\', function () { }) ');
return $params;
} | php | private static function fixParams($method, $params)
{
if (! in_array(strtolower($method), array('get','post','patch','put','delete','any','head')))
throw new \BadMethodCallException("valid methods are 'get','post','patch','put','delete','any','head'");
//fix closures / controllers
if (is_array($params) && isset($params[2]) && is_array($params[2])) {
//controller@method
if (isset($params[2]['uses']) && is_string($params[2]['uses']) && strpos($params[2]['uses'], '@'))
{
$callback = explode('@', $params[2]['uses']);
$params[2] = array('as'=>$params[2]['as'], 'uses'=> $callback);
}
//closure fix
if (isset($params[2]['as']) && isset($params[2][0]) && ($params[2][0] instanceof \Closure))
{
$params[2] = array('as'=>$params[2]['as'], 'uses'=> $params[2][0]);
}
}
//no route name given, so route_name will be the first parameter
if (is_array($params) && isset($params[2]) && ($params[2] instanceof \Closure)) {
$params[2] = array('as'=>$params[0], 'uses'=>$params[2]);
}
if (count($params)<3 ||
!is_array($params[2]) ||
!array_key_exists('as', $params[2]) ||
!array_key_exists('uses', $params[2]) ||
!($params[2]['uses'] instanceof \Closure || is_array($params[2]['uses'])) )
throw new \InvalidArgumentException('third parameter should be an array containing a
valid callback : array(\'as\'=>\'routename\', function () { }) ');
return $params;
} | [
"private",
"static",
"function",
"fixParams",
"(",
"$",
"method",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"method",
")",
",",
"array",
"(",
"'get'",
",",
"'post'",
",",
"'patch'",
",",
"'put'",
",",
"'de... | check if route method call is correct, and try to fix if not
@param $method
@param $params | [
"check",
"if",
"route",
"method",
"call",
"is",
"correct",
"and",
"try",
"to",
"fix",
"if",
"not"
] | 1b2983041d733df1c0633abe5a7c30e3baca1468 | https://github.com/zofe/burp/blob/1b2983041d733df1c0633abe5a7c30e3baca1468/src/Burp.php#L174-L213 |
39,871 | zofe/burp | src/Burp.php | Burp.remove | public function remove()
{
$routes = (is_array(func_get_arg(0))) ? func_get_arg(0) : func_get_args();
end(self::$routes);
self::$remove[key(self::$routes)] = $routes;
return new static();
} | php | public function remove()
{
$routes = (is_array(func_get_arg(0))) ? func_get_arg(0) : func_get_args();
end(self::$routes);
self::$remove[key(self::$routes)] = $routes;
return new static();
} | [
"public",
"function",
"remove",
"(",
")",
"{",
"$",
"routes",
"=",
"(",
"is_array",
"(",
"func_get_arg",
"(",
"0",
")",
")",
")",
"?",
"func_get_arg",
"(",
"0",
")",
":",
"func_get_args",
"(",
")",
";",
"end",
"(",
"self",
"::",
"$",
"routes",
")",... | queque to remove from url one or more named route
@return static | [
"queque",
"to",
"remove",
"from",
"url",
"one",
"or",
"more",
"named",
"route"
] | 1b2983041d733df1c0633abe5a7c30e3baca1468 | https://github.com/zofe/burp/blob/1b2983041d733df1c0633abe5a7c30e3baca1468/src/Burp.php#L220-L227 |
39,872 | zofe/burp | src/Burp.php | Burp.linkUrl | public static function linkUrl($url, $title = null, $attributes = array())
{
$title = ($title) ? $title : $url;
$compiled = '';
if (count($attributes)) {
$compiled = '';
foreach ($attributes as $key => $val) {
$compiled .= ' ' . $key . '="' . htmlspecialchars((string) $val, ENT_QUOTES, "UTF-8", true) . '"';
}
}
return '<a href="'.$url.'"'.$compiled.'>'.$title.'</a>';
} | php | public static function linkUrl($url, $title = null, $attributes = array())
{
$title = ($title) ? $title : $url;
$compiled = '';
if (count($attributes)) {
$compiled = '';
foreach ($attributes as $key => $val) {
$compiled .= ' ' . $key . '="' . htmlspecialchars((string) $val, ENT_QUOTES, "UTF-8", true) . '"';
}
}
return '<a href="'.$url.'"'.$compiled.'>'.$title.'</a>';
} | [
"public",
"static",
"function",
"linkUrl",
"(",
"$",
"url",
",",
"$",
"title",
"=",
"null",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"title",
"=",
"(",
"$",
"title",
")",
"?",
"$",
"title",
":",
"$",
"url",
";",
"$",
"comp... | return a plain html link
@param $url
@param null $title
@param array $attributes
@return string | [
"return",
"a",
"plain",
"html",
"link"
] | 1b2983041d733df1c0633abe5a7c30e3baca1468 | https://github.com/zofe/burp/blob/1b2983041d733df1c0633abe5a7c30e3baca1468/src/Burp.php#L337-L348 |
39,873 | zofe/burp | src/Burp.php | Burp.replacePattern | protected static function replacePattern($pattern, $container, $url, $conditional, $remove_conditional)
{
if (array_key_exists($pattern, $container)) {
$replace = (count(self::$parameters[$pattern]) || $conditional) ? '('.$container[$pattern].')' : $container[$pattern];
if ($conditional) {
$replace = ($remove_conditional) ? '' : $replace.'?';
$url = preg_replace('#\{'.$pattern.'\?\}#', $replace, $url);
} else {
$url = preg_replace('#\{'.$pattern.'\}#', $replace, $url);
}
}
return $url;
} | php | protected static function replacePattern($pattern, $container, $url, $conditional, $remove_conditional)
{
if (array_key_exists($pattern, $container)) {
$replace = (count(self::$parameters[$pattern]) || $conditional) ? '('.$container[$pattern].')' : $container[$pattern];
if ($conditional) {
$replace = ($remove_conditional) ? '' : $replace.'?';
$url = preg_replace('#\{'.$pattern.'\?\}#', $replace, $url);
} else {
$url = preg_replace('#\{'.$pattern.'\}#', $replace, $url);
}
}
return $url;
} | [
"protected",
"static",
"function",
"replacePattern",
"(",
"$",
"pattern",
",",
"$",
"container",
",",
"$",
"url",
",",
"$",
"conditional",
",",
"$",
"remove_conditional",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"pattern",
",",
"$",
"container",
... | replace a pattern in an array of rules
@param $pattern
@param $container
@param $url
@param $conditional
@param $remove_conditional
@return string | [
"replace",
"a",
"pattern",
"in",
"an",
"array",
"of",
"rules"
] | 1b2983041d733df1c0633abe5a7c30e3baca1468 | https://github.com/zofe/burp/blob/1b2983041d733df1c0633abe5a7c30e3baca1468/src/Burp.php#L373-L385 |
39,874 | paragonie/pharaoh | src/Pharaoh/PharDiff.php | PharDiff.printGitDiff | public function printGitDiff(): int
{
// Lazy way; requires git. Will replace with custom implementaiton later.
$argA = \escapeshellarg($this->phars[0]->tmp);
$argB = \escapeshellarg($this->phars[1]->tmp);
/** @var string $diff */
$diff = `git diff --no-index $argA $argB`;
echo $diff;
if (empty($diff) && $this->verbose) {
echo 'No differences encountered.', PHP_EOL;
return 0;
}
return 1;
}
/**
* Prints a GNU diff of the two phars.
*
* @psalm-suppress ForbiddenCode
* @return int
*/
public function printGnuDiff(): int
{
// Lazy way. Will replace with custom implementaiton later.
$argA = \escapeshellarg($this->phars[0]->tmp);
$argB = \escapeshellarg($this->phars[1]->tmp);
/** @var string $diff */
$diff = `diff $argA $argB`;
echo $diff;
if (empty($diff) && $this->verbose) {
echo 'No differences encountered.', PHP_EOL;
return 0;
}
return 1;
} | php | public function printGitDiff(): int
{
// Lazy way; requires git. Will replace with custom implementaiton later.
$argA = \escapeshellarg($this->phars[0]->tmp);
$argB = \escapeshellarg($this->phars[1]->tmp);
/** @var string $diff */
$diff = `git diff --no-index $argA $argB`;
echo $diff;
if (empty($diff) && $this->verbose) {
echo 'No differences encountered.', PHP_EOL;
return 0;
}
return 1;
}
/**
* Prints a GNU diff of the two phars.
*
* @psalm-suppress ForbiddenCode
* @return int
*/
public function printGnuDiff(): int
{
// Lazy way. Will replace with custom implementaiton later.
$argA = \escapeshellarg($this->phars[0]->tmp);
$argB = \escapeshellarg($this->phars[1]->tmp);
/** @var string $diff */
$diff = `diff $argA $argB`;
echo $diff;
if (empty($diff) && $this->verbose) {
echo 'No differences encountered.', PHP_EOL;
return 0;
}
return 1;
} | [
"public",
"function",
"printGitDiff",
"(",
")",
":",
"int",
"{",
"// Lazy way; requires git. Will replace with custom implementaiton later.",
"$",
"argA",
"=",
"\\",
"escapeshellarg",
"(",
"$",
"this",
"->",
"phars",
"[",
"0",
"]",
"->",
"tmp",
")",
";",
"$",
"a... | Prints a git-formatted diff of the two phars.
@psalm-suppress ForbiddenCode
@return int | [
"Prints",
"a",
"git",
"-",
"formatted",
"diff",
"of",
"the",
"two",
"phars",
"."
] | 060418e946de2f39a3618ad70d9b6d0a61437b83 | https://github.com/paragonie/pharaoh/blob/060418e946de2f39a3618ad70d9b6d0a61437b83/src/Pharaoh/PharDiff.php#L48-L83 |
39,875 | paragonie/pharaoh | src/Pharaoh/PharDiff.php | PharDiff.hashChildren | public function hashChildren(string $algo,string $dirA, string $dirB)
{
/**
* @var string $a
* @var string $b
*/
$a = $b = '';
$filesA = $this->listAllFiles($dirA);
$filesB = $this->listAllFiles($dirB);
$numFiles = \max(\count($filesA), \count($filesB));
// Array of two empty arrays
$hashes = [[], []];
for ($i = 0; $i < $numFiles; ++$i) {
$thisFileA = (string) $filesA[$i];
$thisFileB = (string) $filesB[$i];
if (isset($filesA[$i])) {
$a = \preg_replace('#^'.\preg_quote($dirA, '#').'#', '', $thisFileA);
if (isset($filesB[$i])) {
$b = \preg_replace('#^'.\preg_quote($dirB, '#').'#', '', $thisFileB);
} else {
$b = $a;
}
} elseif (isset($filesB[$i])) {
$b = \preg_replace('#^'.\preg_quote($dirB, '#').'#', '', $thisFileB);
$a = $b;
}
if (isset($filesA[$i])) {
// A exists
if (\strtolower($algo) === 'blake2b') {
$hashes[0][$a] = Hex::encode(\ParagonIE_Sodium_File::generichash($thisFileA));
} else {
$hashes[0][$a] = \hash_file($algo, $thisFileA);
}
} elseif (isset($filesB[$i])) {
// A doesn't exist, B does
$hashes[0][$a] = '';
}
if (isset($filesB[$i])) {
// B exists
if (\strtolower($algo) === 'blake2b') {
$hashes[1][$b] = Hex::encode(\ParagonIE_Sodium_File::generichash($thisFileB));
} else {
$hashes[1][$b] = \hash_file($algo, $thisFileB);
}
} elseif (isset($filesA[$i])) {
// B doesn't exist, A does
$hashes[1][$b] = '';
}
}
return $hashes;
} | php | public function hashChildren(string $algo,string $dirA, string $dirB)
{
/**
* @var string $a
* @var string $b
*/
$a = $b = '';
$filesA = $this->listAllFiles($dirA);
$filesB = $this->listAllFiles($dirB);
$numFiles = \max(\count($filesA), \count($filesB));
// Array of two empty arrays
$hashes = [[], []];
for ($i = 0; $i < $numFiles; ++$i) {
$thisFileA = (string) $filesA[$i];
$thisFileB = (string) $filesB[$i];
if (isset($filesA[$i])) {
$a = \preg_replace('#^'.\preg_quote($dirA, '#').'#', '', $thisFileA);
if (isset($filesB[$i])) {
$b = \preg_replace('#^'.\preg_quote($dirB, '#').'#', '', $thisFileB);
} else {
$b = $a;
}
} elseif (isset($filesB[$i])) {
$b = \preg_replace('#^'.\preg_quote($dirB, '#').'#', '', $thisFileB);
$a = $b;
}
if (isset($filesA[$i])) {
// A exists
if (\strtolower($algo) === 'blake2b') {
$hashes[0][$a] = Hex::encode(\ParagonIE_Sodium_File::generichash($thisFileA));
} else {
$hashes[0][$a] = \hash_file($algo, $thisFileA);
}
} elseif (isset($filesB[$i])) {
// A doesn't exist, B does
$hashes[0][$a] = '';
}
if (isset($filesB[$i])) {
// B exists
if (\strtolower($algo) === 'blake2b') {
$hashes[1][$b] = Hex::encode(\ParagonIE_Sodium_File::generichash($thisFileB));
} else {
$hashes[1][$b] = \hash_file($algo, $thisFileB);
}
} elseif (isset($filesA[$i])) {
// B doesn't exist, A does
$hashes[1][$b] = '';
}
}
return $hashes;
} | [
"public",
"function",
"hashChildren",
"(",
"string",
"$",
"algo",
",",
"string",
"$",
"dirA",
",",
"string",
"$",
"dirB",
")",
"{",
"/**\n * @var string $a\n * @var string $b\n */",
"$",
"a",
"=",
"$",
"b",
"=",
"''",
";",
"$",
"filesA",
... | Get hashes of all of the files in the two arrays.
@param string $algo
@param string $dirA
@param string $dirB
@return array<int, array<mixed, string>>
@throws \SodiumException | [
"Get",
"hashes",
"of",
"all",
"of",
"the",
"files",
"in",
"the",
"two",
"arrays",
"."
] | 060418e946de2f39a3618ad70d9b6d0a61437b83 | https://github.com/paragonie/pharaoh/blob/060418e946de2f39a3618ad70d9b6d0a61437b83/src/Pharaoh/PharDiff.php#L94-L147 |
39,876 | paragonie/pharaoh | src/Pharaoh/PharDiff.php | PharDiff.listChecksums | public function listChecksums(string $algo = 'sha384'): int
{
list($pharA, $pharB) = $this->hashChildren(
$algo,
$this->phars[0]->tmp,
$this->phars[1]->tmp
);
$diffs = 0;
/** @var string $i */
foreach (\array_keys($pharA) as $i) {
if (isset($pharA[$i]) && isset($pharB[$i])) {
// We are NOT concerned about local timing attacks.
if ($pharA[$i] !== $pharB[$i]) {
++$diffs;
echo "\t", (string) $i,
"\n\t\t", $this->c['red'], $pharA[$i], $this->c[''],
"\t", $this->c['green'], $pharB[$i], $this->c[''],
"\n";
} elseif (!empty($pharA[$i]) && empty($pharB[$i])) {
++$diffs;
echo "\t", (string) $i,
"\n\t\t", $this->c['red'], $pharA[$i], $this->c[''],
"\t", \str_repeat('-', \strlen($pharA[$i])),
"\n";
} elseif (!empty($pharB[$i]) && empty($pharA[$i])) {
++$diffs;
echo "\t", (string) $i,
"\n\t\t", \str_repeat('-', \strlen($pharB[$i])),
"\t", $this->c['green'], $pharB[$i], $this->c[''],
"\n";
}
}
}
if ($diffs === 0) {
if ($this->verbose) {
echo 'No differences encountered.', PHP_EOL;
}
return 0;
}
return 1;
} | php | public function listChecksums(string $algo = 'sha384'): int
{
list($pharA, $pharB) = $this->hashChildren(
$algo,
$this->phars[0]->tmp,
$this->phars[1]->tmp
);
$diffs = 0;
/** @var string $i */
foreach (\array_keys($pharA) as $i) {
if (isset($pharA[$i]) && isset($pharB[$i])) {
// We are NOT concerned about local timing attacks.
if ($pharA[$i] !== $pharB[$i]) {
++$diffs;
echo "\t", (string) $i,
"\n\t\t", $this->c['red'], $pharA[$i], $this->c[''],
"\t", $this->c['green'], $pharB[$i], $this->c[''],
"\n";
} elseif (!empty($pharA[$i]) && empty($pharB[$i])) {
++$diffs;
echo "\t", (string) $i,
"\n\t\t", $this->c['red'], $pharA[$i], $this->c[''],
"\t", \str_repeat('-', \strlen($pharA[$i])),
"\n";
} elseif (!empty($pharB[$i]) && empty($pharA[$i])) {
++$diffs;
echo "\t", (string) $i,
"\n\t\t", \str_repeat('-', \strlen($pharB[$i])),
"\t", $this->c['green'], $pharB[$i], $this->c[''],
"\n";
}
}
}
if ($diffs === 0) {
if ($this->verbose) {
echo 'No differences encountered.', PHP_EOL;
}
return 0;
}
return 1;
} | [
"public",
"function",
"listChecksums",
"(",
"string",
"$",
"algo",
"=",
"'sha384'",
")",
":",
"int",
"{",
"list",
"(",
"$",
"pharA",
",",
"$",
"pharB",
")",
"=",
"$",
"this",
"->",
"hashChildren",
"(",
"$",
"algo",
",",
"$",
"this",
"->",
"phars",
... | Prints out all of the differences of checksums of the files contained
in both PHP archives.
@param string $algo
@return int
@throws \SodiumException | [
"Prints",
"out",
"all",
"of",
"the",
"differences",
"of",
"checksums",
"of",
"the",
"files",
"contained",
"in",
"both",
"PHP",
"archives",
"."
] | 060418e946de2f39a3618ad70d9b6d0a61437b83 | https://github.com/paragonie/pharaoh/blob/060418e946de2f39a3618ad70d9b6d0a61437b83/src/Pharaoh/PharDiff.php#L205-L246 |
39,877 | younishd/endobox | src/endobox/RendererDecorator.php | RendererDecorator.render | public function render(Renderable $input, array &$data = null, array $shared = null) : string
{
return $this->renderer->render($input, $data, $shared);
} | php | public function render(Renderable $input, array &$data = null, array $shared = null) : string
{
return $this->renderer->render($input, $data, $shared);
} | [
"public",
"function",
"render",
"(",
"Renderable",
"$",
"input",
",",
"array",
"&",
"$",
"data",
"=",
"null",
",",
"array",
"$",
"shared",
"=",
"null",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"renderer",
"->",
"render",
"(",
"$",
"input... | Delegate render functionality to renderer. | [
"Delegate",
"render",
"functionality",
"to",
"renderer",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/RendererDecorator.php#L30-L33 |
39,878 | younishd/endobox | src/endobox/Box.php | Box.render | public function render() : string
{
// assign data if any
if (\func_num_args() > 0) {
// php 7.2.0 is crazy
$args = \func_get_args();
$this->assign($args[0]);
}
$result = '';
$shared = [];
foreach ($this as $box) {
// if box has no shared data
if ($box->child === $box) {
// render, concat, and continue
$result .= $box->renderer->render($box->interior, $box->data);
continue;
}
// cache union sets of shared data arrays using root as key
$root = $box->find();
$key = \spl_object_hash($root);
if (!isset($shared[$key])) {
$shared[$key] = [];
$shared[$key][] = &$root->data;
for ($i = $root->child; $i !== $root; $i = $i->child) {
$shared[$key][] = &$i->data;
}
}
// render with shared data and concat results
$result .= $box->renderer->render($box->interior, $box->data, $shared[$key]);
}
return $result;
} | php | public function render() : string
{
// assign data if any
if (\func_num_args() > 0) {
// php 7.2.0 is crazy
$args = \func_get_args();
$this->assign($args[0]);
}
$result = '';
$shared = [];
foreach ($this as $box) {
// if box has no shared data
if ($box->child === $box) {
// render, concat, and continue
$result .= $box->renderer->render($box->interior, $box->data);
continue;
}
// cache union sets of shared data arrays using root as key
$root = $box->find();
$key = \spl_object_hash($root);
if (!isset($shared[$key])) {
$shared[$key] = [];
$shared[$key][] = &$root->data;
for ($i = $root->child; $i !== $root; $i = $i->child) {
$shared[$key][] = &$i->data;
}
}
// render with shared data and concat results
$result .= $box->renderer->render($box->interior, $box->data, $shared[$key]);
}
return $result;
} | [
"public",
"function",
"render",
"(",
")",
":",
"string",
"{",
"// assign data if any",
"if",
"(",
"\\",
"func_num_args",
"(",
")",
">",
"0",
")",
"{",
"// php 7.2.0 is crazy",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"$",
"this",
"->",
"as... | Render the box and everything attached to it then return the result. | [
"Render",
"the",
"box",
"and",
"everything",
"attached",
"to",
"it",
"then",
"return",
"the",
"result",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L136-L172 |
39,879 | younishd/endobox | src/endobox/Box.php | Box.append | public function append(Box $b) : Box
{
if ($this->next === null && $b->prev === null) {
$this->next = $b;
$b->prev = $this;
} else {
$this->tail()->append($b->head());
}
return $this;
} | php | public function append(Box $b) : Box
{
if ($this->next === null && $b->prev === null) {
$this->next = $b;
$b->prev = $this;
} else {
$this->tail()->append($b->head());
}
return $this;
} | [
"public",
"function",
"append",
"(",
"Box",
"$",
"b",
")",
":",
"Box",
"{",
"if",
"(",
"$",
"this",
"->",
"next",
"===",
"null",
"&&",
"$",
"b",
"->",
"prev",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"next",
"=",
"$",
"b",
";",
"$",
"b",
... | Append a Box to the end of the linked list and return this instance. | [
"Append",
"a",
"Box",
"to",
"the",
"end",
"of",
"the",
"linked",
"list",
"and",
"return",
"this",
"instance",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L182-L191 |
39,880 | younishd/endobox | src/endobox/Box.php | Box.entangle | public function entangle(Box $b) : Box
{
$root1 = $this->find();
$root2 = $b->find();
// if already in same set then nothing to do
if ($root1 === $root2) {
return $this;
}
// union by rank
if ($root1->rank > $root2->rank) {
$root2->parent = $root1;
} elseif ($root2->rank > $root1->rank) {
$root1->parent = $root2;
} else {
$root2->parent = $root1;
++$root1->rank;
}
// merge circular linked lists
$tmp = $this->child;
$this->child = $b->child;
$b->child = $tmp;
return $this;
} | php | public function entangle(Box $b) : Box
{
$root1 = $this->find();
$root2 = $b->find();
// if already in same set then nothing to do
if ($root1 === $root2) {
return $this;
}
// union by rank
if ($root1->rank > $root2->rank) {
$root2->parent = $root1;
} elseif ($root2->rank > $root1->rank) {
$root1->parent = $root2;
} else {
$root2->parent = $root1;
++$root1->rank;
}
// merge circular linked lists
$tmp = $this->child;
$this->child = $b->child;
$b->child = $tmp;
return $this;
} | [
"public",
"function",
"entangle",
"(",
"Box",
"$",
"b",
")",
":",
"Box",
"{",
"$",
"root1",
"=",
"$",
"this",
"->",
"find",
"(",
")",
";",
"$",
"root2",
"=",
"$",
"b",
"->",
"find",
"(",
")",
";",
"// if already in same set then nothing to do",
"if",
... | Union by rank. | [
"Union",
"by",
"rank",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L205-L231 |
39,881 | younishd/endobox | src/endobox/Box.php | Box.assign | public function assign(array $data) : Box
{
// Allow passing closures as data.
// The trick is to wrap the closure in an anonymous class instance that takes the closure and calls it
// when it is invoked as a string or as a function.
// We only support real closures (i.e., instance of Closure), not just any callable,
// because there is no way to know if "time" is supposed to be data or a function name.
foreach ($data as $k => &$v) {
if ($v instanceof \Closure) {
$data[$k] = new class($v) {
private $closure;
public function __construct($c) { $this->closure = $c; }
public function __toString() { return \call_user_func($this->closure); }
public function __invoke(...$args) { return \call_user_func_array($this->closure, $args); }
};
}
}
$this->data = \array_merge($this->data, $data);
return $this;
} | php | public function assign(array $data) : Box
{
// Allow passing closures as data.
// The trick is to wrap the closure in an anonymous class instance that takes the closure and calls it
// when it is invoked as a string or as a function.
// We only support real closures (i.e., instance of Closure), not just any callable,
// because there is no way to know if "time" is supposed to be data or a function name.
foreach ($data as $k => &$v) {
if ($v instanceof \Closure) {
$data[$k] = new class($v) {
private $closure;
public function __construct($c) { $this->closure = $c; }
public function __toString() { return \call_user_func($this->closure); }
public function __invoke(...$args) { return \call_user_func_array($this->closure, $args); }
};
}
}
$this->data = \array_merge($this->data, $data);
return $this;
} | [
"public",
"function",
"assign",
"(",
"array",
"$",
"data",
")",
":",
"Box",
"{",
"// Allow passing closures as data.",
"// The trick is to wrap the closure in an anonymous class instance that takes the closure and calls it",
"// when it is invoked as a string or as a function.",
"// We o... | Assign some data to this Box. | [
"Assign",
"some",
"data",
"to",
"this",
"Box",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L236-L257 |
39,882 | younishd/endobox | src/endobox/Box.php | Box.head | public function head() : Box
{
// keep track of visited boxes for cycle detection
$touched = [];
for ($b = $this; $b->prev !== null; $b = $b->visit($touched)->prev);
return $b;
} | php | public function head() : Box
{
// keep track of visited boxes for cycle detection
$touched = [];
for ($b = $this; $b->prev !== null; $b = $b->visit($touched)->prev);
return $b;
} | [
"public",
"function",
"head",
"(",
")",
":",
"Box",
"{",
"// keep track of visited boxes for cycle detection",
"$",
"touched",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"b",
"=",
"$",
"this",
";",
"$",
"b",
"->",
"prev",
"!==",
"null",
";",
"$",
"b",
"=",
... | Return the head of the list. | [
"Return",
"the",
"head",
"of",
"the",
"list",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L278-L284 |
39,883 | younishd/endobox | src/endobox/Box.php | Box.tail | public function tail() : Box
{
// keep track of visited boxes for cycle detection
$touched = [];
for ($b = $this; $b->next !== null; $b = $b->visit($touched)->next);
return $b;
} | php | public function tail() : Box
{
// keep track of visited boxes for cycle detection
$touched = [];
for ($b = $this; $b->next !== null; $b = $b->visit($touched)->next);
return $b;
} | [
"public",
"function",
"tail",
"(",
")",
":",
"Box",
"{",
"// keep track of visited boxes for cycle detection",
"$",
"touched",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"b",
"=",
"$",
"this",
";",
"$",
"b",
"->",
"next",
"!==",
"null",
";",
"$",
"b",
"=",
... | Return the tail of the list. | [
"Return",
"the",
"tail",
"of",
"the",
"list",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L289-L295 |
39,884 | younishd/endobox | src/endobox/Box.php | Box.find | private function find() : Box
{
// path compression
if ($this->parent !== $this) {
$this->parent = $this->parent->find();
}
return $this->parent;
} | php | private function find() : Box
{
// path compression
if ($this->parent !== $this) {
$this->parent = $this->parent->find();
}
return $this->parent;
} | [
"private",
"function",
"find",
"(",
")",
":",
"Box",
"{",
"// path compression",
"if",
"(",
"$",
"this",
"->",
"parent",
"!==",
"$",
"this",
")",
"{",
"$",
"this",
"->",
"parent",
"=",
"$",
"this",
"->",
"parent",
"->",
"find",
"(",
")",
";",
"}",
... | Find with path compression. | [
"Find",
"with",
"path",
"compression",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L308-L315 |
39,885 | younishd/endobox | src/endobox/Box.php | Box.visit | private function visit(&$touched)
{
$key = \spl_object_hash($this);
if (isset($touched[$key])) {
throw new \RuntimeException("Cycle (endless loop) detected in box graph.");
}
$touched[$key] = true;
// just for convenience
return $this;
} | php | private function visit(&$touched)
{
$key = \spl_object_hash($this);
if (isset($touched[$key])) {
throw new \RuntimeException("Cycle (endless loop) detected in box graph.");
}
$touched[$key] = true;
// just for convenience
return $this;
} | [
"private",
"function",
"visit",
"(",
"&",
"$",
"touched",
")",
"{",
"$",
"key",
"=",
"\\",
"spl_object_hash",
"(",
"$",
"this",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"touched",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Runtime... | Mark this box as visited or throw a RuntimeException if we have detected a cycle in the graph. | [
"Mark",
"this",
"box",
"as",
"visited",
"or",
"throw",
"a",
"RuntimeException",
"if",
"we",
"have",
"detected",
"a",
"cycle",
"in",
"the",
"graph",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/Box.php#L320-L329 |
39,886 | younishd/endobox | src/endobox/BoxFactory.php | BoxFactory.create | public function create(string $template) : Box
{
foreach ($this->paths as &$path) {
// full path to template file without extension
$file = \rtrim($path, '/') . '/' . \trim($template, '/');
if (\file_exists($t = $file . '.php')) {
return (new Box(
new Template($t),
new EvalRendererDecorator(
new NullRenderer())))
->assign([
'markdown' => function($md) {
return new Box(
new Atom($md),
new MarkdownRendererDecorator(
new NullRenderer(), $this->parsedown));
}
]);
}
if (\file_exists($t = $file . '.md.php')) {
return (new Box(
new Template($t),
new MarkdownRendererDecorator(
new EvalRendererDecorator(
new NullRenderer()), $this->parsedown)))
->assign([
'markdown' => function($md) {
return new Box(
new Atom($md),
new MarkdownRendererDecorator(
new NullRenderer(), $this->parsedown));
}
]);
}
if (\file_exists($t = $file . '.md')) {
return new Box(
new Template($t),
new MarkdownRendererDecorator(
new NullRenderer(), $this->parsedown));
}
if (\file_exists($t = $file . '.html')) {
return new Box(
new Template($t),
new NullRenderer());
}
}
throw new \RuntimeException(\sprintf('Template "%s" not found.', $template));
} | php | public function create(string $template) : Box
{
foreach ($this->paths as &$path) {
// full path to template file without extension
$file = \rtrim($path, '/') . '/' . \trim($template, '/');
if (\file_exists($t = $file . '.php')) {
return (new Box(
new Template($t),
new EvalRendererDecorator(
new NullRenderer())))
->assign([
'markdown' => function($md) {
return new Box(
new Atom($md),
new MarkdownRendererDecorator(
new NullRenderer(), $this->parsedown));
}
]);
}
if (\file_exists($t = $file . '.md.php')) {
return (new Box(
new Template($t),
new MarkdownRendererDecorator(
new EvalRendererDecorator(
new NullRenderer()), $this->parsedown)))
->assign([
'markdown' => function($md) {
return new Box(
new Atom($md),
new MarkdownRendererDecorator(
new NullRenderer(), $this->parsedown));
}
]);
}
if (\file_exists($t = $file . '.md')) {
return new Box(
new Template($t),
new MarkdownRendererDecorator(
new NullRenderer(), $this->parsedown));
}
if (\file_exists($t = $file . '.html')) {
return new Box(
new Template($t),
new NullRenderer());
}
}
throw new \RuntimeException(\sprintf('Template "%s" not found.', $template));
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"template",
")",
":",
"Box",
"{",
"foreach",
"(",
"$",
"this",
"->",
"paths",
"as",
"&",
"$",
"path",
")",
"{",
"// full path to template file without extension",
"$",
"file",
"=",
"\\",
"rtrim",
"(",
"$"... | Create a Box based on the given template and return it. | [
"Create",
"a",
"Box",
"based",
"on",
"the",
"given",
"template",
"and",
"return",
"it",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/BoxFactory.php#L44-L96 |
39,887 | younishd/endobox | src/endobox/BoxFactory.php | BoxFactory.addFolder | public function addFolder(string $path)
{
if (!\is_dir($path)) {
throw new \RuntimeException(\sprintf('The path "%s" does not exist or is not a directory.', $path));
}
$this->paths[] = $path;
} | php | public function addFolder(string $path)
{
if (!\is_dir($path)) {
throw new \RuntimeException(\sprintf('The path "%s" does not exist or is not a directory.', $path));
}
$this->paths[] = $path;
} | [
"public",
"function",
"addFolder",
"(",
"string",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"\\",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\\",
"sprintf",
"(",
"'The path \"%s\" does not exist or is not a director... | Add another folder to the list of template paths. | [
"Add",
"another",
"folder",
"to",
"the",
"list",
"of",
"template",
"paths",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/BoxFactory.php#L101-L107 |
39,888 | gpslab/cqrs | src/Command/Queue/Pull/PredisUniquePullCommandQueue.php | PredisUniquePullCommandQueue.pull | public function pull()
{
$value = $this->client->lpop($this->queue_name);
if (!$value) {
return null;
}
try {
return $this->serializer->deserialize($value);
} catch (\Exception $e) {
// it's a critical error
// it is necessary to react quickly to it
$this->logger->critical('Failed denormalize a command in the Redis queue', [$value, $e->getMessage()]);
// try denormalize in later
$this->client->rpush($this->queue_name, [$value]);
return null;
}
} | php | public function pull()
{
$value = $this->client->lpop($this->queue_name);
if (!$value) {
return null;
}
try {
return $this->serializer->deserialize($value);
} catch (\Exception $e) {
// it's a critical error
// it is necessary to react quickly to it
$this->logger->critical('Failed denormalize a command in the Redis queue', [$value, $e->getMessage()]);
// try denormalize in later
$this->client->rpush($this->queue_name, [$value]);
return null;
}
} | [
"public",
"function",
"pull",
"(",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"client",
"->",
"lpop",
"(",
"$",
"this",
"->",
"queue_name",
")",
";",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"return",
... | Pop command from queue. Return NULL if queue is empty.
@return Command|null | [
"Pop",
"command",
"from",
"queue",
".",
"Return",
"NULL",
"if",
"queue",
"is",
"empty",
"."
] | e0544181aeb5d0d3334a51a1189eaaad5fa3c33b | https://github.com/gpslab/cqrs/blob/e0544181aeb5d0d3334a51a1189eaaad5fa3c33b/src/Command/Queue/Pull/PredisUniquePullCommandQueue.php#L76-L96 |
39,889 | younishd/endobox | src/endobox/MarkdownRendererDecorator.php | MarkdownRendererDecorator.render | public function render(Renderable $input, array &$data = null, array $shared = null) : string
{
return $this->parsedown->text(parent::render($input, $data, $shared));
} | php | public function render(Renderable $input, array &$data = null, array $shared = null) : string
{
return $this->parsedown->text(parent::render($input, $data, $shared));
} | [
"public",
"function",
"render",
"(",
"Renderable",
"$",
"input",
",",
"array",
"&",
"$",
"data",
"=",
"null",
",",
"array",
"$",
"shared",
"=",
"null",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"parsedown",
"->",
"text",
"(",
"parent",
":... | Render by passing the inherited result through Parsedown. | [
"Render",
"by",
"passing",
"the",
"inherited",
"result",
"through",
"Parsedown",
"."
] | a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69 | https://github.com/younishd/endobox/blob/a4b9e6aaf954c53c29d4c4e2c1d7a4f8528d0d69/src/endobox/MarkdownRendererDecorator.php#L31-L34 |
39,890 | Rican7/incoming | src/Incoming/Structure/FixedList.php | FixedList.fromArray | public static function fromArray(array $data): self
{
$fixed_list = new static();
$fixed_list->decorated = SplFixedArray::fromArray($data, false);
return $fixed_list;
} | php | public static function fromArray(array $data): self
{
$fixed_list = new static();
$fixed_list->decorated = SplFixedArray::fromArray($data, false);
return $fixed_list;
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"data",
")",
":",
"self",
"{",
"$",
"fixed_list",
"=",
"new",
"static",
"(",
")",
";",
"$",
"fixed_list",
"->",
"decorated",
"=",
"SplFixedArray",
"::",
"fromArray",
"(",
"$",
"data",
",",
... | Create from data in an array.
@param array $data The data to create from.
@return static The resulting data-structure. | [
"Create",
"from",
"data",
"in",
"an",
"array",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Structure/FixedList.php#L59-L66 |
39,891 | Rican7/incoming | src/Incoming/Structure/FixedList.php | FixedList.get | public function get(int $index, $default_val = null)
{
if ($this->offsetExists($index)) {
return $this->offsetGet($index);
}
return $default_val;
} | php | public function get(int $index, $default_val = null)
{
if ($this->offsetExists($index)) {
return $this->offsetGet($index);
}
return $default_val;
} | [
"public",
"function",
"get",
"(",
"int",
"$",
"index",
",",
"$",
"default_val",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"index",
")",
")",
"{",
"return",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"index",
")",... | Get a value in the list by index.
@param int $index The index to get the value for.
@param mixed $default_val The default value to return if the index does
not exist.
@return mixed The resulting value. | [
"Get",
"a",
"value",
"in",
"the",
"list",
"by",
"index",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Structure/FixedList.php#L100-L107 |
39,892 | Rican7/incoming | src/Incoming/Structure/Exception/InvalidStructuralTypeException.php | InvalidStructuralTypeException.withTypeInfo | public static function withTypeInfo($value, int $code = 0, Throwable $previous = null): self
{
$message = self::DEFAULT_MESSAGE;
$message .= sprintf(
self::MESSAGE_EXTENSION_TYPE_FORMAT,
is_object($value) ? get_class($value) : gettype($value)
);
return new static($message, $code, $previous);
} | php | public static function withTypeInfo($value, int $code = 0, Throwable $previous = null): self
{
$message = self::DEFAULT_MESSAGE;
$message .= sprintf(
self::MESSAGE_EXTENSION_TYPE_FORMAT,
is_object($value) ? get_class($value) : gettype($value)
);
return new static($message, $code, $previous);
} | [
"public",
"static",
"function",
"withTypeInfo",
"(",
"$",
"value",
",",
"int",
"$",
"code",
"=",
"0",
",",
"Throwable",
"$",
"previous",
"=",
"null",
")",
":",
"self",
"{",
"$",
"message",
"=",
"self",
"::",
"DEFAULT_MESSAGE",
";",
"$",
"message",
".="... | Create an exception instance with type information.
The type is automatically inspected based on the passed value.
@param mixed $value The value to inspect type information of.
@param int $code The exception code.
@param Throwable|null $previous A previous exception used for chaining.
@return static The newly created exception. | [
"Create",
"an",
"exception",
"instance",
"with",
"type",
"information",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Structure/Exception/InvalidStructuralTypeException.php#L70-L80 |
39,893 | Rican7/incoming | src/Incoming/Structure/Map.php | Map.fromTraversable | public static function fromTraversable(Traversable $data): self
{
$map = new static();
foreach ($data as $key => $val) {
if (!is_scalar($key)) {
throw new InvalidArgumentException('Map keys must be scalar');
}
$map->decorated->offsetSet($key, $val);
}
return $map;
} | php | public static function fromTraversable(Traversable $data): self
{
$map = new static();
foreach ($data as $key => $val) {
if (!is_scalar($key)) {
throw new InvalidArgumentException('Map keys must be scalar');
}
$map->decorated->offsetSet($key, $val);
}
return $map;
} | [
"public",
"static",
"function",
"fromTraversable",
"(",
"Traversable",
"$",
"data",
")",
":",
"self",
"{",
"$",
"map",
"=",
"new",
"static",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"!",
... | Create from data in a Traversable instance.
@param Traversable $data The data to create from.
@return static The resulting data-structure.
@throws InvalidArgumentException If the data contains non-scalar keys. | [
"Create",
"from",
"data",
"in",
"a",
"Traversable",
"instance",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Structure/Map.php#L60-L73 |
39,894 | Rican7/incoming | src/Incoming/Structure/Map.php | Map.get | public function get($key, $default_val = null)
{
if ($this->exists($key)) {
return $this->offsetGet($key);
}
return $default_val;
} | php | public function get($key, $default_val = null)
{
if ($this->exists($key)) {
return $this->offsetGet($key);
}
return $default_val;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default_val",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"key",
")",
";",
"}",
"ret... | Get a value in the map by key.
@param mixed $key The key to get the value for.
@param mixed $default_val The default value to return if the key does
not exist.
@return mixed The resulting value. | [
"Get",
"a",
"value",
"in",
"the",
"map",
"by",
"key",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Structure/Map.php#L107-L114 |
39,895 | Rican7/incoming | src/Incoming/Processor.php | Processor.hydrateModel | protected function hydrateModel($input_data, $model, Hydrator $hydrator = null, Map $context = null)
{
$hydrator = $hydrator ?: $this->getHydratorForModel($model);
$this->enforceProcessCompatibility(($hydrator instanceof ContextualHydrator), (null !== $context), $hydrator);
if ($hydrator instanceof ContextualHydrator) {
return $hydrator->hydrate($input_data, $model, $context);
}
return $hydrator->hydrate($input_data, $model);
} | php | protected function hydrateModel($input_data, $model, Hydrator $hydrator = null, Map $context = null)
{
$hydrator = $hydrator ?: $this->getHydratorForModel($model);
$this->enforceProcessCompatibility(($hydrator instanceof ContextualHydrator), (null !== $context), $hydrator);
if ($hydrator instanceof ContextualHydrator) {
return $hydrator->hydrate($input_data, $model, $context);
}
return $hydrator->hydrate($input_data, $model);
} | [
"protected",
"function",
"hydrateModel",
"(",
"$",
"input_data",
",",
"$",
"model",
",",
"Hydrator",
"$",
"hydrator",
"=",
"null",
",",
"Map",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"hydrator",
"=",
"$",
"hydrator",
"?",
":",
"$",
"this",
"->",
... | Hydrate a model from incoming data.
If a hydrator isn't provided, an attempt will be made to automatically
resolve and build an appropriate hydrator from the provided factory.
@param mixed $input_data The input data.
@param mixed $model The model to hydrate.
@param Hydrator|null $hydrator The hydrator to use.
@param Map|null $context An optional generic key-value map, for providing
contextual values during the process.
@return mixed The hydrated model. | [
"Hydrate",
"a",
"model",
"from",
"incoming",
"data",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Processor.php#L321-L332 |
39,896 | Rican7/incoming | src/Incoming/Processor.php | Processor.buildModel | protected function buildModel($input_data, string $type, Builder $builder = null, Map $context = null)
{
$builder = $builder ?: $this->getBuilderForType($type);
$this->enforceProcessCompatibility(($builder instanceof ContextualBuilder), (null !== $context), $builder);
if ($builder instanceof ContextualBuilder) {
return $builder->build($input_data, $context);
}
return $builder->build($input_data);
} | php | protected function buildModel($input_data, string $type, Builder $builder = null, Map $context = null)
{
$builder = $builder ?: $this->getBuilderForType($type);
$this->enforceProcessCompatibility(($builder instanceof ContextualBuilder), (null !== $context), $builder);
if ($builder instanceof ContextualBuilder) {
return $builder->build($input_data, $context);
}
return $builder->build($input_data);
} | [
"protected",
"function",
"buildModel",
"(",
"$",
"input_data",
",",
"string",
"$",
"type",
",",
"Builder",
"$",
"builder",
"=",
"null",
",",
"Map",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"builder",
"=",
"$",
"builder",
"?",
":",
"$",
"this",
"->... | Build a model from incoming data.
If a builder isn't provided, an attempt will be made to automatically
resolve and build an appropriate builder from the provided factory.
@param mixed $input_data The input data.
@param string $type The type to build.
@param Builder|null $builder The builder to use.
@param Map|null $context An optional generic key-value map, for providing
contextual values during the process.
@return mixed The built model. | [
"Build",
"a",
"model",
"from",
"incoming",
"data",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Processor.php#L347-L358 |
39,897 | Rican7/incoming | src/Incoming/Processor.php | Processor.getHydratorForModel | protected function getHydratorForModel($model): Hydrator
{
if (null === $this->hydrator_factory) {
throw UnresolvableHydratorException::forModel($model);
}
return $this->hydrator_factory->buildForModel($model);
} | php | protected function getHydratorForModel($model): Hydrator
{
if (null === $this->hydrator_factory) {
throw UnresolvableHydratorException::forModel($model);
}
return $this->hydrator_factory->buildForModel($model);
} | [
"protected",
"function",
"getHydratorForModel",
"(",
"$",
"model",
")",
":",
"Hydrator",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"hydrator_factory",
")",
"{",
"throw",
"UnresolvableHydratorException",
"::",
"forModel",
"(",
"$",
"model",
")",
";",
... | Get a Hydrator for a given model.
@param mixed $model The model to get a hydrator for.
@throws UnresolvableHydratorException If a hydrator can't be resolved for
the given model.
@return Hydrator The resulting hydrator. | [
"Get",
"a",
"Hydrator",
"for",
"a",
"given",
"model",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Processor.php#L368-L375 |
39,898 | Rican7/incoming | src/Incoming/Processor.php | Processor.getBuilderForType | protected function getBuilderForType(string $type): Builder
{
if (null === $this->builder_factory) {
throw UnresolvableBuilderException::forType($type);
}
return $this->builder_factory->buildForType($type);
} | php | protected function getBuilderForType(string $type): Builder
{
if (null === $this->builder_factory) {
throw UnresolvableBuilderException::forType($type);
}
return $this->builder_factory->buildForType($type);
} | [
"protected",
"function",
"getBuilderForType",
"(",
"string",
"$",
"type",
")",
":",
"Builder",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"builder_factory",
")",
"{",
"throw",
"UnresolvableBuilderException",
"::",
"forType",
"(",
"$",
"type",
")",
";"... | Get a Builder for a given model.
@param string $type The type to get a builder for.
@throws UnresolvableBuilderException If a builder can't be resolved for
the given model.
@return Builder The resulting builder. | [
"Get",
"a",
"Builder",
"for",
"a",
"given",
"model",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Processor.php#L385-L392 |
39,899 | Rican7/incoming | src/Incoming/Hydrator/Exception/UnresolvableBuilderException.php | UnresolvableBuilderException.forType | public static function forType(
string $type,
int $code = self::CODE_FOR_TYPE,
Throwable $previous = null
): self {
$message = self::DEFAULT_MESSAGE . sprintf(self::MESSAGE_EXTENSION_FOR_TYPE, $type);
return new static($message, $code, $previous);
} | php | public static function forType(
string $type,
int $code = self::CODE_FOR_TYPE,
Throwable $previous = null
): self {
$message = self::DEFAULT_MESSAGE . sprintf(self::MESSAGE_EXTENSION_FOR_TYPE, $type);
return new static($message, $code, $previous);
} | [
"public",
"static",
"function",
"forType",
"(",
"string",
"$",
"type",
",",
"int",
"$",
"code",
"=",
"self",
"::",
"CODE_FOR_TYPE",
",",
"Throwable",
"$",
"previous",
"=",
"null",
")",
":",
"self",
"{",
"$",
"message",
"=",
"self",
"::",
"DEFAULT_MESSAGE... | Create an exception instance for a problem resolving a builder for a
given type.
@param string $type The type to build.
@param int $code The exception code.
@param Throwable|null $previous A previous exception used for chaining.
@return static The newly created exception. | [
"Create",
"an",
"exception",
"instance",
"for",
"a",
"problem",
"resolving",
"a",
"builder",
"for",
"a",
"given",
"type",
"."
] | 23d5179f994980d56dd32ae056498dc91e72c1f7 | https://github.com/Rican7/incoming/blob/23d5179f994980d56dd32ae056498dc91e72c1f7/src/Incoming/Hydrator/Exception/UnresolvableBuilderException.php#L77-L85 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.