repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
koolkode/http | src/HttpMessage.php | HttpMessage.determineHeaderTypeName | protected function determineHeaderTypeName(callable $callback)
{
if(is_array($callback))
{
$ref = new \ReflectionMethod(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], $callback[1]);
}
elseif(is_object($callback) && !$callback instanceof \Closure)
{
$ref = new \ReflectionMethod(get_class($callback), '__invoke');
}
else
{
$ref = new \ReflectionFunction($callback);
}
$params = $ref->getParameters();
if(empty($params))
{
throw new \InvalidArgumentException('Invalid header callback given, the callback must declare 1 argument');
}
$type = $params[0]->getClass();
if(!$type instanceof \ReflectionClass)
{
throw new \InvalidArgumentException('Invalid header callback given, no type hint for first argument');
}
if(!$type->implementsInterface(HttpHeaderInterface::class))
{
throw new \InvalidArgumentException(sprintf('Invalid header callback given, %s is not an HTTP header implementation', $type->getName()));
}
return $type->getName();
} | php | protected function determineHeaderTypeName(callable $callback)
{
if(is_array($callback))
{
$ref = new \ReflectionMethod(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], $callback[1]);
}
elseif(is_object($callback) && !$callback instanceof \Closure)
{
$ref = new \ReflectionMethod(get_class($callback), '__invoke');
}
else
{
$ref = new \ReflectionFunction($callback);
}
$params = $ref->getParameters();
if(empty($params))
{
throw new \InvalidArgumentException('Invalid header callback given, the callback must declare 1 argument');
}
$type = $params[0]->getClass();
if(!$type instanceof \ReflectionClass)
{
throw new \InvalidArgumentException('Invalid header callback given, no type hint for first argument');
}
if(!$type->implementsInterface(HttpHeaderInterface::class))
{
throw new \InvalidArgumentException(sprintf('Invalid header callback given, %s is not an HTTP header implementation', $type->getName()));
}
return $type->getName();
} | [
"protected",
"function",
"determineHeaderTypeName",
"(",
"callable",
"$",
"callback",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"is_object",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
"?",
"get_class",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
":",
"$",
"callback",
"[",
"0",
"]",
",",
"$",
"callback",
"[",
"1",
"]",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"callback",
")",
"&&",
"!",
"$",
"callback",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"get_class",
"(",
"$",
"callback",
")",
",",
"'__invoke'",
")",
";",
"}",
"else",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"callback",
")",
";",
"}",
"$",
"params",
"=",
"$",
"ref",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid header callback given, the callback must declare 1 argument'",
")",
";",
"}",
"$",
"type",
"=",
"$",
"params",
"[",
"0",
"]",
"->",
"getClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"type",
"instanceof",
"\\",
"ReflectionClass",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid header callback given, no type hint for first argument'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"type",
"->",
"implementsInterface",
"(",
"HttpHeaderInterface",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid header callback given, %s is not an HTTP header implementation'",
",",
"$",
"type",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"type",
"->",
"getName",
"(",
")",
";",
"}"
] | Extract meta info of the first argument to the given callback and determine an HTTP header
implementation to be used.
@param callable $callback
@return string
@throws \InvalidArgumentException when the given callback does not specify a valid HTTP header argument. | [
"Extract",
"meta",
"info",
"of",
"the",
"first",
"argument",
"to",
"the",
"given",
"callback",
"and",
"determine",
"an",
"HTTP",
"header",
"implementation",
"to",
"be",
"used",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpMessage.php#L307-L342 | train |
koolkode/http | src/HttpMessage.php | HttpMessage.setEntity | public function setEntity($entity, $prepare = true)
{
if($entity instanceof EntityInterface)
{
$this->entity = $entity;
}
elseif(is_resource($entity) || $entity instanceof StreamInterface)
{
$this->entity = new StreamEntity($entity);
}
elseif((is_array($entity) || is_object($entity)) && is_callable($entity))
{
$this->entity = new CallbackEntity($entity);
}
else
{
$this->entity = new StringEntity($entity);
}
if($prepare)
{
$this->entity->prepare($this);
}
return $this;
} | php | public function setEntity($entity, $prepare = true)
{
if($entity instanceof EntityInterface)
{
$this->entity = $entity;
}
elseif(is_resource($entity) || $entity instanceof StreamInterface)
{
$this->entity = new StreamEntity($entity);
}
elseif((is_array($entity) || is_object($entity)) && is_callable($entity))
{
$this->entity = new CallbackEntity($entity);
}
else
{
$this->entity = new StringEntity($entity);
}
if($prepare)
{
$this->entity->prepare($this);
}
return $this;
} | [
"public",
"function",
"setEntity",
"(",
"$",
"entity",
",",
"$",
"prepare",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"entity",
"instanceof",
"EntityInterface",
")",
"{",
"$",
"this",
"->",
"entity",
"=",
"$",
"entity",
";",
"}",
"elseif",
"(",
"is_resource",
"(",
"$",
"entity",
")",
"||",
"$",
"entity",
"instanceof",
"StreamInterface",
")",
"{",
"$",
"this",
"->",
"entity",
"=",
"new",
"StreamEntity",
"(",
"$",
"entity",
")",
";",
"}",
"elseif",
"(",
"(",
"is_array",
"(",
"$",
"entity",
")",
"||",
"is_object",
"(",
"$",
"entity",
")",
")",
"&&",
"is_callable",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"this",
"->",
"entity",
"=",
"new",
"CallbackEntity",
"(",
"$",
"entity",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"entity",
"=",
"new",
"StringEntity",
"(",
"$",
"entity",
")",
";",
"}",
"if",
"(",
"$",
"prepare",
")",
"{",
"$",
"this",
"->",
"entity",
"->",
"prepare",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Convert the given argument into an HTTP entity and put it in the nessage.
@param mixed $entity
@param boolean $prepare Have the entity inject Content-Type etc. into the HTTP message?
@return HttpMessage | [
"Convert",
"the",
"given",
"argument",
"into",
"an",
"HTTP",
"entity",
"and",
"put",
"it",
"in",
"the",
"nessage",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpMessage.php#L411-L436 | train |
bkstg/schedule-bundle | Timeline/Spread/InvitedSpread.php | InvitedSpread.resolveClass | private function resolveClass($object)
{
if (!$object instanceof Proxy) {
return get_class($object);
}
// If this is a proxy resolve using class metadata.
return $this
->em
->getClassMetadata(get_class($object))
->getReflectionClass()
->getName();
} | php | private function resolveClass($object)
{
if (!$object instanceof Proxy) {
return get_class($object);
}
// If this is a proxy resolve using class metadata.
return $this
->em
->getClassMetadata(get_class($object))
->getReflectionClass()
->getName();
} | [
"private",
"function",
"resolveClass",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"Proxy",
")",
"{",
"return",
"get_class",
"(",
"$",
"object",
")",
";",
"}",
"// If this is a proxy resolve using class metadata.",
"return",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"object",
")",
")",
"->",
"getReflectionClass",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}"
] | Figure out the real class for this object.
@param mixed $object The object.
@return string | [
"Figure",
"out",
"the",
"real",
"class",
"for",
"this",
"object",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Timeline/Spread/InvitedSpread.php#L73-L85 | train |
gplcart/cli | controllers/commands/Module.php | Module.cmdUninstallModule | public function cmdUninstallModule()
{
$result = $this->module_model->uninstall($this->getParam(0));
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | php | public function cmdUninstallModule()
{
$result = $this->module_model->uninstall($this->getParam(0));
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | [
"public",
"function",
"cmdUninstallModule",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"module_model",
"->",
"uninstall",
"(",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"true",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"result",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "module-uninstall" command | [
"Callback",
"for",
"module",
"-",
"uninstall",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Module.php#L49-L58 | train |
gplcart/cli | controllers/commands/Module.php | Module.cmdInstallModule | public function cmdInstallModule()
{
$result = $this->module_model->install($this->getParam(0));
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | php | public function cmdInstallModule()
{
$result = $this->module_model->install($this->getParam(0));
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | [
"public",
"function",
"cmdInstallModule",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"module_model",
"->",
"install",
"(",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"true",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"result",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "module-install" command | [
"Callback",
"for",
"module",
"-",
"install",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Module.php#L63-L72 | train |
gplcart/cli | controllers/commands/Module.php | Module.cmdOffModule | public function cmdOffModule()
{
$id = $this->getParam(0);
if (empty($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->module_model->disable($id);
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | php | public function cmdOffModule()
{
$id = $this->getParam(0);
if (empty($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->module_model->disable($id);
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | [
"public",
"function",
"cmdOffModule",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"module_model",
"->",
"disable",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"true",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"result",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "module-off" command | [
"Callback",
"for",
"module",
"-",
"off",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Module.php#L77-L92 | train |
gplcart/cli | controllers/commands/Module.php | Module.cmdOnModule | public function cmdOnModule()
{
$id = $this->getParam(0);
if (empty($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->module_model->enable($id);
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | php | public function cmdOnModule()
{
$id = $this->getParam(0);
if (empty($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->module_model->enable($id);
if ($result !== true) {
$this->errorAndExit($result);
}
$this->output();
} | [
"public",
"function",
"cmdOnModule",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"module_model",
"->",
"enable",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"true",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"result",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "module-on" command | [
"Callback",
"for",
"module",
"-",
"on",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Module.php#L97-L112 | train |
gplcart/cli | controllers/commands/Module.php | Module.cmdGetModule | public function cmdGetModule()
{
$result = $this->getListModule();
$this->outputFormat($result);
$this->outputFormatTableModule($result);
$this->output();
} | php | public function cmdGetModule()
{
$result = $this->getListModule();
$this->outputFormat($result);
$this->outputFormatTableModule($result);
$this->output();
} | [
"public",
"function",
"cmdGetModule",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListModule",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableModule",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "module-get" command | [
"Callback",
"for",
"module",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Module.php#L117-L123 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/HttpRemoteRequest.php | HttpRemoteRequest.dispatch | public function dispatch($ignoreErrors = true, $timeout = null) {
if (!isset($this->headers)) {
$this->headers = array();
}
if (!isset($this->headers["Content-Type"]))
$this->headers["Content-Type"] = "application/json";
// If we have an auth username and password, use it.
if ($this->authUsername && $this->authPassword) {
$this->headers["Authorization"] = "Basic " . base64_encode($this->authUsername . ":" . $this->authPassword);
}
$headers = array();
foreach ($this->headers as $key => $header) {
$headers[] = $key . ": " . $header;
}
if (is_array($this->parameters))
$queryParams = http_build_query($this->parameters);
if ($this->payload) {
$payload = $this->payload;
} else {
$payload = null;
}
$paramsAsGet = $payload || $this->method == "GET";
$contentData = $payload ? $payload : ($paramsAsGet ? array() : $queryParams);
$options = array('http' => array('header' => $headers, 'method' => $this->method,
'content' => $contentData, 'ignore_errors' => $ignoreErrors));
$url = $this->url;
if ($paramsAsGet && sizeof($this->parameters) > 0) {
$url .= "?" . $queryParams;
}
if ($timeout) {
$options["timeout"] = $timeout;
}
$context = stream_context_create($options);
$results = file_get_contents($url, false, $context);
$responseCode = explode(" ", $http_response_header[0])[1];
if ($responseCode >= 400) {
throw new HttpRequestErrorException($url, $responseCode, $results);
}
return $results;
} | php | public function dispatch($ignoreErrors = true, $timeout = null) {
if (!isset($this->headers)) {
$this->headers = array();
}
if (!isset($this->headers["Content-Type"]))
$this->headers["Content-Type"] = "application/json";
// If we have an auth username and password, use it.
if ($this->authUsername && $this->authPassword) {
$this->headers["Authorization"] = "Basic " . base64_encode($this->authUsername . ":" . $this->authPassword);
}
$headers = array();
foreach ($this->headers as $key => $header) {
$headers[] = $key . ": " . $header;
}
if (is_array($this->parameters))
$queryParams = http_build_query($this->parameters);
if ($this->payload) {
$payload = $this->payload;
} else {
$payload = null;
}
$paramsAsGet = $payload || $this->method == "GET";
$contentData = $payload ? $payload : ($paramsAsGet ? array() : $queryParams);
$options = array('http' => array('header' => $headers, 'method' => $this->method,
'content' => $contentData, 'ignore_errors' => $ignoreErrors));
$url = $this->url;
if ($paramsAsGet && sizeof($this->parameters) > 0) {
$url .= "?" . $queryParams;
}
if ($timeout) {
$options["timeout"] = $timeout;
}
$context = stream_context_create($options);
$results = file_get_contents($url, false, $context);
$responseCode = explode(" ", $http_response_header[0])[1];
if ($responseCode >= 400) {
throw new HttpRequestErrorException($url, $responseCode, $results);
}
return $results;
} | [
"public",
"function",
"dispatch",
"(",
"$",
"ignoreErrors",
"=",
"true",
",",
"$",
"timeout",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Type\"",
"]",
")",
")",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Type\"",
"]",
"=",
"\"application/json\"",
";",
"// If we have an auth username and password, use it.",
"if",
"(",
"$",
"this",
"->",
"authUsername",
"&&",
"$",
"this",
"->",
"authPassword",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"\"Authorization\"",
"]",
"=",
"\"Basic \"",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"authUsername",
".",
"\":\"",
".",
"$",
"this",
"->",
"authPassword",
")",
";",
"}",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"key",
"=>",
"$",
"header",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"$",
"key",
".",
"\": \"",
".",
"$",
"header",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"parameters",
")",
")",
"$",
"queryParams",
"=",
"http_build_query",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"if",
"(",
"$",
"this",
"->",
"payload",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"payload",
";",
"}",
"else",
"{",
"$",
"payload",
"=",
"null",
";",
"}",
"$",
"paramsAsGet",
"=",
"$",
"payload",
"||",
"$",
"this",
"->",
"method",
"==",
"\"GET\"",
";",
"$",
"contentData",
"=",
"$",
"payload",
"?",
"$",
"payload",
":",
"(",
"$",
"paramsAsGet",
"?",
"array",
"(",
")",
":",
"$",
"queryParams",
")",
";",
"$",
"options",
"=",
"array",
"(",
"'http'",
"=>",
"array",
"(",
"'header'",
"=>",
"$",
"headers",
",",
"'method'",
"=>",
"$",
"this",
"->",
"method",
",",
"'content'",
"=>",
"$",
"contentData",
",",
"'ignore_errors'",
"=>",
"$",
"ignoreErrors",
")",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
";",
"if",
"(",
"$",
"paramsAsGet",
"&&",
"sizeof",
"(",
"$",
"this",
"->",
"parameters",
")",
">",
"0",
")",
"{",
"$",
"url",
".=",
"\"?\"",
".",
"$",
"queryParams",
";",
"}",
"if",
"(",
"$",
"timeout",
")",
"{",
"$",
"options",
"[",
"\"timeout\"",
"]",
"=",
"$",
"timeout",
";",
"}",
"$",
"context",
"=",
"stream_context_create",
"(",
"$",
"options",
")",
";",
"$",
"results",
"=",
"file_get_contents",
"(",
"$",
"url",
",",
"false",
",",
"$",
"context",
")",
";",
"$",
"responseCode",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"http_response_header",
"[",
"0",
"]",
")",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"responseCode",
">=",
"400",
")",
"{",
"throw",
"new",
"HttpRequestErrorException",
"(",
"$",
"url",
",",
"$",
"responseCode",
",",
"$",
"results",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Dispatch the request and collect the result.
@return string | [
"Dispatch",
"the",
"request",
"and",
"collect",
"the",
"result",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/HttpRemoteRequest.php#L50-L106 | train |
koolkode/xml | src/XmlStreamReader.php | XmlStreamReader.getNamespaceMappings | public function getNamespaceMappings()
{
$dom = (new XmlDocumentBuilder())->buildDocument($this);
$xpath = new \DOMXPath($dom);
$namespaces = [];
foreach($xpath->query('namespace::*', $dom->documentElement) as $result)
{
$namespaces[(string)$result->prefix] = (string)$result->nodeValue;
}
return $namespaces;
} | php | public function getNamespaceMappings()
{
$dom = (new XmlDocumentBuilder())->buildDocument($this);
$xpath = new \DOMXPath($dom);
$namespaces = [];
foreach($xpath->query('namespace::*', $dom->documentElement) as $result)
{
$namespaces[(string)$result->prefix] = (string)$result->nodeValue;
}
return $namespaces;
} | [
"public",
"function",
"getNamespaceMappings",
"(",
")",
"{",
"$",
"dom",
"=",
"(",
"new",
"XmlDocumentBuilder",
"(",
")",
")",
"->",
"buildDocument",
"(",
"$",
"this",
")",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"dom",
")",
";",
"$",
"namespaces",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"xpath",
"->",
"query",
"(",
"'namespace::*'",
",",
"$",
"dom",
"->",
"documentElement",
")",
"as",
"$",
"result",
")",
"{",
"$",
"namespaces",
"[",
"(",
"string",
")",
"$",
"result",
"->",
"prefix",
"]",
"=",
"(",
"string",
")",
"$",
"result",
"->",
"nodeValue",
";",
"}",
"return",
"$",
"namespaces",
";",
"}"
] | Get a map of namespaces prefix - URI mappings of the current node, prefixes are keys.
@return array<string, string> | [
"Get",
"a",
"map",
"of",
"namespaces",
"prefix",
"-",
"URI",
"mappings",
"of",
"the",
"current",
"node",
"prefixes",
"are",
"keys",
"."
] | 0ce43b8f56c692dee9f05bb740c2b5f4f419176a | https://github.com/koolkode/xml/blob/0ce43b8f56c692dee9f05bb740c2b5f4f419176a/src/XmlStreamReader.php#L162-L175 | train |
Dhii/placeholder-template | src/AbstractBasePlaceholderTemplateFactory.php | AbstractBasePlaceholderTemplateFactory._make | protected function _make($config = null)
{
$productClassname = $this->_normalizeString($this->_getProductClassname());
if (!$this->_classExists($productClassname)) {
throw $this->_createOutOfRangeException($this->__('Class "%1$s" does not exist', [$productClassname]), null, null, $productClassname);
}
$template = $this->_containerGet($config, TemplateFactoryInterface::K_TEMPLATE);
return new $productClassname($template, $this->_getTokenStart(), $this->_getTokenEnd(), $this->_getDefaultPlaceholderValue());
} | php | protected function _make($config = null)
{
$productClassname = $this->_normalizeString($this->_getProductClassname());
if (!$this->_classExists($productClassname)) {
throw $this->_createOutOfRangeException($this->__('Class "%1$s" does not exist', [$productClassname]), null, null, $productClassname);
}
$template = $this->_containerGet($config, TemplateFactoryInterface::K_TEMPLATE);
return new $productClassname($template, $this->_getTokenStart(), $this->_getTokenEnd(), $this->_getDefaultPlaceholderValue());
} | [
"protected",
"function",
"_make",
"(",
"$",
"config",
"=",
"null",
")",
"{",
"$",
"productClassname",
"=",
"$",
"this",
"->",
"_normalizeString",
"(",
"$",
"this",
"->",
"_getProductClassname",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_classExists",
"(",
"$",
"productClassname",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"_createOutOfRangeException",
"(",
"$",
"this",
"->",
"__",
"(",
"'Class \"%1$s\" does not exist'",
",",
"[",
"$",
"productClassname",
"]",
")",
",",
"null",
",",
"null",
",",
"$",
"productClassname",
")",
";",
"}",
"$",
"template",
"=",
"$",
"this",
"->",
"_containerGet",
"(",
"$",
"config",
",",
"TemplateFactoryInterface",
"::",
"K_TEMPLATE",
")",
";",
"return",
"new",
"$",
"productClassname",
"(",
"$",
"template",
",",
"$",
"this",
"->",
"_getTokenStart",
"(",
")",
",",
"$",
"this",
"->",
"_getTokenEnd",
"(",
")",
",",
"$",
"this",
"->",
"_getDefaultPlaceholderValue",
"(",
")",
")",
";",
"}"
] | Creates a new instance of a placeholder template.
@since [*next-version*]
@param array|ArrayAccess|BaseContainerInterface|stdClass|null $config The make config.
@throws InvalidArgumentException If product classname is not a valid type.
@throws OutOfRangeException If class that the factory is trying to make does not exist.
@throws ContainerExceptionInterface If one of the required config keys cannot be accessed.
@throws RootException For other problems.
@return TemplateInterface The new template instance. | [
"Creates",
"a",
"new",
"instance",
"of",
"a",
"placeholder",
"template",
"."
] | ab6eb2f98b085dfdf22cf86fd243cd7e6ee68525 | https://github.com/Dhii/placeholder-template/blob/ab6eb2f98b085dfdf22cf86fd243cd7e6ee68525/src/AbstractBasePlaceholderTemplateFactory.php#L68-L78 | train |
wasinger/adaptimage | src/ImagineFilter/FixOrientation.php | FixOrientation.apply | public function apply(ImageInterface $image)
{
// 1 2 3 4 5 6 7 8
//
// 888888 888888 88 88 8888888888 88 88 8888888888
// 88 88 88 88 88 88 88 88 88 88 88 88
// 8888 8888 8888 8888 88 8888888888 8888888888 88
// 88 88 88 88
// 88 88 888888 888888
switch ($this->orientation) {
case 2:
$image->flipHorizontally();
break;
case 3:
$image->rotate(180);
break;
case 4:
$image->flipVertically();
break;
case 5:
$image->rotate(90)->flipHorizontally();
break;
case 6:
$image->rotate(90);
break;
case 7:
$image->rotate(-90)->flipHorizontally();
break;
case 8:
$image->rotate(-90);
break;
default:
break;
}
// after rotating the image, we need to reset orientation in Exif data to 1
if ($image instanceof \Imagine\Imagick\Image) {
$image->getImagick()->setImageOrientation(1);
} else {
// TODO: how can this be done in GD and Gmagick?
// Workaround: delete all metadata
$image->strip();
}
return $image;
} | php | public function apply(ImageInterface $image)
{
// 1 2 3 4 5 6 7 8
//
// 888888 888888 88 88 8888888888 88 88 8888888888
// 88 88 88 88 88 88 88 88 88 88 88 88
// 8888 8888 8888 8888 88 8888888888 8888888888 88
// 88 88 88 88
// 88 88 888888 888888
switch ($this->orientation) {
case 2:
$image->flipHorizontally();
break;
case 3:
$image->rotate(180);
break;
case 4:
$image->flipVertically();
break;
case 5:
$image->rotate(90)->flipHorizontally();
break;
case 6:
$image->rotate(90);
break;
case 7:
$image->rotate(-90)->flipHorizontally();
break;
case 8:
$image->rotate(-90);
break;
default:
break;
}
// after rotating the image, we need to reset orientation in Exif data to 1
if ($image instanceof \Imagine\Imagick\Image) {
$image->getImagick()->setImageOrientation(1);
} else {
// TODO: how can this be done in GD and Gmagick?
// Workaround: delete all metadata
$image->strip();
}
return $image;
} | [
"public",
"function",
"apply",
"(",
"ImageInterface",
"$",
"image",
")",
"{",
"// 1 2 3 4 5 6 7 8",
"//",
"// 888888 888888 88 88 8888888888 88 88 8888888888",
"// 88 88 88 88 88 88 88 88 88 88 88 88",
"// 8888 8888 8888 8888 88 8888888888 8888888888 88",
"// 88 88 88 88",
"// 88 88 888888 888888",
"switch",
"(",
"$",
"this",
"->",
"orientation",
")",
"{",
"case",
"2",
":",
"$",
"image",
"->",
"flipHorizontally",
"(",
")",
";",
"break",
";",
"case",
"3",
":",
"$",
"image",
"->",
"rotate",
"(",
"180",
")",
";",
"break",
";",
"case",
"4",
":",
"$",
"image",
"->",
"flipVertically",
"(",
")",
";",
"break",
";",
"case",
"5",
":",
"$",
"image",
"->",
"rotate",
"(",
"90",
")",
"->",
"flipHorizontally",
"(",
")",
";",
"break",
";",
"case",
"6",
":",
"$",
"image",
"->",
"rotate",
"(",
"90",
")",
";",
"break",
";",
"case",
"7",
":",
"$",
"image",
"->",
"rotate",
"(",
"-",
"90",
")",
"->",
"flipHorizontally",
"(",
")",
";",
"break",
";",
"case",
"8",
":",
"$",
"image",
"->",
"rotate",
"(",
"-",
"90",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"// after rotating the image, we need to reset orientation in Exif data to 1",
"if",
"(",
"$",
"image",
"instanceof",
"\\",
"Imagine",
"\\",
"Imagick",
"\\",
"Image",
")",
"{",
"$",
"image",
"->",
"getImagick",
"(",
")",
"->",
"setImageOrientation",
"(",
"1",
")",
";",
"}",
"else",
"{",
"// TODO: how can this be done in GD and Gmagick?",
"// Workaround: delete all metadata",
"$",
"image",
"->",
"strip",
"(",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Applies scheduled transformation to ImageInterface instance
Returns processed ImageInterface instance
@param ImageInterface $image
@return ImageInterface | [
"Applies",
"scheduled",
"transformation",
"to",
"ImageInterface",
"instance",
"Returns",
"processed",
"ImageInterface",
"instance"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ImagineFilter/FixOrientation.php#L26-L73 | train |
danielgp/common-lib | source/MySQLiByDanielGPtables.php | MySQLiByDanielGPtables.getFieldOutputNumeric | private function getFieldOutputNumeric($tblSrc, $value, $iar = [])
{
if ($value['EXTRA'] == 'auto_increment') {
return $this->getFieldOutputNumericAI($value, $iar);
}
$fkArray = $this->getForeignKeysToArray($this->advCache['workingDatabase'], $tblSrc, $value['COLUMN_NAME']);
if ($fkArray === []) {
$fldNos = $this->setFieldNumbers($value);
return $this->getFieldOutputTT($value, min(50, (array_key_exists('l', $fldNos) ? $fldNos['l'] : 99)), $iar);
}
return $this->getFieldOutputNumericNonFK($fkArray, $value, $iar);
} | php | private function getFieldOutputNumeric($tblSrc, $value, $iar = [])
{
if ($value['EXTRA'] == 'auto_increment') {
return $this->getFieldOutputNumericAI($value, $iar);
}
$fkArray = $this->getForeignKeysToArray($this->advCache['workingDatabase'], $tblSrc, $value['COLUMN_NAME']);
if ($fkArray === []) {
$fldNos = $this->setFieldNumbers($value);
return $this->getFieldOutputTT($value, min(50, (array_key_exists('l', $fldNos) ? $fldNos['l'] : 99)), $iar);
}
return $this->getFieldOutputNumericNonFK($fkArray, $value, $iar);
} | [
"private",
"function",
"getFieldOutputNumeric",
"(",
"$",
"tblSrc",
",",
"$",
"value",
",",
"$",
"iar",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"value",
"[",
"'EXTRA'",
"]",
"==",
"'auto_increment'",
")",
"{",
"return",
"$",
"this",
"->",
"getFieldOutputNumericAI",
"(",
"$",
"value",
",",
"$",
"iar",
")",
";",
"}",
"$",
"fkArray",
"=",
"$",
"this",
"->",
"getForeignKeysToArray",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'workingDatabase'",
"]",
",",
"$",
"tblSrc",
",",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
")",
";",
"if",
"(",
"$",
"fkArray",
"===",
"[",
"]",
")",
"{",
"$",
"fldNos",
"=",
"$",
"this",
"->",
"setFieldNumbers",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
"->",
"getFieldOutputTT",
"(",
"$",
"value",
",",
"min",
"(",
"50",
",",
"(",
"array_key_exists",
"(",
"'l'",
",",
"$",
"fldNos",
")",
"?",
"$",
"fldNos",
"[",
"'l'",
"]",
":",
"99",
")",
")",
",",
"$",
"iar",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getFieldOutputNumericNonFK",
"(",
"$",
"fkArray",
",",
"$",
"value",
",",
"$",
"iar",
")",
";",
"}"
] | Returns a Numeric field 2 use in a form
@param string $tblSrc
@param array $value
@param array $iar
@return string | [
"Returns",
"a",
"Numeric",
"field",
"2",
"use",
"in",
"a",
"form"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtables.php#L49-L60 | train |
danielgp/common-lib | source/MySQLiByDanielGPtables.php | MySQLiByDanielGPtables.getFieldOutputNumericAI | private function getFieldOutputNumericAI($value, $iar = [])
{
if ($this->getFieldValue($value) == '') {
$spF = ['id' => $value['COLUMN_NAME'], 'style' => 'font-style:italic;'];
return $this->setStringIntoTag('auto-numar', 'span', $spF);
}
$inAdtnl = [
'type' => 'hidden',
'name' => $value['COLUMN_NAME'],
'id' => $value['COLUMN_NAME'],
'value' => $this->getFieldValue($value),
];
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
return '<b>' . $this->getFieldValue($value) . '</b>' . $this->setStringIntoShortTag('input', $inAdtnl);
} | php | private function getFieldOutputNumericAI($value, $iar = [])
{
if ($this->getFieldValue($value) == '') {
$spF = ['id' => $value['COLUMN_NAME'], 'style' => 'font-style:italic;'];
return $this->setStringIntoTag('auto-numar', 'span', $spF);
}
$inAdtnl = [
'type' => 'hidden',
'name' => $value['COLUMN_NAME'],
'id' => $value['COLUMN_NAME'],
'value' => $this->getFieldValue($value),
];
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
return '<b>' . $this->getFieldValue($value) . '</b>' . $this->setStringIntoShortTag('input', $inAdtnl);
} | [
"private",
"function",
"getFieldOutputNumericAI",
"(",
"$",
"value",
",",
"$",
"iar",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"value",
")",
"==",
"''",
")",
"{",
"$",
"spF",
"=",
"[",
"'id'",
"=>",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
",",
"'style'",
"=>",
"'font-style:italic;'",
"]",
";",
"return",
"$",
"this",
"->",
"setStringIntoTag",
"(",
"'auto-numar'",
",",
"'span'",
",",
"$",
"spF",
")",
";",
"}",
"$",
"inAdtnl",
"=",
"[",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
",",
"'id'",
"=>",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
",",
"'value'",
"=>",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"value",
")",
",",
"]",
";",
"if",
"(",
"$",
"iar",
"!==",
"[",
"]",
")",
"{",
"$",
"inAdtnl",
"=",
"array_merge",
"(",
"$",
"inAdtnl",
",",
"$",
"iar",
")",
";",
"}",
"return",
"'<b>'",
".",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"value",
")",
".",
"'</b>'",
".",
"$",
"this",
"->",
"setStringIntoShortTag",
"(",
"'input'",
",",
"$",
"inAdtnl",
")",
";",
"}"
] | Handles creation of Auto Increment numeric field type output
@param array $value
@param array $iar
@return string | [
"Handles",
"creation",
"of",
"Auto",
"Increment",
"numeric",
"field",
"type",
"output"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtables.php#L69-L85 | train |
danielgp/common-lib | source/MySQLiByDanielGPtables.php | MySQLiByDanielGPtables.getFieldOutputNumericNonFK | private function getFieldOutputNumericNonFK($fkArray, $value, $iar = [])
{
$query = $this->sQueryGenericSelectKeyValue([
'`' . $value['COLUMN_NAME'] . '`',
$fkArray[$value['COLUMN_NAME']][2],
$fkArray[$value['COLUMN_NAME']][0],
]);
$selectOptions = $this->setMySQLquery2Server($query, 'array_key_value')['result'];
$selectValue = $this->getFieldValue($value);
$inAdtnl = ['size' => 1];
if ($value['IS_NULLABLE'] == 'YES') {
$inAdtnl = array_merge($inAdtnl, ['include_null']);
}
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
return $this->setArrayToSelect($selectOptions, $selectValue, $value['COLUMN_NAME'], $inAdtnl);
} | php | private function getFieldOutputNumericNonFK($fkArray, $value, $iar = [])
{
$query = $this->sQueryGenericSelectKeyValue([
'`' . $value['COLUMN_NAME'] . '`',
$fkArray[$value['COLUMN_NAME']][2],
$fkArray[$value['COLUMN_NAME']][0],
]);
$selectOptions = $this->setMySQLquery2Server($query, 'array_key_value')['result'];
$selectValue = $this->getFieldValue($value);
$inAdtnl = ['size' => 1];
if ($value['IS_NULLABLE'] == 'YES') {
$inAdtnl = array_merge($inAdtnl, ['include_null']);
}
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
return $this->setArrayToSelect($selectOptions, $selectValue, $value['COLUMN_NAME'], $inAdtnl);
} | [
"private",
"function",
"getFieldOutputNumericNonFK",
"(",
"$",
"fkArray",
",",
"$",
"value",
",",
"$",
"iar",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"sQueryGenericSelectKeyValue",
"(",
"[",
"'`'",
".",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
".",
"'`'",
",",
"$",
"fkArray",
"[",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
"]",
"[",
"2",
"]",
",",
"$",
"fkArray",
"[",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
"]",
"[",
"0",
"]",
",",
"]",
")",
";",
"$",
"selectOptions",
"=",
"$",
"this",
"->",
"setMySQLquery2Server",
"(",
"$",
"query",
",",
"'array_key_value'",
")",
"[",
"'result'",
"]",
";",
"$",
"selectValue",
"=",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"value",
")",
";",
"$",
"inAdtnl",
"=",
"[",
"'size'",
"=>",
"1",
"]",
";",
"if",
"(",
"$",
"value",
"[",
"'IS_NULLABLE'",
"]",
"==",
"'YES'",
")",
"{",
"$",
"inAdtnl",
"=",
"array_merge",
"(",
"$",
"inAdtnl",
",",
"[",
"'include_null'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"iar",
"!==",
"[",
"]",
")",
"{",
"$",
"inAdtnl",
"=",
"array_merge",
"(",
"$",
"inAdtnl",
",",
"$",
"iar",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setArrayToSelect",
"(",
"$",
"selectOptions",
",",
"$",
"selectValue",
",",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
",",
"$",
"inAdtnl",
")",
";",
"}"
] | Builds field output type for numeric types if not FK
@param array $fkArray
@param array $value
@param array $iar
@return string | [
"Builds",
"field",
"output",
"type",
"for",
"numeric",
"types",
"if",
"not",
"FK"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtables.php#L95-L112 | train |
danielgp/common-lib | source/MySQLiByDanielGPtables.php | MySQLiByDanielGPtables.getFieldOutputTextPrerequisites | private function getFieldOutputTextPrerequisites($tbl, $value)
{
$foreignKeysArray = [];
if (($tbl != 'user_rights') && ($value['COLUMN_NAME'] != 'eid')) {
$database = $this->advCache['workingDatabase'];
if (strpos($tbl, '`.`')) {
$database = substr($tbl, 0, strpos($tbl, '`.`'));
}
$foreignKeysArray = $this->getForeignKeysToArray($database, $tbl, $value['COLUMN_NAME']);
}
return $foreignKeysArray;
} | php | private function getFieldOutputTextPrerequisites($tbl, $value)
{
$foreignKeysArray = [];
if (($tbl != 'user_rights') && ($value['COLUMN_NAME'] != 'eid')) {
$database = $this->advCache['workingDatabase'];
if (strpos($tbl, '`.`')) {
$database = substr($tbl, 0, strpos($tbl, '`.`'));
}
$foreignKeysArray = $this->getForeignKeysToArray($database, $tbl, $value['COLUMN_NAME']);
}
return $foreignKeysArray;
} | [
"private",
"function",
"getFieldOutputTextPrerequisites",
"(",
"$",
"tbl",
",",
"$",
"value",
")",
"{",
"$",
"foreignKeysArray",
"=",
"[",
"]",
";",
"if",
"(",
"(",
"$",
"tbl",
"!=",
"'user_rights'",
")",
"&&",
"(",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
"!=",
"'eid'",
")",
")",
"{",
"$",
"database",
"=",
"$",
"this",
"->",
"advCache",
"[",
"'workingDatabase'",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"tbl",
",",
"'`.`'",
")",
")",
"{",
"$",
"database",
"=",
"substr",
"(",
"$",
"tbl",
",",
"0",
",",
"strpos",
"(",
"$",
"tbl",
",",
"'`.`'",
")",
")",
";",
"}",
"$",
"foreignKeysArray",
"=",
"$",
"this",
"->",
"getForeignKeysToArray",
"(",
"$",
"database",
",",
"$",
"tbl",
",",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
")",
";",
"}",
"return",
"$",
"foreignKeysArray",
";",
"}"
] | Prepares the text output fields
@param string $tbl
@param array $value
@return array | [
"Prepares",
"the",
"text",
"output",
"fields"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtables.php#L121-L132 | train |
danielgp/common-lib | source/MySQLiByDanielGPtables.php | MySQLiByDanielGPtables.getForeignKeysToArray | private function getForeignKeysToArray($database, $tblName, $oCol = '')
{
if (!isset($this->advCache['tableFKs'][$database][$tblName])) {
$this->setTableForeignKeyCache($database, $this->fixTableSource($tblName));
}
$aRt = [];
if (isset($this->advCache['tableFKs'][$database][$tblName])) {
$cnm = ['COLUMN_NAME', 'full_array_key_numbered', 'REFERENCED_TABLE_SCHEMA', 'REFERENCED_TABLE_NAME'];
foreach ($this->advCache['tableFKs'][$database][$tblName] as $val) {
if ($val[$cnm[0]] == $oCol) {
$vlQ = array_merge($val, ['LIMIT' => 2]);
$tFd = $this->setMySQLquery2Server($this->getForeignKeysQuery($vlQ), $cnm[1])['result'];
$tgtFld = '`' . ($tFd[0][$cnm[0]] == $val[$cnm[0]] ? $tFd[1][$cnm[0]] : $tFd[0][$cnm[0]]) . '`';
$aRt[$oCol] = [$this->glueDbTb($val[$cnm[2]], $val[$cnm[3]]), $val[$cnm[2]], $tgtFld];
}
}
}
return $aRt;
} | php | private function getForeignKeysToArray($database, $tblName, $oCol = '')
{
if (!isset($this->advCache['tableFKs'][$database][$tblName])) {
$this->setTableForeignKeyCache($database, $this->fixTableSource($tblName));
}
$aRt = [];
if (isset($this->advCache['tableFKs'][$database][$tblName])) {
$cnm = ['COLUMN_NAME', 'full_array_key_numbered', 'REFERENCED_TABLE_SCHEMA', 'REFERENCED_TABLE_NAME'];
foreach ($this->advCache['tableFKs'][$database][$tblName] as $val) {
if ($val[$cnm[0]] == $oCol) {
$vlQ = array_merge($val, ['LIMIT' => 2]);
$tFd = $this->setMySQLquery2Server($this->getForeignKeysQuery($vlQ), $cnm[1])['result'];
$tgtFld = '`' . ($tFd[0][$cnm[0]] == $val[$cnm[0]] ? $tFd[1][$cnm[0]] : $tFd[0][$cnm[0]]) . '`';
$aRt[$oCol] = [$this->glueDbTb($val[$cnm[2]], $val[$cnm[3]]), $val[$cnm[2]], $tgtFld];
}
}
}
return $aRt;
} | [
"private",
"function",
"getForeignKeysToArray",
"(",
"$",
"database",
",",
"$",
"tblName",
",",
"$",
"oCol",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'tableFKs'",
"]",
"[",
"$",
"database",
"]",
"[",
"$",
"tblName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setTableForeignKeyCache",
"(",
"$",
"database",
",",
"$",
"this",
"->",
"fixTableSource",
"(",
"$",
"tblName",
")",
")",
";",
"}",
"$",
"aRt",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'tableFKs'",
"]",
"[",
"$",
"database",
"]",
"[",
"$",
"tblName",
"]",
")",
")",
"{",
"$",
"cnm",
"=",
"[",
"'COLUMN_NAME'",
",",
"'full_array_key_numbered'",
",",
"'REFERENCED_TABLE_SCHEMA'",
",",
"'REFERENCED_TABLE_NAME'",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'tableFKs'",
"]",
"[",
"$",
"database",
"]",
"[",
"$",
"tblName",
"]",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"[",
"$",
"cnm",
"[",
"0",
"]",
"]",
"==",
"$",
"oCol",
")",
"{",
"$",
"vlQ",
"=",
"array_merge",
"(",
"$",
"val",
",",
"[",
"'LIMIT'",
"=>",
"2",
"]",
")",
";",
"$",
"tFd",
"=",
"$",
"this",
"->",
"setMySQLquery2Server",
"(",
"$",
"this",
"->",
"getForeignKeysQuery",
"(",
"$",
"vlQ",
")",
",",
"$",
"cnm",
"[",
"1",
"]",
")",
"[",
"'result'",
"]",
";",
"$",
"tgtFld",
"=",
"'`'",
".",
"(",
"$",
"tFd",
"[",
"0",
"]",
"[",
"$",
"cnm",
"[",
"0",
"]",
"]",
"==",
"$",
"val",
"[",
"$",
"cnm",
"[",
"0",
"]",
"]",
"?",
"$",
"tFd",
"[",
"1",
"]",
"[",
"$",
"cnm",
"[",
"0",
"]",
"]",
":",
"$",
"tFd",
"[",
"0",
"]",
"[",
"$",
"cnm",
"[",
"0",
"]",
"]",
")",
".",
"'`'",
";",
"$",
"aRt",
"[",
"$",
"oCol",
"]",
"=",
"[",
"$",
"this",
"->",
"glueDbTb",
"(",
"$",
"val",
"[",
"$",
"cnm",
"[",
"2",
"]",
"]",
",",
"$",
"val",
"[",
"$",
"cnm",
"[",
"3",
"]",
"]",
")",
",",
"$",
"val",
"[",
"$",
"cnm",
"[",
"2",
"]",
"]",
",",
"$",
"tgtFld",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"aRt",
";",
"}"
] | Returns an array with fields referenced by a Foreign key
@param string $database
@param string $tblName
@param string|array $oCol Only column(s) considered
@return array | [
"Returns",
"an",
"array",
"with",
"fields",
"referenced",
"by",
"a",
"Foreign",
"key"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtables.php#L142-L160 | train |
danielgp/common-lib | source/MySQLiByDanielGPtables.php | MySQLiByDanielGPtables.setTableCache | protected function setTableCache($tblSrc)
{
$dat = $this->establishDatabaseAndTable($tblSrc);
if (!isset($this->advCache['tableStructureCache'][$dat[0]][$dat[1]])) {
$this->advCache['workingDatabase'] = $dat[0];
$this->advCache['tableStructureCache'][$dat[0]][$dat[1]] = $this->getMySQLlistColumns([
'TABLE_SCHEMA' => $dat[0],
'TABLE_NAME' => $dat[1],
]);
$this->setTableForeignKeyCache($dat[0], $dat[1]);
}
} | php | protected function setTableCache($tblSrc)
{
$dat = $this->establishDatabaseAndTable($tblSrc);
if (!isset($this->advCache['tableStructureCache'][$dat[0]][$dat[1]])) {
$this->advCache['workingDatabase'] = $dat[0];
$this->advCache['tableStructureCache'][$dat[0]][$dat[1]] = $this->getMySQLlistColumns([
'TABLE_SCHEMA' => $dat[0],
'TABLE_NAME' => $dat[1],
]);
$this->setTableForeignKeyCache($dat[0], $dat[1]);
}
} | [
"protected",
"function",
"setTableCache",
"(",
"$",
"tblSrc",
")",
"{",
"$",
"dat",
"=",
"$",
"this",
"->",
"establishDatabaseAndTable",
"(",
"$",
"tblSrc",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'tableStructureCache'",
"]",
"[",
"$",
"dat",
"[",
"0",
"]",
"]",
"[",
"$",
"dat",
"[",
"1",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"advCache",
"[",
"'workingDatabase'",
"]",
"=",
"$",
"dat",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"advCache",
"[",
"'tableStructureCache'",
"]",
"[",
"$",
"dat",
"[",
"0",
"]",
"]",
"[",
"$",
"dat",
"[",
"1",
"]",
"]",
"=",
"$",
"this",
"->",
"getMySQLlistColumns",
"(",
"[",
"'TABLE_SCHEMA'",
"=>",
"$",
"dat",
"[",
"0",
"]",
",",
"'TABLE_NAME'",
"=>",
"$",
"dat",
"[",
"1",
"]",
",",
"]",
")",
";",
"$",
"this",
"->",
"setTableForeignKeyCache",
"(",
"$",
"dat",
"[",
"0",
"]",
",",
"$",
"dat",
"[",
"1",
"]",
")",
";",
"}",
"}"
] | create a Cache for given table to use it in many places
@param string $tblSrc | [
"create",
"a",
"Cache",
"for",
"given",
"table",
"to",
"use",
"it",
"in",
"many",
"places"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiByDanielGPtables.php#L167-L178 | train |
ScaraMVC/Framework | src/Scara/Session/File.php | File.content | private function content()
{
$handle = fopen($this->_config, 'r');
$content = @json_decode(stream_get_contents($handle));
return $content;
} | php | private function content()
{
$handle = fopen($this->_config, 'r');
$content = @json_decode(stream_get_contents($handle));
return $content;
} | [
"private",
"function",
"content",
"(",
")",
"{",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"_config",
",",
"'r'",
")",
";",
"$",
"content",
"=",
"@",
"json_decode",
"(",
"stream_get_contents",
"(",
"$",
"handle",
")",
")",
";",
"return",
"$",
"content",
";",
"}"
] | Gets the file session's content.
@return mixed | [
"Gets",
"the",
"file",
"session",
"s",
"content",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Session/File.php#L121-L127 | train |
ScaraMVC/Framework | src/Scara/Session/File.php | File.write | private function write($content)
{
$handle = fopen($this->_config, 'w+');
fwrite($handle, @json_encode($content));
fclose($handle);
} | php | private function write($content)
{
$handle = fopen($this->_config, 'w+');
fwrite($handle, @json_encode($content));
fclose($handle);
} | [
"private",
"function",
"write",
"(",
"$",
"content",
")",
"{",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"_config",
",",
"'w+'",
")",
";",
"fwrite",
"(",
"$",
"handle",
",",
"@",
"json_encode",
"(",
"$",
"content",
")",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"}"
] | Writes session info to file session.
@param mixed $content
@return void | [
"Writes",
"session",
"info",
"to",
"file",
"session",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Session/File.php#L136-L141 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Subfield.php | Subfield.factory | public static function factory (array $subfield)
{
if (!array_key_exists('code', $subfield)) {
throw new InvalidArgumentException("Missing 'code' index in subfield array");
}
if (!array_key_exists('value', $subfield)) {
throw new InvalidArgumentException("Missing 'value' index in subfield array");
}
return new Subfield($subfield['code'], $subfield['value']);
} | php | public static function factory (array $subfield)
{
if (!array_key_exists('code', $subfield)) {
throw new InvalidArgumentException("Missing 'code' index in subfield array");
}
if (!array_key_exists('value', $subfield)) {
throw new InvalidArgumentException("Missing 'value' index in subfield array");
}
return new Subfield($subfield['code'], $subfield['value']);
} | [
"public",
"static",
"function",
"factory",
"(",
"array",
"$",
"subfield",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'code'",
",",
"$",
"subfield",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Missing 'code' index in subfield array\"",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'value'",
",",
"$",
"subfield",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Missing 'value' index in subfield array\"",
")",
";",
"}",
"return",
"new",
"Subfield",
"(",
"$",
"subfield",
"[",
"'code'",
"]",
",",
"$",
"subfield",
"[",
"'value'",
"]",
")",
";",
"}"
] | Return a new subfield based on its array representation.
The array representation of a subfield is an associative array with the
keys `code' and `value', holding the subfield code and value.
@throws InvalidArgumentException Missing code or value index
@param array $subfield Array representation of a subfield
@return Subfield New subfield | [
"Return",
"a",
"new",
"subfield",
"based",
"on",
"its",
"array",
"representation",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Subfield.php#L65-L74 | train |
Talesoft/tale-framework | src/Tale/Factory.php | Factory.registerAlias | public function registerAlias($alias, $className)
{
$this->_aliases[$alias] = $this->resolveClassName($className);
return $this;
} | php | public function registerAlias($alias, $className)
{
$this->_aliases[$alias] = $this->resolveClassName($className);
return $this;
} | [
"public",
"function",
"registerAlias",
"(",
"$",
"alias",
",",
"$",
"className",
")",
"{",
"$",
"this",
"->",
"_aliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"this",
"->",
"resolveClassName",
"(",
"$",
"className",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Registers a new alias with a specific FQCN
@param string $alias The alias the FQDN can be found under
@param string $className The FQCN the given alias should map to
@return $this | [
"Registers",
"a",
"new",
"alias",
"with",
"a",
"specific",
"FQCN"
] | 739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49 | https://github.com/Talesoft/tale-framework/blob/739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49/src/Tale/Factory.php#L78-L84 | train |
Talesoft/tale-framework | src/Tale/Factory.php | Factory.registerAliases | public function registerAliases(array $aliases)
{
foreach ($aliases as $alias => $className)
$this->registerAlias($alias, $className);
return $this;
} | php | public function registerAliases(array $aliases)
{
foreach ($aliases as $alias => $className)
$this->registerAlias($alias, $className);
return $this;
} | [
"public",
"function",
"registerAliases",
"(",
"array",
"$",
"aliases",
")",
"{",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
"=>",
"$",
"className",
")",
"$",
"this",
"->",
"registerAlias",
"(",
"$",
"alias",
",",
"$",
"className",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Registers an array of aliases.
The aliases should be the keys, the FQCNs the values of the associative array
@param array $aliases Associative array of aliases => FQCNs
@return $this | [
"Registers",
"an",
"array",
"of",
"aliases",
".",
"The",
"aliases",
"should",
"be",
"the",
"keys",
"the",
"FQCNs",
"the",
"values",
"of",
"the",
"associative",
"array"
] | 739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49 | https://github.com/Talesoft/tale-framework/blob/739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49/src/Tale/Factory.php#L94-L101 | train |
Talesoft/tale-framework | src/Tale/Factory.php | Factory.resolveClassName | public function resolveClassName($className)
{
if (isset($this->_aliases[$className]))
$className = $this->_aliases[$className];
return $className;
} | php | public function resolveClassName($className)
{
if (isset($this->_aliases[$className]))
$className = $this->_aliases[$className];
return $className;
} | [
"public",
"function",
"resolveClassName",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_aliases",
"[",
"$",
"className",
"]",
")",
")",
"$",
"className",
"=",
"$",
"this",
"->",
"_aliases",
"[",
"$",
"className",
"]",
";",
"return",
"$",
"className",
";",
"}"
] | Resolves a a class-name or an alias to a FQCN
If no alias is found, it returns the class name given
@param string $className The class-name to be converted
@return string The usable FQCN of the class | [
"Resolves",
"a",
"a",
"class",
"-",
"name",
"or",
"an",
"alias",
"to",
"a",
"FQCN"
] | 739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49 | https://github.com/Talesoft/tale-framework/blob/739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49/src/Tale/Factory.php#L113-L120 | train |
Talesoft/tale-framework | src/Tale/Factory.php | Factory.createInstance | public function createInstance($className, array $args = null)
{
$args = $args ? $args : [];
$className = $this->resolveClassName($className);
if (!class_exists($className) || ($this->_baseClassName && !is_subclass_of($className, $this->_baseClassName)))
throw new FactoryException(
"Failed to resolve factory classname: "
."$className does not exist or is not a valid {$this->_baseClassName}"
);
$ref = new \ReflectionClass($className);
return $ref->newInstanceArgs($args);
} | php | public function createInstance($className, array $args = null)
{
$args = $args ? $args : [];
$className = $this->resolveClassName($className);
if (!class_exists($className) || ($this->_baseClassName && !is_subclass_of($className, $this->_baseClassName)))
throw new FactoryException(
"Failed to resolve factory classname: "
."$className does not exist or is not a valid {$this->_baseClassName}"
);
$ref = new \ReflectionClass($className);
return $ref->newInstanceArgs($args);
} | [
"public",
"function",
"createInstance",
"(",
"$",
"className",
",",
"array",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"args",
"=",
"$",
"args",
"?",
"$",
"args",
":",
"[",
"]",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"resolveClassName",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
"||",
"(",
"$",
"this",
"->",
"_baseClassName",
"&&",
"!",
"is_subclass_of",
"(",
"$",
"className",
",",
"$",
"this",
"->",
"_baseClassName",
")",
")",
")",
"throw",
"new",
"FactoryException",
"(",
"\"Failed to resolve factory classname: \"",
".",
"\"$className does not exist or is not a valid {$this->_baseClassName}\"",
")",
";",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"return",
"$",
"ref",
"->",
"newInstanceArgs",
"(",
"$",
"args",
")",
";",
"}"
] | Creates a new instance of a class based on a class name or alias given.
If the class doesnt exist or doesnt extend the base-class of this factory,
a RuntimeException is thrown
Uses Reflection internally
@see ReflectionClass->newInstanceArgs
@param string $className The alias or FQCN to instanciate
@param array|null $args The arguments that should be passed to the constructor
@throws \Tale\FactoryException
@return object The newly created child-class instance | [
"Creates",
"a",
"new",
"instance",
"of",
"a",
"class",
"based",
"on",
"a",
"class",
"name",
"or",
"alias",
"given",
"."
] | 739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49 | https://github.com/Talesoft/tale-framework/blob/739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49/src/Tale/Factory.php#L139-L154 | train |
eloquent/blox | src/Element/DocumentationBlock.php | DocumentationBlock.tagsByName | public function tagsByName($name)
{
$tags = array();
foreach ($this->tags() as $tag) {
if ($name === $tag->name()) {
$tags[] = $tag;
}
}
return $tags;
} | php | public function tagsByName($name)
{
$tags = array();
foreach ($this->tags() as $tag) {
if ($name === $tag->name()) {
$tags[] = $tag;
}
}
return $tags;
} | [
"public",
"function",
"tagsByName",
"(",
"$",
"name",
")",
"{",
"$",
"tags",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tags",
"(",
")",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"$",
"tag",
"->",
"name",
"(",
")",
")",
"{",
"$",
"tags",
"[",
"]",
"=",
"$",
"tag",
";",
"}",
"}",
"return",
"$",
"tags",
";",
"}"
] | Get all the tags of this block with a specific tag name.
@param string $name The tag name to search for.
@return array<DocumentationTag> The tags with a matching tag name. | [
"Get",
"all",
"the",
"tags",
"of",
"this",
"block",
"with",
"a",
"specific",
"tag",
"name",
"."
] | dcfe82a0a703124ab5807d894979530d6fdb536b | https://github.com/eloquent/blox/blob/dcfe82a0a703124ab5807d894979530d6fdb536b/src/Element/DocumentationBlock.php#L57-L67 | train |
vpg/titon.utility | src/Titon/Utility/Number.php | Number.bytesTo | public static function bytesTo($size, $precision = 0) {
$sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'B');
$total = count($sizes);
while ($total-- && $size >= 1024) {
$size /= 1024;
}
return static::precision($size, $precision) . $sizes[$total];
} | php | public static function bytesTo($size, $precision = 0) {
$sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'B');
$total = count($sizes);
while ($total-- && $size >= 1024) {
$size /= 1024;
}
return static::precision($size, $precision) . $sizes[$total];
} | [
"public",
"static",
"function",
"bytesTo",
"(",
"$",
"size",
",",
"$",
"precision",
"=",
"0",
")",
"{",
"$",
"sizes",
"=",
"array",
"(",
"'YB'",
",",
"'ZB'",
",",
"'EB'",
",",
"'PB'",
",",
"'TB'",
",",
"'GB'",
",",
"'MB'",
",",
"'KB'",
",",
"'B'",
")",
";",
"$",
"total",
"=",
"count",
"(",
"$",
"sizes",
")",
";",
"while",
"(",
"$",
"total",
"--",
"&&",
"$",
"size",
">=",
"1024",
")",
"{",
"$",
"size",
"/=",
"1024",
";",
"}",
"return",
"static",
"::",
"precision",
"(",
"$",
"size",
",",
"$",
"precision",
")",
".",
"$",
"sizes",
"[",
"$",
"total",
"]",
";",
"}"
] | Convert a numerical value to the readable string notated equivalent.
@param int $size
@param int $precision
@return string | [
"Convert",
"a",
"numerical",
"value",
"to",
"the",
"readable",
"string",
"notated",
"equivalent",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Number.php#L70-L79 | train |
vpg/titon.utility | src/Titon/Utility/Number.php | Number.convert | public static function convert($no, $fromBase, $toBase) {
if ($fromBase == $toBase) {
return $no;
}
return base_convert($no, $fromBase, $toBase);
} | php | public static function convert($no, $fromBase, $toBase) {
if ($fromBase == $toBase) {
return $no;
}
return base_convert($no, $fromBase, $toBase);
} | [
"public",
"static",
"function",
"convert",
"(",
"$",
"no",
",",
"$",
"fromBase",
",",
"$",
"toBase",
")",
"{",
"if",
"(",
"$",
"fromBase",
"==",
"$",
"toBase",
")",
"{",
"return",
"$",
"no",
";",
"}",
"return",
"base_convert",
"(",
"$",
"no",
",",
"$",
"fromBase",
",",
"$",
"toBase",
")",
";",
"}"
] | Convert a number from one base to another.
@param int $no
@param int $fromBase
@param int $toBase
@return int | [
"Convert",
"a",
"number",
"from",
"one",
"base",
"to",
"another",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Number.php#L89-L95 | train |
vpg/titon.utility | src/Titon/Utility/Number.php | Number.currency | public static function currency($number, array $options = array()) {
$defaults = array(
'thousands' => ',',
'decimals' => '.',
'places' => 2,
'code' => 'USD #',
'dollar' => '$#',
'cents' => '#¢',
'use' => 'dollar',
'negative' => '(#)'
);
$options = $options + $defaults;
$amount = number_format(static::precision(abs($number), $options['places']), $options['places'], $options['decimals'], $options['thousands']);
// Cents
if (($number < 1 && $number > -1) && $options['cents']) {
$amount = str_replace('#', $amount, $options['cents']);
// Dollars
} else {
if ($options['use'] === 'dollar') {
$amount = str_replace('#', $amount, $options['dollar']);
} else {
$amount = str_replace('#', $amount, $options['code']);
}
}
// Negative
if ($number < 0 && $options['negative']) {
$amount = str_replace('#', $amount, $options['negative']);
}
return $amount;
} | php | public static function currency($number, array $options = array()) {
$defaults = array(
'thousands' => ',',
'decimals' => '.',
'places' => 2,
'code' => 'USD #',
'dollar' => '$#',
'cents' => '#¢',
'use' => 'dollar',
'negative' => '(#)'
);
$options = $options + $defaults;
$amount = number_format(static::precision(abs($number), $options['places']), $options['places'], $options['decimals'], $options['thousands']);
// Cents
if (($number < 1 && $number > -1) && $options['cents']) {
$amount = str_replace('#', $amount, $options['cents']);
// Dollars
} else {
if ($options['use'] === 'dollar') {
$amount = str_replace('#', $amount, $options['dollar']);
} else {
$amount = str_replace('#', $amount, $options['code']);
}
}
// Negative
if ($number < 0 && $options['negative']) {
$amount = str_replace('#', $amount, $options['negative']);
}
return $amount;
} | [
"public",
"static",
"function",
"currency",
"(",
"$",
"number",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"defaults",
"=",
"array",
"(",
"'thousands'",
"=>",
"','",
",",
"'decimals'",
"=>",
"'.'",
",",
"'places'",
"=>",
"2",
",",
"'code'",
"=>",
"'USD #'",
",",
"'dollar'",
"=>",
"'$#'",
",",
"'cents'",
"=>",
"'#¢'",
",",
"'use'",
"=>",
"'dollar'",
",",
"'negative'",
"=>",
"'(#)'",
")",
";",
"$",
"options",
"=",
"$",
"options",
"+",
"$",
"defaults",
";",
"$",
"amount",
"=",
"number_format",
"(",
"static",
"::",
"precision",
"(",
"abs",
"(",
"$",
"number",
")",
",",
"$",
"options",
"[",
"'places'",
"]",
")",
",",
"$",
"options",
"[",
"'places'",
"]",
",",
"$",
"options",
"[",
"'decimals'",
"]",
",",
"$",
"options",
"[",
"'thousands'",
"]",
")",
";",
"// Cents",
"if",
"(",
"(",
"$",
"number",
"<",
"1",
"&&",
"$",
"number",
">",
"-",
"1",
")",
"&&",
"$",
"options",
"[",
"'cents'",
"]",
")",
"{",
"$",
"amount",
"=",
"str_replace",
"(",
"'#'",
",",
"$",
"amount",
",",
"$",
"options",
"[",
"'cents'",
"]",
")",
";",
"// Dollars",
"}",
"else",
"{",
"if",
"(",
"$",
"options",
"[",
"'use'",
"]",
"===",
"'dollar'",
")",
"{",
"$",
"amount",
"=",
"str_replace",
"(",
"'#'",
",",
"$",
"amount",
",",
"$",
"options",
"[",
"'dollar'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"amount",
"=",
"str_replace",
"(",
"'#'",
",",
"$",
"amount",
",",
"$",
"options",
"[",
"'code'",
"]",
")",
";",
"}",
"}",
"// Negative",
"if",
"(",
"$",
"number",
"<",
"0",
"&&",
"$",
"options",
"[",
"'negative'",
"]",
")",
"{",
"$",
"amount",
"=",
"str_replace",
"(",
"'#'",
",",
"$",
"amount",
",",
"$",
"options",
"[",
"'negative'",
"]",
")",
";",
"}",
"return",
"$",
"amount",
";",
"}"
] | Convert a number to it's currency equivalent, respecting locale.
Allow for overrides through an options array.
@param int $number
@param array $options {
@type string $thousands Character used for thousands place
@type string $decimals Character used for decimal
@type int $places Decimal (cent) limit
@type string $code Currency code with replaceable hash
@type string $dollar Dollar sign with replaceable hash
@type string $cents Cent sign with replaceable hash
@type string $use Whether to use dollar or code for formatting
@type string $negative Negative sign with replaceable hash
}
@return string | [
"Convert",
"a",
"number",
"to",
"it",
"s",
"currency",
"equivalent",
"respecting",
"locale",
".",
"Allow",
"for",
"overrides",
"through",
"an",
"options",
"array",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Number.php#L114-L148 | train |
vpg/titon.utility | src/Titon/Utility/Number.php | Number.percentage | public static function percentage($number, $options = array()) {
if (!is_array($options)) {
$options = array('places' => $options);
}
$options = $options + array(
'thousands' => ',',
'decimals' => '.',
'places' => 2
);
return number_format(static::precision($number, $options['places']), $options['places'], $options['decimals'], $options['thousands']) . '%';
} | php | public static function percentage($number, $options = array()) {
if (!is_array($options)) {
$options = array('places' => $options);
}
$options = $options + array(
'thousands' => ',',
'decimals' => '.',
'places' => 2
);
return number_format(static::precision($number, $options['places']), $options['places'], $options['decimals'], $options['thousands']) . '%';
} | [
"public",
"static",
"function",
"percentage",
"(",
"$",
"number",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'places'",
"=>",
"$",
"options",
")",
";",
"}",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'thousands'",
"=>",
"','",
",",
"'decimals'",
"=>",
"'.'",
",",
"'places'",
"=>",
"2",
")",
";",
"return",
"number_format",
"(",
"static",
"::",
"precision",
"(",
"$",
"number",
",",
"$",
"options",
"[",
"'places'",
"]",
")",
",",
"$",
"options",
"[",
"'places'",
"]",
",",
"$",
"options",
"[",
"'decimals'",
"]",
",",
"$",
"options",
"[",
"'thousands'",
"]",
")",
".",
"'%'",
";",
"}"
] | Convert a number to a percentage string with decimal and comma separations.
@param int $number
@param int|array $options {
@type string $thousands Character used for thousands place
@type string $decimals Character used for decimal
@type int $places Decimal (cent) limit
}
@return string | [
"Convert",
"a",
"number",
"to",
"a",
"percentage",
"string",
"with",
"decimal",
"and",
"comma",
"separations",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Number.php#L268-L280 | train |
WellCommerce/CurrencyBundle | EventListener/CurrencySubscriber.php | CurrencySubscriber.getLocaleCurrency | protected function getLocaleCurrency(Request $request)
{
$currentLocale = $request->getLocale();
$locale = $this->container->get('locale.repository')->findOneBy(['code' => $currentLocale]);
if (null !== $locale && $locale->getCurrency() instanceof Currency) {
return $locale->getCurrency()->getCode();
}
return null;
} | php | protected function getLocaleCurrency(Request $request)
{
$currentLocale = $request->getLocale();
$locale = $this->container->get('locale.repository')->findOneBy(['code' => $currentLocale]);
if (null !== $locale && $locale->getCurrency() instanceof Currency) {
return $locale->getCurrency()->getCode();
}
return null;
} | [
"protected",
"function",
"getLocaleCurrency",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"currentLocale",
"=",
"$",
"request",
"->",
"getLocale",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'locale.repository'",
")",
"->",
"findOneBy",
"(",
"[",
"'code'",
"=>",
"$",
"currentLocale",
"]",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"locale",
"&&",
"$",
"locale",
"->",
"getCurrency",
"(",
")",
"instanceof",
"Currency",
")",
"{",
"return",
"$",
"locale",
"->",
"getCurrency",
"(",
")",
"->",
"getCode",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the currency code for active locale
@param Request $request
@return string | [
"Returns",
"the",
"currency",
"code",
"for",
"active",
"locale"
] | 48a6995eedb9c1f93d10751a6d1070e4cbca307e | https://github.com/WellCommerce/CurrencyBundle/blob/48a6995eedb9c1f93d10751a6d1070e4cbca307e/EventListener/CurrencySubscriber.php#L54-L64 | train |
lanfisis/deflection | src/Deflection/Generator.php | Generator.asString | public function asString()
{
$display = function ($lines, $length, $loop = 0) use (&$display) {
$output = '';
foreach ($lines as $line) {
$line = is_a($line, 'Deflection\Element\AbstractElement') ? $line->getElement() : $line;
if (is_array($line)) {
$output .= $display($line, $length, $loop+1);
} else {
$size = mb_strlen($line)+($length*$loop);
$output .= str_pad($line, $size, ' ', STR_PAD_LEFT)."\n";
}
}
return $output;
};
return !$this->class ?: "<?php\n".$display($this->class->getElement(), $this->tab);
} | php | public function asString()
{
$display = function ($lines, $length, $loop = 0) use (&$display) {
$output = '';
foreach ($lines as $line) {
$line = is_a($line, 'Deflection\Element\AbstractElement') ? $line->getElement() : $line;
if (is_array($line)) {
$output .= $display($line, $length, $loop+1);
} else {
$size = mb_strlen($line)+($length*$loop);
$output .= str_pad($line, $size, ' ', STR_PAD_LEFT)."\n";
}
}
return $output;
};
return !$this->class ?: "<?php\n".$display($this->class->getElement(), $this->tab);
} | [
"public",
"function",
"asString",
"(",
")",
"{",
"$",
"display",
"=",
"function",
"(",
"$",
"lines",
",",
"$",
"length",
",",
"$",
"loop",
"=",
"0",
")",
"use",
"(",
"&",
"$",
"display",
")",
"{",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"is_a",
"(",
"$",
"line",
",",
"'Deflection\\Element\\AbstractElement'",
")",
"?",
"$",
"line",
"->",
"getElement",
"(",
")",
":",
"$",
"line",
";",
"if",
"(",
"is_array",
"(",
"$",
"line",
")",
")",
"{",
"$",
"output",
".=",
"$",
"display",
"(",
"$",
"line",
",",
"$",
"length",
",",
"$",
"loop",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"size",
"=",
"mb_strlen",
"(",
"$",
"line",
")",
"+",
"(",
"$",
"length",
"*",
"$",
"loop",
")",
";",
"$",
"output",
".=",
"str_pad",
"(",
"$",
"line",
",",
"$",
"size",
",",
"' '",
",",
"STR_PAD_LEFT",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}",
";",
"return",
"!",
"$",
"this",
"->",
"class",
"?",
":",
"\"<?php\\n\"",
".",
"$",
"display",
"(",
"$",
"this",
"->",
"class",
"->",
"getElement",
"(",
")",
",",
"$",
"this",
"->",
"tab",
")",
";",
"}"
] | Returns class definition as a string
@return string | [
"Returns",
"class",
"definition",
"as",
"a",
"string"
] | 31deaf7f085d6456d8a323e7ac3cc9914fbe49a9 | https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Generator.php#L46-L62 | train |
TuumPHP/Web | src/Stack/ViewStack.php | ViewStack.streamView | private function streamView($response)
{
if (Response::isError($response) &&
!$response->getBody() instanceof ViewStream
) {
$response = $this->setErrorView($response);
return $response;
}
return $response;
} | php | private function streamView($response)
{
if (Response::isError($response) &&
!$response->getBody() instanceof ViewStream
) {
$response = $this->setErrorView($response);
return $response;
}
return $response;
} | [
"private",
"function",
"streamView",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"Response",
"::",
"isError",
"(",
"$",
"response",
")",
"&&",
"!",
"$",
"response",
"->",
"getBody",
"(",
")",
"instanceof",
"ViewStream",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"setErrorView",
"(",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | fill up contents for VIEW and ERROR responses.
@param Response $response
@return Response | [
"fill",
"up",
"contents",
"for",
"VIEW",
"and",
"ERROR",
"responses",
"."
] | 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Stack/ViewStack.php#L89-L98 | train |
TuumPHP/Web | src/Stack/ViewStack.php | ViewStack.setErrorView | private function setErrorView($response)
{
if (Response::isServerError($response) && $this->logger) {
$this->logger->error('received a server error response: ' . $response->getStatusCode());
}
$stream = $this->error->getStream($response->getStatusCode(), $response->getData());
$response = $response->withBody($stream);
return $response;
} | php | private function setErrorView($response)
{
if (Response::isServerError($response) && $this->logger) {
$this->logger->error('received a server error response: ' . $response->getStatusCode());
}
$stream = $this->error->getStream($response->getStatusCode(), $response->getData());
$response = $response->withBody($stream);
return $response;
} | [
"private",
"function",
"setErrorView",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"Response",
"::",
"isServerError",
"(",
"$",
"response",
")",
"&&",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"'received a server error response: '",
".",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
";",
"}",
"$",
"stream",
"=",
"$",
"this",
"->",
"error",
"->",
"getStream",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"response",
"->",
"getData",
"(",
")",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withBody",
"(",
"$",
"stream",
")",
";",
"return",
"$",
"response",
";",
"}"
] | render error pages.
@param Response $response
@return Response | [
"render",
"error",
"pages",
"."
] | 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Stack/ViewStack.php#L106-L114 | train |
DoSomething/mobilecommons-php | lib/MobileCommons/Request.php | Request.call | public function call($resource, $params = array(), $method = 'GET')
{
if (!empty($params) && is_array($params)) {
$queryString = http_build_query($params);
}
else {
$queryString = '';
}
$requestUrl = self::API_URL . $resource . ((strtolower($method) == 'get') ? '?' . $queryString : '');
$curl = curl_init();
$curl_options = array(
CURLOPT_USERPWD => $this->getAuthenticationString(),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $requestUrl,
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_HTTPHEADER => array('Accept: application/xml'),
);
if (strtolower($method) == 'post') {
$curl_options[CURLOPT_POST] = 1;
$curl_options[CURLOPT_POSTFIELDS] = $params;
}
curl_setopt_array($curl, $curl_options);
$response = curl_exec($curl);
$curl_info = curl_getinfo($curl);
//@todo test for curl error
if ($errno = curl_errno($curl)) {
$error_message = $errno . ': ' . curl_strerror($errno);
throw new Exception($error_message, $errno);
}
curl_close($curl);
//@todo test for any non 200 response
if ($curl_info['http_code'] != 200) {
throw new Exception("Response: Bad response - HTTP Code:". $curl_info['http_code']);
}
$xmlObject = simplexml_load_string($response);
if ($xmlObject === false) {
throw new Exception("Response: Response was not valid XML");
}
return $xmlObject;
} | php | public function call($resource, $params = array(), $method = 'GET')
{
if (!empty($params) && is_array($params)) {
$queryString = http_build_query($params);
}
else {
$queryString = '';
}
$requestUrl = self::API_URL . $resource . ((strtolower($method) == 'get') ? '?' . $queryString : '');
$curl = curl_init();
$curl_options = array(
CURLOPT_USERPWD => $this->getAuthenticationString(),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $requestUrl,
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_HTTPHEADER => array('Accept: application/xml'),
);
if (strtolower($method) == 'post') {
$curl_options[CURLOPT_POST] = 1;
$curl_options[CURLOPT_POSTFIELDS] = $params;
}
curl_setopt_array($curl, $curl_options);
$response = curl_exec($curl);
$curl_info = curl_getinfo($curl);
//@todo test for curl error
if ($errno = curl_errno($curl)) {
$error_message = $errno . ': ' . curl_strerror($errno);
throw new Exception($error_message, $errno);
}
curl_close($curl);
//@todo test for any non 200 response
if ($curl_info['http_code'] != 200) {
throw new Exception("Response: Bad response - HTTP Code:". $curl_info['http_code']);
}
$xmlObject = simplexml_load_string($response);
if ($xmlObject === false) {
throw new Exception("Response: Response was not valid XML");
}
return $xmlObject;
} | [
"public",
"function",
"call",
"(",
"$",
"resource",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"method",
"=",
"'GET'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
"&&",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"$",
"queryString",
"=",
"http_build_query",
"(",
"$",
"params",
")",
";",
"}",
"else",
"{",
"$",
"queryString",
"=",
"''",
";",
"}",
"$",
"requestUrl",
"=",
"self",
"::",
"API_URL",
".",
"$",
"resource",
".",
"(",
"(",
"strtolower",
"(",
"$",
"method",
")",
"==",
"'get'",
")",
"?",
"'?'",
".",
"$",
"queryString",
":",
"''",
")",
";",
"$",
"curl",
"=",
"curl_init",
"(",
")",
";",
"$",
"curl_options",
"=",
"array",
"(",
"CURLOPT_USERPWD",
"=>",
"$",
"this",
"->",
"getAuthenticationString",
"(",
")",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"1",
",",
"CURLOPT_URL",
"=>",
"$",
"requestUrl",
",",
"CURLOPT_TIMEOUT",
"=>",
"30",
",",
"CURLOPT_CONNECTTIMEOUT",
"=>",
"30",
",",
"CURLOPT_HTTPHEADER",
"=>",
"array",
"(",
"'Accept: application/xml'",
")",
",",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"method",
")",
"==",
"'post'",
")",
"{",
"$",
"curl_options",
"[",
"CURLOPT_POST",
"]",
"=",
"1",
";",
"$",
"curl_options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"$",
"params",
";",
"}",
"curl_setopt_array",
"(",
"$",
"curl",
",",
"$",
"curl_options",
")",
";",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"curl",
")",
";",
"$",
"curl_info",
"=",
"curl_getinfo",
"(",
"$",
"curl",
")",
";",
"//@todo test for curl error",
"if",
"(",
"$",
"errno",
"=",
"curl_errno",
"(",
"$",
"curl",
")",
")",
"{",
"$",
"error_message",
"=",
"$",
"errno",
".",
"': '",
".",
"curl_strerror",
"(",
"$",
"errno",
")",
";",
"throw",
"new",
"Exception",
"(",
"$",
"error_message",
",",
"$",
"errno",
")",
";",
"}",
"curl_close",
"(",
"$",
"curl",
")",
";",
"//@todo test for any non 200 response",
"if",
"(",
"$",
"curl_info",
"[",
"'http_code'",
"]",
"!=",
"200",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Response: Bad response - HTTP Code:\"",
".",
"$",
"curl_info",
"[",
"'http_code'",
"]",
")",
";",
"}",
"$",
"xmlObject",
"=",
"simplexml_load_string",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"xmlObject",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Response: Response was not valid XML\"",
")",
";",
"}",
"return",
"$",
"xmlObject",
";",
"}"
] | Make an api request
@param string $resource
@param array $params
@param string $method | [
"Make",
"an",
"api",
"request"
] | a820ee196d3166f827c30af69902ffb417674890 | https://github.com/DoSomething/mobilecommons-php/blob/a820ee196d3166f827c30af69902ffb417674890/lib/MobileCommons/Request.php#L103-L153 | train |
DoSomething/mobilecommons-php | lib/MobileCommons/Request.php | Request.webform | public function webform($action, $params, $friends = array()) {
$url = self::WEBFORM_URL . $action;
$header = sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthenticationString()));
$header .= "Content-type: application/x-www-form-urlencoded\r\n";
$params = http_build_query($params);
// If we have any friends present:
if (!empty($friends)) {
// Loop through them.
foreach ($friends as $friend) {
// Add each one to the query string.
$params .= '&friends[]=' . $friend;
}
}
$opts = array(
'http' => array(
'method' => 'POST',
'header' => $header,
'content' => $params,
)
);
$context = stream_context_create($opts);
return file_get_contents($url, false, $context);
} | php | public function webform($action, $params, $friends = array()) {
$url = self::WEBFORM_URL . $action;
$header = sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthenticationString()));
$header .= "Content-type: application/x-www-form-urlencoded\r\n";
$params = http_build_query($params);
// If we have any friends present:
if (!empty($friends)) {
// Loop through them.
foreach ($friends as $friend) {
// Add each one to the query string.
$params .= '&friends[]=' . $friend;
}
}
$opts = array(
'http' => array(
'method' => 'POST',
'header' => $header,
'content' => $params,
)
);
$context = stream_context_create($opts);
return file_get_contents($url, false, $context);
} | [
"public",
"function",
"webform",
"(",
"$",
"action",
",",
"$",
"params",
",",
"$",
"friends",
"=",
"array",
"(",
")",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"WEBFORM_URL",
".",
"$",
"action",
";",
"$",
"header",
"=",
"sprintf",
"(",
"\"Authorization: Basic %s\\r\\n\"",
",",
"base64_encode",
"(",
"$",
"this",
"->",
"getAuthenticationString",
"(",
")",
")",
")",
";",
"$",
"header",
".=",
"\"Content-type: application/x-www-form-urlencoded\\r\\n\"",
";",
"$",
"params",
"=",
"http_build_query",
"(",
"$",
"params",
")",
";",
"// If we have any friends present:",
"if",
"(",
"!",
"empty",
"(",
"$",
"friends",
")",
")",
"{",
"// Loop through them.",
"foreach",
"(",
"$",
"friends",
"as",
"$",
"friend",
")",
"{",
"// Add each one to the query string.",
"$",
"params",
".=",
"'&friends[]='",
".",
"$",
"friend",
";",
"}",
"}",
"$",
"opts",
"=",
"array",
"(",
"'http'",
"=>",
"array",
"(",
"'method'",
"=>",
"'POST'",
",",
"'header'",
"=>",
"$",
"header",
",",
"'content'",
"=>",
"$",
"params",
",",
")",
")",
";",
"$",
"context",
"=",
"stream_context_create",
"(",
"$",
"opts",
")",
";",
"return",
"file_get_contents",
"(",
"$",
"url",
",",
"false",
",",
"$",
"context",
")",
";",
"}"
] | Make a request to the Web Form API.
@param string $action
@param array $params
@param array $friends
@return string | [
"Make",
"a",
"request",
"to",
"the",
"Web",
"Form",
"API",
"."
] | a820ee196d3166f827c30af69902ffb417674890 | https://github.com/DoSomething/mobilecommons-php/blob/a820ee196d3166f827c30af69902ffb417674890/lib/MobileCommons/Request.php#L163-L189 | train |
yivi/VerySimpleHtmlWriter | src/VerySimpleHtmlWriter/Tag.php | Tag.addClass | public function addClass( string $class ): Tag
{
if ( ! isset( $this->attributes['class'] ) ) {
$this->attributes['class'] = $class;
} else {
$this->attributes['class'] .= " $class";
}
return $this;
} | php | public function addClass( string $class ): Tag
{
if ( ! isset( $this->attributes['class'] ) ) {
$this->attributes['class'] = $class;
} else {
$this->attributes['class'] .= " $class";
}
return $this;
} | [
"public",
"function",
"addClass",
"(",
"string",
"$",
"class",
")",
":",
"Tag",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
".=",
"\" $class\"",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Convenience method to add a "class" to a tag.
@param string $class
@return Tag | [
"Convenience",
"method",
"to",
"add",
"a",
"class",
"to",
"a",
"tag",
"."
] | d777e3f046e3fba25790cd10ee42ee226cba0710 | https://github.com/yivi/VerySimpleHtmlWriter/blob/d777e3f046e3fba25790cd10ee42ee226cba0710/src/VerySimpleHtmlWriter/Tag.php#L148-L158 | train |
crazy-cats/framework | src/Utility/Profile.php | Profile.start | static public function start( $name )
{
if ( !ObjectManager::getInstance()->get( Config::class )->getValue( 'profile' ) ) {
return;
}
if ( !isset( self::$profileNames[$name] ) ) {
self::$profileNames[$name] = 0;
}
$realName = $name . '_' . self::$profileNames[$name] ++;
array_push( self::$currentProfileNames, $realName );
self::$profiles[implode( self::PATH_SEPARATOR, self::$currentProfileNames )] = [
'start_at' => microtime( true ),
'start_used_memory' => memory_get_usage()
];
} | php | static public function start( $name )
{
if ( !ObjectManager::getInstance()->get( Config::class )->getValue( 'profile' ) ) {
return;
}
if ( !isset( self::$profileNames[$name] ) ) {
self::$profileNames[$name] = 0;
}
$realName = $name . '_' . self::$profileNames[$name] ++;
array_push( self::$currentProfileNames, $realName );
self::$profiles[implode( self::PATH_SEPARATOR, self::$currentProfileNames )] = [
'start_at' => microtime( true ),
'start_used_memory' => memory_get_usage()
];
} | [
"static",
"public",
"function",
"start",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"ObjectManager",
"::",
"getInstance",
"(",
")",
"->",
"get",
"(",
"Config",
"::",
"class",
")",
"->",
"getValue",
"(",
"'profile'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"profileNames",
"[",
"$",
"name",
"]",
")",
")",
"{",
"self",
"::",
"$",
"profileNames",
"[",
"$",
"name",
"]",
"=",
"0",
";",
"}",
"$",
"realName",
"=",
"$",
"name",
".",
"'_'",
".",
"self",
"::",
"$",
"profileNames",
"[",
"$",
"name",
"]",
"++",
";",
"array_push",
"(",
"self",
"::",
"$",
"currentProfileNames",
",",
"$",
"realName",
")",
";",
"self",
"::",
"$",
"profiles",
"[",
"implode",
"(",
"self",
"::",
"PATH_SEPARATOR",
",",
"self",
"::",
"$",
"currentProfileNames",
")",
"]",
"=",
"[",
"'start_at'",
"=>",
"microtime",
"(",
"true",
")",
",",
"'start_used_memory'",
"=>",
"memory_get_usage",
"(",
")",
"]",
";",
"}"
] | Set start point for a new profile
@param string $name | [
"Set",
"start",
"point",
"for",
"a",
"new",
"profile"
] | 5ea53d3f97689a301782c0d3d7b924d763420c66 | https://github.com/crazy-cats/framework/blob/5ea53d3f97689a301782c0d3d7b924d763420c66/src/Utility/Profile.php#L108-L124 | train |
crazy-cats/framework | src/Utility/Profile.php | Profile.end | static public function end( $name )
{
if ( !ObjectManager::getInstance()->get( Config::class )->getValue( 'profile' ) ) {
return;
}
if ( $name != self::getName( self::$currentProfileNames[count( self::$currentProfileNames ) - 1] ) ) {
throw new \Exception( sprintf( 'Not an expected end name `%s`.', $name ) );
}
$path = implode( self::PATH_SEPARATOR, self::$currentProfileNames );
self::$profiles[$path]['end_at'] = microtime( true );
self::$profiles[$path]['end_used_memory'] = memory_get_usage();
array_pop( self::$currentProfileNames );
} | php | static public function end( $name )
{
if ( !ObjectManager::getInstance()->get( Config::class )->getValue( 'profile' ) ) {
return;
}
if ( $name != self::getName( self::$currentProfileNames[count( self::$currentProfileNames ) - 1] ) ) {
throw new \Exception( sprintf( 'Not an expected end name `%s`.', $name ) );
}
$path = implode( self::PATH_SEPARATOR, self::$currentProfileNames );
self::$profiles[$path]['end_at'] = microtime( true );
self::$profiles[$path]['end_used_memory'] = memory_get_usage();
array_pop( self::$currentProfileNames );
} | [
"static",
"public",
"function",
"end",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"ObjectManager",
"::",
"getInstance",
"(",
")",
"->",
"get",
"(",
"Config",
"::",
"class",
")",
"->",
"getValue",
"(",
"'profile'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"name",
"!=",
"self",
"::",
"getName",
"(",
"self",
"::",
"$",
"currentProfileNames",
"[",
"count",
"(",
"self",
"::",
"$",
"currentProfileNames",
")",
"-",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Not an expected end name `%s`.'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"path",
"=",
"implode",
"(",
"self",
"::",
"PATH_SEPARATOR",
",",
"self",
"::",
"$",
"currentProfileNames",
")",
";",
"self",
"::",
"$",
"profiles",
"[",
"$",
"path",
"]",
"[",
"'end_at'",
"]",
"=",
"microtime",
"(",
"true",
")",
";",
"self",
"::",
"$",
"profiles",
"[",
"$",
"path",
"]",
"[",
"'end_used_memory'",
"]",
"=",
"memory_get_usage",
"(",
")",
";",
"array_pop",
"(",
"self",
"::",
"$",
"currentProfileNames",
")",
";",
"}"
] | Set end point for an exist profile
@param string $name | [
"Set",
"end",
"point",
"for",
"an",
"exist",
"profile"
] | 5ea53d3f97689a301782c0d3d7b924d763420c66 | https://github.com/crazy-cats/framework/blob/5ea53d3f97689a301782c0d3d7b924d763420c66/src/Utility/Profile.php#L130-L145 | train |
anime-db/item-folder-filler-bundle | src/Service/FillerFolder.php | FillerFolder.buildMenu | public function buildMenu(ItemInterface $node, ItemEntity $item)
{
if ($item->getPath() && $this->fs->exists($item->getPath())) {
$node->addChild('Fill folder', [
'route' => 'item_folder_filler_fill',
'routeParameters' => [
'id' => $item->getId(),
'name' => $item->getUrlName()
]
])
->setLinkAttribute('class', 'icon-label icon-fill');
}
} | php | public function buildMenu(ItemInterface $node, ItemEntity $item)
{
if ($item->getPath() && $this->fs->exists($item->getPath())) {
$node->addChild('Fill folder', [
'route' => 'item_folder_filler_fill',
'routeParameters' => [
'id' => $item->getId(),
'name' => $item->getUrlName()
]
])
->setLinkAttribute('class', 'icon-label icon-fill');
}
} | [
"public",
"function",
"buildMenu",
"(",
"ItemInterface",
"$",
"node",
",",
"ItemEntity",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
"&&",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"$",
"node",
"->",
"addChild",
"(",
"'Fill folder'",
",",
"[",
"'route'",
"=>",
"'item_folder_filler_fill'",
",",
"'routeParameters'",
"=>",
"[",
"'id'",
"=>",
"$",
"item",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"item",
"->",
"getUrlName",
"(",
")",
"]",
"]",
")",
"->",
"setLinkAttribute",
"(",
"'class'",
",",
"'icon-label icon-fill'",
")",
";",
"}",
"}"
] | Build menu for plugin
@param \Knp\Menu\ItemInterface $node
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@return \Knp\Menu\ItemInterface | [
"Build",
"menu",
"for",
"plugin"
] | 9b5d02628fa235171a42123aaa9b54ddab5d94d1 | https://github.com/anime-db/item-folder-filler-bundle/blob/9b5d02628fa235171a42123aaa9b54ddab5d94d1/src/Service/FillerFolder.php#L104-L116 | train |
anime-db/item-folder-filler-bundle | src/Service/FillerFolder.php | FillerFolder.getCover | protected function getCover(ItemEntity $item)
{
$from = $this->root.$item->getDownloadPath().'/'.$item->getCover();
if (!$this->fs->exists($from)) {
return '';
}
// copy cover
$target = $item->getPath().'/';
$filename = self::COVER_FILENAME.'.'.pathinfo($item->getCover(), PATHINFO_EXTENSION);
if (is_file($item->getPath())) {
$target = dirname($item->getPath()).'/';
$filename = pathinfo($item->getPath(), PATHINFO_FILENAME).'-'.$filename;
}
$this->fs->copy($from, $target.$filename);
return $filename;
} | php | protected function getCover(ItemEntity $item)
{
$from = $this->root.$item->getDownloadPath().'/'.$item->getCover();
if (!$this->fs->exists($from)) {
return '';
}
// copy cover
$target = $item->getPath().'/';
$filename = self::COVER_FILENAME.'.'.pathinfo($item->getCover(), PATHINFO_EXTENSION);
if (is_file($item->getPath())) {
$target = dirname($item->getPath()).'/';
$filename = pathinfo($item->getPath(), PATHINFO_FILENAME).'-'.$filename;
}
$this->fs->copy($from, $target.$filename);
return $filename;
} | [
"protected",
"function",
"getCover",
"(",
"ItemEntity",
"$",
"item",
")",
"{",
"$",
"from",
"=",
"$",
"this",
"->",
"root",
".",
"$",
"item",
"->",
"getDownloadPath",
"(",
")",
".",
"'/'",
".",
"$",
"item",
"->",
"getCover",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"from",
")",
")",
"{",
"return",
"''",
";",
"}",
"// copy cover",
"$",
"target",
"=",
"$",
"item",
"->",
"getPath",
"(",
")",
".",
"'/'",
";",
"$",
"filename",
"=",
"self",
"::",
"COVER_FILENAME",
".",
"'.'",
".",
"pathinfo",
"(",
"$",
"item",
"->",
"getCover",
"(",
")",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"$",
"target",
"=",
"dirname",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
")",
".",
"'/'",
";",
"$",
"filename",
"=",
"pathinfo",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
",",
"PATHINFO_FILENAME",
")",
".",
"'-'",
".",
"$",
"filename",
";",
"}",
"$",
"this",
"->",
"fs",
"->",
"copy",
"(",
"$",
"from",
",",
"$",
"target",
".",
"$",
"filename",
")",
";",
"return",
"$",
"filename",
";",
"}"
] | Get cover filename
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@return string | [
"Get",
"cover",
"filename"
] | 9b5d02628fa235171a42123aaa9b54ddab5d94d1 | https://github.com/anime-db/item-folder-filler-bundle/blob/9b5d02628fa235171a42123aaa9b54ddab5d94d1/src/Service/FillerFolder.php#L144-L160 | train |
anime-db/item-folder-filler-bundle | src/Service/FillerFolder.php | FillerFolder.getInfo | protected function getInfo(ItemEntity $item)
{
$filename = self::INFO_FILENAME.'.html';
if (is_file($item->getPath())) {
return dirname($item->getPath()).pathinfo($item->getPath(), PATHINFO_FILENAME).'-'.$filename;
} else {
return $item->getPath().'/'.$filename;
}
} | php | protected function getInfo(ItemEntity $item)
{
$filename = self::INFO_FILENAME.'.html';
if (is_file($item->getPath())) {
return dirname($item->getPath()).pathinfo($item->getPath(), PATHINFO_FILENAME).'-'.$filename;
} else {
return $item->getPath().'/'.$filename;
}
} | [
"protected",
"function",
"getInfo",
"(",
"ItemEntity",
"$",
"item",
")",
"{",
"$",
"filename",
"=",
"self",
"::",
"INFO_FILENAME",
".",
"'.html'",
";",
"if",
"(",
"is_file",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"return",
"dirname",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
")",
".",
"pathinfo",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
",",
"PATHINFO_FILENAME",
")",
".",
"'-'",
".",
"$",
"filename",
";",
"}",
"else",
"{",
"return",
"$",
"item",
"->",
"getPath",
"(",
")",
".",
"'/'",
".",
"$",
"filename",
";",
"}",
"}"
] | Get info filename
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@return string | [
"Get",
"info",
"filename"
] | 9b5d02628fa235171a42123aaa9b54ddab5d94d1 | https://github.com/anime-db/item-folder-filler-bundle/blob/9b5d02628fa235171a42123aaa9b54ddab5d94d1/src/Service/FillerFolder.php#L169-L177 | train |
phpgears/event | src/AbstractEventHandler.php | AbstractEventHandler.isEventSupported | private function isEventSupported(Event $event): bool
{
$supported = false;
foreach ($this->getSupportedEventTypes() as $supportedEventType) {
if (\is_a($event, $supportedEventType)) {
$supported = true;
break;
}
}
return $supported;
} | php | private function isEventSupported(Event $event): bool
{
$supported = false;
foreach ($this->getSupportedEventTypes() as $supportedEventType) {
if (\is_a($event, $supportedEventType)) {
$supported = true;
break;
}
}
return $supported;
} | [
"private",
"function",
"isEventSupported",
"(",
"Event",
"$",
"event",
")",
":",
"bool",
"{",
"$",
"supported",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"getSupportedEventTypes",
"(",
")",
"as",
"$",
"supportedEventType",
")",
"{",
"if",
"(",
"\\",
"is_a",
"(",
"$",
"event",
",",
"$",
"supportedEventType",
")",
")",
"{",
"$",
"supported",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"supported",
";",
"}"
] | Is event supported.
@param Event $event
@return bool | [
"Is",
"event",
"supported",
"."
] | 9b25301837748a67b3b48cc46ad837c859c4522d | https://github.com/phpgears/event/blob/9b25301837748a67b3b48cc46ad837c859c4522d/src/AbstractEventHandler.php#L45-L58 | train |
ibonly/Potato-ORM | src/Helper/Schema.php | Schema.dateTime | public function dateTime($value, $type = NULL)
{
$apend = "";
switch ($type) {
case 'time':
$apend = 'time';
break;
case 'timestamp':
$apend = 'timestamp';
break;
case 'date':
$apend = 'date';
break;
case 'datetime':
$apend = 'datetime';
break;
case 'year':
$apend = 'year(4)';
break;
default:
$apend = 'timestamp';
break;
}
return $value . " " . $apend . " NOT NULL";
} | php | public function dateTime($value, $type = NULL)
{
$apend = "";
switch ($type) {
case 'time':
$apend = 'time';
break;
case 'timestamp':
$apend = 'timestamp';
break;
case 'date':
$apend = 'date';
break;
case 'datetime':
$apend = 'datetime';
break;
case 'year':
$apend = 'year(4)';
break;
default:
$apend = 'timestamp';
break;
}
return $value . " " . $apend . " NOT NULL";
} | [
"public",
"function",
"dateTime",
"(",
"$",
"value",
",",
"$",
"type",
"=",
"NULL",
")",
"{",
"$",
"apend",
"=",
"\"\"",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'time'",
":",
"$",
"apend",
"=",
"'time'",
";",
"break",
";",
"case",
"'timestamp'",
":",
"$",
"apend",
"=",
"'timestamp'",
";",
"break",
";",
"case",
"'date'",
":",
"$",
"apend",
"=",
"'date'",
";",
"break",
";",
"case",
"'datetime'",
":",
"$",
"apend",
"=",
"'datetime'",
";",
"break",
";",
"case",
"'year'",
":",
"$",
"apend",
"=",
"'year(4)'",
";",
"break",
";",
"default",
":",
"$",
"apend",
"=",
"'timestamp'",
";",
"break",
";",
"}",
"return",
"$",
"value",
".",
"\" \"",
".",
"$",
"apend",
".",
"\" NOT NULL\"",
";",
"}"
] | dateTime description]
@param [type] $value [description]
@param [type] $type [description]
@return [type] [description] | [
"dateTime",
"description",
"]"
] | 644962a99e1c0191b732d7729cd466d52c5d8652 | https://github.com/ibonly/Potato-ORM/blob/644962a99e1c0191b732d7729cd466d52c5d8652/src/Helper/Schema.php#L182-L206 | train |
Kris-Kuiper/sFire-Framework | src/Form/Traits/FormTrait.php | FormTrait.value | public function value($value = null) {
if(null !== $value && false === is_string($value) && false === is_numeric($value)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or number, "%s" given', __METHOD__, gettype($value)), E_USER_ERROR);
}
$this -> value = (string) $value;
$this -> attributes['value'] = (string) $value;
return $this;
} | php | public function value($value = null) {
if(null !== $value && false === is_string($value) && false === is_numeric($value)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or number, "%s" given', __METHOD__, gettype($value)), E_USER_ERROR);
}
$this -> value = (string) $value;
$this -> attributes['value'] = (string) $value;
return $this;
} | [
"public",
"function",
"value",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"value",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"value",
")",
"&&",
"false",
"===",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string or number, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"value",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"$",
"this",
"->",
"attributes",
"[",
"'value'",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set a new value for input
@param string $value
@return sFire\Form\Traits\FormTrait | [
"Set",
"a",
"new",
"value",
"for",
"input"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Traits/FormTrait.php#L85-L95 | train |
Kris-Kuiper/sFire-Framework | src/Form/Traits/FormTrait.php | FormTrait.name | public function name($name = null) {
if(null !== $name && false === is_string($name) && false === is_numeric($name)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or number, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
$this -> name = $name;
$this -> attributes['name'] = $name;
return $this;
} | php | public function name($name = null) {
if(null !== $name && false === is_string($name) && false === is_numeric($name)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or number, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
$this -> name = $name;
$this -> attributes['name'] = $name;
return $this;
} | [
"public",
"function",
"name",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"name",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"name",
")",
"&&",
"false",
"===",
"is_numeric",
"(",
"$",
"name",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string or number, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"name",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"attributes",
"[",
"'name'",
"]",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] | Set a new name for input
@param string $name
@return sFire\Form\Traits\FormTrait | [
"Set",
"a",
"new",
"name",
"for",
"input"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Traits/FormTrait.php#L103-L113 | train |
Kris-Kuiper/sFire-Framework | src/Form/Traits/FormTrait.php | FormTrait.attributes | public function attributes($attributes) {
if(false === is_array($attributes)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($attributes)), E_USER_ERROR);
}
$this -> attributes = array_merge($this -> attributes, $attributes);
return $this;
} | php | public function attributes($attributes) {
if(false === is_array($attributes)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($attributes)), E_USER_ERROR);
}
$this -> attributes = array_merge($this -> attributes, $attributes);
return $this;
} | [
"public",
"function",
"attributes",
"(",
"$",
"attributes",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"attributes",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"attributes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set new attributes for input
@param array $attributes
@return sFire\Form\Traits\FormTrait | [
"Set",
"new",
"attributes",
"for",
"input"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Traits/FormTrait.php#L121-L130 | train |
Kris-Kuiper/sFire-Framework | src/Form/Traits/FormTrait.php | FormTrait.filled | public function filled($filled) {
if(false === is_bool($filled)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($filled)), E_USER_ERROR);
}
$this -> filled = $filled;
return $this;
} | php | public function filled($filled) {
if(false === is_bool($filled)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($filled)), E_USER_ERROR);
}
$this -> filled = $filled;
return $this;
} | [
"public",
"function",
"filled",
"(",
"$",
"filled",
")",
"{",
"if",
"(",
"false",
"===",
"is_bool",
"(",
"$",
"filled",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"filled",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"filled",
"=",
"$",
"filled",
";",
"return",
"$",
"this",
";",
"}"
] | Set if input should be automaticly filled or not
@param boolean $filled
@return sFire\Form\Traits\FormTrait | [
"Set",
"if",
"input",
"should",
"be",
"automaticly",
"filled",
"or",
"not"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Traits/FormTrait.php#L138-L147 | train |
Kris-Kuiper/sFire-Framework | src/Form/Traits/FormTrait.php | FormTrait.onerror | public function onerror($attributes) {
if(false === is_array($attributes)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($attributes)), E_USER_ERROR);
}
if(true === isset($this -> attributes['name'])) {
$helper = new StringToArray();
$data = $helper -> execute($this -> attributes['name'], null, MessageFile :: getErrors(true));
$data = $helper -> execute($this -> attributes['name'], null, MessageForm :: getErrors(true));
if(null !== $data) {
$this -> attributes = array_merge($this -> attributes, $attributes);
}
}
return $this;
} | php | public function onerror($attributes) {
if(false === is_array($attributes)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($attributes)), E_USER_ERROR);
}
if(true === isset($this -> attributes['name'])) {
$helper = new StringToArray();
$data = $helper -> execute($this -> attributes['name'], null, MessageFile :: getErrors(true));
$data = $helper -> execute($this -> attributes['name'], null, MessageForm :: getErrors(true));
if(null !== $data) {
$this -> attributes = array_merge($this -> attributes, $attributes);
}
}
return $this;
} | [
"public",
"function",
"onerror",
"(",
"$",
"attributes",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"attributes",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"helper",
"=",
"new",
"StringToArray",
"(",
")",
";",
"$",
"data",
"=",
"$",
"helper",
"->",
"execute",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'name'",
"]",
",",
"null",
",",
"MessageFile",
"::",
"getErrors",
"(",
"true",
")",
")",
";",
"$",
"data",
"=",
"$",
"helper",
"->",
"execute",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'name'",
"]",
",",
"null",
",",
"MessageForm",
"::",
"getErrors",
"(",
"true",
")",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"attributes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"attributes",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Merges the given attributes with the already existing attributes on error
@param array $attributes
@return sFire\Form\Traits\FormTrait | [
"Merges",
"the",
"given",
"attributes",
"with",
"the",
"already",
"existing",
"attributes",
"on",
"error"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Traits/FormTrait.php#L155-L173 | train |
Kris-Kuiper/sFire-Framework | src/Form/Traits/FormTrait.php | FormTrait.fill | private function fill() {
//Prefill value
if(true === $this -> filled) {
if(true === isset($this -> attributes['name'])) {
if(true === Request :: isPost()) {
$this -> attributes['value'] = Request :: fromPost($this -> attributes['name']);
}
}
}
} | php | private function fill() {
//Prefill value
if(true === $this -> filled) {
if(true === isset($this -> attributes['name'])) {
if(true === Request :: isPost()) {
$this -> attributes['value'] = Request :: fromPost($this -> attributes['name']);
}
}
}
} | [
"private",
"function",
"fill",
"(",
")",
"{",
"//Prefill value\r",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"filled",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'name'",
"]",
")",
")",
"{",
"if",
"(",
"true",
"===",
"Request",
"::",
"isPost",
"(",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'value'",
"]",
"=",
"Request",
"::",
"fromPost",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Sets the value if allowed | [
"Sets",
"the",
"value",
"if",
"allowed"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Form/Traits/FormTrait.php#L179-L191 | train |
bandama-framework/bandama-framework | src/foundation/session/Cookie.php | Cookie.set | public function set($key, $value, $params = array()) {
$expire = 0;
$path = null;
$domain = null;
$secure = false;
$httponly = false;
if (isset($params['expire'])) {
$expire = $params['expire'];
}
if (isset($params['path'])) {
$path = $params['path'];
}
if (isset($params['domain'])) {
$domain = $params['domain'];
}
if (isset($params['secure'])) {
$secure = $params['secure'];
}
if (isset($params['httponly'])) {
$httponly = $params['httponly'];
}
setcookie($key, serialize($value), $expire, $path, $domain, $secure, $httponly);
} | php | public function set($key, $value, $params = array()) {
$expire = 0;
$path = null;
$domain = null;
$secure = false;
$httponly = false;
if (isset($params['expire'])) {
$expire = $params['expire'];
}
if (isset($params['path'])) {
$path = $params['path'];
}
if (isset($params['domain'])) {
$domain = $params['domain'];
}
if (isset($params['secure'])) {
$secure = $params['secure'];
}
if (isset($params['httponly'])) {
$httponly = $params['httponly'];
}
setcookie($key, serialize($value), $expire, $path, $domain, $secure, $httponly);
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"expire",
"=",
"0",
";",
"$",
"path",
"=",
"null",
";",
"$",
"domain",
"=",
"null",
";",
"$",
"secure",
"=",
"false",
";",
"$",
"httponly",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'expire'",
"]",
")",
")",
"{",
"$",
"expire",
"=",
"$",
"params",
"[",
"'expire'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"path",
"=",
"$",
"params",
"[",
"'path'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'domain'",
"]",
")",
")",
"{",
"$",
"domain",
"=",
"$",
"params",
"[",
"'domain'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'secure'",
"]",
")",
")",
"{",
"$",
"secure",
"=",
"$",
"params",
"[",
"'secure'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'httponly'",
"]",
")",
")",
"{",
"$",
"httponly",
"=",
"$",
"params",
"[",
"'httponly'",
"]",
";",
"}",
"setcookie",
"(",
"$",
"key",
",",
"serialize",
"(",
"$",
"value",
")",
",",
"$",
"expire",
",",
"$",
"path",
",",
"$",
"domain",
",",
"$",
"secure",
",",
"$",
"httponly",
")",
";",
"}"
] | Set variable to storage
@var string $key Key
@var mixed $value Value
@var array $params Parameters (expire, path, domain, secure, httponly)
@see SessionInterface::set | [
"Set",
"variable",
"to",
"storage"
] | 234ed703baf9e31268941c9d5f6d5e004cc53066 | https://github.com/bandama-framework/bandama-framework/blob/234ed703baf9e31268941c9d5f6d5e004cc53066/src/foundation/session/Cookie.php#L36-L60 | train |
bandama-framework/bandama-framework | src/foundation/session/Cookie.php | Cookie.delete | public function delete($key) {
if (isset($_COOKIE[$key])) {
unset($_COOKIE[$key]);
setcookie($key, '', time() - 3600);
}
} | php | public function delete($key) {
if (isset($_COOKIE[$key])) {
unset($_COOKIE[$key]);
setcookie($key, '', time() - 3600);
}
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_COOKIE",
"[",
"$",
"key",
"]",
")",
";",
"setcookie",
"(",
"$",
"key",
",",
"''",
",",
"time",
"(",
")",
"-",
"3600",
")",
";",
"}",
"}"
] | Remove variable from storage
@see SessionInterface::delete | [
"Remove",
"variable",
"from",
"storage"
] | 234ed703baf9e31268941c9d5f6d5e004cc53066 | https://github.com/bandama-framework/bandama-framework/blob/234ed703baf9e31268941c9d5f6d5e004cc53066/src/foundation/session/Cookie.php#L67-L72 | train |
CalderaWP/caldera-interop | src/Traits/ProvidesFormsDataSource.php | ProvidesFormsDataSource.getDataSource | public function getDataSource(string $source) : Source
{
switch ($source) {
case 'form':
case 'forms':
return $this
->getDataSources()
->getFormsDataSource();
break;
case 'entry':
case 'entries':
return $this
->getDataSources()
->getEntryDataSource();
break;
case 'entryValue':
case 'entryValues':
return $this
->getDataSources()
->getEntryValuesDataSource();
}
} | php | public function getDataSource(string $source) : Source
{
switch ($source) {
case 'form':
case 'forms':
return $this
->getDataSources()
->getFormsDataSource();
break;
case 'entry':
case 'entries':
return $this
->getDataSources()
->getEntryDataSource();
break;
case 'entryValue':
case 'entryValues':
return $this
->getDataSources()
->getEntryValuesDataSource();
}
} | [
"public",
"function",
"getDataSource",
"(",
"string",
"$",
"source",
")",
":",
"Source",
"{",
"switch",
"(",
"$",
"source",
")",
"{",
"case",
"'form'",
":",
"case",
"'forms'",
":",
"return",
"$",
"this",
"->",
"getDataSources",
"(",
")",
"->",
"getFormsDataSource",
"(",
")",
";",
"break",
";",
"case",
"'entry'",
":",
"case",
"'entries'",
":",
"return",
"$",
"this",
"->",
"getDataSources",
"(",
")",
"->",
"getEntryDataSource",
"(",
")",
";",
"break",
";",
"case",
"'entryValue'",
":",
"case",
"'entryValues'",
":",
"return",
"$",
"this",
"->",
"getDataSources",
"(",
")",
"->",
"getEntryValuesDataSource",
"(",
")",
";",
"}",
"}"
] | Get a form, form entry or form entry value data source.
@param string $source
@return Source | [
"Get",
"a",
"form",
"form",
"entry",
"or",
"form",
"entry",
"value",
"data",
"source",
"."
] | d25c4bc930200b314fbd42d084080b5d85261c94 | https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/Traits/ProvidesFormsDataSource.php#L24-L45 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/Utils.php | Utils.instantiate | public static function instantiate($className, array $namedArguments)
{
$reflectionClass = new ReflectionClass($className);
$parameters = $reflectionClass->getConstructor()->getParameters();
$positionalDefaultFilledArguments = array();
foreach ($parameters as $parameter) {
// Do we have an argument set? If so use that.
if (isset($namedArguments[$parameter->name])) {
$positionalDefaultFilledArguments[] = $namedArguments[$parameter->name];
continue;
}
// Otherwise use the default.
$positionalDefaultFilledArguments[] = $parameter->getDefaultValue();
}
return $reflectionClass->newInstanceArgs($positionalDefaultFilledArguments);
} | php | public static function instantiate($className, array $namedArguments)
{
$reflectionClass = new ReflectionClass($className);
$parameters = $reflectionClass->getConstructor()->getParameters();
$positionalDefaultFilledArguments = array();
foreach ($parameters as $parameter) {
// Do we have an argument set? If so use that.
if (isset($namedArguments[$parameter->name])) {
$positionalDefaultFilledArguments[] = $namedArguments[$parameter->name];
continue;
}
// Otherwise use the default.
$positionalDefaultFilledArguments[] = $parameter->getDefaultValue();
}
return $reflectionClass->newInstanceArgs($positionalDefaultFilledArguments);
} | [
"public",
"static",
"function",
"instantiate",
"(",
"$",
"className",
",",
"array",
"$",
"namedArguments",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"parameters",
"=",
"$",
"reflectionClass",
"->",
"getConstructor",
"(",
")",
"->",
"getParameters",
"(",
")",
";",
"$",
"positionalDefaultFilledArguments",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"// Do we have an argument set? If so use that.",
"if",
"(",
"isset",
"(",
"$",
"namedArguments",
"[",
"$",
"parameter",
"->",
"name",
"]",
")",
")",
"{",
"$",
"positionalDefaultFilledArguments",
"[",
"]",
"=",
"$",
"namedArguments",
"[",
"$",
"parameter",
"->",
"name",
"]",
";",
"continue",
";",
"}",
"// Otherwise use the default.",
"$",
"positionalDefaultFilledArguments",
"[",
"]",
"=",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"return",
"$",
"reflectionClass",
"->",
"newInstanceArgs",
"(",
"$",
"positionalDefaultFilledArguments",
")",
";",
"}"
] | Instantiate a class with named arguments.
An answer to a problem that should not exist (legacy large Entities).
@param string $className
@param array $namedArguments
@return object | [
"Instantiate",
"a",
"class",
"with",
"named",
"arguments",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/Utils.php#L37-L55 | train |
ScaraMVC/Framework | src/Scara/Support/ServiceProvider.php | ServiceProvider.create | public function create($name, $callback)
{
$this->_name = $name;
$this->_class = $callback();
$GLOBALS['providers'][$this->_name] = $this->_class;
} | php | public function create($name, $callback)
{
$this->_name = $name;
$this->_class = $callback();
$GLOBALS['providers'][$this->_name] = $this->_class;
} | [
"public",
"function",
"create",
"(",
"$",
"name",
",",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"_name",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"_class",
"=",
"$",
"callback",
"(",
")",
";",
"$",
"GLOBALS",
"[",
"'providers'",
"]",
"[",
"$",
"this",
"->",
"_name",
"]",
"=",
"$",
"this",
"->",
"_class",
";",
"}"
] | Creates the provider and registers the provider to the global area.
@param string $name - The name of the service provider
@param \Closure $callback - The callback for calling the provider's given class
@return void | [
"Creates",
"the",
"provider",
"and",
"registers",
"the",
"provider",
"to",
"the",
"global",
"area",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Support/ServiceProvider.php#L39-L45 | train |
faizalpribadi/Cache | Driver/OpCache/Apc.php | Apc.set | public function set($id, $data, $lifeTime = 0)
{
if (!function_exists('apc_store')) {
throw new ApcCacheException('function [apc_store] not found !');
}
return apc_store($id, $data, $lifeTime);
} | php | public function set($id, $data, $lifeTime = 0)
{
if (!function_exists('apc_store')) {
throw new ApcCacheException('function [apc_store] not found !');
}
return apc_store($id, $data, $lifeTime);
} | [
"public",
"function",
"set",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"lifeTime",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'apc_store'",
")",
")",
"{",
"throw",
"new",
"ApcCacheException",
"(",
"'function [apc_store] not found !'",
")",
";",
"}",
"return",
"apc_store",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"lifeTime",
")",
";",
"}"
] | Set and store cache key with data content in cache key
@param string $id
@param string $data
@param int $lifeTime
@return array|bool
@throws \Mozart\Library\Cache\Exception\ApcCacheException | [
"Set",
"and",
"store",
"cache",
"key",
"with",
"data",
"content",
"in",
"cache",
"key"
] | e62a4d71739e542ca6e7bac77f5cc522accef8cb | https://github.com/faizalpribadi/Cache/blob/e62a4d71739e542ca6e7bac77f5cc522accef8cb/Driver/OpCache/Apc.php#L47-L54 | train |
jenskooij/cloudcontrol | src/storage/storage/AbstractStorage.php | AbstractStorage.validateFilename | protected function validateFilename($filename, $path)
{
$fileParts = explode('.', $filename);
if (count($fileParts) > 1) {
$extension = end($fileParts);
array_pop($fileParts);
$fileNameWithoutExtension = implode('-', $fileParts);
$fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension);
$filename = $fileNameWithoutExtension . '.' . $extension;
} else {
$filename = StringUtil::slugify($filename);
}
if (file_exists($path . '/' . $filename)) {
$fileParts = explode('.', $filename);
if (count($fileParts) > 1) {
$extension = end($fileParts);
array_pop($fileParts);
$fileNameWithoutExtension = implode('-', $fileParts);
$fileNameWithoutExtension .= '-copy';
$filename = $fileNameWithoutExtension . '.' . $extension;
} else {
$filename .= '-copy';
}
return $this->validateFilename($filename, $path);
}
return $filename;
} | php | protected function validateFilename($filename, $path)
{
$fileParts = explode('.', $filename);
if (count($fileParts) > 1) {
$extension = end($fileParts);
array_pop($fileParts);
$fileNameWithoutExtension = implode('-', $fileParts);
$fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension);
$filename = $fileNameWithoutExtension . '.' . $extension;
} else {
$filename = StringUtil::slugify($filename);
}
if (file_exists($path . '/' . $filename)) {
$fileParts = explode('.', $filename);
if (count($fileParts) > 1) {
$extension = end($fileParts);
array_pop($fileParts);
$fileNameWithoutExtension = implode('-', $fileParts);
$fileNameWithoutExtension .= '-copy';
$filename = $fileNameWithoutExtension . '.' . $extension;
} else {
$filename .= '-copy';
}
return $this->validateFilename($filename, $path);
}
return $filename;
} | [
"protected",
"function",
"validateFilename",
"(",
"$",
"filename",
",",
"$",
"path",
")",
"{",
"$",
"fileParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"filename",
")",
";",
"if",
"(",
"count",
"(",
"$",
"fileParts",
")",
">",
"1",
")",
"{",
"$",
"extension",
"=",
"end",
"(",
"$",
"fileParts",
")",
";",
"array_pop",
"(",
"$",
"fileParts",
")",
";",
"$",
"fileNameWithoutExtension",
"=",
"implode",
"(",
"'-'",
",",
"$",
"fileParts",
")",
";",
"$",
"fileNameWithoutExtension",
"=",
"StringUtil",
"::",
"slugify",
"(",
"$",
"fileNameWithoutExtension",
")",
";",
"$",
"filename",
"=",
"$",
"fileNameWithoutExtension",
".",
"'.'",
".",
"$",
"extension",
";",
"}",
"else",
"{",
"$",
"filename",
"=",
"StringUtil",
"::",
"slugify",
"(",
"$",
"filename",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"path",
".",
"'/'",
".",
"$",
"filename",
")",
")",
"{",
"$",
"fileParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"filename",
")",
";",
"if",
"(",
"count",
"(",
"$",
"fileParts",
")",
">",
"1",
")",
"{",
"$",
"extension",
"=",
"end",
"(",
"$",
"fileParts",
")",
";",
"array_pop",
"(",
"$",
"fileParts",
")",
";",
"$",
"fileNameWithoutExtension",
"=",
"implode",
"(",
"'-'",
",",
"$",
"fileParts",
")",
";",
"$",
"fileNameWithoutExtension",
".=",
"'-copy'",
";",
"$",
"filename",
"=",
"$",
"fileNameWithoutExtension",
".",
"'.'",
".",
"$",
"extension",
";",
"}",
"else",
"{",
"$",
"filename",
".=",
"'-copy'",
";",
"}",
"return",
"$",
"this",
"->",
"validateFilename",
"(",
"$",
"filename",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"filename",
";",
"}"
] | Converts filename to lowercase, remove non-ascii chars
And adds "-copy" if the file already exists
@param $filename
@param $path
@return string | [
"Converts",
"filename",
"to",
"lowercase",
"remove",
"non",
"-",
"ascii",
"chars",
"And",
"adds",
"-",
"copy",
"if",
"the",
"file",
"already",
"exists"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/AbstractStorage.php#L33-L62 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Resource/Relationship.php | Relationship.pushData | public function pushData(EntityInterface $entity)
{
if ($this->isMany()) {
$this->data[] = $entity;
return $this;
}
$this->data = $entity;
return $this;
} | php | public function pushData(EntityInterface $entity)
{
if ($this->isMany()) {
$this->data[] = $entity;
return $this;
}
$this->data = $entity;
return $this;
} | [
"public",
"function",
"pushData",
"(",
"EntityInterface",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isMany",
"(",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"]",
"=",
"$",
"entity",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"data",
"=",
"$",
"entity",
";",
"return",
"$",
"this",
";",
"}"
] | Applys the relationship data.
@param EntityInterface $entity
@return self | [
"Applys",
"the",
"relationship",
"data",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Resource/Relationship.php#L94-L102 | train |
Kris-Kuiper/sFire-Framework | src/Template/Template.php | Template.render | public function render() {
$parse = true;
if($this -> getFile() -> exists()) {
if($this -> getFile() -> entity() -> getModificationTime() >= @filemtime($this -> viewmodel -> getFile())) {
$parse = false;
}
}
if(true === $parse) {
$this -> parse();
$this -> write();
}
return $this;
} | php | public function render() {
$parse = true;
if($this -> getFile() -> exists()) {
if($this -> getFile() -> entity() -> getModificationTime() >= @filemtime($this -> viewmodel -> getFile())) {
$parse = false;
}
}
if(true === $parse) {
$this -> parse();
$this -> write();
}
return $this;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"parse",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"getFile",
"(",
")",
"->",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getFile",
"(",
")",
"->",
"entity",
"(",
")",
"->",
"getModificationTime",
"(",
")",
">=",
"@",
"filemtime",
"(",
"$",
"this",
"->",
"viewmodel",
"->",
"getFile",
"(",
")",
")",
")",
"{",
"$",
"parse",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"true",
"===",
"$",
"parse",
")",
"{",
"$",
"this",
"->",
"parse",
"(",
")",
";",
"$",
"this",
"->",
"write",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Renders the view model
@return sFire\Template\Template | [
"Renders",
"the",
"view",
"model"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Template/Template.php#L91-L109 | train |
Kris-Kuiper/sFire-Framework | src/Template/Template.php | Template.getFileName | public function getFileName() {
if(null === $this -> filename && null !== $this -> viewmodel) {
$this -> filename = md5($this -> viewmodel -> getFile());
}
return $this -> filename;
} | php | public function getFileName() {
if(null === $this -> filename && null !== $this -> viewmodel) {
$this -> filename = md5($this -> viewmodel -> getFile());
}
return $this -> filename;
} | [
"public",
"function",
"getFileName",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"filename",
"&&",
"null",
"!==",
"$",
"this",
"->",
"viewmodel",
")",
"{",
"$",
"this",
"->",
"filename",
"=",
"md5",
"(",
"$",
"this",
"->",
"viewmodel",
"->",
"getFile",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filename",
";",
"}"
] | Generates filename and returns it
@return string | [
"Generates",
"filename",
"and",
"returns",
"it"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Template/Template.php#L116-L123 | train |
Kris-Kuiper/sFire-Framework | src/Template/Template.php | Template.getFile | public function getFile() {
if(null === $this -> file) {
$file = $this -> getFileName();
$this -> file = new File($this -> directory . $file);
}
return $this -> file;
} | php | public function getFile() {
if(null === $this -> file) {
$file = $this -> getFileName();
$this -> file = new File($this -> directory . $file);
}
return $this -> file;
} | [
"public",
"function",
"getFile",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"file",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileName",
"(",
")",
";",
"$",
"this",
"->",
"file",
"=",
"new",
"File",
"(",
"$",
"this",
"->",
"directory",
".",
"$",
"file",
")",
";",
"}",
"return",
"$",
"this",
"->",
"file",
";",
"}"
] | Create file object from current directory and file and returns it
@return sFire\System\File | [
"Create",
"file",
"object",
"from",
"current",
"directory",
"and",
"file",
"and",
"returns",
"it"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Template/Template.php#L130-L139 | train |
Kris-Kuiper/sFire-Framework | src/Template/Template.php | Template.parse | private function parse() {
$lines = file($this -> viewmodel -> getFile());
$this -> code = '';
$classes = [
'MatchEcho',
'MatchForeach',
'MatchEndForeach',
'MatchFor',
'MatchEndFor',
'MatchIf',
'MatchIsset',
'MatchNotIsset',
'MatchEmpty',
'MatchNotEmpty',
'MatchElseIf',
'MatchElse',
'MatchEndIf',
'MatchEndIsset',
'MatchEndNotIsset',
'MatchEndEmpty',
'MatchEndNotEmpty',
'MatchForm',
'MatchTranslation',
'MatchEscape',
'MatchRouter',
'MatchHelper',
'MatchPartial',
'MatchFails',
'MatchPasses',
'MatchPHPTags'
];
foreach($lines as $linenumber => $line) {
foreach($classes as $class) {
$class = self :: NAMESPACE_MATCH . $class;
$match = new $class($line);
$line = $match -> replace() -> getLine();
}
//User defined functions
foreach(TemplateData :: getTemplateFunctions() as $action => $closure) {
$class = self :: NAMESPACE_MATCH . 'MatchUserDefined';
$match = new $class($line, $action);
$line = $match -> replace() -> getLine();
}
$this -> code .= trim($line) . "\n";
}
$this -> code = trim($this -> code);
return $this -> code;
} | php | private function parse() {
$lines = file($this -> viewmodel -> getFile());
$this -> code = '';
$classes = [
'MatchEcho',
'MatchForeach',
'MatchEndForeach',
'MatchFor',
'MatchEndFor',
'MatchIf',
'MatchIsset',
'MatchNotIsset',
'MatchEmpty',
'MatchNotEmpty',
'MatchElseIf',
'MatchElse',
'MatchEndIf',
'MatchEndIsset',
'MatchEndNotIsset',
'MatchEndEmpty',
'MatchEndNotEmpty',
'MatchForm',
'MatchTranslation',
'MatchEscape',
'MatchRouter',
'MatchHelper',
'MatchPartial',
'MatchFails',
'MatchPasses',
'MatchPHPTags'
];
foreach($lines as $linenumber => $line) {
foreach($classes as $class) {
$class = self :: NAMESPACE_MATCH . $class;
$match = new $class($line);
$line = $match -> replace() -> getLine();
}
//User defined functions
foreach(TemplateData :: getTemplateFunctions() as $action => $closure) {
$class = self :: NAMESPACE_MATCH . 'MatchUserDefined';
$match = new $class($line, $action);
$line = $match -> replace() -> getLine();
}
$this -> code .= trim($line) . "\n";
}
$this -> code = trim($this -> code);
return $this -> code;
} | [
"private",
"function",
"parse",
"(",
")",
"{",
"$",
"lines",
"=",
"file",
"(",
"$",
"this",
"->",
"viewmodel",
"->",
"getFile",
"(",
")",
")",
";",
"$",
"this",
"->",
"code",
"=",
"''",
";",
"$",
"classes",
"=",
"[",
"'MatchEcho'",
",",
"'MatchForeach'",
",",
"'MatchEndForeach'",
",",
"'MatchFor'",
",",
"'MatchEndFor'",
",",
"'MatchIf'",
",",
"'MatchIsset'",
",",
"'MatchNotIsset'",
",",
"'MatchEmpty'",
",",
"'MatchNotEmpty'",
",",
"'MatchElseIf'",
",",
"'MatchElse'",
",",
"'MatchEndIf'",
",",
"'MatchEndIsset'",
",",
"'MatchEndNotIsset'",
",",
"'MatchEndEmpty'",
",",
"'MatchEndNotEmpty'",
",",
"'MatchForm'",
",",
"'MatchTranslation'",
",",
"'MatchEscape'",
",",
"'MatchRouter'",
",",
"'MatchHelper'",
",",
"'MatchPartial'",
",",
"'MatchFails'",
",",
"'MatchPasses'",
",",
"'MatchPHPTags'",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"linenumber",
"=>",
"$",
"line",
")",
"{",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"NAMESPACE_MATCH",
".",
"$",
"class",
";",
"$",
"match",
"=",
"new",
"$",
"class",
"(",
"$",
"line",
")",
";",
"$",
"line",
"=",
"$",
"match",
"->",
"replace",
"(",
")",
"->",
"getLine",
"(",
")",
";",
"}",
"//User defined functions\r",
"foreach",
"(",
"TemplateData",
"::",
"getTemplateFunctions",
"(",
")",
"as",
"$",
"action",
"=>",
"$",
"closure",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"NAMESPACE_MATCH",
".",
"'MatchUserDefined'",
";",
"$",
"match",
"=",
"new",
"$",
"class",
"(",
"$",
"line",
",",
"$",
"action",
")",
";",
"$",
"line",
"=",
"$",
"match",
"->",
"replace",
"(",
")",
"->",
"getLine",
"(",
")",
";",
"}",
"$",
"this",
"->",
"code",
".=",
"trim",
"(",
"$",
"line",
")",
".",
"\"\\n\"",
";",
"}",
"$",
"this",
"->",
"code",
"=",
"trim",
"(",
"$",
"this",
"->",
"code",
")",
";",
"return",
"$",
"this",
"->",
"code",
";",
"}"
] | Convert template file to string
@return string | [
"Convert",
"template",
"file",
"to",
"string"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Template/Template.php#L146-L205 | train |
eureka-framework/component-template | src/Template/Template.php | Template.partial | public static function partial($template, array $vars = array())
{
$template = new Template($template, null, $vars);
return trim($template->render());
} | php | public static function partial($template, array $vars = array())
{
$template = new Template($template, null, $vars);
return trim($template->render());
} | [
"public",
"static",
"function",
"partial",
"(",
"$",
"template",
",",
"array",
"$",
"vars",
"=",
"array",
"(",
")",
")",
"{",
"$",
"template",
"=",
"new",
"Template",
"(",
"$",
"template",
",",
"null",
",",
"$",
"vars",
")",
";",
"return",
"trim",
"(",
"$",
"template",
"->",
"render",
"(",
")",
")",
";",
"}"
] | Include partial.
@param string $template
@param array $vars
@return string Content
@throws \Exception | [
"Include",
"partial",
"."
] | 42e9b3954b79892ba340ba7ca909f03ee99c36fe | https://github.com/eureka-framework/component-template/blob/42e9b3954b79892ba340ba7ca909f03ee99c36fe/src/Template/Template.php#L179-L184 | train |
eureka-framework/component-template | src/Template/Template.php | Template.setPathCompiled | public static function setPathCompiled($pathCompiled = '/tmp/Eureka/tpl')
{
$pathCompiled = rtrim($pathCompiled, '/') . '/';
if (!file_exists($pathCompiled) || !is_dir($pathCompiled)) {
if (!mkdir($pathCompiled, 0755, true)) {
throw new \Exception('Cannot create directory for templates compiled (path: ' . $pathCompiled . ')');
}
}
static::$pathCompiled = $pathCompiled;
} | php | public static function setPathCompiled($pathCompiled = '/tmp/Eureka/tpl')
{
$pathCompiled = rtrim($pathCompiled, '/') . '/';
if (!file_exists($pathCompiled) || !is_dir($pathCompiled)) {
if (!mkdir($pathCompiled, 0755, true)) {
throw new \Exception('Cannot create directory for templates compiled (path: ' . $pathCompiled . ')');
}
}
static::$pathCompiled = $pathCompiled;
} | [
"public",
"static",
"function",
"setPathCompiled",
"(",
"$",
"pathCompiled",
"=",
"'/tmp/Eureka/tpl'",
")",
"{",
"$",
"pathCompiled",
"=",
"rtrim",
"(",
"$",
"pathCompiled",
",",
"'/'",
")",
".",
"'/'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"pathCompiled",
")",
"||",
"!",
"is_dir",
"(",
"$",
"pathCompiled",
")",
")",
"{",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"pathCompiled",
",",
"0755",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot create directory for templates compiled (path: '",
".",
"$",
"pathCompiled",
".",
"')'",
")",
";",
"}",
"}",
"static",
"::",
"$",
"pathCompiled",
"=",
"$",
"pathCompiled",
";",
"}"
] | Set path for compiled templates.
@param string $pathCompiled
@return void
@throws \Exception | [
"Set",
"path",
"for",
"compiled",
"templates",
"."
] | 42e9b3954b79892ba340ba7ca909f03ee99c36fe | https://github.com/eureka-framework/component-template/blob/42e9b3954b79892ba340ba7ca909f03ee99c36fe/src/Template/Template.php#L193-L204 | train |
mcaskill/tokenlist | src/TokenList/DOMTokenList.php | DOMTokenList.__update | protected function __update()
{
/** Rebase array indices */
parent::__update();
if ( $this->count() && $this->attribute instanceof DOMAttr ) {
$this->attribute->value = (string) $this;
}
} | php | protected function __update()
{
/** Rebase array indices */
parent::__update();
if ( $this->count() && $this->attribute instanceof DOMAttr ) {
$this->attribute->value = (string) $this;
}
} | [
"protected",
"function",
"__update",
"(",
")",
"{",
"/** Rebase array indices */",
"parent",
"::",
"__update",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"&&",
"$",
"this",
"->",
"attribute",
"instanceof",
"DOMAttr",
")",
"{",
"$",
"this",
"->",
"attribute",
"->",
"value",
"=",
"(",
"string",
")",
"$",
"this",
";",
"}",
"}"
] | Updates the HTML attribute that DOMTokenList represents
Will only update the value if self::$attribute is a DOMAttr. | [
"Updates",
"the",
"HTML",
"attribute",
"that",
"DOMTokenList",
"represents"
] | 5266dc37157179c86f475a7a9301887d470b3664 | https://github.com/mcaskill/tokenlist/blob/5266dc37157179c86f475a7a9301887d470b3664/src/TokenList/DOMTokenList.php#L186-L194 | train |
mcaskill/tokenlist | src/TokenList/DOMTokenList.php | DOMTokenList.__toAttribute | public function __toAttribute()
{
if ( $this->count() ) {
$attr = null;
if ( is_string( $this->attribute ) ) {
$attr = $this->attribute;
}
elseif ( $this->attribute instanceof DOMAttr ) {
$attr = $this->attribute->name;
}
if ( $attr ) {
$values = htmlspecialchars((string) $this, ENT_QUOTES, ini_get('default_charset'), false);
return sprintf('%1$s="%2$s"', $attr, $values);
}
}
return '';
} | php | public function __toAttribute()
{
if ( $this->count() ) {
$attr = null;
if ( is_string( $this->attribute ) ) {
$attr = $this->attribute;
}
elseif ( $this->attribute instanceof DOMAttr ) {
$attr = $this->attribute->name;
}
if ( $attr ) {
$values = htmlspecialchars((string) $this, ENT_QUOTES, ini_get('default_charset'), false);
return sprintf('%1$s="%2$s"', $attr, $values);
}
}
return '';
} | [
"public",
"function",
"__toAttribute",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"count",
"(",
")",
")",
"{",
"$",
"attr",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"attribute",
")",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"attribute",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"attribute",
"instanceof",
"DOMAttr",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"attribute",
"->",
"name",
";",
"}",
"if",
"(",
"$",
"attr",
")",
"{",
"$",
"values",
"=",
"htmlspecialchars",
"(",
"(",
"string",
")",
"$",
"this",
",",
"ENT_QUOTES",
",",
"ini_get",
"(",
"'default_charset'",
")",
",",
"false",
")",
";",
"return",
"sprintf",
"(",
"'%1$s=\"%2$s\"'",
",",
"$",
"attr",
",",
"$",
"values",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Retrieves the HTML attribute and concatenated list of the tokens.
@return string Stringified token list, wrapped in an HTML attribute. | [
"Retrieves",
"the",
"HTML",
"attribute",
"and",
"concatenated",
"list",
"of",
"the",
"tokens",
"."
] | 5266dc37157179c86f475a7a9301887d470b3664 | https://github.com/mcaskill/tokenlist/blob/5266dc37157179c86f475a7a9301887d470b3664/src/TokenList/DOMTokenList.php#L201-L220 | train |
Wedeto/DB | src/Query/Select.php | Select.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
$drv = $params->getDriver();
// First get the source tables: FROM and JOIN clauses
$source = array();
if ($table = $this->getTable())
$source[] = "FROM " . $drv->toSQL($params, $table);
foreach ($this->getJoins() as $join)
$source[] = $drv->toSQL($params, $join);
// Now build the start of the query, all tables should be known
$parts = array();
$parts[] = "SELECT";
$fields = $this->getFields();
if (!empty($fields))
{
$field_parts = array();
foreach ($fields as $field)
$field_parts[] = $drv->toSQL($params, $field);
$parts[] = implode(", ", $field_parts);
}
else
$parts[] = "*";
// Add the source tables and joins to the query
foreach ($source as $part)
$parts[] = $part;
if ($where = $this->getWhere())
$parts[] = $drv->toSQL($params, $where);
if ($union = $this->getUnion())
$parts[] = $drv->toSQL($params, $union);
if ($order = $this->getOrder())
$parts[] = $drv->toSQL($params, $order);
if ($limit = $this->getLimit())
$parts[] = $drv->toSQL($params, $limit);
if ($offset = $this->getOffset())
$parts[] = $drv->toSQL($params, $offset);
return implode(" ", $parts);
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
$drv = $params->getDriver();
// First get the source tables: FROM and JOIN clauses
$source = array();
if ($table = $this->getTable())
$source[] = "FROM " . $drv->toSQL($params, $table);
foreach ($this->getJoins() as $join)
$source[] = $drv->toSQL($params, $join);
// Now build the start of the query, all tables should be known
$parts = array();
$parts[] = "SELECT";
$fields = $this->getFields();
if (!empty($fields))
{
$field_parts = array();
foreach ($fields as $field)
$field_parts[] = $drv->toSQL($params, $field);
$parts[] = implode(", ", $field_parts);
}
else
$parts[] = "*";
// Add the source tables and joins to the query
foreach ($source as $part)
$parts[] = $part;
if ($where = $this->getWhere())
$parts[] = $drv->toSQL($params, $where);
if ($union = $this->getUnion())
$parts[] = $drv->toSQL($params, $union);
if ($order = $this->getOrder())
$parts[] = $drv->toSQL($params, $order);
if ($limit = $this->getLimit())
$parts[] = $drv->toSQL($params, $limit);
if ($offset = $this->getOffset())
$parts[] = $drv->toSQL($params, $offset);
return implode(" ", $parts);
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"$",
"drv",
"=",
"$",
"params",
"->",
"getDriver",
"(",
")",
";",
"// First get the source tables: FROM and JOIN clauses",
"$",
"source",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
"$",
"source",
"[",
"]",
"=",
"\"FROM \"",
".",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"table",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getJoins",
"(",
")",
"as",
"$",
"join",
")",
"$",
"source",
"[",
"]",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"join",
")",
";",
"// Now build the start of the query, all tables should be known",
"$",
"parts",
"=",
"array",
"(",
")",
";",
"$",
"parts",
"[",
"]",
"=",
"\"SELECT\"",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"field_parts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"$",
"field_parts",
"[",
"]",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"field",
")",
";",
"$",
"parts",
"[",
"]",
"=",
"implode",
"(",
"\", \"",
",",
"$",
"field_parts",
")",
";",
"}",
"else",
"$",
"parts",
"[",
"]",
"=",
"\"*\"",
";",
"// Add the source tables and joins to the query",
"foreach",
"(",
"$",
"source",
"as",
"$",
"part",
")",
"$",
"parts",
"[",
"]",
"=",
"$",
"part",
";",
"if",
"(",
"$",
"where",
"=",
"$",
"this",
"->",
"getWhere",
"(",
")",
")",
"$",
"parts",
"[",
"]",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"where",
")",
";",
"if",
"(",
"$",
"union",
"=",
"$",
"this",
"->",
"getUnion",
"(",
")",
")",
"$",
"parts",
"[",
"]",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"union",
")",
";",
"if",
"(",
"$",
"order",
"=",
"$",
"this",
"->",
"getOrder",
"(",
")",
")",
"$",
"parts",
"[",
"]",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"order",
")",
";",
"if",
"(",
"$",
"limit",
"=",
"$",
"this",
"->",
"getLimit",
"(",
")",
")",
"$",
"parts",
"[",
"]",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"limit",
")",
";",
"if",
"(",
"$",
"offset",
"=",
"$",
"this",
"->",
"getOffset",
"(",
")",
")",
"$",
"parts",
"[",
"]",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"offset",
")",
";",
"return",
"implode",
"(",
"\" \"",
",",
"$",
"parts",
")",
";",
"}"
] | Write a select query as SQL query syntax
@param Parameters $params The query parameters: tables and placeholder values
@param bool $inner_clause Unused
@return string The generated SQL | [
"Write",
"a",
"select",
"query",
"as",
"SQL",
"query",
"syntax"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/Select.php#L206-L253 | train |
modulusphp/http | Middleware/AuthenticateWithBasicAuth.php | AuthenticateWithBasicAuth.hasBasicAuth | protected function hasBasicAuth($request) : bool
{
if ($request->headers->has('Authorization') && starts_with($request->header('Authorization'), 'Basic ')) {
return true;
}
return false;
} | php | protected function hasBasicAuth($request) : bool
{
if ($request->headers->has('Authorization') && starts_with($request->header('Authorization'), 'Basic ')) {
return true;
}
return false;
} | [
"protected",
"function",
"hasBasicAuth",
"(",
"$",
"request",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"request",
"->",
"headers",
"->",
"has",
"(",
"'Authorization'",
")",
"&&",
"starts_with",
"(",
"$",
"request",
"->",
"header",
"(",
"'Authorization'",
")",
",",
"'Basic '",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if request has Basic Authentication header
@param \Modulus\Http\Request $request
@return bool | [
"Check",
"if",
"request",
"has",
"Basic",
"Authentication",
"header"
] | fc5c0f2b582a04de1685578d3fb790686a0a240c | https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Middleware/AuthenticateWithBasicAuth.php#L94-L101 | train |
chalasr/RCHCapistranoBundle | Util/CanGenerateTrait.php | CanGenerateTrait.generate | public function generate(GeneratorInterface $generator)
{
$callback = function () use ($generator) {
$handler = Handler::create($generator);
$handler->generate();
};
return $callback();
} | php | public function generate(GeneratorInterface $generator)
{
$callback = function () use ($generator) {
$handler = Handler::create($generator);
$handler->generate();
};
return $callback();
} | [
"public",
"function",
"generate",
"(",
"GeneratorInterface",
"$",
"generator",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"generator",
")",
"{",
"$",
"handler",
"=",
"Handler",
"::",
"create",
"(",
"$",
"generator",
")",
";",
"$",
"handler",
"->",
"generate",
"(",
")",
";",
"}",
";",
"return",
"$",
"callback",
"(",
")",
";",
"}"
] | Generates a document from given configuration using given generator.
@param GeneratorInterface $generator Instance of AbstractGeneratord
@return callable | [
"Generates",
"a",
"document",
"from",
"given",
"configuration",
"using",
"given",
"generator",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Util/CanGenerateTrait.php#L32-L40 | train |
chalasr/RCHCapistranoBundle | Util/CanGenerateTrait.php | CanGenerateTrait.parseYamlStaging | public function parseYamlStaging($yamlFile)
{
$container = !(property_exists(get_called_class(), 'container')) ? $this->getContainer() : $this->container;
$capitalizer = $container->get('rch_capistrano.capitalizer');
$params = Yaml::parse(file_get_contents($yamlFile));
return $capitalizer->camelize($params);
} | php | public function parseYamlStaging($yamlFile)
{
$container = !(property_exists(get_called_class(), 'container')) ? $this->getContainer() : $this->container;
$capitalizer = $container->get('rch_capistrano.capitalizer');
$params = Yaml::parse(file_get_contents($yamlFile));
return $capitalizer->camelize($params);
} | [
"public",
"function",
"parseYamlStaging",
"(",
"$",
"yamlFile",
")",
"{",
"$",
"container",
"=",
"!",
"(",
"property_exists",
"(",
"get_called_class",
"(",
")",
",",
"'container'",
")",
")",
"?",
"$",
"this",
"->",
"getContainer",
"(",
")",
":",
"$",
"this",
"->",
"container",
";",
"$",
"capitalizer",
"=",
"$",
"container",
"->",
"get",
"(",
"'rch_capistrano.capitalizer'",
")",
";",
"$",
"params",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"yamlFile",
")",
")",
";",
"return",
"$",
"capitalizer",
"->",
"camelize",
"(",
"$",
"params",
")",
";",
"}"
] | Read staging parameters from YAML staging file.
@param string $yamlFile The YAML staging filename
@return array | [
"Read",
"staging",
"parameters",
"from",
"YAML",
"staging",
"file",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Util/CanGenerateTrait.php#L61-L68 | train |
ZendExperts/phpids | lib/IDS/Log/Database.php | IDS_Log_Database.execute | public function execute(IDS_Report $data)
{
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
foreach ($data as $event) {
$page = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$ip = $this->ip;
$ip2 = $this->ip2;
$name = $event->getName();
$value = $event->getValue();
$impact = $event->getImpact();
$tags = implode(', ', $event->getTags());
$this->statement->bindParam('name', $name);
$this->statement->bindParam('value', $value);
$this->statement->bindParam('page', $page);
$this->statement->bindParam('tags', $tags);
$this->statement->bindParam('ip', $ip);
$this->statement->bindParam('ip2', $ip2);
$this->statement->bindParam('impact', $impact);
$this->statement->bindParam('origin', $_SERVER['SERVER_ADDR']);
if (!$this->statement->execute()) {
$info = $this->statement->errorInfo();
throw new Exception(
$this->statement->errorCode() . ', ' . $info[1] . ', ' . $info[2]
);
}
}
return true;
} | php | public function execute(IDS_Report $data)
{
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
foreach ($data as $event) {
$page = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$ip = $this->ip;
$ip2 = $this->ip2;
$name = $event->getName();
$value = $event->getValue();
$impact = $event->getImpact();
$tags = implode(', ', $event->getTags());
$this->statement->bindParam('name', $name);
$this->statement->bindParam('value', $value);
$this->statement->bindParam('page', $page);
$this->statement->bindParam('tags', $tags);
$this->statement->bindParam('ip', $ip);
$this->statement->bindParam('ip2', $ip2);
$this->statement->bindParam('impact', $impact);
$this->statement->bindParam('origin', $_SERVER['SERVER_ADDR']);
if (!$this->statement->execute()) {
$info = $this->statement->errorInfo();
throw new Exception(
$this->statement->errorCode() . ', ' . $info[1] . ', ' . $info[2]
);
}
}
return true;
} | [
"public",
"function",
"execute",
"(",
"IDS_Report",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"{",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
"=",
"substr",
"(",
"$",
"_SERVER",
"[",
"'PHP_SELF'",
"]",
",",
"1",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
")",
"&&",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
")",
"{",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
".=",
"'?'",
".",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"event",
")",
"{",
"$",
"page",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
":",
"''",
";",
"$",
"ip",
"=",
"$",
"this",
"->",
"ip",
";",
"$",
"ip2",
"=",
"$",
"this",
"->",
"ip2",
";",
"$",
"name",
"=",
"$",
"event",
"->",
"getName",
"(",
")",
";",
"$",
"value",
"=",
"$",
"event",
"->",
"getValue",
"(",
")",
";",
"$",
"impact",
"=",
"$",
"event",
"->",
"getImpact",
"(",
")",
";",
"$",
"tags",
"=",
"implode",
"(",
"', '",
",",
"$",
"event",
"->",
"getTags",
"(",
")",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'name'",
",",
"$",
"name",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'value'",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'page'",
",",
"$",
"page",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'tags'",
",",
"$",
"tags",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'ip'",
",",
"$",
"ip",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'ip2'",
",",
"$",
"ip2",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'impact'",
",",
"$",
"impact",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"bindParam",
"(",
"'origin'",
",",
"$",
"_SERVER",
"[",
"'SERVER_ADDR'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
")",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"statement",
"->",
"errorInfo",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"$",
"this",
"->",
"statement",
"->",
"errorCode",
"(",
")",
".",
"', '",
".",
"$",
"info",
"[",
"1",
"]",
".",
"', '",
".",
"$",
"info",
"[",
"2",
"]",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Stores given data into the database
@param object $data IDS_Report instance
@throws Exception if db error occurred
@return boolean | [
"Stores",
"given",
"data",
"into",
"the",
"database"
] | f30df04eea47b94d056e2ae9ec8fea1c626f1c03 | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Log/Database.php#L253-L291 | train |
jacksleight/coast | library/Path.php | Path.isWithin | public function isWithin(\Coast\Path $parent)
{
$path = $this->_name;
$parts = \explode(PATH_SEPARATOR, (string) $parent);
foreach ($parts as $part) {
if (\preg_match('/^' . \preg_quote($part, '/') . '/', $path)) {
return true;
}
}
return false;
} | php | public function isWithin(\Coast\Path $parent)
{
$path = $this->_name;
$parts = \explode(PATH_SEPARATOR, (string) $parent);
foreach ($parts as $part) {
if (\preg_match('/^' . \preg_quote($part, '/') . '/', $path)) {
return true;
}
}
return false;
} | [
"public",
"function",
"isWithin",
"(",
"\\",
"Coast",
"\\",
"Path",
"$",
"parent",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_name",
";",
"$",
"parts",
"=",
"\\",
"explode",
"(",
"PATH_SEPARATOR",
",",
"(",
"string",
")",
"$",
"parent",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"\\",
"preg_match",
"(",
"'/^'",
".",
"\\",
"preg_quote",
"(",
"$",
"part",
",",
"'/'",
")",
".",
"'/'",
",",
"$",
"path",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if path is within another
@param Coast\Path $target path to check against.
@return bool | [
"Check",
"if",
"path",
"is",
"within",
"another"
] | cd6cd41e8304adce41f59f799d4183adcaf666f9 | https://github.com/jacksleight/coast/blob/cd6cd41e8304adce41f59f799d4183adcaf666f9/library/Path.php#L167-L177 | train |
jacksleight/coast | library/Path.php | Path.toAbsolute | public function toAbsolute(\Coast\Path $base)
{
if (!$this->isRelative() || !$base->isAbsolute()) {
throw new \Exception("Path '{$this}' is not relative or base path '{$base}' is not absolute");
}
$source = explode('/', (string) $base);
$target = explode('/', $this->_name);
$name = $source;
array_pop($name);
foreach ($target as $part) {
if ($part == '..') {
array_pop($name);
} else if ($part != '.' && $part != '') {
$name[] = $part;
}
}
$name = implode('/', $name);
$class = get_class($this);
return new $class($name);
} | php | public function toAbsolute(\Coast\Path $base)
{
if (!$this->isRelative() || !$base->isAbsolute()) {
throw new \Exception("Path '{$this}' is not relative or base path '{$base}' is not absolute");
}
$source = explode('/', (string) $base);
$target = explode('/', $this->_name);
$name = $source;
array_pop($name);
foreach ($target as $part) {
if ($part == '..') {
array_pop($name);
} else if ($part != '.' && $part != '') {
$name[] = $part;
}
}
$name = implode('/', $name);
$class = get_class($this);
return new $class($name);
} | [
"public",
"function",
"toAbsolute",
"(",
"\\",
"Coast",
"\\",
"Path",
"$",
"base",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isRelative",
"(",
")",
"||",
"!",
"$",
"base",
"->",
"isAbsolute",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Path '{$this}' is not relative or base path '{$base}' is not absolute\"",
")",
";",
"}",
"$",
"source",
"=",
"explode",
"(",
"'/'",
",",
"(",
"string",
")",
"$",
"base",
")",
";",
"$",
"target",
"=",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"_name",
")",
";",
"$",
"name",
"=",
"$",
"source",
";",
"array_pop",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"target",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"$",
"part",
"==",
"'..'",
")",
"{",
"array_pop",
"(",
"$",
"name",
")",
";",
"}",
"else",
"if",
"(",
"$",
"part",
"!=",
"'.'",
"&&",
"$",
"part",
"!=",
"''",
")",
"{",
"$",
"name",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"}",
"$",
"name",
"=",
"implode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"name",
")",
";",
"}"
] | Get absolute path from relative path.
@param Coast\Path $base base absolute path.
@return Coast\Path | [
"Get",
"absolute",
"path",
"from",
"relative",
"path",
"."
] | cd6cd41e8304adce41f59f799d4183adcaf666f9 | https://github.com/jacksleight/coast/blob/cd6cd41e8304adce41f59f799d4183adcaf666f9/library/Path.php#L184-L206 | train |
jacksleight/coast | library/Path.php | Path.toRelative | public function toRelative(\Coast\Path $base)
{
if (!$this->isAbsolute() || !$base->isAbsolute()) {
throw new \Exception("Source path '{$this}' is not absolute or base path '{$base}' is not absolute");
}
$source = explode('/', (string) $base);
$target = explode('/', $this->_name);
$name = $target;
foreach ($source as $i => $part) {
if ($part == $target[$i]) {
array_shift($name);
} else {
$name = array_pad($name, (count($name) + (count($source) - $i) - 1) * -1, '..');
break;
}
}
$name = implode('/', $name);
$class = get_class($this);
return new $class($name);
} | php | public function toRelative(\Coast\Path $base)
{
if (!$this->isAbsolute() || !$base->isAbsolute()) {
throw new \Exception("Source path '{$this}' is not absolute or base path '{$base}' is not absolute");
}
$source = explode('/', (string) $base);
$target = explode('/', $this->_name);
$name = $target;
foreach ($source as $i => $part) {
if ($part == $target[$i]) {
array_shift($name);
} else {
$name = array_pad($name, (count($name) + (count($source) - $i) - 1) * -1, '..');
break;
}
}
$name = implode('/', $name);
$class = get_class($this);
return new $class($name);
} | [
"public",
"function",
"toRelative",
"(",
"\\",
"Coast",
"\\",
"Path",
"$",
"base",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAbsolute",
"(",
")",
"||",
"!",
"$",
"base",
"->",
"isAbsolute",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Source path '{$this}' is not absolute or base path '{$base}' is not absolute\"",
")",
";",
"}",
"$",
"source",
"=",
"explode",
"(",
"'/'",
",",
"(",
"string",
")",
"$",
"base",
")",
";",
"$",
"target",
"=",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"_name",
")",
";",
"$",
"name",
"=",
"$",
"target",
";",
"foreach",
"(",
"$",
"source",
"as",
"$",
"i",
"=>",
"$",
"part",
")",
"{",
"if",
"(",
"$",
"part",
"==",
"$",
"target",
"[",
"$",
"i",
"]",
")",
"{",
"array_shift",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"array_pad",
"(",
"$",
"name",
",",
"(",
"count",
"(",
"$",
"name",
")",
"+",
"(",
"count",
"(",
"$",
"source",
")",
"-",
"$",
"i",
")",
"-",
"1",
")",
"*",
"-",
"1",
",",
"'..'",
")",
";",
"break",
";",
"}",
"}",
"$",
"name",
"=",
"implode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"name",
")",
";",
"}"
] | Get relative path from absolute path.
@param Coast\Path $base Base absolute path.
@return Coast\Path | [
"Get",
"relative",
"path",
"from",
"absolute",
"path",
"."
] | cd6cd41e8304adce41f59f799d4183adcaf666f9 | https://github.com/jacksleight/coast/blob/cd6cd41e8304adce41f59f799d4183adcaf666f9/library/Path.php#L213-L235 | train |
jacksleight/coast | library/Path.php | Path.toReal | public function toReal()
{
if (!$this->isAbsolute()) {
throw new \Exception("Path '{$this}' is not absolute");
}
$target = explode('/', $this->_name);
$name = [];
foreach ($target as $part) {
if ($part == '..') {
array_pop($name);
} else if ($part != '.') {
$name[] = $part;
}
}
$name = implode('/', $name);
$class = get_class($this);
return new $class($name);
} | php | public function toReal()
{
if (!$this->isAbsolute()) {
throw new \Exception("Path '{$this}' is not absolute");
}
$target = explode('/', $this->_name);
$name = [];
foreach ($target as $part) {
if ($part == '..') {
array_pop($name);
} else if ($part != '.') {
$name[] = $part;
}
}
$name = implode('/', $name);
$class = get_class($this);
return new $class($name);
} | [
"public",
"function",
"toReal",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAbsolute",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Path '{$this}' is not absolute\"",
")",
";",
"}",
"$",
"target",
"=",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"_name",
")",
";",
"$",
"name",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"target",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"$",
"part",
"==",
"'..'",
")",
"{",
"array_pop",
"(",
"$",
"name",
")",
";",
"}",
"else",
"if",
"(",
"$",
"part",
"!=",
"'.'",
")",
"{",
"$",
"name",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"}",
"$",
"name",
"=",
"implode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"name",
")",
";",
"}"
] | Reduce absolute path with relative parts to real path.
@return Coast\Path | [
"Reduce",
"absolute",
"path",
"with",
"relative",
"parts",
"to",
"real",
"path",
"."
] | cd6cd41e8304adce41f59f799d4183adcaf666f9 | https://github.com/jacksleight/coast/blob/cd6cd41e8304adce41f59f799d4183adcaf666f9/library/Path.php#L241-L261 | train |
hiqdev/minii-widgets | src/BaseListView.php | BaseListView.init | public function init()
{
if ($this->dataProvider === null) {
throw new InvalidConfigException('The "dataProvider" property must be set.');
}
if ($this->emptyText === null) {
$this->emptyText = Yii::t('yii', 'No results found.');
}
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
} | php | public function init()
{
if ($this->dataProvider === null) {
throw new InvalidConfigException('The "dataProvider" property must be set.');
}
if ($this->emptyText === null) {
$this->emptyText = Yii::t('yii', 'No results found.');
}
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dataProvider",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'The \"dataProvider\" property must be set.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"emptyText",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"emptyText",
"=",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'No results found.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"}",
"}"
] | Initializes the view. | [
"Initializes",
"the",
"view",
"."
] | b8bc54a3645e9e45c228e3ec81b11ff4775385c3 | https://github.com/hiqdev/minii-widgets/blob/b8bc54a3645e9e45c228e3ec81b11ff4775385c3/src/BaseListView.php#L106-L117 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Connectors/SqlServerConnector.php | SqlServerConnector.buildConnectString | protected function buildConnectString($driver, array $arguments)
{
$options = array_map(function ($key) use ($arguments) {
return sprintf('%s=%s', $key, $arguments[$key]);
}, array_keys($arguments));
return $driver.':'.implode(';', $options);
} | php | protected function buildConnectString($driver, array $arguments)
{
$options = array_map(function ($key) use ($arguments) {
return sprintf('%s=%s', $key, $arguments[$key]);
}, array_keys($arguments));
return $driver.':'.implode(';', $options);
} | [
"protected",
"function",
"buildConnectString",
"(",
"$",
"driver",
",",
"array",
"$",
"arguments",
")",
"{",
"$",
"options",
"=",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"use",
"(",
"$",
"arguments",
")",
"{",
"return",
"sprintf",
"(",
"'%s=%s'",
",",
"$",
"key",
",",
"$",
"arguments",
"[",
"$",
"key",
"]",
")",
";",
"}",
",",
"array_keys",
"(",
"$",
"arguments",
")",
")",
";",
"return",
"$",
"driver",
".",
"':'",
".",
"implode",
"(",
"';'",
",",
"$",
"options",
")",
";",
"}"
] | Build a connection string from the given arguments.
@param string $driver
@param array $arguments
@return string | [
"Build",
"a",
"connection",
"string",
"from",
"the",
"given",
"arguments",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Connectors/SqlServerConnector.php#L138-L145 | train |
Becklyn/Gluggi | src/Model/ElementTypesModel.php | ElementTypesModel.getAllElements | public function getAllElements ($elementType)
{
$iterator = new \DirectoryIterator($this->getUserSubDirectory("{$elementType}s"));
$allElements = [];
/** @var \SplFileInfo $file */
foreach ($iterator as $file)
{
if ($file->isDir() || ("twig" !== $file->getExtension()))
{
continue;
}
$reference = "@{$elementType}/{$file->getBasename()}";
$element = new Element($reference);
$allElements[$element->getKey()] = $element;
}
return $allElements;
} | php | public function getAllElements ($elementType)
{
$iterator = new \DirectoryIterator($this->getUserSubDirectory("{$elementType}s"));
$allElements = [];
/** @var \SplFileInfo $file */
foreach ($iterator as $file)
{
if ($file->isDir() || ("twig" !== $file->getExtension()))
{
continue;
}
$reference = "@{$elementType}/{$file->getBasename()}";
$element = new Element($reference);
$allElements[$element->getKey()] = $element;
}
return $allElements;
} | [
"public",
"function",
"getAllElements",
"(",
"$",
"elementType",
")",
"{",
"$",
"iterator",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"getUserSubDirectory",
"(",
"\"{$elementType}s\"",
")",
")",
";",
"$",
"allElements",
"=",
"[",
"]",
";",
"/** @var \\SplFileInfo $file */",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
"||",
"(",
"\"twig\"",
"!==",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"reference",
"=",
"\"@{$elementType}/{$file->getBasename()}\"",
";",
"$",
"element",
"=",
"new",
"Element",
"(",
"$",
"reference",
")",
";",
"$",
"allElements",
"[",
"$",
"element",
"->",
"getKey",
"(",
")",
"]",
"=",
"$",
"element",
";",
"}",
"return",
"$",
"allElements",
";",
"}"
] | Returns a list of all elements
@param string $elementType
@return Element[] | [
"Returns",
"a",
"list",
"of",
"all",
"elements"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Model/ElementTypesModel.php#L66-L85 | train |
Becklyn/Gluggi | src/Model/ElementTypesModel.php | ElementTypesModel.getListedElements | public function getListedElements ($elementType)
{
$allElements = $this->getAllElements($elementType);
usort($allElements,
function (Element $element1, Element $element2)
{
return strnatcasecmp($element1->getKey(), $element2->getKey());
}
);
return array_filter(
$allElements,
function (Element $element)
{
return !$element->isHidden();
}
);
} | php | public function getListedElements ($elementType)
{
$allElements = $this->getAllElements($elementType);
usort($allElements,
function (Element $element1, Element $element2)
{
return strnatcasecmp($element1->getKey(), $element2->getKey());
}
);
return array_filter(
$allElements,
function (Element $element)
{
return !$element->isHidden();
}
);
} | [
"public",
"function",
"getListedElements",
"(",
"$",
"elementType",
")",
"{",
"$",
"allElements",
"=",
"$",
"this",
"->",
"getAllElements",
"(",
"$",
"elementType",
")",
";",
"usort",
"(",
"$",
"allElements",
",",
"function",
"(",
"Element",
"$",
"element1",
",",
"Element",
"$",
"element2",
")",
"{",
"return",
"strnatcasecmp",
"(",
"$",
"element1",
"->",
"getKey",
"(",
")",
",",
"$",
"element2",
"->",
"getKey",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"array_filter",
"(",
"$",
"allElements",
",",
"function",
"(",
"Element",
"$",
"element",
")",
"{",
"return",
"!",
"$",
"element",
"->",
"isHidden",
"(",
")",
";",
"}",
")",
";",
"}"
] | Returns the listed elements
@param string $elementType
@return Element[] | [
"Returns",
"the",
"listed",
"elements"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Model/ElementTypesModel.php#L96-L113 | train |
Becklyn/Gluggi | src/Model/ElementTypesModel.php | ElementTypesModel.getElement | public function getElement ($key, $elementType)
{
$elements = $this->getAllElements($elementType);
return array_key_exists($key, $elements)
? $elements[$key]
: null;
} | php | public function getElement ($key, $elementType)
{
$elements = $this->getAllElements($elementType);
return array_key_exists($key, $elements)
? $elements[$key]
: null;
} | [
"public",
"function",
"getElement",
"(",
"$",
"key",
",",
"$",
"elementType",
")",
"{",
"$",
"elements",
"=",
"$",
"this",
"->",
"getAllElements",
"(",
"$",
"elementType",
")",
";",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"elements",
")",
"?",
"$",
"elements",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Returns the preview by key
@param string $key
@param string $elementType
@return Element|null | [
"Returns",
"the",
"preview",
"by",
"key"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Model/ElementTypesModel.php#L125-L132 | train |
Becklyn/Gluggi | src/Model/ElementTypesModel.php | ElementTypesModel.isFullPageElementType | public function isFullPageElementType ($key)
{
return array_key_exists($key, $this->elementTypes)
? $this->elementTypes[$key]["isFullPage"]
: null;
} | php | public function isFullPageElementType ($key)
{
return array_key_exists($key, $this->elementTypes)
? $this->elementTypes[$key]["isFullPage"]
: null;
} | [
"public",
"function",
"isFullPageElementType",
"(",
"$",
"key",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"elementTypes",
")",
"?",
"$",
"this",
"->",
"elementTypes",
"[",
"$",
"key",
"]",
"[",
"\"isFullPage\"",
"]",
":",
"null",
";",
"}"
] | Returns whether the given element type is full page
@param string $key
@return bool | [
"Returns",
"whether",
"the",
"given",
"element",
"type",
"is",
"full",
"page"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Model/ElementTypesModel.php#L169-L174 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.__callstatic | public static function __callstatic($method, $arguments) {
$route = new Route();
if(false === is_callable([$route, $method])) {
return trigger_error(sprintf('Call to undefined method %s::%s', __CLASS__, $method), E_USER_ERROR);
}
$route = call_user_func_array([$route, $method], $arguments);
return $route;
} | php | public static function __callstatic($method, $arguments) {
$route = new Route();
if(false === is_callable([$route, $method])) {
return trigger_error(sprintf('Call to undefined method %s::%s', __CLASS__, $method), E_USER_ERROR);
}
$route = call_user_func_array([$route, $method], $arguments);
return $route;
} | [
"public",
"static",
"function",
"__callstatic",
"(",
"$",
"method",
",",
"$",
"arguments",
")",
"{",
"$",
"route",
"=",
"new",
"Route",
"(",
")",
";",
"if",
"(",
"false",
"===",
"is_callable",
"(",
"[",
"$",
"route",
",",
"$",
"method",
"]",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Call to undefined method %s::%s'",
",",
"__CLASS__",
",",
"$",
"method",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"route",
"=",
"call_user_func_array",
"(",
"[",
"$",
"route",
",",
"$",
"method",
"]",
",",
"$",
"arguments",
")",
";",
"return",
"$",
"route",
";",
"}"
] | Creates a new route and calls the dynamic given method if exists
@param string $method
@param array $arguments
@return sFire\Routing\Extend\Route | [
"Creates",
"a",
"new",
"route",
"and",
"calls",
"the",
"dynamic",
"given",
"method",
"if",
"exists"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L128-L139 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.setUrl | public static function setUrl($url) {
if(false === is_string($url) && false === $url instanceof URLParser) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or instance of sFire\\Utils\\URLParser, "%s" given', __METHOD__, gettype($url)), E_USER_ERROR);
}
if(true === is_string($url)) {
$url = new URLParser($url);
}
static :: $url = $url;
return $url;
} | php | public static function setUrl($url) {
if(false === is_string($url) && false === $url instanceof URLParser) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or instance of sFire\\Utils\\URLParser, "%s" given', __METHOD__, gettype($url)), E_USER_ERROR);
}
if(true === is_string($url)) {
$url = new URLParser($url);
}
static :: $url = $url;
return $url;
} | [
"public",
"static",
"function",
"setUrl",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"url",
")",
"&&",
"false",
"===",
"$",
"url",
"instanceof",
"URLParser",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string or instance of sFire\\\\Utils\\\\URLParser, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"url",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"true",
"===",
"is_string",
"(",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=",
"new",
"URLParser",
"(",
"$",
"url",
")",
";",
"}",
"static",
"::",
"$",
"url",
"=",
"$",
"url",
";",
"return",
"$",
"url",
";",
"}"
] | Set the current URL
@param string|sFire\Utils\URLParser $url
@return sFire\Utils\URLParser | [
"Set",
"the",
"current",
"URL"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L156-L168 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.routeExists | public static function routeExists($identifier, $domain = null) {
if(false === is_string($identifier)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($identifier)), E_USER_ERROR);
}
if(null !== $domain && false === is_string($domain)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($domain)), E_USER_ERROR);
}
$routes = static :: getRoutes();
if(false === isset($routes[$identifier])) {
return false;
}
if(null !== $domain) {
return static :: domainExists($domain);
}
return true;
} | php | public static function routeExists($identifier, $domain = null) {
if(false === is_string($identifier)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($identifier)), E_USER_ERROR);
}
if(null !== $domain && false === is_string($domain)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($domain)), E_USER_ERROR);
}
$routes = static :: getRoutes();
if(false === isset($routes[$identifier])) {
return false;
}
if(null !== $domain) {
return static :: domainExists($domain);
}
return true;
} | [
"public",
"static",
"function",
"routeExists",
"(",
"$",
"identifier",
",",
"$",
"domain",
"=",
"null",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"identifier",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"identifier",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"domain",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"domain",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"domain",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"routes",
"=",
"static",
"::",
"getRoutes",
"(",
")",
";",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"routes",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"domain",
")",
"{",
"return",
"static",
"::",
"domainExists",
"(",
"$",
"domain",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Check if a Route exists by identifier with optional domain
@param string $identifier
@param string|null $domain
@return boolean | [
"Check",
"if",
"a",
"Route",
"exists",
"by",
"identifier",
"with",
"optional",
"domain"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L311-L332 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.domainExists | public static function domainExists($domain) {
if(false === is_string($domain)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($domain)), E_USER_ERROR);
}
$routes = static :: getRoutes();
foreach($routes as $route) {
$domains = $route -> getDomain();
if(true === is_array($domains)) {
foreach($domains as $url) {
if(preg_match('#'. str_replace('#', '\#', $url) .'#', $domain) || $url === $domain) {
return true;
}
}
}
}
return false;
} | php | public static function domainExists($domain) {
if(false === is_string($domain)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($domain)), E_USER_ERROR);
}
$routes = static :: getRoutes();
foreach($routes as $route) {
$domains = $route -> getDomain();
if(true === is_array($domains)) {
foreach($domains as $url) {
if(preg_match('#'. str_replace('#', '\#', $url) .'#', $domain) || $url === $domain) {
return true;
}
}
}
}
return false;
} | [
"public",
"static",
"function",
"domainExists",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"domain",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"domain",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"routes",
"=",
"static",
"::",
"getRoutes",
"(",
")",
";",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"$",
"domains",
"=",
"$",
"route",
"->",
"getDomain",
"(",
")",
";",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"domains",
")",
")",
"{",
"foreach",
"(",
"$",
"domains",
"as",
"$",
"url",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#'",
".",
"str_replace",
"(",
"'#'",
",",
"'\\#'",
",",
"$",
"url",
")",
".",
"'#'",
",",
"$",
"domain",
")",
"||",
"$",
"url",
"===",
"$",
"domain",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if a given domain exists
@param string $domain
@return boolean | [
"Checks",
"if",
"a",
"given",
"domain",
"exists"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L340-L364 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.getRoute | public static function getRoute($identifier = null) {
if(null !== $identifier && false === is_string($identifier)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($identifier)), E_USER_ERROR);
}
if(null !== $identifier) {
if(false === static :: routeExists($identifier)) {
return trigger_error(sprintf('Route identifier "%s" not found in routes.php', $identifier), E_USER_ERROR);
}
return static :: $routes[$identifier];
}
return static :: $route;
} | php | public static function getRoute($identifier = null) {
if(null !== $identifier && false === is_string($identifier)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($identifier)), E_USER_ERROR);
}
if(null !== $identifier) {
if(false === static :: routeExists($identifier)) {
return trigger_error(sprintf('Route identifier "%s" not found in routes.php', $identifier), E_USER_ERROR);
}
return static :: $routes[$identifier];
}
return static :: $route;
} | [
"public",
"static",
"function",
"getRoute",
"(",
"$",
"identifier",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"identifier",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"identifier",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"identifier",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"identifier",
")",
"{",
"if",
"(",
"false",
"===",
"static",
"::",
"routeExists",
"(",
"$",
"identifier",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Route identifier \"%s\" not found in routes.php'",
",",
"$",
"identifier",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"static",
"::",
"$",
"routes",
"[",
"$",
"identifier",
"]",
";",
"}",
"return",
"static",
"::",
"$",
"route",
";",
"}"
] | Gets the current route or a route based on identifier
@param null|string $identifier
@return sFire\Routing\Extend\Method | [
"Gets",
"the",
"current",
"route",
"or",
"a",
"route",
"based",
"on",
"identifier"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L392-L408 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.addGroup | public static function addGroup($group) {
if(false === is_array($group)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($group)), E_USER_ERROR);
}
static :: $group[] = $group;
} | php | public static function addGroup($group) {
if(false === is_array($group)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($group)), E_USER_ERROR);
}
static :: $group[] = $group;
} | [
"public",
"static",
"function",
"addGroup",
"(",
"$",
"group",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"group",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"group",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"static",
"::",
"$",
"group",
"[",
"]",
"=",
"$",
"group",
";",
"}"
] | Add a new group element to the stack
@param array $group | [
"Add",
"a",
"new",
"group",
"element",
"to",
"the",
"stack"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L415-L422 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.getGroup | public static function getGroup() {
$attr = [];
foreach(static :: $group as $group) {
$attr = static :: arrayRecursiveMerge($attr, $group);
}
return $attr;
} | php | public static function getGroup() {
$attr = [];
foreach(static :: $group as $group) {
$attr = static :: arrayRecursiveMerge($attr, $group);
}
return $attr;
} | [
"public",
"static",
"function",
"getGroup",
"(",
")",
"{",
"$",
"attr",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"group",
"as",
"$",
"group",
")",
"{",
"$",
"attr",
"=",
"static",
"::",
"arrayRecursiveMerge",
"(",
"$",
"attr",
",",
"$",
"group",
")",
";",
"}",
"return",
"$",
"attr",
";",
"}"
] | Return all the groups as one merged array
@return array | [
"Return",
"all",
"the",
"groups",
"as",
"one",
"merged",
"array"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L438-L447 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.getErrorRoute | public static function getErrorRoute($type, $index = 0) {
if(false === ('-' . intval($type) == '-' . $type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
if(false === ('-' . intval($index) == '-' . $index)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($index)), E_USER_ERROR);
}
if(true === isset(static :: $error['types'][$type][$index])) {
return static :: $error['types'][$type][$index];
}
return null;
} | php | public static function getErrorRoute($type, $index = 0) {
if(false === ('-' . intval($type) == '-' . $type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
if(false === ('-' . intval($index) == '-' . $index)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($index)), E_USER_ERROR);
}
if(true === isset(static :: $error['types'][$type][$index])) {
return static :: $error['types'][$type][$index];
}
return null;
} | [
"public",
"static",
"function",
"getErrorRoute",
"(",
"$",
"type",
",",
"$",
"index",
"=",
"0",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"type",
")",
"==",
"'-'",
".",
"$",
"type",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"type",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"index",
")",
"==",
"'-'",
".",
"$",
"index",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"index",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"static",
"::",
"$",
"error",
"[",
"'types'",
"]",
"[",
"$",
"type",
"]",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"error",
"[",
"'types'",
"]",
"[",
"$",
"type",
"]",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Retrieve a route from the error route stack. Default the first on the stack, or route with optional index
@param string|integer $type
@param integer $index
@return null|sFire\Routing\Extend\Route | [
"Retrieve",
"a",
"route",
"from",
"the",
"error",
"route",
"stack",
".",
"Default",
"the",
"first",
"on",
"the",
"stack",
"or",
"route",
"with",
"optional",
"index"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L456-L471 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.addErrorRoute | public static function addErrorRoute($type, Route $route, $default = false) {
if(false === ('-' . intval($type) == '-' . $type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
static :: $error['types'][$type][] = $route;
if(true === $default || false === isset(static :: $error['default'][$type])) {
static :: $error['default'][$type] = $route;
}
} | php | public static function addErrorRoute($type, Route $route, $default = false) {
if(false === ('-' . intval($type) == '-' . $type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
static :: $error['types'][$type][] = $route;
if(true === $default || false === isset(static :: $error['default'][$type])) {
static :: $error['default'][$type] = $route;
}
} | [
"public",
"static",
"function",
"addErrorRoute",
"(",
"$",
"type",
",",
"Route",
"$",
"route",
",",
"$",
"default",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"type",
")",
"==",
"'-'",
".",
"$",
"type",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"type",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"static",
"::",
"$",
"error",
"[",
"'types'",
"]",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"route",
";",
"if",
"(",
"true",
"===",
"$",
"default",
"||",
"false",
"===",
"isset",
"(",
"static",
"::",
"$",
"error",
"[",
"'default'",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"static",
"::",
"$",
"error",
"[",
"'default'",
"]",
"[",
"$",
"type",
"]",
"=",
"$",
"route",
";",
"}",
"}"
] | Adds a new error route to the error routes stack
@param integer $type
@param sFire\Routing\Extend\Route $route
@param boolean $default | [
"Adds",
"a",
"new",
"error",
"route",
"to",
"the",
"error",
"routes",
"stack"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L480-L491 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.setRedirect | public static function setRedirect($bool) {
if(null !== $bool && false === is_bool($bool)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($bool)), E_USER_ERROR);
}
static :: $isRedirect = $bool;
} | php | public static function setRedirect($bool) {
if(null !== $bool && false === is_bool($bool)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($bool)), E_USER_ERROR);
}
static :: $isRedirect = $bool;
} | [
"public",
"static",
"function",
"setRedirect",
"(",
"$",
"bool",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"bool",
"&&",
"false",
"===",
"is_bool",
"(",
"$",
"bool",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"bool",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"static",
"::",
"$",
"isRedirect",
"=",
"$",
"bool",
";",
"}"
] | Set the redirect
@param boolean $redirect | [
"Set",
"the",
"redirect"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L530-L537 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.arrayRecursiveMerge | private static function arrayRecursiveMerge($array1, $array2) {
if(false === is_array($array1) || false === is_array($array2)) {
return $array2;
}
foreach($array2 as $key => $value) {
$array1[$key] = static :: arrayRecursiveMerge(@$array1[$key], $value);
}
return $array1;
} | php | private static function arrayRecursiveMerge($array1, $array2) {
if(false === is_array($array1) || false === is_array($array2)) {
return $array2;
}
foreach($array2 as $key => $value) {
$array1[$key] = static :: arrayRecursiveMerge(@$array1[$key], $value);
}
return $array1;
} | [
"private",
"static",
"function",
"arrayRecursiveMerge",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"array1",
")",
"||",
"false",
"===",
"is_array",
"(",
"$",
"array2",
")",
")",
"{",
"return",
"$",
"array2",
";",
"}",
"foreach",
"(",
"$",
"array2",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"array1",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"arrayRecursiveMerge",
"(",
"@",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"array1",
";",
"}"
] | Recursive merge arrays
@param array $array1
@param array $array2
@return array | [
"Recursive",
"merge",
"arrays"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L555-L566 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.request | private static function request() {
if($uri = Request :: getUri()) {
$url = '';
$host = null;
if(!($scheme = Request :: getScheme())) {
$scheme = 'php';
$host = '127.0.0.1';
Request :: setScheme($scheme);
}
$url .= $scheme . '://';
if($hostname = Request :: getHost()) {
$url .= $hostname;
}
elseif(null !== $host) {
$url .= $host;
}
$url .= $uri;
static :: $url = new URLParser($url);
}
} | php | private static function request() {
if($uri = Request :: getUri()) {
$url = '';
$host = null;
if(!($scheme = Request :: getScheme())) {
$scheme = 'php';
$host = '127.0.0.1';
Request :: setScheme($scheme);
}
$url .= $scheme . '://';
if($hostname = Request :: getHost()) {
$url .= $hostname;
}
elseif(null !== $host) {
$url .= $host;
}
$url .= $uri;
static :: $url = new URLParser($url);
}
} | [
"private",
"static",
"function",
"request",
"(",
")",
"{",
"if",
"(",
"$",
"uri",
"=",
"Request",
"::",
"getUri",
"(",
")",
")",
"{",
"$",
"url",
"=",
"''",
";",
"$",
"host",
"=",
"null",
";",
"if",
"(",
"!",
"(",
"$",
"scheme",
"=",
"Request",
"::",
"getScheme",
"(",
")",
")",
")",
"{",
"$",
"scheme",
"=",
"'php'",
";",
"$",
"host",
"=",
"'127.0.0.1'",
";",
"Request",
"::",
"setScheme",
"(",
"$",
"scheme",
")",
";",
"}",
"$",
"url",
".=",
"$",
"scheme",
".",
"'://'",
";",
"if",
"(",
"$",
"hostname",
"=",
"Request",
"::",
"getHost",
"(",
")",
")",
"{",
"$",
"url",
".=",
"$",
"hostname",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"host",
")",
"{",
"$",
"url",
".=",
"$",
"host",
";",
"}",
"$",
"url",
".=",
"$",
"uri",
";",
"static",
"::",
"$",
"url",
"=",
"new",
"URLParser",
"(",
"$",
"url",
")",
";",
"}",
"}"
] | Try to add the request uri | [
"Try",
"to",
"add",
"the",
"request",
"uri"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L572-L599 | train |
Kris-Kuiper/sFire-Framework | src/Routing/Router.php | Router.format | private static function format() {
$routes = static :: getRoutes();
foreach($routes as $identifier => $route) {
$url = preg_quote($route -> getUrl(), '/');
//Prepend prefix for url
if($prefix = $route -> getPrefix()) {
$url = $prefix['url'] . $url;
}
if(preg_match_all('#(\\\/)*\\\{([a-zA-Z0-9_.]+)(\\\\\?)?\\\}#i', $url, $matches)) {
foreach($matches[0] as $index => $match) {
$match = $matches[0][$index];
$slash = $matches[1][$index];
$type = $matches[2][$index];
$optional = $matches[3][$index];
$where = $route -> getWhere();
$variable = '';
$typefound = false;
if('' !== $slash) {
$variable .= '\/';
}
if(true === is_array($where)) {
foreach($where as $key => $regex) {
if($key === $type) {
$variable .= $regex;
$typefound = true;
break;
}
}
}
if(false === $typefound) {
if(isset(static :: $types[$type])) {
$variable .= static :: $types[$type];
}
else {
$variable .= static :: $types['string'];
}
}
if('' !== $optional) {
$variable = '('. $variable .')?';
}
else {
$variable = '('. $variable .')';
}
$url = preg_replace('#' . preg_quote($match, '/') . '#', $variable, $url, 1);
}
}
$route -> setMatch($url);
}
} | php | private static function format() {
$routes = static :: getRoutes();
foreach($routes as $identifier => $route) {
$url = preg_quote($route -> getUrl(), '/');
//Prepend prefix for url
if($prefix = $route -> getPrefix()) {
$url = $prefix['url'] . $url;
}
if(preg_match_all('#(\\\/)*\\\{([a-zA-Z0-9_.]+)(\\\\\?)?\\\}#i', $url, $matches)) {
foreach($matches[0] as $index => $match) {
$match = $matches[0][$index];
$slash = $matches[1][$index];
$type = $matches[2][$index];
$optional = $matches[3][$index];
$where = $route -> getWhere();
$variable = '';
$typefound = false;
if('' !== $slash) {
$variable .= '\/';
}
if(true === is_array($where)) {
foreach($where as $key => $regex) {
if($key === $type) {
$variable .= $regex;
$typefound = true;
break;
}
}
}
if(false === $typefound) {
if(isset(static :: $types[$type])) {
$variable .= static :: $types[$type];
}
else {
$variable .= static :: $types['string'];
}
}
if('' !== $optional) {
$variable = '('. $variable .')?';
}
else {
$variable = '('. $variable .')';
}
$url = preg_replace('#' . preg_quote($match, '/') . '#', $variable, $url, 1);
}
}
$route -> setMatch($url);
}
} | [
"private",
"static",
"function",
"format",
"(",
")",
"{",
"$",
"routes",
"=",
"static",
"::",
"getRoutes",
"(",
")",
";",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"identifier",
"=>",
"$",
"route",
")",
"{",
"$",
"url",
"=",
"preg_quote",
"(",
"$",
"route",
"->",
"getUrl",
"(",
")",
",",
"'/'",
")",
";",
"//Prepend prefix for url\r",
"if",
"(",
"$",
"prefix",
"=",
"$",
"route",
"->",
"getPrefix",
"(",
")",
")",
"{",
"$",
"url",
"=",
"$",
"prefix",
"[",
"'url'",
"]",
".",
"$",
"url",
";",
"}",
"if",
"(",
"preg_match_all",
"(",
"'#(\\\\\\/)*\\\\\\{([a-zA-Z0-9_.]+)(\\\\\\\\\\?)?\\\\\\}#i'",
",",
"$",
"url",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"match",
")",
"{",
"$",
"match",
"=",
"$",
"matches",
"[",
"0",
"]",
"[",
"$",
"index",
"]",
";",
"$",
"slash",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
";",
"$",
"type",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"index",
"]",
";",
"$",
"optional",
"=",
"$",
"matches",
"[",
"3",
"]",
"[",
"$",
"index",
"]",
";",
"$",
"where",
"=",
"$",
"route",
"->",
"getWhere",
"(",
")",
";",
"$",
"variable",
"=",
"''",
";",
"$",
"typefound",
"=",
"false",
";",
"if",
"(",
"''",
"!==",
"$",
"slash",
")",
"{",
"$",
"variable",
".=",
"'\\/'",
";",
"}",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"where",
")",
")",
"{",
"foreach",
"(",
"$",
"where",
"as",
"$",
"key",
"=>",
"$",
"regex",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"$",
"type",
")",
"{",
"$",
"variable",
".=",
"$",
"regex",
";",
"$",
"typefound",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"false",
"===",
"$",
"typefound",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"types",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"variable",
".=",
"static",
"::",
"$",
"types",
"[",
"$",
"type",
"]",
";",
"}",
"else",
"{",
"$",
"variable",
".=",
"static",
"::",
"$",
"types",
"[",
"'string'",
"]",
";",
"}",
"}",
"if",
"(",
"''",
"!==",
"$",
"optional",
")",
"{",
"$",
"variable",
"=",
"'('",
".",
"$",
"variable",
".",
"')?'",
";",
"}",
"else",
"{",
"$",
"variable",
"=",
"'('",
".",
"$",
"variable",
".",
"')'",
";",
"}",
"$",
"url",
"=",
"preg_replace",
"(",
"'#'",
".",
"preg_quote",
"(",
"$",
"match",
",",
"'/'",
")",
".",
"'#'",
",",
"$",
"variable",
",",
"$",
"url",
",",
"1",
")",
";",
"}",
"}",
"$",
"route",
"->",
"setMatch",
"(",
"$",
"url",
")",
";",
"}",
"}"
] | Formats all the routes urls to a regex pattern that sFire understands to match the current url to the route url | [
"Formats",
"all",
"the",
"routes",
"urls",
"to",
"a",
"regex",
"pattern",
"that",
"sFire",
"understands",
"to",
"match",
"the",
"current",
"url",
"to",
"the",
"route",
"url"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Routing/Router.php#L605-L670 | train |
os-pek/ospek | src/OspekBackend.php | OspekBackend.getOutput | public function getOutput(String $file=null):Array
{
$file = ($file)?$file:$this->_logFile;
if (file_exists($file)) {
return file($file);
}
throw new \RunTimeException("file not found!");
} | php | public function getOutput(String $file=null):Array
{
$file = ($file)?$file:$this->_logFile;
if (file_exists($file)) {
return file($file);
}
throw new \RunTimeException("file not found!");
} | [
"public",
"function",
"getOutput",
"(",
"String",
"$",
"file",
"=",
"null",
")",
":",
"Array",
"{",
"$",
"file",
"=",
"(",
"$",
"file",
")",
"?",
"$",
"file",
":",
"$",
"this",
"->",
"_logFile",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"file",
"(",
"$",
"file",
")",
";",
"}",
"throw",
"new",
"\\",
"RunTimeException",
"(",
"\"file not found!\"",
")",
";",
"}"
] | end kill method | [
"end",
"kill",
"method"
] | 1b2994e7103886f75c0d04d9d7d704ee40f5b7cd | https://github.com/os-pek/ospek/blob/1b2994e7103886f75c0d04d9d7d704ee40f5b7cd/src/OspekBackend.php#L82-L89 | train |
ColonelBlimp/NsanjaCore | src/Nsanja/Core/Traits/PropertySetterTrait.php | PropertySetterTrait.setProperty | protected function setProperty(string $key, array $data, &$property, $default = null): void
{
if (isset($data[$key])) {
$property = $data[$key];
return;
}
// Only set the property to the default IF it is NOT null. Otherwise leave the value of the property as set
// in the class.
if ($default !== null) {
$property = $default; //@codeCoverageIgnore
}
} | php | protected function setProperty(string $key, array $data, &$property, $default = null): void
{
if (isset($data[$key])) {
$property = $data[$key];
return;
}
// Only set the property to the default IF it is NOT null. Otherwise leave the value of the property as set
// in the class.
if ($default !== null) {
$property = $default; //@codeCoverageIgnore
}
} | [
"protected",
"function",
"setProperty",
"(",
"string",
"$",
"key",
",",
"array",
"$",
"data",
",",
"&",
"$",
"property",
",",
"$",
"default",
"=",
"null",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"property",
"=",
"$",
"data",
"[",
"$",
"key",
"]",
";",
"return",
";",
"}",
"// Only set the property to the default IF it is NOT null. Otherwise leave the value of the property as set",
"// in the class.",
"if",
"(",
"$",
"default",
"!==",
"null",
")",
"{",
"$",
"property",
"=",
"$",
"default",
";",
"//@codeCoverageIgnore",
"}",
"}"
] | Checks the given key is set in the data array, if so, the given property is set with the value.
@param string $key
@param array $data
@param mixed $property Must be a property of the class.
@param mixed $default. The default value (if this parameter is set) and the key is not found in the data array. | [
"Checks",
"the",
"given",
"key",
"is",
"set",
"in",
"the",
"data",
"array",
"if",
"so",
"the",
"given",
"property",
"is",
"set",
"with",
"the",
"value",
"."
] | 935b7363ae21b340eaa5867560a29f965ec7d012 | https://github.com/ColonelBlimp/NsanjaCore/blob/935b7363ae21b340eaa5867560a29f965ec7d012/src/Nsanja/Core/Traits/PropertySetterTrait.php#L19-L31 | train |
balintsera/evista-perform | src/Form/Form.php | Form.addCSRFTokenField | private function addCSRFTokenField()
{
$this->nonceValue = $this->createNonce();
$nonce = new FormField(FormField::TYPE_HIDDEN);
$nonce
->setName('nonce')
->setValue($this->createNonce())
->setValidationCallback(
function ($value) {
if (function_exists('wp_verify_nonce')) {
if (!wp_verify_nonce($value, $this->nonceKey)) {
throw new \Exception('Unauthorized request');
}
} // Use own csrf token
else {
if (!isset($_SESSION['csrf_tokens'][$value])) {
throw new \Exception('Unauthorized request');
} else {
unset($_SESSION['csrf_tokens'][$value]);
}
}
return false;
}
)
->setMandatory(true);
$key = 'nonce';
$this->addField($key, $nonce);
} | php | private function addCSRFTokenField()
{
$this->nonceValue = $this->createNonce();
$nonce = new FormField(FormField::TYPE_HIDDEN);
$nonce
->setName('nonce')
->setValue($this->createNonce())
->setValidationCallback(
function ($value) {
if (function_exists('wp_verify_nonce')) {
if (!wp_verify_nonce($value, $this->nonceKey)) {
throw new \Exception('Unauthorized request');
}
} // Use own csrf token
else {
if (!isset($_SESSION['csrf_tokens'][$value])) {
throw new \Exception('Unauthorized request');
} else {
unset($_SESSION['csrf_tokens'][$value]);
}
}
return false;
}
)
->setMandatory(true);
$key = 'nonce';
$this->addField($key, $nonce);
} | [
"private",
"function",
"addCSRFTokenField",
"(",
")",
"{",
"$",
"this",
"->",
"nonceValue",
"=",
"$",
"this",
"->",
"createNonce",
"(",
")",
";",
"$",
"nonce",
"=",
"new",
"FormField",
"(",
"FormField",
"::",
"TYPE_HIDDEN",
")",
";",
"$",
"nonce",
"->",
"setName",
"(",
"'nonce'",
")",
"->",
"setValue",
"(",
"$",
"this",
"->",
"createNonce",
"(",
")",
")",
"->",
"setValidationCallback",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'wp_verify_nonce'",
")",
")",
"{",
"if",
"(",
"!",
"wp_verify_nonce",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"nonceKey",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unauthorized request'",
")",
";",
"}",
"}",
"// Use own csrf token",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"'csrf_tokens'",
"]",
"[",
"$",
"value",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unauthorized request'",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"'csrf_tokens'",
"]",
"[",
"$",
"value",
"]",
")",
";",
"}",
"}",
"return",
"false",
";",
"}",
")",
"->",
"setMandatory",
"(",
"true",
")",
";",
"$",
"key",
"=",
"'nonce'",
";",
"$",
"this",
"->",
"addField",
"(",
"$",
"key",
",",
"$",
"nonce",
")",
";",
"}"
] | Add CSRF token hidden input field | [
"Add",
"CSRF",
"token",
"hidden",
"input",
"field"
] | 2b8723852ebe824ed721f30293e1e0d2c14f4b21 | https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/Form/Form.php#L117-L146 | train |
balintsera/evista-perform | src/Form/Form.php | Form.populateFields | public function populateFields()
{
if (count($this->submittedData) < 1) {
return;
}
array_map(
function (FormField &$field) {
if (isset($this->submittedData[$field->getName()])) {
$raw = $this->submittedData[$field->getName()];
$sanitized = $field->sanitize($raw);
$field->setValue($sanitized);
} else {
// Unset value (see: checkboxes where value only sent when checkbox was checked
if ($field->getType() == FormField::TYPE_CHECKBOX) {
$field->setValue(null);
}
}
},
$this->getFields()
);
} | php | public function populateFields()
{
if (count($this->submittedData) < 1) {
return;
}
array_map(
function (FormField &$field) {
if (isset($this->submittedData[$field->getName()])) {
$raw = $this->submittedData[$field->getName()];
$sanitized = $field->sanitize($raw);
$field->setValue($sanitized);
} else {
// Unset value (see: checkboxes where value only sent when checkbox was checked
if ($field->getType() == FormField::TYPE_CHECKBOX) {
$field->setValue(null);
}
}
},
$this->getFields()
);
} | [
"public",
"function",
"populateFields",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"submittedData",
")",
"<",
"1",
")",
"{",
"return",
";",
"}",
"array_map",
"(",
"function",
"(",
"FormField",
"&",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"submittedData",
"[",
"$",
"field",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"$",
"raw",
"=",
"$",
"this",
"->",
"submittedData",
"[",
"$",
"field",
"->",
"getName",
"(",
")",
"]",
";",
"$",
"sanitized",
"=",
"$",
"field",
"->",
"sanitize",
"(",
"$",
"raw",
")",
";",
"$",
"field",
"->",
"setValue",
"(",
"$",
"sanitized",
")",
";",
"}",
"else",
"{",
"// Unset value (see: checkboxes where value only sent when checkbox was checked",
"if",
"(",
"$",
"field",
"->",
"getType",
"(",
")",
"==",
"FormField",
"::",
"TYPE_CHECKBOX",
")",
"{",
"$",
"field",
"->",
"setValue",
"(",
"null",
")",
";",
"}",
"}",
"}",
",",
"$",
"this",
"->",
"getFields",
"(",
")",
")",
";",
"}"
] | populates form from POST after submission | [
"populates",
"form",
"from",
"POST",
"after",
"submission"
] | 2b8723852ebe824ed721f30293e1e0d2c14f4b21 | https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/Form/Form.php#L173-L194 | train |
balintsera/evista-perform | src/Form/Form.php | Form.addFields | public function addFields(array $fields)
{
array_walk(
$fields,
function ($field, $key) {
$this->addField($key, $field);
}
);
} | php | public function addFields(array $fields)
{
array_walk(
$fields,
function ($field, $key) {
$this->addField($key, $field);
}
);
} | [
"public",
"function",
"addFields",
"(",
"array",
"$",
"fields",
")",
"{",
"array_walk",
"(",
"$",
"fields",
",",
"function",
"(",
"$",
"field",
",",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"addField",
"(",
"$",
"key",
",",
"$",
"field",
")",
";",
"}",
")",
";",
"}"
] | Add fields to the form
@param array $fields | [
"Add",
"fields",
"to",
"the",
"form"
] | 2b8723852ebe824ed721f30293e1e0d2c14f4b21 | https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/Form/Form.php#L351-L359 | train |
TiMESPLiNTER/tsFramework | src/ch/timesplinter/auth/AuthHandlerDB.php | AuthHandlerDB.generateSalt | public static function generateSalt($length = 32)
{
$salt = '';
for($i = 0; $i < $length; ++$i)
$salt .= chr(rand(0,127));
return $salt;
} | php | public static function generateSalt($length = 32)
{
$salt = '';
for($i = 0; $i < $length; ++$i)
$salt .= chr(rand(0,127));
return $salt;
} | [
"public",
"static",
"function",
"generateSalt",
"(",
"$",
"length",
"=",
"32",
")",
"{",
"$",
"salt",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"$",
"salt",
".=",
"chr",
"(",
"rand",
"(",
"0",
",",
"127",
")",
")",
";",
"return",
"$",
"salt",
";",
"}"
] | Generates a random string which can be used to salt the password
@param int $length
@return string | [
"Generates",
"a",
"random",
"string",
"which",
"can",
"be",
"used",
"to",
"salt",
"the",
"password"
] | b3b9fd98f6d456a9e571015877ecca203786fd0c | https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/auth/AuthHandlerDB.php#L231-L239 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.