repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
theopera/framework | src/Component/WebApplication/Controller.php | Controller.addGlobal | protected function addGlobal(string $key, $value)
{
$template = $this->getContext()->getTemplateEngine();
$template->addGlobal($key, $value);
} | php | protected function addGlobal(string $key, $value)
{
$template = $this->getContext()->getTemplateEngine();
$template->addGlobal($key, $value);
} | [
"protected",
"function",
"addGlobal",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
"->",
"getTemplateEngine",
"(",
")",
";",
"$",
"template",
"->",
"addGlobal",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Add a variable that will be globally accessible in the template
@param string $key
@param $value | [
"Add",
"a",
"variable",
"that",
"will",
"be",
"globally",
"accessible",
"in",
"the",
"template"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/Controller.php#L76-L80 | train |
theopera/framework | src/Component/WebApplication/Controller.php | Controller.getTemplateFile | protected function getTemplateFile(string $action = null) : string
{
$path = '/controller/' . lcfirst($this->getControllerName()) . '/';
return $path . ($action ? $action : $this->getActionName());
} | php | protected function getTemplateFile(string $action = null) : string
{
$path = '/controller/' . lcfirst($this->getControllerName()) . '/';
return $path . ($action ? $action : $this->getActionName());
} | [
"protected",
"function",
"getTemplateFile",
"(",
"string",
"$",
"action",
"=",
"null",
")",
":",
"string",
"{",
"$",
"path",
"=",
"'/controller/'",
".",
"lcfirst",
"(",
"$",
"this",
"->",
"getControllerName",
"(",
")",
")",
".",
"'/'",
";",
"return",
"$",
"path",
".",
"(",
"$",
"action",
"?",
"$",
"action",
":",
"$",
"this",
"->",
"getActionName",
"(",
")",
")",
";",
"}"
] | Returns the default template file
@param string $action The action name, leave null for current action name
@return string | [
"Returns",
"the",
"default",
"template",
"file"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/Controller.php#L121-L126 | train |
theopera/framework | src/Component/WebApplication/Controller.php | Controller.isAjax | protected function isAjax() : bool
{
$header = $this->request->getHeaders()->get('X-Requested-With');
if ($header === null) {
return false;
}
return $header->getValue() === 'XMLHttpRequest';
} | php | protected function isAjax() : bool
{
$header = $this->request->getHeaders()->get('X-Requested-With');
if ($header === null) {
return false;
}
return $header->getValue() === 'XMLHttpRequest';
} | [
"protected",
"function",
"isAjax",
"(",
")",
":",
"bool",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"request",
"->",
"getHeaders",
"(",
")",
"->",
"get",
"(",
"'X-Requested-With'",
")",
";",
"if",
"(",
"$",
"header",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"header",
"->",
"getValue",
"(",
")",
"===",
"'XMLHttpRequest'",
";",
"}"
] | Is the current request done with ajax?
@return bool | [
"Is",
"the",
"current",
"request",
"done",
"with",
"ajax?"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/Controller.php#L216-L225 | train |
theopera/framework | src/Component/WebApplication/Controller.php | Controller.redirect | protected function redirect($controller = null, $action = 'index', array $parameters = []) : Response
{
$host = 'http://'. $_SERVER['HTTP_HOST'];
if ($controller === null) {
// Apparently we want to redirect to homepage, so the host will be sufficient
if ($action === 'index') {
return $this->redirectUrl($host);
}
$controller = $this->getControllerName();
}
if ($action === 'index') {
$action = '';
}else{
$action = '/' . $action;
}
return $this->redirectUrl(sprintf('%s/%s%s', $host, lcfirst($controller), $action), $parameters);
} | php | protected function redirect($controller = null, $action = 'index', array $parameters = []) : Response
{
$host = 'http://'. $_SERVER['HTTP_HOST'];
if ($controller === null) {
// Apparently we want to redirect to homepage, so the host will be sufficient
if ($action === 'index') {
return $this->redirectUrl($host);
}
$controller = $this->getControllerName();
}
if ($action === 'index') {
$action = '';
}else{
$action = '/' . $action;
}
return $this->redirectUrl(sprintf('%s/%s%s', $host, lcfirst($controller), $action), $parameters);
} | [
"protected",
"function",
"redirect",
"(",
"$",
"controller",
"=",
"null",
",",
"$",
"action",
"=",
"'index'",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
":",
"Response",
"{",
"$",
"host",
"=",
"'http://'",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
";",
"if",
"(",
"$",
"controller",
"===",
"null",
")",
"{",
"// Apparently we want to redirect to homepage, so the host will be sufficient",
"if",
"(",
"$",
"action",
"===",
"'index'",
")",
"{",
"return",
"$",
"this",
"->",
"redirectUrl",
"(",
"$",
"host",
")",
";",
"}",
"$",
"controller",
"=",
"$",
"this",
"->",
"getControllerName",
"(",
")",
";",
"}",
"if",
"(",
"$",
"action",
"===",
"'index'",
")",
"{",
"$",
"action",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"action",
"=",
"'/'",
".",
"$",
"action",
";",
"}",
"return",
"$",
"this",
"->",
"redirectUrl",
"(",
"sprintf",
"(",
"'%s/%s%s'",
",",
"$",
"host",
",",
"lcfirst",
"(",
"$",
"controller",
")",
",",
"$",
"action",
")",
",",
"$",
"parameters",
")",
";",
"}"
] | Redirect to a controller
@param string $controller
@param string $action
@param string[] $parameters
@return Response | [
"Redirect",
"to",
"a",
"controller"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/Controller.php#L236-L257 | train |
theopera/framework | src/Component/WebApplication/Controller.php | Controller.hasPermission | protected function hasPermission(string $permission, bool $return = false)
{
$auth = $this->getContext()->getAuthentication();
$user = $auth->getUser();
$acl = $this->getContext()->getAccessControlList();
if (!$acl->hasAccess($user, $permission)) {
if ($return) {
return false;
}else{
throw HttpException::forbidden('The current user has no permission to this action');
}
}
return true;
} | php | protected function hasPermission(string $permission, bool $return = false)
{
$auth = $this->getContext()->getAuthentication();
$user = $auth->getUser();
$acl = $this->getContext()->getAccessControlList();
if (!$acl->hasAccess($user, $permission)) {
if ($return) {
return false;
}else{
throw HttpException::forbidden('The current user has no permission to this action');
}
}
return true;
} | [
"protected",
"function",
"hasPermission",
"(",
"string",
"$",
"permission",
",",
"bool",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"auth",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
"->",
"getAuthentication",
"(",
")",
";",
"$",
"user",
"=",
"$",
"auth",
"->",
"getUser",
"(",
")",
";",
"$",
"acl",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
"->",
"getAccessControlList",
"(",
")",
";",
"if",
"(",
"!",
"$",
"acl",
"->",
"hasAccess",
"(",
"$",
"user",
",",
"$",
"permission",
")",
")",
"{",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"HttpException",
"::",
"forbidden",
"(",
"'The current user has no permission to this action'",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Has the current user permission for the given action
@param string $permission
@param bool $return Return a boolean instead of throwing a forbidden exception | [
"Has",
"the",
"current",
"user",
"permission",
"for",
"the",
"given",
"action"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/Controller.php#L298-L314 | train |
Nekland/BaseApi | lib/Nekland/BaseApi/Http/HttpClientFactory.php | HttpClientFactory.createHttpClient | public function createHttpClient($name = '', $client = null)
{
if (empty($name)) {
return $this->createBestClient();
}
if (!isset($this->classes[$name])) {
throw new \InvalidArgumentException(sprintf('The client "%s" is not registered.', $name));
}
$class = $this->classes[$name]['class'];
$client = new $class($this->dispatcher, $this->options, $client);
if ($client instanceof AbstractHttpClient) {
return $client;
}
throw new \InvalidArgumentException('The client must be an implementation of ClientInterface.');
} | php | public function createHttpClient($name = '', $client = null)
{
if (empty($name)) {
return $this->createBestClient();
}
if (!isset($this->classes[$name])) {
throw new \InvalidArgumentException(sprintf('The client "%s" is not registered.', $name));
}
$class = $this->classes[$name]['class'];
$client = new $class($this->dispatcher, $this->options, $client);
if ($client instanceof AbstractHttpClient) {
return $client;
}
throw new \InvalidArgumentException('The client must be an implementation of ClientInterface.');
} | [
"public",
"function",
"createHttpClient",
"(",
"$",
"name",
"=",
"''",
",",
"$",
"client",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createBestClient",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"classes",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The client \"%s\" is not registered.'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"classes",
"[",
"$",
"name",
"]",
"[",
"'class'",
"]",
";",
"$",
"client",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"dispatcher",
",",
"$",
"this",
"->",
"options",
",",
"$",
"client",
")",
";",
"if",
"(",
"$",
"client",
"instanceof",
"AbstractHttpClient",
")",
"{",
"return",
"$",
"client",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The client must be an implementation of ClientInterface.'",
")",
";",
"}"
] | Generate the best http client according to the detected configuration
@param string $name
@param null $client
@return GuzzleAdapter|AbstractHttpClient
@throws \InvalidArgumentException | [
"Generate",
"the",
"best",
"http",
"client",
"according",
"to",
"the",
"detected",
"configuration"
] | c96051b36d6982abf2a8b1f1ec16351bcae2455e | https://github.com/Nekland/BaseApi/blob/c96051b36d6982abf2a8b1f1ec16351bcae2455e/lib/Nekland/BaseApi/Http/HttpClientFactory.php#L55-L73 | train |
Nekland/BaseApi | lib/Nekland/BaseApi/Http/HttpClientFactory.php | HttpClientFactory.register | public function register($name, $class, $requirement = '', $priority = false)
{
if (!class_exists($class)) {
throw new \InvalidArgumentException(sprintf('%s is not a valid class name.', $class));
}
$definition = [
'class' => $class,
'requirement' => $requirement
];
if ($priority) {
$this->classes = array_merge_recursive([$name => $definition], $this->classes);
} else {
$this->classes[$name] = $definition;
}
} | php | public function register($name, $class, $requirement = '', $priority = false)
{
if (!class_exists($class)) {
throw new \InvalidArgumentException(sprintf('%s is not a valid class name.', $class));
}
$definition = [
'class' => $class,
'requirement' => $requirement
];
if ($priority) {
$this->classes = array_merge_recursive([$name => $definition], $this->classes);
} else {
$this->classes[$name] = $definition;
}
} | [
"public",
"function",
"register",
"(",
"$",
"name",
",",
"$",
"class",
",",
"$",
"requirement",
"=",
"''",
",",
"$",
"priority",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s is not a valid class name.'",
",",
"$",
"class",
")",
")",
";",
"}",
"$",
"definition",
"=",
"[",
"'class'",
"=>",
"$",
"class",
",",
"'requirement'",
"=>",
"$",
"requirement",
"]",
";",
"if",
"(",
"$",
"priority",
")",
"{",
"$",
"this",
"->",
"classes",
"=",
"array_merge_recursive",
"(",
"[",
"$",
"name",
"=>",
"$",
"definition",
"]",
",",
"$",
"this",
"->",
"classes",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"classes",
"[",
"$",
"name",
"]",
"=",
"$",
"definition",
";",
"}",
"}"
] | Register a new client that will be able to be use by the ApiFactory
@param string $name
@param string $class
@param string|callable $requirement
@param bool $priority
@throws \InvalidArgumentException | [
"Register",
"a",
"new",
"client",
"that",
"will",
"be",
"able",
"to",
"be",
"use",
"by",
"the",
"ApiFactory"
] | c96051b36d6982abf2a8b1f1ec16351bcae2455e | https://github.com/Nekland/BaseApi/blob/c96051b36d6982abf2a8b1f1ec16351bcae2455e/lib/Nekland/BaseApi/Http/HttpClientFactory.php#L110-L126 | train |
theopera/framework | src/Component/Database/Connection.php | Connection.connect | private function connect(Credentials $credentials) : PDO
{
if ($this->pdo === null) {
$this->pdo = new PDO($credentials->getDSN(), $credentials->getUsername(), $credentials->getPassword());
}
return $this->pdo;
} | php | private function connect(Credentials $credentials) : PDO
{
if ($this->pdo === null) {
$this->pdo = new PDO($credentials->getDSN(), $credentials->getUsername(), $credentials->getPassword());
}
return $this->pdo;
} | [
"private",
"function",
"connect",
"(",
"Credentials",
"$",
"credentials",
")",
":",
"PDO",
"{",
"if",
"(",
"$",
"this",
"->",
"pdo",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"pdo",
"=",
"new",
"PDO",
"(",
"$",
"credentials",
"->",
"getDSN",
"(",
")",
",",
"$",
"credentials",
"->",
"getUsername",
"(",
")",
",",
"$",
"credentials",
"->",
"getPassword",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pdo",
";",
"}"
] | Makes the actual connection to the database
@param Credentials $credentials
@return PDO | [
"Makes",
"the",
"actual",
"connection",
"to",
"the",
"database"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Database/Connection.php#L59-L66 | train |
aztech-digital/phinject | src/Config/TemplatedConfigProcessor.php | TemplatedConfigProcessor.process | public static function process(ArrayResolver $config)
{
$copy = $config->extract();
$instances = $config->resolveArray('apply-templates', []);
foreach ($instances as $name => $instance) {
self::processTemplate($config, $copy, $name, $instance);
}
return new ArrayResolver($copy);
} | php | public static function process(ArrayResolver $config)
{
$copy = $config->extract();
$instances = $config->resolveArray('apply-templates', []);
foreach ($instances as $name => $instance) {
self::processTemplate($config, $copy, $name, $instance);
}
return new ArrayResolver($copy);
} | [
"public",
"static",
"function",
"process",
"(",
"ArrayResolver",
"$",
"config",
")",
"{",
"$",
"copy",
"=",
"$",
"config",
"->",
"extract",
"(",
")",
";",
"$",
"instances",
"=",
"$",
"config",
"->",
"resolveArray",
"(",
"'apply-templates'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"instances",
"as",
"$",
"name",
"=>",
"$",
"instance",
")",
"{",
"self",
"::",
"processTemplate",
"(",
"$",
"config",
",",
"$",
"copy",
",",
"$",
"name",
",",
"$",
"instance",
")",
";",
"}",
"return",
"new",
"ArrayResolver",
"(",
"$",
"copy",
")",
";",
"}"
] | Processes a configuration node to expand the templates it contains.
@param ArrayResolver $config The node containing the configuration templates and templated instances.
@return ArrayResolver An array resolver containing the expanded templates. | [
"Processes",
"a",
"configuration",
"node",
"to",
"expand",
"the",
"templates",
"it",
"contains",
"."
] | 1bb2fb3b5ef44e62f168af71134c613c48b58d95 | https://github.com/aztech-digital/phinject/blob/1bb2fb3b5ef44e62f168af71134c613c48b58d95/src/Config/TemplatedConfigProcessor.php#L16-L26 | train |
t-kanstantsin/fileupload | src/formatter/icon/IconGenerator.php | IconGenerator.getIcon | public function getIcon(?string $extension): ?string
{
$iconClass = $this->iconSet[$this->getIconType($extension)] ?? null;
return $iconClass !== null
? $this->iconPrefix . ' ' . $iconClass
: null;
} | php | public function getIcon(?string $extension): ?string
{
$iconClass = $this->iconSet[$this->getIconType($extension)] ?? null;
return $iconClass !== null
? $this->iconPrefix . ' ' . $iconClass
: null;
} | [
"public",
"function",
"getIcon",
"(",
"?",
"string",
"$",
"extension",
")",
":",
"?",
"string",
"{",
"$",
"iconClass",
"=",
"$",
"this",
"->",
"iconSet",
"[",
"$",
"this",
"->",
"getIconType",
"(",
"$",
"extension",
")",
"]",
"??",
"null",
";",
"return",
"$",
"iconClass",
"!==",
"null",
"?",
"$",
"this",
"->",
"iconPrefix",
".",
"' '",
".",
"$",
"iconClass",
":",
"null",
";",
"}"
] | Returns suitable css class for icon by extension.
@param null|string $extension
@return string returns default icon if nothing found | [
"Returns",
"suitable",
"css",
"class",
"for",
"icon",
"by",
"extension",
"."
] | d6317a9b9b36d992f09affe3900ef7d7ddfd855f | https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/formatter/icon/IconGenerator.php#L90-L97 | train |
t-kanstantsin/fileupload | src/formatter/icon/IconGenerator.php | IconGenerator.getIconType | public function getIconType(?string $extension): string
{
if ($extension !== null && $extension !== '') {
foreach (self::TYPE_TO_REGEX as $type => $regex) {
if ($regex === null) {
continue;
}
if (($regex === $extension && preg_match('/[a-z0-9]+/', $extension))
|| preg_match("/$regex/", $extension)
) {
return $type;
}
}
}
return self::ICON_DEFAULT;
} | php | public function getIconType(?string $extension): string
{
if ($extension !== null && $extension !== '') {
foreach (self::TYPE_TO_REGEX as $type => $regex) {
if ($regex === null) {
continue;
}
if (($regex === $extension && preg_match('/[a-z0-9]+/', $extension))
|| preg_match("/$regex/", $extension)
) {
return $type;
}
}
}
return self::ICON_DEFAULT;
} | [
"public",
"function",
"getIconType",
"(",
"?",
"string",
"$",
"extension",
")",
":",
"string",
"{",
"if",
"(",
"$",
"extension",
"!==",
"null",
"&&",
"$",
"extension",
"!==",
"''",
")",
"{",
"foreach",
"(",
"self",
"::",
"TYPE_TO_REGEX",
"as",
"$",
"type",
"=>",
"$",
"regex",
")",
"{",
"if",
"(",
"$",
"regex",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"(",
"$",
"regex",
"===",
"$",
"extension",
"&&",
"preg_match",
"(",
"'/[a-z0-9]+/'",
",",
"$",
"extension",
")",
")",
"||",
"preg_match",
"(",
"\"/$regex/\"",
",",
"$",
"extension",
")",
")",
"{",
"return",
"$",
"type",
";",
"}",
"}",
"}",
"return",
"self",
"::",
"ICON_DEFAULT",
";",
"}"
] | Searches icon type by it's extension
@param null|string $extension
@return string | [
"Searches",
"icon",
"type",
"by",
"it",
"s",
"extension"
] | d6317a9b9b36d992f09affe3900ef7d7ddfd855f | https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/formatter/icon/IconGenerator.php#L104-L120 | train |
jenskooij/cloudcontrol | src/storage/factories/RedirectsFactory.php | RedirectsFactory.createRedirectFromPostValues | public static function createRedirectFromPostValues($postValues)
{
if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) {
$redirectObject = new \stdClass();
$redirectObject->title = $postValues['title'];
$redirectObject->slug = StringUtil::slugify($postValues['title']);
$redirectObject->fromUrl = $postValues['fromUrl'];
$redirectObject->toUrl = $postValues['toUrl'];
$redirectObject->type = $postValues['type'];
return $redirectObject;
} else {
throw new \Exception('Trying to create valuelist with invalid data.');
}
} | php | public static function createRedirectFromPostValues($postValues)
{
if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) {
$redirectObject = new \stdClass();
$redirectObject->title = $postValues['title'];
$redirectObject->slug = StringUtil::slugify($postValues['title']);
$redirectObject->fromUrl = $postValues['fromUrl'];
$redirectObject->toUrl = $postValues['toUrl'];
$redirectObject->type = $postValues['type'];
return $redirectObject;
} else {
throw new \Exception('Trying to create valuelist with invalid data.');
}
} | [
"public",
"static",
"function",
"createRedirectFromPostValues",
"(",
"$",
"postValues",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"postValues",
"[",
"'title'",
"]",
",",
"$",
"postValues",
"[",
"'fromUrl'",
"]",
",",
"$",
"postValues",
"[",
"'toUrl'",
"]",
")",
")",
"{",
"$",
"redirectObject",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"redirectObject",
"->",
"title",
"=",
"$",
"postValues",
"[",
"'title'",
"]",
";",
"$",
"redirectObject",
"->",
"slug",
"=",
"StringUtil",
"::",
"slugify",
"(",
"$",
"postValues",
"[",
"'title'",
"]",
")",
";",
"$",
"redirectObject",
"->",
"fromUrl",
"=",
"$",
"postValues",
"[",
"'fromUrl'",
"]",
";",
"$",
"redirectObject",
"->",
"toUrl",
"=",
"$",
"postValues",
"[",
"'toUrl'",
"]",
";",
"$",
"redirectObject",
"->",
"type",
"=",
"$",
"postValues",
"[",
"'type'",
"]",
";",
"return",
"$",
"redirectObject",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Trying to create valuelist with invalid data.'",
")",
";",
"}",
"}"
] | Create a new redirect object from postvalues
@param $postValues
@return \stdClass
@throws \Exception | [
"Create",
"a",
"new",
"redirect",
"object",
"from",
"postvalues"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/factories/RedirectsFactory.php#L20-L34 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.clear | public function clear()
{
$lastQuery = $this->query;
$this->query = new Query($this->error, $lastQuery->getInitializer());
$this->query->forceLimit($lastQuery->getLimit());
$this->query->forceOffset($lastQuery->getOffset());
if (!is_array($lastQuery->getResultDataType())) {
$this->query->setResultDataType($lastQuery->getResultDataType());
}
return $this;
} | php | public function clear()
{
$lastQuery = $this->query;
$this->query = new Query($this->error, $lastQuery->getInitializer());
$this->query->forceLimit($lastQuery->getLimit());
$this->query->forceOffset($lastQuery->getOffset());
if (!is_array($lastQuery->getResultDataType())) {
$this->query->setResultDataType($lastQuery->getResultDataType());
}
return $this;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"lastQuery",
"=",
"$",
"this",
"->",
"query",
";",
"$",
"this",
"->",
"query",
"=",
"new",
"Query",
"(",
"$",
"this",
"->",
"error",
",",
"$",
"lastQuery",
"->",
"getInitializer",
"(",
")",
")",
";",
"$",
"this",
"->",
"query",
"->",
"forceLimit",
"(",
"$",
"lastQuery",
"->",
"getLimit",
"(",
")",
")",
";",
"$",
"this",
"->",
"query",
"->",
"forceOffset",
"(",
"$",
"lastQuery",
"->",
"getOffset",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"lastQuery",
"->",
"getResultDataType",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"setResultDataType",
"(",
"$",
"lastQuery",
"->",
"getResultDataType",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Clear and reset persistence query.
@return self | [
"Clear",
"and",
"reset",
"persistence",
"query",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L135-L147 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.setSingleQuery | public function setSingleQuery($query)
{
if ($this->executed) {
$this->clear();
}
$this->query->single()->setQuery($query);
return $this;
} | php | public function setSingleQuery($query)
{
if ($this->executed) {
$this->clear();
}
$this->query->single()->setQuery($query);
return $this;
} | [
"public",
"function",
"setSingleQuery",
"(",
"$",
"query",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"executed",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"$",
"this",
"->",
"query",
"->",
"single",
"(",
")",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set Query to single statement executable.
@param string $query | [
"Set",
"Query",
"to",
"single",
"statement",
"executable",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L154-L162 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.setQuery | public function setQuery($queries)
{
if ($this->executed) {
$this->clear();
}
$this->query->multiple()->setQuery($queries);
return $this;
} | php | public function setQuery($queries)
{
if ($this->executed) {
$this->clear();
}
$this->query->multiple()->setQuery($queries);
return $this;
} | [
"public",
"function",
"setQuery",
"(",
"$",
"queries",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"executed",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"$",
"this",
"->",
"query",
"->",
"multiple",
"(",
")",
"->",
"setQuery",
"(",
"$",
"queries",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set Query to multiple statement
on next call this method will attach or append new query.
@param string $queries | [
"Set",
"Query",
"to",
"multiple",
"statement",
"on",
"next",
"call",
"this",
"method",
"will",
"attach",
"or",
"append",
"new",
"query",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L170-L178 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.getAvailableDrivers | public function getAvailableDrivers()
{
$config = $this->client ? $this->client : $this->config;
return $config->getAvailableDrivers();
} | php | public function getAvailableDrivers()
{
$config = $this->client ? $this->client : $this->config;
return $config->getAvailableDrivers();
} | [
"public",
"function",
"getAvailableDrivers",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"client",
"?",
"$",
"this",
"->",
"client",
":",
"$",
"this",
"->",
"config",
";",
"return",
"$",
"config",
"->",
"getAvailableDrivers",
"(",
")",
";",
"}"
] | Get list of available drivers.
@return array | [
"Get",
"list",
"of",
"available",
"drivers",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L218-L223 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.getServerVersion | public function getServerVersion()
{
if ($this->client) {
return $this->client->getServerVersion();
}
$connection = new Connection($this->config);
return $connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
} | php | public function getServerVersion()
{
if ($this->client) {
return $this->client->getServerVersion();
}
$connection = new Connection($this->config);
return $connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
} | [
"public",
"function",
"getServerVersion",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"client",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"getServerVersion",
"(",
")",
";",
"}",
"$",
"connection",
"=",
"new",
"Connection",
"(",
"$",
"this",
"->",
"config",
")",
";",
"return",
"$",
"connection",
"->",
"getAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_SERVER_VERSION",
")",
";",
"}"
] | Get current version of database platform.
@return string|int|null | [
"Get",
"current",
"version",
"of",
"database",
"platform",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L230-L239 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.run | public function run()
{
$this->executed = true;
if ($this->client instanceof ClientInterface) {
$this->client->sendRequest();
} else {
$connection = new Connection($this->config);
$executor = new Executor($connection);
$executor->execQuery($this->query);
}
return $this->hasError();
} | php | public function run()
{
$this->executed = true;
if ($this->client instanceof ClientInterface) {
$this->client->sendRequest();
} else {
$connection = new Connection($this->config);
$executor = new Executor($connection);
$executor->execQuery($this->query);
}
return $this->hasError();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"this",
"->",
"executed",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"client",
"instanceof",
"ClientInterface",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"sendRequest",
"(",
")",
";",
"}",
"else",
"{",
"$",
"connection",
"=",
"new",
"Connection",
"(",
"$",
"this",
"->",
"config",
")",
";",
"$",
"executor",
"=",
"new",
"Executor",
"(",
"$",
"connection",
")",
";",
"$",
"executor",
"->",
"execQuery",
"(",
"$",
"this",
"->",
"query",
")",
";",
"}",
"return",
"$",
"this",
"->",
"hasError",
"(",
")",
";",
"}"
] | Run and execute prepared sql queries.
@return bool Error status | [
"Run",
"and",
"execute",
"prepared",
"sql",
"queries",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L256-L269 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.getResult | public function getResult($resultMode = 0)
{
switch ($resultMode) {
case self::FETCH_ARRAY:
return $this->query->toArray();
break;
case self::FETCH_JSON:
$result = json_encode($this->query->toArray());
return $result;
break;
case self::FETCH_JSON_BEAUTIFY:
$result = json_encode($this->query->toArray(), JSON_PRETTY_PRINT);
return $result;
break;
case self::FETCH_OBJECT:
$result = json_encode($this->query->toArray());
return json_decode($result);
break;
default:
return $this->query;
break;
}
} | php | public function getResult($resultMode = 0)
{
switch ($resultMode) {
case self::FETCH_ARRAY:
return $this->query->toArray();
break;
case self::FETCH_JSON:
$result = json_encode($this->query->toArray());
return $result;
break;
case self::FETCH_JSON_BEAUTIFY:
$result = json_encode($this->query->toArray(), JSON_PRETTY_PRINT);
return $result;
break;
case self::FETCH_OBJECT:
$result = json_encode($this->query->toArray());
return json_decode($result);
break;
default:
return $this->query;
break;
}
} | [
"public",
"function",
"getResult",
"(",
"$",
"resultMode",
"=",
"0",
")",
"{",
"switch",
"(",
"$",
"resultMode",
")",
"{",
"case",
"self",
"::",
"FETCH_ARRAY",
":",
"return",
"$",
"this",
"->",
"query",
"->",
"toArray",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"FETCH_JSON",
":",
"$",
"result",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"query",
"->",
"toArray",
"(",
")",
")",
";",
"return",
"$",
"result",
";",
"break",
";",
"case",
"self",
"::",
"FETCH_JSON_BEAUTIFY",
":",
"$",
"result",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"query",
"->",
"toArray",
"(",
")",
",",
"JSON_PRETTY_PRINT",
")",
";",
"return",
"$",
"result",
";",
"break",
";",
"case",
"self",
"::",
"FETCH_OBJECT",
":",
"$",
"result",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"query",
"->",
"toArray",
"(",
")",
")",
";",
"return",
"json_decode",
"(",
"$",
"result",
")",
";",
"break",
";",
"default",
":",
"return",
"$",
"this",
"->",
"query",
";",
"break",
";",
"}",
"}"
] | Get Result.
@param int $resultMode Result Mode DBInstance::FETCH_*
@return mixed | [
"Get",
"Result",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L288-L313 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/DBInstance.php | DBInstance.createService | public static function createService($serviceName)
{
switch ($serviceName) {
case self::SERVICE_REST:
return new RestService();
break;
case self::SERVICE_SOAP:
return new SoapService();
break;
case self::SERVICE_XMLRPC:
return new XmlRpcService();
break;
}
throw new \Exception(sprintf('Unknown service %s', $serviceName));
} | php | public static function createService($serviceName)
{
switch ($serviceName) {
case self::SERVICE_REST:
return new RestService();
break;
case self::SERVICE_SOAP:
return new SoapService();
break;
case self::SERVICE_XMLRPC:
return new XmlRpcService();
break;
}
throw new \Exception(sprintf('Unknown service %s', $serviceName));
} | [
"public",
"static",
"function",
"createService",
"(",
"$",
"serviceName",
")",
"{",
"switch",
"(",
"$",
"serviceName",
")",
"{",
"case",
"self",
"::",
"SERVICE_REST",
":",
"return",
"new",
"RestService",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"SERVICE_SOAP",
":",
"return",
"new",
"SoapService",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"SERVICE_XMLRPC",
":",
"return",
"new",
"XmlRpcService",
"(",
")",
";",
"break",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Unknown service %s'",
",",
"$",
"serviceName",
")",
")",
";",
"}"
] | Create Service.
@param int $serviceName Service Type DBInstance::SERVICE_*
@return \Realboard\Component\Database\DBInstance\DBInterface\ServiceInterface | [
"Create",
"Service",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/DBInstance.php#L322-L337 | train |
juliangut/mapping | src/Driver/AbstractAnnotationDriver.php | AbstractAnnotationDriver.getMappingClasses | protected function getMappingClasses(): array
{
AnnotationRegistry::registerLoader('class_exists');
$mappingClasses = [];
foreach ($this->locator->getMappingFiles() as $annotationFile) {
$mappingClasses[] = $this->loadClassFromFile($annotationFile);
}
return \array_map(
function (string $sourceClass) {
return new \ReflectionClass($sourceClass);
},
\array_filter(\array_unique($mappingClasses))
);
} | php | protected function getMappingClasses(): array
{
AnnotationRegistry::registerLoader('class_exists');
$mappingClasses = [];
foreach ($this->locator->getMappingFiles() as $annotationFile) {
$mappingClasses[] = $this->loadClassFromFile($annotationFile);
}
return \array_map(
function (string $sourceClass) {
return new \ReflectionClass($sourceClass);
},
\array_filter(\array_unique($mappingClasses))
);
} | [
"protected",
"function",
"getMappingClasses",
"(",
")",
":",
"array",
"{",
"AnnotationRegistry",
"::",
"registerLoader",
"(",
"'class_exists'",
")",
";",
"$",
"mappingClasses",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"locator",
"->",
"getMappingFiles",
"(",
")",
"as",
"$",
"annotationFile",
")",
"{",
"$",
"mappingClasses",
"[",
"]",
"=",
"$",
"this",
"->",
"loadClassFromFile",
"(",
"$",
"annotationFile",
")",
";",
"}",
"return",
"\\",
"array_map",
"(",
"function",
"(",
"string",
"$",
"sourceClass",
")",
"{",
"return",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"sourceClass",
")",
";",
"}",
",",
"\\",
"array_filter",
"(",
"\\",
"array_unique",
"(",
"$",
"mappingClasses",
")",
")",
")",
";",
"}"
] | Get mapping classes.
@throws \Jgut\Mapping\Exception\DriverException
@return \ReflectionClass[] | [
"Get",
"mapping",
"classes",
"."
] | 1830ff84c054d8e3759df170a5664a97f7070be9 | https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/AbstractAnnotationDriver.php#L59-L75 | train |
juliangut/mapping | src/Driver/AbstractAnnotationDriver.php | AbstractAnnotationDriver.loadClassFromFile | protected function loadClassFromFile(string $annotationFile): string
{
$tokens = \token_get_all(\file_get_contents($annotationFile));
$hasClass = false;
$class = null;
$hasNamespace = false;
$namespace = '';
for ($i = 0, $length = \count($tokens); $i < $length; $i++) {
$token = $tokens[$i];
if (!\is_array($token)) {
continue;
}
if ($hasClass && $token[0] === T_STRING) {
$class = $namespace . '\\' . $token[1];
break;
}
if ($hasNamespace && $token[0] === T_STRING) {
$namespace = '';
do {
$namespace .= $token[1];
$token = $tokens[++$i];
} while ($i < $length && \is_array($token) && \in_array($token[0], [T_NS_SEPARATOR, T_STRING], true));
$hasNamespace = false;
}
if ($token[0] === T_CLASS) {
$hasClass = true;
}
if ($token[0] === T_NAMESPACE) {
$hasNamespace = true;
}
}
return $class ?: '';
} | php | protected function loadClassFromFile(string $annotationFile): string
{
$tokens = \token_get_all(\file_get_contents($annotationFile));
$hasClass = false;
$class = null;
$hasNamespace = false;
$namespace = '';
for ($i = 0, $length = \count($tokens); $i < $length; $i++) {
$token = $tokens[$i];
if (!\is_array($token)) {
continue;
}
if ($hasClass && $token[0] === T_STRING) {
$class = $namespace . '\\' . $token[1];
break;
}
if ($hasNamespace && $token[0] === T_STRING) {
$namespace = '';
do {
$namespace .= $token[1];
$token = $tokens[++$i];
} while ($i < $length && \is_array($token) && \in_array($token[0], [T_NS_SEPARATOR, T_STRING], true));
$hasNamespace = false;
}
if ($token[0] === T_CLASS) {
$hasClass = true;
}
if ($token[0] === T_NAMESPACE) {
$hasNamespace = true;
}
}
return $class ?: '';
} | [
"protected",
"function",
"loadClassFromFile",
"(",
"string",
"$",
"annotationFile",
")",
":",
"string",
"{",
"$",
"tokens",
"=",
"\\",
"token_get_all",
"(",
"\\",
"file_get_contents",
"(",
"$",
"annotationFile",
")",
")",
";",
"$",
"hasClass",
"=",
"false",
";",
"$",
"class",
"=",
"null",
";",
"$",
"hasNamespace",
"=",
"false",
";",
"$",
"namespace",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"length",
"=",
"\\",
"count",
"(",
"$",
"tokens",
")",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"token",
"=",
"$",
"tokens",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"token",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"hasClass",
"&&",
"$",
"token",
"[",
"0",
"]",
"===",
"T_STRING",
")",
"{",
"$",
"class",
"=",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"token",
"[",
"1",
"]",
";",
"break",
";",
"}",
"if",
"(",
"$",
"hasNamespace",
"&&",
"$",
"token",
"[",
"0",
"]",
"===",
"T_STRING",
")",
"{",
"$",
"namespace",
"=",
"''",
";",
"do",
"{",
"$",
"namespace",
".=",
"$",
"token",
"[",
"1",
"]",
";",
"$",
"token",
"=",
"$",
"tokens",
"[",
"++",
"$",
"i",
"]",
";",
"}",
"while",
"(",
"$",
"i",
"<",
"$",
"length",
"&&",
"\\",
"is_array",
"(",
"$",
"token",
")",
"&&",
"\\",
"in_array",
"(",
"$",
"token",
"[",
"0",
"]",
",",
"[",
"T_NS_SEPARATOR",
",",
"T_STRING",
"]",
",",
"true",
")",
")",
";",
"$",
"hasNamespace",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"T_CLASS",
")",
"{",
"$",
"hasClass",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"T_NAMESPACE",
")",
"{",
"$",
"hasNamespace",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"class",
"?",
":",
"''",
";",
"}"
] | Load fully qualified class name from file.
@param string $annotationFile
@return string
@SuppressWarnings(PMD.CyclomaticComplexity)
@SuppressWarnings(PMD.NPathComplexity) | [
"Load",
"fully",
"qualified",
"class",
"name",
"from",
"file",
"."
] | 1830ff84c054d8e3759df170a5664a97f7070be9 | https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/AbstractAnnotationDriver.php#L87-L129 | train |
CHGLongStone/just-core-audit-entity | SERVICES/AUDIT.entity.php | AUDIT_ENTITY.logChange | public function logChange($args){
#echo __METHOD__.__LINE__.'$this->AUDIT_CODE['.$this->AUDIT_CODE.'] args<pre>['.var_export($args, true).']</pre>'.'<br>'.PHP_EOL;
if(!isset($args["code"]) || !is_numeric($args["code"])){
if(isset($this->AUDIT_CODE)){
$args["code"] = $this->AUDIT_CODE;
}else{
return false;
}
}
if(!isset($args["data"]) || '[]' == $args["data"]){
return false;
}
$query = '
INSERT INTO client_log (
client_user_fk,
client_fingerprint_fk,
log_code,
log_message,
log_data
)
VALUES (
'.$_SESSION['user_id'].',
'.$args["client_fingerprint_pk"].',
'.$args["code"].',
"'.$args["log_message"].'",
\''.$args["data"].'\'
)';
#echo __METHOD__.'@'.__LINE__.' query<pre>['.var_export($query, true).']</pre> '.'<br>'.PHP_EOL;
#echo __METHOD__.'@'.__LINE__.' $this->logConfig<pre>['.var_export($this->logConfig, true).']</pre> '.'<br>'.PHP_EOL;
$result = $GLOBALS["DATA_API"]->create($this->logConfig['DSN'], $query, $extArgs=array('returnArray' => true));
#echo __METHOD__.'@'.__LINE__.' result<pre>['.var_export($result, true).']</pre> '.'<br>'.PHP_EOL;
if(isset($result["INSERT_ID"])){
return true;
}
return false;
} | php | public function logChange($args){
#echo __METHOD__.__LINE__.'$this->AUDIT_CODE['.$this->AUDIT_CODE.'] args<pre>['.var_export($args, true).']</pre>'.'<br>'.PHP_EOL;
if(!isset($args["code"]) || !is_numeric($args["code"])){
if(isset($this->AUDIT_CODE)){
$args["code"] = $this->AUDIT_CODE;
}else{
return false;
}
}
if(!isset($args["data"]) || '[]' == $args["data"]){
return false;
}
$query = '
INSERT INTO client_log (
client_user_fk,
client_fingerprint_fk,
log_code,
log_message,
log_data
)
VALUES (
'.$_SESSION['user_id'].',
'.$args["client_fingerprint_pk"].',
'.$args["code"].',
"'.$args["log_message"].'",
\''.$args["data"].'\'
)';
#echo __METHOD__.'@'.__LINE__.' query<pre>['.var_export($query, true).']</pre> '.'<br>'.PHP_EOL;
#echo __METHOD__.'@'.__LINE__.' $this->logConfig<pre>['.var_export($this->logConfig, true).']</pre> '.'<br>'.PHP_EOL;
$result = $GLOBALS["DATA_API"]->create($this->logConfig['DSN'], $query, $extArgs=array('returnArray' => true));
#echo __METHOD__.'@'.__LINE__.' result<pre>['.var_export($result, true).']</pre> '.'<br>'.PHP_EOL;
if(isset($result["INSERT_ID"])){
return true;
}
return false;
} | [
"public",
"function",
"logChange",
"(",
"$",
"args",
")",
"{",
"#echo __METHOD__.__LINE__.'$this->AUDIT_CODE['.$this->AUDIT_CODE.'] args<pre>['.var_export($args, true).']</pre>'.'<br>'.PHP_EOL; ",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"\"code\"",
"]",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"args",
"[",
"\"code\"",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"AUDIT_CODE",
")",
")",
"{",
"$",
"args",
"[",
"\"code\"",
"]",
"=",
"$",
"this",
"->",
"AUDIT_CODE",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"\"data\"",
"]",
")",
"||",
"'[]'",
"==",
"$",
"args",
"[",
"\"data\"",
"]",
")",
"{",
"return",
"false",
";",
"}",
"$",
"query",
"=",
"'\n\t\tINSERT INTO client_log (\n\t\t\tclient_user_fk, \n\t\t\tclient_fingerprint_fk, \n\t\t\tlog_code, \n\t\t\tlog_message, \n\t\t\tlog_data\n\t\t)\n\t\tVALUES (\n\t\t\t'",
".",
"$",
"_SESSION",
"[",
"'user_id'",
"]",
".",
"',\n\t\t\t'",
".",
"$",
"args",
"[",
"\"client_fingerprint_pk\"",
"]",
".",
"', \n\t\t\t'",
".",
"$",
"args",
"[",
"\"code\"",
"]",
".",
"', \n\t\t\t\"'",
".",
"$",
"args",
"[",
"\"log_message\"",
"]",
".",
"'\",\n\t\t\t\\''",
".",
"$",
"args",
"[",
"\"data\"",
"]",
".",
"'\\'\n\t\t)'",
";",
"#echo __METHOD__.'@'.__LINE__.' query<pre>['.var_export($query, true).']</pre> '.'<br>'.PHP_EOL; ",
"#echo __METHOD__.'@'.__LINE__.' $this->logConfig<pre>['.var_export($this->logConfig, true).']</pre> '.'<br>'.PHP_EOL; ",
"$",
"result",
"=",
"$",
"GLOBALS",
"[",
"\"DATA_API\"",
"]",
"->",
"create",
"(",
"$",
"this",
"->",
"logConfig",
"[",
"'DSN'",
"]",
",",
"$",
"query",
",",
"$",
"extArgs",
"=",
"array",
"(",
"'returnArray'",
"=>",
"true",
")",
")",
";",
"#echo __METHOD__.'@'.__LINE__.' result<pre>['.var_export($result, true).']</pre> '.'<br>'.PHP_EOL; ",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"\"INSERT_ID\"",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Log an entity change
@param array args
@return bool | [
"Log",
"an",
"entity",
"change"
] | 5b5aff35dffd06adf900bbca1ad7537b1f00a72e | https://github.com/CHGLongStone/just-core-audit-entity/blob/5b5aff35dffd06adf900bbca1ad7537b1f00a72e/SERVICES/AUDIT.entity.php#L92-L131 | train |
covex-nn/JooS_Stream | src/JooS/Stream/Files.php | Files.tempnam | public function tempnam()
{
$sysTempDir = $this->_sysGetTempDir();
do {
$this->_tempnamCounter++;
$name = $sysTempDir . "/" . $this->_tempnamCounter;
} while (file_exists($name));
return $name;
} | php | public function tempnam()
{
$sysTempDir = $this->_sysGetTempDir();
do {
$this->_tempnamCounter++;
$name = $sysTempDir . "/" . $this->_tempnamCounter;
} while (file_exists($name));
return $name;
} | [
"public",
"function",
"tempnam",
"(",
")",
"{",
"$",
"sysTempDir",
"=",
"$",
"this",
"->",
"_sysGetTempDir",
"(",
")",
";",
"do",
"{",
"$",
"this",
"->",
"_tempnamCounter",
"++",
";",
"$",
"name",
"=",
"$",
"sysTempDir",
".",
"\"/\"",
".",
"$",
"this",
"->",
"_tempnamCounter",
";",
"}",
"while",
"(",
"file_exists",
"(",
"$",
"name",
")",
")",
";",
"return",
"$",
"name",
";",
"}"
] | Return unique filename
@return string | [
"Return",
"unique",
"filename"
] | e9841b804190a9f624b9e44caa0af7a18f3816d1 | https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Files.php#L61-L70 | train |
covex-nn/JooS_Stream | src/JooS/Stream/Files.php | Files._sysGetTempDir | private function _sysGetTempDir($create = true)
{
if (is_null($this->_systemTempDirectory) && $create) {
$sysTmpDir = rtrim(sys_get_temp_dir(), "\\/");
do {
$name = $sysTmpDir . "/" . uniqid("fs", true);
} while (file_exists($name));
mkdir($name, 0777);
$this->_systemTempDirectory = $name;
}
return $this->_systemTempDirectory;
} | php | private function _sysGetTempDir($create = true)
{
if (is_null($this->_systemTempDirectory) && $create) {
$sysTmpDir = rtrim(sys_get_temp_dir(), "\\/");
do {
$name = $sysTmpDir . "/" . uniqid("fs", true);
} while (file_exists($name));
mkdir($name, 0777);
$this->_systemTempDirectory = $name;
}
return $this->_systemTempDirectory;
} | [
"private",
"function",
"_sysGetTempDir",
"(",
"$",
"create",
"=",
"true",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_systemTempDirectory",
")",
"&&",
"$",
"create",
")",
"{",
"$",
"sysTmpDir",
"=",
"rtrim",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"\"\\\\/\"",
")",
";",
"do",
"{",
"$",
"name",
"=",
"$",
"sysTmpDir",
".",
"\"/\"",
".",
"uniqid",
"(",
"\"fs\"",
",",
"true",
")",
";",
"}",
"while",
"(",
"file_exists",
"(",
"$",
"name",
")",
")",
";",
"mkdir",
"(",
"$",
"name",
",",
"0777",
")",
";",
"$",
"this",
"->",
"_systemTempDirectory",
"=",
"$",
"name",
";",
"}",
"return",
"$",
"this",
"->",
"_systemTempDirectory",
";",
"}"
] | Return path to own temp directory
@param boolean $create Create new folder ?
@return string | [
"Return",
"path",
"to",
"own",
"temp",
"directory"
] | e9841b804190a9f624b9e44caa0af7a18f3816d1 | https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Files.php#L145-L158 | train |
hschletz/NADA | src/Column/AbstractColumn.php | AbstractColumn.constructFromTable | public function constructFromTable($table, $data)
{
$this->_database = $table->getDatabase();
$this->_table = $table;
$this->_parseName($data);
$this->_parseDatatype($data);
$this->_parseNotnull($data);
$this->_parseDefault($data);
$this->_parseAutoIncrement($data);
$this->_parseComment($data);
} | php | public function constructFromTable($table, $data)
{
$this->_database = $table->getDatabase();
$this->_table = $table;
$this->_parseName($data);
$this->_parseDatatype($data);
$this->_parseNotnull($data);
$this->_parseDefault($data);
$this->_parseAutoIncrement($data);
$this->_parseComment($data);
} | [
"public",
"function",
"constructFromTable",
"(",
"$",
"table",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"_database",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
";",
"$",
"this",
"->",
"_table",
"=",
"$",
"table",
";",
"$",
"this",
"->",
"_parseName",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_parseDatatype",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_parseNotnull",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_parseDefault",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_parseAutoIncrement",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_parseComment",
"(",
"$",
"data",
")",
";",
"}"
] | Internal method to set up the object from within a \Nada\Table\AbstractTable object
The column data can be of any type and is passed to the _parse*()
methods.
@param \Nada\Table\AbstractTable $table Table that this column belongs to
@param mixed $data Column data
@internal | [
"Internal",
"method",
"to",
"set",
"up",
"the",
"object",
"from",
"within",
"a",
"\\",
"Nada",
"\\",
"Table",
"\\",
"AbstractTable",
"object"
] | 4ead798354089fd360f917ce64dd1432d5650df0 | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/AbstractColumn.php#L159-L169 | train |
hschletz/NADA | src/Column/AbstractColumn.php | AbstractColumn.toArray | public function toArray()
{
return array(
'name' => $this->_name,
'type' => $this->_datatype,
'length' => $this->_length,
'notnull' => $this->_notnull,
'default' => $this->_default,
'autoincrement' => $this->_autoIncrement,
'comment' => $this->_comment,
);
} | php | public function toArray()
{
return array(
'name' => $this->_name,
'type' => $this->_datatype,
'length' => $this->_length,
'notnull' => $this->_notnull,
'default' => $this->_default,
'autoincrement' => $this->_autoIncrement,
'comment' => $this->_comment,
);
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"_name",
",",
"'type'",
"=>",
"$",
"this",
"->",
"_datatype",
",",
"'length'",
"=>",
"$",
"this",
"->",
"_length",
",",
"'notnull'",
"=>",
"$",
"this",
"->",
"_notnull",
",",
"'default'",
"=>",
"$",
"this",
"->",
"_default",
",",
"'autoincrement'",
"=>",
"$",
"this",
"->",
"_autoIncrement",
",",
"'comment'",
"=>",
"$",
"this",
"->",
"_comment",
",",
")",
";",
"}"
] | Export column data to an associative array
@return array Column data: name, type, length, notnull, default, autoincrement, comment | [
"Export",
"column",
"data",
"to",
"an",
"associative",
"array"
] | 4ead798354089fd360f917ce64dd1432d5650df0 | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/AbstractColumn.php#L212-L223 | train |
hschletz/NADA | src/Column/AbstractColumn.php | AbstractColumn._parseNotnull | protected function _parseNotnull($data)
{
switch ($data['is_nullable']) {
case 'YES':
$this->_notnull = false;
break;
case 'NO':
$this->_notnull = true;
break;
default:
throw new \UnexpectedValueException('Invalid yes/no type: ' . $data['is_nullable']);
}
} | php | protected function _parseNotnull($data)
{
switch ($data['is_nullable']) {
case 'YES':
$this->_notnull = false;
break;
case 'NO':
$this->_notnull = true;
break;
default:
throw new \UnexpectedValueException('Invalid yes/no type: ' . $data['is_nullable']);
}
} | [
"protected",
"function",
"_parseNotnull",
"(",
"$",
"data",
")",
"{",
"switch",
"(",
"$",
"data",
"[",
"'is_nullable'",
"]",
")",
"{",
"case",
"'YES'",
":",
"$",
"this",
"->",
"_notnull",
"=",
"false",
";",
"break",
";",
"case",
"'NO'",
":",
"$",
"this",
"->",
"_notnull",
"=",
"true",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Invalid yes/no type: '",
".",
"$",
"data",
"[",
"'is_nullable'",
"]",
")",
";",
"}",
"}"
] | Extract NOT NULL constraint from column data
The default implementation expects an array with information_schema
compatible keys.
@param mixed $data Column data | [
"Extract",
"NOT",
"NULL",
"constraint",
"from",
"column",
"data"
] | 4ead798354089fd360f917ce64dd1432d5650df0 | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/AbstractColumn.php#L256-L268 | train |
hschletz/NADA | src/Column/AbstractColumn.php | AbstractColumn.setName | public function setName($name)
{
if (strlen($name) == 0) {
throw new \InvalidArgumentException('Column name must not be empty');
}
if ($this->_table) {
// Call the table method before the property gets updated because the
// old name is retrieved from $this
$this->_table->renameColumn($this, $name);
}
$this->_name = $name;
} | php | public function setName($name)
{
if (strlen($name) == 0) {
throw new \InvalidArgumentException('Column name must not be empty');
}
if ($this->_table) {
// Call the table method before the property gets updated because the
// old name is retrieved from $this
$this->_table->renameColumn($this, $name);
}
$this->_name = $name;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"name",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Column name must not be empty'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_table",
")",
"{",
"// Call the table method before the property gets updated because the",
"// old name is retrieved from $this",
"$",
"this",
"->",
"_table",
"->",
"renameColumn",
"(",
"$",
"this",
",",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"_name",
"=",
"$",
"name",
";",
"}"
] | Change the column's name
If this instance is linked to a table, i.e. not created via
\Nada\Database\AbstractDatabase::createColumn(), the operation will be
performed on the database.
@param string $name New name
@throws \InvalidArgumentException if name is empty | [
"Change",
"the",
"column",
"s",
"name"
] | 4ead798354089fd360f917ce64dd1432d5650df0 | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/AbstractColumn.php#L400-L411 | train |
hschletz/NADA | src/Column/AbstractColumn.php | AbstractColumn._setDefault | protected function _setDefault()
{
if ($this->_default === null) {
$this->_table->alter(
sprintf('ALTER COLUMN %s DROP DEFAULT', $this->_database->prepareIdentifier($this->_name))
);
} else {
$this->_table->alter(
sprintf(
'ALTER COLUMN %s SET DEFAULT %s',
$this->_database->prepareIdentifier($this->_name),
$this->_database->prepareValue($this->_default, $this->_datatype)
)
);
}
} | php | protected function _setDefault()
{
if ($this->_default === null) {
$this->_table->alter(
sprintf('ALTER COLUMN %s DROP DEFAULT', $this->_database->prepareIdentifier($this->_name))
);
} else {
$this->_table->alter(
sprintf(
'ALTER COLUMN %s SET DEFAULT %s',
$this->_database->prepareIdentifier($this->_name),
$this->_database->prepareValue($this->_default, $this->_datatype)
)
);
}
} | [
"protected",
"function",
"_setDefault",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_default",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_table",
"->",
"alter",
"(",
"sprintf",
"(",
"'ALTER COLUMN %s DROP DEFAULT'",
",",
"$",
"this",
"->",
"_database",
"->",
"prepareIdentifier",
"(",
"$",
"this",
"->",
"_name",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_table",
"->",
"alter",
"(",
"sprintf",
"(",
"'ALTER COLUMN %s SET DEFAULT %s'",
",",
"$",
"this",
"->",
"_database",
"->",
"prepareIdentifier",
"(",
"$",
"this",
"->",
"_name",
")",
",",
"$",
"this",
"->",
"_database",
"->",
"prepareValue",
"(",
"$",
"this",
"->",
"_default",
",",
"$",
"this",
"->",
"_datatype",
")",
")",
")",
";",
"}",
"}"
] | DBMS-specific implementation for setting a column's default value | [
"DBMS",
"-",
"specific",
"implementation",
"for",
"setting",
"a",
"column",
"s",
"default",
"value"
] | 4ead798354089fd360f917ce64dd1432d5650df0 | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/AbstractColumn.php#L493-L508 | train |
hschletz/NADA | src/Column/AbstractColumn.php | AbstractColumn.setComment | public function setComment($comment)
{
if ($this->_comment != $comment) {
$this->_comment = $comment;
if ($this->_table) {
$this->_setComment($comment);
}
}
} | php | public function setComment($comment)
{
if ($this->_comment != $comment) {
$this->_comment = $comment;
if ($this->_table) {
$this->_setComment($comment);
}
}
} | [
"public",
"function",
"setComment",
"(",
"$",
"comment",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_comment",
"!=",
"$",
"comment",
")",
"{",
"$",
"this",
"->",
"_comment",
"=",
"$",
"comment",
";",
"if",
"(",
"$",
"this",
"->",
"_table",
")",
"{",
"$",
"this",
"->",
"_setComment",
"(",
"$",
"comment",
")",
";",
"}",
"}",
"}"
] | Set Column comment
If this instance is linked to a table, i.e. not created via
\Nada\Database\AbstractDatabase::createColumn(), the operation will be
performed on the database.
@param string $comment Comment (use NULL to remove comment) | [
"Set",
"Column",
"comment"
] | 4ead798354089fd360f917ce64dd1432d5650df0 | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/AbstractColumn.php#L519-L527 | train |
hschletz/NADA | src/Column/AbstractColumn.php | AbstractColumn.isDifferent | public function isDifferent(array $newSpec, array $keys = null)
{
$oldSpec = $this->toArray();
if ($keys) {
$keys = array_flip($keys);
$oldSpec = array_intersect_key($oldSpec, $keys);
$newSpec = array_intersect_key($newSpec, $keys);
}
return $this->_isDifferent($oldSpec, $newSpec);
} | php | public function isDifferent(array $newSpec, array $keys = null)
{
$oldSpec = $this->toArray();
if ($keys) {
$keys = array_flip($keys);
$oldSpec = array_intersect_key($oldSpec, $keys);
$newSpec = array_intersect_key($newSpec, $keys);
}
return $this->_isDifferent($oldSpec, $newSpec);
} | [
"public",
"function",
"isDifferent",
"(",
"array",
"$",
"newSpec",
",",
"array",
"$",
"keys",
"=",
"null",
")",
"{",
"$",
"oldSpec",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"$",
"keys",
")",
"{",
"$",
"keys",
"=",
"array_flip",
"(",
"$",
"keys",
")",
";",
"$",
"oldSpec",
"=",
"array_intersect_key",
"(",
"$",
"oldSpec",
",",
"$",
"keys",
")",
";",
"$",
"newSpec",
"=",
"array_intersect_key",
"(",
"$",
"newSpec",
",",
"$",
"keys",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_isDifferent",
"(",
"$",
"oldSpec",
",",
"$",
"newSpec",
")",
";",
"}"
] | Compare with given specification
@param mixed[] $newSpec Specification to compare with. Same keys as toArray() output.
@param string[] $keys Compare only given attributes (default: compare all)
@return bool | [
"Compare",
"with",
"given",
"specification"
] | 4ead798354089fd360f917ce64dd1432d5650df0 | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/AbstractColumn.php#L541-L550 | train |
phossa/phossa-di | src/Phossa/Di/Delegator.php | Delegator.get | public function get($id)
{
/* @var $container InteropContainerInterface */
foreach ($this->getContainers() as $container) {
if ($container->has($id)) {
return $container->get($id);
}
}
// not found
throw new NotFoundException(
Message::get(Message::SERVICE_ID_NOT_FOUND, $id),
Message::SERVICE_ID_NOT_FOUND
);
} | php | public function get($id)
{
/* @var $container InteropContainerInterface */
foreach ($this->getContainers() as $container) {
if ($container->has($id)) {
return $container->get($id);
}
}
// not found
throw new NotFoundException(
Message::get(Message::SERVICE_ID_NOT_FOUND, $id),
Message::SERVICE_ID_NOT_FOUND
);
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"/* @var $container InteropContainerInterface */",
"foreach",
"(",
"$",
"this",
"->",
"getContainers",
"(",
")",
"as",
"$",
"container",
")",
"{",
"if",
"(",
"$",
"container",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"container",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}",
"}",
"// not found",
"throw",
"new",
"NotFoundException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"SERVICE_ID_NOT_FOUND",
",",
"$",
"id",
")",
",",
"Message",
"::",
"SERVICE_ID_NOT_FOUND",
")",
";",
"}"
] | Get from the delegator
{@inheritDoc} | [
"Get",
"from",
"the",
"delegator"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Delegator.php#L80-L94 | train |
zapheus/zapheus | src/Http/Message/ResponseFactory.php | ResponseFactory.make | public function make()
{
return new Response($this->code, $this->headers, $this->stream, $this->version);
} | php | public function make()
{
return new Response($this->code, $this->headers, $this->stream, $this->version);
} | [
"public",
"function",
"make",
"(",
")",
"{",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"code",
",",
"$",
"this",
"->",
"headers",
",",
"$",
"this",
"->",
"stream",
",",
"$",
"this",
"->",
"version",
")",
";",
"}"
] | Creates the response instance.
@return \Zapheus\Http\Message\ResponseInterface | [
"Creates",
"the",
"response",
"instance",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Http/Message/ResponseFactory.php#L53-L56 | train |
phpffcms/ffcms-core | src/Exception/NativeException.php | NativeException.display | public function display($message = null)
{
// if passed message is null get exception msg
if (!$message) {
$message = $this->message;
}
// hide root path from exception
$message = Str::replace(root, '$DOCUMENT_ROOT', $message);
$message = strip_tags($message);
// generate response based on environment type
switch (env_type) {
case 'html':
return $this->sendHTML($message);
case 'json':
return $this->sendJSON($message);
}
return $message;
} | php | public function display($message = null)
{
// if passed message is null get exception msg
if (!$message) {
$message = $this->message;
}
// hide root path from exception
$message = Str::replace(root, '$DOCUMENT_ROOT', $message);
$message = strip_tags($message);
// generate response based on environment type
switch (env_type) {
case 'html':
return $this->sendHTML($message);
case 'json':
return $this->sendJSON($message);
}
return $message;
} | [
"public",
"function",
"display",
"(",
"$",
"message",
"=",
"null",
")",
"{",
"// if passed message is null get exception msg",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"message",
";",
"}",
"// hide root path from exception",
"$",
"message",
"=",
"Str",
"::",
"replace",
"(",
"root",
",",
"'$DOCUMENT_ROOT'",
",",
"$",
"message",
")",
";",
"$",
"message",
"=",
"strip_tags",
"(",
"$",
"message",
")",
";",
"// generate response based on environment type",
"switch",
"(",
"env_type",
")",
"{",
"case",
"'html'",
":",
"return",
"$",
"this",
"->",
"sendHTML",
"(",
"$",
"message",
")",
";",
"case",
"'json'",
":",
"return",
"$",
"this",
"->",
"sendJSON",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | Display native exception
@param string $message
@return string|null | [
"Display",
"native",
"exception"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Exception/NativeException.php#L31-L51 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddLogLifetimeField | private function AddLogLifetimeField()
{
$name = 'LogLifetime';
$field = Input::Text($name, $this->settings->GetLogLifetime());
$this->AddField($field);
$this->AddValidator($name, new Integer(0, 730));
$this->SetRequired($name);
} | php | private function AddLogLifetimeField()
{
$name = 'LogLifetime';
$field = Input::Text($name, $this->settings->GetLogLifetime());
$this->AddField($field);
$this->AddValidator($name, new Integer(0, 730));
$this->SetRequired($name);
} | [
"private",
"function",
"AddLogLifetimeField",
"(",
")",
"{",
"$",
"name",
"=",
"'LogLifetime'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetLogLifetime",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"AddValidator",
"(",
"$",
"name",
",",
"new",
"Integer",
"(",
"0",
",",
"730",
")",
")",
";",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"}"
] | Adds the log lifetime field | [
"Adds",
"the",
"log",
"lifetime",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L44-L51 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddChangeRequestLifetimeField | private function AddChangeRequestLifetimeField()
{
$name = 'ChangeRequestLifetime';
$field = Input::Text($name, $this->settings->GetChangeRequestLifetime());
$this->AddField($field);
$this->AddValidator($name, new Integer(1, 360));
$this->SetRequired($name);
} | php | private function AddChangeRequestLifetimeField()
{
$name = 'ChangeRequestLifetime';
$field = Input::Text($name, $this->settings->GetChangeRequestLifetime());
$this->AddField($field);
$this->AddValidator($name, new Integer(1, 360));
$this->SetRequired($name);
} | [
"private",
"function",
"AddChangeRequestLifetimeField",
"(",
")",
"{",
"$",
"name",
"=",
"'ChangeRequestLifetime'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetChangeRequestLifetime",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"AddValidator",
"(",
"$",
"name",
",",
"new",
"Integer",
"(",
"1",
",",
"360",
")",
")",
";",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"}"
] | Adds the change request lifetime field | [
"Adds",
"the",
"change",
"request",
"lifetime",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L56-L63 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddMailFromEMailField | private function AddMailFromEMailField()
{
$name = 'MailFromEMail';
$field = Input::Text($name, $this->settings->GetMailFromEMail());
$this->AddField($field);
$this->AddValidator($name, PhpFilter::EMail());
} | php | private function AddMailFromEMailField()
{
$name = 'MailFromEMail';
$field = Input::Text($name, $this->settings->GetMailFromEMail());
$this->AddField($field);
$this->AddValidator($name, PhpFilter::EMail());
} | [
"private",
"function",
"AddMailFromEMailField",
"(",
")",
"{",
"$",
"name",
"=",
"'MailFromEMail'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetMailFromEMail",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"AddValidator",
"(",
"$",
"name",
",",
"PhpFilter",
"::",
"EMail",
"(",
")",
")",
";",
"}"
] | Adds the smtp mail from e-mail field | [
"Adds",
"the",
"smtp",
"mail",
"from",
"e",
"-",
"mail",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L68-L74 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddMailFromNameField | private function AddMailFromNameField()
{
$name = 'MailFromName';
$field = Input::Text($name, $this->settings->GetMailFromName());
$this->AddField($field);
} | php | private function AddMailFromNameField()
{
$name = 'MailFromName';
$field = Input::Text($name, $this->settings->GetMailFromName());
$this->AddField($field);
} | [
"private",
"function",
"AddMailFromNameField",
"(",
")",
"{",
"$",
"name",
"=",
"'MailFromName'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetMailFromName",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the mail from name field | [
"Adds",
"the",
"mail",
"from",
"name",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L79-L84 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddSmtpHostField | private function AddSmtpHostField()
{
$name = 'SmtpHost';
$field = Input::Text($name, $this->settings->GetSmtpHost());
$this->AddField($field);
} | php | private function AddSmtpHostField()
{
$name = 'SmtpHost';
$field = Input::Text($name, $this->settings->GetSmtpHost());
$this->AddField($field);
} | [
"private",
"function",
"AddSmtpHostField",
"(",
")",
"{",
"$",
"name",
"=",
"'SmtpHost'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetSmtpHost",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the smtp host field | [
"Adds",
"the",
"smtp",
"host",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L89-L94 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddSmtpPortField | private function AddSmtpPortField()
{
$name = 'SmtpPort';
$field = Input::Text($name, $this->settings->GetSmtpPort());
$this->AddField($field);
$this->AddValidator($name, new Integer(1, 65535));
} | php | private function AddSmtpPortField()
{
$name = 'SmtpPort';
$field = Input::Text($name, $this->settings->GetSmtpPort());
$this->AddField($field);
$this->AddValidator($name, new Integer(1, 65535));
} | [
"private",
"function",
"AddSmtpPortField",
"(",
")",
"{",
"$",
"name",
"=",
"'SmtpPort'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetSmtpPort",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"AddValidator",
"(",
"$",
"name",
",",
"new",
"Integer",
"(",
"1",
",",
"65535",
")",
")",
";",
"}"
] | Adds the smtp port field | [
"Adds",
"the",
"smtp",
"port",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L99-L105 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddSmtpUserField | private function AddSmtpUserField()
{
$name = 'SmtpUser';
$field = Input::Text($name, $this->settings->GetSmtpUser());
$this->AddField($field);
} | php | private function AddSmtpUserField()
{
$name = 'SmtpUser';
$field = Input::Text($name, $this->settings->GetSmtpUser());
$this->AddField($field);
} | [
"private",
"function",
"AddSmtpUserField",
"(",
")",
"{",
"$",
"name",
"=",
"'SmtpUser'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetSmtpUser",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the smtp user field | [
"Adds",
"the",
"smtp",
"user",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L109-L114 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddSmtpPasswordField | private function AddSmtpPasswordField()
{
$name = 'SmtpPassword';
$field = Input::Text($name, $this->settings->GetSmtpPassword());
$this->AddField($field);
} | php | private function AddSmtpPasswordField()
{
$name = 'SmtpPassword';
$field = Input::Text($name, $this->settings->GetSmtpPassword());
$this->AddField($field);
} | [
"private",
"function",
"AddSmtpPasswordField",
"(",
")",
"{",
"$",
"name",
"=",
"'SmtpPassword'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetSmtpPassword",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the smtp password field | [
"Adds",
"the",
"smtp",
"password",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L119-L124 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.AddSmtpSecurityField | private function AddSmtpSecurityField()
{
$name = 'SmtpSecurity';
$field = new Select($name, $this->settings->GetSmtpSecurity());
$values = SmtpSecurity::AllowedValues();
foreach ($values as $value)
{
$field->AddOption($value, Trans("Core.SettingsForm.SmtpSecurity.$value"));
}
$this->AddField($field);
} | php | private function AddSmtpSecurityField()
{
$name = 'SmtpSecurity';
$field = new Select($name, $this->settings->GetSmtpSecurity());
$values = SmtpSecurity::AllowedValues();
foreach ($values as $value)
{
$field->AddOption($value, Trans("Core.SettingsForm.SmtpSecurity.$value"));
}
$this->AddField($field);
} | [
"private",
"function",
"AddSmtpSecurityField",
"(",
")",
"{",
"$",
"name",
"=",
"'SmtpSecurity'",
";",
"$",
"field",
"=",
"new",
"Select",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
"->",
"GetSmtpSecurity",
"(",
")",
")",
";",
"$",
"values",
"=",
"SmtpSecurity",
"::",
"AllowedValues",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"field",
"->",
"AddOption",
"(",
"$",
"value",
",",
"Trans",
"(",
"\"Core.SettingsForm.SmtpSecurity.$value\"",
")",
")",
";",
"}",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the smtp security field | [
"Adds",
"the",
"smtp",
"security",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L129-L139 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SettingsForm.php | SettingsForm.OnSuccess | protected function OnSuccess()
{
$this->settings->SetLogLifetime((int)$this->Value('LogLifetime'));
$this->settings->SetChangeRequestLifetime($this->Value('ChangeRequestLifetime'));
$this->settings->SetMailFromEMail($this->Value('MailFromEMail'));
$this->settings->SetMailFromName($this->Value('MailFromName'));
$this->settings->SetSmtpHost($this->Value('SmtpHost'));
$this->settings->SetSmtpPort($this->Value('SmtpPort'));
$this->settings->SetSmtpUser($this->Value('SmtpUser'));
$this->settings->SetSmtpPassword($this->Value('SmtpPassword'));
$this->settings->SetSmtpSecurity($this->Value('SmtpSecurity'));
$this->settings->Save();
Response::Redirect($this->BackLink());
} | php | protected function OnSuccess()
{
$this->settings->SetLogLifetime((int)$this->Value('LogLifetime'));
$this->settings->SetChangeRequestLifetime($this->Value('ChangeRequestLifetime'));
$this->settings->SetMailFromEMail($this->Value('MailFromEMail'));
$this->settings->SetMailFromName($this->Value('MailFromName'));
$this->settings->SetSmtpHost($this->Value('SmtpHost'));
$this->settings->SetSmtpPort($this->Value('SmtpPort'));
$this->settings->SetSmtpUser($this->Value('SmtpUser'));
$this->settings->SetSmtpPassword($this->Value('SmtpPassword'));
$this->settings->SetSmtpSecurity($this->Value('SmtpSecurity'));
$this->settings->Save();
Response::Redirect($this->BackLink());
} | [
"protected",
"function",
"OnSuccess",
"(",
")",
"{",
"$",
"this",
"->",
"settings",
"->",
"SetLogLifetime",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"Value",
"(",
"'LogLifetime'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetChangeRequestLifetime",
"(",
"$",
"this",
"->",
"Value",
"(",
"'ChangeRequestLifetime'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetMailFromEMail",
"(",
"$",
"this",
"->",
"Value",
"(",
"'MailFromEMail'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetMailFromName",
"(",
"$",
"this",
"->",
"Value",
"(",
"'MailFromName'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetSmtpHost",
"(",
"$",
"this",
"->",
"Value",
"(",
"'SmtpHost'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetSmtpPort",
"(",
"$",
"this",
"->",
"Value",
"(",
"'SmtpPort'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetSmtpUser",
"(",
"$",
"this",
"->",
"Value",
"(",
"'SmtpUser'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetSmtpPassword",
"(",
"$",
"this",
"->",
"Value",
"(",
"'SmtpPassword'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"SetSmtpSecurity",
"(",
"$",
"this",
"->",
"Value",
"(",
"'SmtpSecurity'",
")",
")",
";",
"$",
"this",
"->",
"settings",
"->",
"Save",
"(",
")",
";",
"Response",
"::",
"Redirect",
"(",
"$",
"this",
"->",
"BackLink",
"(",
")",
")",
";",
"}"
] | Saves the settings | [
"Saves",
"the",
"settings"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SettingsForm.php#L145-L158 | train |
guni12/comment | src/Comments/ShowAllService.php | ShowAllService.getAll | public function getAll()
{
$comm = new Comm();
$comm->setDb($this->di->get("db"));
return $comm->findAll();
} | php | public function getAll()
{
$comm = new Comm();
$comm->setDb($this->di->get("db"));
return $comm->findAll();
} | [
"public",
"function",
"getAll",
"(",
")",
"{",
"$",
"comm",
"=",
"new",
"Comm",
"(",
")",
";",
"$",
"comm",
"->",
"setDb",
"(",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"db\"",
")",
")",
";",
"return",
"$",
"comm",
"->",
"findAll",
"(",
")",
";",
"}"
] | Get details on all comments.
@return Comm | [
"Get",
"details",
"on",
"all",
"comments",
"."
] | f9c2f3e2093fea414867f548c5f5e07f96c55bfd | https://github.com/guni12/comment/blob/f9c2f3e2093fea414867f548c5f5e07f96c55bfd/src/Comments/ShowAllService.php#L44-L49 | train |
sndsgd/sndsgd-field | src/field/Rule.php | Rule.setField | public function setField(Field $field, $index = 0)
{
$this->field = $field;
$this->valueIndex = $index;
} | php | public function setField(Field $field, $index = 0)
{
$this->field = $field;
$this->valueIndex = $index;
} | [
"public",
"function",
"setField",
"(",
"Field",
"$",
"field",
",",
"$",
"index",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"field",
"=",
"$",
"field",
";",
"$",
"this",
"->",
"valueIndex",
"=",
"$",
"index",
";",
"}"
] | Set the value's parent field for use in validation
@param sndsgd\Field $field
@param integer $index The index of the value in the field | [
"Set",
"the",
"value",
"s",
"parent",
"field",
"for",
"use",
"in",
"validation"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Rule.php#L145-L149 | train |
sndsgd/sndsgd-field | src/field/Rule.php | Rule.getError | public function getError()
{
$error = new Error($this->getMessage());
$error->setValue($this->value);
if ($this->field !== null) {
$error->setName($this->field->getName());
}
if ($this->valueIndex !== null) {
$error->setIndex($this->valueIndex);
}
return $error;
} | php | public function getError()
{
$error = new Error($this->getMessage());
$error->setValue($this->value);
if ($this->field !== null) {
$error->setName($this->field->getName());
}
if ($this->valueIndex !== null) {
$error->setIndex($this->valueIndex);
}
return $error;
} | [
"public",
"function",
"getError",
"(",
")",
"{",
"$",
"error",
"=",
"new",
"Error",
"(",
"$",
"this",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"error",
"->",
"setValue",
"(",
"$",
"this",
"->",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"field",
"!==",
"null",
")",
"{",
"$",
"error",
"->",
"setName",
"(",
"$",
"this",
"->",
"field",
"->",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"valueIndex",
"!==",
"null",
")",
"{",
"$",
"error",
"->",
"setIndex",
"(",
"$",
"this",
"->",
"valueIndex",
")",
";",
"}",
"return",
"$",
"error",
";",
"}"
] | Get an error instance
@return sndsgd\field\Error | [
"Get",
"an",
"error",
"instance"
] | 34ac3aabfe031bd9b259b3b93e84964b04031334 | https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/field/Rule.php#L166-L177 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.camelCase | public static function camelCase($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return str_replace(' ', '', mb_convert_case(str_replace(array('_', '-'), ' ', preg_replace('/[^-_a-z0-9\s]+/i', '', $string)), MB_CASE_TITLE));
});
} | php | public static function camelCase($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return str_replace(' ', '', mb_convert_case(str_replace(array('_', '-'), ' ', preg_replace('/[^-_a-z0-9\s]+/i', '', $string)), MB_CASE_TITLE));
});
} | [
"public",
"static",
"function",
"camelCase",
"(",
"$",
"string",
")",
"{",
"return",
"static",
"::",
"cache",
"(",
"array",
"(",
"__METHOD__",
",",
"$",
"string",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"string",
")",
"{",
"return",
"str_replace",
"(",
"' '",
",",
"''",
",",
"mb_convert_case",
"(",
"str_replace",
"(",
"array",
"(",
"'_'",
",",
"'-'",
")",
",",
"' '",
",",
"preg_replace",
"(",
"'/[^-_a-z0-9\\s]+/i'",
",",
"''",
",",
"$",
"string",
")",
")",
",",
"MB_CASE_TITLE",
")",
")",
";",
"}",
")",
";",
"}"
] | Inflect a word to a camel case form with the first letter being capitalized.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"to",
"a",
"camel",
"case",
"form",
"with",
"the",
"first",
"letter",
"being",
"capitalized",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L23-L27 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.className | public static function className($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return Inflector::camelCase(Inflector::singularize($string));
});
} | php | public static function className($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return Inflector::camelCase(Inflector::singularize($string));
});
} | [
"public",
"static",
"function",
"className",
"(",
"$",
"string",
")",
"{",
"return",
"static",
"::",
"cache",
"(",
"array",
"(",
"__METHOD__",
",",
"$",
"string",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"string",
")",
"{",
"return",
"Inflector",
"::",
"camelCase",
"(",
"Inflector",
"::",
"singularize",
"(",
"$",
"string",
")",
")",
";",
"}",
")",
";",
"}"
] | Inflect a word to a class name. Singular camel cased form.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"to",
"a",
"class",
"name",
".",
"Singular",
"camel",
"cased",
"form",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L35-L39 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.fileName | public static function fileName($string, $ext = 'php', $capitalize = true) {
if (mb_strpos($string, '.') !== false) {
$string = mb_substr($string, 0, mb_strrpos($string, '.'));
}
$path = static::camelCase($string);
if (!$capitalize) {
$path = lcfirst($path);
}
if (mb_substr($path, -(mb_strlen($ext) + 1)) !== '.' . $ext) {
$path .= '.' . $ext;
}
return $path;
} | php | public static function fileName($string, $ext = 'php', $capitalize = true) {
if (mb_strpos($string, '.') !== false) {
$string = mb_substr($string, 0, mb_strrpos($string, '.'));
}
$path = static::camelCase($string);
if (!$capitalize) {
$path = lcfirst($path);
}
if (mb_substr($path, -(mb_strlen($ext) + 1)) !== '.' . $ext) {
$path .= '.' . $ext;
}
return $path;
} | [
"public",
"static",
"function",
"fileName",
"(",
"$",
"string",
",",
"$",
"ext",
"=",
"'php'",
",",
"$",
"capitalize",
"=",
"true",
")",
"{",
"if",
"(",
"mb_strpos",
"(",
"$",
"string",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"string",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"mb_strrpos",
"(",
"$",
"string",
",",
"'.'",
")",
")",
";",
"}",
"$",
"path",
"=",
"static",
"::",
"camelCase",
"(",
"$",
"string",
")",
";",
"if",
"(",
"!",
"$",
"capitalize",
")",
"{",
"$",
"path",
"=",
"lcfirst",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"mb_substr",
"(",
"$",
"path",
",",
"-",
"(",
"mb_strlen",
"(",
"$",
"ext",
")",
"+",
"1",
")",
")",
"!==",
"'.'",
".",
"$",
"ext",
")",
"{",
"$",
"path",
".=",
"'.'",
".",
"$",
"ext",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Inflect a word for a filename. Studly cased and capitalized.
@param string $string
@param string $ext
@param bool $capitalize
@return string | [
"Inflect",
"a",
"word",
"for",
"a",
"filename",
".",
"Studly",
"cased",
"and",
"capitalized",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L49-L65 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.normalCase | public static function normalCase($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return ucfirst(mb_strtolower(str_replace('_', ' ', $string)));
});
} | php | public static function normalCase($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return ucfirst(mb_strtolower(str_replace('_', ' ', $string)));
});
} | [
"public",
"static",
"function",
"normalCase",
"(",
"$",
"string",
")",
"{",
"return",
"static",
"::",
"cache",
"(",
"array",
"(",
"__METHOD__",
",",
"$",
"string",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"string",
")",
"{",
"return",
"ucfirst",
"(",
"mb_strtolower",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"string",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Inflect a word to a human readable string with only the first word capitalized and the rest lowercased.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"to",
"a",
"human",
"readable",
"string",
"with",
"only",
"the",
"first",
"word",
"capitalized",
"and",
"the",
"rest",
"lowercased",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L85-L89 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.route | public static function route($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return mb_strtolower(Inflector::hyphenate(str_replace('_', '-', preg_replace('/[^-_a-z0-9\s\.]+/i', '', $string))));
});
} | php | public static function route($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return mb_strtolower(Inflector::hyphenate(str_replace('_', '-', preg_replace('/[^-_a-z0-9\s\.]+/i', '', $string))));
});
} | [
"public",
"static",
"function",
"route",
"(",
"$",
"string",
")",
"{",
"return",
"static",
"::",
"cache",
"(",
"array",
"(",
"__METHOD__",
",",
"$",
"string",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"string",
")",
"{",
"return",
"mb_strtolower",
"(",
"Inflector",
"::",
"hyphenate",
"(",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"preg_replace",
"(",
"'/[^-_a-z0-9\\s\\.]+/i'",
",",
"''",
",",
"$",
"string",
")",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Inflect a word to a routeable format. All non-alphanumeric characters will be removed, and any spaces or underscores will be changed to dashes.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"to",
"a",
"routeable",
"format",
".",
"All",
"non",
"-",
"alphanumeric",
"characters",
"will",
"be",
"removed",
"and",
"any",
"spaces",
"or",
"underscores",
"will",
"be",
"changed",
"to",
"dashes",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L117-L121 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.tableName | public static function tableName($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return lcfirst(Inflector::camelCase(Inflector::pluralize($string)));
});
} | php | public static function tableName($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return lcfirst(Inflector::camelCase(Inflector::pluralize($string)));
});
} | [
"public",
"static",
"function",
"tableName",
"(",
"$",
"string",
")",
"{",
"return",
"static",
"::",
"cache",
"(",
"array",
"(",
"__METHOD__",
",",
"$",
"string",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"string",
")",
"{",
"return",
"lcfirst",
"(",
"Inflector",
"::",
"camelCase",
"(",
"Inflector",
"::",
"pluralize",
"(",
"$",
"string",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Inflect a word for a database table name. Formatted as plural and camel case with the first letter lowercase.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"for",
"a",
"database",
"table",
"name",
".",
"Formatted",
"as",
"plural",
"and",
"camel",
"case",
"with",
"the",
"first",
"letter",
"lowercase",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L170-L174 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.titleCase | public static function titleCase($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return mb_convert_case(str_replace('_', ' ', $string), MB_CASE_TITLE);
});
} | php | public static function titleCase($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return mb_convert_case(str_replace('_', ' ', $string), MB_CASE_TITLE);
});
} | [
"public",
"static",
"function",
"titleCase",
"(",
"$",
"string",
")",
"{",
"return",
"static",
"::",
"cache",
"(",
"array",
"(",
"__METHOD__",
",",
"$",
"string",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"string",
")",
"{",
"return",
"mb_convert_case",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"string",
")",
",",
"MB_CASE_TITLE",
")",
";",
"}",
")",
";",
"}"
] | Inflect a word to a human readable string with all words capitalized.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"to",
"a",
"human",
"readable",
"string",
"with",
"all",
"words",
"capitalized",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L182-L186 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.underscore | public static function underscore($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return trim(mb_strtolower(str_replace('__', '_', preg_replace('/([A-Z]{1})/', '_$1', preg_replace('/[^_a-z0-9]+/i', '', preg_replace('/[\s]+/', '_', $string))))), '_');
});
} | php | public static function underscore($string) {
return static::cache(array(__METHOD__, $string), function() use ($string) {
return trim(mb_strtolower(str_replace('__', '_', preg_replace('/([A-Z]{1})/', '_$1', preg_replace('/[^_a-z0-9]+/i', '', preg_replace('/[\s]+/', '_', $string))))), '_');
});
} | [
"public",
"static",
"function",
"underscore",
"(",
"$",
"string",
")",
"{",
"return",
"static",
"::",
"cache",
"(",
"array",
"(",
"__METHOD__",
",",
"$",
"string",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"string",
")",
"{",
"return",
"trim",
"(",
"mb_strtolower",
"(",
"str_replace",
"(",
"'__'",
",",
"'_'",
",",
"preg_replace",
"(",
"'/([A-Z]{1})/'",
",",
"'_$1'",
",",
"preg_replace",
"(",
"'/[^_a-z0-9]+/i'",
",",
"''",
",",
"preg_replace",
"(",
"'/[\\s]+/'",
",",
"'_'",
",",
"$",
"string",
")",
")",
")",
")",
")",
",",
"'_'",
")",
";",
"}",
")",
";",
"}"
] | Inflect a word to an underscore form that strips all punctuation and special characters and converts spaces to underscores.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"to",
"an",
"underscore",
"form",
"that",
"strips",
"all",
"punctuation",
"and",
"special",
"characters",
"and",
"converts",
"spaces",
"to",
"underscores",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L204-L208 | train |
vpg/titon.utility | src/Titon/Utility/Inflector.php | Inflector.variable | public static function variable($string) {
$string = preg_replace('/[^_a-z0-9]+/i', '', $string);
if (is_numeric(mb_substr($string, 0, 1))) {
$string = '_' . $string;
}
return $string;
} | php | public static function variable($string) {
$string = preg_replace('/[^_a-z0-9]+/i', '', $string);
if (is_numeric(mb_substr($string, 0, 1))) {
$string = '_' . $string;
}
return $string;
} | [
"public",
"static",
"function",
"variable",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"'/[^_a-z0-9]+/i'",
",",
"''",
",",
"$",
"string",
")",
";",
"if",
"(",
"is_numeric",
"(",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"1",
")",
")",
")",
"{",
"$",
"string",
"=",
"'_'",
".",
"$",
"string",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Inflect a word to be used as a PHP variable. Strip all but letters, numbers and underscores. Add an underscore if the first letter is numeric.
@param string $string
@return string | [
"Inflect",
"a",
"word",
"to",
"be",
"used",
"as",
"a",
"PHP",
"variable",
".",
"Strip",
"all",
"but",
"letters",
"numbers",
"and",
"underscores",
".",
"Add",
"an",
"underscore",
"if",
"the",
"first",
"letter",
"is",
"numeric",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Inflector.php#L216-L224 | train |
native5/native5-sdk-client-php | src/Native5/Route/DeviceDetection/UA.php | UA.parse | public static function parse($ua = NULL) {
self::$ua = $ua ? $ua : strip_tags($_SERVER["HTTP_USER_AGENT"]);
self::$accept = empty($_SERVER["HTTP_ACCEPT"]) ? '' : strip_tags($_SERVER["HTTP_ACCEPT"]);
if (empty(self::$regexes)) {
if (file_exists(__DIR__."/resources/regexes.yaml")) {
self::$regexes = Yaml::parse(__DIR__."/resources/regexes.yaml");
} else {
print "<h1>Error</h1>
<p>Please download the regexes.yaml file before using UAParser.php.</p>
<p>You can type the following at the command line to download the latest version:</p>
<blockquote>
<code>%: cd /path/to/UAParser</code><br />
<code>%: php UAParser.php -get</code>
</blockquote>";
exit;
}
}
// run the regexes to match things up
$uaRegexes = self::$regexes['user_agent_parsers'];
foreach ($uaRegexes as $uaRegex) {
if ($result = self::uaParser($uaRegex)) {
$result->uaOriginal = self::$ua;
break;
}
}
// if no browser was found check to see if it can be matched at least against a device (e.g. spider, generic feature phone or generic smartphone)
if (!$result) {
if (($result = self::deviceParser()) && ($result->device != 'Spider')) {
$result->isMobile = true;
$result->isMobileDevice = true;
$result->uaOriginal = self::$ua;
} else if (isset($result) && isset($result->device) && ($result->device == "Spider")) {
$result->isMobile = false;
$result->isSpider = true;
$result->uaOriginal = self::$ua;
}
}
// still false?! see if it's a really dumb feature phone, if not just mark it as unknown
if (!$result) {
if ((strpos(self::$accept,'text/vnd.wap.wml') > 0) || (strpos(self::$accept,'application/vnd.wap.xhtml+xml') > 0) || isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
$result = new \stdClass();
$result->device = "Generic Feature Phone";
$result->deviceFull = "Generic Feature Phone";
$result->isMobile = true;
$result->isMobileDevice = true;
$result->uaOriginal = self::$ua;
} else {
$result = new \stdClass();
$result->device = "Unknown";
$result->deviceFull = "Unknown";
$result->isMobile = false;
$result->isMobileDevice = false;
$result->isComputer = true;
$result->uaOriginal = self::$ua;
}
}
// log the results when testing
if (self::$debug) {
self::log($result);
}
return $result;
} | php | public static function parse($ua = NULL) {
self::$ua = $ua ? $ua : strip_tags($_SERVER["HTTP_USER_AGENT"]);
self::$accept = empty($_SERVER["HTTP_ACCEPT"]) ? '' : strip_tags($_SERVER["HTTP_ACCEPT"]);
if (empty(self::$regexes)) {
if (file_exists(__DIR__."/resources/regexes.yaml")) {
self::$regexes = Yaml::parse(__DIR__."/resources/regexes.yaml");
} else {
print "<h1>Error</h1>
<p>Please download the regexes.yaml file before using UAParser.php.</p>
<p>You can type the following at the command line to download the latest version:</p>
<blockquote>
<code>%: cd /path/to/UAParser</code><br />
<code>%: php UAParser.php -get</code>
</blockquote>";
exit;
}
}
// run the regexes to match things up
$uaRegexes = self::$regexes['user_agent_parsers'];
foreach ($uaRegexes as $uaRegex) {
if ($result = self::uaParser($uaRegex)) {
$result->uaOriginal = self::$ua;
break;
}
}
// if no browser was found check to see if it can be matched at least against a device (e.g. spider, generic feature phone or generic smartphone)
if (!$result) {
if (($result = self::deviceParser()) && ($result->device != 'Spider')) {
$result->isMobile = true;
$result->isMobileDevice = true;
$result->uaOriginal = self::$ua;
} else if (isset($result) && isset($result->device) && ($result->device == "Spider")) {
$result->isMobile = false;
$result->isSpider = true;
$result->uaOriginal = self::$ua;
}
}
// still false?! see if it's a really dumb feature phone, if not just mark it as unknown
if (!$result) {
if ((strpos(self::$accept,'text/vnd.wap.wml') > 0) || (strpos(self::$accept,'application/vnd.wap.xhtml+xml') > 0) || isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
$result = new \stdClass();
$result->device = "Generic Feature Phone";
$result->deviceFull = "Generic Feature Phone";
$result->isMobile = true;
$result->isMobileDevice = true;
$result->uaOriginal = self::$ua;
} else {
$result = new \stdClass();
$result->device = "Unknown";
$result->deviceFull = "Unknown";
$result->isMobile = false;
$result->isMobileDevice = false;
$result->isComputer = true;
$result->uaOriginal = self::$ua;
}
}
// log the results when testing
if (self::$debug) {
self::log($result);
}
return $result;
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"ua",
"=",
"NULL",
")",
"{",
"self",
"::",
"$",
"ua",
"=",
"$",
"ua",
"?",
"$",
"ua",
":",
"strip_tags",
"(",
"$",
"_SERVER",
"[",
"\"HTTP_USER_AGENT\"",
"]",
")",
";",
"self",
"::",
"$",
"accept",
"=",
"empty",
"(",
"$",
"_SERVER",
"[",
"\"HTTP_ACCEPT\"",
"]",
")",
"?",
"''",
":",
"strip_tags",
"(",
"$",
"_SERVER",
"[",
"\"HTTP_ACCEPT\"",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"regexes",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"__DIR__",
".",
"\"/resources/regexes.yaml\"",
")",
")",
"{",
"self",
"::",
"$",
"regexes",
"=",
"Yaml",
"::",
"parse",
"(",
"__DIR__",
".",
"\"/resources/regexes.yaml\"",
")",
";",
"}",
"else",
"{",
"print",
"\"<h1>Error</h1>\n <p>Please download the regexes.yaml file before using UAParser.php.</p>\n <p>You can type the following at the command line to download the latest version:</p>\n <blockquote>\n <code>%: cd /path/to/UAParser</code><br />\n <code>%: php UAParser.php -get</code>\n </blockquote>\"",
";",
"exit",
";",
"}",
"}",
"// run the regexes to match things up",
"$",
"uaRegexes",
"=",
"self",
"::",
"$",
"regexes",
"[",
"'user_agent_parsers'",
"]",
";",
"foreach",
"(",
"$",
"uaRegexes",
"as",
"$",
"uaRegex",
")",
"{",
"if",
"(",
"$",
"result",
"=",
"self",
"::",
"uaParser",
"(",
"$",
"uaRegex",
")",
")",
"{",
"$",
"result",
"->",
"uaOriginal",
"=",
"self",
"::",
"$",
"ua",
";",
"break",
";",
"}",
"}",
"// if no browser was found check to see if it can be matched at least against a device (e.g. spider, generic feature phone or generic smartphone)",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"if",
"(",
"(",
"$",
"result",
"=",
"self",
"::",
"deviceParser",
"(",
")",
")",
"&&",
"(",
"$",
"result",
"->",
"device",
"!=",
"'Spider'",
")",
")",
"{",
"$",
"result",
"->",
"isMobile",
"=",
"true",
";",
"$",
"result",
"->",
"isMobileDevice",
"=",
"true",
";",
"$",
"result",
"->",
"uaOriginal",
"=",
"self",
"::",
"$",
"ua",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"result",
")",
"&&",
"isset",
"(",
"$",
"result",
"->",
"device",
")",
"&&",
"(",
"$",
"result",
"->",
"device",
"==",
"\"Spider\"",
")",
")",
"{",
"$",
"result",
"->",
"isMobile",
"=",
"false",
";",
"$",
"result",
"->",
"isSpider",
"=",
"true",
";",
"$",
"result",
"->",
"uaOriginal",
"=",
"self",
"::",
"$",
"ua",
";",
"}",
"}",
"// still false?! see if it's a really dumb feature phone, if not just mark it as unknown",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"if",
"(",
"(",
"strpos",
"(",
"self",
"::",
"$",
"accept",
",",
"'text/vnd.wap.wml'",
")",
">",
"0",
")",
"||",
"(",
"strpos",
"(",
"self",
"::",
"$",
"accept",
",",
"'application/vnd.wap.xhtml+xml'",
")",
">",
"0",
")",
"||",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_WAP_PROFILE'",
"]",
")",
"||",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_PROFILE'",
"]",
")",
")",
"{",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"device",
"=",
"\"Generic Feature Phone\"",
";",
"$",
"result",
"->",
"deviceFull",
"=",
"\"Generic Feature Phone\"",
";",
"$",
"result",
"->",
"isMobile",
"=",
"true",
";",
"$",
"result",
"->",
"isMobileDevice",
"=",
"true",
";",
"$",
"result",
"->",
"uaOriginal",
"=",
"self",
"::",
"$",
"ua",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"device",
"=",
"\"Unknown\"",
";",
"$",
"result",
"->",
"deviceFull",
"=",
"\"Unknown\"",
";",
"$",
"result",
"->",
"isMobile",
"=",
"false",
";",
"$",
"result",
"->",
"isMobileDevice",
"=",
"false",
";",
"$",
"result",
"->",
"isComputer",
"=",
"true",
";",
"$",
"result",
"->",
"uaOriginal",
"=",
"self",
"::",
"$",
"ua",
";",
"}",
"}",
"// log the results when testing",
"if",
"(",
"self",
"::",
"$",
"debug",
")",
"{",
"self",
"::",
"log",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Sets up some standard variables as well as starts the user agent parsing process
@return {Object} the result of the user agent parsing | [
"Sets",
"up",
"some",
"standard",
"variables",
"as",
"well",
"as",
"starts",
"the",
"user",
"agent",
"parsing",
"process"
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Route/DeviceDetection/UA.php#L52-L120 | train |
native5/native5-sdk-client-php | src/Native5/Route/DeviceDetection/UA.php | UA.log | private static function log($data) {
if (!$data) {
$data = new \stdClass();
$data->ua = self::$ua;
}
$jsonData = json_encode($data);
echo $jsonData."\r\n";
//$fp = fopen(__DIR__."/log/user_agents.log", "a");
//fwrite($fp, $jsonData."\r\n");
//fclose($fp);
} | php | private static function log($data) {
if (!$data) {
$data = new \stdClass();
$data->ua = self::$ua;
}
$jsonData = json_encode($data);
echo $jsonData."\r\n";
//$fp = fopen(__DIR__."/log/user_agents.log", "a");
//fwrite($fp, $jsonData."\r\n");
//fclose($fp);
} | [
"private",
"static",
"function",
"log",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"ua",
"=",
"self",
"::",
"$",
"ua",
";",
"}",
"$",
"jsonData",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"echo",
"$",
"jsonData",
".",
"\"\\r\\n\"",
";",
"//$fp = fopen(__DIR__.\"/log/user_agents.log\", \"a\");",
"//fwrite($fp, $jsonData.\"\\r\\n\");",
"//fclose($fp);",
"}"
] | Logs the user agent info | [
"Logs",
"the",
"user",
"agent",
"info"
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Route/DeviceDetection/UA.php#L365-L375 | train |
native5/native5-sdk-client-php | src/Native5/Route/DeviceDetection/UA.php | UA.get | public static function get() {
if ($data = @file_get_contents("https://raw.github.com/tobie/ua-parser/master/regexes.yaml")) {
if (file_exists(__DIR__."/resources/regexes.yaml")) {
if (!self::$nobackup) {
if (!self::$silent) { print("backing up old YAML file...\n"); }
if (!copy(__DIR__."/resources/regexes.yaml", __DIR__."/resources/regexes.".date("Ymdhis").".yaml")) {
if (!self::$silent) { print("back-up failed...\n"); }
exit;
}
}
}
$fp = fopen(__DIR__."/resources/regexes.yaml", "w");
fwrite($fp, $data);
fclose($fp);
if (!self::$silent) { print("success...\n"); }
} else {
if (!self::$silent) { print("failed to get the file...\n"); }
}
} | php | public static function get() {
if ($data = @file_get_contents("https://raw.github.com/tobie/ua-parser/master/regexes.yaml")) {
if (file_exists(__DIR__."/resources/regexes.yaml")) {
if (!self::$nobackup) {
if (!self::$silent) { print("backing up old YAML file...\n"); }
if (!copy(__DIR__."/resources/regexes.yaml", __DIR__."/resources/regexes.".date("Ymdhis").".yaml")) {
if (!self::$silent) { print("back-up failed...\n"); }
exit;
}
}
}
$fp = fopen(__DIR__."/resources/regexes.yaml", "w");
fwrite($fp, $data);
fclose($fp);
if (!self::$silent) { print("success...\n"); }
} else {
if (!self::$silent) { print("failed to get the file...\n"); }
}
} | [
"public",
"static",
"function",
"get",
"(",
")",
"{",
"if",
"(",
"$",
"data",
"=",
"@",
"file_get_contents",
"(",
"\"https://raw.github.com/tobie/ua-parser/master/regexes.yaml\"",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"__DIR__",
".",
"\"/resources/regexes.yaml\"",
")",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"nobackup",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"silent",
")",
"{",
"print",
"(",
"\"backing up old YAML file...\\n\"",
")",
";",
"}",
"if",
"(",
"!",
"copy",
"(",
"__DIR__",
".",
"\"/resources/regexes.yaml\"",
",",
"__DIR__",
".",
"\"/resources/regexes.\"",
".",
"date",
"(",
"\"Ymdhis\"",
")",
".",
"\".yaml\"",
")",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"silent",
")",
"{",
"print",
"(",
"\"back-up failed...\\n\"",
")",
";",
"}",
"exit",
";",
"}",
"}",
"}",
"$",
"fp",
"=",
"fopen",
"(",
"__DIR__",
".",
"\"/resources/regexes.yaml\"",
",",
"\"w\"",
")",
";",
"fwrite",
"(",
"$",
"fp",
",",
"$",
"data",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"silent",
")",
"{",
"print",
"(",
"\"success...\\n\"",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"silent",
")",
"{",
"print",
"(",
"\"failed to get the file...\\n\"",
")",
";",
"}",
"}",
"}"
] | Gets the latest user agent. Back-ups the old version first. it will fail silently if something is wrong... | [
"Gets",
"the",
"latest",
"user",
"agent",
".",
"Back",
"-",
"ups",
"the",
"old",
"version",
"first",
".",
"it",
"will",
"fail",
"silently",
"if",
"something",
"is",
"wrong",
"..."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Route/DeviceDetection/UA.php#L380-L398 | train |
Wedeto/DB | src/Query/SQLFunction.php | SQLFunction.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
$func = $this->getFunction();
$arguments = $this->getArguments();
$args = array();
foreach ($arguments as $arg)
$args[] = $params->getDriver()->toSQL($params, $arg, false);
return $func . '(' . implode(', ', $args) . ')';
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
$func = $this->getFunction();
$arguments = $this->getArguments();
$args = array();
foreach ($arguments as $arg)
$args[] = $params->getDriver()->toSQL($params, $arg, false);
return $func . '(' . implode(', ', $args) . ')';
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"$",
"func",
"=",
"$",
"this",
"->",
"getFunction",
"(",
")",
";",
"$",
"arguments",
"=",
"$",
"this",
"->",
"getArguments",
"(",
")",
";",
"$",
"args",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"arg",
")",
"$",
"args",
"[",
"]",
"=",
"$",
"params",
"->",
"getDriver",
"(",
")",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"arg",
",",
"false",
")",
";",
"return",
"$",
"func",
".",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"args",
")",
".",
"')'",
";",
"}"
] | Write a function as SQL query syntax
@param Parameters $params The query parameters: tables and placeholder values
@param SQLFunction $expression The function to write
@return string The generated SQL | [
"Write",
"a",
"function",
"as",
"SQL",
"query",
"syntax"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/SQLFunction.php#L65-L75 | train |
Kris-Kuiper/sFire-Framework | src/DB/ResultSet.php | ResultSet.current | public function current() {
$current = parent :: current();
if(null !== $current) {
if(false === is_string($current) && false === is_numeric($current) && true === $this -> is_multidimensional($current)) {
if($this -> convert !== self :: TYPE_ARRAY) {
return trigger_error(sprintf('Multidimensional Array can not be converted to "%s" type in "%s"', $this -> convert, __METHOD__), E_USER_ERROR);
}
return $current;
}
switch($this -> convert) {
case self :: TYPE_ARRAY:
return $current;
case self :: TYPE_OBJECT:
return (object) $current;
case self :: TYPE_JSON:
return json_encode($current);
default :
if(false === class_exists($this -> entity)) {
return trigger_error(sprintf('"%s" is not a valid type or Entity class file in %s', $type, __METHOD__), E_USER_ERROR);
}
$entity = new $this -> entity();
$entity -> setAdapter($this -> adapter);
$entity -> fromArray($current);
return $entity;
}
}
} | php | public function current() {
$current = parent :: current();
if(null !== $current) {
if(false === is_string($current) && false === is_numeric($current) && true === $this -> is_multidimensional($current)) {
if($this -> convert !== self :: TYPE_ARRAY) {
return trigger_error(sprintf('Multidimensional Array can not be converted to "%s" type in "%s"', $this -> convert, __METHOD__), E_USER_ERROR);
}
return $current;
}
switch($this -> convert) {
case self :: TYPE_ARRAY:
return $current;
case self :: TYPE_OBJECT:
return (object) $current;
case self :: TYPE_JSON:
return json_encode($current);
default :
if(false === class_exists($this -> entity)) {
return trigger_error(sprintf('"%s" is not a valid type or Entity class file in %s', $type, __METHOD__), E_USER_ERROR);
}
$entity = new $this -> entity();
$entity -> setAdapter($this -> adapter);
$entity -> fromArray($current);
return $entity;
}
}
} | [
"public",
"function",
"current",
"(",
")",
"{",
"$",
"current",
"=",
"parent",
"::",
"current",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"current",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"current",
")",
"&&",
"false",
"===",
"is_numeric",
"(",
"$",
"current",
")",
"&&",
"true",
"===",
"$",
"this",
"->",
"is_multidimensional",
"(",
"$",
"current",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"convert",
"!==",
"self",
"::",
"TYPE_ARRAY",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Multidimensional Array can not be converted to \"%s\" type in \"%s\"'",
",",
"$",
"this",
"->",
"convert",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"$",
"current",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"convert",
")",
"{",
"case",
"self",
"::",
"TYPE_ARRAY",
":",
"return",
"$",
"current",
";",
"case",
"self",
"::",
"TYPE_OBJECT",
":",
"return",
"(",
"object",
")",
"$",
"current",
";",
"case",
"self",
"::",
"TYPE_JSON",
":",
"return",
"json_encode",
"(",
"$",
"current",
")",
";",
"default",
":",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"this",
"->",
"entity",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'\"%s\" is not a valid type or Entity class file in %s'",
",",
"$",
"type",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"entity",
"=",
"new",
"$",
"this",
"->",
"entity",
"(",
")",
";",
"$",
"entity",
"->",
"setAdapter",
"(",
"$",
"this",
"->",
"adapter",
")",
";",
"$",
"entity",
"->",
"fromArray",
"(",
"$",
"current",
")",
";",
"return",
"$",
"entity",
";",
"}",
"}",
"}"
] | Converts current array element to entity when requested
@return mixed | [
"Converts",
"current",
"array",
"element",
"to",
"entity",
"when",
"requested"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/ResultSet.php#L85-L125 | train |
Kris-Kuiper/sFire-Framework | src/DB/ResultSet.php | ResultSet.pluck | public function pluck($column) {
$plucked = [];
while(parent :: valid()) {
$current = parent :: current();
if(true === is_array($column)) {
$tmp = $current;
$insert = true;
foreach($column as $index) {
if(false === isset($tmp[$index])) {
$insert = false;
break;
}
$tmp = $tmp[$index];
}
if(true === $insert) {
$plucked[] = $tmp;
}
}
if(true === isset($current[$column])) {
$plucked[] = $current[$column];
}
parent :: next();
}
switch($this -> convert) {
case self :: TYPE_ARRAY: return $plucked;
case self :: TYPE_OBJECT: return (object) $plucked;
case self :: TYPE_JSON: return json_encode($plucked);
}
} | php | public function pluck($column) {
$plucked = [];
while(parent :: valid()) {
$current = parent :: current();
if(true === is_array($column)) {
$tmp = $current;
$insert = true;
foreach($column as $index) {
if(false === isset($tmp[$index])) {
$insert = false;
break;
}
$tmp = $tmp[$index];
}
if(true === $insert) {
$plucked[] = $tmp;
}
}
if(true === isset($current[$column])) {
$plucked[] = $current[$column];
}
parent :: next();
}
switch($this -> convert) {
case self :: TYPE_ARRAY: return $plucked;
case self :: TYPE_OBJECT: return (object) $plucked;
case self :: TYPE_JSON: return json_encode($plucked);
}
} | [
"public",
"function",
"pluck",
"(",
"$",
"column",
")",
"{",
"$",
"plucked",
"=",
"[",
"]",
";",
"while",
"(",
"parent",
"::",
"valid",
"(",
")",
")",
"{",
"$",
"current",
"=",
"parent",
"::",
"current",
"(",
")",
";",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"$",
"tmp",
"=",
"$",
"current",
";",
"$",
"insert",
"=",
"true",
";",
"foreach",
"(",
"$",
"column",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"tmp",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"insert",
"=",
"false",
";",
"break",
";",
"}",
"$",
"tmp",
"=",
"$",
"tmp",
"[",
"$",
"index",
"]",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"insert",
")",
"{",
"$",
"plucked",
"[",
"]",
"=",
"$",
"tmp",
";",
"}",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"current",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"plucked",
"[",
"]",
"=",
"$",
"current",
"[",
"$",
"column",
"]",
";",
"}",
"parent",
"::",
"next",
"(",
")",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"convert",
")",
"{",
"case",
"self",
"::",
"TYPE_ARRAY",
":",
"return",
"$",
"plucked",
";",
"case",
"self",
"::",
"TYPE_OBJECT",
":",
"return",
"(",
"object",
")",
"$",
"plucked",
";",
"case",
"self",
"::",
"TYPE_JSON",
":",
"return",
"json_encode",
"(",
"$",
"plucked",
")",
";",
"}",
"}"
] | Plucks a column from a resultset
@param string|integer $column
@return new sFire\DB\Resultset | [
"Plucks",
"a",
"column",
"from",
"a",
"resultset"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/ResultSet.php#L133-L175 | train |
Kris-Kuiper/sFire-Framework | src/DB/ResultSet.php | ResultSet.is_multidimensional | private function is_multidimensional($array) {
if(false === is_array($array)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Array, "%s" given', __METHOD__, gettype($array)), E_USER_ERROR);
}
return (count(array_filter($array, 'is_array')) > 0);
} | php | private function is_multidimensional($array) {
if(false === is_array($array)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Array, "%s" given', __METHOD__, gettype($array)), E_USER_ERROR);
}
return (count(array_filter($array, 'is_array')) > 0);
} | [
"private",
"function",
"is_multidimensional",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type Array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"array",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"(",
"count",
"(",
"array_filter",
"(",
"$",
"array",
",",
"'is_array'",
")",
")",
">",
"0",
")",
";",
"}"
] | Returns if an Array is multidimensional
@param Array $array
@return boolean | [
"Returns",
"if",
"an",
"Array",
"is",
"multidimensional"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/ResultSet.php#L183-L190 | train |
SlaxWeb/Config | src/Factory.php | Factory.init | public static function init(string $handlerType, array $resLocations): Container
{
switch (strtolower($handlerType)) {
case Config::PHP_CONFIG_HANDLER:
$handler = new PhpHandler($resLocations);
break;
case Config::XML_CONFIG_HANDLER:
$xml = new \Desperado\XmlBundle\Model\XmlReader;
$handler = new XmlHandler($resLocations, $xml);
break;
case Config::YAML_CONFIG_HANDLER:
$handler = new YamlHandler($resLocations);
break;
default:
throw new Exception\InvalidHandlerTypeException(
"Handler type must be one of ['php', 'xml', 'yaml']"
);
}
return new Container($handler);
} | php | public static function init(string $handlerType, array $resLocations): Container
{
switch (strtolower($handlerType)) {
case Config::PHP_CONFIG_HANDLER:
$handler = new PhpHandler($resLocations);
break;
case Config::XML_CONFIG_HANDLER:
$xml = new \Desperado\XmlBundle\Model\XmlReader;
$handler = new XmlHandler($resLocations, $xml);
break;
case Config::YAML_CONFIG_HANDLER:
$handler = new YamlHandler($resLocations);
break;
default:
throw new Exception\InvalidHandlerTypeException(
"Handler type must be one of ['php', 'xml', 'yaml']"
);
}
return new Container($handler);
} | [
"public",
"static",
"function",
"init",
"(",
"string",
"$",
"handlerType",
",",
"array",
"$",
"resLocations",
")",
":",
"Container",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"handlerType",
")",
")",
"{",
"case",
"Config",
"::",
"PHP_CONFIG_HANDLER",
":",
"$",
"handler",
"=",
"new",
"PhpHandler",
"(",
"$",
"resLocations",
")",
";",
"break",
";",
"case",
"Config",
"::",
"XML_CONFIG_HANDLER",
":",
"$",
"xml",
"=",
"new",
"\\",
"Desperado",
"\\",
"XmlBundle",
"\\",
"Model",
"\\",
"XmlReader",
";",
"$",
"handler",
"=",
"new",
"XmlHandler",
"(",
"$",
"resLocations",
",",
"$",
"xml",
")",
";",
"break",
";",
"case",
"Config",
"::",
"YAML_CONFIG_HANDLER",
":",
"$",
"handler",
"=",
"new",
"YamlHandler",
"(",
"$",
"resLocations",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"\\",
"InvalidHandlerTypeException",
"(",
"\"Handler type must be one of ['php', 'xml', 'yaml']\"",
")",
";",
"}",
"return",
"new",
"Container",
"(",
"$",
"handler",
")",
";",
"}"
] | Instantiate Config class
Instantiate the configuration handler, pass it to the Config class when
instantiating it, and return its object.
@param string $handlerType Type of handler to use
@param array $resLocations Locations of configuration resource
@return \SlaxWeb\Config\Container | [
"Instantiate",
"Config",
"class"
] | 92e75c3538d3903e00f5c52507bc0a322c4d1f11 | https://github.com/SlaxWeb/Config/blob/92e75c3538d3903e00f5c52507bc0a322c4d1f11/src/Factory.php#L28-L48 | train |
native5/native5-sdk-client-php | src/Native5/Route/DeviceDetection/DeviceManager.php | DeviceManager.determineCategory | public function determineCategory($userAgent = null, $defaultGrade = Grades::UNSUPPORTED) {
$logger = $GLOBALS['logger'];
$app = $GLOBALS['app'];
$parsedUA = UA::parse($userAgent);
if (!empty($app) && !$app->getConfiguration()->isLocal()) {
try {
$logger->info('Attempting device lookup in database');
$browser = $this->_lookupDB($parsedUA);
return $this->_computeCategory($browser);
} catch (\Exception $ex) {
$logger->info("No device database found, defaulting to local file based detection");
$browser = $this->_lookupLocal($parsedUA, $defaultGrade);
return $this->_computeCategory($browser);
}
} else {
//$logger->info("Local environment, defaulting to local file based detection");
$browser = $this->_lookupLocal($parsedUA, $defaultGrade);
return $this->_computeCategory($browser);
}
} | php | public function determineCategory($userAgent = null, $defaultGrade = Grades::UNSUPPORTED) {
$logger = $GLOBALS['logger'];
$app = $GLOBALS['app'];
$parsedUA = UA::parse($userAgent);
if (!empty($app) && !$app->getConfiguration()->isLocal()) {
try {
$logger->info('Attempting device lookup in database');
$browser = $this->_lookupDB($parsedUA);
return $this->_computeCategory($browser);
} catch (\Exception $ex) {
$logger->info("No device database found, defaulting to local file based detection");
$browser = $this->_lookupLocal($parsedUA, $defaultGrade);
return $this->_computeCategory($browser);
}
} else {
//$logger->info("Local environment, defaulting to local file based detection");
$browser = $this->_lookupLocal($parsedUA, $defaultGrade);
return $this->_computeCategory($browser);
}
} | [
"public",
"function",
"determineCategory",
"(",
"$",
"userAgent",
"=",
"null",
",",
"$",
"defaultGrade",
"=",
"Grades",
"::",
"UNSUPPORTED",
")",
"{",
"$",
"logger",
"=",
"$",
"GLOBALS",
"[",
"'logger'",
"]",
";",
"$",
"app",
"=",
"$",
"GLOBALS",
"[",
"'app'",
"]",
";",
"$",
"parsedUA",
"=",
"UA",
"::",
"parse",
"(",
"$",
"userAgent",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"app",
")",
"&&",
"!",
"$",
"app",
"->",
"getConfiguration",
"(",
")",
"->",
"isLocal",
"(",
")",
")",
"{",
"try",
"{",
"$",
"logger",
"->",
"info",
"(",
"'Attempting device lookup in database'",
")",
";",
"$",
"browser",
"=",
"$",
"this",
"->",
"_lookupDB",
"(",
"$",
"parsedUA",
")",
";",
"return",
"$",
"this",
"->",
"_computeCategory",
"(",
"$",
"browser",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"logger",
"->",
"info",
"(",
"\"No device database found, defaulting to local file based detection\"",
")",
";",
"$",
"browser",
"=",
"$",
"this",
"->",
"_lookupLocal",
"(",
"$",
"parsedUA",
",",
"$",
"defaultGrade",
")",
";",
"return",
"$",
"this",
"->",
"_computeCategory",
"(",
"$",
"browser",
")",
";",
"}",
"}",
"else",
"{",
"//$logger->info(\"Local environment, defaulting to local file based detection\");",
"$",
"browser",
"=",
"$",
"this",
"->",
"_lookupLocal",
"(",
"$",
"parsedUA",
",",
"$",
"defaultGrade",
")",
";",
"return",
"$",
"this",
"->",
"_computeCategory",
"(",
"$",
"browser",
")",
";",
"}",
"}"
] | Categorize Incoming Request
@access public
@return category of request, typically of the order M00X. | [
"Categorize",
"Incoming",
"Request"
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Route/DeviceDetection/DeviceManager.php#L53-L72 | train |
native5/native5-sdk-client-php | src/Native5/Route/DeviceDetection/DeviceManager.php | DeviceManager._lookupLocal | private function _lookupLocal($ua, $defaultGrade)
{
$logger = $GLOBALS['logger'];
$browser = new Browser();
$gradePrefix = 'X';
$gradeSuffix = Grades::UNSUPPORTED;
if (($ua->isMobile || $ua->isMobileDevice) && $ua->isTablet) {
$gradePrefix = DeviceTypes::TABLET;
$gradeSuffix == Grades::_001;
} else if (($ua->isMobile || $ua->isMobileDevice)) {
$gradePrefix = DeviceTypes::MOBILE;
//$logger->info(print_r($ua->os." : ".$ua->osMajor.$ua->osMinor,1));
switch($ua->os) {
case "Android" :
if (intval($ua->osMajor) >= 4) {
$gradeSuffix = Grades::_201;
} else {
$gradeSuffix = Grades::_210;
}
break;
case "iOS" :
if (intval($ua->osMajor) >= 4 && intval($ua->osMinor >= 2)) {
$gradeSuffix = Grades::_101;
} else {
$gradeSuffix = Grades::_110;
}
break;
case "Windows Phone" :
if (intval($ua->osMajor) >= 8) {
$gradeSuffix = Grades::_301;
} else if (intval($ua->osMajor) >= 7 && intval($ua->osMinor) >= 5) {
$gradeSuffix = Grades::_320;
}
break;
default :
$gradeSuffix = Grades::_400;
break;
}
} else {
$gradePrefix = DeviceTypes::DESKTOP;
$gradeSuffix = Grades::_001;
}
$browser->setGrade($gradePrefix.$gradeSuffix);
return $browser;
} | php | private function _lookupLocal($ua, $defaultGrade)
{
$logger = $GLOBALS['logger'];
$browser = new Browser();
$gradePrefix = 'X';
$gradeSuffix = Grades::UNSUPPORTED;
if (($ua->isMobile || $ua->isMobileDevice) && $ua->isTablet) {
$gradePrefix = DeviceTypes::TABLET;
$gradeSuffix == Grades::_001;
} else if (($ua->isMobile || $ua->isMobileDevice)) {
$gradePrefix = DeviceTypes::MOBILE;
//$logger->info(print_r($ua->os." : ".$ua->osMajor.$ua->osMinor,1));
switch($ua->os) {
case "Android" :
if (intval($ua->osMajor) >= 4) {
$gradeSuffix = Grades::_201;
} else {
$gradeSuffix = Grades::_210;
}
break;
case "iOS" :
if (intval($ua->osMajor) >= 4 && intval($ua->osMinor >= 2)) {
$gradeSuffix = Grades::_101;
} else {
$gradeSuffix = Grades::_110;
}
break;
case "Windows Phone" :
if (intval($ua->osMajor) >= 8) {
$gradeSuffix = Grades::_301;
} else if (intval($ua->osMajor) >= 7 && intval($ua->osMinor) >= 5) {
$gradeSuffix = Grades::_320;
}
break;
default :
$gradeSuffix = Grades::_400;
break;
}
} else {
$gradePrefix = DeviceTypes::DESKTOP;
$gradeSuffix = Grades::_001;
}
$browser->setGrade($gradePrefix.$gradeSuffix);
return $browser;
} | [
"private",
"function",
"_lookupLocal",
"(",
"$",
"ua",
",",
"$",
"defaultGrade",
")",
"{",
"$",
"logger",
"=",
"$",
"GLOBALS",
"[",
"'logger'",
"]",
";",
"$",
"browser",
"=",
"new",
"Browser",
"(",
")",
";",
"$",
"gradePrefix",
"=",
"'X'",
";",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"UNSUPPORTED",
";",
"if",
"(",
"(",
"$",
"ua",
"->",
"isMobile",
"||",
"$",
"ua",
"->",
"isMobileDevice",
")",
"&&",
"$",
"ua",
"->",
"isTablet",
")",
"{",
"$",
"gradePrefix",
"=",
"DeviceTypes",
"::",
"TABLET",
";",
"$",
"gradeSuffix",
"==",
"Grades",
"::",
"_001",
";",
"}",
"else",
"if",
"(",
"(",
"$",
"ua",
"->",
"isMobile",
"||",
"$",
"ua",
"->",
"isMobileDevice",
")",
")",
"{",
"$",
"gradePrefix",
"=",
"DeviceTypes",
"::",
"MOBILE",
";",
"//$logger->info(print_r($ua->os.\" : \".$ua->osMajor.$ua->osMinor,1));",
"switch",
"(",
"$",
"ua",
"->",
"os",
")",
"{",
"case",
"\"Android\"",
":",
"if",
"(",
"intval",
"(",
"$",
"ua",
"->",
"osMajor",
")",
">=",
"4",
")",
"{",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_201",
";",
"}",
"else",
"{",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_210",
";",
"}",
"break",
";",
"case",
"\"iOS\"",
":",
"if",
"(",
"intval",
"(",
"$",
"ua",
"->",
"osMajor",
")",
">=",
"4",
"&&",
"intval",
"(",
"$",
"ua",
"->",
"osMinor",
">=",
"2",
")",
")",
"{",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_101",
";",
"}",
"else",
"{",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_110",
";",
"}",
"break",
";",
"case",
"\"Windows Phone\"",
":",
"if",
"(",
"intval",
"(",
"$",
"ua",
"->",
"osMajor",
")",
">=",
"8",
")",
"{",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_301",
";",
"}",
"else",
"if",
"(",
"intval",
"(",
"$",
"ua",
"->",
"osMajor",
")",
">=",
"7",
"&&",
"intval",
"(",
"$",
"ua",
"->",
"osMinor",
")",
">=",
"5",
")",
"{",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_320",
";",
"}",
"break",
";",
"default",
":",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_400",
";",
"break",
";",
"}",
"}",
"else",
"{",
"$",
"gradePrefix",
"=",
"DeviceTypes",
"::",
"DESKTOP",
";",
"$",
"gradeSuffix",
"=",
"Grades",
"::",
"_001",
";",
"}",
"$",
"browser",
"->",
"setGrade",
"(",
"$",
"gradePrefix",
".",
"$",
"gradeSuffix",
")",
";",
"return",
"$",
"browser",
";",
"}"
] | Lookup Device Detection based on File.
@param mixed $ua The user agent.
@access private
@return void | [
"Lookup",
"Device",
"Detection",
"based",
"on",
"File",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Route/DeviceDetection/DeviceManager.php#L83-L128 | train |
native5/native5-sdk-client-php | src/Native5/Route/DeviceDetection/DeviceManager.php | DeviceManager._lookupDB | private function _lookupDB($ua)
{
$browser = new Browser();
$browser->setGrade(Grades::UNSUPPORTED);
$conn = new \Mongo('mongodb://'.DeviceManager::HOST);
$collection = $conn->selectDB(DeviceManager::DB)->devices;
// Determine Regex fitting the U/A Category.
$pattern = $this->_getMatchingRegex($ua);
$uaRegex = new \MongoRegex($pattern);
//$device = $collection->findOne(array("userAgent"=>$nameRegex));
// Match User Agent independent of OS Version, Check OS Version >= Base Matching Version
$device = $collection->findOne(
array (
'$and'=>array (
array ("userAgent"=>$uaRegex),
array ('$or'=> array(
array("device.os.version"=>array('$exists'=>false)),
array("device.os.version"=>array('$lte'=>"".$ua->osVersion))
))
)
)
);
if (!empty($device)) {
$browser = $this->_createBrowser($device);
} else {
// TODO : Request for Browser Categorization
}
return $browser;
} | php | private function _lookupDB($ua)
{
$browser = new Browser();
$browser->setGrade(Grades::UNSUPPORTED);
$conn = new \Mongo('mongodb://'.DeviceManager::HOST);
$collection = $conn->selectDB(DeviceManager::DB)->devices;
// Determine Regex fitting the U/A Category.
$pattern = $this->_getMatchingRegex($ua);
$uaRegex = new \MongoRegex($pattern);
//$device = $collection->findOne(array("userAgent"=>$nameRegex));
// Match User Agent independent of OS Version, Check OS Version >= Base Matching Version
$device = $collection->findOne(
array (
'$and'=>array (
array ("userAgent"=>$uaRegex),
array ('$or'=> array(
array("device.os.version"=>array('$exists'=>false)),
array("device.os.version"=>array('$lte'=>"".$ua->osVersion))
))
)
)
);
if (!empty($device)) {
$browser = $this->_createBrowser($device);
} else {
// TODO : Request for Browser Categorization
}
return $browser;
} | [
"private",
"function",
"_lookupDB",
"(",
"$",
"ua",
")",
"{",
"$",
"browser",
"=",
"new",
"Browser",
"(",
")",
";",
"$",
"browser",
"->",
"setGrade",
"(",
"Grades",
"::",
"UNSUPPORTED",
")",
";",
"$",
"conn",
"=",
"new",
"\\",
"Mongo",
"(",
"'mongodb://'",
".",
"DeviceManager",
"::",
"HOST",
")",
";",
"$",
"collection",
"=",
"$",
"conn",
"->",
"selectDB",
"(",
"DeviceManager",
"::",
"DB",
")",
"->",
"devices",
";",
"// Determine Regex fitting the U/A Category. ",
"$",
"pattern",
"=",
"$",
"this",
"->",
"_getMatchingRegex",
"(",
"$",
"ua",
")",
";",
"$",
"uaRegex",
"=",
"new",
"\\",
"MongoRegex",
"(",
"$",
"pattern",
")",
";",
"//$device = $collection->findOne(array(\"userAgent\"=>$nameRegex));",
"// Match User Agent independent of OS Version, Check OS Version >= Base Matching Version",
"$",
"device",
"=",
"$",
"collection",
"->",
"findOne",
"(",
"array",
"(",
"'$and'",
"=>",
"array",
"(",
"array",
"(",
"\"userAgent\"",
"=>",
"$",
"uaRegex",
")",
",",
"array",
"(",
"'$or'",
"=>",
"array",
"(",
"array",
"(",
"\"device.os.version\"",
"=>",
"array",
"(",
"'$exists'",
"=>",
"false",
")",
")",
",",
"array",
"(",
"\"device.os.version\"",
"=>",
"array",
"(",
"'$lte'",
"=>",
"\"\"",
".",
"$",
"ua",
"->",
"osVersion",
")",
")",
")",
")",
")",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"device",
")",
")",
"{",
"$",
"browser",
"=",
"$",
"this",
"->",
"_createBrowser",
"(",
"$",
"device",
")",
";",
"}",
"else",
"{",
"// TODO : Request for Browser Categorization ",
"}",
"return",
"$",
"browser",
";",
"}"
] | Finds closest match given the user agent
@param mixed $ua : User Agent Object parsed using UA
@access private
@return void | [
"Finds",
"closest",
"match",
"given",
"the",
"user",
"agent"
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Route/DeviceDetection/DeviceManager.php#L139-L171 | train |
OliverMonneke/pennePHP | src/Datatype/Number.php | Number.random | public static function random($min, $max = null)
{
if (String::isEmpty($max) ||
$max > getrandmax()) {
$max = getrandmax();
}
return rand($min, $max);
} | php | public static function random($min, $max = null)
{
if (String::isEmpty($max) ||
$max > getrandmax()) {
$max = getrandmax();
}
return rand($min, $max);
} | [
"public",
"static",
"function",
"random",
"(",
"$",
"min",
",",
"$",
"max",
"=",
"null",
")",
"{",
"if",
"(",
"String",
"::",
"isEmpty",
"(",
"$",
"max",
")",
"||",
"$",
"max",
">",
"getrandmax",
"(",
")",
")",
"{",
"$",
"max",
"=",
"getrandmax",
"(",
")",
";",
"}",
"return",
"rand",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
] | Generate random number
@param int $min Minimum value
@param int $max Maximum value
@return int | [
"Generate",
"random",
"number"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/Number.php#L210-L218 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PostUpdates.php | PostUpdates.postIdOfPostupdate | public function postIdOfPostupdate($id)
{
// $record is a stdClass
$record = DB::table('postupdates')
->select('post_id')
->where('id', '=', $id)
->first()
;
return $record->post_id;
} | php | public function postIdOfPostupdate($id)
{
// $record is a stdClass
$record = DB::table('postupdates')
->select('post_id')
->where('id', '=', $id)
->first()
;
return $record->post_id;
} | [
"public",
"function",
"postIdOfPostupdate",
"(",
"$",
"id",
")",
"{",
"// $record is a stdClass",
"$",
"record",
"=",
"DB",
"::",
"table",
"(",
"'postupdates'",
")",
"->",
"select",
"(",
"'post_id'",
")",
"->",
"where",
"(",
"'id'",
",",
"'='",
",",
"$",
"id",
")",
"->",
"first",
"(",
")",
";",
"return",
"$",
"record",
"->",
"post_id",
";",
"}"
] | What is the post_id of a given postupdate?
@param int $id The ID of a postupdate
@return mixed | [
"What",
"is",
"the",
"post_id",
"of",
"a",
"given",
"postupdate?"
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PostUpdates.php#L71-L81 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PostUpdates.php | PostUpdates.postupdateNotExist | public function postupdateNotExist($post_id)
{
if ($this->countPostUpdates($post_id) == 0)
{
DB::table('posts')
->where('id', '=', $post_id)
->update(['postupdate' => 0])
;
}
} | php | public function postupdateNotExist($post_id)
{
if ($this->countPostUpdates($post_id) == 0)
{
DB::table('posts')
->where('id', '=', $post_id)
->update(['postupdate' => 0])
;
}
} | [
"public",
"function",
"postupdateNotExist",
"(",
"$",
"post_id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"countPostUpdates",
"(",
"$",
"post_id",
")",
"==",
"0",
")",
"{",
"DB",
"::",
"table",
"(",
"'posts'",
")",
"->",
"where",
"(",
"'id'",
",",
"'='",
",",
"$",
"post_id",
")",
"->",
"update",
"(",
"[",
"'postupdate'",
"=>",
"0",
"]",
")",
";",
"}",
"}"
] | When a post update is deleted, and no more post updates exist for that post, then update the
POSTS table to indicate that no post updates for that post exist.
@param int $post_id The ID of the post that the post update pertains.
@return void | [
"When",
"a",
"post",
"update",
"is",
"deleted",
"and",
"no",
"more",
"post",
"updates",
"exist",
"for",
"that",
"post",
"then",
"update",
"the",
"POSTS",
"table",
"to",
"indicate",
"that",
"no",
"post",
"updates",
"for",
"that",
"post",
"exist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PostUpdates.php#L91-L100 | train |
dmitrya2e/filtration-bundle | Filter/Filter/AbstractFilter.php | AbstractFilter.hasAppliedValue | public function hasAppliedValue()
{
$customFunction = $this->getHasAppliedValueFunction();
if (is_callable($customFunction)) {
$result = call_user_func($customFunction, $this);
if (!is_bool($result)) {
throw new FilterException('Returned value from callable function must be boolean.');
}
return $result;
}
$convertedValue = $this->getConvertedValue();
if (is_array($convertedValue)) {
return count($convertedValue) > 0;
}
if (is_string($convertedValue)) {
return $convertedValue !== '';
}
// Fallback to empty() function by default.
// If the value is int/float and it is equal to 0, it will be considered that the value has not been applied.
// To change this behaviour, please override this method.
return !empty($convertedValue);
} | php | public function hasAppliedValue()
{
$customFunction = $this->getHasAppliedValueFunction();
if (is_callable($customFunction)) {
$result = call_user_func($customFunction, $this);
if (!is_bool($result)) {
throw new FilterException('Returned value from callable function must be boolean.');
}
return $result;
}
$convertedValue = $this->getConvertedValue();
if (is_array($convertedValue)) {
return count($convertedValue) > 0;
}
if (is_string($convertedValue)) {
return $convertedValue !== '';
}
// Fallback to empty() function by default.
// If the value is int/float and it is equal to 0, it will be considered that the value has not been applied.
// To change this behaviour, please override this method.
return !empty($convertedValue);
} | [
"public",
"function",
"hasAppliedValue",
"(",
")",
"{",
"$",
"customFunction",
"=",
"$",
"this",
"->",
"getHasAppliedValueFunction",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"customFunction",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func",
"(",
"$",
"customFunction",
",",
"$",
"this",
")",
";",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"FilterException",
"(",
"'Returned value from callable function must be boolean.'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"$",
"convertedValue",
"=",
"$",
"this",
"->",
"getConvertedValue",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"convertedValue",
")",
")",
"{",
"return",
"count",
"(",
"$",
"convertedValue",
")",
">",
"0",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"convertedValue",
")",
")",
"{",
"return",
"$",
"convertedValue",
"!==",
"''",
";",
"}",
"// Fallback to empty() function by default.\r",
"// If the value is int/float and it is equal to 0, it will be considered that the value has not been applied.\r",
"// To change this behaviour, please override this method.\r",
"return",
"!",
"empty",
"(",
"$",
"convertedValue",
")",
";",
"}"
] | Checks if the filter value was applied.
Note, that the converted value is used for checking.
If there is a custom function for checking if the filter value is applied,
it will be executed instead of default checking.
Note, that custom function must return boolean result of checking if the filter value has been applied.
@see AbstractFilter::getConvertedValue()
@see AbstractFilter::getHasAppliedValueFunction() for custom function for checking if the filter value is applied
@return bool
@throws FilterException On invalid custom function returned value | [
"Checks",
"if",
"the",
"filter",
"value",
"was",
"applied",
".",
"Note",
"that",
"the",
"converted",
"value",
"is",
"used",
"for",
"checking",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractFilter.php#L358-L386 | train |
dmitrya2e/filtration-bundle | Filter/Filter/AbstractFilter.php | AbstractFilter.setApplyFilterFunction | public function setApplyFilterFunction(callable $function)
{
$validator = $this->getCallableValidatorApplyFilters();
$validator->setCallableFunction($function);
if ($validator->isValid() === false) {
throw $validator->getException();
}
$this->applyFilterFunction = $function;
return $this;
} | php | public function setApplyFilterFunction(callable $function)
{
$validator = $this->getCallableValidatorApplyFilters();
$validator->setCallableFunction($function);
if ($validator->isValid() === false) {
throw $validator->getException();
}
$this->applyFilterFunction = $function;
return $this;
} | [
"public",
"function",
"setApplyFilterFunction",
"(",
"callable",
"$",
"function",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
"->",
"getCallableValidatorApplyFilters",
"(",
")",
";",
"$",
"validator",
"->",
"setCallableFunction",
"(",
"$",
"function",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"isValid",
"(",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"validator",
"->",
"getException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"applyFilterFunction",
"=",
"$",
"function",
";",
"return",
"$",
"this",
";",
"}"
] | Sets custom "apply filter" function.
@param callable $function
@see ApplyFiltersFunctionValidator
@return static
@throws CallableFunctionValidatorException On invalid callable arguments | [
"Sets",
"custom",
"apply",
"filter",
"function",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractFilter.php#L556-L568 | train |
dmitrya2e/filtration-bundle | Filter/Filter/AbstractFilter.php | AbstractFilter.setAppendFormFieldsFunction | public function setAppendFormFieldsFunction(callable $function)
{
$validator = $this->getCallableValidatorAppendFormFields();
$validator->setCallableFunction($function);
if ($validator->isValid() === false) {
throw $validator->getException();
}
$this->appendFormFieldsFunction = $function;
return $this;
} | php | public function setAppendFormFieldsFunction(callable $function)
{
$validator = $this->getCallableValidatorAppendFormFields();
$validator->setCallableFunction($function);
if ($validator->isValid() === false) {
throw $validator->getException();
}
$this->appendFormFieldsFunction = $function;
return $this;
} | [
"public",
"function",
"setAppendFormFieldsFunction",
"(",
"callable",
"$",
"function",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
"->",
"getCallableValidatorAppendFormFields",
"(",
")",
";",
"$",
"validator",
"->",
"setCallableFunction",
"(",
"$",
"function",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"isValid",
"(",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"validator",
"->",
"getException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"appendFormFieldsFunction",
"=",
"$",
"function",
";",
"return",
"$",
"this",
";",
"}"
] | Sets custom "append form fields" function.
@param callable $function
@see AppendFormFieldsFunctionValidator
@return static
@throws CallableFunctionValidatorException On invalid callable arguments | [
"Sets",
"custom",
"append",
"form",
"fields",
"function",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractFilter.php#L590-L602 | train |
dmitrya2e/filtration-bundle | Filter/Filter/AbstractFilter.php | AbstractFilter.setConvertValueFunction | public function setConvertValueFunction(callable $function)
{
$validator = $this->getCallableValidatorConvertValue();
$validator->setCallableFunction($function);
if ($validator->isValid() === false) {
throw $validator->getException();
}
$this->convertValueFunction = $function;
return $this;
} | php | public function setConvertValueFunction(callable $function)
{
$validator = $this->getCallableValidatorConvertValue();
$validator->setCallableFunction($function);
if ($validator->isValid() === false) {
throw $validator->getException();
}
$this->convertValueFunction = $function;
return $this;
} | [
"public",
"function",
"setConvertValueFunction",
"(",
"callable",
"$",
"function",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
"->",
"getCallableValidatorConvertValue",
"(",
")",
";",
"$",
"validator",
"->",
"setCallableFunction",
"(",
"$",
"function",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"isValid",
"(",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"validator",
"->",
"getException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"convertValueFunction",
"=",
"$",
"function",
";",
"return",
"$",
"this",
";",
"}"
] | Sets custom "convert value" function.
@param callable $function
@see ConvertValueFunctionValidator
@return static
@throws CallableFunctionValidatorException On invalid callable arguments | [
"Sets",
"custom",
"convert",
"value",
"function",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractFilter.php#L624-L636 | train |
dmitrya2e/filtration-bundle | Filter/Filter/AbstractFilter.php | AbstractFilter.setValuePropertyName | public function setValuePropertyName($valuePropertyName)
{
if (!is_string($valuePropertyName) || $valuePropertyName === '') {
throw new InvalidArgumentException('"Value property name" argument must be a string and must not empty.');
}
if (!property_exists($this, $valuePropertyName)) {
throw new InvalidArgumentException(sprintf('Property "%s" does not exist.', $valuePropertyName));
}
$this->valuePropertyName = $valuePropertyName;
return $this;
} | php | public function setValuePropertyName($valuePropertyName)
{
if (!is_string($valuePropertyName) || $valuePropertyName === '') {
throw new InvalidArgumentException('"Value property name" argument must be a string and must not empty.');
}
if (!property_exists($this, $valuePropertyName)) {
throw new InvalidArgumentException(sprintf('Property "%s" does not exist.', $valuePropertyName));
}
$this->valuePropertyName = $valuePropertyName;
return $this;
} | [
"public",
"function",
"setValuePropertyName",
"(",
"$",
"valuePropertyName",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"valuePropertyName",
")",
"||",
"$",
"valuePropertyName",
"===",
"''",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'\"Value property name\" argument must be a string and must not empty.'",
")",
";",
"}",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"this",
",",
"$",
"valuePropertyName",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Property \"%s\" does not exist.'",
",",
"$",
"valuePropertyName",
")",
")",
";",
"}",
"$",
"this",
"->",
"valuePropertyName",
"=",
"$",
"valuePropertyName",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the name of the property which contains the raw value.
@param string $valuePropertyName
@return static
@throws InvalidArgumentException On invalid argument | [
"Sets",
"the",
"name",
"of",
"the",
"property",
"which",
"contains",
"the",
"raw",
"value",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractFilter.php#L734-L747 | train |
dmitrya2e/filtration-bundle | Filter/Filter/AbstractFilter.php | AbstractFilter.setFormFieldType | public function setFormFieldType($formFieldType)
{
if (!is_string($formFieldType) || $formFieldType === '') {
throw new InvalidArgumentException('"Form field type" argument must be a string and must not empty.');
}
$this->formFieldType = $formFieldType;
return $this;
} | php | public function setFormFieldType($formFieldType)
{
if (!is_string($formFieldType) || $formFieldType === '') {
throw new InvalidArgumentException('"Form field type" argument must be a string and must not empty.');
}
$this->formFieldType = $formFieldType;
return $this;
} | [
"public",
"function",
"setFormFieldType",
"(",
"$",
"formFieldType",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"formFieldType",
")",
"||",
"$",
"formFieldType",
"===",
"''",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'\"Form field type\" argument must be a string and must not empty.'",
")",
";",
"}",
"$",
"this",
"->",
"formFieldType",
"=",
"$",
"formFieldType",
";",
"return",
"$",
"this",
";",
"}"
] | Sets form field type.
@param string $formFieldType
@return static
@throws InvalidArgumentException On invalid argument | [
"Sets",
"form",
"field",
"type",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractFilter.php#L777-L786 | train |
itkg/core | src/Itkg/Core/Response/Processor/CompressProcessor.php | CompressProcessor.process | public function process(Response $response)
{
$content = preg_replace('/<!\-\-.[^(\-\-\>)]*?\-\->/i', '', $response->getContent());
$content = str_replace("\t", " ", $content);
$content = preg_replace('/(\s)\/\/(.*)(\s)/', '\\1/* \\2 */\\3', $content);
$search = array(
'/(\s+)?(\<.+\>)(\s+)?/',
'/(\s)+/s'
);
$replace = array(
'\\2',
'\\1'
);
$content = preg_replace($search, $replace, $content);
$content = str_replace("\n", "", $content);
$response->setContent($content);
} | php | public function process(Response $response)
{
$content = preg_replace('/<!\-\-.[^(\-\-\>)]*?\-\->/i', '', $response->getContent());
$content = str_replace("\t", " ", $content);
$content = preg_replace('/(\s)\/\/(.*)(\s)/', '\\1/* \\2 */\\3', $content);
$search = array(
'/(\s+)?(\<.+\>)(\s+)?/',
'/(\s)+/s'
);
$replace = array(
'\\2',
'\\1'
);
$content = preg_replace($search, $replace, $content);
$content = str_replace("\n", "", $content);
$response->setContent($content);
} | [
"public",
"function",
"process",
"(",
"Response",
"$",
"response",
")",
"{",
"$",
"content",
"=",
"preg_replace",
"(",
"'/<!\\-\\-.[^(\\-\\-\\>)]*?\\-\\->/i'",
",",
"''",
",",
"$",
"response",
"->",
"getContent",
"(",
")",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"\"\\t\"",
",",
"\" \"",
",",
"$",
"content",
")",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'/(\\s)\\/\\/(.*)(\\s)/'",
",",
"'\\\\1/* \\\\2 */\\\\3'",
",",
"$",
"content",
")",
";",
"$",
"search",
"=",
"array",
"(",
"'/(\\s+)?(\\<.+\\>)(\\s+)?/'",
",",
"'/(\\s)+/s'",
")",
";",
"$",
"replace",
"=",
"array",
"(",
"'\\\\2'",
",",
"'\\\\1'",
")",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"content",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\"",
",",
"$",
"content",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"}"
] | Drop comments & compress response content
@param Response $response | [
"Drop",
"comments",
"&",
"compress",
"response",
"content"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Response/Processor/CompressProcessor.php#L25-L44 | train |
rollerworks/search-doctrine-orm | DqlConditionGenerator.php | DqlConditionGenerator.getQueryHintValue | public function getQueryHintValue(): SqlConversionInfo
{
if (null === $this->whereClause) {
throw new BadMethodCallException(
'Unable to get query-hint value for ConditionGenerator. Call getWhereClause() before calling this method.'
);
}
return new SqlConversionInfo($this->nativePlatform, $this->parameters, $this->fieldsConfig->getFieldsForHint());
} | php | public function getQueryHintValue(): SqlConversionInfo
{
if (null === $this->whereClause) {
throw new BadMethodCallException(
'Unable to get query-hint value for ConditionGenerator. Call getWhereClause() before calling this method.'
);
}
return new SqlConversionInfo($this->nativePlatform, $this->parameters, $this->fieldsConfig->getFieldsForHint());
} | [
"public",
"function",
"getQueryHintValue",
"(",
")",
":",
"SqlConversionInfo",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"whereClause",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'Unable to get query-hint value for ConditionGenerator. Call getWhereClause() before calling this method.'",
")",
";",
"}",
"return",
"new",
"SqlConversionInfo",
"(",
"$",
"this",
"->",
"nativePlatform",
",",
"$",
"this",
"->",
"parameters",
",",
"$",
"this",
"->",
"fieldsConfig",
"->",
"getFieldsForHint",
"(",
")",
")",
";",
"}"
] | Returns the Query-hint value for the query object.
The Query hint is used for conversions. | [
"Returns",
"the",
"Query",
"-",
"hint",
"value",
"for",
"the",
"query",
"object",
"."
] | d4d7e9cfc6591d34e9d00f084c35f109f971ac4f | https://github.com/rollerworks/search-doctrine-orm/blob/d4d7e9cfc6591d34e9d00f084c35f109f971ac4f/DqlConditionGenerator.php#L144-L153 | train |
SahilDude89ss/PyntaxFramework-Config | src/Pyntax/Config/ConfigAbstract.php | ConfigAbstract.read | public static function read($key = false)
{
if(is_array($key) && !empty($key)) {
$_value_to_be_returned = self::$_config;
foreach(array_values($key) as $key => $_val) {
$_value_to_be_returned = $_value_to_be_returned[$_val];
}
return $_value_to_be_returned;
}
return isset(self::$_config[$key]) ? self::$_config[$key] : false;
} | php | public static function read($key = false)
{
if(is_array($key) && !empty($key)) {
$_value_to_be_returned = self::$_config;
foreach(array_values($key) as $key => $_val) {
$_value_to_be_returned = $_value_to_be_returned[$_val];
}
return $_value_to_be_returned;
}
return isset(self::$_config[$key]) ? self::$_config[$key] : false;
} | [
"public",
"static",
"function",
"read",
"(",
"$",
"key",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
"&&",
"!",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"_value_to_be_returned",
"=",
"self",
"::",
"$",
"_config",
";",
"foreach",
"(",
"array_values",
"(",
"$",
"key",
")",
"as",
"$",
"key",
"=>",
"$",
"_val",
")",
"{",
"$",
"_value_to_be_returned",
"=",
"$",
"_value_to_be_returned",
"[",
"$",
"_val",
"]",
";",
"}",
"return",
"$",
"_value_to_be_returned",
";",
"}",
"return",
"isset",
"(",
"self",
"::",
"$",
"_config",
"[",
"$",
"key",
"]",
")",
"?",
"self",
"::",
"$",
"_config",
"[",
"$",
"key",
"]",
":",
"false",
";",
"}"
] | This function returns the value of the key in the config.
@param bool|false $key
@return mixed | [
"This",
"function",
"returns",
"the",
"value",
"of",
"the",
"key",
"in",
"the",
"config",
"."
] | 4d7d336d2f83c4141583765fcc42a16002f5345e | https://github.com/SahilDude89ss/PyntaxFramework-Config/blob/4d7d336d2f83c4141583765fcc42a16002f5345e/src/Pyntax/Config/ConfigAbstract.php#L60-L72 | train |
SahilDude89ss/PyntaxFramework-Config | src/Pyntax/Config/ConfigAbstract.php | ConfigAbstract.loadConfigFiles | public static function loadConfigFiles($configPath = false)
{
if(!is_dir($configPath)) {
throw new \Exception("Config directory {$configPath} not found!");
}
$filesToBeLoaded = scandir($configPath);
foreach($filesToBeLoaded as $_file) {
if(preg_match('/.*\.php/',$_file)) {
include_once $configPath.DIRECTORY_SEPARATOR.$_file;
}
}
return true;
} | php | public static function loadConfigFiles($configPath = false)
{
if(!is_dir($configPath)) {
throw new \Exception("Config directory {$configPath} not found!");
}
$filesToBeLoaded = scandir($configPath);
foreach($filesToBeLoaded as $_file) {
if(preg_match('/.*\.php/',$_file)) {
include_once $configPath.DIRECTORY_SEPARATOR.$_file;
}
}
return true;
} | [
"public",
"static",
"function",
"loadConfigFiles",
"(",
"$",
"configPath",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"configPath",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Config directory {$configPath} not found!\"",
")",
";",
"}",
"$",
"filesToBeLoaded",
"=",
"scandir",
"(",
"$",
"configPath",
")",
";",
"foreach",
"(",
"$",
"filesToBeLoaded",
"as",
"$",
"_file",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/.*\\.php/'",
",",
"$",
"_file",
")",
")",
"{",
"include_once",
"$",
"configPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"_file",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | This function is loads all the files in a particular folder, this is meant to the config folder.
@param bool|false $configPath
@return bool
@throws \Exception | [
"This",
"function",
"is",
"loads",
"all",
"the",
"files",
"in",
"a",
"particular",
"folder",
"this",
"is",
"meant",
"to",
"the",
"config",
"folder",
"."
] | 4d7d336d2f83c4141583765fcc42a16002f5345e | https://github.com/SahilDude89ss/PyntaxFramework-Config/blob/4d7d336d2f83c4141583765fcc42a16002f5345e/src/Pyntax/Config/ConfigAbstract.php#L93-L107 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Backend/HtmlCodeForm.php | HtmlCodeForm.InitForm | protected function InitForm()
{
$this->htmlCode = $this->LoadElement();
$name = 'Code';
$this->AddField(new Textarea($name, $this->htmlCode->GetCode()));
$this->SetRequired($name);
$this->AddCssClassField();
$this->AddCssIDField();
$this->AddSubmit();
} | php | protected function InitForm()
{
$this->htmlCode = $this->LoadElement();
$name = 'Code';
$this->AddField(new Textarea($name, $this->htmlCode->GetCode()));
$this->SetRequired($name);
$this->AddCssClassField();
$this->AddCssIDField();
$this->AddSubmit();
} | [
"protected",
"function",
"InitForm",
"(",
")",
"{",
"$",
"this",
"->",
"htmlCode",
"=",
"$",
"this",
"->",
"LoadElement",
"(",
")",
";",
"$",
"name",
"=",
"'Code'",
";",
"$",
"this",
"->",
"AddField",
"(",
"new",
"Textarea",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"htmlCode",
"->",
"GetCode",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"AddCssClassField",
"(",
")",
";",
"$",
"this",
"->",
"AddCssIDField",
"(",
")",
";",
"$",
"this",
"->",
"AddSubmit",
"(",
")",
";",
"}"
] | Initializes the html code content form | [
"Initializes",
"the",
"html",
"code",
"content",
"form"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Backend/HtmlCodeForm.php#L38-L47 | train |
eureka-framework/component-orm | src/Orm/Config/Config.php | Config.init | public function init($config, $global)
{
//~ Comment
$this->author = $global['comment']['author'];
$this->version = $global['comment']['version'];
//~ Class
$this->classname = $config['class']['classname'];
$this->namespace = $config['class']['namespace'];
//~ Cache
$this->cacheName = $config['cache']['name'];
$this->cachePrefix = $config['cache']['prefix'];
//~ Db
$this->dbTable = $config['db']['table'];
$this->dbPrefix = $config['db']['prefix'];
//~ Joins
$this->joinList = (isset($config['joins']) ? $config['joins'] : array());
return $this;
} | php | public function init($config, $global)
{
//~ Comment
$this->author = $global['comment']['author'];
$this->version = $global['comment']['version'];
//~ Class
$this->classname = $config['class']['classname'];
$this->namespace = $config['class']['namespace'];
//~ Cache
$this->cacheName = $config['cache']['name'];
$this->cachePrefix = $config['cache']['prefix'];
//~ Db
$this->dbTable = $config['db']['table'];
$this->dbPrefix = $config['db']['prefix'];
//~ Joins
$this->joinList = (isset($config['joins']) ? $config['joins'] : array());
return $this;
} | [
"public",
"function",
"init",
"(",
"$",
"config",
",",
"$",
"global",
")",
"{",
"//~ Comment",
"$",
"this",
"->",
"author",
"=",
"$",
"global",
"[",
"'comment'",
"]",
"[",
"'author'",
"]",
";",
"$",
"this",
"->",
"version",
"=",
"$",
"global",
"[",
"'comment'",
"]",
"[",
"'version'",
"]",
";",
"//~ Class",
"$",
"this",
"->",
"classname",
"=",
"$",
"config",
"[",
"'class'",
"]",
"[",
"'classname'",
"]",
";",
"$",
"this",
"->",
"namespace",
"=",
"$",
"config",
"[",
"'class'",
"]",
"[",
"'namespace'",
"]",
";",
"//~ Cache",
"$",
"this",
"->",
"cacheName",
"=",
"$",
"config",
"[",
"'cache'",
"]",
"[",
"'name'",
"]",
";",
"$",
"this",
"->",
"cachePrefix",
"=",
"$",
"config",
"[",
"'cache'",
"]",
"[",
"'prefix'",
"]",
";",
"//~ Db",
"$",
"this",
"->",
"dbTable",
"=",
"$",
"config",
"[",
"'db'",
"]",
"[",
"'table'",
"]",
";",
"$",
"this",
"->",
"dbPrefix",
"=",
"$",
"config",
"[",
"'db'",
"]",
"[",
"'prefix'",
"]",
";",
"//~ Joins",
"$",
"this",
"->",
"joinList",
"=",
"(",
"isset",
"(",
"$",
"config",
"[",
"'joins'",
"]",
")",
"?",
"$",
"config",
"[",
"'joins'",
"]",
":",
"array",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Initialize config.
@param array $config
@param array $global
@return self | [
"Initialize",
"config",
"."
] | bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Config/Config.php#L26-L48 | train |
kreta/SimpleApiDocBundle | src/Kreta/SimpleApiDocBundle/Parser/ValidationParser.php | ValidationParser.getValidations | public function getValidations($class = null)
{
$reflectionClass = $class ? new \ReflectionClass($class) : false;
if ($reflectionClass === false) {
return [];
}
$result = $this->buildValidation($class);
$validations = [];
foreach ($result as $keyElement => $element) {
if (is_array($element)) {
foreach ($element as $keyChild => $child) {
if (is_array($child)) {
foreach ($child as $grandChild) {
$validations[] = sprintf('%s => %s', $keyChild, $grandChild);
}
} else {
$validations[] = sprintf('%s => %s', $keyElement, $child);
}
}
} else {
$validations[] = $element;
}
}
return $validations;
} | php | public function getValidations($class = null)
{
$reflectionClass = $class ? new \ReflectionClass($class) : false;
if ($reflectionClass === false) {
return [];
}
$result = $this->buildValidation($class);
$validations = [];
foreach ($result as $keyElement => $element) {
if (is_array($element)) {
foreach ($element as $keyChild => $child) {
if (is_array($child)) {
foreach ($child as $grandChild) {
$validations[] = sprintf('%s => %s', $keyChild, $grandChild);
}
} else {
$validations[] = sprintf('%s => %s', $keyElement, $child);
}
}
} else {
$validations[] = $element;
}
}
return $validations;
} | [
"public",
"function",
"getValidations",
"(",
"$",
"class",
"=",
"null",
")",
"{",
"$",
"reflectionClass",
"=",
"$",
"class",
"?",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
":",
"false",
";",
"if",
"(",
"$",
"reflectionClass",
"===",
"false",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"buildValidation",
"(",
"$",
"class",
")",
";",
"$",
"validations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"keyElement",
"=>",
"$",
"element",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"element",
")",
")",
"{",
"foreach",
"(",
"$",
"element",
"as",
"$",
"keyChild",
"=>",
"$",
"child",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"child",
")",
")",
"{",
"foreach",
"(",
"$",
"child",
"as",
"$",
"grandChild",
")",
"{",
"$",
"validations",
"[",
"]",
"=",
"sprintf",
"(",
"'%s => %s'",
",",
"$",
"keyChild",
",",
"$",
"grandChild",
")",
";",
"}",
"}",
"else",
"{",
"$",
"validations",
"[",
"]",
"=",
"sprintf",
"(",
"'%s => %s'",
",",
"$",
"keyElement",
",",
"$",
"child",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"validations",
"[",
"]",
"=",
"$",
"element",
";",
"}",
"}",
"return",
"$",
"validations",
";",
"}"
] | Gets the validations.
@param string|null $class The class namespace
@return array | [
"Gets",
"the",
"validations",
"."
] | 786aa9310cdf087253f65f68165a0a0c8ad5c816 | https://github.com/kreta/SimpleApiDocBundle/blob/786aa9310cdf087253f65f68165a0a0c8ad5c816/src/Kreta/SimpleApiDocBundle/Parser/ValidationParser.php#L55-L80 | train |
kreta/SimpleApiDocBundle | src/Kreta/SimpleApiDocBundle/Parser/ValidationParser.php | ValidationParser.buildValidation | protected function buildValidation($class = null)
{
$validations = [];
$metadata = $this->validator->getMetadataFor($class);
$entityConstraints = [];
foreach ($metadata->getConstraints() as $constraint) {
$class = new \ReflectionClass($constraint);
$fields = $constraint->fields;
$entityConstraint = [implode(', ', (array) $fields) => $constraint->message];
$entityConstraints = array_merge($entityConstraints, $entityConstraint);
$validations[$class->getShortName()] = $entityConstraint;
}
foreach ($metadata->getConstrainedProperties() as $property) {
$constraints = $metadata->getPropertyMetadata($property)[0]->constraints;
$result = [];
foreach ($constraints as $constraint) {
$class = new \ReflectionObject($constraint);
switch ($name = $class->getShortName()) {
case 'True':
$result[$name] = $constraint->message;
break;
case 'NotBlank':
$result[$name] = $constraint->message;
break;
case 'Type':
$result[$name] = $constraint->type;
break;
case 'Length':
$result[$name] = $this->constraintMessages($constraint);
break;
case 'Count':
$result[$name] = $this->constraintMessages($constraint);
break;
}
}
$validations[$property] = $result;
}
return $validations;
} | php | protected function buildValidation($class = null)
{
$validations = [];
$metadata = $this->validator->getMetadataFor($class);
$entityConstraints = [];
foreach ($metadata->getConstraints() as $constraint) {
$class = new \ReflectionClass($constraint);
$fields = $constraint->fields;
$entityConstraint = [implode(', ', (array) $fields) => $constraint->message];
$entityConstraints = array_merge($entityConstraints, $entityConstraint);
$validations[$class->getShortName()] = $entityConstraint;
}
foreach ($metadata->getConstrainedProperties() as $property) {
$constraints = $metadata->getPropertyMetadata($property)[0]->constraints;
$result = [];
foreach ($constraints as $constraint) {
$class = new \ReflectionObject($constraint);
switch ($name = $class->getShortName()) {
case 'True':
$result[$name] = $constraint->message;
break;
case 'NotBlank':
$result[$name] = $constraint->message;
break;
case 'Type':
$result[$name] = $constraint->type;
break;
case 'Length':
$result[$name] = $this->constraintMessages($constraint);
break;
case 'Count':
$result[$name] = $this->constraintMessages($constraint);
break;
}
}
$validations[$property] = $result;
}
return $validations;
} | [
"protected",
"function",
"buildValidation",
"(",
"$",
"class",
"=",
"null",
")",
"{",
"$",
"validations",
"=",
"[",
"]",
";",
"$",
"metadata",
"=",
"$",
"this",
"->",
"validator",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
";",
"$",
"entityConstraints",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"metadata",
"->",
"getConstraints",
"(",
")",
"as",
"$",
"constraint",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"constraint",
")",
";",
"$",
"fields",
"=",
"$",
"constraint",
"->",
"fields",
";",
"$",
"entityConstraint",
"=",
"[",
"implode",
"(",
"', '",
",",
"(",
"array",
")",
"$",
"fields",
")",
"=>",
"$",
"constraint",
"->",
"message",
"]",
";",
"$",
"entityConstraints",
"=",
"array_merge",
"(",
"$",
"entityConstraints",
",",
"$",
"entityConstraint",
")",
";",
"$",
"validations",
"[",
"$",
"class",
"->",
"getShortName",
"(",
")",
"]",
"=",
"$",
"entityConstraint",
";",
"}",
"foreach",
"(",
"$",
"metadata",
"->",
"getConstrainedProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"constraints",
"=",
"$",
"metadata",
"->",
"getPropertyMetadata",
"(",
"$",
"property",
")",
"[",
"0",
"]",
"->",
"constraints",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"constraints",
"as",
"$",
"constraint",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"constraint",
")",
";",
"switch",
"(",
"$",
"name",
"=",
"$",
"class",
"->",
"getShortName",
"(",
")",
")",
"{",
"case",
"'True'",
":",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"constraint",
"->",
"message",
";",
"break",
";",
"case",
"'NotBlank'",
":",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"constraint",
"->",
"message",
";",
"break",
";",
"case",
"'Type'",
":",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"constraint",
"->",
"type",
";",
"break",
";",
"case",
"'Length'",
":",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"constraintMessages",
"(",
"$",
"constraint",
")",
";",
"break",
";",
"case",
"'Count'",
":",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"constraintMessages",
"(",
"$",
"constraint",
")",
";",
"break",
";",
"}",
"}",
"$",
"validations",
"[",
"$",
"property",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"validations",
";",
"}"
] | Parses and builds the validation.
@param string|null $class The class namespace
@return array | [
"Parses",
"and",
"builds",
"the",
"validation",
"."
] | 786aa9310cdf087253f65f68165a0a0c8ad5c816 | https://github.com/kreta/SimpleApiDocBundle/blob/786aa9310cdf087253f65f68165a0a0c8ad5c816/src/Kreta/SimpleApiDocBundle/Parser/ValidationParser.php#L89-L129 | train |
kreta/SimpleApiDocBundle | src/Kreta/SimpleApiDocBundle/Parser/ValidationParser.php | ValidationParser.constraintMessages | protected function constraintMessages(Constraint $constraint)
{
$result = [];
if (isset($constraint->min) && $constraint->min !== null) {
$count = new Count(['min' => $constraint->min]);
$length = new Length(['min' => $constraint->min]);
$result[] = $constraint->minMessage;
}
if (isset($constraint->max) && $constraint->max !== null) {
$count = new Count(['max' => $constraint->min]);
$length = new Length(['max' => $constraint->min]);
$result[] = $constraint->maxMessage;
}
if (isset($constraint->exactMessage)
&& $constraint->exactMessage !== $count->exactMessage
&& $constraint->exactMessage !== $length->exactMessage
) {
$result[] = $constraint->exactMessage;
}
return $result;
} | php | protected function constraintMessages(Constraint $constraint)
{
$result = [];
if (isset($constraint->min) && $constraint->min !== null) {
$count = new Count(['min' => $constraint->min]);
$length = new Length(['min' => $constraint->min]);
$result[] = $constraint->minMessage;
}
if (isset($constraint->max) && $constraint->max !== null) {
$count = new Count(['max' => $constraint->min]);
$length = new Length(['max' => $constraint->min]);
$result[] = $constraint->maxMessage;
}
if (isset($constraint->exactMessage)
&& $constraint->exactMessage !== $count->exactMessage
&& $constraint->exactMessage !== $length->exactMessage
) {
$result[] = $constraint->exactMessage;
}
return $result;
} | [
"protected",
"function",
"constraintMessages",
"(",
"Constraint",
"$",
"constraint",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"constraint",
"->",
"min",
")",
"&&",
"$",
"constraint",
"->",
"min",
"!==",
"null",
")",
"{",
"$",
"count",
"=",
"new",
"Count",
"(",
"[",
"'min'",
"=>",
"$",
"constraint",
"->",
"min",
"]",
")",
";",
"$",
"length",
"=",
"new",
"Length",
"(",
"[",
"'min'",
"=>",
"$",
"constraint",
"->",
"min",
"]",
")",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"constraint",
"->",
"minMessage",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"constraint",
"->",
"max",
")",
"&&",
"$",
"constraint",
"->",
"max",
"!==",
"null",
")",
"{",
"$",
"count",
"=",
"new",
"Count",
"(",
"[",
"'max'",
"=>",
"$",
"constraint",
"->",
"min",
"]",
")",
";",
"$",
"length",
"=",
"new",
"Length",
"(",
"[",
"'max'",
"=>",
"$",
"constraint",
"->",
"min",
"]",
")",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"constraint",
"->",
"maxMessage",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"constraint",
"->",
"exactMessage",
")",
"&&",
"$",
"constraint",
"->",
"exactMessage",
"!==",
"$",
"count",
"->",
"exactMessage",
"&&",
"$",
"constraint",
"->",
"exactMessage",
"!==",
"$",
"length",
"->",
"exactMessage",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"constraint",
"->",
"exactMessage",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Parses the constraint message.
@param \Symfony\Component\Validator\Constraint $constraint The constraint
@return array | [
"Parses",
"the",
"constraint",
"message",
"."
] | 786aa9310cdf087253f65f68165a0a0c8ad5c816 | https://github.com/kreta/SimpleApiDocBundle/blob/786aa9310cdf087253f65f68165a0a0c8ad5c816/src/Kreta/SimpleApiDocBundle/Parser/ValidationParser.php#L138-L159 | train |
gplcart/cli | controllers/commands/CollectionItem.php | CollectionItem.cmdGetCollectionItem | public function cmdGetCollectionItem()
{
$result = $this->getListCollectionItem();
$this->outputFormat($result);
$this->outputFormatTableCollectionItem($result);
$this->output();
} | php | public function cmdGetCollectionItem()
{
$result = $this->getListCollectionItem();
$this->outputFormat($result);
$this->outputFormatTableCollectionItem($result);
$this->output();
} | [
"public",
"function",
"cmdGetCollectionItem",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListCollectionItem",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableCollectionItem",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "collection-item-get" command | [
"Callback",
"for",
"collection",
"-",
"item",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CollectionItem.php#L40-L46 | train |
gplcart/cli | controllers/commands/CollectionItem.php | CollectionItem.cmdDeleteCollectionItem | public function cmdDeleteCollectionItem()
{
$id = $this->getParam(0);
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid command'));
}
$condition = $id;
if ($this->getParam('collection')) {
$condition = array('collection_id' => $id);
}
$result = $this->collection_item->delete($condition);
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdDeleteCollectionItem()
{
$id = $this->getParam(0);
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid command'));
}
$condition = $id;
if ($this->getParam('collection')) {
$condition = array('collection_id' => $id);
}
$result = $this->collection_item->delete($condition);
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdDeleteCollectionItem",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"condition",
"=",
"$",
"id",
";",
"if",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'collection'",
")",
")",
"{",
"$",
"condition",
"=",
"array",
"(",
"'collection_id'",
"=>",
"$",
"id",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"collection_item",
"->",
"delete",
"(",
"$",
"condition",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "collection-item-delete" command | [
"Callback",
"for",
"collection",
"-",
"item",
"-",
"delete",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CollectionItem.php#L51-L71 | train |
gplcart/cli | controllers/commands/CollectionItem.php | CollectionItem.cmdUpdateCollectionItem | public function cmdUpdateCollectionItem()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('collection_item');
$this->updateCollectionItem($params[0]);
$this->output();
} | php | public function cmdUpdateCollectionItem()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('collection_item');
$this->updateCollectionItem($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateCollectionItem",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'collection_item'",
")",
";",
"$",
"this",
"->",
"updateCollectionItem",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "collection-item-update" command | [
"Callback",
"for",
"collection",
"-",
"item",
"-",
"update",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CollectionItem.php#L90-L108 | train |
gplcart/cli | controllers/commands/CollectionItem.php | CollectionItem.addCollectionItem | protected function addCollectionItem()
{
if (!$this->isError()) {
$id = $this->collection_item->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | php | protected function addCollectionItem()
{
if (!$this->isError()) {
$id = $this->collection_item->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | [
"protected",
"function",
"addCollectionItem",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"collection_item",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Add a new collection item | [
"Add",
"a",
"new",
"collection",
"item"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CollectionItem.php#L171-L180 | train |
gplcart/cli | controllers/commands/CollectionItem.php | CollectionItem.updateCollectionItem | protected function updateCollectionItem($collection_item_id)
{
if (!$this->isError() && !$this->collection_item->update($collection_item_id, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | php | protected function updateCollectionItem($collection_item_id)
{
if (!$this->isError() && !$this->collection_item->update($collection_item_id, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | [
"protected",
"function",
"updateCollectionItem",
"(",
"$",
"collection_item_id",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"collection_item",
"->",
"update",
"(",
"$",
"collection_item_id",
",",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"}"
] | Updates a collection item
@param string $collection_item_id | [
"Updates",
"a",
"collection",
"item"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CollectionItem.php#L186-L191 | train |
gplcart/cli | controllers/commands/CollectionItem.php | CollectionItem.submitAddCollectionItem | protected function submitAddCollectionItem()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('collection_item');
$this->addCollectionItem();
} | php | protected function submitAddCollectionItem()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('collection_item');
$this->addCollectionItem();
} | [
"protected",
"function",
"submitAddCollectionItem",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'collection_item'",
")",
";",
"$",
"this",
"->",
"addCollectionItem",
"(",
")",
";",
"}"
] | Add a new collection item at once | [
"Add",
"a",
"new",
"collection",
"item",
"at",
"once"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CollectionItem.php#L196-L201 | train |
gplcart/cli | controllers/commands/CollectionItem.php | CollectionItem.wizardAddCollectionItem | protected function wizardAddCollectionItem()
{
$this->validatePrompt('collection_id', $this->text('Collection ID'), 'collection_item');
$this->validatePrompt('entity_id', $this->text('Entity ID'), 'collection_item');
$this->validatePrompt('weight', $this->text('Weight'), 'collection_item', 0);
$this->validatePrompt('status', $this->text('Status'), 'collection_item', 0);
$this->validatePrompt('data', $this->text('Data'), 'collection_item');
$this->validateComponent('collection_item');
$this->addCollectionItem();
} | php | protected function wizardAddCollectionItem()
{
$this->validatePrompt('collection_id', $this->text('Collection ID'), 'collection_item');
$this->validatePrompt('entity_id', $this->text('Entity ID'), 'collection_item');
$this->validatePrompt('weight', $this->text('Weight'), 'collection_item', 0);
$this->validatePrompt('status', $this->text('Status'), 'collection_item', 0);
$this->validatePrompt('data', $this->text('Data'), 'collection_item');
$this->validateComponent('collection_item');
$this->addCollectionItem();
} | [
"protected",
"function",
"wizardAddCollectionItem",
"(",
")",
"{",
"$",
"this",
"->",
"validatePrompt",
"(",
"'collection_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Collection ID'",
")",
",",
"'collection_item'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'entity_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Entity ID'",
")",
",",
"'collection_item'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'weight'",
",",
"$",
"this",
"->",
"text",
"(",
"'Weight'",
")",
",",
"'collection_item'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'collection_item'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'data'",
",",
"$",
"this",
"->",
"text",
"(",
"'Data'",
")",
",",
"'collection_item'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'collection_item'",
")",
";",
"$",
"this",
"->",
"addCollectionItem",
"(",
")",
";",
"}"
] | Add a collection item step by step | [
"Add",
"a",
"collection",
"item",
"step",
"by",
"step"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/CollectionItem.php#L206-L216 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Map/MediaTableMap.php | MediaTableMap.doDelete | public static function doDelete($values, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(MediaTableMap::DATABASE_NAME);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = $values;
} elseif ($values instanceof \Attogram\SharedMedia\Orm\Media) { // it's a model object
// create criteria based on pk values
$criteria = $values->buildPkeyCriteria();
} else { // it's a primary key, or an array of pks
$criteria = new Criteria(MediaTableMap::DATABASE_NAME);
$criteria->add(MediaTableMap::COL_ID, (array) $values, Criteria::IN);
}
$query = MediaQuery::create()->mergeWith($criteria);
if ($values instanceof Criteria) {
MediaTableMap::clearInstancePool();
} elseif (!is_object($values)) { // it's a primary key, or an array of pks
foreach ((array) $values as $singleval) {
MediaTableMap::removeInstanceFromPool($singleval);
}
}
return $query->delete($con);
} | php | public static function doDelete($values, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(MediaTableMap::DATABASE_NAME);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = $values;
} elseif ($values instanceof \Attogram\SharedMedia\Orm\Media) { // it's a model object
// create criteria based on pk values
$criteria = $values->buildPkeyCriteria();
} else { // it's a primary key, or an array of pks
$criteria = new Criteria(MediaTableMap::DATABASE_NAME);
$criteria->add(MediaTableMap::COL_ID, (array) $values, Criteria::IN);
}
$query = MediaQuery::create()->mergeWith($criteria);
if ($values instanceof Criteria) {
MediaTableMap::clearInstancePool();
} elseif (!is_object($values)) { // it's a primary key, or an array of pks
foreach ((array) $values as $singleval) {
MediaTableMap::removeInstanceFromPool($singleval);
}
}
return $query->delete($con);
} | [
"public",
"static",
"function",
"doDelete",
"(",
"$",
"values",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"MediaTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"if",
"(",
"$",
"values",
"instanceof",
"Criteria",
")",
"{",
"// rename for clarity",
"$",
"criteria",
"=",
"$",
"values",
";",
"}",
"elseif",
"(",
"$",
"values",
"instanceof",
"\\",
"Attogram",
"\\",
"SharedMedia",
"\\",
"Orm",
"\\",
"Media",
")",
"{",
"// it's a model object",
"// create criteria based on pk values",
"$",
"criteria",
"=",
"$",
"values",
"->",
"buildPkeyCriteria",
"(",
")",
";",
"}",
"else",
"{",
"// it's a primary key, or an array of pks",
"$",
"criteria",
"=",
"new",
"Criteria",
"(",
"MediaTableMap",
"::",
"DATABASE_NAME",
")",
";",
"$",
"criteria",
"->",
"add",
"(",
"MediaTableMap",
"::",
"COL_ID",
",",
"(",
"array",
")",
"$",
"values",
",",
"Criteria",
"::",
"IN",
")",
";",
"}",
"$",
"query",
"=",
"MediaQuery",
"::",
"create",
"(",
")",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"values",
"instanceof",
"Criteria",
")",
"{",
"MediaTableMap",
"::",
"clearInstancePool",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"is_object",
"(",
"$",
"values",
")",
")",
"{",
"// it's a primary key, or an array of pks",
"foreach",
"(",
"(",
"array",
")",
"$",
"values",
"as",
"$",
"singleval",
")",
"{",
"MediaTableMap",
"::",
"removeInstanceFromPool",
"(",
"$",
"singleval",
")",
";",
"}",
"}",
"return",
"$",
"query",
"->",
"delete",
"(",
"$",
"con",
")",
";",
"}"
] | Performs a DELETE on the database, given a Media or Criteria object OR a primary key value.
@param mixed $values Criteria or Media object or primary key or array of primary keys
which is used to create the DELETE statement
@param ConnectionInterface $con the connection to use
@return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
if supported by native driver or if emulated using Propel.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException. | [
"Performs",
"a",
"DELETE",
"on",
"the",
"database",
"given",
"a",
"Media",
"or",
"Criteria",
"object",
"OR",
"a",
"primary",
"key",
"value",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Map/MediaTableMap.php#L602-L630 | train |
helsingborg-stad/custom-short-links | source/php/Shortlinks.php | Shortlinks.registerPostType | public function registerPostType()
{
$nameSingular = 'Shortlink';
$namePlural = 'Shortlinks';
$description = 'Create shortlinks to your posts or pages';
$labels = array(
'name' => _x($nameSingular, 'post type general name', 'custom-short-links'),
'singular_name' => _x($nameSingular, 'post type singular name', 'custom-short-links'),
'menu_name' => _x($namePlural, 'admin menu', 'custom-short-links'),
'name_admin_bar' => _x($nameSingular, 'add new on admin bar', 'custom-short-links'),
'add_new' => _x('Add New', 'add new button', 'custom-short-links'),
'add_new_item' => sprintf(__('Add new %s', 'custom-short-links'), $nameSingular),
'new_item' => sprintf(__('New %s', 'custom-short-links'), $nameSingular),
'edit_item' => sprintf(__('Edit %s', 'custom-short-links'), $nameSingular),
'view_item' => sprintf(__('View %s', 'custom-short-links'), $nameSingular),
'all_items' => sprintf(__('%s', 'custom-short-links'), $namePlural),
'search_items' => sprintf(__('Search %s', 'custom-short-links'), $namePlural),
'parent_item_colon' => sprintf(__('Parent %s', 'custom-short-links'), $namePlural),
'not_found' => sprintf(__('No %s', 'custom-short-links'), $namePlural),
'not_found_in_trash' => sprintf(__('No %s in trash', 'custom-short-links'), $namePlural)
);
$args = array(
'labels' => $labels,
'description' => __($description, 'custom-short-links'),
'public' => false,
'publicly_queriable' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_menu' => 'options-general.php',
'has_archive' => false,
'rewrite' => false,
'hierarchical' => false,
'menu_position' => 100,
'exclude_from_search' => true,
'menu_icon' => 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNDguMTU1IDQ4LjE1NSI+PHBhdGggZD0iTTM2Ljg1IDI0LjY1Nmw5LjUwNC05LjUwM0wzNi44NSA1LjY1SDI0LjA4di00LjZjMC0uNTc3LS40NzMtMS4wNS0xLjA1LTEuMDVIMTkuMjRjLS41NzggMC0xLjA1LjQ3My0xLjA1IDEuMDV2NC42SDIuM2EuNS41IDAgMCAwLS41LjV2MTguMDA3YS41LjUgMCAwIDAgLjUuNWgxNS44OXYzLjczaC01Ljg4bC00Ljc1MiA0Ljc1IDQuNzUyIDQuNzUzaDUuODh2OS4yMTRjMCAuNTc3LjQ3MiAxLjA1MiAxLjA1IDEuMDUyaDMuNzg1Yy41NzggMCAxLjA1LS40NzUgMS4wNS0xLjA1MlYzNy44OWg3LjI2YS41LjUgMCAwIDAgLjUtLjV2LTguNTA0YS41LjUgMCAwIDAtLjUtLjVoLTcuMjZ2LTMuNzNoMTIuNzc0eiIgZmlsbD0iIzk5OSIvPjwvc3ZnPg==',
'supports' => array('title')
);
register_post_type('custom-short-link', $args);
add_filter('manage_edit-custom-short-link_columns', array($this, 'listColumns'));
add_action('manage_custom-short-link_posts_custom_column', array($this, 'listColumnsContent'), 10, 2);
add_filter('manage_edit-custom-short-link_sortable_columns', array($this, 'listColumnsSorting'));
} | php | public function registerPostType()
{
$nameSingular = 'Shortlink';
$namePlural = 'Shortlinks';
$description = 'Create shortlinks to your posts or pages';
$labels = array(
'name' => _x($nameSingular, 'post type general name', 'custom-short-links'),
'singular_name' => _x($nameSingular, 'post type singular name', 'custom-short-links'),
'menu_name' => _x($namePlural, 'admin menu', 'custom-short-links'),
'name_admin_bar' => _x($nameSingular, 'add new on admin bar', 'custom-short-links'),
'add_new' => _x('Add New', 'add new button', 'custom-short-links'),
'add_new_item' => sprintf(__('Add new %s', 'custom-short-links'), $nameSingular),
'new_item' => sprintf(__('New %s', 'custom-short-links'), $nameSingular),
'edit_item' => sprintf(__('Edit %s', 'custom-short-links'), $nameSingular),
'view_item' => sprintf(__('View %s', 'custom-short-links'), $nameSingular),
'all_items' => sprintf(__('%s', 'custom-short-links'), $namePlural),
'search_items' => sprintf(__('Search %s', 'custom-short-links'), $namePlural),
'parent_item_colon' => sprintf(__('Parent %s', 'custom-short-links'), $namePlural),
'not_found' => sprintf(__('No %s', 'custom-short-links'), $namePlural),
'not_found_in_trash' => sprintf(__('No %s in trash', 'custom-short-links'), $namePlural)
);
$args = array(
'labels' => $labels,
'description' => __($description, 'custom-short-links'),
'public' => false,
'publicly_queriable' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_menu' => 'options-general.php',
'has_archive' => false,
'rewrite' => false,
'hierarchical' => false,
'menu_position' => 100,
'exclude_from_search' => true,
'menu_icon' => 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNDguMTU1IDQ4LjE1NSI+PHBhdGggZD0iTTM2Ljg1IDI0LjY1Nmw5LjUwNC05LjUwM0wzNi44NSA1LjY1SDI0LjA4di00LjZjMC0uNTc3LS40NzMtMS4wNS0xLjA1LTEuMDVIMTkuMjRjLS41NzggMC0xLjA1LjQ3My0xLjA1IDEuMDV2NC42SDIuM2EuNS41IDAgMCAwLS41LjV2MTguMDA3YS41LjUgMCAwIDAgLjUuNWgxNS44OXYzLjczaC01Ljg4bC00Ljc1MiA0Ljc1IDQuNzUyIDQuNzUzaDUuODh2OS4yMTRjMCAuNTc3LjQ3MiAxLjA1MiAxLjA1IDEuMDUyaDMuNzg1Yy41NzggMCAxLjA1LS40NzUgMS4wNS0xLjA1MlYzNy44OWg3LjI2YS41LjUgMCAwIDAgLjUtLjV2LTguNTA0YS41LjUgMCAwIDAtLjUtLjVoLTcuMjZ2LTMuNzNoMTIuNzc0eiIgZmlsbD0iIzk5OSIvPjwvc3ZnPg==',
'supports' => array('title')
);
register_post_type('custom-short-link', $args);
add_filter('manage_edit-custom-short-link_columns', array($this, 'listColumns'));
add_action('manage_custom-short-link_posts_custom_column', array($this, 'listColumnsContent'), 10, 2);
add_filter('manage_edit-custom-short-link_sortable_columns', array($this, 'listColumnsSorting'));
} | [
"public",
"function",
"registerPostType",
"(",
")",
"{",
"$",
"nameSingular",
"=",
"'Shortlink'",
";",
"$",
"namePlural",
"=",
"'Shortlinks'",
";",
"$",
"description",
"=",
"'Create shortlinks to your posts or pages'",
";",
"$",
"labels",
"=",
"array",
"(",
"'name'",
"=>",
"_x",
"(",
"$",
"nameSingular",
",",
"'post type general name'",
",",
"'custom-short-links'",
")",
",",
"'singular_name'",
"=>",
"_x",
"(",
"$",
"nameSingular",
",",
"'post type singular name'",
",",
"'custom-short-links'",
")",
",",
"'menu_name'",
"=>",
"_x",
"(",
"$",
"namePlural",
",",
"'admin menu'",
",",
"'custom-short-links'",
")",
",",
"'name_admin_bar'",
"=>",
"_x",
"(",
"$",
"nameSingular",
",",
"'add new on admin bar'",
",",
"'custom-short-links'",
")",
",",
"'add_new'",
"=>",
"_x",
"(",
"'Add New'",
",",
"'add new button'",
",",
"'custom-short-links'",
")",
",",
"'add_new_item'",
"=>",
"sprintf",
"(",
"__",
"(",
"'Add new %s'",
",",
"'custom-short-links'",
")",
",",
"$",
"nameSingular",
")",
",",
"'new_item'",
"=>",
"sprintf",
"(",
"__",
"(",
"'New %s'",
",",
"'custom-short-links'",
")",
",",
"$",
"nameSingular",
")",
",",
"'edit_item'",
"=>",
"sprintf",
"(",
"__",
"(",
"'Edit %s'",
",",
"'custom-short-links'",
")",
",",
"$",
"nameSingular",
")",
",",
"'view_item'",
"=>",
"sprintf",
"(",
"__",
"(",
"'View %s'",
",",
"'custom-short-links'",
")",
",",
"$",
"nameSingular",
")",
",",
"'all_items'",
"=>",
"sprintf",
"(",
"__",
"(",
"'%s'",
",",
"'custom-short-links'",
")",
",",
"$",
"namePlural",
")",
",",
"'search_items'",
"=>",
"sprintf",
"(",
"__",
"(",
"'Search %s'",
",",
"'custom-short-links'",
")",
",",
"$",
"namePlural",
")",
",",
"'parent_item_colon'",
"=>",
"sprintf",
"(",
"__",
"(",
"'Parent %s'",
",",
"'custom-short-links'",
")",
",",
"$",
"namePlural",
")",
",",
"'not_found'",
"=>",
"sprintf",
"(",
"__",
"(",
"'No %s'",
",",
"'custom-short-links'",
")",
",",
"$",
"namePlural",
")",
",",
"'not_found_in_trash'",
"=>",
"sprintf",
"(",
"__",
"(",
"'No %s in trash'",
",",
"'custom-short-links'",
")",
",",
"$",
"namePlural",
")",
")",
";",
"$",
"args",
"=",
"array",
"(",
"'labels'",
"=>",
"$",
"labels",
",",
"'description'",
"=>",
"__",
"(",
"$",
"description",
",",
"'custom-short-links'",
")",
",",
"'public'",
"=>",
"false",
",",
"'publicly_queriable'",
"=>",
"false",
",",
"'show_ui'",
"=>",
"true",
",",
"'show_in_nav_menus'",
"=>",
"false",
",",
"'show_in_menu'",
"=>",
"'options-general.php'",
",",
"'has_archive'",
"=>",
"false",
",",
"'rewrite'",
"=>",
"false",
",",
"'hierarchical'",
"=>",
"false",
",",
"'menu_position'",
"=>",
"100",
",",
"'exclude_from_search'",
"=>",
"true",
",",
"'menu_icon'",
"=>",
"'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNDguMTU1IDQ4LjE1NSI+PHBhdGggZD0iTTM2Ljg1IDI0LjY1Nmw5LjUwNC05LjUwM0wzNi44NSA1LjY1SDI0LjA4di00LjZjMC0uNTc3LS40NzMtMS4wNS0xLjA1LTEuMDVIMTkuMjRjLS41NzggMC0xLjA1LjQ3My0xLjA1IDEuMDV2NC42SDIuM2EuNS41IDAgMCAwLS41LjV2MTguMDA3YS41LjUgMCAwIDAgLjUuNWgxNS44OXYzLjczaC01Ljg4bC00Ljc1MiA0Ljc1IDQuNzUyIDQuNzUzaDUuODh2OS4yMTRjMCAuNTc3LjQ3MiAxLjA1MiAxLjA1IDEuMDUyaDMuNzg1Yy41NzggMCAxLjA1LS40NzUgMS4wNS0xLjA1MlYzNy44OWg3LjI2YS41LjUgMCAwIDAgLjUtLjV2LTguNTA0YS41LjUgMCAwIDAtLjUtLjVoLTcuMjZ2LTMuNzNoMTIuNzc0eiIgZmlsbD0iIzk5OSIvPjwvc3ZnPg=='",
",",
"'supports'",
"=>",
"array",
"(",
"'title'",
")",
")",
";",
"register_post_type",
"(",
"'custom-short-link'",
",",
"$",
"args",
")",
";",
"add_filter",
"(",
"'manage_edit-custom-short-link_columns'",
",",
"array",
"(",
"$",
"this",
",",
"'listColumns'",
")",
")",
";",
"add_action",
"(",
"'manage_custom-short-link_posts_custom_column'",
",",
"array",
"(",
"$",
"this",
",",
"'listColumnsContent'",
")",
",",
"10",
",",
"2",
")",
";",
"add_filter",
"(",
"'manage_edit-custom-short-link_sortable_columns'",
",",
"array",
"(",
"$",
"this",
",",
"'listColumnsSorting'",
")",
")",
";",
"}"
] | Register shortlinks posttype
@return void | [
"Register",
"shortlinks",
"posttype"
] | 3b82a090eb2318470278c9f888e37527f31ddecc | https://github.com/helsingborg-stad/custom-short-links/blob/3b82a090eb2318470278c9f888e37527f31ddecc/source/php/Shortlinks.php#L21-L66 | train |
helsingborg-stad/custom-short-links | source/php/Shortlinks.php | Shortlinks.simpleRedirect | public function simpleRedirect()
{
global $wp;
if (!$request = $wp->request) {
return;
}
$currentSlug = add_query_arg(array(), $request);
$post = get_page_by_title($currentSlug, 'OBJECT', 'custom-short-link');
if (!$post) {
return;
}
$fields = get_fields($post->ID);
$redirectTo = null;
// Find redirect url
switch ($fields['custom_short_links_redirect_url_type']) {
case 'external':
$redirectTo = $fields['custom_short_links_redirect_to_external'];
break;
case 'internal':
$redirectTo = $fields['custom_short_links_redirect_to_internal'];
break;
}
// Make redirect with selected method
switch ($fields['custom_short_links_redirect_method']) {
case 'meta':
add_action('wp_head', function () use ($fields, $redirectTo) {
echo '<meta http-equiv="refresh" content="' . $fields['custom_short_links_timeout'] . ';URL=' . $redirectTo . '">';
});
break;
// 301 or 302
default:
wp_redirect($redirectTo, intval($fields['custom_short_links_redirect_method']));
break;
}
} | php | public function simpleRedirect()
{
global $wp;
if (!$request = $wp->request) {
return;
}
$currentSlug = add_query_arg(array(), $request);
$post = get_page_by_title($currentSlug, 'OBJECT', 'custom-short-link');
if (!$post) {
return;
}
$fields = get_fields($post->ID);
$redirectTo = null;
// Find redirect url
switch ($fields['custom_short_links_redirect_url_type']) {
case 'external':
$redirectTo = $fields['custom_short_links_redirect_to_external'];
break;
case 'internal':
$redirectTo = $fields['custom_short_links_redirect_to_internal'];
break;
}
// Make redirect with selected method
switch ($fields['custom_short_links_redirect_method']) {
case 'meta':
add_action('wp_head', function () use ($fields, $redirectTo) {
echo '<meta http-equiv="refresh" content="' . $fields['custom_short_links_timeout'] . ';URL=' . $redirectTo . '">';
});
break;
// 301 or 302
default:
wp_redirect($redirectTo, intval($fields['custom_short_links_redirect_method']));
break;
}
} | [
"public",
"function",
"simpleRedirect",
"(",
")",
"{",
"global",
"$",
"wp",
";",
"if",
"(",
"!",
"$",
"request",
"=",
"$",
"wp",
"->",
"request",
")",
"{",
"return",
";",
"}",
"$",
"currentSlug",
"=",
"add_query_arg",
"(",
"array",
"(",
")",
",",
"$",
"request",
")",
";",
"$",
"post",
"=",
"get_page_by_title",
"(",
"$",
"currentSlug",
",",
"'OBJECT'",
",",
"'custom-short-link'",
")",
";",
"if",
"(",
"!",
"$",
"post",
")",
"{",
"return",
";",
"}",
"$",
"fields",
"=",
"get_fields",
"(",
"$",
"post",
"->",
"ID",
")",
";",
"$",
"redirectTo",
"=",
"null",
";",
"// Find redirect url",
"switch",
"(",
"$",
"fields",
"[",
"'custom_short_links_redirect_url_type'",
"]",
")",
"{",
"case",
"'external'",
":",
"$",
"redirectTo",
"=",
"$",
"fields",
"[",
"'custom_short_links_redirect_to_external'",
"]",
";",
"break",
";",
"case",
"'internal'",
":",
"$",
"redirectTo",
"=",
"$",
"fields",
"[",
"'custom_short_links_redirect_to_internal'",
"]",
";",
"break",
";",
"}",
"// Make redirect with selected method",
"switch",
"(",
"$",
"fields",
"[",
"'custom_short_links_redirect_method'",
"]",
")",
"{",
"case",
"'meta'",
":",
"add_action",
"(",
"'wp_head'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"fields",
",",
"$",
"redirectTo",
")",
"{",
"echo",
"'<meta http-equiv=\"refresh\" content=\"'",
".",
"$",
"fields",
"[",
"'custom_short_links_timeout'",
"]",
".",
"';URL='",
".",
"$",
"redirectTo",
".",
"'\">'",
";",
"}",
")",
";",
"break",
";",
"// 301 or 302",
"default",
":",
"wp_redirect",
"(",
"$",
"redirectTo",
",",
"intval",
"(",
"$",
"fields",
"[",
"'custom_short_links_redirect_method'",
"]",
")",
")",
";",
"break",
";",
"}",
"}"
] | Make a simple PHP redirect to the target page
@return void | [
"Make",
"a",
"simple",
"PHP",
"redirect",
"to",
"the",
"target",
"page"
] | 3b82a090eb2318470278c9f888e37527f31ddecc | https://github.com/helsingborg-stad/custom-short-links/blob/3b82a090eb2318470278c9f888e37527f31ddecc/source/php/Shortlinks.php#L131-L171 | train |
itcreator/custom-cmf | Module/Url/src/Cmf/Url/Builder/Adapter/Short.php | Short.validateUrlData | protected function validateUrlData($urlData, $i)
{
$part1 = isset($urlData[$i]) ? explode('~', $urlData[$i]) : [];
$part2 = isset($urlData[$i + 1]) ? explode('~', $urlData[$i + 1]) : [];
$part3 = isset($urlData[$i + 2]) ? explode('~', $urlData[$i + 2]) : [];
if (count($part1) == 1) {
$module = $part1[0];
if (count($part2) == 1) {
$controller = $part2[0];
if (count($part3) == 1) {
$action = $part3[0];
} else {
$action = '';
}
} else {
$controller = '';
$action = '';
}
} else {
$controller = '';
$action = '';
$module = '';
}
$config = Application::getConfigManager()->loadForModule('Cmf\System', 'module');
$isDefaultModule = $module == $config->defaultModule;
$isDefaultAction = $action == $config->defaultAction;
$isDefaultController = ($action == '' && $controller == $config->defaultController);
if ($isDefaultModule || $isDefaultAction || $isDefaultController) {
$result = false;
} else {
$result = true;
}
return $result;
} | php | protected function validateUrlData($urlData, $i)
{
$part1 = isset($urlData[$i]) ? explode('~', $urlData[$i]) : [];
$part2 = isset($urlData[$i + 1]) ? explode('~', $urlData[$i + 1]) : [];
$part3 = isset($urlData[$i + 2]) ? explode('~', $urlData[$i + 2]) : [];
if (count($part1) == 1) {
$module = $part1[0];
if (count($part2) == 1) {
$controller = $part2[0];
if (count($part3) == 1) {
$action = $part3[0];
} else {
$action = '';
}
} else {
$controller = '';
$action = '';
}
} else {
$controller = '';
$action = '';
$module = '';
}
$config = Application::getConfigManager()->loadForModule('Cmf\System', 'module');
$isDefaultModule = $module == $config->defaultModule;
$isDefaultAction = $action == $config->defaultAction;
$isDefaultController = ($action == '' && $controller == $config->defaultController);
if ($isDefaultModule || $isDefaultAction || $isDefaultController) {
$result = false;
} else {
$result = true;
}
return $result;
} | [
"protected",
"function",
"validateUrlData",
"(",
"$",
"urlData",
",",
"$",
"i",
")",
"{",
"$",
"part1",
"=",
"isset",
"(",
"$",
"urlData",
"[",
"$",
"i",
"]",
")",
"?",
"explode",
"(",
"'~'",
",",
"$",
"urlData",
"[",
"$",
"i",
"]",
")",
":",
"[",
"]",
";",
"$",
"part2",
"=",
"isset",
"(",
"$",
"urlData",
"[",
"$",
"i",
"+",
"1",
"]",
")",
"?",
"explode",
"(",
"'~'",
",",
"$",
"urlData",
"[",
"$",
"i",
"+",
"1",
"]",
")",
":",
"[",
"]",
";",
"$",
"part3",
"=",
"isset",
"(",
"$",
"urlData",
"[",
"$",
"i",
"+",
"2",
"]",
")",
"?",
"explode",
"(",
"'~'",
",",
"$",
"urlData",
"[",
"$",
"i",
"+",
"2",
"]",
")",
":",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"part1",
")",
"==",
"1",
")",
"{",
"$",
"module",
"=",
"$",
"part1",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"part2",
")",
"==",
"1",
")",
"{",
"$",
"controller",
"=",
"$",
"part2",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"part3",
")",
"==",
"1",
")",
"{",
"$",
"action",
"=",
"$",
"part3",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"action",
"=",
"''",
";",
"}",
"}",
"else",
"{",
"$",
"controller",
"=",
"''",
";",
"$",
"action",
"=",
"''",
";",
"}",
"}",
"else",
"{",
"$",
"controller",
"=",
"''",
";",
"$",
"action",
"=",
"''",
";",
"$",
"module",
"=",
"''",
";",
"}",
"$",
"config",
"=",
"Application",
"::",
"getConfigManager",
"(",
")",
"->",
"loadForModule",
"(",
"'Cmf\\System'",
",",
"'module'",
")",
";",
"$",
"isDefaultModule",
"=",
"$",
"module",
"==",
"$",
"config",
"->",
"defaultModule",
";",
"$",
"isDefaultAction",
"=",
"$",
"action",
"==",
"$",
"config",
"->",
"defaultAction",
";",
"$",
"isDefaultController",
"=",
"(",
"$",
"action",
"==",
"''",
"&&",
"$",
"controller",
"==",
"$",
"config",
"->",
"defaultController",
")",
";",
"if",
"(",
"$",
"isDefaultModule",
"||",
"$",
"isDefaultAction",
"||",
"$",
"isDefaultController",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | This function check for duplicate of page
It's need for SEO
@param array $urlData
@param int $i
@return bool | [
"This",
"function",
"check",
"for",
"duplicate",
"of",
"page",
"It",
"s",
"need",
"for",
"SEO"
] | 42fc0535dfa0f641856f06673f6ab596b2020c40 | https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/Url/src/Cmf/Url/Builder/Adapter/Short.php#L101-L138 | train |
shgysk8zer0/core_api | traits/mime_type.php | Mime_Type.getMimeTypeFromFile | public function getMimeTypeFromFile($file)
{
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (array_key_exists($extension, $this->_alt_mime_types)) {
return $this->_alt_mime_types[$extension];
} else {
return (new \Finfo(FILEINFO_MIME_TYPE))->file($file);
}
} | php | public function getMimeTypeFromFile($file)
{
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (array_key_exists($extension, $this->_alt_mime_types)) {
return $this->_alt_mime_types[$extension];
} else {
return (new \Finfo(FILEINFO_MIME_TYPE))->file($file);
}
} | [
"public",
"function",
"getMimeTypeFromFile",
"(",
"$",
"file",
")",
"{",
"$",
"extension",
"=",
"strtolower",
"(",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"extension",
",",
"$",
"this",
"->",
"_alt_mime_types",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_alt_mime_types",
"[",
"$",
"extension",
"]",
";",
"}",
"else",
"{",
"return",
"(",
"new",
"\\",
"Finfo",
"(",
"FILEINFO_MIME_TYPE",
")",
")",
"->",
"file",
"(",
"$",
"file",
")",
";",
"}",
"}"
] | Get mime-type from file.
Checks extensions array first, then attempts to get mime-type using Finfo
@param string $file Path to file
@return string Mime-type | [
"Get",
"mime",
"-",
"type",
"from",
"file",
".",
"Checks",
"extensions",
"array",
"first",
"then",
"attempts",
"to",
"get",
"mime",
"-",
"type",
"using",
"Finfo"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/mime_type.php#L65-L73 | train |
cmsgears/module-community | common/models/mappers/Friend.php | Friend.getFriend | public function getFriend() {
$userTable = CoreTables::getTableName( CoreTables::TABLE_USER );
return $this->hasOne( User::class, [ 'id' => 'friendId' ] )->from( "$userTable as friend" );
} | php | public function getFriend() {
$userTable = CoreTables::getTableName( CoreTables::TABLE_USER );
return $this->hasOne( User::class, [ 'id' => 'friendId' ] )->from( "$userTable as friend" );
} | [
"public",
"function",
"getFriend",
"(",
")",
"{",
"$",
"userTable",
"=",
"CoreTables",
"::",
"getTableName",
"(",
"CoreTables",
"::",
"TABLE_USER",
")",
";",
"return",
"$",
"this",
"->",
"hasOne",
"(",
"User",
"::",
"class",
",",
"[",
"'id'",
"=>",
"'friendId'",
"]",
")",
"->",
"from",
"(",
"\"$userTable as friend\"",
")",
";",
"}"
] | Return user who got friendship invite.
@return \cmsgears\core\common\models\entities\User | [
"Return",
"user",
"who",
"got",
"friendship",
"invite",
"."
] | 0ca9cf0aa0cee395a4788bd6085f291e10728555 | https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/common/models/mappers/Friend.php#L196-L201 | train |
infusephp/cron | src/Libs/Run.php | Run.writeOutput | public function writeOutput($str)
{
if (empty($str)) {
return $this;
}
$this->output[] = $str;
if ($this->consoleOutput) {
$this->consoleOutput->writeln($str);
}
return $this;
} | php | public function writeOutput($str)
{
if (empty($str)) {
return $this;
}
$this->output[] = $str;
if ($this->consoleOutput) {
$this->consoleOutput->writeln($str);
}
return $this;
} | [
"public",
"function",
"writeOutput",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"str",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"output",
"[",
"]",
"=",
"$",
"str",
";",
"if",
"(",
"$",
"this",
"->",
"consoleOutput",
")",
"{",
"$",
"this",
"->",
"consoleOutput",
"->",
"writeln",
"(",
"$",
"str",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Writes output to the run.
@param string $str
@return self | [
"Writes",
"output",
"to",
"the",
"run",
"."
] | 783f6078b455a48415efeba0a6ee97ab17a3a903 | https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/Run.php#L44-L57 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.