repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
alexlcdee/colorcli | src/Logger.php | Logger.resetBGColor | public function resetBGColor()
{
static::$backgroundColorMap = [
LogLevel::EMERGENCY => BackgroundColors::RED(),
LogLevel::ALERT => BackgroundColors::RED(),
LogLevel::CRITICAL => BackgroundColors::YELLOW(),
LogLevel::ERROR => null,
LogLevel::WARNING => null,
LogLevel::NOTICE => null,
LogLevel::INFO => null,
LogLevel::DEBUG => null
];
} | php | public function resetBGColor()
{
static::$backgroundColorMap = [
LogLevel::EMERGENCY => BackgroundColors::RED(),
LogLevel::ALERT => BackgroundColors::RED(),
LogLevel::CRITICAL => BackgroundColors::YELLOW(),
LogLevel::ERROR => null,
LogLevel::WARNING => null,
LogLevel::NOTICE => null,
LogLevel::INFO => null,
LogLevel::DEBUG => null
];
} | [
"public",
"function",
"resetBGColor",
"(",
")",
"{",
"static",
"::",
"$",
"backgroundColorMap",
"=",
"[",
"LogLevel",
"::",
"EMERGENCY",
"=>",
"BackgroundColors",
"::",
"RED",
"(",
")",
",",
"LogLevel",
"::",
"ALERT",
"=>",
"BackgroundColors",
"::",
"RED",
"(",
")",
",",
"LogLevel",
"::",
"CRITICAL",
"=>",
"BackgroundColors",
"::",
"YELLOW",
"(",
")",
",",
"LogLevel",
"::",
"ERROR",
"=>",
"null",
",",
"LogLevel",
"::",
"WARNING",
"=>",
"null",
",",
"LogLevel",
"::",
"NOTICE",
"=>",
"null",
",",
"LogLevel",
"::",
"INFO",
"=>",
"null",
",",
"LogLevel",
"::",
"DEBUG",
"=>",
"null",
"]",
";",
"}"
] | Set background colors map to default ones | [
"Set",
"background",
"colors",
"map",
"to",
"default",
"ones"
] | 2107917987f6c300ac5ce4a26102c9bf8e6b3d95 | https://github.com/alexlcdee/colorcli/blob/2107917987f6c300ac5ce4a26102c9bf8e6b3d95/src/Logger.php#L121-L133 | train |
alexlcdee/colorcli | src/Logger.php | Logger.resetOutputStreams | public function resetOutputStreams()
{
defined('STDOUT') || define('STDOUT', fopen('php://stdout', 'w'));
defined('STDERR') || define('STDERR', fopen('php://stderr', 'w'));
static::$streamsMap = [
LogLevel::EMERGENCY => STDERR,
LogLevel::ALERT => STDERR,
LogLevel::CRITICAL => STDERR,
LogLevel::ERROR => STDERR,
LogLevel::WARNING => STDERR,
LogLevel::NOTICE => STDOUT,
LogLevel::INFO => STDOUT,
LogLevel::DEBUG => STDOUT
];
} | php | public function resetOutputStreams()
{
defined('STDOUT') || define('STDOUT', fopen('php://stdout', 'w'));
defined('STDERR') || define('STDERR', fopen('php://stderr', 'w'));
static::$streamsMap = [
LogLevel::EMERGENCY => STDERR,
LogLevel::ALERT => STDERR,
LogLevel::CRITICAL => STDERR,
LogLevel::ERROR => STDERR,
LogLevel::WARNING => STDERR,
LogLevel::NOTICE => STDOUT,
LogLevel::INFO => STDOUT,
LogLevel::DEBUG => STDOUT
];
} | [
"public",
"function",
"resetOutputStreams",
"(",
")",
"{",
"defined",
"(",
"'STDOUT'",
")",
"||",
"define",
"(",
"'STDOUT'",
",",
"fopen",
"(",
"'php://stdout'",
",",
"'w'",
")",
")",
";",
"defined",
"(",
"'STDERR'",
")",
"||",
"define",
"(",
"'STDERR'",
",",
"fopen",
"(",
"'php://stderr'",
",",
"'w'",
")",
")",
";",
"static",
"::",
"$",
"streamsMap",
"=",
"[",
"LogLevel",
"::",
"EMERGENCY",
"=>",
"STDERR",
",",
"LogLevel",
"::",
"ALERT",
"=>",
"STDERR",
",",
"LogLevel",
"::",
"CRITICAL",
"=>",
"STDERR",
",",
"LogLevel",
"::",
"ERROR",
"=>",
"STDERR",
",",
"LogLevel",
"::",
"WARNING",
"=>",
"STDERR",
",",
"LogLevel",
"::",
"NOTICE",
"=>",
"STDOUT",
",",
"LogLevel",
"::",
"INFO",
"=>",
"STDOUT",
",",
"LogLevel",
"::",
"DEBUG",
"=>",
"STDOUT",
"]",
";",
"}"
] | Set output streams map to default map | [
"Set",
"output",
"streams",
"map",
"to",
"default",
"map"
] | 2107917987f6c300ac5ce4a26102c9bf8e6b3d95 | https://github.com/alexlcdee/colorcli/blob/2107917987f6c300ac5ce4a26102c9bf8e6b3d95/src/Logger.php#L209-L223 | train |
alexlcdee/colorcli | src/Logger.php | Logger.setFGColor | public function setFGColor($level, ForegroundColors $color)
{
if (static::$foregroundColorMap === null) {
$this->resetFGColors();
}
$this->checkLevel($level);
static::$foregroundColorMap[$level] = $color;
return $this;
} | php | public function setFGColor($level, ForegroundColors $color)
{
if (static::$foregroundColorMap === null) {
$this->resetFGColors();
}
$this->checkLevel($level);
static::$foregroundColorMap[$level] = $color;
return $this;
} | [
"public",
"function",
"setFGColor",
"(",
"$",
"level",
",",
"ForegroundColors",
"$",
"color",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"foregroundColorMap",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"resetFGColors",
"(",
")",
";",
"}",
"$",
"this",
"->",
"checkLevel",
"(",
"$",
"level",
")",
";",
"static",
"::",
"$",
"foregroundColorMap",
"[",
"$",
"level",
"]",
"=",
"$",
"color",
";",
"return",
"$",
"this",
";",
"}"
] | Set foreground color for specified level
@param mixed $level
@param ForegroundColors $color
@return $this | [
"Set",
"foreground",
"color",
"for",
"specified",
"level"
] | 2107917987f6c300ac5ce4a26102c9bf8e6b3d95 | https://github.com/alexlcdee/colorcli/blob/2107917987f6c300ac5ce4a26102c9bf8e6b3d95/src/Logger.php#L231-L239 | train |
alexlcdee/colorcli | src/Logger.php | Logger.setBGColor | public function setBGColor($level, ForegroundColors $color)
{
if (static::$foregroundColorMap === null) {
$this->resetBGColor();
}
$this->checkLevel($level);
static::$foregroundColorMap[$level] = $color;
return $this;
} | php | public function setBGColor($level, ForegroundColors $color)
{
if (static::$foregroundColorMap === null) {
$this->resetBGColor();
}
$this->checkLevel($level);
static::$foregroundColorMap[$level] = $color;
return $this;
} | [
"public",
"function",
"setBGColor",
"(",
"$",
"level",
",",
"ForegroundColors",
"$",
"color",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"foregroundColorMap",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"resetBGColor",
"(",
")",
";",
"}",
"$",
"this",
"->",
"checkLevel",
"(",
"$",
"level",
")",
";",
"static",
"::",
"$",
"foregroundColorMap",
"[",
"$",
"level",
"]",
"=",
"$",
"color",
";",
"return",
"$",
"this",
";",
"}"
] | Set background color for specified level
@param mixed $level
@param ForegroundColors $color
@return $this | [
"Set",
"background",
"color",
"for",
"specified",
"level"
] | 2107917987f6c300ac5ce4a26102c9bf8e6b3d95 | https://github.com/alexlcdee/colorcli/blob/2107917987f6c300ac5ce4a26102c9bf8e6b3d95/src/Logger.php#L247-L255 | train |
alexlcdee/colorcli | src/Logger.php | Logger.setOutputStream | public function setOutputStream($level, $stream)
{
if (static::$streamsMap === null) {
$this->resetOutputStreams();
}
$this->checkLevel($level);
if (!is_resource($stream)) {
throw new \UnexpectedValueException("Argument '\$stream' must be a writable stream resource");
}
static::$streamsMap[$level] = $stream;
return $this;
} | php | public function setOutputStream($level, $stream)
{
if (static::$streamsMap === null) {
$this->resetOutputStreams();
}
$this->checkLevel($level);
if (!is_resource($stream)) {
throw new \UnexpectedValueException("Argument '\$stream' must be a writable stream resource");
}
static::$streamsMap[$level] = $stream;
return $this;
} | [
"public",
"function",
"setOutputStream",
"(",
"$",
"level",
",",
"$",
"stream",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"streamsMap",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"resetOutputStreams",
"(",
")",
";",
"}",
"$",
"this",
"->",
"checkLevel",
"(",
"$",
"level",
")",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"stream",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Argument '\\$stream' must be a writable stream resource\"",
")",
";",
"}",
"static",
"::",
"$",
"streamsMap",
"[",
"$",
"level",
"]",
"=",
"$",
"stream",
";",
"return",
"$",
"this",
";",
"}"
] | Set output stream for specified level
@param mixed $level
@param resource $stream
@return $this | [
"Set",
"output",
"stream",
"for",
"specified",
"level"
] | 2107917987f6c300ac5ce4a26102c9bf8e6b3d95 | https://github.com/alexlcdee/colorcli/blob/2107917987f6c300ac5ce4a26102c9bf8e6b3d95/src/Logger.php#L263-L274 | train |
ekyna/SettingBundle | Controller/Admin/ParameterController.php | ParameterController.showAction | public function showAction()
{
$this->isGranted('VIEW');
$this->container->get('ekyna_admin.menu.builder')
->breadcrumbAppend('settings', 'ekyna_setting.parameter.label.plural');
$manager = $this->getSettingsManager();
$schemas = $this->getSettingsRegistry()->getSchemas();
$settings = [];
foreach($schemas as $namespace => $schema) {
$settings[$namespace] = $manager->loadSettings($namespace);
}
return $this->render('EkynaSettingBundle:Settings:show.html.twig', [
'settings' => $settings,
'labels' => $manager->getLabels(),
'templates' => $manager->getShowTemplates(),
]);
} | php | public function showAction()
{
$this->isGranted('VIEW');
$this->container->get('ekyna_admin.menu.builder')
->breadcrumbAppend('settings', 'ekyna_setting.parameter.label.plural');
$manager = $this->getSettingsManager();
$schemas = $this->getSettingsRegistry()->getSchemas();
$settings = [];
foreach($schemas as $namespace => $schema) {
$settings[$namespace] = $manager->loadSettings($namespace);
}
return $this->render('EkynaSettingBundle:Settings:show.html.twig', [
'settings' => $settings,
'labels' => $manager->getLabels(),
'templates' => $manager->getShowTemplates(),
]);
} | [
"public",
"function",
"showAction",
"(",
")",
"{",
"$",
"this",
"->",
"isGranted",
"(",
"'VIEW'",
")",
";",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'ekyna_admin.menu.builder'",
")",
"->",
"breadcrumbAppend",
"(",
"'settings'",
",",
"'ekyna_setting.parameter.label.plural'",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getSettingsManager",
"(",
")",
";",
"$",
"schemas",
"=",
"$",
"this",
"->",
"getSettingsRegistry",
"(",
")",
"->",
"getSchemas",
"(",
")",
";",
"$",
"settings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"schemas",
"as",
"$",
"namespace",
"=>",
"$",
"schema",
")",
"{",
"$",
"settings",
"[",
"$",
"namespace",
"]",
"=",
"$",
"manager",
"->",
"loadSettings",
"(",
"$",
"namespace",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'EkynaSettingBundle:Settings:show.html.twig'",
",",
"[",
"'settings'",
"=>",
"$",
"settings",
",",
"'labels'",
"=>",
"$",
"manager",
"->",
"getLabels",
"(",
")",
",",
"'templates'",
"=>",
"$",
"manager",
"->",
"getShowTemplates",
"(",
")",
",",
"]",
")",
";",
"}"
] | Show the parameters.
@return \Symfony\Component\HttpFoundation\Response | [
"Show",
"the",
"parameters",
"."
] | df58f83eb3a01ef56cd76ea73639322c581e75c1 | https://github.com/ekyna/SettingBundle/blob/df58f83eb3a01ef56cd76ea73639322c581e75c1/Controller/Admin/ParameterController.php#L22-L42 | train |
ekyna/SettingBundle | Controller/Admin/ParameterController.php | ParameterController.editAction | public function editAction(Request $request)
{
$this->isGranted('EDIT');
$this->container->get('ekyna_admin.menu.builder')
->breadcrumbAppend('settings', 'ekyna_setting.parameter.label.plural');
$manager = $this->getSettingsManager();
$schemas = $this->getSettingsRegistry()->getSchemas();
$settings = [];
$builder = $this
->createFormBuilder(null, [
'data_class' => null,
'admin_mode' => true,
'cascade_validation' => true,
])
->add('actions', 'form_actions', [
'buttons' => [
'save' => [
'type' => 'submit', 'options' => [
'button_class' => 'primary',
'label' => 'ekyna_core.button.save',
'attr' => [
'icon' => 'ok',
],
],
],
'cancel' => [
'type' => 'button', 'options' => [
'label' => 'ekyna_core.button.cancel',
'button_class' => 'default',
'as_link' => true,
'attr' => [
'class' => 'form-cancel-btn',
'icon' => 'remove',
'href' => $this->generateUrl('ekyna_setting_parameter_admin_show'),
],
],
],
],
])
;
foreach($schemas as $namespace => $schema) {
$builder->add($namespace, $schema);
$settings[$namespace] = $manager->loadSettings($namespace);
}
$form = $builder
->getForm()
->setData($settings)
;
if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
$messageType = 'success';
try {
foreach($schemas as $namespace => $schema) {
$manager->saveSettings($namespace, $form->get($namespace)->getData());
}
$message = $this->getTranslator()->trans('ekyna_setting.parameter.flash.edit');
} catch (ValidatorException $exception) {
$message = $this->getTranslator()->trans($exception->getMessage(), [], 'validators');
$messageType = 'danger';
}
$this->addFlash($message, $messageType);
return $this->redirect($this->generateUrl('ekyna_setting_parameter_admin_show'));
}
return $this->render('EkynaSettingBundle:Settings:edit.html.twig', [
'labels' => $manager->getLabels(),
'templates' => $manager->getFormTemplates(),
'form' => $form->createView(),
]);
} | php | public function editAction(Request $request)
{
$this->isGranted('EDIT');
$this->container->get('ekyna_admin.menu.builder')
->breadcrumbAppend('settings', 'ekyna_setting.parameter.label.plural');
$manager = $this->getSettingsManager();
$schemas = $this->getSettingsRegistry()->getSchemas();
$settings = [];
$builder = $this
->createFormBuilder(null, [
'data_class' => null,
'admin_mode' => true,
'cascade_validation' => true,
])
->add('actions', 'form_actions', [
'buttons' => [
'save' => [
'type' => 'submit', 'options' => [
'button_class' => 'primary',
'label' => 'ekyna_core.button.save',
'attr' => [
'icon' => 'ok',
],
],
],
'cancel' => [
'type' => 'button', 'options' => [
'label' => 'ekyna_core.button.cancel',
'button_class' => 'default',
'as_link' => true,
'attr' => [
'class' => 'form-cancel-btn',
'icon' => 'remove',
'href' => $this->generateUrl('ekyna_setting_parameter_admin_show'),
],
],
],
],
])
;
foreach($schemas as $namespace => $schema) {
$builder->add($namespace, $schema);
$settings[$namespace] = $manager->loadSettings($namespace);
}
$form = $builder
->getForm()
->setData($settings)
;
if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
$messageType = 'success';
try {
foreach($schemas as $namespace => $schema) {
$manager->saveSettings($namespace, $form->get($namespace)->getData());
}
$message = $this->getTranslator()->trans('ekyna_setting.parameter.flash.edit');
} catch (ValidatorException $exception) {
$message = $this->getTranslator()->trans($exception->getMessage(), [], 'validators');
$messageType = 'danger';
}
$this->addFlash($message, $messageType);
return $this->redirect($this->generateUrl('ekyna_setting_parameter_admin_show'));
}
return $this->render('EkynaSettingBundle:Settings:edit.html.twig', [
'labels' => $manager->getLabels(),
'templates' => $manager->getFormTemplates(),
'form' => $form->createView(),
]);
} | [
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"isGranted",
"(",
"'EDIT'",
")",
";",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'ekyna_admin.menu.builder'",
")",
"->",
"breadcrumbAppend",
"(",
"'settings'",
",",
"'ekyna_setting.parameter.label.plural'",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getSettingsManager",
"(",
")",
";",
"$",
"schemas",
"=",
"$",
"this",
"->",
"getSettingsRegistry",
"(",
")",
"->",
"getSchemas",
"(",
")",
";",
"$",
"settings",
"=",
"[",
"]",
";",
"$",
"builder",
"=",
"$",
"this",
"->",
"createFormBuilder",
"(",
"null",
",",
"[",
"'data_class'",
"=>",
"null",
",",
"'admin_mode'",
"=>",
"true",
",",
"'cascade_validation'",
"=>",
"true",
",",
"]",
")",
"->",
"add",
"(",
"'actions'",
",",
"'form_actions'",
",",
"[",
"'buttons'",
"=>",
"[",
"'save'",
"=>",
"[",
"'type'",
"=>",
"'submit'",
",",
"'options'",
"=>",
"[",
"'button_class'",
"=>",
"'primary'",
",",
"'label'",
"=>",
"'ekyna_core.button.save'",
",",
"'attr'",
"=>",
"[",
"'icon'",
"=>",
"'ok'",
",",
"]",
",",
"]",
",",
"]",
",",
"'cancel'",
"=>",
"[",
"'type'",
"=>",
"'button'",
",",
"'options'",
"=>",
"[",
"'label'",
"=>",
"'ekyna_core.button.cancel'",
",",
"'button_class'",
"=>",
"'default'",
",",
"'as_link'",
"=>",
"true",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'form-cancel-btn'",
",",
"'icon'",
"=>",
"'remove'",
",",
"'href'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'ekyna_setting_parameter_admin_show'",
")",
",",
"]",
",",
"]",
",",
"]",
",",
"]",
",",
"]",
")",
";",
"foreach",
"(",
"$",
"schemas",
"as",
"$",
"namespace",
"=>",
"$",
"schema",
")",
"{",
"$",
"builder",
"->",
"add",
"(",
"$",
"namespace",
",",
"$",
"schema",
")",
";",
"$",
"settings",
"[",
"$",
"namespace",
"]",
"=",
"$",
"manager",
"->",
"loadSettings",
"(",
"$",
"namespace",
")",
";",
"}",
"$",
"form",
"=",
"$",
"builder",
"->",
"getForm",
"(",
")",
"->",
"setData",
"(",
"$",
"settings",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isMethod",
"(",
"'POST'",
")",
"&&",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"messageType",
"=",
"'success'",
";",
"try",
"{",
"foreach",
"(",
"$",
"schemas",
"as",
"$",
"namespace",
"=>",
"$",
"schema",
")",
"{",
"$",
"manager",
"->",
"saveSettings",
"(",
"$",
"namespace",
",",
"$",
"form",
"->",
"get",
"(",
"$",
"namespace",
")",
"->",
"getData",
"(",
")",
")",
";",
"}",
"$",
"message",
"=",
"$",
"this",
"->",
"getTranslator",
"(",
")",
"->",
"trans",
"(",
"'ekyna_setting.parameter.flash.edit'",
")",
";",
"}",
"catch",
"(",
"ValidatorException",
"$",
"exception",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getTranslator",
"(",
")",
"->",
"trans",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"[",
"]",
",",
"'validators'",
")",
";",
"$",
"messageType",
"=",
"'danger'",
";",
"}",
"$",
"this",
"->",
"addFlash",
"(",
"$",
"message",
",",
"$",
"messageType",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'ekyna_setting_parameter_admin_show'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'EkynaSettingBundle:Settings:edit.html.twig'",
",",
"[",
"'labels'",
"=>",
"$",
"manager",
"->",
"getLabels",
"(",
")",
",",
"'templates'",
"=>",
"$",
"manager",
"->",
"getFormTemplates",
"(",
")",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"]",
")",
";",
"}"
] | Edit the parameters.
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Edit",
"the",
"parameters",
"."
] | df58f83eb3a01ef56cd76ea73639322c581e75c1 | https://github.com/ekyna/SettingBundle/blob/df58f83eb3a01ef56cd76ea73639322c581e75c1/Controller/Admin/ParameterController.php#L50-L124 | train |
ziopod/Tanuki-core | classes/View/Tanuki.php | View_Tanuki.title | public function title()
{
// Try to load title from model
$model_name = $this->model_name;
if (isset($this->$model_name->title))
{
return $this->$model_name->title;
}
// Instead use global config
return Arr::path($this->tanuki(), 'title');
} | php | public function title()
{
// Try to load title from model
$model_name = $this->model_name;
if (isset($this->$model_name->title))
{
return $this->$model_name->title;
}
// Instead use global config
return Arr::path($this->tanuki(), 'title');
} | [
"public",
"function",
"title",
"(",
")",
"{",
"// Try to load title from model",
"$",
"model_name",
"=",
"$",
"this",
"->",
"model_name",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"$",
"model_name",
"->",
"title",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"model_name",
"->",
"title",
";",
"}",
"// Instead use global config",
"return",
"Arr",
"::",
"path",
"(",
"$",
"this",
"->",
"tanuki",
"(",
")",
",",
"'title'",
")",
";",
"}"
] | Set HTML title tag
@return string | [
"Set",
"HTML",
"title",
"tag"
] | 8dbe2dd45c6cafd0029aa747cd1ffebea4a936ab | https://github.com/ziopod/Tanuki-core/blob/8dbe2dd45c6cafd0029aa747cd1ffebea4a936ab/classes/View/Tanuki.php#L133-L145 | train |
mtils/cmsable | src/Cmsable/Mail/MessageBuilder.php | MessageBuilder.setupMessage | public function setupMessage(Message $message){
$this->addRecipients($message);
$this->setSubject($message);
$this->callCustomBuilder($message);
} | php | public function setupMessage(Message $message){
$this->addRecipients($message);
$this->setSubject($message);
$this->callCustomBuilder($message);
} | [
"public",
"function",
"setupMessage",
"(",
"Message",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"addRecipients",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"setSubject",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"callCustomBuilder",
"(",
"$",
"message",
")",
";",
"}"
] | This method will be called by the returned closure
@param \Illuminate\Mail\Message $message
@return void | [
"This",
"method",
"will",
"be",
"called",
"by",
"the",
"returned",
"closure"
] | 03ae84ee3c7d46146f2a1cf687e5c29d6de4286d | https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/MessageBuilder.php#L57-L65 | train |
mtils/cmsable | src/Cmsable/Mail/MessageBuilder.php | MessageBuilder.addRecipients | protected function addRecipients(Message $message){
if($overwriteTo = $this->getOverwriteTo()){
$message->to($overwriteTo);
return;
}
$first = true;
foreach($this->recipients as $recipient){
if($first){
$message->to($recipient);
}
else{
$message->bcc($recipient);
}
$first = false;
}
} | php | protected function addRecipients(Message $message){
if($overwriteTo = $this->getOverwriteTo()){
$message->to($overwriteTo);
return;
}
$first = true;
foreach($this->recipients as $recipient){
if($first){
$message->to($recipient);
}
else{
$message->bcc($recipient);
}
$first = false;
}
} | [
"protected",
"function",
"addRecipients",
"(",
"Message",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"overwriteTo",
"=",
"$",
"this",
"->",
"getOverwriteTo",
"(",
")",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"overwriteTo",
")",
";",
"return",
";",
"}",
"$",
"first",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"recipients",
"as",
"$",
"recipient",
")",
"{",
"if",
"(",
"$",
"first",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"recipient",
")",
";",
"}",
"else",
"{",
"$",
"message",
"->",
"bcc",
"(",
"$",
"recipient",
")",
";",
"}",
"$",
"first",
"=",
"false",
";",
"}",
"}"
] | Adds the recipients to the message
@param \Illuminate\Mail\Message $message
@return void | [
"Adds",
"the",
"recipients",
"to",
"the",
"message"
] | 03ae84ee3c7d46146f2a1cf687e5c29d6de4286d | https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/MessageBuilder.php#L105-L127 | train |
mtils/cmsable | src/Cmsable/Mail/MessageBuilder.php | MessageBuilder.setSubject | protected function setSubject(Message $message){
if(!isset($this->data['subject'])){
throw new OutOfBoundsException("You have to pass a subject key and value in your view data");
}
$message->subject($this->data['subject']);
} | php | protected function setSubject(Message $message){
if(!isset($this->data['subject'])){
throw new OutOfBoundsException("You have to pass a subject key and value in your view data");
}
$message->subject($this->data['subject']);
} | [
"protected",
"function",
"setSubject",
"(",
"Message",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'subject'",
"]",
")",
")",
"{",
"throw",
"new",
"OutOfBoundsException",
"(",
"\"You have to pass a subject key and value in your view data\"",
")",
";",
"}",
"$",
"message",
"->",
"subject",
"(",
"$",
"this",
"->",
"data",
"[",
"'subject'",
"]",
")",
";",
"}"
] | Sets tzhe subject of the message
@param \Illuminate\Mail\Message $message
@return void | [
"Sets",
"tzhe",
"subject",
"of",
"the",
"message"
] | 03ae84ee3c7d46146f2a1cf687e5c29d6de4286d | https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/MessageBuilder.php#L135-L143 | train |
bytic/orm | src/Relations/Traits/HasPivotTable.php | HasPivotTable.generatePivotTable | public function generatePivotTable()
{
$tables = [
$this->getManager()->getTable(),
$this->getWith()->getTable()
];
sort($tables);
return implode("_", $tables);
} | php | public function generatePivotTable()
{
$tables = [
$this->getManager()->getTable(),
$this->getWith()->getTable()
];
sort($tables);
return implode("_", $tables);
} | [
"public",
"function",
"generatePivotTable",
"(",
")",
"{",
"$",
"tables",
"=",
"[",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getTable",
"(",
")",
",",
"$",
"this",
"->",
"getWith",
"(",
")",
"->",
"getTable",
"(",
")",
"]",
";",
"sort",
"(",
"$",
"tables",
")",
";",
"return",
"implode",
"(",
"\"_\"",
",",
"$",
"tables",
")",
";",
"}"
] | Builds the name of a has-and-belongs-to-many association table
@return string | [
"Builds",
"the",
"name",
"of",
"a",
"has",
"-",
"and",
"-",
"belongs",
"-",
"to",
"-",
"many",
"association",
"table"
] | 8d9a79b47761af0bfd9b8d1d28c83221dcac0de0 | https://github.com/bytic/orm/blob/8d9a79b47761af0bfd9b8d1d28c83221dcac0de0/src/Relations/Traits/HasPivotTable.php#L46-L55 | train |
kherge-abandoned/php-service-process | src/lib/Herrera/Service/Process/Process.php | Process.glob | public function glob($pattern)
{
foreach (glob($pattern) as $result) {
$this->builder->add($result);
}
} | php | public function glob($pattern)
{
foreach (glob($pattern) as $result) {
$this->builder->add($result);
}
} | [
"public",
"function",
"glob",
"(",
"$",
"pattern",
")",
"{",
"foreach",
"(",
"glob",
"(",
"$",
"pattern",
")",
"as",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"add",
"(",
"$",
"result",
")",
";",
"}",
"}"
] | Expands the glob pattern and add the results as arguments.
@param string $pattern The glob pattern.
@return Process For method chaining. | [
"Expands",
"the",
"glob",
"pattern",
"and",
"add",
"the",
"results",
"as",
"arguments",
"."
] | 33b6e17c027d99dcb38bfe66f250b56800a525fa | https://github.com/kherge-abandoned/php-service-process/blob/33b6e17c027d99dcb38bfe66f250b56800a525fa/src/lib/Herrera/Service/Process/Process.php#L90-L95 | train |
SevenEcks/string-utils | src/StringUtils.php | StringUtils.tostr | public function tostr(...$strings)
{
$new_string = '';
foreach ($strings as $temp) {
switch (gettype($temp)) {
case "array":
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($temp));
foreach($it as $v) {
$temp_str .= ' ' . $this->tostr($v);
}
break;
default:
$temp_str = (string)$temp;
break;
}
$new_string .= $temp_str;
}
return trim($new_string);
} | php | public function tostr(...$strings)
{
$new_string = '';
foreach ($strings as $temp) {
switch (gettype($temp)) {
case "array":
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($temp));
foreach($it as $v) {
$temp_str .= ' ' . $this->tostr($v);
}
break;
default:
$temp_str = (string)$temp;
break;
}
$new_string .= $temp_str;
}
return trim($new_string);
} | [
"public",
"function",
"tostr",
"(",
"...",
"$",
"strings",
")",
"{",
"$",
"new_string",
"=",
"''",
";",
"foreach",
"(",
"$",
"strings",
"as",
"$",
"temp",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"temp",
")",
")",
"{",
"case",
"\"array\"",
":",
"$",
"it",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveArrayIterator",
"(",
"$",
"temp",
")",
")",
";",
"foreach",
"(",
"$",
"it",
"as",
"$",
"v",
")",
"{",
"$",
"temp_str",
".=",
"' '",
".",
"$",
"this",
"->",
"tostr",
"(",
"$",
"v",
")",
";",
"}",
"break",
";",
"default",
":",
"$",
"temp_str",
"=",
"(",
"string",
")",
"$",
"temp",
";",
"break",
";",
"}",
"$",
"new_string",
".=",
"$",
"temp_str",
";",
"}",
"return",
"trim",
"(",
"$",
"new_string",
")",
";",
"}"
] | Take n arguments and combine them into a single
string and return that string
@param string $strings
@param ... $strings
@return string | [
"Take",
"n",
"arguments",
"and",
"combine",
"them",
"into",
"a",
"single",
"string",
"and",
"return",
"that",
"string"
] | 3d1fc3cbac2a77d1fbd52c4eca1868f6136ae3a0 | https://github.com/SevenEcks/string-utils/blob/3d1fc3cbac2a77d1fbd52c4eca1868f6136ae3a0/src/StringUtils.php#L136-L154 | train |
SevenEcks/string-utils | src/StringUtils.php | StringUtils.wordWrap | public function wordWrap($string)
{
return wordwrap($string, $this->line_length, $this->break_string, $this->split_mid_word);
} | php | public function wordWrap($string)
{
return wordwrap($string, $this->line_length, $this->break_string, $this->split_mid_word);
} | [
"public",
"function",
"wordWrap",
"(",
"$",
"string",
")",
"{",
"return",
"wordwrap",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"line_length",
",",
"$",
"this",
"->",
"break_string",
",",
"$",
"this",
"->",
"split_mid_word",
")",
";",
"}"
] | Return a string wrapped either at a word, or close to the words completion
using the break_string defined on the object
@param string $string
@return none | [
"Return",
"a",
"string",
"wrapped",
"either",
"at",
"a",
"word",
"or",
"close",
"to",
"the",
"words",
"completion",
"using",
"the",
"break_string",
"defined",
"on",
"the",
"object"
] | 3d1fc3cbac2a77d1fbd52c4eca1868f6136ae3a0 | https://github.com/SevenEcks/string-utils/blob/3d1fc3cbac2a77d1fbd52c4eca1868f6136ae3a0/src/StringUtils.php#L176-L179 | train |
SevenEcks/string-utils | src/StringUtils.php | StringUtils.massColor | public function massColor(array $strings, string $color)
{
$len_array = count($strings);
for ($i = 0; $i < $len_array; $i++) {
$strings[$i] = $this->colorize->{$color}($strings[$i]);
}
return $strings;
} | php | public function massColor(array $strings, string $color)
{
$len_array = count($strings);
for ($i = 0; $i < $len_array; $i++) {
$strings[$i] = $this->colorize->{$color}($strings[$i]);
}
return $strings;
} | [
"public",
"function",
"massColor",
"(",
"array",
"$",
"strings",
",",
"string",
"$",
"color",
")",
"{",
"$",
"len_array",
"=",
"count",
"(",
"$",
"strings",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len_array",
";",
"$",
"i",
"++",
")",
"{",
"$",
"strings",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"colorize",
"->",
"{",
"$",
"color",
"}",
"(",
"$",
"strings",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"strings",
";",
"}"
] | Mass colorize an array of strings
@param array $strings
@param string $color
@return array | [
"Mass",
"colorize",
"an",
"array",
"of",
"strings"
] | 3d1fc3cbac2a77d1fbd52c4eca1868f6136ae3a0 | https://github.com/SevenEcks/string-utils/blob/3d1fc3cbac2a77d1fbd52c4eca1868f6136ae3a0/src/StringUtils.php#L308-L315 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Color.php | Color.setRGB | public function setRGB( $rgbValue ) : Color
{
if ( \is_string( $rgbValue ) )
{
$this->setRGBString( $rgbValue );
}
else if ( \is_array( $rgbValue ) && \count( $rgbValue ) > 2 )
{
$this->setRGBArray( $rgbValue );
}
else
{
throw new ArgumentError(
'rgbValue',
$rgbValue,
'Drawing',
'Illegal RGB-Value Format!'
);
}
return $this;
} | php | public function setRGB( $rgbValue ) : Color
{
if ( \is_string( $rgbValue ) )
{
$this->setRGBString( $rgbValue );
}
else if ( \is_array( $rgbValue ) && \count( $rgbValue ) > 2 )
{
$this->setRGBArray( $rgbValue );
}
else
{
throw new ArgumentError(
'rgbValue',
$rgbValue,
'Drawing',
'Illegal RGB-Value Format!'
);
}
return $this;
} | [
"public",
"function",
"setRGB",
"(",
"$",
"rgbValue",
")",
":",
"Color",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"rgbValue",
")",
")",
"{",
"$",
"this",
"->",
"setRGBString",
"(",
"$",
"rgbValue",
")",
";",
"}",
"else",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"rgbValue",
")",
"&&",
"\\",
"count",
"(",
"$",
"rgbValue",
")",
">",
"2",
")",
"{",
"$",
"this",
"->",
"setRGBArray",
"(",
"$",
"rgbValue",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'rgbValue'",
",",
"$",
"rgbValue",
",",
"'Drawing'",
",",
"'Illegal RGB-Value Format!'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets a new color, defined by a valid RGB value.
If a string is used the following formats are valid: 'rgb(r,g,b)' or 'r,g,b'
Or a array (0=r,1=g,2=b) or associative with keys 'r'|'red', 'g'|'green', 'b'|'blue'
@param string|array $rgbValue
@return \Beluga\Drawing\Color
@throws \Beluga\ArgumentError | [
"Sets",
"a",
"new",
"color",
"defined",
"by",
"a",
"valid",
"RGB",
"value",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Color.php#L287-L310 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Color.php | Color.FromString | public static function FromString( $objectString )
{
if ( false !== ( $rgb = ColorTool::Color2Rgb( $objectString ) ) )
{
return new Color(
ColorTool::Rgb2Hex(
$rgb[ 0 ],
$rgb[ 1 ],
$rgb[ 2 ]
)
);
}
if ( false !== ( $hex = self::RgbStringToHex( $objectString ) ) )
{
return new Color( $hex );
}
return new Color();
} | php | public static function FromString( $objectString )
{
if ( false !== ( $rgb = ColorTool::Color2Rgb( $objectString ) ) )
{
return new Color(
ColorTool::Rgb2Hex(
$rgb[ 0 ],
$rgb[ 1 ],
$rgb[ 2 ]
)
);
}
if ( false !== ( $hex = self::RgbStringToHex( $objectString ) ) )
{
return new Color( $hex );
}
return new Color();
} | [
"public",
"static",
"function",
"FromString",
"(",
"$",
"objectString",
")",
"{",
"if",
"(",
"false",
"!==",
"(",
"$",
"rgb",
"=",
"ColorTool",
"::",
"Color2Rgb",
"(",
"$",
"objectString",
")",
")",
")",
"{",
"return",
"new",
"Color",
"(",
"ColorTool",
"::",
"Rgb2Hex",
"(",
"$",
"rgb",
"[",
"0",
"]",
",",
"$",
"rgb",
"[",
"1",
"]",
",",
"$",
"rgb",
"[",
"2",
"]",
")",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"(",
"$",
"hex",
"=",
"self",
"::",
"RgbStringToHex",
"(",
"$",
"objectString",
")",
")",
")",
"{",
"return",
"new",
"Color",
"(",
"$",
"hex",
")",
";",
"}",
"return",
"new",
"Color",
"(",
")",
";",
"}"
] | Init a new instance from defined string.
@param string $objectString
@return \Beluga\Drawing\Color | [
"Init",
"a",
"new",
"instance",
"from",
"defined",
"string",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Color.php#L701-L722 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Color.php | Color.FromArray | public static function FromArray( array $objectData )
{
if ( \count( $objectData ) == 3 )
{
if ( false !== ( $hex = ColorTool::Color2Hex( $objectData ) ) )
{
return new Color( $hex );
}
}
$rgb = array();
if ( isset( $objectData[ 'r' ] ) )
{
$rgb[ 0 ] = \intval( $objectData[ 'r' ] );
}
else if ( isset( $objectData[ 'red' ] ) )
{
$rgb[ 0 ] = \intval( $objectData[ 'red' ] );
}
else if ( isset( $objectData[ 'Red' ] ) )
{
$rgb[ 0 ] = \intval( $objectData[ 'Red' ] );
}
else
{
return new Color();
}
if ( isset( $objectData[ 'g' ] ) )
{
$rgb[ 1 ] = \intval( $objectData[ 'g' ] );
}
else if ( isset( $objectData[ 'green' ] ) )
{
$rgb[ 1 ] = \intval( $objectData[ 'green' ] );
}
else if ( isset( $objectData[ 'Green' ] ) )
{
$rgb[ 1 ] = \intval( $objectData[ 'Green' ] );
}
else
{
return new Color();
}
if ( isset( $objectData[ 'b' ] ) )
{
$rgb[ 2 ] = \intval( $objectData[ 'b' ] );
}
else if ( isset( $objectData[ 'blue' ] ) )
{
$rgb[ 2 ] = \intval( $objectData[ 'blue' ] );
}
else if ( isset( $objectData[ 'Blue' ] ) )
{
$rgb[ 2 ] = \intval( $objectData[ 'Blue' ] );
}
else
{
return new Color();
}
if ( false !== ( $hex = ColorTool::Rgb2Hex( $rgb ) ) )
{
return new Color( $hex );
}
return new Color();
} | php | public static function FromArray( array $objectData )
{
if ( \count( $objectData ) == 3 )
{
if ( false !== ( $hex = ColorTool::Color2Hex( $objectData ) ) )
{
return new Color( $hex );
}
}
$rgb = array();
if ( isset( $objectData[ 'r' ] ) )
{
$rgb[ 0 ] = \intval( $objectData[ 'r' ] );
}
else if ( isset( $objectData[ 'red' ] ) )
{
$rgb[ 0 ] = \intval( $objectData[ 'red' ] );
}
else if ( isset( $objectData[ 'Red' ] ) )
{
$rgb[ 0 ] = \intval( $objectData[ 'Red' ] );
}
else
{
return new Color();
}
if ( isset( $objectData[ 'g' ] ) )
{
$rgb[ 1 ] = \intval( $objectData[ 'g' ] );
}
else if ( isset( $objectData[ 'green' ] ) )
{
$rgb[ 1 ] = \intval( $objectData[ 'green' ] );
}
else if ( isset( $objectData[ 'Green' ] ) )
{
$rgb[ 1 ] = \intval( $objectData[ 'Green' ] );
}
else
{
return new Color();
}
if ( isset( $objectData[ 'b' ] ) )
{
$rgb[ 2 ] = \intval( $objectData[ 'b' ] );
}
else if ( isset( $objectData[ 'blue' ] ) )
{
$rgb[ 2 ] = \intval( $objectData[ 'blue' ] );
}
else if ( isset( $objectData[ 'Blue' ] ) )
{
$rgb[ 2 ] = \intval( $objectData[ 'Blue' ] );
}
else
{
return new Color();
}
if ( false !== ( $hex = ColorTool::Rgb2Hex( $rgb ) ) )
{
return new Color( $hex );
}
return new Color();
} | [
"public",
"static",
"function",
"FromArray",
"(",
"array",
"$",
"objectData",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"objectData",
")",
"==",
"3",
")",
"{",
"if",
"(",
"false",
"!==",
"(",
"$",
"hex",
"=",
"ColorTool",
"::",
"Color2Hex",
"(",
"$",
"objectData",
")",
")",
")",
"{",
"return",
"new",
"Color",
"(",
"$",
"hex",
")",
";",
"}",
"}",
"$",
"rgb",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'r'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"0",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'r'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'red'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"0",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'red'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'Red'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"0",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'Red'",
"]",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Color",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'g'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"1",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'g'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'green'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"1",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'green'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'Green'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"1",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'Green'",
"]",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Color",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'b'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"2",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'b'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'blue'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"2",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'blue'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'Blue'",
"]",
")",
")",
"{",
"$",
"rgb",
"[",
"2",
"]",
"=",
"\\",
"intval",
"(",
"$",
"objectData",
"[",
"'Blue'",
"]",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Color",
"(",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"(",
"$",
"hex",
"=",
"ColorTool",
"::",
"Rgb2Hex",
"(",
"$",
"rgb",
")",
")",
")",
"{",
"return",
"new",
"Color",
"(",
"$",
"hex",
")",
";",
"}",
"return",
"new",
"Color",
"(",
")",
";",
"}"
] | Init a new instance from defined array.
@param array $objectData
@return \Beluga\Drawing\Color Or boolean FALSE | [
"Init",
"a",
"new",
"instance",
"from",
"defined",
"array",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Color.php#L730-L801 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Color.php | Color.FromGdValueWithAlpha | public static function FromGdValueWithAlpha( $gdValueWithAlpha )
{
$a = ( $gdValueWithAlpha >> 24 ) & 0xFF;
$r = ( $gdValueWithAlpha >> 16 ) & 0xFF;
$g = ( $gdValueWithAlpha >> 8 ) & 0xFF;
$b = $gdValueWithAlpha & 0xFF;
if ( $a == 0 )
{
$o = 0;
}
else if ( $a == 127 )
{
$o = 100;
}
else
{
$o = \intval( \floor( ( 100 * $a ) / 127 ) );
}
return new Color( array( $r, $g, $b ), $o );
} | php | public static function FromGdValueWithAlpha( $gdValueWithAlpha )
{
$a = ( $gdValueWithAlpha >> 24 ) & 0xFF;
$r = ( $gdValueWithAlpha >> 16 ) & 0xFF;
$g = ( $gdValueWithAlpha >> 8 ) & 0xFF;
$b = $gdValueWithAlpha & 0xFF;
if ( $a == 0 )
{
$o = 0;
}
else if ( $a == 127 )
{
$o = 100;
}
else
{
$o = \intval( \floor( ( 100 * $a ) / 127 ) );
}
return new Color( array( $r, $g, $b ), $o );
} | [
"public",
"static",
"function",
"FromGdValueWithAlpha",
"(",
"$",
"gdValueWithAlpha",
")",
"{",
"$",
"a",
"=",
"(",
"$",
"gdValueWithAlpha",
">>",
"24",
")",
"&",
"0xFF",
";",
"$",
"r",
"=",
"(",
"$",
"gdValueWithAlpha",
">>",
"16",
")",
"&",
"0xFF",
";",
"$",
"g",
"=",
"(",
"$",
"gdValueWithAlpha",
">>",
"8",
")",
"&",
"0xFF",
";",
"$",
"b",
"=",
"$",
"gdValueWithAlpha",
"&",
"0xFF",
";",
"if",
"(",
"$",
"a",
"==",
"0",
")",
"{",
"$",
"o",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"$",
"a",
"==",
"127",
")",
"{",
"$",
"o",
"=",
"100",
";",
"}",
"else",
"{",
"$",
"o",
"=",
"\\",
"intval",
"(",
"\\",
"floor",
"(",
"(",
"100",
"*",
"$",
"a",
")",
"/",
"127",
")",
")",
";",
"}",
"return",
"new",
"Color",
"(",
"array",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
",",
"$",
"o",
")",
";",
"}"
] | Converts a GD integer value as color with alpha channel to an \Beluga\Drawing\Color instance.
@param int $gdValueWithAlpha
@return \Beluga\Drawing\Color | [
"Converts",
"a",
"GD",
"integer",
"value",
"as",
"color",
"with",
"alpha",
"channel",
"to",
"an",
"\\",
"Beluga",
"\\",
"Drawing",
"\\",
"Color",
"instance",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Color.php#L809-L832 | train |
Dhii/config | src/GetDataCapableByPathTrait.php | GetDataCapableByPathTrait._getData | protected function _getData($key)
{
$separator = $this->_getPathSegmentSeparator();
$path = $this->_normalizePath($key, $separator);
$store = $this->_getDataStore();
return $this->_containerGetPath($store, $path);
} | php | protected function _getData($key)
{
$separator = $this->_getPathSegmentSeparator();
$path = $this->_normalizePath($key, $separator);
$store = $this->_getDataStore();
return $this->_containerGetPath($store, $path);
} | [
"protected",
"function",
"_getData",
"(",
"$",
"key",
")",
"{",
"$",
"separator",
"=",
"$",
"this",
"->",
"_getPathSegmentSeparator",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"_normalizePath",
"(",
"$",
"key",
",",
"$",
"separator",
")",
";",
"$",
"store",
"=",
"$",
"this",
"->",
"_getDataStore",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_containerGetPath",
"(",
"$",
"store",
",",
"$",
"path",
")",
";",
"}"
] | Retrieves the data associated with the specified key or path.
Will traverse the hierarchy of containers identified by the path segments.
@since [*next-version*]
@param string|Stringable $key The key or list of keys in the path to get the data for.
@return mixed The data corresponding to the path. | [
"Retrieves",
"the",
"data",
"associated",
"with",
"the",
"specified",
"key",
"or",
"path",
"."
] | 1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf | https://github.com/Dhii/config/blob/1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf/src/GetDataCapableByPathTrait.php#L32-L39 | train |
SlabPHP/bundle-stack | src/Stack.php | Stack.findClassName | public function findClassName($className)
{
if (!empty($this->lookupCache->classes[$className])) {
return $this->lookupCache->classes[$className];
}
if (class_exists($className)) return $className;
$startsWithSlash = ($className[0] == '\\');
foreach ($this->searchOrder as $namespace)
{
$testClass = '\\' . $namespace;
if (!$startsWithSlash) {
$testClass .= '\\';
}
$testClass .= $className;
if (class_exists($testClass)) {
$this->lookupCache->classes[$className] = $testClass;
return $testClass;
}
}
return null;
} | php | public function findClassName($className)
{
if (!empty($this->lookupCache->classes[$className])) {
return $this->lookupCache->classes[$className];
}
if (class_exists($className)) return $className;
$startsWithSlash = ($className[0] == '\\');
foreach ($this->searchOrder as $namespace)
{
$testClass = '\\' . $namespace;
if (!$startsWithSlash) {
$testClass .= '\\';
}
$testClass .= $className;
if (class_exists($testClass)) {
$this->lookupCache->classes[$className] = $testClass;
return $testClass;
}
}
return null;
} | [
"public",
"function",
"findClassName",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"lookupCache",
"->",
"classes",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"lookupCache",
"->",
"classes",
"[",
"$",
"className",
"]",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"className",
")",
")",
"return",
"$",
"className",
";",
"$",
"startsWithSlash",
"=",
"(",
"$",
"className",
"[",
"0",
"]",
"==",
"'\\\\'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"searchOrder",
"as",
"$",
"namespace",
")",
"{",
"$",
"testClass",
"=",
"'\\\\'",
".",
"$",
"namespace",
";",
"if",
"(",
"!",
"$",
"startsWithSlash",
")",
"{",
"$",
"testClass",
".=",
"'\\\\'",
";",
"}",
"$",
"testClass",
".=",
"$",
"className",
";",
"if",
"(",
"class_exists",
"(",
"$",
"testClass",
")",
")",
"{",
"$",
"this",
"->",
"lookupCache",
"->",
"classes",
"[",
"$",
"className",
"]",
"=",
"$",
"testClass",
";",
"return",
"$",
"testClass",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Find class name
@param $className
@return null|string | [
"Find",
"class",
"name"
] | d96c4de469e58040968044d2d6525cb60d9dd8c6 | https://github.com/SlabPHP/bundle-stack/blob/d96c4de469e58040968044d2d6525cb60d9dd8c6/src/Stack.php#L79-L104 | train |
jenskooij/cloudcontrol | src/util/StringUtil.php | StringUtil.slugify | public static function slugify($str, $replace = array(), $delimiter = '-')
{
if (!empty($replace)) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
} | php | public static function slugify($str, $replace = array(), $delimiter = '-')
{
if (!empty($replace)) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
} | [
"public",
"static",
"function",
"slugify",
"(",
"$",
"str",
",",
"$",
"replace",
"=",
"array",
"(",
")",
",",
"$",
"delimiter",
"=",
"'-'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"replace",
")",
")",
"{",
"$",
"str",
"=",
"str_replace",
"(",
"(",
"array",
")",
"$",
"replace",
",",
"' '",
",",
"$",
"str",
")",
";",
"}",
"$",
"clean",
"=",
"iconv",
"(",
"'UTF-8'",
",",
"'ASCII//TRANSLIT//IGNORE'",
",",
"$",
"str",
")",
";",
"$",
"clean",
"=",
"preg_replace",
"(",
"\"/[^a-zA-Z0-9\\/_|+ -]/\"",
",",
"''",
",",
"$",
"clean",
")",
";",
"$",
"clean",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"clean",
",",
"'-'",
")",
")",
";",
"$",
"clean",
"=",
"preg_replace",
"(",
"\"/[\\/_|+ -]+/\"",
",",
"$",
"delimiter",
",",
"$",
"clean",
")",
";",
"return",
"$",
"clean",
";",
"}"
] | Convert a string to url friendly slug
@param string $str
@param array $replace
@param string $delimiter
@return mixed|string | [
"Convert",
"a",
"string",
"to",
"url",
"friendly",
"slug"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/util/StringUtil.php#L38-L50 | train |
jenskooij/cloudcontrol | src/util/StringUtil.php | StringUtil.iconByFileType | public static function iconByFileType($fileType)
{
foreach (self::$fileTypeIcons as $needle => $icon) {
if (strpos($fileType, $needle) !== false) {
return $icon;
}
}
return 'file-o';
} | php | public static function iconByFileType($fileType)
{
foreach (self::$fileTypeIcons as $needle => $icon) {
if (strpos($fileType, $needle) !== false) {
return $icon;
}
}
return 'file-o';
} | [
"public",
"static",
"function",
"iconByFileType",
"(",
"$",
"fileType",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"fileTypeIcons",
"as",
"$",
"needle",
"=>",
"$",
"icon",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"fileType",
",",
"$",
"needle",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"icon",
";",
"}",
"}",
"return",
"'file-o'",
";",
"}"
] | Selects the right font-awesome icon for each filetype
@param $fileType
@return string | [
"Selects",
"the",
"right",
"font",
"-",
"awesome",
"icon",
"for",
"each",
"filetype"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/util/StringUtil.php#L59-L70 | train |
jenskooij/cloudcontrol | src/util/StringUtil.php | StringUtil.humanFileSize | public static function humanFileSize($size, $unit = '')
{
if (self::isHumanFilesizeUnitGb($size, $unit)) {
return number_format($size / (1 << 30), 2) . 'GB';
}
if (self::isHumanFilesizeUnitMb($size, $unit)) {
return number_format($size / (1 << 20), 2) . 'MB';
}
if (self::isHumanFilesizeUnitKb($size, $unit)) {
return number_format($size / (1 << 10), 2) . 'KB';
}
return number_format($size) . ' bytes';
} | php | public static function humanFileSize($size, $unit = '')
{
if (self::isHumanFilesizeUnitGb($size, $unit)) {
return number_format($size / (1 << 30), 2) . 'GB';
}
if (self::isHumanFilesizeUnitMb($size, $unit)) {
return number_format($size / (1 << 20), 2) . 'MB';
}
if (self::isHumanFilesizeUnitKb($size, $unit)) {
return number_format($size / (1 << 10), 2) . 'KB';
}
return number_format($size) . ' bytes';
} | [
"public",
"static",
"function",
"humanFileSize",
"(",
"$",
"size",
",",
"$",
"unit",
"=",
"''",
")",
"{",
"if",
"(",
"self",
"::",
"isHumanFilesizeUnitGb",
"(",
"$",
"size",
",",
"$",
"unit",
")",
")",
"{",
"return",
"number_format",
"(",
"$",
"size",
"/",
"(",
"1",
"<<",
"30",
")",
",",
"2",
")",
".",
"'GB'",
";",
"}",
"if",
"(",
"self",
"::",
"isHumanFilesizeUnitMb",
"(",
"$",
"size",
",",
"$",
"unit",
")",
")",
"{",
"return",
"number_format",
"(",
"$",
"size",
"/",
"(",
"1",
"<<",
"20",
")",
",",
"2",
")",
".",
"'MB'",
";",
"}",
"if",
"(",
"self",
"::",
"isHumanFilesizeUnitKb",
"(",
"$",
"size",
",",
"$",
"unit",
")",
")",
"{",
"return",
"number_format",
"(",
"$",
"size",
"/",
"(",
"1",
"<<",
"10",
")",
",",
"2",
")",
".",
"'KB'",
";",
"}",
"return",
"number_format",
"(",
"$",
"size",
")",
".",
"' bytes'",
";",
"}"
] | Converts an amount of bytes to a human readable
format
@param $size
@param string $unit
@return string | [
"Converts",
"an",
"amount",
"of",
"bytes",
"to",
"a",
"human",
"readable",
"format"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/util/StringUtil.php#L81-L94 | train |
native5/native5-sdk-client-php | src/Native5/UI/TemplatingEngine.php | TemplatingEngine.render | protected function render($tmpl, $in_data=array()) {
try {
$data = array();
$app = array();
$app['content'] = $in_data;
$app['settings'] = $this->_viewData['settings'];
$data['app'] = $app;
$data['global'] = array('styles'=>$this->_viewData['styles']);
$data['device'] = $this->_viewData['device'];
return $this->_renderer->render($tmpl, $data);
} catch (\Exception $e) {
return 'Issues with data, cannot be rendered';
}//end try
} | php | protected function render($tmpl, $in_data=array()) {
try {
$data = array();
$app = array();
$app['content'] = $in_data;
$app['settings'] = $this->_viewData['settings'];
$data['app'] = $app;
$data['global'] = array('styles'=>$this->_viewData['styles']);
$data['device'] = $this->_viewData['device'];
return $this->_renderer->render($tmpl, $data);
} catch (\Exception $e) {
return 'Issues with data, cannot be rendered';
}//end try
} | [
"protected",
"function",
"render",
"(",
"$",
"tmpl",
",",
"$",
"in_data",
"=",
"array",
"(",
")",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"app",
"=",
"array",
"(",
")",
";",
"$",
"app",
"[",
"'content'",
"]",
"=",
"$",
"in_data",
";",
"$",
"app",
"[",
"'settings'",
"]",
"=",
"$",
"this",
"->",
"_viewData",
"[",
"'settings'",
"]",
";",
"$",
"data",
"[",
"'app'",
"]",
"=",
"$",
"app",
";",
"$",
"data",
"[",
"'global'",
"]",
"=",
"array",
"(",
"'styles'",
"=>",
"$",
"this",
"->",
"_viewData",
"[",
"'styles'",
"]",
")",
";",
"$",
"data",
"[",
"'device'",
"]",
"=",
"$",
"this",
"->",
"_viewData",
"[",
"'device'",
"]",
";",
"return",
"$",
"this",
"->",
"_renderer",
"->",
"render",
"(",
"$",
"tmpl",
",",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"'Issues with data, cannot be rendered'",
";",
"}",
"//end try",
"}"
] | Renders a given template along with input data.
@param mixed $tmpl The template to render.
@param mixed $in_data The data to render with.
@access protected
@return void | [
"Renders",
"a",
"given",
"template",
"along",
"with",
"input",
"data",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/UI/TemplatingEngine.php#L148-L164 | train |
ARCANESOFT/Media | src/MediaServiceProvider.php | MediaServiceProvider.syncFilesystemConfig | private function syncFilesystemConfig()
{
foreach ($this->config()->get('arcanesoft.media.filesystem.disks', []) as $disk => $config) {
$this->config()->set("filesystems.disks.$disk", $config);
}
} | php | private function syncFilesystemConfig()
{
foreach ($this->config()->get('arcanesoft.media.filesystem.disks', []) as $disk => $config) {
$this->config()->set("filesystems.disks.$disk", $config);
}
} | [
"private",
"function",
"syncFilesystemConfig",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'arcanesoft.media.filesystem.disks'",
",",
"[",
"]",
")",
"as",
"$",
"disk",
"=>",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"set",
"(",
"\"filesystems.disks.$disk\"",
",",
"$",
"config",
")",
";",
"}",
"}"
] | Sync the filesystem config. | [
"Sync",
"the",
"filesystem",
"config",
"."
] | e98aad52f94e6587fcbf79c56f7bf7072929bfc9 | https://github.com/ARCANESOFT/Media/blob/e98aad52f94e6587fcbf79c56f7bf7072929bfc9/src/MediaServiceProvider.php#L84-L89 | train |
theopera/framework | src/Component/Template/PhpEngine.php | PhpEngine.loadFile | public function loadFile(string $file)
{
$path = $this->basePath . '/' . $file . '.phtml';
if (!is_readable($path)) {
throw new TemplateException(sprintf('Template engine could not read the file "%s"', $path));
};
if (($this->contents = file_get_contents($path)) === false) {
throw new TemplateException(sprintf('File "%s" not readable', $path));
}
} | php | public function loadFile(string $file)
{
$path = $this->basePath . '/' . $file . '.phtml';
if (!is_readable($path)) {
throw new TemplateException(sprintf('Template engine could not read the file "%s"', $path));
};
if (($this->contents = file_get_contents($path)) === false) {
throw new TemplateException(sprintf('File "%s" not readable', $path));
}
} | [
"public",
"function",
"loadFile",
"(",
"string",
"$",
"file",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"basePath",
".",
"'/'",
".",
"$",
"file",
".",
"'.phtml'",
";",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"TemplateException",
"(",
"sprintf",
"(",
"'Template engine could not read the file \"%s\"'",
",",
"$",
"path",
")",
")",
";",
"}",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"contents",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"TemplateException",
"(",
"sprintf",
"(",
"'File \"%s\" not readable'",
",",
"$",
"path",
")",
")",
";",
"}",
"}"
] | Loads a template file into memory
@param string $file
@return mixed | [
"Loads",
"a",
"template",
"file",
"into",
"memory"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Template/PhpEngine.php#L55-L66 | train |
chalasr/RCHCapistranoBundle | Generator/CapfileGenerator.php | CapfileGenerator.write | public function write()
{
$capfile = '';
foreach ($this->parameters as $namespace) {
$line = str_replace('<requirement>', $namespace, self::$template);
$capfile = sprintf('%s%s%s', $capfile, PHP_EOL, $line);
}
$capfile .= self::$importTemplate;
fwrite($this->file, $this->addHeaders($capfile));
} | php | public function write()
{
$capfile = '';
foreach ($this->parameters as $namespace) {
$line = str_replace('<requirement>', $namespace, self::$template);
$capfile = sprintf('%s%s%s', $capfile, PHP_EOL, $line);
}
$capfile .= self::$importTemplate;
fwrite($this->file, $this->addHeaders($capfile));
} | [
"public",
"function",
"write",
"(",
")",
"{",
"$",
"capfile",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"parameters",
"as",
"$",
"namespace",
")",
"{",
"$",
"line",
"=",
"str_replace",
"(",
"'<requirement>'",
",",
"$",
"namespace",
",",
"self",
"::",
"$",
"template",
")",
";",
"$",
"capfile",
"=",
"sprintf",
"(",
"'%s%s%s'",
",",
"$",
"capfile",
",",
"PHP_EOL",
",",
"$",
"line",
")",
";",
"}",
"$",
"capfile",
".=",
"self",
"::",
"$",
"importTemplate",
";",
"fwrite",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"addHeaders",
"(",
"$",
"capfile",
")",
")",
";",
"}"
] | Writes Capfile. | [
"Writes",
"Capfile",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Generator/CapfileGenerator.php#L49-L61 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Cookie/SetCookie.php | SetCookie.fromString | public static function fromString($cookie)
{
// Create the default return array
$data = self::$defaults;
// Explode the cookie string using a series of semicolons
$pieces = array_filter(array_map('trim', explode(';', $cookie)));
// The name of the cookie (first kvp) must include an equal sign.
if (empty($pieces) || !strpos($pieces[0], '=')) {
return new self($data);
}
// Add the cookie pieces into the parsed data array
foreach ($pieces as $part) {
$cookieParts = explode('=', $part, 2);
$key = trim($cookieParts[0]);
$value = isset($cookieParts[1])
? trim($cookieParts[1], " \n\r\t\0\x0B\"")
: true;
// Only check for non-cookies when cookies have been found
if (empty($data['Name'])) {
$data['Name'] = $key;
$data['Value'] = $value;
} else {
foreach (array_keys(self::$defaults) as $search) {
if (!strcasecmp($search, $key)) {
$data[$search] = $value;
continue 2;
}
}
$data[$key] = $value;
}
}
return new self($data);
} | php | public static function fromString($cookie)
{
// Create the default return array
$data = self::$defaults;
// Explode the cookie string using a series of semicolons
$pieces = array_filter(array_map('trim', explode(';', $cookie)));
// The name of the cookie (first kvp) must include an equal sign.
if (empty($pieces) || !strpos($pieces[0], '=')) {
return new self($data);
}
// Add the cookie pieces into the parsed data array
foreach ($pieces as $part) {
$cookieParts = explode('=', $part, 2);
$key = trim($cookieParts[0]);
$value = isset($cookieParts[1])
? trim($cookieParts[1], " \n\r\t\0\x0B\"")
: true;
// Only check for non-cookies when cookies have been found
if (empty($data['Name'])) {
$data['Name'] = $key;
$data['Value'] = $value;
} else {
foreach (array_keys(self::$defaults) as $search) {
if (!strcasecmp($search, $key)) {
$data[$search] = $value;
continue 2;
}
}
$data[$key] = $value;
}
}
return new self($data);
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"cookie",
")",
"{",
"// Create the default return array",
"$",
"data",
"=",
"self",
"::",
"$",
"defaults",
";",
"// Explode the cookie string using a series of semicolons",
"$",
"pieces",
"=",
"array_filter",
"(",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"';'",
",",
"$",
"cookie",
")",
")",
")",
";",
"// The name of the cookie (first kvp) must include an equal sign.",
"if",
"(",
"empty",
"(",
"$",
"pieces",
")",
"||",
"!",
"strpos",
"(",
"$",
"pieces",
"[",
"0",
"]",
",",
"'='",
")",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"data",
")",
";",
"}",
"// Add the cookie pieces into the parsed data array",
"foreach",
"(",
"$",
"pieces",
"as",
"$",
"part",
")",
"{",
"$",
"cookieParts",
"=",
"explode",
"(",
"'='",
",",
"$",
"part",
",",
"2",
")",
";",
"$",
"key",
"=",
"trim",
"(",
"$",
"cookieParts",
"[",
"0",
"]",
")",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"cookieParts",
"[",
"1",
"]",
")",
"?",
"trim",
"(",
"$",
"cookieParts",
"[",
"1",
"]",
",",
"\" \\n\\r\\t\\0\\x0B\\\"\"",
")",
":",
"true",
";",
"// Only check for non-cookies when cookies have been found",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'Name'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'Name'",
"]",
"=",
"$",
"key",
";",
"$",
"data",
"[",
"'Value'",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"foreach",
"(",
"array_keys",
"(",
"self",
"::",
"$",
"defaults",
")",
"as",
"$",
"search",
")",
"{",
"if",
"(",
"!",
"strcasecmp",
"(",
"$",
"search",
",",
"$",
"key",
")",
")",
"{",
"$",
"data",
"[",
"$",
"search",
"]",
"=",
"$",
"value",
";",
"continue",
"2",
";",
"}",
"}",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"new",
"self",
"(",
"$",
"data",
")",
";",
"}"
] | Create a new SetCookie object from a string
@param string $cookie Set-Cookie header string
@return self | [
"Create",
"a",
"new",
"SetCookie",
"object",
"from",
"a",
"string"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Cookie/SetCookie.php#L35-L71 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Cookie/SetCookie.php | SetCookie.setExpires | public function setExpires($timestamp)
{
$this->data['Expires'] = is_numeric($timestamp)
? (int) $timestamp
: strtotime($timestamp);
return $this;
} | php | public function setExpires($timestamp)
{
$this->data['Expires'] = is_numeric($timestamp)
? (int) $timestamp
: strtotime($timestamp);
return $this;
} | [
"public",
"function",
"setExpires",
"(",
"$",
"timestamp",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"'Expires'",
"]",
"=",
"is_numeric",
"(",
"$",
"timestamp",
")",
"?",
"(",
"int",
")",
"$",
"timestamp",
":",
"strtotime",
"(",
"$",
"timestamp",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the unix timestamp for which the cookie will expire
@param int $timestamp Unix timestamp
@return self | [
"Set",
"the",
"unix",
"timestamp",
"for",
"which",
"the",
"cookie",
"will",
"expire"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Cookie/SetCookie.php#L246-L253 | train |
Kris-Kuiper/sFire-Framework | src/Image/Image.php | Image.setImage | public function setImage($file) {
if(false === is_string($file)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($file)), E_USER_ERROR);
}
if(false === is_file($file)) {
return trigger_error(sprintf('File "%s" passed to %s() does not exists', $file, __METHOD__), E_USER_ERROR);
}
if(false === is_readable($file)) {
return trigger_error(sprintf('File "%s" passed to %s() is not readable', $file, __METHOD__), E_USER_ERROR);
}
$info = @getimagesize($file);
if(false === is_array($info) || count($info) < 3) {
return trigger_error(sprintf('File "%s" passed to %s() is not an image', $file, __METHOD__), E_USER_ERROR);
}
$this -> image = @imagecreatefromstring(file_get_contents($file));
$this -> extension = pathinfo($file, PATHINFO_EXTENSION);
return $this;
} | php | public function setImage($file) {
if(false === is_string($file)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($file)), E_USER_ERROR);
}
if(false === is_file($file)) {
return trigger_error(sprintf('File "%s" passed to %s() does not exists', $file, __METHOD__), E_USER_ERROR);
}
if(false === is_readable($file)) {
return trigger_error(sprintf('File "%s" passed to %s() is not readable', $file, __METHOD__), E_USER_ERROR);
}
$info = @getimagesize($file);
if(false === is_array($info) || count($info) < 3) {
return trigger_error(sprintf('File "%s" passed to %s() is not an image', $file, __METHOD__), E_USER_ERROR);
}
$this -> image = @imagecreatefromstring(file_get_contents($file));
$this -> extension = pathinfo($file, PATHINFO_EXTENSION);
return $this;
} | [
"public",
"function",
"setImage",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"file",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"file",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'File \"%s\" passed to %s() does not exists'",
",",
"$",
"file",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'File \"%s\" passed to %s() is not readable'",
",",
"$",
"file",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"info",
"=",
"@",
"getimagesize",
"(",
"$",
"file",
")",
";",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"info",
")",
"||",
"count",
"(",
"$",
"info",
")",
"<",
"3",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'File \"%s\" passed to %s() is not an image'",
",",
"$",
"file",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"image",
"=",
"@",
"imagecreatefromstring",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"$",
"this",
"->",
"extension",
"=",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set a new image
@param string $image
@return sFire\Image\Image | [
"Set",
"a",
"new",
"image"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Image.php#L94-L118 | train |
Kris-Kuiper/sFire-Framework | src/Image/Image.php | Image.flip | public function flip($mode = self :: FLIP_HORIZONTAL) {
if(false === in_array($mode, [self :: FLIP_HORIZONTAL, self :: FLIP_VERTICAL, self :: FLIP_BOTH])) {
return trigger_error(sprintf('Unknown mode passed %s(), "%s" given', __METHOD__, gettype($mode)), E_USER_ERROR);
}
$this -> add(__FUNCTION__, func_get_args());
return $this;
} | php | public function flip($mode = self :: FLIP_HORIZONTAL) {
if(false === in_array($mode, [self :: FLIP_HORIZONTAL, self :: FLIP_VERTICAL, self :: FLIP_BOTH])) {
return trigger_error(sprintf('Unknown mode passed %s(), "%s" given', __METHOD__, gettype($mode)), E_USER_ERROR);
}
$this -> add(__FUNCTION__, func_get_args());
return $this;
} | [
"public",
"function",
"flip",
"(",
"$",
"mode",
"=",
"self",
"::",
"FLIP_HORIZONTAL",
")",
"{",
"if",
"(",
"false",
"===",
"in_array",
"(",
"$",
"mode",
",",
"[",
"self",
"::",
"FLIP_HORIZONTAL",
",",
"self",
"::",
"FLIP_VERTICAL",
",",
"self",
"::",
"FLIP_BOTH",
"]",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Unknown mode passed %s(), \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"mode",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"add",
"(",
"__FUNCTION__",
",",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Flip the current image horizontal, vertical or both
@param int $mode
@return sFire\Image\Image | [
"Flip",
"the",
"current",
"image",
"horizontal",
"vertical",
"or",
"both"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Image.php#L340-L348 | train |
Kris-Kuiper/sFire-Framework | src/Image/Image.php | Image.call | private function call() {
if(null === $this -> driver) {
return trigger_error('Driver is not set. Set the driver with the setDriver() method', E_USER_ERROR);
}
if(null === $this -> image) {
return trigger_error('Image has not been set. Set the image with the setImage() method', E_USER_ERROR);
}
if(null === $this -> driverInstance) {
$this -> driverInstance = new $this -> driver($this -> image);
}
return $this -> driverInstance;
} | php | private function call() {
if(null === $this -> driver) {
return trigger_error('Driver is not set. Set the driver with the setDriver() method', E_USER_ERROR);
}
if(null === $this -> image) {
return trigger_error('Image has not been set. Set the image with the setImage() method', E_USER_ERROR);
}
if(null === $this -> driverInstance) {
$this -> driverInstance = new $this -> driver($this -> image);
}
return $this -> driverInstance;
} | [
"private",
"function",
"call",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"driver",
")",
"{",
"return",
"trigger_error",
"(",
"'Driver is not set. Set the driver with the setDriver() method'",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"image",
")",
"{",
"return",
"trigger_error",
"(",
"'Image has not been set. Set the image with the setImage() method'",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"driverInstance",
")",
"{",
"$",
"this",
"->",
"driverInstance",
"=",
"new",
"$",
"this",
"->",
"driver",
"(",
"$",
"this",
"->",
"image",
")",
";",
"}",
"return",
"$",
"this",
"->",
"driverInstance",
";",
"}"
] | Check if image and driver is set and returns the driver
@return mixed | [
"Check",
"if",
"image",
"and",
"driver",
"is",
"set",
"and",
"returns",
"the",
"driver"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Image.php#L458-L473 | train |
Kris-Kuiper/sFire-Framework | src/Image/Image.php | Image.getQuality | private function getQuality($quality, $extension) {
if(false === ('-' . intval($quality) == '-' . $quality)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($quality)), E_USER_ERROR);
}
if(false === is_string($extension)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($extension)), E_USER_ERROR);
}
if(strtolower($extension) === 'png' && $quality > 9) {
$quality = floor(($quality - 1) / 10);
}
return $quality;
} | php | private function getQuality($quality, $extension) {
if(false === ('-' . intval($quality) == '-' . $quality)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($quality)), E_USER_ERROR);
}
if(false === is_string($extension)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($extension)), E_USER_ERROR);
}
if(strtolower($extension) === 'png' && $quality > 9) {
$quality = floor(($quality - 1) / 10);
}
return $quality;
} | [
"private",
"function",
"getQuality",
"(",
"$",
"quality",
",",
"$",
"extension",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"quality",
")",
"==",
"'-'",
".",
"$",
"quality",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"quality",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"extension",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"extension",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"strtolower",
"(",
"$",
"extension",
")",
"===",
"'png'",
"&&",
"$",
"quality",
">",
"9",
")",
"{",
"$",
"quality",
"=",
"floor",
"(",
"(",
"$",
"quality",
"-",
"1",
")",
"/",
"10",
")",
";",
"}",
"return",
"$",
"quality",
";",
"}"
] | Validates and returns quality based on image extension
@param int $quality
@param string $extension
@return int | [
"Validates",
"and",
"returns",
"quality",
"based",
"on",
"image",
"extension"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Image.php#L482-L497 | train |
ndavison/groundwork-framework | src/Groundwork/Classes/Resource.php | Resource.output | public function output()
{
// Check that the method for this HTTP request method exists.
$methodName = 'http_' . $this->request->httpMethod();
if (method_exists($this, $methodName)) {
// Execute the requested Resource instance's method that
// corresponds with the requested HTTP method.
return $this->$methodName();
} else {
// The Resource instance didn't define a method for the request's
// HTTP method - return a 405.
return $this->response->send(
405,
'The requested resource does not support the HTTP method'.
' "' . $this->request->httpMethod() . '".'
);
}
} | php | public function output()
{
// Check that the method for this HTTP request method exists.
$methodName = 'http_' . $this->request->httpMethod();
if (method_exists($this, $methodName)) {
// Execute the requested Resource instance's method that
// corresponds with the requested HTTP method.
return $this->$methodName();
} else {
// The Resource instance didn't define a method for the request's
// HTTP method - return a 405.
return $this->response->send(
405,
'The requested resource does not support the HTTP method'.
' "' . $this->request->httpMethod() . '".'
);
}
} | [
"public",
"function",
"output",
"(",
")",
"{",
"// Check that the method for this HTTP request method exists.",
"$",
"methodName",
"=",
"'http_'",
".",
"$",
"this",
"->",
"request",
"->",
"httpMethod",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
")",
"{",
"// Execute the requested Resource instance's method that ",
"// corresponds with the requested HTTP method.",
"return",
"$",
"this",
"->",
"$",
"methodName",
"(",
")",
";",
"}",
"else",
"{",
"// The Resource instance didn't define a method for the request's ",
"// HTTP method - return a 405.",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"405",
",",
"'The requested resource does not support the HTTP method'",
".",
"' \"'",
".",
"$",
"this",
"->",
"request",
"->",
"httpMethod",
"(",
")",
".",
"'\".'",
")",
";",
"}",
"}"
] | Generate the output of the requested Resource instance.
@return mixed | [
"Generate",
"the",
"output",
"of",
"the",
"requested",
"Resource",
"instance",
"."
] | c3d22a1410c8d8a07b4ca1f99a35a1181516cd6c | https://github.com/ndavison/groundwork-framework/blob/c3d22a1410c8d8a07b4ca1f99a35a1181516cd6c/src/Groundwork/Classes/Resource.php#L53-L70 | train |
brightnucleus/options-store | src/Exception/InvalidOption.php | InvalidOption.fromOption | public static function fromOption($option)
{
$message = sprintf(
'Could not add invalid Option of type "%1$s" to option repository.',
is_object($option)
? get_class($option)
: gettype($option)
);
return new static($message);
} | php | public static function fromOption($option)
{
$message = sprintf(
'Could not add invalid Option of type "%1$s" to option repository.',
is_object($option)
? get_class($option)
: gettype($option)
);
return new static($message);
} | [
"public",
"static",
"function",
"fromOption",
"(",
"$",
"option",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Could not add invalid Option of type \"%1$s\" to option repository.'",
",",
"is_object",
"(",
"$",
"option",
")",
"?",
"get_class",
"(",
"$",
"option",
")",
":",
"gettype",
"(",
"$",
"option",
")",
")",
";",
"return",
"new",
"static",
"(",
"$",
"message",
")",
";",
"}"
] | Get a new exception based on the type of an invalid option.
@since 0.1.0
@param mixed $option Option that was tried to be added.
@return static | [
"Get",
"a",
"new",
"exception",
"based",
"on",
"the",
"type",
"of",
"an",
"invalid",
"option",
"."
] | 9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1 | https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/Exception/InvalidOption.php#L40-L50 | train |
EdwinDayot/shorty-framework | src/Framework/Routing/Controller.php | Controller.middleware | public function middleware($name)
{
if (is_string($name)) {
app()->addRouteMiddleware($name);
} else if (is_array($name)) {
foreach ($name as $middlewareName) {
app()->addRouteMiddleware($middlewareName);
}
}
} | php | public function middleware($name)
{
if (is_string($name)) {
app()->addRouteMiddleware($name);
} else if (is_array($name)) {
foreach ($name as $middlewareName) {
app()->addRouteMiddleware($middlewareName);
}
}
} | [
"public",
"function",
"middleware",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"app",
"(",
")",
"->",
"addRouteMiddleware",
"(",
"$",
"name",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"$",
"middlewareName",
")",
"{",
"app",
"(",
")",
"->",
"addRouteMiddleware",
"(",
"$",
"middlewareName",
")",
";",
"}",
"}",
"}"
] | Middlewares to add.
@param string|string[] $name | [
"Middlewares",
"to",
"add",
"."
] | e03c991ea86aedbd87674d1ee2f9041b55b5e578 | https://github.com/EdwinDayot/shorty-framework/blob/e03c991ea86aedbd87674d1ee2f9041b55b5e578/src/Framework/Routing/Controller.php#L20-L29 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Normalizer/MajoraNormalizer.php | MajoraNormalizer.createNormalizer | public static function createNormalizer($key = 'default')
{
return isset(self::$instancePool[$key]) ?
self::$instancePool[$key] :
self::$instancePool[$key] = new static(
PropertyAccess::createPropertyAccessor()
);
} | php | public static function createNormalizer($key = 'default')
{
return isset(self::$instancePool[$key]) ?
self::$instancePool[$key] :
self::$instancePool[$key] = new static(
PropertyAccess::createPropertyAccessor()
);
} | [
"public",
"static",
"function",
"createNormalizer",
"(",
"$",
"key",
"=",
"'default'",
")",
"{",
"return",
"isset",
"(",
"self",
"::",
"$",
"instancePool",
"[",
"$",
"key",
"]",
")",
"?",
"self",
"::",
"$",
"instancePool",
"[",
"$",
"key",
"]",
":",
"self",
"::",
"$",
"instancePool",
"[",
"$",
"key",
"]",
"=",
"new",
"static",
"(",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
")",
";",
"}"
] | Create and return an instantiated normalizer, returns always the same throught this call.
@param string $key optionnal normalizer key
@return MajoraNormalizer | [
"Create",
"and",
"return",
"an",
"instantiated",
"normalizer",
"returns",
"always",
"the",
"same",
"throught",
"this",
"call",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Normalizer/MajoraNormalizer.php#L69-L76 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Normalizer/MajoraNormalizer.php | MajoraNormalizer.createReadingDelegate | private function createReadingDelegate()
{
return $this->readDelegate ?: $this->readDelegate = function ($property, PropertyAccessor $propertyAccessor) {
switch (true) {
// Public property / accessor case
case $propertyAccessor->isReadable($this, $property) :
return $propertyAccessor->getValue($this, $property);
// Private property / StdClass
case property_exists($this, $property) || $this instanceof \StdClass:
return $this->$property;
}
throw new InvalidScopeException(sprintf(
'Unable to read "%s" property from a "%s" object, any existing property path to read it in.',
$property,
get_class($this)
));
};
} | php | private function createReadingDelegate()
{
return $this->readDelegate ?: $this->readDelegate = function ($property, PropertyAccessor $propertyAccessor) {
switch (true) {
// Public property / accessor case
case $propertyAccessor->isReadable($this, $property) :
return $propertyAccessor->getValue($this, $property);
// Private property / StdClass
case property_exists($this, $property) || $this instanceof \StdClass:
return $this->$property;
}
throw new InvalidScopeException(sprintf(
'Unable to read "%s" property from a "%s" object, any existing property path to read it in.',
$property,
get_class($this)
));
};
} | [
"private",
"function",
"createReadingDelegate",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"readDelegate",
"?",
":",
"$",
"this",
"->",
"readDelegate",
"=",
"function",
"(",
"$",
"property",
",",
"PropertyAccessor",
"$",
"propertyAccessor",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"// Public property / accessor case",
"case",
"$",
"propertyAccessor",
"->",
"isReadable",
"(",
"$",
"this",
",",
"$",
"property",
")",
":",
"return",
"$",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"this",
",",
"$",
"property",
")",
";",
"// Private property / StdClass",
"case",
"property_exists",
"(",
"$",
"this",
",",
"$",
"property",
")",
"||",
"$",
"this",
"instanceof",
"\\",
"StdClass",
":",
"return",
"$",
"this",
"->",
"$",
"property",
";",
"}",
"throw",
"new",
"InvalidScopeException",
"(",
"sprintf",
"(",
"'Unable to read \"%s\" property from a \"%s\" object, any existing property path to read it in.'",
",",
"$",
"property",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
";",
"}"
] | Create and return a Closure available to read an object property through a property path or a private property.
@return \Closure | [
"Create",
"and",
"return",
"a",
"Closure",
"available",
"to",
"read",
"an",
"object",
"property",
"through",
"a",
"property",
"path",
"or",
"a",
"private",
"property",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Normalizer/MajoraNormalizer.php#L107-L127 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Normalizer/MajoraNormalizer.php | MajoraNormalizer.normalize | public function normalize($object, $scope = 'default')
{
switch (true) {
// Cannot normalized anything which already are
case !is_object($object) :
return $object;
// StdClass can be cast as array
case $object instanceof StdClass :
return (array) $object;
// DateTime : ISO format
case $object instanceof \DateTime:
return $object->format(\DateTime::ISO8601);
// Other objects : we use a closure hack to read data
case !$object instanceof NormalizableInterface :
$extractor = \Closure::bind($this->createExtractorDelegate(), $object, get_class($object));
return $extractor($object);
// At this point, we always got a Normalizable
default:
return $object->normalize($scope);
}
} | php | public function normalize($object, $scope = 'default')
{
switch (true) {
// Cannot normalized anything which already are
case !is_object($object) :
return $object;
// StdClass can be cast as array
case $object instanceof StdClass :
return (array) $object;
// DateTime : ISO format
case $object instanceof \DateTime:
return $object->format(\DateTime::ISO8601);
// Other objects : we use a closure hack to read data
case !$object instanceof NormalizableInterface :
$extractor = \Closure::bind($this->createExtractorDelegate(), $object, get_class($object));
return $extractor($object);
// At this point, we always got a Normalizable
default:
return $object->normalize($scope);
}
} | [
"public",
"function",
"normalize",
"(",
"$",
"object",
",",
"$",
"scope",
"=",
"'default'",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"// Cannot normalized anything which already are",
"case",
"!",
"is_object",
"(",
"$",
"object",
")",
":",
"return",
"$",
"object",
";",
"// StdClass can be cast as array",
"case",
"$",
"object",
"instanceof",
"StdClass",
":",
"return",
"(",
"array",
")",
"$",
"object",
";",
"// DateTime : ISO format",
"case",
"$",
"object",
"instanceof",
"\\",
"DateTime",
":",
"return",
"$",
"object",
"->",
"format",
"(",
"\\",
"DateTime",
"::",
"ISO8601",
")",
";",
"// Other objects : we use a closure hack to read data",
"case",
"!",
"$",
"object",
"instanceof",
"NormalizableInterface",
":",
"$",
"extractor",
"=",
"\\",
"Closure",
"::",
"bind",
"(",
"$",
"this",
"->",
"createExtractorDelegate",
"(",
")",
",",
"$",
"object",
",",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"return",
"$",
"extractor",
"(",
"$",
"object",
")",
";",
"// At this point, we always got a Normalizable",
"default",
":",
"return",
"$",
"object",
"->",
"normalize",
"(",
"$",
"scope",
")",
";",
"}",
"}"
] | Normalize given object using given scope.
@param mixed $object
@param string $scope
@return array|string
@throws ScopeNotFoundException If given scope not defined into given normalizable
@throws InvalidScopeException If given scope requires an unaccessible field | [
"Normalize",
"given",
"object",
"using",
"given",
"scope",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Normalizer/MajoraNormalizer.php#L140-L166 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Normalizer/MajoraNormalizer.php | MajoraNormalizer.scopify | public function scopify(NormalizableInterface $object, $scope)
{
$scopes = $object->getScopes();
if (!isset($scopes[$scope])) {
throw new ScopeNotFoundException(sprintf(
'Invalid scope for %s object, only ["%s"] supported, "%s" given.',
get_class($object),
implode('", "', array_keys($scopes)),
$scope
));
}
if (empty($scopes) || empty($scopes[$scope])) {
return array();
}
$read = \Closure::bind(
$this->createReadingDelegate(),
$object,
get_class($object)
);
// simple value scope
if (is_string($scopes[$scope])) {
return $read($scopes[$scope], $this->propertyAccessor);
}
// flatten fields
$fields = array();
$stack = array($scopes[$scope]);
do {
$stackedField = array_shift($stack);
foreach ($stackedField as $fieldConfig) {
if (strpos($fieldConfig, '@') === 0) {
if (!array_key_exists(
$inheritedScope = str_replace('@', '', $fieldConfig),
$scopes
)) {
throw new ScopeNotFoundException(sprintf(
'Invalid inherited scope for %s object at %s scope, only ["%s"] supported, "%s" given.',
get_class($object),
$scope,
implode(', ', array_keys($scopes)),
$inheritedScope
));
}
array_unshift($stack, $scopes[$inheritedScope]);
continue;
}
$fields[] = $fieldConfig;
}
} while (!empty($stack));
// begin normalization
$data = array();
foreach ($fields as $field) {
// optionnal field detection
$optionnal = false;
if (strpos($field, '?') !== false) {
$field = str_replace('?', '', $field);
$optionnal = true;
}
// external scopes : first in, last in
$subScope = 'default';
if (strpos($field, '@') !== false) {
list($field, $subScope) = explode('@', $field);
}
if (isset($data[$field])) {
continue;
}
$value = $this->normalize(
$read($field, $this->propertyAccessor),
$subScope
);
// nullable ?
if (!(is_null($value) && $optionnal)) {
$data[$field] = $value;
}
}
return $data;
} | php | public function scopify(NormalizableInterface $object, $scope)
{
$scopes = $object->getScopes();
if (!isset($scopes[$scope])) {
throw new ScopeNotFoundException(sprintf(
'Invalid scope for %s object, only ["%s"] supported, "%s" given.',
get_class($object),
implode('", "', array_keys($scopes)),
$scope
));
}
if (empty($scopes) || empty($scopes[$scope])) {
return array();
}
$read = \Closure::bind(
$this->createReadingDelegate(),
$object,
get_class($object)
);
// simple value scope
if (is_string($scopes[$scope])) {
return $read($scopes[$scope], $this->propertyAccessor);
}
// flatten fields
$fields = array();
$stack = array($scopes[$scope]);
do {
$stackedField = array_shift($stack);
foreach ($stackedField as $fieldConfig) {
if (strpos($fieldConfig, '@') === 0) {
if (!array_key_exists(
$inheritedScope = str_replace('@', '', $fieldConfig),
$scopes
)) {
throw new ScopeNotFoundException(sprintf(
'Invalid inherited scope for %s object at %s scope, only ["%s"] supported, "%s" given.',
get_class($object),
$scope,
implode(', ', array_keys($scopes)),
$inheritedScope
));
}
array_unshift($stack, $scopes[$inheritedScope]);
continue;
}
$fields[] = $fieldConfig;
}
} while (!empty($stack));
// begin normalization
$data = array();
foreach ($fields as $field) {
// optionnal field detection
$optionnal = false;
if (strpos($field, '?') !== false) {
$field = str_replace('?', '', $field);
$optionnal = true;
}
// external scopes : first in, last in
$subScope = 'default';
if (strpos($field, '@') !== false) {
list($field, $subScope) = explode('@', $field);
}
if (isset($data[$field])) {
continue;
}
$value = $this->normalize(
$read($field, $this->propertyAccessor),
$subScope
);
// nullable ?
if (!(is_null($value) && $optionnal)) {
$data[$field] = $value;
}
}
return $data;
} | [
"public",
"function",
"scopify",
"(",
"NormalizableInterface",
"$",
"object",
",",
"$",
"scope",
")",
"{",
"$",
"scopes",
"=",
"$",
"object",
"->",
"getScopes",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"scopes",
"[",
"$",
"scope",
"]",
")",
")",
"{",
"throw",
"new",
"ScopeNotFoundException",
"(",
"sprintf",
"(",
"'Invalid scope for %s object, only [\"%s\"] supported, \"%s\" given.'",
",",
"get_class",
"(",
"$",
"object",
")",
",",
"implode",
"(",
"'\", \"'",
",",
"array_keys",
"(",
"$",
"scopes",
")",
")",
",",
"$",
"scope",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"scopes",
")",
"||",
"empty",
"(",
"$",
"scopes",
"[",
"$",
"scope",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"read",
"=",
"\\",
"Closure",
"::",
"bind",
"(",
"$",
"this",
"->",
"createReadingDelegate",
"(",
")",
",",
"$",
"object",
",",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"// simple value scope",
"if",
"(",
"is_string",
"(",
"$",
"scopes",
"[",
"$",
"scope",
"]",
")",
")",
"{",
"return",
"$",
"read",
"(",
"$",
"scopes",
"[",
"$",
"scope",
"]",
",",
"$",
"this",
"->",
"propertyAccessor",
")",
";",
"}",
"// flatten fields",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"$",
"stack",
"=",
"array",
"(",
"$",
"scopes",
"[",
"$",
"scope",
"]",
")",
";",
"do",
"{",
"$",
"stackedField",
"=",
"array_shift",
"(",
"$",
"stack",
")",
";",
"foreach",
"(",
"$",
"stackedField",
"as",
"$",
"fieldConfig",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"fieldConfig",
",",
"'@'",
")",
"===",
"0",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"inheritedScope",
"=",
"str_replace",
"(",
"'@'",
",",
"''",
",",
"$",
"fieldConfig",
")",
",",
"$",
"scopes",
")",
")",
"{",
"throw",
"new",
"ScopeNotFoundException",
"(",
"sprintf",
"(",
"'Invalid inherited scope for %s object at %s scope, only [\"%s\"] supported, \"%s\" given.'",
",",
"get_class",
"(",
"$",
"object",
")",
",",
"$",
"scope",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"scopes",
")",
")",
",",
"$",
"inheritedScope",
")",
")",
";",
"}",
"array_unshift",
"(",
"$",
"stack",
",",
"$",
"scopes",
"[",
"$",
"inheritedScope",
"]",
")",
";",
"continue",
";",
"}",
"$",
"fields",
"[",
"]",
"=",
"$",
"fieldConfig",
";",
"}",
"}",
"while",
"(",
"!",
"empty",
"(",
"$",
"stack",
")",
")",
";",
"// begin normalization",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"// optionnal field detection",
"$",
"optionnal",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'?'",
")",
"!==",
"false",
")",
"{",
"$",
"field",
"=",
"str_replace",
"(",
"'?'",
",",
"''",
",",
"$",
"field",
")",
";",
"$",
"optionnal",
"=",
"true",
";",
"}",
"// external scopes : first in, last in",
"$",
"subScope",
"=",
"'default'",
";",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'@'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"field",
",",
"$",
"subScope",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"field",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"normalize",
"(",
"$",
"read",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"propertyAccessor",
")",
",",
"$",
"subScope",
")",
";",
"// nullable ?",
"if",
"(",
"!",
"(",
"is_null",
"(",
"$",
"value",
")",
"&&",
"$",
"optionnal",
")",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Normalize given normalizable following given scope.
@param NormalizableInterface $object
@param string $scope
@return array | [
"Normalize",
"given",
"normalizable",
"following",
"given",
"scope",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Normalizer/MajoraNormalizer.php#L176-L261 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Normalizer/MajoraNormalizer.php | MajoraNormalizer.createWrittingDelegate | private function createWrittingDelegate()
{
return $this->writeDelegate ?: $this->writeDelegate = function (PropertyPathInterface $property, $value, PropertyAccessor $propertyAccessor) {
switch (true) {
// Public property / accessor case
case $propertyAccessor->isWritable($this, $property) :
return $propertyAccessor->setValue($this, $property, $value);
// Private property / StdClass
case property_exists($this, $property) || $this instanceof \StdClass :
return $this->$property = $value;
}
throw new InvalidScopeException(sprintf(
'Unable to set "%s" property into a "%s" object, any existing property path to write it in.',
$property,
get_class($this)
));
};
} | php | private function createWrittingDelegate()
{
return $this->writeDelegate ?: $this->writeDelegate = function (PropertyPathInterface $property, $value, PropertyAccessor $propertyAccessor) {
switch (true) {
// Public property / accessor case
case $propertyAccessor->isWritable($this, $property) :
return $propertyAccessor->setValue($this, $property, $value);
// Private property / StdClass
case property_exists($this, $property) || $this instanceof \StdClass :
return $this->$property = $value;
}
throw new InvalidScopeException(sprintf(
'Unable to set "%s" property into a "%s" object, any existing property path to write it in.',
$property,
get_class($this)
));
};
} | [
"private",
"function",
"createWrittingDelegate",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"writeDelegate",
"?",
":",
"$",
"this",
"->",
"writeDelegate",
"=",
"function",
"(",
"PropertyPathInterface",
"$",
"property",
",",
"$",
"value",
",",
"PropertyAccessor",
"$",
"propertyAccessor",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"// Public property / accessor case",
"case",
"$",
"propertyAccessor",
"->",
"isWritable",
"(",
"$",
"this",
",",
"$",
"property",
")",
":",
"return",
"$",
"propertyAccessor",
"->",
"setValue",
"(",
"$",
"this",
",",
"$",
"property",
",",
"$",
"value",
")",
";",
"// Private property / StdClass",
"case",
"property_exists",
"(",
"$",
"this",
",",
"$",
"property",
")",
"||",
"$",
"this",
"instanceof",
"\\",
"StdClass",
":",
"return",
"$",
"this",
"->",
"$",
"property",
"=",
"$",
"value",
";",
"}",
"throw",
"new",
"InvalidScopeException",
"(",
"sprintf",
"(",
"'Unable to set \"%s\" property into a \"%s\" object, any existing property path to write it in.'",
",",
"$",
"property",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
";",
"}"
] | Create and return a Closure available to write an object property through a property path or a private property.
@return \Closure | [
"Create",
"and",
"return",
"a",
"Closure",
"available",
"to",
"write",
"an",
"object",
"property",
"through",
"a",
"property",
"path",
"or",
"a",
"private",
"property",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Normalizer/MajoraNormalizer.php#L268-L288 | train |
kambalabs/KmbPmProxy | src/KmbPmProxy/Service/PuppetModule.php | PuppetModule.getModuleHydrator | public function getModuleHydrator()
{
if ($this->moduleHydrator == null) {
$moduleHydratorClass = $this->getOptions()->getPuppetModuleHydratorClass();
$this->moduleHydrator = new $moduleHydratorClass;
}
return $this->moduleHydrator;
} | php | public function getModuleHydrator()
{
if ($this->moduleHydrator == null) {
$moduleHydratorClass = $this->getOptions()->getPuppetModuleHydratorClass();
$this->moduleHydrator = new $moduleHydratorClass;
}
return $this->moduleHydrator;
} | [
"public",
"function",
"getModuleHydrator",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"moduleHydrator",
"==",
"null",
")",
"{",
"$",
"moduleHydratorClass",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getPuppetModuleHydratorClass",
"(",
")",
";",
"$",
"this",
"->",
"moduleHydrator",
"=",
"new",
"$",
"moduleHydratorClass",
";",
"}",
"return",
"$",
"this",
"->",
"moduleHydrator",
";",
"}"
] | Get ModuleHydrator.
@return \Zend\Stdlib\Hydrator\HydratorInterface | [
"Get",
"ModuleHydrator",
"."
] | b4c664ae8b6f29e4e8768461ed99e1b0b80bde18 | https://github.com/kambalabs/KmbPmProxy/blob/b4c664ae8b6f29e4e8768461ed99e1b0b80bde18/src/KmbPmProxy/Service/PuppetModule.php#L224-L231 | train |
kambalabs/KmbPmProxy | src/KmbPmProxy/Service/PuppetModule.php | PuppetModule.getClassHydrator | public function getClassHydrator()
{
if ($this->classHydrator == null) {
$classHydratorClass = $this->getOptions()->getPuppetClassHydratorClass();
$this->classHydrator = new $classHydratorClass;
}
return $this->classHydrator;
} | php | public function getClassHydrator()
{
if ($this->classHydrator == null) {
$classHydratorClass = $this->getOptions()->getPuppetClassHydratorClass();
$this->classHydrator = new $classHydratorClass;
}
return $this->classHydrator;
} | [
"public",
"function",
"getClassHydrator",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classHydrator",
"==",
"null",
")",
"{",
"$",
"classHydratorClass",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getPuppetClassHydratorClass",
"(",
")",
";",
"$",
"this",
"->",
"classHydrator",
"=",
"new",
"$",
"classHydratorClass",
";",
"}",
"return",
"$",
"this",
"->",
"classHydrator",
";",
"}"
] | Get ClassHydrator.
@return \Zend\Stdlib\Hydrator\HydratorInterface | [
"Get",
"ClassHydrator",
"."
] | b4c664ae8b6f29e4e8768461ed99e1b0b80bde18 | https://github.com/kambalabs/KmbPmProxy/blob/b4c664ae8b6f29e4e8768461ed99e1b0b80bde18/src/KmbPmProxy/Service/PuppetModule.php#L250-L257 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/RelationshipMetadata.php | RelationshipMetadata.validateType | protected function validateType($relType)
{
$valid = ['one', 'many'];
if (!in_array($relType, $valid)) {
throw MetadataException::invalidRelType($relType, $valid);
}
return true;
} | php | protected function validateType($relType)
{
$valid = ['one', 'many'];
if (!in_array($relType, $valid)) {
throw MetadataException::invalidRelType($relType, $valid);
}
return true;
} | [
"protected",
"function",
"validateType",
"(",
"$",
"relType",
")",
"{",
"$",
"valid",
"=",
"[",
"'one'",
",",
"'many'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relType",
",",
"$",
"valid",
")",
")",
"{",
"throw",
"MetadataException",
"::",
"invalidRelType",
"(",
"$",
"relType",
",",
"$",
"valid",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Validates the relationship type.
@param string $type
@return bool
@throws MetadataException | [
"Validates",
"the",
"relationship",
"type",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/RelationshipMetadata.php#L108-L115 | train |
SlabPHP/configuration-manager | src/Parameter.php | Parameter.getConfigurationParameterName | public function getConfigurationParameterName($value = null)
{
$output = '';
if (!empty($this->_parent) && $this->_parent instanceof Parameter) {
$output .= $this->_parent->getConfigurationParameterName();
}
if (!empty($this->_name)) {
if (!empty($output)) $output .= '->';
$output .= $this->_name;
} else {
if (!empty($output)) $output .= '->';
$output .= '{unspecified}';
}
if (!empty($value)) {
if (!empty($output)) $output .= '->';
$output .= $value;
}
return $output;
} | php | public function getConfigurationParameterName($value = null)
{
$output = '';
if (!empty($this->_parent) && $this->_parent instanceof Parameter) {
$output .= $this->_parent->getConfigurationParameterName();
}
if (!empty($this->_name)) {
if (!empty($output)) $output .= '->';
$output .= $this->_name;
} else {
if (!empty($output)) $output .= '->';
$output .= '{unspecified}';
}
if (!empty($value)) {
if (!empty($output)) $output .= '->';
$output .= $value;
}
return $output;
} | [
"public",
"function",
"getConfigurationParameterName",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_parent",
")",
"&&",
"$",
"this",
"->",
"_parent",
"instanceof",
"Parameter",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"_parent",
"->",
"getConfigurationParameterName",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_name",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"output",
")",
")",
"$",
"output",
".=",
"'->'",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"_name",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"output",
")",
")",
"$",
"output",
".=",
"'->'",
";",
"$",
"output",
".=",
"'{unspecified}'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"output",
")",
")",
"$",
"output",
".=",
"'->'",
";",
"$",
"output",
".=",
"$",
"value",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Get name of configuration value
@param string $value
return $string; | [
"Get",
"name",
"of",
"configuration",
"value"
] | 3f36b528b8d7b0ffbb43ec933e82efd7312a3397 | https://github.com/SlabPHP/configuration-manager/blob/3f36b528b8d7b0ffbb43ec933e82efd7312a3397/src/Parameter.php#L50-L75 | train |
SlabPHP/configuration-manager | src/Parameter.php | Parameter.flattenResult | public function flattenResult()
{
$output = [];
$vars = (array)$this;
foreach ($vars as $field => $value) {
//Trim off the protected items that come in as \0*\0_name
if (ord($field[0]) == 0) continue;
if ($value instanceof Parameter) {
$output[$field] = $value->flattenResult();
} else {
$output[$field] = $value;
}
}
return $output;
} | php | public function flattenResult()
{
$output = [];
$vars = (array)$this;
foreach ($vars as $field => $value) {
//Trim off the protected items that come in as \0*\0_name
if (ord($field[0]) == 0) continue;
if ($value instanceof Parameter) {
$output[$field] = $value->flattenResult();
} else {
$output[$field] = $value;
}
}
return $output;
} | [
"public",
"function",
"flattenResult",
"(",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"vars",
"=",
"(",
"array",
")",
"$",
"this",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"//Trim off the protected items that come in as \\0*\\0_name",
"if",
"(",
"ord",
"(",
"$",
"field",
"[",
"0",
"]",
")",
"==",
"0",
")",
"continue",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Parameter",
")",
"{",
"$",
"output",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
"->",
"flattenResult",
"(",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Get flattened scalars from a configuration parameter, recursively
@return array | [
"Get",
"flattened",
"scalars",
"from",
"a",
"configuration",
"parameter",
"recursively"
] | 3f36b528b8d7b0ffbb43ec933e82efd7312a3397 | https://github.com/SlabPHP/configuration-manager/blob/3f36b528b8d7b0ffbb43ec933e82efd7312a3397/src/Parameter.php#L119-L137 | train |
moaction/jsonrpc-common | src/Moaction/Jsonrpc/Common/Request.php | Request.toArray | public function toArray()
{
if (!$this->getMethod()) {
throw new \InvalidArgumentException('Method must be provided for request');
}
$data = array(
'jsonrpc' => self::VERSION,
'method' => $this->getMethod(),
);
if ($this->getParams()) {
$data['params'] = $this->getParams();
}
if ($this->getId()) {
$data['id'] = $this->getId();
}
return $data;
} | php | public function toArray()
{
if (!$this->getMethod()) {
throw new \InvalidArgumentException('Method must be provided for request');
}
$data = array(
'jsonrpc' => self::VERSION,
'method' => $this->getMethod(),
);
if ($this->getParams()) {
$data['params'] = $this->getParams();
}
if ($this->getId()) {
$data['id'] = $this->getId();
}
return $data;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getMethod",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Method must be provided for request'",
")",
";",
"}",
"$",
"data",
"=",
"array",
"(",
"'jsonrpc'",
"=>",
"self",
"::",
"VERSION",
",",
"'method'",
"=>",
"$",
"this",
"->",
"getMethod",
"(",
")",
",",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'params'",
"]",
"=",
"$",
"this",
"->",
"getParams",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Serialize into array
@throws \InvalidArgumentException
@return array | [
"Serialize",
"into",
"array"
] | 05692a2c58d647f20f11b6f7b9568c8fff2d5f8c | https://github.com/moaction/jsonrpc-common/blob/05692a2c58d647f20f11b6f7b9568c8fff2d5f8c/src/Moaction/Jsonrpc/Common/Request.php#L87-L107 | train |
Rundiz/serializer | Rundiz/Serializer/Serializer.php | Serializer.isSerialized | public function isSerialized($string)
{
if (!is_string($string)) {
return false;
}
$string = trim($string);
if ($string === 'N;') {
// if serialized string is NULL.
return true;
}
$string_encoding = mb_detect_encoding($string);
$length = mb_strlen($string, $string_encoding);
$last_char = mb_substr($string, -1, NULL, $string_encoding);
unset($string_encoding);
if ($length < 4) {
// if total characters of this string (string length) is less than 4 then it is not serialized except NULL which is verified above.
unset($last_char, $length);
return false;
}
if ($string[1] !== ':') {
// if character number 2 (offset 1, start at 0) from this string is not colon means it is not serialized string.
unset($last_char, $length);
return false;
}
if (in_array($string[0], ['b', 'i', 'd', 's']) && $last_char !== ';') {
// if first character maybe boolean, integer, double or float, string but last character is not semicolon means it is not serialized string.
unset($last_char, $length);
return false;
} elseif (in_array($string[0], ['a', 'O']) && $last_char !== '}') {
// last character of array, object is not right curly bracket means it is not serialized string.
unset($last_char, $length);
return false;
}
// switch to first character of this string.
switch ($string[0]) {
case 'b':
// this maybe boolean
if ($length > 4 || ($string[2] !== '0' && $string[2] !== '1')) {
// if string length is more than 4 or character number 3 (offset 2) is not 0 (false) and is not 1 (true) means it is not serialized string.
return false;
} elseif ($length == 4 && ($string[2] === '0' || $string[2] === '1')) {
// if string length is exactly 4 and character number 3 (offset 2) is 0 (false) or 1 (true) means it is serialized string.
return true;
} else {
return false;
}
case 'i':
// this maybe integer
return (boolean) preg_match('#^'.$string[0].':[0-9\-]+\\'.$last_char.'#', $string);
case 'd':
// this maybe double or float
return (boolean) preg_match('#^'.$string[0].':[0-9\.E\-\+]+\\'.$last_char.'#', $string);
case 's':
// this maybe string
$exp_string = explode(':', $string);
if (isset($exp_string[1]) && isset($exp_string[2])) {
// if found number of total characters in serialize, count to make sure that it is matched.
unset($last_char, $length);
// number in serialized string type seems to use `strlen` because it is not counting the real unicode characters.
return (intval($exp_string[1]) === intval(strlen(trim($exp_string[2], ';"'))));
}
unset($exp_string, $last_char, $length);
return false;
case 'a':
// this maybe array
case 'O':
// this maybe object
return (boolean) preg_match('#^'.$string[0].':[0-9]+\:#s', $string);
}// endswitch;
return false;
} | php | public function isSerialized($string)
{
if (!is_string($string)) {
return false;
}
$string = trim($string);
if ($string === 'N;') {
// if serialized string is NULL.
return true;
}
$string_encoding = mb_detect_encoding($string);
$length = mb_strlen($string, $string_encoding);
$last_char = mb_substr($string, -1, NULL, $string_encoding);
unset($string_encoding);
if ($length < 4) {
// if total characters of this string (string length) is less than 4 then it is not serialized except NULL which is verified above.
unset($last_char, $length);
return false;
}
if ($string[1] !== ':') {
// if character number 2 (offset 1, start at 0) from this string is not colon means it is not serialized string.
unset($last_char, $length);
return false;
}
if (in_array($string[0], ['b', 'i', 'd', 's']) && $last_char !== ';') {
// if first character maybe boolean, integer, double or float, string but last character is not semicolon means it is not serialized string.
unset($last_char, $length);
return false;
} elseif (in_array($string[0], ['a', 'O']) && $last_char !== '}') {
// last character of array, object is not right curly bracket means it is not serialized string.
unset($last_char, $length);
return false;
}
// switch to first character of this string.
switch ($string[0]) {
case 'b':
// this maybe boolean
if ($length > 4 || ($string[2] !== '0' && $string[2] !== '1')) {
// if string length is more than 4 or character number 3 (offset 2) is not 0 (false) and is not 1 (true) means it is not serialized string.
return false;
} elseif ($length == 4 && ($string[2] === '0' || $string[2] === '1')) {
// if string length is exactly 4 and character number 3 (offset 2) is 0 (false) or 1 (true) means it is serialized string.
return true;
} else {
return false;
}
case 'i':
// this maybe integer
return (boolean) preg_match('#^'.$string[0].':[0-9\-]+\\'.$last_char.'#', $string);
case 'd':
// this maybe double or float
return (boolean) preg_match('#^'.$string[0].':[0-9\.E\-\+]+\\'.$last_char.'#', $string);
case 's':
// this maybe string
$exp_string = explode(':', $string);
if (isset($exp_string[1]) && isset($exp_string[2])) {
// if found number of total characters in serialize, count to make sure that it is matched.
unset($last_char, $length);
// number in serialized string type seems to use `strlen` because it is not counting the real unicode characters.
return (intval($exp_string[1]) === intval(strlen(trim($exp_string[2], ';"'))));
}
unset($exp_string, $last_char, $length);
return false;
case 'a':
// this maybe array
case 'O':
// this maybe object
return (boolean) preg_match('#^'.$string[0].':[0-9]+\:#s', $string);
}// endswitch;
return false;
} | [
"public",
"function",
"isSerialized",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"if",
"(",
"$",
"string",
"===",
"'N;'",
")",
"{",
"// if serialized string is NULL.",
"return",
"true",
";",
"}",
"$",
"string_encoding",
"=",
"mb_detect_encoding",
"(",
"$",
"string",
")",
";",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"string",
",",
"$",
"string_encoding",
")",
";",
"$",
"last_char",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"-",
"1",
",",
"NULL",
",",
"$",
"string_encoding",
")",
";",
"unset",
"(",
"$",
"string_encoding",
")",
";",
"if",
"(",
"$",
"length",
"<",
"4",
")",
"{",
"// if total characters of this string (string length) is less than 4 then it is not serialized except NULL which is verified above.",
"unset",
"(",
"$",
"last_char",
",",
"$",
"length",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"string",
"[",
"1",
"]",
"!==",
"':'",
")",
"{",
"// if character number 2 (offset 1, start at 0) from this string is not colon means it is not serialized string.",
"unset",
"(",
"$",
"last_char",
",",
"$",
"length",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"string",
"[",
"0",
"]",
",",
"[",
"'b'",
",",
"'i'",
",",
"'d'",
",",
"'s'",
"]",
")",
"&&",
"$",
"last_char",
"!==",
"';'",
")",
"{",
"// if first character maybe boolean, integer, double or float, string but last character is not semicolon means it is not serialized string.",
"unset",
"(",
"$",
"last_char",
",",
"$",
"length",
")",
";",
"return",
"false",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"string",
"[",
"0",
"]",
",",
"[",
"'a'",
",",
"'O'",
"]",
")",
"&&",
"$",
"last_char",
"!==",
"'}'",
")",
"{",
"// last character of array, object is not right curly bracket means it is not serialized string.",
"unset",
"(",
"$",
"last_char",
",",
"$",
"length",
")",
";",
"return",
"false",
";",
"}",
"// switch to first character of this string.",
"switch",
"(",
"$",
"string",
"[",
"0",
"]",
")",
"{",
"case",
"'b'",
":",
"// this maybe boolean",
"if",
"(",
"$",
"length",
">",
"4",
"||",
"(",
"$",
"string",
"[",
"2",
"]",
"!==",
"'0'",
"&&",
"$",
"string",
"[",
"2",
"]",
"!==",
"'1'",
")",
")",
"{",
"// if string length is more than 4 or character number 3 (offset 2) is not 0 (false) and is not 1 (true) means it is not serialized string.",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"length",
"==",
"4",
"&&",
"(",
"$",
"string",
"[",
"2",
"]",
"===",
"'0'",
"||",
"$",
"string",
"[",
"2",
"]",
"===",
"'1'",
")",
")",
"{",
"// if string length is exactly 4 and character number 3 (offset 2) is 0 (false) or 1 (true) means it is serialized string.",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"case",
"'i'",
":",
"// this maybe integer",
"return",
"(",
"boolean",
")",
"preg_match",
"(",
"'#^'",
".",
"$",
"string",
"[",
"0",
"]",
".",
"':[0-9\\-]+\\\\'",
".",
"$",
"last_char",
".",
"'#'",
",",
"$",
"string",
")",
";",
"case",
"'d'",
":",
"// this maybe double or float",
"return",
"(",
"boolean",
")",
"preg_match",
"(",
"'#^'",
".",
"$",
"string",
"[",
"0",
"]",
".",
"':[0-9\\.E\\-\\+]+\\\\'",
".",
"$",
"last_char",
".",
"'#'",
",",
"$",
"string",
")",
";",
"case",
"'s'",
":",
"// this maybe string",
"$",
"exp_string",
"=",
"explode",
"(",
"':'",
",",
"$",
"string",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"exp_string",
"[",
"1",
"]",
")",
"&&",
"isset",
"(",
"$",
"exp_string",
"[",
"2",
"]",
")",
")",
"{",
"// if found number of total characters in serialize, count to make sure that it is matched.",
"unset",
"(",
"$",
"last_char",
",",
"$",
"length",
")",
";",
"// number in serialized string type seems to use `strlen` because it is not counting the real unicode characters.",
"return",
"(",
"intval",
"(",
"$",
"exp_string",
"[",
"1",
"]",
")",
"===",
"intval",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"exp_string",
"[",
"2",
"]",
",",
"';\"'",
")",
")",
")",
")",
";",
"}",
"unset",
"(",
"$",
"exp_string",
",",
"$",
"last_char",
",",
"$",
"length",
")",
";",
"return",
"false",
";",
"case",
"'a'",
":",
"// this maybe array",
"case",
"'O'",
":",
"// this maybe object",
"return",
"(",
"boolean",
")",
"preg_match",
"(",
"'#^'",
".",
"$",
"string",
"[",
"0",
"]",
".",
"':[0-9]+\\:#s'",
",",
"$",
"string",
")",
";",
"}",
"// endswitch;",
"return",
"false",
";",
"}"
] | Is serialized string.
@link https://core.trac.wordpress.org/browser/tags/4.7.3/src/wp-includes/functions.php#L341 Reference from WordPress.
@link https://gist.github.com/cs278/217091 Reference from Github cs278/is_serialized.php
@param string $string The string to check.
@return boolean Return true if serialized, false for otherwise. | [
"Is",
"serialized",
"string",
"."
] | e50185a835949a7f0c7a5d73ae48daa7f3f4a2d9 | https://github.com/Rundiz/serializer/blob/e50185a835949a7f0c7a5d73ae48daa7f3f4a2d9/Rundiz/Serializer/Serializer.php#L33-L111 | train |
AnnotateFramework/backend | src/Content/Providers/MainPanelContentProvider.php | MainPanelContentProvider.addLink | public function addLink($url, $title, $icon = NULL, $priority = 0)
{
$link = [
"moduleUrl" => str_replace("#", NULL, substr($url, 0, strpos($url, ":"))),
"url" => $url,
"title" => $title,
"icon" => $icon,
"priority" => $priority
];
$this->links[] = $link;
} | php | public function addLink($url, $title, $icon = NULL, $priority = 0)
{
$link = [
"moduleUrl" => str_replace("#", NULL, substr($url, 0, strpos($url, ":"))),
"url" => $url,
"title" => $title,
"icon" => $icon,
"priority" => $priority
];
$this->links[] = $link;
} | [
"public",
"function",
"addLink",
"(",
"$",
"url",
",",
"$",
"title",
",",
"$",
"icon",
"=",
"NULL",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"$",
"link",
"=",
"[",
"\"moduleUrl\"",
"=>",
"str_replace",
"(",
"\"#\"",
",",
"NULL",
",",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"strpos",
"(",
"$",
"url",
",",
"\":\"",
")",
")",
")",
",",
"\"url\"",
"=>",
"$",
"url",
",",
"\"title\"",
"=>",
"$",
"title",
",",
"\"icon\"",
"=>",
"$",
"icon",
",",
"\"priority\"",
"=>",
"$",
"priority",
"]",
";",
"$",
"this",
"->",
"links",
"[",
"]",
"=",
"$",
"link",
";",
"}"
] | Adds link to mainPanel
@param string
@param string
@param string|NULL
@param int|NULL goes from min to max | [
"Adds",
"link",
"to",
"mainPanel"
] | dbc524ceb9d2af5f5f76a72ea0f6100399bc2f17 | https://github.com/AnnotateFramework/backend/blob/dbc524ceb9d2af5f5f76a72ea0f6100399bc2f17/src/Content/Providers/MainPanelContentProvider.php#L45-L55 | train |
ScaraMVC/Framework | src/Scara/Debug/ExceptionRenderer.php | ExceptionRenderer.render | public function render(Exception $e, $debug)
{
$e = FlattenException::create($e);
$handler = new SymfonyExceptionHandler($debug);
$status = $e->getStatusCode();
$response = SymfonyResponse::create($handler->getHtml($e), $status, $e->getHeaders());
$rex = explode("\n", $response);
if (strstr(strtolower($rex[0]), 'http')) {
for ($i = 0; $i < 2; $i++) {
array_shift($rex);
}
}
if (View::exists("errors.{$status}")) {
echo View::renderView("errors.{$status}", 'exception', implode("\n", $rex));
} else {
echo implode("\n", $rex);
}
} | php | public function render(Exception $e, $debug)
{
$e = FlattenException::create($e);
$handler = new SymfonyExceptionHandler($debug);
$status = $e->getStatusCode();
$response = SymfonyResponse::create($handler->getHtml($e), $status, $e->getHeaders());
$rex = explode("\n", $response);
if (strstr(strtolower($rex[0]), 'http')) {
for ($i = 0; $i < 2; $i++) {
array_shift($rex);
}
}
if (View::exists("errors.{$status}")) {
echo View::renderView("errors.{$status}", 'exception', implode("\n", $rex));
} else {
echo implode("\n", $rex);
}
} | [
"public",
"function",
"render",
"(",
"Exception",
"$",
"e",
",",
"$",
"debug",
")",
"{",
"$",
"e",
"=",
"FlattenException",
"::",
"create",
"(",
"$",
"e",
")",
";",
"$",
"handler",
"=",
"new",
"SymfonyExceptionHandler",
"(",
"$",
"debug",
")",
";",
"$",
"status",
"=",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"response",
"=",
"SymfonyResponse",
"::",
"create",
"(",
"$",
"handler",
"->",
"getHtml",
"(",
"$",
"e",
")",
",",
"$",
"status",
",",
"$",
"e",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rex",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"response",
")",
";",
"if",
"(",
"strstr",
"(",
"strtolower",
"(",
"$",
"rex",
"[",
"0",
"]",
")",
",",
"'http'",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"2",
";",
"$",
"i",
"++",
")",
"{",
"array_shift",
"(",
"$",
"rex",
")",
";",
"}",
"}",
"if",
"(",
"View",
"::",
"exists",
"(",
"\"errors.{$status}\"",
")",
")",
"{",
"echo",
"View",
"::",
"renderView",
"(",
"\"errors.{$status}\"",
",",
"'exception'",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"rex",
")",
")",
";",
"}",
"else",
"{",
"echo",
"implode",
"(",
"\"\\n\"",
",",
"$",
"rex",
")",
";",
"}",
"}"
] | Renders the error.
@param \Exception $e
@param bool $debug
@return void | [
"Renders",
"the",
"error",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Debug/ExceptionRenderer.php#L30-L51 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/caching/interfaces/AbstractCache.php | AbstractCache.multiGet | public function multiGet(array $keys, $localOnly = false)
{
$keys = array_unique($keys);
$results = array();
$others = array();
foreach ($keys as $key) {
$cacheKey = $this->cacheKey($key);
if ($this->keepLocalCache && array_key_exists($cacheKey, $this->localCache))
$results[$cacheKey] = $this->localCache[$cacheKey];
else
$others[] = $cacheKey;
}
if(!$localOnly) {
$results = array_merge($results, ($cached = $this->cacheStore->multiGet($others)) == false ? array() : $cached);
if($this->keepLocalCache && !empty($cached))
foreach($cached as $key => $value)
$this->localCache[$key] = $value;
unset($cached);
}
unset($keys);
unset($others);
return $results;
} | php | public function multiGet(array $keys, $localOnly = false)
{
$keys = array_unique($keys);
$results = array();
$others = array();
foreach ($keys as $key) {
$cacheKey = $this->cacheKey($key);
if ($this->keepLocalCache && array_key_exists($cacheKey, $this->localCache))
$results[$cacheKey] = $this->localCache[$cacheKey];
else
$others[] = $cacheKey;
}
if(!$localOnly) {
$results = array_merge($results, ($cached = $this->cacheStore->multiGet($others)) == false ? array() : $cached);
if($this->keepLocalCache && !empty($cached))
foreach($cached as $key => $value)
$this->localCache[$key] = $value;
unset($cached);
}
unset($keys);
unset($others);
return $results;
} | [
"public",
"function",
"multiGet",
"(",
"array",
"$",
"keys",
",",
"$",
"localOnly",
"=",
"false",
")",
"{",
"$",
"keys",
"=",
"array_unique",
"(",
"$",
"keys",
")",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"$",
"others",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"cacheKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"->",
"keepLocalCache",
"&&",
"array_key_exists",
"(",
"$",
"cacheKey",
",",
"$",
"this",
"->",
"localCache",
")",
")",
"$",
"results",
"[",
"$",
"cacheKey",
"]",
"=",
"$",
"this",
"->",
"localCache",
"[",
"$",
"cacheKey",
"]",
";",
"else",
"$",
"others",
"[",
"]",
"=",
"$",
"cacheKey",
";",
"}",
"if",
"(",
"!",
"$",
"localOnly",
")",
"{",
"$",
"results",
"=",
"array_merge",
"(",
"$",
"results",
",",
"(",
"$",
"cached",
"=",
"$",
"this",
"->",
"cacheStore",
"->",
"multiGet",
"(",
"$",
"others",
")",
")",
"==",
"false",
"?",
"array",
"(",
")",
":",
"$",
"cached",
")",
";",
"if",
"(",
"$",
"this",
"->",
"keepLocalCache",
"&&",
"!",
"empty",
"(",
"$",
"cached",
")",
")",
"foreach",
"(",
"$",
"cached",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"$",
"this",
"->",
"localCache",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"cached",
")",
";",
"}",
"unset",
"(",
"$",
"keys",
")",
";",
"unset",
"(",
"$",
"others",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Returns an array of nodes from cache specified by key
@param array $keys An array of keys to fetch
@param bool $localOnly
@return array | [
"Returns",
"an",
"array",
"of",
"nodes",
"from",
"cache",
"specified",
"by",
"key"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/AbstractCache.php#L54-L80 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/caching/interfaces/AbstractCache.php | AbstractCache.put | public function put($key, $value, $duration, $localOnly = false)
{
$cacheKey = $this->cacheKey($key);
if($this->keepLocalCache)
$this->localCache[$cacheKey] = $value;
if(!$localOnly)
$this->cacheStore->put($cacheKey, $value, $duration);
} | php | public function put($key, $value, $duration, $localOnly = false)
{
$cacheKey = $this->cacheKey($key);
if($this->keepLocalCache)
$this->localCache[$cacheKey] = $value;
if(!$localOnly)
$this->cacheStore->put($cacheKey, $value, $duration);
} | [
"public",
"function",
"put",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"duration",
",",
"$",
"localOnly",
"=",
"false",
")",
"{",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"cacheKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"->",
"keepLocalCache",
")",
"$",
"this",
"->",
"localCache",
"[",
"$",
"cacheKey",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"!",
"$",
"localOnly",
")",
"$",
"this",
"->",
"cacheStore",
"->",
"put",
"(",
"$",
"cacheKey",
",",
"$",
"value",
",",
"$",
"duration",
")",
";",
"}"
] | Stores the value specified with the cacheKey given.
@param string $cacheKey The cache key
@param mixed $value The value to store
@access public
@return void | [
"Stores",
"the",
"value",
"specified",
"with",
"the",
"cacheKey",
"given",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/AbstractCache.php#L91-L98 | train |
ZFrapid/zfrapid-core | src/Console/Application.php | Application.translateRoutes | protected function translateRoutes(array $routes = [])
{
foreach ($routes as $routeKey => $routeParams) {
if (isset($routeParams['description'])) {
$routes[$routeKey]['description']
= $this->translator->translate(
$routeParams['description']
);
}
if (isset($routeParams['short_description'])) {
$routes[$routeKey]['short_description']
= $this->translator->translate(
$routeParams['short_description']
);
}
if (isset($routeParams['options_descriptions'])) {
foreach (
$routeParams['options_descriptions'] as
$optionKey => $optionText
) {
$routes[$routeKey]['options_descriptions'][$optionKey]
= $this->translator->translate(
$optionText
);
}
}
}
return $routes;
} | php | protected function translateRoutes(array $routes = [])
{
foreach ($routes as $routeKey => $routeParams) {
if (isset($routeParams['description'])) {
$routes[$routeKey]['description']
= $this->translator->translate(
$routeParams['description']
);
}
if (isset($routeParams['short_description'])) {
$routes[$routeKey]['short_description']
= $this->translator->translate(
$routeParams['short_description']
);
}
if (isset($routeParams['options_descriptions'])) {
foreach (
$routeParams['options_descriptions'] as
$optionKey => $optionText
) {
$routes[$routeKey]['options_descriptions'][$optionKey]
= $this->translator->translate(
$optionText
);
}
}
}
return $routes;
} | [
"protected",
"function",
"translateRoutes",
"(",
"array",
"$",
"routes",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"routeKey",
"=>",
"$",
"routeParams",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"routeParams",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"routes",
"[",
"$",
"routeKey",
"]",
"[",
"'description'",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"$",
"routeParams",
"[",
"'description'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"routeParams",
"[",
"'short_description'",
"]",
")",
")",
"{",
"$",
"routes",
"[",
"$",
"routeKey",
"]",
"[",
"'short_description'",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"$",
"routeParams",
"[",
"'short_description'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"routeParams",
"[",
"'options_descriptions'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"routeParams",
"[",
"'options_descriptions'",
"]",
"as",
"$",
"optionKey",
"=>",
"$",
"optionText",
")",
"{",
"$",
"routes",
"[",
"$",
"routeKey",
"]",
"[",
"'options_descriptions'",
"]",
"[",
"$",
"optionKey",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"$",
"optionText",
")",
";",
"}",
"}",
"}",
"return",
"$",
"routes",
";",
"}"
] | Translate the route texts
@param array $routes
@return array | [
"Translate",
"the",
"route",
"texts"
] | 8be56b82f9f5a687619a2b2175fcaa66ad3d2233 | https://github.com/ZFrapid/zfrapid-core/blob/8be56b82f9f5a687619a2b2175fcaa66ad3d2233/src/Console/Application.php#L132-L161 | train |
ZFrapid/zfrapid-core | src/Console/Application.php | Application.writeApplicationBanner | public function writeApplicationBanner(AdapterInterface $console)
{
$console->writeLine();
$console->writeLine(
str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT),
Color::GREEN
);
$console->write('=', Color::GREEN);
$console->write(
str_pad(
'' . $this->name . ' - ' . $this->slogan
. ' (Version ' . $this->version . ')',
$console->getWidth() - 3,
' ',
STR_PAD_BOTH
)
);
$console->writeLine('=', Color::GREEN);
$console->writeLine(
str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT),
Color::GREEN
);
$console->writeLine();
} | php | public function writeApplicationBanner(AdapterInterface $console)
{
$console->writeLine();
$console->writeLine(
str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT),
Color::GREEN
);
$console->write('=', Color::GREEN);
$console->write(
str_pad(
'' . $this->name . ' - ' . $this->slogan
. ' (Version ' . $this->version . ')',
$console->getWidth() - 3,
' ',
STR_PAD_BOTH
)
);
$console->writeLine('=', Color::GREEN);
$console->writeLine(
str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT),
Color::GREEN
);
$console->writeLine();
} | [
"public",
"function",
"writeApplicationBanner",
"(",
"AdapterInterface",
"$",
"console",
")",
"{",
"$",
"console",
"->",
"writeLine",
"(",
")",
";",
"$",
"console",
"->",
"writeLine",
"(",
"str_pad",
"(",
"''",
",",
"$",
"console",
"->",
"getWidth",
"(",
")",
"-",
"1",
",",
"'='",
",",
"STR_PAD_RIGHT",
")",
",",
"Color",
"::",
"GREEN",
")",
";",
"$",
"console",
"->",
"write",
"(",
"'='",
",",
"Color",
"::",
"GREEN",
")",
";",
"$",
"console",
"->",
"write",
"(",
"str_pad",
"(",
"''",
".",
"$",
"this",
"->",
"name",
".",
"' - '",
".",
"$",
"this",
"->",
"slogan",
".",
"' (Version '",
".",
"$",
"this",
"->",
"version",
".",
"')'",
",",
"$",
"console",
"->",
"getWidth",
"(",
")",
"-",
"3",
",",
"' '",
",",
"STR_PAD_BOTH",
")",
")",
";",
"$",
"console",
"->",
"writeLine",
"(",
"'='",
",",
"Color",
"::",
"GREEN",
")",
";",
"$",
"console",
"->",
"writeLine",
"(",
"str_pad",
"(",
"''",
",",
"$",
"console",
"->",
"getWidth",
"(",
")",
"-",
"1",
",",
"'='",
",",
"STR_PAD_RIGHT",
")",
",",
"Color",
"::",
"GREEN",
")",
";",
"$",
"console",
"->",
"writeLine",
"(",
")",
";",
"}"
] | Write application banner
@param AdapterInterface $console | [
"Write",
"application",
"banner"
] | 8be56b82f9f5a687619a2b2175fcaa66ad3d2233 | https://github.com/ZFrapid/zfrapid-core/blob/8be56b82f9f5a687619a2b2175fcaa66ad3d2233/src/Console/Application.php#L168-L195 | train |
ZFrapid/zfrapid-core | src/Console/Application.php | Application.writeApplicationFooter | public function writeApplicationFooter(AdapterInterface $console)
{
$console->writeLine(
str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT),
Color::GREEN
);
$console->writeLine();
} | php | public function writeApplicationFooter(AdapterInterface $console)
{
$console->writeLine(
str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT),
Color::GREEN
);
$console->writeLine();
} | [
"public",
"function",
"writeApplicationFooter",
"(",
"AdapterInterface",
"$",
"console",
")",
"{",
"$",
"console",
"->",
"writeLine",
"(",
"str_pad",
"(",
"''",
",",
"$",
"console",
"->",
"getWidth",
"(",
")",
"-",
"1",
",",
"'='",
",",
"STR_PAD_RIGHT",
")",
",",
"Color",
"::",
"GREEN",
")",
";",
"$",
"console",
"->",
"writeLine",
"(",
")",
";",
"}"
] | Write application footer
@param AdapterInterface $console | [
"Write",
"application",
"footer"
] | 8be56b82f9f5a687619a2b2175fcaa66ad3d2233 | https://github.com/ZFrapid/zfrapid-core/blob/8be56b82f9f5a687619a2b2175fcaa66ad3d2233/src/Console/Application.php#L202-L210 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/inputclean/InputClean.php | InputClean.clean | public function clean($string, $allowedTags = null)
{
if (is_array($string)) {
$new_array = array();
foreach ($string as $key => $val) {
$new_array[$key] = $this->clean($val, $allowedTags);
}
return $new_array;
}
$string = $this->cleanHTMLPurify($string, $allowedTags);
return str_replace(array("\r\n", "\r"), "\n", $string);
} | php | public function clean($string, $allowedTags = null)
{
if (is_array($string)) {
$new_array = array();
foreach ($string as $key => $val) {
$new_array[$key] = $this->clean($val, $allowedTags);
}
return $new_array;
}
$string = $this->cleanHTMLPurify($string, $allowedTags);
return str_replace(array("\r\n", "\r"), "\n", $string);
} | [
"public",
"function",
"clean",
"(",
"$",
"string",
",",
"$",
"allowedTags",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"$",
"new_array",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"string",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"new_array",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"clean",
"(",
"$",
"val",
",",
"$",
"allowedTags",
")",
";",
"}",
"return",
"$",
"new_array",
";",
"}",
"$",
"string",
"=",
"$",
"this",
"->",
"cleanHTMLPurify",
"(",
"$",
"string",
",",
"$",
"allowedTags",
")",
";",
"return",
"str_replace",
"(",
"array",
"(",
"\"\\r\\n\"",
",",
"\"\\r\"",
")",
",",
"\"\\n\"",
",",
"$",
"string",
")",
";",
"}"
] | Cleans XSS by removing all tags
@param string $string to clean
@return string cleaned | [
"Cleans",
"XSS",
"by",
"removing",
"all",
"tags"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/inputclean/InputClean.php#L94-L107 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/inputclean/InputClean.php | InputClean.cleanHTMLPurify | protected function cleanHTMLPurify($string, $allowedTags = null)
{
if(strlen($string)==0)
return '';
if($allowedTags === null)
$allowedTags = $this->defaultAllowedTags;
if($allowedTags == '*')
return $string;
if(is_null($this->purifier))
{
require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php';
$this->purifier = HTMLPurifier::instance();
FileSystemUtils::recursiveMkdir($this->vendorCacheDirectory.'/purifier/');
}
$string = $this->purifier->purify($string, array(
'Core.Encoding' => $this->charset,
'HTML.TidyLevel' =>'none',
'HTML.Allowed' => $allowedTags,
'AutoFormat.AutoParagraph' => false,
//'HTML.Doctype' => 'XHTML 1.0 Transitional',
'Cache.SerializerPath' => $this->vendorCacheDirectory.'/purifier/'
));
// $string = html_entity_decode($string, ENT_COMPAT, $this->charset);
return $string;
} | php | protected function cleanHTMLPurify($string, $allowedTags = null)
{
if(strlen($string)==0)
return '';
if($allowedTags === null)
$allowedTags = $this->defaultAllowedTags;
if($allowedTags == '*')
return $string;
if(is_null($this->purifier))
{
require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php';
$this->purifier = HTMLPurifier::instance();
FileSystemUtils::recursiveMkdir($this->vendorCacheDirectory.'/purifier/');
}
$string = $this->purifier->purify($string, array(
'Core.Encoding' => $this->charset,
'HTML.TidyLevel' =>'none',
'HTML.Allowed' => $allowedTags,
'AutoFormat.AutoParagraph' => false,
//'HTML.Doctype' => 'XHTML 1.0 Transitional',
'Cache.SerializerPath' => $this->vendorCacheDirectory.'/purifier/'
));
// $string = html_entity_decode($string, ENT_COMPAT, $this->charset);
return $string;
} | [
"protected",
"function",
"cleanHTMLPurify",
"(",
"$",
"string",
",",
"$",
"allowedTags",
"=",
"null",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"string",
")",
"==",
"0",
")",
"return",
"''",
";",
"if",
"(",
"$",
"allowedTags",
"===",
"null",
")",
"$",
"allowedTags",
"=",
"$",
"this",
"->",
"defaultAllowedTags",
";",
"if",
"(",
"$",
"allowedTags",
"==",
"'*'",
")",
"return",
"$",
"string",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"purifier",
")",
")",
"{",
"require_once",
"PATH_SYSTEM",
".",
"'/vendors/HTMLPurifier.php'",
";",
"$",
"this",
"->",
"purifier",
"=",
"HTMLPurifier",
"::",
"instance",
"(",
")",
";",
"FileSystemUtils",
"::",
"recursiveMkdir",
"(",
"$",
"this",
"->",
"vendorCacheDirectory",
".",
"'/purifier/'",
")",
";",
"}",
"$",
"string",
"=",
"$",
"this",
"->",
"purifier",
"->",
"purify",
"(",
"$",
"string",
",",
"array",
"(",
"'Core.Encoding'",
"=>",
"$",
"this",
"->",
"charset",
",",
"'HTML.TidyLevel'",
"=>",
"'none'",
",",
"'HTML.Allowed'",
"=>",
"$",
"allowedTags",
",",
"'AutoFormat.AutoParagraph'",
"=>",
"false",
",",
"//'HTML.Doctype' => 'XHTML 1.0 Transitional',",
"'Cache.SerializerPath'",
"=>",
"$",
"this",
"->",
"vendorCacheDirectory",
".",
"'/purifier/'",
")",
")",
";",
"// $string = html_entity_decode($string, ENT_COMPAT, $this->charset);",
"return",
"$",
"string",
";",
"}"
] | Produces a nicely-formatted HTML string with all non-matching tags stripped.
@param string $string The HTML string to format
@param string $allowedTags A comma separated list of tags to allow in the result
@return string A nicely-formatted version of the input text, containing only the tags specified. | [
"Produces",
"a",
"nicely",
"-",
"formatted",
"HTML",
"string",
"with",
"all",
"non",
"-",
"matching",
"tags",
"stripped",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/inputclean/InputClean.php#L157-L190 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/inputclean/InputClean.php | InputClean.autoParagraph | public function autoParagraph($string, $allowedTags = null, $linkUrls = true)
{
if(is_null($allowedTags))
$allowedTags = $this->defaultAllowedTags;
if(is_null($this->purifier))
{
require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php';
$this->purifier = HTMLPurifier::instance();
FileSystemUtils::recursiveMkdir($this->vendorCacheDirectory.'/purifier/');
}
if ($this->injectors == null && $linkUrls)
$this->injectors = array(new CF_HTMLPurifier_Injector_Linkify());
$purifierConfig = array(
'Core.Encoding' => $this->charset,
'AutoFormat.AutoParagraph' => true,
'HTML.TidyLevel' =>'none',
'HTML.Allowed' => $allowedTags,
'Cache.SerializerPath' => $this->vendorCacheDirectory
);
if(!is_null($this->injectors))
$purifierConfig['AutoFormat.Custom'] = $this->injectors;
$string = $this->purifier->purify($string, $purifierConfig);
$string = str_replace("\n\n", '[DBLBR]', $string);
$string = str_replace("\n", '<br/>', $string);
$string = str_replace('[DBLBR]', "\n\n", $string);
// trim links
$string = preg_replace_callback("/\<a\s+href\=\"(".URLUtils::URL_MATCH.")\"\>\\1<\/a\>/Uix",
array($this, 'trimCallback'), $string);
// trim all words longer than 60 chars that aren't URLs, ignoring tags
if (preg_match_all("/\S60/", strip_tags(preg_replace('/(\<(\/?[^\>]+)\>)/', ' $1', $string)), $m)) {
foreach ($m[0] as $n) {
if( !preg_match("/".URLUtils::URL_MATCH."/", $n) )
$string = str_replace($n, trim(substr($n, 0, (60 - 3)), '.') . '...', $string);
}
}
return $string;
} | php | public function autoParagraph($string, $allowedTags = null, $linkUrls = true)
{
if(is_null($allowedTags))
$allowedTags = $this->defaultAllowedTags;
if(is_null($this->purifier))
{
require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php';
$this->purifier = HTMLPurifier::instance();
FileSystemUtils::recursiveMkdir($this->vendorCacheDirectory.'/purifier/');
}
if ($this->injectors == null && $linkUrls)
$this->injectors = array(new CF_HTMLPurifier_Injector_Linkify());
$purifierConfig = array(
'Core.Encoding' => $this->charset,
'AutoFormat.AutoParagraph' => true,
'HTML.TidyLevel' =>'none',
'HTML.Allowed' => $allowedTags,
'Cache.SerializerPath' => $this->vendorCacheDirectory
);
if(!is_null($this->injectors))
$purifierConfig['AutoFormat.Custom'] = $this->injectors;
$string = $this->purifier->purify($string, $purifierConfig);
$string = str_replace("\n\n", '[DBLBR]', $string);
$string = str_replace("\n", '<br/>', $string);
$string = str_replace('[DBLBR]', "\n\n", $string);
// trim links
$string = preg_replace_callback("/\<a\s+href\=\"(".URLUtils::URL_MATCH.")\"\>\\1<\/a\>/Uix",
array($this, 'trimCallback'), $string);
// trim all words longer than 60 chars that aren't URLs, ignoring tags
if (preg_match_all("/\S60/", strip_tags(preg_replace('/(\<(\/?[^\>]+)\>)/', ' $1', $string)), $m)) {
foreach ($m[0] as $n) {
if( !preg_match("/".URLUtils::URL_MATCH."/", $n) )
$string = str_replace($n, trim(substr($n, 0, (60 - 3)), '.') . '...', $string);
}
}
return $string;
} | [
"public",
"function",
"autoParagraph",
"(",
"$",
"string",
",",
"$",
"allowedTags",
"=",
"null",
",",
"$",
"linkUrls",
"=",
"true",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"allowedTags",
")",
")",
"$",
"allowedTags",
"=",
"$",
"this",
"->",
"defaultAllowedTags",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"purifier",
")",
")",
"{",
"require_once",
"PATH_SYSTEM",
".",
"'/vendors/HTMLPurifier.php'",
";",
"$",
"this",
"->",
"purifier",
"=",
"HTMLPurifier",
"::",
"instance",
"(",
")",
";",
"FileSystemUtils",
"::",
"recursiveMkdir",
"(",
"$",
"this",
"->",
"vendorCacheDirectory",
".",
"'/purifier/'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"injectors",
"==",
"null",
"&&",
"$",
"linkUrls",
")",
"$",
"this",
"->",
"injectors",
"=",
"array",
"(",
"new",
"CF_HTMLPurifier_Injector_Linkify",
"(",
")",
")",
";",
"$",
"purifierConfig",
"=",
"array",
"(",
"'Core.Encoding'",
"=>",
"$",
"this",
"->",
"charset",
",",
"'AutoFormat.AutoParagraph'",
"=>",
"true",
",",
"'HTML.TidyLevel'",
"=>",
"'none'",
",",
"'HTML.Allowed'",
"=>",
"$",
"allowedTags",
",",
"'Cache.SerializerPath'",
"=>",
"$",
"this",
"->",
"vendorCacheDirectory",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"injectors",
")",
")",
"$",
"purifierConfig",
"[",
"'AutoFormat.Custom'",
"]",
"=",
"$",
"this",
"->",
"injectors",
";",
"$",
"string",
"=",
"$",
"this",
"->",
"purifier",
"->",
"purify",
"(",
"$",
"string",
",",
"$",
"purifierConfig",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"\"\\n\\n\"",
",",
"'[DBLBR]'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"'<br/>'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"'[DBLBR]'",
",",
"\"\\n\\n\"",
",",
"$",
"string",
")",
";",
"// trim links",
"$",
"string",
"=",
"preg_replace_callback",
"(",
"\"/\\<a\\s+href\\=\\\"(\"",
".",
"URLUtils",
"::",
"URL_MATCH",
".",
"\")\\\"\\>\\\\1<\\/a\\>/Uix\"",
",",
"array",
"(",
"$",
"this",
",",
"'trimCallback'",
")",
",",
"$",
"string",
")",
";",
"// trim all words longer than 60 chars that aren't URLs, ignoring tags",
"if",
"(",
"preg_match_all",
"(",
"\"/\\S60/\"",
",",
"strip_tags",
"(",
"preg_replace",
"(",
"'/(\\<(\\/?[^\\>]+)\\>)/'",
",",
"' $1'",
",",
"$",
"string",
")",
")",
",",
"$",
"m",
")",
")",
"{",
"foreach",
"(",
"$",
"m",
"[",
"0",
"]",
"as",
"$",
"n",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"\"/\"",
".",
"URLUtils",
"::",
"URL_MATCH",
".",
"\"/\"",
",",
"$",
"n",
")",
")",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"n",
",",
"trim",
"(",
"substr",
"(",
"$",
"n",
",",
"0",
",",
"(",
"60",
"-",
"3",
")",
")",
",",
"'.'",
")",
".",
"'...'",
",",
"$",
"string",
")",
";",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] | Marks up a string with paragraphs and automatically links any urls.
This function marks up the output with paragraph tags and auto-links any URLs that are found.
The resulting output is suitable for display in any web-browser, but must have
paragraph and extra html tags removed before it's ready for editing.
Content is XSS cleaned and stripped of all but a few tags (specified by implementation.)
@param string $string The HTML string to format
@param string $allowedTags (optional) A comma-separated list of allowed tags.
@return string A nicely-formatted version of the input text, with automatic paragraphs and urls in place
@see unAutoParagraph() | [
"Marks",
"up",
"a",
"string",
"with",
"paragraphs",
"and",
"automatically",
"links",
"any",
"urls",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/inputclean/InputClean.php#L209-L258 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/inputclean/InputClean.php | InputClean.unAutoParagraph | public function unAutoParagraph($string)
{
$string = str_replace(array("<p>","</p>","<br/>", "<br />"), array("", "\n\n", "\n", "\n"), $string);
$string = preg_replace("/\<a href\=\"(".URLUtils::URL_MATCH.")\"\>\\1\<\/a\>/i", '$1', $string);
$string = preg_replace_callback("/\<a href\=\"(".URLUtils::URL_MATCH.")\"\>(.+)\.\.\.\<\/a\>/iU",
array($this, 'linkMatches'), $string);
return $string;
} | php | public function unAutoParagraph($string)
{
$string = str_replace(array("<p>","</p>","<br/>", "<br />"), array("", "\n\n", "\n", "\n"), $string);
$string = preg_replace("/\<a href\=\"(".URLUtils::URL_MATCH.")\"\>\\1\<\/a\>/i", '$1', $string);
$string = preg_replace_callback("/\<a href\=\"(".URLUtils::URL_MATCH.")\"\>(.+)\.\.\.\<\/a\>/iU",
array($this, 'linkMatches'), $string);
return $string;
} | [
"public",
"function",
"unAutoParagraph",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"array",
"(",
"\"<p>\"",
",",
"\"</p>\"",
",",
"\"<br/>\"",
",",
"\"<br />\"",
")",
",",
"array",
"(",
"\"\"",
",",
"\"\\n\\n\"",
",",
"\"\\n\"",
",",
"\"\\n\"",
")",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/\\<a href\\=\\\"(\"",
".",
"URLUtils",
"::",
"URL_MATCH",
".",
"\")\\\"\\>\\\\1\\<\\/a\\>/i\"",
",",
"'$1'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace_callback",
"(",
"\"/\\<a href\\=\\\"(\"",
".",
"URLUtils",
"::",
"URL_MATCH",
".",
"\")\\\"\\>(.+)\\.\\.\\.\\<\\/a\\>/iU\"",
",",
"array",
"(",
"$",
"this",
",",
"'linkMatches'",
")",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Removes the markup added by autoParagraph.
This will restore the string to a version that's safe to display in a simple <textarea> editor.
All autolinked urls are unlinked and paragraph tags are removed.
@param string $string The string that will be deconverted
@return string A version of $string suitable for editing in a <textarea>
@see autoParagraph() | [
"Removes",
"the",
"markup",
"added",
"by",
"autoParagraph",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/inputclean/InputClean.php#L291-L300 | train |
codeblanche/Entity | src/Entity/Utils.php | Utils.makeSetterGetterDoc | public static function makeSetterGetterDoc(Entity $entity)
{
$properties = $entity->toArray(false);
$entityName = $entity->calledClassName();
echo "<pre>\n";
foreach ($properties as $name => $value) {
$methodName = ucfirst($name);
$type = $entity->typeof($name);
echo " * @method $entityName set$methodName($type \$value)\n";
echo " * @method $type get$methodName()\n";
}
echo "</pre>\n";
} | php | public static function makeSetterGetterDoc(Entity $entity)
{
$properties = $entity->toArray(false);
$entityName = $entity->calledClassName();
echo "<pre>\n";
foreach ($properties as $name => $value) {
$methodName = ucfirst($name);
$type = $entity->typeof($name);
echo " * @method $entityName set$methodName($type \$value)\n";
echo " * @method $type get$methodName()\n";
}
echo "</pre>\n";
} | [
"public",
"static",
"function",
"makeSetterGetterDoc",
"(",
"Entity",
"$",
"entity",
")",
"{",
"$",
"properties",
"=",
"$",
"entity",
"->",
"toArray",
"(",
"false",
")",
";",
"$",
"entityName",
"=",
"$",
"entity",
"->",
"calledClassName",
"(",
")",
";",
"echo",
"\"<pre>\\n\"",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"methodName",
"=",
"ucfirst",
"(",
"$",
"name",
")",
";",
"$",
"type",
"=",
"$",
"entity",
"->",
"typeof",
"(",
"$",
"name",
")",
";",
"echo",
"\" * @method $entityName set$methodName($type \\$value)\\n\"",
";",
"echo",
"\" * @method $type get$methodName()\\n\"",
";",
"}",
"echo",
"\"</pre>\\n\"",
";",
"}"
] | Generate the setter and getter method PHPDoc declaration to paste into your entity class.
@param Entity $entity | [
"Generate",
"the",
"setter",
"and",
"getter",
"method",
"PHPDoc",
"declaration",
"to",
"paste",
"into",
"your",
"entity",
"class",
"."
] | 1d3839c09d7639ae8bbfc9d2721223202f3a5cdd | https://github.com/codeblanche/Entity/blob/1d3839c09d7639ae8bbfc9d2721223202f3a5cdd/src/Entity/Utils.php#L20-L35 | train |
codeblanche/Entity | src/Entity/Utils.php | Utils.makePublicProperties | public static function makePublicProperties(array $properties)
{
echo '<pre>'."\n";
foreach ($properties as $key => $value)
{
$type = gettype($value);
if ($type === 'object') {
$type = get_class($value);
}
echo <<<EODOC
/**
* @var $type
*/
public \$$key;
EODOC;
}
echo '</pre>'."\n";
} | php | public static function makePublicProperties(array $properties)
{
echo '<pre>'."\n";
foreach ($properties as $key => $value)
{
$type = gettype($value);
if ($type === 'object') {
$type = get_class($value);
}
echo <<<EODOC
/**
* @var $type
*/
public \$$key;
EODOC;
}
echo '</pre>'."\n";
} | [
"public",
"static",
"function",
"makePublicProperties",
"(",
"array",
"$",
"properties",
")",
"{",
"echo",
"'<pre>'",
".",
"\"\\n\"",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"type",
"===",
"'object'",
")",
"{",
"$",
"type",
"=",
"get_class",
"(",
"$",
"value",
")",
";",
"}",
"echo",
" <<<EODOC\n /**\n * @var $type\n */\n public \\$$key;\n\nEODOC",
";",
"}",
"echo",
"'</pre>'",
".",
"\"\\n\"",
";",
"}"
] | Generate the public properties PHPDoc declarations to paste into your entity class.
@param array $properties | [
"Generate",
"the",
"public",
"properties",
"PHPDoc",
"declarations",
"to",
"paste",
"into",
"your",
"entity",
"class",
"."
] | 1d3839c09d7639ae8bbfc9d2721223202f3a5cdd | https://github.com/codeblanche/Entity/blob/1d3839c09d7639ae8bbfc9d2721223202f3a5cdd/src/Entity/Utils.php#L41-L63 | train |
covex-nn/JooS | src/JooS/Event/Event.php | Event.getInstance | final public static function getInstance()
{
$className = get_called_class();
if (!isset(self::$_instances[$className])) {
self::$_instances[$className] = new static();
}
self::$_instances[$className]->initialize();
return self::$_instances[$className];
} | php | final public static function getInstance()
{
$className = get_called_class();
if (!isset(self::$_instances[$className])) {
self::$_instances[$className] = new static();
}
self::$_instances[$className]->initialize();
return self::$_instances[$className];
} | [
"final",
"public",
"static",
"function",
"getInstance",
"(",
")",
"{",
"$",
"className",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
"=",
"new",
"static",
"(",
")",
";",
"}",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
"->",
"initialize",
"(",
")",
";",
"return",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
";",
"}"
] | Return event instance
@return Event | [
"Return",
"event",
"instance"
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Event/Event.php#L63-L73 | train |
covex-nn/JooS | src/JooS/Event/Event.php | Event.clearInstance | final public static function clearInstance($className)
{
if (isset(self::$_instances[$className])) {
$name = self::_configName($className);
Config::clearInstance($name);
self::$_instances[$className]->_loadObservers();
}
} | php | final public static function clearInstance($className)
{
if (isset(self::$_instances[$className])) {
$name = self::_configName($className);
Config::clearInstance($name);
self::$_instances[$className]->_loadObservers();
}
} | [
"final",
"public",
"static",
"function",
"clearInstance",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"_configName",
"(",
"$",
"className",
")",
";",
"Config",
"::",
"clearInstance",
"(",
"$",
"name",
")",
";",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
"->",
"_loadObservers",
"(",
")",
";",
"}",
"}"
] | Unloads event instance.
@param string $className Event name
@return null | [
"Unloads",
"event",
"instance",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Event/Event.php#L82-L90 | train |
covex-nn/JooS | src/JooS/Event/Event.php | Event.notify | final public function notify()
{
$observers = array_values($this->_observers);
foreach ($observers as $observer) {
switch (false) {
case is_array($observer):
case isset($observer[0]):
case isset($observer[1]):
case is_string($observer[0]):
break;
default:
Loader::loadClass($observer[0]);
break;
}
if (!is_callable($observer)) {
continue;
}
call_user_func($observer, $this);
}
return $this;
} | php | final public function notify()
{
$observers = array_values($this->_observers);
foreach ($observers as $observer) {
switch (false) {
case is_array($observer):
case isset($observer[0]):
case isset($observer[1]):
case is_string($observer[0]):
break;
default:
Loader::loadClass($observer[0]);
break;
}
if (!is_callable($observer)) {
continue;
}
call_user_func($observer, $this);
}
return $this;
} | [
"final",
"public",
"function",
"notify",
"(",
")",
"{",
"$",
"observers",
"=",
"array_values",
"(",
"$",
"this",
"->",
"_observers",
")",
";",
"foreach",
"(",
"$",
"observers",
"as",
"$",
"observer",
")",
"{",
"switch",
"(",
"false",
")",
"{",
"case",
"is_array",
"(",
"$",
"observer",
")",
":",
"case",
"isset",
"(",
"$",
"observer",
"[",
"0",
"]",
")",
":",
"case",
"isset",
"(",
"$",
"observer",
"[",
"1",
"]",
")",
":",
"case",
"is_string",
"(",
"$",
"observer",
"[",
"0",
"]",
")",
":",
"break",
";",
"default",
":",
"Loader",
"::",
"loadClass",
"(",
"$",
"observer",
"[",
"0",
"]",
")",
";",
"break",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"observer",
")",
")",
"{",
"continue",
";",
"}",
"call_user_func",
"(",
"$",
"observer",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Notify observers.
@return Event | [
"Notify",
"observers",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Event/Event.php#L111-L134 | train |
covex-nn/JooS | src/JooS/Event/Event.php | Event.attach | final public function attach($observer)
{
if (!in_array($observer, $this->_observers)) {
array_push($this->_observers, $observer);
}
return $this;
} | php | final public function attach($observer)
{
if (!in_array($observer, $this->_observers)) {
array_push($this->_observers, $observer);
}
return $this;
} | [
"final",
"public",
"function",
"attach",
"(",
"$",
"observer",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"observer",
",",
"$",
"this",
"->",
"_observers",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"_observers",
",",
"$",
"observer",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Attach new observer.
@param callback $observer Observer
@return Event | [
"Attach",
"new",
"observer",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Event/Event.php#L143-L149 | train |
covex-nn/JooS | src/JooS/Event/Event.php | Event.detach | final public function detach($observer)
{
$key = array_search($observer, $this->_observers);
if ($key !== false) {
unset($this->_observers[$key]);
}
return $this;
} | php | final public function detach($observer)
{
$key = array_search($observer, $this->_observers);
if ($key !== false) {
unset($this->_observers[$key]);
}
return $this;
} | [
"final",
"public",
"function",
"detach",
"(",
"$",
"observer",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"observer",
",",
"$",
"this",
"->",
"_observers",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_observers",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Detach observer.
@param callback $observer Observer
@return Event | [
"Detach",
"observer",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Event/Event.php#L158-L165 | train |
covex-nn/JooS | src/JooS/Event/Event.php | Event._loadObservers | private function _loadObservers()
{
$class = $this->name();
$name = self::_configName($class);
$config = Config::getInstance($name);
$this->_observers = $config->valueOf();
} | php | private function _loadObservers()
{
$class = $this->name();
$name = self::_configName($class);
$config = Config::getInstance($name);
$this->_observers = $config->valueOf();
} | [
"private",
"function",
"_loadObservers",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"name",
"(",
")",
";",
"$",
"name",
"=",
"self",
"::",
"_configName",
"(",
"$",
"class",
")",
";",
"$",
"config",
"=",
"Config",
"::",
"getInstance",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"_observers",
"=",
"$",
"config",
"->",
"valueOf",
"(",
")",
";",
"}"
] | Load observers.
@return null | [
"Load",
"observers",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Event/Event.php#L208-L215 | train |
jamset/commands-executor | src/CommandsManager.php | CommandsManager.getSystemLoadInfo | public function getSystemLoadInfo()
{
$cpuMemDto = new CpuMemDto();
$cpuMemDto = $this->getMemFree($cpuMemDto);
$cpuMemDto = $this->getCpuIdle($cpuMemDto);
return $cpuMemDto;
} | php | public function getSystemLoadInfo()
{
$cpuMemDto = new CpuMemDto();
$cpuMemDto = $this->getMemFree($cpuMemDto);
$cpuMemDto = $this->getCpuIdle($cpuMemDto);
return $cpuMemDto;
} | [
"public",
"function",
"getSystemLoadInfo",
"(",
")",
"{",
"$",
"cpuMemDto",
"=",
"new",
"CpuMemDto",
"(",
")",
";",
"$",
"cpuMemDto",
"=",
"$",
"this",
"->",
"getMemFree",
"(",
"$",
"cpuMemDto",
")",
";",
"$",
"cpuMemDto",
"=",
"$",
"this",
"->",
"getCpuIdle",
"(",
"$",
"cpuMemDto",
")",
";",
"return",
"$",
"cpuMemDto",
";",
"}"
] | Get current cpu idle and memory free
@return CpuMemDto | [
"Get",
"current",
"cpu",
"idle",
"and",
"memory",
"free"
] | 5cca74fdd36d30e83dfae7c8c2457a00c8855d4f | https://github.com/jamset/commands-executor/blob/5cca74fdd36d30e83dfae7c8c2457a00c8855d4f/src/CommandsManager.php#L52-L60 | train |
jamset/commands-executor | src/CommandsManager.php | CommandsManager.getPidByPpid | public function getPidByPpid($ppid)
{
$commandsDto = new CommandsExecutionDto();
$commandsDto->setCommandName(CommandsConstants::GET_PID_BY_PPID);
$commandsDto->setPid($ppid);
return $this->getCommandExecutionResult($commandsDto);
} | php | public function getPidByPpid($ppid)
{
$commandsDto = new CommandsExecutionDto();
$commandsDto->setCommandName(CommandsConstants::GET_PID_BY_PPID);
$commandsDto->setPid($ppid);
return $this->getCommandExecutionResult($commandsDto);
} | [
"public",
"function",
"getPidByPpid",
"(",
"$",
"ppid",
")",
"{",
"$",
"commandsDto",
"=",
"new",
"CommandsExecutionDto",
"(",
")",
";",
"$",
"commandsDto",
"->",
"setCommandName",
"(",
"CommandsConstants",
"::",
"GET_PID_BY_PPID",
")",
";",
"$",
"commandsDto",
"->",
"setPid",
"(",
"$",
"ppid",
")",
";",
"return",
"$",
"this",
"->",
"getCommandExecutionResult",
"(",
"$",
"commandsDto",
")",
";",
"}"
] | Return PID of the child's process by parent PID
@param $pid | [
"Return",
"PID",
"of",
"the",
"child",
"s",
"process",
"by",
"parent",
"PID"
] | 5cca74fdd36d30e83dfae7c8c2457a00c8855d4f | https://github.com/jamset/commands-executor/blob/5cca74fdd36d30e83dfae7c8c2457a00c8855d4f/src/CommandsManager.php#L93-L100 | train |
php-api-clients/installer | src/Filesystem.php | Filesystem.write | public function write(string $filename, string $contents): int
{
return (int)file_put_contents($filename, $contents);
} | php | public function write(string $filename, string $contents): int
{
return (int)file_put_contents($filename, $contents);
} | [
"public",
"function",
"write",
"(",
"string",
"$",
"filename",
",",
"string",
"$",
"contents",
")",
":",
"int",
"{",
"return",
"(",
"int",
")",
"file_put_contents",
"(",
"$",
"filename",
",",
"$",
"contents",
")",
";",
"}"
] | Write the given contents to the given file.
@param string $filename
@param string $contents
@return int | [
"Write",
"the",
"given",
"contents",
"to",
"the",
"given",
"file",
"."
] | 5d5a936520ff2261cf94882b335c2d1d7ea4dda2 | https://github.com/php-api-clients/installer/blob/5d5a936520ff2261cf94882b335c2d1d7ea4dda2/src/Filesystem.php#L25-L28 | train |
php-api-clients/installer | src/Filesystem.php | Filesystem.ls | public function ls(string $path): array
{
$files = [];
$d = dir($path);
while (false !== ($entry = $d->read())) {
if (in_array($entry, ['.', '..'], true)) {
continue;
}
$entryPath = $path . $entry;
if (is_dir($entryPath)) {
foreach ($this->ls($entryPath . DIRECTORY_SEPARATOR) as $entryPath) {
$files[] = $entryPath;
}
continue;
}
if (!is_file($entryPath)) {
continue;
}
$files[] = $entryPath;
}
$d->close();
return $files;
} | php | public function ls(string $path): array
{
$files = [];
$d = dir($path);
while (false !== ($entry = $d->read())) {
if (in_array($entry, ['.', '..'], true)) {
continue;
}
$entryPath = $path . $entry;
if (is_dir($entryPath)) {
foreach ($this->ls($entryPath . DIRECTORY_SEPARATOR) as $entryPath) {
$files[] = $entryPath;
}
continue;
}
if (!is_file($entryPath)) {
continue;
}
$files[] = $entryPath;
}
$d->close();
return $files;
} | [
"public",
"function",
"ls",
"(",
"string",
"$",
"path",
")",
":",
"array",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"d",
"=",
"dir",
"(",
"$",
"path",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"entry",
"=",
"$",
"d",
"->",
"read",
"(",
")",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"entry",
",",
"[",
"'.'",
",",
"'..'",
"]",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"$",
"entryPath",
"=",
"$",
"path",
".",
"$",
"entry",
";",
"if",
"(",
"is_dir",
"(",
"$",
"entryPath",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"ls",
"(",
"$",
"entryPath",
".",
"DIRECTORY_SEPARATOR",
")",
"as",
"$",
"entryPath",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"entryPath",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"!",
"is_file",
"(",
"$",
"entryPath",
")",
")",
"{",
"continue",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"$",
"entryPath",
";",
"}",
"$",
"d",
"->",
"close",
"(",
")",
";",
"return",
"$",
"files",
";",
"}"
] | List all files in a directory and it's subdirectories.
@param string $path
@return array | [
"List",
"all",
"files",
"in",
"a",
"directory",
"and",
"it",
"s",
"subdirectories",
"."
] | 5d5a936520ff2261cf94882b335c2d1d7ea4dda2 | https://github.com/php-api-clients/installer/blob/5d5a936520ff2261cf94882b335c2d1d7ea4dda2/src/Filesystem.php#L36-L59 | train |
geoffadams/bedrest-core | library/BedRest/Content/Negotiation/QualityFactorList.php | QualityFactorList.qualityFactorComparator | public function qualityFactorComparator($mediaType1, $mediaType2)
{
$diff = $mediaType2['q'] - $mediaType1['q'];
// doesn't cope too well with values 1 > v > -1, so make sure we return simple integers
if ($diff > 0) {
$diff = 1;
} elseif ($diff < 0) {
$diff = -1;
}
return $diff;
} | php | public function qualityFactorComparator($mediaType1, $mediaType2)
{
$diff = $mediaType2['q'] - $mediaType1['q'];
// doesn't cope too well with values 1 > v > -1, so make sure we return simple integers
if ($diff > 0) {
$diff = 1;
} elseif ($diff < 0) {
$diff = -1;
}
return $diff;
} | [
"public",
"function",
"qualityFactorComparator",
"(",
"$",
"mediaType1",
",",
"$",
"mediaType2",
")",
"{",
"$",
"diff",
"=",
"$",
"mediaType2",
"[",
"'q'",
"]",
"-",
"$",
"mediaType1",
"[",
"'q'",
"]",
";",
"// doesn't cope too well with values 1 > v > -1, so make sure we return simple integers",
"if",
"(",
"$",
"diff",
">",
"0",
")",
"{",
"$",
"diff",
"=",
"1",
";",
"}",
"elseif",
"(",
"$",
"diff",
"<",
"0",
")",
"{",
"$",
"diff",
"=",
"-",
"1",
";",
"}",
"return",
"$",
"diff",
";",
"}"
] | Comparator function for sorting a list of arrays by their 'q' factor.
@param array $mediaType1
@param array $mediaType2
@return integer | [
"Comparator",
"function",
"for",
"sorting",
"a",
"list",
"of",
"arrays",
"by",
"their",
"q",
"factor",
"."
] | a77bf8b7492dfbfb720b201f7ec91a4f03417b5c | https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Content/Negotiation/QualityFactorList.php#L80-L92 | train |
pixelpolishers/makedocs | src/MakeDocs/Generator/AssetManager.php | AssetManager.addAsset | public function addAsset($name, $path)
{
if (!is_file($path)) {
throw new \RuntimeException('The asset file "' . $path . '" does not exist.');
}
$this->assets[$name] = $path;
} | php | public function addAsset($name, $path)
{
if (!is_file($path)) {
throw new \RuntimeException('The asset file "' . $path . '" does not exist.');
}
$this->assets[$name] = $path;
} | [
"public",
"function",
"addAsset",
"(",
"$",
"name",
",",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'The asset file \"'",
".",
"$",
"path",
".",
"'\" does not exist.'",
")",
";",
"}",
"$",
"this",
"->",
"assets",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
";",
"}"
] | Adds an asset.
@param string $name The name of the asset.
@param string $path The path to the asset.
@throws \RuntimeException | [
"Adds",
"an",
"asset",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Generator/AssetManager.php#L35-L41 | train |
pixelpolishers/makedocs | src/MakeDocs/Generator/AssetManager.php | AssetManager.copyTo | public function copyTo($path)
{
foreach ($this->assets as $assetName => $assetPath) {
$outputPath = $path . '/' . $assetName;
$this->copyFromTo($assetPath, $outputPath);
}
} | php | public function copyTo($path)
{
foreach ($this->assets as $assetName => $assetPath) {
$outputPath = $path . '/' . $assetName;
$this->copyFromTo($assetPath, $outputPath);
}
} | [
"public",
"function",
"copyTo",
"(",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"assets",
"as",
"$",
"assetName",
"=>",
"$",
"assetPath",
")",
"{",
"$",
"outputPath",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"assetName",
";",
"$",
"this",
"->",
"copyFromTo",
"(",
"$",
"assetPath",
",",
"$",
"outputPath",
")",
";",
"}",
"}"
] | Copies all assets to the given path.
@param string $path The path to copy to. | [
"Copies",
"all",
"assets",
"to",
"the",
"given",
"path",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Generator/AssetManager.php#L48-L55 | train |
pixelpolishers/makedocs | src/MakeDocs/Generator/AssetManager.php | AssetManager.copyFromTo | private function copyFromTo($from, $to)
{
$directory = dirname($to);
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}
copy($from, $to);
} | php | private function copyFromTo($from, $to)
{
$directory = dirname($to);
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}
copy($from, $to);
} | [
"private",
"function",
"copyFromTo",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"$",
"directory",
"=",
"dirname",
"(",
"$",
"to",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"mkdir",
"(",
"$",
"directory",
",",
"0777",
",",
"true",
")",
";",
"}",
"copy",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"}"
] | Copies a single asset from a path to a path.
@param string $from The location to copy from.
@param string $to The location to copy to. | [
"Copies",
"a",
"single",
"asset",
"from",
"a",
"path",
"to",
"a",
"path",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Generator/AssetManager.php#L63-L71 | train |
vukbgit/PHPCraft.Subject | src/Traits/Upload/Field.php | Field.setInput | private function setInput()
{
$this->inputFile = $_FILES[$this->field]['name'];
$this->inputHash = hash_file('md5', $_FILES[$this->field]['tmp_name']);
} | php | private function setInput()
{
$this->inputFile = $_FILES[$this->field]['name'];
$this->inputHash = hash_file('md5', $_FILES[$this->field]['tmp_name']);
} | [
"private",
"function",
"setInput",
"(",
")",
"{",
"$",
"this",
"->",
"inputFile",
"=",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"field",
"]",
"[",
"'name'",
"]",
";",
"$",
"this",
"->",
"inputHash",
"=",
"hash_file",
"(",
"'md5'",
",",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"field",
"]",
"[",
"'tmp_name'",
"]",
")",
";",
"}"
] | Stores input informations | [
"Stores",
"input",
"informations"
] | a43ad7868098ff1e7bda6819547ea64f9a853732 | https://github.com/vukbgit/PHPCraft.Subject/blob/a43ad7868098ff1e7bda6819547ea64f9a853732/src/Traits/Upload/Field.php#L60-L64 | train |
vukbgit/PHPCraft.Subject | src/Traits/Upload/Field.php | Field.handleUpload | public function handleUpload(&$uploader)
{
// store uploader
$this->uploader =& $uploader;
//store input
$this->setInput();
// tell uploader which field is uploaded
$this->uploader->setField($this->field);
// make temporary file
$this->uploader->setDestination(sys_get_temp_dir());
// loop validation rules
foreach($this->validations as $validation) {
$options = isset($validation['options']) ? $validation['options'] : null;
$message = isset($validation['message']) ? $validation['message'] : null;
// set rule
$this->uploader->addValidationRule($validation['type'], $options, $message);
}
// upload
if(!$this->uploader->process()) {
// failure
return false;
}
// loop field outputs
$temporaryFile = sprintf('%s/%s', sys_get_temp_dir(), $this->uploader->getUploadedFileInfo()['name']);
foreach($this->outputs as $outputName => $output) {
$outputPath = $output->getDestination() . $this->uploader->getUploadedFileInfo()['name'];
if(is_file($outputPath)){
$outputPath = sprintf('%s%s_%s', $output->getDestination(), time(), $this->uploader->getUploadedFileInfo()['name']);
}
copy($temporaryFile, $outputPath);
$this->outputsFiles[$outputName] = [
'name' => $this->uploader->getUploadedFileInfo()['name'],
'path' => $outputPath
];
}
// delete temporary file
unlink($temporaryFile);
// close upload
$this->uploader->close();
return true;
} | php | public function handleUpload(&$uploader)
{
// store uploader
$this->uploader =& $uploader;
//store input
$this->setInput();
// tell uploader which field is uploaded
$this->uploader->setField($this->field);
// make temporary file
$this->uploader->setDestination(sys_get_temp_dir());
// loop validation rules
foreach($this->validations as $validation) {
$options = isset($validation['options']) ? $validation['options'] : null;
$message = isset($validation['message']) ? $validation['message'] : null;
// set rule
$this->uploader->addValidationRule($validation['type'], $options, $message);
}
// upload
if(!$this->uploader->process()) {
// failure
return false;
}
// loop field outputs
$temporaryFile = sprintf('%s/%s', sys_get_temp_dir(), $this->uploader->getUploadedFileInfo()['name']);
foreach($this->outputs as $outputName => $output) {
$outputPath = $output->getDestination() . $this->uploader->getUploadedFileInfo()['name'];
if(is_file($outputPath)){
$outputPath = sprintf('%s%s_%s', $output->getDestination(), time(), $this->uploader->getUploadedFileInfo()['name']);
}
copy($temporaryFile, $outputPath);
$this->outputsFiles[$outputName] = [
'name' => $this->uploader->getUploadedFileInfo()['name'],
'path' => $outputPath
];
}
// delete temporary file
unlink($temporaryFile);
// close upload
$this->uploader->close();
return true;
} | [
"public",
"function",
"handleUpload",
"(",
"&",
"$",
"uploader",
")",
"{",
"// store uploader",
"$",
"this",
"->",
"uploader",
"=",
"&",
"$",
"uploader",
";",
"//store input",
"$",
"this",
"->",
"setInput",
"(",
")",
";",
"// tell uploader which field is uploaded",
"$",
"this",
"->",
"uploader",
"->",
"setField",
"(",
"$",
"this",
"->",
"field",
")",
";",
"// make temporary file",
"$",
"this",
"->",
"uploader",
"->",
"setDestination",
"(",
"sys_get_temp_dir",
"(",
")",
")",
";",
"// loop validation rules",
"foreach",
"(",
"$",
"this",
"->",
"validations",
"as",
"$",
"validation",
")",
"{",
"$",
"options",
"=",
"isset",
"(",
"$",
"validation",
"[",
"'options'",
"]",
")",
"?",
"$",
"validation",
"[",
"'options'",
"]",
":",
"null",
";",
"$",
"message",
"=",
"isset",
"(",
"$",
"validation",
"[",
"'message'",
"]",
")",
"?",
"$",
"validation",
"[",
"'message'",
"]",
":",
"null",
";",
"// set rule",
"$",
"this",
"->",
"uploader",
"->",
"addValidationRule",
"(",
"$",
"validation",
"[",
"'type'",
"]",
",",
"$",
"options",
",",
"$",
"message",
")",
";",
"}",
"// upload",
"if",
"(",
"!",
"$",
"this",
"->",
"uploader",
"->",
"process",
"(",
")",
")",
"{",
"// failure",
"return",
"false",
";",
"}",
"// loop field outputs",
"$",
"temporaryFile",
"=",
"sprintf",
"(",
"'%s/%s'",
",",
"sys_get_temp_dir",
"(",
")",
",",
"$",
"this",
"->",
"uploader",
"->",
"getUploadedFileInfo",
"(",
")",
"[",
"'name'",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"outputs",
"as",
"$",
"outputName",
"=>",
"$",
"output",
")",
"{",
"$",
"outputPath",
"=",
"$",
"output",
"->",
"getDestination",
"(",
")",
".",
"$",
"this",
"->",
"uploader",
"->",
"getUploadedFileInfo",
"(",
")",
"[",
"'name'",
"]",
";",
"if",
"(",
"is_file",
"(",
"$",
"outputPath",
")",
")",
"{",
"$",
"outputPath",
"=",
"sprintf",
"(",
"'%s%s_%s'",
",",
"$",
"output",
"->",
"getDestination",
"(",
")",
",",
"time",
"(",
")",
",",
"$",
"this",
"->",
"uploader",
"->",
"getUploadedFileInfo",
"(",
")",
"[",
"'name'",
"]",
")",
";",
"}",
"copy",
"(",
"$",
"temporaryFile",
",",
"$",
"outputPath",
")",
";",
"$",
"this",
"->",
"outputsFiles",
"[",
"$",
"outputName",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"uploader",
"->",
"getUploadedFileInfo",
"(",
")",
"[",
"'name'",
"]",
",",
"'path'",
"=>",
"$",
"outputPath",
"]",
";",
"}",
"// delete temporary file",
"unlink",
"(",
"$",
"temporaryFile",
")",
";",
"// close upload",
"$",
"this",
"->",
"uploader",
"->",
"close",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Handles an upload
@param $uploader adapter following PHPCraft\Upload\UploadInterface | [
"Handles",
"an",
"upload"
] | a43ad7868098ff1e7bda6819547ea64f9a853732 | https://github.com/vukbgit/PHPCraft.Subject/blob/a43ad7868098ff1e7bda6819547ea64f9a853732/src/Traits/Upload/Field.php#L80-L120 | train |
Kris-Kuiper/sFire-Framework | src/Form/Types/Button.php | Button.text | public function text($text) {
if(false === is_string($text)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($text)), E_USER_ERROR);
}
$this -> text = $text;
return $this;
} | php | public function text($text) {
if(false === is_string($text)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($text)), E_USER_ERROR);
}
$this -> text = $text;
return $this;
} | [
"public",
"function",
"text",
"(",
"$",
"text",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"text",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"text",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"text",
"=",
"$",
"text",
";",
"return",
"$",
"this",
";",
"}"
] | Set the text of the button
@param string $text
@return sFire\Form\Types\Button | [
"Set",
"the",
"text",
"of",
"the",
"button"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Types/Button.php#L32-L41 | train |
t3v/t3v_core | Classes/Service/LanguageService.php | LanguageService.getLanguage | public function getLanguage(string $default = null): string {
$language = $default ?: 'en';
if (TYPO3_MODE === 'FE') {
if (isset($GLOBALS['TSFE']->lang)) {
$language = $GLOBALS['TSFE']->lang;
}
} elseif (is_object($GLOBALS['LANG'])) {
if (isset($GLOBALS['LANG']->lang)) {
$language = $GLOBALS['LANG']->lang;
}
}
// if (TYPO3_MODE === 'FE') {
// if (isset($GLOBALS['TSFE']->config['config']['language'])) {
// $language = $GLOBALS['TSFE']->config['config']['language'];
// }
// } elseif (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {
// $language = $GLOBALS['BE_USER']->uc['lang'];
// }
return $language;
} | php | public function getLanguage(string $default = null): string {
$language = $default ?: 'en';
if (TYPO3_MODE === 'FE') {
if (isset($GLOBALS['TSFE']->lang)) {
$language = $GLOBALS['TSFE']->lang;
}
} elseif (is_object($GLOBALS['LANG'])) {
if (isset($GLOBALS['LANG']->lang)) {
$language = $GLOBALS['LANG']->lang;
}
}
// if (TYPO3_MODE === 'FE') {
// if (isset($GLOBALS['TSFE']->config['config']['language'])) {
// $language = $GLOBALS['TSFE']->config['config']['language'];
// }
// } elseif (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {
// $language = $GLOBALS['BE_USER']->uc['lang'];
// }
return $language;
} | [
"public",
"function",
"getLanguage",
"(",
"string",
"$",
"default",
"=",
"null",
")",
":",
"string",
"{",
"$",
"language",
"=",
"$",
"default",
"?",
":",
"'en'",
";",
"if",
"(",
"TYPO3_MODE",
"===",
"'FE'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TSFE'",
"]",
"->",
"lang",
")",
")",
"{",
"$",
"language",
"=",
"$",
"GLOBALS",
"[",
"'TSFE'",
"]",
"->",
"lang",
";",
"}",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"GLOBALS",
"[",
"'LANG'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'LANG'",
"]",
"->",
"lang",
")",
")",
"{",
"$",
"language",
"=",
"$",
"GLOBALS",
"[",
"'LANG'",
"]",
"->",
"lang",
";",
"}",
"}",
"// if (TYPO3_MODE === 'FE') {",
"// if (isset($GLOBALS['TSFE']->config['config']['language'])) {",
"// $language = $GLOBALS['TSFE']->config['config']['language'];",
"// }",
"// } elseif (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {",
"// $language = $GLOBALS['BE_USER']->uc['lang'];",
"// }",
"return",
"$",
"language",
";",
"}"
] | Gets the current language.
@param string $default The default language, defaults to `en`
@return string The current language if available, otherwise the default one | [
"Gets",
"the",
"current",
"language",
"."
] | 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/LanguageService.php#L18-L40 | train |
t3v/t3v_core | Classes/Service/LanguageService.php | LanguageService.getLanguageUid | public function getLanguageUid(int $default = null): int {
$languageUid = $default ?: 0;
if (TYPO3_MODE === 'FE') {
if (isset($GLOBALS['TSFE']->sys_language_uid)) {
$languageUid = $GLOBALS['TSFE']->sys_language_uid;
}
} elseif (is_object($GLOBALS['LANG'])) {
if (isset($GLOBALS['LANG']->sys_language_uid)) {
$languageUid = $GLOBALS['LANG']->sys_language_uid;
}
}
return $languageUid;
} | php | public function getLanguageUid(int $default = null): int {
$languageUid = $default ?: 0;
if (TYPO3_MODE === 'FE') {
if (isset($GLOBALS['TSFE']->sys_language_uid)) {
$languageUid = $GLOBALS['TSFE']->sys_language_uid;
}
} elseif (is_object($GLOBALS['LANG'])) {
if (isset($GLOBALS['LANG']->sys_language_uid)) {
$languageUid = $GLOBALS['LANG']->sys_language_uid;
}
}
return $languageUid;
} | [
"public",
"function",
"getLanguageUid",
"(",
"int",
"$",
"default",
"=",
"null",
")",
":",
"int",
"{",
"$",
"languageUid",
"=",
"$",
"default",
"?",
":",
"0",
";",
"if",
"(",
"TYPO3_MODE",
"===",
"'FE'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TSFE'",
"]",
"->",
"sys_language_uid",
")",
")",
"{",
"$",
"languageUid",
"=",
"$",
"GLOBALS",
"[",
"'TSFE'",
"]",
"->",
"sys_language_uid",
";",
"}",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"GLOBALS",
"[",
"'LANG'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'LANG'",
"]",
"->",
"sys_language_uid",
")",
")",
"{",
"$",
"languageUid",
"=",
"$",
"GLOBALS",
"[",
"'LANG'",
"]",
"->",
"sys_language_uid",
";",
"}",
"}",
"return",
"$",
"languageUid",
";",
"}"
] | Gets the current language UID.
@param int $default The default language UID, defaults to `0`
@return int The current language UID if available, otherwise the default one | [
"Gets",
"the",
"current",
"language",
"UID",
"."
] | 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/LanguageService.php#L48-L62 | train |
brain-diminished/schema-version-control | src/SchemaVersionControlService.php | SchemaVersionControlService.loadSchemaFile | public function loadSchemaFile(): Schema
{
if (!file_exists($this->schemaFile)) {
return new Schema();
}
$content = file_get_contents($this->schemaFile);
$desc = Yaml::parse($content);
if (empty($desc)) {
return new Schema();
}
$builder = new SchemaBuilder();
return $builder->build($desc['schema']);
} | php | public function loadSchemaFile(): Schema
{
if (!file_exists($this->schemaFile)) {
return new Schema();
}
$content = file_get_contents($this->schemaFile);
$desc = Yaml::parse($content);
if (empty($desc)) {
return new Schema();
}
$builder = new SchemaBuilder();
return $builder->build($desc['schema']);
} | [
"public",
"function",
"loadSchemaFile",
"(",
")",
":",
"Schema",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"schemaFile",
")",
")",
"{",
"return",
"new",
"Schema",
"(",
")",
";",
"}",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"schemaFile",
")",
";",
"$",
"desc",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"content",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"desc",
")",
")",
"{",
"return",
"new",
"Schema",
"(",
")",
";",
"}",
"$",
"builder",
"=",
"new",
"SchemaBuilder",
"(",
")",
";",
"return",
"$",
"builder",
"->",
"build",
"(",
"$",
"desc",
"[",
"'schema'",
"]",
")",
";",
"}"
] | Load schema from config file.
@return Schema | [
"Load",
"schema",
"from",
"config",
"file",
"."
] | 215dd96394072720b61a682e10a55a6520470c46 | https://github.com/brain-diminished/schema-version-control/blob/215dd96394072720b61a682e10a55a6520470c46/src/SchemaVersionControlService.php#L52-L66 | train |
brain-diminished/schema-version-control | src/SchemaVersionControlService.php | SchemaVersionControlService.applySchema | public function applySchema(bool $strict = false): array
{
$sqlStatements = $this->getMigrationSql();
foreach ($sqlStatements as $sqlStatement) {
$this->connection->exec($sqlStatement);
}
if ($strict) {
$reorderSql = $this->reorderSql();
$sqlStatements = array_merge($sqlStatements, $reorderSql);
foreach ($reorderSql as $sqlStatement) {
$this->connection->exec($sqlStatement);
}
}
return $sqlStatements;
} | php | public function applySchema(bool $strict = false): array
{
$sqlStatements = $this->getMigrationSql();
foreach ($sqlStatements as $sqlStatement) {
$this->connection->exec($sqlStatement);
}
if ($strict) {
$reorderSql = $this->reorderSql();
$sqlStatements = array_merge($sqlStatements, $reorderSql);
foreach ($reorderSql as $sqlStatement) {
$this->connection->exec($sqlStatement);
}
}
return $sqlStatements;
} | [
"public",
"function",
"applySchema",
"(",
"bool",
"$",
"strict",
"=",
"false",
")",
":",
"array",
"{",
"$",
"sqlStatements",
"=",
"$",
"this",
"->",
"getMigrationSql",
"(",
")",
";",
"foreach",
"(",
"$",
"sqlStatements",
"as",
"$",
"sqlStatement",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"exec",
"(",
"$",
"sqlStatement",
")",
";",
"}",
"if",
"(",
"$",
"strict",
")",
"{",
"$",
"reorderSql",
"=",
"$",
"this",
"->",
"reorderSql",
"(",
")",
";",
"$",
"sqlStatements",
"=",
"array_merge",
"(",
"$",
"sqlStatements",
",",
"$",
"reorderSql",
")",
";",
"foreach",
"(",
"$",
"reorderSql",
"as",
"$",
"sqlStatement",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"exec",
"(",
"$",
"sqlStatement",
")",
";",
"}",
"}",
"return",
"$",
"sqlStatements",
";",
"}"
] | Alter schema in database, according to config file.
@return int | [
"Alter",
"schema",
"in",
"database",
"according",
"to",
"config",
"file",
"."
] | 215dd96394072720b61a682e10a55a6520470c46 | https://github.com/brain-diminished/schema-version-control/blob/215dd96394072720b61a682e10a55a6520470c46/src/SchemaVersionControlService.php#L72-L86 | train |
brain-diminished/schema-version-control | src/SchemaVersionControlService.php | SchemaVersionControlService.getSchemaDiff | public function getSchemaDiff(bool $reverseDiff = false): SchemaDiff
{
$currentSchema = $this->getCurrentSchema();
$newSchema = $this->loadSchemaFile();
$comparator = new Comparator();
if ($reverseDiff) {
return $comparator->compare($newSchema, $currentSchema);
} else {
return $comparator->compare($currentSchema, $newSchema);
}
} | php | public function getSchemaDiff(bool $reverseDiff = false): SchemaDiff
{
$currentSchema = $this->getCurrentSchema();
$newSchema = $this->loadSchemaFile();
$comparator = new Comparator();
if ($reverseDiff) {
return $comparator->compare($newSchema, $currentSchema);
} else {
return $comparator->compare($currentSchema, $newSchema);
}
} | [
"public",
"function",
"getSchemaDiff",
"(",
"bool",
"$",
"reverseDiff",
"=",
"false",
")",
":",
"SchemaDiff",
"{",
"$",
"currentSchema",
"=",
"$",
"this",
"->",
"getCurrentSchema",
"(",
")",
";",
"$",
"newSchema",
"=",
"$",
"this",
"->",
"loadSchemaFile",
"(",
")",
";",
"$",
"comparator",
"=",
"new",
"Comparator",
"(",
")",
";",
"if",
"(",
"$",
"reverseDiff",
")",
"{",
"return",
"$",
"comparator",
"->",
"compare",
"(",
"$",
"newSchema",
",",
"$",
"currentSchema",
")",
";",
"}",
"else",
"{",
"return",
"$",
"comparator",
"->",
"compare",
"(",
"$",
"currentSchema",
",",
"$",
"newSchema",
")",
";",
"}",
"}"
] | Get diff between current schema and config file
@return SchemaDiff | [
"Get",
"diff",
"between",
"current",
"schema",
"and",
"config",
"file"
] | 215dd96394072720b61a682e10a55a6520470c46 | https://github.com/brain-diminished/schema-version-control/blob/215dd96394072720b61a682e10a55a6520470c46/src/SchemaVersionControlService.php#L102-L112 | train |
brain-diminished/schema-version-control | src/SchemaVersionControlService.php | SchemaVersionControlService.dumpSchema | public function dumpSchema()
{
$schema = $this->getCurrentSchema();
$normalizer = new SchemaNormalizer();
$desc = $normalizer->normalize($schema);
$yamlSchema = Yaml::dump(['schema' =>$desc], 10, 2);
$directory = dirname($this->schemaFile);
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
file_put_contents($this->schemaFile, $yamlSchema);
} | php | public function dumpSchema()
{
$schema = $this->getCurrentSchema();
$normalizer = new SchemaNormalizer();
$desc = $normalizer->normalize($schema);
$yamlSchema = Yaml::dump(['schema' =>$desc], 10, 2);
$directory = dirname($this->schemaFile);
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
file_put_contents($this->schemaFile, $yamlSchema);
} | [
"public",
"function",
"dumpSchema",
"(",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getCurrentSchema",
"(",
")",
";",
"$",
"normalizer",
"=",
"new",
"SchemaNormalizer",
"(",
")",
";",
"$",
"desc",
"=",
"$",
"normalizer",
"->",
"normalize",
"(",
"$",
"schema",
")",
";",
"$",
"yamlSchema",
"=",
"Yaml",
"::",
"dump",
"(",
"[",
"'schema'",
"=>",
"$",
"desc",
"]",
",",
"10",
",",
"2",
")",
";",
"$",
"directory",
"=",
"dirname",
"(",
"$",
"this",
"->",
"schemaFile",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"directory",
")",
")",
"{",
"mkdir",
"(",
"$",
"directory",
",",
"0777",
",",
"true",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"this",
"->",
"schemaFile",
",",
"$",
"yamlSchema",
")",
";",
"}"
] | Write current database schema in config file | [
"Write",
"current",
"database",
"schema",
"in",
"config",
"file"
] | 215dd96394072720b61a682e10a55a6520470c46 | https://github.com/brain-diminished/schema-version-control/blob/215dd96394072720b61a682e10a55a6520470c46/src/SchemaVersionControlService.php#L117-L128 | train |
jenskooij/cloudcontrol | src/storage/storage/DocumentTypesStorage.php | DocumentTypesStorage.addDocumentType | public function addDocumentType($postValues)
{
$documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
$documentTypes = $this->repository->documentTypes;
$documentTypes[] = $documentTypeObject;
$this->repository->documentTypes = $documentTypes;
$this->save();
} | php | public function addDocumentType($postValues)
{
$documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
$documentTypes = $this->repository->documentTypes;
$documentTypes[] = $documentTypeObject;
$this->repository->documentTypes = $documentTypes;
$this->save();
} | [
"public",
"function",
"addDocumentType",
"(",
"$",
"postValues",
")",
"{",
"$",
"documentTypeObject",
"=",
"DocumentTypeFactory",
"::",
"createDocumentTypeFromPostValues",
"(",
"$",
"postValues",
")",
";",
"$",
"documentTypes",
"=",
"$",
"this",
"->",
"repository",
"->",
"documentTypes",
";",
"$",
"documentTypes",
"[",
"]",
"=",
"$",
"documentTypeObject",
";",
"$",
"this",
"->",
"repository",
"->",
"documentTypes",
"=",
"$",
"documentTypes",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Add a document type from post values
@param $postValues
@throws \Exception | [
"Add",
"a",
"document",
"type",
"from",
"post",
"values"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/DocumentTypesStorage.php#L33-L42 | train |
jenskooij/cloudcontrol | src/storage/storage/DocumentTypesStorage.php | DocumentTypesStorage.deleteDocumentTypeBySlug | public function deleteDocumentTypeBySlug($slug)
{
$documentTypes = $this->repository->documentTypes;
foreach ($documentTypes as $key => $documentTypeObject) {
if ($documentTypeObject->slug == $slug) {
unset($documentTypes[$key]);
}
}
$documentTypes = array_values($documentTypes);
$this->repository->documentTypes = $documentTypes;
$this->save();
} | php | public function deleteDocumentTypeBySlug($slug)
{
$documentTypes = $this->repository->documentTypes;
foreach ($documentTypes as $key => $documentTypeObject) {
if ($documentTypeObject->slug == $slug) {
unset($documentTypes[$key]);
}
}
$documentTypes = array_values($documentTypes);
$this->repository->documentTypes = $documentTypes;
$this->save();
} | [
"public",
"function",
"deleteDocumentTypeBySlug",
"(",
"$",
"slug",
")",
"{",
"$",
"documentTypes",
"=",
"$",
"this",
"->",
"repository",
"->",
"documentTypes",
";",
"foreach",
"(",
"$",
"documentTypes",
"as",
"$",
"key",
"=>",
"$",
"documentTypeObject",
")",
"{",
"if",
"(",
"$",
"documentTypeObject",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"unset",
"(",
"$",
"documentTypes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"documentTypes",
"=",
"array_values",
"(",
"$",
"documentTypes",
")",
";",
"$",
"this",
"->",
"repository",
"->",
"documentTypes",
"=",
"$",
"documentTypes",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Delete document type
@param $slug
@throws \Exception | [
"Delete",
"document",
"type"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/DocumentTypesStorage.php#L51-L62 | train |
jenskooij/cloudcontrol | src/storage/storage/DocumentTypesStorage.php | DocumentTypesStorage.getDocumentTypeBySlug | public function getDocumentTypeBySlug($slug, $getBricks = false)
{
$documentTypes = $this->repository->documentTypes;
foreach ($documentTypes as $documentType) {
if ($documentType->slug == $slug) {
if ($getBricks === true) {
foreach ($documentType->bricks as $key => $brick) {
$brickStructure = $this->getBricks()->getBrickBySlug($brick->brickSlug);
$documentType->bricks[$key]->structure = $brickStructure;
}
foreach ($documentType->dynamicBricks as $key => $brickSlug) {
$brickStructure = $this->getBricks()->getBrickBySlug($brickSlug);
$documentType->dynamicBricks[$key] = $brickStructure;
}
}
return $documentType;
}
}
return null;
} | php | public function getDocumentTypeBySlug($slug, $getBricks = false)
{
$documentTypes = $this->repository->documentTypes;
foreach ($documentTypes as $documentType) {
if ($documentType->slug == $slug) {
if ($getBricks === true) {
foreach ($documentType->bricks as $key => $brick) {
$brickStructure = $this->getBricks()->getBrickBySlug($brick->brickSlug);
$documentType->bricks[$key]->structure = $brickStructure;
}
foreach ($documentType->dynamicBricks as $key => $brickSlug) {
$brickStructure = $this->getBricks()->getBrickBySlug($brickSlug);
$documentType->dynamicBricks[$key] = $brickStructure;
}
}
return $documentType;
}
}
return null;
} | [
"public",
"function",
"getDocumentTypeBySlug",
"(",
"$",
"slug",
",",
"$",
"getBricks",
"=",
"false",
")",
"{",
"$",
"documentTypes",
"=",
"$",
"this",
"->",
"repository",
"->",
"documentTypes",
";",
"foreach",
"(",
"$",
"documentTypes",
"as",
"$",
"documentType",
")",
"{",
"if",
"(",
"$",
"documentType",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"if",
"(",
"$",
"getBricks",
"===",
"true",
")",
"{",
"foreach",
"(",
"$",
"documentType",
"->",
"bricks",
"as",
"$",
"key",
"=>",
"$",
"brick",
")",
"{",
"$",
"brickStructure",
"=",
"$",
"this",
"->",
"getBricks",
"(",
")",
"->",
"getBrickBySlug",
"(",
"$",
"brick",
"->",
"brickSlug",
")",
";",
"$",
"documentType",
"->",
"bricks",
"[",
"$",
"key",
"]",
"->",
"structure",
"=",
"$",
"brickStructure",
";",
"}",
"foreach",
"(",
"$",
"documentType",
"->",
"dynamicBricks",
"as",
"$",
"key",
"=>",
"$",
"brickSlug",
")",
"{",
"$",
"brickStructure",
"=",
"$",
"this",
"->",
"getBricks",
"(",
")",
"->",
"getBrickBySlug",
"(",
"$",
"brickSlug",
")",
";",
"$",
"documentType",
"->",
"dynamicBricks",
"[",
"$",
"key",
"]",
"=",
"$",
"brickStructure",
";",
"}",
"}",
"return",
"$",
"documentType",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get document type by its slug
@param $slug
@param bool $getBricks
@return mixed | [
"Get",
"document",
"type",
"by",
"its",
"slug"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/DocumentTypesStorage.php#L72-L93 | train |
jenskooij/cloudcontrol | src/storage/storage/DocumentTypesStorage.php | DocumentTypesStorage.saveDocumentType | public function saveDocumentType($slug, $postValues)
{
$documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
$documentTypes = $this->repository->documentTypes;
foreach ($documentTypes as $key => $documentType) {
if ($documentType->slug == $slug) {
$documentTypes[$key] = $documentTypeObject;
}
}
$this->repository->documentTypes = $documentTypes;
$this->save();
} | php | public function saveDocumentType($slug, $postValues)
{
$documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
$documentTypes = $this->repository->documentTypes;
foreach ($documentTypes as $key => $documentType) {
if ($documentType->slug == $slug) {
$documentTypes[$key] = $documentTypeObject;
}
}
$this->repository->documentTypes = $documentTypes;
$this->save();
} | [
"public",
"function",
"saveDocumentType",
"(",
"$",
"slug",
",",
"$",
"postValues",
")",
"{",
"$",
"documentTypeObject",
"=",
"DocumentTypeFactory",
"::",
"createDocumentTypeFromPostValues",
"(",
"$",
"postValues",
")",
";",
"$",
"documentTypes",
"=",
"$",
"this",
"->",
"repository",
"->",
"documentTypes",
";",
"foreach",
"(",
"$",
"documentTypes",
"as",
"$",
"key",
"=>",
"$",
"documentType",
")",
"{",
"if",
"(",
"$",
"documentType",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"$",
"documentTypes",
"[",
"$",
"key",
"]",
"=",
"$",
"documentTypeObject",
";",
"}",
"}",
"$",
"this",
"->",
"repository",
"->",
"documentTypes",
"=",
"$",
"documentTypes",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Save changes to a document type
@param $slug
@param $postValues
@throws \Exception | [
"Save",
"changes",
"to",
"a",
"document",
"type"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/DocumentTypesStorage.php#L103-L115 | train |
Eden-PHP/Block | Component/Tree.php | Tree.addItem | public function addItem($path, $object = array(), $class = null)
{
$path = explode('/', $path);
$object['class'] = $class;
$args = array();
foreach($path as $key) {
$args[] = $key;
$args[] = 'children';
}
//soft inject
$tree = eden('registry', $this->tree);
$last = count($args);
foreach($object as $key => $value) {
$args[$last - 1] = $key;
$args[$last] = $value;
$tree->callArray('set', $args);
}
$this->tree = $tree->getArray();
return $this;
} | php | public function addItem($path, $object = array(), $class = null)
{
$path = explode('/', $path);
$object['class'] = $class;
$args = array();
foreach($path as $key) {
$args[] = $key;
$args[] = 'children';
}
//soft inject
$tree = eden('registry', $this->tree);
$last = count($args);
foreach($object as $key => $value) {
$args[$last - 1] = $key;
$args[$last] = $value;
$tree->callArray('set', $args);
}
$this->tree = $tree->getArray();
return $this;
} | [
"public",
"function",
"addItem",
"(",
"$",
"path",
",",
"$",
"object",
"=",
"array",
"(",
")",
",",
"$",
"class",
"=",
"null",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"object",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"$",
"args",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"key",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"$",
"key",
";",
"$",
"args",
"[",
"]",
"=",
"'children'",
";",
"}",
"//soft inject",
"$",
"tree",
"=",
"eden",
"(",
"'registry'",
",",
"$",
"this",
"->",
"tree",
")",
";",
"$",
"last",
"=",
"count",
"(",
"$",
"args",
")",
";",
"foreach",
"(",
"$",
"object",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"args",
"[",
"$",
"last",
"-",
"1",
"]",
"=",
"$",
"key",
";",
"$",
"args",
"[",
"$",
"last",
"]",
"=",
"$",
"value",
";",
"$",
"tree",
"->",
"callArray",
"(",
"'set'",
",",
"$",
"args",
")",
";",
"}",
"$",
"this",
"->",
"tree",
"=",
"$",
"tree",
"->",
"getArray",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds item to the tree
@param string
@param mixed
@return array | [
"Adds",
"item",
"to",
"the",
"tree"
] | 681b9f01dd118612d0fced84d2f702167b52109b | https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Component/Tree.php#L50-L73 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Eloquent/Nested/SetMapper.php | SetMapper.map | public function map( $modelList )
{
$self = $this;
return $this->wrapInTransaction( function () use ( $self, $modelList )
{
forward_static_call( [get_class( $self->model ), 'unguard'] );
$result = $self->mapTree( $modelList );
forward_static_call( [get_class( $self->model ), 'reguard'] );
return $result;
} );
} | php | public function map( $modelList )
{
$self = $this;
return $this->wrapInTransaction( function () use ( $self, $modelList )
{
forward_static_call( [get_class( $self->model ), 'unguard'] );
$result = $self->mapTree( $modelList );
forward_static_call( [get_class( $self->model ), 'reguard'] );
return $result;
} );
} | [
"public",
"function",
"map",
"(",
"$",
"modelList",
")",
"{",
"$",
"self",
"=",
"$",
"this",
";",
"return",
"$",
"this",
"->",
"wrapInTransaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"self",
",",
"$",
"modelList",
")",
"{",
"forward_static_call",
"(",
"[",
"get_class",
"(",
"$",
"self",
"->",
"model",
")",
",",
"'unguard'",
"]",
")",
";",
"$",
"result",
"=",
"$",
"self",
"->",
"mapTree",
"(",
"$",
"modelList",
")",
";",
"forward_static_call",
"(",
"[",
"get_class",
"(",
"$",
"self",
"->",
"model",
")",
",",
"'reguard'",
"]",
")",
";",
"return",
"$",
"result",
";",
"}",
")",
";",
"}"
] | Maps a tree structure into the database. Unguards & wraps in transaction.
@param array|Arrayable
@return boolean | [
"Maps",
"a",
"tree",
"structure",
"into",
"the",
"database",
".",
"Unguards",
"&",
"wraps",
"in",
"transaction",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/SetMapper.php#L41-L55 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Eloquent/Nested/SetMapper.php | SetMapper.mapTree | public function mapTree( $modelList )
{
$tree = $modelList instanceof Arrayable ? $modelList->toArray() : $modelList;
$affectedKeys = [];
$result = $this->mapTreeRecursive( $tree, $this->model->getKey(), $affectedKeys );
if ( $result && count( $affectedKeys ) > 0 )
$this->deleteUnaffected( $affectedKeys );
return $result;
} | php | public function mapTree( $modelList )
{
$tree = $modelList instanceof Arrayable ? $modelList->toArray() : $modelList;
$affectedKeys = [];
$result = $this->mapTreeRecursive( $tree, $this->model->getKey(), $affectedKeys );
if ( $result && count( $affectedKeys ) > 0 )
$this->deleteUnaffected( $affectedKeys );
return $result;
} | [
"public",
"function",
"mapTree",
"(",
"$",
"modelList",
")",
"{",
"$",
"tree",
"=",
"$",
"modelList",
"instanceof",
"Arrayable",
"?",
"$",
"modelList",
"->",
"toArray",
"(",
")",
":",
"$",
"modelList",
";",
"$",
"affectedKeys",
"=",
"[",
"]",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mapTreeRecursive",
"(",
"$",
"tree",
",",
"$",
"this",
"->",
"model",
"->",
"getKey",
"(",
")",
",",
"$",
"affectedKeys",
")",
";",
"if",
"(",
"$",
"result",
"&&",
"count",
"(",
"$",
"affectedKeys",
")",
">",
"0",
")",
"$",
"this",
"->",
"deleteUnaffected",
"(",
"$",
"affectedKeys",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Maps a tree structure into the database without unguarding nor wrapping
inside a transaction.
@param array|Arrayable
@return boolean | [
"Maps",
"a",
"tree",
"structure",
"into",
"the",
"database",
"without",
"unguarding",
"nor",
"wrapping",
"inside",
"a",
"transaction",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/SetMapper.php#L64-L76 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Backend/LoginForm.php | LoginForm.SaveElement | protected function SaveElement()
{
$this->login->SetNextUrl($this->selectorNext->Save($this->login->GetNextUrl()));
$this->login->SetPasswordUrl($this->selectorPassword->Save($this->login->GetPasswordUrl()));
return $this->login;
} | php | protected function SaveElement()
{
$this->login->SetNextUrl($this->selectorNext->Save($this->login->GetNextUrl()));
$this->login->SetPasswordUrl($this->selectorPassword->Save($this->login->GetPasswordUrl()));
return $this->login;
} | [
"protected",
"function",
"SaveElement",
"(",
")",
"{",
"$",
"this",
"->",
"login",
"->",
"SetNextUrl",
"(",
"$",
"this",
"->",
"selectorNext",
"->",
"Save",
"(",
"$",
"this",
"->",
"login",
"->",
"GetNextUrl",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"login",
"->",
"SetPasswordUrl",
"(",
"$",
"this",
"->",
"selectorPassword",
"->",
"Save",
"(",
"$",
"this",
"->",
"login",
"->",
"GetPasswordUrl",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"login",
";",
"}"
] | Saves the login element and returns it
@return ContentLogin Returns the login element with form values applied | [
"Saves",
"the",
"login",
"element",
"and",
"returns",
"it"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Backend/LoginForm.php#L81-L86 | train |
ivopetkov/form-bearframework-addon | classes/Form/Constraints.php | Constraints.setMinLength | public function setMinLength(string $elementName, int $minLength, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = sprintf(__('ivopetkov.form.The length of this field must be atleast %s characters.'), $minLength);
}
$this->data[] = ['minLength', $errorMessage, $elementName, $minLength];
return $this;
} | php | public function setMinLength(string $elementName, int $minLength, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = sprintf(__('ivopetkov.form.The length of this field must be atleast %s characters.'), $minLength);
}
$this->data[] = ['minLength', $errorMessage, $elementName, $minLength];
return $this;
} | [
"public",
"function",
"setMinLength",
"(",
"string",
"$",
"elementName",
",",
"int",
"$",
"minLength",
",",
"string",
"$",
"errorMessage",
"=",
"null",
")",
":",
"\\",
"IvoPetkov",
"\\",
"BearFrameworkAddons",
"\\",
"Form",
"\\",
"Constraints",
"{",
"if",
"(",
"$",
"errorMessage",
"===",
"null",
")",
"{",
"$",
"errorMessage",
"=",
"sprintf",
"(",
"__",
"(",
"'ivopetkov.form.The length of this field must be atleast %s characters.'",
")",
",",
"$",
"minLength",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"]",
"=",
"[",
"'minLength'",
",",
"$",
"errorMessage",
",",
"$",
"elementName",
",",
"$",
"minLength",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a minimum length requirement for an element
@param string $elementName The element name
@param int $minLength
@param string $errorMessage Error message
@return \IvoPetkov\BearFrameworkAddons\Form\Constraints Returns a reference to itself. | [
"Sets",
"a",
"minimum",
"length",
"requirement",
"for",
"an",
"element"
] | 78ab860c430166805b4e81942eb5a8c32777df01 | https://github.com/ivopetkov/form-bearframework-addon/blob/78ab860c430166805b4e81942eb5a8c32777df01/classes/Form/Constraints.php#L48-L55 | train |
ivopetkov/form-bearframework-addon | classes/Form/Constraints.php | Constraints.setMaxLength | public function setMaxLength(string $elementName, int $maxLength, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = sprintf(__('ivopetkov.form.The length of this field must be atmost %s characters.'), $maxLength);
}
$this->data[] = ['maxLength', $errorMessage, $elementName, $maxLength];
return $this;
} | php | public function setMaxLength(string $elementName, int $maxLength, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = sprintf(__('ivopetkov.form.The length of this field must be atmost %s characters.'), $maxLength);
}
$this->data[] = ['maxLength', $errorMessage, $elementName, $maxLength];
return $this;
} | [
"public",
"function",
"setMaxLength",
"(",
"string",
"$",
"elementName",
",",
"int",
"$",
"maxLength",
",",
"string",
"$",
"errorMessage",
"=",
"null",
")",
":",
"\\",
"IvoPetkov",
"\\",
"BearFrameworkAddons",
"\\",
"Form",
"\\",
"Constraints",
"{",
"if",
"(",
"$",
"errorMessage",
"===",
"null",
")",
"{",
"$",
"errorMessage",
"=",
"sprintf",
"(",
"__",
"(",
"'ivopetkov.form.The length of this field must be atmost %s characters.'",
")",
",",
"$",
"maxLength",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"]",
"=",
"[",
"'maxLength'",
",",
"$",
"errorMessage",
",",
"$",
"elementName",
",",
"$",
"maxLength",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a maximum length requirement for an element
@param string $elementName The element name
@param int $maxLength
@param string $errorMessage Error message
@return \IvoPetkov\BearFrameworkAddons\Form\Constraints Returns a reference to itself. | [
"Sets",
"a",
"maximum",
"length",
"requirement",
"for",
"an",
"element"
] | 78ab860c430166805b4e81942eb5a8c32777df01 | https://github.com/ivopetkov/form-bearframework-addon/blob/78ab860c430166805b4e81942eb5a8c32777df01/classes/Form/Constraints.php#L65-L72 | train |
ivopetkov/form-bearframework-addon | classes/Form/Constraints.php | Constraints.setEmail | public function setEmail(string $elementName, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = __('ivopetkov.form.This is not a valid email address.');
}
$this->data[] = ['email', $errorMessage, $elementName];
return $this;
} | php | public function setEmail(string $elementName, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = __('ivopetkov.form.This is not a valid email address.');
}
$this->data[] = ['email', $errorMessage, $elementName];
return $this;
} | [
"public",
"function",
"setEmail",
"(",
"string",
"$",
"elementName",
",",
"string",
"$",
"errorMessage",
"=",
"null",
")",
":",
"\\",
"IvoPetkov",
"\\",
"BearFrameworkAddons",
"\\",
"Form",
"\\",
"Constraints",
"{",
"if",
"(",
"$",
"errorMessage",
"===",
"null",
")",
"{",
"$",
"errorMessage",
"=",
"__",
"(",
"'ivopetkov.form.This is not a valid email address.'",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"]",
"=",
"[",
"'email'",
",",
"$",
"errorMessage",
",",
"$",
"elementName",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Requires the element value to be a valid email address
@param string $elementName The element name
@param string $errorMessage Error message
@return \IvoPetkov\BearFrameworkAddons\Form\Constraints Returns a reference to itself. | [
"Requires",
"the",
"element",
"value",
"to",
"be",
"a",
"valid",
"email",
"address"
] | 78ab860c430166805b4e81942eb5a8c32777df01 | https://github.com/ivopetkov/form-bearframework-addon/blob/78ab860c430166805b4e81942eb5a8c32777df01/classes/Form/Constraints.php#L81-L88 | train |
ivopetkov/form-bearframework-addon | classes/Form/Constraints.php | Constraints.setRegularExpression | public function setRegularExpression(string $elementName, string $regularExpression, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = __('ivopetkov.form.This is not a valid value.');
}
$this->data[] = ['regExp', $errorMessage, $elementName, $regularExpression];
return $this;
} | php | public function setRegularExpression(string $elementName, string $regularExpression, string $errorMessage = null): \IvoPetkov\BearFrameworkAddons\Form\Constraints
{
if ($errorMessage === null) {
$errorMessage = __('ivopetkov.form.This is not a valid value.');
}
$this->data[] = ['regExp', $errorMessage, $elementName, $regularExpression];
return $this;
} | [
"public",
"function",
"setRegularExpression",
"(",
"string",
"$",
"elementName",
",",
"string",
"$",
"regularExpression",
",",
"string",
"$",
"errorMessage",
"=",
"null",
")",
":",
"\\",
"IvoPetkov",
"\\",
"BearFrameworkAddons",
"\\",
"Form",
"\\",
"Constraints",
"{",
"if",
"(",
"$",
"errorMessage",
"===",
"null",
")",
"{",
"$",
"errorMessage",
"=",
"__",
"(",
"'ivopetkov.form.This is not a valid value.'",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"]",
"=",
"[",
"'regExp'",
",",
"$",
"errorMessage",
",",
"$",
"elementName",
",",
"$",
"regularExpression",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Performs a regular expression validation
@param string $elementName The element name
@param string $regularExpression
@param string $errorMessage Error message
@return \IvoPetkov\BearFrameworkAddons\Form\Constraints Returns a reference to itself. | [
"Performs",
"a",
"regular",
"expression",
"validation"
] | 78ab860c430166805b4e81942eb5a8c32777df01 | https://github.com/ivopetkov/form-bearframework-addon/blob/78ab860c430166805b4e81942eb5a8c32777df01/classes/Form/Constraints.php#L98-L105 | train |
ivopetkov/form-bearframework-addon | classes/Form/Constraints.php | Constraints.validate | public function validate(array $values, array &$errorsList): bool
{
$hasErrors = false;
foreach ($this->data as $item) {
$type = $item[0];
$errorMessage = $item[1];
$elementName = $item[2];
$value = isset($values[$elementName]) ? (string) $values[$elementName] : '';
$hasError = false;
if ($type === 'required') {
if (strlen($value) === 0) {
$hasError = true;
}
} elseif ($type === 'minLength') {
if (strlen($value) < $item[3]) {
$hasError = true;
}
} elseif ($type === 'maxLength') {
if (strlen($value) > $item[3]) {
$hasError = true;
}
} elseif ($type === 'email') {
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
$hasError = true;
}
} elseif ($type === 'regExp') {
if (!filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $item[3]]])) {
$hasError = true;
}
}
if ($hasError) {
$errorsList[] = [
'elementName' => $elementName,
'errorMessage' => $errorMessage
];
$hasErrors = true;
}
}
return !$hasErrors;
} | php | public function validate(array $values, array &$errorsList): bool
{
$hasErrors = false;
foreach ($this->data as $item) {
$type = $item[0];
$errorMessage = $item[1];
$elementName = $item[2];
$value = isset($values[$elementName]) ? (string) $values[$elementName] : '';
$hasError = false;
if ($type === 'required') {
if (strlen($value) === 0) {
$hasError = true;
}
} elseif ($type === 'minLength') {
if (strlen($value) < $item[3]) {
$hasError = true;
}
} elseif ($type === 'maxLength') {
if (strlen($value) > $item[3]) {
$hasError = true;
}
} elseif ($type === 'email') {
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
$hasError = true;
}
} elseif ($type === 'regExp') {
if (!filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $item[3]]])) {
$hasError = true;
}
}
if ($hasError) {
$errorsList[] = [
'elementName' => $elementName,
'errorMessage' => $errorMessage
];
$hasErrors = true;
}
}
return !$hasErrors;
} | [
"public",
"function",
"validate",
"(",
"array",
"$",
"values",
",",
"array",
"&",
"$",
"errorsList",
")",
":",
"bool",
"{",
"$",
"hasErrors",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"item",
")",
"{",
"$",
"type",
"=",
"$",
"item",
"[",
"0",
"]",
";",
"$",
"errorMessage",
"=",
"$",
"item",
"[",
"1",
"]",
";",
"$",
"elementName",
"=",
"$",
"item",
"[",
"2",
"]",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"values",
"[",
"$",
"elementName",
"]",
")",
"?",
"(",
"string",
")",
"$",
"values",
"[",
"$",
"elementName",
"]",
":",
"''",
";",
"$",
"hasError",
"=",
"false",
";",
"if",
"(",
"$",
"type",
"===",
"'required'",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
"===",
"0",
")",
"{",
"$",
"hasError",
"=",
"true",
";",
"}",
"}",
"elseif",
"(",
"$",
"type",
"===",
"'minLength'",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
"<",
"$",
"item",
"[",
"3",
"]",
")",
"{",
"$",
"hasError",
"=",
"true",
";",
"}",
"}",
"elseif",
"(",
"$",
"type",
"===",
"'maxLength'",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
">",
"$",
"item",
"[",
"3",
"]",
")",
"{",
"$",
"hasError",
"=",
"true",
";",
"}",
"}",
"elseif",
"(",
"$",
"type",
"===",
"'email'",
")",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"$",
"hasError",
"=",
"true",
";",
"}",
"}",
"elseif",
"(",
"$",
"type",
"===",
"'regExp'",
")",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_REGEXP",
",",
"[",
"'options'",
"=>",
"[",
"'regexp'",
"=>",
"$",
"item",
"[",
"3",
"]",
"]",
"]",
")",
")",
"{",
"$",
"hasError",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"hasError",
")",
"{",
"$",
"errorsList",
"[",
"]",
"=",
"[",
"'elementName'",
"=>",
"$",
"elementName",
",",
"'errorMessage'",
"=>",
"$",
"errorMessage",
"]",
";",
"$",
"hasErrors",
"=",
"true",
";",
"}",
"}",
"return",
"!",
"$",
"hasErrors",
";",
"}"
] | Validates the values passed
@param array $values The values to checks
@param array $errorsList List of validation errors
@return bool TRUE if no validation errors found. FALSE otherwise. | [
"Validates",
"the",
"values",
"passed"
] | 78ab860c430166805b4e81942eb5a8c32777df01 | https://github.com/ivopetkov/form-bearframework-addon/blob/78ab860c430166805b4e81942eb5a8c32777df01/classes/Form/Constraints.php#L114-L153 | train |
DoSomething/mb-toolbox | src/MB_Toolbox.php | MB_Toolbox.isDSAffiliate | public function isDSAffiliate($targetCountyCode)
{
$foundAffiliate = false;
$affiliates = [
'GB', // United Kingdom
'UK', // United Kingdom
'CA', // Canada
'ID', // Indonesia
'BW', // Botswana
'KE', // Kenya
'GH', // Ghana
'NG', // Nigeria
'CD', // Congo, The Democratic Republic of the"
'BR', // Brazil
'MX', // Mexico
];
if (in_array($targetCountyCode, $affiliates)) {
$affiliateURL = [
'GB' => 'https://uk.dosomething.org', // United Kingdom
'UK' => 'https://uk.dosomething.org', // United Kingdom
'CA' => 'https://canada.dosomething.org', // Canada
'ID' => 'https://indonesia.dosomething.org', // Indonesia
'BW' => 'https://botswana.dosomething.org', // Botswana
'KE' => 'https://kenya.dosomething.org', // Kenya
'GH' => 'https://ghana.dosomething.org', // Ghana
'NG' => 'https://nigeria.dosomething.org', // Nigeria
'CD' => 'https://congo.dosomething.org', // Congo, The Democratic Republic of the"
'BR' => 'https://brazil.dosomething.org', // Brazil
'MX' => 'https://mexico.dosomething.org', // Mexico
];
$foundAffiliate['url'] = $affiliateURL[$targetCountyCode];
$this->statHat->ezCount('MB_Toolbox: isDSAffiliate Found');
} else {
$this->statHat->ezCount('MB_Toolbox: isDSAffiliate Not Found');
}
return $foundAffiliate;
} | php | public function isDSAffiliate($targetCountyCode)
{
$foundAffiliate = false;
$affiliates = [
'GB', // United Kingdom
'UK', // United Kingdom
'CA', // Canada
'ID', // Indonesia
'BW', // Botswana
'KE', // Kenya
'GH', // Ghana
'NG', // Nigeria
'CD', // Congo, The Democratic Republic of the"
'BR', // Brazil
'MX', // Mexico
];
if (in_array($targetCountyCode, $affiliates)) {
$affiliateURL = [
'GB' => 'https://uk.dosomething.org', // United Kingdom
'UK' => 'https://uk.dosomething.org', // United Kingdom
'CA' => 'https://canada.dosomething.org', // Canada
'ID' => 'https://indonesia.dosomething.org', // Indonesia
'BW' => 'https://botswana.dosomething.org', // Botswana
'KE' => 'https://kenya.dosomething.org', // Kenya
'GH' => 'https://ghana.dosomething.org', // Ghana
'NG' => 'https://nigeria.dosomething.org', // Nigeria
'CD' => 'https://congo.dosomething.org', // Congo, The Democratic Republic of the"
'BR' => 'https://brazil.dosomething.org', // Brazil
'MX' => 'https://mexico.dosomething.org', // Mexico
];
$foundAffiliate['url'] = $affiliateURL[$targetCountyCode];
$this->statHat->ezCount('MB_Toolbox: isDSAffiliate Found');
} else {
$this->statHat->ezCount('MB_Toolbox: isDSAffiliate Not Found');
}
return $foundAffiliate;
} | [
"public",
"function",
"isDSAffiliate",
"(",
"$",
"targetCountyCode",
")",
"{",
"$",
"foundAffiliate",
"=",
"false",
";",
"$",
"affiliates",
"=",
"[",
"'GB'",
",",
"// United Kingdom",
"'UK'",
",",
"// United Kingdom",
"'CA'",
",",
"// Canada",
"'ID'",
",",
"// Indonesia",
"'BW'",
",",
"// Botswana",
"'KE'",
",",
"// Kenya",
"'GH'",
",",
"// Ghana",
"'NG'",
",",
"// Nigeria",
"'CD'",
",",
"// Congo, The Democratic Republic of the\"",
"'BR'",
",",
"// Brazil",
"'MX'",
",",
"// Mexico",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"targetCountyCode",
",",
"$",
"affiliates",
")",
")",
"{",
"$",
"affiliateURL",
"=",
"[",
"'GB'",
"=>",
"'https://uk.dosomething.org'",
",",
"// United Kingdom",
"'UK'",
"=>",
"'https://uk.dosomething.org'",
",",
"// United Kingdom",
"'CA'",
"=>",
"'https://canada.dosomething.org'",
",",
"// Canada",
"'ID'",
"=>",
"'https://indonesia.dosomething.org'",
",",
"// Indonesia",
"'BW'",
"=>",
"'https://botswana.dosomething.org'",
",",
"// Botswana",
"'KE'",
"=>",
"'https://kenya.dosomething.org'",
",",
"// Kenya",
"'GH'",
"=>",
"'https://ghana.dosomething.org'",
",",
"// Ghana",
"'NG'",
"=>",
"'https://nigeria.dosomething.org'",
",",
"// Nigeria",
"'CD'",
"=>",
"'https://congo.dosomething.org'",
",",
"// Congo, The Democratic Republic of the\"",
"'BR'",
"=>",
"'https://brazil.dosomething.org'",
",",
"// Brazil",
"'MX'",
"=>",
"'https://mexico.dosomething.org'",
",",
"// Mexico",
"]",
";",
"$",
"foundAffiliate",
"[",
"'url'",
"]",
"=",
"$",
"affiliateURL",
"[",
"$",
"targetCountyCode",
"]",
";",
"$",
"this",
"->",
"statHat",
"->",
"ezCount",
"(",
"'MB_Toolbox: isDSAffiliate Found'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"statHat",
"->",
"ezCount",
"(",
"'MB_Toolbox: isDSAffiliate Not Found'",
")",
";",
"}",
"return",
"$",
"foundAffiliate",
";",
"}"
] | Test if country code has a DoSomething affiliate.
Follow country code convention defined in:
http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
@param string $targetCountyCode
Country code to check.
@return boolean/array $foundAffiliate
Test if supplied country code is a DoSomething affiliate country the URL
to the affiliate site is returned vs boolean false if match is not found. | [
"Test",
"if",
"country",
"code",
"has",
"a",
"DoSomething",
"affiliate",
"."
] | ceec5fc594bae137d1ab1f447344800343b62ac6 | https://github.com/DoSomething/mb-toolbox/blob/ceec5fc594bae137d1ab1f447344800343b62ac6/src/MB_Toolbox.php#L83-L123 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.