repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration/Object.php
|
Object.registerToConfigurationWithIdentifier
|
public function registerToConfigurationWithIdentifier(
Configuration $configuration,
string $identifier
): ObjectInterface {
$this->identifier($identifier);
$configuration->addConfigurationObjectWithIdentifier($this->className, $this, $identifier);
return $this;
}
|
php
|
public function registerToConfigurationWithIdentifier(
Configuration $configuration,
string $identifier
): ObjectInterface {
$this->identifier($identifier);
$configuration->addConfigurationObjectWithIdentifier($this->className, $this, $identifier);
return $this;
}
|
[
"public",
"function",
"registerToConfigurationWithIdentifier",
"(",
"Configuration",
"$",
"configuration",
",",
"string",
"$",
"identifier",
")",
":",
"ObjectInterface",
"{",
"$",
"this",
"->",
"identifier",
"(",
"$",
"identifier",
")",
";",
"$",
"configuration",
"->",
"addConfigurationObjectWithIdentifier",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"this",
",",
"$",
"identifier",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
@param Configuration $configuration
@param string $identifier
@return ObjectInterface
|
[
"@param",
"Configuration",
"$configuration",
"@param",
"string",
"$identifier"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration/Object.php#L196-L204
|
blackprism/serializer
|
src/Blackprism/Serializer/Configuration/Object.php
|
Object.getTypeForAttribute
|
public function getTypeForAttribute(string $attribute): TypeInterface
{
if (isset($this->attributes[$attribute]) === false) {
return $this->blackhole;
}
return $this->attributes[$attribute];
}
|
php
|
public function getTypeForAttribute(string $attribute): TypeInterface
{
if (isset($this->attributes[$attribute]) === false) {
return $this->blackhole;
}
return $this->attributes[$attribute];
}
|
[
"public",
"function",
"getTypeForAttribute",
"(",
"string",
"$",
"attribute",
")",
":",
"TypeInterface",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attribute",
"]",
")",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"blackhole",
";",
"}",
"return",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attribute",
"]",
";",
"}"
] |
@param string $attribute
@return TypeInterface
|
[
"@param",
"string",
"$attribute"
] |
train
|
https://github.com/blackprism/serializer/blob/f5bd6ebeec802d2ad747daba7c9211b252ee4776/src/Blackprism/Serializer/Configuration/Object.php#L211-L218
|
drmvc/framework
|
src/Framework/App.php
|
App.initRequest
|
private function initRequest(): App
{
try {
$request = ServerRequestFactory::fromGlobals();
$this->containers()->set('request', $request);
} catch (\InvalidArgumentException $e) {
new Exception($e);
}
return $this;
}
|
php
|
private function initRequest(): App
{
try {
$request = ServerRequestFactory::fromGlobals();
$this->containers()->set('request', $request);
} catch (\InvalidArgumentException $e) {
new Exception($e);
}
return $this;
}
|
[
"private",
"function",
"initRequest",
"(",
")",
":",
"App",
"{",
"try",
"{",
"$",
"request",
"=",
"ServerRequestFactory",
"::",
"fromGlobals",
"(",
")",
";",
"$",
"this",
"->",
"containers",
"(",
")",
"->",
"set",
"(",
"'request'",
",",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"new",
"Exception",
"(",
"$",
"e",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Initiate PSR-7 request object
@return App
|
[
"Initiate",
"PSR",
"-",
"7",
"request",
"object"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L94-L103
|
drmvc/framework
|
src/Framework/App.php
|
App.initResponse
|
private function initResponse(): App
{
try {
$response = new Response();
$this->containers()->set('response', $response);
} catch (\InvalidArgumentException $e) {
new Exception($e);
}
return $this;
}
|
php
|
private function initResponse(): App
{
try {
$response = new Response();
$this->containers()->set('response', $response);
} catch (\InvalidArgumentException $e) {
new Exception($e);
}
return $this;
}
|
[
"private",
"function",
"initResponse",
"(",
")",
":",
"App",
"{",
"try",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"this",
"->",
"containers",
"(",
")",
"->",
"set",
"(",
"'response'",
",",
"$",
"response",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"new",
"Exception",
"(",
"$",
"e",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Initiate PSR-7 response object
@return App
|
[
"Initiate",
"PSR",
"-",
"7",
"response",
"object"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L110-L119
|
drmvc/framework
|
src/Framework/App.php
|
App.initRouter
|
private function initRouter(): App
{
$request = $this->container('request');
$response = $this->container('response');
$router = new Router($request, $response);
$router->error(Error::class);
$this->containers()->set('router', $router);
return $this;
}
|
php
|
private function initRouter(): App
{
$request = $this->container('request');
$response = $this->container('response');
$router = new Router($request, $response);
$router->error(Error::class);
$this->containers()->set('router', $router);
return $this;
}
|
[
"private",
"function",
"initRouter",
"(",
")",
":",
"App",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"container",
"(",
"'request'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"container",
"(",
"'response'",
")",
";",
"$",
"router",
"=",
"new",
"Router",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"$",
"router",
"->",
"error",
"(",
"Error",
"::",
"class",
")",
";",
"$",
"this",
"->",
"containers",
"(",
")",
"->",
"set",
"(",
"'router'",
",",
"$",
"router",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Put route into the container of classes
@return App
|
[
"Put",
"route",
"into",
"the",
"container",
"of",
"classes"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L126-L135
|
drmvc/framework
|
src/Framework/App.php
|
App.map
|
public function map(array $methods, string $pattern, $callable): MethodsInterface
{
$this->container('router')->map($methods, $pattern, $callable);
return $this;
}
|
php
|
public function map(array $methods, string $pattern, $callable): MethodsInterface
{
$this->container('router')->map($methods, $pattern, $callable);
return $this;
}
|
[
"public",
"function",
"map",
"(",
"array",
"$",
"methods",
",",
"string",
"$",
"pattern",
",",
"$",
"callable",
")",
":",
"MethodsInterface",
"{",
"$",
"this",
"->",
"container",
"(",
"'router'",
")",
"->",
"map",
"(",
"$",
"methods",
",",
"$",
"pattern",
",",
"$",
"callable",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Few methods provided
@param array $methods
@param string $pattern
@param callable|string $callable
@return MethodsInterface
|
[
"Few",
"methods",
"provided"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L206-L210
|
drmvc/framework
|
src/Framework/App.php
|
App.extractActionFromClass
|
private function extractActionFromClass(string $className)
{
// If class contain method name
if (strpos($className, ':') !== false) {
$classArray = explode(':', $className);
$classAction = end($classArray);
} else {
$classAction = null;
}
return $classAction;
}
|
php
|
private function extractActionFromClass(string $className)
{
// If class contain method name
if (strpos($className, ':') !== false) {
$classArray = explode(':', $className);
$classAction = end($classArray);
} else {
$classAction = null;
}
return $classAction;
}
|
[
"private",
"function",
"extractActionFromClass",
"(",
"string",
"$",
"className",
")",
"{",
"// If class contain method name",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"$",
"classArray",
"=",
"explode",
"(",
"':'",
",",
"$",
"className",
")",
";",
"$",
"classAction",
"=",
"end",
"(",
"$",
"classArray",
")",
";",
"}",
"else",
"{",
"$",
"classAction",
"=",
"null",
";",
"}",
"return",
"$",
"classAction",
";",
"}"
] |
Here we need parse line of class and extract action name after last ":" symbol
@param string $className
@return string|null
|
[
"Here",
"we",
"need",
"parse",
"line",
"of",
"class",
"and",
"extract",
"action",
"name",
"after",
"last",
":",
"symbol"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L218-L228
|
drmvc/framework
|
src/Framework/App.php
|
App.extractClass
|
private function extractClass(string $className): string
{
// If class name contain ":" symbol
if (strpos($className, ':') !== false) {
$classArray = explode(':', $className);
$className = $classArray[0];
}
return $className;
}
|
php
|
private function extractClass(string $className): string
{
// If class name contain ":" symbol
if (strpos($className, ':') !== false) {
$classArray = explode(':', $className);
$className = $classArray[0];
}
return $className;
}
|
[
"private",
"function",
"extractClass",
"(",
"string",
"$",
"className",
")",
":",
"string",
"{",
"// If class name contain \":\" symbol",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"$",
"classArray",
"=",
"explode",
"(",
"':'",
",",
"$",
"className",
")",
";",
"$",
"className",
"=",
"$",
"classArray",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"className",
";",
"}"
] |
Parse line of class, end return only class name (without possible action)
@param string $className
@return string
|
[
"Parse",
"line",
"of",
"class",
"end",
"return",
"only",
"class",
"name",
"(",
"without",
"possible",
"action",
")"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L236-L244
|
drmvc/framework
|
src/Framework/App.php
|
App.detectAction
|
private function detectAction(string $className, array $variables = []): string
{
$action =
// 1. Action name in line with class name eg. MyApp\Index:test - alias for `action_test`
$this->extractActionFromClass($className)
?? (
// 2. If action name in variables (we need first item)
$variables['action'][0]
// 3. Default action is index
?? self::DEFAULT_ACTION
);
return 'action_' . $action;
}
|
php
|
private function detectAction(string $className, array $variables = []): string
{
$action =
// 1. Action name in line with class name eg. MyApp\Index:test - alias for `action_test`
$this->extractActionFromClass($className)
?? (
// 2. If action name in variables (we need first item)
$variables['action'][0]
// 3. Default action is index
?? self::DEFAULT_ACTION
);
return 'action_' . $action;
}
|
[
"private",
"function",
"detectAction",
"(",
"string",
"$",
"className",
",",
"array",
"$",
"variables",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"action",
"=",
"// 1. Action name in line with class name eg. MyApp\\Index:test - alias for `action_test`",
"$",
"this",
"->",
"extractActionFromClass",
"(",
"$",
"className",
")",
"??",
"(",
"// 2. If action name in variables (we need first item)",
"$",
"variables",
"[",
"'action'",
"]",
"[",
"0",
"]",
"// 3. Default action is index",
"??",
"self",
"::",
"DEFAULT_ACTION",
")",
";",
"return",
"'action_'",
".",
"$",
"action",
";",
"}"
] |
Detect action by string name, variable or use default
@param string $className - eg. MyApp\Index:test
@param array $variables
@return string
|
[
"Detect",
"action",
"by",
"string",
"name",
"variable",
"or",
"use",
"default"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L253-L266
|
drmvc/framework
|
src/Framework/App.php
|
App.methodCheck
|
private function methodCheck($class, string $action): bool
{
try {
// If method not found in required class
if (!\method_exists($class, $action)) {
$className = \get_class($class);
throw new Exception("Method \"$action\" is not found in \"$className\"");
}
} catch (Exception $e) {
return false;
}
return true;
}
|
php
|
private function methodCheck($class, string $action): bool
{
try {
// If method not found in required class
if (!\method_exists($class, $action)) {
$className = \get_class($class);
throw new Exception("Method \"$action\" is not found in \"$className\"");
}
} catch (Exception $e) {
return false;
}
return true;
}
|
[
"private",
"function",
"methodCheck",
"(",
"$",
"class",
",",
"string",
"$",
"action",
")",
":",
"bool",
"{",
"try",
"{",
"// If method not found in required class",
"if",
"(",
"!",
"\\",
"method_exists",
"(",
"$",
"class",
",",
"$",
"action",
")",
")",
"{",
"$",
"className",
"=",
"\\",
"get_class",
"(",
"$",
"class",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Method \\\"$action\\\" is not found in \\\"$className\\\"\"",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if method exist in required class
@param object $class
@param string $action
@return bool
|
[
"Check",
"if",
"method",
"exist",
"in",
"required",
"class"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L275-L287
|
drmvc/framework
|
src/Framework/App.php
|
App.exec
|
private function exec(
RouteInterface $route,
RequestInterface $request,
ResponseInterface $response,
bool $error = false
) {
$variables = $route->getVariables();
$callback = $route->getCallback();
// If extracted call back is string
if (\is_string($callback)) {
$className = $this->extractClass($callback);
// Then class provided
$class = new $className();
$action = $this->detectAction($callback, $variables);
// If method is not found in class and error is not triggered, then trigger error
if (true !== $error && false === $this->methodCheck($class, $action)) {
$router = $this->container('router');
$routeError = $router->getError();
return $this->exec($routeError, $request, $response, true);
}
// Call required action, with request/response
$class->$action($request, $response, $variables);
} else {
// Else simple callback
$callback($request, $response, $variables);
}
return $response->getBody();
}
|
php
|
private function exec(
RouteInterface $route,
RequestInterface $request,
ResponseInterface $response,
bool $error = false
) {
$variables = $route->getVariables();
$callback = $route->getCallback();
// If extracted call back is string
if (\is_string($callback)) {
$className = $this->extractClass($callback);
// Then class provided
$class = new $className();
$action = $this->detectAction($callback, $variables);
// If method is not found in class and error is not triggered, then trigger error
if (true !== $error && false === $this->methodCheck($class, $action)) {
$router = $this->container('router');
$routeError = $router->getError();
return $this->exec($routeError, $request, $response, true);
}
// Call required action, with request/response
$class->$action($request, $response, $variables);
} else {
// Else simple callback
$callback($request, $response, $variables);
}
return $response->getBody();
}
|
[
"private",
"function",
"exec",
"(",
"RouteInterface",
"$",
"route",
",",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"bool",
"$",
"error",
"=",
"false",
")",
"{",
"$",
"variables",
"=",
"$",
"route",
"->",
"getVariables",
"(",
")",
";",
"$",
"callback",
"=",
"$",
"route",
"->",
"getCallback",
"(",
")",
";",
"// If extracted call back is string",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"extractClass",
"(",
"$",
"callback",
")",
";",
"// Then class provided",
"$",
"class",
"=",
"new",
"$",
"className",
"(",
")",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"detectAction",
"(",
"$",
"callback",
",",
"$",
"variables",
")",
";",
"// If method is not found in class and error is not triggered, then trigger error",
"if",
"(",
"true",
"!==",
"$",
"error",
"&&",
"false",
"===",
"$",
"this",
"->",
"methodCheck",
"(",
"$",
"class",
",",
"$",
"action",
")",
")",
"{",
"$",
"router",
"=",
"$",
"this",
"->",
"container",
"(",
"'router'",
")",
";",
"$",
"routeError",
"=",
"$",
"router",
"->",
"getError",
"(",
")",
";",
"return",
"$",
"this",
"->",
"exec",
"(",
"$",
"routeError",
",",
"$",
"request",
",",
"$",
"response",
",",
"true",
")",
";",
"}",
"// Call required action, with request/response",
"$",
"class",
"->",
"$",
"action",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"variables",
")",
";",
"}",
"else",
"{",
"// Else simple callback",
"$",
"callback",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"variables",
")",
";",
"}",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
] |
Here we need to solve how to display the page, and if method is
not available need to show error
@param RouteInterface $route
@param RequestInterface $request
@param ResponseInterface $response
@param bool $error
@return StreamInterface
|
[
"Here",
"we",
"need",
"to",
"solve",
"how",
"to",
"display",
"the",
"page",
"and",
"if",
"method",
"is",
"not",
"available",
"need",
"to",
"show",
"error"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L299-L331
|
drmvc/framework
|
src/Framework/App.php
|
App.run
|
public function run(): StreamInterface
{
// Extract some important objects
$router = $this->container('router');
$request = $this->container('request');
$response = $this->container('response');
// Get current matched route with and extract variables with callback
$route = $router->getRoute();
return $this->exec($route, $request, $response);
}
|
php
|
public function run(): StreamInterface
{
// Extract some important objects
$router = $this->container('router');
$request = $this->container('request');
$response = $this->container('response');
// Get current matched route with and extract variables with callback
$route = $router->getRoute();
return $this->exec($route, $request, $response);
}
|
[
"public",
"function",
"run",
"(",
")",
":",
"StreamInterface",
"{",
"// Extract some important objects",
"$",
"router",
"=",
"$",
"this",
"->",
"container",
"(",
"'router'",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"container",
"(",
"'request'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"container",
"(",
"'response'",
")",
";",
"// Get current matched route with and extract variables with callback",
"$",
"route",
"=",
"$",
"router",
"->",
"getRoute",
"(",
")",
";",
"return",
"$",
"this",
"->",
"exec",
"(",
"$",
"route",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] |
Simple runner should parse query and make work on user's class
@return StreamInterface
|
[
"Simple",
"runner",
"should",
"parse",
"query",
"and",
"make",
"work",
"on",
"user",
"s",
"class"
] |
train
|
https://github.com/drmvc/framework/blob/6a49aa4e0314b37343a95d7c8ac5d10f72b45d71/src/Framework/App.php#L338-L349
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/ResolvingResource.php
|
ResolvingResource.resolve
|
public function resolve(Request $request, Response $response)
{
$uriPath = $this->calledUri->path($this->route->configuredPath());
$target = $this->route->target();
if (is_callable($target)) {
return $target($request, $response, $uriPath);
}
if ($target instanceof Target) {
return $target->resolve($request, $response, $uriPath);
}
$targetInstance = $this->injector->getInstance($target);
if (!($targetInstance instanceof Target)) {
return $response->internalServerError(
'Configured target class ' . $target . ' for route ' . $uriPath
. ' is not an instance of ' . Target::class
);
}
return $targetInstance->resolve($request, $response, $uriPath);
}
|
php
|
public function resolve(Request $request, Response $response)
{
$uriPath = $this->calledUri->path($this->route->configuredPath());
$target = $this->route->target();
if (is_callable($target)) {
return $target($request, $response, $uriPath);
}
if ($target instanceof Target) {
return $target->resolve($request, $response, $uriPath);
}
$targetInstance = $this->injector->getInstance($target);
if (!($targetInstance instanceof Target)) {
return $response->internalServerError(
'Configured target class ' . $target . ' for route ' . $uriPath
. ' is not an instance of ' . Target::class
);
}
return $targetInstance->resolve($request, $response, $uriPath);
}
|
[
"public",
"function",
"resolve",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"uriPath",
"=",
"$",
"this",
"->",
"calledUri",
"->",
"path",
"(",
"$",
"this",
"->",
"route",
"->",
"configuredPath",
"(",
")",
")",
";",
"$",
"target",
"=",
"$",
"this",
"->",
"route",
"->",
"target",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"target",
")",
")",
"{",
"return",
"$",
"target",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"uriPath",
")",
";",
"}",
"if",
"(",
"$",
"target",
"instanceof",
"Target",
")",
"{",
"return",
"$",
"target",
"->",
"resolve",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"uriPath",
")",
";",
"}",
"$",
"targetInstance",
"=",
"$",
"this",
"->",
"injector",
"->",
"getInstance",
"(",
"$",
"target",
")",
";",
"if",
"(",
"!",
"(",
"$",
"targetInstance",
"instanceof",
"Target",
")",
")",
"{",
"return",
"$",
"response",
"->",
"internalServerError",
"(",
"'Configured target class '",
".",
"$",
"target",
".",
"' for route '",
".",
"$",
"uriPath",
".",
"' is not an instance of '",
".",
"Target",
"::",
"class",
")",
";",
"}",
"return",
"$",
"targetInstance",
"->",
"resolve",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"uriPath",
")",
";",
"}"
] |
triggers actual logic on this resource
The logic might be capsuled in a closure, a callback, or a processor
class. The return value from this logic will be used to evaluate whether
post processors are called by the web app. A return value of false means
no post processor will be called, whereas any other or no return value
will result in post processors being called by the webapp.
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return mixed
|
[
"triggers",
"actual",
"logic",
"on",
"this",
"resource"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/ResolvingResource.php#L73-L94
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.table
|
public function table(Table\Table $table)
{
// Headers
$head = '';
$headers = [];
$hasStrainer = false;
foreach($table->getColumns() as $column) {
/** @var Column\Column $column */
$label = $column->getLabel();
if ($column->hasDescription()) {
$label .= ' <i class="fa fa-question-circle" data-toggle="tooltip" title="'.$column->getDescription().'"></i>';
}
$head .= html('th', ['class' => 'text-center'], $label);
$headers[] = $column->getName();
$hasStrainer = $hasStrainer || $column->hasStrainer();
}
$head = html('tr', ['class' => 'heading'], $head);
// Strainer
if ($hasStrainer) {
// initialisation des strainer
$strainer = '';
foreach($table->getColumns() as $column) {
/** @var Column\Column $column */
$content = '';
if ($column->hasStrainer()) {
$content = $column->getStrainer()->render();
}
$strainer .= html('th', ['class' => 'text-center'],$content);
}
$head .= html('tr', ['class' => 'filter'], $strainer);
}
// Data
$body = '';
foreach($table->getRows() as $row) {
$line = '';
foreach($table->getColumns() as $name => $column) {
$attributes = $column->getAttributes();
if ($table->hasIdField()) {
if (!isset($row[$table->getIdField()])) {
throw new \LogicException($table->getIdField() . ' column is not found');
}
//too soon for you
// $attributes['data-id'] = sprintf('%s#%s', $row[$table->getIdField()], $name);
}
// remove class in colum because it set in column for datatable
if ($table->isDatatable()) {
unset($attributes['class']);
}
$line .= html('td', $attributes, $column->render((array) $row)) . PHP_EOL;
}
$body .= html('tr', [],$line );
}
// Footer
$footer = '';
if ($table->isDatatable()) {
$this->render('datatable', $table);
} elseif ($table->hasFooter()) {
$current = $table->getPage();
$footer .= sprintf('<li class="disabled"><span>«</span></li>');
for ($i = 1; $i <= min(10, $table->getPagesTotal()); $i++) {
$footer .= html('li', ['class' => $current == $i ? 'active' : null], sprintf('<a href="%s">%s</a>', $table->getPageUrl($i), $i));
}
$footer .= sprintf('<li><a href="%s" rel="next">»</a></li>', '#');
$footer = html('ul', ['class' => 'pagination'], $footer);
$footer = html('td', ['colspan' => count($headers)], $footer);
$footer = html('tr', [], $footer);
$footer = html('tfoot', ['class' => 'text-center'], $footer);
}
// Bootstrap class management
$table->addClass(Style::TABLE_CLASS);
if ($table->isStriped()){
$table->addClass(Style::TABLE_CLASS_STRIPED);
}
if ($table->isBordered()) {
$table->addClass(Style::TABLE_CLASS_BORDERED);
}
if ($table->isCondensed()) {
$table->addClass(Style::TABLE_CLASS_CONDENSED);
}
if ($table->hasHover()) {
$table->addClass(Style::TABLE_CLASS_HOVER);
}
$html = html('table', $table->getAttributes(), html('thead', [], $head) . html('tbody', [], $body) . $footer);
// responsive
if ($table->isResponsive()){
$html = html('div', ['class' => Style::TABLE_CLASS_RESPONSIVE], $html);
}
if ($table->hasPanel()) {
$html = $table->getPanel()->setBody($html)->render();
}
return $html;
}
|
php
|
public function table(Table\Table $table)
{
// Headers
$head = '';
$headers = [];
$hasStrainer = false;
foreach($table->getColumns() as $column) {
/** @var Column\Column $column */
$label = $column->getLabel();
if ($column->hasDescription()) {
$label .= ' <i class="fa fa-question-circle" data-toggle="tooltip" title="'.$column->getDescription().'"></i>';
}
$head .= html('th', ['class' => 'text-center'], $label);
$headers[] = $column->getName();
$hasStrainer = $hasStrainer || $column->hasStrainer();
}
$head = html('tr', ['class' => 'heading'], $head);
// Strainer
if ($hasStrainer) {
// initialisation des strainer
$strainer = '';
foreach($table->getColumns() as $column) {
/** @var Column\Column $column */
$content = '';
if ($column->hasStrainer()) {
$content = $column->getStrainer()->render();
}
$strainer .= html('th', ['class' => 'text-center'],$content);
}
$head .= html('tr', ['class' => 'filter'], $strainer);
}
// Data
$body = '';
foreach($table->getRows() as $row) {
$line = '';
foreach($table->getColumns() as $name => $column) {
$attributes = $column->getAttributes();
if ($table->hasIdField()) {
if (!isset($row[$table->getIdField()])) {
throw new \LogicException($table->getIdField() . ' column is not found');
}
//too soon for you
// $attributes['data-id'] = sprintf('%s#%s', $row[$table->getIdField()], $name);
}
// remove class in colum because it set in column for datatable
if ($table->isDatatable()) {
unset($attributes['class']);
}
$line .= html('td', $attributes, $column->render((array) $row)) . PHP_EOL;
}
$body .= html('tr', [],$line );
}
// Footer
$footer = '';
if ($table->isDatatable()) {
$this->render('datatable', $table);
} elseif ($table->hasFooter()) {
$current = $table->getPage();
$footer .= sprintf('<li class="disabled"><span>«</span></li>');
for ($i = 1; $i <= min(10, $table->getPagesTotal()); $i++) {
$footer .= html('li', ['class' => $current == $i ? 'active' : null], sprintf('<a href="%s">%s</a>', $table->getPageUrl($i), $i));
}
$footer .= sprintf('<li><a href="%s" rel="next">»</a></li>', '#');
$footer = html('ul', ['class' => 'pagination'], $footer);
$footer = html('td', ['colspan' => count($headers)], $footer);
$footer = html('tr', [], $footer);
$footer = html('tfoot', ['class' => 'text-center'], $footer);
}
// Bootstrap class management
$table->addClass(Style::TABLE_CLASS);
if ($table->isStriped()){
$table->addClass(Style::TABLE_CLASS_STRIPED);
}
if ($table->isBordered()) {
$table->addClass(Style::TABLE_CLASS_BORDERED);
}
if ($table->isCondensed()) {
$table->addClass(Style::TABLE_CLASS_CONDENSED);
}
if ($table->hasHover()) {
$table->addClass(Style::TABLE_CLASS_HOVER);
}
$html = html('table', $table->getAttributes(), html('thead', [], $head) . html('tbody', [], $body) . $footer);
// responsive
if ($table->isResponsive()){
$html = html('div', ['class' => Style::TABLE_CLASS_RESPONSIVE], $html);
}
if ($table->hasPanel()) {
$html = $table->getPanel()->setBody($html)->render();
}
return $html;
}
|
[
"public",
"function",
"table",
"(",
"Table",
"\\",
"Table",
"$",
"table",
")",
"{",
"// Headers",
"$",
"head",
"=",
"''",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"hasStrainer",
"=",
"false",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"/** @var Column\\Column $column */",
"$",
"label",
"=",
"$",
"column",
"->",
"getLabel",
"(",
")",
";",
"if",
"(",
"$",
"column",
"->",
"hasDescription",
"(",
")",
")",
"{",
"$",
"label",
".=",
"' <i class=\"fa fa-question-circle\" data-toggle=\"tooltip\" title=\"'",
".",
"$",
"column",
"->",
"getDescription",
"(",
")",
".",
"'\"></i>'",
";",
"}",
"$",
"head",
".=",
"html",
"(",
"'th'",
",",
"[",
"'class'",
"=>",
"'text-center'",
"]",
",",
"$",
"label",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"$",
"column",
"->",
"getName",
"(",
")",
";",
"$",
"hasStrainer",
"=",
"$",
"hasStrainer",
"||",
"$",
"column",
"->",
"hasStrainer",
"(",
")",
";",
"}",
"$",
"head",
"=",
"html",
"(",
"'tr'",
",",
"[",
"'class'",
"=>",
"'heading'",
"]",
",",
"$",
"head",
")",
";",
"// Strainer",
"if",
"(",
"$",
"hasStrainer",
")",
"{",
"// initialisation des strainer",
"$",
"strainer",
"=",
"''",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"/** @var Column\\Column $column */",
"$",
"content",
"=",
"''",
";",
"if",
"(",
"$",
"column",
"->",
"hasStrainer",
"(",
")",
")",
"{",
"$",
"content",
"=",
"$",
"column",
"->",
"getStrainer",
"(",
")",
"->",
"render",
"(",
")",
";",
"}",
"$",
"strainer",
".=",
"html",
"(",
"'th'",
",",
"[",
"'class'",
"=>",
"'text-center'",
"]",
",",
"$",
"content",
")",
";",
"}",
"$",
"head",
".=",
"html",
"(",
"'tr'",
",",
"[",
"'class'",
"=>",
"'filter'",
"]",
",",
"$",
"strainer",
")",
";",
"}",
"// Data",
"$",
"body",
"=",
"''",
";",
"foreach",
"(",
"$",
"table",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"line",
"=",
"''",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"column",
")",
"{",
"$",
"attributes",
"=",
"$",
"column",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"$",
"table",
"->",
"hasIdField",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"$",
"table",
"->",
"getIdField",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"$",
"table",
"->",
"getIdField",
"(",
")",
".",
"' column is not found'",
")",
";",
"}",
"//too soon for you",
"// $attributes['data-id'] = sprintf('%s#%s', $row[$table->getIdField()], $name);",
"}",
"// remove class in colum because it set in column for datatable",
"if",
"(",
"$",
"table",
"->",
"isDatatable",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"'class'",
"]",
")",
";",
"}",
"$",
"line",
".=",
"html",
"(",
"'td'",
",",
"$",
"attributes",
",",
"$",
"column",
"->",
"render",
"(",
"(",
"array",
")",
"$",
"row",
")",
")",
".",
"PHP_EOL",
";",
"}",
"$",
"body",
".=",
"html",
"(",
"'tr'",
",",
"[",
"]",
",",
"$",
"line",
")",
";",
"}",
"// Footer",
"$",
"footer",
"=",
"''",
";",
"if",
"(",
"$",
"table",
"->",
"isDatatable",
"(",
")",
")",
"{",
"$",
"this",
"->",
"render",
"(",
"'datatable'",
",",
"$",
"table",
")",
";",
"}",
"elseif",
"(",
"$",
"table",
"->",
"hasFooter",
"(",
")",
")",
"{",
"$",
"current",
"=",
"$",
"table",
"->",
"getPage",
"(",
")",
";",
"$",
"footer",
".=",
"sprintf",
"(",
"'<li class=\"disabled\"><span>«</span></li>'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"min",
"(",
"10",
",",
"$",
"table",
"->",
"getPagesTotal",
"(",
")",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"footer",
".=",
"html",
"(",
"'li'",
",",
"[",
"'class'",
"=>",
"$",
"current",
"==",
"$",
"i",
"?",
"'active'",
":",
"null",
"]",
",",
"sprintf",
"(",
"'<a href=\"%s\">%s</a>'",
",",
"$",
"table",
"->",
"getPageUrl",
"(",
"$",
"i",
")",
",",
"$",
"i",
")",
")",
";",
"}",
"$",
"footer",
".=",
"sprintf",
"(",
"'<li><a href=\"%s\" rel=\"next\">»</a></li>'",
",",
"'#'",
")",
";",
"$",
"footer",
"=",
"html",
"(",
"'ul'",
",",
"[",
"'class'",
"=>",
"'pagination'",
"]",
",",
"$",
"footer",
")",
";",
"$",
"footer",
"=",
"html",
"(",
"'td'",
",",
"[",
"'colspan'",
"=>",
"count",
"(",
"$",
"headers",
")",
"]",
",",
"$",
"footer",
")",
";",
"$",
"footer",
"=",
"html",
"(",
"'tr'",
",",
"[",
"]",
",",
"$",
"footer",
")",
";",
"$",
"footer",
"=",
"html",
"(",
"'tfoot'",
",",
"[",
"'class'",
"=>",
"'text-center'",
"]",
",",
"$",
"footer",
")",
";",
"}",
"// Bootstrap class management",
"$",
"table",
"->",
"addClass",
"(",
"Style",
"::",
"TABLE_CLASS",
")",
";",
"if",
"(",
"$",
"table",
"->",
"isStriped",
"(",
")",
")",
"{",
"$",
"table",
"->",
"addClass",
"(",
"Style",
"::",
"TABLE_CLASS_STRIPED",
")",
";",
"}",
"if",
"(",
"$",
"table",
"->",
"isBordered",
"(",
")",
")",
"{",
"$",
"table",
"->",
"addClass",
"(",
"Style",
"::",
"TABLE_CLASS_BORDERED",
")",
";",
"}",
"if",
"(",
"$",
"table",
"->",
"isCondensed",
"(",
")",
")",
"{",
"$",
"table",
"->",
"addClass",
"(",
"Style",
"::",
"TABLE_CLASS_CONDENSED",
")",
";",
"}",
"if",
"(",
"$",
"table",
"->",
"hasHover",
"(",
")",
")",
"{",
"$",
"table",
"->",
"addClass",
"(",
"Style",
"::",
"TABLE_CLASS_HOVER",
")",
";",
"}",
"$",
"html",
"=",
"html",
"(",
"'table'",
",",
"$",
"table",
"->",
"getAttributes",
"(",
")",
",",
"html",
"(",
"'thead'",
",",
"[",
"]",
",",
"$",
"head",
")",
".",
"html",
"(",
"'tbody'",
",",
"[",
"]",
",",
"$",
"body",
")",
".",
"$",
"footer",
")",
";",
"// responsive",
"if",
"(",
"$",
"table",
"->",
"isResponsive",
"(",
")",
")",
"{",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"[",
"'class'",
"=>",
"Style",
"::",
"TABLE_CLASS_RESPONSIVE",
"]",
",",
"$",
"html",
")",
";",
"}",
"if",
"(",
"$",
"table",
"->",
"hasPanel",
"(",
")",
")",
"{",
"$",
"html",
"=",
"$",
"table",
"->",
"getPanel",
"(",
")",
"->",
"setBody",
"(",
"$",
"html",
")",
"->",
"render",
"(",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] |
Render the table structure
Main method
@param \FrenchFrogs\Table\Table\Table $table
@return mixed|string
@throws \Exception
|
[
"Render",
"the",
"table",
"structure",
"Main",
"method"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L56-L176
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.container
|
public function container(Column\Container $column, array $row) {
$html = '';
foreach($column->getColumns() as $c) {
/** @var Column\Column $c */
$html .= $c->render($row) . PHP_EOL;
}
return $this->post($html, $column, $row);
}
|
php
|
public function container(Column\Container $column, array $row) {
$html = '';
foreach($column->getColumns() as $c) {
/** @var Column\Column $c */
$html .= $c->render($row) . PHP_EOL;
}
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"container",
"(",
"Column",
"\\",
"Container",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"column",
"->",
"getColumns",
"(",
")",
"as",
"$",
"c",
")",
"{",
"/** @var Column\\Column $c */",
"$",
"html",
".=",
"$",
"c",
"->",
"render",
"(",
"$",
"row",
")",
".",
"PHP_EOL",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Render a container
@param \FrenchFrogs\Table\Column\Container $column
@param array $row
@return string
|
[
"Render",
"a",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L186-L195
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.boolean
|
public function boolean(Column\Boolean $column, array $row)
{
$html = '';
if($column->getValue($row)) {
$html .= '<i class="fa fa-check"></i>';
}
return $this->post($html, $column, $row);
}
|
php
|
public function boolean(Column\Boolean $column, array $row)
{
$html = '';
if($column->getValue($row)) {
$html .= '<i class="fa fa-check"></i>';
}
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"boolean",
"(",
"Column",
"\\",
"Boolean",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"html",
"=",
"''",
";",
"if",
"(",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
")",
"{",
"$",
"html",
".=",
"'<i class=\"fa fa-check\"></i>'",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
render boolean icon
@param \FrenchFrogs\Table\Column\Boolean $column
@param array $row
@return string
|
[
"render",
"boolean",
"icon"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L204-L213
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.remote_boolean
|
public function remote_boolean(Column\RemoteBoolean $column, array $row)
{
$table = $column->getTable();
// Attributes
$attributes = [
'class' => 'ff-remote-boolean make-switch',
'type' => 'checkbox',
'data-size' => 'small',
'value' => true,
'data-id' => $row[$column->getTable()->getIdField()],
'data-column' => $column->getName(),
];
if(isset($row[$column->getName()]) && !empty($row[$column->getName()])) {
$attributes['checked'] = 'checked';
}
$html = html('input', $attributes);
return $this->post($html, $column, $row);
}
|
php
|
public function remote_boolean(Column\RemoteBoolean $column, array $row)
{
$table = $column->getTable();
// Attributes
$attributes = [
'class' => 'ff-remote-boolean make-switch',
'type' => 'checkbox',
'data-size' => 'small',
'value' => true,
'data-id' => $row[$column->getTable()->getIdField()],
'data-column' => $column->getName(),
];
if(isset($row[$column->getName()]) && !empty($row[$column->getName()])) {
$attributes['checked'] = 'checked';
}
$html = html('input', $attributes);
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"remote_boolean",
"(",
"Column",
"\\",
"RemoteBoolean",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"table",
"=",
"$",
"column",
"->",
"getTable",
"(",
")",
";",
"// Attributes",
"$",
"attributes",
"=",
"[",
"'class'",
"=>",
"'ff-remote-boolean make-switch'",
",",
"'type'",
"=>",
"'checkbox'",
",",
"'data-size'",
"=>",
"'small'",
",",
"'value'",
"=>",
"true",
",",
"'data-id'",
"=>",
"$",
"row",
"[",
"$",
"column",
"->",
"getTable",
"(",
")",
"->",
"getIdField",
"(",
")",
"]",
",",
"'data-column'",
"=>",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"$",
"column",
"->",
"getName",
"(",
")",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"row",
"[",
"$",
"column",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"$",
"attributes",
"[",
"'checked'",
"]",
"=",
"'checked'",
";",
"}",
"$",
"html",
"=",
"html",
"(",
"'input'",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
render boolean switch
@param \FrenchFrogs\Table\Column\BooleanSwitch $column
@param array $row
@return string
|
[
"render",
"boolean",
"switch"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L222-L245
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.icon
|
public function icon(Column\Icon $column, array $row)
{
$html = '';
$html .= '<i class="fa '. $column->getValue($row).'"></i>';
return $this->post($html, $column, $row);
}
|
php
|
public function icon(Column\Icon $column, array $row)
{
$html = '';
$html .= '<i class="fa '. $column->getValue($row).'"></i>';
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"icon",
"(",
"Column",
"\\",
"Icon",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"html",
".=",
"'<i class=\"fa '",
".",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
".",
"'\"></i>'",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Render Icon column
@param \FrenchFrogs\Table\Column\Icon $column
@param array $row
@return string
|
[
"Render",
"Icon",
"column"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L255-L262
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.custom
|
public function custom(Column\Custom $column, array $row)
{
$html = call_user_func($column->getCustom(), $row);
return $this->post($html, $column, $row);
}
|
php
|
public function custom(Column\Custom $column, array $row)
{
$html = call_user_func($column->getCustom(), $row);
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"custom",
"(",
"Column",
"\\",
"Custom",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"html",
"=",
"call_user_func",
"(",
"$",
"column",
"->",
"getCustom",
"(",
")",
",",
"$",
"row",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Render custom callable column
@param \FrenchFrogs\Table\Column\Custom $column
@param array $row
@return mixed
|
[
"Render",
"custom",
"callable",
"column"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L271-L275
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.text
|
public function text(Column\Text $column, array $row)
{
$attributes = $column->getAttributes();
if($column->hasTooltip()){
$attributes += [
'data-placement' => $column->getTooltipPosition(),
'data-original-title' => $column->getValue($row),
'data-toggle' => 'tooltip'
];
$html = html('div', $attributes, str_limit($column->getValue($row), 70));
} else {
$html = html('span',$attributes, $column->getValue($row));
}
return $this->post($html, $column, $row);
}
|
php
|
public function text(Column\Text $column, array $row)
{
$attributes = $column->getAttributes();
if($column->hasTooltip()){
$attributes += [
'data-placement' => $column->getTooltipPosition(),
'data-original-title' => $column->getValue($row),
'data-toggle' => 'tooltip'
];
$html = html('div', $attributes, str_limit($column->getValue($row), 70));
} else {
$html = html('span',$attributes, $column->getValue($row));
}
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"text",
"(",
"Column",
"\\",
"Text",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"attributes",
"=",
"$",
"column",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"$",
"column",
"->",
"hasTooltip",
"(",
")",
")",
"{",
"$",
"attributes",
"+=",
"[",
"'data-placement'",
"=>",
"$",
"column",
"->",
"getTooltipPosition",
"(",
")",
",",
"'data-original-title'",
"=>",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
",",
"'data-toggle'",
"=>",
"'tooltip'",
"]",
";",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"$",
"attributes",
",",
"str_limit",
"(",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
",",
"70",
")",
")",
";",
"}",
"else",
"{",
"$",
"html",
"=",
"html",
"(",
"'span'",
",",
"$",
"attributes",
",",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Render text column
@param \FrenchFrogs\Table\Column\Text $column
@param array $row
@return mixed|string
|
[
"Render",
"text",
"column"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L285-L303
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.remote_text
|
public function remote_text(Column\RemoteText $column, array $row)
{
$html = $this->text($column, $row);
$html .= html('input', [
'type' => 'text',
'data-id' => $row[$column->getTable()->getIdField()],
'data-column' => $column->getName()
]);
$html = html('div', ['class' => 'ff-remote-text'], $html);
return $html;
}
|
php
|
public function remote_text(Column\RemoteText $column, array $row)
{
$html = $this->text($column, $row);
$html .= html('input', [
'type' => 'text',
'data-id' => $row[$column->getTable()->getIdField()],
'data-column' => $column->getName()
]);
$html = html('div', ['class' => 'ff-remote-text'], $html);
return $html;
}
|
[
"public",
"function",
"remote_text",
"(",
"Column",
"\\",
"RemoteText",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"text",
"(",
"$",
"column",
",",
"$",
"row",
")",
";",
"$",
"html",
".=",
"html",
"(",
"'input'",
",",
"[",
"'type'",
"=>",
"'text'",
",",
"'data-id'",
"=>",
"$",
"row",
"[",
"$",
"column",
"->",
"getTable",
"(",
")",
"->",
"getIdField",
"(",
")",
"]",
",",
"'data-column'",
"=>",
"$",
"column",
"->",
"getName",
"(",
")",
"]",
")",
";",
"$",
"html",
"=",
"html",
"(",
"'div'",
",",
"[",
"'class'",
"=>",
"'ff-remote-text'",
"]",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Render a text remote
@param \FrenchFrogs\Table\Column\RemoteText $column
@param array $row
@return mixed|string
|
[
"Render",
"a",
"text",
"remote"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L342-L353
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.remote_select
|
public function remote_select(Column\RemoteSelect $column, array $row)
{
// OPTIONS
$options = html('option', [], '--');
$elementValue = $row[$column->getIndex()];
foreach($column->getOptions() as $value => $key){
$attr = ['value' => $value];
if ($value == $elementValue){
$attr['selected'] = 'selected';
}
$options .= html('option', $attr, $key);
}
$html = html('select', [
'class' => 'ff-remote-select',
'data-id' => $row[$column->getTable()->getIdField()],
'data-column' => $column->getName()
], $options);
return $html;
}
|
php
|
public function remote_select(Column\RemoteSelect $column, array $row)
{
// OPTIONS
$options = html('option', [], '--');
$elementValue = $row[$column->getIndex()];
foreach($column->getOptions() as $value => $key){
$attr = ['value' => $value];
if ($value == $elementValue){
$attr['selected'] = 'selected';
}
$options .= html('option', $attr, $key);
}
$html = html('select', [
'class' => 'ff-remote-select',
'data-id' => $row[$column->getTable()->getIdField()],
'data-column' => $column->getName()
], $options);
return $html;
}
|
[
"public",
"function",
"remote_select",
"(",
"Column",
"\\",
"RemoteSelect",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"// OPTIONS",
"$",
"options",
"=",
"html",
"(",
"'option'",
",",
"[",
"]",
",",
"'--'",
")",
";",
"$",
"elementValue",
"=",
"$",
"row",
"[",
"$",
"column",
"->",
"getIndex",
"(",
")",
"]",
";",
"foreach",
"(",
"$",
"column",
"->",
"getOptions",
"(",
")",
"as",
"$",
"value",
"=>",
"$",
"key",
")",
"{",
"$",
"attr",
"=",
"[",
"'value'",
"=>",
"$",
"value",
"]",
";",
"if",
"(",
"$",
"value",
"==",
"$",
"elementValue",
")",
"{",
"$",
"attr",
"[",
"'selected'",
"]",
"=",
"'selected'",
";",
"}",
"$",
"options",
".=",
"html",
"(",
"'option'",
",",
"$",
"attr",
",",
"$",
"key",
")",
";",
"}",
"$",
"html",
"=",
"html",
"(",
"'select'",
",",
"[",
"'class'",
"=>",
"'ff-remote-select'",
",",
"'data-id'",
"=>",
"$",
"row",
"[",
"$",
"column",
"->",
"getTable",
"(",
")",
"->",
"getIdField",
"(",
")",
"]",
",",
"'data-column'",
"=>",
"$",
"column",
"->",
"getName",
"(",
")",
"]",
",",
"$",
"options",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Render remote Select
@param \FrenchFrogs\Table\Column\RemoteSelect $column
@param array $row
@return string
|
[
"Render",
"remote",
"Select"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L362-L382
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.link
|
public function link(Column\Link $column, array $row)
{
if ($column->isRemote()) {
$column->addAttribute('data-target', '#' . $column->getRemoteId())
->addAttribute('data-toggle', 'modal');
} elseif($column->isCallback()) {
$column->addClass('callback-remote');
}
$html = html('a', ['href' => $column->getBindedLink($row)], $column->getValue($row));
return $this->post($html, $column, $row);
}
|
php
|
public function link(Column\Link $column, array $row)
{
if ($column->isRemote()) {
$column->addAttribute('data-target', '#' . $column->getRemoteId())
->addAttribute('data-toggle', 'modal');
} elseif($column->isCallback()) {
$column->addClass('callback-remote');
}
$html = html('a', ['href' => $column->getBindedLink($row)], $column->getValue($row));
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"link",
"(",
"Column",
"\\",
"Link",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"column",
"->",
"isRemote",
"(",
")",
")",
"{",
"$",
"column",
"->",
"addAttribute",
"(",
"'data-target'",
",",
"'#'",
".",
"$",
"column",
"->",
"getRemoteId",
"(",
")",
")",
"->",
"addAttribute",
"(",
"'data-toggle'",
",",
"'modal'",
")",
";",
"}",
"elseif",
"(",
"$",
"column",
"->",
"isCallback",
"(",
")",
")",
"{",
"$",
"column",
"->",
"addClass",
"(",
"'callback-remote'",
")",
";",
"}",
"$",
"html",
"=",
"html",
"(",
"'a'",
",",
"[",
"'href'",
"=>",
"$",
"column",
"->",
"getBindedLink",
"(",
"$",
"row",
")",
"]",
",",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Render link column
@param \FrenchFrogs\Table\Column\Link $column
@param array $row
@return string
|
[
"Render",
"link",
"column"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L392-L404
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.media
|
public function media(Column\Media $column, array $row)
{
$media = $column->getBindedLink($row);
$extension = pathinfo($media, PATHINFO_EXTENSION);
if (empty($extension)) {
return '';
}
if (($pos = strpos($extension, '?')) !== false) {
$extension = substr($extension, 0, $pos);
}
// Fancybox compatible Image
if (in_array($extension, ['jpg', 'png', 'jpeg', 'gif'])) {
$html = html('img', ['style' => 'object-fit: cover;', 'width' => $column->getMediaWidth(), 'height' => $column->getMediaHeight(), 'src' => $media]);
return html('a', ['href' => $media, 'class' => 'fancybox'], $html);
}elseif(in_array($extension, ['mp4'])) {
$source = html('source', ['src' => $media, 'type' => 'video/' . $extension]);
return html('video', ['style' => sprintf('width:%spx;height:%spx', $column->getMediaWidth(), $column->getMediaHeight()), 'controls' => 'controls'], $source);
} else {
dd($extension);
throw new \Exception('Extension pas trouvé : ' . $media);
}
$html = html('a', ['href' => $column->getBindedLink($row)], $column->getBindedLabel($row));
return $this->post($html, $column, $row);
}
|
php
|
public function media(Column\Media $column, array $row)
{
$media = $column->getBindedLink($row);
$extension = pathinfo($media, PATHINFO_EXTENSION);
if (empty($extension)) {
return '';
}
if (($pos = strpos($extension, '?')) !== false) {
$extension = substr($extension, 0, $pos);
}
// Fancybox compatible Image
if (in_array($extension, ['jpg', 'png', 'jpeg', 'gif'])) {
$html = html('img', ['style' => 'object-fit: cover;', 'width' => $column->getMediaWidth(), 'height' => $column->getMediaHeight(), 'src' => $media]);
return html('a', ['href' => $media, 'class' => 'fancybox'], $html);
}elseif(in_array($extension, ['mp4'])) {
$source = html('source', ['src' => $media, 'type' => 'video/' . $extension]);
return html('video', ['style' => sprintf('width:%spx;height:%spx', $column->getMediaWidth(), $column->getMediaHeight()), 'controls' => 'controls'], $source);
} else {
dd($extension);
throw new \Exception('Extension pas trouvé : ' . $media);
}
$html = html('a', ['href' => $column->getBindedLink($row)], $column->getBindedLabel($row));
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"media",
"(",
"Column",
"\\",
"Media",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"media",
"=",
"$",
"column",
"->",
"getBindedLink",
"(",
"$",
"row",
")",
";",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"media",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"extension",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"extension",
",",
"'?'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"extension",
"=",
"substr",
"(",
"$",
"extension",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"// Fancybox compatible Image",
"if",
"(",
"in_array",
"(",
"$",
"extension",
",",
"[",
"'jpg'",
",",
"'png'",
",",
"'jpeg'",
",",
"'gif'",
"]",
")",
")",
"{",
"$",
"html",
"=",
"html",
"(",
"'img'",
",",
"[",
"'style'",
"=>",
"'object-fit: cover;'",
",",
"'width'",
"=>",
"$",
"column",
"->",
"getMediaWidth",
"(",
")",
",",
"'height'",
"=>",
"$",
"column",
"->",
"getMediaHeight",
"(",
")",
",",
"'src'",
"=>",
"$",
"media",
"]",
")",
";",
"return",
"html",
"(",
"'a'",
",",
"[",
"'href'",
"=>",
"$",
"media",
",",
"'class'",
"=>",
"'fancybox'",
"]",
",",
"$",
"html",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"extension",
",",
"[",
"'mp4'",
"]",
")",
")",
"{",
"$",
"source",
"=",
"html",
"(",
"'source'",
",",
"[",
"'src'",
"=>",
"$",
"media",
",",
"'type'",
"=>",
"'video/'",
".",
"$",
"extension",
"]",
")",
";",
"return",
"html",
"(",
"'video'",
",",
"[",
"'style'",
"=>",
"sprintf",
"(",
"'width:%spx;height:%spx'",
",",
"$",
"column",
"->",
"getMediaWidth",
"(",
")",
",",
"$",
"column",
"->",
"getMediaHeight",
"(",
")",
")",
",",
"'controls'",
"=>",
"'controls'",
"]",
",",
"$",
"source",
")",
";",
"}",
"else",
"{",
"dd",
"(",
"$",
"extension",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"'Extension pas trouvé : ' ",
" ",
"m",
"edia)",
";",
"",
"}",
"$",
"html",
"=",
"html",
"(",
"'a'",
",",
"[",
"'href'",
"=>",
"$",
"column",
"->",
"getBindedLink",
"(",
"$",
"row",
")",
"]",
",",
"$",
"column",
"->",
"getBindedLabel",
"(",
"$",
"row",
")",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Render a media content
@param \FrenchFrogs\Table\Column\Link $column
@param array $row
@return string
|
[
"Render",
"a",
"media",
"content"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L413-L442
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.button
|
public function button(Column\Button $column, array $row)
{
if ($column->hasOption()) {
$column->addClass(constant( Style::class . '::' . $column->getOption()));
}
if ($column->hasSize()) {
$column->addClass(constant( Style::class . '::' . $column->getSize()));
}
$column->addClass(Style::BUTTON_CLASS);
$column->addAttribute('href',$column->getBindedLink($row));
$label = '';
if ($column->hasIcon()) {
$label .= html('i', ['class' => $column->getIcon()]);
$label .= PHP_EOL;
}
$name = $column->getBindedLabel($row);
if ($column->isIconOnly()) {
$column->addClass('ff-tooltip-left');
} else {
$label .= $name;
}
if ($column->isRemote()) {
$column->addAttribute('data-target', '#' . $column->getRemoteId())
->addClass('modal-remote');
} elseif($column->isCallback()) {
$column->addClass('callback-remote');
}
$column->addAttribute('title', $name);
$html = html('a', $column->getAttributes(), $label );
$column->clearClasses()->center();
return $html;
}
|
php
|
public function button(Column\Button $column, array $row)
{
if ($column->hasOption()) {
$column->addClass(constant( Style::class . '::' . $column->getOption()));
}
if ($column->hasSize()) {
$column->addClass(constant( Style::class . '::' . $column->getSize()));
}
$column->addClass(Style::BUTTON_CLASS);
$column->addAttribute('href',$column->getBindedLink($row));
$label = '';
if ($column->hasIcon()) {
$label .= html('i', ['class' => $column->getIcon()]);
$label .= PHP_EOL;
}
$name = $column->getBindedLabel($row);
if ($column->isIconOnly()) {
$column->addClass('ff-tooltip-left');
} else {
$label .= $name;
}
if ($column->isRemote()) {
$column->addAttribute('data-target', '#' . $column->getRemoteId())
->addClass('modal-remote');
} elseif($column->isCallback()) {
$column->addClass('callback-remote');
}
$column->addAttribute('title', $name);
$html = html('a', $column->getAttributes(), $label );
$column->clearClasses()->center();
return $html;
}
|
[
"public",
"function",
"button",
"(",
"Column",
"\\",
"Button",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"column",
"->",
"hasOption",
"(",
")",
")",
"{",
"$",
"column",
"->",
"addClass",
"(",
"constant",
"(",
"Style",
"::",
"class",
".",
"'::'",
".",
"$",
"column",
"->",
"getOption",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"column",
"->",
"hasSize",
"(",
")",
")",
"{",
"$",
"column",
"->",
"addClass",
"(",
"constant",
"(",
"Style",
"::",
"class",
".",
"'::'",
".",
"$",
"column",
"->",
"getSize",
"(",
")",
")",
")",
";",
"}",
"$",
"column",
"->",
"addClass",
"(",
"Style",
"::",
"BUTTON_CLASS",
")",
";",
"$",
"column",
"->",
"addAttribute",
"(",
"'href'",
",",
"$",
"column",
"->",
"getBindedLink",
"(",
"$",
"row",
")",
")",
";",
"$",
"label",
"=",
"''",
";",
"if",
"(",
"$",
"column",
"->",
"hasIcon",
"(",
")",
")",
"{",
"$",
"label",
".=",
"html",
"(",
"'i'",
",",
"[",
"'class'",
"=>",
"$",
"column",
"->",
"getIcon",
"(",
")",
"]",
")",
";",
"$",
"label",
".=",
"PHP_EOL",
";",
"}",
"$",
"name",
"=",
"$",
"column",
"->",
"getBindedLabel",
"(",
"$",
"row",
")",
";",
"if",
"(",
"$",
"column",
"->",
"isIconOnly",
"(",
")",
")",
"{",
"$",
"column",
"->",
"addClass",
"(",
"'ff-tooltip-left'",
")",
";",
"}",
"else",
"{",
"$",
"label",
".=",
"$",
"name",
";",
"}",
"if",
"(",
"$",
"column",
"->",
"isRemote",
"(",
")",
")",
"{",
"$",
"column",
"->",
"addAttribute",
"(",
"'data-target'",
",",
"'#'",
".",
"$",
"column",
"->",
"getRemoteId",
"(",
")",
")",
"->",
"addClass",
"(",
"'modal-remote'",
")",
";",
"}",
"elseif",
"(",
"$",
"column",
"->",
"isCallback",
"(",
")",
")",
"{",
"$",
"column",
"->",
"addClass",
"(",
"'callback-remote'",
")",
";",
"}",
"$",
"column",
"->",
"addAttribute",
"(",
"'title'",
",",
"$",
"name",
")",
";",
"$",
"html",
"=",
"html",
"(",
"'a'",
",",
"$",
"column",
"->",
"getAttributes",
"(",
")",
",",
"$",
"label",
")",
";",
"$",
"column",
"->",
"clearClasses",
"(",
")",
"->",
"center",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Render a button
@param \FrenchFrogs\Table\Column\Button $column
@param array $row
@return mixed
|
[
"Render",
"a",
"button"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L452-L493
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.code
|
public function code(Column\Code $column, array $row)
{
$html = html('code', [],$column->getValue($row));
return $this->post($html, $column, $row);
}
|
php
|
public function code(Column\Code $column, array $row)
{
$html = html('code', [],$column->getValue($row));
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"code",
"(",
"Column",
"\\",
"Code",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"html",
"=",
"html",
"(",
"'code'",
",",
"[",
"]",
",",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Rendor a code element
@param \FrenchFrogs\Table\Column\Code $column
@param array $row
@return string
|
[
"Rendor",
"a",
"code",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L503-L507
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.pre
|
public function pre(Column\Pre $column, array $row)
{
$html = html('pre', [],$column->getValue($row));
return $this->post($html, $column, $row);
}
|
php
|
public function pre(Column\Pre $column, array $row)
{
$html = html('pre', [],$column->getValue($row));
return $this->post($html, $column, $row);
}
|
[
"public",
"function",
"pre",
"(",
"Column",
"\\",
"Pre",
"$",
"column",
",",
"array",
"$",
"row",
")",
"{",
"$",
"html",
"=",
"html",
"(",
"'pre'",
",",
"[",
"]",
",",
"$",
"column",
"->",
"getValue",
"(",
"$",
"row",
")",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"$",
"html",
",",
"$",
"column",
",",
"$",
"row",
")",
";",
"}"
] |
Render a pre element
@param \FrenchFrogs\Table\Column\Code $column
@param array $row
@return string
|
[
"Render",
"a",
"pre",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L516-L520
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.datatable
|
public function datatable(Table\Table $table)
{
$options = [];
// Is remote loading
if ($table->isRemote()) {
$table->addClass('datatable-remote');
$table->save();
$options += [
'ajax' => ['url' => route('datatable', ['token' => $table->getToken()])],
'processing' => true,
'serverSide' => true,
'pageLength' => $table->getItemsPerPage(),
'deferLoading' => $table->getItemsTotal()
];
}
//param par default
$options += ['searching' => true];
//Param dom datatable
$dom = '';
//header dom
$dom .= '<"dataTables_wrapper no-footer"<"row"<"col-md-6 col-sm-12"lB>';
// is a search is set
if ($table->hasSearch()) {
$dom .= '<"col-md-6 col-sm-12"f>';
}
$dom .= '>';
//dom table
$dom .= '<"table-scrollable"t>';
//footer dom
if ($table->hasFooter()) {
$dom .= '<"row"<"col-md-5 col-sm-12"i><"col-md-7 col-sm-12"p>>';
}
//Set dom
$options += ['dom' => $dom];
// columns mamangement
$columns = [];
$order = [];
$index = 0;
$search = '';
foreach($table->getColumns() as $c) {
$data = [];
/**@var Column\Column $c */
$class = $c->getClasses();
if (!empty($class)) {
$data['className'] = trim($class);
}
// width
if ($c->hasWidth()) {
$data['width'] = $c->getWidth();
}
// other column attribute
$data['orderable'] = $c->hasOrder();
$data['searchable'] = $c->hasStrainer();
$data['name'] = $c->getName();
if ($data['searchable'] && !is_null($value = $c->getStrainer()->getValue())) {
$value = is_bool($value) ? intval($value) : $value;
$search[] = $value;
} else {
$search[] = null;
}
// set order for main table
if ($c->hasOrderDirection()) {
$order[] = [$index, $c->getOrderDirection()];
}
// set columns to null if column parameters is empty
$columns[] = empty($data) ? null : $data;
$index++;
}
if (!empty($columns)) {
$options += ['columns' => $columns];
}
// buttons
if ($table->hasDatatableButtons())
{
$options += ['buttons' => $table->getDatatableButtons()];
}
// main order foir the table
$options['order'] = $order;
js('onload', '#' . $table->getAttribute('id'), 'dtt', $options);
// init search configuration - seartchcols doesn't work
foreach($search as $i => $s) {
if (is_null($s)) {continue;}
js('onload', '#' . $table->getAttribute('id'), 'DataTable().columns('.$i.').search', $s);
}
return '';
}
|
php
|
public function datatable(Table\Table $table)
{
$options = [];
// Is remote loading
if ($table->isRemote()) {
$table->addClass('datatable-remote');
$table->save();
$options += [
'ajax' => ['url' => route('datatable', ['token' => $table->getToken()])],
'processing' => true,
'serverSide' => true,
'pageLength' => $table->getItemsPerPage(),
'deferLoading' => $table->getItemsTotal()
];
}
//param par default
$options += ['searching' => true];
//Param dom datatable
$dom = '';
//header dom
$dom .= '<"dataTables_wrapper no-footer"<"row"<"col-md-6 col-sm-12"lB>';
// is a search is set
if ($table->hasSearch()) {
$dom .= '<"col-md-6 col-sm-12"f>';
}
$dom .= '>';
//dom table
$dom .= '<"table-scrollable"t>';
//footer dom
if ($table->hasFooter()) {
$dom .= '<"row"<"col-md-5 col-sm-12"i><"col-md-7 col-sm-12"p>>';
}
//Set dom
$options += ['dom' => $dom];
// columns mamangement
$columns = [];
$order = [];
$index = 0;
$search = '';
foreach($table->getColumns() as $c) {
$data = [];
/**@var Column\Column $c */
$class = $c->getClasses();
if (!empty($class)) {
$data['className'] = trim($class);
}
// width
if ($c->hasWidth()) {
$data['width'] = $c->getWidth();
}
// other column attribute
$data['orderable'] = $c->hasOrder();
$data['searchable'] = $c->hasStrainer();
$data['name'] = $c->getName();
if ($data['searchable'] && !is_null($value = $c->getStrainer()->getValue())) {
$value = is_bool($value) ? intval($value) : $value;
$search[] = $value;
} else {
$search[] = null;
}
// set order for main table
if ($c->hasOrderDirection()) {
$order[] = [$index, $c->getOrderDirection()];
}
// set columns to null if column parameters is empty
$columns[] = empty($data) ? null : $data;
$index++;
}
if (!empty($columns)) {
$options += ['columns' => $columns];
}
// buttons
if ($table->hasDatatableButtons())
{
$options += ['buttons' => $table->getDatatableButtons()];
}
// main order foir the table
$options['order'] = $order;
js('onload', '#' . $table->getAttribute('id'), 'dtt', $options);
// init search configuration - seartchcols doesn't work
foreach($search as $i => $s) {
if (is_null($s)) {continue;}
js('onload', '#' . $table->getAttribute('id'), 'DataTable().columns('.$i.').search', $s);
}
return '';
}
|
[
"public",
"function",
"datatable",
"(",
"Table",
"\\",
"Table",
"$",
"table",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"// Is remote loading",
"if",
"(",
"$",
"table",
"->",
"isRemote",
"(",
")",
")",
"{",
"$",
"table",
"->",
"addClass",
"(",
"'datatable-remote'",
")",
";",
"$",
"table",
"->",
"save",
"(",
")",
";",
"$",
"options",
"+=",
"[",
"'ajax'",
"=>",
"[",
"'url'",
"=>",
"route",
"(",
"'datatable'",
",",
"[",
"'token'",
"=>",
"$",
"table",
"->",
"getToken",
"(",
")",
"]",
")",
"]",
",",
"'processing'",
"=>",
"true",
",",
"'serverSide'",
"=>",
"true",
",",
"'pageLength'",
"=>",
"$",
"table",
"->",
"getItemsPerPage",
"(",
")",
",",
"'deferLoading'",
"=>",
"$",
"table",
"->",
"getItemsTotal",
"(",
")",
"]",
";",
"}",
"//param par default",
"$",
"options",
"+=",
"[",
"'searching'",
"=>",
"true",
"]",
";",
"//Param dom datatable",
"$",
"dom",
"=",
"''",
";",
"//header dom",
"$",
"dom",
".=",
"'<\"dataTables_wrapper no-footer\"<\"row\"<\"col-md-6 col-sm-12\"lB>'",
";",
"// is a search is set",
"if",
"(",
"$",
"table",
"->",
"hasSearch",
"(",
")",
")",
"{",
"$",
"dom",
".=",
"'<\"col-md-6 col-sm-12\"f>'",
";",
"}",
"$",
"dom",
".=",
"'>'",
";",
"//dom table",
"$",
"dom",
".=",
"'<\"table-scrollable\"t>'",
";",
"//footer dom",
"if",
"(",
"$",
"table",
"->",
"hasFooter",
"(",
")",
")",
"{",
"$",
"dom",
".=",
"'<\"row\"<\"col-md-5 col-sm-12\"i><\"col-md-7 col-sm-12\"p>>'",
";",
"}",
"//Set dom",
"$",
"options",
"+=",
"[",
"'dom'",
"=>",
"$",
"dom",
"]",
";",
"// columns mamangement",
"$",
"columns",
"=",
"[",
"]",
";",
"$",
"order",
"=",
"[",
"]",
";",
"$",
"index",
"=",
"0",
";",
"$",
"search",
"=",
"''",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"c",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"/**@var Column\\Column $c */",
"$",
"class",
"=",
"$",
"c",
"->",
"getClasses",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
")",
")",
"{",
"$",
"data",
"[",
"'className'",
"]",
"=",
"trim",
"(",
"$",
"class",
")",
";",
"}",
"// width",
"if",
"(",
"$",
"c",
"->",
"hasWidth",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'width'",
"]",
"=",
"$",
"c",
"->",
"getWidth",
"(",
")",
";",
"}",
"// other column attribute",
"$",
"data",
"[",
"'orderable'",
"]",
"=",
"$",
"c",
"->",
"hasOrder",
"(",
")",
";",
"$",
"data",
"[",
"'searchable'",
"]",
"=",
"$",
"c",
"->",
"hasStrainer",
"(",
")",
";",
"$",
"data",
"[",
"'name'",
"]",
"=",
"$",
"c",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'searchable'",
"]",
"&&",
"!",
"is_null",
"(",
"$",
"value",
"=",
"$",
"c",
"->",
"getStrainer",
"(",
")",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"$",
"value",
"=",
"is_bool",
"(",
"$",
"value",
")",
"?",
"intval",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"$",
"search",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"search",
"[",
"]",
"=",
"null",
";",
"}",
"// set order for main table",
"if",
"(",
"$",
"c",
"->",
"hasOrderDirection",
"(",
")",
")",
"{",
"$",
"order",
"[",
"]",
"=",
"[",
"$",
"index",
",",
"$",
"c",
"->",
"getOrderDirection",
"(",
")",
"]",
";",
"}",
"// set columns to null if column parameters is empty",
"$",
"columns",
"[",
"]",
"=",
"empty",
"(",
"$",
"data",
")",
"?",
"null",
":",
"$",
"data",
";",
"$",
"index",
"++",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"options",
"+=",
"[",
"'columns'",
"=>",
"$",
"columns",
"]",
";",
"}",
"// buttons",
"if",
"(",
"$",
"table",
"->",
"hasDatatableButtons",
"(",
")",
")",
"{",
"$",
"options",
"+=",
"[",
"'buttons'",
"=>",
"$",
"table",
"->",
"getDatatableButtons",
"(",
")",
"]",
";",
"}",
"// main order foir the table",
"$",
"options",
"[",
"'order'",
"]",
"=",
"$",
"order",
";",
"js",
"(",
"'onload'",
",",
"'#'",
".",
"$",
"table",
"->",
"getAttribute",
"(",
"'id'",
")",
",",
"'dtt'",
",",
"$",
"options",
")",
";",
"// init search configuration - seartchcols doesn't work",
"foreach",
"(",
"$",
"search",
"as",
"$",
"i",
"=>",
"$",
"s",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"s",
")",
")",
"{",
"continue",
";",
"}",
"js",
"(",
"'onload'",
",",
"'#'",
".",
"$",
"table",
"->",
"getAttribute",
"(",
"'id'",
")",
",",
"'DataTable().columns('",
".",
"$",
"i",
".",
"').search'",
",",
"$",
"s",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Render datatable js
@param \FrenchFrogs\Table\Table\Table $table
@return string
|
[
"Render",
"datatable",
"js"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L530-L639
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.strainerSelect
|
public function strainerSelect(Column\Strainer\Select $strainer)
{
$element = $strainer->getElement();
$element->addStyle('width', '100%');
$element->addClass(Style::FORM_ELEMENT_CONTROL);
$options = '';
if ($element->hasPlaceholder()){
$options .= html('option', ['value' => null], $element->getPlaceholder());
}
foreach($element->getOptions() as $value => $label){
$attr = ['value' => $value];
if ($element->hasValue() && in_array($value, $element->getValue())){
$attr['selected'] = 'selected';
}
$options .= html('option', $attr, $label);
}
return html('select', $element->getAttributes(), $options);
}
|
php
|
public function strainerSelect(Column\Strainer\Select $strainer)
{
$element = $strainer->getElement();
$element->addStyle('width', '100%');
$element->addClass(Style::FORM_ELEMENT_CONTROL);
$options = '';
if ($element->hasPlaceholder()){
$options .= html('option', ['value' => null], $element->getPlaceholder());
}
foreach($element->getOptions() as $value => $label){
$attr = ['value' => $value];
if ($element->hasValue() && in_array($value, $element->getValue())){
$attr['selected'] = 'selected';
}
$options .= html('option', $attr, $label);
}
return html('select', $element->getAttributes(), $options);
}
|
[
"public",
"function",
"strainerSelect",
"(",
"Column",
"\\",
"Strainer",
"\\",
"Select",
"$",
"strainer",
")",
"{",
"$",
"element",
"=",
"$",
"strainer",
"->",
"getElement",
"(",
")",
";",
"$",
"element",
"->",
"addStyle",
"(",
"'width'",
",",
"'100%'",
")",
";",
"$",
"element",
"->",
"addClass",
"(",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
")",
";",
"$",
"options",
"=",
"''",
";",
"if",
"(",
"$",
"element",
"->",
"hasPlaceholder",
"(",
")",
")",
"{",
"$",
"options",
".=",
"html",
"(",
"'option'",
",",
"[",
"'value'",
"=>",
"null",
"]",
",",
"$",
"element",
"->",
"getPlaceholder",
"(",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"element",
"->",
"getOptions",
"(",
")",
"as",
"$",
"value",
"=>",
"$",
"label",
")",
"{",
"$",
"attr",
"=",
"[",
"'value'",
"=>",
"$",
"value",
"]",
";",
"if",
"(",
"$",
"element",
"->",
"hasValue",
"(",
")",
"&&",
"in_array",
"(",
"$",
"value",
",",
"$",
"element",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"$",
"attr",
"[",
"'selected'",
"]",
"=",
"'selected'",
";",
"}",
"$",
"options",
".=",
"html",
"(",
"'option'",
",",
"$",
"attr",
",",
"$",
"label",
")",
";",
"}",
"return",
"html",
"(",
"'select'",
",",
"$",
"element",
"->",
"getAttributes",
"(",
")",
",",
"$",
"options",
")",
";",
"}"
] |
Render strainer for a select element
@param \FrenchFrogs\Table\Column\Strainer\Select $strainer
@return string
|
[
"Render",
"strainer",
"for",
"a",
"select",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L647-L668
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.strainerText
|
public function strainerText(Column\Strainer\Text $strainer)
{
$element = $strainer->getElement();
$element->addStyle('width', '100%');
$element->addClass('text-center');
$element->addClass(Style::FORM_ELEMENT_CONTROL);
return html('input', $element->getAttributes());
}
|
php
|
public function strainerText(Column\Strainer\Text $strainer)
{
$element = $strainer->getElement();
$element->addStyle('width', '100%');
$element->addClass('text-center');
$element->addClass(Style::FORM_ELEMENT_CONTROL);
return html('input', $element->getAttributes());
}
|
[
"public",
"function",
"strainerText",
"(",
"Column",
"\\",
"Strainer",
"\\",
"Text",
"$",
"strainer",
")",
"{",
"$",
"element",
"=",
"$",
"strainer",
"->",
"getElement",
"(",
")",
";",
"$",
"element",
"->",
"addStyle",
"(",
"'width'",
",",
"'100%'",
")",
";",
"$",
"element",
"->",
"addClass",
"(",
"'text-center'",
")",
";",
"$",
"element",
"->",
"addClass",
"(",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
")",
";",
"return",
"html",
"(",
"'input'",
",",
"$",
"element",
"->",
"getAttributes",
"(",
")",
")",
";",
"}"
] |
Render a striner for a text element
@param Column\Strainer\Text $strainer
@return string
|
[
"Render",
"a",
"striner",
"for",
"a",
"text",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L677-L685
|
FrenchFrogs/framework
|
src/Table/Renderer/Bootstrap.php
|
Bootstrap.strainerDateRange
|
public function strainerDateRange(Column\Strainer\DateRange $strainer)
{
$element = $strainer->getElement();
$html = html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getFrom()]);
$html .= '<span class="input-group-addon">-</span>';
$html .= html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getTo()]);
return html('div', [
'name' => $element->getName(),
'class' => 'input-group date-picker daterange input-daterange text-center',
'data-date-format' => configurator()->get('form.element.date.formatjs')
], $html);
}
|
php
|
public function strainerDateRange(Column\Strainer\DateRange $strainer)
{
$element = $strainer->getElement();
$html = html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getFrom()]);
$html .= '<span class="input-group-addon">-</span>';
$html .= html('input', ['type' => 'text', 'class' => Style::FORM_ELEMENT_CONTROL, 'name' => $element->getTo()]);
return html('div', [
'name' => $element->getName(),
'class' => 'input-group date-picker daterange input-daterange text-center',
'data-date-format' => configurator()->get('form.element.date.formatjs')
], $html);
}
|
[
"public",
"function",
"strainerDateRange",
"(",
"Column",
"\\",
"Strainer",
"\\",
"DateRange",
"$",
"strainer",
")",
"{",
"$",
"element",
"=",
"$",
"strainer",
"->",
"getElement",
"(",
")",
";",
"$",
"html",
"=",
"html",
"(",
"'input'",
",",
"[",
"'type'",
"=>",
"'text'",
",",
"'class'",
"=>",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
",",
"'name'",
"=>",
"$",
"element",
"->",
"getFrom",
"(",
")",
"]",
")",
";",
"$",
"html",
".=",
"'<span class=\"input-group-addon\">-</span>'",
";",
"$",
"html",
".=",
"html",
"(",
"'input'",
",",
"[",
"'type'",
"=>",
"'text'",
",",
"'class'",
"=>",
"Style",
"::",
"FORM_ELEMENT_CONTROL",
",",
"'name'",
"=>",
"$",
"element",
"->",
"getTo",
"(",
")",
"]",
")",
";",
"return",
"html",
"(",
"'div'",
",",
"[",
"'name'",
"=>",
"$",
"element",
"->",
"getName",
"(",
")",
",",
"'class'",
"=>",
"'input-group date-picker daterange input-daterange text-center'",
",",
"'data-date-format'",
"=>",
"configurator",
"(",
")",
"->",
"get",
"(",
"'form.element.date.formatjs'",
")",
"]",
",",
"$",
"html",
")",
";",
"}"
] |
Render a striner for a text element
@param Column\Strainer\Text $strainer
@return string
|
[
"Render",
"a",
"striner",
"for",
"a",
"text",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Bootstrap.php#L723-L735
|
bestit/commercetools-order-export-bundle
|
src/OrderNameGenerator.php
|
OrderNameGenerator.getOrderName
|
public function getOrderName(Order $order): string
{
if (preg_match_all('/{{(.*)}}/U', $scheme = $this->getNameScheme(), $matches)) {
foreach ($matches[1] as $index => $foundSnippet) {
$foundSnippetName = trim($foundSnippet);
$usedSnippet = $order->hasField($foundSnippetName)
? $order->get($foundSnippetName)
: date($foundSnippetName);
$scheme = str_replace($matches[0][$index], $usedSnippet, $scheme);
}
}
return $scheme;
}
|
php
|
public function getOrderName(Order $order): string
{
if (preg_match_all('/{{(.*)}}/U', $scheme = $this->getNameScheme(), $matches)) {
foreach ($matches[1] as $index => $foundSnippet) {
$foundSnippetName = trim($foundSnippet);
$usedSnippet = $order->hasField($foundSnippetName)
? $order->get($foundSnippetName)
: date($foundSnippetName);
$scheme = str_replace($matches[0][$index], $usedSnippet, $scheme);
}
}
return $scheme;
}
|
[
"public",
"function",
"getOrderName",
"(",
"Order",
"$",
"order",
")",
":",
"string",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/{{(.*)}}/U'",
",",
"$",
"scheme",
"=",
"$",
"this",
"->",
"getNameScheme",
"(",
")",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"1",
"]",
"as",
"$",
"index",
"=>",
"$",
"foundSnippet",
")",
"{",
"$",
"foundSnippetName",
"=",
"trim",
"(",
"$",
"foundSnippet",
")",
";",
"$",
"usedSnippet",
"=",
"$",
"order",
"->",
"hasField",
"(",
"$",
"foundSnippetName",
")",
"?",
"$",
"order",
"->",
"get",
"(",
"$",
"foundSnippetName",
")",
":",
"date",
"(",
"$",
"foundSnippetName",
")",
";",
"$",
"scheme",
"=",
"str_replace",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"$",
"index",
"]",
",",
"$",
"usedSnippet",
",",
"$",
"scheme",
")",
";",
"}",
"}",
"return",
"$",
"scheme",
";",
"}"
] |
Returns the name for the order.
@param Order $order
@return string
|
[
"Returns",
"the",
"name",
"for",
"the",
"order",
"."
] |
train
|
https://github.com/bestit/commercetools-order-export-bundle/blob/44bd0dedff6edab5ecf5803dcf6d24ffe0dbf845/src/OrderNameGenerator.php#L44-L58
|
nicoSWD/put.io-api-v2
|
src/PutIO/Helpers/HTTP/HTTPHelper.php
|
HTTPHelper.getMIMEType
|
protected function getMIMEType($file)
{
$mime = 'application/octet-stream';
if (function_exists('finfo_open') && $info = @finfo_open(FILEINFO_MIME)) {
if (($mime = @finfo_file($info, $file)) !== \false) {
$mime = explode(';', $mime);
$mime = trim($mime[0]);
}
}
return $mime;
}
|
php
|
protected function getMIMEType($file)
{
$mime = 'application/octet-stream';
if (function_exists('finfo_open') && $info = @finfo_open(FILEINFO_MIME)) {
if (($mime = @finfo_file($info, $file)) !== \false) {
$mime = explode(';', $mime);
$mime = trim($mime[0]);
}
}
return $mime;
}
|
[
"protected",
"function",
"getMIMEType",
"(",
"$",
"file",
")",
"{",
"$",
"mime",
"=",
"'application/octet-stream'",
";",
"if",
"(",
"function_exists",
"(",
"'finfo_open'",
")",
"&&",
"$",
"info",
"=",
"@",
"finfo_open",
"(",
"FILEINFO_MIME",
")",
")",
"{",
"if",
"(",
"(",
"$",
"mime",
"=",
"@",
"finfo_file",
"(",
"$",
"info",
",",
"$",
"file",
")",
")",
"!==",
"\\",
"false",
")",
"{",
"$",
"mime",
"=",
"explode",
"(",
"';'",
",",
"$",
"mime",
")",
";",
"$",
"mime",
"=",
"trim",
"(",
"$",
"mime",
"[",
"0",
"]",
")",
";",
"}",
"}",
"return",
"$",
"mime",
";",
"}"
] |
Attempts to get the MIME type of a given file. Required for native file
uploads.
Relies on the file info extension, which is shipped with PHP 5.3
and enabled by default. So,... nothing should go wrong, RIGHT?
@param string $file Path of the file you want to get the MIME type of.
@return string
|
[
"Attempts",
"to",
"get",
"the",
"MIME",
"type",
"of",
"a",
"given",
"file",
".",
"Required",
"for",
"native",
"file",
"uploads",
"."
] |
train
|
https://github.com/nicoSWD/put.io-api-v2/blob/d91bedd91ea75793512a921bfd9aa83e86a6f0a7/src/PutIO/Helpers/HTTP/HTTPHelper.php#L85-L97
|
nicoSWD/put.io-api-v2
|
src/PutIO/Helpers/HTTP/HTTPHelper.php
|
HTTPHelper.getResponse
|
protected function getResponse($response, $returnBool, $arrayKey = '')
{
$response = $this->jsonDecode($response);
if ($response === \null) {
return \false;
}
if ($returnBool) {
return $this->getStatus($response);
}
if ($arrayKey) {
if (isset($response[$arrayKey])) {
return $response[$arrayKey];
}
return \false;
}
return $response;
}
|
php
|
protected function getResponse($response, $returnBool, $arrayKey = '')
{
$response = $this->jsonDecode($response);
if ($response === \null) {
return \false;
}
if ($returnBool) {
return $this->getStatus($response);
}
if ($arrayKey) {
if (isset($response[$arrayKey])) {
return $response[$arrayKey];
}
return \false;
}
return $response;
}
|
[
"protected",
"function",
"getResponse",
"(",
"$",
"response",
",",
"$",
"returnBool",
",",
"$",
"arrayKey",
"=",
"''",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"jsonDecode",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"response",
"===",
"\\",
"null",
")",
"{",
"return",
"\\",
"false",
";",
"}",
"if",
"(",
"$",
"returnBool",
")",
"{",
"return",
"$",
"this",
"->",
"getStatus",
"(",
"$",
"response",
")",
";",
"}",
"if",
"(",
"$",
"arrayKey",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"response",
"[",
"$",
"arrayKey",
"]",
")",
")",
"{",
"return",
"$",
"response",
"[",
"$",
"arrayKey",
"]",
";",
"}",
"return",
"\\",
"false",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Decodes the response and returns the appropriate value
@param string $response Response data from server.
@param bool $returnBool Whether or not to return boolean
@param string $arrayKey Will return all data on a specific array key
of the response.
@return array|bool
|
[
"Decodes",
"the",
"response",
"and",
"returns",
"the",
"appropriate",
"value"
] |
train
|
https://github.com/nicoSWD/put.io-api-v2/blob/d91bedd91ea75793512a921bfd9aa83e86a6f0a7/src/PutIO/Helpers/HTTP/HTTPHelper.php#L108-L129
|
nicoSWD/put.io-api-v2
|
src/PutIO/Helpers/HTTP/HTTPHelper.php
|
HTTPHelper.nativeJsonDecode
|
protected function nativeJsonDecode($string)
{
$result = @json_decode($string, \true);
if (!$result || JSON_ERROR_NONE !== json_last_error()) {
$result = \null;
}
return $result;
}
|
php
|
protected function nativeJsonDecode($string)
{
$result = @json_decode($string, \true);
if (!$result || JSON_ERROR_NONE !== json_last_error()) {
$result = \null;
}
return $result;
}
|
[
"protected",
"function",
"nativeJsonDecode",
"(",
"$",
"string",
")",
"{",
"$",
"result",
"=",
"@",
"json_decode",
"(",
"$",
"string",
",",
"\\",
"true",
")",
";",
"if",
"(",
"!",
"$",
"result",
"||",
"JSON_ERROR_NONE",
"!==",
"json_last_error",
"(",
")",
")",
"{",
"$",
"result",
"=",
"\\",
"null",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Decodes a JSON encoded string natively.
@param string $string
@return array|null
|
[
"Decodes",
"a",
"JSON",
"encoded",
"string",
"natively",
"."
] |
train
|
https://github.com/nicoSWD/put.io-api-v2/blob/d91bedd91ea75793512a921bfd9aa83e86a6f0a7/src/PutIO/Helpers/HTTP/HTTPHelper.php#L160-L169
|
chippyash/Math-Type-Calculator
|
src/Chippyash/Math/Type/Comparator/Native.php
|
Native.compare
|
public function compare(NI $a, NI $b)
{
switch ($this->arbitrate($a, $b)) {
case 'int':
case 'whole':
case 'natural':
case 'float':
return $this->intFloatCompare($a, $b);
case 'rational':
list($a, $b) = $this->checkRationalTypes($a, $b);
return $this->rationalCompare($a, $b);
case 'complex':
return $this->complexCompare($a, $b);
case 'complex:numeric':
return $this->complexCompare($a, $b->asComplex());
case 'numeric:complex':
return $this->complexCompare($a->asComplex(), $b);
}
}
|
php
|
public function compare(NI $a, NI $b)
{
switch ($this->arbitrate($a, $b)) {
case 'int':
case 'whole':
case 'natural':
case 'float':
return $this->intFloatCompare($a, $b);
case 'rational':
list($a, $b) = $this->checkRationalTypes($a, $b);
return $this->rationalCompare($a, $b);
case 'complex':
return $this->complexCompare($a, $b);
case 'complex:numeric':
return $this->complexCompare($a, $b->asComplex());
case 'numeric:complex':
return $this->complexCompare($a->asComplex(), $b);
}
}
|
[
"public",
"function",
"compare",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"arbitrate",
"(",
"$",
"a",
",",
"$",
"b",
")",
")",
"{",
"case",
"'int'",
":",
"case",
"'whole'",
":",
"case",
"'natural'",
":",
"case",
"'float'",
":",
"return",
"$",
"this",
"->",
"intFloatCompare",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"case",
"'rational'",
":",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkRationalTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"$",
"this",
"->",
"rationalCompare",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"case",
"'complex'",
":",
"return",
"$",
"this",
"->",
"complexCompare",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"case",
"'complex:numeric'",
":",
"return",
"$",
"this",
"->",
"complexCompare",
"(",
"$",
"a",
",",
"$",
"b",
"->",
"asComplex",
"(",
")",
")",
";",
"case",
"'numeric:complex'",
":",
"return",
"$",
"this",
"->",
"complexCompare",
"(",
"$",
"a",
"->",
"asComplex",
"(",
")",
",",
"$",
"b",
")",
";",
"}",
"}"
] |
a == b = 0
a < b = -1
a > b = 1
@param NI $a first term
@param NI $b second term
@return int
@noinspection PhpInconsistentReturnPointsInspection
|
[
"a",
"==",
"b",
"=",
"0",
"a",
"<",
"b",
"=",
"-",
"1",
"a",
">",
"b",
"=",
"1"
] |
train
|
https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Comparator/Native.php#L48-L66
|
chippyash/Math-Type-Calculator
|
src/Chippyash/Math/Type/Comparator/Native.php
|
Native.intFloatCompare
|
protected function intFloatCompare(NI $a, NI $b)
{
return $this->rationalCompare(
RationalTypeFactory::fromFloat($a->asFloatType()),
RationalTypeFactory::fromFloat($b->asFloatType())
);
}
|
php
|
protected function intFloatCompare(NI $a, NI $b)
{
return $this->rationalCompare(
RationalTypeFactory::fromFloat($a->asFloatType()),
RationalTypeFactory::fromFloat($b->asFloatType())
);
}
|
[
"protected",
"function",
"intFloatCompare",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"return",
"$",
"this",
"->",
"rationalCompare",
"(",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"a",
"->",
"asFloatType",
"(",
")",
")",
",",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"b",
"->",
"asFloatType",
"(",
")",
")",
")",
";",
"}"
] |
Compare int and float types
@param NI $a
@param NI $b
@return int
|
[
"Compare",
"int",
"and",
"float",
"types"
] |
train
|
https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Comparator/Native.php#L75-L81
|
chippyash/Math-Type-Calculator
|
src/Chippyash/Math/Type/Comparator/Native.php
|
Native.rationalCompare
|
protected function rationalCompare(RationalType $a, RationalType $b)
{
$res = $this->calculator->rationalSub($a, $b);
if ($res->numerator()->get() == 0) {
return 0;
}
if ($res->numerator()->get() < 0) {
return -1;
}
return 1;
}
|
php
|
protected function rationalCompare(RationalType $a, RationalType $b)
{
$res = $this->calculator->rationalSub($a, $b);
if ($res->numerator()->get() == 0) {
return 0;
}
if ($res->numerator()->get() < 0) {
return -1;
}
return 1;
}
|
[
"protected",
"function",
"rationalCompare",
"(",
"RationalType",
"$",
"a",
",",
"RationalType",
"$",
"b",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"calculator",
"->",
"rationalSub",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"if",
"(",
"$",
"res",
"->",
"numerator",
"(",
")",
"->",
"get",
"(",
")",
"==",
"0",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"res",
"->",
"numerator",
"(",
")",
"->",
"get",
"(",
")",
"<",
"0",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"1",
";",
"}"
] |
Compare two rationals
@param RationalType $a
@param RationalType $b
@return int
|
[
"Compare",
"two",
"rationals"
] |
train
|
https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Comparator/Native.php#L90-L101
|
chippyash/Math-Type-Calculator
|
src/Chippyash/Math/Type/Comparator/Native.php
|
Native.complexCompare
|
protected function complexCompare(ComplexType $a, ComplexType $b)
{
if ($a->isReal() && $b->isReal()) {
return $this->rationalCompare($a->r(), $b->r());
}
//hack to get around native php integer limitations
//what we should be doing here is to return $this->rationalCompare($a->modulus(), $b->modulus())
//but this blows up because of the big rationals it produces
$am = $a->modulus()->asFloatType()->get();
$bm = $b->modulus()->asFloatType()->get();
if ($am == $bm) {
return 0;
}
if ($am < $bm) {
return -1;
}
return 1;
}
|
php
|
protected function complexCompare(ComplexType $a, ComplexType $b)
{
if ($a->isReal() && $b->isReal()) {
return $this->rationalCompare($a->r(), $b->r());
}
//hack to get around native php integer limitations
//what we should be doing here is to return $this->rationalCompare($a->modulus(), $b->modulus())
//but this blows up because of the big rationals it produces
$am = $a->modulus()->asFloatType()->get();
$bm = $b->modulus()->asFloatType()->get();
if ($am == $bm) {
return 0;
}
if ($am < $bm) {
return -1;
}
return 1;
}
|
[
"protected",
"function",
"complexCompare",
"(",
"ComplexType",
"$",
"a",
",",
"ComplexType",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"isReal",
"(",
")",
"&&",
"$",
"b",
"->",
"isReal",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rationalCompare",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
";",
"}",
"//hack to get around native php integer limitations",
"//what we should be doing here is to return $this->rationalCompare($a->modulus(), $b->modulus())",
"//but this blows up because of the big rationals it produces",
"$",
"am",
"=",
"$",
"a",
"->",
"modulus",
"(",
")",
"->",
"asFloatType",
"(",
")",
"->",
"get",
"(",
")",
";",
"$",
"bm",
"=",
"$",
"b",
"->",
"modulus",
"(",
")",
"->",
"asFloatType",
"(",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"$",
"am",
"==",
"$",
"bm",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"am",
"<",
"$",
"bm",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"1",
";",
"}"
] |
Compare complex numbers.
If both operands are real then compare the real parts
else compare the modulii of the two numbers
@param ComplexType $a
@param ComplexType $b
@return boolean
|
[
"Compare",
"complex",
"numbers",
".",
"If",
"both",
"operands",
"are",
"real",
"then",
"compare",
"the",
"real",
"parts",
"else",
"compare",
"the",
"modulii",
"of",
"the",
"two",
"numbers"
] |
train
|
https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Comparator/Native.php#L113-L132
|
acasademont/wurfl
|
WURFL/Handlers/CatchAllMozillaHandler.php
|
WURFL_Handlers_CatchAllMozillaHandler.applyConclusiveMatch
|
public function applyConclusiveMatch($userAgent)
{
if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance()) {
//High performance mode
$tolerance = WURFL_Handlers_Utils::firstCloseParen($userAgent);
return $this->getDeviceIDFromRIS($userAgent, $tolerance);
} else {
//High accuracy mode
return $this->getDeviceIDFromLD($userAgent, 5);
}
}
|
php
|
public function applyConclusiveMatch($userAgent)
{
if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance()) {
//High performance mode
$tolerance = WURFL_Handlers_Utils::firstCloseParen($userAgent);
return $this->getDeviceIDFromRIS($userAgent, $tolerance);
} else {
//High accuracy mode
return $this->getDeviceIDFromLD($userAgent, 5);
}
}
|
[
"public",
"function",
"applyConclusiveMatch",
"(",
"$",
"userAgent",
")",
"{",
"if",
"(",
"WURFL_Configuration_ConfigHolder",
"::",
"getWURFLConfig",
"(",
")",
"->",
"isHighPerformance",
"(",
")",
")",
"{",
"//High performance mode",
"$",
"tolerance",
"=",
"WURFL_Handlers_Utils",
"::",
"firstCloseParen",
"(",
"$",
"userAgent",
")",
";",
"return",
"$",
"this",
"->",
"getDeviceIDFromRIS",
"(",
"$",
"userAgent",
",",
"$",
"tolerance",
")",
";",
"}",
"else",
"{",
"//High accuracy mode",
"return",
"$",
"this",
"->",
"getDeviceIDFromLD",
"(",
"$",
"userAgent",
",",
"5",
")",
";",
"}",
"}"
] |
If UA starts with Mozilla, apply LD with tolerance 5.
@param string $userAgent
@return string
|
[
"If",
"UA",
"starts",
"with",
"Mozilla",
"apply",
"LD",
"with",
"tolerance",
"5",
"."
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/Handlers/CatchAllMozillaHandler.php#L51-L61
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.setOptions
|
public function setOptions(array $options)
{
$limit = array_get($options, static::OPT_LIMIT);
if (!empty($limit)) {
$this->setHeaders(['x-ms-max-item-count' => $limit]);
}
}
|
php
|
public function setOptions(array $options)
{
$limit = array_get($options, static::OPT_LIMIT);
if (!empty($limit)) {
$this->setHeaders(['x-ms-max-item-count' => $limit]);
}
}
|
[
"public",
"function",
"setOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"limit",
"=",
"array_get",
"(",
"$",
"options",
",",
"static",
"::",
"OPT_LIMIT",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"this",
"->",
"setHeaders",
"(",
"[",
"'x-ms-max-item-count'",
"=>",
"$",
"limit",
"]",
")",
";",
"}",
"}"
] |
Sets options.
@param array $options
|
[
"Sets",
"options",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L52-L59
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.listCollections
|
public function listCollections(array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->getAll();
$this->checkResponse($rs);
$colls = array_get($rs, 'DocumentCollections');
$list = [];
if (!empty($colls)) {
foreach ($colls as $coll) {
$list[] = array_get($coll, 'id');
}
}
return $list;
}
|
php
|
public function listCollections(array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->getAll();
$this->checkResponse($rs);
$colls = array_get($rs, 'DocumentCollections');
$list = [];
if (!empty($colls)) {
foreach ($colls as $coll) {
$list[] = array_get($coll, 'id');
}
}
return $list;
}
|
[
"public",
"function",
"listCollections",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"getAll",
"(",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"$",
"colls",
"=",
"array_get",
"(",
"$",
"rs",
",",
"'DocumentCollections'",
")",
";",
"$",
"list",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"colls",
")",
")",
"{",
"foreach",
"(",
"$",
"colls",
"as",
"$",
"coll",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"array_get",
"(",
"$",
"coll",
",",
"'id'",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
] |
List all collections in a Database.
@param array $options Operation options
@return array
|
[
"List",
"all",
"collections",
"in",
"a",
"Database",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L87-L103
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.getCollection
|
public function getCollection($id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function getCollection($id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"getCollection",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Retrieves a collection information.
@param string $id Collection ID
@param array $options Operation options
@return array
|
[
"Retrieves",
"a",
"collection",
"information",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L113-L123
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.createCollection
|
public function createCollection(array $data, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->create($data);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function createCollection(array $data, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->create($data);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"createCollection",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"create",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Creates a collection.
@param array $data Collection data
@param array $options Operation options
@return array
|
[
"Creates",
"a",
"collection",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L133-L143
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.replaceCollection
|
public function replaceCollection(array $data, $id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function replaceCollection(array $data, $id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"replaceCollection",
"(",
"array",
"$",
"data",
",",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"replace",
"(",
"$",
"data",
",",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Replaces a collection.
@param array $data Collection data
@param string $id
@param array $options Operation options
@return array
|
[
"Replaces",
"a",
"collection",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L154-L164
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.deleteCollection
|
public function deleteCollection($id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->delete($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function deleteCollection($id, array $options = [])
{
$this->setOptions($options);
$coll = new Collection($this->client, $this->database);
$coll->setHeaders($this->getHeaders());
$rs = $coll->delete($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"deleteCollection",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"coll",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
")",
";",
"$",
"coll",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"coll",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Deletes a collection.
@param string $id Collection ID
@param array $options Operation options
@return array
|
[
"Deletes",
"a",
"collection",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L174-L184
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.listDocuments
|
public function listDocuments($collection, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->getAll();
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function listDocuments($collection, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->getAll();
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"listDocuments",
"(",
"$",
"collection",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"getAll",
"(",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
List all documents in a collection.
@param string $collection Collection to list documents from
@param array $options Operation options
@return array
|
[
"List",
"all",
"documents",
"in",
"a",
"collection",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L198-L208
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.getDocument
|
public function getDocument($collection, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function getDocument($collection, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->get($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"getDocument",
"(",
"$",
"collection",
",",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Retrieves a document.
@param string $collection Collection to list document from
@param string $id ID of the document to retrieve
@param array $options Operation options
@return array
|
[
"Retrieves",
"a",
"document",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L219-L229
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.createDocument
|
public function createDocument($collection, array $data, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->create($data);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function createDocument($collection, array $data, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->create($data);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"createDocument",
"(",
"$",
"collection",
",",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"create",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Creates a document.
@param string $collection Collection to create a document in
@param array $data Document data
@param array $options Operation options
@return array
|
[
"Creates",
"a",
"document",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L240-L250
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.replaceDocument
|
public function replaceDocument($collection, array $data, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function replaceDocument($collection, array $data, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->replace($data, $id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"replaceDocument",
"(",
"$",
"collection",
",",
"array",
"$",
"data",
",",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"replace",
"(",
"$",
"data",
",",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Replaces a document.
@param string $collection Collection to replace a document in
@param array $data Document data
@param string $id ID of the document being replaced
@param array $options Operation options
@return array
|
[
"Replaces",
"a",
"document",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L262-L272
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.deleteDocument
|
public function deleteDocument($collection, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->delete($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function deleteDocument($collection, $id, array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->delete($id);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"deleteDocument",
"(",
"$",
"collection",
",",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Deletes a document.
@param string $collection Collection to delete a document from
@param string $id ID of the document to delete
@param array $options Operation options
@return array
|
[
"Deletes",
"a",
"document",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L283-L293
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.queryDocument
|
public function queryDocument($collection, $sql, array $params = [], array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->query($sql, $params);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
php
|
public function queryDocument($collection, $sql, array $params = [], array $options = [])
{
$this->setOptions($options);
$doc = new Document($this->client, $this->database, $collection);
$doc->setHeaders($this->getHeaders());
$rs = $doc->query($sql, $params);
$this->checkResponse($rs);
unset($rs['_curl_info']);
return $rs;
}
|
[
"public",
"function",
"queryDocument",
"(",
"$",
"collection",
",",
"$",
"sql",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"doc",
"=",
"new",
"Document",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"database",
",",
"$",
"collection",
")",
";",
"$",
"doc",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"doc",
"->",
"query",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"checkResponse",
"(",
"$",
"rs",
")",
";",
"unset",
"(",
"$",
"rs",
"[",
"'_curl_info'",
"]",
")",
";",
"return",
"$",
"rs",
";",
"}"
] |
Queries a collection for documents.
@param string $collection Collection to perform the query on
@param string $sql SQL query string
@param array $params Query parameters
@param array $options Operation options
@return array
|
[
"Queries",
"a",
"collection",
"for",
"documents",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L305-L315
|
dreamfactorysoftware/df-azure
|
src/Components/DocumentDBConnection.php
|
DocumentDBConnection.checkResponse
|
protected function checkResponse(array $response)
{
$responseCode = intval(array_get($response, '_curl_info.http_code'));
$message = array_get($response, 'message');
if ($responseCode >= 400) {
$context = ['response_headers' => array_get($response, '_curl_info.response_headers')];
throw new RestException($responseCode, $message, null, null, $context);
}
}
|
php
|
protected function checkResponse(array $response)
{
$responseCode = intval(array_get($response, '_curl_info.http_code'));
$message = array_get($response, 'message');
if ($responseCode >= 400) {
$context = ['response_headers' => array_get($response, '_curl_info.response_headers')];
throw new RestException($responseCode, $message, null, null, $context);
}
}
|
[
"protected",
"function",
"checkResponse",
"(",
"array",
"$",
"response",
")",
"{",
"$",
"responseCode",
"=",
"intval",
"(",
"array_get",
"(",
"$",
"response",
",",
"'_curl_info.http_code'",
")",
")",
";",
"$",
"message",
"=",
"array_get",
"(",
"$",
"response",
",",
"'message'",
")",
";",
"if",
"(",
"$",
"responseCode",
">=",
"400",
")",
"{",
"$",
"context",
"=",
"[",
"'response_headers'",
"=>",
"array_get",
"(",
"$",
"response",
",",
"'_curl_info.response_headers'",
")",
"]",
";",
"throw",
"new",
"RestException",
"(",
"$",
"responseCode",
",",
"$",
"message",
",",
"null",
",",
"null",
",",
"$",
"context",
")",
";",
"}",
"}"
] |
Checks response status code for exceptions.
@param array $response
@throws \DreamFactory\Core\Exceptions\RestException
|
[
"Checks",
"response",
"status",
"code",
"for",
"exceptions",
"."
] |
train
|
https://github.com/dreamfactorysoftware/df-azure/blob/48dff2796dc544344c0c7badaaa6917f1bcd623f/src/Components/DocumentDBConnection.php#L324-L333
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Admin/Entity/MenuAdmin.php
|
MenuAdmin.setUploadDir
|
public function setUploadDir($uploadDir, $webDir)
{
$this->uploadDir = $uploadDir;
$this->webDir = $webDir;
return $this;
}
|
php
|
public function setUploadDir($uploadDir, $webDir)
{
$this->uploadDir = $uploadDir;
$this->webDir = $webDir;
return $this;
}
|
[
"public",
"function",
"setUploadDir",
"(",
"$",
"uploadDir",
",",
"$",
"webDir",
")",
"{",
"$",
"this",
"->",
"uploadDir",
"=",
"$",
"uploadDir",
";",
"$",
"this",
"->",
"webDir",
"=",
"$",
"webDir",
";",
"return",
"$",
"this",
";",
"}"
] |
Set upload directory
@author Vincent Chalamon <[email protected]>
@param string $uploadDir
@param string $webDir
@return MenuAdmin
|
[
"Set",
"upload",
"directory"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/MenuAdmin.php#L117-L123
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Admin/Entity/MenuAdmin.php
|
MenuAdmin.createQuery
|
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->leftJoin($query->getRootAlias().'.article', 'article')->addSelect('article')
->leftJoin($query->getRootAlias().'.parent', 'parent')->addSelect('parent')
->leftJoin($query->getRootAlias().'.children', 'children')->addSelect('children')
->orderBy($query->getRootAlias().'.root, '.$query->getRootAlias().'.lft', 'ASC');
return $query;
}
|
php
|
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->leftJoin($query->getRootAlias().'.article', 'article')->addSelect('article')
->leftJoin($query->getRootAlias().'.parent', 'parent')->addSelect('parent')
->leftJoin($query->getRootAlias().'.children', 'children')->addSelect('children')
->orderBy($query->getRootAlias().'.root, '.$query->getRootAlias().'.lft', 'ASC');
return $query;
}
|
[
"public",
"function",
"createQuery",
"(",
"$",
"context",
"=",
"'list'",
")",
"{",
"$",
"query",
"=",
"parent",
"::",
"createQuery",
"(",
"$",
"context",
")",
";",
"$",
"query",
"->",
"leftJoin",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.article'",
",",
"'article'",
")",
"->",
"addSelect",
"(",
"'article'",
")",
"->",
"leftJoin",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.parent'",
",",
"'parent'",
")",
"->",
"addSelect",
"(",
"'parent'",
")",
"->",
"leftJoin",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.children'",
",",
"'children'",
")",
"->",
"addSelect",
"(",
"'children'",
")",
"->",
"orderBy",
"(",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.root, '",
".",
"$",
"query",
"->",
"getRootAlias",
"(",
")",
".",
"'.lft'",
",",
"'ASC'",
")",
";",
"return",
"$",
"query",
";",
"}"
] |
Need to override createQuery method because of list order & joins
{@inheritdoc}
|
[
"Need",
"to",
"override",
"createQuery",
"method",
"because",
"of",
"list",
"order",
"&",
"joins"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/MenuAdmin.php#L130-L139
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Admin/Entity/MenuAdmin.php
|
MenuAdmin.configureListFields
|
protected function configureListFields(ListMapper $mapper)
{
$mapper
->add('up', 'field_tree_up', array(
'label' => 'menu.field.up',
)
)
->add('down', 'field_tree_down', array(
'label' => 'menu.field.down',
)
)
->addIdentifier('adminListTitle', 'html', array(
'label' => 'menu.field.title',
)
)
;
parent::configureListFields($mapper);
}
|
php
|
protected function configureListFields(ListMapper $mapper)
{
$mapper
->add('up', 'field_tree_up', array(
'label' => 'menu.field.up',
)
)
->add('down', 'field_tree_down', array(
'label' => 'menu.field.down',
)
)
->addIdentifier('adminListTitle', 'html', array(
'label' => 'menu.field.title',
)
)
;
parent::configureListFields($mapper);
}
|
[
"protected",
"function",
"configureListFields",
"(",
"ListMapper",
"$",
"mapper",
")",
"{",
"$",
"mapper",
"->",
"add",
"(",
"'up'",
",",
"'field_tree_up'",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.up'",
",",
")",
")",
"->",
"add",
"(",
"'down'",
",",
"'field_tree_down'",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.down'",
",",
")",
")",
"->",
"addIdentifier",
"(",
"'adminListTitle'",
",",
"'html'",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.title'",
",",
")",
")",
";",
"parent",
"::",
"configureListFields",
"(",
"$",
"mapper",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/MenuAdmin.php#L144-L161
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Admin/Entity/MenuAdmin.php
|
MenuAdmin.configureFormFields
|
protected function configureFormFields(FormMapper $mapper)
{
$id = $this->getSubject()->getId();
$mapper->with('menu.group.general', array('class' => 'col-md-6'));
if (!$id || $this->getSubject()->getLvl()) {
$mapper
->add('parent', null, array(
'label' => 'menu.field.parent',
'property' => 'adminListTitle',
'query_builder' => function (EntityRepository $entityRepository) use ($id) {
$builder = $entityRepository->createQueryBuilder('p')->orderBy('p.root, p.lft', 'ASC');
if ($id) {
$builder->andWhere('p.id != :id')->setParameter('id', $id);
}
return $builder;
},
)
);
}
$mapper->add('title', null, array(
'label' => 'menu.field.title',
)
)
->add('image', null, array(
'label' => 'menu.field.image',
'required' => false,
)
)
->add('file', 'file', array(
'label' => 'menu.field.path',
'required' => false,
'filename' => $this->getSubject()->getPath(),
)
)
->end();
parent::configureFormFields($mapper);
if (!$id || $this->getSubject()->getParent()) {
$mapper
->with('menu.group.url', array('class' => 'col-md-6'))
->add('url', null, array(
'label' => 'menu.field.url',
'required' => false,
)
)
->add('article', null, array(
'label' => 'menu.field.article',
'help' => 'menu.help.article',
'required' => false,
'query_builder' => function (EntityRepository $entityRepository) {
return $entityRepository->createQueryBuilder('a')
->andWhere('SUBSTRING(a.slug, 1, 5) != :error')
->setParameter('error', 'error')
->orderBy('a.title', 'ASC');
},
)
)
->add('target', 'choice', array(
'label' => 'menu.field.target',
'required' => false,
'choices' => array(
'_blank' => $this->trans('menu.help.target.blank', array(), 'SonataAdminBundle'),
'_self' => $this->trans('menu.help.target.self', array(), 'SonataAdminBundle'),
),
)
)
->end();
}
}
|
php
|
protected function configureFormFields(FormMapper $mapper)
{
$id = $this->getSubject()->getId();
$mapper->with('menu.group.general', array('class' => 'col-md-6'));
if (!$id || $this->getSubject()->getLvl()) {
$mapper
->add('parent', null, array(
'label' => 'menu.field.parent',
'property' => 'adminListTitle',
'query_builder' => function (EntityRepository $entityRepository) use ($id) {
$builder = $entityRepository->createQueryBuilder('p')->orderBy('p.root, p.lft', 'ASC');
if ($id) {
$builder->andWhere('p.id != :id')->setParameter('id', $id);
}
return $builder;
},
)
);
}
$mapper->add('title', null, array(
'label' => 'menu.field.title',
)
)
->add('image', null, array(
'label' => 'menu.field.image',
'required' => false,
)
)
->add('file', 'file', array(
'label' => 'menu.field.path',
'required' => false,
'filename' => $this->getSubject()->getPath(),
)
)
->end();
parent::configureFormFields($mapper);
if (!$id || $this->getSubject()->getParent()) {
$mapper
->with('menu.group.url', array('class' => 'col-md-6'))
->add('url', null, array(
'label' => 'menu.field.url',
'required' => false,
)
)
->add('article', null, array(
'label' => 'menu.field.article',
'help' => 'menu.help.article',
'required' => false,
'query_builder' => function (EntityRepository $entityRepository) {
return $entityRepository->createQueryBuilder('a')
->andWhere('SUBSTRING(a.slug, 1, 5) != :error')
->setParameter('error', 'error')
->orderBy('a.title', 'ASC');
},
)
)
->add('target', 'choice', array(
'label' => 'menu.field.target',
'required' => false,
'choices' => array(
'_blank' => $this->trans('menu.help.target.blank', array(), 'SonataAdminBundle'),
'_self' => $this->trans('menu.help.target.self', array(), 'SonataAdminBundle'),
),
)
)
->end();
}
}
|
[
"protected",
"function",
"configureFormFields",
"(",
"FormMapper",
"$",
"mapper",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getSubject",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"mapper",
"->",
"with",
"(",
"'menu.group.general'",
",",
"array",
"(",
"'class'",
"=>",
"'col-md-6'",
")",
")",
";",
"if",
"(",
"!",
"$",
"id",
"||",
"$",
"this",
"->",
"getSubject",
"(",
")",
"->",
"getLvl",
"(",
")",
")",
"{",
"$",
"mapper",
"->",
"add",
"(",
"'parent'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.parent'",
",",
"'property'",
"=>",
"'adminListTitle'",
",",
"'query_builder'",
"=>",
"function",
"(",
"EntityRepository",
"$",
"entityRepository",
")",
"use",
"(",
"$",
"id",
")",
"{",
"$",
"builder",
"=",
"$",
"entityRepository",
"->",
"createQueryBuilder",
"(",
"'p'",
")",
"->",
"orderBy",
"(",
"'p.root, p.lft'",
",",
"'ASC'",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"builder",
"->",
"andWhere",
"(",
"'p.id != :id'",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"builder",
";",
"}",
",",
")",
")",
";",
"}",
"$",
"mapper",
"->",
"add",
"(",
"'title'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.title'",
",",
")",
")",
"->",
"add",
"(",
"'image'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.image'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
"->",
"add",
"(",
"'file'",
",",
"'file'",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.path'",
",",
"'required'",
"=>",
"false",
",",
"'filename'",
"=>",
"$",
"this",
"->",
"getSubject",
"(",
")",
"->",
"getPath",
"(",
")",
",",
")",
")",
"->",
"end",
"(",
")",
";",
"parent",
"::",
"configureFormFields",
"(",
"$",
"mapper",
")",
";",
"if",
"(",
"!",
"$",
"id",
"||",
"$",
"this",
"->",
"getSubject",
"(",
")",
"->",
"getParent",
"(",
")",
")",
"{",
"$",
"mapper",
"->",
"with",
"(",
"'menu.group.url'",
",",
"array",
"(",
"'class'",
"=>",
"'col-md-6'",
")",
")",
"->",
"add",
"(",
"'url'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.url'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
"->",
"add",
"(",
"'article'",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.article'",
",",
"'help'",
"=>",
"'menu.help.article'",
",",
"'required'",
"=>",
"false",
",",
"'query_builder'",
"=>",
"function",
"(",
"EntityRepository",
"$",
"entityRepository",
")",
"{",
"return",
"$",
"entityRepository",
"->",
"createQueryBuilder",
"(",
"'a'",
")",
"->",
"andWhere",
"(",
"'SUBSTRING(a.slug, 1, 5) != :error'",
")",
"->",
"setParameter",
"(",
"'error'",
",",
"'error'",
")",
"->",
"orderBy",
"(",
"'a.title'",
",",
"'ASC'",
")",
";",
"}",
",",
")",
")",
"->",
"add",
"(",
"'target'",
",",
"'choice'",
",",
"array",
"(",
"'label'",
"=>",
"'menu.field.target'",
",",
"'required'",
"=>",
"false",
",",
"'choices'",
"=>",
"array",
"(",
"'_blank'",
"=>",
"$",
"this",
"->",
"trans",
"(",
"'menu.help.target.blank'",
",",
"array",
"(",
")",
",",
"'SonataAdminBundle'",
")",
",",
"'_self'",
"=>",
"$",
"this",
"->",
"trans",
"(",
"'menu.help.target.self'",
",",
"array",
"(",
")",
",",
"'SonataAdminBundle'",
")",
",",
")",
",",
")",
")",
"->",
"end",
"(",
")",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/MenuAdmin.php#L174-L242
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Admin/Entity/MenuAdmin.php
|
MenuAdmin.preRemove
|
public function preRemove($object)
{
/** @var Menu $object */
if ($object->isImage() && is_file($this->uploadDir.pathinfo($object->getPath(), PATHINFO_BASENAME))) {
unlink($this->uploadDir.pathinfo($object->getPath(), PATHINFO_BASENAME));
}
$this->menuRepository->verify();
$this->menuRepository->recover();
}
|
php
|
public function preRemove($object)
{
/** @var Menu $object */
if ($object->isImage() && is_file($this->uploadDir.pathinfo($object->getPath(), PATHINFO_BASENAME))) {
unlink($this->uploadDir.pathinfo($object->getPath(), PATHINFO_BASENAME));
}
$this->menuRepository->verify();
$this->menuRepository->recover();
}
|
[
"public",
"function",
"preRemove",
"(",
"$",
"object",
")",
"{",
"/** @var Menu $object */",
"if",
"(",
"$",
"object",
"->",
"isImage",
"(",
")",
"&&",
"is_file",
"(",
"$",
"this",
"->",
"uploadDir",
".",
"pathinfo",
"(",
"$",
"object",
"->",
"getPath",
"(",
")",
",",
"PATHINFO_BASENAME",
")",
")",
")",
"{",
"unlink",
"(",
"$",
"this",
"->",
"uploadDir",
".",
"pathinfo",
"(",
"$",
"object",
"->",
"getPath",
"(",
")",
",",
"PATHINFO_BASENAME",
")",
")",
";",
"}",
"$",
"this",
"->",
"menuRepository",
"->",
"verify",
"(",
")",
";",
"$",
"this",
"->",
"menuRepository",
"->",
"recover",
"(",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/MenuAdmin.php#L247-L255
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Admin/Entity/MenuAdmin.php
|
MenuAdmin.prePersist
|
public function prePersist($object)
{
/** @var Menu $object */
if ($object->isImage()) {
$object->upload($this->uploadDir, $this->webDir);
}
$this->menuRepository->verify();
$this->menuRepository->recover();
}
|
php
|
public function prePersist($object)
{
/** @var Menu $object */
if ($object->isImage()) {
$object->upload($this->uploadDir, $this->webDir);
}
$this->menuRepository->verify();
$this->menuRepository->recover();
}
|
[
"public",
"function",
"prePersist",
"(",
"$",
"object",
")",
"{",
"/** @var Menu $object */",
"if",
"(",
"$",
"object",
"->",
"isImage",
"(",
")",
")",
"{",
"$",
"object",
"->",
"upload",
"(",
"$",
"this",
"->",
"uploadDir",
",",
"$",
"this",
"->",
"webDir",
")",
";",
"}",
"$",
"this",
"->",
"menuRepository",
"->",
"verify",
"(",
")",
";",
"$",
"this",
"->",
"menuRepository",
"->",
"recover",
"(",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/MenuAdmin.php#L260-L268
|
yosmanyga/resource
|
src/Yosmanyga/Resource/Cacher/Storer/CheckFileStorer.php
|
CheckFileStorer.getFilename
|
protected function getFilename(Resource $resource)
{
return sprintf(
'%s/%s%s',
$this->dir,
md5(serialize($resource)),
$this->suffix
);
}
|
php
|
protected function getFilename(Resource $resource)
{
return sprintf(
'%s/%s%s',
$this->dir,
md5(serialize($resource)),
$this->suffix
);
}
|
[
"protected",
"function",
"getFilename",
"(",
"Resource",
"$",
"resource",
")",
"{",
"return",
"sprintf",
"(",
"'%s/%s%s'",
",",
"$",
"this",
"->",
"dir",
",",
"md5",
"(",
"serialize",
"(",
"$",
"resource",
")",
")",
",",
"$",
"this",
"->",
"suffix",
")",
";",
"}"
] |
@param \Yosmanyga\Resource\Resource $resource
@return string
|
[
"@param",
"\\",
"Yosmanyga",
"\\",
"Resource",
"\\",
"Resource",
"$resource"
] |
train
|
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Cacher/Storer/CheckFileStorer.php#L30-L38
|
gugglegum/mb-str-pad
|
src/MbString.php
|
MbString.mb_str_pad
|
public static function mb_str_pad(string $input, int $pad_length, string $pad_string = " ", int $pad_type = STR_PAD_RIGHT, string $encoding = "UTF-8")
{
$input_length = mb_strlen($input);
switch ($pad_type) {
case STR_PAD_RIGHT :
return $input . self::mb_fill_string($pad_string, $pad_length - $input_length);
case STR_PAD_LEFT :
return self::mb_fill_string($pad_string, $pad_length - $input_length) . $input;
case STR_PAD_BOTH :
return self::mb_fill_string($pad_string, (int) floor(($pad_length - $input_length) / 2), $encoding)
. $input
. self::mb_fill_string($pad_string, (int) ceil(($pad_length - $input_length) / 2), $encoding);
default :
throw new \InvalidArgumentException("mb_str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT or STR_PAD_BOTH");
}
}
|
php
|
public static function mb_str_pad(string $input, int $pad_length, string $pad_string = " ", int $pad_type = STR_PAD_RIGHT, string $encoding = "UTF-8")
{
$input_length = mb_strlen($input);
switch ($pad_type) {
case STR_PAD_RIGHT :
return $input . self::mb_fill_string($pad_string, $pad_length - $input_length);
case STR_PAD_LEFT :
return self::mb_fill_string($pad_string, $pad_length - $input_length) . $input;
case STR_PAD_BOTH :
return self::mb_fill_string($pad_string, (int) floor(($pad_length - $input_length) / 2), $encoding)
. $input
. self::mb_fill_string($pad_string, (int) ceil(($pad_length - $input_length) / 2), $encoding);
default :
throw new \InvalidArgumentException("mb_str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT or STR_PAD_BOTH");
}
}
|
[
"public",
"static",
"function",
"mb_str_pad",
"(",
"string",
"$",
"input",
",",
"int",
"$",
"pad_length",
",",
"string",
"$",
"pad_string",
"=",
"\" \"",
",",
"int",
"$",
"pad_type",
"=",
"STR_PAD_RIGHT",
",",
"string",
"$",
"encoding",
"=",
"\"UTF-8\"",
")",
"{",
"$",
"input_length",
"=",
"mb_strlen",
"(",
"$",
"input",
")",
";",
"switch",
"(",
"$",
"pad_type",
")",
"{",
"case",
"STR_PAD_RIGHT",
":",
"return",
"$",
"input",
".",
"self",
"::",
"mb_fill_string",
"(",
"$",
"pad_string",
",",
"$",
"pad_length",
"-",
"$",
"input_length",
")",
";",
"case",
"STR_PAD_LEFT",
":",
"return",
"self",
"::",
"mb_fill_string",
"(",
"$",
"pad_string",
",",
"$",
"pad_length",
"-",
"$",
"input_length",
")",
".",
"$",
"input",
";",
"case",
"STR_PAD_BOTH",
":",
"return",
"self",
"::",
"mb_fill_string",
"(",
"$",
"pad_string",
",",
"(",
"int",
")",
"floor",
"(",
"(",
"$",
"pad_length",
"-",
"$",
"input_length",
")",
"/",
"2",
")",
",",
"$",
"encoding",
")",
".",
"$",
"input",
".",
"self",
"::",
"mb_fill_string",
"(",
"$",
"pad_string",
",",
"(",
"int",
")",
"ceil",
"(",
"(",
"$",
"pad_length",
"-",
"$",
"input_length",
")",
"/",
"2",
")",
",",
"$",
"encoding",
")",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"mb_str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT or STR_PAD_BOTH\"",
")",
";",
"}",
"}"
] |
Multi-byte version of str_pad()
@param string $input
@param int $pad_length
@param string $pad_string
@param int $pad_type
@param string $encoding
@return string
|
[
"Multi",
"-",
"byte",
"version",
"of",
"str_pad",
"()"
] |
train
|
https://github.com/gugglegum/mb-str-pad/blob/18fefbdf543dd35b2c25e26d6aab1e3d61cde9f1/src/MbString.php#L19-L34
|
gugglegum/mb-str-pad
|
src/MbString.php
|
MbString.mb_fill_string
|
private static function mb_fill_string(string $pattern, $length, $encoding = 'UTF-8'): string
{
$pattern_length = mb_strlen($pattern, $encoding);
$str = '';
$i = 0;
while ($i < $length) {
if ($length - $i >= $pattern_length) {
$str .= $pattern;
$i += $pattern_length;
} else {
$str .= mb_substr($pattern, 0, $length - $i, $encoding);
break;
}
}
return $str;
}
|
php
|
private static function mb_fill_string(string $pattern, $length, $encoding = 'UTF-8'): string
{
$pattern_length = mb_strlen($pattern, $encoding);
$str = '';
$i = 0;
while ($i < $length) {
if ($length - $i >= $pattern_length) {
$str .= $pattern;
$i += $pattern_length;
} else {
$str .= mb_substr($pattern, 0, $length - $i, $encoding);
break;
}
}
return $str;
}
|
[
"private",
"static",
"function",
"mb_fill_string",
"(",
"string",
"$",
"pattern",
",",
"$",
"length",
",",
"$",
"encoding",
"=",
"'UTF-8'",
")",
":",
"string",
"{",
"$",
"pattern_length",
"=",
"mb_strlen",
"(",
"$",
"pattern",
",",
"$",
"encoding",
")",
";",
"$",
"str",
"=",
"''",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"length",
")",
"{",
"if",
"(",
"$",
"length",
"-",
"$",
"i",
">=",
"$",
"pattern_length",
")",
"{",
"$",
"str",
".=",
"$",
"pattern",
";",
"$",
"i",
"+=",
"$",
"pattern_length",
";",
"}",
"else",
"{",
"$",
"str",
".=",
"mb_substr",
"(",
"$",
"pattern",
",",
"0",
",",
"$",
"length",
"-",
"$",
"i",
",",
"$",
"encoding",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] |
Returns a string of given length filled with some pattern substring
@param string $pattern
@param $length
@param string $encoding
@return string
|
[
"Returns",
"a",
"string",
"of",
"given",
"length",
"filled",
"with",
"some",
"pattern",
"substring"
] |
train
|
https://github.com/gugglegum/mb-str-pad/blob/18fefbdf543dd35b2c25e26d6aab1e3d61cde9f1/src/MbString.php#L44-L59
|
stubbles/stubbles-webapp-core
|
src/main/php/htmlpassthrough/HtmlFilePassThrough.php
|
HtmlFilePassThrough.resolve
|
public function resolve(Request $request, Response $response, UriPath $uriPath)
{
$routeName = $uriPath->remaining('index.html');
if (!file_exists($this->routePath . $routeName)) {
return $response->notFound();
}
return $this->modifyContent(
$request,
$response,
file_get_contents($this->routePath . $routeName),
$routeName
);
}
|
php
|
public function resolve(Request $request, Response $response, UriPath $uriPath)
{
$routeName = $uriPath->remaining('index.html');
if (!file_exists($this->routePath . $routeName)) {
return $response->notFound();
}
return $this->modifyContent(
$request,
$response,
file_get_contents($this->routePath . $routeName),
$routeName
);
}
|
[
"public",
"function",
"resolve",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"UriPath",
"$",
"uriPath",
")",
"{",
"$",
"routeName",
"=",
"$",
"uriPath",
"->",
"remaining",
"(",
"'index.html'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"routePath",
".",
"$",
"routeName",
")",
")",
"{",
"return",
"$",
"response",
"->",
"notFound",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"modifyContent",
"(",
"$",
"request",
",",
"$",
"response",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"routePath",
".",
"$",
"routeName",
")",
",",
"$",
"routeName",
")",
";",
"}"
] |
processes the request
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@param \stubbles\webapp\UriPath $uriPath information about called uri path
@return string|\stubbles\webapp\response\Error
|
[
"processes",
"the",
"request"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/htmlpassthrough/HtmlFilePassThrough.php#L49-L62
|
stubbles/stubbles-webapp-core
|
src/main/php/htmlpassthrough/HtmlFilePassThrough.php
|
HtmlFilePassThrough.modifyContent
|
protected function modifyContent(
Request $request,
Response $response,
string $content,
string $routeName
): string {
return $content;
}
|
php
|
protected function modifyContent(
Request $request,
Response $response,
string $content,
string $routeName
): string {
return $content;
}
|
[
"protected",
"function",
"modifyContent",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"string",
"$",
"content",
",",
"string",
"$",
"routeName",
")",
":",
"string",
"{",
"return",
"$",
"content",
";",
"}"
] |
hook to modify the content before passing it to the response
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@param string $content actual content for response
@param string $routeName name of the route
@return string
|
[
"hook",
"to",
"modify",
"the",
"content",
"before",
"passing",
"it",
"to",
"the",
"response"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/htmlpassthrough/HtmlFilePassThrough.php#L73-L80
|
activecollab/databasestructure
|
src/Field/Composite/CreatedByField.php
|
CreatedByField.onAddedToType
|
public function onAddedToType(TypeInterface &$type)
{
parent::onAddedToType($type);
if ($this->isRequired()) {
$type->addTrait(CreatedByRequiredInterface::class);
} else {
$type->addTrait(CreatedByOptionalInterface::class);
}
}
|
php
|
public function onAddedToType(TypeInterface &$type)
{
parent::onAddedToType($type);
if ($this->isRequired()) {
$type->addTrait(CreatedByRequiredInterface::class);
} else {
$type->addTrait(CreatedByOptionalInterface::class);
}
}
|
[
"public",
"function",
"onAddedToType",
"(",
"TypeInterface",
"&",
"$",
"type",
")",
"{",
"parent",
"::",
"onAddedToType",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"type",
"->",
"addTrait",
"(",
"CreatedByRequiredInterface",
"::",
"class",
")",
";",
"}",
"else",
"{",
"$",
"type",
"->",
"addTrait",
"(",
"CreatedByOptionalInterface",
"::",
"class",
")",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Field/Composite/CreatedByField.php#L34-L43
|
eloquent/liberator
|
src/LiberatorObject.php
|
LiberatorObject.popsCall
|
public function popsCall($method, array &$arguments)
{
if ($this->liberatorReflector->hasMethod($method)) {
$method = $this->liberatorReflector->getMethod($method);
$method->setAccessible(true);
return $this->popsProxySubValue(
$method->invokeArgs($this->popsValue(), $arguments)
);
}
return parent::popsCall($method, $arguments);
}
|
php
|
public function popsCall($method, array &$arguments)
{
if ($this->liberatorReflector->hasMethod($method)) {
$method = $this->liberatorReflector->getMethod($method);
$method->setAccessible(true);
return $this->popsProxySubValue(
$method->invokeArgs($this->popsValue(), $arguments)
);
}
return parent::popsCall($method, $arguments);
}
|
[
"public",
"function",
"popsCall",
"(",
"$",
"method",
",",
"array",
"&",
"$",
"arguments",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"liberatorReflector",
"->",
"hasMethod",
"(",
"$",
"method",
")",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"liberatorReflector",
"->",
"getMethod",
"(",
"$",
"method",
")",
";",
"$",
"method",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"this",
"->",
"popsProxySubValue",
"(",
"$",
"method",
"->",
"invokeArgs",
"(",
"$",
"this",
"->",
"popsValue",
"(",
")",
",",
"$",
"arguments",
")",
")",
";",
"}",
"return",
"parent",
"::",
"popsCall",
"(",
"$",
"method",
",",
"$",
"arguments",
")",
";",
"}"
] |
Call a method on the wrapped object with support for by-reference
arguments.
@param string $method The name of the method to call.
@param array &$arguments The arguments.
@return mixed The result of the method call.
|
[
"Call",
"a",
"method",
"on",
"the",
"wrapped",
"object",
"with",
"support",
"for",
"by",
"-",
"reference",
"arguments",
"."
] |
train
|
https://github.com/eloquent/liberator/blob/d90c159e0067f7f3e376c8e4b1b72d502f7aa0aa/src/LiberatorObject.php#L60-L72
|
eloquent/liberator
|
src/LiberatorObject.php
|
LiberatorObject.__isset
|
public function __isset($property)
{
if ($propertyReflector = $this->liberatorPropertyReflector($property)) {
return null !== $propertyReflector->getValue($this->popsValue());
}
return parent::__isset($property);
}
|
php
|
public function __isset($property)
{
if ($propertyReflector = $this->liberatorPropertyReflector($property)) {
return null !== $propertyReflector->getValue($this->popsValue());
}
return parent::__isset($property);
}
|
[
"public",
"function",
"__isset",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"propertyReflector",
"=",
"$",
"this",
"->",
"liberatorPropertyReflector",
"(",
"$",
"property",
")",
")",
"{",
"return",
"null",
"!==",
"$",
"propertyReflector",
"->",
"getValue",
"(",
"$",
"this",
"->",
"popsValue",
"(",
")",
")",
";",
"}",
"return",
"parent",
"::",
"__isset",
"(",
"$",
"property",
")",
";",
"}"
] |
Returns true if the property exists on the wrapped object.
@param string $property The name of the property to search for.
@return boolean True if the property exists.
|
[
"Returns",
"true",
"if",
"the",
"property",
"exists",
"on",
"the",
"wrapped",
"object",
"."
] |
train
|
https://github.com/eloquent/liberator/blob/d90c159e0067f7f3e376c8e4b1b72d502f7aa0aa/src/LiberatorObject.php#L116-L123
|
hollodotme/TreeMDown
|
src/Utilities/Linker.php
|
Linker.getInternalLinks
|
public function getInternalLinks( \DOMNode $node ) : array
{
$this->guardHasOwnerDocument( $node );
$internalLinks = [];
$xpath = new \DOMXPath( $node->ownerDocument );
$aTags = $xpath->query( '*//a[@href]' );
/** @var \DOMElement $aTag */
foreach ( $aTags as $aTag )
{
$href = $aTag->getAttribute( 'href' );
if ( !$this->isHyperRefIgnored( $href ) )
{
$internalLinks[] = $aTag;
}
}
return $internalLinks;
}
|
php
|
public function getInternalLinks( \DOMNode $node ) : array
{
$this->guardHasOwnerDocument( $node );
$internalLinks = [];
$xpath = new \DOMXPath( $node->ownerDocument );
$aTags = $xpath->query( '*//a[@href]' );
/** @var \DOMElement $aTag */
foreach ( $aTags as $aTag )
{
$href = $aTag->getAttribute( 'href' );
if ( !$this->isHyperRefIgnored( $href ) )
{
$internalLinks[] = $aTag;
}
}
return $internalLinks;
}
|
[
"public",
"function",
"getInternalLinks",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
":",
"array",
"{",
"$",
"this",
"->",
"guardHasOwnerDocument",
"(",
"$",
"node",
")",
";",
"$",
"internalLinks",
"=",
"[",
"]",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"node",
"->",
"ownerDocument",
")",
";",
"$",
"aTags",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'*//a[@href]'",
")",
";",
"/** @var \\DOMElement $aTag */",
"foreach",
"(",
"$",
"aTags",
"as",
"$",
"aTag",
")",
"{",
"$",
"href",
"=",
"$",
"aTag",
"->",
"getAttribute",
"(",
"'href'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isHyperRefIgnored",
"(",
"$",
"href",
")",
")",
"{",
"$",
"internalLinks",
"[",
"]",
"=",
"$",
"aTag",
";",
"}",
"}",
"return",
"$",
"internalLinks",
";",
"}"
] |
@param \DOMNode $node
@throws \InvalidArgumentException
@return array|\DOMElement[]
|
[
"@param",
"\\",
"DOMNode",
"$node"
] |
train
|
https://github.com/hollodotme/TreeMDown/blob/462c4118c70b68963e0176d540fc8502730ffe27/src/Utilities/Linker.php#L29-L48
|
WellCommerce/CoreBundle
|
Form/AbstractFormBuilder.php
|
AbstractFormBuilder.initService
|
protected function initService(string $type, string $alias, array $options)
{
$id = $this->resolverFactory->resolve($type, $alias);
$service = $this->get($id);
$service->setOptions($options);
return $service;
}
|
php
|
protected function initService(string $type, string $alias, array $options)
{
$id = $this->resolverFactory->resolve($type, $alias);
$service = $this->get($id);
$service->setOptions($options);
return $service;
}
|
[
"protected",
"function",
"initService",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"alias",
",",
"array",
"$",
"options",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"resolverFactory",
"->",
"resolve",
"(",
"$",
"type",
",",
"$",
"alias",
")",
";",
"$",
"service",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"service",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"return",
"$",
"service",
";",
"}"
] |
Initializes a service by its type
@param string $type
@param string $alias
@param array $options
@return object
|
[
"Initializes",
"a",
"service",
"by",
"its",
"type"
] |
train
|
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Form/AbstractFormBuilder.php#L129-L137
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/AbstractResource.php
|
AbstractResource.negotiateMimeType
|
public function negotiateMimeType(Request $request, Response $response): bool
{
if ($this->supportedMimeTypes->isContentNegotationDisabled()) {
return true;
}
$mimeType = $this->supportedMimeTypes->findMatch(
$request->readHeader('HTTP_ACCEPT')
->defaultingTo(emptyAcceptHeader())
->withFilter(new AcceptFilter())
);
if (null === $mimeType) {
$response->notAcceptable($this->supportedMimeTypes->asArray());
return false;
}
if (!$this->supportedMimeTypes->provideClass($mimeType)) {
$response->write(
$response->internalServerError(
'No mime type class defined for negotiated content type ' . $mimeType
)
);
return false;
}
$response->adjustMimeType(
$this->injector->getInstance(
$this->supportedMimeTypes->classFor($mimeType)
)->specialise($mimeType)
);
return true;
}
|
php
|
public function negotiateMimeType(Request $request, Response $response): bool
{
if ($this->supportedMimeTypes->isContentNegotationDisabled()) {
return true;
}
$mimeType = $this->supportedMimeTypes->findMatch(
$request->readHeader('HTTP_ACCEPT')
->defaultingTo(emptyAcceptHeader())
->withFilter(new AcceptFilter())
);
if (null === $mimeType) {
$response->notAcceptable($this->supportedMimeTypes->asArray());
return false;
}
if (!$this->supportedMimeTypes->provideClass($mimeType)) {
$response->write(
$response->internalServerError(
'No mime type class defined for negotiated content type ' . $mimeType
)
);
return false;
}
$response->adjustMimeType(
$this->injector->getInstance(
$this->supportedMimeTypes->classFor($mimeType)
)->specialise($mimeType)
);
return true;
}
|
[
"public",
"function",
"negotiateMimeType",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"supportedMimeTypes",
"->",
"isContentNegotationDisabled",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"mimeType",
"=",
"$",
"this",
"->",
"supportedMimeTypes",
"->",
"findMatch",
"(",
"$",
"request",
"->",
"readHeader",
"(",
"'HTTP_ACCEPT'",
")",
"->",
"defaultingTo",
"(",
"emptyAcceptHeader",
"(",
")",
")",
"->",
"withFilter",
"(",
"new",
"AcceptFilter",
"(",
")",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"mimeType",
")",
"{",
"$",
"response",
"->",
"notAcceptable",
"(",
"$",
"this",
"->",
"supportedMimeTypes",
"->",
"asArray",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"supportedMimeTypes",
"->",
"provideClass",
"(",
"$",
"mimeType",
")",
")",
"{",
"$",
"response",
"->",
"write",
"(",
"$",
"response",
"->",
"internalServerError",
"(",
"'No mime type class defined for negotiated content type '",
".",
"$",
"mimeType",
")",
")",
";",
"return",
"false",
";",
"}",
"$",
"response",
"->",
"adjustMimeType",
"(",
"$",
"this",
"->",
"injector",
"->",
"getInstance",
"(",
"$",
"this",
"->",
"supportedMimeTypes",
"->",
"classFor",
"(",
"$",
"mimeType",
")",
")",
"->",
"specialise",
"(",
"$",
"mimeType",
")",
")",
";",
"return",
"true",
";",
"}"
] |
negotiates proper mime type for given request
@param \stubbles\webapp\Request $request
@param \stubbles\webapp\Response $response response to send
@return bool
@since 6.0.0
|
[
"negotiates",
"proper",
"mime",
"type",
"for",
"given",
"request"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/AbstractResource.php#L89-L120
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/AbstractResource.php
|
AbstractResource.applyPreInterceptors
|
public function applyPreInterceptors(Request $request, Response $response): bool
{
return $this->interceptors->preProcess($request, $response);
}
|
php
|
public function applyPreInterceptors(Request $request, Response $response): bool
{
return $this->interceptors->preProcess($request, $response);
}
|
[
"public",
"function",
"applyPreInterceptors",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"interceptors",
"->",
"preProcess",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] |
apply pre interceptors
Returns false if one of the pre interceptors cancels the request.
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return bool
|
[
"apply",
"pre",
"interceptors"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/AbstractResource.php#L141-L144
|
stubbles/stubbles-webapp-core
|
src/main/php/routing/AbstractResource.php
|
AbstractResource.applyPostInterceptors
|
public function applyPostInterceptors(Request $request, Response $response): bool
{
return $this->interceptors->postProcess($request, $response);
}
|
php
|
public function applyPostInterceptors(Request $request, Response $response): bool
{
return $this->interceptors->postProcess($request, $response);
}
|
[
"public",
"function",
"applyPostInterceptors",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"interceptors",
"->",
"postProcess",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] |
apply post interceptors
@param \stubbles\webapp\Request $request current request
@param \stubbles\webapp\Response $response response to send
@return bool
|
[
"apply",
"post",
"interceptors"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/AbstractResource.php#L153-L156
|
hamjoint/mustard-auctions
|
src/lib/Http/Controllers/ItemController.php
|
ItemController.getBid
|
public function getBid($itemId)
{
$item = Item::findOrFail($itemId);
if (!$item->auction) {
return redirect($item->url)->withErrors([
'This item is not an auction, so cannot be bid on.',
]);
}
$bids = $item->getBidHistory();
$highest_bid = $bids->first() ?: new Bid();
if ($bids->isEmpty()) {
$minimum_bid = $item->startPrice;
} elseif ($highest_bid->bidder == Auth::user()) {
$minimum_bid = BidIncrement::getMinimumNextBid($highest_bid->amount);
} else {
$minimum_bid = BidIncrement::getMinimumNextBid($item->biddingPrice);
}
return view('mustard::item.bid', [
'item' => $item,
'bids' => $bids,
'highest_bid' => $highest_bid,
'minimum_bid' => $minimum_bid,
]);
}
|
php
|
public function getBid($itemId)
{
$item = Item::findOrFail($itemId);
if (!$item->auction) {
return redirect($item->url)->withErrors([
'This item is not an auction, so cannot be bid on.',
]);
}
$bids = $item->getBidHistory();
$highest_bid = $bids->first() ?: new Bid();
if ($bids->isEmpty()) {
$minimum_bid = $item->startPrice;
} elseif ($highest_bid->bidder == Auth::user()) {
$minimum_bid = BidIncrement::getMinimumNextBid($highest_bid->amount);
} else {
$minimum_bid = BidIncrement::getMinimumNextBid($item->biddingPrice);
}
return view('mustard::item.bid', [
'item' => $item,
'bids' => $bids,
'highest_bid' => $highest_bid,
'minimum_bid' => $minimum_bid,
]);
}
|
[
"public",
"function",
"getBid",
"(",
"$",
"itemId",
")",
"{",
"$",
"item",
"=",
"Item",
"::",
"findOrFail",
"(",
"$",
"itemId",
")",
";",
"if",
"(",
"!",
"$",
"item",
"->",
"auction",
")",
"{",
"return",
"redirect",
"(",
"$",
"item",
"->",
"url",
")",
"->",
"withErrors",
"(",
"[",
"'This item is not an auction, so cannot be bid on.'",
",",
"]",
")",
";",
"}",
"$",
"bids",
"=",
"$",
"item",
"->",
"getBidHistory",
"(",
")",
";",
"$",
"highest_bid",
"=",
"$",
"bids",
"->",
"first",
"(",
")",
"?",
":",
"new",
"Bid",
"(",
")",
";",
"if",
"(",
"$",
"bids",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"minimum_bid",
"=",
"$",
"item",
"->",
"startPrice",
";",
"}",
"elseif",
"(",
"$",
"highest_bid",
"->",
"bidder",
"==",
"Auth",
"::",
"user",
"(",
")",
")",
"{",
"$",
"minimum_bid",
"=",
"BidIncrement",
"::",
"getMinimumNextBid",
"(",
"$",
"highest_bid",
"->",
"amount",
")",
";",
"}",
"else",
"{",
"$",
"minimum_bid",
"=",
"BidIncrement",
"::",
"getMinimumNextBid",
"(",
"$",
"item",
"->",
"biddingPrice",
")",
";",
"}",
"return",
"view",
"(",
"'mustard::item.bid'",
",",
"[",
"'item'",
"=>",
"$",
"item",
",",
"'bids'",
"=>",
"$",
"bids",
",",
"'highest_bid'",
"=>",
"$",
"highest_bid",
",",
"'minimum_bid'",
"=>",
"$",
"minimum_bid",
",",
"]",
")",
";",
"}"
] |
Return the item bid view.
@param int $itemId
@return \Illuminate\View\View
|
[
"Return",
"the",
"item",
"bid",
"view",
"."
] |
train
|
https://github.com/hamjoint/mustard-auctions/blob/66c8723d8681466e280263ad100f3fdc5895480d/src/lib/Http/Controllers/ItemController.php#L40-L68
|
hamjoint/mustard-auctions
|
src/lib/Http/Controllers/ItemController.php
|
ItemController.postBid
|
public function postBid(Request $request)
{
$item = Item::findOrFail($request->input('item_id'));
if ($item->seller->userId == Auth::user()->userId) {
return redirect()->back()->withErrors([
'You cannot bid on your own items.',
]);
}
if (time() < $item->startDate) {
return redirect()->back()->withErrors([
'This item is not yet open for bidding.',
]);
}
if (time() > $item->endDate) {
return redirect()->back()->withErrors([
'This item has ended and cannot be bid on.',
]);
}
$minimum_bid = ($item->bids->count())
? BidIncrement::getMinimumNextBid($item->biddingPrice)
: $item->startPrice;
$highest_bid = $item->getBidHistory()->first();
// If highest bidder, new bid must be higher than existing maximum
if ($highest_bid && $highest_bid->bidder == Auth::user()) {
if ($request->input('amount') < BidIncrement::getMinimumNextBid($highest_bid->amount)) {
return redirect()->back()->withErrors([
'amount' => 'Your new maximum bid does not meet the minimum amount.',
]);
}
// Not highest bidder, so bid must be higher than minimum amount for current bidding price
} elseif ($request->input('amount') < $minimum_bid) {
return redirect()->back()->withErrors([
'amount' => 'Your bid does not meet the minimum amount.',
]);
}
$this->validate(
$request,
[
'amount' => 'required|monetary',
]
);
$item->placeBid($request->input('amount'), Auth::user());
// If there's no highest bid, there's no bids, so bidding price can stay at start price
if ($highest_bid) {
// Have we beaten the highest bid?
if ($request->input('amount') > $highest_bid->amount) {
// If the reserve price is above the last highest bid but below the new maximum bid, set bidding to that
if ($item->isReserved() && $request->input('amount') >= $item->reservePrice) {
$item->biddingPrice = $item->reservePrice;
}
// Check if we're increasing the maximum bid
if ($highest_bid->bidder == Auth::user()) {
// Save in case the bidding price has been bumped to the reserve
$item->save();
$highest_bid->delete();
return redirect()->back()->withStatus('Your maximum bid has been increased.');
}
// Make sure we're not using the reserve price as the new bidding price
if (!in_array('bidding_price', array_keys($item->getDirty()))) {
// Set bidding to the maximum bid or the next increment, whichever is lower
$item->biddingPrice = min([
$request->input('amount'),
// Calculate the next increment after the previous highest bid
$item::getMinimumBidAmount($highest_bid->amount),
]);
}
$highest_bid->bidder->sendEmail(
"You've been outbid",
'emails.item.outbid',
[
'item_id' => $item->itemId,
'item_name' => $item->name,
'item_price' => $item->biddingPrice,
]
);
// We're not the highest bid, so just increment
} else {
$item->biddingPrice = $request->input('amount');
}
} else {
$item->biddingPrice = ($item->isReserved() && $request->input('amount') >= $item->reservePrice)
? $item->reservePrice
: $item->startPrice;
}
$item->save();
return redirect()->back()->withStatus('Your bid has been placed.');
}
|
php
|
public function postBid(Request $request)
{
$item = Item::findOrFail($request->input('item_id'));
if ($item->seller->userId == Auth::user()->userId) {
return redirect()->back()->withErrors([
'You cannot bid on your own items.',
]);
}
if (time() < $item->startDate) {
return redirect()->back()->withErrors([
'This item is not yet open for bidding.',
]);
}
if (time() > $item->endDate) {
return redirect()->back()->withErrors([
'This item has ended and cannot be bid on.',
]);
}
$minimum_bid = ($item->bids->count())
? BidIncrement::getMinimumNextBid($item->biddingPrice)
: $item->startPrice;
$highest_bid = $item->getBidHistory()->first();
// If highest bidder, new bid must be higher than existing maximum
if ($highest_bid && $highest_bid->bidder == Auth::user()) {
if ($request->input('amount') < BidIncrement::getMinimumNextBid($highest_bid->amount)) {
return redirect()->back()->withErrors([
'amount' => 'Your new maximum bid does not meet the minimum amount.',
]);
}
// Not highest bidder, so bid must be higher than minimum amount for current bidding price
} elseif ($request->input('amount') < $minimum_bid) {
return redirect()->back()->withErrors([
'amount' => 'Your bid does not meet the minimum amount.',
]);
}
$this->validate(
$request,
[
'amount' => 'required|monetary',
]
);
$item->placeBid($request->input('amount'), Auth::user());
// If there's no highest bid, there's no bids, so bidding price can stay at start price
if ($highest_bid) {
// Have we beaten the highest bid?
if ($request->input('amount') > $highest_bid->amount) {
// If the reserve price is above the last highest bid but below the new maximum bid, set bidding to that
if ($item->isReserved() && $request->input('amount') >= $item->reservePrice) {
$item->biddingPrice = $item->reservePrice;
}
// Check if we're increasing the maximum bid
if ($highest_bid->bidder == Auth::user()) {
// Save in case the bidding price has been bumped to the reserve
$item->save();
$highest_bid->delete();
return redirect()->back()->withStatus('Your maximum bid has been increased.');
}
// Make sure we're not using the reserve price as the new bidding price
if (!in_array('bidding_price', array_keys($item->getDirty()))) {
// Set bidding to the maximum bid or the next increment, whichever is lower
$item->biddingPrice = min([
$request->input('amount'),
// Calculate the next increment after the previous highest bid
$item::getMinimumBidAmount($highest_bid->amount),
]);
}
$highest_bid->bidder->sendEmail(
"You've been outbid",
'emails.item.outbid',
[
'item_id' => $item->itemId,
'item_name' => $item->name,
'item_price' => $item->biddingPrice,
]
);
// We're not the highest bid, so just increment
} else {
$item->biddingPrice = $request->input('amount');
}
} else {
$item->biddingPrice = ($item->isReserved() && $request->input('amount') >= $item->reservePrice)
? $item->reservePrice
: $item->startPrice;
}
$item->save();
return redirect()->back()->withStatus('Your bid has been placed.');
}
|
[
"public",
"function",
"postBid",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"item",
"=",
"Item",
"::",
"findOrFail",
"(",
"$",
"request",
"->",
"input",
"(",
"'item_id'",
")",
")",
";",
"if",
"(",
"$",
"item",
"->",
"seller",
"->",
"userId",
"==",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withErrors",
"(",
"[",
"'You cannot bid on your own items.'",
",",
"]",
")",
";",
"}",
"if",
"(",
"time",
"(",
")",
"<",
"$",
"item",
"->",
"startDate",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withErrors",
"(",
"[",
"'This item is not yet open for bidding.'",
",",
"]",
")",
";",
"}",
"if",
"(",
"time",
"(",
")",
">",
"$",
"item",
"->",
"endDate",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withErrors",
"(",
"[",
"'This item has ended and cannot be bid on.'",
",",
"]",
")",
";",
"}",
"$",
"minimum_bid",
"=",
"(",
"$",
"item",
"->",
"bids",
"->",
"count",
"(",
")",
")",
"?",
"BidIncrement",
"::",
"getMinimumNextBid",
"(",
"$",
"item",
"->",
"biddingPrice",
")",
":",
"$",
"item",
"->",
"startPrice",
";",
"$",
"highest_bid",
"=",
"$",
"item",
"->",
"getBidHistory",
"(",
")",
"->",
"first",
"(",
")",
";",
"// If highest bidder, new bid must be higher than existing maximum",
"if",
"(",
"$",
"highest_bid",
"&&",
"$",
"highest_bid",
"->",
"bidder",
"==",
"Auth",
"::",
"user",
"(",
")",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
"<",
"BidIncrement",
"::",
"getMinimumNextBid",
"(",
"$",
"highest_bid",
"->",
"amount",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withErrors",
"(",
"[",
"'amount'",
"=>",
"'Your new maximum bid does not meet the minimum amount.'",
",",
"]",
")",
";",
"}",
"// Not highest bidder, so bid must be higher than minimum amount for current bidding price",
"}",
"elseif",
"(",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
"<",
"$",
"minimum_bid",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withErrors",
"(",
"[",
"'amount'",
"=>",
"'Your bid does not meet the minimum amount.'",
",",
"]",
")",
";",
"}",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"[",
"'amount'",
"=>",
"'required|monetary'",
",",
"]",
")",
";",
"$",
"item",
"->",
"placeBid",
"(",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
",",
"Auth",
"::",
"user",
"(",
")",
")",
";",
"// If there's no highest bid, there's no bids, so bidding price can stay at start price",
"if",
"(",
"$",
"highest_bid",
")",
"{",
"// Have we beaten the highest bid?",
"if",
"(",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
">",
"$",
"highest_bid",
"->",
"amount",
")",
"{",
"// If the reserve price is above the last highest bid but below the new maximum bid, set bidding to that",
"if",
"(",
"$",
"item",
"->",
"isReserved",
"(",
")",
"&&",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
">=",
"$",
"item",
"->",
"reservePrice",
")",
"{",
"$",
"item",
"->",
"biddingPrice",
"=",
"$",
"item",
"->",
"reservePrice",
";",
"}",
"// Check if we're increasing the maximum bid",
"if",
"(",
"$",
"highest_bid",
"->",
"bidder",
"==",
"Auth",
"::",
"user",
"(",
")",
")",
"{",
"// Save in case the bidding price has been bumped to the reserve",
"$",
"item",
"->",
"save",
"(",
")",
";",
"$",
"highest_bid",
"->",
"delete",
"(",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withStatus",
"(",
"'Your maximum bid has been increased.'",
")",
";",
"}",
"// Make sure we're not using the reserve price as the new bidding price",
"if",
"(",
"!",
"in_array",
"(",
"'bidding_price'",
",",
"array_keys",
"(",
"$",
"item",
"->",
"getDirty",
"(",
")",
")",
")",
")",
"{",
"// Set bidding to the maximum bid or the next increment, whichever is lower",
"$",
"item",
"->",
"biddingPrice",
"=",
"min",
"(",
"[",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
",",
"// Calculate the next increment after the previous highest bid",
"$",
"item",
"::",
"getMinimumBidAmount",
"(",
"$",
"highest_bid",
"->",
"amount",
")",
",",
"]",
")",
";",
"}",
"$",
"highest_bid",
"->",
"bidder",
"->",
"sendEmail",
"(",
"\"You've been outbid\"",
",",
"'emails.item.outbid'",
",",
"[",
"'item_id'",
"=>",
"$",
"item",
"->",
"itemId",
",",
"'item_name'",
"=>",
"$",
"item",
"->",
"name",
",",
"'item_price'",
"=>",
"$",
"item",
"->",
"biddingPrice",
",",
"]",
")",
";",
"// We're not the highest bid, so just increment",
"}",
"else",
"{",
"$",
"item",
"->",
"biddingPrice",
"=",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"item",
"->",
"biddingPrice",
"=",
"(",
"$",
"item",
"->",
"isReserved",
"(",
")",
"&&",
"$",
"request",
"->",
"input",
"(",
"'amount'",
")",
">=",
"$",
"item",
"->",
"reservePrice",
")",
"?",
"$",
"item",
"->",
"reservePrice",
":",
"$",
"item",
"->",
"startPrice",
";",
"}",
"$",
"item",
"->",
"save",
"(",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withStatus",
"(",
"'Your bid has been placed.'",
")",
";",
"}"
] |
Place a bid.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\RedirectResponse
|
[
"Place",
"a",
"bid",
"."
] |
train
|
https://github.com/hamjoint/mustard-auctions/blob/66c8723d8681466e280263ad100f3fdc5895480d/src/lib/Http/Controllers/ItemController.php#L77-L179
|
hamjoint/mustard-auctions
|
src/lib/Http/Controllers/ItemController.php
|
ItemController.endedAuctionsAdmin
|
public static function endedAuctionsAdmin()
{
$items = Item::has('bids')
->where('auction', true)
->whereRaw('`reserve_price` <= `bidding_price`')
->where('user_ended', 0)
->where('winning_bid_id', 0)
->where('end_date', '<', time())
->get();
foreach ($items as $item) {
$item->end();
$item->winningBid->bidder->sendEmail(
'You won an item',
'emails.item.won',
[
'item_id' => $item->itemId,
'item_name' => $item->name,
'item_price' => $item->biddingPrice,
'bid_amount' => $item->winningBid->amount,
'bid_placed' => $item->winningBid->placed,
]
);
}
}
|
php
|
public static function endedAuctionsAdmin()
{
$items = Item::has('bids')
->where('auction', true)
->whereRaw('`reserve_price` <= `bidding_price`')
->where('user_ended', 0)
->where('winning_bid_id', 0)
->where('end_date', '<', time())
->get();
foreach ($items as $item) {
$item->end();
$item->winningBid->bidder->sendEmail(
'You won an item',
'emails.item.won',
[
'item_id' => $item->itemId,
'item_name' => $item->name,
'item_price' => $item->biddingPrice,
'bid_amount' => $item->winningBid->amount,
'bid_placed' => $item->winningBid->placed,
]
);
}
}
|
[
"public",
"static",
"function",
"endedAuctionsAdmin",
"(",
")",
"{",
"$",
"items",
"=",
"Item",
"::",
"has",
"(",
"'bids'",
")",
"->",
"where",
"(",
"'auction'",
",",
"true",
")",
"->",
"whereRaw",
"(",
"'`reserve_price` <= `bidding_price`'",
")",
"->",
"where",
"(",
"'user_ended'",
",",
"0",
")",
"->",
"where",
"(",
"'winning_bid_id'",
",",
"0",
")",
"->",
"where",
"(",
"'end_date'",
",",
"'<'",
",",
"time",
"(",
")",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"end",
"(",
")",
";",
"$",
"item",
"->",
"winningBid",
"->",
"bidder",
"->",
"sendEmail",
"(",
"'You won an item'",
",",
"'emails.item.won'",
",",
"[",
"'item_id'",
"=>",
"$",
"item",
"->",
"itemId",
",",
"'item_name'",
"=>",
"$",
"item",
"->",
"name",
",",
"'item_price'",
"=>",
"$",
"item",
"->",
"biddingPrice",
",",
"'bid_amount'",
"=>",
"$",
"item",
"->",
"winningBid",
"->",
"amount",
",",
"'bid_placed'",
"=>",
"$",
"item",
"->",
"winningBid",
"->",
"placed",
",",
"]",
")",
";",
"}",
"}"
] |
Watch an item.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\RedirectResponse
|
[
"Watch",
"an",
"item",
"."
] |
train
|
https://github.com/hamjoint/mustard-auctions/blob/66c8723d8681466e280263ad100f3fdc5895480d/src/lib/Http/Controllers/ItemController.php#L188-L213
|
nkt/flame
|
src/QueryBuilder/SaveQuery.php
|
SaveQuery.column
|
public function column($name, $value)
{
$this->columns[$this->grammar->buildId($name)] = $value;
return $this;
}
|
php
|
public function column($name, $value)
{
$this->columns[$this->grammar->buildId($name)] = $value;
return $this;
}
|
[
"public",
"function",
"column",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"columns",
"[",
"$",
"this",
"->",
"grammar",
"->",
"buildId",
"(",
"$",
"name",
")",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
@param string $name
@param string $value
@return static
|
[
"@param",
"string",
"$name",
"@param",
"string",
"$value"
] |
train
|
https://github.com/nkt/flame/blob/16f9f172db5a8a618b628429e0986eacb089d217/src/QueryBuilder/SaveQuery.php#L56-L61
|
nkt/flame
|
src/QueryBuilder/SaveQuery.php
|
SaveQuery.columns
|
public function columns(array $columns)
{
foreach ($columns as $name => $value) {
$this->columns[$this->grammar->buildId($name)] = $value;
}
return $this;
}
|
php
|
public function columns(array $columns)
{
foreach ($columns as $name => $value) {
$this->columns[$this->grammar->buildId($name)] = $value;
}
return $this;
}
|
[
"public",
"function",
"columns",
"(",
"array",
"$",
"columns",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"columns",
"[",
"$",
"this",
"->",
"grammar",
"->",
"buildId",
"(",
"$",
"name",
")",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
@param array $columns
@return static
|
[
"@param",
"array",
"$columns"
] |
train
|
https://github.com/nkt/flame/blob/16f9f172db5a8a618b628429e0986eacb089d217/src/QueryBuilder/SaveQuery.php#L68-L75
|
movoin/one-swoole
|
src/Config/Config.php
|
Config.setRootPath
|
public static function setRootPath(string $root)
{
$mode = static::mode();
$path = "{$root}/{$mode}";
if (! file_exists($path)) {
throw new InvalidArgumentException("'{$path}' not exists");
}
static::$root = realpath($root);
static::$path = realpath($path);
unset($mode, $path);
}
|
php
|
public static function setRootPath(string $root)
{
$mode = static::mode();
$path = "{$root}/{$mode}";
if (! file_exists($path)) {
throw new InvalidArgumentException("'{$path}' not exists");
}
static::$root = realpath($root);
static::$path = realpath($path);
unset($mode, $path);
}
|
[
"public",
"static",
"function",
"setRootPath",
"(",
"string",
"$",
"root",
")",
"{",
"$",
"mode",
"=",
"static",
"::",
"mode",
"(",
")",
";",
"$",
"path",
"=",
"\"{$root}/{$mode}\"",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"'{$path}' not exists\"",
")",
";",
"}",
"static",
"::",
"$",
"root",
"=",
"realpath",
"(",
"$",
"root",
")",
";",
"static",
"::",
"$",
"path",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"unset",
"(",
"$",
"mode",
",",
"$",
"path",
")",
";",
"}"
] |
设置配置文件根目录
@param string $root
@throws \InvalidArgumentException
|
[
"设置配置文件根目录"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Config/Config.php#L81-L94
|
movoin/one-swoole
|
src/Config/Config.php
|
Config.load
|
public static function load($force = false)
{
if ($force === false && ! empty(static::$config)) {
return;
}
if (! isset(static::$placeholders['{ROOT_PATH}'])) {
static::addPlaceHolder('{ROOT_PATH}', ROOT_PATH);
}
if (! isset(static::$placeholders['{RUNTIME_PATH}'])) {
static::addPlaceHolder('{RUNTIME_PATH}', RUNTIME_PATH);
}
if (! isset(static::$root)) {
static::setRootPath(CONFIG_PATH);
}
$conf = static::importFromPath(static::$path);
// 全局配置
$globals = [
'swoole' => static::$root . '/swoole.yml',
'global' => static::$root . '/global.yml',
];
foreach ($globals as $name => $path) {
if (file_exists($path)) {
$conf[$name] = static::readFile($path);
}
}
unset($globals);
// 主配置
if (! isset($conf['global']['name'])) {
$conf['global']['name'] = static::NAME;
}
if (! isset($conf['global']['version'])) {
$conf['global']['version'] = static::VERSION;
}
// 协议配置
if (isset($conf['server'])) {
foreach ($conf['server'] as $name => &$server) {
// Swoole 配置
if (isset($server['swoole'])) {
$server['swoole'] = array_merge(
$conf['swoole'],
$server['swoole']
);
} else {
$server['swoole'] = $conf['swoole'];
}
// Protocol
$server['protocol'] = isset($server['protocol']) ? strtolower($server['protocol']) : 'http';
// Runtime
if (! isset($server['runtime_path'])) {
$server['runtime_path'] = $conf['global']['runtime_path'];
}
// Swoole 日志
if (! isset($server['swoole']['log_file'])) {
$server['swoole']['log_file'] = $server['runtime_path'] . '/logs/error.log';
}
// TCP 监听
if (! isset($server['sock'])) {
$server['sock'] = $server['runtime_path'] . '/var/' . $name . '.sock';
}
// 主进程 PID 文件位置
$server['swoole']['pid_file'] = $server['runtime_path'] . '/var/' . $name . '.pid';
}
}
$global = $conf['global'];
unset($conf['swoole'], $conf['global']);
// {{
static::$config = static::preformPlaceHolder(array_merge($global, $conf));
// }}
unset($conf, $global);
}
|
php
|
public static function load($force = false)
{
if ($force === false && ! empty(static::$config)) {
return;
}
if (! isset(static::$placeholders['{ROOT_PATH}'])) {
static::addPlaceHolder('{ROOT_PATH}', ROOT_PATH);
}
if (! isset(static::$placeholders['{RUNTIME_PATH}'])) {
static::addPlaceHolder('{RUNTIME_PATH}', RUNTIME_PATH);
}
if (! isset(static::$root)) {
static::setRootPath(CONFIG_PATH);
}
$conf = static::importFromPath(static::$path);
// 全局配置
$globals = [
'swoole' => static::$root . '/swoole.yml',
'global' => static::$root . '/global.yml',
];
foreach ($globals as $name => $path) {
if (file_exists($path)) {
$conf[$name] = static::readFile($path);
}
}
unset($globals);
// 主配置
if (! isset($conf['global']['name'])) {
$conf['global']['name'] = static::NAME;
}
if (! isset($conf['global']['version'])) {
$conf['global']['version'] = static::VERSION;
}
// 协议配置
if (isset($conf['server'])) {
foreach ($conf['server'] as $name => &$server) {
// Swoole 配置
if (isset($server['swoole'])) {
$server['swoole'] = array_merge(
$conf['swoole'],
$server['swoole']
);
} else {
$server['swoole'] = $conf['swoole'];
}
// Protocol
$server['protocol'] = isset($server['protocol']) ? strtolower($server['protocol']) : 'http';
// Runtime
if (! isset($server['runtime_path'])) {
$server['runtime_path'] = $conf['global']['runtime_path'];
}
// Swoole 日志
if (! isset($server['swoole']['log_file'])) {
$server['swoole']['log_file'] = $server['runtime_path'] . '/logs/error.log';
}
// TCP 监听
if (! isset($server['sock'])) {
$server['sock'] = $server['runtime_path'] . '/var/' . $name . '.sock';
}
// 主进程 PID 文件位置
$server['swoole']['pid_file'] = $server['runtime_path'] . '/var/' . $name . '.pid';
}
}
$global = $conf['global'];
unset($conf['swoole'], $conf['global']);
// {{
static::$config = static::preformPlaceHolder(array_merge($global, $conf));
// }}
unset($conf, $global);
}
|
[
"public",
"static",
"function",
"load",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"force",
"===",
"false",
"&&",
"!",
"empty",
"(",
"static",
"::",
"$",
"config",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"placeholders",
"[",
"'{ROOT_PATH}'",
"]",
")",
")",
"{",
"static",
"::",
"addPlaceHolder",
"(",
"'{ROOT_PATH}'",
",",
"ROOT_PATH",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"placeholders",
"[",
"'{RUNTIME_PATH}'",
"]",
")",
")",
"{",
"static",
"::",
"addPlaceHolder",
"(",
"'{RUNTIME_PATH}'",
",",
"RUNTIME_PATH",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"root",
")",
")",
"{",
"static",
"::",
"setRootPath",
"(",
"CONFIG_PATH",
")",
";",
"}",
"$",
"conf",
"=",
"static",
"::",
"importFromPath",
"(",
"static",
"::",
"$",
"path",
")",
";",
"// 全局配置",
"$",
"globals",
"=",
"[",
"'swoole'",
"=>",
"static",
"::",
"$",
"root",
".",
"'/swoole.yml'",
",",
"'global'",
"=>",
"static",
"::",
"$",
"root",
".",
"'/global.yml'",
",",
"]",
";",
"foreach",
"(",
"$",
"globals",
"as",
"$",
"name",
"=>",
"$",
"path",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"conf",
"[",
"$",
"name",
"]",
"=",
"static",
"::",
"readFile",
"(",
"$",
"path",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"globals",
")",
";",
"// 主配置",
"if",
"(",
"!",
"isset",
"(",
"$",
"conf",
"[",
"'global'",
"]",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"conf",
"[",
"'global'",
"]",
"[",
"'name'",
"]",
"=",
"static",
"::",
"NAME",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"conf",
"[",
"'global'",
"]",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"conf",
"[",
"'global'",
"]",
"[",
"'version'",
"]",
"=",
"static",
"::",
"VERSION",
";",
"}",
"// 协议配置",
"if",
"(",
"isset",
"(",
"$",
"conf",
"[",
"'server'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"conf",
"[",
"'server'",
"]",
"as",
"$",
"name",
"=>",
"&",
"$",
"server",
")",
"{",
"// Swoole 配置",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'swoole'",
"]",
")",
")",
"{",
"$",
"server",
"[",
"'swoole'",
"]",
"=",
"array_merge",
"(",
"$",
"conf",
"[",
"'swoole'",
"]",
",",
"$",
"server",
"[",
"'swoole'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"server",
"[",
"'swoole'",
"]",
"=",
"$",
"conf",
"[",
"'swoole'",
"]",
";",
"}",
"// Protocol",
"$",
"server",
"[",
"'protocol'",
"]",
"=",
"isset",
"(",
"$",
"server",
"[",
"'protocol'",
"]",
")",
"?",
"strtolower",
"(",
"$",
"server",
"[",
"'protocol'",
"]",
")",
":",
"'http'",
";",
"// Runtime",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'runtime_path'",
"]",
")",
")",
"{",
"$",
"server",
"[",
"'runtime_path'",
"]",
"=",
"$",
"conf",
"[",
"'global'",
"]",
"[",
"'runtime_path'",
"]",
";",
"}",
"// Swoole 日志",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'swoole'",
"]",
"[",
"'log_file'",
"]",
")",
")",
"{",
"$",
"server",
"[",
"'swoole'",
"]",
"[",
"'log_file'",
"]",
"=",
"$",
"server",
"[",
"'runtime_path'",
"]",
".",
"'/logs/error.log'",
";",
"}",
"// TCP 监听",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'sock'",
"]",
")",
")",
"{",
"$",
"server",
"[",
"'sock'",
"]",
"=",
"$",
"server",
"[",
"'runtime_path'",
"]",
".",
"'/var/'",
".",
"$",
"name",
".",
"'.sock'",
";",
"}",
"// 主进程 PID 文件位置",
"$",
"server",
"[",
"'swoole'",
"]",
"[",
"'pid_file'",
"]",
"=",
"$",
"server",
"[",
"'runtime_path'",
"]",
".",
"'/var/'",
".",
"$",
"name",
".",
"'.pid'",
";",
"}",
"}",
"$",
"global",
"=",
"$",
"conf",
"[",
"'global'",
"]",
";",
"unset",
"(",
"$",
"conf",
"[",
"'swoole'",
"]",
",",
"$",
"conf",
"[",
"'global'",
"]",
")",
";",
"// {{",
"static",
"::",
"$",
"config",
"=",
"static",
"::",
"preformPlaceHolder",
"(",
"array_merge",
"(",
"$",
"global",
",",
"$",
"conf",
")",
")",
";",
"// }}",
"unset",
"(",
"$",
"conf",
",",
"$",
"global",
")",
";",
"}"
] |
加载配置
@param bool $force
@throws \RuntimeException
|
[
"加载配置"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Config/Config.php#L127-L215
|
movoin/one-swoole
|
src/Config/Config.php
|
Config.writeFile
|
public static function writeFile(string $filename, array $config): bool
{
return (bool) file_put_contents(
static::$root . '/' . $filename,
Yaml::dump($config)
);
}
|
php
|
public static function writeFile(string $filename, array $config): bool
{
return (bool) file_put_contents(
static::$root . '/' . $filename,
Yaml::dump($config)
);
}
|
[
"public",
"static",
"function",
"writeFile",
"(",
"string",
"$",
"filename",
",",
"array",
"$",
"config",
")",
":",
"bool",
"{",
"return",
"(",
"bool",
")",
"file_put_contents",
"(",
"static",
"::",
"$",
"root",
".",
"'/'",
".",
"$",
"filename",
",",
"Yaml",
"::",
"dump",
"(",
"$",
"config",
")",
")",
";",
"}"
] |
写入配置文件
@param string $filename
@param array $config
@return bool
|
[
"写入配置文件"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Config/Config.php#L249-L255
|
movoin/one-swoole
|
src/Config/Config.php
|
Config.importFromPath
|
private static function importFromPath(string $path): array
{
$conf = [];
$paths = new DirectoryIterator($path);
foreach ($paths as $path) {
if ($path->isDot()) {
continue;
}
if ($path->isDir()) {
$conf[$path->getFileName()] = static::importFromPath($path->getPathName());
}
if ($path->isFile()) {
if ($path->getExtension() === 'yml') {
$pathinfo = pathinfo($path->getFileName());
$conf[$pathinfo['filename']] = (array) static::readFile($path->getPathName(), []);
unset($pathinfo);
}
}
}
unset($paths);
return $conf;
}
|
php
|
private static function importFromPath(string $path): array
{
$conf = [];
$paths = new DirectoryIterator($path);
foreach ($paths as $path) {
if ($path->isDot()) {
continue;
}
if ($path->isDir()) {
$conf[$path->getFileName()] = static::importFromPath($path->getPathName());
}
if ($path->isFile()) {
if ($path->getExtension() === 'yml') {
$pathinfo = pathinfo($path->getFileName());
$conf[$pathinfo['filename']] = (array) static::readFile($path->getPathName(), []);
unset($pathinfo);
}
}
}
unset($paths);
return $conf;
}
|
[
"private",
"static",
"function",
"importFromPath",
"(",
"string",
"$",
"path",
")",
":",
"array",
"{",
"$",
"conf",
"=",
"[",
"]",
";",
"$",
"paths",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"path",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"path",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"conf",
"[",
"$",
"path",
"->",
"getFileName",
"(",
")",
"]",
"=",
"static",
"::",
"importFromPath",
"(",
"$",
"path",
"->",
"getPathName",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"path",
"->",
"isFile",
"(",
")",
")",
"{",
"if",
"(",
"$",
"path",
"->",
"getExtension",
"(",
")",
"===",
"'yml'",
")",
"{",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"path",
"->",
"getFileName",
"(",
")",
")",
";",
"$",
"conf",
"[",
"$",
"pathinfo",
"[",
"'filename'",
"]",
"]",
"=",
"(",
"array",
")",
"static",
"::",
"readFile",
"(",
"$",
"path",
"->",
"getPathName",
"(",
")",
",",
"[",
"]",
")",
";",
"unset",
"(",
"$",
"pathinfo",
")",
";",
"}",
"}",
"}",
"unset",
"(",
"$",
"paths",
")",
";",
"return",
"$",
"conf",
";",
"}"
] |
从路径导入配置文件
@param string $path
@return array
|
[
"从路径导入配置文件"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Config/Config.php#L264-L292
|
movoin/one-swoole
|
src/Config/Config.php
|
Config.preformPlaceHolder
|
private static function preformPlaceHolder(array $config): array
{
$preform = [];
foreach ($config as $name => $value) {
if (Assert::array($value)) {
$preform[$name] = static::preformPlaceHolder($value);
} elseif (Assert::string($value)) {
$preform[$name] = trim($value);
foreach (static::$placeholders as $placeholder => $path) {
if (Assert::contains($preform[$name], $placeholder)) {
$preform[$name] = str_replace($placeholder, $path, $preform[$name]);
}
}
} else {
$preform[$name] = trim($value);
}
}
return $preform;
}
|
php
|
private static function preformPlaceHolder(array $config): array
{
$preform = [];
foreach ($config as $name => $value) {
if (Assert::array($value)) {
$preform[$name] = static::preformPlaceHolder($value);
} elseif (Assert::string($value)) {
$preform[$name] = trim($value);
foreach (static::$placeholders as $placeholder => $path) {
if (Assert::contains($preform[$name], $placeholder)) {
$preform[$name] = str_replace($placeholder, $path, $preform[$name]);
}
}
} else {
$preform[$name] = trim($value);
}
}
return $preform;
}
|
[
"private",
"static",
"function",
"preformPlaceHolder",
"(",
"array",
"$",
"config",
")",
":",
"array",
"{",
"$",
"preform",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"Assert",
"::",
"array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"preform",
"[",
"$",
"name",
"]",
"=",
"static",
"::",
"preformPlaceHolder",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"Assert",
"::",
"string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"preform",
"[",
"$",
"name",
"]",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"placeholders",
"as",
"$",
"placeholder",
"=>",
"$",
"path",
")",
"{",
"if",
"(",
"Assert",
"::",
"contains",
"(",
"$",
"preform",
"[",
"$",
"name",
"]",
",",
"$",
"placeholder",
")",
")",
"{",
"$",
"preform",
"[",
"$",
"name",
"]",
"=",
"str_replace",
"(",
"$",
"placeholder",
",",
"$",
"path",
",",
"$",
"preform",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"preform",
"[",
"$",
"name",
"]",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"preform",
";",
"}"
] |
预处理占位符
@param array $config
@return array
|
[
"预处理占位符"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Config/Config.php#L301-L322
|
27cm/password-generator
|
src/Generator.php
|
Generator.generate
|
public function generate($lenght = 4, $separator = ' ')
{
$length = count($this->lists);
$words = [];
$randomArray = static::getRandomArray($lenght);
foreach ($randomArray as $index => $random) {
$list = $this->lists[$index % $length];
$words[] = $list->get($random);
}
return implode($separator, $words);
}
|
php
|
public function generate($lenght = 4, $separator = ' ')
{
$length = count($this->lists);
$words = [];
$randomArray = static::getRandomArray($lenght);
foreach ($randomArray as $index => $random) {
$list = $this->lists[$index % $length];
$words[] = $list->get($random);
}
return implode($separator, $words);
}
|
[
"public",
"function",
"generate",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"length",
"=",
"count",
"(",
"$",
"this",
"->",
"lists",
")",
";",
"$",
"words",
"=",
"[",
"]",
";",
"$",
"randomArray",
"=",
"static",
"::",
"getRandomArray",
"(",
"$",
"lenght",
")",
";",
"foreach",
"(",
"$",
"randomArray",
"as",
"$",
"index",
"=>",
"$",
"random",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"lists",
"[",
"$",
"index",
"%",
"$",
"length",
"]",
";",
"$",
"words",
"[",
"]",
"=",
"$",
"list",
"->",
"get",
"(",
"$",
"random",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"separator",
",",
"$",
"words",
")",
";",
"}"
] |
Generate password from word lists.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password.
|
[
"Generate",
"password",
"from",
"word",
"lists",
"."
] |
train
|
https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L41-L53
|
27cm/password-generator
|
src/Generator.php
|
Generator.generateRu
|
public static function generateRu($lenght = 4, $separator = ' ')
{
$list = new WordList\Ru();
return (new static($list))->generate($lenght, $separator);
}
|
php
|
public static function generateRu($lenght = 4, $separator = ' ')
{
$list = new WordList\Ru();
return (new static($list))->generate($lenght, $separator);
}
|
[
"public",
"static",
"function",
"generateRu",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"Ru",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
] |
Static function generates Russian phrase password.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password.
|
[
"Static",
"function",
"generates",
"Russian",
"phrase",
"password",
"."
] |
train
|
https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L63-L67
|
27cm/password-generator
|
src/Generator.php
|
Generator.generateEn
|
public static function generateEn($lenght = 4, $separator = ' ')
{
$list = new WordList\En();
return (new static($list))->generate($lenght, $separator);
}
|
php
|
public static function generateEn($lenght = 4, $separator = ' ')
{
$list = new WordList\En();
return (new static($list))->generate($lenght, $separator);
}
|
[
"public",
"static",
"function",
"generateEn",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"En",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
] |
Static function generates English phrase password.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password.
|
[
"Static",
"function",
"generates",
"English",
"phrase",
"password",
"."
] |
train
|
https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L77-L81
|
27cm/password-generator
|
src/Generator.php
|
Generator.generateDe
|
public static function generateDe($lenght = 4, $separator = ' ')
{
$list = new WordList\De();
return (new static($list))->generate($lenght, $separator);
}
|
php
|
public static function generateDe($lenght = 4, $separator = ' ')
{
$list = new WordList\De();
return (new static($list))->generate($lenght, $separator);
}
|
[
"public",
"static",
"function",
"generateDe",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"De",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
] |
Static function generates German phrase password.
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password.
|
[
"Static",
"function",
"generates",
"German",
"phrase",
"password",
"."
] |
train
|
https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L91-L95
|
27cm/password-generator
|
src/Generator.php
|
Generator.generateRuTranslit
|
public static function generateRuTranslit($lenght = 4, $separator = ' ')
{
$list = new WordList\RuTranslit();
return (new static($list))->generate($lenght, $separator);
}
|
php
|
public static function generateRuTranslit($lenght = 4, $separator = ' ')
{
$list = new WordList\RuTranslit();
return (new static($list))->generate($lenght, $separator);
}
|
[
"public",
"static",
"function",
"generateRuTranslit",
"(",
"$",
"lenght",
"=",
"4",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"$",
"list",
"=",
"new",
"WordList",
"\\",
"RuTranslit",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
"$",
"list",
")",
")",
"->",
"generate",
"(",
"$",
"lenght",
",",
"$",
"separator",
")",
";",
"}"
] |
Static function generates transliterated Russian phrase password
@param int $lenght Password length in words.
@param string $separator Word separator.
@return string Generated password.
|
[
"Static",
"function",
"generates",
"transliterated",
"Russian",
"phrase",
"password"
] |
train
|
https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L105-L109
|
27cm/password-generator
|
src/Generator.php
|
Generator.getRandomArray
|
protected static function getRandomArray($length)
{
$bytes = random_bytes($length * 2);
$result = [];
foreach (unpack('S*', $bytes) as $long) {
$result[] = $long / 0xFFFF;
}
return $result;
}
|
php
|
protected static function getRandomArray($length)
{
$bytes = random_bytes($length * 2);
$result = [];
foreach (unpack('S*', $bytes) as $long) {
$result[] = $long / 0xFFFF;
}
return $result;
}
|
[
"protected",
"static",
"function",
"getRandomArray",
"(",
"$",
"length",
")",
"{",
"$",
"bytes",
"=",
"random_bytes",
"(",
"$",
"length",
"*",
"2",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"unpack",
"(",
"'S*'",
",",
"$",
"bytes",
")",
"as",
"$",
"long",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"long",
"/",
"0xFFFF",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get array of random numbers between 0.0 - 1.0.
@param int $length Array length.
@return float[] Array of random values 0.0 - 1.0.
|
[
"Get",
"array",
"of",
"random",
"numbers",
"between",
"0",
".",
"0",
"-",
"1",
".",
"0",
"."
] |
train
|
https://github.com/27cm/password-generator/blob/c7f835f3bc302a91497bf5f659e404e750fb03bf/src/Generator.php#L118-L126
|
axelitus/php-base
|
src/Bool.php
|
Bool.extIs
|
public static function extIs($value)
{
if (static::is($value)) {
return true;
}
if (is_string($value)) {
// This function should be case insensitive so let's compare to the lower-cased input string.
$value = strtolower($value);
return (static::isTrueStrExt($value) || static::isFalseStrExt($value));
}
return false;
}
|
php
|
public static function extIs($value)
{
if (static::is($value)) {
return true;
}
if (is_string($value)) {
// This function should be case insensitive so let's compare to the lower-cased input string.
$value = strtolower($value);
return (static::isTrueStrExt($value) || static::isFalseStrExt($value));
}
return false;
}
|
[
"public",
"static",
"function",
"extIs",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"static",
"::",
"is",
"(",
"$",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"// This function should be case insensitive so let's compare to the lower-cased input string.",
"$",
"value",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"return",
"(",
"static",
"::",
"isTrueStrExt",
"(",
"$",
"value",
")",
"||",
"static",
"::",
"isFalseStrExt",
"(",
"$",
"value",
")",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Tests if the given value is a bool or not.
This function considers also the strings 'true', 'false', 'on', 'off', 'yes', 'no', 'y', 'n', '1', '0'
to be booleans. The function is NOT case sensitive.
@param mixed $value The value to test.
@return bool Returns true if the value is a bool or 0 or 1, false otherwise.
|
[
"Tests",
"if",
"the",
"given",
"value",
"is",
"a",
"bool",
"or",
"not",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Bool.php#L52-L65
|
axelitus/php-base
|
src/Bool.php
|
Bool.compare
|
public static function compare($bool1, $bool2)
{
if (!static::is($bool1) || !static::is($bool2)) {
throw new \InvalidArgumentException(
"The \$bool1 and \$bool2 parameters must be of type bool."
);
}
return ((int)$bool1 - (int)$bool2);
}
|
php
|
public static function compare($bool1, $bool2)
{
if (!static::is($bool1) || !static::is($bool2)) {
throw new \InvalidArgumentException(
"The \$bool1 and \$bool2 parameters must be of type bool."
);
}
return ((int)$bool1 - (int)$bool2);
}
|
[
"public",
"static",
"function",
"compare",
"(",
"$",
"bool1",
",",
"$",
"bool2",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"is",
"(",
"$",
"bool1",
")",
"||",
"!",
"static",
"::",
"is",
"(",
"$",
"bool2",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$bool1 and \\$bool2 parameters must be of type bool.\"",
")",
";",
"}",
"return",
"(",
"(",
"int",
")",
"$",
"bool1",
"-",
"(",
"int",
")",
"$",
"bool2",
")",
";",
"}"
] |
Compares two bool values.
The returning value contains the actual value difference.
@param bool $bool1 The left operand.
@param bool $bool2 The right operand.
@return int Returns -1 if $bool1=false and $bool2=true, =0 if $bool1 == $bool2, 1 if $bool1=true and $bool2=false
@throws \InvalidArgumentException
|
[
"Compares",
"two",
"bool",
"values",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Bool.php#L130-L139
|
axelitus/php-base
|
src/Bool.php
|
Bool.parse
|
public static function parse($input)
{
if (Str::isNotOrEmpty($input)) {
throw new \InvalidArgumentException("The \$input parameter must be a non-empty string.");
}
// This function is case insensitive so let's compare to the lower-cased input string.
$input = strtolower($input);
// Use true so that the expressions of the switch will evaluate to
// (true && (result of expression)) effectively entering the first
// case in which the expression evaluates to true.
switch (true) {
case static::isTrueStr($input):
$ret = true;
break;
case static::isFalseStr($input):
$ret = false;
break;
default:
throw new \RuntimeException(
"The \$input string cannot be parsed because it does not match 'true', 'false', '1' or '0'."
);
}
return $ret;
}
|
php
|
public static function parse($input)
{
if (Str::isNotOrEmpty($input)) {
throw new \InvalidArgumentException("The \$input parameter must be a non-empty string.");
}
// This function is case insensitive so let's compare to the lower-cased input string.
$input = strtolower($input);
// Use true so that the expressions of the switch will evaluate to
// (true && (result of expression)) effectively entering the first
// case in which the expression evaluates to true.
switch (true) {
case static::isTrueStr($input):
$ret = true;
break;
case static::isFalseStr($input):
$ret = false;
break;
default:
throw new \RuntimeException(
"The \$input string cannot be parsed because it does not match 'true', 'false', '1' or '0'."
);
}
return $ret;
}
|
[
"public",
"static",
"function",
"parse",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"Str",
"::",
"isNotOrEmpty",
"(",
"$",
"input",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$input parameter must be a non-empty string.\"",
")",
";",
"}",
"// This function is case insensitive so let's compare to the lower-cased input string.",
"$",
"input",
"=",
"strtolower",
"(",
"$",
"input",
")",
";",
"// Use true so that the expressions of the switch will evaluate to",
"// (true && (result of expression)) effectively entering the first",
"// case in which the expression evaluates to true.",
"switch",
"(",
"true",
")",
"{",
"case",
"static",
"::",
"isTrueStr",
"(",
"$",
"input",
")",
":",
"$",
"ret",
"=",
"true",
";",
"break",
";",
"case",
"static",
"::",
"isFalseStr",
"(",
"$",
"input",
")",
":",
"$",
"ret",
"=",
"false",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"The \\$input string cannot be parsed because it does not match 'true', 'false', '1' or '0'.\"",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Parses the input string into a bool.
The only strings that this function parses to boolean are 'true', 'false', '1' and '0'.
This function is NOT case sensitive.
@param string $input The string to be parsed.
@return bool The parsed bool.
@throws \RuntimeException
@throws \InvalidArgumentException
|
[
"Parses",
"the",
"input",
"string",
"into",
"a",
"bool",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Bool.php#L180-L206
|
axelitus/php-base
|
src/Bool.php
|
Bool.extParse
|
public static function extParse($input)
{
if (Str::isNotOrEmpty($input)) {
throw new \InvalidArgumentException("The \$input parameter must be a non-empty string.");
}
// This function is case insensitive so let's compare to the lower-cased input string.
$input = strtolower($input);
// Use true so that the expressions of the switch will evaluate to
// (true && (result of expression)) effectively entering the first
// case in which the expression evaluates to true.
switch (true) {
case static::isTrueStrExt($input):
$ret = true;
break;
case static::isFalseStrExt($input):
$ret = false;
break;
default:
throw new \RuntimeException(
"The \$input parameter did not match any of the valid strings that can be parsed."
);
}
return $ret;
}
|
php
|
public static function extParse($input)
{
if (Str::isNotOrEmpty($input)) {
throw new \InvalidArgumentException("The \$input parameter must be a non-empty string.");
}
// This function is case insensitive so let's compare to the lower-cased input string.
$input = strtolower($input);
// Use true so that the expressions of the switch will evaluate to
// (true && (result of expression)) effectively entering the first
// case in which the expression evaluates to true.
switch (true) {
case static::isTrueStrExt($input):
$ret = true;
break;
case static::isFalseStrExt($input):
$ret = false;
break;
default:
throw new \RuntimeException(
"The \$input parameter did not match any of the valid strings that can be parsed."
);
}
return $ret;
}
|
[
"public",
"static",
"function",
"extParse",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"Str",
"::",
"isNotOrEmpty",
"(",
"$",
"input",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$input parameter must be a non-empty string.\"",
")",
";",
"}",
"// This function is case insensitive so let's compare to the lower-cased input string.",
"$",
"input",
"=",
"strtolower",
"(",
"$",
"input",
")",
";",
"// Use true so that the expressions of the switch will evaluate to",
"// (true && (result of expression)) effectively entering the first",
"// case in which the expression evaluates to true.",
"switch",
"(",
"true",
")",
"{",
"case",
"static",
"::",
"isTrueStrExt",
"(",
"$",
"input",
")",
":",
"$",
"ret",
"=",
"true",
";",
"break",
";",
"case",
"static",
"::",
"isFalseStrExt",
"(",
"$",
"input",
")",
":",
"$",
"ret",
"=",
"false",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"The \\$input parameter did not match any of the valid strings that can be parsed.\"",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Parses the input string into a bool.
This function allows for an extended set of strings that are parsed as booleans:
'true', '1', 'on', 'yes', 'y', 'false', '0', 'off', 'no', 'n'.
This function is NOT case sensitive.
@param string $input The string to be parsed.
@return bool The parsed bool.
@throws \RuntimeException
@throws \InvalidArgumentException
|
[
"Parses",
"the",
"input",
"string",
"into",
"a",
"bool",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Bool.php#L221-L247
|
awethemes/wp-session
|
src/WP_Session_Handler.php
|
WP_Session_Handler.read
|
public function read( $session_id ) {
$session = get_option( $this->get_option_name( $session_id ), null );
if ( $this->expired( $session ) ) {
$this->exists = true;
return null;
}
if ( isset( $session['payload'] ) ) {
$this->exists = true;
return $session['payload'];
}
}
|
php
|
public function read( $session_id ) {
$session = get_option( $this->get_option_name( $session_id ), null );
if ( $this->expired( $session ) ) {
$this->exists = true;
return null;
}
if ( isset( $session['payload'] ) ) {
$this->exists = true;
return $session['payload'];
}
}
|
[
"public",
"function",
"read",
"(",
"$",
"session_id",
")",
"{",
"$",
"session",
"=",
"get_option",
"(",
"$",
"this",
"->",
"get_option_name",
"(",
"$",
"session_id",
")",
",",
"null",
")",
";",
"if",
"(",
"$",
"this",
"->",
"expired",
"(",
"$",
"session",
")",
")",
"{",
"$",
"this",
"->",
"exists",
"=",
"true",
";",
"return",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"session",
"[",
"'payload'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"exists",
"=",
"true",
";",
"return",
"$",
"session",
"[",
"'payload'",
"]",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/WP_Session_Handler.php#L55-L69
|
awethemes/wp-session
|
src/WP_Session_Handler.php
|
WP_Session_Handler.write
|
public function write( $session_id, $data ) {
$payload = [
'payload' => $data,
'last_activity' => time(),
];
// Try determines existence state of session ID.
if ( ! $this->exists ) {
$this->read( $session_id );
}
if ( $this->exists ) {
update_option( $this->get_option_name( $session_id ), $payload, false );
} else {
add_option( $this->get_option_name( $session_id ), $payload, '', 'no' );
}
return true;
}
|
php
|
public function write( $session_id, $data ) {
$payload = [
'payload' => $data,
'last_activity' => time(),
];
// Try determines existence state of session ID.
if ( ! $this->exists ) {
$this->read( $session_id );
}
if ( $this->exists ) {
update_option( $this->get_option_name( $session_id ), $payload, false );
} else {
add_option( $this->get_option_name( $session_id ), $payload, '', 'no' );
}
return true;
}
|
[
"public",
"function",
"write",
"(",
"$",
"session_id",
",",
"$",
"data",
")",
"{",
"$",
"payload",
"=",
"[",
"'payload'",
"=>",
"$",
"data",
",",
"'last_activity'",
"=>",
"time",
"(",
")",
",",
"]",
";",
"// Try determines existence state of session ID.",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
")",
"{",
"$",
"this",
"->",
"read",
"(",
"$",
"session_id",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"exists",
")",
"{",
"update_option",
"(",
"$",
"this",
"->",
"get_option_name",
"(",
"$",
"session_id",
")",
",",
"$",
"payload",
",",
"false",
")",
";",
"}",
"else",
"{",
"add_option",
"(",
"$",
"this",
"->",
"get_option_name",
"(",
"$",
"session_id",
")",
",",
"$",
"payload",
",",
"''",
",",
"'no'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/WP_Session_Handler.php#L74-L92
|
awethemes/wp-session
|
src/WP_Session_Handler.php
|
WP_Session_Handler.destroy
|
public function destroy( $session_id ) {
delete_option( $this->get_option_name( $session_id ) );
$this->exists = false;
return true;
}
|
php
|
public function destroy( $session_id ) {
delete_option( $this->get_option_name( $session_id ) );
$this->exists = false;
return true;
}
|
[
"public",
"function",
"destroy",
"(",
"$",
"session_id",
")",
"{",
"delete_option",
"(",
"$",
"this",
"->",
"get_option_name",
"(",
"$",
"session_id",
")",
")",
";",
"$",
"this",
"->",
"exists",
"=",
"false",
";",
"return",
"true",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/WP_Session_Handler.php#L97-L103
|
awethemes/wp-session
|
src/WP_Session_Handler.php
|
WP_Session_Handler.gc
|
public function gc( $lifetime ) {
global $wpdb;
$placeholder = $this->get_option_name( '' );
// @codingStandardsIgnoreLine
$sessions = $wpdb->get_results( "SELECT * FROM `$wpdb->options` WHERE `option_name` LIKE '{$placeholder}%' LIMIT 0, 10000", ARRAY_A );
if ( empty( $sessions ) ) {
return;
}
$expired = [];
$expired_time = time() - $lifetime;
foreach ( $sessions as $session ) {
$payload = maybe_unserialize( $session['option_value'] );
if ( ! isset( $payload['last_activity'] ) || $payload['last_activity'] <= $expired_time ) {
$expired[] = (int) $session['option_id'];
}
}
// Delete expired sessions.
if ( ! empty( $expired ) ) {
$placeholders = implode( ', ', $expired );
// @codingStandardsIgnoreLine
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_id` IN ($placeholders)" );
}
}
|
php
|
public function gc( $lifetime ) {
global $wpdb;
$placeholder = $this->get_option_name( '' );
// @codingStandardsIgnoreLine
$sessions = $wpdb->get_results( "SELECT * FROM `$wpdb->options` WHERE `option_name` LIKE '{$placeholder}%' LIMIT 0, 10000", ARRAY_A );
if ( empty( $sessions ) ) {
return;
}
$expired = [];
$expired_time = time() - $lifetime;
foreach ( $sessions as $session ) {
$payload = maybe_unserialize( $session['option_value'] );
if ( ! isset( $payload['last_activity'] ) || $payload['last_activity'] <= $expired_time ) {
$expired[] = (int) $session['option_id'];
}
}
// Delete expired sessions.
if ( ! empty( $expired ) ) {
$placeholders = implode( ', ', $expired );
// @codingStandardsIgnoreLine
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_id` IN ($placeholders)" );
}
}
|
[
"public",
"function",
"gc",
"(",
"$",
"lifetime",
")",
"{",
"global",
"$",
"wpdb",
";",
"$",
"placeholder",
"=",
"$",
"this",
"->",
"get_option_name",
"(",
"''",
")",
";",
"// @codingStandardsIgnoreLine",
"$",
"sessions",
"=",
"$",
"wpdb",
"->",
"get_results",
"(",
"\"SELECT * FROM `$wpdb->options` WHERE `option_name` LIKE '{$placeholder}%' LIMIT 0, 10000\"",
",",
"ARRAY_A",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sessions",
")",
")",
"{",
"return",
";",
"}",
"$",
"expired",
"=",
"[",
"]",
";",
"$",
"expired_time",
"=",
"time",
"(",
")",
"-",
"$",
"lifetime",
";",
"foreach",
"(",
"$",
"sessions",
"as",
"$",
"session",
")",
"{",
"$",
"payload",
"=",
"maybe_unserialize",
"(",
"$",
"session",
"[",
"'option_value'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"payload",
"[",
"'last_activity'",
"]",
")",
"||",
"$",
"payload",
"[",
"'last_activity'",
"]",
"<=",
"$",
"expired_time",
")",
"{",
"$",
"expired",
"[",
"]",
"=",
"(",
"int",
")",
"$",
"session",
"[",
"'option_id'",
"]",
";",
"}",
"}",
"// Delete expired sessions.",
"if",
"(",
"!",
"empty",
"(",
"$",
"expired",
")",
")",
"{",
"$",
"placeholders",
"=",
"implode",
"(",
"', '",
",",
"$",
"expired",
")",
";",
"// @codingStandardsIgnoreLine",
"$",
"wpdb",
"->",
"query",
"(",
"\"DELETE FROM `$wpdb->options` WHERE `option_id` IN ($placeholders)\"",
")",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/WP_Session_Handler.php#L108-L138
|
tonicospinelli/class-generation
|
src/ClassGeneration/PropertyCollection.php
|
PropertyCollection.add
|
public function add($property)
{
if (!$property instanceof PropertyInterface) {
throw new \InvalidArgumentException(
'This Property must be a instance of \ClassGeneration\PropertyInterface'
);
}
if ($property->getName() === null) {
$property->setName('property' . ($this->count() + 1));
}
parent::set($property->getName(), $property);
return true;
}
|
php
|
public function add($property)
{
if (!$property instanceof PropertyInterface) {
throw new \InvalidArgumentException(
'This Property must be a instance of \ClassGeneration\PropertyInterface'
);
}
if ($property->getName() === null) {
$property->setName('property' . ($this->count() + 1));
}
parent::set($property->getName(), $property);
return true;
}
|
[
"public",
"function",
"add",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"$",
"property",
"instanceof",
"PropertyInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'This Property must be a instance of \\ClassGeneration\\PropertyInterface'",
")",
";",
"}",
"if",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
"===",
"null",
")",
"{",
"$",
"property",
"->",
"setName",
"(",
"'property'",
".",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"1",
")",
")",
";",
"}",
"parent",
"::",
"set",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"property",
")",
";",
"return",
"true",
";",
"}"
] |
Adds a new Property on the collection.
@param PropertyInterface $property
@return bool
@throws \InvalidArgumentException
|
[
"Adds",
"a",
"new",
"Property",
"on",
"the",
"collection",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/PropertyCollection.php#L31-L45
|
tonicospinelli/class-generation
|
src/ClassGeneration/PropertyCollection.php
|
PropertyCollection.toString
|
public function toString()
{
$string = '';
$properties = $this->getIterator();
foreach ($properties as $property) {
$string .= $property->toString();
}
return $string;
}
|
php
|
public function toString()
{
$string = '';
$properties = $this->getIterator();
foreach ($properties as $property) {
$string .= $property->toString();
}
return $string;
}
|
[
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"properties",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"$",
"string",
".=",
"$",
"property",
"->",
"toString",
"(",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] |
Parse the Property Collection to string.
@return string
|
[
"Parse",
"the",
"Property",
"Collection",
"to",
"string",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/PropertyCollection.php#L69-L78
|
tonicospinelli/class-generation
|
src/ClassGeneration/PropertyCollection.php
|
PropertyCollection.getByName
|
public function getByName($propertyName)
{
$foundList = new self();
$list = $this->getIterator();
foreach ($list as $property) {
if ((is_array($propertyName) && in_array($property->getName(), $propertyName))
|| ($property->getName() === $propertyName)
) {
$foundList->add($property);
}
}
return $foundList;
}
|
php
|
public function getByName($propertyName)
{
$foundList = new self();
$list = $this->getIterator();
foreach ($list as $property) {
if ((is_array($propertyName) && in_array($property->getName(), $propertyName))
|| ($property->getName() === $propertyName)
) {
$foundList->add($property);
}
}
return $foundList;
}
|
[
"public",
"function",
"getByName",
"(",
"$",
"propertyName",
")",
"{",
"$",
"foundList",
"=",
"new",
"self",
"(",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"propertyName",
")",
"&&",
"in_array",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"propertyName",
")",
")",
"||",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
"===",
"$",
"propertyName",
")",
")",
"{",
"$",
"foundList",
"->",
"add",
"(",
"$",
"property",
")",
";",
"}",
"}",
"return",
"$",
"foundList",
";",
"}"
] |
Find the properties by name.
@param string $propertyName
@return PropertyCollection
|
[
"Find",
"the",
"properties",
"by",
"name",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/PropertyCollection.php#L87-L100
|
tonicospinelli/class-generation
|
src/ClassGeneration/PropertyCollection.php
|
PropertyCollection.removeByName
|
public function removeByName($propertyName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $property) {
if ((is_array($propertyName) && in_array($property->getName(), $propertyName))
|| ($property->getName() === $propertyName)
) {
$removedList->add(clone $property);
$this->remove($index);
}
}
return $removedList;
}
|
php
|
public function removeByName($propertyName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $property) {
if ((is_array($propertyName) && in_array($property->getName(), $propertyName))
|| ($property->getName() === $propertyName)
) {
$removedList->add(clone $property);
$this->remove($index);
}
}
return $removedList;
}
|
[
"public",
"function",
"removeByName",
"(",
"$",
"propertyName",
")",
"{",
"$",
"removedList",
"=",
"new",
"self",
"(",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"index",
"=>",
"$",
"property",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"propertyName",
")",
"&&",
"in_array",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"propertyName",
")",
")",
"||",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
"===",
"$",
"propertyName",
")",
")",
"{",
"$",
"removedList",
"->",
"add",
"(",
"clone",
"$",
"property",
")",
";",
"$",
"this",
"->",
"remove",
"(",
"$",
"index",
")",
";",
"}",
"}",
"return",
"$",
"removedList",
";",
"}"
] |
Removes tags by name.
@param string $propertyName
@return PropertyCollection
|
[
"Removes",
"tags",
"by",
"name",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/PropertyCollection.php#L109-L123
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.