repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
Sedona-Solutions/sedona-sbo | src/Sedona/SBOGeneratorBundle/Generator/DoctrineCrudGenerator.php | DoctrineCrudGenerator.generateControllerClass | protected function generateControllerClass($forceOverwrite)
{
$dir = $this->bundle->getPath();
$parts = explode('\\', $this->entity);
$entityClass = array_pop($parts);
$entityNamespace = implode('\\', $parts);
$target = sprintf(
'%s/Controller/Admin/%s/%sController.php',
$dir,
str_replace('\\', '/', $entityNamespace),
$entityClass
);
if (!$forceOverwrite && file_exists($target)) {
throw new \RuntimeException('Unable to generate the controller as it already exists.');
}
$params = array(
'actions' => $this->actions,
'route_prefix' => $this->routePrefix,
'route_name_prefix' => $this->routeNamePrefix,
'bundle' => $this->bundle->getName(),
'entity' => $this->entity,
'fields' => $this->getFieldsFromMetadata($this->metadata),
'entity_class' => $entityClass,
'namespace' => $this->bundle->getNamespace(),
'entity_namespace' => $entityNamespace,
'format' => $this->format,
'dir' => $dir,
);
$this->renderFile('crud/controller.php.twig', $target, $params);
// Generate base generator if not exists
$baseControllerFile = $dir.'/Controller/Admin/BaseCrudController.php';
if (!file_exists($baseControllerFile)) {
$this->renderFile('crud/BaseCrudController.php.twig', $baseControllerFile, $params);
}
// Generate home controller if not exists
$baseControllerFile = $dir.'/Controller/Admin/DefaultController.php';
if (!file_exists($baseControllerFile)) {
$this->renderFile('crud/DefaultController.php.twig', $baseControllerFile, $params);
}
} | php | protected function generateControllerClass($forceOverwrite)
{
$dir = $this->bundle->getPath();
$parts = explode('\\', $this->entity);
$entityClass = array_pop($parts);
$entityNamespace = implode('\\', $parts);
$target = sprintf(
'%s/Controller/Admin/%s/%sController.php',
$dir,
str_replace('\\', '/', $entityNamespace),
$entityClass
);
if (!$forceOverwrite && file_exists($target)) {
throw new \RuntimeException('Unable to generate the controller as it already exists.');
}
$params = array(
'actions' => $this->actions,
'route_prefix' => $this->routePrefix,
'route_name_prefix' => $this->routeNamePrefix,
'bundle' => $this->bundle->getName(),
'entity' => $this->entity,
'fields' => $this->getFieldsFromMetadata($this->metadata),
'entity_class' => $entityClass,
'namespace' => $this->bundle->getNamespace(),
'entity_namespace' => $entityNamespace,
'format' => $this->format,
'dir' => $dir,
);
$this->renderFile('crud/controller.php.twig', $target, $params);
// Generate base generator if not exists
$baseControllerFile = $dir.'/Controller/Admin/BaseCrudController.php';
if (!file_exists($baseControllerFile)) {
$this->renderFile('crud/BaseCrudController.php.twig', $baseControllerFile, $params);
}
// Generate home controller if not exists
$baseControllerFile = $dir.'/Controller/Admin/DefaultController.php';
if (!file_exists($baseControllerFile)) {
$this->renderFile('crud/DefaultController.php.twig', $baseControllerFile, $params);
}
} | [
"protected",
"function",
"generateControllerClass",
"(",
"$",
"forceOverwrite",
")",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"bundle",
"->",
"getPath",
"(",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"this",
"->",
"entity",
")",
";",
"$",
"entityClass",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"entityNamespace",
"=",
"implode",
"(",
"'\\\\'",
",",
"$",
"parts",
")",
";",
"$",
"target",
"=",
"sprintf",
"(",
"'%s/Controller/Admin/%s/%sController.php'",
",",
"$",
"dir",
",",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"entityNamespace",
")",
",",
"$",
"entityClass",
")",
";",
"if",
"(",
"!",
"$",
"forceOverwrite",
"&&",
"file_exists",
"(",
"$",
"target",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to generate the controller as it already exists.'",
")",
";",
"}",
"$",
"params",
"=",
"array",
"(",
"'actions'",
"=>",
"$",
"this",
"->",
"actions",
",",
"'route_prefix'",
"=>",
"$",
"this",
"->",
"routePrefix",
",",
"'route_name_prefix'",
"=>",
"$",
"this",
"->",
"routeNamePrefix",
",",
"'bundle'",
"=>",
"$",
"this",
"->",
"bundle",
"->",
"getName",
"(",
")",
",",
"'entity'",
"=>",
"$",
"this",
"->",
"entity",
",",
"'fields'",
"=>",
"$",
"this",
"->",
"getFieldsFromMetadata",
"(",
"$",
"this",
"->",
"metadata",
")",
",",
"'entity_class'",
"=>",
"$",
"entityClass",
",",
"'namespace'",
"=>",
"$",
"this",
"->",
"bundle",
"->",
"getNamespace",
"(",
")",
",",
"'entity_namespace'",
"=>",
"$",
"entityNamespace",
",",
"'format'",
"=>",
"$",
"this",
"->",
"format",
",",
"'dir'",
"=>",
"$",
"dir",
",",
")",
";",
"$",
"this",
"->",
"renderFile",
"(",
"'crud/controller.php.twig'",
",",
"$",
"target",
",",
"$",
"params",
")",
";",
"// Generate base generator if not exists",
"$",
"baseControllerFile",
"=",
"$",
"dir",
".",
"'/Controller/Admin/BaseCrudController.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"baseControllerFile",
")",
")",
"{",
"$",
"this",
"->",
"renderFile",
"(",
"'crud/BaseCrudController.php.twig'",
",",
"$",
"baseControllerFile",
",",
"$",
"params",
")",
";",
"}",
"// Generate home controller if not exists",
"$",
"baseControllerFile",
"=",
"$",
"dir",
".",
"'/Controller/Admin/DefaultController.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"baseControllerFile",
")",
")",
"{",
"$",
"this",
"->",
"renderFile",
"(",
"'crud/DefaultController.php.twig'",
",",
"$",
"baseControllerFile",
",",
"$",
"params",
")",
";",
"}",
"}"
] | Generates the controller class only. | [
"Generates",
"the",
"controller",
"class",
"only",
"."
] | train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBOGeneratorBundle/Generator/DoctrineCrudGenerator.php#L155-L201 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBOGeneratorBundle/Generator/DoctrineCrudGenerator.php | DoctrineCrudGenerator.generateIndexView | protected function generateIndexView($dir)
{
$this->renderFile('crud/views/index.html.twig.twig', $dir.'/index.html.twig', array(
'bundle' => $this->bundle->getName(),
'entity' => $this->entity,
'entities_name' => strtolower(Inflector::pluralize($this->entity)),
'fields' => $this->metadata->fieldMappings,
'actions' => $this->actions,
'record_actions' => $this->getRecordActions(),
'route_prefix' => $this->routePrefix,
'route_name_prefix' => $this->routeNamePrefix,
'dir' => $dir,
));
} | php | protected function generateIndexView($dir)
{
$this->renderFile('crud/views/index.html.twig.twig', $dir.'/index.html.twig', array(
'bundle' => $this->bundle->getName(),
'entity' => $this->entity,
'entities_name' => strtolower(Inflector::pluralize($this->entity)),
'fields' => $this->metadata->fieldMappings,
'actions' => $this->actions,
'record_actions' => $this->getRecordActions(),
'route_prefix' => $this->routePrefix,
'route_name_prefix' => $this->routeNamePrefix,
'dir' => $dir,
));
} | [
"protected",
"function",
"generateIndexView",
"(",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"renderFile",
"(",
"'crud/views/index.html.twig.twig'",
",",
"$",
"dir",
".",
"'/index.html.twig'",
",",
"array",
"(",
"'bundle'",
"=>",
"$",
"this",
"->",
"bundle",
"->",
"getName",
"(",
")",
",",
"'entity'",
"=>",
"$",
"this",
"->",
"entity",
",",
"'entities_name'",
"=>",
"strtolower",
"(",
"Inflector",
"::",
"pluralize",
"(",
"$",
"this",
"->",
"entity",
")",
")",
",",
"'fields'",
"=>",
"$",
"this",
"->",
"metadata",
"->",
"fieldMappings",
",",
"'actions'",
"=>",
"$",
"this",
"->",
"actions",
",",
"'record_actions'",
"=>",
"$",
"this",
"->",
"getRecordActions",
"(",
")",
",",
"'route_prefix'",
"=>",
"$",
"this",
"->",
"routePrefix",
",",
"'route_name_prefix'",
"=>",
"$",
"this",
"->",
"routeNamePrefix",
",",
"'dir'",
"=>",
"$",
"dir",
",",
")",
")",
";",
"}"
] | Generates the index.html.twig template in the final bundle.
@param string $dir The path to the folder that hosts templates in the bundle | [
"Generates",
"the",
"index",
".",
"html",
".",
"twig",
"template",
"in",
"the",
"final",
"bundle",
"."
] | train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBOGeneratorBundle/Generator/DoctrineCrudGenerator.php#L255-L268 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBOGeneratorBundle/Generator/DoctrineCrudGenerator.php | DoctrineCrudGenerator.generateShowView | protected function generateShowView($dir)
{
$this->renderFile('crud/views/show.html.twig.twig', $dir.'/show.html.twig', array(
'bundle' => $this->bundle->getName(),
'entity' => $this->entity,
'fields' => $this->getFieldsFromMetadata($this->metadata),
'actions' => $this->actions,
'route_prefix' => $this->routePrefix,
'route_name_prefix' => $this->routeNamePrefix,
'dir' => $dir,
));
} | php | protected function generateShowView($dir)
{
$this->renderFile('crud/views/show.html.twig.twig', $dir.'/show.html.twig', array(
'bundle' => $this->bundle->getName(),
'entity' => $this->entity,
'fields' => $this->getFieldsFromMetadata($this->metadata),
'actions' => $this->actions,
'route_prefix' => $this->routePrefix,
'route_name_prefix' => $this->routeNamePrefix,
'dir' => $dir,
));
} | [
"protected",
"function",
"generateShowView",
"(",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"renderFile",
"(",
"'crud/views/show.html.twig.twig'",
",",
"$",
"dir",
".",
"'/show.html.twig'",
",",
"array",
"(",
"'bundle'",
"=>",
"$",
"this",
"->",
"bundle",
"->",
"getName",
"(",
")",
",",
"'entity'",
"=>",
"$",
"this",
"->",
"entity",
",",
"'fields'",
"=>",
"$",
"this",
"->",
"getFieldsFromMetadata",
"(",
"$",
"this",
"->",
"metadata",
")",
",",
"'actions'",
"=>",
"$",
"this",
"->",
"actions",
",",
"'route_prefix'",
"=>",
"$",
"this",
"->",
"routePrefix",
",",
"'route_name_prefix'",
"=>",
"$",
"this",
"->",
"routeNamePrefix",
",",
"'dir'",
"=>",
"$",
"dir",
",",
")",
")",
";",
"}"
] | Generates the show.html.twig template in the final bundle.
@param string $dir The path to the folder that hosts templates in the bundle | [
"Generates",
"the",
"show",
".",
"html",
".",
"twig",
"template",
"in",
"the",
"final",
"bundle",
"."
] | train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBOGeneratorBundle/Generator/DoctrineCrudGenerator.php#L275-L286 |
inc2734/wp-share-buttons | src/App/Shortcode/Twitter.php | Twitter._shortcode | public function _shortcode( $attributes ) {
if ( ! isset( $attributes['post_id'] ) ) {
return;
}
$title = wp_strip_all_tags( get_the_title( $attributes['post_id'] ) . ' - ' . get_bloginfo( 'name' ) );
$attributes = shortcode_atts(
[
'type' => 'balloon',
'title' => apply_filters( 'inc2734_wp_share_buttons_shared_title', $title, 'twitter' ),
'post_id' => '',
'hashtags' => apply_filters( 'inc2734_wp_share_buttons_shared_hashtags', '', 'twitter' ),
],
$attributes
);
if ( 'official' === $attributes['type'] ) {
$file = 'official';
} else {
$file = 'twitter';
}
if ( function_exists( 'scc_get_share_twitter' ) ) {
$has_cache = true;
$expiration = null;
$count = scc_get_share_twitter();
} else {
$count_cache = new Count_Cache( $attributes['post_id'], 'twitter' );
$has_cache = $count_cache->is_enabled();
$expiration = $count_cache->get_cache_expiration();
$cache = $count_cache->get();
$count = ( ! is_null( $cache ) ) ? $cache : '-';
}
return $this->render(
'twitter/' . $file,
[
'type' => $attributes['type'],
'title' => $attributes['title'],
'post_id' => $attributes['post_id'],
'hashtags' => $attributes['hashtags'],
'has_cache' => $has_cache,
'expiration' => $expiration,
'count' => $count,
]
);
} | php | public function _shortcode( $attributes ) {
if ( ! isset( $attributes['post_id'] ) ) {
return;
}
$title = wp_strip_all_tags( get_the_title( $attributes['post_id'] ) . ' - ' . get_bloginfo( 'name' ) );
$attributes = shortcode_atts(
[
'type' => 'balloon',
'title' => apply_filters( 'inc2734_wp_share_buttons_shared_title', $title, 'twitter' ),
'post_id' => '',
'hashtags' => apply_filters( 'inc2734_wp_share_buttons_shared_hashtags', '', 'twitter' ),
],
$attributes
);
if ( 'official' === $attributes['type'] ) {
$file = 'official';
} else {
$file = 'twitter';
}
if ( function_exists( 'scc_get_share_twitter' ) ) {
$has_cache = true;
$expiration = null;
$count = scc_get_share_twitter();
} else {
$count_cache = new Count_Cache( $attributes['post_id'], 'twitter' );
$has_cache = $count_cache->is_enabled();
$expiration = $count_cache->get_cache_expiration();
$cache = $count_cache->get();
$count = ( ! is_null( $cache ) ) ? $cache : '-';
}
return $this->render(
'twitter/' . $file,
[
'type' => $attributes['type'],
'title' => $attributes['title'],
'post_id' => $attributes['post_id'],
'hashtags' => $attributes['hashtags'],
'has_cache' => $has_cache,
'expiration' => $expiration,
'count' => $count,
]
);
} | [
"public",
"function",
"_shortcode",
"(",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"'post_id'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"title",
"=",
"wp_strip_all_tags",
"(",
"get_the_title",
"(",
"$",
"attributes",
"[",
"'post_id'",
"]",
")",
".",
"' - '",
".",
"get_bloginfo",
"(",
"'name'",
")",
")",
";",
"$",
"attributes",
"=",
"shortcode_atts",
"(",
"[",
"'type'",
"=>",
"'balloon'",
",",
"'title'",
"=>",
"apply_filters",
"(",
"'inc2734_wp_share_buttons_shared_title'",
",",
"$",
"title",
",",
"'twitter'",
")",
",",
"'post_id'",
"=>",
"''",
",",
"'hashtags'",
"=>",
"apply_filters",
"(",
"'inc2734_wp_share_buttons_shared_hashtags'",
",",
"''",
",",
"'twitter'",
")",
",",
"]",
",",
"$",
"attributes",
")",
";",
"if",
"(",
"'official'",
"===",
"$",
"attributes",
"[",
"'type'",
"]",
")",
"{",
"$",
"file",
"=",
"'official'",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"'twitter'",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'scc_get_share_twitter'",
")",
")",
"{",
"$",
"has_cache",
"=",
"true",
";",
"$",
"expiration",
"=",
"null",
";",
"$",
"count",
"=",
"scc_get_share_twitter",
"(",
")",
";",
"}",
"else",
"{",
"$",
"count_cache",
"=",
"new",
"Count_Cache",
"(",
"$",
"attributes",
"[",
"'post_id'",
"]",
",",
"'twitter'",
")",
";",
"$",
"has_cache",
"=",
"$",
"count_cache",
"->",
"is_enabled",
"(",
")",
";",
"$",
"expiration",
"=",
"$",
"count_cache",
"->",
"get_cache_expiration",
"(",
")",
";",
"$",
"cache",
"=",
"$",
"count_cache",
"->",
"get",
"(",
")",
";",
"$",
"count",
"=",
"(",
"!",
"is_null",
"(",
"$",
"cache",
")",
")",
"?",
"$",
"cache",
":",
"'-'",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'twitter/'",
".",
"$",
"file",
",",
"[",
"'type'",
"=>",
"$",
"attributes",
"[",
"'type'",
"]",
",",
"'title'",
"=>",
"$",
"attributes",
"[",
"'title'",
"]",
",",
"'post_id'",
"=>",
"$",
"attributes",
"[",
"'post_id'",
"]",
",",
"'hashtags'",
"=>",
"$",
"attributes",
"[",
"'hashtags'",
"]",
",",
"'has_cache'",
"=>",
"$",
"has_cache",
",",
"'expiration'",
"=>",
"$",
"expiration",
",",
"'count'",
"=>",
"$",
"count",
",",
"]",
")",
";",
"}"
] | Register shortcode
@param array $attributes
@return void | [
"Register",
"shortcode"
] | train | https://github.com/inc2734/wp-share-buttons/blob/cd032893ca083a343f5871e855cce68f4ede3a17/src/App/Shortcode/Twitter.php#L24-L71 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Uri/Http.php | Zend_Uri_Http._parseUri | protected function _parseUri($schemeSpecific)
{
// High-level decomposition parser
$pattern = '~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~';
$status = @preg_match($pattern, $schemeSpecific, $matches);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: scheme-specific decomposition failed');
}
// Failed decomposition; no further processing needed
if ($status === false) {
return;
}
// Save URI components that need no further decomposition
$this->_path = isset($matches[4]) === true ? $matches[4] : '';
$this->_query = isset($matches[6]) === true ? $matches[6] : '';
$this->_fragment = isset($matches[8]) === true ? $matches[8] : '';
// Additional decomposition to get username, password, host, and port
$combo = isset($matches[3]) === true ? $matches[3] : '';
$pattern = '~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~';
$status = @preg_match($pattern, $combo, $matches);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: authority decomposition failed');
}
// Failed decomposition; no further processing needed
if ($status === false) {
return;
}
// Save remaining URI components
$this->_username = isset($matches[2]) === true ? $matches[2] : '';
$this->_password = isset($matches[4]) === true ? $matches[4] : '';
$this->_host = isset($matches[5]) === true ? $matches[5] : '';
$this->_port = isset($matches[7]) === true ? $matches[7] : '';
} | php | protected function _parseUri($schemeSpecific)
{
// High-level decomposition parser
$pattern = '~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~';
$status = @preg_match($pattern, $schemeSpecific, $matches);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: scheme-specific decomposition failed');
}
// Failed decomposition; no further processing needed
if ($status === false) {
return;
}
// Save URI components that need no further decomposition
$this->_path = isset($matches[4]) === true ? $matches[4] : '';
$this->_query = isset($matches[6]) === true ? $matches[6] : '';
$this->_fragment = isset($matches[8]) === true ? $matches[8] : '';
// Additional decomposition to get username, password, host, and port
$combo = isset($matches[3]) === true ? $matches[3] : '';
$pattern = '~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~';
$status = @preg_match($pattern, $combo, $matches);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: authority decomposition failed');
}
// Failed decomposition; no further processing needed
if ($status === false) {
return;
}
// Save remaining URI components
$this->_username = isset($matches[2]) === true ? $matches[2] : '';
$this->_password = isset($matches[4]) === true ? $matches[4] : '';
$this->_host = isset($matches[5]) === true ? $matches[5] : '';
$this->_port = isset($matches[7]) === true ? $matches[7] : '';
} | [
"protected",
"function",
"_parseUri",
"(",
"$",
"schemeSpecific",
")",
"{",
"// High-level decomposition parser",
"$",
"pattern",
"=",
"'~^((//)([^/?#]*))([^?#]*)(\\?([^#]*))?(#(.*))?$~'",
";",
"$",
"status",
"=",
"@",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"schemeSpecific",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"status",
"===",
"false",
")",
"{",
"require_once",
"'Zend/Uri/Exception.php'",
";",
"throw",
"new",
"Zend_Uri_Exception",
"(",
"'Internal error: scheme-specific decomposition failed'",
")",
";",
"}",
"// Failed decomposition; no further processing needed",
"if",
"(",
"$",
"status",
"===",
"false",
")",
"{",
"return",
";",
"}",
"// Save URI components that need no further decomposition",
"$",
"this",
"->",
"_path",
"=",
"isset",
"(",
"$",
"matches",
"[",
"4",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"4",
"]",
":",
"''",
";",
"$",
"this",
"->",
"_query",
"=",
"isset",
"(",
"$",
"matches",
"[",
"6",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"6",
"]",
":",
"''",
";",
"$",
"this",
"->",
"_fragment",
"=",
"isset",
"(",
"$",
"matches",
"[",
"8",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"8",
"]",
":",
"''",
";",
"// Additional decomposition to get username, password, host, and port",
"$",
"combo",
"=",
"isset",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"3",
"]",
":",
"''",
";",
"$",
"pattern",
"=",
"'~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~'",
";",
"$",
"status",
"=",
"@",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"combo",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"status",
"===",
"false",
")",
"{",
"require_once",
"'Zend/Uri/Exception.php'",
";",
"throw",
"new",
"Zend_Uri_Exception",
"(",
"'Internal error: authority decomposition failed'",
")",
";",
"}",
"// Failed decomposition; no further processing needed",
"if",
"(",
"$",
"status",
"===",
"false",
")",
"{",
"return",
";",
"}",
"// Save remaining URI components",
"$",
"this",
"->",
"_username",
"=",
"isset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"2",
"]",
":",
"''",
";",
"$",
"this",
"->",
"_password",
"=",
"isset",
"(",
"$",
"matches",
"[",
"4",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"4",
"]",
":",
"''",
";",
"$",
"this",
"->",
"_host",
"=",
"isset",
"(",
"$",
"matches",
"[",
"5",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"5",
"]",
":",
"''",
";",
"$",
"this",
"->",
"_port",
"=",
"isset",
"(",
"$",
"matches",
"[",
"7",
"]",
")",
"===",
"true",
"?",
"$",
"matches",
"[",
"7",
"]",
":",
"''",
";",
"}"
] | Parse the scheme-specific portion of the URI and place its parts into instance variables.
@param string $schemeSpecific The scheme-specific portion to parse
@throws Zend_Uri_Exception When scheme-specific decoposition fails
@throws Zend_Uri_Exception When authority decomposition fails
@return void | [
"Parse",
"the",
"scheme",
"-",
"specific",
"portion",
"of",
"the",
"URI",
"and",
"place",
"its",
"parts",
"into",
"instance",
"variables",
"."
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Uri/Http.php#L198-L238 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Uri/Http.php | Zend_Uri_Http.getUri | public function getUri()
{
if ($this->valid() === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('One or more parts of the URI are invalid');
}
$password = strlen($this->_password) > 0 ? ":$this->_password" : '';
$auth = strlen($this->_username) > 0 ? "$this->_username$password@" : '';
$port = strlen($this->_port) > 0 ? ":$this->_port" : '';
$query = strlen($this->_query) > 0 ? "?$this->_query" : '';
$fragment = strlen($this->_fragment) > 0 ? "#$this->_fragment" : '';
return $this->_scheme
. '://'
. $auth
. $this->_host
. $port
. $this->_path
. $query
. $fragment;
} | php | public function getUri()
{
if ($this->valid() === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('One or more parts of the URI are invalid');
}
$password = strlen($this->_password) > 0 ? ":$this->_password" : '';
$auth = strlen($this->_username) > 0 ? "$this->_username$password@" : '';
$port = strlen($this->_port) > 0 ? ":$this->_port" : '';
$query = strlen($this->_query) > 0 ? "?$this->_query" : '';
$fragment = strlen($this->_fragment) > 0 ? "#$this->_fragment" : '';
return $this->_scheme
. '://'
. $auth
. $this->_host
. $port
. $this->_path
. $query
. $fragment;
} | [
"public",
"function",
"getUri",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"valid",
"(",
")",
"===",
"false",
")",
"{",
"require_once",
"'Zend/Uri/Exception.php'",
";",
"throw",
"new",
"Zend_Uri_Exception",
"(",
"'One or more parts of the URI are invalid'",
")",
";",
"}",
"$",
"password",
"=",
"strlen",
"(",
"$",
"this",
"->",
"_password",
")",
">",
"0",
"?",
"\":$this->_password\"",
":",
"''",
";",
"$",
"auth",
"=",
"strlen",
"(",
"$",
"this",
"->",
"_username",
")",
">",
"0",
"?",
"\"$this->_username$password@\"",
":",
"''",
";",
"$",
"port",
"=",
"strlen",
"(",
"$",
"this",
"->",
"_port",
")",
">",
"0",
"?",
"\":$this->_port\"",
":",
"''",
";",
"$",
"query",
"=",
"strlen",
"(",
"$",
"this",
"->",
"_query",
")",
">",
"0",
"?",
"\"?$this->_query\"",
":",
"''",
";",
"$",
"fragment",
"=",
"strlen",
"(",
"$",
"this",
"->",
"_fragment",
")",
">",
"0",
"?",
"\"#$this->_fragment\"",
":",
"''",
";",
"return",
"$",
"this",
"->",
"_scheme",
".",
"'://'",
".",
"$",
"auth",
".",
"$",
"this",
"->",
"_host",
".",
"$",
"port",
".",
"$",
"this",
"->",
"_path",
".",
"$",
"query",
".",
"$",
"fragment",
";",
"}"
] | Returns a URI based on current values of the instance variables. If any
part of the URI does not pass validation, then an exception is thrown.
@throws Zend_Uri_Exception When one or more parts of the URI are invalid
@return string | [
"Returns",
"a",
"URI",
"based",
"on",
"current",
"values",
"of",
"the",
"instance",
"variables",
".",
"If",
"any",
"part",
"of",
"the",
"URI",
"does",
"not",
"pass",
"validation",
"then",
"an",
"exception",
"is",
"thrown",
"."
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Uri/Http.php#L247-L268 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Uri/Http.php | Zend_Uri_Http.validatePath | public function validatePath($path = null)
{
if ($path === null) {
$path = $this->_path;
}
// If the path is empty, then it is considered valid
if (strlen($path) === 0) {
return true;
}
// Determine whether the path is well-formed
$pattern = '/^' . $this->_regex['path'] . '$/';
$status = @preg_match($pattern, $path);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: path validation failed');
}
return (boolean) $status;
} | php | public function validatePath($path = null)
{
if ($path === null) {
$path = $this->_path;
}
// If the path is empty, then it is considered valid
if (strlen($path) === 0) {
return true;
}
// Determine whether the path is well-formed
$pattern = '/^' . $this->_regex['path'] . '$/';
$status = @preg_match($pattern, $path);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: path validation failed');
}
return (boolean) $status;
} | [
"public",
"function",
"validatePath",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"null",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_path",
";",
"}",
"// If the path is empty, then it is considered valid",
"if",
"(",
"strlen",
"(",
"$",
"path",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"// Determine whether the path is well-formed",
"$",
"pattern",
"=",
"'/^'",
".",
"$",
"this",
"->",
"_regex",
"[",
"'path'",
"]",
".",
"'$/'",
";",
"$",
"status",
"=",
"@",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"path",
")",
";",
"if",
"(",
"$",
"status",
"===",
"false",
")",
"{",
"require_once",
"'Zend/Uri/Exception.php'",
";",
"throw",
"new",
"Zend_Uri_Exception",
"(",
"'Internal error: path validation failed'",
")",
";",
"}",
"return",
"(",
"boolean",
")",
"$",
"status",
";",
"}"
] | Returns true if and only if the path string passes validation. If no path is passed,
then the path contained in the instance variable is used.
@param string $path The HTTP path
@throws Zend_Uri_Exception When path validation fails
@return boolean | [
"Returns",
"true",
"if",
"and",
"only",
"if",
"the",
"path",
"string",
"passes",
"validation",
".",
"If",
"no",
"path",
"is",
"passed",
"then",
"the",
"path",
"contained",
"in",
"the",
"instance",
"variable",
"is",
"used",
"."
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Uri/Http.php#L542-L562 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Uri/Http.php | Zend_Uri_Http.setPath | public function setPath($path)
{
if ($this->validatePath($path) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Path \"$path\" is not a valid HTTP path");
}
$oldPath = $this->_path;
$this->_path = $path;
return $oldPath;
} | php | public function setPath($path)
{
if ($this->validatePath($path) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Path \"$path\" is not a valid HTTP path");
}
$oldPath = $this->_path;
$this->_path = $path;
return $oldPath;
} | [
"public",
"function",
"setPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validatePath",
"(",
"$",
"path",
")",
"===",
"false",
")",
"{",
"require_once",
"'Zend/Uri/Exception.php'",
";",
"throw",
"new",
"Zend_Uri_Exception",
"(",
"\"Path \\\"$path\\\" is not a valid HTTP path\"",
")",
";",
"}",
"$",
"oldPath",
"=",
"$",
"this",
"->",
"_path",
";",
"$",
"this",
"->",
"_path",
"=",
"$",
"path",
";",
"return",
"$",
"oldPath",
";",
"}"
] | Sets the path for the current URI, and returns the old path
@param string $path The HTTP path
@throws Zend_Uri_Exception When $path is not a valid HTTP path
@return string | [
"Sets",
"the",
"path",
"for",
"the",
"current",
"URI",
"and",
"returns",
"the",
"old",
"path"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Uri/Http.php#L571-L582 |
xinix-technology/norm | src/Norm/Connection/MongoDBConnection.php | MongoDBConnection.persist | public function persist($collection, array $document)
{
if ($collection instanceof Collection) {
$collection = $collection->getName();
}
$marshalledDocument = $this->marshall($document);
$result = false;
if (isset($document['$id'])) {
$criteria = array(
'_id' => new MongoId($document['$id']),
);
$marshalledDocument = $this->raw->$collection->findAndModify(
$criteria,
array('$set' => $marshalledDocument),
null,
array('new' => true)
);
} else {
$retval = $this->raw->$collection->insert($marshalledDocument);
if (!$retval['ok']) {
throw new Exception($retval['errmsg']);
}
}
return $this->unmarshall($marshalledDocument);
} | php | public function persist($collection, array $document)
{
if ($collection instanceof Collection) {
$collection = $collection->getName();
}
$marshalledDocument = $this->marshall($document);
$result = false;
if (isset($document['$id'])) {
$criteria = array(
'_id' => new MongoId($document['$id']),
);
$marshalledDocument = $this->raw->$collection->findAndModify(
$criteria,
array('$set' => $marshalledDocument),
null,
array('new' => true)
);
} else {
$retval = $this->raw->$collection->insert($marshalledDocument);
if (!$retval['ok']) {
throw new Exception($retval['errmsg']);
}
}
return $this->unmarshall($marshalledDocument);
} | [
"public",
"function",
"persist",
"(",
"$",
"collection",
",",
"array",
"$",
"document",
")",
"{",
"if",
"(",
"$",
"collection",
"instanceof",
"Collection",
")",
"{",
"$",
"collection",
"=",
"$",
"collection",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"marshalledDocument",
"=",
"$",
"this",
"->",
"marshall",
"(",
"$",
"document",
")",
";",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"document",
"[",
"'$id'",
"]",
")",
")",
"{",
"$",
"criteria",
"=",
"array",
"(",
"'_id'",
"=>",
"new",
"MongoId",
"(",
"$",
"document",
"[",
"'$id'",
"]",
")",
",",
")",
";",
"$",
"marshalledDocument",
"=",
"$",
"this",
"->",
"raw",
"->",
"$",
"collection",
"->",
"findAndModify",
"(",
"$",
"criteria",
",",
"array",
"(",
"'$set'",
"=>",
"$",
"marshalledDocument",
")",
",",
"null",
",",
"array",
"(",
"'new'",
"=>",
"true",
")",
")",
";",
"}",
"else",
"{",
"$",
"retval",
"=",
"$",
"this",
"->",
"raw",
"->",
"$",
"collection",
"->",
"insert",
"(",
"$",
"marshalledDocument",
")",
";",
"if",
"(",
"!",
"$",
"retval",
"[",
"'ok'",
"]",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"retval",
"[",
"'errmsg'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"unmarshall",
"(",
"$",
"marshalledDocument",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/MongoDBConnection.php#L84-L114 |
xinix-technology/norm | src/Norm/Connection/MongoDBConnection.php | MongoDBConnection.remove | public function remove($collection, $criteria = null)
{
if ($collection instanceof Collection) {
$collection = $collection->getName();
}
if (func_num_args() === 1) {
$result = $this->raw->$collection->remove();
} else {
if ($criteria instanceof Model) {
$criteria = $criteria->getId();
}
if (is_string($criteria)) {
$criteria = array(
'_id' => new MongoId($criteria),
);
} elseif (! is_array($criteria)) {
throw new Exception('[Norm/Connection] Cannot remove with specified criteria. Criteria must be array, string, or model');
}
$result = $this->raw->$collection->remove($criteria);
}
if ((int) $result['ok'] !== 1) {
throw new Exception($result['errmsg']);
}
} | php | public function remove($collection, $criteria = null)
{
if ($collection instanceof Collection) {
$collection = $collection->getName();
}
if (func_num_args() === 1) {
$result = $this->raw->$collection->remove();
} else {
if ($criteria instanceof Model) {
$criteria = $criteria->getId();
}
if (is_string($criteria)) {
$criteria = array(
'_id' => new MongoId($criteria),
);
} elseif (! is_array($criteria)) {
throw new Exception('[Norm/Connection] Cannot remove with specified criteria. Criteria must be array, string, or model');
}
$result = $this->raw->$collection->remove($criteria);
}
if ((int) $result['ok'] !== 1) {
throw new Exception($result['errmsg']);
}
} | [
"public",
"function",
"remove",
"(",
"$",
"collection",
",",
"$",
"criteria",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"collection",
"instanceof",
"Collection",
")",
"{",
"$",
"collection",
"=",
"$",
"collection",
"->",
"getName",
"(",
")",
";",
"}",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"1",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"raw",
"->",
"$",
"collection",
"->",
"remove",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"criteria",
"instanceof",
"Model",
")",
"{",
"$",
"criteria",
"=",
"$",
"criteria",
"->",
"getId",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"criteria",
")",
")",
"{",
"$",
"criteria",
"=",
"array",
"(",
"'_id'",
"=>",
"new",
"MongoId",
"(",
"$",
"criteria",
")",
",",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"criteria",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'[Norm/Connection] Cannot remove with specified criteria. Criteria must be array, string, or model'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"raw",
"->",
"$",
"collection",
"->",
"remove",
"(",
"$",
"criteria",
")",
";",
"}",
"if",
"(",
"(",
"int",
")",
"$",
"result",
"[",
"'ok'",
"]",
"!==",
"1",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"result",
"[",
"'errmsg'",
"]",
")",
";",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/MongoDBConnection.php#L119-L146 |
xinix-technology/norm | src/Norm/Connection/MongoDBConnection.php | MongoDBConnection.unmarshall | public function unmarshall($object)
{
if (isset($object['_id'])) {
$object['$id'] = (string) $object['_id'];
unset($object['_id']);
}
foreach ($object as $key => &$value) {
if ($value instanceof MongoDate) {
$value = new DateTime('@'.$value->sec);
} elseif ($value instanceof MongoId) {
$value = (string) $value;
}
if ($key[0] === '_') {
unset($object[$key]);
$key[0] = '$';
$object[$key] = $value;
}
}
return $object;
} | php | public function unmarshall($object)
{
if (isset($object['_id'])) {
$object['$id'] = (string) $object['_id'];
unset($object['_id']);
}
foreach ($object as $key => &$value) {
if ($value instanceof MongoDate) {
$value = new DateTime('@'.$value->sec);
} elseif ($value instanceof MongoId) {
$value = (string) $value;
}
if ($key[0] === '_') {
unset($object[$key]);
$key[0] = '$';
$object[$key] = $value;
}
}
return $object;
} | [
"public",
"function",
"unmarshall",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"object",
"[",
"'_id'",
"]",
")",
")",
"{",
"$",
"object",
"[",
"'$id'",
"]",
"=",
"(",
"string",
")",
"$",
"object",
"[",
"'_id'",
"]",
";",
"unset",
"(",
"$",
"object",
"[",
"'_id'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"object",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"MongoDate",
")",
"{",
"$",
"value",
"=",
"new",
"DateTime",
"(",
"'@'",
".",
"$",
"value",
"->",
"sec",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"MongoId",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"key",
"[",
"0",
"]",
"===",
"'_'",
")",
"{",
"unset",
"(",
"$",
"object",
"[",
"$",
"key",
"]",
")",
";",
"$",
"key",
"[",
"0",
"]",
"=",
"'$'",
";",
"$",
"object",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"object",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/MongoDBConnection.php#L161-L183 |
xinix-technology/norm | src/Norm/Connection/MongoDBConnection.php | MongoDBConnection.marshall | public function marshall($object)
{
if ($object instanceof NormDateTime) {
return new MongoDate($object->getTimestamp());
} elseif ($object instanceof NormArray) {
return $object->toArray();
} elseif ($object instanceof NObject) {
return $object->toObject();
} else {
return parent::marshall($object);
}
} | php | public function marshall($object)
{
if ($object instanceof NormDateTime) {
return new MongoDate($object->getTimestamp());
} elseif ($object instanceof NormArray) {
return $object->toArray();
} elseif ($object instanceof NObject) {
return $object->toObject();
} else {
return parent::marshall($object);
}
} | [
"public",
"function",
"marshall",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"object",
"instanceof",
"NormDateTime",
")",
"{",
"return",
"new",
"MongoDate",
"(",
"$",
"object",
"->",
"getTimestamp",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"object",
"instanceof",
"NormArray",
")",
"{",
"return",
"$",
"object",
"->",
"toArray",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"object",
"instanceof",
"NObject",
")",
"{",
"return",
"$",
"object",
"->",
"toObject",
"(",
")",
";",
"}",
"else",
"{",
"return",
"parent",
"::",
"marshall",
"(",
"$",
"object",
")",
";",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/MongoDBConnection.php#L188-L199 |
periaptio/empress-generator | src/Generators/BaseGenerator.php | BaseGenerator.generateFile | public function generateFile($filename, $templateData, $templatePath = null)
{
$this->makeDirectory($this->rootPath);
$path = $this->rootPath.$filename;
if (is_null($templatePath)) {
$templatePath = $this->templatePath;
}
$content = $this->generateContent($templatePath, $templateData);
if (! file_exists($path)) {
$this->fileHelper->put($path, $content);
$this->command->info($filename.' created successfully.');
} else {
$this->command->info($filename.' already exists ... skipping.');
}
} | php | public function generateFile($filename, $templateData, $templatePath = null)
{
$this->makeDirectory($this->rootPath);
$path = $this->rootPath.$filename;
if (is_null($templatePath)) {
$templatePath = $this->templatePath;
}
$content = $this->generateContent($templatePath, $templateData);
if (! file_exists($path)) {
$this->fileHelper->put($path, $content);
$this->command->info($filename.' created successfully.');
} else {
$this->command->info($filename.' already exists ... skipping.');
}
} | [
"public",
"function",
"generateFile",
"(",
"$",
"filename",
",",
"$",
"templateData",
",",
"$",
"templatePath",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"makeDirectory",
"(",
"$",
"this",
"->",
"rootPath",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"rootPath",
".",
"$",
"filename",
";",
"if",
"(",
"is_null",
"(",
"$",
"templatePath",
")",
")",
"{",
"$",
"templatePath",
"=",
"$",
"this",
"->",
"templatePath",
";",
"}",
"$",
"content",
"=",
"$",
"this",
"->",
"generateContent",
"(",
"$",
"templatePath",
",",
"$",
"templateData",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"fileHelper",
"->",
"put",
"(",
"$",
"path",
",",
"$",
"content",
")",
";",
"$",
"this",
"->",
"command",
"->",
"info",
"(",
"$",
"filename",
".",
"' created successfully.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"command",
"->",
"info",
"(",
"$",
"filename",
".",
"' already exists ... skipping.'",
")",
";",
"}",
"}"
] | Execute the console command.
@return bool|null | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Generators/BaseGenerator.php#L99-L117 |
periaptio/empress-generator | src/Generators/BaseGenerator.php | BaseGenerator.makeDirectory | protected function makeDirectory($path)
{
if (! $this->fileHelper->exists($path)) {
$this->fileHelper->makeDirectory($path, 0777, true, true);
}
} | php | protected function makeDirectory($path)
{
if (! $this->fileHelper->exists($path)) {
$this->fileHelper->makeDirectory($path, 0777, true, true);
}
} | [
"protected",
"function",
"makeDirectory",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fileHelper",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"fileHelper",
"->",
"makeDirectory",
"(",
"$",
"path",
",",
"0777",
",",
"true",
",",
"true",
")",
";",
"}",
"}"
] | Build the directory for the class if necessary.
@param string $path
@return string | [
"Build",
"the",
"directory",
"for",
"the",
"class",
"if",
"necessary",
"."
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Generators/BaseGenerator.php#L125-L130 |
periaptio/empress-generator | src/Generators/BaseGenerator.php | BaseGenerator.generateContent | protected function generateContent($templatePath, $templateData)
{
$template = $this->getTemplate($templatePath);
$content = $this->compile($template, $templateData);
return $content;
} | php | protected function generateContent($templatePath, $templateData)
{
$template = $this->getTemplate($templatePath);
$content = $this->compile($template, $templateData);
return $content;
} | [
"protected",
"function",
"generateContent",
"(",
"$",
"templatePath",
",",
"$",
"templateData",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"getTemplate",
"(",
"$",
"templatePath",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"compile",
"(",
"$",
"template",
",",
"$",
"templateData",
")",
";",
"return",
"$",
"content",
";",
"}"
] | Generate content with template data is given.
@param array $templateData
@return string | [
"Generate",
"content",
"with",
"template",
"data",
"is",
"given",
"."
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Generators/BaseGenerator.php#L138-L145 |
periaptio/empress-generator | src/Generators/BaseGenerator.php | BaseGenerator.getTemplate | protected function getTemplate($templatePath)
{
$path = base_path('resources/generator-templates/'.$templatePath.'.stub');
if (!file_exists($path)) {
$path = __DIR__.'/../../templates/'.$templatePath.'.stub';
}
return $this->fileHelper->get($path);
} | php | protected function getTemplate($templatePath)
{
$path = base_path('resources/generator-templates/'.$templatePath.'.stub');
if (!file_exists($path)) {
$path = __DIR__.'/../../templates/'.$templatePath.'.stub';
}
return $this->fileHelper->get($path);
} | [
"protected",
"function",
"getTemplate",
"(",
"$",
"templatePath",
")",
"{",
"$",
"path",
"=",
"base_path",
"(",
"'resources/generator-templates/'",
".",
"$",
"templatePath",
".",
"'.stub'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"__DIR__",
".",
"'/../../templates/'",
".",
"$",
"templatePath",
".",
"'.stub'",
";",
"}",
"return",
"$",
"this",
"->",
"fileHelper",
"->",
"get",
"(",
"$",
"path",
")",
";",
"}"
] | Get the template for the generator.
@param string $templatePath
@return string | [
"Get",
"the",
"template",
"for",
"the",
"generator",
"."
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Generators/BaseGenerator.php#L153-L162 |
webforge-labs/psc-cms | lib/Psc/System/LoggerObject.php | LoggerObject.setLogger | public function setLogger(\Psc\System\Logger $logger, $prefix = NULL) {
$this->logger = $logger;
$this->logger->setPrefix($prefix ?: '['.Code::getClassName($this).']');
return $this;
} | php | public function setLogger(\Psc\System\Logger $logger, $prefix = NULL) {
$this->logger = $logger;
$this->logger->setPrefix($prefix ?: '['.Code::getClassName($this).']');
return $this;
} | [
"public",
"function",
"setLogger",
"(",
"\\",
"Psc",
"\\",
"System",
"\\",
"Logger",
"$",
"logger",
",",
"$",
"prefix",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"logger",
"=",
"$",
"logger",
";",
"$",
"this",
"->",
"logger",
"->",
"setPrefix",
"(",
"$",
"prefix",
"?",
":",
"'['",
".",
"Code",
"::",
"getClassName",
"(",
"$",
"this",
")",
".",
"']'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | protected $logLevel = 0; | [
"protected",
"$logLevel",
"=",
"0",
";"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/System/LoggerObject.php#L19-L23 |
webforge-labs/psc-cms | lib/Psc/System/LoggerObject.php | LoggerObject.logError | public function logError(\Exception $e, $detailLevel = 1, $level = 1) {
if ($detailLevel >= 5) {
return $this->log("\n".'ERROR: '.\Psc\Exception::getExceptionText($e, 'text'));
} else {
return $this->log("\n".'ERROR: Exception: '.$e->getMessage(), $level);
}
} | php | public function logError(\Exception $e, $detailLevel = 1, $level = 1) {
if ($detailLevel >= 5) {
return $this->log("\n".'ERROR: '.\Psc\Exception::getExceptionText($e, 'text'));
} else {
return $this->log("\n".'ERROR: Exception: '.$e->getMessage(), $level);
}
} | [
"public",
"function",
"logError",
"(",
"\\",
"Exception",
"$",
"e",
",",
"$",
"detailLevel",
"=",
"1",
",",
"$",
"level",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"detailLevel",
">=",
"5",
")",
"{",
"return",
"$",
"this",
"->",
"log",
"(",
"\"\\n\"",
".",
"'ERROR: '",
".",
"\\",
"Psc",
"\\",
"Exception",
"::",
"getExceptionText",
"(",
"$",
"e",
",",
"'text'",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"log",
"(",
"\"\\n\"",
".",
"'ERROR: Exception: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"level",
")",
";",
"}",
"}"
] | ab detailLevel >= 5 wird der exceptionTrace mit geloggt | [
"ab",
"detailLevel",
">",
"=",
"5",
"wird",
"der",
"exceptionTrace",
"mit",
"geloggt"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/System/LoggerObject.php#L42-L48 |
fond-of/spryker-brand | src/FondOfSpryker/Client/Brand/BrandDependencyProvider.php | BrandDependencyProvider.addZedRequestClient | protected function addZedRequestClient(Container $container): Container
{
$container[static::CLIENT_ZED_REQUEST] = function (Container $container) {
return new BrandToZedRequestClientBridge($container->getLocator()->zedRequest()->client());
};
return $container;
} | php | protected function addZedRequestClient(Container $container): Container
{
$container[static::CLIENT_ZED_REQUEST] = function (Container $container) {
return new BrandToZedRequestClientBridge($container->getLocator()->zedRequest()->client());
};
return $container;
} | [
"protected",
"function",
"addZedRequestClient",
"(",
"Container",
"$",
"container",
")",
":",
"Container",
"{",
"$",
"container",
"[",
"static",
"::",
"CLIENT_ZED_REQUEST",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"BrandToZedRequestClientBridge",
"(",
"$",
"container",
"->",
"getLocator",
"(",
")",
"->",
"zedRequest",
"(",
")",
"->",
"client",
"(",
")",
")",
";",
"}",
";",
"return",
"$",
"container",
";",
"}"
] | @param \Spryker\Client\Kernel\Container $container
@return \Spryker\Client\Kernel\Container | [
"@param",
"\\",
"Spryker",
"\\",
"Client",
"\\",
"Kernel",
"\\",
"Container",
"$container"
] | train | https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Client/Brand/BrandDependencyProvider.php#L30-L37 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.invoke | public function invoke(MethodInvocation $invocation)
{
list($onValidate, $onFailure) = $this->getOnValidate($invocation->getMethod());
list($isValid, $failure) = $this->validate($invocation, $onValidate, $onFailure);
if ($isValid === true) {
// validation success
return $invocation->proceed();
}
// onFailure
return $failure;
} | php | public function invoke(MethodInvocation $invocation)
{
list($onValidate, $onFailure) = $this->getOnValidate($invocation->getMethod());
list($isValid, $failure) = $this->validate($invocation, $onValidate, $onFailure);
if ($isValid === true) {
// validation success
return $invocation->proceed();
}
// onFailure
return $failure;
} | [
"public",
"function",
"invoke",
"(",
"MethodInvocation",
"$",
"invocation",
")",
"{",
"list",
"(",
"$",
"onValidate",
",",
"$",
"onFailure",
")",
"=",
"$",
"this",
"->",
"getOnValidate",
"(",
"$",
"invocation",
"->",
"getMethod",
"(",
")",
")",
";",
"list",
"(",
"$",
"isValid",
",",
"$",
"failure",
")",
"=",
"$",
"this",
"->",
"validate",
"(",
"$",
"invocation",
",",
"$",
"onValidate",
",",
"$",
"onFailure",
")",
";",
"if",
"(",
"$",
"isValid",
"===",
"true",
")",
"{",
"// validation success",
"return",
"$",
"invocation",
"->",
"proceed",
"(",
")",
";",
"}",
"// onFailure",
"return",
"$",
"failure",
";",
"}"
] | {@inheritdoc}
@throws InvalidArgumentException | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L36-L47 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.getOnValidate | private function getOnValidate(\ReflectionMethod $method)
{
/** @var $valid Valid */
$valid = $this->reader->getMethodAnnotation($method, Valid::class);
$class = $method->getDeclaringClass();
$onMethods = $this->findOnMethods($class, $valid);
if ($onMethods[0] && $onMethods[0] instanceof \ReflectionMethod) {
return $onMethods;
}
throw new ValidateMethodNotFound($method->getShortName());
} | php | private function getOnValidate(\ReflectionMethod $method)
{
/** @var $valid Valid */
$valid = $this->reader->getMethodAnnotation($method, Valid::class);
$class = $method->getDeclaringClass();
$onMethods = $this->findOnMethods($class, $valid);
if ($onMethods[0] && $onMethods[0] instanceof \ReflectionMethod) {
return $onMethods;
}
throw new ValidateMethodNotFound($method->getShortName());
} | [
"private",
"function",
"getOnValidate",
"(",
"\\",
"ReflectionMethod",
"$",
"method",
")",
"{",
"/** @var $valid Valid */",
"$",
"valid",
"=",
"$",
"this",
"->",
"reader",
"->",
"getMethodAnnotation",
"(",
"$",
"method",
",",
"Valid",
"::",
"class",
")",
";",
"$",
"class",
"=",
"$",
"method",
"->",
"getDeclaringClass",
"(",
")",
";",
"$",
"onMethods",
"=",
"$",
"this",
"->",
"findOnMethods",
"(",
"$",
"class",
",",
"$",
"valid",
")",
";",
"if",
"(",
"$",
"onMethods",
"[",
"0",
"]",
"&&",
"$",
"onMethods",
"[",
"0",
"]",
"instanceof",
"\\",
"ReflectionMethod",
")",
"{",
"return",
"$",
"onMethods",
";",
"}",
"throw",
"new",
"ValidateMethodNotFound",
"(",
"$",
"method",
"->",
"getShortName",
"(",
")",
")",
";",
"}"
] | Return Validate and OnFailure method
@param \ReflectionMethod $method
@return \ReflectionMethod[] [$onValidateMethod, $onFailureMethod] | [
"Return",
"Validate",
"and",
"OnFailure",
"method"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L56-L66 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.validate | private function validate(MethodInvocation $invocation, \ReflectionMethod $onValidate, \ReflectionMethod $onFailure = null)
{
$validation = $onValidate->invokeArgs($invocation->getThis(), (array) $invocation->getArguments());
if ($validation instanceof Validation && $validation->getMessages()) {
/* @var $validation Validation */
$validation->setInvocation($invocation);
$failure = $this->getFailure($invocation, $validation, $onFailure);
if ($failure instanceof \Exception) {
throw $failure;
}
return [false, $failure];
}
return [true, null];
} | php | private function validate(MethodInvocation $invocation, \ReflectionMethod $onValidate, \ReflectionMethod $onFailure = null)
{
$validation = $onValidate->invokeArgs($invocation->getThis(), (array) $invocation->getArguments());
if ($validation instanceof Validation && $validation->getMessages()) {
/* @var $validation Validation */
$validation->setInvocation($invocation);
$failure = $this->getFailure($invocation, $validation, $onFailure);
if ($failure instanceof \Exception) {
throw $failure;
}
return [false, $failure];
}
return [true, null];
} | [
"private",
"function",
"validate",
"(",
"MethodInvocation",
"$",
"invocation",
",",
"\\",
"ReflectionMethod",
"$",
"onValidate",
",",
"\\",
"ReflectionMethod",
"$",
"onFailure",
"=",
"null",
")",
"{",
"$",
"validation",
"=",
"$",
"onValidate",
"->",
"invokeArgs",
"(",
"$",
"invocation",
"->",
"getThis",
"(",
")",
",",
"(",
"array",
")",
"$",
"invocation",
"->",
"getArguments",
"(",
")",
")",
";",
"if",
"(",
"$",
"validation",
"instanceof",
"Validation",
"&&",
"$",
"validation",
"->",
"getMessages",
"(",
")",
")",
"{",
"/* @var $validation Validation */",
"$",
"validation",
"->",
"setInvocation",
"(",
"$",
"invocation",
")",
";",
"$",
"failure",
"=",
"$",
"this",
"->",
"getFailure",
"(",
"$",
"invocation",
",",
"$",
"validation",
",",
"$",
"onFailure",
")",
";",
"if",
"(",
"$",
"failure",
"instanceof",
"\\",
"Exception",
")",
"{",
"throw",
"$",
"failure",
";",
"}",
"return",
"[",
"false",
",",
"$",
"failure",
"]",
";",
"}",
"return",
"[",
"true",
",",
"null",
"]",
";",
"}"
] | Validate with Validate method
@param MethodInvocation $invocation
@param \ReflectionMethod $onValidate
@param \ReflectionMethod $onFailure
@throws \Exception
@return bool|mixed|InvalidArgumentException | [
"Validate",
"with",
"Validate",
"method"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L79-L94 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.getFailure | private function getFailure(MethodInvocation $invocation, FailureInterface $failure, \ReflectionMethod $onFailure = null)
{
if ($onFailure) {
return $onFailure->invoke($invocation->getThis(), $failure);
}
return $this->failureException($invocation, $failure);
} | php | private function getFailure(MethodInvocation $invocation, FailureInterface $failure, \ReflectionMethod $onFailure = null)
{
if ($onFailure) {
return $onFailure->invoke($invocation->getThis(), $failure);
}
return $this->failureException($invocation, $failure);
} | [
"private",
"function",
"getFailure",
"(",
"MethodInvocation",
"$",
"invocation",
",",
"FailureInterface",
"$",
"failure",
",",
"\\",
"ReflectionMethod",
"$",
"onFailure",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"onFailure",
")",
"{",
"return",
"$",
"onFailure",
"->",
"invoke",
"(",
"$",
"invocation",
"->",
"getThis",
"(",
")",
",",
"$",
"failure",
")",
";",
"}",
"return",
"$",
"this",
"->",
"failureException",
"(",
"$",
"invocation",
",",
"$",
"failure",
")",
";",
"}"
] | Return result OnFailure
@param MethodInvocation $invocation
@param FailureInterface $failure
@param \ReflectionMethod $onFailure
@return mixed|InvalidArgumentException | [
"Return",
"result",
"OnFailure"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L105-L112 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.failureException | private function failureException(MethodInvocation $invocation, FailureInterface $failure)
{
$class = new \ReflectionClass($invocation->getThis());
$className = $class->implementsInterface(WeavedInterface::class) ? $class->getParentClass()->name : $class->name;
$errors = json_encode($failure->getMessages());
$msg = sprintf('%s::%s() %s', $className, $invocation->getMethod()->name, $errors);
return new InvalidArgumentException($msg, 400);
} | php | private function failureException(MethodInvocation $invocation, FailureInterface $failure)
{
$class = new \ReflectionClass($invocation->getThis());
$className = $class->implementsInterface(WeavedInterface::class) ? $class->getParentClass()->name : $class->name;
$errors = json_encode($failure->getMessages());
$msg = sprintf('%s::%s() %s', $className, $invocation->getMethod()->name, $errors);
return new InvalidArgumentException($msg, 400);
} | [
"private",
"function",
"failureException",
"(",
"MethodInvocation",
"$",
"invocation",
",",
"FailureInterface",
"$",
"failure",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"invocation",
"->",
"getThis",
"(",
")",
")",
";",
"$",
"className",
"=",
"$",
"class",
"->",
"implementsInterface",
"(",
"WeavedInterface",
"::",
"class",
")",
"?",
"$",
"class",
"->",
"getParentClass",
"(",
")",
"->",
"name",
":",
"$",
"class",
"->",
"name",
";",
"$",
"errors",
"=",
"json_encode",
"(",
"$",
"failure",
"->",
"getMessages",
"(",
")",
")",
";",
"$",
"msg",
"=",
"sprintf",
"(",
"'%s::%s() %s'",
",",
"$",
"className",
",",
"$",
"invocation",
"->",
"getMethod",
"(",
")",
"->",
"name",
",",
"$",
"errors",
")",
";",
"return",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
",",
"400",
")",
";",
"}"
] | Return InvalidArgumentException exception
@param MethodInvocation $invocation
@param FailureInterface $failure
@return InvalidArgumentException | [
"Return",
"InvalidArgumentException",
"exception"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L122-L130 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.findOnMethods | private function findOnMethods(\ReflectionClass $class, Valid $valid)
{
$onValidateMethod = $onFailureMethod = null;
foreach ($class->getMethods() as $method) {
$annotations = $this->reader->getMethodAnnotations($method);
list($onValidateMethod, $onFailureMethod) = $this->scanAnnotation(
$valid,
$annotations,
$method,
$onValidateMethod,
$onFailureMethod
);
}
return [$onValidateMethod, $onFailureMethod];
} | php | private function findOnMethods(\ReflectionClass $class, Valid $valid)
{
$onValidateMethod = $onFailureMethod = null;
foreach ($class->getMethods() as $method) {
$annotations = $this->reader->getMethodAnnotations($method);
list($onValidateMethod, $onFailureMethod) = $this->scanAnnotation(
$valid,
$annotations,
$method,
$onValidateMethod,
$onFailureMethod
);
}
return [$onValidateMethod, $onFailureMethod];
} | [
"private",
"function",
"findOnMethods",
"(",
"\\",
"ReflectionClass",
"$",
"class",
",",
"Valid",
"$",
"valid",
")",
"{",
"$",
"onValidateMethod",
"=",
"$",
"onFailureMethod",
"=",
"null",
";",
"foreach",
"(",
"$",
"class",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"$",
"annotations",
"=",
"$",
"this",
"->",
"reader",
"->",
"getMethodAnnotations",
"(",
"$",
"method",
")",
";",
"list",
"(",
"$",
"onValidateMethod",
",",
"$",
"onFailureMethod",
")",
"=",
"$",
"this",
"->",
"scanAnnotation",
"(",
"$",
"valid",
",",
"$",
"annotations",
",",
"$",
"method",
",",
"$",
"onValidateMethod",
",",
"$",
"onFailureMethod",
")",
";",
"}",
"return",
"[",
"$",
"onValidateMethod",
",",
"$",
"onFailureMethod",
"]",
";",
"}"
] | @param \ReflectionClass $class
@param Valid $valid
@return \ReflectionMethod[] | [
"@param",
"\\",
"ReflectionClass",
"$class",
"@param",
"Valid",
"$valid"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L138-L153 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.scanAnnotation | private function scanAnnotation(
Valid $valid,
array $annotations,
\ReflectionMethod $method,
\ReflectionMethod $onValidateMethod = null,
\ReflectionMethod $onFailureMethod = null
) {
foreach ($annotations as $annotation) {
if ($this->isOnValidateFound($annotation, $valid, $onValidateMethod)) {
$onValidateMethod = $method;
}
if ($this->isOnFailureFound($annotation, $valid, $onFailureMethod)) {
$onFailureMethod = $method;
}
}
return [$onValidateMethod, $onFailureMethod];
} | php | private function scanAnnotation(
Valid $valid,
array $annotations,
\ReflectionMethod $method,
\ReflectionMethod $onValidateMethod = null,
\ReflectionMethod $onFailureMethod = null
) {
foreach ($annotations as $annotation) {
if ($this->isOnValidateFound($annotation, $valid, $onValidateMethod)) {
$onValidateMethod = $method;
}
if ($this->isOnFailureFound($annotation, $valid, $onFailureMethod)) {
$onFailureMethod = $method;
}
}
return [$onValidateMethod, $onFailureMethod];
} | [
"private",
"function",
"scanAnnotation",
"(",
"Valid",
"$",
"valid",
",",
"array",
"$",
"annotations",
",",
"\\",
"ReflectionMethod",
"$",
"method",
",",
"\\",
"ReflectionMethod",
"$",
"onValidateMethod",
"=",
"null",
",",
"\\",
"ReflectionMethod",
"$",
"onFailureMethod",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"annotation",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOnValidateFound",
"(",
"$",
"annotation",
",",
"$",
"valid",
",",
"$",
"onValidateMethod",
")",
")",
"{",
"$",
"onValidateMethod",
"=",
"$",
"method",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isOnFailureFound",
"(",
"$",
"annotation",
",",
"$",
"valid",
",",
"$",
"onFailureMethod",
")",
")",
"{",
"$",
"onFailureMethod",
"=",
"$",
"method",
";",
"}",
"}",
"return",
"[",
"$",
"onValidateMethod",
",",
"$",
"onFailureMethod",
"]",
";",
"}"
] | @param Valid $valid
@param array $annotations
@param \ReflectionMethod $method
@param \ReflectionMethod $onValidateMethod
@param \ReflectionMethod $onFailureMethod
@return array | [
"@param",
"Valid",
"$valid",
"@param",
"array",
"$annotations",
"@param",
"\\",
"ReflectionMethod",
"$method",
"@param",
"\\",
"ReflectionMethod",
"$onValidateMethod",
"@param",
"\\",
"ReflectionMethod",
"$onFailureMethod"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L164-L181 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.isOnValidateFound | private function isOnValidateFound($annotation, Valid $valid, \ReflectionMethod $onValidateMethod = null)
{
return (is_null($onValidateMethod) && $annotation instanceof OnValidate && $annotation->value === $valid->value) ? true : false;
} | php | private function isOnValidateFound($annotation, Valid $valid, \ReflectionMethod $onValidateMethod = null)
{
return (is_null($onValidateMethod) && $annotation instanceof OnValidate && $annotation->value === $valid->value) ? true : false;
} | [
"private",
"function",
"isOnValidateFound",
"(",
"$",
"annotation",
",",
"Valid",
"$",
"valid",
",",
"\\",
"ReflectionMethod",
"$",
"onValidateMethod",
"=",
"null",
")",
"{",
"return",
"(",
"is_null",
"(",
"$",
"onValidateMethod",
")",
"&&",
"$",
"annotation",
"instanceof",
"OnValidate",
"&&",
"$",
"annotation",
"->",
"value",
"===",
"$",
"valid",
"->",
"value",
")",
"?",
"true",
":",
"false",
";",
"}"
] | @param object $annotation
@param Valid $valid
@param \ReflectionMethod $onValidateMethod
@return bool | [
"@param",
"object",
"$annotation",
"@param",
"Valid",
"$valid",
"@param",
"\\",
"ReflectionMethod",
"$onValidateMethod"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L190-L193 |
ray-di/Ray.ValidateModule | src/ValidateInterceptor.php | ValidateInterceptor.isOnFailureFound | private function isOnFailureFound($annotation, Valid $valid, \ReflectionMethod $onFailureMethod = null)
{
return (is_null($onFailureMethod) && $annotation instanceof OnFailure && $annotation->value === $valid->value) ? true : false;
} | php | private function isOnFailureFound($annotation, Valid $valid, \ReflectionMethod $onFailureMethod = null)
{
return (is_null($onFailureMethod) && $annotation instanceof OnFailure && $annotation->value === $valid->value) ? true : false;
} | [
"private",
"function",
"isOnFailureFound",
"(",
"$",
"annotation",
",",
"Valid",
"$",
"valid",
",",
"\\",
"ReflectionMethod",
"$",
"onFailureMethod",
"=",
"null",
")",
"{",
"return",
"(",
"is_null",
"(",
"$",
"onFailureMethod",
")",
"&&",
"$",
"annotation",
"instanceof",
"OnFailure",
"&&",
"$",
"annotation",
"->",
"value",
"===",
"$",
"valid",
"->",
"value",
")",
"?",
"true",
":",
"false",
";",
"}"
] | @param object $annotation
@param Valid $valid
@param \ReflectionMethod $onFailureMethod
@return bool | [
"@param",
"object",
"$annotation",
"@param",
"Valid",
"$valid",
"@param",
"\\",
"ReflectionMethod",
"$onFailureMethod"
] | train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/src/ValidateInterceptor.php#L202-L205 |
Lansoweb/LosReCaptcha | src/Form/View/Helper/Captcha/ReCaptcha.php | ReCaptcha.render | public function render(ElementInterface $element)
{
$attributes = $element->getAttributes();
$captcha = $element->getCaptcha();
if ($captcha === null || ! $captcha instanceof CaptchaAdapter) {
throw new Exception\DomainException(sprintf(
'%s requires that the element has a "captcha" is an instance of LosReCaptcha\Captcha\ReCaptcha',
__METHOD__
));
}
$name = $element->getName();
$id = isset($attributes['id']) ? $attributes['id'] : $name;
$responseName = empty($name) ? 'recaptcha_response_field' : $name . '[recaptcha_response_field]';
$responseId = $id . '-response';
$markup = $captcha->getService()->getHtml($name);
$hidden = $this->renderHiddenInput($responseName, $responseId);
$js = $this->renderJsEvents($responseId);
return $hidden . $markup . $js;
} | php | public function render(ElementInterface $element)
{
$attributes = $element->getAttributes();
$captcha = $element->getCaptcha();
if ($captcha === null || ! $captcha instanceof CaptchaAdapter) {
throw new Exception\DomainException(sprintf(
'%s requires that the element has a "captcha" is an instance of LosReCaptcha\Captcha\ReCaptcha',
__METHOD__
));
}
$name = $element->getName();
$id = isset($attributes['id']) ? $attributes['id'] : $name;
$responseName = empty($name) ? 'recaptcha_response_field' : $name . '[recaptcha_response_field]';
$responseId = $id . '-response';
$markup = $captcha->getService()->getHtml($name);
$hidden = $this->renderHiddenInput($responseName, $responseId);
$js = $this->renderJsEvents($responseId);
return $hidden . $markup . $js;
} | [
"public",
"function",
"render",
"(",
"ElementInterface",
"$",
"element",
")",
"{",
"$",
"attributes",
"=",
"$",
"element",
"->",
"getAttributes",
"(",
")",
";",
"$",
"captcha",
"=",
"$",
"element",
"->",
"getCaptcha",
"(",
")",
";",
"if",
"(",
"$",
"captcha",
"===",
"null",
"||",
"!",
"$",
"captcha",
"instanceof",
"CaptchaAdapter",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"DomainException",
"(",
"sprintf",
"(",
"'%s requires that the element has a \"captcha\" is an instance of LosReCaptcha\\Captcha\\ReCaptcha'",
",",
"__METHOD__",
")",
")",
";",
"}",
"$",
"name",
"=",
"$",
"element",
"->",
"getName",
"(",
")",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"attributes",
"[",
"'id'",
"]",
")",
"?",
"$",
"attributes",
"[",
"'id'",
"]",
":",
"$",
"name",
";",
"$",
"responseName",
"=",
"empty",
"(",
"$",
"name",
")",
"?",
"'recaptcha_response_field'",
":",
"$",
"name",
".",
"'[recaptcha_response_field]'",
";",
"$",
"responseId",
"=",
"$",
"id",
".",
"'-response'",
";",
"$",
"markup",
"=",
"$",
"captcha",
"->",
"getService",
"(",
")",
"->",
"getHtml",
"(",
"$",
"name",
")",
";",
"$",
"hidden",
"=",
"$",
"this",
"->",
"renderHiddenInput",
"(",
"$",
"responseName",
",",
"$",
"responseId",
")",
";",
"$",
"js",
"=",
"$",
"this",
"->",
"renderJsEvents",
"(",
"$",
"responseId",
")",
";",
"return",
"$",
"hidden",
".",
"$",
"markup",
".",
"$",
"js",
";",
"}"
] | Render ReCaptcha form elements
@param ElementInterface $element
@throws Exception\DomainException
@return string | [
"Render",
"ReCaptcha",
"form",
"elements"
] | train | https://github.com/Lansoweb/LosReCaptcha/blob/8df866995501db087c3850f97fd2b6547632e6ed/src/Form/View/Helper/Captcha/ReCaptcha.php#L43-L65 |
CakeCMS/Core | src/Controller/Component/AppComponent.php | AppComponent.initialize | public function initialize(array $config)
{
$this->_controller = $this->_registry->getController();
$this->_request = $this->_controller->request;
parent::initialize($config);
} | php | public function initialize(array $config)
{
$this->_controller = $this->_registry->getController();
$this->_request = $this->_controller->request;
parent::initialize($config);
} | [
"public",
"function",
"initialize",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"_controller",
"=",
"$",
"this",
"->",
"_registry",
"->",
"getController",
"(",
")",
";",
"$",
"this",
"->",
"_request",
"=",
"$",
"this",
"->",
"_controller",
"->",
"request",
";",
"parent",
"::",
"initialize",
"(",
"$",
"config",
")",
";",
"}"
] | Constructor hook method.
@param array $config
@return void | [
"Constructor",
"hook",
"method",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Controller/Component/AppComponent.php#L55-L61 |
CakeCMS/Core | src/Controller/Component/AppComponent.php | AppComponent.redirect | public function redirect(array $options = [])
{
$plugin = $this->_request->getParam('plugin');
$controller = $this->_request->getParam('controller');
$_options = [
'apply' => [],
'savenew' => [
'plugin' => $plugin,
'controller' => $controller,
'action' => 'add'
],
'save' => [
'plugin' => $plugin,
'controller' => $controller,
'action' => 'index',
]
];
$options = Hash::merge($_options, $options);
$url = $options['save'];
if ($rAction = $this->_request->getData('action')) {
list(, $action) = pluginSplit($rAction);
$action = Str::low($action);
if (Arr::key($action, $options)) {
$url = $options[$action];
}
}
return $this->_controller->redirect($url);
} | php | public function redirect(array $options = [])
{
$plugin = $this->_request->getParam('plugin');
$controller = $this->_request->getParam('controller');
$_options = [
'apply' => [],
'savenew' => [
'plugin' => $plugin,
'controller' => $controller,
'action' => 'add'
],
'save' => [
'plugin' => $plugin,
'controller' => $controller,
'action' => 'index',
]
];
$options = Hash::merge($_options, $options);
$url = $options['save'];
if ($rAction = $this->_request->getData('action')) {
list(, $action) = pluginSplit($rAction);
$action = Str::low($action);
if (Arr::key($action, $options)) {
$url = $options[$action];
}
}
return $this->_controller->redirect($url);
} | [
"public",
"function",
"redirect",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"plugin",
"=",
"$",
"this",
"->",
"_request",
"->",
"getParam",
"(",
"'plugin'",
")",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"_request",
"->",
"getParam",
"(",
"'controller'",
")",
";",
"$",
"_options",
"=",
"[",
"'apply'",
"=>",
"[",
"]",
",",
"'savenew'",
"=>",
"[",
"'plugin'",
"=>",
"$",
"plugin",
",",
"'controller'",
"=>",
"$",
"controller",
",",
"'action'",
"=>",
"'add'",
"]",
",",
"'save'",
"=>",
"[",
"'plugin'",
"=>",
"$",
"plugin",
",",
"'controller'",
"=>",
"$",
"controller",
",",
"'action'",
"=>",
"'index'",
",",
"]",
"]",
";",
"$",
"options",
"=",
"Hash",
"::",
"merge",
"(",
"$",
"_options",
",",
"$",
"options",
")",
";",
"$",
"url",
"=",
"$",
"options",
"[",
"'save'",
"]",
";",
"if",
"(",
"$",
"rAction",
"=",
"$",
"this",
"->",
"_request",
"->",
"getData",
"(",
"'action'",
")",
")",
"{",
"list",
"(",
",",
"$",
"action",
")",
"=",
"pluginSplit",
"(",
"$",
"rAction",
")",
";",
"$",
"action",
"=",
"Str",
"::",
"low",
"(",
"$",
"action",
")",
";",
"if",
"(",
"Arr",
"::",
"key",
"(",
"$",
"action",
",",
"$",
"options",
")",
")",
"{",
"$",
"url",
"=",
"$",
"options",
"[",
"$",
"action",
"]",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_controller",
"->",
"redirect",
"(",
"$",
"url",
")",
";",
"}"
] | Redirect by request data.
@param array $options
@return \Cake\Http\Response|null | [
"Redirect",
"by",
"request",
"data",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Controller/Component/AppComponent.php#L69-L100 |
CakeCMS/Core | src/Controller/Component/AppComponent.php | AppComponent.toggleField | public function toggleField(Table $table, $id, $value, $field = 'status')
{
$this->checkIsAjax();
$this->_checkToggleData($id, $value);
$this->_controller->viewBuilder()
->setLayout('ajax')
->setTemplate('toggle')
->setTemplatePath('Common');
$entity = $table->get($id);
$entity->set($field, !(int) $value);
if ($result = $table->save($entity)) {
$this->_controller->set('entity', $result);
$this->_controller->render('toggle');
} else {
throw new \RuntimeException(__d('core', 'Failed toggling field {0} to {1}', $field, $entity->get($field)));
}
} | php | public function toggleField(Table $table, $id, $value, $field = 'status')
{
$this->checkIsAjax();
$this->_checkToggleData($id, $value);
$this->_controller->viewBuilder()
->setLayout('ajax')
->setTemplate('toggle')
->setTemplatePath('Common');
$entity = $table->get($id);
$entity->set($field, !(int) $value);
if ($result = $table->save($entity)) {
$this->_controller->set('entity', $result);
$this->_controller->render('toggle');
} else {
throw new \RuntimeException(__d('core', 'Failed toggling field {0} to {1}', $field, $entity->get($field)));
}
} | [
"public",
"function",
"toggleField",
"(",
"Table",
"$",
"table",
",",
"$",
"id",
",",
"$",
"value",
",",
"$",
"field",
"=",
"'status'",
")",
"{",
"$",
"this",
"->",
"checkIsAjax",
"(",
")",
";",
"$",
"this",
"->",
"_checkToggleData",
"(",
"$",
"id",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"_controller",
"->",
"viewBuilder",
"(",
")",
"->",
"setLayout",
"(",
"'ajax'",
")",
"->",
"setTemplate",
"(",
"'toggle'",
")",
"->",
"setTemplatePath",
"(",
"'Common'",
")",
";",
"$",
"entity",
"=",
"$",
"table",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"entity",
"->",
"set",
"(",
"$",
"field",
",",
"!",
"(",
"int",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"table",
"->",
"save",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"this",
"->",
"_controller",
"->",
"set",
"(",
"'entity'",
",",
"$",
"result",
")",
";",
"$",
"this",
"->",
"_controller",
"->",
"render",
"(",
"'toggle'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"__d",
"(",
"'core'",
",",
"'Failed toggling field {0} to {1}'",
",",
"$",
"field",
",",
"$",
"entity",
"->",
"get",
"(",
"$",
"field",
")",
")",
")",
";",
"}",
"}"
] | Toggle table field value.
@param Table $table
@param int $id
@param string|int $value
@param string $field
@throws \RuntimeException
@throws \Aura\Intl\Exception | [
"Toggle",
"table",
"field",
"value",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Controller/Component/AppComponent.php#L113-L132 |
boekkooi/tactician-amqp | src/Exception/MissingPublisherException.php | MissingPublisherException.forMessage | public static function forMessage(Message $message)
{
$exception = new static('Missing publisher for message of class ' . get_class($message));
$exception->tacticianMessage = $message;
return $exception;
} | php | public static function forMessage(Message $message)
{
$exception = new static('Missing publisher for message of class ' . get_class($message));
$exception->tacticianMessage = $message;
return $exception;
} | [
"public",
"static",
"function",
"forMessage",
"(",
"Message",
"$",
"message",
")",
"{",
"$",
"exception",
"=",
"new",
"static",
"(",
"'Missing publisher for message of class '",
".",
"get_class",
"(",
"$",
"message",
")",
")",
";",
"$",
"exception",
"->",
"tacticianMessage",
"=",
"$",
"message",
";",
"return",
"$",
"exception",
";",
"}"
] | @param Message $message
@return static | [
"@param",
"Message",
"$message"
] | train | https://github.com/boekkooi/tactician-amqp/blob/55cbb8b9e20aab7891e6a6090b248377c599360e/src/Exception/MissingPublisherException.php#L26-L32 |
teneleven/GeolocatorBundle | Extractor/AddressExtractorRegistry.php | AddressExtractorRegistry.getExtractor | public function getExtractor($key)
{
if (!$this->hasExtractor($key)) {
throw new \InvalidArgumentException(sprintf('Address extractor with key "%s" does not exist', $key));
}
return $this->extractors[$key];
} | php | public function getExtractor($key)
{
if (!$this->hasExtractor($key)) {
throw new \InvalidArgumentException(sprintf('Address extractor with key "%s" does not exist', $key));
}
return $this->extractors[$key];
} | [
"public",
"function",
"getExtractor",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasExtractor",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Address extractor with key \"%s\" does not exist'",
",",
"$",
"key",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"extractors",
"[",
"$",
"key",
"]",
";",
"}"
] | Get the extractor for the specified key
@param string $key
@return AddressExtractorInterface
@throws \InvalidArgumentException | [
"Get",
"the",
"extractor",
"for",
"the",
"specified",
"key"
] | train | https://github.com/teneleven/GeolocatorBundle/blob/4ead8e783a91577f2a67aa302b79641d4b9e99ad/Extractor/AddressExtractorRegistry.php#L63-L70 |
jenwachter/html-form | src/Utility/Validator.php | Validator.validate | public function validate($addable)
{
foreach ($addable->elements as $element) {
$classes = class_parents($element);
// no validation needed
if (in_array("HtmlForm\Elements\Parents\Html", $classes)) {
continue;
}
if (in_array("HtmlForm\Abstracts\Addable", $classes)) {
// validate this addable (fieldset)
$moreErrors = $this->validate($element);
} else {
$class = $this->findclass($element);
if ($class == "honeypot") {
$value = $element->getRawValue();
$this->honeypot($value);
continue;
}
// validate this element
$elementErrors = $element->validate();
// add new errors to the list
$this->errors = array_merge($this->errors, $elementErrors);
}
}
return empty($this->errors);
} | php | public function validate($addable)
{
foreach ($addable->elements as $element) {
$classes = class_parents($element);
// no validation needed
if (in_array("HtmlForm\Elements\Parents\Html", $classes)) {
continue;
}
if (in_array("HtmlForm\Abstracts\Addable", $classes)) {
// validate this addable (fieldset)
$moreErrors = $this->validate($element);
} else {
$class = $this->findclass($element);
if ($class == "honeypot") {
$value = $element->getRawValue();
$this->honeypot($value);
continue;
}
// validate this element
$elementErrors = $element->validate();
// add new errors to the list
$this->errors = array_merge($this->errors, $elementErrors);
}
}
return empty($this->errors);
} | [
"public",
"function",
"validate",
"(",
"$",
"addable",
")",
"{",
"foreach",
"(",
"$",
"addable",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"classes",
"=",
"class_parents",
"(",
"$",
"element",
")",
";",
"// no validation needed",
"if",
"(",
"in_array",
"(",
"\"HtmlForm\\Elements\\Parents\\Html\"",
",",
"$",
"classes",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"\"HtmlForm\\Abstracts\\Addable\"",
",",
"$",
"classes",
")",
")",
"{",
"// validate this addable (fieldset)",
"$",
"moreErrors",
"=",
"$",
"this",
"->",
"validate",
"(",
"$",
"element",
")",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"findclass",
"(",
"$",
"element",
")",
";",
"if",
"(",
"$",
"class",
"==",
"\"honeypot\"",
")",
"{",
"$",
"value",
"=",
"$",
"element",
"->",
"getRawValue",
"(",
")",
";",
"$",
"this",
"->",
"honeypot",
"(",
"$",
"value",
")",
";",
"continue",
";",
"}",
"// validate this element",
"$",
"elementErrors",
"=",
"$",
"element",
"->",
"validate",
"(",
")",
";",
"// add new errors to the list",
"$",
"this",
"->",
"errors",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"errors",
",",
"$",
"elementErrors",
")",
";",
"}",
"}",
"return",
"empty",
"(",
"$",
"this",
"->",
"errors",
")",
";",
"}"
] | Runs through the validation required by
each form element.
@param object $addable Object that extends from \HtmlForm\Abstracts\Addable
@return array Found errors | [
"Runs",
"through",
"the",
"validation",
"required",
"by",
"each",
"form",
"element",
"."
] | train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Utility/Validator.php#L30-L67 |
ClanCats/Core | src/classes/CCColor.php | CCColor.create | public static function create( $color )
{
// our return
$rgb = array();
if ( is_array( $color ) )
{
$color = array_values( $color );
$rgb[0] = $color[0];
$rgb[1] = $color[1];
$rgb[2] = $color[2];
}
// parse hex color
elseif ( is_string( $color ) && substr( $color, 0, 1 ) == '#' )
{
$color = substr( $color, 1 );
if( strlen( $color ) == 3 )
{
$rgb[0] = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) );
$rgb[1] = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) );
$rgb[2] = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) );
}
elseif( strlen( $color ) == 6 )
{
$rgb[0] = hexdec( substr( $color, 0, 2 ) );
$rgb[1] = hexdec( substr( $color, 2, 2 ) );
$rgb[2] = hexdec( substr( $color, 4, 2 ) );
}
}
// could not be parsed
else
{
return false;
}
return new static( $rgb );
} | php | public static function create( $color )
{
// our return
$rgb = array();
if ( is_array( $color ) )
{
$color = array_values( $color );
$rgb[0] = $color[0];
$rgb[1] = $color[1];
$rgb[2] = $color[2];
}
// parse hex color
elseif ( is_string( $color ) && substr( $color, 0, 1 ) == '#' )
{
$color = substr( $color, 1 );
if( strlen( $color ) == 3 )
{
$rgb[0] = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) );
$rgb[1] = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) );
$rgb[2] = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) );
}
elseif( strlen( $color ) == 6 )
{
$rgb[0] = hexdec( substr( $color, 0, 2 ) );
$rgb[1] = hexdec( substr( $color, 2, 2 ) );
$rgb[2] = hexdec( substr( $color, 4, 2 ) );
}
}
// could not be parsed
else
{
return false;
}
return new static( $rgb );
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"color",
")",
"{",
"// our return",
"$",
"rgb",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"color",
")",
")",
"{",
"$",
"color",
"=",
"array_values",
"(",
"$",
"color",
")",
";",
"$",
"rgb",
"[",
"0",
"]",
"=",
"$",
"color",
"[",
"0",
"]",
";",
"$",
"rgb",
"[",
"1",
"]",
"=",
"$",
"color",
"[",
"1",
"]",
";",
"$",
"rgb",
"[",
"2",
"]",
"=",
"$",
"color",
"[",
"2",
"]",
";",
"}",
"// parse hex color ",
"elseif",
"(",
"is_string",
"(",
"$",
"color",
")",
"&&",
"substr",
"(",
"$",
"color",
",",
"0",
",",
"1",
")",
"==",
"'#'",
")",
"{",
"$",
"color",
"=",
"substr",
"(",
"$",
"color",
",",
"1",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"color",
")",
"==",
"3",
")",
"{",
"$",
"rgb",
"[",
"0",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"0",
",",
"1",
")",
".",
"substr",
"(",
"$",
"color",
",",
"0",
",",
"1",
")",
")",
";",
"$",
"rgb",
"[",
"1",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"1",
",",
"1",
")",
".",
"substr",
"(",
"$",
"color",
",",
"1",
",",
"1",
")",
")",
";",
"$",
"rgb",
"[",
"2",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"2",
",",
"1",
")",
".",
"substr",
"(",
"$",
"color",
",",
"2",
",",
"1",
")",
")",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"color",
")",
"==",
"6",
")",
"{",
"$",
"rgb",
"[",
"0",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"0",
",",
"2",
")",
")",
";",
"$",
"rgb",
"[",
"1",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"2",
",",
"2",
")",
")",
";",
"$",
"rgb",
"[",
"2",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"4",
",",
"2",
")",
")",
";",
"}",
"}",
"// could not be parsed ",
"else",
"{",
"return",
"false",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"rgb",
")",
";",
"}"
] | parse an color
@param mixed $color | [
"parse",
"an",
"color"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCColor.php#L18-L55 |
phpmob/changmin | src/PhpMob/ChangMinBundle/Controller/TaxonController.php | TaxonController.move | private function move(Request $request, $direction)
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
$this->isGrantedOr403($configuration, ResourceActions::UPDATE);
$resource = $this->findOr404($configuration);
$this->repository->$direction($resource);
/** @var ResourceControllerEvent $event */
$event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource);
if ($event->isStopped() && !$configuration->isHtmlRequest()) {
throw new HttpException($event->getErrorCode(), $event->getMessage());
}
if ($event->isStopped()) {
$this->flashHelper->addFlashFromEvent($configuration, $event);
if ($event->hasResponse()) {
return $event->getResponse();
}
return $this->redirectHandler->redirectToResource($configuration, $resource);
}
try {
$this->resourceUpdateHandler->handle($resource, $configuration, $this->manager);
} catch (UpdateHandlingException $exception) {
if (!$configuration->isHtmlRequest()) {
return $this->viewHandler->handle(
$configuration,
View::create(null, $exception->getApiResponseCode())
);
}
$this->flashHelper->addErrorFlash($configuration, $exception->getFlash());
return $this->redirectHandler->redirectToReferer($configuration);
}
$postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource);
if (!$configuration->isHtmlRequest()) {
$view = $configuration->getParameters()->get('return_content', false) ? View::create(
$resource,
Response::HTTP_OK
) : View::create(null, Response::HTTP_NO_CONTENT);
return $this->viewHandler->handle($configuration, $view);
}
$this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource);
if ($postEvent->hasResponse()) {
return $postEvent->getResponse();
}
return $this->redirectHandler->redirectToResource($configuration, $resource);
} | php | private function move(Request $request, $direction)
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
$this->isGrantedOr403($configuration, ResourceActions::UPDATE);
$resource = $this->findOr404($configuration);
$this->repository->$direction($resource);
/** @var ResourceControllerEvent $event */
$event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource);
if ($event->isStopped() && !$configuration->isHtmlRequest()) {
throw new HttpException($event->getErrorCode(), $event->getMessage());
}
if ($event->isStopped()) {
$this->flashHelper->addFlashFromEvent($configuration, $event);
if ($event->hasResponse()) {
return $event->getResponse();
}
return $this->redirectHandler->redirectToResource($configuration, $resource);
}
try {
$this->resourceUpdateHandler->handle($resource, $configuration, $this->manager);
} catch (UpdateHandlingException $exception) {
if (!$configuration->isHtmlRequest()) {
return $this->viewHandler->handle(
$configuration,
View::create(null, $exception->getApiResponseCode())
);
}
$this->flashHelper->addErrorFlash($configuration, $exception->getFlash());
return $this->redirectHandler->redirectToReferer($configuration);
}
$postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource);
if (!$configuration->isHtmlRequest()) {
$view = $configuration->getParameters()->get('return_content', false) ? View::create(
$resource,
Response::HTTP_OK
) : View::create(null, Response::HTTP_NO_CONTENT);
return $this->viewHandler->handle($configuration, $view);
}
$this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource);
if ($postEvent->hasResponse()) {
return $postEvent->getResponse();
}
return $this->redirectHandler->redirectToResource($configuration, $resource);
} | [
"private",
"function",
"move",
"(",
"Request",
"$",
"request",
",",
"$",
"direction",
")",
"{",
"$",
"configuration",
"=",
"$",
"this",
"->",
"requestConfigurationFactory",
"->",
"create",
"(",
"$",
"this",
"->",
"metadata",
",",
"$",
"request",
")",
";",
"$",
"this",
"->",
"isGrantedOr403",
"(",
"$",
"configuration",
",",
"ResourceActions",
"::",
"UPDATE",
")",
";",
"$",
"resource",
"=",
"$",
"this",
"->",
"findOr404",
"(",
"$",
"configuration",
")",
";",
"$",
"this",
"->",
"repository",
"->",
"$",
"direction",
"(",
"$",
"resource",
")",
";",
"/** @var ResourceControllerEvent $event */",
"$",
"event",
"=",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatchPreEvent",
"(",
"ResourceActions",
"::",
"UPDATE",
",",
"$",
"configuration",
",",
"$",
"resource",
")",
";",
"if",
"(",
"$",
"event",
"->",
"isStopped",
"(",
")",
"&&",
"!",
"$",
"configuration",
"->",
"isHtmlRequest",
"(",
")",
")",
"{",
"throw",
"new",
"HttpException",
"(",
"$",
"event",
"->",
"getErrorCode",
"(",
")",
",",
"$",
"event",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"event",
"->",
"isStopped",
"(",
")",
")",
"{",
"$",
"this",
"->",
"flashHelper",
"->",
"addFlashFromEvent",
"(",
"$",
"configuration",
",",
"$",
"event",
")",
";",
"if",
"(",
"$",
"event",
"->",
"hasResponse",
"(",
")",
")",
"{",
"return",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectHandler",
"->",
"redirectToResource",
"(",
"$",
"configuration",
",",
"$",
"resource",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"resourceUpdateHandler",
"->",
"handle",
"(",
"$",
"resource",
",",
"$",
"configuration",
",",
"$",
"this",
"->",
"manager",
")",
";",
"}",
"catch",
"(",
"UpdateHandlingException",
"$",
"exception",
")",
"{",
"if",
"(",
"!",
"$",
"configuration",
"->",
"isHtmlRequest",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"viewHandler",
"->",
"handle",
"(",
"$",
"configuration",
",",
"View",
"::",
"create",
"(",
"null",
",",
"$",
"exception",
"->",
"getApiResponseCode",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"flashHelper",
"->",
"addErrorFlash",
"(",
"$",
"configuration",
",",
"$",
"exception",
"->",
"getFlash",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirectHandler",
"->",
"redirectToReferer",
"(",
"$",
"configuration",
")",
";",
"}",
"$",
"postEvent",
"=",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatchPostEvent",
"(",
"ResourceActions",
"::",
"UPDATE",
",",
"$",
"configuration",
",",
"$",
"resource",
")",
";",
"if",
"(",
"!",
"$",
"configuration",
"->",
"isHtmlRequest",
"(",
")",
")",
"{",
"$",
"view",
"=",
"$",
"configuration",
"->",
"getParameters",
"(",
")",
"->",
"get",
"(",
"'return_content'",
",",
"false",
")",
"?",
"View",
"::",
"create",
"(",
"$",
"resource",
",",
"Response",
"::",
"HTTP_OK",
")",
":",
"View",
"::",
"create",
"(",
"null",
",",
"Response",
"::",
"HTTP_NO_CONTENT",
")",
";",
"return",
"$",
"this",
"->",
"viewHandler",
"->",
"handle",
"(",
"$",
"configuration",
",",
"$",
"view",
")",
";",
"}",
"$",
"this",
"->",
"flashHelper",
"->",
"addSuccessFlash",
"(",
"$",
"configuration",
",",
"ResourceActions",
"::",
"UPDATE",
",",
"$",
"resource",
")",
";",
"if",
"(",
"$",
"postEvent",
"->",
"hasResponse",
"(",
")",
")",
"{",
"return",
"$",
"postEvent",
"->",
"getResponse",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectHandler",
"->",
"redirectToResource",
"(",
"$",
"configuration",
",",
"$",
"resource",
")",
";",
"}"
] | @param Request $request
@param $direction
@return Response | [
"@param",
"Request",
"$request",
"@param",
"$direction"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Controller/TaxonController.php#L35-L93 |
webforge-labs/psc-cms | lib/Psc/Net/ServiceErrorPackage.php | ServiceErrorPackage.invalidArgument | public function invalidArgument($method, $argumentName, $argumentValue, $msg = '') {
return HTTPException::BadRequest('Falscher Parameter '.Code::varInfo($argumentValue).' für '.$method.'( :$'.$argumentName." )\n".$msg.' in Controller: '.Code::getClass($this->controller));
} | php | public function invalidArgument($method, $argumentName, $argumentValue, $msg = '') {
return HTTPException::BadRequest('Falscher Parameter '.Code::varInfo($argumentValue).' für '.$method.'( :$'.$argumentName." )\n".$msg.' in Controller: '.Code::getClass($this->controller));
} | [
"public",
"function",
"invalidArgument",
"(",
"$",
"method",
",",
"$",
"argumentName",
",",
"$",
"argumentValue",
",",
"$",
"msg",
"=",
"''",
")",
"{",
"return",
"HTTPException",
"::",
"BadRequest",
"(",
"'Falscher Parameter '",
".",
"Code",
"::",
"varInfo",
"(",
"$",
"argumentValue",
")",
".",
"' für '.",
"$",
"m",
"ethod.",
"'",
"( :$'.",
"$",
"a",
"rgumentName.",
"\"",
" )\\n\".",
"$",
"m",
"sg.",
"'",
" in Controller: '.",
"C",
"ode:",
":g",
"etClass(",
"$",
"t",
"his-",
">c",
"ontroller)",
")",
";",
"",
"}"
] | FEHLER: Ein Parameter oder eine Subresource einer Methode ist nicht korrekt gewesen
die Syntax des Requests ist falsch
@param string $method
@param string $argument | [
"FEHLER",
":",
"Ein",
"Parameter",
"oder",
"eine",
"Subresource",
"einer",
"Methode",
"ist",
"nicht",
"korrekt",
"gewesen"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Net/ServiceErrorPackage.php#L33-L35 |
webforge-labs/psc-cms | lib/Psc/Net/ServiceErrorPackage.php | ServiceErrorPackage.validationResponse | public function validationResponse(\Psc\Form\ValidatorExceptionList $list, $format = ServiceResponse::JSON, MetadataGenerator $metadataGenerator = NULL) {
if ($format === ServiceResponse::JSON) {
$body = (object) array('errors'=>array());
foreach ($list->getExceptions() as $validatorException) {
$body->errors[$validatorException->field] = $validatorException->getMessage();
}
return HTTPResponseException::BadRequest(json_encode($body), NULL, array('Content-Type'=>'application/json'));
} else {
$metadataGenerator = $metadataGenerator ?: new MetadataGenerator();
return HTTPException::BadRequest(
$list->getMessage(),
$list,
array_merge(
array('Content-Type'=>'text/html'),
$metadataGenerator->validationList($list)->toHeaders()
)
);
}
} | php | public function validationResponse(\Psc\Form\ValidatorExceptionList $list, $format = ServiceResponse::JSON, MetadataGenerator $metadataGenerator = NULL) {
if ($format === ServiceResponse::JSON) {
$body = (object) array('errors'=>array());
foreach ($list->getExceptions() as $validatorException) {
$body->errors[$validatorException->field] = $validatorException->getMessage();
}
return HTTPResponseException::BadRequest(json_encode($body), NULL, array('Content-Type'=>'application/json'));
} else {
$metadataGenerator = $metadataGenerator ?: new MetadataGenerator();
return HTTPException::BadRequest(
$list->getMessage(),
$list,
array_merge(
array('Content-Type'=>'text/html'),
$metadataGenerator->validationList($list)->toHeaders()
)
);
}
} | [
"public",
"function",
"validationResponse",
"(",
"\\",
"Psc",
"\\",
"Form",
"\\",
"ValidatorExceptionList",
"$",
"list",
",",
"$",
"format",
"=",
"ServiceResponse",
"::",
"JSON",
",",
"MetadataGenerator",
"$",
"metadataGenerator",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"format",
"===",
"ServiceResponse",
"::",
"JSON",
")",
"{",
"$",
"body",
"=",
"(",
"object",
")",
"array",
"(",
"'errors'",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"list",
"->",
"getExceptions",
"(",
")",
"as",
"$",
"validatorException",
")",
"{",
"$",
"body",
"->",
"errors",
"[",
"$",
"validatorException",
"->",
"field",
"]",
"=",
"$",
"validatorException",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"HTTPResponseException",
"::",
"BadRequest",
"(",
"json_encode",
"(",
"$",
"body",
")",
",",
"NULL",
",",
"array",
"(",
"'Content-Type'",
"=>",
"'application/json'",
")",
")",
";",
"}",
"else",
"{",
"$",
"metadataGenerator",
"=",
"$",
"metadataGenerator",
"?",
":",
"new",
"MetadataGenerator",
"(",
")",
";",
"return",
"HTTPException",
"::",
"BadRequest",
"(",
"$",
"list",
"->",
"getMessage",
"(",
")",
",",
"$",
"list",
",",
"array_merge",
"(",
"array",
"(",
"'Content-Type'",
"=>",
"'text/html'",
")",
",",
"$",
"metadataGenerator",
"->",
"validationList",
"(",
"$",
"list",
")",
"->",
"toHeaders",
"(",
")",
")",
")",
";",
"}",
"}"
] | Throws an ValidationResponse
it handles the JSON case and the HTML case
@param ValidatorException[]
@param const $format im moment nur JSON oder HTML
@return HTTPException | [
"Throws",
"an",
"ValidationResponse"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Net/ServiceErrorPackage.php#L58-L79 |
webforge-labs/psc-cms | lib/Psc/Net/ServiceErrorPackage.php | ServiceErrorPackage.resourceNotFound | public function resourceNotFound($method, $resourceType, $argumentValues, \Exception $e = NULL) {
return HTTPException::NotFound(
sprintf("Die Resource '%s' konnte nicht mit den Parametern %s gefunden werden. Der Request konnte nicht vollständig ausgeführt werden. Möglicherweise ist die Resource nicht mehr vorhanden.", $resourceType, Code::varInfo($argumentValues)),
$e
);
} | php | public function resourceNotFound($method, $resourceType, $argumentValues, \Exception $e = NULL) {
return HTTPException::NotFound(
sprintf("Die Resource '%s' konnte nicht mit den Parametern %s gefunden werden. Der Request konnte nicht vollständig ausgeführt werden. Möglicherweise ist die Resource nicht mehr vorhanden.", $resourceType, Code::varInfo($argumentValues)),
$e
);
} | [
"public",
"function",
"resourceNotFound",
"(",
"$",
"method",
",",
"$",
"resourceType",
",",
"$",
"argumentValues",
",",
"\\",
"Exception",
"$",
"e",
"=",
"NULL",
")",
"{",
"return",
"HTTPException",
"::",
"NotFound",
"(",
"sprintf",
"(",
"\"Die Resource '%s' konnte nicht mit den Parametern %s gefunden werden. Der Request konnte nicht vollständig ausgeführt werden. Möglicherweise ist die Resource nicht mehr vorhanden.\", $",
"r",
"s",
"ourceType, C",
"o",
"e::v",
"ar",
"Info($a",
"r",
"g",
"umentValues)),",
"",
"",
"",
"$",
"e",
")",
";",
"}"
] | FEHLER: Eine Resource die zum ausführen des Requests benötigt wird, wurde niicht gefunden
z. B. Ein PUT Request wird für ein Entity gemacht welches nicht mehr vorhanden ist
für ein Entity soll ein Formular geladen werden, und der Identifier ergibt kein ergebnis in der Datenbank | [
"FEHLER",
":",
"Eine",
"Resource",
"die",
"zum",
"ausführen",
"des",
"Requests",
"benötigt",
"wird",
"wurde",
"niicht",
"gefunden"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Net/ServiceErrorPackage.php#L87-L92 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.findUser | final public function findUser(Userinfo $userinfo)
{
$userloopup = $this->lookupUser($userinfo);
if ($userloopup instanceof Userinfo) {
$user = $this->getUser($userloopup);
} else {
$user = $this->getUser($userinfo);
if ($user instanceof Userinfo) {
/**
* TODO: determine if the update lookup should really be here or not.
*/
$this->updateLookup($user, $userinfo);
}
}
return $user;
} | php | final public function findUser(Userinfo $userinfo)
{
$userloopup = $this->lookupUser($userinfo);
if ($userloopup instanceof Userinfo) {
$user = $this->getUser($userloopup);
} else {
$user = $this->getUser($userinfo);
if ($user instanceof Userinfo) {
/**
* TODO: determine if the update lookup should really be here or not.
*/
$this->updateLookup($user, $userinfo);
}
}
return $user;
} | [
"final",
"public",
"function",
"findUser",
"(",
"Userinfo",
"$",
"userinfo",
")",
"{",
"$",
"userloopup",
"=",
"$",
"this",
"->",
"lookupUser",
"(",
"$",
"userinfo",
")",
";",
"if",
"(",
"$",
"userloopup",
"instanceof",
"Userinfo",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
"$",
"userloopup",
")",
";",
"}",
"else",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
"$",
"userinfo",
")",
";",
"if",
"(",
"$",
"user",
"instanceof",
"Userinfo",
")",
"{",
"/**\n\t\t\t\t * TODO: determine if the update lookup should really be here or not.\n\t\t\t\t */",
"$",
"this",
"->",
"updateLookup",
"(",
"$",
"user",
",",
"$",
"userinfo",
")",
";",
"}",
"}",
"return",
"$",
"user",
";",
"}"
] | Gets the userinfo from the JFusion integrated software. it uses the lookup function
@param Userinfo $userinfo contains the object of the user
@return null|Userinfo Userinfo containing the user information | [
"Gets",
"the",
"userinfo",
"from",
"the",
"JFusion",
"integrated",
"software",
".",
"it",
"uses",
"the",
"lookup",
"function"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L74-L89 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.getUserIdentifier | public final function getUserIdentifier(Userinfo &$userinfo, $username_col, $email_col, $userid_col, $lowerEmail = true)
{
$login_identifier = $this->params->get('login_identifier', 1);
if ($this->getJname() == $userinfo->getJname() && $userinfo->userid != null) {
$login_identifier = 4;
} elseif ($username_col == null) {
$login_identifier = 2;
}
switch ($login_identifier) {
default:
case 1:
// username
$identifier = $userinfo->username;
$identifier_type = $username_col;
break;
case 2:
// email
$identifier = $userinfo->email;
$identifier_type = $email_col;
break;
case 3:
// username or email
$pattern = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i';
if (preg_match($pattern, $userinfo->username)) {
$identifier_type = $email_col;
$identifier = $userinfo->email;
} else {
$identifier_type = $username_col;
$identifier = $userinfo->username;
}
break;
case 4:
// userid
$identifier_type = $userid_col;
$identifier = $userinfo->userid;
break;
}
if ($lowerEmail && $identifier_type == $email_col) {
$identifier_type = 'LOWER(' . $identifier_type . ')';
$identifier = strtolower($identifier);
}
return array($identifier_type, $identifier);
} | php | public final function getUserIdentifier(Userinfo &$userinfo, $username_col, $email_col, $userid_col, $lowerEmail = true)
{
$login_identifier = $this->params->get('login_identifier', 1);
if ($this->getJname() == $userinfo->getJname() && $userinfo->userid != null) {
$login_identifier = 4;
} elseif ($username_col == null) {
$login_identifier = 2;
}
switch ($login_identifier) {
default:
case 1:
// username
$identifier = $userinfo->username;
$identifier_type = $username_col;
break;
case 2:
// email
$identifier = $userinfo->email;
$identifier_type = $email_col;
break;
case 3:
// username or email
$pattern = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i';
if (preg_match($pattern, $userinfo->username)) {
$identifier_type = $email_col;
$identifier = $userinfo->email;
} else {
$identifier_type = $username_col;
$identifier = $userinfo->username;
}
break;
case 4:
// userid
$identifier_type = $userid_col;
$identifier = $userinfo->userid;
break;
}
if ($lowerEmail && $identifier_type == $email_col) {
$identifier_type = 'LOWER(' . $identifier_type . ')';
$identifier = strtolower($identifier);
}
return array($identifier_type, $identifier);
} | [
"public",
"final",
"function",
"getUserIdentifier",
"(",
"Userinfo",
"&",
"$",
"userinfo",
",",
"$",
"username_col",
",",
"$",
"email_col",
",",
"$",
"userid_col",
",",
"$",
"lowerEmail",
"=",
"true",
")",
"{",
"$",
"login_identifier",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'login_identifier'",
",",
"1",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
"==",
"$",
"userinfo",
"->",
"getJname",
"(",
")",
"&&",
"$",
"userinfo",
"->",
"userid",
"!=",
"null",
")",
"{",
"$",
"login_identifier",
"=",
"4",
";",
"}",
"elseif",
"(",
"$",
"username_col",
"==",
"null",
")",
"{",
"$",
"login_identifier",
"=",
"2",
";",
"}",
"switch",
"(",
"$",
"login_identifier",
")",
"{",
"default",
":",
"case",
"1",
":",
"// username",
"$",
"identifier",
"=",
"$",
"userinfo",
"->",
"username",
";",
"$",
"identifier_type",
"=",
"$",
"username_col",
";",
"break",
";",
"case",
"2",
":",
"// email",
"$",
"identifier",
"=",
"$",
"userinfo",
"->",
"email",
";",
"$",
"identifier_type",
"=",
"$",
"email_col",
";",
"break",
";",
"case",
"3",
":",
"// username or email",
"$",
"pattern",
"=",
"'/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"userinfo",
"->",
"username",
")",
")",
"{",
"$",
"identifier_type",
"=",
"$",
"email_col",
";",
"$",
"identifier",
"=",
"$",
"userinfo",
"->",
"email",
";",
"}",
"else",
"{",
"$",
"identifier_type",
"=",
"$",
"username_col",
";",
"$",
"identifier",
"=",
"$",
"userinfo",
"->",
"username",
";",
"}",
"break",
";",
"case",
"4",
":",
"// userid",
"$",
"identifier_type",
"=",
"$",
"userid_col",
";",
"$",
"identifier",
"=",
"$",
"userinfo",
"->",
"userid",
";",
"break",
";",
"}",
"if",
"(",
"$",
"lowerEmail",
"&&",
"$",
"identifier_type",
"==",
"$",
"email_col",
")",
"{",
"$",
"identifier_type",
"=",
"'LOWER('",
".",
"$",
"identifier_type",
".",
"')'",
";",
"$",
"identifier",
"=",
"strtolower",
"(",
"$",
"identifier",
")",
";",
"}",
"return",
"array",
"(",
"$",
"identifier_type",
",",
"$",
"identifier",
")",
";",
"}"
] | Returns the identifier and identifier_type for getUser
@param Userinfo &$userinfo object with user identifying information
@param string $username_col Database column for username
@param string $email_col Database column for email
@param string $userid_col Database column for userid
@param bool $lowerEmail Boolean to lowercase emails for comparison
@return array array($identifier, $identifier_type) | [
"Returns",
"the",
"identifier",
"and",
"identifier_type",
"for",
"getUser"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L102-L145 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.destroySession | function destroySession(Userinfo $userinfo, $options)
{
$result = array(LogLevel::ERROR => array(), LogLevel::DEBUG => array());
return $result;
} | php | function destroySession(Userinfo $userinfo, $options)
{
$result = array(LogLevel::ERROR => array(), LogLevel::DEBUG => array());
return $result;
} | [
"function",
"destroySession",
"(",
"Userinfo",
"$",
"userinfo",
",",
"$",
"options",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"LogLevel",
"::",
"ERROR",
"=>",
"array",
"(",
")",
",",
"LogLevel",
"::",
"DEBUG",
"=>",
"array",
"(",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Function that automatically logs out the user from the integrated software
$result['error'] (contains any error messages)
$result[LogLevel::DEBUG] (contains information on what was done)
@param Userinfo $userinfo contains the userinfo
@param array $options contains Array with the login options, such as remember_me
@return array result Array containing the result of the session destroy | [
"Function",
"that",
"automatically",
"logs",
"out",
"the",
"user",
"from",
"the",
"integrated",
"software",
"$result",
"[",
"error",
"]",
"(",
"contains",
"any",
"error",
"messages",
")",
"$result",
"[",
"LogLevel",
"::",
"DEBUG",
"]",
"(",
"contains",
"information",
"on",
"what",
"was",
"done",
")"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L157-L161 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.createSession | function createSession(Userinfo $userinfo, $options)
{
$result = array(LogLevel::ERROR => array(), LogLevel::DEBUG => array());
return $result;
} | php | function createSession(Userinfo $userinfo, $options)
{
$result = array(LogLevel::ERROR => array(), LogLevel::DEBUG => array());
return $result;
} | [
"function",
"createSession",
"(",
"Userinfo",
"$",
"userinfo",
",",
"$",
"options",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"LogLevel",
"::",
"ERROR",
"=>",
"array",
"(",
")",
",",
"LogLevel",
"::",
"DEBUG",
"=>",
"array",
"(",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Function that automatically logs in the user from the integrated software
$result['error'] (contains any error messages)
$result[LogLevel::DEBUG] (contains information on what was done)
@param Userinfo $userinfo contains the userinfo
@param array $options contains array with the login options, such as remember_me *
@return array result Array containing the result of the session creation | [
"Function",
"that",
"automatically",
"logs",
"in",
"the",
"user",
"from",
"the",
"integrated",
"software",
"$result",
"[",
"error",
"]",
"(",
"contains",
"any",
"error",
"messages",
")",
"$result",
"[",
"LogLevel",
"::",
"DEBUG",
"]",
"(",
"contains",
"information",
"on",
"what",
"was",
"done",
")"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L173-L177 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.updateUser | function updateUser(Userinfo $userinfo, $overwrite = 0)
{
//get the user
$existinguser = $this->getUser($userinfo);
if ($existinguser instanceof Userinfo) {
$changed = false;
//a matching user has been found
$this->debugger->addDebug(Text::_('USER_DATA_FOUND'));
if($this->doUpdateEmail($userinfo, $existinguser, $overwrite)) {
$changed = true;
}
if($this->doUpdatePassword($userinfo, $existinguser)) {
$changed = true;
}
if ($this->doUpdateBlock($userinfo, $existinguser, $overwrite)) {
$changed = true;
}
if($this->doUpdateActivate($userinfo, $existinguser, $overwrite)) {
$changed = true;
}
if($this->doUpdateUsergroup($userinfo, $existinguser)) {
$changed = true;
}
if($this->doUserLanguage($userinfo, $existinguser)) {
$changed = true;
}
if ($this->debugger->isEmpty('error')) {
if ($changed == true) {
$this->debugger->set('action', 'updated');
//let's get updated information
$existinguser = $this->getUser($userinfo);
} else {
$this->debugger->set('action', 'unchanged');
}
}
} else {
$existinguser = $this->createUser($userinfo);
$this->debugger->set('action', 'created');
}
return $existinguser;
} | php | function updateUser(Userinfo $userinfo, $overwrite = 0)
{
//get the user
$existinguser = $this->getUser($userinfo);
if ($existinguser instanceof Userinfo) {
$changed = false;
//a matching user has been found
$this->debugger->addDebug(Text::_('USER_DATA_FOUND'));
if($this->doUpdateEmail($userinfo, $existinguser, $overwrite)) {
$changed = true;
}
if($this->doUpdatePassword($userinfo, $existinguser)) {
$changed = true;
}
if ($this->doUpdateBlock($userinfo, $existinguser, $overwrite)) {
$changed = true;
}
if($this->doUpdateActivate($userinfo, $existinguser, $overwrite)) {
$changed = true;
}
if($this->doUpdateUsergroup($userinfo, $existinguser)) {
$changed = true;
}
if($this->doUserLanguage($userinfo, $existinguser)) {
$changed = true;
}
if ($this->debugger->isEmpty('error')) {
if ($changed == true) {
$this->debugger->set('action', 'updated');
//let's get updated information
$existinguser = $this->getUser($userinfo);
} else {
$this->debugger->set('action', 'unchanged');
}
}
} else {
$existinguser = $this->createUser($userinfo);
$this->debugger->set('action', 'created');
}
return $existinguser;
} | [
"function",
"updateUser",
"(",
"Userinfo",
"$",
"userinfo",
",",
"$",
"overwrite",
"=",
"0",
")",
"{",
"//get the user",
"$",
"existinguser",
"=",
"$",
"this",
"->",
"getUser",
"(",
"$",
"userinfo",
")",
";",
"if",
"(",
"$",
"existinguser",
"instanceof",
"Userinfo",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"//a matching user has been found",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'USER_DATA_FOUND'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"doUpdateEmail",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
",",
"$",
"overwrite",
")",
")",
"{",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"doUpdatePassword",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
")",
"{",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"doUpdateBlock",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
",",
"$",
"overwrite",
")",
")",
"{",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"doUpdateActivate",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
",",
"$",
"overwrite",
")",
")",
"{",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"doUpdateUsergroup",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
")",
"{",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"doUserLanguage",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
")",
"{",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"debugger",
"->",
"isEmpty",
"(",
"'error'",
")",
")",
"{",
"if",
"(",
"$",
"changed",
"==",
"true",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"set",
"(",
"'action'",
",",
"'updated'",
")",
";",
"//let's get updated information",
"$",
"existinguser",
"=",
"$",
"this",
"->",
"getUser",
"(",
"$",
"userinfo",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"debugger",
"->",
"set",
"(",
"'action'",
",",
"'unchanged'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"existinguser",
"=",
"$",
"this",
"->",
"createUser",
"(",
"$",
"userinfo",
")",
";",
"$",
"this",
"->",
"debugger",
"->",
"set",
"(",
"'action'",
",",
"'created'",
")",
";",
"}",
"return",
"$",
"existinguser",
";",
"}"
] | Updates or creates a user for the integrated software. This allows JFusion to have external software as slave for user management
$result['error'] (contains any error messages)
$result['userinfo'] (contains the userinfo object of the integrated software user)
@param Userinfo $userinfo contains the userinfo
@param int $overwrite determines if the userinfo can be overwritten
@throws RuntimeException
@return Userinfo|null returns updated userinfo | [
"Updates",
"or",
"creates",
"a",
"user",
"for",
"the",
"integrated",
"software",
".",
"This",
"allows",
"JFusion",
"to",
"have",
"external",
"software",
"as",
"slave",
"for",
"user",
"management",
"$result",
"[",
"error",
"]",
"(",
"contains",
"any",
"error",
"messages",
")",
"$result",
"[",
"userinfo",
"]",
"(",
"contains",
"the",
"userinfo",
"object",
"of",
"the",
"integrated",
"software",
"user",
")"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L216-L263 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.doUpdateUsergroup | function doUpdateUsergroup(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
//check for advanced usergroup sync
if (!$userinfo->block && empty($userinfo->activation)) {
if (Groups::isUpdate($this->getJname())) {
try {
$usergroup_updated = $this->executeUpdateUsergroup($userinfo, $existinguser);
if ($usergroup_updated) {
$changed = true;
} else {
$this->debugger->addDebug(Text::_('SKIPPED_GROUP_UPDATE') . ':' . Text::_('GROUP_VALID'));
}
} catch (Exception $e) {
$this->debugger->addError(Text::_('GROUP_UPDATE_ERROR') . ' ' . $e->getMessage());
}
}
}
return $changed;
} | php | function doUpdateUsergroup(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
//check for advanced usergroup sync
if (!$userinfo->block && empty($userinfo->activation)) {
if (Groups::isUpdate($this->getJname())) {
try {
$usergroup_updated = $this->executeUpdateUsergroup($userinfo, $existinguser);
if ($usergroup_updated) {
$changed = true;
} else {
$this->debugger->addDebug(Text::_('SKIPPED_GROUP_UPDATE') . ':' . Text::_('GROUP_VALID'));
}
} catch (Exception $e) {
$this->debugger->addError(Text::_('GROUP_UPDATE_ERROR') . ' ' . $e->getMessage());
}
}
}
return $changed;
} | [
"function",
"doUpdateUsergroup",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"&",
"$",
"existinguser",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"//check for advanced usergroup sync",
"if",
"(",
"!",
"$",
"userinfo",
"->",
"block",
"&&",
"empty",
"(",
"$",
"userinfo",
"->",
"activation",
")",
")",
"{",
"if",
"(",
"Groups",
"::",
"isUpdate",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
")",
"{",
"try",
"{",
"$",
"usergroup_updated",
"=",
"$",
"this",
"->",
"executeUpdateUsergroup",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"if",
"(",
"$",
"usergroup_updated",
")",
"{",
"$",
"changed",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'SKIPPED_GROUP_UPDATE'",
")",
".",
"':'",
".",
"Text",
"::",
"_",
"(",
"'GROUP_VALID'",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'GROUP_UPDATE_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"changed",
";",
"}"
] | @param Userinfo $userinfo
@param Userinfo $existinguser
@return boolean return true if changed | [
"@param",
"Userinfo",
"$userinfo",
"@param",
"Userinfo",
"$existinguser"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L271-L290 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.executeUpdateUsergroup | function executeUpdateUsergroup(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
$usergroups = $this->getCorrectUserGroups($userinfo);
if (!$this->compareUserGroups($existinguser, $usergroups)) {
$this->updateUsergroup($userinfo, $existinguser);
$changed = true;
}
return $changed;
} | php | function executeUpdateUsergroup(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
$usergroups = $this->getCorrectUserGroups($userinfo);
if (!$this->compareUserGroups($existinguser, $usergroups)) {
$this->updateUsergroup($userinfo, $existinguser);
$changed = true;
}
return $changed;
} | [
"function",
"executeUpdateUsergroup",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"&",
"$",
"existinguser",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"$",
"usergroups",
"=",
"$",
"this",
"->",
"getCorrectUserGroups",
"(",
"$",
"userinfo",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"compareUserGroups",
"(",
"$",
"existinguser",
",",
"$",
"usergroups",
")",
")",
"{",
"$",
"this",
"->",
"updateUsergroup",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"return",
"$",
"changed",
";",
"}"
] | Function that determines if the usergroup needs to be updated and executes updateUsergroup if it does
@param Userinfo $userinfo Object containing the new userinfo
@param Userinfo &$existinguser Object containing the old userinfo
@throws RuntimeException
@return boolean Whether updateUsergroup was executed or not | [
"Function",
"that",
"determines",
"if",
"the",
"usergroup",
"needs",
"to",
"be",
"updated",
"and",
"executes",
"updateUsergroup",
"if",
"it",
"does"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L302-L311 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.doUpdatePassword | function doUpdatePassword(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
if (!empty($userinfo->password_clear) && strlen($userinfo->password_clear) != 32) {
// add password_clear to existinguser for the Joomla helper routines
$existinguser->password_clear = $userinfo->password_clear;
//check if the password needs to be updated
try {
$model = Factory::getAuth($this->getJname());
if ($model->checkPassword($existinguser) !== true) {
try {
$this->updatePassword($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('PASSWORD_UPDATE_ERROR') . ' ' . $e->getMessage());
}
} else {
$this->debugger->addDebug(Text::_('SKIPPED_PASSWORD_UPDATE') . ':' . Text::_('PASSWORD_VALID'));
}
} catch (Exception $e) {
$this->debugger->addError(Text::_('SKIPPED_PASSWORD_UPDATE') . ':' . $e->getMessage());
}
} else {
$this->debugger->addDebug(Text::_('SKIPPED_PASSWORD_UPDATE') . ': ' . Text::_('PASSWORD_UNAVAILABLE'));
}
return $changed;
} | php | function doUpdatePassword(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
if (!empty($userinfo->password_clear) && strlen($userinfo->password_clear) != 32) {
// add password_clear to existinguser for the Joomla helper routines
$existinguser->password_clear = $userinfo->password_clear;
//check if the password needs to be updated
try {
$model = Factory::getAuth($this->getJname());
if ($model->checkPassword($existinguser) !== true) {
try {
$this->updatePassword($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('PASSWORD_UPDATE_ERROR') . ' ' . $e->getMessage());
}
} else {
$this->debugger->addDebug(Text::_('SKIPPED_PASSWORD_UPDATE') . ':' . Text::_('PASSWORD_VALID'));
}
} catch (Exception $e) {
$this->debugger->addError(Text::_('SKIPPED_PASSWORD_UPDATE') . ':' . $e->getMessage());
}
} else {
$this->debugger->addDebug(Text::_('SKIPPED_PASSWORD_UPDATE') . ': ' . Text::_('PASSWORD_UNAVAILABLE'));
}
return $changed;
} | [
"function",
"doUpdatePassword",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"&",
"$",
"existinguser",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"userinfo",
"->",
"password_clear",
")",
"&&",
"strlen",
"(",
"$",
"userinfo",
"->",
"password_clear",
")",
"!=",
"32",
")",
"{",
"// add password_clear to existinguser for the Joomla helper routines",
"$",
"existinguser",
"->",
"password_clear",
"=",
"$",
"userinfo",
"->",
"password_clear",
";",
"//check if the password needs to be updated",
"try",
"{",
"$",
"model",
"=",
"Factory",
"::",
"getAuth",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
";",
"if",
"(",
"$",
"model",
"->",
"checkPassword",
"(",
"$",
"existinguser",
")",
"!==",
"true",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"updatePassword",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'PASSWORD_UPDATE_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'SKIPPED_PASSWORD_UPDATE'",
")",
".",
"':'",
".",
"Text",
"::",
"_",
"(",
"'PASSWORD_VALID'",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'SKIPPED_PASSWORD_UPDATE'",
")",
".",
"':'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'SKIPPED_PASSWORD_UPDATE'",
")",
".",
"': '",
".",
"Text",
"::",
"_",
"(",
"'PASSWORD_UNAVAILABLE'",
")",
")",
";",
"}",
"return",
"$",
"changed",
";",
"}"
] | @param Userinfo $userinfo
@param Userinfo $existinguser
@return boolean return true if changed | [
"@param",
"Userinfo",
"$userinfo",
"@param",
"Userinfo",
"$existinguser"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L319-L346 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.doUpdateEmail | function doUpdateEmail(Userinfo $userinfo, Userinfo &$existinguser, $overwrite)
{
$changed = false;
if (strtolower($existinguser->email) != strtolower($userinfo->email)) {
$this->debugger->addDebug(Text::_('EMAIL_CONFLICT'));
$update_email = $this->params->get('update_email', false);
if ($update_email || $overwrite) {
$this->debugger->addDebug(Text::_('EMAIL_CONFLICT_OVERWITE_ENABLED'));
try {
$this->updateEmail($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('EMAIL_UPDATE_ERROR') . ' ' . $e->getMessage());
}
} else {
//return a email conflict
$this->debugger->addDebug(Text::_('EMAIL_CONFLICT_OVERWITE_DISABLED'));
$this->debugger->set('userinfo', $existinguser);
throw new RuntimeException(Text::_('EMAIL') . ' ' . Text::_('CONFLICT') . ': ' . $existinguser->email . ' -> ' . $userinfo->email);
}
}
return $changed;
} | php | function doUpdateEmail(Userinfo $userinfo, Userinfo &$existinguser, $overwrite)
{
$changed = false;
if (strtolower($existinguser->email) != strtolower($userinfo->email)) {
$this->debugger->addDebug(Text::_('EMAIL_CONFLICT'));
$update_email = $this->params->get('update_email', false);
if ($update_email || $overwrite) {
$this->debugger->addDebug(Text::_('EMAIL_CONFLICT_OVERWITE_ENABLED'));
try {
$this->updateEmail($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('EMAIL_UPDATE_ERROR') . ' ' . $e->getMessage());
}
} else {
//return a email conflict
$this->debugger->addDebug(Text::_('EMAIL_CONFLICT_OVERWITE_DISABLED'));
$this->debugger->set('userinfo', $existinguser);
throw new RuntimeException(Text::_('EMAIL') . ' ' . Text::_('CONFLICT') . ': ' . $existinguser->email . ' -> ' . $userinfo->email);
}
}
return $changed;
} | [
"function",
"doUpdateEmail",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"&",
"$",
"existinguser",
",",
"$",
"overwrite",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"if",
"(",
"strtolower",
"(",
"$",
"existinguser",
"->",
"email",
")",
"!=",
"strtolower",
"(",
"$",
"userinfo",
"->",
"email",
")",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'EMAIL_CONFLICT'",
")",
")",
";",
"$",
"update_email",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'update_email'",
",",
"false",
")",
";",
"if",
"(",
"$",
"update_email",
"||",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'EMAIL_CONFLICT_OVERWITE_ENABLED'",
")",
")",
";",
"try",
"{",
"$",
"this",
"->",
"updateEmail",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'EMAIL_UPDATE_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"//return a email conflict",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'EMAIL_CONFLICT_OVERWITE_DISABLED'",
")",
")",
";",
"$",
"this",
"->",
"debugger",
"->",
"set",
"(",
"'userinfo'",
",",
"$",
"existinguser",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"Text",
"::",
"_",
"(",
"'EMAIL'",
")",
".",
"' '",
".",
"Text",
"::",
"_",
"(",
"'CONFLICT'",
")",
".",
"': '",
".",
"$",
"existinguser",
"->",
"email",
".",
"' -> '",
".",
"$",
"userinfo",
"->",
"email",
")",
";",
"}",
"}",
"return",
"$",
"changed",
";",
"}"
] | @param Userinfo $userinfo
@param Userinfo $existinguser
@param $overwrite
@throws RuntimeException
@return boolean return true if changed | [
"@param",
"Userinfo",
"$userinfo",
"@param",
"Userinfo",
"$existinguser",
"@param",
"$overwrite"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L383-L407 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.doUpdateBlock | function doUpdateBlock(Userinfo $userinfo, Userinfo &$existinguser, $overwrite)
{
$changed = false;
//check the blocked status
if ($existinguser->block != $userinfo->block) {
$update_block = $this->params->get('update_block', false);
if ($update_block || $overwrite) {
if ($userinfo->block) {
//block the user
try {
$this->blockUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('BLOCK_UPDATE_ERROR') . ' ' . $e->getMessage());
}
$changed = true;
} else {
//unblock the user
try {
$this->unblockUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('BLOCK_UPDATE_ERROR') . ' ' . $e->getMessage());
}
}
} else {
//return a debug to inform we skipped this step
$this->debugger->addDebug(Text::_('SKIPPED_BLOCK_UPDATE') . ': ' . $existinguser->block . ' -> ' . $userinfo->block);
}
}
return $changed;
} | php | function doUpdateBlock(Userinfo $userinfo, Userinfo &$existinguser, $overwrite)
{
$changed = false;
//check the blocked status
if ($existinguser->block != $userinfo->block) {
$update_block = $this->params->get('update_block', false);
if ($update_block || $overwrite) {
if ($userinfo->block) {
//block the user
try {
$this->blockUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('BLOCK_UPDATE_ERROR') . ' ' . $e->getMessage());
}
$changed = true;
} else {
//unblock the user
try {
$this->unblockUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('BLOCK_UPDATE_ERROR') . ' ' . $e->getMessage());
}
}
} else {
//return a debug to inform we skipped this step
$this->debugger->addDebug(Text::_('SKIPPED_BLOCK_UPDATE') . ': ' . $existinguser->block . ' -> ' . $userinfo->block);
}
}
return $changed;
} | [
"function",
"doUpdateBlock",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"&",
"$",
"existinguser",
",",
"$",
"overwrite",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"//check the blocked status",
"if",
"(",
"$",
"existinguser",
"->",
"block",
"!=",
"$",
"userinfo",
"->",
"block",
")",
"{",
"$",
"update_block",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'update_block'",
",",
"false",
")",
";",
"if",
"(",
"$",
"update_block",
"||",
"$",
"overwrite",
")",
"{",
"if",
"(",
"$",
"userinfo",
"->",
"block",
")",
"{",
"//block the user",
"try",
"{",
"$",
"this",
"->",
"blockUser",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'BLOCK_UPDATE_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"changed",
"=",
"true",
";",
"}",
"else",
"{",
"//unblock the user",
"try",
"{",
"$",
"this",
"->",
"unblockUser",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'BLOCK_UPDATE_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"//return a debug to inform we skipped this step",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'SKIPPED_BLOCK_UPDATE'",
")",
".",
"': '",
".",
"$",
"existinguser",
"->",
"block",
".",
"' -> '",
".",
"$",
"userinfo",
"->",
"block",
")",
";",
"}",
"}",
"return",
"$",
"changed",
";",
"}"
] | @param Userinfo $userinfo
@param Userinfo $existinguser
@param $overwrite
@return boolean return true if changed | [
"@param",
"Userinfo",
"$userinfo",
"@param",
"Userinfo",
"$existinguser",
"@param",
"$overwrite"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L442-L474 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.doUpdateActivate | function doUpdateActivate(Userinfo $userinfo, Userinfo &$existinguser, $overwrite)
{
$changed = false;
//check the activation status
if (isset($existinguser->activation)) {
if ($existinguser->activation != $userinfo->activation) {
$update_activation = $this->params->get('update_activation', false);
if ($update_activation || $overwrite) {
if ($userinfo->activation) {
//inactive the user
try {
$this->inactivateUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('ACTIVATION_UPDATE_ERROR') . ' ' . $e->getMessage());
}
} else {
//activate the user
try {
$this->activateUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('ACTIVATION_UPDATE_ERROR') . ' ' . $e->getMessage());
}
}
} else {
//return a debug to inform we skipped this step
$this->debugger->addDebug(Text::_('SKIPPED_ACTIVATION_UPDATE') . ': ' . $existinguser->activation . ' -> ' . $userinfo->activation);
}
}
}
return $changed;
} | php | function doUpdateActivate(Userinfo $userinfo, Userinfo &$existinguser, $overwrite)
{
$changed = false;
//check the activation status
if (isset($existinguser->activation)) {
if ($existinguser->activation != $userinfo->activation) {
$update_activation = $this->params->get('update_activation', false);
if ($update_activation || $overwrite) {
if ($userinfo->activation) {
//inactive the user
try {
$this->inactivateUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('ACTIVATION_UPDATE_ERROR') . ' ' . $e->getMessage());
}
} else {
//activate the user
try {
$this->activateUser($userinfo, $existinguser);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('ACTIVATION_UPDATE_ERROR') . ' ' . $e->getMessage());
}
}
} else {
//return a debug to inform we skipped this step
$this->debugger->addDebug(Text::_('SKIPPED_ACTIVATION_UPDATE') . ': ' . $existinguser->activation . ' -> ' . $userinfo->activation);
}
}
}
return $changed;
} | [
"function",
"doUpdateActivate",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"&",
"$",
"existinguser",
",",
"$",
"overwrite",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"//check the activation status",
"if",
"(",
"isset",
"(",
"$",
"existinguser",
"->",
"activation",
")",
")",
"{",
"if",
"(",
"$",
"existinguser",
"->",
"activation",
"!=",
"$",
"userinfo",
"->",
"activation",
")",
"{",
"$",
"update_activation",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'update_activation'",
",",
"false",
")",
";",
"if",
"(",
"$",
"update_activation",
"||",
"$",
"overwrite",
")",
"{",
"if",
"(",
"$",
"userinfo",
"->",
"activation",
")",
"{",
"//inactive the user",
"try",
"{",
"$",
"this",
"->",
"inactivateUser",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'ACTIVATION_UPDATE_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"//activate the user",
"try",
"{",
"$",
"this",
"->",
"activateUser",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'ACTIVATION_UPDATE_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"//return a debug to inform we skipped this step",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'SKIPPED_ACTIVATION_UPDATE'",
")",
".",
"': '",
".",
"$",
"existinguser",
"->",
"activation",
".",
"' -> '",
".",
"$",
"userinfo",
"->",
"activation",
")",
";",
"}",
"}",
"}",
"return",
"$",
"changed",
";",
"}"
] | @param Userinfo $userinfo
@param Userinfo $existinguser
@param $overwrite
@return boolean return true if changed | [
"@param",
"Userinfo",
"$userinfo",
"@param",
"Userinfo",
"$existinguser",
"@param",
"$overwrite"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L510-L543 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.doCreateUser | function doCreateUser(Userinfo $userinfo)
{
$user = null;
//check activation and block status
$create_inactive = $this->params->get('create_inactive', 1);
$create_blocked = $this->params->get('create_blocked', 1);
if ((empty($create_inactive) && !empty($userinfo->activation)) || (empty($create_blocked) && !empty($userinfo->block))) {
//block user creation
$this->debugger->addDebug(Text::_('SKIPPED_USER_CREATION'));
$this->debugger->set('action', 'unchanged');
} else {
$this->debugger->addDebug(Text::_('NO_USER_FOUND_CREATING_ONE'));
try {
$user = $this->createUser($userinfo);
$this->debugger->addDebug(Text::_('USER_CREATION'));
$this->debugger->set('action', 'created');
} catch (Exception $e) {
$this->debugger->addError(Text::_('USER_CREATION_ERROR') . $e->getMessage());
}
}
return $user;
} | php | function doCreateUser(Userinfo $userinfo)
{
$user = null;
//check activation and block status
$create_inactive = $this->params->get('create_inactive', 1);
$create_blocked = $this->params->get('create_blocked', 1);
if ((empty($create_inactive) && !empty($userinfo->activation)) || (empty($create_blocked) && !empty($userinfo->block))) {
//block user creation
$this->debugger->addDebug(Text::_('SKIPPED_USER_CREATION'));
$this->debugger->set('action', 'unchanged');
} else {
$this->debugger->addDebug(Text::_('NO_USER_FOUND_CREATING_ONE'));
try {
$user = $this->createUser($userinfo);
$this->debugger->addDebug(Text::_('USER_CREATION'));
$this->debugger->set('action', 'created');
} catch (Exception $e) {
$this->debugger->addError(Text::_('USER_CREATION_ERROR') . $e->getMessage());
}
}
return $user;
} | [
"function",
"doCreateUser",
"(",
"Userinfo",
"$",
"userinfo",
")",
"{",
"$",
"user",
"=",
"null",
";",
"//check activation and block status",
"$",
"create_inactive",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'create_inactive'",
",",
"1",
")",
";",
"$",
"create_blocked",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'create_blocked'",
",",
"1",
")",
";",
"if",
"(",
"(",
"empty",
"(",
"$",
"create_inactive",
")",
"&&",
"!",
"empty",
"(",
"$",
"userinfo",
"->",
"activation",
")",
")",
"||",
"(",
"empty",
"(",
"$",
"create_blocked",
")",
"&&",
"!",
"empty",
"(",
"$",
"userinfo",
"->",
"block",
")",
")",
")",
"{",
"//block user creation",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'SKIPPED_USER_CREATION'",
")",
")",
";",
"$",
"this",
"->",
"debugger",
"->",
"set",
"(",
"'action'",
",",
"'unchanged'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'NO_USER_FOUND_CREATING_ONE'",
")",
")",
";",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"createUser",
"(",
"$",
"userinfo",
")",
";",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'USER_CREATION'",
")",
")",
";",
"$",
"this",
"->",
"debugger",
"->",
"set",
"(",
"'action'",
",",
"'created'",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'USER_CREATION_ERROR'",
")",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"user",
";",
"}"
] | @param Userinfo $userinfo
@return Userinfo|null | [
"@param",
"Userinfo",
"$userinfo"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L577-L600 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.doUserLanguage | function doUserLanguage(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
//Update the user language with the current used in Joomla or the one existing from an other plugin
if (empty($userinfo->language)) {
$user_lang = '';
if (!empty($userinfo->params)) {
$params = new Registry($userinfo->params);
$user_lang = $params->get('language');
}
$userinfo->language = !empty($user_lang) ? $user_lang : Factory::getLanguage()->getTag();
}
if (!empty($userinfo->language) && isset($existinguser->language) && !empty($existinguser->language) && $userinfo->language != $existinguser->language) {
try {
$this->updateUserLanguage($userinfo, $existinguser);
$existinguser->language = $userinfo->language;
$this->debugger->addDebug(Text::_('LANGUAGE_UPDATED') . ' : ' . $existinguser->language . ' -> ' . $userinfo->language);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('LANGUAGE_UPDATED_ERROR') . ' ' . $e->getMessage());
}
} else {
//return a debug to inform we skipped this step
$this->debugger->addDebug(Text::_('LANGUAGE_NOT_UPDATED'));
}
return $changed;
} | php | function doUserLanguage(Userinfo $userinfo, Userinfo &$existinguser)
{
$changed = false;
//Update the user language with the current used in Joomla or the one existing from an other plugin
if (empty($userinfo->language)) {
$user_lang = '';
if (!empty($userinfo->params)) {
$params = new Registry($userinfo->params);
$user_lang = $params->get('language');
}
$userinfo->language = !empty($user_lang) ? $user_lang : Factory::getLanguage()->getTag();
}
if (!empty($userinfo->language) && isset($existinguser->language) && !empty($existinguser->language) && $userinfo->language != $existinguser->language) {
try {
$this->updateUserLanguage($userinfo, $existinguser);
$existinguser->language = $userinfo->language;
$this->debugger->addDebug(Text::_('LANGUAGE_UPDATED') . ' : ' . $existinguser->language . ' -> ' . $userinfo->language);
$changed = true;
} catch (Exception $e) {
$this->debugger->addError(Text::_('LANGUAGE_UPDATED_ERROR') . ' ' . $e->getMessage());
}
} else {
//return a debug to inform we skipped this step
$this->debugger->addDebug(Text::_('LANGUAGE_NOT_UPDATED'));
}
return $changed;
} | [
"function",
"doUserLanguage",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"&",
"$",
"existinguser",
")",
"{",
"$",
"changed",
"=",
"false",
";",
"//Update the user language with the current used in Joomla or the one existing from an other plugin",
"if",
"(",
"empty",
"(",
"$",
"userinfo",
"->",
"language",
")",
")",
"{",
"$",
"user_lang",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"userinfo",
"->",
"params",
")",
")",
"{",
"$",
"params",
"=",
"new",
"Registry",
"(",
"$",
"userinfo",
"->",
"params",
")",
";",
"$",
"user_lang",
"=",
"$",
"params",
"->",
"get",
"(",
"'language'",
")",
";",
"}",
"$",
"userinfo",
"->",
"language",
"=",
"!",
"empty",
"(",
"$",
"user_lang",
")",
"?",
"$",
"user_lang",
":",
"Factory",
"::",
"getLanguage",
"(",
")",
"->",
"getTag",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"userinfo",
"->",
"language",
")",
"&&",
"isset",
"(",
"$",
"existinguser",
"->",
"language",
")",
"&&",
"!",
"empty",
"(",
"$",
"existinguser",
"->",
"language",
")",
"&&",
"$",
"userinfo",
"->",
"language",
"!=",
"$",
"existinguser",
"->",
"language",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"updateUserLanguage",
"(",
"$",
"userinfo",
",",
"$",
"existinguser",
")",
";",
"$",
"existinguser",
"->",
"language",
"=",
"$",
"userinfo",
"->",
"language",
";",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'LANGUAGE_UPDATED'",
")",
".",
"' : '",
".",
"$",
"existinguser",
"->",
"language",
".",
"' -> '",
".",
"$",
"userinfo",
"->",
"language",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"debugger",
"->",
"addError",
"(",
"Text",
"::",
"_",
"(",
"'LANGUAGE_UPDATED_ERROR'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"//return a debug to inform we skipped this step",
"$",
"this",
"->",
"debugger",
"->",
"addDebug",
"(",
"Text",
"::",
"_",
"(",
"'LANGUAGE_NOT_UPDATED'",
")",
")",
";",
"}",
"return",
"$",
"changed",
";",
"}"
] | @param Userinfo $userinfo
@param Userinfo $existinguser
@return boolean return true if changed | [
"@param",
"Userinfo",
"$userinfo",
"@param",
"Userinfo",
"$existinguser"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L634-L661 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.compareUserGroups | public function compareUserGroups(Userinfo $userinfo, $usergroups) {
if (!is_array($usergroups)) {
$usergroups = array($usergroups);
}
$correct = false;
$count = 0;
if (count($usergroups) == count($userinfo->groups)) {
foreach ($usergroups as $group) {
if (in_array($group, $userinfo->groups, true)) {
$count++;
}
}
if (count($userinfo->groups) == $count) {
$correct = true;
}
}
return $correct;
} | php | public function compareUserGroups(Userinfo $userinfo, $usergroups) {
if (!is_array($usergroups)) {
$usergroups = array($usergroups);
}
$correct = false;
$count = 0;
if (count($usergroups) == count($userinfo->groups)) {
foreach ($usergroups as $group) {
if (in_array($group, $userinfo->groups, true)) {
$count++;
}
}
if (count($userinfo->groups) == $count) {
$correct = true;
}
}
return $correct;
} | [
"public",
"function",
"compareUserGroups",
"(",
"Userinfo",
"$",
"userinfo",
",",
"$",
"usergroups",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"usergroups",
")",
")",
"{",
"$",
"usergroups",
"=",
"array",
"(",
"$",
"usergroups",
")",
";",
"}",
"$",
"correct",
"=",
"false",
";",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"count",
"(",
"$",
"usergroups",
")",
"==",
"count",
"(",
"$",
"userinfo",
"->",
"groups",
")",
")",
"{",
"foreach",
"(",
"$",
"usergroups",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"group",
",",
"$",
"userinfo",
"->",
"groups",
",",
"true",
")",
")",
"{",
"$",
"count",
"++",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"userinfo",
"->",
"groups",
")",
"==",
"$",
"count",
")",
"{",
"$",
"correct",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"correct",
";",
"}"
] | compare set of usergroup with a user returns true if the usergroups are correct
@param Userinfo $userinfo user with current usergroups
@param array $usergroups array with the correct usergroups
@return boolean | [
"compare",
"set",
"of",
"usergroup",
"with",
"a",
"user",
"returns",
"true",
"if",
"the",
"usergroups",
"are",
"correct"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L682-L701 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.getUserGroupIndex | function getUserGroupIndex(Userinfo $userinfo)
{
$index = 0;
$master = Framework::getMaster();
if ($master) {
$mastergroups = Groups::get($master->name);
foreach ($mastergroups as $key => $mastergroup) {
if ($mastergroup) {
if (count($mastergroup) == count($userinfo->groups)) {
$count = 0;
foreach ($mastergroup as $value) {
if (in_array($value, $userinfo->groups, true)) {
$count++;
}
}
if (count($userinfo->groups) == $count) {
$index = $key;
break;
}
}
}
}
}
return $index;
} | php | function getUserGroupIndex(Userinfo $userinfo)
{
$index = 0;
$master = Framework::getMaster();
if ($master) {
$mastergroups = Groups::get($master->name);
foreach ($mastergroups as $key => $mastergroup) {
if ($mastergroup) {
if (count($mastergroup) == count($userinfo->groups)) {
$count = 0;
foreach ($mastergroup as $value) {
if (in_array($value, $userinfo->groups, true)) {
$count++;
}
}
if (count($userinfo->groups) == $count) {
$index = $key;
break;
}
}
}
}
}
return $index;
} | [
"function",
"getUserGroupIndex",
"(",
"Userinfo",
"$",
"userinfo",
")",
"{",
"$",
"index",
"=",
"0",
";",
"$",
"master",
"=",
"Framework",
"::",
"getMaster",
"(",
")",
";",
"if",
"(",
"$",
"master",
")",
"{",
"$",
"mastergroups",
"=",
"Groups",
"::",
"get",
"(",
"$",
"master",
"->",
"name",
")",
";",
"foreach",
"(",
"$",
"mastergroups",
"as",
"$",
"key",
"=>",
"$",
"mastergroup",
")",
"{",
"if",
"(",
"$",
"mastergroup",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"mastergroup",
")",
"==",
"count",
"(",
"$",
"userinfo",
"->",
"groups",
")",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"mastergroup",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"userinfo",
"->",
"groups",
",",
"true",
")",
")",
"{",
"$",
"count",
"++",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"userinfo",
"->",
"groups",
")",
"==",
"$",
"count",
")",
"{",
"$",
"index",
"=",
"$",
"key",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"index",
";",
"}"
] | Function That find the correct user group index
@param Userinfo $userinfo
@return int | [
"Function",
"That",
"find",
"the",
"correct",
"user",
"group",
"index"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L710-L736 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.curlLogin | final public function curlLogin(Userinfo $userinfo, $options, $type = 'brute_force', $curl_options_merge = array())
{
$curl_options = array();
$status = array(LogLevel::ERROR => array(), LogLevel::DEBUG => array());
$source_url = $this->params->get('source_url');
$login_url = $this->params->get('login_url');
//prevent user error by not supplying trailing forward slash
if (substr($source_url, -1) != '/') {
$source_url = $source_url . '/';
}
//prevent user error by preventing a heading forward slash
ltrim($login_url, '/');
$curl_options['post_url'] = $source_url . $login_url;
$curl_options['formid'] = $this->params->get('loginform_id');
$login_identifier = $this->params->get('login_identifier', '1');
$identifier = ($login_identifier === '2') ? 'email' : 'username';
$curl_options['username'] = $userinfo->$identifier;
$curl_options['password'] = $userinfo->password_clear;
$integrationtype1 = $this->params->get('integrationtype');
$curl_options['relpath']= $this->params->get('relpath');
$curl_options['hidden'] = $this->params->get('hidden');
$curl_options['buttons'] = $this->params->get('buttons');
$curl_options['override'] = $this->params->get('override');
$curl_options['cookiedomain'] = $this->params->get('cookie_domain');
$curl_options['cookiepath'] = $this->params->get('cookie_path');
$curl_options['expires'] = $this->params->get('cookie_expires');
$curl_options['input_username_id'] = $this->params->get('input_username_id');
$curl_options['input_password_id'] = $this->params->get('input_password_id');
$curl_options['secure'] = $this->params->get('secure');
$curl_options['httponly'] = $this->params->get('httponly');
$curl_options['verifyhost'] = 0; //$params->get('ssl_verifyhost');
$curl_options['httpauth'] = $this->params->get('httpauth');
$curl_options['httpauth_username'] = $this->params->get('curl_username');
$curl_options['httpauth_password'] = $this->params->get('curl_password');
// to prevent endless loops on systems where there are multiple places where a user can login
// we post an unique ID for the initiating software so we can make a difference between
// a user logging in or another jFusion installation, or even another system with reverse dual login code.
// We always use the source url of the initializing system, here the source_url as defined in the joomla_int
// plugin. This is totally transparent for the the webmaster. No additional setup is needed
$curl_options['jnodeid'] = Framework::getNodeID();
// For further simplifying setup we send also an indication if this system is a host. Other hosts should
// only perform local joomla login when received this post. We define being a host if we have
// at least one slave.
$plugins = Factory::getPlugins('slave');
if (count($plugins) > 2 ) {
$jhost = true;
} else {
$jhost = false;
}
if ($jhost) {
$curl_options['jhost'] = true;
}
if (!empty($curl_options_merge)) {
$curl_options = array_merge($curl_options, $curl_options_merge);
}
// This check is just for Jfusion 1.x to support the reverse dual login function
// We need to check if JFusion tries to create this session because of this integration
// initiated a login by means of the reverse dual login extensions. Note that
// if the curl routines are not used, the same check must be performed in the
// create session routine in the user.php file of the plugin concerned.
// In version 2.0 we will never reach this point as the user plugin will handle this
$jnodeid = strtolower(Application::getInstance()->input->get('jnodeid'));
if (!empty($jnodeid)) {
if($jnodeid == Factory::getPluginNodeId($this->getJname())) {
// do not create a session, this integration started the log in and the user is already logged in
$status[LogLevel::DEBUG][] = Text::_('ALREADY_LOGGED_IN');
return $status;
}
}
// correction of the integration type for Joomla Joomla using a sessionid in the logout form
// for joomla 1.5 we need integration type 1 for login (LI) and 0 for logout (LO)
// this is backward compatible
// joomla 1.5 : use 3
// joomla 1.6+ : use 1
switch ($integrationtype1) {
case '0': // LI = 0 LO = 0
case '2': // LI = 0, LO = 1
$integrationtype = 0;
break;
case '1': // LI = 1 LO = 1
case '3': // LI = 1, LO = 0
default:
$integrationtype = 1;
break;
}
$curl_options['integrationtype'] = $integrationtype;
// extra lines for passing curl options to other routines, like ambrasubs payment processor
// we are using the super global $_SESSION to pass data in $_SESSION[$var]
$var = 'curl_options';
if(!array_key_exists($var, $_SESSION)) $_SESSION[$var] = '';
$_SESSION[$var] = $curl_options;
$GLOBALS[$var] = &$_SESSION[$var];
// end extra lines
$type = strtolower($type);
switch ($type) {
case 'url':
// $status = JFusionCurl::RemoteLoginUrl($curl_options);
$status[LogLevel::ERROR][] = Text::_('CURL_LOGINTYPE_NOT_SUPPORTED');
break;
case 'brute_force':
$curl_options['brute_force'] = $type;
$curl = new Curl($curl_options);
$status = $curl->login();
break;
default:
$curl = new Curl($curl_options);
$status = $curl->login();
}
$status[LogLevel::DEBUG][] = Text::_('CURL_LOGINTYPE') . '=' . $type;
return $status;
} | php | final public function curlLogin(Userinfo $userinfo, $options, $type = 'brute_force', $curl_options_merge = array())
{
$curl_options = array();
$status = array(LogLevel::ERROR => array(), LogLevel::DEBUG => array());
$source_url = $this->params->get('source_url');
$login_url = $this->params->get('login_url');
//prevent user error by not supplying trailing forward slash
if (substr($source_url, -1) != '/') {
$source_url = $source_url . '/';
}
//prevent user error by preventing a heading forward slash
ltrim($login_url, '/');
$curl_options['post_url'] = $source_url . $login_url;
$curl_options['formid'] = $this->params->get('loginform_id');
$login_identifier = $this->params->get('login_identifier', '1');
$identifier = ($login_identifier === '2') ? 'email' : 'username';
$curl_options['username'] = $userinfo->$identifier;
$curl_options['password'] = $userinfo->password_clear;
$integrationtype1 = $this->params->get('integrationtype');
$curl_options['relpath']= $this->params->get('relpath');
$curl_options['hidden'] = $this->params->get('hidden');
$curl_options['buttons'] = $this->params->get('buttons');
$curl_options['override'] = $this->params->get('override');
$curl_options['cookiedomain'] = $this->params->get('cookie_domain');
$curl_options['cookiepath'] = $this->params->get('cookie_path');
$curl_options['expires'] = $this->params->get('cookie_expires');
$curl_options['input_username_id'] = $this->params->get('input_username_id');
$curl_options['input_password_id'] = $this->params->get('input_password_id');
$curl_options['secure'] = $this->params->get('secure');
$curl_options['httponly'] = $this->params->get('httponly');
$curl_options['verifyhost'] = 0; //$params->get('ssl_verifyhost');
$curl_options['httpauth'] = $this->params->get('httpauth');
$curl_options['httpauth_username'] = $this->params->get('curl_username');
$curl_options['httpauth_password'] = $this->params->get('curl_password');
// to prevent endless loops on systems where there are multiple places where a user can login
// we post an unique ID for the initiating software so we can make a difference between
// a user logging in or another jFusion installation, or even another system with reverse dual login code.
// We always use the source url of the initializing system, here the source_url as defined in the joomla_int
// plugin. This is totally transparent for the the webmaster. No additional setup is needed
$curl_options['jnodeid'] = Framework::getNodeID();
// For further simplifying setup we send also an indication if this system is a host. Other hosts should
// only perform local joomla login when received this post. We define being a host if we have
// at least one slave.
$plugins = Factory::getPlugins('slave');
if (count($plugins) > 2 ) {
$jhost = true;
} else {
$jhost = false;
}
if ($jhost) {
$curl_options['jhost'] = true;
}
if (!empty($curl_options_merge)) {
$curl_options = array_merge($curl_options, $curl_options_merge);
}
// This check is just for Jfusion 1.x to support the reverse dual login function
// We need to check if JFusion tries to create this session because of this integration
// initiated a login by means of the reverse dual login extensions. Note that
// if the curl routines are not used, the same check must be performed in the
// create session routine in the user.php file of the plugin concerned.
// In version 2.0 we will never reach this point as the user plugin will handle this
$jnodeid = strtolower(Application::getInstance()->input->get('jnodeid'));
if (!empty($jnodeid)) {
if($jnodeid == Factory::getPluginNodeId($this->getJname())) {
// do not create a session, this integration started the log in and the user is already logged in
$status[LogLevel::DEBUG][] = Text::_('ALREADY_LOGGED_IN');
return $status;
}
}
// correction of the integration type for Joomla Joomla using a sessionid in the logout form
// for joomla 1.5 we need integration type 1 for login (LI) and 0 for logout (LO)
// this is backward compatible
// joomla 1.5 : use 3
// joomla 1.6+ : use 1
switch ($integrationtype1) {
case '0': // LI = 0 LO = 0
case '2': // LI = 0, LO = 1
$integrationtype = 0;
break;
case '1': // LI = 1 LO = 1
case '3': // LI = 1, LO = 0
default:
$integrationtype = 1;
break;
}
$curl_options['integrationtype'] = $integrationtype;
// extra lines for passing curl options to other routines, like ambrasubs payment processor
// we are using the super global $_SESSION to pass data in $_SESSION[$var]
$var = 'curl_options';
if(!array_key_exists($var, $_SESSION)) $_SESSION[$var] = '';
$_SESSION[$var] = $curl_options;
$GLOBALS[$var] = &$_SESSION[$var];
// end extra lines
$type = strtolower($type);
switch ($type) {
case 'url':
// $status = JFusionCurl::RemoteLoginUrl($curl_options);
$status[LogLevel::ERROR][] = Text::_('CURL_LOGINTYPE_NOT_SUPPORTED');
break;
case 'brute_force':
$curl_options['brute_force'] = $type;
$curl = new Curl($curl_options);
$status = $curl->login();
break;
default:
$curl = new Curl($curl_options);
$status = $curl->login();
}
$status[LogLevel::DEBUG][] = Text::_('CURL_LOGINTYPE') . '=' . $type;
return $status;
} | [
"final",
"public",
"function",
"curlLogin",
"(",
"Userinfo",
"$",
"userinfo",
",",
"$",
"options",
",",
"$",
"type",
"=",
"'brute_force'",
",",
"$",
"curl_options_merge",
"=",
"array",
"(",
")",
")",
"{",
"$",
"curl_options",
"=",
"array",
"(",
")",
";",
"$",
"status",
"=",
"array",
"(",
"LogLevel",
"::",
"ERROR",
"=>",
"array",
"(",
")",
",",
"LogLevel",
"::",
"DEBUG",
"=>",
"array",
"(",
")",
")",
";",
"$",
"source_url",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'source_url'",
")",
";",
"$",
"login_url",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'login_url'",
")",
";",
"//prevent user error by not supplying trailing forward slash",
"if",
"(",
"substr",
"(",
"$",
"source_url",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"source_url",
"=",
"$",
"source_url",
".",
"'/'",
";",
"}",
"//prevent user error by preventing a heading forward slash",
"ltrim",
"(",
"$",
"login_url",
",",
"'/'",
")",
";",
"$",
"curl_options",
"[",
"'post_url'",
"]",
"=",
"$",
"source_url",
".",
"$",
"login_url",
";",
"$",
"curl_options",
"[",
"'formid'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'loginform_id'",
")",
";",
"$",
"login_identifier",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'login_identifier'",
",",
"'1'",
")",
";",
"$",
"identifier",
"=",
"(",
"$",
"login_identifier",
"===",
"'2'",
")",
"?",
"'email'",
":",
"'username'",
";",
"$",
"curl_options",
"[",
"'username'",
"]",
"=",
"$",
"userinfo",
"->",
"$",
"identifier",
";",
"$",
"curl_options",
"[",
"'password'",
"]",
"=",
"$",
"userinfo",
"->",
"password_clear",
";",
"$",
"integrationtype1",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'integrationtype'",
")",
";",
"$",
"curl_options",
"[",
"'relpath'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'relpath'",
")",
";",
"$",
"curl_options",
"[",
"'hidden'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'hidden'",
")",
";",
"$",
"curl_options",
"[",
"'buttons'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'buttons'",
")",
";",
"$",
"curl_options",
"[",
"'override'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'override'",
")",
";",
"$",
"curl_options",
"[",
"'cookiedomain'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'cookie_domain'",
")",
";",
"$",
"curl_options",
"[",
"'cookiepath'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'cookie_path'",
")",
";",
"$",
"curl_options",
"[",
"'expires'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'cookie_expires'",
")",
";",
"$",
"curl_options",
"[",
"'input_username_id'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'input_username_id'",
")",
";",
"$",
"curl_options",
"[",
"'input_password_id'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'input_password_id'",
")",
";",
"$",
"curl_options",
"[",
"'secure'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'secure'",
")",
";",
"$",
"curl_options",
"[",
"'httponly'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'httponly'",
")",
";",
"$",
"curl_options",
"[",
"'verifyhost'",
"]",
"=",
"0",
";",
"//$params->get('ssl_verifyhost');",
"$",
"curl_options",
"[",
"'httpauth'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'httpauth'",
")",
";",
"$",
"curl_options",
"[",
"'httpauth_username'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'curl_username'",
")",
";",
"$",
"curl_options",
"[",
"'httpauth_password'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'curl_password'",
")",
";",
"// to prevent endless loops on systems where there are multiple places where a user can login",
"// we post an unique ID for the initiating software so we can make a difference between",
"// a user logging in or another jFusion installation, or even another system with reverse dual login code.",
"// We always use the source url of the initializing system, here the source_url as defined in the joomla_int",
"// plugin. This is totally transparent for the the webmaster. No additional setup is needed",
"$",
"curl_options",
"[",
"'jnodeid'",
"]",
"=",
"Framework",
"::",
"getNodeID",
"(",
")",
";",
"// For further simplifying setup we send also an indication if this system is a host. Other hosts should",
"// only perform local joomla login when received this post. We define being a host if we have",
"// at least one slave.",
"$",
"plugins",
"=",
"Factory",
"::",
"getPlugins",
"(",
"'slave'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"plugins",
")",
">",
"2",
")",
"{",
"$",
"jhost",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"jhost",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"jhost",
")",
"{",
"$",
"curl_options",
"[",
"'jhost'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"curl_options_merge",
")",
")",
"{",
"$",
"curl_options",
"=",
"array_merge",
"(",
"$",
"curl_options",
",",
"$",
"curl_options_merge",
")",
";",
"}",
"// This check is just for Jfusion 1.x to support the reverse dual login function",
"// We need to check if JFusion tries to create this session because of this integration",
"// initiated a login by means of the reverse dual login extensions. Note that",
"// if the curl routines are not used, the same check must be performed in the",
"// create session routine in the user.php file of the plugin concerned.",
"// In version 2.0 we will never reach this point as the user plugin will handle this",
"$",
"jnodeid",
"=",
"strtolower",
"(",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"input",
"->",
"get",
"(",
"'jnodeid'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"jnodeid",
")",
")",
"{",
"if",
"(",
"$",
"jnodeid",
"==",
"Factory",
"::",
"getPluginNodeId",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
")",
"{",
"// do not create a session, this integration started the log in and the user is already logged in",
"$",
"status",
"[",
"LogLevel",
"::",
"DEBUG",
"]",
"[",
"]",
"=",
"Text",
"::",
"_",
"(",
"'ALREADY_LOGGED_IN'",
")",
";",
"return",
"$",
"status",
";",
"}",
"}",
"// correction of the integration type for Joomla Joomla using a sessionid in the logout form",
"// for joomla 1.5 we need integration type 1 for login (LI) and 0 for logout (LO)",
"// this is backward compatible",
"// joomla 1.5 : use 3",
"// joomla 1.6+ : use 1",
"switch",
"(",
"$",
"integrationtype1",
")",
"{",
"case",
"'0'",
":",
"// LI = 0 LO = 0",
"case",
"'2'",
":",
"// LI = 0, LO = 1",
"$",
"integrationtype",
"=",
"0",
";",
"break",
";",
"case",
"'1'",
":",
"// LI = 1 LO = 1",
"case",
"'3'",
":",
"// LI = 1, LO = 0",
"default",
":",
"$",
"integrationtype",
"=",
"1",
";",
"break",
";",
"}",
"$",
"curl_options",
"[",
"'integrationtype'",
"]",
"=",
"$",
"integrationtype",
";",
"// extra lines for passing curl options to other routines, like ambrasubs payment processor",
"// we are using the super global $_SESSION to pass data in $_SESSION[$var]",
"$",
"var",
"=",
"'curl_options'",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"var",
",",
"$",
"_SESSION",
")",
")",
"$",
"_SESSION",
"[",
"$",
"var",
"]",
"=",
"''",
";",
"$",
"_SESSION",
"[",
"$",
"var",
"]",
"=",
"$",
"curl_options",
";",
"$",
"GLOBALS",
"[",
"$",
"var",
"]",
"=",
"&",
"$",
"_SESSION",
"[",
"$",
"var",
"]",
";",
"// end extra lines",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'url'",
":",
"// $status = JFusionCurl::RemoteLoginUrl($curl_options);",
"$",
"status",
"[",
"LogLevel",
"::",
"ERROR",
"]",
"[",
"]",
"=",
"Text",
"::",
"_",
"(",
"'CURL_LOGINTYPE_NOT_SUPPORTED'",
")",
";",
"break",
";",
"case",
"'brute_force'",
":",
"$",
"curl_options",
"[",
"'brute_force'",
"]",
"=",
"$",
"type",
";",
"$",
"curl",
"=",
"new",
"Curl",
"(",
"$",
"curl_options",
")",
";",
"$",
"status",
"=",
"$",
"curl",
"->",
"login",
"(",
")",
";",
"break",
";",
"default",
":",
"$",
"curl",
"=",
"new",
"Curl",
"(",
"$",
"curl_options",
")",
";",
"$",
"status",
"=",
"$",
"curl",
"->",
"login",
"(",
")",
";",
"}",
"$",
"status",
"[",
"LogLevel",
"::",
"DEBUG",
"]",
"[",
"]",
"=",
"Text",
"::",
"_",
"(",
"'CURL_LOGINTYPE'",
")",
".",
"'='",
".",
"$",
"type",
";",
"return",
"$",
"status",
";",
"}"
] | Common code for user.php
@param Userinfo $userinfo userinfo
@param array $options options
@param string $type jname
@param array $curl_options_merge
@return string nothing | [
"Common",
"code",
"for",
"user",
".",
"php"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L748-L873 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.curlLogout | final public function curlLogout(Userinfo $userinfo, $options, $type = 'brute_force', $curl_options_merge = array())
{
$curl_options = array();
$status = array('error' => array(), 'debug' => array());
$source_url = $this->params->get('source_url');
$logout_url = $this->params->get('logout_url');
//prevent user error by not supplying trailing forward slash
if (substr($source_url, -1) != '/') {
$source_url = $source_url . '/';
}
//prevent user error by preventing a heading forward slash
ltrim($logout_url, '/');
$curl_options['post_url'] = $source_url . $logout_url;
$curl_options['formid'] = $this->params->get('loginform_id');
$curl_options['username'] = $userinfo->username;
// $curl_options['password'] = $userinfo->password_clear;
$integrationtype1 = $this->params->get('integrationtype');
$curl_options['relpath'] = $this->params->get('relpathl', $this->params->get('relpath', 0));
$curl_options['hidden'] = '1';
$curl_options['buttons'] = '1';
$curl_options['override'] = '';
$curl_options['cookiedomain'] = $this->params->get('cookie_domain');
$curl_options['cookiepath'] = $this->params->get('cookie_path');
$curl_options['expires'] = time() - 30*60*60;
$curl_options['input_username_id'] = $this->params->get('input_username_id');
$curl_options['input_password_id'] = $this->params->get('input_password_id');
$curl_options['secure'] = $this->params->get('secure');
$curl_options['httponly'] = $this->params->get('httponly');
$curl_options['verifyhost'] = 0; //$params->get('ssl_verifyhost');
$curl_options['httpauth'] = $this->params->get('httpauth');
$curl_options['httpauth_username'] = $this->params->get('curl_username');
$curl_options['httpauth_password'] = $this->params->get('curl_password');
$curl_options['leavealone'] = $this->params->get('leavealone');
$curl_options['postfields'] = $this->params->get('postfields','');
$curl_options['logout'] = '1';
// to prevent endless loops on systems where there are multiple places where a user can login
// we post an unique ID for the initiating software so we can make a difference between
// a user logging in or another jFusion installation, or even another system with reverse dual login code.
// We always use the source url of the initializing system, here the source_url as defined in the joomla_int
// plugin. This is totally transparent for the the webmaster. No additional setup is needed
$curl_options['jnodeid'] = Framework::getNodeID();
// For further simplifying setup we send also an indication if this system is a host. Other hosts should
// only perform local joomla login when received this post. We define being a host if we have
// at least one slave.
$plugins = Factory::getPlugins('slave');
if (count($plugins) > 2 ) {
$jhost = true;
} else {
$jhost = false;
}
if ($jhost) {
$curl_options['jhost'] = true;
}
if (!empty($curl_options_merge)) {
$curl_options = array_merge($curl_options, $curl_options_merge);
}
// This check is just for Jfusion 1.x to support the reverse dual login function
// We need to check if JFusion tries to delete this session because of this integration
// initiated a logout by means of the reverse dual login extensions. Note that
// if the curl routines are not used, the same check must be performed in the
// destroysession routine in the user.php file of the plugin concerned.
// In version 2.0 we will never reach this point as the user plugin will handle this
$jnodeid = strtolower(Application::getInstance()->input->get('jnodeid'));
if (!empty($jnodeid)) {
if($jnodeid == Factory::getPluginNodeId($this->getJname())) {
// do not delete a session, this integration started the log out and the user is already logged out
$status[LogLevel::DEBUG][] = Text::_('ALREADY_LOGGED_OUT');
return $status;
}
}
// correction of the integration type for Joomla Joomla using a sessionid in the logout form
// for joomla 1.5 we need integration type 1 for login (LI) and 0 for logout (LO)
// this is backward compatible
// joomla 1.5 : use 3
// joomla 1.6+ : use 1
switch ($integrationtype1) {
case '0': // LI = 0 LO = 0
case '3': // LI = 1, LO = 0
$integrationtype = 0;
break;
case '1': // LI = 1 LO = 1
case '2': // LI = 0, LO = 1
default:
$integrationtype = 1;
break;
}
$curl_options['integrationtype'] = $integrationtype;
$type = strtolower($type);
$curl = new Curl($curl_options);
switch ($type) {
case 'url':
$status = $curl->logoutUrl();
break;
case 'form':
$status = $curl->login();
break;
case 'brute_force':
default:
$status = $curl->logout();
}
$status[LogLevel::DEBUG][] = Text::_('CURL_LOGOUTTYPE') . '=' . $type;
return $status;
} | php | final public function curlLogout(Userinfo $userinfo, $options, $type = 'brute_force', $curl_options_merge = array())
{
$curl_options = array();
$status = array('error' => array(), 'debug' => array());
$source_url = $this->params->get('source_url');
$logout_url = $this->params->get('logout_url');
//prevent user error by not supplying trailing forward slash
if (substr($source_url, -1) != '/') {
$source_url = $source_url . '/';
}
//prevent user error by preventing a heading forward slash
ltrim($logout_url, '/');
$curl_options['post_url'] = $source_url . $logout_url;
$curl_options['formid'] = $this->params->get('loginform_id');
$curl_options['username'] = $userinfo->username;
// $curl_options['password'] = $userinfo->password_clear;
$integrationtype1 = $this->params->get('integrationtype');
$curl_options['relpath'] = $this->params->get('relpathl', $this->params->get('relpath', 0));
$curl_options['hidden'] = '1';
$curl_options['buttons'] = '1';
$curl_options['override'] = '';
$curl_options['cookiedomain'] = $this->params->get('cookie_domain');
$curl_options['cookiepath'] = $this->params->get('cookie_path');
$curl_options['expires'] = time() - 30*60*60;
$curl_options['input_username_id'] = $this->params->get('input_username_id');
$curl_options['input_password_id'] = $this->params->get('input_password_id');
$curl_options['secure'] = $this->params->get('secure');
$curl_options['httponly'] = $this->params->get('httponly');
$curl_options['verifyhost'] = 0; //$params->get('ssl_verifyhost');
$curl_options['httpauth'] = $this->params->get('httpauth');
$curl_options['httpauth_username'] = $this->params->get('curl_username');
$curl_options['httpauth_password'] = $this->params->get('curl_password');
$curl_options['leavealone'] = $this->params->get('leavealone');
$curl_options['postfields'] = $this->params->get('postfields','');
$curl_options['logout'] = '1';
// to prevent endless loops on systems where there are multiple places where a user can login
// we post an unique ID for the initiating software so we can make a difference between
// a user logging in or another jFusion installation, or even another system with reverse dual login code.
// We always use the source url of the initializing system, here the source_url as defined in the joomla_int
// plugin. This is totally transparent for the the webmaster. No additional setup is needed
$curl_options['jnodeid'] = Framework::getNodeID();
// For further simplifying setup we send also an indication if this system is a host. Other hosts should
// only perform local joomla login when received this post. We define being a host if we have
// at least one slave.
$plugins = Factory::getPlugins('slave');
if (count($plugins) > 2 ) {
$jhost = true;
} else {
$jhost = false;
}
if ($jhost) {
$curl_options['jhost'] = true;
}
if (!empty($curl_options_merge)) {
$curl_options = array_merge($curl_options, $curl_options_merge);
}
// This check is just for Jfusion 1.x to support the reverse dual login function
// We need to check if JFusion tries to delete this session because of this integration
// initiated a logout by means of the reverse dual login extensions. Note that
// if the curl routines are not used, the same check must be performed in the
// destroysession routine in the user.php file of the plugin concerned.
// In version 2.0 we will never reach this point as the user plugin will handle this
$jnodeid = strtolower(Application::getInstance()->input->get('jnodeid'));
if (!empty($jnodeid)) {
if($jnodeid == Factory::getPluginNodeId($this->getJname())) {
// do not delete a session, this integration started the log out and the user is already logged out
$status[LogLevel::DEBUG][] = Text::_('ALREADY_LOGGED_OUT');
return $status;
}
}
// correction of the integration type for Joomla Joomla using a sessionid in the logout form
// for joomla 1.5 we need integration type 1 for login (LI) and 0 for logout (LO)
// this is backward compatible
// joomla 1.5 : use 3
// joomla 1.6+ : use 1
switch ($integrationtype1) {
case '0': // LI = 0 LO = 0
case '3': // LI = 1, LO = 0
$integrationtype = 0;
break;
case '1': // LI = 1 LO = 1
case '2': // LI = 0, LO = 1
default:
$integrationtype = 1;
break;
}
$curl_options['integrationtype'] = $integrationtype;
$type = strtolower($type);
$curl = new Curl($curl_options);
switch ($type) {
case 'url':
$status = $curl->logoutUrl();
break;
case 'form':
$status = $curl->login();
break;
case 'brute_force':
default:
$status = $curl->logout();
}
$status[LogLevel::DEBUG][] = Text::_('CURL_LOGOUTTYPE') . '=' . $type;
return $status;
} | [
"final",
"public",
"function",
"curlLogout",
"(",
"Userinfo",
"$",
"userinfo",
",",
"$",
"options",
",",
"$",
"type",
"=",
"'brute_force'",
",",
"$",
"curl_options_merge",
"=",
"array",
"(",
")",
")",
"{",
"$",
"curl_options",
"=",
"array",
"(",
")",
";",
"$",
"status",
"=",
"array",
"(",
"'error'",
"=>",
"array",
"(",
")",
",",
"'debug'",
"=>",
"array",
"(",
")",
")",
";",
"$",
"source_url",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'source_url'",
")",
";",
"$",
"logout_url",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'logout_url'",
")",
";",
"//prevent user error by not supplying trailing forward slash",
"if",
"(",
"substr",
"(",
"$",
"source_url",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"source_url",
"=",
"$",
"source_url",
".",
"'/'",
";",
"}",
"//prevent user error by preventing a heading forward slash",
"ltrim",
"(",
"$",
"logout_url",
",",
"'/'",
")",
";",
"$",
"curl_options",
"[",
"'post_url'",
"]",
"=",
"$",
"source_url",
".",
"$",
"logout_url",
";",
"$",
"curl_options",
"[",
"'formid'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'loginform_id'",
")",
";",
"$",
"curl_options",
"[",
"'username'",
"]",
"=",
"$",
"userinfo",
"->",
"username",
";",
"// $curl_options['password'] = $userinfo->password_clear;",
"$",
"integrationtype1",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'integrationtype'",
")",
";",
"$",
"curl_options",
"[",
"'relpath'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'relpathl'",
",",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'relpath'",
",",
"0",
")",
")",
";",
"$",
"curl_options",
"[",
"'hidden'",
"]",
"=",
"'1'",
";",
"$",
"curl_options",
"[",
"'buttons'",
"]",
"=",
"'1'",
";",
"$",
"curl_options",
"[",
"'override'",
"]",
"=",
"''",
";",
"$",
"curl_options",
"[",
"'cookiedomain'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'cookie_domain'",
")",
";",
"$",
"curl_options",
"[",
"'cookiepath'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'cookie_path'",
")",
";",
"$",
"curl_options",
"[",
"'expires'",
"]",
"=",
"time",
"(",
")",
"-",
"30",
"*",
"60",
"*",
"60",
";",
"$",
"curl_options",
"[",
"'input_username_id'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'input_username_id'",
")",
";",
"$",
"curl_options",
"[",
"'input_password_id'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'input_password_id'",
")",
";",
"$",
"curl_options",
"[",
"'secure'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'secure'",
")",
";",
"$",
"curl_options",
"[",
"'httponly'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'httponly'",
")",
";",
"$",
"curl_options",
"[",
"'verifyhost'",
"]",
"=",
"0",
";",
"//$params->get('ssl_verifyhost');",
"$",
"curl_options",
"[",
"'httpauth'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'httpauth'",
")",
";",
"$",
"curl_options",
"[",
"'httpauth_username'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'curl_username'",
")",
";",
"$",
"curl_options",
"[",
"'httpauth_password'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'curl_password'",
")",
";",
"$",
"curl_options",
"[",
"'leavealone'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'leavealone'",
")",
";",
"$",
"curl_options",
"[",
"'postfields'",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"get",
"(",
"'postfields'",
",",
"''",
")",
";",
"$",
"curl_options",
"[",
"'logout'",
"]",
"=",
"'1'",
";",
"// to prevent endless loops on systems where there are multiple places where a user can login",
"// we post an unique ID for the initiating software so we can make a difference between",
"// a user logging in or another jFusion installation, or even another system with reverse dual login code.",
"// We always use the source url of the initializing system, here the source_url as defined in the joomla_int",
"// plugin. This is totally transparent for the the webmaster. No additional setup is needed",
"$",
"curl_options",
"[",
"'jnodeid'",
"]",
"=",
"Framework",
"::",
"getNodeID",
"(",
")",
";",
"// For further simplifying setup we send also an indication if this system is a host. Other hosts should",
"// only perform local joomla login when received this post. We define being a host if we have",
"// at least one slave.",
"$",
"plugins",
"=",
"Factory",
"::",
"getPlugins",
"(",
"'slave'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"plugins",
")",
">",
"2",
")",
"{",
"$",
"jhost",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"jhost",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"jhost",
")",
"{",
"$",
"curl_options",
"[",
"'jhost'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"curl_options_merge",
")",
")",
"{",
"$",
"curl_options",
"=",
"array_merge",
"(",
"$",
"curl_options",
",",
"$",
"curl_options_merge",
")",
";",
"}",
"// This check is just for Jfusion 1.x to support the reverse dual login function",
"// We need to check if JFusion tries to delete this session because of this integration",
"// initiated a logout by means of the reverse dual login extensions. Note that",
"// if the curl routines are not used, the same check must be performed in the",
"// destroysession routine in the user.php file of the plugin concerned.",
"// In version 2.0 we will never reach this point as the user plugin will handle this",
"$",
"jnodeid",
"=",
"strtolower",
"(",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"input",
"->",
"get",
"(",
"'jnodeid'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"jnodeid",
")",
")",
"{",
"if",
"(",
"$",
"jnodeid",
"==",
"Factory",
"::",
"getPluginNodeId",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
")",
"{",
"// do not delete a session, this integration started the log out and the user is already logged out",
"$",
"status",
"[",
"LogLevel",
"::",
"DEBUG",
"]",
"[",
"]",
"=",
"Text",
"::",
"_",
"(",
"'ALREADY_LOGGED_OUT'",
")",
";",
"return",
"$",
"status",
";",
"}",
"}",
"// correction of the integration type for Joomla Joomla using a sessionid in the logout form",
"// for joomla 1.5 we need integration type 1 for login (LI) and 0 for logout (LO)",
"// this is backward compatible",
"// joomla 1.5 : use 3",
"// joomla 1.6+ : use 1",
"switch",
"(",
"$",
"integrationtype1",
")",
"{",
"case",
"'0'",
":",
"// LI = 0 LO = 0",
"case",
"'3'",
":",
"// LI = 1, LO = 0",
"$",
"integrationtype",
"=",
"0",
";",
"break",
";",
"case",
"'1'",
":",
"// LI = 1 LO = 1",
"case",
"'2'",
":",
"// LI = 0, LO = 1",
"default",
":",
"$",
"integrationtype",
"=",
"1",
";",
"break",
";",
"}",
"$",
"curl_options",
"[",
"'integrationtype'",
"]",
"=",
"$",
"integrationtype",
";",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"$",
"curl",
"=",
"new",
"Curl",
"(",
"$",
"curl_options",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'url'",
":",
"$",
"status",
"=",
"$",
"curl",
"->",
"logoutUrl",
"(",
")",
";",
"break",
";",
"case",
"'form'",
":",
"$",
"status",
"=",
"$",
"curl",
"->",
"login",
"(",
")",
";",
"break",
";",
"case",
"'brute_force'",
":",
"default",
":",
"$",
"status",
"=",
"$",
"curl",
"->",
"logout",
"(",
")",
";",
"}",
"$",
"status",
"[",
"LogLevel",
"::",
"DEBUG",
"]",
"[",
"]",
"=",
"Text",
"::",
"_",
"(",
"'CURL_LOGOUTTYPE'",
")",
".",
"'='",
".",
"$",
"type",
";",
"return",
"$",
"status",
";",
"}"
] | Function that automatically logs out the user from the integrated software
@param Userinfo $userinfo contains the userinfo
@param array $options contains Array with the login options, such as remember_me
@param string $type method of destruction
@param array $curl_options_merge
@return array result Array containing the result of the session destroy | [
"Function",
"that",
"automatically",
"logs",
"out",
"the",
"user",
"from",
"the",
"integrated",
"software"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L931-L1045 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.getCorrectUserGroups | final public function getCorrectUserGroups(Userinfo $userinfo)
{
$jname = $this->getJname();
$group = array();
$master = Framework::getMaster();
if ($master) {
if ($master->name == $jname) {
$group = Groups::get($master->name, true);
} else {
$slavegroups = Groups::get($jname);
$user = Factory::getUser($master->name);
$index = $user->getUserGroupIndex($userinfo);
if (isset($slavegroups[$index])) {
$group = $slavegroups[$index];
}
if ($group === null && isset($slavegroups[0])) {
$group = $slavegroups[0];
}
}
}
if (!is_array($group)) {
if ($group !== null) {
$group = array($group);
} else {
$group = array();
}
}
return $group;
} | php | final public function getCorrectUserGroups(Userinfo $userinfo)
{
$jname = $this->getJname();
$group = array();
$master = Framework::getMaster();
if ($master) {
if ($master->name == $jname) {
$group = Groups::get($master->name, true);
} else {
$slavegroups = Groups::get($jname);
$user = Factory::getUser($master->name);
$index = $user->getUserGroupIndex($userinfo);
if (isset($slavegroups[$index])) {
$group = $slavegroups[$index];
}
if ($group === null && isset($slavegroups[0])) {
$group = $slavegroups[0];
}
}
}
if (!is_array($group)) {
if ($group !== null) {
$group = array($group);
} else {
$group = array();
}
}
return $group;
} | [
"final",
"public",
"function",
"getCorrectUserGroups",
"(",
"Userinfo",
"$",
"userinfo",
")",
"{",
"$",
"jname",
"=",
"$",
"this",
"->",
"getJname",
"(",
")",
";",
"$",
"group",
"=",
"array",
"(",
")",
";",
"$",
"master",
"=",
"Framework",
"::",
"getMaster",
"(",
")",
";",
"if",
"(",
"$",
"master",
")",
"{",
"if",
"(",
"$",
"master",
"->",
"name",
"==",
"$",
"jname",
")",
"{",
"$",
"group",
"=",
"Groups",
"::",
"get",
"(",
"$",
"master",
"->",
"name",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"slavegroups",
"=",
"Groups",
"::",
"get",
"(",
"$",
"jname",
")",
";",
"$",
"user",
"=",
"Factory",
"::",
"getUser",
"(",
"$",
"master",
"->",
"name",
")",
";",
"$",
"index",
"=",
"$",
"user",
"->",
"getUserGroupIndex",
"(",
"$",
"userinfo",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"slavegroups",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"group",
"=",
"$",
"slavegroups",
"[",
"$",
"index",
"]",
";",
"}",
"if",
"(",
"$",
"group",
"===",
"null",
"&&",
"isset",
"(",
"$",
"slavegroups",
"[",
"0",
"]",
")",
")",
"{",
"$",
"group",
"=",
"$",
"slavegroups",
"[",
"0",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"group",
")",
")",
"{",
"if",
"(",
"$",
"group",
"!==",
"null",
")",
"{",
"$",
"group",
"=",
"array",
"(",
"$",
"group",
")",
";",
"}",
"else",
"{",
"$",
"group",
"=",
"array",
"(",
")",
";",
"}",
"}",
"return",
"$",
"group",
";",
"}"
] | return the correct usergroups for a given user
@param Userinfo|null $userinfo user with correct usergroups, if null it will return the usergroup for new users
@return array | [
"return",
"the",
"correct",
"usergroups",
"for",
"a",
"given",
"user"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L1054-L1087 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.addCookie | final public function addCookie($name, $value, $expires, $path, $domain, $secure = false, $httponly = false, $mask = false)
{
$cookies = Factory::getCookies();
return $cookies->addCookie($name, $value, $expires, $path, $domain, $secure, $httponly, $mask);
} | php | final public function addCookie($name, $value, $expires, $path, $domain, $secure = false, $httponly = false, $mask = false)
{
$cookies = Factory::getCookies();
return $cookies->addCookie($name, $value, $expires, $path, $domain, $secure, $httponly, $mask);
} | [
"final",
"public",
"function",
"addCookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"expires",
",",
"$",
"path",
",",
"$",
"domain",
",",
"$",
"secure",
"=",
"false",
",",
"$",
"httponly",
"=",
"false",
",",
"$",
"mask",
"=",
"false",
")",
"{",
"$",
"cookies",
"=",
"Factory",
"::",
"getCookies",
"(",
")",
";",
"return",
"$",
"cookies",
"->",
"addCookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"expires",
",",
"$",
"path",
",",
"$",
"domain",
",",
"$",
"secure",
",",
"$",
"httponly",
",",
"$",
"mask",
")",
";",
"}"
] | Adds a cookie to the php header
@param string $name cookie name
@param string $value cookie value
@param int $expires cookie expiry time
@param string $path cookie path
@param string $domain cookie domain
@param bool $secure is the secure
@param bool $httponly is the cookie http only
@param bool $mask should debug info be masked ?
@return array cookie debug info | [
"Adds",
"a",
"cookie",
"to",
"the",
"php",
"header"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L1103-L1107 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.lookupUser | final public function lookupUser(Userinfo $exsistinginfo)
{
$user = null;
if ($exsistinginfo) {
//initialise some vars
$db = Factory::getDBO();
$query = $db->getQuery(true)
->select('b.userid, b.username, b.email')
->from('#__jfusion_users AS a')
->innerJoin('#__jfusion_users AS b ON a.id = b.id')
->where('b.jname = ' . $db->quote($this->getJname()))
->where('a.jname = ' . $db->quote($exsistinginfo->getJname()));
$search = array();
if (isset($exsistinginfo->userid)) {
$search[] = 'a.userid = ' . $db->quote($exsistinginfo->userid);
}
if (isset($exsistinginfo->username)) {
$search[] = 'a.username = ' . $db->quote($exsistinginfo->username);
}
if (isset($exsistinginfo->email)) {
$search[] = 'a.email = ' . $db->quote($exsistinginfo->email);
}
if (!empty($search)) {
$query->where('( ' . implode(' OR ', $search) . ' )');
$db->setQuery($query);
$result = $db->loadObject();
if ($result) {
$user = new Userinfo($this->getJname());
$user->bind($result);
}
}
}
return $user;
} | php | final public function lookupUser(Userinfo $exsistinginfo)
{
$user = null;
if ($exsistinginfo) {
//initialise some vars
$db = Factory::getDBO();
$query = $db->getQuery(true)
->select('b.userid, b.username, b.email')
->from('#__jfusion_users AS a')
->innerJoin('#__jfusion_users AS b ON a.id = b.id')
->where('b.jname = ' . $db->quote($this->getJname()))
->where('a.jname = ' . $db->quote($exsistinginfo->getJname()));
$search = array();
if (isset($exsistinginfo->userid)) {
$search[] = 'a.userid = ' . $db->quote($exsistinginfo->userid);
}
if (isset($exsistinginfo->username)) {
$search[] = 'a.username = ' . $db->quote($exsistinginfo->username);
}
if (isset($exsistinginfo->email)) {
$search[] = 'a.email = ' . $db->quote($exsistinginfo->email);
}
if (!empty($search)) {
$query->where('( ' . implode(' OR ', $search) . ' )');
$db->setQuery($query);
$result = $db->loadObject();
if ($result) {
$user = new Userinfo($this->getJname());
$user->bind($result);
}
}
}
return $user;
} | [
"final",
"public",
"function",
"lookupUser",
"(",
"Userinfo",
"$",
"exsistinginfo",
")",
"{",
"$",
"user",
"=",
"null",
";",
"if",
"(",
"$",
"exsistinginfo",
")",
"{",
"//initialise some vars",
"$",
"db",
"=",
"Factory",
"::",
"getDBO",
"(",
")",
";",
"$",
"query",
"=",
"$",
"db",
"->",
"getQuery",
"(",
"true",
")",
"->",
"select",
"(",
"'b.userid, b.username, b.email'",
")",
"->",
"from",
"(",
"'#__jfusion_users AS a'",
")",
"->",
"innerJoin",
"(",
"'#__jfusion_users AS b ON a.id = b.id'",
")",
"->",
"where",
"(",
"'b.jname = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
")",
"->",
"where",
"(",
"'a.jname = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
")",
")",
";",
"$",
"search",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"exsistinginfo",
"->",
"userid",
")",
")",
"{",
"$",
"search",
"[",
"]",
"=",
"'a.userid = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exsistinginfo",
"->",
"userid",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"exsistinginfo",
"->",
"username",
")",
")",
"{",
"$",
"search",
"[",
"]",
"=",
"'a.username = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exsistinginfo",
"->",
"username",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"exsistinginfo",
"->",
"email",
")",
")",
"{",
"$",
"search",
"[",
"]",
"=",
"'a.email = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exsistinginfo",
"->",
"email",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"search",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'( '",
".",
"implode",
"(",
"' OR '",
",",
"$",
"search",
")",
".",
"' )'",
")",
";",
"$",
"db",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"loadObject",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"user",
"=",
"new",
"Userinfo",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
";",
"$",
"user",
"->",
"bind",
"(",
"$",
"result",
")",
";",
"}",
"}",
"}",
"return",
"$",
"user",
";",
"}"
] | Returns the userinfo data for JFusion plugin based on the userid
@param Userinfo $exsistinginfo user info
@return Userinfo|null returns user login info from the requester software or null | [
"Returns",
"the",
"userinfo",
"data",
"for",
"JFusion",
"plugin",
"based",
"on",
"the",
"userid"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L1117-L1153 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.updateLookup | final public function updateLookup(Userinfo $userinfo, Userinfo $exsistinginfo)
{
$jname = $this->getJname();
if ($userinfo->getJname() == $jname) {
$db = Factory::getDBO();
//we don't need to update the lookup for internal joomla unless deleting a user
try {
$query = $db->getQuery(true)
->select('*')
->from('#__jfusion_users')
->where('( userid = ' . $db->quote($exsistinginfo->userid) . ' AND ' . 'jname = ' . $db->quote($exsistinginfo->getJname()) . ' )', 'OR')
->where('( email = ' . $db->quote($userinfo->email) . ' AND ' . 'jname = ' . $db->quote($exsistinginfo->getJname()) . ' )', 'OR');
if ($jname != $exsistinginfo->getJname()) {
$query->where('( userid = ' . $db->quote($userinfo->userid) . ' AND ' . 'jname = ' . $db->quote($jname) . ' )', 'OR')
->where('( email = ' . $db->quote($userinfo->email) . ' AND ' . 'jname = ' . $db->quote($jname) . ' )', 'OR');
}
$db->setQuery($query);
$list = $db->loadObjectList('jname');
if (empty($list)) {
$first = new stdClass();
$first->id = -1;
$first->username = $exsistinginfo->username;
$first->userid = $exsistinginfo->userid;
$first->email = $exsistinginfo->email;
$first->jname = $exsistinginfo->getJname();
$db->insertObject('#__jfusion_users', $first, 'autoid');
$first->id = $first->autoid;
$db->updateObject('#__jfusion_users', $first, 'autoid');
if ($jname != $exsistinginfo->getJname()) {
$second = new stdClass();
$second->id = $first->id;
$second->username = $userinfo->username;
$second->userid = $userinfo->userid;
$second->email = $userinfo->email;
$second->jname = $jname;
$db->insertObject('#__jfusion_users', $second);
}
} else if (!isset($list[$exsistinginfo->getJname()])) {
$first = new stdClass();
$first->id = $list[$jname]->id;
$first->username = $exsistinginfo->username;
$first->userid = $exsistinginfo->userid;
$first->email = $exsistinginfo->email;
$first->jname = $exsistinginfo->getJname();
$db->insertObject('#__jfusion_users', $first, 'autoid');
} else if (!isset($list[$jname])) {
$first = new stdClass();
$first->id = $list[$exsistinginfo->getJname()]->id;
$first->username = $userinfo->username;
$first->userid = $userinfo->userid;
$first->userid = $userinfo->userid;
$first->jname = $jname;
$db->insertObject('#__jfusion_users', $first, 'autoid');
} else {
$first = $list[$jname];
$first->username = $userinfo->username;
$first->userid = $userinfo->userid;
$first->email = $userinfo->email;
$db->updateObject('#__jfusion_users', $first, 'autoid');
}
return true;
} catch (Exception $e) {
echo $e->getMessage();
Framework::raise(LogLevel::ERROR, $e);
}
}
return false;
} | php | final public function updateLookup(Userinfo $userinfo, Userinfo $exsistinginfo)
{
$jname = $this->getJname();
if ($userinfo->getJname() == $jname) {
$db = Factory::getDBO();
//we don't need to update the lookup for internal joomla unless deleting a user
try {
$query = $db->getQuery(true)
->select('*')
->from('#__jfusion_users')
->where('( userid = ' . $db->quote($exsistinginfo->userid) . ' AND ' . 'jname = ' . $db->quote($exsistinginfo->getJname()) . ' )', 'OR')
->where('( email = ' . $db->quote($userinfo->email) . ' AND ' . 'jname = ' . $db->quote($exsistinginfo->getJname()) . ' )', 'OR');
if ($jname != $exsistinginfo->getJname()) {
$query->where('( userid = ' . $db->quote($userinfo->userid) . ' AND ' . 'jname = ' . $db->quote($jname) . ' )', 'OR')
->where('( email = ' . $db->quote($userinfo->email) . ' AND ' . 'jname = ' . $db->quote($jname) . ' )', 'OR');
}
$db->setQuery($query);
$list = $db->loadObjectList('jname');
if (empty($list)) {
$first = new stdClass();
$first->id = -1;
$first->username = $exsistinginfo->username;
$first->userid = $exsistinginfo->userid;
$first->email = $exsistinginfo->email;
$first->jname = $exsistinginfo->getJname();
$db->insertObject('#__jfusion_users', $first, 'autoid');
$first->id = $first->autoid;
$db->updateObject('#__jfusion_users', $first, 'autoid');
if ($jname != $exsistinginfo->getJname()) {
$second = new stdClass();
$second->id = $first->id;
$second->username = $userinfo->username;
$second->userid = $userinfo->userid;
$second->email = $userinfo->email;
$second->jname = $jname;
$db->insertObject('#__jfusion_users', $second);
}
} else if (!isset($list[$exsistinginfo->getJname()])) {
$first = new stdClass();
$first->id = $list[$jname]->id;
$first->username = $exsistinginfo->username;
$first->userid = $exsistinginfo->userid;
$first->email = $exsistinginfo->email;
$first->jname = $exsistinginfo->getJname();
$db->insertObject('#__jfusion_users', $first, 'autoid');
} else if (!isset($list[$jname])) {
$first = new stdClass();
$first->id = $list[$exsistinginfo->getJname()]->id;
$first->username = $userinfo->username;
$first->userid = $userinfo->userid;
$first->userid = $userinfo->userid;
$first->jname = $jname;
$db->insertObject('#__jfusion_users', $first, 'autoid');
} else {
$first = $list[$jname];
$first->username = $userinfo->username;
$first->userid = $userinfo->userid;
$first->email = $userinfo->email;
$db->updateObject('#__jfusion_users', $first, 'autoid');
}
return true;
} catch (Exception $e) {
echo $e->getMessage();
Framework::raise(LogLevel::ERROR, $e);
}
}
return false;
} | [
"final",
"public",
"function",
"updateLookup",
"(",
"Userinfo",
"$",
"userinfo",
",",
"Userinfo",
"$",
"exsistinginfo",
")",
"{",
"$",
"jname",
"=",
"$",
"this",
"->",
"getJname",
"(",
")",
";",
"if",
"(",
"$",
"userinfo",
"->",
"getJname",
"(",
")",
"==",
"$",
"jname",
")",
"{",
"$",
"db",
"=",
"Factory",
"::",
"getDBO",
"(",
")",
";",
"//we don't need to update the lookup for internal joomla unless deleting a user",
"try",
"{",
"$",
"query",
"=",
"$",
"db",
"->",
"getQuery",
"(",
"true",
")",
"->",
"select",
"(",
"'*'",
")",
"->",
"from",
"(",
"'#__jfusion_users'",
")",
"->",
"where",
"(",
"'( userid = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exsistinginfo",
"->",
"userid",
")",
".",
"' AND '",
".",
"'jname = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
")",
".",
"' )'",
",",
"'OR'",
")",
"->",
"where",
"(",
"'( email = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"userinfo",
"->",
"email",
")",
".",
"' AND '",
".",
"'jname = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
")",
".",
"' )'",
",",
"'OR'",
")",
";",
"if",
"(",
"$",
"jname",
"!=",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'( userid = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"userinfo",
"->",
"userid",
")",
".",
"' AND '",
".",
"'jname = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"jname",
")",
".",
"' )'",
",",
"'OR'",
")",
"->",
"where",
"(",
"'( email = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"userinfo",
"->",
"email",
")",
".",
"' AND '",
".",
"'jname = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"jname",
")",
".",
"' )'",
",",
"'OR'",
")",
";",
"}",
"$",
"db",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"$",
"list",
"=",
"$",
"db",
"->",
"loadObjectList",
"(",
"'jname'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"list",
")",
")",
"{",
"$",
"first",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"first",
"->",
"id",
"=",
"-",
"1",
";",
"$",
"first",
"->",
"username",
"=",
"$",
"exsistinginfo",
"->",
"username",
";",
"$",
"first",
"->",
"userid",
"=",
"$",
"exsistinginfo",
"->",
"userid",
";",
"$",
"first",
"->",
"email",
"=",
"$",
"exsistinginfo",
"->",
"email",
";",
"$",
"first",
"->",
"jname",
"=",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
";",
"$",
"db",
"->",
"insertObject",
"(",
"'#__jfusion_users'",
",",
"$",
"first",
",",
"'autoid'",
")",
";",
"$",
"first",
"->",
"id",
"=",
"$",
"first",
"->",
"autoid",
";",
"$",
"db",
"->",
"updateObject",
"(",
"'#__jfusion_users'",
",",
"$",
"first",
",",
"'autoid'",
")",
";",
"if",
"(",
"$",
"jname",
"!=",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
")",
"{",
"$",
"second",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"second",
"->",
"id",
"=",
"$",
"first",
"->",
"id",
";",
"$",
"second",
"->",
"username",
"=",
"$",
"userinfo",
"->",
"username",
";",
"$",
"second",
"->",
"userid",
"=",
"$",
"userinfo",
"->",
"userid",
";",
"$",
"second",
"->",
"email",
"=",
"$",
"userinfo",
"->",
"email",
";",
"$",
"second",
"->",
"jname",
"=",
"$",
"jname",
";",
"$",
"db",
"->",
"insertObject",
"(",
"'#__jfusion_users'",
",",
"$",
"second",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"list",
"[",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
"]",
")",
")",
"{",
"$",
"first",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"first",
"->",
"id",
"=",
"$",
"list",
"[",
"$",
"jname",
"]",
"->",
"id",
";",
"$",
"first",
"->",
"username",
"=",
"$",
"exsistinginfo",
"->",
"username",
";",
"$",
"first",
"->",
"userid",
"=",
"$",
"exsistinginfo",
"->",
"userid",
";",
"$",
"first",
"->",
"email",
"=",
"$",
"exsistinginfo",
"->",
"email",
";",
"$",
"first",
"->",
"jname",
"=",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
";",
"$",
"db",
"->",
"insertObject",
"(",
"'#__jfusion_users'",
",",
"$",
"first",
",",
"'autoid'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"list",
"[",
"$",
"jname",
"]",
")",
")",
"{",
"$",
"first",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"first",
"->",
"id",
"=",
"$",
"list",
"[",
"$",
"exsistinginfo",
"->",
"getJname",
"(",
")",
"]",
"->",
"id",
";",
"$",
"first",
"->",
"username",
"=",
"$",
"userinfo",
"->",
"username",
";",
"$",
"first",
"->",
"userid",
"=",
"$",
"userinfo",
"->",
"userid",
";",
"$",
"first",
"->",
"userid",
"=",
"$",
"userinfo",
"->",
"userid",
";",
"$",
"first",
"->",
"jname",
"=",
"$",
"jname",
";",
"$",
"db",
"->",
"insertObject",
"(",
"'#__jfusion_users'",
",",
"$",
"first",
",",
"'autoid'",
")",
";",
"}",
"else",
"{",
"$",
"first",
"=",
"$",
"list",
"[",
"$",
"jname",
"]",
";",
"$",
"first",
"->",
"username",
"=",
"$",
"userinfo",
"->",
"username",
";",
"$",
"first",
"->",
"userid",
"=",
"$",
"userinfo",
"->",
"userid",
";",
"$",
"first",
"->",
"email",
"=",
"$",
"userinfo",
"->",
"email",
";",
"$",
"db",
"->",
"updateObject",
"(",
"'#__jfusion_users'",
",",
"$",
"first",
",",
"'autoid'",
")",
";",
"}",
"return",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"echo",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"Framework",
"::",
"raise",
"(",
"LogLevel",
"::",
"ERROR",
",",
"$",
"e",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Updates the JFusion user lookup table during login
@param Userinfo $userinfo object containing the userdata
@param Userinfo $exsistinginfo object containing the userdata
@return bool | [
"Updates",
"the",
"JFusion",
"user",
"lookup",
"table",
"during",
"login"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L1163-L1233 |
jfusion/org.jfusion.framework | src/Plugin/User.php | User.deleteLookup | final public function deleteLookup(Userinfo $userinfo)
{
if ($userinfo->getJname() == $this->getJname()) {
$db = Factory::getDBO();
//we don't need to update the lookup for internal joomla unless deleting a user
try {
$query = $db->getQuery(true)
->delete('#__jfusion_users')
->where('userid = ' . $db->quote($userinfo->userid))
->where('jname = ' . $db->quote($this->getJname()));
$db->setQuery($query);
$db->execute();
return true;
} catch (Exception $e) {
Framework::raise(LogLevel::ERROR, $e);
}
}
return false;
} | php | final public function deleteLookup(Userinfo $userinfo)
{
if ($userinfo->getJname() == $this->getJname()) {
$db = Factory::getDBO();
//we don't need to update the lookup for internal joomla unless deleting a user
try {
$query = $db->getQuery(true)
->delete('#__jfusion_users')
->where('userid = ' . $db->quote($userinfo->userid))
->where('jname = ' . $db->quote($this->getJname()));
$db->setQuery($query);
$db->execute();
return true;
} catch (Exception $e) {
Framework::raise(LogLevel::ERROR, $e);
}
}
return false;
} | [
"final",
"public",
"function",
"deleteLookup",
"(",
"Userinfo",
"$",
"userinfo",
")",
"{",
"if",
"(",
"$",
"userinfo",
"->",
"getJname",
"(",
")",
"==",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
"{",
"$",
"db",
"=",
"Factory",
"::",
"getDBO",
"(",
")",
";",
"//we don't need to update the lookup for internal joomla unless deleting a user",
"try",
"{",
"$",
"query",
"=",
"$",
"db",
"->",
"getQuery",
"(",
"true",
")",
"->",
"delete",
"(",
"'#__jfusion_users'",
")",
"->",
"where",
"(",
"'userid = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"userinfo",
"->",
"userid",
")",
")",
"->",
"where",
"(",
"'jname = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"this",
"->",
"getJname",
"(",
")",
")",
")",
";",
"$",
"db",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"$",
"db",
"->",
"execute",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"Framework",
"::",
"raise",
"(",
"LogLevel",
"::",
"ERROR",
",",
"$",
"e",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Updates the JFusion user lookup table during login
@param Userinfo $userinfo object containing the userdata
@return bool | [
"Updates",
"the",
"JFusion",
"user",
"lookup",
"table",
"during",
"login"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/User.php#L1242-L1262 |
firefinancialservices/fire-business-api-php | Fire/Business/Api/AccountDetails.php | AccountDetails.fireTransfer | public function fireTransfer($transfer) {
$ft = new FireTransfer($this->api, $this->solution['accountId']);
return $ft->transfer($transfer);
} | php | public function fireTransfer($transfer) {
$ft = new FireTransfer($this->api, $this->solution['accountId']);
return $ft->transfer($transfer);
} | [
"public",
"function",
"fireTransfer",
"(",
"$",
"transfer",
")",
"{",
"$",
"ft",
"=",
"new",
"FireTransfer",
"(",
"$",
"this",
"->",
"api",
",",
"$",
"this",
"->",
"solution",
"[",
"'accountId'",
"]",
")",
";",
"return",
"$",
"ft",
"->",
"transfer",
"(",
"$",
"transfer",
")",
";",
"}"
] | TODO change to internal transfer batch | [
"TODO",
"change",
"to",
"internal",
"transfer",
"batch"
] | train | https://github.com/firefinancialservices/fire-business-api-php/blob/77b8328163010af4d4d1f589cecc2e60176542ff/Fire/Business/Api/AccountDetails.php#L32-L35 |
yuncms/framework | migrations/m180428_084537_create_tasks_table.php | m180428_084537_create_tasks_table.safeUp | public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable($this->tableName, [
'id' => $this->primaryKey(),
'name' => $this->string(50)->notNull(),//定时任务名称
'route' => $this->string(100)->notNull(),//任务路由
'crontab_str' => $this->string(50)->notNull(),//crontab格式
'switch' => $this->boolean()->notNull()->defaultValue(false),//任务开关 0关闭 1开启
'status' => $this->boolean()->defaultValue(false),//任务运行状态 0正常 1任务报错
'last_rundate' => $this->dateTime()->null(),//任务上次运行时间
'next_rundate' => $this->dateTime()->null(),//任务下次运行时间
'execmemory' => $this->decimal(9,2)->defaultValue('0.00'),//任务执行消耗内存(单位/byte)
'exectime' => $this->decimal(9,2)->defaultValue('0.00'),//任务执行消耗时间
], $tableOptions);
} | php | public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
$this->createTable($this->tableName, [
'id' => $this->primaryKey(),
'name' => $this->string(50)->notNull(),//定时任务名称
'route' => $this->string(100)->notNull(),//任务路由
'crontab_str' => $this->string(50)->notNull(),//crontab格式
'switch' => $this->boolean()->notNull()->defaultValue(false),//任务开关 0关闭 1开启
'status' => $this->boolean()->defaultValue(false),//任务运行状态 0正常 1任务报错
'last_rundate' => $this->dateTime()->null(),//任务上次运行时间
'next_rundate' => $this->dateTime()->null(),//任务下次运行时间
'execmemory' => $this->decimal(9,2)->defaultValue('0.00'),//任务执行消耗内存(单位/byte)
'exectime' => $this->decimal(9,2)->defaultValue('0.00'),//任务执行消耗时间
], $tableOptions);
} | [
"public",
"function",
"safeUp",
"(",
")",
"{",
"$",
"tableOptions",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"driverName",
"===",
"'mysql'",
")",
"{",
"// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci",
"$",
"tableOptions",
"=",
"'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'",
";",
"}",
"$",
"this",
"->",
"createTable",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"primaryKey",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"string",
"(",
"50",
")",
"->",
"notNull",
"(",
")",
",",
"//定时任务名称",
"'route'",
"=>",
"$",
"this",
"->",
"string",
"(",
"100",
")",
"->",
"notNull",
"(",
")",
",",
"//任务路由",
"'crontab_str'",
"=>",
"$",
"this",
"->",
"string",
"(",
"50",
")",
"->",
"notNull",
"(",
")",
",",
"//crontab格式",
"'switch'",
"=>",
"$",
"this",
"->",
"boolean",
"(",
")",
"->",
"notNull",
"(",
")",
"->",
"defaultValue",
"(",
"false",
")",
",",
"//任务开关 0关闭 1开启",
"'status'",
"=>",
"$",
"this",
"->",
"boolean",
"(",
")",
"->",
"defaultValue",
"(",
"false",
")",
",",
"//任务运行状态 0正常 1任务报错",
"'last_rundate'",
"=>",
"$",
"this",
"->",
"dateTime",
"(",
")",
"->",
"null",
"(",
")",
",",
"//任务上次运行时间",
"'next_rundate'",
"=>",
"$",
"this",
"->",
"dateTime",
"(",
")",
"->",
"null",
"(",
")",
",",
"//任务下次运行时间",
"'execmemory'",
"=>",
"$",
"this",
"->",
"decimal",
"(",
"9",
",",
"2",
")",
"->",
"defaultValue",
"(",
"'0.00'",
")",
",",
"//任务执行消耗内存(单位/byte)",
"'exectime'",
"=>",
"$",
"this",
"->",
"decimal",
"(",
"9",
",",
"2",
")",
"->",
"defaultValue",
"(",
"'0.00'",
")",
",",
"//任务执行消耗时间",
"]",
",",
"$",
"tableOptions",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/migrations/m180428_084537_create_tasks_table.php#L18-L37 |
fubhy/graphql-php | src/Type/Definition/Types/EnumType.php | EnumType.coerce | public function coerce($value)
{
$enumValue = $this->getValueLookup()[$value];
return $enumValue ? $enumValue->getName() : NULL;
} | php | public function coerce($value)
{
$enumValue = $this->getValueLookup()[$value];
return $enumValue ? $enumValue->getName() : NULL;
} | [
"public",
"function",
"coerce",
"(",
"$",
"value",
")",
"{",
"$",
"enumValue",
"=",
"$",
"this",
"->",
"getValueLookup",
"(",
")",
"[",
"$",
"value",
"]",
";",
"return",
"$",
"enumValue",
"?",
"$",
"enumValue",
"->",
"getName",
"(",
")",
":",
"NULL",
";",
"}"
] | @param mixed $value
@return string|null | [
"@param",
"mixed",
"$value"
] | train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Type/Definition/Types/EnumType.php#L81-L85 |
fubhy/graphql-php | src/Type/Definition/Types/EnumType.php | EnumType.coerceLiteral | public function coerceLiteral(Node $value)
{
if ($value instanceof EnumValue) {
$key = $value->get('value');
if (($lookup = $this->getNameLookup()) && isset($lookup[$key])) {
return $lookup[$key] ? $lookup[$key]->getName() : NULL;
}
}
return NULL;
} | php | public function coerceLiteral(Node $value)
{
if ($value instanceof EnumValue) {
$key = $value->get('value');
if (($lookup = $this->getNameLookup()) && isset($lookup[$key])) {
return $lookup[$key] ? $lookup[$key]->getName() : NULL;
}
}
return NULL;
} | [
"public",
"function",
"coerceLiteral",
"(",
"Node",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"EnumValue",
")",
"{",
"$",
"key",
"=",
"$",
"value",
"->",
"get",
"(",
"'value'",
")",
";",
"if",
"(",
"(",
"$",
"lookup",
"=",
"$",
"this",
"->",
"getNameLookup",
"(",
")",
")",
"&&",
"isset",
"(",
"$",
"lookup",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"lookup",
"[",
"$",
"key",
"]",
"?",
"$",
"lookup",
"[",
"$",
"key",
"]",
"->",
"getName",
"(",
")",
":",
"NULL",
";",
"}",
"}",
"return",
"NULL",
";",
"}"
] | @param \Fubhy\GraphQL\Language\Node $value
@return string|null | [
"@param",
"\\",
"Fubhy",
"\\",
"GraphQL",
"\\",
"Language",
"\\",
"Node",
"$value"
] | train | https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Type/Definition/Types/EnumType.php#L92-L102 |
yuncms/framework | src/mq/BaseMessage.php | BaseMessage.send | public function send(MessageQueueInterface $messageQueue = null)
{
if ($messageQueue === null && $this->messageQueue === null) {
$messageQueue = Yii::$app->getMessageQueue();
} elseif ($messageQueue === null) {
$messageQueue = $this->messageQueue;
}
return $messageQueue->send($this);
} | php | public function send(MessageQueueInterface $messageQueue = null)
{
if ($messageQueue === null && $this->messageQueue === null) {
$messageQueue = Yii::$app->getMessageQueue();
} elseif ($messageQueue === null) {
$messageQueue = $this->messageQueue;
}
return $messageQueue->send($this);
} | [
"public",
"function",
"send",
"(",
"MessageQueueInterface",
"$",
"messageQueue",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"messageQueue",
"===",
"null",
"&&",
"$",
"this",
"->",
"messageQueue",
"===",
"null",
")",
"{",
"$",
"messageQueue",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getMessageQueue",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"messageQueue",
"===",
"null",
")",
"{",
"$",
"messageQueue",
"=",
"$",
"this",
"->",
"messageQueue",
";",
"}",
"return",
"$",
"messageQueue",
"->",
"send",
"(",
"$",
"this",
")",
";",
"}"
] | Sends this message queue message.
@param MessageQueueInterface $messageQueue the message queue that should be used to send this message.
If no message queue is given it will first check if [[messageQueue]] is set and if not,
the "messageQueue" application component will be used instead.
@return bool whether this message is sent successfully. | [
"Sends",
"this",
"message",
"queue",
"message",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/mq/BaseMessage.php#L110-L118 |
php-rise/rise | src/Session.php | Session.getFlash | public function getFlash($key) {
return $this->started && isset($_SESSION[$this->flashSessionKey][$key])
? $_SESSION[$this->flashSessionKey][$key]
: null;
} | php | public function getFlash($key) {
return $this->started && isset($_SESSION[$this->flashSessionKey][$key])
? $_SESSION[$this->flashSessionKey][$key]
: null;
} | [
"public",
"function",
"getFlash",
"(",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"started",
"&&",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"flashSessionKey",
"]",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"flashSessionKey",
"]",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Get data from the current flash messages bag.
@param string $key
@return mixed | [
"Get",
"data",
"from",
"the",
"current",
"flash",
"messages",
"bag",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Session.php#L116-L120 |
php-rise/rise | src/Session.php | Session.setFlash | public function setFlash($key, $value) {
if (!$this->started) {
return $this;
}
$_SESSION[$this->nextFlashSessionKey][$key] = $value;
return $this;
} | php | public function setFlash($key, $value) {
if (!$this->started) {
return $this;
}
$_SESSION[$this->nextFlashSessionKey][$key] = $value;
return $this;
} | [
"public",
"function",
"setFlash",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"nextFlashSessionKey",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set data to the flash messages bag for the next request.
@param string $key
@param mixed $value
@return self | [
"Set",
"data",
"to",
"the",
"flash",
"messages",
"bag",
"for",
"the",
"next",
"request",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Session.php#L129-L136 |
php-rise/rise | src/Session.php | Session.toNextFlash | public function toNextFlash() {
if (!$this->started) {
return $this;
}
$_SESSION[$this->flashSessionKey] =
isset($_SESSION[$this->nextFlashSessionKey])
? $_SESSION[$this->nextFlashSessionKey]
: [];
$_SESSION[$this->nextFlashSessionKey] = [];
return $this;
} | php | public function toNextFlash() {
if (!$this->started) {
return $this;
}
$_SESSION[$this->flashSessionKey] =
isset($_SESSION[$this->nextFlashSessionKey])
? $_SESSION[$this->nextFlashSessionKey]
: [];
$_SESSION[$this->nextFlashSessionKey] = [];
return $this;
} | [
"public",
"function",
"toNextFlash",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"flashSessionKey",
"]",
"=",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"nextFlashSessionKey",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"nextFlashSessionKey",
"]",
":",
"[",
"]",
";",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"nextFlashSessionKey",
"]",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Copy the next flash data to current flash. This should be done in the end of request.
@return self | [
"Copy",
"the",
"next",
"flash",
"data",
"to",
"current",
"flash",
".",
"This",
"should",
"be",
"done",
"in",
"the",
"end",
"of",
"request",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Session.php#L153-L165 |
php-rise/rise | src/Session.php | Session.generateCsrfToken | public function generateCsrfToken() {
$token = hash("sha512", mt_rand(0, mt_getrandmax()));
$_SESSION[$this->csrfTokenSessionKey] = $token;
return $token;
} | php | public function generateCsrfToken() {
$token = hash("sha512", mt_rand(0, mt_getrandmax()));
$_SESSION[$this->csrfTokenSessionKey] = $token;
return $token;
} | [
"public",
"function",
"generateCsrfToken",
"(",
")",
"{",
"$",
"token",
"=",
"hash",
"(",
"\"sha512\"",
",",
"mt_rand",
"(",
"0",
",",
"mt_getrandmax",
"(",
")",
")",
")",
";",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"csrfTokenSessionKey",
"]",
"=",
"$",
"token",
";",
"return",
"$",
"token",
";",
"}"
] | Generate CSRF token.
@return string | [
"Generate",
"CSRF",
"token",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Session.php#L172-L176 |
php-rise/rise | src/Session.php | Session.getCsrfToken | public function getCsrfToken() {
if (!isset($_SESSION[$this->csrfTokenSessionKey])) {
$this->generateCsrfToken();
}
return $_SESSION[$this->csrfTokenSessionKey];
} | php | public function getCsrfToken() {
if (!isset($_SESSION[$this->csrfTokenSessionKey])) {
$this->generateCsrfToken();
}
return $_SESSION[$this->csrfTokenSessionKey];
} | [
"public",
"function",
"getCsrfToken",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"csrfTokenSessionKey",
"]",
")",
")",
"{",
"$",
"this",
"->",
"generateCsrfToken",
"(",
")",
";",
"}",
"return",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"csrfTokenSessionKey",
"]",
";",
"}"
] | Get CSRF token.
@return string | [
"Get",
"CSRF",
"token",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Session.php#L183-L188 |
php-rise/rise | src/Session.php | Session.validateCsrfToken | public function validateCsrfToken($token) {
return (
isset($_SESSION[$this->csrfTokenSessionKey])
&& $_SESSION[$this->csrfTokenSessionKey] === $token
);
} | php | public function validateCsrfToken($token) {
return (
isset($_SESSION[$this->csrfTokenSessionKey])
&& $_SESSION[$this->csrfTokenSessionKey] === $token
);
} | [
"public",
"function",
"validateCsrfToken",
"(",
"$",
"token",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"csrfTokenSessionKey",
"]",
")",
"&&",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"csrfTokenSessionKey",
"]",
"===",
"$",
"token",
")",
";",
"}"
] | Validate with the token stored in session.
@param string $token
@return bool | [
"Validate",
"with",
"the",
"token",
"stored",
"in",
"session",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Session.php#L214-L219 |
php-rise/rise | src/Session.php | Session.readConfig | protected function readConfig() {
$file = $this->path->getConfigPath() . '/session.php';
if (file_exists($file)) {
$config = require($file);
$this->enabled = true;
if (isset($config['options']) && is_array($config['options'])) {
$this->startOptions = $config['options'];
}
}
} | php | protected function readConfig() {
$file = $this->path->getConfigPath() . '/session.php';
if (file_exists($file)) {
$config = require($file);
$this->enabled = true;
if (isset($config['options']) && is_array($config['options'])) {
$this->startOptions = $config['options'];
}
}
} | [
"protected",
"function",
"readConfig",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"path",
"->",
"getConfigPath",
"(",
")",
".",
"'/session.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"config",
"=",
"require",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"enabled",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"startOptions",
"=",
"$",
"config",
"[",
"'options'",
"]",
";",
"}",
"}",
"}"
] | Read configuration file. | [
"Read",
"configuration",
"file",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Session.php#L243-L254 |
nyeholt/silverstripe-external-content | code/pages/ExternalContentPage.php | ExternalContentPage.RelativeLink | public function RelativeLink($action = null) {
$remoteObject = $this->ContentItem();
if (!is_string($action)) {
$action = null;
}
if ($remoteObject) {
return $this->LinkFor($remoteObject, $action ? $action : 'view');
}
return parent::RelativeLink($action);
} | php | public function RelativeLink($action = null) {
$remoteObject = $this->ContentItem();
if (!is_string($action)) {
$action = null;
}
if ($remoteObject) {
return $this->LinkFor($remoteObject, $action ? $action : 'view');
}
return parent::RelativeLink($action);
} | [
"public",
"function",
"RelativeLink",
"(",
"$",
"action",
"=",
"null",
")",
"{",
"$",
"remoteObject",
"=",
"$",
"this",
"->",
"ContentItem",
"(",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"action",
")",
")",
"{",
"$",
"action",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"remoteObject",
")",
"{",
"return",
"$",
"this",
"->",
"LinkFor",
"(",
"$",
"remoteObject",
",",
"$",
"action",
"?",
"$",
"action",
":",
"'view'",
")",
";",
"}",
"return",
"parent",
"::",
"RelativeLink",
"(",
"$",
"action",
")",
";",
"}"
] | When linking to this external content page, return a URL that'll let
you view the external content item directly
(non-PHPdoc)
@see sapphire/core/model/SiteTree#Link($action) | [
"When",
"linking",
"to",
"this",
"external",
"content",
"page",
"return",
"a",
"URL",
"that",
"ll",
"let",
"you",
"view",
"the",
"external",
"content",
"item",
"directly"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/code/pages/ExternalContentPage.php#L36-L45 |
nyeholt/silverstripe-external-content | code/pages/ExternalContentPage.php | ExternalContentPage.ContentItem | public function ContentItem($what='k') {
if ($this->requestedItem) {
return $this->requestedItem;
}
if (!$this->ExternalContentRoot) {
return null;
}
// See if an item was requested in the url directly
$id = isset($_REQUEST['item']) ? $_REQUEST['item'] : null;
if (!$id) {
$id = $this->ExternalContentRoot;
}
$remoteObject = ExternalContent::getDataObjectFor($id);
if ($remoteObject) {
$this->requestedItem = $remoteObject;
return $this->requestedItem;
}
return null;
} | php | public function ContentItem($what='k') {
if ($this->requestedItem) {
return $this->requestedItem;
}
if (!$this->ExternalContentRoot) {
return null;
}
// See if an item was requested in the url directly
$id = isset($_REQUEST['item']) ? $_REQUEST['item'] : null;
if (!$id) {
$id = $this->ExternalContentRoot;
}
$remoteObject = ExternalContent::getDataObjectFor($id);
if ($remoteObject) {
$this->requestedItem = $remoteObject;
return $this->requestedItem;
}
return null;
} | [
"public",
"function",
"ContentItem",
"(",
"$",
"what",
"=",
"'k'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requestedItem",
")",
"{",
"return",
"$",
"this",
"->",
"requestedItem",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"ExternalContentRoot",
")",
"{",
"return",
"null",
";",
"}",
"// See if an item was requested in the url directly",
"$",
"id",
"=",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'item'",
"]",
")",
"?",
"$",
"_REQUEST",
"[",
"'item'",
"]",
":",
"null",
";",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"ExternalContentRoot",
";",
"}",
"$",
"remoteObject",
"=",
"ExternalContent",
"::",
"getDataObjectFor",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"remoteObject",
")",
"{",
"$",
"this",
"->",
"requestedItem",
"=",
"$",
"remoteObject",
";",
"return",
"$",
"this",
"->",
"requestedItem",
";",
"}",
"return",
"null",
";",
"}"
] | Get the external content item
@return DataObject | [
"Get",
"the",
"external",
"content",
"item"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/code/pages/ExternalContentPage.php#L71-L95 |
nyeholt/silverstripe-external-content | code/pages/ExternalContentPage.php | ExternalContentPage_Controller.view | public function view($request) {
$object = null;
if ($id = $request->param('ID')) {
$object = ExternalContent::getDataObjectFor($id);
if ($object instanceof ExternalContentSource) {
$object = $object->getRoot();
}
if ($object && ($object instanceof ExternalContentItem || $object instanceof ExternalContentSource)) {
$this->data()->setRequestedItem($object);
$type = $object instanceof ExternalContentItem ? $object->getType() : 'source';
$template = 'ExternalContent_' . get_class($object) . '_' . $type;
$viewer = new SSViewer(array($template, 'ExternalContent_' . get_class($object), 'ExternalContent', 'Page'));
$action = 'view';
$this->extend('updateViewer', $action, $viewer);
return $this->customise($object)->renderWith($viewer);
}
}
echo "Template not found for " . ($object ? get_class($object) . ' #' . $object->ID : '');
} | php | public function view($request) {
$object = null;
if ($id = $request->param('ID')) {
$object = ExternalContent::getDataObjectFor($id);
if ($object instanceof ExternalContentSource) {
$object = $object->getRoot();
}
if ($object && ($object instanceof ExternalContentItem || $object instanceof ExternalContentSource)) {
$this->data()->setRequestedItem($object);
$type = $object instanceof ExternalContentItem ? $object->getType() : 'source';
$template = 'ExternalContent_' . get_class($object) . '_' . $type;
$viewer = new SSViewer(array($template, 'ExternalContent_' . get_class($object), 'ExternalContent', 'Page'));
$action = 'view';
$this->extend('updateViewer', $action, $viewer);
return $this->customise($object)->renderWith($viewer);
}
}
echo "Template not found for " . ($object ? get_class($object) . ' #' . $object->ID : '');
} | [
"public",
"function",
"view",
"(",
"$",
"request",
")",
"{",
"$",
"object",
"=",
"null",
";",
"if",
"(",
"$",
"id",
"=",
"$",
"request",
"->",
"param",
"(",
"'ID'",
")",
")",
"{",
"$",
"object",
"=",
"ExternalContent",
"::",
"getDataObjectFor",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"object",
"instanceof",
"ExternalContentSource",
")",
"{",
"$",
"object",
"=",
"$",
"object",
"->",
"getRoot",
"(",
")",
";",
"}",
"if",
"(",
"$",
"object",
"&&",
"(",
"$",
"object",
"instanceof",
"ExternalContentItem",
"||",
"$",
"object",
"instanceof",
"ExternalContentSource",
")",
")",
"{",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"setRequestedItem",
"(",
"$",
"object",
")",
";",
"$",
"type",
"=",
"$",
"object",
"instanceof",
"ExternalContentItem",
"?",
"$",
"object",
"->",
"getType",
"(",
")",
":",
"'source'",
";",
"$",
"template",
"=",
"'ExternalContent_'",
".",
"get_class",
"(",
"$",
"object",
")",
".",
"'_'",
".",
"$",
"type",
";",
"$",
"viewer",
"=",
"new",
"SSViewer",
"(",
"array",
"(",
"$",
"template",
",",
"'ExternalContent_'",
".",
"get_class",
"(",
"$",
"object",
")",
",",
"'ExternalContent'",
",",
"'Page'",
")",
")",
";",
"$",
"action",
"=",
"'view'",
";",
"$",
"this",
"->",
"extend",
"(",
"'updateViewer'",
",",
"$",
"action",
",",
"$",
"viewer",
")",
";",
"return",
"$",
"this",
"->",
"customise",
"(",
"$",
"object",
")",
"->",
"renderWith",
"(",
"$",
"viewer",
")",
";",
"}",
"}",
"echo",
"\"Template not found for \"",
".",
"(",
"$",
"object",
"?",
"get_class",
"(",
"$",
"object",
")",
".",
"' #'",
".",
"$",
"object",
"->",
"ID",
":",
"''",
")",
";",
"}"
] | Display an item.
@param HTTP_Request $request
@return String | [
"Display",
"an",
"item",
"."
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/code/pages/ExternalContentPage.php#L133-L155 |
nyeholt/silverstripe-external-content | code/pages/ExternalContentPage.php | ExternalContentPage_Controller.download | public function download($request) {
if ($request->param('ID')) {
$object = ExternalContent::getDataObjectFor($request->param('ID'));
if ($object && $object instanceof ExternalContentItem) {
$object->streamContent();
}
}
} | php | public function download($request) {
if ($request->param('ID')) {
$object = ExternalContent::getDataObjectFor($request->param('ID'));
if ($object && $object instanceof ExternalContentItem) {
$object->streamContent();
}
}
} | [
"public",
"function",
"download",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"param",
"(",
"'ID'",
")",
")",
"{",
"$",
"object",
"=",
"ExternalContent",
"::",
"getDataObjectFor",
"(",
"$",
"request",
"->",
"param",
"(",
"'ID'",
")",
")",
";",
"if",
"(",
"$",
"object",
"&&",
"$",
"object",
"instanceof",
"ExternalContentItem",
")",
"{",
"$",
"object",
"->",
"streamContent",
"(",
")",
";",
"}",
"}",
"}"
] | Called to download this content item and stream it directly to the browser
@param HTTP_Request $request | [
"Called",
"to",
"download",
"this",
"content",
"item",
"and",
"stream",
"it",
"directly",
"to",
"the",
"browser"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/code/pages/ExternalContentPage.php#L162-L169 |
joseph-walker/vector | src/Core/Module.php | Module.curryWithArity | protected static function curryWithArity(Callable $f, $arity, $appliedArgs = [])
{
// Return a new function where we use the arguments already closed over,
// and merge them with the arguments we get from the new function.
return function(...$suppliedArgs) use ($f, $appliedArgs, $arity) {
$args = array_merge($appliedArgs, $suppliedArgs);
// If we have enough arguments, apply them to the internally curried function
// closed over from the original function call.
if (count($args) >= $arity)
return call_user_func_array($f, $args);
// Otherwise, recursively call curry again, passing in the arguments supplied
// from this call
else
return self::curryWithArity($f, $arity, $args);
};
} | php | protected static function curryWithArity(Callable $f, $arity, $appliedArgs = [])
{
// Return a new function where we use the arguments already closed over,
// and merge them with the arguments we get from the new function.
return function(...$suppliedArgs) use ($f, $appliedArgs, $arity) {
$args = array_merge($appliedArgs, $suppliedArgs);
// If we have enough arguments, apply them to the internally curried function
// closed over from the original function call.
if (count($args) >= $arity)
return call_user_func_array($f, $args);
// Otherwise, recursively call curry again, passing in the arguments supplied
// from this call
else
return self::curryWithArity($f, $arity, $args);
};
} | [
"protected",
"static",
"function",
"curryWithArity",
"(",
"Callable",
"$",
"f",
",",
"$",
"arity",
",",
"$",
"appliedArgs",
"=",
"[",
"]",
")",
"{",
"// Return a new function where we use the arguments already closed over,",
"// and merge them with the arguments we get from the new function.",
"return",
"function",
"(",
"...",
"$",
"suppliedArgs",
")",
"use",
"(",
"$",
"f",
",",
"$",
"appliedArgs",
",",
"$",
"arity",
")",
"{",
"$",
"args",
"=",
"array_merge",
"(",
"$",
"appliedArgs",
",",
"$",
"suppliedArgs",
")",
";",
"// If we have enough arguments, apply them to the internally curried function",
"// closed over from the original function call.",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">=",
"$",
"arity",
")",
"return",
"call_user_func_array",
"(",
"$",
"f",
",",
"$",
"args",
")",
";",
"// Otherwise, recursively call curry again, passing in the arguments supplied",
"// from this call",
"else",
"return",
"self",
"::",
"curryWithArity",
"(",
"$",
"f",
",",
"$",
"arity",
",",
"$",
"args",
")",
";",
"}",
";",
"}"
] | Curry a function with a specific arity. This is used internally
to curry functions that accept variadic arguments, e.g. for memoized functions.
@param Callable $f Function to curry
@param Int $arity Arity of $f
@param array $appliedArgs The arguments already applied to the curried function. This
argument is for internal use only.
@return Callable The result of currying the original function. | [
"Curry",
"a",
"function",
"with",
"a",
"specific",
"arity",
".",
"This",
"is",
"used",
"internally",
"to",
"curry",
"functions",
"that",
"accept",
"variadic",
"arguments",
"e",
".",
"g",
".",
"for",
"memoized",
"functions",
"."
] | train | https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Core/Module.php#L99-L115 |
joseph-walker/vector | src/Core/Module.php | Module.memoize | protected static function memoize(Callable $f)
{
return function(...$args) use ($f) {
static $cache;
if ($cache === null)
$cache = [];
$key = serialize($args);
if (array_key_exists($key, $cache)) {
return $cache[$key];
} else {
$result = call_user_func_array($f, $args);
$cache[$key] = $result;
return $result;
}
};
} | php | protected static function memoize(Callable $f)
{
return function(...$args) use ($f) {
static $cache;
if ($cache === null)
$cache = [];
$key = serialize($args);
if (array_key_exists($key, $cache)) {
return $cache[$key];
} else {
$result = call_user_func_array($f, $args);
$cache[$key] = $result;
return $result;
}
};
} | [
"protected",
"static",
"function",
"memoize",
"(",
"Callable",
"$",
"f",
")",
"{",
"return",
"function",
"(",
"...",
"$",
"args",
")",
"use",
"(",
"$",
"f",
")",
"{",
"static",
"$",
"cache",
";",
"if",
"(",
"$",
"cache",
"===",
"null",
")",
"$",
"cache",
"=",
"[",
"]",
";",
"$",
"key",
"=",
"serialize",
"(",
"$",
"args",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"cache",
")",
")",
"{",
"return",
"$",
"cache",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"f",
",",
"$",
"args",
")",
";",
"$",
"cache",
"[",
"$",
"key",
"]",
"=",
"$",
"result",
";",
"return",
"$",
"result",
";",
"}",
"}",
";",
"}"
] | Memoize a Function
Provided a function $f, return a new function that keeps track of all calls to
$f and caches their responses. Good for functions that have long-running execution times.
Bad for functions that have side effects. But you don't write those now do you?
```
$myFastFunction = $memoize($myBigFunction);
$myFastFunction(1, 2); // Really long wait
$myFastFunction(1, 2); // Instantaneous response
```
@type (* -> *) -> * -> *
@param Callable $f Function to memoize
@return Callable Memoized funciton $f | [
"Memoize",
"a",
"Function"
] | train | https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Core/Module.php#L136-L155 |
joseph-walker/vector | src/Core/Module.php | Module.getArity | protected static function getArity(callable $f)
{
if (is_string($f) || $f instanceof \Closure) {
$reflector = (new \ReflectionFunction($f));
} else {
$reflector = (new \ReflectionMethod($f[0], $f[1]));
}
// Count the number of arguments the function is asking for
return $reflector->getNumberOfParameters();
} | php | protected static function getArity(callable $f)
{
if (is_string($f) || $f instanceof \Closure) {
$reflector = (new \ReflectionFunction($f));
} else {
$reflector = (new \ReflectionMethod($f[0], $f[1]));
}
// Count the number of arguments the function is asking for
return $reflector->getNumberOfParameters();
} | [
"protected",
"static",
"function",
"getArity",
"(",
"callable",
"$",
"f",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"f",
")",
"||",
"$",
"f",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"reflector",
"=",
"(",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"f",
")",
")",
";",
"}",
"else",
"{",
"$",
"reflector",
"=",
"(",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"f",
"[",
"0",
"]",
",",
"$",
"f",
"[",
"1",
"]",
")",
")",
";",
"}",
"// Count the number of arguments the function is asking for",
"return",
"$",
"reflector",
"->",
"getNumberOfParameters",
"(",
")",
";",
"}"
] | Function Arity
Returns the arity of a funciton, e.g. the number of arguments it
expects to recieve before it returns a value.
@param Callable $f Function to get arity for
@return Int Number of arguments for $f | [
"Function",
"Arity"
] | train | https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Core/Module.php#L166-L176 |
joseph-walker/vector | src/Core/Module.php | Module.using | public static function using(...$requestedFunctions)
{
$context = get_called_class();
$fulfilledRequest = array_map(function($f) use ($context) {
// Append a '__' to the name we're looking for
$internalName = '__' . $f;
// See if we've already fulfilled the request for this function. If so, just return the cached one.
if (array_key_exists($context, static::$fulfillmentCache) && array_key_exists($internalName, static::$fulfillmentCache[$context]))
return static::$fulfillmentCache[$context][$internalName];
// If we haven't fulfilled it already, check to see if it even exists
if (!method_exists($context, $internalName))
throw new FunctionNotFoundException("Function $f not found in module $context");
// Check to see if we're memoizing this function, or the whole module. Otherwise, carry on.
if ($context::$memoize === true || in_array($f, $context::$memoize)) {
$functionInContext = self::memoize([$context, $internalName]);
}
else
$functionInContext = [$context, $internalName];
// If the function exists, then see if we're supposed to curry it. If not, just return it in a closure.
if ($context::$doNotCurry === true || (is_array($context::$doNotCurry) && in_array($f, $context::$doNotCurry))) {
$fulfillment = function(...$args) use ($functionInContext) {
return call_user_func_array($functionInContext, $args);
};
}
// Otherwise, curry it
else
$fulfillment = self::curryWithArity($functionInContext, self::getArity([$context, $internalName]));
// Then store it in our cache so we can short circuit this process in the future
self::$fulfillmentCache[$context][$internalName] = $fulfillment;
// And return it
return $fulfillment;
}, $requestedFunctions);
// If only one function was requested, return it. Otherwise keep it in an array for list() to work.
return count($fulfilledRequest) === 1
? $fulfilledRequest[0]
: $fulfilledRequest;
} | php | public static function using(...$requestedFunctions)
{
$context = get_called_class();
$fulfilledRequest = array_map(function($f) use ($context) {
// Append a '__' to the name we're looking for
$internalName = '__' . $f;
// See if we've already fulfilled the request for this function. If so, just return the cached one.
if (array_key_exists($context, static::$fulfillmentCache) && array_key_exists($internalName, static::$fulfillmentCache[$context]))
return static::$fulfillmentCache[$context][$internalName];
// If we haven't fulfilled it already, check to see if it even exists
if (!method_exists($context, $internalName))
throw new FunctionNotFoundException("Function $f not found in module $context");
// Check to see if we're memoizing this function, or the whole module. Otherwise, carry on.
if ($context::$memoize === true || in_array($f, $context::$memoize)) {
$functionInContext = self::memoize([$context, $internalName]);
}
else
$functionInContext = [$context, $internalName];
// If the function exists, then see if we're supposed to curry it. If not, just return it in a closure.
if ($context::$doNotCurry === true || (is_array($context::$doNotCurry) && in_array($f, $context::$doNotCurry))) {
$fulfillment = function(...$args) use ($functionInContext) {
return call_user_func_array($functionInContext, $args);
};
}
// Otherwise, curry it
else
$fulfillment = self::curryWithArity($functionInContext, self::getArity([$context, $internalName]));
// Then store it in our cache so we can short circuit this process in the future
self::$fulfillmentCache[$context][$internalName] = $fulfillment;
// And return it
return $fulfillment;
}, $requestedFunctions);
// If only one function was requested, return it. Otherwise keep it in an array for list() to work.
return count($fulfilledRequest) === 1
? $fulfilledRequest[0]
: $fulfilledRequest;
} | [
"public",
"static",
"function",
"using",
"(",
"...",
"$",
"requestedFunctions",
")",
"{",
"$",
"context",
"=",
"get_called_class",
"(",
")",
";",
"$",
"fulfilledRequest",
"=",
"array_map",
"(",
"function",
"(",
"$",
"f",
")",
"use",
"(",
"$",
"context",
")",
"{",
"// Append a '__' to the name we're looking for",
"$",
"internalName",
"=",
"'__'",
".",
"$",
"f",
";",
"// See if we've already fulfilled the request for this function. If so, just return the cached one.",
"if",
"(",
"array_key_exists",
"(",
"$",
"context",
",",
"static",
"::",
"$",
"fulfillmentCache",
")",
"&&",
"array_key_exists",
"(",
"$",
"internalName",
",",
"static",
"::",
"$",
"fulfillmentCache",
"[",
"$",
"context",
"]",
")",
")",
"return",
"static",
"::",
"$",
"fulfillmentCache",
"[",
"$",
"context",
"]",
"[",
"$",
"internalName",
"]",
";",
"// If we haven't fulfilled it already, check to see if it even exists",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"context",
",",
"$",
"internalName",
")",
")",
"throw",
"new",
"FunctionNotFoundException",
"(",
"\"Function $f not found in module $context\"",
")",
";",
"// Check to see if we're memoizing this function, or the whole module. Otherwise, carry on.",
"if",
"(",
"$",
"context",
"::",
"$",
"memoize",
"===",
"true",
"||",
"in_array",
"(",
"$",
"f",
",",
"$",
"context",
"::",
"$",
"memoize",
")",
")",
"{",
"$",
"functionInContext",
"=",
"self",
"::",
"memoize",
"(",
"[",
"$",
"context",
",",
"$",
"internalName",
"]",
")",
";",
"}",
"else",
"$",
"functionInContext",
"=",
"[",
"$",
"context",
",",
"$",
"internalName",
"]",
";",
"// If the function exists, then see if we're supposed to curry it. If not, just return it in a closure.",
"if",
"(",
"$",
"context",
"::",
"$",
"doNotCurry",
"===",
"true",
"||",
"(",
"is_array",
"(",
"$",
"context",
"::",
"$",
"doNotCurry",
")",
"&&",
"in_array",
"(",
"$",
"f",
",",
"$",
"context",
"::",
"$",
"doNotCurry",
")",
")",
")",
"{",
"$",
"fulfillment",
"=",
"function",
"(",
"...",
"$",
"args",
")",
"use",
"(",
"$",
"functionInContext",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"functionInContext",
",",
"$",
"args",
")",
";",
"}",
";",
"}",
"// Otherwise, curry it",
"else",
"$",
"fulfillment",
"=",
"self",
"::",
"curryWithArity",
"(",
"$",
"functionInContext",
",",
"self",
"::",
"getArity",
"(",
"[",
"$",
"context",
",",
"$",
"internalName",
"]",
")",
")",
";",
"// Then store it in our cache so we can short circuit this process in the future",
"self",
"::",
"$",
"fulfillmentCache",
"[",
"$",
"context",
"]",
"[",
"$",
"internalName",
"]",
"=",
"$",
"fulfillment",
";",
"// And return it",
"return",
"$",
"fulfillment",
";",
"}",
",",
"$",
"requestedFunctions",
")",
";",
"// If only one function was requested, return it. Otherwise keep it in an array for list() to work.",
"return",
"count",
"(",
"$",
"fulfilledRequest",
")",
"===",
"1",
"?",
"$",
"fulfilledRequest",
"[",
"0",
"]",
":",
"$",
"fulfilledRequest",
";",
"}"
] | Module Loading
Provided some function name, load that function into a callable from the definition.
The function is automatically curried unless it is listed in that module's doNotCurry list.
If `using` is passed multiple function names, they are returned in an array so they can be
split apart using PHP's internal `list` function.
```
$myFunc = MyModule::using('myFunc'); // Callable
list($foo, $bar) = MyModule::using('foo', 'bar'); // $foo = Callable, $bar = Callable
```
@type String -> (* -> *)
@param array $requestedFunctions Variadic list of strings, function names to request
@return callable A single callable, or an array of callable representing
the fulfilled request for functions from the module | [
"Module",
"Loading"
] | train | https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Core/Module.php#L197-L241 |
ClanCats/Core | src/classes/CCConfig/File.php | CCConfig_File.read | public function read( $name )
{
// check for absolut path
if ( substr( $name, 0, 1 ) == '/' && file_exists( $name ) )
{
return $this->read_file( $name );
}
$in_namespace = false;
// split the namespace
if ( strpos( $name, '::' ) !== false )
{
$conf = explode( '::', $name );
$in_namespace = $conf[0];
$name = $conf[1];
unset( $conf );
}
// the two holders
$main = $default = array();
/*
* App config
* if app config try to load the equal core config as defaults
*/
if ( !$in_namespace )
{
$core_conf = $this->path( CCCORE_NAMESPACE.'::'.$name, true );
$app_conf = $this->path( $name, true );
if ( file_exists( $core_conf ) )
{
$default = $this->read_file( $core_conf );
}
if ( file_exists( $app_conf ) )
{
$main = $this->read_file( $app_conf );
}
}
/*
* Namespaced config
* means use the namespaced config as default also try to load the app implementation
*/
elseif ( $in_namespace )
{
$main_conf = $this->path( $in_namespace.'::'.$name, true );
$app_conf = $this->path( $name, true );
if ( file_exists( $main_conf ) )
{
$default = $this->read_file( $main_conf );
}
if ( file_exists( $app_conf ) )
{
$main = $this->read_file( $app_conf );
}
}
// finally return the data
return CCArr::merge( $default, $main );
} | php | public function read( $name )
{
// check for absolut path
if ( substr( $name, 0, 1 ) == '/' && file_exists( $name ) )
{
return $this->read_file( $name );
}
$in_namespace = false;
// split the namespace
if ( strpos( $name, '::' ) !== false )
{
$conf = explode( '::', $name );
$in_namespace = $conf[0];
$name = $conf[1];
unset( $conf );
}
// the two holders
$main = $default = array();
/*
* App config
* if app config try to load the equal core config as defaults
*/
if ( !$in_namespace )
{
$core_conf = $this->path( CCCORE_NAMESPACE.'::'.$name, true );
$app_conf = $this->path( $name, true );
if ( file_exists( $core_conf ) )
{
$default = $this->read_file( $core_conf );
}
if ( file_exists( $app_conf ) )
{
$main = $this->read_file( $app_conf );
}
}
/*
* Namespaced config
* means use the namespaced config as default also try to load the app implementation
*/
elseif ( $in_namespace )
{
$main_conf = $this->path( $in_namespace.'::'.$name, true );
$app_conf = $this->path( $name, true );
if ( file_exists( $main_conf ) )
{
$default = $this->read_file( $main_conf );
}
if ( file_exists( $app_conf ) )
{
$main = $this->read_file( $app_conf );
}
}
// finally return the data
return CCArr::merge( $default, $main );
} | [
"public",
"function",
"read",
"(",
"$",
"name",
")",
"{",
"// check for absolut path",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"1",
")",
"==",
"'/'",
"&&",
"file_exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"read_file",
"(",
"$",
"name",
")",
";",
"}",
"$",
"in_namespace",
"=",
"false",
";",
"// split the namespace",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'::'",
")",
"!==",
"false",
")",
"{",
"$",
"conf",
"=",
"explode",
"(",
"'::'",
",",
"$",
"name",
")",
";",
"$",
"in_namespace",
"=",
"$",
"conf",
"[",
"0",
"]",
";",
"$",
"name",
"=",
"$",
"conf",
"[",
"1",
"]",
";",
"unset",
"(",
"$",
"conf",
")",
";",
"}",
"// the two holders",
"$",
"main",
"=",
"$",
"default",
"=",
"array",
"(",
")",
";",
"/*\n\t\t * App config\n\t\t * if app config try to load the equal core config as defaults\n\t\t */",
"if",
"(",
"!",
"$",
"in_namespace",
")",
"{",
"$",
"core_conf",
"=",
"$",
"this",
"->",
"path",
"(",
"CCCORE_NAMESPACE",
".",
"'::'",
".",
"$",
"name",
",",
"true",
")",
";",
"$",
"app_conf",
"=",
"$",
"this",
"->",
"path",
"(",
"$",
"name",
",",
"true",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"core_conf",
")",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"read_file",
"(",
"$",
"core_conf",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"app_conf",
")",
")",
"{",
"$",
"main",
"=",
"$",
"this",
"->",
"read_file",
"(",
"$",
"app_conf",
")",
";",
"}",
"}",
"/*\n\t\t * Namespaced config\n\t\t * means use the namespaced config as default also try to load the app implementation\n\t\t */",
"elseif",
"(",
"$",
"in_namespace",
")",
"{",
"$",
"main_conf",
"=",
"$",
"this",
"->",
"path",
"(",
"$",
"in_namespace",
".",
"'::'",
".",
"$",
"name",
",",
"true",
")",
";",
"$",
"app_conf",
"=",
"$",
"this",
"->",
"path",
"(",
"$",
"name",
",",
"true",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"main_conf",
")",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"read_file",
"(",
"$",
"main_conf",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"app_conf",
")",
")",
"{",
"$",
"main",
"=",
"$",
"this",
"->",
"read_file",
"(",
"$",
"app_conf",
")",
";",
"}",
"}",
"// finally return the data",
"return",
"CCArr",
"::",
"merge",
"(",
"$",
"default",
",",
"$",
"main",
")",
";",
"}"
] | Read the configuration data
Get the configuration data and return them as array
@param string $name
@return array | [
"Read",
"the",
"configuration",
"data",
"Get",
"the",
"configuration",
"data",
"and",
"return",
"them",
"as",
"array"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCConfig/File.php#L26-L90 |
ClanCats/Core | src/classes/CCConfig/File.php | CCConfig_File.write | public function write( $file, $data )
{
// check for absolut path
if ( substr( $file, 0, 1 ) == '/' )
{
return $this->write_file( $file, $data );
}
$this->write_file( $this->path( $file ), $data );
} | php | public function write( $file, $data )
{
// check for absolut path
if ( substr( $file, 0, 1 ) == '/' )
{
return $this->write_file( $file, $data );
}
$this->write_file( $this->path( $file ), $data );
} | [
"public",
"function",
"write",
"(",
"$",
"file",
",",
"$",
"data",
")",
"{",
"// check for absolut path",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"1",
")",
"==",
"'/'",
")",
"{",
"return",
"$",
"this",
"->",
"write_file",
"(",
"$",
"file",
",",
"$",
"data",
")",
";",
"}",
"$",
"this",
"->",
"write_file",
"(",
"$",
"this",
"->",
"path",
"(",
"$",
"file",
")",
",",
"$",
"data",
")",
";",
"}"
] | Write the configuration data
@param string $file
@return void | [
"Write",
"the",
"configuration",
"data"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCConfig/File.php#L98-L107 |
ClanCats/Core | src/classes/CCConfig/File.php | CCConfig_File.delete | public function delete( $file )
{
// check for absolut path
if ( substr( $file, 0, 1 ) == '/' )
{
return CCFile::delete( $file );
}
return CCFile::delete( $this->path( $file ) );
} | php | public function delete( $file )
{
// check for absolut path
if ( substr( $file, 0, 1 ) == '/' )
{
return CCFile::delete( $file );
}
return CCFile::delete( $this->path( $file ) );
} | [
"public",
"function",
"delete",
"(",
"$",
"file",
")",
"{",
"// check for absolut path",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"1",
")",
"==",
"'/'",
")",
"{",
"return",
"CCFile",
"::",
"delete",
"(",
"$",
"file",
")",
";",
"}",
"return",
"CCFile",
"::",
"delete",
"(",
"$",
"this",
"->",
"path",
"(",
"$",
"file",
")",
")",
";",
"}"
] | delete the configuration data
@param string $file
@return void | [
"delete",
"the",
"configuration",
"data"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCConfig/File.php#L115-L124 |
ClanCats/Core | src/classes/CCConfig/File.php | CCConfig_File.path | protected function path( $name, $env = false )
{
$conf = CCPath::get( $name, \CCDIR_CONFIG, static::EXT );
if ( !$env )
{
return $conf;
}
$env_conf = CCPath::get( $name, \CCDIR_CONFIG.ClanCats::environment().'/', static::EXT );
if ( file_exists( $env_conf ) )
{
return $env_conf;
}
return $conf;
} | php | protected function path( $name, $env = false )
{
$conf = CCPath::get( $name, \CCDIR_CONFIG, static::EXT );
if ( !$env )
{
return $conf;
}
$env_conf = CCPath::get( $name, \CCDIR_CONFIG.ClanCats::environment().'/', static::EXT );
if ( file_exists( $env_conf ) )
{
return $env_conf;
}
return $conf;
} | [
"protected",
"function",
"path",
"(",
"$",
"name",
",",
"$",
"env",
"=",
"false",
")",
"{",
"$",
"conf",
"=",
"CCPath",
"::",
"get",
"(",
"$",
"name",
",",
"\\",
"CCDIR_CONFIG",
",",
"static",
"::",
"EXT",
")",
";",
"if",
"(",
"!",
"$",
"env",
")",
"{",
"return",
"$",
"conf",
";",
"}",
"$",
"env_conf",
"=",
"CCPath",
"::",
"get",
"(",
"$",
"name",
",",
"\\",
"CCDIR_CONFIG",
".",
"ClanCats",
"::",
"environment",
"(",
")",
".",
"'/'",
",",
"static",
"::",
"EXT",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"env_conf",
")",
")",
"{",
"return",
"$",
"env_conf",
";",
"}",
"return",
"$",
"conf",
";",
"}"
] | generates a path for a config name
@param string $name
@param bool $env | [
"generates",
"a",
"path",
"for",
"a",
"config",
"name"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCConfig/File.php#L152-L169 |
tbreuss/pvc | src/View/ViewHelpers.php | ViewHelpers.add | public function add(string $name, callable $callback): self
{
if ($this->exists($name)) {
throw new LogicException(
'The helper function name "' . $name . '" is already registered.'
);
}
$this->helpers[$name] = $callback;
return $this;
} | php | public function add(string $name, callable $callback): self
{
if ($this->exists($name)) {
throw new LogicException(
'The helper function name "' . $name . '" is already registered.'
);
}
$this->helpers[$name] = $callback;
return $this;
} | [
"public",
"function",
"add",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'The helper function name \"'",
".",
"$",
"name",
".",
"'\" is already registered.'",
")",
";",
"}",
"$",
"this",
"->",
"helpers",
"[",
"$",
"name",
"]",
"=",
"$",
"callback",
";",
"return",
"$",
"this",
";",
"}"
] | Add a new template function.
@param string $name
@param callback $callback
@return ViewHelpers | [
"Add",
"a",
"new",
"template",
"function",
"."
] | train | https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/View/ViewHelpers.php#L26-L37 |
tbreuss/pvc | src/View/ViewHelpers.php | ViewHelpers.remove | public function remove(string $name): self
{
if (!$this->exists($name)) {
throw new LogicException(
'The template function "' . $name . '" was not found.'
);
}
unset($this->helpers[$name]);
return $this;
} | php | public function remove(string $name): self
{
if (!$this->exists($name)) {
throw new LogicException(
'The template function "' . $name . '" was not found.'
);
}
unset($this->helpers[$name]);
return $this;
} | [
"public",
"function",
"remove",
"(",
"string",
"$",
"name",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'The template function \"'",
".",
"$",
"name",
".",
"'\" was not found.'",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"helpers",
"[",
"$",
"name",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Remove a template function.
@param string $name
@return ViewHelpers | [
"Remove",
"a",
"template",
"function",
"."
] | train | https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/View/ViewHelpers.php#L44-L55 |
tbreuss/pvc | src/View/ViewHelpers.php | ViewHelpers.get | public function get(string $name): callable
{
if (!$this->exists($name)) {
throw new LogicException('The template function "' . $name . '" was not found.');
}
return $this->helpers[$name];
} | php | public function get(string $name): callable
{
if (!$this->exists($name)) {
throw new LogicException('The template function "' . $name . '" was not found.');
}
return $this->helpers[$name];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"name",
")",
":",
"callable",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'The template function \"'",
".",
"$",
"name",
".",
"'\" was not found.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"helpers",
"[",
"$",
"name",
"]",
";",
"}"
] | Get a template function.
@param string $name
@return callable | [
"Get",
"a",
"template",
"function",
"."
] | train | https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/View/ViewHelpers.php#L62-L69 |
krzysztofmazur/php-object-mapper | src/KrzysztofMazur/ObjectMapper/Mapping/Field/ValueReader/PropertyValueReader.php | PropertyValueReader.readValue | protected function readValue($object)
{
return Reflection::getProperty(get_class($object), $this->propertyName)->getValue($object);
} | php | protected function readValue($object)
{
return Reflection::getProperty(get_class($object), $this->propertyName)->getValue($object);
} | [
"protected",
"function",
"readValue",
"(",
"$",
"object",
")",
"{",
"return",
"Reflection",
"::",
"getProperty",
"(",
"get_class",
"(",
"$",
"object",
")",
",",
"$",
"this",
"->",
"propertyName",
")",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/krzysztofmazur/php-object-mapper/blob/2c22acad9634cfe8e9a75d72e665d450ada8d4e3/src/KrzysztofMazur/ObjectMapper/Mapping/Field/ValueReader/PropertyValueReader.php#L36-L39 |
jakim/yii2-authserver | src/Server.php | Server.getResponse | public function getResponse()
{
$grant = $this->resolveGrant();
if ($grant && $grant->load($this->request->post(), '') && $grant->validate()) {
/** @var UserIdentityInterface $identity */
if (($identity = $grant->findIdentity()) === null) {
\Yii::error("Invalid grant: " . get_class($grant), __METHOD__);
$this->error = 'invalid_grant';
} else {
$identity->setAccessToken($this->generateAccessToken());
$identity->setRefreshToken($this->generateRefreshToken());
if (!$identity->save()) {
\Yii::error('User model error: ' . print_r($identity->getErrors(), true), __METHOD__);
throw new ServerErrorHttpException();
}
$this->identity = $identity;
return $this->prepareResponse($identity);
}
} elseif ($grant && $grant->hasErrors()) {
\Yii::error("Invalid request: " . print_r($grant->getErrors(), true), __METHOD__);
$this->error = 'invalid_request';
}
return null;
} | php | public function getResponse()
{
$grant = $this->resolveGrant();
if ($grant && $grant->load($this->request->post(), '') && $grant->validate()) {
/** @var UserIdentityInterface $identity */
if (($identity = $grant->findIdentity()) === null) {
\Yii::error("Invalid grant: " . get_class($grant), __METHOD__);
$this->error = 'invalid_grant';
} else {
$identity->setAccessToken($this->generateAccessToken());
$identity->setRefreshToken($this->generateRefreshToken());
if (!$identity->save()) {
\Yii::error('User model error: ' . print_r($identity->getErrors(), true), __METHOD__);
throw new ServerErrorHttpException();
}
$this->identity = $identity;
return $this->prepareResponse($identity);
}
} elseif ($grant && $grant->hasErrors()) {
\Yii::error("Invalid request: " . print_r($grant->getErrors(), true), __METHOD__);
$this->error = 'invalid_request';
}
return null;
} | [
"public",
"function",
"getResponse",
"(",
")",
"{",
"$",
"grant",
"=",
"$",
"this",
"->",
"resolveGrant",
"(",
")",
";",
"if",
"(",
"$",
"grant",
"&&",
"$",
"grant",
"->",
"load",
"(",
"$",
"this",
"->",
"request",
"->",
"post",
"(",
")",
",",
"''",
")",
"&&",
"$",
"grant",
"->",
"validate",
"(",
")",
")",
"{",
"/** @var UserIdentityInterface $identity */",
"if",
"(",
"(",
"$",
"identity",
"=",
"$",
"grant",
"->",
"findIdentity",
"(",
")",
")",
"===",
"null",
")",
"{",
"\\",
"Yii",
"::",
"error",
"(",
"\"Invalid grant: \"",
".",
"get_class",
"(",
"$",
"grant",
")",
",",
"__METHOD__",
")",
";",
"$",
"this",
"->",
"error",
"=",
"'invalid_grant'",
";",
"}",
"else",
"{",
"$",
"identity",
"->",
"setAccessToken",
"(",
"$",
"this",
"->",
"generateAccessToken",
"(",
")",
")",
";",
"$",
"identity",
"->",
"setRefreshToken",
"(",
"$",
"this",
"->",
"generateRefreshToken",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"identity",
"->",
"save",
"(",
")",
")",
"{",
"\\",
"Yii",
"::",
"error",
"(",
"'User model error: '",
".",
"print_r",
"(",
"$",
"identity",
"->",
"getErrors",
"(",
")",
",",
"true",
")",
",",
"__METHOD__",
")",
";",
"throw",
"new",
"ServerErrorHttpException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"identity",
"=",
"$",
"identity",
";",
"return",
"$",
"this",
"->",
"prepareResponse",
"(",
"$",
"identity",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"grant",
"&&",
"$",
"grant",
"->",
"hasErrors",
"(",
")",
")",
"{",
"\\",
"Yii",
"::",
"error",
"(",
"\"Invalid request: \"",
".",
"print_r",
"(",
"$",
"grant",
"->",
"getErrors",
"(",
")",
",",
"true",
")",
",",
"__METHOD__",
")",
";",
"$",
"this",
"->",
"error",
"=",
"'invalid_request'",
";",
"}",
"return",
"null",
";",
"}"
] | @return \jakim\authserver\response\TokenResponse|null
@throws \yii\web\ServerErrorHttpException
@see https://tools.ietf.org/html/rfc6749#section-4.3 | [
"@return",
"\\",
"jakim",
"\\",
"authserver",
"\\",
"response",
"\\",
"TokenResponse|null",
"@throws",
"\\",
"yii",
"\\",
"web",
"\\",
"ServerErrorHttpException"
] | train | https://github.com/jakim/yii2-authserver/blob/6c11d09cf08405925403fe27f61da52e1c7aa07d/src/Server.php#L73-L99 |
jakim/yii2-authserver | src/Server.php | Server.getError | public function getError()
{
$this->setResponseHeaders();
\Yii::$app->response->setStatusCode(400);
return $this->error ? new ErrorResponse(['error' => $this->error]) : null;
} | php | public function getError()
{
$this->setResponseHeaders();
\Yii::$app->response->setStatusCode(400);
return $this->error ? new ErrorResponse(['error' => $this->error]) : null;
} | [
"public",
"function",
"getError",
"(",
")",
"{",
"$",
"this",
"->",
"setResponseHeaders",
"(",
")",
";",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"setStatusCode",
"(",
"400",
")",
";",
"return",
"$",
"this",
"->",
"error",
"?",
"new",
"ErrorResponse",
"(",
"[",
"'error'",
"=>",
"$",
"this",
"->",
"error",
"]",
")",
":",
"null",
";",
"}"
] | @return \jakim\authserver\response\ErrorResponse|null
@see https://tools.ietf.org/html/rfc6749#section-5.2 | [
"@return",
"\\",
"jakim",
"\\",
"authserver",
"\\",
"response",
"\\",
"ErrorResponse|null"
] | train | https://github.com/jakim/yii2-authserver/blob/6c11d09cf08405925403fe27f61da52e1c7aa07d/src/Server.php#L114-L120 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBOGeneratorBundle/Generator/Generator.php | Generator.getFieldsFromMetadata | protected function getFieldsFromMetadata($metadata)
{
$fields = $metadata->fieldMappings;
// Remove the primary key field if it's not managed manually
if (!$metadata->isIdentifierNatural()) {
foreach ($metadata->identifier as $oneId) {
unset($fields[$oneId]);
}
}
foreach ($metadata->associationMappings as $fieldName => $relation) {
if (in_array($relation['type'], [ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_MANY])) {
$fields[$fieldName] = $relation;
} elseif ($relation['type'] == ClassMetadataInfo::MANY_TO_MANY && (empty($relation['mappedBy']) == false || empty($relation['inversedBy']) == false)) {
/*|| $relation['targetEntity'] == $relation['sourceEntity']*/
$fields[$fieldName] = $relation;
}
}
return $fields;
} | php | protected function getFieldsFromMetadata($metadata)
{
$fields = $metadata->fieldMappings;
// Remove the primary key field if it's not managed manually
if (!$metadata->isIdentifierNatural()) {
foreach ($metadata->identifier as $oneId) {
unset($fields[$oneId]);
}
}
foreach ($metadata->associationMappings as $fieldName => $relation) {
if (in_array($relation['type'], [ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_MANY])) {
$fields[$fieldName] = $relation;
} elseif ($relation['type'] == ClassMetadataInfo::MANY_TO_MANY && (empty($relation['mappedBy']) == false || empty($relation['inversedBy']) == false)) {
/*|| $relation['targetEntity'] == $relation['sourceEntity']*/
$fields[$fieldName] = $relation;
}
}
return $fields;
} | [
"protected",
"function",
"getFieldsFromMetadata",
"(",
"$",
"metadata",
")",
"{",
"$",
"fields",
"=",
"$",
"metadata",
"->",
"fieldMappings",
";",
"// Remove the primary key field if it's not managed manually",
"if",
"(",
"!",
"$",
"metadata",
"->",
"isIdentifierNatural",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"metadata",
"->",
"identifier",
"as",
"$",
"oneId",
")",
"{",
"unset",
"(",
"$",
"fields",
"[",
"$",
"oneId",
"]",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"metadata",
"->",
"associationMappings",
"as",
"$",
"fieldName",
"=>",
"$",
"relation",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"relation",
"[",
"'type'",
"]",
",",
"[",
"ClassMetadataInfo",
"::",
"MANY_TO_ONE",
",",
"ClassMetadataInfo",
"::",
"ONE_TO_MANY",
"]",
")",
")",
"{",
"$",
"fields",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"relation",
";",
"}",
"elseif",
"(",
"$",
"relation",
"[",
"'type'",
"]",
"==",
"ClassMetadataInfo",
"::",
"MANY_TO_MANY",
"&&",
"(",
"empty",
"(",
"$",
"relation",
"[",
"'mappedBy'",
"]",
")",
"==",
"false",
"||",
"empty",
"(",
"$",
"relation",
"[",
"'inversedBy'",
"]",
")",
"==",
"false",
")",
")",
"{",
"/*|| $relation['targetEntity'] == $relation['sourceEntity']*/",
"$",
"fields",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"relation",
";",
"}",
"}",
"return",
"$",
"fields",
";",
"}"
] | Returns an array of fields. Fields can be both column fields and
association fields.
@return array $fields | [
"Returns",
"an",
"array",
"of",
"fields",
".",
"Fields",
"can",
"be",
"both",
"column",
"fields",
"and",
"association",
"fields",
"."
] | train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBOGeneratorBundle/Generator/Generator.php#L43-L64 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBOGeneratorBundle/Generator/Generator.php | Generator.render | protected function render($template, $parameters)
{
$option = array(
'debug' => true,
'cache' => false,
'strict_variables' => true,
'autoescape' => false,
);
$self = $this;
$twig = new \Twig_Environment(new \Twig_Loader_Filesystem($this->SBOskeletonDirs), $option);
$twig->addFunction(new \Twig_SimpleFunction(
'renderFile',
function ($template, $target, $subParameters = []) use ($self,$parameters) {
$self->renderFile($template, $target, array_merge($parameters, $subParameters));
return '';
},
$option
));
$twig->addFunction(new \Twig_SimpleFunction(
'method_exists',
function ($object, $methodeName) {
return method_exists($object, $methodeName);
},
$option
));
return $twig->render($template, $parameters);
} | php | protected function render($template, $parameters)
{
$option = array(
'debug' => true,
'cache' => false,
'strict_variables' => true,
'autoescape' => false,
);
$self = $this;
$twig = new \Twig_Environment(new \Twig_Loader_Filesystem($this->SBOskeletonDirs), $option);
$twig->addFunction(new \Twig_SimpleFunction(
'renderFile',
function ($template, $target, $subParameters = []) use ($self,$parameters) {
$self->renderFile($template, $target, array_merge($parameters, $subParameters));
return '';
},
$option
));
$twig->addFunction(new \Twig_SimpleFunction(
'method_exists',
function ($object, $methodeName) {
return method_exists($object, $methodeName);
},
$option
));
return $twig->render($template, $parameters);
} | [
"protected",
"function",
"render",
"(",
"$",
"template",
",",
"$",
"parameters",
")",
"{",
"$",
"option",
"=",
"array",
"(",
"'debug'",
"=>",
"true",
",",
"'cache'",
"=>",
"false",
",",
"'strict_variables'",
"=>",
"true",
",",
"'autoescape'",
"=>",
"false",
",",
")",
";",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"twig",
"=",
"new",
"\\",
"Twig_Environment",
"(",
"new",
"\\",
"Twig_Loader_Filesystem",
"(",
"$",
"this",
"->",
"SBOskeletonDirs",
")",
",",
"$",
"option",
")",
";",
"$",
"twig",
"->",
"addFunction",
"(",
"new",
"\\",
"Twig_SimpleFunction",
"(",
"'renderFile'",
",",
"function",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"subParameters",
"=",
"[",
"]",
")",
"use",
"(",
"$",
"self",
",",
"$",
"parameters",
")",
"{",
"$",
"self",
"->",
"renderFile",
"(",
"$",
"template",
",",
"$",
"target",
",",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"subParameters",
")",
")",
";",
"return",
"''",
";",
"}",
",",
"$",
"option",
")",
")",
";",
"$",
"twig",
"->",
"addFunction",
"(",
"new",
"\\",
"Twig_SimpleFunction",
"(",
"'method_exists'",
",",
"function",
"(",
"$",
"object",
",",
"$",
"methodeName",
")",
"{",
"return",
"method_exists",
"(",
"$",
"object",
",",
"$",
"methodeName",
")",
";",
"}",
",",
"$",
"option",
")",
")",
";",
"return",
"$",
"twig",
"->",
"render",
"(",
"$",
"template",
",",
"$",
"parameters",
")",
";",
"}"
] | @param $template
@param $parameters
@return string | [
"@param",
"$template",
"@param",
"$parameters"
] | train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBOGeneratorBundle/Generator/Generator.php#L72-L103 |
ixudra/generators | src/Commands/GenerateFlowFileCommand.php | GenerateFlowFileCommand.deriveArguments | protected function deriveArguments()
{
$this->flowClass = Str::studly( $this->argument('flow') );
$this->flowVariable = lcfirst( Str::studly( $this->argument('flow') ) );
$this->stepClass = Str::studly( $this->argument('step') );
$this->stepVariable = lcfirst( Str::studly( $this->argument('step') ) );
$this->stepBreadcrumb = str_replace( '_', '-', $this->argument('step') );
} | php | protected function deriveArguments()
{
$this->flowClass = Str::studly( $this->argument('flow') );
$this->flowVariable = lcfirst( Str::studly( $this->argument('flow') ) );
$this->stepClass = Str::studly( $this->argument('step') );
$this->stepVariable = lcfirst( Str::studly( $this->argument('step') ) );
$this->stepBreadcrumb = str_replace( '_', '-', $this->argument('step') );
} | [
"protected",
"function",
"deriveArguments",
"(",
")",
"{",
"$",
"this",
"->",
"flowClass",
"=",
"Str",
"::",
"studly",
"(",
"$",
"this",
"->",
"argument",
"(",
"'flow'",
")",
")",
";",
"$",
"this",
"->",
"flowVariable",
"=",
"lcfirst",
"(",
"Str",
"::",
"studly",
"(",
"$",
"this",
"->",
"argument",
"(",
"'flow'",
")",
")",
")",
";",
"$",
"this",
"->",
"stepClass",
"=",
"Str",
"::",
"studly",
"(",
"$",
"this",
"->",
"argument",
"(",
"'step'",
")",
")",
";",
"$",
"this",
"->",
"stepVariable",
"=",
"lcfirst",
"(",
"Str",
"::",
"studly",
"(",
"$",
"this",
"->",
"argument",
"(",
"'step'",
")",
")",
")",
";",
"$",
"this",
"->",
"stepBreadcrumb",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"this",
"->",
"argument",
"(",
"'step'",
")",
")",
";",
"}"
] | - Value deduction --- | [
"-",
"Value",
"deduction",
"---"
] | train | https://github.com/ixudra/generators/blob/3fa16efa157716f1425afa7a252b87df0d248a14/src/Commands/GenerateFlowFileCommand.php#L68-L76 |
ixudra/generators | src/Commands/GenerateFlowFileCommand.php | GenerateFlowFileCommand.replaceValues | protected function replaceValues($template)
{
$template = str_replace( '##NAMESPACE##', Config::get('generators.namespace'), $template );
$template = str_replace( '##FLOW_CLASS##', $this->flowClass, $template );
$template = str_replace( '##FLOW_VARIABLE##', $this->flowVariable, $template );
$template = str_replace( '##FLOW_STEP_CLASS##', $this->stepClass, $template );
$template = str_replace( '##FLOW_STEP_VARIABLE##', $this->stepVariable, $template );
$template = str_replace( '##FLOW_STEP_BREADCRUMB##', $this->stepBreadcrumb, $template );
return $template;
} | php | protected function replaceValues($template)
{
$template = str_replace( '##NAMESPACE##', Config::get('generators.namespace'), $template );
$template = str_replace( '##FLOW_CLASS##', $this->flowClass, $template );
$template = str_replace( '##FLOW_VARIABLE##', $this->flowVariable, $template );
$template = str_replace( '##FLOW_STEP_CLASS##', $this->stepClass, $template );
$template = str_replace( '##FLOW_STEP_VARIABLE##', $this->stepVariable, $template );
$template = str_replace( '##FLOW_STEP_BREADCRUMB##', $this->stepBreadcrumb, $template );
return $template;
} | [
"protected",
"function",
"replaceValues",
"(",
"$",
"template",
")",
"{",
"$",
"template",
"=",
"str_replace",
"(",
"'##NAMESPACE##'",
",",
"Config",
"::",
"get",
"(",
"'generators.namespace'",
")",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'##FLOW_CLASS##'",
",",
"$",
"this",
"->",
"flowClass",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'##FLOW_VARIABLE##'",
",",
"$",
"this",
"->",
"flowVariable",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'##FLOW_STEP_CLASS##'",
",",
"$",
"this",
"->",
"stepClass",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'##FLOW_STEP_VARIABLE##'",
",",
"$",
"this",
"->",
"stepVariable",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'##FLOW_STEP_BREADCRUMB##'",
",",
"$",
"this",
"->",
"stepBreadcrumb",
",",
"$",
"template",
")",
";",
"return",
"$",
"template",
";",
"}"
] | - File generation --- | [
"-",
"File",
"generation",
"---"
] | train | https://github.com/ixudra/generators/blob/3fa16efa157716f1425afa7a252b87df0d248a14/src/Commands/GenerateFlowFileCommand.php#L81-L91 |
Chill-project/Main | Entity/PermissionsGroup.php | PermissionsGroup.isRoleScopePresentOnce | public function isRoleScopePresentOnce(ExecutionContextInterface $context)
{
$roleScopesId = array_map(function(RoleScope $roleScope) {
return $roleScope->getId();
},
$this->getRoleScopes()->toArray());
$countedIds = array_count_values($roleScopesId);
foreach ($countedIds as $id => $nb) {
if ($nb > 1) {
$context->buildViolation("A permission is already present "
. "for the same role and scope")
->addViolation();
}
}
} | php | public function isRoleScopePresentOnce(ExecutionContextInterface $context)
{
$roleScopesId = array_map(function(RoleScope $roleScope) {
return $roleScope->getId();
},
$this->getRoleScopes()->toArray());
$countedIds = array_count_values($roleScopesId);
foreach ($countedIds as $id => $nb) {
if ($nb > 1) {
$context->buildViolation("A permission is already present "
. "for the same role and scope")
->addViolation();
}
}
} | [
"public",
"function",
"isRoleScopePresentOnce",
"(",
"ExecutionContextInterface",
"$",
"context",
")",
"{",
"$",
"roleScopesId",
"=",
"array_map",
"(",
"function",
"(",
"RoleScope",
"$",
"roleScope",
")",
"{",
"return",
"$",
"roleScope",
"->",
"getId",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"getRoleScopes",
"(",
")",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"countedIds",
"=",
"array_count_values",
"(",
"$",
"roleScopesId",
")",
";",
"foreach",
"(",
"$",
"countedIds",
"as",
"$",
"id",
"=>",
"$",
"nb",
")",
"{",
"if",
"(",
"$",
"nb",
">",
"1",
")",
"{",
"$",
"context",
"->",
"buildViolation",
"(",
"\"A permission is already present \"",
".",
"\"for the same role and scope\"",
")",
"->",
"addViolation",
"(",
")",
";",
"}",
"}",
"}"
] | Test that a role scope is associated only once with the permission group
@param ExecutionContextInterface $context | [
"Test",
"that",
"a",
"role",
"scope",
"is",
"associated",
"only",
"once",
"with",
"the",
"permission",
"group"
] | train | https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Entity/PermissionsGroup.php#L110-L125 |
austinkregel/Warden | src/Warden/Http/Controllers/ModelController.php | ModelController.getModelList | protected function getModelList($model_name)
{
/*
* Here we need to make sure that we have all of the fields that we want to
* have shown, if the visible field is not currently set we should grab
* the fillable fields so we can populate the table on the view.
*/
$model = $this->findModel($model_name, null);
/*
* We need to get the fields for the model, so use the model we newed up
* above and grab the Visible field first, if it's not set then grab
* the fillable fields.
*/
$field_names = !empty($model->getVisible()) ?
$model->getVisible() :
$model->getFillable();
// Paginate the results to plan for lots of items within the database.
$desired_objects = $model::paginate(50);
// Inject a quick form for deleting the objects.
return view('warden::view-models')
->with('field_names', ($field_names))
->with('models', $desired_objects)
->with('model_name', $model_name);
} | php | protected function getModelList($model_name)
{
/*
* Here we need to make sure that we have all of the fields that we want to
* have shown, if the visible field is not currently set we should grab
* the fillable fields so we can populate the table on the view.
*/
$model = $this->findModel($model_name, null);
/*
* We need to get the fields for the model, so use the model we newed up
* above and grab the Visible field first, if it's not set then grab
* the fillable fields.
*/
$field_names = !empty($model->getVisible()) ?
$model->getVisible() :
$model->getFillable();
// Paginate the results to plan for lots of items within the database.
$desired_objects = $model::paginate(50);
// Inject a quick form for deleting the objects.
return view('warden::view-models')
->with('field_names', ($field_names))
->with('models', $desired_objects)
->with('model_name', $model_name);
} | [
"protected",
"function",
"getModelList",
"(",
"$",
"model_name",
")",
"{",
"/*\n * Here we need to make sure that we have all of the fields that we want to\n * have shown, if the visible field is not currently set we should grab\n * the fillable fields so we can populate the table on the view.\n */",
"$",
"model",
"=",
"$",
"this",
"->",
"findModel",
"(",
"$",
"model_name",
",",
"null",
")",
";",
"/*\n * We need to get the fields for the model, so use the model we newed up\n * above and grab the Visible field first, if it's not set then grab\n * the fillable fields.\n */",
"$",
"field_names",
"=",
"!",
"empty",
"(",
"$",
"model",
"->",
"getVisible",
"(",
")",
")",
"?",
"$",
"model",
"->",
"getVisible",
"(",
")",
":",
"$",
"model",
"->",
"getFillable",
"(",
")",
";",
"// Paginate the results to plan for lots of items within the database.",
"$",
"desired_objects",
"=",
"$",
"model",
"::",
"paginate",
"(",
"50",
")",
";",
"// Inject a quick form for deleting the objects.",
"return",
"view",
"(",
"'warden::view-models'",
")",
"->",
"with",
"(",
"'field_names'",
",",
"(",
"$",
"field_names",
")",
")",
"->",
"with",
"(",
"'models'",
",",
"$",
"desired_objects",
")",
"->",
"with",
"(",
"'model_name'",
",",
"$",
"model_name",
")",
";",
"}"
] | @param string $model_name A key in the warden.models configuration
@return view | [
"@param",
"string",
"$model_name",
"A",
"key",
"in",
"the",
"warden",
".",
"models",
"configuration"
] | train | https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ModelController.php#L18-L44 |
austinkregel/Warden | src/Warden/Http/Controllers/ModelController.php | ModelController.findModel | private function findModel($model_name, $id = null)
{
$model = config('kregel.warden.models.'.$model_name.'.model');
if (empty($model)) {
throw new \Exception('There is no model by the name {'.$model_name.'}');
}
if (empty($id) | !is_numeric($id)) {
return new $model();
}
return $model::findOrFail($id);
} | php | private function findModel($model_name, $id = null)
{
$model = config('kregel.warden.models.'.$model_name.'.model');
if (empty($model)) {
throw new \Exception('There is no model by the name {'.$model_name.'}');
}
if (empty($id) | !is_numeric($id)) {
return new $model();
}
return $model::findOrFail($id);
} | [
"private",
"function",
"findModel",
"(",
"$",
"model_name",
",",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"model",
"=",
"config",
"(",
"'kregel.warden.models.'",
".",
"$",
"model_name",
".",
"'.model'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"model",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'There is no model by the name {'",
".",
"$",
"model_name",
".",
"'}'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"|",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"return",
"new",
"$",
"model",
"(",
")",
";",
"}",
"return",
"$",
"model",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"}"
] | @param string $model_name Must be a valid class
@param int $id ID of the desired class
@throws \Exception
@return Model A model defined by ID | [
"@param",
"string",
"$model_name",
"Must",
"be",
"a",
"valid",
"class",
"@param",
"int",
"$id",
"ID",
"of",
"the",
"desired",
"class"
] | train | https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ModelController.php#L54-L65 |
austinkregel/Warden | src/Warden/Http/Controllers/ModelController.php | ModelController.getModel | protected function getModel($model_name, $id, FormModel $form)
{
/*
* We need to grab the model from the config and select one entry for
* that model from within the database.
*/
$model = $this->findModel($model_name, $id);
/*
* Here we generate the form to update the model using the kregel/formmodel
* package
*/
$form = $form->using(config('kregel.formmodel.using.framework'))
->withModel($model)
->submitTo(route('warden::api.update-model', [$model_name, $model->id]));
$form_info = $form->form([
'method' => 'post',
'enctype' => 'multipart/form-data',
]);
return view('warden::view-model')
->with('form', $form_info)
->with('model_name', $model_name)
->with('vue_components', $form->vue_components);
} | php | protected function getModel($model_name, $id, FormModel $form)
{
/*
* We need to grab the model from the config and select one entry for
* that model from within the database.
*/
$model = $this->findModel($model_name, $id);
/*
* Here we generate the form to update the model using the kregel/formmodel
* package
*/
$form = $form->using(config('kregel.formmodel.using.framework'))
->withModel($model)
->submitTo(route('warden::api.update-model', [$model_name, $model->id]));
$form_info = $form->form([
'method' => 'post',
'enctype' => 'multipart/form-data',
]);
return view('warden::view-model')
->with('form', $form_info)
->with('model_name', $model_name)
->with('vue_components', $form->vue_components);
} | [
"protected",
"function",
"getModel",
"(",
"$",
"model_name",
",",
"$",
"id",
",",
"FormModel",
"$",
"form",
")",
"{",
"/*\n * We need to grab the model from the config and select one entry for\n * that model from within the database.\n */",
"$",
"model",
"=",
"$",
"this",
"->",
"findModel",
"(",
"$",
"model_name",
",",
"$",
"id",
")",
";",
"/*\n * Here we generate the form to update the model using the kregel/formmodel\n * package\n */",
"$",
"form",
"=",
"$",
"form",
"->",
"using",
"(",
"config",
"(",
"'kregel.formmodel.using.framework'",
")",
")",
"->",
"withModel",
"(",
"$",
"model",
")",
"->",
"submitTo",
"(",
"route",
"(",
"'warden::api.update-model'",
",",
"[",
"$",
"model_name",
",",
"$",
"model",
"->",
"id",
"]",
")",
")",
";",
"$",
"form_info",
"=",
"$",
"form",
"->",
"form",
"(",
"[",
"'method'",
"=>",
"'post'",
",",
"'enctype'",
"=>",
"'multipart/form-data'",
",",
"]",
")",
";",
"return",
"view",
"(",
"'warden::view-model'",
")",
"->",
"with",
"(",
"'form'",
",",
"$",
"form_info",
")",
"->",
"with",
"(",
"'model_name'",
",",
"$",
"model_name",
")",
"->",
"with",
"(",
"'vue_components'",
",",
"$",
"form",
"->",
"vue_components",
")",
";",
"}"
] | @param string $model_name A key in the warden.models configuration
@param int $id The id of the model
@param FormModel $form An injected model
@return mixed | [
"@param",
"string",
"$model_name",
"A",
"key",
"in",
"the",
"warden",
".",
"models",
"configuration",
"@param",
"int",
"$id",
"The",
"id",
"of",
"the",
"model",
"@param",
"FormModel",
"$form",
"An",
"injected",
"model"
] | train | https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ModelController.php#L74-L97 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.