repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mcaskill/charcoal-support | src/Cms/SectionAwareTrait.php | SectionAwareTrait.setSection | public function setSection($obj)
{
if ($obj instanceof SectionInterface) {
$this->section = $obj;
} else {
$this->createSection();
$this->section->load($obj);
}
return $this;
} | php | public function setSection($obj)
{
if ($obj instanceof SectionInterface) {
$this->section = $obj;
} else {
$this->createSection();
$this->section->load($obj);
}
return $this;
} | [
"public",
"function",
"setSection",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"SectionInterface",
")",
"{",
"$",
"this",
"->",
"section",
"=",
"$",
"obj",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"createSection",
"(",
")",
";",... | Assign the current section object.
@see Charcoal\Object\RoutableInterface The section object is usually determined by the route.
@param SectionInterface|integer $obj A section object or ID.
@return self | [
"Assign",
"the",
"current",
"section",
"object",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/SectionAwareTrait.php#L95-L106 | train |
mcaskill/charcoal-support | src/Cms/SectionAwareTrait.php | SectionAwareTrait.templateOptions | public function templateOptions()
{
$section = $this->section();
$options = $section->templateOptions();
if (is_string($options)) {
return json_decode($options);
}
return [];
} | php | public function templateOptions()
{
$section = $this->section();
$options = $section->templateOptions();
if (is_string($options)) {
return json_decode($options);
}
return [];
} | [
"public",
"function",
"templateOptions",
"(",
")",
"{",
"$",
"section",
"=",
"$",
"this",
"->",
"section",
"(",
")",
";",
"$",
"options",
"=",
"$",
"section",
"->",
"templateOptions",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
"... | Retrieve the template options from the current section.
@return array | [
"Retrieve",
"the",
"template",
"options",
"from",
"the",
"current",
"section",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/SectionAwareTrait.php#L129-L139 | train |
phpgithook/hello-world | src/Hooks/PostCommit.php | PostCommit.postCommit | public function postCommit(
InputInterface $input,
OutputInterface $output,
ParameterBagInterface $configuration
): void {
// Yes we can send a notification to slack fx?
// Then we would just add some configuration with slack channel, username etc etc
// And then require the slack API via composer and do the code here
// But very simple, we can say Hello World! to the console
$output->write('Hello World!');
} | php | public function postCommit(
InputInterface $input,
OutputInterface $output,
ParameterBagInterface $configuration
): void {
// Yes we can send a notification to slack fx?
// Then we would just add some configuration with slack channel, username etc etc
// And then require the slack API via composer and do the code here
// But very simple, we can say Hello World! to the console
$output->write('Hello World!');
} | [
"public",
"function",
"postCommit",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"ParameterBagInterface",
"$",
"configuration",
")",
":",
"void",
"{",
"// Yes we can send a notification to slack fx?",
"// Then we would just add some configu... | Called after the actual commit is made. Because of this, it cannot disrupt the commit.
It is mainly used to allow notifications.
@param InputInterface $input
@param OutputInterface $output
@param ParameterBagInterface $configuration | [
"Called",
"after",
"the",
"actual",
"commit",
"is",
"made",
".",
"Because",
"of",
"this",
"it",
"cannot",
"disrupt",
"the",
"commit",
".",
"It",
"is",
"mainly",
"used",
"to",
"allow",
"notifications",
"."
] | c01e5d57b24f5b4823c4007127d8fdf401f2f7da | https://github.com/phpgithook/hello-world/blob/c01e5d57b24f5b4823c4007127d8fdf401f2f7da/src/Hooks/PostCommit.php#L20-L31 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheConfig.php | CacheConfig.addType | public function addType($type)
{
if (!in_array($type, $this->validTypes())) {
throw new InvalidArgumentException(
sprintf('Invalid cache type: "%s"', $type)
);
}
$this->types[$type] = true;
return $this;
} | php | public function addType($type)
{
if (!in_array($type, $this->validTypes())) {
throw new InvalidArgumentException(
sprintf('Invalid cache type: "%s"', $type)
);
}
$this->types[$type] = true;
return $this;
} | [
"public",
"function",
"addType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"validTypes",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid cache typ... | Add a cache type to use.
@param string $type The cache type.
@throws InvalidArgumentException If the type is not a string or unsupported.
@return CacheConfig Chainable | [
"Add",
"a",
"cache",
"type",
"to",
"use",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheConfig.php#L139-L149 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheConfig.php | CacheConfig.setDefaultTtl | public function setDefaultTtl($ttl)
{
if (!is_numeric($ttl)) {
throw new InvalidArgumentException(
'TTL must be an integer (seconds)'
);
}
$this->defaultTtl = intval($ttl);
return $this;
} | php | public function setDefaultTtl($ttl)
{
if (!is_numeric($ttl)) {
throw new InvalidArgumentException(
'TTL must be an integer (seconds)'
);
}
$this->defaultTtl = intval($ttl);
return $this;
} | [
"public",
"function",
"setDefaultTtl",
"(",
"$",
"ttl",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"ttl",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'TTL must be an integer (seconds)'",
")",
";",
"}",
"$",
"this",
"->",
"defaultT... | Set the default time-to-live for cached items.
@param mixed $ttl A number representing time in seconds.
@throws InvalidArgumentException If the TTL is not numeric.
@return CacheConfig Chainable | [
"Set",
"the",
"default",
"time",
"-",
"to",
"-",
"live",
"for",
"cached",
"items",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheConfig.php#L201-L211 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheConfig.php | CacheConfig.setPrefix | public function setPrefix($prefix)
{
if (!is_string($prefix)) {
throw new InvalidArgumentException(
'Prefix must be a string'
);
}
/** @see \Stash\Pool\::setNamespace */
if (!ctype_alnum($prefix)) {
throw new InvalidArgumentException(
'Prefix must be alphanumeric'
);
}
$this->prefix = $prefix;
return $this;
} | php | public function setPrefix($prefix)
{
if (!is_string($prefix)) {
throw new InvalidArgumentException(
'Prefix must be a string'
);
}
/** @see \Stash\Pool\::setNamespace */
if (!ctype_alnum($prefix)) {
throw new InvalidArgumentException(
'Prefix must be alphanumeric'
);
}
$this->prefix = $prefix;
return $this;
} | [
"public",
"function",
"setPrefix",
"(",
"$",
"prefix",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"prefix",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Prefix must be a string'",
")",
";",
"}",
"/** @see \\Stash\\Pool\\::setNamespace */... | Set the cache namespace.
@param string $prefix The cache prefix (or namespace).
@throws InvalidArgumentException If the prefix is not a string.
@return CacheConfig Chainable | [
"Set",
"the",
"cache",
"namespace",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheConfig.php#L230-L247 | train |
rodrigoiii/skeleton-core | src/classes/Utilities/Validator.php | Validator.validate | public static function validate($request, $rules, $messages=[])
{
$errors = [];
$files = $request->getUploadedFiles();
foreach ($rules as $field => $rule)
{
try
{
if ($rule instanceof v)
{
// check if the field is for file
if (isset($files[$field]))
{
if (is_array($files[$field])) // multiple file
{
$files = $files[$field];
foreach ($files as $file_row)
{
if ($file_row instanceof UploadedFile)
{
$rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($file_row->file));
}
}
}
else // single file
{
if ($files[$field] instanceof UploadedFile)
{
$rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($files[$field]->file));
}
}
}
else
{
$rule->setName(str_title(ucfirst($field)))->assert($request->getParam($field));
}
}
else
{
\Log::error("Error: Rule must be Respect\Validation\Validator object");
}
} catch (NestedValidationException $e) {
$translator = config('validation.translator');
$e->setParam('translator', function($message) use($translator) {
$language = $translator['lang'];
$messages = $translator['messages'];
return isset($messages[$message]) ? $messages[$message][$language] : $message;
});
$e->findMessages($messages);
$errors[$field] = $e->getMessages();
}
}
Session::set('errors', $errors);
return __CLASS__;
} | php | public static function validate($request, $rules, $messages=[])
{
$errors = [];
$files = $request->getUploadedFiles();
foreach ($rules as $field => $rule)
{
try
{
if ($rule instanceof v)
{
// check if the field is for file
if (isset($files[$field]))
{
if (is_array($files[$field])) // multiple file
{
$files = $files[$field];
foreach ($files as $file_row)
{
if ($file_row instanceof UploadedFile)
{
$rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($file_row->file));
}
}
}
else // single file
{
if ($files[$field] instanceof UploadedFile)
{
$rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($files[$field]->file));
}
}
}
else
{
$rule->setName(str_title(ucfirst($field)))->assert($request->getParam($field));
}
}
else
{
\Log::error("Error: Rule must be Respect\Validation\Validator object");
}
} catch (NestedValidationException $e) {
$translator = config('validation.translator');
$e->setParam('translator', function($message) use($translator) {
$language = $translator['lang'];
$messages = $translator['messages'];
return isset($messages[$message]) ? $messages[$message][$language] : $message;
});
$e->findMessages($messages);
$errors[$field] = $e->getMessages();
}
}
Session::set('errors', $errors);
return __CLASS__;
} | [
"public",
"static",
"function",
"validate",
"(",
"$",
"request",
",",
"$",
"rules",
",",
"$",
"messages",
"=",
"[",
"]",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"$",
"files",
"=",
"$",
"request",
"->",
"getUploadedFiles",
"(",
")",
";",
"forea... | Put all fails in session
@param Psr\Http\Message\RequestInterface $request
@param array $rules
@return SkeletonCore\Utilities\Validator | [
"Put",
"all",
"fails",
"in",
"session"
] | 5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0 | https://github.com/rodrigoiii/skeleton-core/blob/5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0/src/classes/Utilities/Validator.php#L18-L75 | train |
cmsgears/module-core | common/models/resources/File.php | File.getFileUrl | public function getFileUrl() {
if( $this->changed ) {
return Yii::$app->fileManager->uploadUrl . '/' . CoreProperties::DIR_TEMP . $this->directory . "/" . $this->name . "." . $this->extension;
}
else if( $this->id > 0 ) {
return Yii::$app->fileManager->uploadUrl . '/' . $this->url;
}
return "";
} | php | public function getFileUrl() {
if( $this->changed ) {
return Yii::$app->fileManager->uploadUrl . '/' . CoreProperties::DIR_TEMP . $this->directory . "/" . $this->name . "." . $this->extension;
}
else if( $this->id > 0 ) {
return Yii::$app->fileManager->uploadUrl . '/' . $this->url;
}
return "";
} | [
"public",
"function",
"getFileUrl",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"changed",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"fileManager",
"->",
"uploadUrl",
".",
"'/'",
".",
"CoreProperties",
"::",
"DIR_TEMP",
".",
"$",
"this",
"->"... | Generate and Return file URL using file attributes.
@return string | [
"Generate",
"and",
"Return",
"file",
"URL",
"using",
"file",
"attributes",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L259-L271 | train |
cmsgears/module-core | common/models/resources/File.php | File.getMediumUrl | public function getMediumUrl() {
if( $this->changed ) {
return Yii::$app->fileManager->uploadUrl . '/' . CoreProperties::DIR_TEMP . $this->directory . "/" . $this->name . "-medium." . $this->extension;
}
else if( $this->id > 0 ) {
return Yii::$app->fileManager->uploadUrl . '/' . $this->medium;
}
return "";
} | php | public function getMediumUrl() {
if( $this->changed ) {
return Yii::$app->fileManager->uploadUrl . '/' . CoreProperties::DIR_TEMP . $this->directory . "/" . $this->name . "-medium." . $this->extension;
}
else if( $this->id > 0 ) {
return Yii::$app->fileManager->uploadUrl . '/' . $this->medium;
}
return "";
} | [
"public",
"function",
"getMediumUrl",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"changed",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"fileManager",
"->",
"uploadUrl",
".",
"'/'",
".",
"CoreProperties",
"::",
"DIR_TEMP",
".",
"$",
"this",
"-... | Generate and Return medium file URL using file attributes.
@return string | [
"Generate",
"and",
"Return",
"medium",
"file",
"URL",
"using",
"file",
"attributes",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L278-L290 | train |
cmsgears/module-core | common/models/resources/File.php | File.getThumbUrl | public function getThumbUrl() {
if( $this->changed ) {
return Yii::$app->fileManager->uploadUrl . '/' . CoreProperties::DIR_TEMP . $this->directory . "/" . $this->name . "-thumb." . $this->extension;
}
else if( $this->id > 0 ) {
return Yii::$app->fileManager->uploadUrl . '/' . $this->thumb;
}
return "";
} | php | public function getThumbUrl() {
if( $this->changed ) {
return Yii::$app->fileManager->uploadUrl . '/' . CoreProperties::DIR_TEMP . $this->directory . "/" . $this->name . "-thumb." . $this->extension;
}
else if( $this->id > 0 ) {
return Yii::$app->fileManager->uploadUrl . '/' . $this->thumb;
}
return "";
} | [
"public",
"function",
"getThumbUrl",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"changed",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"fileManager",
"->",
"uploadUrl",
".",
"'/'",
".",
"CoreProperties",
"::",
"DIR_TEMP",
".",
"$",
"this",
"->... | Generate and Return thumb URL using file attributes.
@return string | [
"Generate",
"and",
"Return",
"thumb",
"URL",
"using",
"file",
"attributes",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L297-L309 | train |
cmsgears/module-core | common/models/resources/File.php | File.getFilePath | public function getFilePath() {
if( isset( $this->url ) ) {
return Yii::$app->fileManager->uploadDir . '/' . $this->url;
}
return false;
} | php | public function getFilePath() {
if( isset( $this->url ) ) {
return Yii::$app->fileManager->uploadDir . '/' . $this->url;
}
return false;
} | [
"public",
"function",
"getFilePath",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"url",
")",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"fileManager",
"->",
"uploadDir",
".",
"'/'",
".",
"$",
"this",
"->",
"url",
";",
"}",
... | Return physical storage location of the file.
@return string|boolean | [
"Return",
"physical",
"storage",
"location",
"of",
"the",
"file",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L316-L324 | train |
cmsgears/module-core | common/models/resources/File.php | File.getMediumPath | public function getMediumPath() {
if( isset( $this->medium ) ) {
return Yii::$app->fileManager->uploadDir . '/' . $this->medium;
}
return false;
} | php | public function getMediumPath() {
if( isset( $this->medium ) ) {
return Yii::$app->fileManager->uploadDir . '/' . $this->medium;
}
return false;
} | [
"public",
"function",
"getMediumPath",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"medium",
")",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"fileManager",
"->",
"uploadDir",
".",
"'/'",
".",
"$",
"this",
"->",
"medium",
";",
... | Return physical storage location of the medium file.
@return string|boolean | [
"Return",
"physical",
"storage",
"location",
"of",
"the",
"medium",
"file",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L331-L339 | train |
cmsgears/module-core | common/models/resources/File.php | File.getThumbPath | public function getThumbPath() {
if( isset( $this->thumb ) ) {
return Yii::$app->fileManager->uploadDir . '/' . $this->thumb;
}
return false;
} | php | public function getThumbPath() {
if( isset( $this->thumb ) ) {
return Yii::$app->fileManager->uploadDir . '/' . $this->thumb;
}
return false;
} | [
"public",
"function",
"getThumbPath",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"thumb",
")",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"fileManager",
"->",
"uploadDir",
".",
"'/'",
".",
"$",
"this",
"->",
"thumb",
";",
"}... | Return physical storage location of thumb.
@return string|boolean | [
"Return",
"physical",
"storage",
"location",
"of",
"thumb",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L346-L354 | train |
cmsgears/module-core | common/models/resources/File.php | File.resetSize | public function resetSize() {
$filePath = $this->getFilePath();
if( $filePath && file_exists( $filePath ) && is_file( $filePath ) ) {
$size = filesize( $filePath ); // bytes
$sizeInMb = $size / pow( 1024, 2 );
$this->size = round( $sizeInMb, 4 ); // Round upto 4 precision, expected size at least in kb
}
} | php | public function resetSize() {
$filePath = $this->getFilePath();
if( $filePath && file_exists( $filePath ) && is_file( $filePath ) ) {
$size = filesize( $filePath ); // bytes
$sizeInMb = $size / pow( 1024, 2 );
$this->size = round( $sizeInMb, 4 ); // Round upto 4 precision, expected size at least in kb
}
} | [
"public",
"function",
"resetSize",
"(",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"getFilePath",
"(",
")",
";",
"if",
"(",
"$",
"filePath",
"&&",
"file_exists",
"(",
"$",
"filePath",
")",
"&&",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",... | Calculate and set the file size in MB.
@return void | [
"Calculate",
"and",
"set",
"the",
"file",
"size",
"in",
"MB",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L361-L372 | train |
cmsgears/module-core | common/models/resources/File.php | File.clearDisk | public function clearDisk() {
$filePath = $this->getFilePath();
$mediumPath = $this->getMediumPath();
$thumbPath = $this->getThumbPath();
// Delete from disk
if( $filePath && file_exists( $filePath ) && is_file( $filePath ) ) {
unlink( $filePath );
}
if( $mediumPath && file_exists( $mediumPath ) && is_file( $mediumPath ) ) {
unlink( $mediumPath );
}
if( $thumbPath && file_exists( $thumbPath ) && is_file( $thumbPath ) ) {
unlink( $thumbPath );
}
} | php | public function clearDisk() {
$filePath = $this->getFilePath();
$mediumPath = $this->getMediumPath();
$thumbPath = $this->getThumbPath();
// Delete from disk
if( $filePath && file_exists( $filePath ) && is_file( $filePath ) ) {
unlink( $filePath );
}
if( $mediumPath && file_exists( $mediumPath ) && is_file( $mediumPath ) ) {
unlink( $mediumPath );
}
if( $thumbPath && file_exists( $thumbPath ) && is_file( $thumbPath ) ) {
unlink( $thumbPath );
}
} | [
"public",
"function",
"clearDisk",
"(",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"getFilePath",
"(",
")",
";",
"$",
"mediumPath",
"=",
"$",
"this",
"->",
"getMediumPath",
"(",
")",
";",
"$",
"thumbPath",
"=",
"$",
"this",
"->",
"getThumbPath"... | Delete all the associated files from disk. Useful while updating file.
@return void | [
"Delete",
"all",
"the",
"associated",
"files",
"from",
"disk",
".",
"Useful",
"while",
"updating",
"file",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L379-L400 | train |
cmsgears/module-core | common/models/resources/File.php | File.loadFile | public static function loadFile( $file, $name ) {
if( !isset( $file ) ) {
$file = new File();
}
$file->load( Yii::$app->request->post(), $name );
return $file;
} | php | public static function loadFile( $file, $name ) {
if( !isset( $file ) ) {
$file = new File();
}
$file->load( Yii::$app->request->post(), $name );
return $file;
} | [
"public",
"static",
"function",
"loadFile",
"(",
"$",
"file",
",",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"file",
")",
")",
"{",
"$",
"file",
"=",
"new",
"File",
"(",
")",
";",
"}",
"$",
"file",
"->",
"load",
"(",
"Yii",
":... | Load the file attributes submitted by form and return the updated file model.
@param File $file
@param string $name
@return File - after loading from request url | [
"Load",
"the",
"file",
"attributes",
"submitted",
"by",
"form",
"and",
"return",
"the",
"updated",
"file",
"model",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L497-L507 | train |
cmsgears/module-core | common/models/resources/File.php | File.loadFiles | public function loadFiles( $name, $files = [] ) {
$filesToLoad = Yii::$app->request->post( $name );
$count = count( $filesToLoad );
if ( $count > 0 ) {
$filesToLoad = [];
// TODO: Use existing file models using $files param.
for( $i = 0; $i < $count; $i++ ) {
$filesToLoad[] = new File();
}
File::loadMultiple( $filesToLoad, Yii::$app->request->post(), $name );
return $filesToLoad;
}
return $files;
} | php | public function loadFiles( $name, $files = [] ) {
$filesToLoad = Yii::$app->request->post( $name );
$count = count( $filesToLoad );
if ( $count > 0 ) {
$filesToLoad = [];
// TODO: Use existing file models using $files param.
for( $i = 0; $i < $count; $i++ ) {
$filesToLoad[] = new File();
}
File::loadMultiple( $filesToLoad, Yii::$app->request->post(), $name );
return $filesToLoad;
}
return $files;
} | [
"public",
"function",
"loadFiles",
"(",
"$",
"name",
",",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"$",
"filesToLoad",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
"$",
"name",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
... | Load file attributes submitted by form and return the updated file models.
@param string $name
@param File[] $files
@return File - after loading from request url | [
"Load",
"file",
"attributes",
"submitted",
"by",
"form",
"and",
"return",
"the",
"updated",
"file",
"models",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/File.php#L516-L537 | train |
geekwright/RegDom | src/PublicSuffixList.php | PublicSuffixList.loadTree | protected function loadTree()
{
$this->setFallbackURL();
$this->tree = $this->readCachedPSL($this->url);
if (false !== $this->tree) {
return;
}
$this->tree = array();
$list = $this->readPSL();
if (false===$list) {
throw new \RuntimeException('Cannot read ' . $this->url);
}
$this->parsePSL($list);
$this->cachePSL($this->url);
} | php | protected function loadTree()
{
$this->setFallbackURL();
$this->tree = $this->readCachedPSL($this->url);
if (false !== $this->tree) {
return;
}
$this->tree = array();
$list = $this->readPSL();
if (false===$list) {
throw new \RuntimeException('Cannot read ' . $this->url);
}
$this->parsePSL($list);
$this->cachePSL($this->url);
} | [
"protected",
"function",
"loadTree",
"(",
")",
"{",
"$",
"this",
"->",
"setFallbackURL",
"(",
")",
";",
"$",
"this",
"->",
"tree",
"=",
"$",
"this",
"->",
"readCachedPSL",
"(",
"$",
"this",
"->",
"url",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"th... | load the PSL tree, automatically handling caches
@return void (results in $this->tree)
@throws \RuntimeException | [
"load",
"the",
"PSL",
"tree",
"automatically",
"handling",
"caches"
] | f51eb343c526913f699d84c47596195a8a63ce09 | https://github.com/geekwright/RegDom/blob/f51eb343c526913f699d84c47596195a8a63ce09/src/PublicSuffixList.php#L67-L85 | train |
geekwright/RegDom | src/PublicSuffixList.php | PublicSuffixList.parsePSL | protected function parsePSL($fileData)
{
$lines = explode("\n", $fileData);
foreach ($lines as $line) {
if ($this->startsWith($line, "//") || $line == '') {
continue;
}
// this line should be a TLD
$tldParts = explode('.', $line);
$this->buildSubDomain($this->tree, $tldParts);
}
} | php | protected function parsePSL($fileData)
{
$lines = explode("\n", $fileData);
foreach ($lines as $line) {
if ($this->startsWith($line, "//") || $line == '') {
continue;
}
// this line should be a TLD
$tldParts = explode('.', $line);
$this->buildSubDomain($this->tree, $tldParts);
}
} | [
"protected",
"function",
"parsePSL",
"(",
"$",
"fileData",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"fileData",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"startsWith",
... | Parse the PSL data
@param string $fileData the PSL data
@return void (results in $this->tree) | [
"Parse",
"the",
"PSL",
"data"
] | f51eb343c526913f699d84c47596195a8a63ce09 | https://github.com/geekwright/RegDom/blob/f51eb343c526913f699d84c47596195a8a63ce09/src/PublicSuffixList.php#L94-L108 | train |
geekwright/RegDom | src/PublicSuffixList.php | PublicSuffixList.buildSubDomain | protected function buildSubDomain(&$node, $tldParts)
{
$dom = trim(array_pop($tldParts));
$isNotDomain = false;
if ($this->startsWith($dom, "!")) {
$dom = substr($dom, 1);
$isNotDomain = true;
}
if (!array_key_exists($dom, $node)) {
if ($isNotDomain) {
$node[$dom] = array("!" => "");
} else {
$node[$dom] = array();
}
}
if (!$isNotDomain && count($tldParts) > 0) {
$this->buildSubDomain($node[$dom], $tldParts);
}
} | php | protected function buildSubDomain(&$node, $tldParts)
{
$dom = trim(array_pop($tldParts));
$isNotDomain = false;
if ($this->startsWith($dom, "!")) {
$dom = substr($dom, 1);
$isNotDomain = true;
}
if (!array_key_exists($dom, $node)) {
if ($isNotDomain) {
$node[$dom] = array("!" => "");
} else {
$node[$dom] = array();
}
}
if (!$isNotDomain && count($tldParts) > 0) {
$this->buildSubDomain($node[$dom], $tldParts);
}
} | [
"protected",
"function",
"buildSubDomain",
"(",
"&",
"$",
"node",
",",
"$",
"tldParts",
")",
"{",
"$",
"dom",
"=",
"trim",
"(",
"array_pop",
"(",
"$",
"tldParts",
")",
")",
";",
"$",
"isNotDomain",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"... | Add domains to tree
@param array $node tree array by reference
@param string[] $tldParts array of domain parts
@return void - changes made to $node by reference | [
"Add",
"domains",
"to",
"tree"
] | f51eb343c526913f699d84c47596195a8a63ce09 | https://github.com/geekwright/RegDom/blob/f51eb343c526913f699d84c47596195a8a63ce09/src/PublicSuffixList.php#L131-L152 | train |
geekwright/RegDom | src/PublicSuffixList.php | PublicSuffixList.readCachedPSL | protected function readCachedPSL($url)
{
$cacheFile = $this->getCacheFileName($url);
if (file_exists($cacheFile)) {
$cachedTree = file_get_contents($cacheFile);
return unserialize($cachedTree);
}
return false;
} | php | protected function readCachedPSL($url)
{
$cacheFile = $this->getCacheFileName($url);
if (file_exists($cacheFile)) {
$cachedTree = file_get_contents($cacheFile);
return unserialize($cachedTree);
}
return false;
} | [
"protected",
"function",
"readCachedPSL",
"(",
"$",
"url",
")",
"{",
"$",
"cacheFile",
"=",
"$",
"this",
"->",
"getCacheFileName",
"(",
"$",
"url",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"cacheFile",
")",
")",
"{",
"$",
"cachedTree",
"=",
"file_... | Attempt to load a cached Public Suffix List tree for a given source
@param string $url URL/filename of source PSL
@return bool|string[] PSL tree | [
"Attempt",
"to",
"load",
"a",
"cached",
"Public",
"Suffix",
"List",
"tree",
"for",
"a",
"given",
"source"
] | f51eb343c526913f699d84c47596195a8a63ce09 | https://github.com/geekwright/RegDom/blob/f51eb343c526913f699d84c47596195a8a63ce09/src/PublicSuffixList.php#L224-L232 | train |
geekwright/RegDom | src/PublicSuffixList.php | PublicSuffixList.setLocalPSLName | protected function setLocalPSLName($url)
{
if (null === $url) {
$url = $this->sourceURL;
}
$parts = parse_url($url);
$fileName = basename($parts['path']);
$this->localPSL = $this->dataDir . $fileName;
} | php | protected function setLocalPSLName($url)
{
if (null === $url) {
$url = $this->sourceURL;
}
$parts = parse_url($url);
$fileName = basename($parts['path']);
$this->localPSL = $this->dataDir . $fileName;
} | [
"protected",
"function",
"setLocalPSLName",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"sourceURL",
";",
"}",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"fil... | Set localPSL name based on URL
@param null|string $url the URL for the PSL
@return void (sets $this->localPSL) | [
"Set",
"localPSL",
"name",
"based",
"on",
"URL"
] | f51eb343c526913f699d84c47596195a8a63ce09 | https://github.com/geekwright/RegDom/blob/f51eb343c526913f699d84c47596195a8a63ce09/src/PublicSuffixList.php#L265-L273 | train |
geekwright/RegDom | src/PublicSuffixList.php | PublicSuffixList.clearDataDirectory | public function clearDataDirectory($cacheOnly = false)
{
$dir = __DIR__ . $this->dataDir;
if (is_dir($dir)) {
if ($dirHandle = opendir($dir)) {
while (($file = readdir($dirHandle)) !== false) {
if (filetype($dir . $file) === 'file'
&& (false === $cacheOnly || $this->startsWith($file, $this->cachedPrefix))) {
unlink($dir . $file);
}
}
closedir($dirHandle);
}
}
} | php | public function clearDataDirectory($cacheOnly = false)
{
$dir = __DIR__ . $this->dataDir;
if (is_dir($dir)) {
if ($dirHandle = opendir($dir)) {
while (($file = readdir($dirHandle)) !== false) {
if (filetype($dir . $file) === 'file'
&& (false === $cacheOnly || $this->startsWith($file, $this->cachedPrefix))) {
unlink($dir . $file);
}
}
closedir($dirHandle);
}
}
} | [
"public",
"function",
"clearDataDirectory",
"(",
"$",
"cacheOnly",
"=",
"false",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"$",
"this",
"->",
"dataDir",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"$",
"dirHandle",
"=",
"o... | Delete files in the data directory
@param bool $cacheOnly true to limit clearing to cached serialized PSLs, false to clear all
@return void | [
"Delete",
"files",
"in",
"the",
"data",
"directory"
] | f51eb343c526913f699d84c47596195a8a63ce09 | https://github.com/geekwright/RegDom/blob/f51eb343c526913f699d84c47596195a8a63ce09/src/PublicSuffixList.php#L282-L296 | train |
atk14/UrlFetcher | src/url_fetcher.php | UrlFetcher.setAuthorization | function setAuthorization($username,$password){
settype($username,"string");
settype($password,"string");
$this->_Username = $username;
$this->_Password = $password;
$this->_AuthType = "basic";
} | php | function setAuthorization($username,$password){
settype($username,"string");
settype($password,"string");
$this->_Username = $username;
$this->_Password = $password;
$this->_AuthType = "basic";
} | [
"function",
"setAuthorization",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"settype",
"(",
"$",
"username",
",",
"\"string\"",
")",
";",
"settype",
"(",
"$",
"password",
",",
"\"string\"",
")",
";",
"$",
"this",
"->",
"_Username",
"=",
"$",
... | Set authorization parameters.
@param string $username
@param string $password | [
"Set",
"authorization",
"parameters",
"."
] | 80b3dab3c34edc6971925147021812990eb90fc4 | https://github.com/atk14/UrlFetcher/blob/80b3dab3c34edc6971925147021812990eb90fc4/src/url_fetcher.php#L244-L251 | train |
atk14/UrlFetcher | src/url_fetcher.php | UrlFetcher.post | function post($data = "",$options = array()){
if(is_array($data)){
$d = array();
foreach($data as $k => $v){
$d[] = urlencode($k)."=".urlencode($v);
}
$data = join("&",$d);
}
$options = array_merge(array(
"content_type" => "application/x-www-form-urlencoded",
"additional_headers" => array(),
),$options);
$this->_RequestMethod = "POST";
$this->_PostData = $data;
$this->_AdditionalHeaders = $options["additional_headers"];
$this->_AdditionalHeaders[] = "Content-Type: $options[content_type]";
return $this->fetchContent();
} | php | function post($data = "",$options = array()){
if(is_array($data)){
$d = array();
foreach($data as $k => $v){
$d[] = urlencode($k)."=".urlencode($v);
}
$data = join("&",$d);
}
$options = array_merge(array(
"content_type" => "application/x-www-form-urlencoded",
"additional_headers" => array(),
),$options);
$this->_RequestMethod = "POST";
$this->_PostData = $data;
$this->_AdditionalHeaders = $options["additional_headers"];
$this->_AdditionalHeaders[] = "Content-Type: $options[content_type]";
return $this->fetchContent();
} | [
"function",
"post",
"(",
"$",
"data",
"=",
"\"\"",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"d",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
... | Performs a POST request
@param mixed $data when array it is sent as query parameters, otherwise $data is sent without processing
@param array $options
- content_type string - value for Content-Type HTTP header
- additional_headers array - more headers
@return bool result of request | [
"Performs",
"a",
"POST",
"request"
] | 80b3dab3c34edc6971925147021812990eb90fc4 | https://github.com/atk14/UrlFetcher/blob/80b3dab3c34edc6971925147021812990eb90fc4/src/url_fetcher.php#L417-L437 | train |
atk14/UrlFetcher | src/url_fetcher.php | UrlFetcher.put | function put($url = "",$options = array()){
if(is_array($url)){
$options = $url;
$url = "";
}
$options["request_method"] = "PUT";
return $this->fetchContent($url,$options);
} | php | function put($url = "",$options = array()){
if(is_array($url)){
$options = $url;
$url = "";
}
$options["request_method"] = "PUT";
return $this->fetchContent($url,$options);
} | [
"function",
"put",
"(",
"$",
"url",
"=",
"\"\"",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"$",
"options",
"=",
"$",
"url",
";",
"$",
"url",
"=",
"\"\"",
";",
"}",
"$",
"op... | Performs a PUT request | [
"Performs",
"a",
"PUT",
"request"
] | 80b3dab3c34edc6971925147021812990eb90fc4 | https://github.com/atk14/UrlFetcher/blob/80b3dab3c34edc6971925147021812990eb90fc4/src/url_fetcher.php#L442-L449 | train |
atk14/UrlFetcher | src/url_fetcher.php | UrlFetcher.delete | function delete($url = "",$options = array()){
if(is_array($url)){
$options = $url;
$url = "";
}
$options["request_method"] = "DELETE";
return $this->fetchContent($url,$options);
} | php | function delete($url = "",$options = array()){
if(is_array($url)){
$options = $url;
$url = "";
}
$options["request_method"] = "DELETE";
return $this->fetchContent($url,$options);
} | [
"function",
"delete",
"(",
"$",
"url",
"=",
"\"\"",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"$",
"options",
"=",
"$",
"url",
";",
"$",
"url",
"=",
"\"\"",
";",
"}",
"$",
... | Performs a DELETE request | [
"Performs",
"a",
"DELETE",
"request"
] | 80b3dab3c34edc6971925147021812990eb90fc4 | https://github.com/atk14/UrlFetcher/blob/80b3dab3c34edc6971925147021812990eb90fc4/src/url_fetcher.php#L454-L461 | train |
atk14/UrlFetcher | src/url_fetcher.php | UrlFetcher.getResponseHeaders | function getResponseHeaders($options = array()){
$options = array_merge(array(
"as_hash" => false,
"lowerize_keys" => false
),$options);
$this->fetchContent();
$out = $this->_ResponseHeaders;
if($options["as_hash"]){
$headers = explode("\n",$out);
$out = array();
foreach($headers as $h){
if(preg_match("/^([^ ]+):(.*)/",trim($h),$matches)){
$key = $options["lowerize_keys"] ? strtolower($matches[1]) : $matches[1];
$out[$key] = trim($matches[2]);
}
}
}
return $out;
} | php | function getResponseHeaders($options = array()){
$options = array_merge(array(
"as_hash" => false,
"lowerize_keys" => false
),$options);
$this->fetchContent();
$out = $this->_ResponseHeaders;
if($options["as_hash"]){
$headers = explode("\n",$out);
$out = array();
foreach($headers as $h){
if(preg_match("/^([^ ]+):(.*)/",trim($h),$matches)){
$key = $options["lowerize_keys"] ? strtolower($matches[1]) : $matches[1];
$out[$key] = trim($matches[2]);
}
}
}
return $out;
} | [
"function",
"getResponseHeaders",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"\"as_hash\"",
"=>",
"false",
",",
"\"lowerize_keys\"",
"=>",
"false",
")",
",",
"$",
"options",
")",
";",
"$"... | Gets headers returned by the server.
@param array $options
- <b>as_hash</b> - returns headers as array when set to true [default: false]
- <b>lowerize_keys</b> - convert header names lowercase when set to true [default: false]
@return string|array | [
"Gets",
"headers",
"returned",
"by",
"the",
"server",
"."
] | 80b3dab3c34edc6971925147021812990eb90fc4 | https://github.com/atk14/UrlFetcher/blob/80b3dab3c34edc6971925147021812990eb90fc4/src/url_fetcher.php#L478-L500 | train |
atk14/UrlFetcher | src/url_fetcher.php | UrlFetcher.getHeaderValue | function getHeaderValue($header){
$header = strtolower($header);
$headers = $this->getResponseHeaders(array("as_hash" => true, "lowerize_keys" => true));
if(isset($headers["$header"])){ return $headers["$header"]; }
} | php | function getHeaderValue($header){
$header = strtolower($header);
$headers = $this->getResponseHeaders(array("as_hash" => true, "lowerize_keys" => true));
if(isset($headers["$header"])){ return $headers["$header"]; }
} | [
"function",
"getHeaderValue",
"(",
"$",
"header",
")",
"{",
"$",
"header",
"=",
"strtolower",
"(",
"$",
"header",
")",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"getResponseHeaders",
"(",
"array",
"(",
"\"as_hash\"",
"=>",
"true",
",",
"\"lowerize_keys\... | Returns value of given header
```
$c_type = $uf->getHeaderValue("Content-Type"); // "text/xml"
```
@param string $header
@return string | [
"Returns",
"value",
"of",
"given",
"header"
] | 80b3dab3c34edc6971925147021812990eb90fc4 | https://github.com/atk14/UrlFetcher/blob/80b3dab3c34edc6971925147021812990eb90fc4/src/url_fetcher.php#L527-L531 | train |
atk14/UrlFetcher | src/url_fetcher.php | UrlFetcher._fwriteStream | protected function _fwriteStream(&$fp, &$string) {
$fwrite = 0;
for($written = 0; $written < strlen($string); $written += $fwrite){
$fwrite = @fwrite($fp, substr($string, $written));
if($fwrite === false){
return $written;
}
if(!$fwrite){ // 0 bytes written; error code 11: Resource temporarily unavailable
usleep(10000);
continue;
}
}
return $written;
} | php | protected function _fwriteStream(&$fp, &$string) {
$fwrite = 0;
for($written = 0; $written < strlen($string); $written += $fwrite){
$fwrite = @fwrite($fp, substr($string, $written));
if($fwrite === false){
return $written;
}
if(!$fwrite){ // 0 bytes written; error code 11: Resource temporarily unavailable
usleep(10000);
continue;
}
}
return $written;
} | [
"protected",
"function",
"_fwriteStream",
"(",
"&",
"$",
"fp",
",",
"&",
"$",
"string",
")",
"{",
"$",
"fwrite",
"=",
"0",
";",
"for",
"(",
"$",
"written",
"=",
"0",
";",
"$",
"written",
"<",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"written"... | Writes string to a network socket
See http://php.net/fwrite
Note: Writing to a network stream may end before the whole string is written. Return value of fwrite() may be checked:
@ignore | [
"Writes",
"string",
"to",
"a",
"network",
"socket"
] | 80b3dab3c34edc6971925147021812990eb90fc4 | https://github.com/atk14/UrlFetcher/blob/80b3dab3c34edc6971925147021812990eb90fc4/src/url_fetcher.php#L719-L734 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/IpProperty.php | IpProperty.storageVal | public function storageVal($val)
{
$mode = $this->storageMode();
if ($mode === self::STORAGE_MODE_INT) {
return $this->intVal($val);
} else {
return $this->stringVal($val);
}
} | php | public function storageVal($val)
{
$mode = $this->storageMode();
if ($mode === self::STORAGE_MODE_INT) {
return $this->intVal($val);
} else {
return $this->stringVal($val);
}
} | [
"public",
"function",
"storageVal",
"(",
"$",
"val",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"storageMode",
"(",
")",
";",
"if",
"(",
"$",
"mode",
"===",
"self",
"::",
"STORAGE_MODE_INT",
")",
"{",
"return",
"$",
"this",
"->",
"intVal",
"(",
... | Get the IP value in the suitable format for storage.
@param mixed $val The value to convert to string.
@see StorablePropertyTrait::storageVal()
@return string | [
"Get",
"the",
"IP",
"value",
"in",
"the",
"suitable",
"format",
"for",
"storage",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/IpProperty.php#L167-L176 | train |
cmsgears/module-core | common/utilities/CodeGenUtil.php | CodeGenUtil.getPaginationDetail | public static function getPaginationDetail( $dataProvider ) {
$total = $dataProvider->getTotalCount();
$pagination = $dataProvider->getPagination();
$current_page = $pagination->getPage();
$page_size = $pagination->getPageSize();
$start = $page_size * $current_page;
$end = $page_size * ( $current_page + 1 ) - 1;
$currentSize = count( $dataProvider->getModels() );
$currentDisplay = $end - $start;
if( $currentSize < $currentDisplay ) {
$end = $start + $currentSize;
}
if( $end > 0 ) {
$start += 1;
}
if( $currentSize == $page_size ) {
$end += 1;
}
return "Showing $start to $end out of $total entries";
} | php | public static function getPaginationDetail( $dataProvider ) {
$total = $dataProvider->getTotalCount();
$pagination = $dataProvider->getPagination();
$current_page = $pagination->getPage();
$page_size = $pagination->getPageSize();
$start = $page_size * $current_page;
$end = $page_size * ( $current_page + 1 ) - 1;
$currentSize = count( $dataProvider->getModels() );
$currentDisplay = $end - $start;
if( $currentSize < $currentDisplay ) {
$end = $start + $currentSize;
}
if( $end > 0 ) {
$start += 1;
}
if( $currentSize == $page_size ) {
$end += 1;
}
return "Showing $start to $end out of $total entries";
} | [
"public",
"static",
"function",
"getPaginationDetail",
"(",
"$",
"dataProvider",
")",
"{",
"$",
"total",
"=",
"$",
"dataProvider",
"->",
"getTotalCount",
"(",
")",
";",
"$",
"pagination",
"=",
"$",
"dataProvider",
"->",
"getPagination",
"(",
")",
";",
"$",
... | Return pagination info to be displayed on data grid footer or header.
@return string - pagination info | [
"Return",
"pagination",
"info",
"to",
"be",
"displayed",
"on",
"data",
"grid",
"footer",
"or",
"header",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/utilities/CodeGenUtil.php#L23-L50 | train |
cmsgears/module-core | common/utilities/CodeGenUtil.php | CodeGenUtil.getImageThumbTag | public static function getImageThumbTag( $image, $options = [] ) {
// Use Image from DB
if( isset( $image ) ) {
$thumbUrl = $image->getThumbUrl();
if( isset( $options[ 'class' ] ) ) {
$class = $options[ 'class' ];
return "<img class='$class' src='$thumbUrl'>";
}
else {
return "<img src='$thumbUrl'>";
}
}
else {
// Use Image from web root directory
if( isset( $options[ 'image' ] ) ) {
$images = Yii::getAlias( '@images' );
$img = $options[ 'image' ];
if( isset( $options[ 'class' ] ) ) {
$class = $options[ 'class' ];
return "<img class='$class' src='$images/$img'>";
}
else {
return "<img src='$images/$img'>";
}
}
// Use icon
else if( isset( $options[ 'icon' ] ) ) {
$icon = $options[ 'icon' ];
return "<span class='$icon'></span>";
}
}
} | php | public static function getImageThumbTag( $image, $options = [] ) {
// Use Image from DB
if( isset( $image ) ) {
$thumbUrl = $image->getThumbUrl();
if( isset( $options[ 'class' ] ) ) {
$class = $options[ 'class' ];
return "<img class='$class' src='$thumbUrl'>";
}
else {
return "<img src='$thumbUrl'>";
}
}
else {
// Use Image from web root directory
if( isset( $options[ 'image' ] ) ) {
$images = Yii::getAlias( '@images' );
$img = $options[ 'image' ];
if( isset( $options[ 'class' ] ) ) {
$class = $options[ 'class' ];
return "<img class='$class' src='$images/$img'>";
}
else {
return "<img src='$images/$img'>";
}
}
// Use icon
else if( isset( $options[ 'icon' ] ) ) {
$icon = $options[ 'icon' ];
return "<span class='$icon'></span>";
}
}
} | [
"public",
"static",
"function",
"getImageThumbTag",
"(",
"$",
"image",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"// Use Image from DB",
"if",
"(",
"isset",
"(",
"$",
"image",
")",
")",
"{",
"$",
"thumbUrl",
"=",
"$",
"image",
"->",
"getThumbUrl",
... | Return Image Tag | [
"Return",
"Image",
"Tag"
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/utilities/CodeGenUtil.php#L289-L334 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/StructureProperty.php | StructureProperty.setSqlType | public function setSqlType($sqlType)
{
if (!is_string($sqlType)) {
throw new InvalidArgumentException(
'SQL Type must be a string.'
);
}
switch (strtoupper($sqlType)) {
case 'TEXT':
$sqlType = 'TEXT';
break;
case 'TINY':
case 'TINYTEXT':
$sqlType = 'TINYTEXT';
break;
case 'MEDIUM':
case 'MEDIUMTEXT':
$sqlType = 'MEDIUMTEXT';
break;
case 'LONG':
case 'LONGTEXT':
$sqlType = 'LONGTEXT';
break;
default:
throw new InvalidArgumentException(
'SQL Type must be one of TEXT, TINYTEXT, MEDIUMTEXT, LONGTEXT.'
);
}
$this->sqlType = $sqlType;
return $this;
} | php | public function setSqlType($sqlType)
{
if (!is_string($sqlType)) {
throw new InvalidArgumentException(
'SQL Type must be a string.'
);
}
switch (strtoupper($sqlType)) {
case 'TEXT':
$sqlType = 'TEXT';
break;
case 'TINY':
case 'TINYTEXT':
$sqlType = 'TINYTEXT';
break;
case 'MEDIUM':
case 'MEDIUMTEXT':
$sqlType = 'MEDIUMTEXT';
break;
case 'LONG':
case 'LONGTEXT':
$sqlType = 'LONGTEXT';
break;
default:
throw new InvalidArgumentException(
'SQL Type must be one of TEXT, TINYTEXT, MEDIUMTEXT, LONGTEXT.'
);
}
$this->sqlType = $sqlType;
return $this;
} | [
"public",
"function",
"setSqlType",
"(",
"$",
"sqlType",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"sqlType",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'SQL Type must be a string.'",
")",
";",
"}",
"switch",
"(",
"strtoupper",
"... | Set the property's SQL encoding & collation.
@param string $sqlType The field SQL column type.
@throws InvalidArgumentException If the SQL type is invalid.
@return self | [
"Set",
"the",
"property",
"s",
"SQL",
"encoding",
"&",
"collation",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/StructureProperty.php#L180-L217 | train |
cmsgears/module-core | common/components/Core.php | Core.init | public function init() {
parent::init();
// Initialise core validators
CoreValidator::initValidators();
/** Set CMSGears alias to be used by all modules, plugins, widgets and themes.
* It will be located within the vendor directory for composer.
*/
Yii::setAlias( 'cmsgears', dirname( dirname( dirname( __DIR__ ) ) ) );
} | php | public function init() {
parent::init();
// Initialise core validators
CoreValidator::initValidators();
/** Set CMSGears alias to be used by all modules, plugins, widgets and themes.
* It will be located within the vendor directory for composer.
*/
Yii::setAlias( 'cmsgears', dirname( dirname( dirname( __DIR__ ) ) ) );
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"// Initialise core validators",
"CoreValidator",
"::",
"initValidators",
"(",
")",
";",
"/** Set CMSGears alias to be used by all modules, plugins, widgets and themes.\n\t\t * It will be locate... | Initialise the CMG Core Component. | [
"Initialise",
"the",
"CMG",
"Core",
"Component",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/components/Core.php#L231-L242 | train |
cmsgears/module-core | common/components/Core.php | Core.setAppUser | public function setAppUser( $user ) {
$cookieName = '_app-user';
$guestUser[ 'user' ] = [ 'id' => $user->id, 'firstname' => $user->firstName, 'lastname' => $user->lastName, 'email' => $user->email ];
if( isset( $_COOKIE[ $cookieName ] ) ) {
$data = unserialize( $_COOKIE[ $cookieName ] );
if( $data[ 'user' ][ 'id' ] != $user->id ) {
return setcookie( $cookieName, serialize( $guestUser ), time() + ( 10 * 365 * 24 * 60 * 60 ), "/", null );
}
}
else {
return setcookie( $cookieName, serialize( $guestUser ), time() + ( 10 * 365 * 24 * 60 * 60 ), "/", null );
}
} | php | public function setAppUser( $user ) {
$cookieName = '_app-user';
$guestUser[ 'user' ] = [ 'id' => $user->id, 'firstname' => $user->firstName, 'lastname' => $user->lastName, 'email' => $user->email ];
if( isset( $_COOKIE[ $cookieName ] ) ) {
$data = unserialize( $_COOKIE[ $cookieName ] );
if( $data[ 'user' ][ 'id' ] != $user->id ) {
return setcookie( $cookieName, serialize( $guestUser ), time() + ( 10 * 365 * 24 * 60 * 60 ), "/", null );
}
}
else {
return setcookie( $cookieName, serialize( $guestUser ), time() + ( 10 * 365 * 24 * 60 * 60 ), "/", null );
}
} | [
"public",
"function",
"setAppUser",
"(",
"$",
"user",
")",
"{",
"$",
"cookieName",
"=",
"'_app-user'",
";",
"$",
"guestUser",
"[",
"'user'",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"user",
"->",
"id",
",",
"'firstname'",
"=>",
"$",
"user",
"->",
"firstName",... | Cookies & Session | [
"Cookies",
"&",
"Session"
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/components/Core.php#L556-L575 | train |
cmsgears/module-core | common/components/Core.php | Core.getAppUser | public function getAppUser() {
$cookieName = '_app-user';
$appUser = null;
$user = Yii::$app->user->identity;
if( $user != null ) {
$appUser = $user;
}
else if( isset( $_COOKIE[ $cookieName ] ) ) {
$data = unserialize( $_COOKIE[ $cookieName ] );
if( isset( $data[ 'user' ] ) ) {
//$appUser = (object) $data[ 'user' ]['user'];
$appUser = UserService::findById( $data[ 'user' ][ 'id' ] );
}
}
return $appUser;
} | php | public function getAppUser() {
$cookieName = '_app-user';
$appUser = null;
$user = Yii::$app->user->identity;
if( $user != null ) {
$appUser = $user;
}
else if( isset( $_COOKIE[ $cookieName ] ) ) {
$data = unserialize( $_COOKIE[ $cookieName ] );
if( isset( $data[ 'user' ] ) ) {
//$appUser = (object) $data[ 'user' ]['user'];
$appUser = UserService::findById( $data[ 'user' ][ 'id' ] );
}
}
return $appUser;
} | [
"public",
"function",
"getAppUser",
"(",
")",
"{",
"$",
"cookieName",
"=",
"'_app-user'",
";",
"$",
"appUser",
"=",
"null",
";",
"$",
"user",
"=",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"identity",
";",
"if",
"(",
"$",
"user",
"!=",
"null",
"... | Call setAppUser at least once for new user before calling this method. | [
"Call",
"setAppUser",
"at",
"least",
"once",
"for",
"new",
"user",
"before",
"calling",
"this",
"method",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/components/Core.php#L578-L601 | train |
tamago-db/LinkedinImporterBundle | Controller/DefaultController.php | DefaultController.requestPrivateAction | public function requestPrivateAction()
{
//load up the importer class
$importer = $this->get('linkedin.importer');
//set a redirect for linkedin to bump the user back to after they approve your app
$importer->setRedirect($this->generateUrl('ccc_linkedin_importer_receivePrivate', array('submit' => true), true));
//nothing on this form except for a submit button to start the process
$form = $this->createForm(new LiForm\RequestPrivate());
$request = $this->getRequest();
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
//user hit the start button, so request permission from the user to allow your app on their linkedin account
//this will redirect to linkedin's site
return $importer->requestPermission();
}
}
return $this->render('CCCLinkedinImporterBundle:Default:requestPrivate.html.twig', array('form' => $form->createView()));
} | php | public function requestPrivateAction()
{
//load up the importer class
$importer = $this->get('linkedin.importer');
//set a redirect for linkedin to bump the user back to after they approve your app
$importer->setRedirect($this->generateUrl('ccc_linkedin_importer_receivePrivate', array('submit' => true), true));
//nothing on this form except for a submit button to start the process
$form = $this->createForm(new LiForm\RequestPrivate());
$request = $this->getRequest();
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
//user hit the start button, so request permission from the user to allow your app on their linkedin account
//this will redirect to linkedin's site
return $importer->requestPermission();
}
}
return $this->render('CCCLinkedinImporterBundle:Default:requestPrivate.html.twig', array('form' => $form->createView()));
} | [
"public",
"function",
"requestPrivateAction",
"(",
")",
"{",
"//load up the importer class",
"$",
"importer",
"=",
"$",
"this",
"->",
"get",
"(",
"'linkedin.importer'",
")",
";",
"//set a redirect for linkedin to bump the user back to after they approve your app",
"$",
"impor... | Example of how to request the user's private data. | [
"Example",
"of",
"how",
"to",
"request",
"the",
"user",
"s",
"private",
"data",
"."
] | bf510a675311c181995b17744e1420fc4fbb2e60 | https://github.com/tamago-db/LinkedinImporterBundle/blob/bf510a675311c181995b17744e1420fc4fbb2e60/Controller/DefaultController.php#L13-L37 | train |
tamago-db/LinkedinImporterBundle | Controller/DefaultController.php | DefaultController.requestPublicAction | public function requestPublicAction()
{
$importer = $this->get('linkedin.importer');
$form = $this->createForm(new LiForm\RequestPublic());
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$form_data = $form->getData();
//add the other user's public profile url to the redirect
$importer->setRedirect($this->generateUrl('ccc_linkedin_importer_receivePublic', array('submit' => true, 'url' => urlencode($form_data['url'])), true));
//still need to ask the current user for permission to go through our app
return $importer->requestPermission('public');
}
}
return $this->render('CCCLinkedinImporterBundle:Default:requestPublic.html.twig', array('form' => $form->createView()));
} | php | public function requestPublicAction()
{
$importer = $this->get('linkedin.importer');
$form = $this->createForm(new LiForm\RequestPublic());
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$form_data = $form->getData();
//add the other user's public profile url to the redirect
$importer->setRedirect($this->generateUrl('ccc_linkedin_importer_receivePublic', array('submit' => true, 'url' => urlencode($form_data['url'])), true));
//still need to ask the current user for permission to go through our app
return $importer->requestPermission('public');
}
}
return $this->render('CCCLinkedinImporterBundle:Default:requestPublic.html.twig', array('form' => $form->createView()));
} | [
"public",
"function",
"requestPublicAction",
"(",
")",
"{",
"$",
"importer",
"=",
"$",
"this",
"->",
"get",
"(",
"'linkedin.importer'",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"LiForm",
"\\",
"RequestPublic",
"(",
")",
")... | Example of how to request the user's public data.
First step is same as above, except that this form has a text field to input another user's public profile url | [
"Example",
"of",
"how",
"to",
"request",
"the",
"user",
"s",
"public",
"data",
".",
"First",
"step",
"is",
"same",
"as",
"above",
"except",
"that",
"this",
"form",
"has",
"a",
"text",
"field",
"to",
"input",
"another",
"user",
"s",
"public",
"profile",
... | bf510a675311c181995b17744e1420fc4fbb2e60 | https://github.com/tamago-db/LinkedinImporterBundle/blob/bf510a675311c181995b17744e1420fc4fbb2e60/Controller/DefaultController.php#L76-L96 | train |
cmsgears/module-core | common/controllers/base/Controller.php | Controller.checkHome | protected function checkHome() {
// Send user to home if already logged in
if ( !Yii::$app->user->isGuest ) {
$user = Yii::$app->user->getIdentity();
$role = $user->role;
$storedLink = Url::previous( CoreGlobal::REDIRECT_LOGIN );
$siteId = Yii::$app->core->getSiteId();
$siteMember = Yii::$app->factory->get( 'siteMemberService' )->getBySiteIdUserId( $siteId, $user->id );
// Auto-Register site member
if( !isset( $siteMember ) ) {
Yii::$app->factory->get( 'siteMemberService' )->create( $user );
}
// Redirect user to stored link on login
if( isset( $storedLink ) ) {
Yii::$app->response->redirect( $storedLink )->send();
}
// Redirect user having role to home
else if( isset( $role ) ) {
// Switch according to app id
$appAdmin = Yii::$app->core->getAppAdmin();
$appFrontend = Yii::$app->core->getAppFrontend();
// User is on admin app
if( Yii::$app->id === $appAdmin && isset( $role->adminUrl ) ) {
Yii::$app->response->redirect( [ "/$role->adminUrl" ] )->send();
}
// User is on frontend app
else if( Yii::$app->id === $appFrontend && isset( $role->homeUrl ) ) {
Yii::$app->response->redirect( [ "/$role->homeUrl" ] )->send();
}
// Redirect user to home set by app config
else {
Yii::$app->response->redirect( [ Yii::$app->core->getLoginRedirectPage() ] )->send();
}
}
// Redirect user to home set by app config
else {
Yii::$app->response->redirect( [ Yii::$app->core->getLoginRedirectPage() ] )->send();
}
}
} | php | protected function checkHome() {
// Send user to home if already logged in
if ( !Yii::$app->user->isGuest ) {
$user = Yii::$app->user->getIdentity();
$role = $user->role;
$storedLink = Url::previous( CoreGlobal::REDIRECT_LOGIN );
$siteId = Yii::$app->core->getSiteId();
$siteMember = Yii::$app->factory->get( 'siteMemberService' )->getBySiteIdUserId( $siteId, $user->id );
// Auto-Register site member
if( !isset( $siteMember ) ) {
Yii::$app->factory->get( 'siteMemberService' )->create( $user );
}
// Redirect user to stored link on login
if( isset( $storedLink ) ) {
Yii::$app->response->redirect( $storedLink )->send();
}
// Redirect user having role to home
else if( isset( $role ) ) {
// Switch according to app id
$appAdmin = Yii::$app->core->getAppAdmin();
$appFrontend = Yii::$app->core->getAppFrontend();
// User is on admin app
if( Yii::$app->id === $appAdmin && isset( $role->adminUrl ) ) {
Yii::$app->response->redirect( [ "/$role->adminUrl" ] )->send();
}
// User is on frontend app
else if( Yii::$app->id === $appFrontend && isset( $role->homeUrl ) ) {
Yii::$app->response->redirect( [ "/$role->homeUrl" ] )->send();
}
// Redirect user to home set by app config
else {
Yii::$app->response->redirect( [ Yii::$app->core->getLoginRedirectPage() ] )->send();
}
}
// Redirect user to home set by app config
else {
Yii::$app->response->redirect( [ Yii::$app->core->getLoginRedirectPage() ] )->send();
}
}
} | [
"protected",
"function",
"checkHome",
"(",
")",
"{",
"// Send user to home if already logged in",
"if",
"(",
"!",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"user",
"=",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"getIdentity"... | The method check whether user is logged in and send to respective home page. | [
"The",
"method",
"check",
"whether",
"user",
"is",
"logged",
"in",
"and",
"send",
"to",
"respective",
"home",
"page",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/controllers/base/Controller.php#L212-L265 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/MultiObjectProperty.php | MultiObjectProperty.createJoinTable | public function createJoinTable()
{
if ($this->joinTableExists() === true) {
return;
}
$q = 'CREATE TABLE \''.$this->joinTable().'\' (
target_type VARCHAR(255),
target_id VARCHAR(255),
target_property VARCHAR(255),
attachment_type VARCHAR(255),
attachment_id VARCHAR(255),
created DATETIME
)';
$this->logger->debug($q);
$this->source()->db()->query($q);
} | php | public function createJoinTable()
{
if ($this->joinTableExists() === true) {
return;
}
$q = 'CREATE TABLE \''.$this->joinTable().'\' (
target_type VARCHAR(255),
target_id VARCHAR(255),
target_property VARCHAR(255),
attachment_type VARCHAR(255),
attachment_id VARCHAR(255),
created DATETIME
)';
$this->logger->debug($q);
$this->source()->db()->query($q);
} | [
"public",
"function",
"createJoinTable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"joinTableExists",
"(",
")",
"===",
"true",
")",
"{",
"return",
";",
"}",
"$",
"q",
"=",
"'CREATE TABLE \\''",
".",
"$",
"this",
"->",
"joinTable",
"(",
")",
".",
"... | Create the join table on the database source, if it does not exist.
@return void | [
"Create",
"the",
"join",
"table",
"on",
"the",
"database",
"source",
"if",
"it",
"does",
"not",
"exist",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/MultiObjectProperty.php#L94-L110 | train |
nails/module-form-builder | src/Service/DefaultValue.php | DefaultValue.getAllFlat | public function getAllFlat()
{
$aAvailable = $this->getAll();
$aOut = [];
foreach ($aAvailable as $oDefault) {
$aOut[$oDefault->slug] = $oDefault->label;
}
return $aOut;
} | php | public function getAllFlat()
{
$aAvailable = $this->getAll();
$aOut = [];
foreach ($aAvailable as $oDefault) {
$aOut[$oDefault->slug] = $oDefault->label;
}
return $aOut;
} | [
"public",
"function",
"getAllFlat",
"(",
")",
"{",
"$",
"aAvailable",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aAvailable",
"as",
"$",
"oDefault",
")",
"{",
"$",
"aOut",
"[",
"$",
"oD... | Returns the various default values which a field can have as a flat array
@return array | [
"Returns",
"the",
"various",
"default",
"values",
"which",
"a",
"field",
"can",
"have",
"as",
"a",
"flat",
"array"
] | a961a8791a75d01884f46f8e2b492d1cca07fb5b | https://github.com/nails/module-form-builder/blob/a961a8791a75d01884f46f8e2b492d1cca07fb5b/src/Service/DefaultValue.php#L108-L118 | train |
nails/module-form-builder | src/Service/DefaultValue.php | DefaultValue.getBySlug | public function getBySlug($sSlug)
{
$aAvailable = $this->getAll();
foreach ($aAvailable as $oDefault) {
if ($oDefault->slug == $sSlug) {
if (!isset($oDefault->instance)) {
$oDefault->instance = Factory::factory(
$oDefault->component,
$oDefault->provider
);
}
return $oDefault->instance;
}
}
return null;
} | php | public function getBySlug($sSlug)
{
$aAvailable = $this->getAll();
foreach ($aAvailable as $oDefault) {
if ($oDefault->slug == $sSlug) {
if (!isset($oDefault->instance)) {
$oDefault->instance = Factory::factory(
$oDefault->component,
$oDefault->provider
);
}
return $oDefault->instance;
}
}
return null;
} | [
"public",
"function",
"getBySlug",
"(",
"$",
"sSlug",
")",
"{",
"$",
"aAvailable",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"foreach",
"(",
"$",
"aAvailable",
"as",
"$",
"oDefault",
")",
"{",
"if",
"(",
"$",
"oDefault",
"->",
"slug",
"==",
... | Get an individual default value instance by it's slug
@param string $sSlug The Default Value's slug
@return object | [
"Get",
"an",
"individual",
"default",
"value",
"instance",
"by",
"it",
"s",
"slug"
] | a961a8791a75d01884f46f8e2b492d1cca07fb5b | https://github.com/nails/module-form-builder/blob/a961a8791a75d01884f46f8e2b492d1cca07fb5b/src/Service/DefaultValue.php#L129-L149 | train |
nails/module-email | admin/controllers/Utilities.php | Utilities.index | public function index()
{
if (!userHasPermission('admin:email:utilities:sendTest')) {
unauthorised();
}
// --------------------------------------------------------------------------
// Page Title
$this->data['page']->title = 'Send a Test Email';
// --------------------------------------------------------------------------
$oInput = Factory::service('Input');
if ($oInput->post()) {
// Form validation and update
$oFormValidation = Factory::service('FormValidation');
// Define rules
$oFormValidation->set_rules('recipient', '', 'required|valid_email');
// Set Messages
$oFormValidation->set_message('required', lang('fv_required'));
$oFormValidation->set_message('valid_email', lang('fv_valid_email'));
// Execute
if ($oFormValidation->run()) {
// Prepare data
$oNow = Factory::factory('DateTime');
$oEmail = (object) [
'type' => 'test_email',
'to_email' => $oInput->post('recipient', true),
'data' => [
'sentAt' => $oNow->format('Y-m-d H:i:s'),
],
];
// Send the email
$oEmailer = Factory::service('Emailer', 'nails/module-email');
if ($oEmailer->send($oEmail)) {
$this->data['success'] = '<strong>Done!</strong> Test email successfully sent to <strong>';
$this->data['success'] .= $oEmail->to_email . '</strong> at ' . toUserDatetime();
} else {
echo '<h1>Sending Failed, debugging data below:</h1>';
echo $oEmailer->print_debugger();
return;
}
}
}
// --------------------------------------------------------------------------
// Load views
Helper::loadView('index');
} | php | public function index()
{
if (!userHasPermission('admin:email:utilities:sendTest')) {
unauthorised();
}
// --------------------------------------------------------------------------
// Page Title
$this->data['page']->title = 'Send a Test Email';
// --------------------------------------------------------------------------
$oInput = Factory::service('Input');
if ($oInput->post()) {
// Form validation and update
$oFormValidation = Factory::service('FormValidation');
// Define rules
$oFormValidation->set_rules('recipient', '', 'required|valid_email');
// Set Messages
$oFormValidation->set_message('required', lang('fv_required'));
$oFormValidation->set_message('valid_email', lang('fv_valid_email'));
// Execute
if ($oFormValidation->run()) {
// Prepare data
$oNow = Factory::factory('DateTime');
$oEmail = (object) [
'type' => 'test_email',
'to_email' => $oInput->post('recipient', true),
'data' => [
'sentAt' => $oNow->format('Y-m-d H:i:s'),
],
];
// Send the email
$oEmailer = Factory::service('Emailer', 'nails/module-email');
if ($oEmailer->send($oEmail)) {
$this->data['success'] = '<strong>Done!</strong> Test email successfully sent to <strong>';
$this->data['success'] .= $oEmail->to_email . '</strong> at ' . toUserDatetime();
} else {
echo '<h1>Sending Failed, debugging data below:</h1>';
echo $oEmailer->print_debugger();
return;
}
}
}
// --------------------------------------------------------------------------
// Load views
Helper::loadView('index');
} | [
"public",
"function",
"index",
"(",
")",
"{",
"if",
"(",
"!",
"userHasPermission",
"(",
"'admin:email:utilities:sendTest'",
")",
")",
"{",
"unauthorised",
"(",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"// Page Title",
... | Send a test email
@return void | [
"Send",
"a",
"test",
"email"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/admin/controllers/Utilities.php#L59-L118 | train |
mcaskill/charcoal-support | src/Cms/LocaleAwareTrait.php | LocaleAwareTrait.setLocales | protected function setLocales(array $locales)
{
$this->locales = [];
foreach ($locales as $langCode => $localeStruct) {
$this->locales[$langCode] = $this->parseLocale($localeStruct, $langCode);
}
return $this;
} | php | protected function setLocales(array $locales)
{
$this->locales = [];
foreach ($locales as $langCode => $localeStruct) {
$this->locales[$langCode] = $this->parseLocale($localeStruct, $langCode);
}
return $this;
} | [
"protected",
"function",
"setLocales",
"(",
"array",
"$",
"locales",
")",
"{",
"$",
"this",
"->",
"locales",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"langCode",
"=>",
"$",
"localeStruct",
")",
"{",
"$",
"this",
"->",
"locales",
... | Set the available locales.
@param array $locales The list of language structures.
@return self | [
"Set",
"the",
"available",
"locales",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/LocaleAwareTrait.php#L53-L61 | train |
mcaskill/charcoal-support | src/Cms/LocaleAwareTrait.php | LocaleAwareTrait.parseLocale | private function parseLocale(array $localeStruct, $langCode)
{
$trans = 'locale.' . $langCode;
/** Setup the name of the language in the current locale */
if (isset($localeStruct['name'])) {
$name = $this->translator()->translate($localeStruct['name']);
} else {
$name = $this->translator()->translate($trans);
if ($trans === $name) {
$name = strtoupper($langCode);
}
}
/** Setup the native name of the language */
if (isset($localeStruct['native'])) {
$native = $this->translator()->translate($localeStruct['native'], [], null, $langCode);
} else {
$native = $this->translator()->translate($trans, [], null, $langCode);
if ($trans === $native) {
$native = strtoupper($langCode);
}
}
if (!isset($localeStruct['locale'])) {
$localeStruct['locale'] = $langCode;
}
$localeStruct['name'] = $name;
$localeStruct['native'] = $native;
$localeStruct['code'] = $langCode;
return $localeStruct;
} | php | private function parseLocale(array $localeStruct, $langCode)
{
$trans = 'locale.' . $langCode;
/** Setup the name of the language in the current locale */
if (isset($localeStruct['name'])) {
$name = $this->translator()->translate($localeStruct['name']);
} else {
$name = $this->translator()->translate($trans);
if ($trans === $name) {
$name = strtoupper($langCode);
}
}
/** Setup the native name of the language */
if (isset($localeStruct['native'])) {
$native = $this->translator()->translate($localeStruct['native'], [], null, $langCode);
} else {
$native = $this->translator()->translate($trans, [], null, $langCode);
if ($trans === $native) {
$native = strtoupper($langCode);
}
}
if (!isset($localeStruct['locale'])) {
$localeStruct['locale'] = $langCode;
}
$localeStruct['name'] = $name;
$localeStruct['native'] = $native;
$localeStruct['code'] = $langCode;
return $localeStruct;
} | [
"private",
"function",
"parseLocale",
"(",
"array",
"$",
"localeStruct",
",",
"$",
"langCode",
")",
"{",
"$",
"trans",
"=",
"'locale.'",
".",
"$",
"langCode",
";",
"/** Setup the name of the language in the current locale */",
"if",
"(",
"isset",
"(",
"$",
"locale... | Parse the given locale.
@see \Charcoal\Admin\Widget\FormSidebarWidget::languages()
@see \Charcoal\Admin\Widget\FormGroupWidget::languages()
@param array $localeStruct The language structure.
@param string $langCode The language code.
@throws InvalidArgumentException If the locale does not have a language code.
@return array | [
"Parse",
"the",
"given",
"locale",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/LocaleAwareTrait.php#L73-L106 | train |
mcaskill/charcoal-support | src/Cms/LocaleAwareTrait.php | LocaleAwareTrait.buildAlternateTranslations | protected function buildAlternateTranslations()
{
$translations = [];
$context = $this->contextObject();
$origLang = $this->currentLanguage();
$this->translator()->isIteratingLocales = true;
foreach ($this->locales() as $langCode => $localeStruct) {
if ($langCode === $origLang) {
continue;
}
$this->translator()->setLocale($langCode);
$translations[$langCode] = $this->formatAlternateTranslation($context, $localeStruct);
}
$this->translator()->setLocale($origLang);
unset($this->translator()->isIteratingLocales);
return $translations;
} | php | protected function buildAlternateTranslations()
{
$translations = [];
$context = $this->contextObject();
$origLang = $this->currentLanguage();
$this->translator()->isIteratingLocales = true;
foreach ($this->locales() as $langCode => $localeStruct) {
if ($langCode === $origLang) {
continue;
}
$this->translator()->setLocale($langCode);
$translations[$langCode] = $this->formatAlternateTranslation($context, $localeStruct);
}
$this->translator()->setLocale($origLang);
unset($this->translator()->isIteratingLocales);
return $translations;
} | [
"protected",
"function",
"buildAlternateTranslations",
"(",
")",
"{",
"$",
"translations",
"=",
"[",
"]",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"contextObject",
"(",
")",
";",
"$",
"origLang",
"=",
"$",
"this",
"->",
"currentLanguage",
"(",
")",
"... | Build the alternate translations associated with the current route.
This method _excludes_ the current route's canonical URI.
@return array | [
"Build",
"the",
"alternate",
"translations",
"associated",
"with",
"the",
"current",
"route",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/LocaleAwareTrait.php#L125-L147 | train |
mcaskill/charcoal-support | src/Cms/LocaleAwareTrait.php | LocaleAwareTrait.getAlternateTranslations | protected function getAlternateTranslations()
{
if ($this->alternateTranslations === null) {
$this->alternateTranslations = $this->buildAlternateTranslations();
}
return $this->alternateTranslations;
} | php | protected function getAlternateTranslations()
{
if ($this->alternateTranslations === null) {
$this->alternateTranslations = $this->buildAlternateTranslations();
}
return $this->alternateTranslations;
} | [
"protected",
"function",
"getAlternateTranslations",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"alternateTranslations",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"alternateTranslations",
"=",
"$",
"this",
"->",
"buildAlternateTranslations",
"(",
")",
";",
... | Retrieve the alternate translations associated with the current route.
This method _excludes_ the current route's canonical URI.
@return array | [
"Retrieve",
"the",
"alternate",
"translations",
"associated",
"with",
"the",
"current",
"route",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/LocaleAwareTrait.php#L156-L163 | train |
mcaskill/charcoal-support | src/Cms/LocaleAwareTrait.php | LocaleAwareTrait.formatAlternateTranslation | protected function formatAlternateTranslation($context, array $localeStruct)
{
return [
'id' => ($context['id']) ? : $this->templateName(),
'title' => ((string)$context['title']) ? : $this->title(),
'url' => $this->formatAlternateTranslationUrl($context, $localeStruct),
'hreflang' => $localeStruct['code'],
'locale' => $localeStruct['locale'],
'name' => $localeStruct['name'],
'native' => $localeStruct['native'],
];
} | php | protected function formatAlternateTranslation($context, array $localeStruct)
{
return [
'id' => ($context['id']) ? : $this->templateName(),
'title' => ((string)$context['title']) ? : $this->title(),
'url' => $this->formatAlternateTranslationUrl($context, $localeStruct),
'hreflang' => $localeStruct['code'],
'locale' => $localeStruct['locale'],
'name' => $localeStruct['name'],
'native' => $localeStruct['native'],
];
} | [
"protected",
"function",
"formatAlternateTranslation",
"(",
"$",
"context",
",",
"array",
"$",
"localeStruct",
")",
"{",
"return",
"[",
"'id'",
"=>",
"(",
"$",
"context",
"[",
"'id'",
"]",
")",
"?",
":",
"$",
"this",
"->",
"templateName",
"(",
")",
",",
... | Format an alternate translation for the given translatable model.
Note: The application's locale is already modified and will be reset
after processing all available languages.
@param mixed $context The translated {@see \Charcoal\Model\ModelInterface model}
or array-accessible structure.
@param array $localeStruct The currently iterated language.
@return array Returns a link structure. | [
"Format",
"an",
"alternate",
"translation",
"for",
"the",
"given",
"translatable",
"model",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/LocaleAwareTrait.php#L176-L187 | train |
mcaskill/charcoal-support | src/Cms/LocaleAwareTrait.php | LocaleAwareTrait.formatAlternateTranslationUrl | protected function formatAlternateTranslationUrl($context, array $localeStruct)
{
$isRoutable = ($context instanceof RoutableInterface && $context->isActiveRoute());
$langCode = $localeStruct['code'];
$path = ($isRoutable ? $context->url($langCode) : ($this->currentUrl() ? : $langCode));
if ($path instanceof UriInterface) {
$path = $path->getPath();
}
return $this->baseUrl()->withPath($path);
} | php | protected function formatAlternateTranslationUrl($context, array $localeStruct)
{
$isRoutable = ($context instanceof RoutableInterface && $context->isActiveRoute());
$langCode = $localeStruct['code'];
$path = ($isRoutable ? $context->url($langCode) : ($this->currentUrl() ? : $langCode));
if ($path instanceof UriInterface) {
$path = $path->getPath();
}
return $this->baseUrl()->withPath($path);
} | [
"protected",
"function",
"formatAlternateTranslationUrl",
"(",
"$",
"context",
",",
"array",
"$",
"localeStruct",
")",
"{",
"$",
"isRoutable",
"=",
"(",
"$",
"context",
"instanceof",
"RoutableInterface",
"&&",
"$",
"context",
"->",
"isActiveRoute",
"(",
")",
")"... | Format an alternate translation URL for the given translatable model.
Note: The application's locale is already modified and will be reset
after processing all available languages.
@param mixed $context The translated {@see \Charcoal\Model\ModelInterface model}
or array-accessible structure.
@param array $localeStruct The currently iterated language.
@return string Returns a link. | [
"Format",
"an",
"alternate",
"translation",
"URL",
"for",
"the",
"given",
"translatable",
"model",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/LocaleAwareTrait.php#L200-L211 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/AbstractProperty.php | AbstractProperty.l10nIdent | public function l10nIdent($lang = null)
{
if ($this->ident === '') {
throw new RuntimeException('Missing Property Identifier');
}
if (!$this->l10n()) {
throw new LogicException(sprintf(
'Property "%s" is not multilingual',
$this->ident
));
}
if ($lang === null) {
$lang = $this->translator()->getLocale();
} elseif (!is_string($lang)) {
throw new InvalidArgumentException(sprintf(
'Language must be a string for Property "%s"',
$this->ident
));
}
return sprintf('%1$s_%2$s', $this->ident, $lang);
} | php | public function l10nIdent($lang = null)
{
if ($this->ident === '') {
throw new RuntimeException('Missing Property Identifier');
}
if (!$this->l10n()) {
throw new LogicException(sprintf(
'Property "%s" is not multilingual',
$this->ident
));
}
if ($lang === null) {
$lang = $this->translator()->getLocale();
} elseif (!is_string($lang)) {
throw new InvalidArgumentException(sprintf(
'Language must be a string for Property "%s"',
$this->ident
));
}
return sprintf('%1$s_%2$s', $this->ident, $lang);
} | [
"public",
"function",
"l10nIdent",
"(",
"$",
"lang",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ident",
"===",
"''",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Missing Property Identifier'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"thi... | Retrieve the property's localized identifier.
@param string|null $lang The language code to return the identifier with.
@throws LogicException If the property is not multilingual.
@throws RuntimeException If the property has no identifier.
@throws InvalidArgumentException If the language code is invalid.
@return string | [
"Retrieve",
"the",
"property",
"s",
"localized",
"identifier",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/AbstractProperty.php#L256-L279 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/AbstractProperty.php | AbstractProperty.setMultiple | public function setMultiple($multiple)
{
if (!is_bool($multiple)) {
if (is_array($multiple)) {
$this->setMultipleOptions($multiple);
} elseif (is_int($multiple)) {
$this->setMultipleOptions([
'min' => $multiple,
'max' => $multiple
]);
}
}
$this->multiple = !!$multiple;
return $this;
} | php | public function setMultiple($multiple)
{
if (!is_bool($multiple)) {
if (is_array($multiple)) {
$this->setMultipleOptions($multiple);
} elseif (is_int($multiple)) {
$this->setMultipleOptions([
'min' => $multiple,
'max' => $multiple
]);
}
}
$this->multiple = !!$multiple;
return $this;
} | [
"public",
"function",
"setMultiple",
"(",
"$",
"multiple",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"multiple",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"multiple",
")",
")",
"{",
"$",
"this",
"->",
"setMultipleOptions",
"(",
"$",
"multi... | Set whether this property accepts multiple values or a single value.
@param boolean $multiple The multiple flag.
@return self | [
"Set",
"whether",
"this",
"property",
"accepts",
"multiple",
"values",
"or",
"a",
"single",
"value",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/AbstractProperty.php#L533-L549 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/AbstractProperty.php | AbstractProperty.multipleOptions | public function multipleOptions($key = null)
{
if ($this->multipleOptions === null) {
$this->multipleOptions = $this->defaultMultipleOptions();
}
if (is_string($key)) {
if (isset($this->multipleOptions[$key])) {
return $this->multipleOptions[$key];
} else {
return null;
}
}
return $this->multipleOptions;
} | php | public function multipleOptions($key = null)
{
if ($this->multipleOptions === null) {
$this->multipleOptions = $this->defaultMultipleOptions();
}
if (is_string($key)) {
if (isset($this->multipleOptions[$key])) {
return $this->multipleOptions[$key];
} else {
return null;
}
}
return $this->multipleOptions;
} | [
"public",
"function",
"multipleOptions",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"multipleOptions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"multipleOptions",
"=",
"$",
"this",
"->",
"defaultMultipleOptions",
"(",
")",
"... | The options defining the property behavior when the multiple flag is set to true.
@see self::defaultMultipleOptions
@param string|null $key Optional setting to retrieve from the options.
@return array|mixed|null | [
"The",
"options",
"defining",
"the",
"property",
"behavior",
"when",
"the",
"multiple",
"flag",
"is",
"set",
"to",
"true",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/AbstractProperty.php#L594-L609 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/AbstractProperty.php | AbstractProperty.viewOptions | final public function viewOptions($ident = null)
{
// No options defined
if (!$this->viewOptions) {
return [];
}
// No ident defined
if (!$ident) {
return $this->viewOptions;
}
// Invalid ident
if (!isset($this->viewOptions[$ident])) {
return [];
}
// Success!
return $this->viewOptions[$ident];
} | php | final public function viewOptions($ident = null)
{
// No options defined
if (!$this->viewOptions) {
return [];
}
// No ident defined
if (!$ident) {
return $this->viewOptions;
}
// Invalid ident
if (!isset($this->viewOptions[$ident])) {
return [];
}
// Success!
return $this->viewOptions[$ident];
} | [
"final",
"public",
"function",
"viewOptions",
"(",
"$",
"ident",
"=",
"null",
")",
"{",
"// No options defined",
"if",
"(",
"!",
"$",
"this",
"->",
"viewOptions",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// No ident defined",
"if",
"(",
"!",
"$",
"ident"... | View options.
@param string $ident The display ident (ex: charcoal/admin/property/display/text).
@return array Should ALWAYS be an array. | [
"View",
"options",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/AbstractProperty.php#L896-L915 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/AbstractProperty.php | AbstractProperty.l10nVal | protected function l10nVal($val, $lang = null)
{
if (!is_string($lang)) {
if (is_array($lang) && isset($lang['lang'])) {
$lang = $lang['lang'];
} else {
$lang = $this->translator()->getLocale();
}
}
if (isset($val[$lang])) {
return $val[$lang];
} else {
return null;
}
} | php | protected function l10nVal($val, $lang = null)
{
if (!is_string($lang)) {
if (is_array($lang) && isset($lang['lang'])) {
$lang = $lang['lang'];
} else {
$lang = $this->translator()->getLocale();
}
}
if (isset($val[$lang])) {
return $val[$lang];
} else {
return null;
}
} | [
"protected",
"function",
"l10nVal",
"(",
"$",
"val",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"lang",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"lang",
")",
"&&",
"isset",
"(",
"$",
"lang",
"[",
"'la... | Attempt to get the multilingual value in the requested language.
@param mixed $val The multilingual value to lookup.
@param mixed $lang The language to return the value in.
@return string|null | [
"Attempt",
"to",
"get",
"the",
"multilingual",
"value",
"in",
"the",
"requested",
"language",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/AbstractProperty.php#L947-L962 | train |
dotsunited/BundleFu | src/DotsUnited/BundleFu/Filter/FilterChain.php | FilterChain.addFilter | public function addFilter(FilterInterface $filter, $placement = self::CHAIN_APPEND)
{
if ($placement == self::CHAIN_PREPEND) {
array_unshift($this->filters, $filter);
} else {
$this->filters[] = $filter;
}
return $this;
} | php | public function addFilter(FilterInterface $filter, $placement = self::CHAIN_APPEND)
{
if ($placement == self::CHAIN_PREPEND) {
array_unshift($this->filters, $filter);
} else {
$this->filters[] = $filter;
}
return $this;
} | [
"public",
"function",
"addFilter",
"(",
"FilterInterface",
"$",
"filter",
",",
"$",
"placement",
"=",
"self",
"::",
"CHAIN_APPEND",
")",
"{",
"if",
"(",
"$",
"placement",
"==",
"self",
"::",
"CHAIN_PREPEND",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->... | Adds a filter to the chain
@param FilterInterface $filter
@param string $placement
@return FilterChain | [
"Adds",
"a",
"filter",
"to",
"the",
"chain"
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Filter/FilterChain.php#L39-L48 | train |
dotsunited/BundleFu | src/DotsUnited/BundleFu/Filter/CssUrlRewriteFilter.php | CssUrlRewriteFilter.rewriteUrl | protected function rewriteUrl($matches)
{
$matchedUrl = trim($matches['url']);
// First check also matches protocol-relative urls like //example.com/images/bg.gif
if ('/' === $matchedUrl[0] || false !== strpos($matchedUrl, '://') || 0 === strpos($matchedUrl, 'data:')) {
return $matches[0];
}
$sourceUrl = dirname($this->file);
if ('.' === $sourceUrl) {
$sourceUrl = '/';
}
$path = $this->bundleUrl;
if (false !== strpos($path, '://') || 0 === strpos($path, '//')) {
// parse_url() does not work with protocol-relative urls
list(, $url) = explode('//', $path, 2);
list(, $path) = explode('/', $url, 2);
}
$bundleUrl = dirname($path);
if ('.' === $bundleUrl) {
$bundleUrl = '/';
}
$url = $this->rewriteRelative($matchedUrl, $sourceUrl, $bundleUrl);
return str_replace($matchedUrl, $url, $matches[0]);
} | php | protected function rewriteUrl($matches)
{
$matchedUrl = trim($matches['url']);
// First check also matches protocol-relative urls like //example.com/images/bg.gif
if ('/' === $matchedUrl[0] || false !== strpos($matchedUrl, '://') || 0 === strpos($matchedUrl, 'data:')) {
return $matches[0];
}
$sourceUrl = dirname($this->file);
if ('.' === $sourceUrl) {
$sourceUrl = '/';
}
$path = $this->bundleUrl;
if (false !== strpos($path, '://') || 0 === strpos($path, '//')) {
// parse_url() does not work with protocol-relative urls
list(, $url) = explode('//', $path, 2);
list(, $path) = explode('/', $url, 2);
}
$bundleUrl = dirname($path);
if ('.' === $bundleUrl) {
$bundleUrl = '/';
}
$url = $this->rewriteRelative($matchedUrl, $sourceUrl, $bundleUrl);
return str_replace($matchedUrl, $url, $matches[0]);
} | [
"protected",
"function",
"rewriteUrl",
"(",
"$",
"matches",
")",
"{",
"$",
"matchedUrl",
"=",
"trim",
"(",
"$",
"matches",
"[",
"'url'",
"]",
")",
";",
"// First check also matches protocol-relative urls like //example.com/images/bg.gif",
"if",
"(",
"'/'",
"===",
"$... | Callback which rewrites matched CSS ruls.
@param array $matches
@return string | [
"Callback",
"which",
"rewrites",
"matched",
"CSS",
"ruls",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Filter/CssUrlRewriteFilter.php#L55-L87 | train |
dotsunited/BundleFu | src/DotsUnited/BundleFu/Filter/CssUrlRewriteFilter.php | CssUrlRewriteFilter.rewriteRelative | protected function rewriteRelative($url, $sourceUrl, $bundleUrl)
{
$sourceUrl = trim($sourceUrl, '/');
$bundleUrl = trim($bundleUrl, '/');
if ($bundleUrl === $sourceUrl) {
return $url;
}
if ('' === $sourceUrl) {
return str_repeat('../', count(explode('/', $bundleUrl))) . $url;
}
if ('' === $bundleUrl) {
return $this->canonicalize($sourceUrl . '/' . $url);
}
if (0 === strpos($bundleUrl, $sourceUrl)) {
$prepend = $bundleUrl;
$count = 0;
while ($prepend !== $sourceUrl) {
$count++;
$prepend = dirname($prepend);
}
return str_repeat('../', $count) . $url;
} elseif (0 === strpos($sourceUrl, $bundleUrl)) {
$path = $sourceUrl;
while (0 === strpos($url, '../') && $path !== $bundleUrl) {
$path = dirname($path);
$url = substr($url, 3);
}
return $url;
} else {
$prepend = str_repeat('../', count(explode('/', $bundleUrl)));
$path = $sourceUrl . '/' . $url;
return $prepend . $this->canonicalize($path);
}
} | php | protected function rewriteRelative($url, $sourceUrl, $bundleUrl)
{
$sourceUrl = trim($sourceUrl, '/');
$bundleUrl = trim($bundleUrl, '/');
if ($bundleUrl === $sourceUrl) {
return $url;
}
if ('' === $sourceUrl) {
return str_repeat('../', count(explode('/', $bundleUrl))) . $url;
}
if ('' === $bundleUrl) {
return $this->canonicalize($sourceUrl . '/' . $url);
}
if (0 === strpos($bundleUrl, $sourceUrl)) {
$prepend = $bundleUrl;
$count = 0;
while ($prepend !== $sourceUrl) {
$count++;
$prepend = dirname($prepend);
}
return str_repeat('../', $count) . $url;
} elseif (0 === strpos($sourceUrl, $bundleUrl)) {
$path = $sourceUrl;
while (0 === strpos($url, '../') && $path !== $bundleUrl) {
$path = dirname($path);
$url = substr($url, 3);
}
return $url;
} else {
$prepend = str_repeat('../', count(explode('/', $bundleUrl)));
$path = $sourceUrl . '/' . $url;
return $prepend . $this->canonicalize($path);
}
} | [
"protected",
"function",
"rewriteRelative",
"(",
"$",
"url",
",",
"$",
"sourceUrl",
",",
"$",
"bundleUrl",
")",
"{",
"$",
"sourceUrl",
"=",
"trim",
"(",
"$",
"sourceUrl",
",",
"'/'",
")",
";",
"$",
"bundleUrl",
"=",
"trim",
"(",
"$",
"bundleUrl",
",",
... | Rewrites to a relative url.
@param string $url
@param string $sourceUrl
@param string $bundleUrl
@return string | [
"Rewrites",
"to",
"a",
"relative",
"url",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Filter/CssUrlRewriteFilter.php#L97-L138 | train |
dotsunited/BundleFu | src/DotsUnited/BundleFu/Filter/CssUrlRewriteFilter.php | CssUrlRewriteFilter.canonicalize | protected function canonicalize($path)
{
$parts = array_filter(explode('/', $path));
$canonicalized = array();
foreach ($parts as $part) {
if ('.' == $part) {
continue;
}
if ('..' == $part) {
array_pop($canonicalized);
} else {
$canonicalized[] = $part;
}
}
return implode('/', $canonicalized);
} | php | protected function canonicalize($path)
{
$parts = array_filter(explode('/', $path));
$canonicalized = array();
foreach ($parts as $part) {
if ('.' == $part) {
continue;
}
if ('..' == $part) {
array_pop($canonicalized);
} else {
$canonicalized[] = $part;
}
}
return implode('/', $canonicalized);
} | [
"protected",
"function",
"canonicalize",
"(",
"$",
"path",
")",
"{",
"$",
"parts",
"=",
"array_filter",
"(",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
")",
";",
"$",
"canonicalized",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parts",
"as"... | Canonicalizes a path.
@param string $path
@return string | [
"Canonicalizes",
"a",
"path",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Filter/CssUrlRewriteFilter.php#L146-L164 | train |
dotsunited/BundleFu | src/DotsUnited/BundleFu/Factory.php | Factory.setFilter | public function setFilter($name, FilterInterface $filter = null)
{
$this->filters[$name] = $filter;
return $this;
} | php | public function setFilter($name, FilterInterface $filter = null)
{
$this->filters[$name] = $filter;
return $this;
} | [
"public",
"function",
"setFilter",
"(",
"$",
"name",
",",
"FilterInterface",
"$",
"filter",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"filters",
"[",
"$",
"name",
"]",
"=",
"$",
"filter",
";",
"return",
"$",
"this",
";",
"}"
] | Set a filter.
@param string $name
@param \DotsUnited\BundleFu\Filter\FilterInterface $filter
@return \DotsUnited\BundleFu\Factory | [
"Set",
"a",
"filter",
"."
] | d219bef65b5ca1dd6f542c816a1bad88383b924a | https://github.com/dotsunited/BundleFu/blob/d219bef65b5ca1dd6f542c816a1bad88383b924a/src/DotsUnited/BundleFu/Factory.php#L76-L81 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.