repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
VincentChalnot/SidusAdminBundle
|
Controller/AbstractAdminController.php
|
AbstractAdminController.getTemplate
|
protected function getTemplate(Action $action = null, $templateType = 'html')
{
return $this->container->get(TemplateResolverInterface::class)->getTemplate(
$action ?: $this->admin->getCurrentAction(),
$templateType
);
}
|
php
|
protected function getTemplate(Action $action = null, $templateType = 'html')
{
return $this->container->get(TemplateResolverInterface::class)->getTemplate(
$action ?: $this->admin->getCurrentAction(),
$templateType
);
}
|
[
"protected",
"function",
"getTemplate",
"(",
"Action",
"$",
"action",
"=",
"null",
",",
"$",
"templateType",
"=",
"'html'",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"TemplateResolverInterface",
"::",
"class",
")",
"->",
"getTemplate",
"(",
"$",
"action",
"?",
":",
"$",
"this",
"->",
"admin",
"->",
"getCurrentAction",
"(",
")",
",",
"$",
"templateType",
")",
";",
"}"
] |
@param Action $action
@param string $templateType
@throws \Exception
@return \Twig_Template
|
[
"@param",
"Action",
"$action",
"@param",
"string",
"$templateType"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Controller/AbstractAdminController.php#L214-L220
|
VincentChalnot/SidusAdminBundle
|
Controller/AbstractAdminController.php
|
AbstractAdminController.renderAction
|
protected function renderAction(array $parameters = [], Action $action = null)
{
$response = new Response();
$response->setContent($this->getTemplate($action)->render($parameters));
return $response;
}
|
php
|
protected function renderAction(array $parameters = [], Action $action = null)
{
$response = new Response();
$response->setContent($this->getTemplate($action)->render($parameters));
return $response;
}
|
[
"protected",
"function",
"renderAction",
"(",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"Action",
"$",
"action",
"=",
"null",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"this",
"->",
"getTemplate",
"(",
"$",
"action",
")",
"->",
"render",
"(",
"$",
"parameters",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
@param array $parameters
@param Action|null $action
@throws \UnexpectedValueException
@throws \InvalidArgumentException
@return Response
|
[
"@param",
"array",
"$parameters",
"@param",
"Action|null",
"$action"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Controller/AbstractAdminController.php#L232-L238
|
VincentChalnot/SidusAdminBundle
|
Controller/AbstractAdminController.php
|
AbstractAdminController.getDataFromRequest
|
protected function getDataFromRequest(Request $request, $configuration = null)
{
if (null === $configuration) {
$configuration = [
new ParamConverter(
[
'name' => 'data',
'class' => $this->admin->getEntity(),
]
),
];
}
$this->container->get('sensio_framework_extra.converter.manager')->apply($request, $configuration);
return $request->attributes->get('data');
}
|
php
|
protected function getDataFromRequest(Request $request, $configuration = null)
{
if (null === $configuration) {
$configuration = [
new ParamConverter(
[
'name' => 'data',
'class' => $this->admin->getEntity(),
]
),
];
}
$this->container->get('sensio_framework_extra.converter.manager')->apply($request, $configuration);
return $request->attributes->get('data');
}
|
[
"protected",
"function",
"getDataFromRequest",
"(",
"Request",
"$",
"request",
",",
"$",
"configuration",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"configuration",
")",
"{",
"$",
"configuration",
"=",
"[",
"new",
"ParamConverter",
"(",
"[",
"'name'",
"=>",
"'data'",
",",
"'class'",
"=>",
"$",
"this",
"->",
"admin",
"->",
"getEntity",
"(",
")",
",",
"]",
")",
",",
"]",
";",
"}",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sensio_framework_extra.converter.manager'",
")",
"->",
"apply",
"(",
"$",
"request",
",",
"$",
"configuration",
")",
";",
"return",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'data'",
")",
";",
"}"
] |
@param Request $request
@param array|ParamConverterInterface $configuration
@throws \Exception
@return mixed
|
[
"@param",
"Request",
"$request",
"@param",
"array|ParamConverterInterface",
"$configuration"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Controller/AbstractAdminController.php#L248-L263
|
VincentChalnot/SidusAdminBundle
|
Controller/AbstractAdminController.php
|
AbstractAdminController.redirectToEntity
|
protected function redirectToEntity(
$entity,
$action,
array $parameters = [],
$referenceType = UrlGeneratorInterface::ABSOLUTE_PATH,
$status = 302
) {
$url = $this->container->get(AdminRouter::class)
->generateAdminEntityPath($this->admin, $entity, $action, $parameters, $referenceType);
return new RedirectResponse($url, $status);
}
|
php
|
protected function redirectToEntity(
$entity,
$action,
array $parameters = [],
$referenceType = UrlGeneratorInterface::ABSOLUTE_PATH,
$status = 302
) {
$url = $this->container->get(AdminRouter::class)
->generateAdminEntityPath($this->admin, $entity, $action, $parameters, $referenceType);
return new RedirectResponse($url, $status);
}
|
[
"protected",
"function",
"redirectToEntity",
"(",
"$",
"entity",
",",
"$",
"action",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"referenceType",
"=",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_PATH",
",",
"$",
"status",
"=",
"302",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"AdminRouter",
"::",
"class",
")",
"->",
"generateAdminEntityPath",
"(",
"$",
"this",
"->",
"admin",
",",
"$",
"entity",
",",
"$",
"action",
",",
"$",
"parameters",
",",
"$",
"referenceType",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"url",
",",
"$",
"status",
")",
";",
"}"
] |
@param mixed $entity
@param string $action
@param array $parameters
@param int $referenceType
@param int $status
@throws \Exception
@return RedirectResponse
|
[
"@param",
"mixed",
"$entity",
"@param",
"string",
"$action",
"@param",
"array",
"$parameters",
"@param",
"int",
"$referenceType",
"@param",
"int",
"$status"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Controller/AbstractAdminController.php#L276-L287
|
VincentChalnot/SidusAdminBundle
|
Controller/AbstractAdminController.php
|
AbstractAdminController.redirectToAction
|
protected function redirectToAction(
$action,
array $parameters = [],
$referenceType = UrlGeneratorInterface::ABSOLUTE_PATH,
$status = 302
) {
$url = $this->container->get(AdminRouter::class)
->generateAdminPath($this->admin, $action, $parameters, $referenceType);
return new RedirectResponse($url, $status);
}
|
php
|
protected function redirectToAction(
$action,
array $parameters = [],
$referenceType = UrlGeneratorInterface::ABSOLUTE_PATH,
$status = 302
) {
$url = $this->container->get(AdminRouter::class)
->generateAdminPath($this->admin, $action, $parameters, $referenceType);
return new RedirectResponse($url, $status);
}
|
[
"protected",
"function",
"redirectToAction",
"(",
"$",
"action",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"referenceType",
"=",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_PATH",
",",
"$",
"status",
"=",
"302",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"AdminRouter",
"::",
"class",
")",
"->",
"generateAdminPath",
"(",
"$",
"this",
"->",
"admin",
",",
"$",
"action",
",",
"$",
"parameters",
",",
"$",
"referenceType",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"url",
",",
"$",
"status",
")",
";",
"}"
] |
@param string $action
@param array $parameters
@param int $referenceType
@param int $status
@throws \Exception
@return RedirectResponse
|
[
"@param",
"string",
"$action",
"@param",
"array",
"$parameters",
"@param",
"int",
"$referenceType",
"@param",
"int",
"$status"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Controller/AbstractAdminController.php#L299-L309
|
VincentChalnot/SidusAdminBundle
|
Controller/AbstractAdminController.php
|
AbstractAdminController.getCurrentUri
|
protected function getCurrentUri(Request $request, array $parameters = [])
{
$params = $request->attributes->get('_route_params');
return $this->generateUrl($request->attributes->get('_route'), array_merge($params, $parameters));
}
|
php
|
protected function getCurrentUri(Request $request, array $parameters = [])
{
$params = $request->attributes->get('_route_params');
return $this->generateUrl($request->attributes->get('_route'), array_merge($params, $parameters));
}
|
[
"protected",
"function",
"getCurrentUri",
"(",
"Request",
"$",
"request",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route_params'",
")",
";",
"return",
"$",
"this",
"->",
"generateUrl",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route'",
")",
",",
"array_merge",
"(",
"$",
"params",
",",
"$",
"parameters",
")",
")",
";",
"}"
] |
@param Request $request
@param array $parameters
@throws \InvalidArgumentException
@return string
|
[
"@param",
"Request",
"$request",
"@param",
"array",
"$parameters"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Controller/AbstractAdminController.php#L319-L324
|
phpmob/changmin
|
src/PhpMob/CoreBundle/Fixture/UserGroupFactory.php
|
UserGroupFactory.create
|
public function create(array $options = [])
{
$options = $this->optionsResolver->resolve($options);
/** @var UserGroupInterface $group */
$group = $this->userGroupFactory->createNew();
$group->setCode($options['code']);
$group->setName($options['name']);
return $group;
}
|
php
|
public function create(array $options = [])
{
$options = $this->optionsResolver->resolve($options);
/** @var UserGroupInterface $group */
$group = $this->userGroupFactory->createNew();
$group->setCode($options['code']);
$group->setName($options['name']);
return $group;
}
|
[
"public",
"function",
"create",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"optionsResolver",
"->",
"resolve",
"(",
"$",
"options",
")",
";",
"/** @var UserGroupInterface $group */",
"$",
"group",
"=",
"$",
"this",
"->",
"userGroupFactory",
"->",
"createNew",
"(",
")",
";",
"$",
"group",
"->",
"setCode",
"(",
"$",
"options",
"[",
"'code'",
"]",
")",
";",
"$",
"group",
"->",
"setName",
"(",
"$",
"options",
"[",
"'name'",
"]",
")",
";",
"return",
"$",
"group",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Fixture/UserGroupFactory.php#L47-L57
|
phpmob/changmin
|
src/PhpMob/CoreBundle/Fixture/UserGroupFactory.php
|
UserGroupFactory.configureOptions
|
protected function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('code', function (Options $options) {
return $this->faker->word;
})
->setDefault('name', function (Options $options) {
return $this->faker->word;
})
;
}
|
php
|
protected function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('code', function (Options $options) {
return $this->faker->word;
})
->setDefault('name', function (Options $options) {
return $this->faker->word;
})
;
}
|
[
"protected",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefault",
"(",
"'code'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"word",
";",
"}",
")",
"->",
"setDefault",
"(",
"'name'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"word",
";",
"}",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Fixture/UserGroupFactory.php#L62-L72
|
abbert/datagrid
|
src/Datagrid.php
|
Datagrid.renderJson
|
public function renderJson()
{
$totalCount = $this->getDatasource()->totalCount();
$rows = $this->getDatasource()->listRows();
$tmpData = [];
foreach ($rows as $row) {
$tmp = [];
$this->currentRow = new DefaultRow();
if ($this->rowCallback instanceof \Closure) {
$this->rowCallback->call($this, $row);
}
foreach ($this->getColumns() as $key => $column) {
$this->currentColumn = $key;
$tmp[$column->getName()] = $column->format($row);
}
$tmpData[] = $tmp;
}
$data = [
'draw' => $this->getRequest()->get('draw'), // @todo param names configurable
'recordsTotal' => $totalCount,
'recordsFiltered' => $totalCount,
'data' => $tmpData,
];
header('Content-Type: application/json');
echo json_encode($data);die;
}
|
php
|
public function renderJson()
{
$totalCount = $this->getDatasource()->totalCount();
$rows = $this->getDatasource()->listRows();
$tmpData = [];
foreach ($rows as $row) {
$tmp = [];
$this->currentRow = new DefaultRow();
if ($this->rowCallback instanceof \Closure) {
$this->rowCallback->call($this, $row);
}
foreach ($this->getColumns() as $key => $column) {
$this->currentColumn = $key;
$tmp[$column->getName()] = $column->format($row);
}
$tmpData[] = $tmp;
}
$data = [
'draw' => $this->getRequest()->get('draw'), // @todo param names configurable
'recordsTotal' => $totalCount,
'recordsFiltered' => $totalCount,
'data' => $tmpData,
];
header('Content-Type: application/json');
echo json_encode($data);die;
}
|
[
"public",
"function",
"renderJson",
"(",
")",
"{",
"$",
"totalCount",
"=",
"$",
"this",
"->",
"getDatasource",
"(",
")",
"->",
"totalCount",
"(",
")",
";",
"$",
"rows",
"=",
"$",
"this",
"->",
"getDatasource",
"(",
")",
"->",
"listRows",
"(",
")",
";",
"$",
"tmpData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"tmp",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"currentRow",
"=",
"new",
"DefaultRow",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"rowCallback",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"this",
"->",
"rowCallback",
"->",
"call",
"(",
"$",
"this",
",",
"$",
"row",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getColumns",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"currentColumn",
"=",
"$",
"key",
";",
"$",
"tmp",
"[",
"$",
"column",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"column",
"->",
"format",
"(",
"$",
"row",
")",
";",
"}",
"$",
"tmpData",
"[",
"]",
"=",
"$",
"tmp",
";",
"}",
"$",
"data",
"=",
"[",
"'draw'",
"=>",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'draw'",
")",
",",
"// @todo param names configurable",
"'recordsTotal'",
"=>",
"$",
"totalCount",
",",
"'recordsFiltered'",
"=>",
"$",
"totalCount",
",",
"'data'",
"=>",
"$",
"tmpData",
",",
"]",
";",
"header",
"(",
"'Content-Type: application/json'",
")",
";",
"echo",
"json_encode",
"(",
"$",
"data",
")",
";",
"die",
";",
"}"
] |
Send immediately
|
[
"Send",
"immediately"
] |
train
|
https://github.com/abbert/datagrid/blob/fff9ee02f9f41c734f926c9d4834a251b891a6e1/src/Datagrid.php#L197-L228
|
lode/fem
|
src/resources.php
|
resources.get_timestamped_url
|
private static function get_timestamped_url($file, $type) {
$search = ['{{root_dir}}', '{{type}}'];
$replace = [self::$root_dir, $type];
$base_path = str_replace($search, $replace, self::$base_path);
$base_url = str_replace($search, $replace, self::$base_url);
$file = trim($file);
$absolute = ($file[0] == '/');
$file = ($absolute) ? $file : $base_url.$file;
$full_path = $base_path.$file.'.'.$type;
if (file_exists($full_path) == false) {
$exception = bootstrap::get_library('exception');
throw new $exception('can not find '.$type.' resource '.$file);
}
$timestamp = filemtime($full_path);
$full_url = $file.'.'.$timestamp.'.'.$type;
return $full_url;
}
|
php
|
private static function get_timestamped_url($file, $type) {
$search = ['{{root_dir}}', '{{type}}'];
$replace = [self::$root_dir, $type];
$base_path = str_replace($search, $replace, self::$base_path);
$base_url = str_replace($search, $replace, self::$base_url);
$file = trim($file);
$absolute = ($file[0] == '/');
$file = ($absolute) ? $file : $base_url.$file;
$full_path = $base_path.$file.'.'.$type;
if (file_exists($full_path) == false) {
$exception = bootstrap::get_library('exception');
throw new $exception('can not find '.$type.' resource '.$file);
}
$timestamp = filemtime($full_path);
$full_url = $file.'.'.$timestamp.'.'.$type;
return $full_url;
}
|
[
"private",
"static",
"function",
"get_timestamped_url",
"(",
"$",
"file",
",",
"$",
"type",
")",
"{",
"$",
"search",
"=",
"[",
"'{{root_dir}}'",
",",
"'{{type}}'",
"]",
";",
"$",
"replace",
"=",
"[",
"self",
"::",
"$",
"root_dir",
",",
"$",
"type",
"]",
";",
"$",
"base_path",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"self",
"::",
"$",
"base_path",
")",
";",
"$",
"base_url",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"self",
"::",
"$",
"base_url",
")",
";",
"$",
"file",
"=",
"trim",
"(",
"$",
"file",
")",
";",
"$",
"absolute",
"=",
"(",
"$",
"file",
"[",
"0",
"]",
"==",
"'/'",
")",
";",
"$",
"file",
"=",
"(",
"$",
"absolute",
")",
"?",
"$",
"file",
":",
"$",
"base_url",
".",
"$",
"file",
";",
"$",
"full_path",
"=",
"$",
"base_path",
".",
"$",
"file",
".",
"'.'",
".",
"$",
"type",
";",
"if",
"(",
"file_exists",
"(",
"$",
"full_path",
")",
"==",
"false",
")",
"{",
"$",
"exception",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'exception'",
")",
";",
"throw",
"new",
"$",
"exception",
"(",
"'can not find '",
".",
"$",
"type",
".",
"' resource '",
".",
"$",
"file",
")",
";",
"}",
"$",
"timestamp",
"=",
"filemtime",
"(",
"$",
"full_path",
")",
";",
"$",
"full_url",
"=",
"$",
"file",
".",
"'.'",
".",
"$",
"timestamp",
".",
"'.'",
".",
"$",
"type",
";",
"return",
"$",
"full_url",
";",
"}"
] |
adds a modification timestamp to a file path
@param string $file relative path from css/ or js/, excluding the extension
or absolute from the docroot when starting with a '/'
absolute is handy for loading css from a js plugin directory
i.e.: 'foo/bar' will become '/frontend/css/foo/bar.1234567890.css'
i.e.: '/frontend/js/plugin/style' will become '/frontend/js/plugin/style.1234567890.css'
@param string $type 'css' or 'js'
@return string $file with a timestamp before the extension
|
[
"adds",
"a",
"modification",
"timestamp",
"to",
"a",
"file",
"path"
] |
train
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/resources.php#L34-L54
|
openclerk/emails
|
src/Email.php
|
Email.send
|
static function send($to_or_user, $template_id, $arguments = array()) {
// add any global arguments
foreach (static::$global_arguments as $name => $callback) {
if (!isset($arguments[$name])) {
$arguments[$name] = call_user_func($callback, $arguments);
}
}
$to_name = false;
$to_id = null;
if (is_object($to_or_user)) {
$to_email = $to_or_user->getEmail();
if (method_exists($to_or_user, 'getName')) {
$to_name = $to_or_user->getName();
}
if (method_exists($to_or_user, 'getId')) {
$to_id = $to_or_user->getId();
}
} else if (is_string($to_or_user)) {
$to_email = $to_or_user;
} else {
throw new MailerException("Unknown 'to' type " . gettype($to_or_user));
}
if (!$to_name) {
$to_name = $to_email;
}
// default arguments
if (!isset($arguments['email'])) {
$arguments['email'] = $to_email;
}
if (!isset($arguments['name'])) {
$arguments['name'] = $to_name;
}
$compiled = self::compile($template_id, $arguments);
$template = $compiled['text'];
$html_template = $compiled['html'];
$subject = $compiled['subject'];
// now send the email
// may throw MailerException
if (self::$mock_mailer) {
$message_id = call_user_func(self::$mock_mailer, $to_email, $to_name, $subject, $template, $html_template);
} else {
$message_id = Email::phpmailer($to_email, $to_name, $subject, $template, $html_template);
}
// allow others to capture this event
$result = array(
"user_id" => $to_id,
"to_name" => $to_name,
"to_email" => $to_email,
"subject" => $subject,
"template_id" => $template_id,
"arguments" => $arguments,
"message_id" => $message_id,
);
\Openclerk\Events::trigger('email_sent', $result);
return $result;
}
|
php
|
static function send($to_or_user, $template_id, $arguments = array()) {
// add any global arguments
foreach (static::$global_arguments as $name => $callback) {
if (!isset($arguments[$name])) {
$arguments[$name] = call_user_func($callback, $arguments);
}
}
$to_name = false;
$to_id = null;
if (is_object($to_or_user)) {
$to_email = $to_or_user->getEmail();
if (method_exists($to_or_user, 'getName')) {
$to_name = $to_or_user->getName();
}
if (method_exists($to_or_user, 'getId')) {
$to_id = $to_or_user->getId();
}
} else if (is_string($to_or_user)) {
$to_email = $to_or_user;
} else {
throw new MailerException("Unknown 'to' type " . gettype($to_or_user));
}
if (!$to_name) {
$to_name = $to_email;
}
// default arguments
if (!isset($arguments['email'])) {
$arguments['email'] = $to_email;
}
if (!isset($arguments['name'])) {
$arguments['name'] = $to_name;
}
$compiled = self::compile($template_id, $arguments);
$template = $compiled['text'];
$html_template = $compiled['html'];
$subject = $compiled['subject'];
// now send the email
// may throw MailerException
if (self::$mock_mailer) {
$message_id = call_user_func(self::$mock_mailer, $to_email, $to_name, $subject, $template, $html_template);
} else {
$message_id = Email::phpmailer($to_email, $to_name, $subject, $template, $html_template);
}
// allow others to capture this event
$result = array(
"user_id" => $to_id,
"to_name" => $to_name,
"to_email" => $to_email,
"subject" => $subject,
"template_id" => $template_id,
"arguments" => $arguments,
"message_id" => $message_id,
);
\Openclerk\Events::trigger('email_sent', $result);
return $result;
}
|
[
"static",
"function",
"send",
"(",
"$",
"to_or_user",
",",
"$",
"template_id",
",",
"$",
"arguments",
"=",
"array",
"(",
")",
")",
"{",
"// add any global arguments",
"foreach",
"(",
"static",
"::",
"$",
"global_arguments",
"as",
"$",
"name",
"=>",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"arguments",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"arguments",
"[",
"$",
"name",
"]",
"=",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"arguments",
")",
";",
"}",
"}",
"$",
"to_name",
"=",
"false",
";",
"$",
"to_id",
"=",
"null",
";",
"if",
"(",
"is_object",
"(",
"$",
"to_or_user",
")",
")",
"{",
"$",
"to_email",
"=",
"$",
"to_or_user",
"->",
"getEmail",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"to_or_user",
",",
"'getName'",
")",
")",
"{",
"$",
"to_name",
"=",
"$",
"to_or_user",
"->",
"getName",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"to_or_user",
",",
"'getId'",
")",
")",
"{",
"$",
"to_id",
"=",
"$",
"to_or_user",
"->",
"getId",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"to_or_user",
")",
")",
"{",
"$",
"to_email",
"=",
"$",
"to_or_user",
";",
"}",
"else",
"{",
"throw",
"new",
"MailerException",
"(",
"\"Unknown 'to' type \"",
".",
"gettype",
"(",
"$",
"to_or_user",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"to_name",
")",
"{",
"$",
"to_name",
"=",
"$",
"to_email",
";",
"}",
"// default arguments",
"if",
"(",
"!",
"isset",
"(",
"$",
"arguments",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"arguments",
"[",
"'email'",
"]",
"=",
"$",
"to_email",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"arguments",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"arguments",
"[",
"'name'",
"]",
"=",
"$",
"to_name",
";",
"}",
"$",
"compiled",
"=",
"self",
"::",
"compile",
"(",
"$",
"template_id",
",",
"$",
"arguments",
")",
";",
"$",
"template",
"=",
"$",
"compiled",
"[",
"'text'",
"]",
";",
"$",
"html_template",
"=",
"$",
"compiled",
"[",
"'html'",
"]",
";",
"$",
"subject",
"=",
"$",
"compiled",
"[",
"'subject'",
"]",
";",
"// now send the email",
"// may throw MailerException",
"if",
"(",
"self",
"::",
"$",
"mock_mailer",
")",
"{",
"$",
"message_id",
"=",
"call_user_func",
"(",
"self",
"::",
"$",
"mock_mailer",
",",
"$",
"to_email",
",",
"$",
"to_name",
",",
"$",
"subject",
",",
"$",
"template",
",",
"$",
"html_template",
")",
";",
"}",
"else",
"{",
"$",
"message_id",
"=",
"Email",
"::",
"phpmailer",
"(",
"$",
"to_email",
",",
"$",
"to_name",
",",
"$",
"subject",
",",
"$",
"template",
",",
"$",
"html_template",
")",
";",
"}",
"// allow others to capture this event",
"$",
"result",
"=",
"array",
"(",
"\"user_id\"",
"=>",
"$",
"to_id",
",",
"\"to_name\"",
"=>",
"$",
"to_name",
",",
"\"to_email\"",
"=>",
"$",
"to_email",
",",
"\"subject\"",
"=>",
"$",
"subject",
",",
"\"template_id\"",
"=>",
"$",
"template_id",
",",
"\"arguments\"",
"=>",
"$",
"arguments",
",",
"\"message_id\"",
"=>",
"$",
"message_id",
",",
")",
";",
"\\",
"Openclerk",
"\\",
"Events",
"::",
"trigger",
"(",
"'email_sent'",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Send an email with the given template to the given user or address.
The subject of the e-mail is obtained from the first line of the text e-mail template, or the
<title> of the HTML template.
TODO support mock mailing
TODO support i18n
TODO service wrapper to allow emails to be queued
@param $to_or_user either an email address, or something with getEmail() and optionally getName()
@throws MailerException if the mail could not be immediately sent (e.g. technical error, invalid e-mail address...)
@return the email result object, which is also sent to the `email_sent` event trigger
|
[
"Send",
"an",
"email",
"with",
"the",
"given",
"template",
"to",
"the",
"given",
"user",
"or",
"address",
".",
"The",
"subject",
"of",
"the",
"e",
"-",
"mail",
"is",
"obtained",
"from",
"the",
"first",
"line",
"of",
"the",
"text",
"e",
"-",
"mail",
"template",
"or",
"the",
"<title",
">",
"of",
"the",
"HTML",
"template",
"."
] |
train
|
https://github.com/openclerk/emails/blob/b145e5f1f85524e84a37784e86d6beeac66999d2/src/Email.php#L31-L92
|
openclerk/emails
|
src/Email.php
|
Email.phpmailer
|
static function phpmailer($to, $to_name, $subject, $message, $html_message = false) {
$mail = new \PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = \Openclerk\Config::get('phpmailer_host'); // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = \Openclerk\Config::get('phpmailer_username'); // SMTP username
$mail->Password = \Openclerk\Config::get('phpmailer_password'); // SMTP password
$mail->From = \Openclerk\Config::get('phpmailer_from');
$mail->FromName = \Openclerk\Config::get('phpmailer_from_name');
$mail->Sender = \Openclerk\Config::get('phpmailer_from');
$mail->AddAddress($to, $to_name);
if (\Openclerk\Config::get('phpmailer_reply_to')) {
$mail->AddReplyTo(\Openclerk\Config::get('phpmailer_reply_to'));
}
if (\Openclerk\Config::get('phpmailer_bcc', false)) {
$mail->AddBCC(\Openclerk\Config::get('phpmailer_bcc'));
}
$mail->Subject = $subject;
if ($html_message) {
$mail->Body = $html_message;
$mail->AltBody = $message;
$mail->IsHTML(true);
} else {
$mail->Body = $message;
}
if(!$mail->Send()) {
throw new MailerException("Message could not be sent: " . $mail->ErrorInfo);
}
return $mail->GetLastMessageID();
}
|
php
|
static function phpmailer($to, $to_name, $subject, $message, $html_message = false) {
$mail = new \PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = \Openclerk\Config::get('phpmailer_host'); // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = \Openclerk\Config::get('phpmailer_username'); // SMTP username
$mail->Password = \Openclerk\Config::get('phpmailer_password'); // SMTP password
$mail->From = \Openclerk\Config::get('phpmailer_from');
$mail->FromName = \Openclerk\Config::get('phpmailer_from_name');
$mail->Sender = \Openclerk\Config::get('phpmailer_from');
$mail->AddAddress($to, $to_name);
if (\Openclerk\Config::get('phpmailer_reply_to')) {
$mail->AddReplyTo(\Openclerk\Config::get('phpmailer_reply_to'));
}
if (\Openclerk\Config::get('phpmailer_bcc', false)) {
$mail->AddBCC(\Openclerk\Config::get('phpmailer_bcc'));
}
$mail->Subject = $subject;
if ($html_message) {
$mail->Body = $html_message;
$mail->AltBody = $message;
$mail->IsHTML(true);
} else {
$mail->Body = $message;
}
if(!$mail->Send()) {
throw new MailerException("Message could not be sent: " . $mail->ErrorInfo);
}
return $mail->GetLastMessageID();
}
|
[
"static",
"function",
"phpmailer",
"(",
"$",
"to",
",",
"$",
"to_name",
",",
"$",
"subject",
",",
"$",
"message",
",",
"$",
"html_message",
"=",
"false",
")",
"{",
"$",
"mail",
"=",
"new",
"\\",
"PHPMailer",
"(",
")",
";",
"$",
"mail",
"->",
"IsSMTP",
"(",
")",
";",
"// set mailer to use SMTP",
"$",
"mail",
"->",
"Host",
"=",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_host'",
")",
";",
"// specify main and backup server",
"$",
"mail",
"->",
"SMTPAuth",
"=",
"true",
";",
"// turn on SMTP authentication",
"$",
"mail",
"->",
"Username",
"=",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_username'",
")",
";",
"// SMTP username",
"$",
"mail",
"->",
"Password",
"=",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_password'",
")",
";",
"// SMTP password",
"$",
"mail",
"->",
"From",
"=",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_from'",
")",
";",
"$",
"mail",
"->",
"FromName",
"=",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_from_name'",
")",
";",
"$",
"mail",
"->",
"Sender",
"=",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_from'",
")",
";",
"$",
"mail",
"->",
"AddAddress",
"(",
"$",
"to",
",",
"$",
"to_name",
")",
";",
"if",
"(",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_reply_to'",
")",
")",
"{",
"$",
"mail",
"->",
"AddReplyTo",
"(",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_reply_to'",
")",
")",
";",
"}",
"if",
"(",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_bcc'",
",",
"false",
")",
")",
"{",
"$",
"mail",
"->",
"AddBCC",
"(",
"\\",
"Openclerk",
"\\",
"Config",
"::",
"get",
"(",
"'phpmailer_bcc'",
")",
")",
";",
"}",
"$",
"mail",
"->",
"Subject",
"=",
"$",
"subject",
";",
"if",
"(",
"$",
"html_message",
")",
"{",
"$",
"mail",
"->",
"Body",
"=",
"$",
"html_message",
";",
"$",
"mail",
"->",
"AltBody",
"=",
"$",
"message",
";",
"$",
"mail",
"->",
"IsHTML",
"(",
"true",
")",
";",
"}",
"else",
"{",
"$",
"mail",
"->",
"Body",
"=",
"$",
"message",
";",
"}",
"if",
"(",
"!",
"$",
"mail",
"->",
"Send",
"(",
")",
")",
"{",
"throw",
"new",
"MailerException",
"(",
"\"Message could not be sent: \"",
".",
"$",
"mail",
"->",
"ErrorInfo",
")",
";",
"}",
"return",
"$",
"mail",
"->",
"GetLastMessageID",
"(",
")",
";",
"}"
] |
TODO support HTML emails
@return the sent message ID
@throws MailerException if the mail could not be immediately sent
|
[
"TODO",
"support",
"HTML",
"emails"
] |
train
|
https://github.com/openclerk/emails/blob/b145e5f1f85524e84a37784e86d6beeac66999d2/src/Email.php#L180-L215
|
tableau-mkt/eggs-n-cereal
|
src/Utils/ConverterToHTML.php
|
ConverterToHTML.toHTML
|
public function toHTML($pretty_print = TRUE) {
$this->out = new \DOMDocument('1.0', 'UTF-8');
$this->out->formatOutput = $pretty_print;
$field = $this->doc->getElementsByTagName('xlf:group')->item(0);
foreach ($field->childNodes as $child) {
if ($output = $this->convert($child)) {
$this->out->appendChild($output);
}
}
return html_entity_decode($this->out->saveHTML(), ENT_QUOTES, 'UTF-8');
}
|
php
|
public function toHTML($pretty_print = TRUE) {
$this->out = new \DOMDocument('1.0', 'UTF-8');
$this->out->formatOutput = $pretty_print;
$field = $this->doc->getElementsByTagName('xlf:group')->item(0);
foreach ($field->childNodes as $child) {
if ($output = $this->convert($child)) {
$this->out->appendChild($output);
}
}
return html_entity_decode($this->out->saveHTML(), ENT_QUOTES, 'UTF-8');
}
|
[
"public",
"function",
"toHTML",
"(",
"$",
"pretty_print",
"=",
"TRUE",
")",
"{",
"$",
"this",
"->",
"out",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
")",
";",
"$",
"this",
"->",
"out",
"->",
"formatOutput",
"=",
"$",
"pretty_print",
";",
"$",
"field",
"=",
"$",
"this",
"->",
"doc",
"->",
"getElementsByTagName",
"(",
"'xlf:group'",
")",
"->",
"item",
"(",
"0",
")",
";",
"foreach",
"(",
"$",
"field",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"output",
"=",
"$",
"this",
"->",
"convert",
"(",
"$",
"child",
")",
")",
"{",
"$",
"this",
"->",
"out",
"->",
"appendChild",
"(",
"$",
"output",
")",
";",
"}",
"}",
"return",
"html_entity_decode",
"(",
"$",
"this",
"->",
"out",
"->",
"saveHTML",
"(",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"}"
] |
Converts XML to the corresponding HTML representation.
@return string
The source XML converted to HTML.
|
[
"Converts",
"XML",
"to",
"the",
"corresponding",
"HTML",
"representation",
"."
] |
train
|
https://github.com/tableau-mkt/eggs-n-cereal/blob/778b83ddae1dd687724a84545ce8afa1a31e4bcf/src/Utils/ConverterToHTML.php#L36-L49
|
VincentChalnot/SidusAdminBundle
|
Admin/Admin.php
|
Admin.getAction
|
public function getAction(string $code): Action
{
if (!$this->hasAction($code)) {
throw new \UnexpectedValueException("No action with code: '{$code}' for admin '{$this->getCode()}'");
}
return $this->actions[$code];
}
|
php
|
public function getAction(string $code): Action
{
if (!$this->hasAction($code)) {
throw new \UnexpectedValueException("No action with code: '{$code}' for admin '{$this->getCode()}'");
}
return $this->actions[$code];
}
|
[
"public",
"function",
"getAction",
"(",
"string",
"$",
"code",
")",
":",
"Action",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasAction",
"(",
"$",
"code",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"No action with code: '{$code}' for admin '{$this->getCode()}'\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"actions",
"[",
"$",
"code",
"]",
";",
"}"
] |
@param string $code
@throws \UnexpectedValueException
@return Action
|
[
"@param",
"string",
"$code"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Admin/Admin.php#L134-L141
|
VincentChalnot/SidusAdminBundle
|
Admin/Admin.php
|
Admin.hasRoute
|
public function hasRoute(string $route): bool
{
foreach ($this->getActions() as $action) {
if ($action->getRouteName() === $route) {
return true;
}
}
return false;
}
|
php
|
public function hasRoute(string $route): bool
{
foreach ($this->getActions() as $action) {
if ($action->getRouteName() === $route) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasRoute",
"(",
"string",
"$",
"route",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getActions",
"(",
")",
"as",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"action",
"->",
"getRouteName",
"(",
")",
"===",
"$",
"route",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
@param string $route
@return bool
|
[
"@param",
"string",
"$route"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Admin/Admin.php#L158-L167
|
VincentChalnot/SidusAdminBundle
|
Admin/Admin.php
|
Admin.getOption
|
public function getOption(string $option, $default = null)
{
if (!$this->hasOption($option)) {
return $default;
}
return $this->options[$option];
}
|
php
|
public function getOption(string $option, $default = null)
{
if (!$this->hasOption($option)) {
return $default;
}
return $this->options[$option];
}
|
[
"public",
"function",
"getOption",
"(",
"string",
"$",
"option",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOption",
"(",
"$",
"option",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}"
] |
@param string $option
@param mixed $default
@return mixed
|
[
"@param",
"string",
"$option",
"@param",
"mixed",
"$default"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Admin/Admin.php#L199-L206
|
VincentChalnot/SidusAdminBundle
|
Admin/Admin.php
|
Admin.setCurrentAction
|
public function setCurrentAction($action): void
{
if (!$action instanceof Action) {
$action = $this->getAction($action);
}
$this->currentAction = $action;
}
|
php
|
public function setCurrentAction($action): void
{
if (!$action instanceof Action) {
$action = $this->getAction($action);
}
$this->currentAction = $action;
}
|
[
"public",
"function",
"setCurrentAction",
"(",
"$",
"action",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"action",
"instanceof",
"Action",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"getAction",
"(",
"$",
"action",
")",
";",
"}",
"$",
"this",
"->",
"currentAction",
"=",
"$",
"action",
";",
"}"
] |
@param string|Action $action
@throws \UnexpectedValueException
|
[
"@param",
"string|Action",
"$action"
] |
train
|
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Admin/Admin.php#L239-L245
|
ClanCats/Core
|
src/classes/CCDataObject.php
|
CCDataObject.set
|
public function set( $key, $value, $param = null )
{
CCArr::set( $key, $value, $this->_data );
}
|
php
|
public function set( $key, $value, $param = null )
{
CCArr::set( $key, $value, $this->_data );
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"param",
"=",
"null",
")",
"{",
"CCArr",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"_data",
")",
";",
"}"
] |
set data to the object.
@param string $key
@param mixed $value
@param mixed $param
@return void
|
[
"set",
"data",
"to",
"the",
"object",
"."
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCDataObject.php#L43-L46
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Processor.php
|
Processor.synchronizeCollectionNormal
|
public function synchronizeCollectionNormal($entity, $field, $toCollection, Type $type) {
if (!$this->dc) {
throw new \RuntimeException('DCPackage muss für synchronizeCollectionNormal gesetzt sein');
}
$entityMeta = $this->dc->getEntityMeta($entity->getEntityName());
$entityClassMeta = $entityMeta->getClassMetadata();
$entityAssoc = $entityClassMeta->getAssociationMapping($field);
$fromCollection = $entity->callGetter($field);
if (!$entityClassMeta->isCollectionValuedAssociation($field)) {
throw new \RuntimeException('Das Property '.$entity->getEntityName().'->'.$field.' ist keine Collection und kann somit nicht synchronisiert werden');
}
$adder = $remover = NULL;
if ($entityClassMeta->isAssociationInverseSide($field)) {
$otherMeta = $this->dc->getEntityMeta($entityAssoc['targetEntity']);
$otherMetaClass = $otherMeta->getClassMetadata();
$otherProperty = $entityAssoc['mappedBy'];
$otherIsCollection = $otherMetaClass->isCollectionValuedAssociation($otherProperty);
$addOrSet = $otherIsCollection
? 'add'.ucfirst($otherProperty)
: 'set'.ucfirst($otherProperty);
// da der CollectionSynchronizer nur die owningSide automatisch pflegt, injecten wir hier den adder und remover um die inverse Side zu pflegen
$adder = function ($entity, $toEntity, $repository) use ($addOrSet) {
$repository->persist($toEntity);
$toEntity->$addOrSet($entity);
};
if ($otherIsCollection) {
$remove = 'remove'.ucfirst($otherProperty);
$remover = function ($entity, $toEntity, $repository) use ($remove) {
$repository->persist($toEntity);
$toEntity->$remove($entity);
};
} else {
$set = 'set'.ucfirst($otherProperty);
$remover = function ($entity, $toEntity, $repository) use ($set) {
$repository->persist($toEntity);
$toEntity->$set(NULL);
};
}
}
$synchronizer = CollectionSynchronizer::createFor($entity->getEntityName(), $field, $this->dc);
$synchronizer->init($entity, $adder, $remover);
return $synchronizer->process($fromCollection, $toCollection);
}
|
php
|
public function synchronizeCollectionNormal($entity, $field, $toCollection, Type $type) {
if (!$this->dc) {
throw new \RuntimeException('DCPackage muss für synchronizeCollectionNormal gesetzt sein');
}
$entityMeta = $this->dc->getEntityMeta($entity->getEntityName());
$entityClassMeta = $entityMeta->getClassMetadata();
$entityAssoc = $entityClassMeta->getAssociationMapping($field);
$fromCollection = $entity->callGetter($field);
if (!$entityClassMeta->isCollectionValuedAssociation($field)) {
throw new \RuntimeException('Das Property '.$entity->getEntityName().'->'.$field.' ist keine Collection und kann somit nicht synchronisiert werden');
}
$adder = $remover = NULL;
if ($entityClassMeta->isAssociationInverseSide($field)) {
$otherMeta = $this->dc->getEntityMeta($entityAssoc['targetEntity']);
$otherMetaClass = $otherMeta->getClassMetadata();
$otherProperty = $entityAssoc['mappedBy'];
$otherIsCollection = $otherMetaClass->isCollectionValuedAssociation($otherProperty);
$addOrSet = $otherIsCollection
? 'add'.ucfirst($otherProperty)
: 'set'.ucfirst($otherProperty);
// da der CollectionSynchronizer nur die owningSide automatisch pflegt, injecten wir hier den adder und remover um die inverse Side zu pflegen
$adder = function ($entity, $toEntity, $repository) use ($addOrSet) {
$repository->persist($toEntity);
$toEntity->$addOrSet($entity);
};
if ($otherIsCollection) {
$remove = 'remove'.ucfirst($otherProperty);
$remover = function ($entity, $toEntity, $repository) use ($remove) {
$repository->persist($toEntity);
$toEntity->$remove($entity);
};
} else {
$set = 'set'.ucfirst($otherProperty);
$remover = function ($entity, $toEntity, $repository) use ($set) {
$repository->persist($toEntity);
$toEntity->$set(NULL);
};
}
}
$synchronizer = CollectionSynchronizer::createFor($entity->getEntityName(), $field, $this->dc);
$synchronizer->init($entity, $adder, $remover);
return $synchronizer->process($fromCollection, $toCollection);
}
|
[
"public",
"function",
"synchronizeCollectionNormal",
"(",
"$",
"entity",
",",
"$",
"field",
",",
"$",
"toCollection",
",",
"Type",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dc",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'DCPackage muss für synchronizeCollectionNormal gesetzt sein')",
";",
"",
"}",
"$",
"entityMeta",
"=",
"$",
"this",
"->",
"dc",
"->",
"getEntityMeta",
"(",
"$",
"entity",
"->",
"getEntityName",
"(",
")",
")",
";",
"$",
"entityClassMeta",
"=",
"$",
"entityMeta",
"->",
"getClassMetadata",
"(",
")",
";",
"$",
"entityAssoc",
"=",
"$",
"entityClassMeta",
"->",
"getAssociationMapping",
"(",
"$",
"field",
")",
";",
"$",
"fromCollection",
"=",
"$",
"entity",
"->",
"callGetter",
"(",
"$",
"field",
")",
";",
"if",
"(",
"!",
"$",
"entityClassMeta",
"->",
"isCollectionValuedAssociation",
"(",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Das Property '",
".",
"$",
"entity",
"->",
"getEntityName",
"(",
")",
".",
"'->'",
".",
"$",
"field",
".",
"' ist keine Collection und kann somit nicht synchronisiert werden'",
")",
";",
"}",
"$",
"adder",
"=",
"$",
"remover",
"=",
"NULL",
";",
"if",
"(",
"$",
"entityClassMeta",
"->",
"isAssociationInverseSide",
"(",
"$",
"field",
")",
")",
"{",
"$",
"otherMeta",
"=",
"$",
"this",
"->",
"dc",
"->",
"getEntityMeta",
"(",
"$",
"entityAssoc",
"[",
"'targetEntity'",
"]",
")",
";",
"$",
"otherMetaClass",
"=",
"$",
"otherMeta",
"->",
"getClassMetadata",
"(",
")",
";",
"$",
"otherProperty",
"=",
"$",
"entityAssoc",
"[",
"'mappedBy'",
"]",
";",
"$",
"otherIsCollection",
"=",
"$",
"otherMetaClass",
"->",
"isCollectionValuedAssociation",
"(",
"$",
"otherProperty",
")",
";",
"$",
"addOrSet",
"=",
"$",
"otherIsCollection",
"?",
"'add'",
".",
"ucfirst",
"(",
"$",
"otherProperty",
")",
":",
"'set'",
".",
"ucfirst",
"(",
"$",
"otherProperty",
")",
";",
"// da der CollectionSynchronizer nur die owningSide automatisch pflegt, injecten wir hier den adder und remover um die inverse Side zu pflegen",
"$",
"adder",
"=",
"function",
"(",
"$",
"entity",
",",
"$",
"toEntity",
",",
"$",
"repository",
")",
"use",
"(",
"$",
"addOrSet",
")",
"{",
"$",
"repository",
"->",
"persist",
"(",
"$",
"toEntity",
")",
";",
"$",
"toEntity",
"->",
"$",
"addOrSet",
"(",
"$",
"entity",
")",
";",
"}",
";",
"if",
"(",
"$",
"otherIsCollection",
")",
"{",
"$",
"remove",
"=",
"'remove'",
".",
"ucfirst",
"(",
"$",
"otherProperty",
")",
";",
"$",
"remover",
"=",
"function",
"(",
"$",
"entity",
",",
"$",
"toEntity",
",",
"$",
"repository",
")",
"use",
"(",
"$",
"remove",
")",
"{",
"$",
"repository",
"->",
"persist",
"(",
"$",
"toEntity",
")",
";",
"$",
"toEntity",
"->",
"$",
"remove",
"(",
"$",
"entity",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
"set",
"=",
"'set'",
".",
"ucfirst",
"(",
"$",
"otherProperty",
")",
";",
"$",
"remover",
"=",
"function",
"(",
"$",
"entity",
",",
"$",
"toEntity",
",",
"$",
"repository",
")",
"use",
"(",
"$",
"set",
")",
"{",
"$",
"repository",
"->",
"persist",
"(",
"$",
"toEntity",
")",
";",
"$",
"toEntity",
"->",
"$",
"set",
"(",
"NULL",
")",
";",
"}",
";",
"}",
"}",
"$",
"synchronizer",
"=",
"CollectionSynchronizer",
"::",
"createFor",
"(",
"$",
"entity",
"->",
"getEntityName",
"(",
")",
",",
"$",
"field",
",",
"$",
"this",
"->",
"dc",
")",
";",
"$",
"synchronizer",
"->",
"init",
"(",
"$",
"entity",
",",
"$",
"adder",
",",
"$",
"remover",
")",
";",
"return",
"$",
"synchronizer",
"->",
"process",
"(",
"$",
"fromCollection",
",",
"$",
"toCollection",
")",
";",
"}"
] |
Synchronisiert Collections in einem Property des Entities
Initialisiert einen CollectionSynchronizer, um das $entity->$field vom $type zu $toCollection zu synchronisieren
|
[
"Synchronisiert",
"Collections",
"in",
"einem",
"Property",
"des",
"Entities"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Processor.php#L118-L168
|
webforge-labs/psc-cms
|
lib/Psc/Doctrine/Processor.php
|
Processor.synchronizeCollection
|
public function synchronizeCollection($associationName, $newCollection) {
if (!is_string($associationName)) {
throw new \Psc\Exception('string erwartet: '.Code::varInfo($associationName));
}
/*
$mapping = $coll->getMapping();
$targetClass = $this->_em->getClassMetadata($mapping['targetEntity']);
$sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
*/
if ($this->entity instanceof \Psc\Doctrine\Object) {
$entityClass = $this->entity->getDoctrineMetadata(); // Sound
} elseif ($this->entity instanceof \Psc\Doctrine\Entity) {
$entityClass = $this->em->getClassMetadata($this->entity->getEntityName());
} else {
throw new \InvalidArgumentException('$this->entity ist von der Klasse: '.Code::getClass($this->entity).' und diese ist unbekannt');
}
$entityAssoc = $entityClass->getAssociationMapping($associationName); // speakers
$owning = $entityAssoc['isOwningSide']; // true
$targetClass = $this->em->getClassMetadata($entityAssoc['targetEntity']); // Metadata:Speaker
if ($owning) {
$entityProperty = $entityAssoc['inversedBy'];
$collectionProperty = $entityAssoc['fieldName'];
} else {
$entityProperty = $entityAssoc['mappedBy'];
$collectionProperty = $entityAssoc['fieldName'];
}
// entityProperty = sounds
// collectionProperty = speakers
$getter = Code::castGetter($collectionProperty); //getSpeakers
$collection = $getter($this->entity); // $this->entity->getSpeakers()
$collection = Code::castCollection($collection);
$newCollection = Code::castCollection($newCollection);
$this->log(sprintf("synchronizeCollection '%s'",$associationName));
$this->log('in DBCollection:');
$this->log(DoctrineHelper::debugCollection($collection));
$this->log(NULL);
$this->log('in FormCollection:');
$this->log(DoctrineHelper::debugCollection($newCollection));
$this->log(NULL);
$this->log('Processing:');
/*
Wir synchronisieren hier auf der Owning Side oder Reverse Side
jenachdem müssen wir auf der owning oder reverse side die add + remove funktionen aufrufen
*/
if ($owning) {
$remove = 'remove'.ucfirst(Inflector::singular($collectionProperty)); // removeSpeaker
$add = 'add'.ucfirst(Inflector::singular($collectionProperty)); // addSpeaker
} else {
$remove = 'remove'.ucfirst(Inflector::singular($entityProperty)); // removeSound
$add = 'add'.ucfirst(Inflector::singular($entityProperty)); // addSound
}
$logThis = Code::getClassName($entityClass->getName());
// @TODO hier mit reflection prüfen
//if (!->hasMethod($remove)) {
// throw new \Psc\Exception('Es gibt keine '.$remove.' Methode im Entity: '.$owningEntity);
//}
//if (!$this->entity->hasMethod($add)) {
// throw new \Psc\Exception('Es gibt keine '.$add.' Methode im Entity: '.$owningEntity);
//}
//
foreach ($collection->deleteDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) {
if ($owning) {
$this->entity->$remove($entity); // $sound->removeSpeaker($speaker)
} else {
$this->em->persist($entity); // $speaker persist
$entity->$remove($this->entity); // $speaker->removeSound($sound)
}
}
foreach ($collection->insertDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) {
if ($owning) {
$this->entity->$add($entity);
$this->em->persist($entity);
} else {
$entity->$add($this->entity);
$this->em->persist($entity);
}
}
}
|
php
|
public function synchronizeCollection($associationName, $newCollection) {
if (!is_string($associationName)) {
throw new \Psc\Exception('string erwartet: '.Code::varInfo($associationName));
}
/*
$mapping = $coll->getMapping();
$targetClass = $this->_em->getClassMetadata($mapping['targetEntity']);
$sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
*/
if ($this->entity instanceof \Psc\Doctrine\Object) {
$entityClass = $this->entity->getDoctrineMetadata(); // Sound
} elseif ($this->entity instanceof \Psc\Doctrine\Entity) {
$entityClass = $this->em->getClassMetadata($this->entity->getEntityName());
} else {
throw new \InvalidArgumentException('$this->entity ist von der Klasse: '.Code::getClass($this->entity).' und diese ist unbekannt');
}
$entityAssoc = $entityClass->getAssociationMapping($associationName); // speakers
$owning = $entityAssoc['isOwningSide']; // true
$targetClass = $this->em->getClassMetadata($entityAssoc['targetEntity']); // Metadata:Speaker
if ($owning) {
$entityProperty = $entityAssoc['inversedBy'];
$collectionProperty = $entityAssoc['fieldName'];
} else {
$entityProperty = $entityAssoc['mappedBy'];
$collectionProperty = $entityAssoc['fieldName'];
}
// entityProperty = sounds
// collectionProperty = speakers
$getter = Code::castGetter($collectionProperty); //getSpeakers
$collection = $getter($this->entity); // $this->entity->getSpeakers()
$collection = Code::castCollection($collection);
$newCollection = Code::castCollection($newCollection);
$this->log(sprintf("synchronizeCollection '%s'",$associationName));
$this->log('in DBCollection:');
$this->log(DoctrineHelper::debugCollection($collection));
$this->log(NULL);
$this->log('in FormCollection:');
$this->log(DoctrineHelper::debugCollection($newCollection));
$this->log(NULL);
$this->log('Processing:');
/*
Wir synchronisieren hier auf der Owning Side oder Reverse Side
jenachdem müssen wir auf der owning oder reverse side die add + remove funktionen aufrufen
*/
if ($owning) {
$remove = 'remove'.ucfirst(Inflector::singular($collectionProperty)); // removeSpeaker
$add = 'add'.ucfirst(Inflector::singular($collectionProperty)); // addSpeaker
} else {
$remove = 'remove'.ucfirst(Inflector::singular($entityProperty)); // removeSound
$add = 'add'.ucfirst(Inflector::singular($entityProperty)); // addSound
}
$logThis = Code::getClassName($entityClass->getName());
// @TODO hier mit reflection prüfen
//if (!->hasMethod($remove)) {
// throw new \Psc\Exception('Es gibt keine '.$remove.' Methode im Entity: '.$owningEntity);
//}
//if (!$this->entity->hasMethod($add)) {
// throw new \Psc\Exception('Es gibt keine '.$add.' Methode im Entity: '.$owningEntity);
//}
//
foreach ($collection->deleteDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) {
if ($owning) {
$this->entity->$remove($entity); // $sound->removeSpeaker($speaker)
} else {
$this->em->persist($entity); // $speaker persist
$entity->$remove($this->entity); // $speaker->removeSound($sound)
}
}
foreach ($collection->insertDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) {
if ($owning) {
$this->entity->$add($entity);
$this->em->persist($entity);
} else {
$entity->$add($this->entity);
$this->em->persist($entity);
}
}
}
|
[
"public",
"function",
"synchronizeCollection",
"(",
"$",
"associationName",
",",
"$",
"newCollection",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"associationName",
")",
")",
"{",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'string erwartet: '",
".",
"Code",
"::",
"varInfo",
"(",
"$",
"associationName",
")",
")",
";",
"}",
"/*\n $mapping = $coll->getMapping();\n $targetClass = $this->_em->getClassMetadata($mapping['targetEntity']);\n $sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']);\n $id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());\n */",
"if",
"(",
"$",
"this",
"->",
"entity",
"instanceof",
"\\",
"Psc",
"\\",
"Doctrine",
"\\",
"Object",
")",
"{",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"entity",
"->",
"getDoctrineMetadata",
"(",
")",
";",
"// Sound",
"}",
"elseif",
"(",
"$",
"this",
"->",
"entity",
"instanceof",
"\\",
"Psc",
"\\",
"Doctrine",
"\\",
"Entity",
")",
"{",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"$",
"this",
"->",
"entity",
"->",
"getEntityName",
"(",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$this->entity ist von der Klasse: '",
".",
"Code",
"::",
"getClass",
"(",
"$",
"this",
"->",
"entity",
")",
".",
"' und diese ist unbekannt'",
")",
";",
"}",
"$",
"entityAssoc",
"=",
"$",
"entityClass",
"->",
"getAssociationMapping",
"(",
"$",
"associationName",
")",
";",
"// speakers",
"$",
"owning",
"=",
"$",
"entityAssoc",
"[",
"'isOwningSide'",
"]",
";",
"// true",
"$",
"targetClass",
"=",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"$",
"entityAssoc",
"[",
"'targetEntity'",
"]",
")",
";",
"// Metadata:Speaker",
"if",
"(",
"$",
"owning",
")",
"{",
"$",
"entityProperty",
"=",
"$",
"entityAssoc",
"[",
"'inversedBy'",
"]",
";",
"$",
"collectionProperty",
"=",
"$",
"entityAssoc",
"[",
"'fieldName'",
"]",
";",
"}",
"else",
"{",
"$",
"entityProperty",
"=",
"$",
"entityAssoc",
"[",
"'mappedBy'",
"]",
";",
"$",
"collectionProperty",
"=",
"$",
"entityAssoc",
"[",
"'fieldName'",
"]",
";",
"}",
"// entityProperty = sounds",
"// collectionProperty = speakers",
"$",
"getter",
"=",
"Code",
"::",
"castGetter",
"(",
"$",
"collectionProperty",
")",
";",
"//getSpeakers",
"$",
"collection",
"=",
"$",
"getter",
"(",
"$",
"this",
"->",
"entity",
")",
";",
"// $this->entity->getSpeakers()",
"$",
"collection",
"=",
"Code",
"::",
"castCollection",
"(",
"$",
"collection",
")",
";",
"$",
"newCollection",
"=",
"Code",
"::",
"castCollection",
"(",
"$",
"newCollection",
")",
";",
"$",
"this",
"->",
"log",
"(",
"sprintf",
"(",
"\"synchronizeCollection '%s'\"",
",",
"$",
"associationName",
")",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'in DBCollection:'",
")",
";",
"$",
"this",
"->",
"log",
"(",
"DoctrineHelper",
"::",
"debugCollection",
"(",
"$",
"collection",
")",
")",
";",
"$",
"this",
"->",
"log",
"(",
"NULL",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'in FormCollection:'",
")",
";",
"$",
"this",
"->",
"log",
"(",
"DoctrineHelper",
"::",
"debugCollection",
"(",
"$",
"newCollection",
")",
")",
";",
"$",
"this",
"->",
"log",
"(",
"NULL",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'Processing:'",
")",
";",
"/*\n Wir synchronisieren hier auf der Owning Side oder Reverse Side\n jenachdem müssen wir auf der owning oder reverse side die add + remove funktionen aufrufen\n */",
"if",
"(",
"$",
"owning",
")",
"{",
"$",
"remove",
"=",
"'remove'",
".",
"ucfirst",
"(",
"Inflector",
"::",
"singular",
"(",
"$",
"collectionProperty",
")",
")",
";",
"// removeSpeaker",
"$",
"add",
"=",
"'add'",
".",
"ucfirst",
"(",
"Inflector",
"::",
"singular",
"(",
"$",
"collectionProperty",
")",
")",
";",
"// addSpeaker",
"}",
"else",
"{",
"$",
"remove",
"=",
"'remove'",
".",
"ucfirst",
"(",
"Inflector",
"::",
"singular",
"(",
"$",
"entityProperty",
")",
")",
";",
"// removeSound",
"$",
"add",
"=",
"'add'",
".",
"ucfirst",
"(",
"Inflector",
"::",
"singular",
"(",
"$",
"entityProperty",
")",
")",
";",
"// addSound",
"}",
"$",
"logThis",
"=",
"Code",
"::",
"getClassName",
"(",
"$",
"entityClass",
"->",
"getName",
"(",
")",
")",
";",
"// @TODO hier mit reflection prüfen",
"//if (!->hasMethod($remove)) {",
"// throw new \\Psc\\Exception('Es gibt keine '.$remove.' Methode im Entity: '.$owningEntity);",
"//}",
"//if (!$this->entity->hasMethod($add)) {",
"// throw new \\Psc\\Exception('Es gibt keine '.$add.' Methode im Entity: '.$owningEntity);",
"//}",
"//",
"foreach",
"(",
"$",
"collection",
"->",
"deleteDiff",
"(",
"$",
"newCollection",
",",
"ArrayCollection",
"::",
"COMPARE_OBJECTS",
")",
"as",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"owning",
")",
"{",
"$",
"this",
"->",
"entity",
"->",
"$",
"remove",
"(",
"$",
"entity",
")",
";",
"// $sound->removeSpeaker($speaker)",
"}",
"else",
"{",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"// $speaker persist",
"$",
"entity",
"->",
"$",
"remove",
"(",
"$",
"this",
"->",
"entity",
")",
";",
"// $speaker->removeSound($sound)",
"}",
"}",
"foreach",
"(",
"$",
"collection",
"->",
"insertDiff",
"(",
"$",
"newCollection",
",",
"ArrayCollection",
"::",
"COMPARE_OBJECTS",
")",
"as",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"owning",
")",
"{",
"$",
"this",
"->",
"entity",
"->",
"$",
"add",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"}",
"else",
"{",
"$",
"entity",
"->",
"$",
"add",
"(",
"$",
"this",
"->",
"entity",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"}",
"}",
"}"
] |
Synchronisiert eine Collection eines Entities mit Entities in der Datenbank (deprecated)
Diese Art der Synchroniserung ist deprecated, weil es mittlerweile ausgelagerte Funktionen dafür gibt
(siehe Psc\Doctrine\*Synchro*)
also es werden für die bestehenden Objekte in $entity->$collectionProperty die objekte gelöscht
die nicht in newCollection drin sind und die, die in $newCollection drin sind aber nicht in
$entity->$collectionProperty gelöscht
- Achtung(!): dies führt persist() auf den Entitys der Collection (also quasi andere Seite der Association) aus, wenn $this->entity nicht die Owning-Side der CollectionAssociation ist
- Dies führt persist für items in newCollection, die neu sind
Die Basis für eine erfolgreiche Synchronization ist eine $newCollection die wirklich die gleichen Objekte enthält, für die Updates gemacht werden sollen. Also vorsicht mit serialisierten Einträgen und clones
@param string $associationName der Name des Properties der Collection in $entity
|
[
"Synchronisiert",
"eine",
"Collection",
"eines",
"Entities",
"mit",
"Entities",
"in",
"der",
"Datenbank",
"(",
"deprecated",
")"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Processor.php#L233-L320
|
Chill-project/Main
|
Timeline/TimelineBuilder.php
|
TimelineBuilder.getTimelineHTML
|
public function getTimelineHTML($context, array $args, $page = 0, $number = 20)
{
$query = $this->buildUnionQuery($context, $args, $page, $number);
$fetched = $this->runQuery($query);
$entitiesByKey = $this->getEntities($fetched, $context);
return $this->render($fetched, $entitiesByKey, $context, $args);
}
|
php
|
public function getTimelineHTML($context, array $args, $page = 0, $number = 20)
{
$query = $this->buildUnionQuery($context, $args, $page, $number);
$fetched = $this->runQuery($query);
$entitiesByKey = $this->getEntities($fetched, $context);
return $this->render($fetched, $entitiesByKey, $context, $args);
}
|
[
"public",
"function",
"getTimelineHTML",
"(",
"$",
"context",
",",
"array",
"$",
"args",
",",
"$",
"page",
"=",
"0",
",",
"$",
"number",
"=",
"20",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"buildUnionQuery",
"(",
"$",
"context",
",",
"$",
"args",
",",
"$",
"page",
",",
"$",
"number",
")",
";",
"$",
"fetched",
"=",
"$",
"this",
"->",
"runQuery",
"(",
"$",
"query",
")",
";",
"$",
"entitiesByKey",
"=",
"$",
"this",
"->",
"getEntities",
"(",
"$",
"fetched",
",",
"$",
"context",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"fetched",
",",
"$",
"entitiesByKey",
",",
"$",
"context",
",",
"$",
"args",
")",
";",
"}"
] |
return an HTML string with timeline
This function must be called from controller
@example https://redmine.champs-libres.coop/projects/chillperson/repository/revisions/bd2e1b1808f73e39532e9538413025df5487cad0/entry/Controller/TimelinePersonController.php#L47 the implementation in person bundle
@param string $context
@param array $args arguments defined by the bundle which create the context
@param int $page first page = 0
@param int $number number of items by page
@return string an HTML representation, must be included using `|raw` filter
|
[
"return",
"an",
"HTML",
"string",
"with",
"timeline"
] |
train
|
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Timeline/TimelineBuilder.php#L66-L73
|
Chill-project/Main
|
Timeline/TimelineBuilder.php
|
TimelineBuilder.getProvidersByContext
|
public function getProvidersByContext($context)
{
$providers = array();
foreach($this->providers[$context] as $providerId) {
$providers[] = $this->container->get($providerId);
}
return $providers;
}
|
php
|
public function getProvidersByContext($context)
{
$providers = array();
foreach($this->providers[$context] as $providerId) {
$providers[] = $this->container->get($providerId);
}
return $providers;
}
|
[
"public",
"function",
"getProvidersByContext",
"(",
"$",
"context",
")",
"{",
"$",
"providers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"providers",
"[",
"$",
"context",
"]",
"as",
"$",
"providerId",
")",
"{",
"$",
"providers",
"[",
"]",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"providerId",
")",
";",
"}",
"return",
"$",
"providers",
";",
"}"
] |
Get providers by context
@param string $context
@return TimelineProviderInterface[]
|
[
"Get",
"providers",
"by",
"context"
] |
train
|
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Timeline/TimelineBuilder.php#L94-L103
|
Chill-project/Main
|
Timeline/TimelineBuilder.php
|
TimelineBuilder.buildUnionQuery
|
private function buildUnionQuery($context, array $args, $page, $number)
{
//throw an exception if no provider have been defined for this context
if (!array_key_exists($context, $this->providers)) {
throw new \LogicException(sprintf('No builders have been defined for "%s"'
. ' context', $context));
}
//append SELECT queries with UNION keyword between them
$union = '';
foreach($this->getProvidersByContext($context) as $provider) {
$select = $this->buildSelectQuery($provider, $context, $args);
$append = ($union === '') ? $select : ' UNION '.$select;
$union .= $append;
}
//add ORDER BY clause and LIMIT
$union .= sprintf(' ORDER BY date DESC LIMIT %d OFFSET %d',
$number, $page * $number);
return $union;
}
|
php
|
private function buildUnionQuery($context, array $args, $page, $number)
{
//throw an exception if no provider have been defined for this context
if (!array_key_exists($context, $this->providers)) {
throw new \LogicException(sprintf('No builders have been defined for "%s"'
. ' context', $context));
}
//append SELECT queries with UNION keyword between them
$union = '';
foreach($this->getProvidersByContext($context) as $provider) {
$select = $this->buildSelectQuery($provider, $context, $args);
$append = ($union === '') ? $select : ' UNION '.$select;
$union .= $append;
}
//add ORDER BY clause and LIMIT
$union .= sprintf(' ORDER BY date DESC LIMIT %d OFFSET %d',
$number, $page * $number);
return $union;
}
|
[
"private",
"function",
"buildUnionQuery",
"(",
"$",
"context",
",",
"array",
"$",
"args",
",",
"$",
"page",
",",
"$",
"number",
")",
"{",
"//throw an exception if no provider have been defined for this context",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"context",
",",
"$",
"this",
"->",
"providers",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'No builders have been defined for \"%s\"'",
".",
"' context'",
",",
"$",
"context",
")",
")",
";",
"}",
"//append SELECT queries with UNION keyword between them",
"$",
"union",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"getProvidersByContext",
"(",
"$",
"context",
")",
"as",
"$",
"provider",
")",
"{",
"$",
"select",
"=",
"$",
"this",
"->",
"buildSelectQuery",
"(",
"$",
"provider",
",",
"$",
"context",
",",
"$",
"args",
")",
";",
"$",
"append",
"=",
"(",
"$",
"union",
"===",
"''",
")",
"?",
"$",
"select",
":",
"' UNION '",
".",
"$",
"select",
";",
"$",
"union",
".=",
"$",
"append",
";",
"}",
"//add ORDER BY clause and LIMIT",
"$",
"union",
".=",
"sprintf",
"(",
"' ORDER BY date DESC LIMIT %d OFFSET %d'",
",",
"$",
"number",
",",
"$",
"page",
"*",
"$",
"number",
")",
";",
"return",
"$",
"union",
";",
"}"
] |
build the UNION query with all providers
@uses self::buildSelectQuery to build individual SELECT queries
@param string $context
@param mixed $args
@param int $page
@param int $number
@return string
@throws \LogicException if no builder have been defined for this context
|
[
"build",
"the",
"UNION",
"query",
"with",
"all",
"providers"
] |
train
|
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Timeline/TimelineBuilder.php#L117-L137
|
Chill-project/Main
|
Timeline/TimelineBuilder.php
|
TimelineBuilder.buildSelectQuery
|
private function buildSelectQuery(TimelineProviderInterface $provider, $context, array $args)
{
$data = $provider->fetchQuery($context, $args);
return sprintf(
'SELECT %s AS id, '
. '%s AS "date", '
. "'%s' AS type "
. 'FROM %s '
. 'WHERE %s',
$data['id'],
$data['date'],
$data['type'],
$data['FROM'],
$data['WHERE']);
}
|
php
|
private function buildSelectQuery(TimelineProviderInterface $provider, $context, array $args)
{
$data = $provider->fetchQuery($context, $args);
return sprintf(
'SELECT %s AS id, '
. '%s AS "date", '
. "'%s' AS type "
. 'FROM %s '
. 'WHERE %s',
$data['id'],
$data['date'],
$data['type'],
$data['FROM'],
$data['WHERE']);
}
|
[
"private",
"function",
"buildSelectQuery",
"(",
"TimelineProviderInterface",
"$",
"provider",
",",
"$",
"context",
",",
"array",
"$",
"args",
")",
"{",
"$",
"data",
"=",
"$",
"provider",
"->",
"fetchQuery",
"(",
"$",
"context",
",",
"$",
"args",
")",
";",
"return",
"sprintf",
"(",
"'SELECT %s AS id, '",
".",
"'%s AS \"date\", '",
".",
"\"'%s' AS type \"",
".",
"'FROM %s '",
".",
"'WHERE %s'",
",",
"$",
"data",
"[",
"'id'",
"]",
",",
"$",
"data",
"[",
"'date'",
"]",
",",
"$",
"data",
"[",
"'type'",
"]",
",",
"$",
"data",
"[",
"'FROM'",
"]",
",",
"$",
"data",
"[",
"'WHERE'",
"]",
")",
";",
"}"
] |
return the SQL SELECT query as a string,
@uses TimelineProfiderInterface::fetchQuery use the fetchQuery function
@param \Chill\MainBundle\Timeline\TimelineProviderInterface $provider
@param string $context
@param mixed[] $args
@return string
|
[
"return",
"the",
"SQL",
"SELECT",
"query",
"as",
"a",
"string"
] |
train
|
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Timeline/TimelineBuilder.php#L148-L163
|
Chill-project/Main
|
Timeline/TimelineBuilder.php
|
TimelineBuilder.runQuery
|
private function runQuery($query)
{
$resultSetMapping = (new ResultSetMapping())
->addScalarResult('id', 'id')
->addScalarResult('type', 'type')
->addScalarResult('date', 'date');
return $this->em->createNativeQuery($query, $resultSetMapping)
->getArrayResult();
}
|
php
|
private function runQuery($query)
{
$resultSetMapping = (new ResultSetMapping())
->addScalarResult('id', 'id')
->addScalarResult('type', 'type')
->addScalarResult('date', 'date');
return $this->em->createNativeQuery($query, $resultSetMapping)
->getArrayResult();
}
|
[
"private",
"function",
"runQuery",
"(",
"$",
"query",
")",
"{",
"$",
"resultSetMapping",
"=",
"(",
"new",
"ResultSetMapping",
"(",
")",
")",
"->",
"addScalarResult",
"(",
"'id'",
",",
"'id'",
")",
"->",
"addScalarResult",
"(",
"'type'",
",",
"'type'",
")",
"->",
"addScalarResult",
"(",
"'date'",
",",
"'date'",
")",
";",
"return",
"$",
"this",
"->",
"em",
"->",
"createNativeQuery",
"(",
"$",
"query",
",",
"$",
"resultSetMapping",
")",
"->",
"getArrayResult",
"(",
")",
";",
"}"
] |
run the UNION query and return result as an array
@param string $query
@return array
|
[
"run",
"the",
"UNION",
"query",
"and",
"return",
"result",
"as",
"an",
"array"
] |
train
|
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Timeline/TimelineBuilder.php#L171-L180
|
Chill-project/Main
|
Timeline/TimelineBuilder.php
|
TimelineBuilder.render
|
private function render(array $fetched, array $entitiesByType, $context, array $args)
{
//add results to a pretty array
$timelineEntries = array();
foreach ($fetched as $result) {
$data = $this->getTemplateData(
$result['type'],
$entitiesByType[$result['type']][$result['id']], //the entity
$context,
$args);
$timelineEntry['date'] = new \DateTime($result['date']);
$timelineEntry['template'] = $data['template'];
$timelineEntry['template_data'] = $data['template_data'];
$timelineEntries[] = $timelineEntry;
}
return $this->container->get('templating')
->render('ChillMainBundle:Timeline:index.html.twig', array(
'results' => $timelineEntries
));
}
|
php
|
private function render(array $fetched, array $entitiesByType, $context, array $args)
{
//add results to a pretty array
$timelineEntries = array();
foreach ($fetched as $result) {
$data = $this->getTemplateData(
$result['type'],
$entitiesByType[$result['type']][$result['id']], //the entity
$context,
$args);
$timelineEntry['date'] = new \DateTime($result['date']);
$timelineEntry['template'] = $data['template'];
$timelineEntry['template_data'] = $data['template_data'];
$timelineEntries[] = $timelineEntry;
}
return $this->container->get('templating')
->render('ChillMainBundle:Timeline:index.html.twig', array(
'results' => $timelineEntries
));
}
|
[
"private",
"function",
"render",
"(",
"array",
"$",
"fetched",
",",
"array",
"$",
"entitiesByType",
",",
"$",
"context",
",",
"array",
"$",
"args",
")",
"{",
"//add results to a pretty array",
"$",
"timelineEntries",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fetched",
"as",
"$",
"result",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getTemplateData",
"(",
"$",
"result",
"[",
"'type'",
"]",
",",
"$",
"entitiesByType",
"[",
"$",
"result",
"[",
"'type'",
"]",
"]",
"[",
"$",
"result",
"[",
"'id'",
"]",
"]",
",",
"//the entity",
"$",
"context",
",",
"$",
"args",
")",
";",
"$",
"timelineEntry",
"[",
"'date'",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"result",
"[",
"'date'",
"]",
")",
";",
"$",
"timelineEntry",
"[",
"'template'",
"]",
"=",
"$",
"data",
"[",
"'template'",
"]",
";",
"$",
"timelineEntry",
"[",
"'template_data'",
"]",
"=",
"$",
"data",
"[",
"'template_data'",
"]",
";",
"$",
"timelineEntries",
"[",
"]",
"=",
"$",
"timelineEntry",
";",
"}",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"'ChillMainBundle:Timeline:index.html.twig'",
",",
"array",
"(",
"'results'",
"=>",
"$",
"timelineEntries",
")",
")",
";",
"}"
] |
render the timeline as HTML
@param array $fetched
@param array $entitiesByType
@param string $context
@param mixed[] $args
@return string the HTML representation of the timeline
|
[
"render",
"the",
"timeline",
"as",
"HTML"
] |
train
|
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Timeline/TimelineBuilder.php#L221-L243
|
Chill-project/Main
|
Timeline/TimelineBuilder.php
|
TimelineBuilder.getTemplateData
|
private function getTemplateData($type, $entity, $context, array $args)
{
foreach($this->getProvidersByContext($context) as $provider) {
if ($provider->supportsType($type)) {
return $provider->getEntityTemplate($entity, $context, $args);
}
}
}
|
php
|
private function getTemplateData($type, $entity, $context, array $args)
{
foreach($this->getProvidersByContext($context) as $provider) {
if ($provider->supportsType($type)) {
return $provider->getEntityTemplate($entity, $context, $args);
}
}
}
|
[
"private",
"function",
"getTemplateData",
"(",
"$",
"type",
",",
"$",
"entity",
",",
"$",
"context",
",",
"array",
"$",
"args",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getProvidersByContext",
"(",
"$",
"context",
")",
"as",
"$",
"provider",
")",
"{",
"if",
"(",
"$",
"provider",
"->",
"supportsType",
"(",
"$",
"type",
")",
")",
"{",
"return",
"$",
"provider",
"->",
"getEntityTemplate",
"(",
"$",
"entity",
",",
"$",
"context",
",",
"$",
"args",
")",
";",
"}",
"}",
"}"
] |
get the template data from the provider for the given entity, by type.
@param string $type
@param mixed $entity
@param string $context
@param mixed[] $args
@return array the template data fetched from the provider
|
[
"get",
"the",
"template",
"data",
"from",
"the",
"provider",
"for",
"the",
"given",
"entity",
"by",
"type",
"."
] |
train
|
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Timeline/TimelineBuilder.php#L254-L261
|
flipboxstudio/orm-manager
|
src/Flipbox/OrmManager/Consoles/FontColor.php
|
FontColor.paintString
|
public function paintString($string, $foregroundColor = null, $backgroundCcolor = null, $option=null)
{
$coloredString = "";
if (isset($this->foregroundColors[$foregroundColor])) {
$coloredString .= "\033[".$this->foregroundColors[$foregroundColor]."m";
}
if (isset($this->backgroundColors[$backgroundCcolor])) {
$coloredString .= "\033[".$this->backgroundColors[$backgroundCcolor]."m";
}
if (isset($this->options[$option])) {
$coloredString .= "\033[".$this->options[$option]."m";
}
return $coloredString.$string."\033[0m";
}
|
php
|
public function paintString($string, $foregroundColor = null, $backgroundCcolor = null, $option=null)
{
$coloredString = "";
if (isset($this->foregroundColors[$foregroundColor])) {
$coloredString .= "\033[".$this->foregroundColors[$foregroundColor]."m";
}
if (isset($this->backgroundColors[$backgroundCcolor])) {
$coloredString .= "\033[".$this->backgroundColors[$backgroundCcolor]."m";
}
if (isset($this->options[$option])) {
$coloredString .= "\033[".$this->options[$option]."m";
}
return $coloredString.$string."\033[0m";
}
|
[
"public",
"function",
"paintString",
"(",
"$",
"string",
",",
"$",
"foregroundColor",
"=",
"null",
",",
"$",
"backgroundCcolor",
"=",
"null",
",",
"$",
"option",
"=",
"null",
")",
"{",
"$",
"coloredString",
"=",
"\"\"",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"foregroundColors",
"[",
"$",
"foregroundColor",
"]",
")",
")",
"{",
"$",
"coloredString",
".=",
"\"\\033[\"",
".",
"$",
"this",
"->",
"foregroundColors",
"[",
"$",
"foregroundColor",
"]",
".",
"\"m\"",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"backgroundColors",
"[",
"$",
"backgroundCcolor",
"]",
")",
")",
"{",
"$",
"coloredString",
".=",
"\"\\033[\"",
".",
"$",
"this",
"->",
"backgroundColors",
"[",
"$",
"backgroundCcolor",
"]",
".",
"\"m\"",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
")",
")",
"{",
"$",
"coloredString",
".=",
"\"\\033[\"",
".",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
".",
"\"m\"",
";",
"}",
"return",
"$",
"coloredString",
".",
"$",
"string",
".",
"\"\\033[0m\"",
";",
"}"
] |
paint string
@param string $string
@param mixed $foregroundColor
@param mixed $backgroundCcolor
@return string
|
[
"paint",
"string"
] |
train
|
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/Consoles/FontColor.php#L55-L72
|
spiral-modules/auth
|
source/Auth/Authenticators/CredentialsAuthenticator.php
|
CredentialsAuthenticator.getUser
|
public function getUser(string $username, string $password): PasswordAwareInterface
{
$user = $this->source->findByUsername($username);
if (empty($user)) {
throw new CredentialsException("Unable to authorize, no such user");
}
if (!$user instanceof PasswordAwareInterface) {
throw new LogicException("User must be instance of PasswordAwareInterface");
}
if (!$this->hasher->hashEquals($password, $user->getPasswordHash())) {
throw new CredentialsException("Unable to authorize, invalid password");
}
return $user;
}
|
php
|
public function getUser(string $username, string $password): PasswordAwareInterface
{
$user = $this->source->findByUsername($username);
if (empty($user)) {
throw new CredentialsException("Unable to authorize, no such user");
}
if (!$user instanceof PasswordAwareInterface) {
throw new LogicException("User must be instance of PasswordAwareInterface");
}
if (!$this->hasher->hashEquals($password, $user->getPasswordHash())) {
throw new CredentialsException("Unable to authorize, invalid password");
}
return $user;
}
|
[
"public",
"function",
"getUser",
"(",
"string",
"$",
"username",
",",
"string",
"$",
"password",
")",
":",
"PasswordAwareInterface",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"source",
"->",
"findByUsername",
"(",
"$",
"username",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"CredentialsException",
"(",
"\"Unable to authorize, no such user\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"instanceof",
"PasswordAwareInterface",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"\"User must be instance of PasswordAwareInterface\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasher",
"->",
"hashEquals",
"(",
"$",
"password",
",",
"$",
"user",
"->",
"getPasswordHash",
"(",
")",
")",
")",
"{",
"throw",
"new",
"CredentialsException",
"(",
"\"Unable to authorize, invalid password\"",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] |
Authorizes user based on given credentials. Will throw CredentialsException in case of any
auth related error (i.e. invalid password, invalid username).
@param string $username
@param string $password
@return PasswordAwareInterface
@throws LogicException When user does not implement proper interface.
@throws CredentialsException When user does not exists or credentials do not match.
|
[
"Authorizes",
"user",
"based",
"on",
"given",
"credentials",
".",
"Will",
"throw",
"CredentialsException",
"in",
"case",
"of",
"any",
"auth",
"related",
"error",
"(",
"i",
".",
"e",
".",
"invalid",
"password",
"invalid",
"username",
")",
"."
] |
train
|
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Authenticators/CredentialsAuthenticator.php#L52-L68
|
nexusnetsoftgmbh/nexuscli
|
src/Nexus/DockerClient/Communication/Command/Exec/DockerExecCommand.php
|
DockerExecCommand.execute
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$command = sprintf(
'exec -i %s %s',
$input->getArgument('container'),
$input->getArgument('execcmd')
);
$response = $this->getFacade()->runDocker($command);
if ($output->isVerbose()) {
$output->writeln($response);
}
}
|
php
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$command = sprintf(
'exec -i %s %s',
$input->getArgument('container'),
$input->getArgument('execcmd')
);
$response = $this->getFacade()->runDocker($command);
if ($output->isVerbose()) {
$output->writeln($response);
}
}
|
[
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"command",
"=",
"sprintf",
"(",
"'exec -i %s %s'",
",",
"$",
"input",
"->",
"getArgument",
"(",
"'container'",
")",
",",
"$",
"input",
"->",
"getArgument",
"(",
"'execcmd'",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getFacade",
"(",
")",
"->",
"runDocker",
"(",
"$",
"command",
")",
";",
"if",
"(",
"$",
"output",
"->",
"isVerbose",
"(",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"response",
")",
";",
"}",
"}"
] |
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@return int|null|void
|
[
"@param",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Input",
"\\",
"InputInterface",
"$input",
"@param",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Output",
"\\",
"OutputInterface",
"$output"
] |
train
|
https://github.com/nexusnetsoftgmbh/nexuscli/blob/8416b43d31ad56ea379ae2b0bf85d456e78ba67a/src/Nexus/DockerClient/Communication/Command/Exec/DockerExecCommand.php#L32-L45
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.getAuthorizationCode
|
public function getAuthorizationCode($code)
{
$sql = sprintf('SELECT * from %s where authorization_code = :code', $this->config['code_table']);
$code = $this->fetch($sql, compact('code'));
if ($code) {
// convert date string back to timestamp
$code['expires'] = strtotime($code['expires']);
}
return $code;
}
|
php
|
public function getAuthorizationCode($code)
{
$sql = sprintf('SELECT * from %s where authorization_code = :code', $this->config['code_table']);
$code = $this->fetch($sql, compact('code'));
if ($code) {
// convert date string back to timestamp
$code['expires'] = strtotime($code['expires']);
}
return $code;
}
|
[
"public",
"function",
"getAuthorizationCode",
"(",
"$",
"code",
")",
"{",
"$",
"sql",
"=",
"sprintf",
"(",
"'SELECT * from %s where authorization_code = :code'",
",",
"$",
"this",
"->",
"config",
"[",
"'code_table'",
"]",
")",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"sql",
",",
"compact",
"(",
"'code'",
")",
")",
";",
"if",
"(",
"$",
"code",
")",
"{",
"// convert date string back to timestamp",
"$",
"code",
"[",
"'expires'",
"]",
"=",
"strtotime",
"(",
"$",
"code",
"[",
"'expires'",
"]",
")",
";",
"}",
"return",
"$",
"code",
";",
"}"
] |
/* OAuth2_Storage_AuthorizationCodeInterface
|
[
"/",
"*",
"OAuth2_Storage_AuthorizationCodeInterface"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L40-L50
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.checkClientCredentials
|
public function checkClientCredentials($client_id, $client_secret = null)
{
$sql = sprintf('SELECT * from %s where client_id = :client_id', $this->config['client_table']);
$result = $this->fetch($sql, compact('client_id'));
// make this extensible
return $result ? $result['client_secret'] == $client_secret : false;
}
|
php
|
public function checkClientCredentials($client_id, $client_secret = null)
{
$sql = sprintf('SELECT * from %s where client_id = :client_id', $this->config['client_table']);
$result = $this->fetch($sql, compact('client_id'));
// make this extensible
return $result ? $result['client_secret'] == $client_secret : false;
}
|
[
"public",
"function",
"checkClientCredentials",
"(",
"$",
"client_id",
",",
"$",
"client_secret",
"=",
"null",
")",
"{",
"$",
"sql",
"=",
"sprintf",
"(",
"'SELECT * from %s where client_id = :client_id'",
",",
"$",
"this",
"->",
"config",
"[",
"'client_table'",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"sql",
",",
"compact",
"(",
"'client_id'",
")",
")",
";",
"// make this extensible",
"return",
"$",
"result",
"?",
"$",
"result",
"[",
"'client_secret'",
"]",
"==",
"$",
"client_secret",
":",
"false",
";",
"}"
] |
/* OAuth2_Storage_ClientCredentialsInterface
|
[
"/",
"*",
"OAuth2_Storage_ClientCredentialsInterface"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L53-L60
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.getAccessToken
|
public function getAccessToken($access_token)
{
$sql = sprintf('SELECT * from %s where access_token = :access_token', $this->config['access_token_table']);
$token = $this->fetch($sql, compact('access_token'));
if ($token) {
// convert date string back to timestamp
$token['expires'] = strtotime($token['expires']);
}
return $token;
}
|
php
|
public function getAccessToken($access_token)
{
$sql = sprintf('SELECT * from %s where access_token = :access_token', $this->config['access_token_table']);
$token = $this->fetch($sql, compact('access_token'));
if ($token) {
// convert date string back to timestamp
$token['expires'] = strtotime($token['expires']);
}
return $token;
}
|
[
"public",
"function",
"getAccessToken",
"(",
"$",
"access_token",
")",
"{",
"$",
"sql",
"=",
"sprintf",
"(",
"'SELECT * from %s where access_token = :access_token'",
",",
"$",
"this",
"->",
"config",
"[",
"'access_token_table'",
"]",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"sql",
",",
"compact",
"(",
"'access_token'",
")",
")",
";",
"if",
"(",
"$",
"token",
")",
"{",
"// convert date string back to timestamp",
"$",
"token",
"[",
"'expires'",
"]",
"=",
"strtotime",
"(",
"$",
"token",
"[",
"'expires'",
"]",
")",
";",
"}",
"return",
"$",
"token",
";",
"}"
] |
/* OAuth2_Storage_AccessTokenInterface
|
[
"/",
"*",
"OAuth2_Storage_AccessTokenInterface"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L70-L80
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.getRefreshToken
|
public function getRefreshToken($refresh_token)
{
$sql = sprintf('SELECT * from %s where refresh_token = :refresh_token', $this->config['refresh_token_table']);
$token = $this->fetch($sql, compact('refresh_token'));
if ($token) {
// convert expires to epoch time
$token['expires'] = strtotime($token['expires']);
}
return $token;
}
|
php
|
public function getRefreshToken($refresh_token)
{
$sql = sprintf('SELECT * from %s where refresh_token = :refresh_token', $this->config['refresh_token_table']);
$token = $this->fetch($sql, compact('refresh_token'));
if ($token) {
// convert expires to epoch time
$token['expires'] = strtotime($token['expires']);
}
return $token;
}
|
[
"public",
"function",
"getRefreshToken",
"(",
"$",
"refresh_token",
")",
"{",
"$",
"sql",
"=",
"sprintf",
"(",
"'SELECT * from %s where refresh_token = :refresh_token'",
",",
"$",
"this",
"->",
"config",
"[",
"'refresh_token_table'",
"]",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"sql",
",",
"compact",
"(",
"'refresh_token'",
")",
")",
";",
"if",
"(",
"$",
"token",
")",
"{",
"// convert expires to epoch time",
"$",
"token",
"[",
"'expires'",
"]",
"=",
"strtotime",
"(",
"$",
"token",
"[",
"'expires'",
"]",
")",
";",
"}",
"return",
"$",
"token",
";",
"}"
] |
/* OAuth2_Storage_RefreshTokenInterface
|
[
"/",
"*",
"OAuth2_Storage_RefreshTokenInterface"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L83-L93
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.fetch
|
public function fetch($sql, $params = array())
{
$stmt = $this->db->prepare($sql);
$stmt->execute($params);
if (!$res = $stmt->fetch(\PDO::FETCH_ASSOC)) {
return false;
}
return $res;
}
|
php
|
public function fetch($sql, $params = array())
{
$stmt = $this->db->prepare($sql);
$stmt->execute($params);
if (!$res = $stmt->fetch(\PDO::FETCH_ASSOC)) {
return false;
}
return $res;
}
|
[
"public",
"function",
"fetch",
"(",
"$",
"sql",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"res",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"res",
";",
"}"
] |
@param string $sql
@param array $params
@return array|bool
|
[
"@param",
"string",
"$sql",
"@param",
"array",
"$params"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L101-L110
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.gc
|
public function gc()
{
$expires = date('Y-m-d H:i:s');
$tables = array(
'access_token_table',
'refresh_token_table',
'code_table',
);
foreach ($tables as $table) {
$stmt = $this->db->prepare(sprintf('DELETE FROM %s WHERE expires < :expires', $this->config[$table]));
$stmt->execute(compact('expires'));
}
}
|
php
|
public function gc()
{
$expires = date('Y-m-d H:i:s');
$tables = array(
'access_token_table',
'refresh_token_table',
'code_table',
);
foreach ($tables as $table) {
$stmt = $this->db->prepare(sprintf('DELETE FROM %s WHERE expires < :expires', $this->config[$table]));
$stmt->execute(compact('expires'));
}
}
|
[
"public",
"function",
"gc",
"(",
")",
"{",
"$",
"expires",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"tables",
"=",
"array",
"(",
"'access_token_table'",
",",
"'refresh_token_table'",
",",
"'code_table'",
",",
")",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"sprintf",
"(",
"'DELETE FROM %s WHERE expires < :expires'",
",",
"$",
"this",
"->",
"config",
"[",
"$",
"table",
"]",
")",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"compact",
"(",
"'expires'",
")",
")",
";",
"}",
"}"
] |
Garbage Collection
|
[
"Garbage",
"Collection"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L115-L127
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.setClientUser
|
public function setClientUser($client_id, $user_id)
{
if ($this->getClientUser($client_id, $user_id)) {
return true;
} else {
$created_at = date('Y-m-d H:i:s');
$sql = 'INSERT INTO %s (client_id, user_id, created_at) VALUES (:client_id, :user_id, :created_at)';
$sql = sprintf($sql, $this->config['client_user_table']);
$params = array_map('trim', compact('client_id', 'user_id', 'created_at'));
return $this->db->prepare($sql)->execute($params);
}
}
|
php
|
public function setClientUser($client_id, $user_id)
{
if ($this->getClientUser($client_id, $user_id)) {
return true;
} else {
$created_at = date('Y-m-d H:i:s');
$sql = 'INSERT INTO %s (client_id, user_id, created_at) VALUES (:client_id, :user_id, :created_at)';
$sql = sprintf($sql, $this->config['client_user_table']);
$params = array_map('trim', compact('client_id', 'user_id', 'created_at'));
return $this->db->prepare($sql)->execute($params);
}
}
|
[
"public",
"function",
"setClientUser",
"(",
"$",
"client_id",
",",
"$",
"user_id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getClientUser",
"(",
"$",
"client_id",
",",
"$",
"user_id",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"created_at",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"sql",
"=",
"'INSERT INTO %s (client_id, user_id, created_at) VALUES (:client_id, :user_id, :created_at)'",
";",
"$",
"sql",
"=",
"sprintf",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"config",
"[",
"'client_user_table'",
"]",
")",
";",
"$",
"params",
"=",
"array_map",
"(",
"'trim'",
",",
"compact",
"(",
"'client_id'",
",",
"'user_id'",
",",
"'created_at'",
")",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"}",
"}"
] |
@param string $client_id
@param string $user_id
@return bool
|
[
"@param",
"string",
"$client_id",
"@param",
"string",
"$user_id"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L135-L148
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.getClientUser
|
public function getClientUser($client_id, $user_id)
{
$sql = 'SELECT * from %s where client_id = :client_id and user_id = :user_id';
$sql = sprintf($sql, $this->config['client_user_table']);
return $this->fetch($sql, compact('client_id', 'user_id'));
}
|
php
|
public function getClientUser($client_id, $user_id)
{
$sql = 'SELECT * from %s where client_id = :client_id and user_id = :user_id';
$sql = sprintf($sql, $this->config['client_user_table']);
return $this->fetch($sql, compact('client_id', 'user_id'));
}
|
[
"public",
"function",
"getClientUser",
"(",
"$",
"client_id",
",",
"$",
"user_id",
")",
"{",
"$",
"sql",
"=",
"'SELECT * from %s where client_id = :client_id and user_id = :user_id'",
";",
"$",
"sql",
"=",
"sprintf",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"config",
"[",
"'client_user_table'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"fetch",
"(",
"$",
"sql",
",",
"compact",
"(",
"'client_id'",
",",
"'user_id'",
")",
")",
";",
"}"
] |
@param string $client_id
@param string $user_id
@return array|bool
|
[
"@param",
"string",
"$client_id",
"@param",
"string",
"$user_id"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L156-L162
|
paliari/oauth2-server-facade
|
src/Paliari/Oauth2ServerFacade/Storage.php
|
Storage.removeClientUser
|
public function removeClientUser($client_id, $user_id)
{
$sql = 'DELETE from %s where client_id = :client_id and user_id = :user_id';
$sql = sprintf($sql, $this->config['client_user_table']);
$params = array_map('trim', compact('client_id', 'user_id'));
return $this->db->prepare($sql)->execute($params);
}
|
php
|
public function removeClientUser($client_id, $user_id)
{
$sql = 'DELETE from %s where client_id = :client_id and user_id = :user_id';
$sql = sprintf($sql, $this->config['client_user_table']);
$params = array_map('trim', compact('client_id', 'user_id'));
return $this->db->prepare($sql)->execute($params);
}
|
[
"public",
"function",
"removeClientUser",
"(",
"$",
"client_id",
",",
"$",
"user_id",
")",
"{",
"$",
"sql",
"=",
"'DELETE from %s where client_id = :client_id and user_id = :user_id'",
";",
"$",
"sql",
"=",
"sprintf",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"config",
"[",
"'client_user_table'",
"]",
")",
";",
"$",
"params",
"=",
"array_map",
"(",
"'trim'",
",",
"compact",
"(",
"'client_id'",
",",
"'user_id'",
")",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"}"
] |
@param string $client_id
@param string $user_id
@return bool
|
[
"@param",
"string",
"$client_id",
"@param",
"string",
"$user_id"
] |
train
|
https://github.com/paliari/oauth2-server-facade/blob/72785397ff5b2d4c9e8cf487b4215b3808bbcfdf/src/Paliari/Oauth2ServerFacade/Storage.php#L170-L177
|
titon/db
|
src/Titon/Db/Finder/ListFinder.php
|
ListFinder.after
|
public function after(array $results, array $options = []) {
$key = isset($options['key']) ? $options['key'] : null;
$value = isset($options['value']) ? $options['value'] : null;
$list = [];
if (!$key || !$value) {
throw new InvalidArgumentException('Missing key or value option for ListFinder');
}
foreach ($results as $result) {
if ($result instanceof Entity) {
$result = $result->toArray();
}
$list[Hash::get($result, $key)] = Hash::get($result, $value);
}
return $list;
}
|
php
|
public function after(array $results, array $options = []) {
$key = isset($options['key']) ? $options['key'] : null;
$value = isset($options['value']) ? $options['value'] : null;
$list = [];
if (!$key || !$value) {
throw new InvalidArgumentException('Missing key or value option for ListFinder');
}
foreach ($results as $result) {
if ($result instanceof Entity) {
$result = $result->toArray();
}
$list[Hash::get($result, $key)] = Hash::get($result, $value);
}
return $list;
}
|
[
"public",
"function",
"after",
"(",
"array",
"$",
"results",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"key",
"=",
"isset",
"(",
"$",
"options",
"[",
"'key'",
"]",
")",
"?",
"$",
"options",
"[",
"'key'",
"]",
":",
"null",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"options",
"[",
"'value'",
"]",
")",
"?",
"$",
"options",
"[",
"'value'",
"]",
":",
"null",
";",
"$",
"list",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"key",
"||",
"!",
"$",
"value",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Missing key or value option for ListFinder'",
")",
";",
"}",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"instanceof",
"Entity",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"list",
"[",
"Hash",
"::",
"get",
"(",
"$",
"result",
",",
"$",
"key",
")",
"]",
"=",
"Hash",
"::",
"get",
"(",
"$",
"result",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Finder/ListFinder.php#L24-L42
|
phrest/sdk
|
src/Generator/Request/RequestGenerator.php
|
RequestGenerator.create
|
public function create()
{
$class = ClassGen::classGen(
$this->name,
$this->namespace,
[
'Phrest\API\Enums\RequestMethodEnum',
'Phrest\SDK\Request\AbstractRequest',
'Phrest\SDK\Request\RequestOptions',
'Phrest\SDK\PhrestSDK'
],
'AbstractRequest'
);
// Path
$path = '/' . $this->version . '/'
. strtolower($this->entityName)
. $this->getPlaceholderUriFromUrl($this->action->url);
$property = ClassGen::property('path', 'private', $path, 'string');
$class->addPropertyFromGenerator($property);
// Properties and constructor parameters
/** @var ParameterGenerator[] $parameters */
$parameters = [];
// Get properties
$getParams = $this->generateGetParamsFromUrl($this->action->url);
if (!empty($getParams))
{
foreach ($getParams as $getParam)
{
$class->addPropertyFromGenerator(
ClassGen::property($getParam, 'public', null)
);
$parameter = new ParameterGenerator($getParam);
$parameter->setDefaultValue(null);
$parameters[$getParam] = $parameter;
}
}
// Post properties
if (!empty($this->action->postParams))
{
foreach ($this->action->postParams as $name => $type)
{
if ($class->hasProperty($name))
{
continue;
}
$class->addPropertyFromGenerator(
ClassGen::property($name, 'public', null, $type)
);
$parameter = new ParameterGenerator($name, $type);
$parameter->setDefaultValue(null);
$parameters[$name] = $parameter;
}
}
// Constructor
if (!empty($parameters))
{
$constructor = ClassGen::constructor($parameters);
$class->addMethodFromGenerator($constructor);
}
// Create method
$create = ClassGen::method('create', [], 'public', $this->getCreateBody());
$class->addMethodFromGenerator($create);
// Setters
foreach ($parameters as $parameter)
{
$class->addMethodFromGenerator(
ClassGen::setter($parameter->getName(), $parameter->getType())
);
}
return $class;
}
|
php
|
public function create()
{
$class = ClassGen::classGen(
$this->name,
$this->namespace,
[
'Phrest\API\Enums\RequestMethodEnum',
'Phrest\SDK\Request\AbstractRequest',
'Phrest\SDK\Request\RequestOptions',
'Phrest\SDK\PhrestSDK'
],
'AbstractRequest'
);
// Path
$path = '/' . $this->version . '/'
. strtolower($this->entityName)
. $this->getPlaceholderUriFromUrl($this->action->url);
$property = ClassGen::property('path', 'private', $path, 'string');
$class->addPropertyFromGenerator($property);
// Properties and constructor parameters
/** @var ParameterGenerator[] $parameters */
$parameters = [];
// Get properties
$getParams = $this->generateGetParamsFromUrl($this->action->url);
if (!empty($getParams))
{
foreach ($getParams as $getParam)
{
$class->addPropertyFromGenerator(
ClassGen::property($getParam, 'public', null)
);
$parameter = new ParameterGenerator($getParam);
$parameter->setDefaultValue(null);
$parameters[$getParam] = $parameter;
}
}
// Post properties
if (!empty($this->action->postParams))
{
foreach ($this->action->postParams as $name => $type)
{
if ($class->hasProperty($name))
{
continue;
}
$class->addPropertyFromGenerator(
ClassGen::property($name, 'public', null, $type)
);
$parameter = new ParameterGenerator($name, $type);
$parameter->setDefaultValue(null);
$parameters[$name] = $parameter;
}
}
// Constructor
if (!empty($parameters))
{
$constructor = ClassGen::constructor($parameters);
$class->addMethodFromGenerator($constructor);
}
// Create method
$create = ClassGen::method('create', [], 'public', $this->getCreateBody());
$class->addMethodFromGenerator($create);
// Setters
foreach ($parameters as $parameter)
{
$class->addMethodFromGenerator(
ClassGen::setter($parameter->getName(), $parameter->getType())
);
}
return $class;
}
|
[
"public",
"function",
"create",
"(",
")",
"{",
"$",
"class",
"=",
"ClassGen",
"::",
"classGen",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"namespace",
",",
"[",
"'Phrest\\API\\Enums\\RequestMethodEnum'",
",",
"'Phrest\\SDK\\Request\\AbstractRequest'",
",",
"'Phrest\\SDK\\Request\\RequestOptions'",
",",
"'Phrest\\SDK\\PhrestSDK'",
"]",
",",
"'AbstractRequest'",
")",
";",
"// Path",
"$",
"path",
"=",
"'/'",
".",
"$",
"this",
"->",
"version",
".",
"'/'",
".",
"strtolower",
"(",
"$",
"this",
"->",
"entityName",
")",
".",
"$",
"this",
"->",
"getPlaceholderUriFromUrl",
"(",
"$",
"this",
"->",
"action",
"->",
"url",
")",
";",
"$",
"property",
"=",
"ClassGen",
"::",
"property",
"(",
"'path'",
",",
"'private'",
",",
"$",
"path",
",",
"'string'",
")",
";",
"$",
"class",
"->",
"addPropertyFromGenerator",
"(",
"$",
"property",
")",
";",
"// Properties and constructor parameters",
"/** @var ParameterGenerator[] $parameters */",
"$",
"parameters",
"=",
"[",
"]",
";",
"// Get properties",
"$",
"getParams",
"=",
"$",
"this",
"->",
"generateGetParamsFromUrl",
"(",
"$",
"this",
"->",
"action",
"->",
"url",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"getParams",
")",
")",
"{",
"foreach",
"(",
"$",
"getParams",
"as",
"$",
"getParam",
")",
"{",
"$",
"class",
"->",
"addPropertyFromGenerator",
"(",
"ClassGen",
"::",
"property",
"(",
"$",
"getParam",
",",
"'public'",
",",
"null",
")",
")",
";",
"$",
"parameter",
"=",
"new",
"ParameterGenerator",
"(",
"$",
"getParam",
")",
";",
"$",
"parameter",
"->",
"setDefaultValue",
"(",
"null",
")",
";",
"$",
"parameters",
"[",
"$",
"getParam",
"]",
"=",
"$",
"parameter",
";",
"}",
"}",
"// Post properties",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"action",
"->",
"postParams",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"action",
"->",
"postParams",
"as",
"$",
"name",
"=>",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"class",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"continue",
";",
"}",
"$",
"class",
"->",
"addPropertyFromGenerator",
"(",
"ClassGen",
"::",
"property",
"(",
"$",
"name",
",",
"'public'",
",",
"null",
",",
"$",
"type",
")",
")",
";",
"$",
"parameter",
"=",
"new",
"ParameterGenerator",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"$",
"parameter",
"->",
"setDefaultValue",
"(",
"null",
")",
";",
"$",
"parameters",
"[",
"$",
"name",
"]",
"=",
"$",
"parameter",
";",
"}",
"}",
"// Constructor",
"if",
"(",
"!",
"empty",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"constructor",
"=",
"ClassGen",
"::",
"constructor",
"(",
"$",
"parameters",
")",
";",
"$",
"class",
"->",
"addMethodFromGenerator",
"(",
"$",
"constructor",
")",
";",
"}",
"// Create method",
"$",
"create",
"=",
"ClassGen",
"::",
"method",
"(",
"'create'",
",",
"[",
"]",
",",
"'public'",
",",
"$",
"this",
"->",
"getCreateBody",
"(",
")",
")",
";",
"$",
"class",
"->",
"addMethodFromGenerator",
"(",
"$",
"create",
")",
";",
"// Setters",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"class",
"->",
"addMethodFromGenerator",
"(",
"ClassGen",
"::",
"setter",
"(",
"$",
"parameter",
"->",
"getName",
"(",
")",
",",
"$",
"parameter",
"->",
"getType",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"class",
";",
"}"
] |
Process and create code/files
|
[
"Process",
"and",
"create",
"code",
"/",
"files"
] |
train
|
https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/Generator/Request/RequestGenerator.php#L72-L156
|
phrest/sdk
|
src/Generator/Request/RequestGenerator.php
|
RequestGenerator.getCreateBody
|
public function getCreateBody()
{
$createBody = '$requestOptions = new RequestOptions();' . PHP_EOL . PHP_EOL;
if (!empty($this->action->postParams))
{
$createBody .= '$requestOptions->addPostParams(' . PHP_EOL .
Generator::$indentation . "[" . PHP_EOL;
foreach ($this->action->postParams as $name => $type)
{
$createBody .= sprintf(
"%s'%s' => \$this->%s,%s",
Generator::$indentation . Generator::$indentation,
$name,
$name,
PHP_EOL
);
}
$createBody .= Generator::$indentation . "]" . PHP_EOL
. ');' . PHP_EOL . PHP_EOL;
}
$getParams = $this->generateGetParamsFromUrl($this->action->url);
if ($getParams)
{
foreach ($getParams as $getParam)
{
$createBody .= 'if (!isset($this->' . $getParam . '))' . PHP_EOL
. '{' . PHP_EOL
. Generator::$indentation
. sprintf(
'throw new \Exception("Parameter \'%s\' is required. It is a GET parameter.");',
$getParam
) . PHP_EOL
. '}' . PHP_EOL . PHP_EOL;
}
array_walk($getParams,
function (&$value, $key)
{
$value = '$this->' . $value;
}
);
$path = sprintf("sprintf(\$this->path, %s)", implode(', ', $getParams));
}
else
{
$path = '$this->path';
}
$createBody .= 'return PhrestSDK::getResponse(' . PHP_EOL
. Generator::$indentation
. 'RequestMethodEnum::' . strtoupper($this->requestMethod) . ',' . PHP_EOL
. Generator::$indentation
. $path . ',' . PHP_EOL
. Generator::$indentation
. '$requestOptions' . PHP_EOL
. ');' . PHP_EOL;
return $createBody;
}
|
php
|
public function getCreateBody()
{
$createBody = '$requestOptions = new RequestOptions();' . PHP_EOL . PHP_EOL;
if (!empty($this->action->postParams))
{
$createBody .= '$requestOptions->addPostParams(' . PHP_EOL .
Generator::$indentation . "[" . PHP_EOL;
foreach ($this->action->postParams as $name => $type)
{
$createBody .= sprintf(
"%s'%s' => \$this->%s,%s",
Generator::$indentation . Generator::$indentation,
$name,
$name,
PHP_EOL
);
}
$createBody .= Generator::$indentation . "]" . PHP_EOL
. ');' . PHP_EOL . PHP_EOL;
}
$getParams = $this->generateGetParamsFromUrl($this->action->url);
if ($getParams)
{
foreach ($getParams as $getParam)
{
$createBody .= 'if (!isset($this->' . $getParam . '))' . PHP_EOL
. '{' . PHP_EOL
. Generator::$indentation
. sprintf(
'throw new \Exception("Parameter \'%s\' is required. It is a GET parameter.");',
$getParam
) . PHP_EOL
. '}' . PHP_EOL . PHP_EOL;
}
array_walk($getParams,
function (&$value, $key)
{
$value = '$this->' . $value;
}
);
$path = sprintf("sprintf(\$this->path, %s)", implode(', ', $getParams));
}
else
{
$path = '$this->path';
}
$createBody .= 'return PhrestSDK::getResponse(' . PHP_EOL
. Generator::$indentation
. 'RequestMethodEnum::' . strtoupper($this->requestMethod) . ',' . PHP_EOL
. Generator::$indentation
. $path . ',' . PHP_EOL
. Generator::$indentation
. '$requestOptions' . PHP_EOL
. ');' . PHP_EOL;
return $createBody;
}
|
[
"public",
"function",
"getCreateBody",
"(",
")",
"{",
"$",
"createBody",
"=",
"'$requestOptions = new RequestOptions();'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"action",
"->",
"postParams",
")",
")",
"{",
"$",
"createBody",
".=",
"'$requestOptions->addPostParams('",
".",
"PHP_EOL",
".",
"Generator",
"::",
"$",
"indentation",
".",
"\"[\"",
".",
"PHP_EOL",
";",
"foreach",
"(",
"$",
"this",
"->",
"action",
"->",
"postParams",
"as",
"$",
"name",
"=>",
"$",
"type",
")",
"{",
"$",
"createBody",
".=",
"sprintf",
"(",
"\"%s'%s' => \\$this->%s,%s\"",
",",
"Generator",
"::",
"$",
"indentation",
".",
"Generator",
"::",
"$",
"indentation",
",",
"$",
"name",
",",
"$",
"name",
",",
"PHP_EOL",
")",
";",
"}",
"$",
"createBody",
".=",
"Generator",
"::",
"$",
"indentation",
".",
"\"]\"",
".",
"PHP_EOL",
".",
"');'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"$",
"getParams",
"=",
"$",
"this",
"->",
"generateGetParamsFromUrl",
"(",
"$",
"this",
"->",
"action",
"->",
"url",
")",
";",
"if",
"(",
"$",
"getParams",
")",
"{",
"foreach",
"(",
"$",
"getParams",
"as",
"$",
"getParam",
")",
"{",
"$",
"createBody",
".=",
"'if (!isset($this->'",
".",
"$",
"getParam",
".",
"'))'",
".",
"PHP_EOL",
".",
"'{'",
".",
"PHP_EOL",
".",
"Generator",
"::",
"$",
"indentation",
".",
"sprintf",
"(",
"'throw new \\Exception(\"Parameter \\'%s\\' is required. It is a GET parameter.\");'",
",",
"$",
"getParam",
")",
".",
"PHP_EOL",
".",
"'}'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"array_walk",
"(",
"$",
"getParams",
",",
"function",
"(",
"&",
"$",
"value",
",",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"'$this->'",
".",
"$",
"value",
";",
"}",
")",
";",
"$",
"path",
"=",
"sprintf",
"(",
"\"sprintf(\\$this->path, %s)\"",
",",
"implode",
"(",
"', '",
",",
"$",
"getParams",
")",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"'$this->path'",
";",
"}",
"$",
"createBody",
".=",
"'return PhrestSDK::getResponse('",
".",
"PHP_EOL",
".",
"Generator",
"::",
"$",
"indentation",
".",
"'RequestMethodEnum::'",
".",
"strtoupper",
"(",
"$",
"this",
"->",
"requestMethod",
")",
".",
"','",
".",
"PHP_EOL",
".",
"Generator",
"::",
"$",
"indentation",
".",
"$",
"path",
".",
"','",
".",
"PHP_EOL",
".",
"Generator",
"::",
"$",
"indentation",
".",
"'$requestOptions'",
".",
"PHP_EOL",
".",
"');'",
".",
"PHP_EOL",
";",
"return",
"$",
"createBody",
";",
"}"
] |
E.G.
<code>
$requestOptions = new RequestOptions();
$requestOptions->addPostParams(
[
'name' => $this->name,
'email' => $this->email,
'password' => $this->password,
]
);
if (!isset($this->id))
{
throw new \Exception("Parameter 'id' is required. It is a GET
parameter.");
}
return PhrestSDK::getResponse(
self::METHOD_POST,
$this->path,
$requestOptions
);
</code>
@return string
|
[
"E",
".",
"G",
".",
"<code",
">",
"$requestOptions",
"=",
"new",
"RequestOptions",
"()",
";",
"$requestOptions",
"-",
">",
"addPostParams",
"(",
"[",
"name",
"=",
">",
"$this",
"-",
">",
"name",
"email",
"=",
">",
"$this",
"-",
">",
"email",
"password",
"=",
">",
"$this",
"-",
">",
"password",
"]",
")",
";",
"if",
"(",
"!isset",
"(",
"$this",
"-",
">",
"id",
"))",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"Parameter",
"id",
"is",
"required",
".",
"It",
"is",
"a",
"GET",
"parameter",
".",
")",
";",
"}",
"return",
"PhrestSDK",
"::",
"getResponse",
"(",
"self",
"::",
"METHOD_POST",
"$this",
"-",
">",
"path",
"$requestOptions",
")",
";",
"<",
"/",
"code",
">"
] |
train
|
https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/Generator/Request/RequestGenerator.php#L210-L273
|
PeekAndPoke/psi
|
src/DefaultPsiFactory.php
|
DefaultPsiFactory.createIterator
|
public function createIterator(array $iteratables, PsiOptions $options)
{
$count = count($iteratables);
if ($count === 1) {
return $this->createSingleIterator($iteratables[0]);
}
if ($count > 1) {
return $this->createIteratorForMultipleInputs($iteratables, $options);
}
return new \ArrayIterator();
}
|
php
|
public function createIterator(array $iteratables, PsiOptions $options)
{
$count = count($iteratables);
if ($count === 1) {
return $this->createSingleIterator($iteratables[0]);
}
if ($count > 1) {
return $this->createIteratorForMultipleInputs($iteratables, $options);
}
return new \ArrayIterator();
}
|
[
"public",
"function",
"createIterator",
"(",
"array",
"$",
"iteratables",
",",
"PsiOptions",
"$",
"options",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"iteratables",
")",
";",
"if",
"(",
"$",
"count",
"===",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"createSingleIterator",
"(",
"$",
"iteratables",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"$",
"count",
">",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"createIteratorForMultipleInputs",
"(",
"$",
"iteratables",
",",
"$",
"options",
")",
";",
"}",
"return",
"new",
"\\",
"ArrayIterator",
"(",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/DefaultPsiFactory.php#L31-L44
|
PeekAndPoke/psi
|
src/DefaultPsiFactory.php
|
DefaultPsiFactory.createIteratorForMultipleInputs
|
protected function createIteratorForMultipleInputs(array $iteratables, PsiOptions $options)
{
// when we have multiple inputs we need an option to decide on how to deal with colliding keys
if ($options->isPreserveKeysOfMultipleInputs()) {
// this iterator return the original keys of each child iterator
// -> this leads to conflicts OR means we preserve keys
$iterator = new \AppendIterator();
} else {
// this iterator will create numeric keys from 0 .. n
$iterator = new KeylessAppendIterator();
}
foreach ($iteratables as $iteratable) {
$iterator->append($this->createSingleIterator($iteratable));
}
return $iterator;
}
|
php
|
protected function createIteratorForMultipleInputs(array $iteratables, PsiOptions $options)
{
// when we have multiple inputs we need an option to decide on how to deal with colliding keys
if ($options->isPreserveKeysOfMultipleInputs()) {
// this iterator return the original keys of each child iterator
// -> this leads to conflicts OR means we preserve keys
$iterator = new \AppendIterator();
} else {
// this iterator will create numeric keys from 0 .. n
$iterator = new KeylessAppendIterator();
}
foreach ($iteratables as $iteratable) {
$iterator->append($this->createSingleIterator($iteratable));
}
return $iterator;
}
|
[
"protected",
"function",
"createIteratorForMultipleInputs",
"(",
"array",
"$",
"iteratables",
",",
"PsiOptions",
"$",
"options",
")",
"{",
"// when we have multiple inputs we need an option to decide on how to deal with colliding keys",
"if",
"(",
"$",
"options",
"->",
"isPreserveKeysOfMultipleInputs",
"(",
")",
")",
"{",
"// this iterator return the original keys of each child iterator",
"// -> this leads to conflicts OR means we preserve keys",
"$",
"iterator",
"=",
"new",
"\\",
"AppendIterator",
"(",
")",
";",
"}",
"else",
"{",
"// this iterator will create numeric keys from 0 .. n",
"$",
"iterator",
"=",
"new",
"KeylessAppendIterator",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"iteratables",
"as",
"$",
"iteratable",
")",
"{",
"$",
"iterator",
"->",
"append",
"(",
"$",
"this",
"->",
"createSingleIterator",
"(",
"$",
"iteratable",
")",
")",
";",
"}",
"return",
"$",
"iterator",
";",
"}"
] |
@param array $iteratables
@param PsiOptions $options
@return \AppendIterator|KeylessAppendIterator
@throws PsiException
|
[
"@param",
"array",
"$iteratables",
"@param",
"PsiOptions",
"$options"
] |
train
|
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/DefaultPsiFactory.php#L54-L71
|
PeekAndPoke/psi
|
src/DefaultPsiFactory.php
|
DefaultPsiFactory.createSingleIterator
|
protected function createSingleIterator($iteratable)
{
if ($iteratable === null) {
return new \ArrayIterator();
}
if ($iteratable instanceof \Iterator) {
return $iteratable;
}
if ($iteratable instanceof \Traversable) {
return new \IteratorIterator($iteratable);
}
if (is_array($iteratable)) {
return new \ArrayIterator($iteratable);
}
throw new PsiException('Invalid input, not an array or an Iterator or a Traversable');
}
|
php
|
protected function createSingleIterator($iteratable)
{
if ($iteratable === null) {
return new \ArrayIterator();
}
if ($iteratable instanceof \Iterator) {
return $iteratable;
}
if ($iteratable instanceof \Traversable) {
return new \IteratorIterator($iteratable);
}
if (is_array($iteratable)) {
return new \ArrayIterator($iteratable);
}
throw new PsiException('Invalid input, not an array or an Iterator or a Traversable');
}
|
[
"protected",
"function",
"createSingleIterator",
"(",
"$",
"iteratable",
")",
"{",
"if",
"(",
"$",
"iteratable",
"===",
"null",
")",
"{",
"return",
"new",
"\\",
"ArrayIterator",
"(",
")",
";",
"}",
"if",
"(",
"$",
"iteratable",
"instanceof",
"\\",
"Iterator",
")",
"{",
"return",
"$",
"iteratable",
";",
"}",
"if",
"(",
"$",
"iteratable",
"instanceof",
"\\",
"Traversable",
")",
"{",
"return",
"new",
"\\",
"IteratorIterator",
"(",
"$",
"iteratable",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"iteratable",
")",
")",
"{",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"iteratable",
")",
";",
"}",
"throw",
"new",
"PsiException",
"(",
"'Invalid input, not an array or an Iterator or a Traversable'",
")",
";",
"}"
] |
@param mixed $iteratable
@return \Iterator|\Traversable
@throws PsiException
|
[
"@param",
"mixed",
"$iteratable"
] |
train
|
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/DefaultPsiFactory.php#L80-L99
|
dandisy/laravel-generator
|
src/Commands/Publish/VueJsLayoutPublishCommand.php
|
VueJsLayoutPublishCommand.fillTemplate
|
private function fillTemplate($templateData)
{
$templateData = str_replace(
'$NAMESPACE_CONTROLLER$',
config('webcore.laravel_generator.namespace.controller'), $templateData
);
$templateData = str_replace(
'$NAMESPACE_REQUEST$',
config('webcore.laravel_generator.namespace.request'), $templateData
);
return $templateData;
}
|
php
|
private function fillTemplate($templateData)
{
$templateData = str_replace(
'$NAMESPACE_CONTROLLER$',
config('webcore.laravel_generator.namespace.controller'), $templateData
);
$templateData = str_replace(
'$NAMESPACE_REQUEST$',
config('webcore.laravel_generator.namespace.request'), $templateData
);
return $templateData;
}
|
[
"private",
"function",
"fillTemplate",
"(",
"$",
"templateData",
")",
"{",
"$",
"templateData",
"=",
"str_replace",
"(",
"'$NAMESPACE_CONTROLLER$'",
",",
"config",
"(",
"'webcore.laravel_generator.namespace.controller'",
")",
",",
"$",
"templateData",
")",
";",
"$",
"templateData",
"=",
"str_replace",
"(",
"'$NAMESPACE_REQUEST$'",
",",
"config",
"(",
"'webcore.laravel_generator.namespace.request'",
")",
",",
"$",
"templateData",
")",
";",
"return",
"$",
"templateData",
";",
"}"
] |
Replaces dynamic variables of template.
@param string $templateData
@return string
|
[
"Replaces",
"dynamic",
"variables",
"of",
"template",
"."
] |
train
|
https://github.com/dandisy/laravel-generator/blob/742797c8483bc88b54b6302a516a9a85eeb8579b/src/Commands/Publish/VueJsLayoutPublishCommand.php#L260-L273
|
2amigos/yiifoundation
|
helpers/Panel.php
|
Panel.panel
|
public static function panel($content, $htmlOptions = array())
{
ArrayHelper::addValue('class', Enum::PANEL, $htmlOptions);
return \CHtml::tag('div', $htmlOptions, $content);
}
|
php
|
public static function panel($content, $htmlOptions = array())
{
ArrayHelper::addValue('class', Enum::PANEL, $htmlOptions);
return \CHtml::tag('div', $htmlOptions, $content);
}
|
[
"public",
"static",
"function",
"panel",
"(",
"$",
"content",
",",
"$",
"htmlOptions",
"=",
"array",
"(",
")",
")",
"{",
"ArrayHelper",
"::",
"addValue",
"(",
"'class'",
",",
"Enum",
"::",
"PANEL",
",",
"$",
"htmlOptions",
")",
";",
"return",
"\\",
"CHtml",
"::",
"tag",
"(",
"'div'",
",",
"$",
"htmlOptions",
",",
"$",
"content",
")",
";",
"}"
] |
Generates a panel
@param string $content the content to display
@param array $htmlOptions the HTML attributes of the panel
@return string
@see http://foundation.zurb.com/docs/components/panels.html
|
[
"Generates",
"a",
"panel"
] |
train
|
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Panel.php#L31-L35
|
2amigos/yiifoundation
|
helpers/Panel.php
|
Panel.callout
|
public static function callout($content, $htmlOptions = array())
{
ArrayHelper::addValue('class', Enum::PANEL_CALLOUT, $htmlOptions);
return static::panel($content, $htmlOptions);
}
|
php
|
public static function callout($content, $htmlOptions = array())
{
ArrayHelper::addValue('class', Enum::PANEL_CALLOUT, $htmlOptions);
return static::panel($content, $htmlOptions);
}
|
[
"public",
"static",
"function",
"callout",
"(",
"$",
"content",
",",
"$",
"htmlOptions",
"=",
"array",
"(",
")",
")",
"{",
"ArrayHelper",
"::",
"addValue",
"(",
"'class'",
",",
"Enum",
"::",
"PANEL_CALLOUT",
",",
"$",
"htmlOptions",
")",
";",
"return",
"static",
"::",
"panel",
"(",
"$",
"content",
",",
"$",
"htmlOptions",
")",
";",
"}"
] |
Generates a callout panel
@param string $content the content to display
@param array $htmlOptions the HTML attributes of the panel
@return string
|
[
"Generates",
"a",
"callout",
"panel"
] |
train
|
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Panel.php#L44-L48
|
ClanCats/Core
|
src/console/doctor.php
|
doctor.action_security_key
|
public function action_security_key( $params )
{
$path = \CCPath::config( 'main.config'.EXT );
// Check if the file exists
if ( !file_exists( $path ) )
{
$this->error( 'Could not find main configuration file.' ); return;
}
// Now try to replace the placeholder with
// an new generated key
$data = \CCFile::read( $path );
if ( strpos( $data, '{{security salt here}}' ) === false )
{
$this->error( 'The key has already been generated or set.' ); return;
}
$data = str_replace( '{{security salt here}}', \CCStr::random( 32, 'password' ), $data );
// write the data back down
\CCFile::write( $path, $data );
$this->success( 'The key has been generated.' );
}
|
php
|
public function action_security_key( $params )
{
$path = \CCPath::config( 'main.config'.EXT );
// Check if the file exists
if ( !file_exists( $path ) )
{
$this->error( 'Could not find main configuration file.' ); return;
}
// Now try to replace the placeholder with
// an new generated key
$data = \CCFile::read( $path );
if ( strpos( $data, '{{security salt here}}' ) === false )
{
$this->error( 'The key has already been generated or set.' ); return;
}
$data = str_replace( '{{security salt here}}', \CCStr::random( 32, 'password' ), $data );
// write the data back down
\CCFile::write( $path, $data );
$this->success( 'The key has been generated.' );
}
|
[
"public",
"function",
"action_security_key",
"(",
"$",
"params",
")",
"{",
"$",
"path",
"=",
"\\",
"CCPath",
"::",
"config",
"(",
"'main.config'",
".",
"EXT",
")",
";",
"// Check if the file exists",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Could not find main configuration file.'",
")",
";",
"return",
";",
"}",
"// Now try to replace the placeholder with ",
"// an new generated key",
"$",
"data",
"=",
"\\",
"CCFile",
"::",
"read",
"(",
"$",
"path",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"data",
",",
"'{{security salt here}}'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'The key has already been generated or set.'",
")",
";",
"return",
";",
"}",
"$",
"data",
"=",
"str_replace",
"(",
"'{{security salt here}}'",
",",
"\\",
"CCStr",
"::",
"random",
"(",
"32",
",",
"'password'",
")",
",",
"$",
"data",
")",
";",
"// write the data back down",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"path",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"success",
"(",
"'The key has been generated.'",
")",
";",
"}"
] |
Try to generate a security key in the main config file
@param array $params
|
[
"Try",
"to",
"generate",
"a",
"security",
"key",
"in",
"the",
"main",
"config",
"file"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/doctor.php#L43-L68
|
ClanCats/Core
|
src/console/doctor.php
|
doctor.action_permissions
|
public function action_permissions( $params )
{
$folders = \CCEvent::fire( 'ccdoctor.permissions' );
if ( !is_array( $folders ) )
{
$folders = array();
}
// add storage directories
foreach( \ClanCats::$config->get( 'storage.paths' ) as $folder )
{
$folders[] = $folder;
}
foreach( $folders as $folder )
{
$display_folder = \CCStr::replace( $folder, array( CCROOT => '' ) );
// create directory if not existing
if ( !is_dir( $folder ) )
{
if ( !mkdir( $folder, 0755, true ) )
{
$this->error( "doctor could not create folder at: {$display_folder}" );
}
}
// check permissions
$perm = substr( decoct( fileperms( $folder ) ), 2 );
if ( $perm < 755 )
{
CCCli::line( CCCli::color( $perm, 'red' ).
' - '.
$display_folder.
' fixing with '.CCCli::color( '755', 'green' )
);
if ( !chmod( $folder, 0755 ) )
{
CCCli::line( "doctor - is not able to change permissions for: {$display_folder}", 'red' );
}
}
elseif ( $perm == 777 )
{
CCCli::line( CCCli::color( $perm, 'yellow' ).
' - '.
$display_folder.
' warning! this can be dangerous.'
);
}
else
{
$this->success( '- '.$display_folder, $perm );
}
}
}
|
php
|
public function action_permissions( $params )
{
$folders = \CCEvent::fire( 'ccdoctor.permissions' );
if ( !is_array( $folders ) )
{
$folders = array();
}
// add storage directories
foreach( \ClanCats::$config->get( 'storage.paths' ) as $folder )
{
$folders[] = $folder;
}
foreach( $folders as $folder )
{
$display_folder = \CCStr::replace( $folder, array( CCROOT => '' ) );
// create directory if not existing
if ( !is_dir( $folder ) )
{
if ( !mkdir( $folder, 0755, true ) )
{
$this->error( "doctor could not create folder at: {$display_folder}" );
}
}
// check permissions
$perm = substr( decoct( fileperms( $folder ) ), 2 );
if ( $perm < 755 )
{
CCCli::line( CCCli::color( $perm, 'red' ).
' - '.
$display_folder.
' fixing with '.CCCli::color( '755', 'green' )
);
if ( !chmod( $folder, 0755 ) )
{
CCCli::line( "doctor - is not able to change permissions for: {$display_folder}", 'red' );
}
}
elseif ( $perm == 777 )
{
CCCli::line( CCCli::color( $perm, 'yellow' ).
' - '.
$display_folder.
' warning! this can be dangerous.'
);
}
else
{
$this->success( '- '.$display_folder, $perm );
}
}
}
|
[
"public",
"function",
"action_permissions",
"(",
"$",
"params",
")",
"{",
"$",
"folders",
"=",
"\\",
"CCEvent",
"::",
"fire",
"(",
"'ccdoctor.permissions'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"folders",
")",
")",
"{",
"$",
"folders",
"=",
"array",
"(",
")",
";",
"}",
"// add storage directories",
"foreach",
"(",
"\\",
"ClanCats",
"::",
"$",
"config",
"->",
"get",
"(",
"'storage.paths'",
")",
"as",
"$",
"folder",
")",
"{",
"$",
"folders",
"[",
"]",
"=",
"$",
"folder",
";",
"}",
"foreach",
"(",
"$",
"folders",
"as",
"$",
"folder",
")",
"{",
"$",
"display_folder",
"=",
"\\",
"CCStr",
"::",
"replace",
"(",
"$",
"folder",
",",
"array",
"(",
"CCROOT",
"=>",
"''",
")",
")",
";",
"// create directory if not existing",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"folder",
",",
"0755",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"doctor could not create folder at: {$display_folder}\"",
")",
";",
"}",
"}",
"// check permissions",
"$",
"perm",
"=",
"substr",
"(",
"decoct",
"(",
"fileperms",
"(",
"$",
"folder",
")",
")",
",",
"2",
")",
";",
"if",
"(",
"$",
"perm",
"<",
"755",
")",
"{",
"CCCli",
"::",
"line",
"(",
"CCCli",
"::",
"color",
"(",
"$",
"perm",
",",
"'red'",
")",
".",
"' - '",
".",
"$",
"display_folder",
".",
"' fixing with '",
".",
"CCCli",
"::",
"color",
"(",
"'755'",
",",
"'green'",
")",
")",
";",
"if",
"(",
"!",
"chmod",
"(",
"$",
"folder",
",",
"0755",
")",
")",
"{",
"CCCli",
"::",
"line",
"(",
"\"doctor - is not able to change permissions for: {$display_folder}\"",
",",
"'red'",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"perm",
"==",
"777",
")",
"{",
"CCCli",
"::",
"line",
"(",
"CCCli",
"::",
"color",
"(",
"$",
"perm",
",",
"'yellow'",
")",
".",
"' - '",
".",
"$",
"display_folder",
".",
"' warning! this can be dangerous.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"success",
"(",
"'- '",
".",
"$",
"display_folder",
",",
"$",
"perm",
")",
";",
"}",
"}",
"}"
] |
install an orbit module
@param array $params
|
[
"install",
"an",
"orbit",
"module"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/doctor.php#L75-L131
|
xltxlm/logger
|
src/Operation/Connect/ElasticsearchConnectLog.php
|
ElasticsearchConnectLog.setElasticsearchConfig
|
public function setElasticsearchConfig(ElasticsearchConfig $ElasticsearchConfig): ElasticsearchConnectLog
{
if (strpos(get_class($ElasticsearchConfig), 'class@anonymous') !== false) {
$this->ElasticsearchConfig = (new ConvertObject())
->setObject($ElasticsearchConfig)
->toArray();
} else {
$this->ElasticsearchConfig = $ElasticsearchConfig;
}
return $this;
}
|
php
|
public function setElasticsearchConfig(ElasticsearchConfig $ElasticsearchConfig): ElasticsearchConnectLog
{
if (strpos(get_class($ElasticsearchConfig), 'class@anonymous') !== false) {
$this->ElasticsearchConfig = (new ConvertObject())
->setObject($ElasticsearchConfig)
->toArray();
} else {
$this->ElasticsearchConfig = $ElasticsearchConfig;
}
return $this;
}
|
[
"public",
"function",
"setElasticsearchConfig",
"(",
"ElasticsearchConfig",
"$",
"ElasticsearchConfig",
")",
":",
"ElasticsearchConnectLog",
"{",
"if",
"(",
"strpos",
"(",
"get_class",
"(",
"$",
"ElasticsearchConfig",
")",
",",
"'class@anonymous'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"ElasticsearchConfig",
"=",
"(",
"new",
"ConvertObject",
"(",
")",
")",
"->",
"setObject",
"(",
"$",
"ElasticsearchConfig",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ElasticsearchConfig",
"=",
"$",
"ElasticsearchConfig",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
@param ElasticsearchConfig $ElasticsearchConfig
@return ElasticsearchConnectLog
|
[
"@param",
"ElasticsearchConfig",
"$ElasticsearchConfig"
] |
train
|
https://github.com/xltxlm/logger/blob/09592eeac38c6760bb4faabef939dd542f69b056/src/Operation/Connect/ElasticsearchConnectLog.php#L54-L65
|
barebone-php/barebone-core
|
lib/Database.php
|
Database.instance
|
public static function instance()
{
if (null === self::$_instance) {
$capsule = new Capsule;
$capsule->addConnection(self::getConfig());
$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->setAsGlobal();
self::$_instance = $capsule;
}
return self::$_instance;
}
|
php
|
public static function instance()
{
if (null === self::$_instance) {
$capsule = new Capsule;
$capsule->addConnection(self::getConfig());
$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->setAsGlobal();
self::$_instance = $capsule;
}
return self::$_instance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"self",
"::",
"$",
"_instance",
")",
"{",
"$",
"capsule",
"=",
"new",
"Capsule",
";",
"$",
"capsule",
"->",
"addConnection",
"(",
"self",
"::",
"getConfig",
"(",
")",
")",
";",
"$",
"capsule",
"->",
"setEventDispatcher",
"(",
"new",
"Dispatcher",
"(",
"new",
"Container",
")",
")",
";",
"$",
"capsule",
"->",
"setAsGlobal",
"(",
")",
";",
"self",
"::",
"$",
"_instance",
"=",
"$",
"capsule",
";",
"}",
"return",
"self",
"::",
"$",
"_instance",
";",
"}"
] |
Instantiate Eloquent ORM
@return Capsule
|
[
"Instantiate",
"Eloquent",
"ORM"
] |
train
|
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/Database.php#L48-L59
|
yuncms/framework
|
src/console/controllers/MigrateController.php
|
MigrateController.initMigrationPath
|
public function initMigrationPath()
{
$manifestFile = Yii::getAlias('@vendor/yuncms/migrations.php');
if (is_file($manifestFile)) {
$migrationPaths = require($manifestFile);
$this->migrationPath = ArrayHelper::merge($this->migrationPath, $migrationPaths);
}
$this->migrationPath = array_values($this->migrationPath);
}
|
php
|
public function initMigrationPath()
{
$manifestFile = Yii::getAlias('@vendor/yuncms/migrations.php');
if (is_file($manifestFile)) {
$migrationPaths = require($manifestFile);
$this->migrationPath = ArrayHelper::merge($this->migrationPath, $migrationPaths);
}
$this->migrationPath = array_values($this->migrationPath);
}
|
[
"public",
"function",
"initMigrationPath",
"(",
")",
"{",
"$",
"manifestFile",
"=",
"Yii",
"::",
"getAlias",
"(",
"'@vendor/yuncms/migrations.php'",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"manifestFile",
")",
")",
"{",
"$",
"migrationPaths",
"=",
"require",
"(",
"$",
"manifestFile",
")",
";",
"$",
"this",
"->",
"migrationPath",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"$",
"this",
"->",
"migrationPath",
",",
"$",
"migrationPaths",
")",
";",
"}",
"$",
"this",
"->",
"migrationPath",
"=",
"array_values",
"(",
"$",
"this",
"->",
"migrationPath",
")",
";",
"}"
] |
初始化迁移路径
|
[
"初始化迁移路径"
] |
train
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/console/controllers/MigrateController.php#L67-L75
|
phpbench/container
|
lib/Container.php
|
Container.init
|
public function init()
{
$extensions = [];
if (empty($this->extensionClasses) && empty($this->userConfig)) {
return;
}
foreach ($this->extensionClasses as $extensionClass) {
if (!class_exists($extensionClass)) {
throw new \InvalidArgumentException(sprintf(
'Extension class "%s" does not exist',
$extensionClass
));
}
$extension = new $extensionClass();
if (!$extension instanceof ExtensionInterface) {
throw new \InvalidArgumentException(sprintf(
// add any manually specified extensions
'Extension "%s" must implement the PhpBench\\Extension interface',
get_class($extension)
));
}
$extensions[] = $extension;
$this->config = array_merge(
$this->config,
$extension->getDefaultConfig()
);
}
$diff = array_diff(array_keys($this->userConfig), array_keys($this->config));
if ($diff) {
throw new \InvalidArgumentException(sprintf(
'Unknown configuration keys: "%s". Permitted keys: "%s"',
implode('", "', $diff), implode('", "', array_keys($this->config))
));
}
$this->config = array_merge(
$this->config,
$this->userConfig
);
foreach ($extensions as $extension) {
$extension->load($this);
}
}
|
php
|
public function init()
{
$extensions = [];
if (empty($this->extensionClasses) && empty($this->userConfig)) {
return;
}
foreach ($this->extensionClasses as $extensionClass) {
if (!class_exists($extensionClass)) {
throw new \InvalidArgumentException(sprintf(
'Extension class "%s" does not exist',
$extensionClass
));
}
$extension = new $extensionClass();
if (!$extension instanceof ExtensionInterface) {
throw new \InvalidArgumentException(sprintf(
// add any manually specified extensions
'Extension "%s" must implement the PhpBench\\Extension interface',
get_class($extension)
));
}
$extensions[] = $extension;
$this->config = array_merge(
$this->config,
$extension->getDefaultConfig()
);
}
$diff = array_diff(array_keys($this->userConfig), array_keys($this->config));
if ($diff) {
throw new \InvalidArgumentException(sprintf(
'Unknown configuration keys: "%s". Permitted keys: "%s"',
implode('", "', $diff), implode('", "', array_keys($this->config))
));
}
$this->config = array_merge(
$this->config,
$this->userConfig
);
foreach ($extensions as $extension) {
$extension->load($this);
}
}
|
[
"public",
"function",
"init",
"(",
")",
"{",
"$",
"extensions",
"=",
"[",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"extensionClasses",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"userConfig",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"extensionClasses",
"as",
"$",
"extensionClass",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"extensionClass",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Extension class \"%s\" does not exist'",
",",
"$",
"extensionClass",
")",
")",
";",
"}",
"$",
"extension",
"=",
"new",
"$",
"extensionClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"extension",
"instanceof",
"ExtensionInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"// add any manually specified extensions",
"'Extension \"%s\" must implement the PhpBench\\\\Extension interface'",
",",
"get_class",
"(",
"$",
"extension",
")",
")",
")",
";",
"}",
"$",
"extensions",
"[",
"]",
"=",
"$",
"extension",
";",
"$",
"this",
"->",
"config",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"extension",
"->",
"getDefaultConfig",
"(",
")",
")",
";",
"}",
"$",
"diff",
"=",
"array_diff",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"userConfig",
")",
",",
"array_keys",
"(",
"$",
"this",
"->",
"config",
")",
")",
";",
"if",
"(",
"$",
"diff",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unknown configuration keys: \"%s\". Permitted keys: \"%s\"'",
",",
"implode",
"(",
"'\", \"'",
",",
"$",
"diff",
")",
",",
"implode",
"(",
"'\", \"'",
",",
"array_keys",
"(",
"$",
"this",
"->",
"config",
")",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"config",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"userConfig",
")",
";",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"load",
"(",
"$",
"this",
")",
";",
"}",
"}"
] |
Configure the container. This method will call the `configure()` method
on each extension. Extensions must use this opportunity to register their
services and define any default config.
This method must be called before `build()`.
|
[
"Configure",
"the",
"container",
".",
"This",
"method",
"will",
"call",
"the",
"configure",
"()",
"method",
"on",
"each",
"extension",
".",
"Extensions",
"must",
"use",
"this",
"opportunity",
"to",
"register",
"their",
"services",
"and",
"define",
"any",
"default",
"config",
"."
] |
train
|
https://github.com/phpbench/container/blob/7acabddac1fd09cb58d4790443b6b791bf9f3095/lib/Container.php#L44-L95
|
phpbench/container
|
lib/Container.php
|
Container.get
|
public function get($serviceId)
{
if (isset($this->services[$serviceId])) {
return $this->services[$serviceId];
}
if (!isset($this->instantiators[$serviceId])) {
throw new \InvalidArgumentException(sprintf(
'No instantiator has been registered for requested service "%s"',
$serviceId
));
}
$this->services[$serviceId] = $this->instantiators[$serviceId]($this);
return $this->services[$serviceId];
}
|
php
|
public function get($serviceId)
{
if (isset($this->services[$serviceId])) {
return $this->services[$serviceId];
}
if (!isset($this->instantiators[$serviceId])) {
throw new \InvalidArgumentException(sprintf(
'No instantiator has been registered for requested service "%s"',
$serviceId
));
}
$this->services[$serviceId] = $this->instantiators[$serviceId]($this);
return $this->services[$serviceId];
}
|
[
"public",
"function",
"get",
"(",
"$",
"serviceId",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"services",
"[",
"$",
"serviceId",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"services",
"[",
"$",
"serviceId",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"instantiators",
"[",
"$",
"serviceId",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No instantiator has been registered for requested service \"%s\"'",
",",
"$",
"serviceId",
")",
")",
";",
"}",
"$",
"this",
"->",
"services",
"[",
"$",
"serviceId",
"]",
"=",
"$",
"this",
"->",
"instantiators",
"[",
"$",
"serviceId",
"]",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"services",
"[",
"$",
"serviceId",
"]",
";",
"}"
] |
Instantiate and return the service with the given ID.
Note that this method will return the same instance on subsequent calls.
@param string $serviceId
@return mixed
|
[
"Instantiate",
"and",
"return",
"the",
"service",
"with",
"the",
"given",
"ID",
".",
"Note",
"that",
"this",
"method",
"will",
"return",
"the",
"same",
"instance",
"on",
"subsequent",
"calls",
"."
] |
train
|
https://github.com/phpbench/container/blob/7acabddac1fd09cb58d4790443b6b791bf9f3095/lib/Container.php#L105-L121
|
phpbench/container
|
lib/Container.php
|
Container.getServiceIdsForTag
|
public function getServiceIdsForTag($tag)
{
$serviceIds = [];
foreach ($this->tags as $serviceId => $tags) {
if (isset($tags[$tag])) {
$serviceIds[$serviceId] = $tags[$tag];
}
}
return $serviceIds;
}
|
php
|
public function getServiceIdsForTag($tag)
{
$serviceIds = [];
foreach ($this->tags as $serviceId => $tags) {
if (isset($tags[$tag])) {
$serviceIds[$serviceId] = $tags[$tag];
}
}
return $serviceIds;
}
|
[
"public",
"function",
"getServiceIdsForTag",
"(",
"$",
"tag",
")",
"{",
"$",
"serviceIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"tags",
"as",
"$",
"serviceId",
"=>",
"$",
"tags",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"tags",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"$",
"serviceIds",
"[",
"$",
"serviceId",
"]",
"=",
"$",
"tags",
"[",
"$",
"tag",
"]",
";",
"}",
"}",
"return",
"$",
"serviceIds",
";",
"}"
] |
Return services IDs for the given tag.
@param string $tag
@return string[][]
|
[
"Return",
"services",
"IDs",
"for",
"the",
"given",
"tag",
"."
] |
train
|
https://github.com/phpbench/container/blob/7acabddac1fd09cb58d4790443b6b791bf9f3095/lib/Container.php#L146-L156
|
phpbench/container
|
lib/Container.php
|
Container.register
|
public function register($serviceId, \Closure $instantiator, array $tags = [])
{
if (isset($this->instantiators[$serviceId])) {
throw new \InvalidArgumentException(sprintf(
'Service with ID "%s" has already been registered', $serviceId));
}
$this->instantiators[$serviceId] = $instantiator;
$this->tags[$serviceId] = $tags;
}
|
php
|
public function register($serviceId, \Closure $instantiator, array $tags = [])
{
if (isset($this->instantiators[$serviceId])) {
throw new \InvalidArgumentException(sprintf(
'Service with ID "%s" has already been registered', $serviceId));
}
$this->instantiators[$serviceId] = $instantiator;
$this->tags[$serviceId] = $tags;
}
|
[
"public",
"function",
"register",
"(",
"$",
"serviceId",
",",
"\\",
"Closure",
"$",
"instantiator",
",",
"array",
"$",
"tags",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"instantiators",
"[",
"$",
"serviceId",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Service with ID \"%s\" has already been registered'",
",",
"$",
"serviceId",
")",
")",
";",
"}",
"$",
"this",
"->",
"instantiators",
"[",
"$",
"serviceId",
"]",
"=",
"$",
"instantiator",
";",
"$",
"this",
"->",
"tags",
"[",
"$",
"serviceId",
"]",
"=",
"$",
"tags",
";",
"}"
] |
Register a service with the given ID and instantiator.
The instantiator is a closure which accepts an instance of this container and
returns a new instance of the service class.
@param string $serviceId
@param \Closure $instantiator
@param string[][] $tags
|
[
"Register",
"a",
"service",
"with",
"the",
"given",
"ID",
"and",
"instantiator",
"."
] |
train
|
https://github.com/phpbench/container/blob/7acabddac1fd09cb58d4790443b6b791bf9f3095/lib/Container.php#L168-L177
|
phpbench/container
|
lib/Container.php
|
Container.getParameter
|
public function getParameter($name)
{
if (!array_key_exists($name, $this->config)) {
throw new \InvalidArgumentException(sprintf(
'Parameter "%s" has not been registered',
$name
));
}
return $this->config[$name];
}
|
php
|
public function getParameter($name)
{
if (!array_key_exists($name, $this->config)) {
throw new \InvalidArgumentException(sprintf(
'Parameter "%s" has not been registered',
$name
));
}
return $this->config[$name];
}
|
[
"public",
"function",
"getParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Parameter \"%s\" has not been registered'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"config",
"[",
"$",
"name",
"]",
";",
"}"
] |
Return the parameter with the given name.
@param string $name
@throws \InvalidArgumentException
@return mixed
|
[
"Return",
"the",
"parameter",
"with",
"the",
"given",
"name",
"."
] |
train
|
https://github.com/phpbench/container/blob/7acabddac1fd09cb58d4790443b6b791bf9f3095/lib/Container.php#L216-L226
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.escape
|
public function escape( $string )
{
if ( \DB::is_expression( $string ) )
{
return $string->value;
}
// the string might contain an 'as' statement that we wil have to split.
if ( strpos( $string, ' as ' ) !== false )
{
$string = explode( ' as ', $string );
return $this->escape( trim( $string[0] ) ).' as '. $this->escape( trim( $string[1] ) );
}
// it also might contain dott seperations we have to split
if ( strpos( $string, '.' ) !== false )
{
$string = explode( '.', $string );
foreach( $string as $key => $item )
{
$string[$key] = $this->escape_string( $item );
}
return implode( '.' , $string );
}
return $this->escape_string( $string );
}
|
php
|
public function escape( $string )
{
if ( \DB::is_expression( $string ) )
{
return $string->value;
}
// the string might contain an 'as' statement that we wil have to split.
if ( strpos( $string, ' as ' ) !== false )
{
$string = explode( ' as ', $string );
return $this->escape( trim( $string[0] ) ).' as '. $this->escape( trim( $string[1] ) );
}
// it also might contain dott seperations we have to split
if ( strpos( $string, '.' ) !== false )
{
$string = explode( '.', $string );
foreach( $string as $key => $item )
{
$string[$key] = $this->escape_string( $item );
}
return implode( '.' , $string );
}
return $this->escape_string( $string );
}
|
[
"public",
"function",
"escape",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"\\",
"DB",
"::",
"is_expression",
"(",
"$",
"string",
")",
")",
"{",
"return",
"$",
"string",
"->",
"value",
";",
"}",
"// the string might contain an 'as' statement that we wil have to split.",
"if",
"(",
"strpos",
"(",
"$",
"string",
",",
"' as '",
")",
"!==",
"false",
")",
"{",
"$",
"string",
"=",
"explode",
"(",
"' as '",
",",
"$",
"string",
")",
";",
"return",
"$",
"this",
"->",
"escape",
"(",
"trim",
"(",
"$",
"string",
"[",
"0",
"]",
")",
")",
".",
"' as '",
".",
"$",
"this",
"->",
"escape",
"(",
"trim",
"(",
"$",
"string",
"[",
"1",
"]",
")",
")",
";",
"}",
"// it also might contain dott seperations we have to split",
"if",
"(",
"strpos",
"(",
"$",
"string",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"string",
"=",
"explode",
"(",
"'.'",
",",
"$",
"string",
")",
";",
"foreach",
"(",
"$",
"string",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"string",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"escape_string",
"(",
"$",
"item",
")",
";",
"}",
"return",
"implode",
"(",
"'.'",
",",
"$",
"string",
")",
";",
"}",
"return",
"$",
"this",
"->",
"escape_string",
"(",
"$",
"string",
")",
";",
"}"
] |
Escape / wrap an string for sql
@param string|Expression $string
|
[
"Escape",
"/",
"wrap",
"an",
"string",
"for",
"sql"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L82-L110
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.escape_table
|
public function escape_table( &$query )
{
$table = $query->table;
if ( is_array( $table ) )
{
reset($table); $table = key($table).' as '.$table[key($table)];
}
return $this->escape( $table );
}
|
php
|
public function escape_table( &$query )
{
$table = $query->table;
if ( is_array( $table ) )
{
reset($table); $table = key($table).' as '.$table[key($table)];
}
return $this->escape( $table );
}
|
[
"public",
"function",
"escape_table",
"(",
"&",
"$",
"query",
")",
"{",
"$",
"table",
"=",
"$",
"query",
"->",
"table",
";",
"if",
"(",
"is_array",
"(",
"$",
"table",
")",
")",
"{",
"reset",
"(",
"$",
"table",
")",
";",
"$",
"table",
"=",
"key",
"(",
"$",
"table",
")",
".",
"' as '",
".",
"$",
"table",
"[",
"key",
"(",
"$",
"table",
")",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"escape",
"(",
"$",
"table",
")",
";",
"}"
] |
Escape the table
@param Query $query
@return string
|
[
"Escape",
"the",
"table"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L145-L155
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.parameterize
|
public function parameterize( $params )
{
foreach( $params as $key => $param )
{
$params[$key] = $this->param( $param );
}
return implode( ', ', $params );
}
|
php
|
public function parameterize( $params )
{
foreach( $params as $key => $param )
{
$params[$key] = $this->param( $param );
}
return implode( ', ', $params );
}
|
[
"public",
"function",
"parameterize",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"param",
")",
"{",
"$",
"params",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"param",
"(",
"$",
"param",
")",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"params",
")",
";",
"}"
] |
Convert data to parameters and bind them to the query
@param array $params
@return string
|
[
"Convert",
"data",
"to",
"parameters",
"and",
"bind",
"them",
"to",
"the",
"query"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L163-L171
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.compile_insert
|
public function compile_insert( &$query )
{
$build = ( $query->ignore ? 'insert ignore' : 'insert' ).' into '.$this->escape_table( $query ).' ';
$value_collection = $query->values;
// Get the array keys from the first array in the collection.
// We use them as insert keys.
$build .= '('.$this->escape_list( array_keys( reset( $value_collection ) ) ).') values ';
// add the array values.
foreach( $value_collection as $values )
{
$build .= '('.$this->parameterize( $values ).'), ';
}
// cut the last comma away
return substr( $build, 0, -2 );
}
|
php
|
public function compile_insert( &$query )
{
$build = ( $query->ignore ? 'insert ignore' : 'insert' ).' into '.$this->escape_table( $query ).' ';
$value_collection = $query->values;
// Get the array keys from the first array in the collection.
// We use them as insert keys.
$build .= '('.$this->escape_list( array_keys( reset( $value_collection ) ) ).') values ';
// add the array values.
foreach( $value_collection as $values )
{
$build .= '('.$this->parameterize( $values ).'), ';
}
// cut the last comma away
return substr( $build, 0, -2 );
}
|
[
"public",
"function",
"compile_insert",
"(",
"&",
"$",
"query",
")",
"{",
"$",
"build",
"=",
"(",
"$",
"query",
"->",
"ignore",
"?",
"'insert ignore'",
":",
"'insert'",
")",
".",
"' into '",
".",
"$",
"this",
"->",
"escape_table",
"(",
"$",
"query",
")",
".",
"' '",
";",
"$",
"value_collection",
"=",
"$",
"query",
"->",
"values",
";",
"// Get the array keys from the first array in the collection.",
"// We use them as insert keys.",
"$",
"build",
".=",
"'('",
".",
"$",
"this",
"->",
"escape_list",
"(",
"array_keys",
"(",
"reset",
"(",
"$",
"value_collection",
")",
")",
")",
".",
"') values '",
";",
"// add the array values.",
"foreach",
"(",
"$",
"value_collection",
"as",
"$",
"values",
")",
"{",
"$",
"build",
".=",
"'('",
".",
"$",
"this",
"->",
"parameterize",
"(",
"$",
"values",
")",
".",
"'), '",
";",
"}",
"// cut the last comma away",
"return",
"substr",
"(",
"$",
"build",
",",
"0",
",",
"-",
"2",
")",
";",
"}"
] |
Build an insert query
@param Query $query
@return string
|
[
"Build",
"an",
"insert",
"query"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L179-L197
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.compile_update
|
public function compile_update( &$query )
{
$build = 'update '.$this->escape_table( $query ).' set ';
// add the array values.
foreach( $query->values as $key => $value )
{
$build .= $this->escape( $key ).' = '.$this->param( $value ).', ';
}
$build = substr( $build, 0, -2 );
$build .= $this->compile_where( $query );
$build .= $this->compile_limit( $query );
// cut the last comma away
return $build;
}
|
php
|
public function compile_update( &$query )
{
$build = 'update '.$this->escape_table( $query ).' set ';
// add the array values.
foreach( $query->values as $key => $value )
{
$build .= $this->escape( $key ).' = '.$this->param( $value ).', ';
}
$build = substr( $build, 0, -2 );
$build .= $this->compile_where( $query );
$build .= $this->compile_limit( $query );
// cut the last comma away
return $build;
}
|
[
"public",
"function",
"compile_update",
"(",
"&",
"$",
"query",
")",
"{",
"$",
"build",
"=",
"'update '",
".",
"$",
"this",
"->",
"escape_table",
"(",
"$",
"query",
")",
".",
"' set '",
";",
"// add the array values.",
"foreach",
"(",
"$",
"query",
"->",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"build",
".=",
"$",
"this",
"->",
"escape",
"(",
"$",
"key",
")",
".",
"' = '",
".",
"$",
"this",
"->",
"param",
"(",
"$",
"value",
")",
".",
"', '",
";",
"}",
"$",
"build",
"=",
"substr",
"(",
"$",
"build",
",",
"0",
",",
"-",
"2",
")",
";",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_where",
"(",
"$",
"query",
")",
";",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_limit",
"(",
"$",
"query",
")",
";",
"// cut the last comma away",
"return",
"$",
"build",
";",
"}"
] |
Build an update query
@param Query $query
@return string
|
[
"Build",
"an",
"update",
"query"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L205-L221
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.compile_delete
|
public function compile_delete( &$query )
{
$build = 'delete from '.$this->escape_table( $query );
$build .= $this->compile_where( $query );
$build .= $this->compile_limit( $query );
// cut the last comma away
return $build;
}
|
php
|
public function compile_delete( &$query )
{
$build = 'delete from '.$this->escape_table( $query );
$build .= $this->compile_where( $query );
$build .= $this->compile_limit( $query );
// cut the last comma away
return $build;
}
|
[
"public",
"function",
"compile_delete",
"(",
"&",
"$",
"query",
")",
"{",
"$",
"build",
"=",
"'delete from '",
".",
"$",
"this",
"->",
"escape_table",
"(",
"$",
"query",
")",
";",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_where",
"(",
"$",
"query",
")",
";",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_limit",
"(",
"$",
"query",
")",
";",
"// cut the last comma away",
"return",
"$",
"build",
";",
"}"
] |
Build an delete query
@param Query $query
@return string
|
[
"Build",
"an",
"delete",
"query"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L229-L238
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.compile_select
|
public function compile_select( &$query )
{
$build = ( $query->distinct ? 'select distinct' : 'select' ).' ';
if ( !empty( $query->fields ) )
{
foreach( $query->fields as $key => $field )
{
if ( !is_numeric( $key ) )
{
$build .= $this->escape( $key ).' as '.$this->escape( $field );
}
elseif ( is_array( $field ) )
{
$build .= $this->escape( $field[0] ).' as '.$this->escape( $field[1] );
}
else
{
$build .= $this->escape( $field );
}
$build .= ', ';
}
$build = substr( $build, 0, -2 );
}
else
{
$build .= '*';
}
// append the table
$build .= ' from '.$this->escape_table( $query );
// build the where stuff
$build .= $this->compile_where( $query );
$build .= $this->compile_group( $query );
$build .= $this->compile_order( $query );
$build .= $this->compile_limit_with_offset( $query );
return $build;
}
|
php
|
public function compile_select( &$query )
{
$build = ( $query->distinct ? 'select distinct' : 'select' ).' ';
if ( !empty( $query->fields ) )
{
foreach( $query->fields as $key => $field )
{
if ( !is_numeric( $key ) )
{
$build .= $this->escape( $key ).' as '.$this->escape( $field );
}
elseif ( is_array( $field ) )
{
$build .= $this->escape( $field[0] ).' as '.$this->escape( $field[1] );
}
else
{
$build .= $this->escape( $field );
}
$build .= ', ';
}
$build = substr( $build, 0, -2 );
}
else
{
$build .= '*';
}
// append the table
$build .= ' from '.$this->escape_table( $query );
// build the where stuff
$build .= $this->compile_where( $query );
$build .= $this->compile_group( $query );
$build .= $this->compile_order( $query );
$build .= $this->compile_limit_with_offset( $query );
return $build;
}
|
[
"public",
"function",
"compile_select",
"(",
"&",
"$",
"query",
")",
"{",
"$",
"build",
"=",
"(",
"$",
"query",
"->",
"distinct",
"?",
"'select distinct'",
":",
"'select'",
")",
".",
"' '",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
"->",
"fields",
")",
")",
"{",
"foreach",
"(",
"$",
"query",
"->",
"fields",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"build",
".=",
"$",
"this",
"->",
"escape",
"(",
"$",
"key",
")",
".",
"' as '",
".",
"$",
"this",
"->",
"escape",
"(",
"$",
"field",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"field",
")",
")",
"{",
"$",
"build",
".=",
"$",
"this",
"->",
"escape",
"(",
"$",
"field",
"[",
"0",
"]",
")",
".",
"' as '",
".",
"$",
"this",
"->",
"escape",
"(",
"$",
"field",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"build",
".=",
"$",
"this",
"->",
"escape",
"(",
"$",
"field",
")",
";",
"}",
"$",
"build",
".=",
"', '",
";",
"}",
"$",
"build",
"=",
"substr",
"(",
"$",
"build",
",",
"0",
",",
"-",
"2",
")",
";",
"}",
"else",
"{",
"$",
"build",
".=",
"'*'",
";",
"}",
"// append the table",
"$",
"build",
".=",
"' from '",
".",
"$",
"this",
"->",
"escape_table",
"(",
"$",
"query",
")",
";",
"// build the where stuff",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_where",
"(",
"$",
"query",
")",
";",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_group",
"(",
"$",
"query",
")",
";",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_order",
"(",
"$",
"query",
")",
";",
"$",
"build",
".=",
"$",
"this",
"->",
"compile_limit_with_offset",
"(",
"$",
"query",
")",
";",
"return",
"$",
"build",
";",
"}"
] |
Build a select
@param Query $query
@return string
|
[
"Build",
"a",
"select"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L246-L286
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.compile_where
|
public function compile_where( &$query )
{
$build = '';
foreach( $query->wheres as $where )
{
// to make nested wheres possible you can pass an closure
// wich will create a new query where you can add your nested wheres
if ( !isset( $where[2] ) && is_closure( $where[1] ) )
{
$sub_query = new Query;
call_user_func( $where[1], $sub_query );
// The parameters get added by the call of compile where
$build .= ' '.$where[0].' ( '.substr( $this->compile_where( $sub_query ), 7 ).' )';
continue;
}
// when we have an array as where values we have
// to parameterize them
if ( is_array( $where[3] ) )
{
$where[3] = '('.$this->parameterize( $where[3] ).')';
}
else
{
$where[3] = $this->param( $where[3] );
}
// we always need to escepe where 1 wich referrs to the key
$where[1] = $this->escape( $where[1] );
// implode the beauty
$build .= ' '.implode( ' ', $where );
}
return $build;
}
|
php
|
public function compile_where( &$query )
{
$build = '';
foreach( $query->wheres as $where )
{
// to make nested wheres possible you can pass an closure
// wich will create a new query where you can add your nested wheres
if ( !isset( $where[2] ) && is_closure( $where[1] ) )
{
$sub_query = new Query;
call_user_func( $where[1], $sub_query );
// The parameters get added by the call of compile where
$build .= ' '.$where[0].' ( '.substr( $this->compile_where( $sub_query ), 7 ).' )';
continue;
}
// when we have an array as where values we have
// to parameterize them
if ( is_array( $where[3] ) )
{
$where[3] = '('.$this->parameterize( $where[3] ).')';
}
else
{
$where[3] = $this->param( $where[3] );
}
// we always need to escepe where 1 wich referrs to the key
$where[1] = $this->escape( $where[1] );
// implode the beauty
$build .= ' '.implode( ' ', $where );
}
return $build;
}
|
[
"public",
"function",
"compile_where",
"(",
"&",
"$",
"query",
")",
"{",
"$",
"build",
"=",
"''",
";",
"foreach",
"(",
"$",
"query",
"->",
"wheres",
"as",
"$",
"where",
")",
"{",
"// to make nested wheres possible you can pass an closure ",
"// wich will create a new query where you can add your nested wheres",
"if",
"(",
"!",
"isset",
"(",
"$",
"where",
"[",
"2",
"]",
")",
"&&",
"is_closure",
"(",
"$",
"where",
"[",
"1",
"]",
")",
")",
"{",
"$",
"sub_query",
"=",
"new",
"Query",
";",
"call_user_func",
"(",
"$",
"where",
"[",
"1",
"]",
",",
"$",
"sub_query",
")",
";",
"// The parameters get added by the call of compile where",
"$",
"build",
".=",
"' '",
".",
"$",
"where",
"[",
"0",
"]",
".",
"' ( '",
".",
"substr",
"(",
"$",
"this",
"->",
"compile_where",
"(",
"$",
"sub_query",
")",
",",
"7",
")",
".",
"' )'",
";",
"continue",
";",
"}",
"// when we have an array as where values we have ",
"// to parameterize them",
"if",
"(",
"is_array",
"(",
"$",
"where",
"[",
"3",
"]",
")",
")",
"{",
"$",
"where",
"[",
"3",
"]",
"=",
"'('",
".",
"$",
"this",
"->",
"parameterize",
"(",
"$",
"where",
"[",
"3",
"]",
")",
".",
"')'",
";",
"}",
"else",
"{",
"$",
"where",
"[",
"3",
"]",
"=",
"$",
"this",
"->",
"param",
"(",
"$",
"where",
"[",
"3",
"]",
")",
";",
"}",
"// we always need to escepe where 1 wich referrs to the key",
"$",
"where",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"escape",
"(",
"$",
"where",
"[",
"1",
"]",
")",
";",
"// implode the beauty",
"$",
"build",
".=",
"' '",
".",
"implode",
"(",
"' '",
",",
"$",
"where",
")",
";",
"}",
"return",
"$",
"build",
";",
"}"
] |
Build the where part
@param Query $query
@return string
|
[
"Build",
"the",
"where",
"part"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L294-L333
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.compile_limit_with_offset
|
public function compile_limit_with_offset( &$query )
{
if ( is_null( $query->limit ) )
{
return "";
}
return ' limit '.( (int) $query->offset ).', '.( (int) $query->limit );
}
|
php
|
public function compile_limit_with_offset( &$query )
{
if ( is_null( $query->limit ) )
{
return "";
}
return ' limit '.( (int) $query->offset ).', '.( (int) $query->limit );
}
|
[
"public",
"function",
"compile_limit_with_offset",
"(",
"&",
"$",
"query",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"query",
"->",
"limit",
")",
")",
"{",
"return",
"\"\"",
";",
"}",
"return",
"' limit '",
".",
"(",
"(",
"int",
")",
"$",
"query",
"->",
"offset",
")",
".",
"', '",
".",
"(",
"(",
"int",
")",
"$",
"query",
"->",
"limit",
")",
";",
"}"
] |
Build the limit and offset part
@param Query $query
@return string
|
[
"Build",
"the",
"limit",
"and",
"offset",
"part"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L341-L349
|
ClanCats/Core
|
src/bundles/Database/Builder.php
|
Builder.compile_order
|
protected function compile_order( &$query )
{
if ( empty( $query->orders ) )
{
return '';
}
$build = " order by ";
foreach( $query->orders as $order )
{
$build .= $this->escape( $order[0] ).' '.$order[1].', ';
}
return substr( $build, 0, -2 );
}
|
php
|
protected function compile_order( &$query )
{
if ( empty( $query->orders ) )
{
return '';
}
$build = " order by ";
foreach( $query->orders as $order )
{
$build .= $this->escape( $order[0] ).' '.$order[1].', ';
}
return substr( $build, 0, -2 );
}
|
[
"protected",
"function",
"compile_order",
"(",
"&",
"$",
"query",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"query",
"->",
"orders",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"build",
"=",
"\" order by \"",
";",
"foreach",
"(",
"$",
"query",
"->",
"orders",
"as",
"$",
"order",
")",
"{",
"$",
"build",
".=",
"$",
"this",
"->",
"escape",
"(",
"$",
"order",
"[",
"0",
"]",
")",
".",
"' '",
".",
"$",
"order",
"[",
"1",
"]",
".",
"', '",
";",
"}",
"return",
"substr",
"(",
"$",
"build",
",",
"0",
",",
"-",
"2",
")",
";",
"}"
] |
Build the order by statement
@param Query $query
@return string
|
[
"Build",
"the",
"order",
"by",
"statement"
] |
train
|
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Builder.php#L373-L388
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.element
|
protected function element(string $name): \DOMElement
{
if (\strpos($name, ':') !== false)
{
$keys = explode(':', $name);
return $this->document()->createElementNS(
$this->namespaces[$this->options()->getNamespace() . ':' . \current($keys)],
$name
);
}
return $this->createElement($name);
}
|
php
|
protected function element(string $name): \DOMElement
{
if (\strpos($name, ':') !== false)
{
$keys = explode(':', $name);
return $this->document()->createElementNS(
$this->namespaces[$this->options()->getNamespace() . ':' . \current($keys)],
$name
);
}
return $this->createElement($name);
}
|
[
"protected",
"function",
"element",
"(",
"string",
"$",
"name",
")",
":",
"\\",
"DOMElement",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"name",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"':'",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"document",
"(",
")",
"->",
"createElementNS",
"(",
"$",
"this",
"->",
"namespaces",
"[",
"$",
"this",
"->",
"options",
"(",
")",
"->",
"getNamespace",
"(",
")",
".",
"':'",
".",
"\\",
"current",
"(",
"$",
"keys",
")",
"]",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createElement",
"(",
"$",
"name",
")",
";",
"}"
] |
@param string $name
@return \DOMElement
|
[
"@param",
"string",
"$name"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L108-L121
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader._property
|
protected function _property(\SimpleXMLElement $element, $property): array
{
$output = [];
if (\method_exists($element, $property)) {
$properties = $element->$property();
if ($properties) {
$data = \is_array($properties) ?
$properties : $this->_asArray($properties);
if ($data !== null || $data === '') {
$output['@' . $property] = $data;
}
}
}
return $output;
}
|
php
|
protected function _property(\SimpleXMLElement $element, $property): array
{
$output = [];
if (\method_exists($element, $property)) {
$properties = $element->$property();
if ($properties) {
$data = \is_array($properties) ?
$properties : $this->_asArray($properties);
if ($data !== null || $data === '') {
$output['@' . $property] = $data;
}
}
}
return $output;
}
|
[
"protected",
"function",
"_property",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
",",
"$",
"property",
")",
":",
"array",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"if",
"(",
"\\",
"method_exists",
"(",
"$",
"element",
",",
"$",
"property",
")",
")",
"{",
"$",
"properties",
"=",
"$",
"element",
"->",
"$",
"property",
"(",
")",
";",
"if",
"(",
"$",
"properties",
")",
"{",
"$",
"data",
"=",
"\\",
"is_array",
"(",
"$",
"properties",
")",
"?",
"$",
"properties",
":",
"$",
"this",
"->",
"_asArray",
"(",
"$",
"properties",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"null",
"||",
"$",
"data",
"===",
"''",
")",
"{",
"$",
"output",
"[",
"'@'",
".",
"$",
"property",
"]",
"=",
"$",
"data",
";",
"}",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] |
@param \SimpleXMLElement $element
@param string $property
@return array
|
[
"@param",
"\\",
"SimpleXMLElement",
"$element",
"@param",
"string",
"$property"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L129-L148
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader._asData
|
protected function _asData(\SimpleXMLElement $element)
{
$output = $this->_property($element, 'attributes');
if (!$element->count()) {
$output['@value'] = (string)$element;
if (!isset($output['@attributes'])) {
$output = $output['@value'];
}
}
return $output;
}
|
php
|
protected function _asData(\SimpleXMLElement $element)
{
$output = $this->_property($element, 'attributes');
if (!$element->count()) {
$output['@value'] = (string)$element;
if (!isset($output['@attributes'])) {
$output = $output['@value'];
}
}
return $output;
}
|
[
"protected",
"function",
"_asData",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"_property",
"(",
"$",
"element",
",",
"'attributes'",
")",
";",
"if",
"(",
"!",
"$",
"element",
"->",
"count",
"(",
")",
")",
"{",
"$",
"output",
"[",
"'@value'",
"]",
"=",
"(",
"string",
")",
"$",
"element",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"output",
"[",
"'@attributes'",
"]",
")",
")",
"{",
"$",
"output",
"=",
"$",
"output",
"[",
"'@value'",
"]",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] |
@param \SimpleXMLElement $element
@return array|string
@codeCoverageIgnore
|
[
"@param",
"\\",
"SimpleXMLElement",
"$element"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L157-L169
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader._asArray
|
protected function _asArray(\SimpleXMLElement $element)
{
$output = $this->_asData($element);
if (!$element->count()) {
return $output;
}
return $this->_pushArray($output, $element);
}
|
php
|
protected function _asArray(\SimpleXMLElement $element)
{
$output = $this->_asData($element);
if (!$element->count()) {
return $output;
}
return $this->_pushArray($output, $element);
}
|
[
"protected",
"function",
"_asArray",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"_asData",
"(",
"$",
"element",
")",
";",
"if",
"(",
"!",
"$",
"element",
"->",
"count",
"(",
")",
")",
"{",
"return",
"$",
"output",
";",
"}",
"return",
"$",
"this",
"->",
"_pushArray",
"(",
"$",
"output",
",",
"$",
"element",
")",
";",
"}"
] |
@param \SimpleXMLElement $element
@return array|string
@codeCoverageIgnore
|
[
"@param",
"\\",
"SimpleXMLElement",
"$element"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L178-L187
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader._pushArray
|
protected function _pushArray(array &$output, \SimpleXMLElement $element): array
{
$first = [];
/**
* @var \SimpleXMLElement $item
*/
foreach ($element as $key => $item)
{
if (!isset($output[$key])) {
$first[$key] = true;
$output[$key] = $this->_asArray($item);
continue;
}
if (!empty($first[$key])) {
$output[$key] = [$output[$key]];
}
$output[$key][] = $this->_asArray($item);
$first[$key] = false;
}
return $output;
}
|
php
|
protected function _pushArray(array &$output, \SimpleXMLElement $element): array
{
$first = [];
/**
* @var \SimpleXMLElement $item
*/
foreach ($element as $key => $item)
{
if (!isset($output[$key])) {
$first[$key] = true;
$output[$key] = $this->_asArray($item);
continue;
}
if (!empty($first[$key])) {
$output[$key] = [$output[$key]];
}
$output[$key][] = $this->_asArray($item);
$first[$key] = false;
}
return $output;
}
|
[
"protected",
"function",
"_pushArray",
"(",
"array",
"&",
"$",
"output",
",",
"\\",
"SimpleXMLElement",
"$",
"element",
")",
":",
"array",
"{",
"$",
"first",
"=",
"[",
"]",
";",
"/**\n * @var \\SimpleXMLElement $item\n */",
"foreach",
"(",
"$",
"element",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"output",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"first",
"[",
"$",
"key",
"]",
"=",
"true",
";",
"$",
"output",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"_asArray",
"(",
"$",
"item",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"first",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"output",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"output",
"[",
"$",
"key",
"]",
"]",
";",
"}",
"$",
"output",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_asArray",
"(",
"$",
"item",
")",
";",
"$",
"first",
"[",
"$",
"key",
"]",
"=",
"false",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
@param array $output
@param \SimpleXMLElement $element
@return array
@codeCoverageIgnore
|
[
"@param",
"array",
"$output",
"@param",
"\\",
"SimpleXMLElement",
"$element"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L197-L221
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader._simpleXml
|
protected function _simpleXml($mixed): \SimpleXMLElement
{
if ($mixed instanceof \DOMNode) {
return \simplexml_import_dom($mixed);
}
if (File::isFile($mixed))
{
$mixed = \file_get_contents($mixed);
}
return \simplexml_load_string($mixed);
}
|
php
|
protected function _simpleXml($mixed): \SimpleXMLElement
{
if ($mixed instanceof \DOMNode) {
return \simplexml_import_dom($mixed);
}
if (File::isFile($mixed))
{
$mixed = \file_get_contents($mixed);
}
return \simplexml_load_string($mixed);
}
|
[
"protected",
"function",
"_simpleXml",
"(",
"$",
"mixed",
")",
":",
"\\",
"SimpleXMLElement",
"{",
"if",
"(",
"$",
"mixed",
"instanceof",
"\\",
"DOMNode",
")",
"{",
"return",
"\\",
"simplexml_import_dom",
"(",
"$",
"mixed",
")",
";",
"}",
"if",
"(",
"File",
"::",
"isFile",
"(",
"$",
"mixed",
")",
")",
"{",
"$",
"mixed",
"=",
"\\",
"file_get_contents",
"(",
"$",
"mixed",
")",
";",
"}",
"return",
"\\",
"simplexml_load_string",
"(",
"$",
"mixed",
")",
";",
"}"
] |
@param string|\DOMNode $mixed
@return \SimpleXMLElement
@codeCoverageIgnore
|
[
"@param",
"string|",
"\\",
"DOMNode",
"$mixed"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L230-L242
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.asArray
|
public function asArray($mixed): ?array
{
$data = $this->_simpleXml($mixed);
return $data ? $this->_asArray($data) : null;
}
|
php
|
public function asArray($mixed): ?array
{
$data = $this->_simpleXml($mixed);
return $data ? $this->_asArray($data) : null;
}
|
[
"public",
"function",
"asArray",
"(",
"$",
"mixed",
")",
":",
"?",
"array",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_simpleXml",
"(",
"$",
"mixed",
")",
";",
"return",
"$",
"data",
"?",
"$",
"this",
"->",
"_asArray",
"(",
"$",
"data",
")",
":",
"null",
";",
"}"
] |
@param string|\DOMNode $mixed
@return array|null
|
[
"@param",
"string|",
"\\",
"DOMNode",
"$mixed"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L249-L253
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.asXML
|
public function asXML($storage, string $name = null, array $attributes = []): string
{
$storage = $this->fragments($storage);
$element = $this->element($name ?? $this->options()->getRootName());
$this->addAttributes($element, $attributes);
$this->document()->appendChild($element);
$this->convert($element, $this->_convertStorage($storage));
$xml = $this->document()->saveXML();
$this->document = null;
return $xml;
}
|
php
|
public function asXML($storage, string $name = null, array $attributes = []): string
{
$storage = $this->fragments($storage);
$element = $this->element($name ?? $this->options()->getRootName());
$this->addAttributes($element, $attributes);
$this->document()->appendChild($element);
$this->convert($element, $this->_convertStorage($storage));
$xml = $this->document()->saveXML();
$this->document = null;
return $xml;
}
|
[
"public",
"function",
"asXML",
"(",
"$",
"storage",
",",
"string",
"$",
"name",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"fragments",
"(",
"$",
"storage",
")",
";",
"$",
"element",
"=",
"$",
"this",
"->",
"element",
"(",
"$",
"name",
"??",
"$",
"this",
"->",
"options",
"(",
")",
"->",
"getRootName",
"(",
")",
")",
";",
"$",
"this",
"->",
"addAttributes",
"(",
"$",
"element",
",",
"$",
"attributes",
")",
";",
"$",
"this",
"->",
"document",
"(",
")",
"->",
"appendChild",
"(",
"$",
"element",
")",
";",
"$",
"this",
"->",
"convert",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"_convertStorage",
"(",
"$",
"storage",
")",
")",
";",
"$",
"xml",
"=",
"$",
"this",
"->",
"document",
"(",
")",
"->",
"saveXML",
"(",
")",
";",
"$",
"this",
"->",
"document",
"=",
"null",
";",
"return",
"$",
"xml",
";",
"}"
] |
@param array|\Traversable $storage
@param string $name
@param array $attributes
@return string
|
[
"@param",
"array|",
"\\",
"Traversable",
"$storage",
"@param",
"string",
"$name",
"@param",
"array",
"$attributes"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L286-L299
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.convert
|
protected function convert(DOMElement $element, $storage): void
{
if (\is_object($storage)) {
$element->appendChild($element->ownerDocument->importNode($storage));
return;
}
if (!\is_array($storage)) {
$element->nodeValue = \htmlspecialchars($storage);
return;
}
if (empty($storage)) {
throw new Exceptions\Blank('Array is empty');
}
$isInt = Arr::map(Arr::getKeys($storage), '\is_int');
$sequential = !Arr::in($isInt, false);
foreach ($storage as $key => $data) {
if ($sequential) {
$this->sequential($element, $data);
continue;
}
$this->addNodeWithKey($key, $element, $data);
}
}
|
php
|
protected function convert(DOMElement $element, $storage): void
{
if (\is_object($storage)) {
$element->appendChild($element->ownerDocument->importNode($storage));
return;
}
if (!\is_array($storage)) {
$element->nodeValue = \htmlspecialchars($storage);
return;
}
if (empty($storage)) {
throw new Exceptions\Blank('Array is empty');
}
$isInt = Arr::map(Arr::getKeys($storage), '\is_int');
$sequential = !Arr::in($isInt, false);
foreach ($storage as $key => $data) {
if ($sequential) {
$this->sequential($element, $data);
continue;
}
$this->addNodeWithKey($key, $element, $data);
}
}
|
[
"protected",
"function",
"convert",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"storage",
")",
":",
"void",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"storage",
")",
")",
"{",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"element",
"->",
"ownerDocument",
"->",
"importNode",
"(",
"$",
"storage",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"storage",
")",
")",
"{",
"$",
"element",
"->",
"nodeValue",
"=",
"\\",
"htmlspecialchars",
"(",
"$",
"storage",
")",
";",
"return",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"storage",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"Blank",
"(",
"'Array is empty'",
")",
";",
"}",
"$",
"isInt",
"=",
"Arr",
"::",
"map",
"(",
"Arr",
"::",
"getKeys",
"(",
"$",
"storage",
")",
",",
"'\\is_int'",
")",
";",
"$",
"sequential",
"=",
"!",
"Arr",
"::",
"in",
"(",
"$",
"isInt",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"storage",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"sequential",
")",
"{",
"$",
"this",
"->",
"sequential",
"(",
"$",
"element",
",",
"$",
"data",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"addNodeWithKey",
"(",
"$",
"key",
",",
"$",
"element",
",",
"$",
"data",
")",
";",
"}",
"}"
] |
@param DOMElement $element
@param mixed $storage
@throws Exceptions\Blank
@codeCoverageIgnore
|
[
"@param",
"DOMElement",
"$element",
"@param",
"mixed",
"$storage"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L309-L336
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.addNodeWithKey
|
protected function addNodeWithKey($key, DOMElement $element, $storage): void
{
if ($key === '@attributes') {
$this->addAttributes($element, $storage);
return;
}
if ($key === '@value') {
if (\is_string($storage)) {
$element->nodeValue = $storage;
return;
}
$dom = new \DOMDocument();
$fragment = $element->ownerDocument->createDocumentFragment();
$dom->loadXML(static::toXml($storage, 'root', $this->namespaces));
/**
* @var $childNode \DOMText
*/
foreach ($dom->firstChild->childNodes as $childNode) {
$fragment->appendXML($childNode->ownerDocument->saveXML($childNode));
}
$element->appendChild($fragment);
return;
}
$this->addNode($element, $key, $storage);
}
|
php
|
protected function addNodeWithKey($key, DOMElement $element, $storage): void
{
if ($key === '@attributes') {
$this->addAttributes($element, $storage);
return;
}
if ($key === '@value') {
if (\is_string($storage)) {
$element->nodeValue = $storage;
return;
}
$dom = new \DOMDocument();
$fragment = $element->ownerDocument->createDocumentFragment();
$dom->loadXML(static::toXml($storage, 'root', $this->namespaces));
/**
* @var $childNode \DOMText
*/
foreach ($dom->firstChild->childNodes as $childNode) {
$fragment->appendXML($childNode->ownerDocument->saveXML($childNode));
}
$element->appendChild($fragment);
return;
}
$this->addNode($element, $key, $storage);
}
|
[
"protected",
"function",
"addNodeWithKey",
"(",
"$",
"key",
",",
"DOMElement",
"$",
"element",
",",
"$",
"storage",
")",
":",
"void",
"{",
"if",
"(",
"$",
"key",
"===",
"'@attributes'",
")",
"{",
"$",
"this",
"->",
"addAttributes",
"(",
"$",
"element",
",",
"$",
"storage",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"key",
"===",
"'@value'",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"storage",
")",
")",
"{",
"$",
"element",
"->",
"nodeValue",
"=",
"$",
"storage",
";",
"return",
";",
"}",
"$",
"dom",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"fragment",
"=",
"$",
"element",
"->",
"ownerDocument",
"->",
"createDocumentFragment",
"(",
")",
";",
"$",
"dom",
"->",
"loadXML",
"(",
"static",
"::",
"toXml",
"(",
"$",
"storage",
",",
"'root'",
",",
"$",
"this",
"->",
"namespaces",
")",
")",
";",
"/**\n * @var $childNode \\DOMText\n */",
"foreach",
"(",
"$",
"dom",
"->",
"firstChild",
"->",
"childNodes",
"as",
"$",
"childNode",
")",
"{",
"$",
"fragment",
"->",
"appendXML",
"(",
"$",
"childNode",
"->",
"ownerDocument",
"->",
"saveXML",
"(",
"$",
"childNode",
")",
")",
";",
"}",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"fragment",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"addNode",
"(",
"$",
"element",
",",
"$",
"key",
",",
"$",
"storage",
")",
";",
"}"
] |
@param string $key
@param DOMElement $element
@param mixed $storage
@codeCoverageIgnore
|
[
"@param",
"string",
"$key",
"@param",
"DOMElement",
"$element",
"@param",
"mixed",
"$storage"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L360-L390
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.sequential
|
protected function sequential(DOMElement $element, $storage): void
{
if (\is_array($storage)) {
$this->addCollectionNode($element, $storage);
return;
}
$this->addSequentialNode($element, $storage);
}
|
php
|
protected function sequential(DOMElement $element, $storage): void
{
if (\is_array($storage)) {
$this->addCollectionNode($element, $storage);
return;
}
$this->addSequentialNode($element, $storage);
}
|
[
"protected",
"function",
"sequential",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"storage",
")",
":",
"void",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"storage",
")",
")",
"{",
"$",
"this",
"->",
"addCollectionNode",
"(",
"$",
"element",
",",
"$",
"storage",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"addSequentialNode",
"(",
"$",
"element",
",",
"$",
"storage",
")",
";",
"}"
] |
@param DOMElement $element
@param mixed $storage
@codeCoverageIgnore
|
[
"@param",
"DOMElement",
"$element",
"@param",
"mixed",
"$storage"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L398-L406
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.addNode
|
protected function addNode(DOMElement $element, $key, $value): void
{
$key = \str_replace(' ', '-', $key);
$child = $this->element($key);
$element->appendChild($child);
$this->convert($child, $value);
}
|
php
|
protected function addNode(DOMElement $element, $key, $value): void
{
$key = \str_replace(' ', '-', $key);
$child = $this->element($key);
$element->appendChild($child);
$this->convert($child, $value);
}
|
[
"protected",
"function",
"addNode",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"key",
",",
"$",
"value",
")",
":",
"void",
"{",
"$",
"key",
"=",
"\\",
"str_replace",
"(",
"' '",
",",
"'-'",
",",
"$",
"key",
")",
";",
"$",
"child",
"=",
"$",
"this",
"->",
"element",
"(",
"$",
"key",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"$",
"this",
"->",
"convert",
"(",
"$",
"child",
",",
"$",
"value",
")",
";",
"}"
] |
@param DOMElement $element
@param string $key
@param mixed $value
@throws Exceptions\Blank
@codeCoverageIgnore
|
[
"@param",
"DOMElement",
"$element",
"@param",
"string",
"$key",
"@param",
"mixed",
"$value"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L417-L423
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.addCollectionNode
|
protected function addCollectionNode(DOMElement $element, $value): void
{
if ($element->childNodes->length === 0) {
$this->convert($element, $value);
return;
}
/**
* @var $child DOMElement
*/
$child = $this->element($element->nodeName);
$element->parentNode->appendChild($child);
$this->convert($child, $value);
}
|
php
|
protected function addCollectionNode(DOMElement $element, $value): void
{
if ($element->childNodes->length === 0) {
$this->convert($element, $value);
return;
}
/**
* @var $child DOMElement
*/
$child = $this->element($element->nodeName);
$element->parentNode->appendChild($child);
$this->convert($child, $value);
}
|
[
"protected",
"function",
"addCollectionNode",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"$",
"element",
"->",
"childNodes",
"->",
"length",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"convert",
"(",
"$",
"element",
",",
"$",
"value",
")",
";",
"return",
";",
"}",
"/**\n * @var $child DOMElement\n */",
"$",
"child",
"=",
"$",
"this",
"->",
"element",
"(",
"$",
"element",
"->",
"nodeName",
")",
";",
"$",
"element",
"->",
"parentNode",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"$",
"this",
"->",
"convert",
"(",
"$",
"child",
",",
"$",
"value",
")",
";",
"}"
] |
@param DOMElement $element
@param mixed $value
@throws Exceptions\Blank
@codeCoverageIgnore
|
[
"@param",
"DOMElement",
"$element",
"@param",
"mixed",
"$value"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L433-L446
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.addSequentialNode
|
protected function addSequentialNode(DOMElement $element, $value): void
{
if (empty($element->nodeValue)) {
$element->nodeValue = \htmlspecialchars($value);
return;
}
$child = $this->element($element->nodeName);
$child->nodeValue = \htmlspecialchars($value);
$element->parentNode->appendChild($child);
}
|
php
|
protected function addSequentialNode(DOMElement $element, $value): void
{
if (empty($element->nodeValue)) {
$element->nodeValue = \htmlspecialchars($value);
return;
}
$child = $this->element($element->nodeName);
$child->nodeValue = \htmlspecialchars($value);
$element->parentNode->appendChild($child);
}
|
[
"protected",
"function",
"addSequentialNode",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"empty",
"(",
"$",
"element",
"->",
"nodeValue",
")",
")",
"{",
"$",
"element",
"->",
"nodeValue",
"=",
"\\",
"htmlspecialchars",
"(",
"$",
"value",
")",
";",
"return",
";",
"}",
"$",
"child",
"=",
"$",
"this",
"->",
"element",
"(",
"$",
"element",
"->",
"nodeName",
")",
";",
"$",
"child",
"->",
"nodeValue",
"=",
"\\",
"htmlspecialchars",
"(",
"$",
"value",
")",
";",
"$",
"element",
"->",
"parentNode",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}"
] |
@param DOMElement $element
@param mixed $value
@codeCoverageIgnore
|
[
"@param",
"DOMElement",
"$element",
"@param",
"mixed",
"$value"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L454-L464
|
bavix/xml
|
src/XMLReader/XMLReader.php
|
XMLReader.addAttributes
|
protected function addAttributes(DOMElement $element, $storage): void
{
foreach ($storage as $attrKey => $attrVal) {
if (strpos($attrKey, ':') !== false) {
$this->namespaces[$attrKey] = $attrVal;
}
$element->setAttribute($attrKey, $attrVal);
}
}
|
php
|
protected function addAttributes(DOMElement $element, $storage): void
{
foreach ($storage as $attrKey => $attrVal) {
if (strpos($attrKey, ':') !== false) {
$this->namespaces[$attrKey] = $attrVal;
}
$element->setAttribute($attrKey, $attrVal);
}
}
|
[
"protected",
"function",
"addAttributes",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"storage",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"storage",
"as",
"$",
"attrKey",
"=>",
"$",
"attrVal",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"attrKey",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"namespaces",
"[",
"$",
"attrKey",
"]",
"=",
"$",
"attrVal",
";",
"}",
"$",
"element",
"->",
"setAttribute",
"(",
"$",
"attrKey",
",",
"$",
"attrVal",
")",
";",
"}",
"}"
] |
@param DOMElement $element
@param array|\Traversable $storage
@codeCoverageIgnore
|
[
"@param",
"DOMElement",
"$element",
"@param",
"array|",
"\\",
"Traversable",
"$storage"
] |
train
|
https://github.com/bavix/xml/blob/c329f16863260e7fd822d2d8b24ee47426f8224d/src/XMLReader/XMLReader.php#L472-L481
|
devture/dbal
|
src/Devture/Component/DBAL/Repository/BaseRepository.php
|
BaseRepository.createModel
|
public function createModel(array $data) {
if (!isset($data['_id'])) {
return $this->hydrateModel($data);
}
$id = (string) $data['_id'];
if (!isset($this->models[$id])) {
$this->models[$id] = $this->hydrateModel($data);
}
return $this->models[$id];
}
|
php
|
public function createModel(array $data) {
if (!isset($data['_id'])) {
return $this->hydrateModel($data);
}
$id = (string) $data['_id'];
if (!isset($this->models[$id])) {
$this->models[$id] = $this->hydrateModel($data);
}
return $this->models[$id];
}
|
[
"public",
"function",
"createModel",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"hydrateModel",
"(",
"$",
"data",
")",
";",
"}",
"$",
"id",
"=",
"(",
"string",
")",
"$",
"data",
"[",
"'_id'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"models",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"models",
"[",
"$",
"id",
"]",
"=",
"$",
"this",
"->",
"hydrateModel",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"models",
"[",
"$",
"id",
"]",
";",
"}"
] |
Creates a new model from the data the first time it's called.
If called subsequently for the same id, it will return a reference to the first
object, no matter what $data contains this run.
@see \Devture\Component\DBAL\Repository\RepositoryInterface::createModel()
@param array $data
@return BaseModel
|
[
"Creates",
"a",
"new",
"model",
"from",
"the",
"data",
"the",
"first",
"time",
"it",
"s",
"called",
".",
"If",
"called",
"subsequently",
"for",
"the",
"same",
"id",
"it",
"will",
"return",
"a",
"reference",
"to",
"the",
"first",
"object",
"no",
"matter",
"what",
"$data",
"contains",
"this",
"run",
"."
] |
train
|
https://github.com/devture/dbal/blob/e2538d13baf9220fc388a48596acd176cd2bb42f/src/Devture/Component/DBAL/Repository/BaseRepository.php#L21-L31
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.newUserModel
|
protected function newUserModel($username, $password, array $options = [])
{
$user = new User();
$user->username = $username;
$user->password = $password;
foreach ($options as $key => $value) {
$user->{$key} = $value;
}
return $user;
}
|
php
|
protected function newUserModel($username, $password, array $options = [])
{
$user = new User();
$user->username = $username;
$user->password = $password;
foreach ($options as $key => $value) {
$user->{$key} = $value;
}
return $user;
}
|
[
"protected",
"function",
"newUserModel",
"(",
"$",
"username",
",",
"$",
"password",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"user",
"=",
"new",
"User",
"(",
")",
";",
"$",
"user",
"->",
"username",
"=",
"$",
"username",
";",
"$",
"user",
"->",
"password",
"=",
"$",
"password",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"user",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"user",
";",
"}"
] |
Create new user model instance
@param string $username
@param string $password
@param array $options
@return \ViKon\Auth\Model\User
|
[
"Create",
"new",
"user",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L28-L39
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.createUserModel
|
protected function createUserModel($username, $password, array $options = [])
{
$user = $this->newUserModel($username, $password, $options);
$user->save();
return $user;
}
|
php
|
protected function createUserModel($username, $password, array $options = [])
{
$user = $this->newUserModel($username, $password, $options);
$user->save();
return $user;
}
|
[
"protected",
"function",
"createUserModel",
"(",
"$",
"username",
",",
"$",
"password",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"newUserModel",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"options",
")",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"return",
"$",
"user",
";",
"}"
] |
Create and store in database new user model instance
@param string $username
@param string $password
@param array $options
@return \ViKon\Auth\Model\User
|
[
"Create",
"and",
"store",
"in",
"database",
"new",
"user",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L50-L56
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.createUserRecord
|
protected function createUserRecord($username, $password, array $options = [])
{
return [
// Username
User::FIELD_USERNAME => $username,
// Password
User::FIELD_PASSWORD => bcrypt($password),
// Email
User::FIELD_EMAIL => array_key_exists(User::FIELD_EMAIL, $options)
? $options[User::FIELD_EMAIL]
: $username . '@local . com',
// Home
User::FIELD_HOME => array_key_exists(User::FIELD_HOME, $options)
? $options[User::FIELD_HOME]
: null,
// Is blocked
User::FIELD_BLOCKED => array_key_exists(User::FIELD_BLOCKED, $options)
? $options[User::FIELD_BLOCKED]
: false,
// Is static
User::FIELD_STATIC => array_key_exists(User::FIELD_STATIC, $options)
? $options[User::FIELD_STATIC]
: false,
// Is hidden
User::FIELD_HIDDEN => array_key_exists(User::FIELD_HIDDEN, $options)
? $options[User::FIELD_HIDDEN]
: false,
];
}
|
php
|
protected function createUserRecord($username, $password, array $options = [])
{
return [
// Username
User::FIELD_USERNAME => $username,
// Password
User::FIELD_PASSWORD => bcrypt($password),
// Email
User::FIELD_EMAIL => array_key_exists(User::FIELD_EMAIL, $options)
? $options[User::FIELD_EMAIL]
: $username . '@local . com',
// Home
User::FIELD_HOME => array_key_exists(User::FIELD_HOME, $options)
? $options[User::FIELD_HOME]
: null,
// Is blocked
User::FIELD_BLOCKED => array_key_exists(User::FIELD_BLOCKED, $options)
? $options[User::FIELD_BLOCKED]
: false,
// Is static
User::FIELD_STATIC => array_key_exists(User::FIELD_STATIC, $options)
? $options[User::FIELD_STATIC]
: false,
// Is hidden
User::FIELD_HIDDEN => array_key_exists(User::FIELD_HIDDEN, $options)
? $options[User::FIELD_HIDDEN]
: false,
];
}
|
[
"protected",
"function",
"createUserRecord",
"(",
"$",
"username",
",",
"$",
"password",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"[",
"// Username",
"User",
"::",
"FIELD_USERNAME",
"=>",
"$",
"username",
",",
"// Password",
"User",
"::",
"FIELD_PASSWORD",
"=>",
"bcrypt",
"(",
"$",
"password",
")",
",",
"// Email",
"User",
"::",
"FIELD_EMAIL",
"=>",
"array_key_exists",
"(",
"User",
"::",
"FIELD_EMAIL",
",",
"$",
"options",
")",
"?",
"$",
"options",
"[",
"User",
"::",
"FIELD_EMAIL",
"]",
":",
"$",
"username",
".",
"'@local . com'",
",",
"// Home",
"User",
"::",
"FIELD_HOME",
"=>",
"array_key_exists",
"(",
"User",
"::",
"FIELD_HOME",
",",
"$",
"options",
")",
"?",
"$",
"options",
"[",
"User",
"::",
"FIELD_HOME",
"]",
":",
"null",
",",
"// Is blocked",
"User",
"::",
"FIELD_BLOCKED",
"=>",
"array_key_exists",
"(",
"User",
"::",
"FIELD_BLOCKED",
",",
"$",
"options",
")",
"?",
"$",
"options",
"[",
"User",
"::",
"FIELD_BLOCKED",
"]",
":",
"false",
",",
"// Is static",
"User",
"::",
"FIELD_STATIC",
"=>",
"array_key_exists",
"(",
"User",
"::",
"FIELD_STATIC",
",",
"$",
"options",
")",
"?",
"$",
"options",
"[",
"User",
"::",
"FIELD_STATIC",
"]",
":",
"false",
",",
"// Is hidden",
"User",
"::",
"FIELD_HIDDEN",
"=>",
"array_key_exists",
"(",
"User",
"::",
"FIELD_HIDDEN",
",",
"$",
"options",
")",
"?",
"$",
"options",
"[",
"User",
"::",
"FIELD_HIDDEN",
"]",
":",
"false",
",",
"]",
";",
"}"
] |
Create single user record
@param string $username authentication username
@param string $password authentication password
@param array $options additional column values
@return array array with user field values
|
[
"Create",
"single",
"user",
"record"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L67-L95
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.newGroupModel
|
protected function newGroupModel($token, array $options = [])
{
$group = new Group();
$group->token = $token;
foreach ($options as $key => $value) {
$group->{$key} = $value;
}
return $group;
}
|
php
|
protected function newGroupModel($token, array $options = [])
{
$group = new Group();
$group->token = $token;
foreach ($options as $key => $value) {
$group->{$key} = $value;
}
return $group;
}
|
[
"protected",
"function",
"newGroupModel",
"(",
"$",
"token",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"group",
"=",
"new",
"Group",
"(",
")",
";",
"$",
"group",
"->",
"token",
"=",
"$",
"token",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"group",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"group",
";",
"}"
] |
Create new group model instance
@param string $token group token
@param array $options additional column valuesF
@return \ViKon\Auth\Model\Group
|
[
"Create",
"new",
"group",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L105-L115
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.createGroupModel
|
protected function createGroupModel($token, array $options = [])
{
$group = $this->newGroupModel($token, $options);
$group->save();
return $group;
}
|
php
|
protected function createGroupModel($token, array $options = [])
{
$group = $this->newGroupModel($token, $options);
$group->save();
return $group;
}
|
[
"protected",
"function",
"createGroupModel",
"(",
"$",
"token",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"newGroupModel",
"(",
"$",
"token",
",",
"$",
"options",
")",
";",
"$",
"group",
"->",
"save",
"(",
")",
";",
"return",
"$",
"group",
";",
"}"
] |
Create and store in database new group model instance
@param string $token group token
@param array $options additional column values
@return \ViKon\Auth\Model\Group
|
[
"Create",
"and",
"store",
"in",
"database",
"new",
"group",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L125-L131
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.newRoleModel
|
protected function newRoleModel($token, array $options = [])
{
$role = new Role();
$role->token = $token;
foreach ($options as $key => $value) {
$role->{$key} = $value;
}
return $role;
}
|
php
|
protected function newRoleModel($token, array $options = [])
{
$role = new Role();
$role->token = $token;
foreach ($options as $key => $value) {
$role->{$key} = $value;
}
return $role;
}
|
[
"protected",
"function",
"newRoleModel",
"(",
"$",
"token",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"role",
"=",
"new",
"Role",
"(",
")",
";",
"$",
"role",
"->",
"token",
"=",
"$",
"token",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"role",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"role",
";",
"}"
] |
Create new role model instance
@param string $token role token
@param array $options additional column valuesF
@return \ViKon\Auth\Model\Role
|
[
"Create",
"new",
"role",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L141-L151
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.createRoleModel
|
protected function createRoleModel($token, array $options = [])
{
$role = $this->newRoleModel($token, $options);
$role->save();
return $role;
}
|
php
|
protected function createRoleModel($token, array $options = [])
{
$role = $this->newRoleModel($token, $options);
$role->save();
return $role;
}
|
[
"protected",
"function",
"createRoleModel",
"(",
"$",
"token",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"newRoleModel",
"(",
"$",
"token",
",",
"$",
"options",
")",
";",
"$",
"role",
"->",
"save",
"(",
")",
";",
"return",
"$",
"role",
";",
"}"
] |
Create and store in database new role model instance
@param string $token role token
@param array $options additional column values
@return \ViKon\Auth\Model\Role
|
[
"Create",
"and",
"store",
"in",
"database",
"new",
"role",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L161-L167
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.newPermissionModel
|
protected function newPermissionModel($token, array $options = [])
{
$permission = new Permission();
$permission->token = $token;
foreach ($options as $key => $value) {
$permission->{$key} = $value;
}
return $permission;
}
|
php
|
protected function newPermissionModel($token, array $options = [])
{
$permission = new Permission();
$permission->token = $token;
foreach ($options as $key => $value) {
$permission->{$key} = $value;
}
return $permission;
}
|
[
"protected",
"function",
"newPermissionModel",
"(",
"$",
"token",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"permission",
"=",
"new",
"Permission",
"(",
")",
";",
"$",
"permission",
"->",
"token",
"=",
"$",
"token",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"permission",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"permission",
";",
"}"
] |
Create new permission model instance
@param string $token
@param array $options
@return \ViKon\Auth\Model\Permission
|
[
"Create",
"new",
"permission",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L177-L187
|
vi-kon/laravel-auth
|
src/ViKon/Auth/AuthSeederTrait.php
|
AuthSeederTrait.createPermissionModel
|
protected function createPermissionModel($token, array $options = [])
{
$permission = $this->newPermissionModel($token, $options);
$permission->save();
return $permission;
}
|
php
|
protected function createPermissionModel($token, array $options = [])
{
$permission = $this->newPermissionModel($token, $options);
$permission->save();
return $permission;
}
|
[
"protected",
"function",
"createPermissionModel",
"(",
"$",
"token",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"permission",
"=",
"$",
"this",
"->",
"newPermissionModel",
"(",
"$",
"token",
",",
"$",
"options",
")",
";",
"$",
"permission",
"->",
"save",
"(",
")",
";",
"return",
"$",
"permission",
";",
"}"
] |
Create and store in database new permission model instance
@param string $token
@param array $options
@return \ViKon\Auth\Model\Permission
|
[
"Create",
"and",
"store",
"in",
"database",
"new",
"permission",
"model",
"instance"
] |
train
|
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthSeederTrait.php#L197-L203
|
webforge-labs/psc-cms
|
lib/Psc/Code/Compile/AddPropertyExtension.php
|
AddPropertyExtension.compile
|
public function compile(GClass $gClass, $flags = 0x000000) {
// das ist okay, wenn man getters oder setters oder den constructor adden will (imo)
//if ($gClass->hasProperty($this->property->name)) {
// throw new \InvalidArgumentException('Property: '.$this->property->name. ' besteht bereits in Klasse '.$gClass);
//}
$this->createClassBuilder($gClass);
$this->cProperty = $this->classBuilder->addProperty($this->property->name, $this->property->type);
if ($this->property->upcaseName) {
$this->cProperty->setUpcaseName($this->property->upcaseName);
}
if ($this->generateSetter) {
$this->classBuilder->generateSetter($this->cProperty, NULL, ClassBuilder::INHERIT);
}
if ($this->generateGetter) {
$this->classBuilder->generateGetter($this->cProperty, NULL, ClassBuilder::INHERIT);
}
if (($cs = $this->generateInConstructor) !== FALSE) {
$constructor = $this->classBuilder->getConstructor(TRUE);
if (!$constructor->hasParameter($this->property->name)) {
$parameter = new GParameter($this->property->name,
$this->property->type ? $this->property->type->getPHPHint() : NULL,
$this->constructorDefaultValue
);
$constructor->addParameter($parameter, $this->generateInConstructor);
if ($this->dependencyInjection === self::DEPENDENCY_INJECTION_CONSTRUCTOR) {
if (!($this->property->type instanceof ObjectType) || !$this->property->type->hasClass()) {
throw new \InvalidArgumentException('Wenn DependencyInjection CONSTRUCTOR ist, muss der property-type ein ObjectType sein mit einer Klasse. Type ist: '.Code::varInfo($this->property->type));
}
$objectValue = new Expression(sprintf('$%s ?: new %s()', $parameter->getName(), $this->property->type->getGClass()->getClassName()));
} else {
$objectValue = new AST\Variable($parameter->getName(), new AST\LType('Mixed'));
}
$constructor->appendBodyLines(array(
$this->codeWriter->callSetter(
new AST\Variable('this', new AST\LType('Object')),
$this->cProperty->getUpcaseName(),
$objectValue
).';'
)
);
}
}
$this->classBuilder->generateDocBlocks();
return $gClass;
}
|
php
|
public function compile(GClass $gClass, $flags = 0x000000) {
// das ist okay, wenn man getters oder setters oder den constructor adden will (imo)
//if ($gClass->hasProperty($this->property->name)) {
// throw new \InvalidArgumentException('Property: '.$this->property->name. ' besteht bereits in Klasse '.$gClass);
//}
$this->createClassBuilder($gClass);
$this->cProperty = $this->classBuilder->addProperty($this->property->name, $this->property->type);
if ($this->property->upcaseName) {
$this->cProperty->setUpcaseName($this->property->upcaseName);
}
if ($this->generateSetter) {
$this->classBuilder->generateSetter($this->cProperty, NULL, ClassBuilder::INHERIT);
}
if ($this->generateGetter) {
$this->classBuilder->generateGetter($this->cProperty, NULL, ClassBuilder::INHERIT);
}
if (($cs = $this->generateInConstructor) !== FALSE) {
$constructor = $this->classBuilder->getConstructor(TRUE);
if (!$constructor->hasParameter($this->property->name)) {
$parameter = new GParameter($this->property->name,
$this->property->type ? $this->property->type->getPHPHint() : NULL,
$this->constructorDefaultValue
);
$constructor->addParameter($parameter, $this->generateInConstructor);
if ($this->dependencyInjection === self::DEPENDENCY_INJECTION_CONSTRUCTOR) {
if (!($this->property->type instanceof ObjectType) || !$this->property->type->hasClass()) {
throw new \InvalidArgumentException('Wenn DependencyInjection CONSTRUCTOR ist, muss der property-type ein ObjectType sein mit einer Klasse. Type ist: '.Code::varInfo($this->property->type));
}
$objectValue = new Expression(sprintf('$%s ?: new %s()', $parameter->getName(), $this->property->type->getGClass()->getClassName()));
} else {
$objectValue = new AST\Variable($parameter->getName(), new AST\LType('Mixed'));
}
$constructor->appendBodyLines(array(
$this->codeWriter->callSetter(
new AST\Variable('this', new AST\LType('Object')),
$this->cProperty->getUpcaseName(),
$objectValue
).';'
)
);
}
}
$this->classBuilder->generateDocBlocks();
return $gClass;
}
|
[
"public",
"function",
"compile",
"(",
"GClass",
"$",
"gClass",
",",
"$",
"flags",
"=",
"0x000000",
")",
"{",
"// das ist okay, wenn man getters oder setters oder den constructor adden will (imo)",
"//if ($gClass->hasProperty($this->property->name)) {",
"// throw new \\InvalidArgumentException('Property: '.$this->property->name. ' besteht bereits in Klasse '.$gClass);",
"//}",
"$",
"this",
"->",
"createClassBuilder",
"(",
"$",
"gClass",
")",
";",
"$",
"this",
"->",
"cProperty",
"=",
"$",
"this",
"->",
"classBuilder",
"->",
"addProperty",
"(",
"$",
"this",
"->",
"property",
"->",
"name",
",",
"$",
"this",
"->",
"property",
"->",
"type",
")",
";",
"if",
"(",
"$",
"this",
"->",
"property",
"->",
"upcaseName",
")",
"{",
"$",
"this",
"->",
"cProperty",
"->",
"setUpcaseName",
"(",
"$",
"this",
"->",
"property",
"->",
"upcaseName",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"generateSetter",
")",
"{",
"$",
"this",
"->",
"classBuilder",
"->",
"generateSetter",
"(",
"$",
"this",
"->",
"cProperty",
",",
"NULL",
",",
"ClassBuilder",
"::",
"INHERIT",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"generateGetter",
")",
"{",
"$",
"this",
"->",
"classBuilder",
"->",
"generateGetter",
"(",
"$",
"this",
"->",
"cProperty",
",",
"NULL",
",",
"ClassBuilder",
"::",
"INHERIT",
")",
";",
"}",
"if",
"(",
"(",
"$",
"cs",
"=",
"$",
"this",
"->",
"generateInConstructor",
")",
"!==",
"FALSE",
")",
"{",
"$",
"constructor",
"=",
"$",
"this",
"->",
"classBuilder",
"->",
"getConstructor",
"(",
"TRUE",
")",
";",
"if",
"(",
"!",
"$",
"constructor",
"->",
"hasParameter",
"(",
"$",
"this",
"->",
"property",
"->",
"name",
")",
")",
"{",
"$",
"parameter",
"=",
"new",
"GParameter",
"(",
"$",
"this",
"->",
"property",
"->",
"name",
",",
"$",
"this",
"->",
"property",
"->",
"type",
"?",
"$",
"this",
"->",
"property",
"->",
"type",
"->",
"getPHPHint",
"(",
")",
":",
"NULL",
",",
"$",
"this",
"->",
"constructorDefaultValue",
")",
";",
"$",
"constructor",
"->",
"addParameter",
"(",
"$",
"parameter",
",",
"$",
"this",
"->",
"generateInConstructor",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dependencyInjection",
"===",
"self",
"::",
"DEPENDENCY_INJECTION_CONSTRUCTOR",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"property",
"->",
"type",
"instanceof",
"ObjectType",
")",
"||",
"!",
"$",
"this",
"->",
"property",
"->",
"type",
"->",
"hasClass",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Wenn DependencyInjection CONSTRUCTOR ist, muss der property-type ein ObjectType sein mit einer Klasse. Type ist: '",
".",
"Code",
"::",
"varInfo",
"(",
"$",
"this",
"->",
"property",
"->",
"type",
")",
")",
";",
"}",
"$",
"objectValue",
"=",
"new",
"Expression",
"(",
"sprintf",
"(",
"'$%s ?: new %s()'",
",",
"$",
"parameter",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"property",
"->",
"type",
"->",
"getGClass",
"(",
")",
"->",
"getClassName",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"objectValue",
"=",
"new",
"AST",
"\\",
"Variable",
"(",
"$",
"parameter",
"->",
"getName",
"(",
")",
",",
"new",
"AST",
"\\",
"LType",
"(",
"'Mixed'",
")",
")",
";",
"}",
"$",
"constructor",
"->",
"appendBodyLines",
"(",
"array",
"(",
"$",
"this",
"->",
"codeWriter",
"->",
"callSetter",
"(",
"new",
"AST",
"\\",
"Variable",
"(",
"'this'",
",",
"new",
"AST",
"\\",
"LType",
"(",
"'Object'",
")",
")",
",",
"$",
"this",
"->",
"cProperty",
"->",
"getUpcaseName",
"(",
")",
",",
"$",
"objectValue",
")",
".",
"';'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"classBuilder",
"->",
"generateDocBlocks",
"(",
")",
";",
"return",
"$",
"gClass",
";",
"}"
] |
Fügt ein Property hinzu
added das Property, seine Setter und gegebenfalls auch einen Eintrag im Constructor
|
[
"Fügt",
"ein",
"Property",
"hinzu"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/Compile/AddPropertyExtension.php#L68-L123
|
inpsyde/inpsyde-filter
|
src/WordPress/EscHtml.php
|
EscHtml.filter
|
public function filter( $value ) {
if ( ! is_scalar( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not scalar or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return esc_html( (string) $value );
}
|
php
|
public function filter( $value ) {
if ( ! is_scalar( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not scalar or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return esc_html( (string) $value );
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"do_action",
"(",
"'inpsyde.filter.error'",
",",
"'The given value is not scalar or empty.'",
",",
"[",
"'method'",
"=>",
"__METHOD__",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"return",
"$",
"value",
";",
"}",
"return",
"esc_html",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/EscHtml.php#L17-L26
|
webforge-labs/psc-cms
|
lib/Psc/TPL/TPL.php
|
TPL.get
|
public static function get($tpl, Array $__variablesDefinitions = NULL, $__indent = NULL) {
$tpl = new Template($tpl);
$tpl->setLanguage(Config::req('i18n.language'));
$tpl->setVars($__variablesDefinitions);
//if (FALSE) {
// print 'Variables for "'.$__templateName.'": '."\n";
// print_r($__variablesDefinitions);
// print "\n\n";
//}
return $tpl->get();
}
|
php
|
public static function get($tpl, Array $__variablesDefinitions = NULL, $__indent = NULL) {
$tpl = new Template($tpl);
$tpl->setLanguage(Config::req('i18n.language'));
$tpl->setVars($__variablesDefinitions);
//if (FALSE) {
// print 'Variables for "'.$__templateName.'": '."\n";
// print_r($__variablesDefinitions);
// print "\n\n";
//}
return $tpl->get();
}
|
[
"public",
"static",
"function",
"get",
"(",
"$",
"tpl",
",",
"Array",
"$",
"__variablesDefinitions",
"=",
"NULL",
",",
"$",
"__indent",
"=",
"NULL",
")",
"{",
"$",
"tpl",
"=",
"new",
"Template",
"(",
"$",
"tpl",
")",
";",
"$",
"tpl",
"->",
"setLanguage",
"(",
"Config",
"::",
"req",
"(",
"'i18n.language'",
")",
")",
";",
"$",
"tpl",
"->",
"setVars",
"(",
"$",
"__variablesDefinitions",
")",
";",
"//if (FALSE) {",
"// print 'Variables for \"'.$__templateName.'\": '.\"\\n\";",
"// print_r($__variablesDefinitions);",
"// print \"\\n\\n\";",
"//}",
"return",
"$",
"tpl",
"->",
"get",
"(",
")",
";",
"}"
] |
Inkludiert ein Template und gibt das HTML zurück
Das Template wird inkludiert und das ausgegebene HTML als String zurückgegeben.<br />
Nur die definierten Variablen in <var>$__variablesDefinitions</var> werden an das Template weitergereicht.<br />
Im Template werden Smarty ähmliche Variablen Bezeichner wie z.b. {$title} mit dem Inhalt der Variable als String umgewandelt ersetzt.
@param string $tpl der Name des templates wird zu tpl/<var>$__templateName</var>.php ergänzt wird als array mit unterverzeichnissen interpretiert
@param array $__variablesDefinitions die Variablen die ans Template übergeben werden sollen. Schlüssel sind die Variablen Bezeichner.
@return string
|
[
"Inkludiert",
"ein",
"Template",
"und",
"gibt",
"das",
"HTML",
"zurück"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/TPL/TPL.php#L29-L42
|
webforge-labs/psc-cms
|
lib/Psc/TPL/TPL.php
|
TPL.display
|
public static function display($tpl, $variablesDefinitions = NULL, $indent = NULL) {
$html = self::get($tpl, $variablesDefinitions, $indent);
print $html;
}
|
php
|
public static function display($tpl, $variablesDefinitions = NULL, $indent = NULL) {
$html = self::get($tpl, $variablesDefinitions, $indent);
print $html;
}
|
[
"public",
"static",
"function",
"display",
"(",
"$",
"tpl",
",",
"$",
"variablesDefinitions",
"=",
"NULL",
",",
"$",
"indent",
"=",
"NULL",
")",
"{",
"$",
"html",
"=",
"self",
"::",
"get",
"(",
"$",
"tpl",
",",
"$",
"variablesDefinitions",
",",
"$",
"indent",
")",
";",
"print",
"$",
"html",
";",
"}"
] |
Inkludiert ein Template
Gibt die Rückgabe von template_get aus.
@param mixed $tpl
@param array $variablesDefinitions
@param int $indent wie weit der Quelltext eingerückt werden soll
@see template_get
|
[
"Inkludiert",
"ein",
"Template"
] |
train
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/TPL/TPL.php#L53-L56
|
SURFnet/messagebird-api-client-bundle
|
src/Surfnet/MessageBirdApiClient/Messaging/MessagingService.php
|
MessagingService.send
|
public function send(Message $message)
{
$response = $this->guzzleClient->post('/messages', [
'json' => [
'originator' => $message->getOriginator(),
'recipients' => $message->getRecipient(),
'body' => $message->getBody(),
],
'http_errors' => false,
]);
try {
$document = JsonHelper::decode((string) $response->getBody());
} catch (\RuntimeException $e) {
throw new ApiRuntimeException('The MessageBird server did not return valid JSON.', [], $e);
}
if (isset($document['errors'])) {
$errors = $document['errors'];
} else {
$errors = [];
}
$statusCode = (int) $response->getStatusCode();
if (!in_array($statusCode, [200, 201, 204, 401, 404, 405, 422]) && !($statusCode >= 500 && $statusCode < 600)) {
throw new ApiRuntimeException(sprintf('Unexpected MessageBird server behaviour (HTTP %d)', $statusCode), $errors);
}
if (!isset($document['recipients']['items'][0]['status'])) {
$deliveryStatus = SendMessageResult::STATUS_NOT_SENT;
} else {
$deliveryStatus = $document['recipients']['items'][0]['status'];
}
return new SendMessageResult($deliveryStatus, $errors);
}
|
php
|
public function send(Message $message)
{
$response = $this->guzzleClient->post('/messages', [
'json' => [
'originator' => $message->getOriginator(),
'recipients' => $message->getRecipient(),
'body' => $message->getBody(),
],
'http_errors' => false,
]);
try {
$document = JsonHelper::decode((string) $response->getBody());
} catch (\RuntimeException $e) {
throw new ApiRuntimeException('The MessageBird server did not return valid JSON.', [], $e);
}
if (isset($document['errors'])) {
$errors = $document['errors'];
} else {
$errors = [];
}
$statusCode = (int) $response->getStatusCode();
if (!in_array($statusCode, [200, 201, 204, 401, 404, 405, 422]) && !($statusCode >= 500 && $statusCode < 600)) {
throw new ApiRuntimeException(sprintf('Unexpected MessageBird server behaviour (HTTP %d)', $statusCode), $errors);
}
if (!isset($document['recipients']['items'][0]['status'])) {
$deliveryStatus = SendMessageResult::STATUS_NOT_SENT;
} else {
$deliveryStatus = $document['recipients']['items'][0]['status'];
}
return new SendMessageResult($deliveryStatus, $errors);
}
|
[
"public",
"function",
"send",
"(",
"Message",
"$",
"message",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"post",
"(",
"'/messages'",
",",
"[",
"'json'",
"=>",
"[",
"'originator'",
"=>",
"$",
"message",
"->",
"getOriginator",
"(",
")",
",",
"'recipients'",
"=>",
"$",
"message",
"->",
"getRecipient",
"(",
")",
",",
"'body'",
"=>",
"$",
"message",
"->",
"getBody",
"(",
")",
",",
"]",
",",
"'http_errors'",
"=>",
"false",
",",
"]",
")",
";",
"try",
"{",
"$",
"document",
"=",
"JsonHelper",
"::",
"decode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"RuntimeException",
"$",
"e",
")",
"{",
"throw",
"new",
"ApiRuntimeException",
"(",
"'The MessageBird server did not return valid JSON.'",
",",
"[",
"]",
",",
"$",
"e",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"document",
"[",
"'errors'",
"]",
")",
")",
"{",
"$",
"errors",
"=",
"$",
"document",
"[",
"'errors'",
"]",
";",
"}",
"else",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"}",
"$",
"statusCode",
"=",
"(",
"int",
")",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"statusCode",
",",
"[",
"200",
",",
"201",
",",
"204",
",",
"401",
",",
"404",
",",
"405",
",",
"422",
"]",
")",
"&&",
"!",
"(",
"$",
"statusCode",
">=",
"500",
"&&",
"$",
"statusCode",
"<",
"600",
")",
")",
"{",
"throw",
"new",
"ApiRuntimeException",
"(",
"sprintf",
"(",
"'Unexpected MessageBird server behaviour (HTTP %d)'",
",",
"$",
"statusCode",
")",
",",
"$",
"errors",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"document",
"[",
"'recipients'",
"]",
"[",
"'items'",
"]",
"[",
"0",
"]",
"[",
"'status'",
"]",
")",
")",
"{",
"$",
"deliveryStatus",
"=",
"SendMessageResult",
"::",
"STATUS_NOT_SENT",
";",
"}",
"else",
"{",
"$",
"deliveryStatus",
"=",
"$",
"document",
"[",
"'recipients'",
"]",
"[",
"'items'",
"]",
"[",
"0",
"]",
"[",
"'status'",
"]",
";",
"}",
"return",
"new",
"SendMessageResult",
"(",
"$",
"deliveryStatus",
",",
"$",
"errors",
")",
";",
"}"
] |
@param Message $message
@return SendMessageResult
@throws ApiRuntimeException
@throws TransferException Thrown by Guzzle during communication failure or unexpected server behaviour.
|
[
"@param",
"Message",
"$message",
"@return",
"SendMessageResult"
] |
train
|
https://github.com/SURFnet/messagebird-api-client-bundle/blob/50f3bc942f3313e218c54270b64fc23cbcd768c4/src/Surfnet/MessageBirdApiClient/Messaging/MessagingService.php#L50-L86
|
cohesion/cohesion-core
|
src/Config/Config.php
|
Config.load
|
public function load($data, $key = null) {
if ($key) {
if (isset($this->data[$key])) {
$this->data[$key] = self::array_merge_recursive_unique($this->data[$key], $data);
} else {
$this->data[$key] = $data;
}
} else {
if (is_array($data)) {
$this->data = self::array_merge_recursive_unique($this->data, $data);
}
}
}
|
php
|
public function load($data, $key = null) {
if ($key) {
if (isset($this->data[$key])) {
$this->data[$key] = self::array_merge_recursive_unique($this->data[$key], $data);
} else {
$this->data[$key] = $data;
}
} else {
if (is_array($data)) {
$this->data = self::array_merge_recursive_unique($this->data, $data);
}
}
}
|
[
"public",
"function",
"load",
"(",
"$",
"data",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"array_merge_recursive_unique",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"self",
"::",
"array_merge_recursive_unique",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"data",
")",
";",
"}",
"}",
"}"
] |
Load from array
|
[
"Load",
"from",
"array"
] |
train
|
https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Config/Config.php#L45-L57
|
cohesion/cohesion-core
|
src/Config/Config.php
|
Config.add
|
public function add($key, $value) {
if (isset($this->data[$key])) {
throw new \InvalidArgumentException("Key $key is already set");
}
$this->data[$key] = $value;
}
|
php
|
public function add($key, $value) {
if (isset($this->data[$key])) {
throw new \InvalidArgumentException("Key $key is already set");
}
$this->data[$key] = $value;
}
|
[
"public",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Key $key is already set\"",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] |
Add a new key value pairing.
@throws InvalidArgumentException if the key is already set
|
[
"Add",
"a",
"new",
"key",
"value",
"pairing",
"."
] |
train
|
https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Config/Config.php#L64-L69
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.