repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
Wedeto/Auth
src/ACL/Rule.php
Rule.setRole
public function setRole($role_id) { if (!empty($role_id) && $this->policy === Rule::NOINHERIT) throw new Exception("Rule::NOINHERIT can not be used in combination with a role"); if ($role_id instanceof Role) { $this->role = $role_id; $role_id = $role_id->getID(); } elseif (!is_scalar($role_id)) throw new Exception("Role-ID must be a Role or a scalar"); if ($role_id !== $this->role_id) { $this->changed = true; $this->role_id = $role_id; } }
php
public function setRole($role_id) { if (!empty($role_id) && $this->policy === Rule::NOINHERIT) throw new Exception("Rule::NOINHERIT can not be used in combination with a role"); if ($role_id instanceof Role) { $this->role = $role_id; $role_id = $role_id->getID(); } elseif (!is_scalar($role_id)) throw new Exception("Role-ID must be a Role or a scalar"); if ($role_id !== $this->role_id) { $this->changed = true; $this->role_id = $role_id; } }
[ "public", "function", "setRole", "(", "$", "role_id", ")", "{", "if", "(", "!", "empty", "(", "$", "role_id", ")", "&&", "$", "this", "->", "policy", "===", "Rule", "::", "NOINHERIT", ")", "throw", "new", "Exception", "(", "\"Rule::NOINHERIT can not be used in combination with a role\"", ")", ";", "if", "(", "$", "role_id", "instanceof", "Role", ")", "{", "$", "this", "->", "role", "=", "$", "role_id", ";", "$", "role_id", "=", "$", "role_id", "->", "getID", "(", ")", ";", "}", "elseif", "(", "!", "is_scalar", "(", "$", "role_id", ")", ")", "throw", "new", "Exception", "(", "\"Role-ID must be a Role or a scalar\"", ")", ";", "if", "(", "$", "role_id", "!==", "$", "this", "->", "role_id", ")", "{", "$", "this", "->", "changed", "=", "true", ";", "$", "this", "->", "role_id", "=", "$", "role_id", ";", "}", "}" ]
Set the role this Rule applies to. @param scala|Role $role_id Either a Role object or a Role-ID @throws Wedeto\ACL\Exception When the role is not a Role object or a scalar
[ "Set", "the", "role", "this", "Rule", "applies", "to", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Rule.php#L111-L129
train
Wedeto/Auth
src/ACL/Rule.php
Rule.setEntity
public function setEntity($entity_id) { if ($entity_id instanceof Entity) { $this->entity = $entity_id; $entity_id = $entity_id->getID(); } elseif (!is_scalar($entity_id)) throw new Exception("Entity-ID must be an Entity or a scalar"); if ($entity_id !== $this->entity_id) { $this->entity_id = $entity_id; $this->changed = true; } }
php
public function setEntity($entity_id) { if ($entity_id instanceof Entity) { $this->entity = $entity_id; $entity_id = $entity_id->getID(); } elseif (!is_scalar($entity_id)) throw new Exception("Entity-ID must be an Entity or a scalar"); if ($entity_id !== $this->entity_id) { $this->entity_id = $entity_id; $this->changed = true; } }
[ "public", "function", "setEntity", "(", "$", "entity_id", ")", "{", "if", "(", "$", "entity_id", "instanceof", "Entity", ")", "{", "$", "this", "->", "entity", "=", "$", "entity_id", ";", "$", "entity_id", "=", "$", "entity_id", "->", "getID", "(", ")", ";", "}", "elseif", "(", "!", "is_scalar", "(", "$", "entity_id", ")", ")", "throw", "new", "Exception", "(", "\"Entity-ID must be an Entity or a scalar\"", ")", ";", "if", "(", "$", "entity_id", "!==", "$", "this", "->", "entity_id", ")", "{", "$", "this", "->", "entity_id", "=", "$", "entity_id", ";", "$", "this", "->", "changed", "=", "true", ";", "}", "}" ]
Set the entity this Rule applies to @param scalar|Entity $entity_id Either a Entity object or a Role-ID @throws Wedeto\ACL\Exception When the entity is not a Entity object or a scalar
[ "Set", "the", "entity", "this", "Rule", "applies", "to" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Rule.php#L137-L152
train
Wedeto/Auth
src/ACL/Rule.php
Rule.setPolicy
public function setPolicy(int $policy) { if (!($policy === Rule::ALLOW || $policy === Rule::DENY || $policy === Rule::INHERIT || $policy === Rule::NOINHERIT)) throw new Exception("Policy must be either Rule::ALLOW, Rule::DENY, Rule::INHERIT or Rule::NOINHERIT"); if ($policy === Rule::NOINHERIT && !empty($this->action)) throw new Exception("Rule::NOINHERIT can not be used in combination with an action"); if ($policy === Rule::NOINHERIT && !empty($this->role_id)) throw new Exception("Rule::NOINHERIT can not be used in combination with a role"); if ($policy !== $this->policy) { $this->policy = $policy; $this->changed = true; } }
php
public function setPolicy(int $policy) { if (!($policy === Rule::ALLOW || $policy === Rule::DENY || $policy === Rule::INHERIT || $policy === Rule::NOINHERIT)) throw new Exception("Policy must be either Rule::ALLOW, Rule::DENY, Rule::INHERIT or Rule::NOINHERIT"); if ($policy === Rule::NOINHERIT && !empty($this->action)) throw new Exception("Rule::NOINHERIT can not be used in combination with an action"); if ($policy === Rule::NOINHERIT && !empty($this->role_id)) throw new Exception("Rule::NOINHERIT can not be used in combination with a role"); if ($policy !== $this->policy) { $this->policy = $policy; $this->changed = true; } }
[ "public", "function", "setPolicy", "(", "int", "$", "policy", ")", "{", "if", "(", "!", "(", "$", "policy", "===", "Rule", "::", "ALLOW", "||", "$", "policy", "===", "Rule", "::", "DENY", "||", "$", "policy", "===", "Rule", "::", "INHERIT", "||", "$", "policy", "===", "Rule", "::", "NOINHERIT", ")", ")", "throw", "new", "Exception", "(", "\"Policy must be either Rule::ALLOW, Rule::DENY, Rule::INHERIT or Rule::NOINHERIT\"", ")", ";", "if", "(", "$", "policy", "===", "Rule", "::", "NOINHERIT", "&&", "!", "empty", "(", "$", "this", "->", "action", ")", ")", "throw", "new", "Exception", "(", "\"Rule::NOINHERIT can not be used in combination with an action\"", ")", ";", "if", "(", "$", "policy", "===", "Rule", "::", "NOINHERIT", "&&", "!", "empty", "(", "$", "this", "->", "role_id", ")", ")", "throw", "new", "Exception", "(", "\"Rule::NOINHERIT can not be used in combination with a role\"", ")", ";", "if", "(", "$", "policy", "!==", "$", "this", "->", "policy", ")", "{", "$", "this", "->", "policy", "=", "$", "policy", ";", "$", "this", "->", "changed", "=", "true", ";", "}", "}" ]
Set the policy on the entity @param policy integer Should be one of Rule::ALLOW, Rule::DENY or Rule::UNDEFINED @throws Wedeto\ACL\Exception When the Rule is not ALLOW, DENY or UNDEFINED
[ "Set", "the", "policy", "on", "the", "entity" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Rule.php#L179-L195
train
Wedeto/Auth
src/ACL/Rule.php
Rule.setAction
public function setAction(string $action) { if (!empty($action) && $this->policy === Rule::NOINHERIT) throw new Exception("Rule::NOINHERIT can not be used in combination with an action"); $action = (string)$action; if ($action !== $this->action) { $validator = $this->acl->getActionValidator(); if (null !== $validator) { if (($reason = $validator->isValid($action)) !== true) throw new Exception("Action can not be validated: " . $reason); } $this->changed = true; $this->action = $action; } }
php
public function setAction(string $action) { if (!empty($action) && $this->policy === Rule::NOINHERIT) throw new Exception("Rule::NOINHERIT can not be used in combination with an action"); $action = (string)$action; if ($action !== $this->action) { $validator = $this->acl->getActionValidator(); if (null !== $validator) { if (($reason = $validator->isValid($action)) !== true) throw new Exception("Action can not be validated: " . $reason); } $this->changed = true; $this->action = $action; } }
[ "public", "function", "setAction", "(", "string", "$", "action", ")", "{", "if", "(", "!", "empty", "(", "$", "action", ")", "&&", "$", "this", "->", "policy", "===", "Rule", "::", "NOINHERIT", ")", "throw", "new", "Exception", "(", "\"Rule::NOINHERIT can not be used in combination with an action\"", ")", ";", "$", "action", "=", "(", "string", ")", "$", "action", ";", "if", "(", "$", "action", "!==", "$", "this", "->", "action", ")", "{", "$", "validator", "=", "$", "this", "->", "acl", "->", "getActionValidator", "(", ")", ";", "if", "(", "null", "!==", "$", "validator", ")", "{", "if", "(", "(", "$", "reason", "=", "$", "validator", "->", "isValid", "(", "$", "action", ")", ")", "!==", "true", ")", "throw", "new", "Exception", "(", "\"Action can not be validated: \"", ".", "$", "reason", ")", ";", "}", "$", "this", "->", "changed", "=", "true", ";", "$", "this", "->", "action", "=", "$", "action", ";", "}", "}" ]
Set the action on the entity @param $action scalar The action this Rule has a policy on. @throws Wedeto\ACL\Exception When the action is not a scalar
[ "Set", "the", "action", "on", "the", "entity" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Rule.php#L202-L219
train
kynx/v8js-handlebars
src/Handlebars.php
Handlebars.isRegistered
public static function isRegistered($runtime = false) { $extension = $runtime ? self::EXTN_RUNTIME : self::EXTN_HANDLEBARS; return isset(V8Js::getExtensions()[$extension]); }
php
public static function isRegistered($runtime = false) { $extension = $runtime ? self::EXTN_RUNTIME : self::EXTN_HANDLEBARS; return isset(V8Js::getExtensions()[$extension]); }
[ "public", "static", "function", "isRegistered", "(", "$", "runtime", "=", "false", ")", "{", "$", "extension", "=", "$", "runtime", "?", "self", "::", "EXTN_RUNTIME", ":", "self", "::", "EXTN_HANDLEBARS", ";", "return", "isset", "(", "V8Js", "::", "getExtensions", "(", ")", "[", "$", "extension", "]", ")", ";", "}" ]
Returns true if the handlebars has been registered with V8Js @param bool|false $runtime @return bool
[ "Returns", "true", "if", "the", "handlebars", "has", "been", "registered", "with", "V8Js" ]
8e450d930efbcd56eb12ba36516831d8e1407a24
https://github.com/kynx/v8js-handlebars/blob/8e450d930efbcd56eb12ba36516831d8e1407a24/src/Handlebars.php#L67-L71
train
kynx/v8js-handlebars
src/Handlebars.php
Handlebars.registerHandlebarsExtension
public static function registerHandlebarsExtension($source, $runtime = false) { if (!self::isRegistered($runtime)) { $extension = $runtime ? self::EXTN_RUNTIME : self::EXTN_HANDLEBARS; V8Js::registerExtension($extension, $source, [], false); } }
php
public static function registerHandlebarsExtension($source, $runtime = false) { if (!self::isRegistered($runtime)) { $extension = $runtime ? self::EXTN_RUNTIME : self::EXTN_HANDLEBARS; V8Js::registerExtension($extension, $source, [], false); } }
[ "public", "static", "function", "registerHandlebarsExtension", "(", "$", "source", ",", "$", "runtime", "=", "false", ")", "{", "if", "(", "!", "self", "::", "isRegistered", "(", "$", "runtime", ")", ")", "{", "$", "extension", "=", "$", "runtime", "?", "self", "::", "EXTN_RUNTIME", ":", "self", "::", "EXTN_HANDLEBARS", ";", "V8Js", "::", "registerExtension", "(", "$", "extension", ",", "$", "source", ",", "[", "]", ",", "false", ")", ";", "}", "}" ]
Registers handlebars script with V8Js This *must* be called before the first call to self::create() @param string $source @param boolean $runtime
[ "Registers", "handlebars", "script", "with", "V8Js" ]
8e450d930efbcd56eb12ba36516831d8e1407a24
https://github.com/kynx/v8js-handlebars/blob/8e450d930efbcd56eb12ba36516831d8e1407a24/src/Handlebars.php#L80-L86
train
kynx/v8js-handlebars
src/Handlebars.php
Handlebars.create
public static function create($runtime = false, $extensions = [], $report_uncaught_exceptions = true) { return new Handlebars($runtime, $extensions, $report_uncaught_exceptions); }
php
public static function create($runtime = false, $extensions = [], $report_uncaught_exceptions = true) { return new Handlebars($runtime, $extensions, $report_uncaught_exceptions); }
[ "public", "static", "function", "create", "(", "$", "runtime", "=", "false", ",", "$", "extensions", "=", "[", "]", ",", "$", "report_uncaught_exceptions", "=", "true", ")", "{", "return", "new", "Handlebars", "(", "$", "runtime", ",", "$", "extensions", ",", "$", "report_uncaught_exceptions", ")", ";", "}" ]
Returns configured Handlebars instance @param boolean $runtime @param array $extensions @param bool|true $report_uncaught_exceptions @return Handlebars
[ "Returns", "configured", "Handlebars", "instance" ]
8e450d930efbcd56eb12ba36516831d8e1407a24
https://github.com/kynx/v8js-handlebars/blob/8e450d930efbcd56eb12ba36516831d8e1407a24/src/Handlebars.php#L95-L98
train
kynx/v8js-handlebars
src/Handlebars.php
Handlebars.precompile
public function precompile($template, $options = []) { if ($this->isRuntime) { throw new \BadMethodCallException("Cannot precompile templates using runtime"); } $this->v8->template = $template; $this->v8->options = $options; return $this->v8->executeString( 'jsHb.precompile(phpHb.template, phpHb.options)', __CLASS__ . '::' . __METHOD__ . '()' ); }
php
public function precompile($template, $options = []) { if ($this->isRuntime) { throw new \BadMethodCallException("Cannot precompile templates using runtime"); } $this->v8->template = $template; $this->v8->options = $options; return $this->v8->executeString( 'jsHb.precompile(phpHb.template, phpHb.options)', __CLASS__ . '::' . __METHOD__ . '()' ); }
[ "public", "function", "precompile", "(", "$", "template", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "isRuntime", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "\"Cannot precompile templates using runtime\"", ")", ";", "}", "$", "this", "->", "v8", "->", "template", "=", "$", "template", ";", "$", "this", "->", "v8", "->", "options", "=", "$", "options", ";", "return", "$", "this", "->", "v8", "->", "executeString", "(", "'jsHb.precompile(phpHb.template, phpHb.options)'", ",", "__CLASS__", ".", "'::'", ".", "__METHOD__", ".", "'()'", ")", ";", "}" ]
Precompiles a given template so it can be sent to the client and executed without compilation @param string $template @param array $options @return mixed
[ "Precompiles", "a", "given", "template", "so", "it", "can", "be", "sent", "to", "the", "client", "and", "executed", "without", "compilation" ]
8e450d930efbcd56eb12ba36516831d8e1407a24
https://github.com/kynx/v8js-handlebars/blob/8e450d930efbcd56eb12ba36516831d8e1407a24/src/Handlebars.php#L126-L138
train
kynx/v8js-handlebars
src/Handlebars.php
Handlebars.registerPartial
public function registerPartial($name, $partial = false) { $partials = []; if (is_array($name)) { $partials = $name; } elseif (is_object($name)) { $partials = get_object_vars($name); } if (count($partials)) { $this->registerPhpArray('partial', $partials); } elseif ($partial === false) { $this->registerJavascriptObject('partial', $name); } else { $this->register('partial', $name, $partial); } }
php
public function registerPartial($name, $partial = false) { $partials = []; if (is_array($name)) { $partials = $name; } elseif (is_object($name)) { $partials = get_object_vars($name); } if (count($partials)) { $this->registerPhpArray('partial', $partials); } elseif ($partial === false) { $this->registerJavascriptObject('partial', $name); } else { $this->register('partial', $name, $partial); } }
[ "public", "function", "registerPartial", "(", "$", "name", ",", "$", "partial", "=", "false", ")", "{", "$", "partials", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "partials", "=", "$", "name", ";", "}", "elseif", "(", "is_object", "(", "$", "name", ")", ")", "{", "$", "partials", "=", "get_object_vars", "(", "$", "name", ")", ";", "}", "if", "(", "count", "(", "$", "partials", ")", ")", "{", "$", "this", "->", "registerPhpArray", "(", "'partial'", ",", "$", "partials", ")", ";", "}", "elseif", "(", "$", "partial", "===", "false", ")", "{", "$", "this", "->", "registerJavascriptObject", "(", "'partial'", ",", "$", "name", ")", ";", "}", "else", "{", "$", "this", "->", "register", "(", "'partial'", ",", "$", "name", ",", "$", "partial", ")", ";", "}", "}" ]
Registers partials accessible by any template in the environment @param string|array|object $name @param string|bool $partial
[ "Registers", "partials", "accessible", "by", "any", "template", "in", "the", "environment" ]
8e450d930efbcd56eb12ba36516831d8e1407a24
https://github.com/kynx/v8js-handlebars/blob/8e450d930efbcd56eb12ba36516831d8e1407a24/src/Handlebars.php#L158-L174
train
kynx/v8js-handlebars
src/Handlebars.php
Handlebars.registerHelper
public function registerHelper($name, $helper = false) { if (is_array($name)) { foreach ($name as $n => $helper) { $this->registerHelper($n, $helper); } } elseif (is_object($name)) { $this->registerJavascriptObject('helper', $this->wrapHelperObject($name)); } elseif ($helper === false) { $this->registerJavascriptObject('helper', $name); } elseif (is_callable($helper)) { $this->registerJavascriptFunction('helper', $name, $this->wrapHelperCallable($name, $helper)); } else { $this->registerJavascriptFunction('helper', $name, $helper); } }
php
public function registerHelper($name, $helper = false) { if (is_array($name)) { foreach ($name as $n => $helper) { $this->registerHelper($n, $helper); } } elseif (is_object($name)) { $this->registerJavascriptObject('helper', $this->wrapHelperObject($name)); } elseif ($helper === false) { $this->registerJavascriptObject('helper', $name); } elseif (is_callable($helper)) { $this->registerJavascriptFunction('helper', $name, $this->wrapHelperCallable($name, $helper)); } else { $this->registerJavascriptFunction('helper', $name, $helper); } }
[ "public", "function", "registerHelper", "(", "$", "name", ",", "$", "helper", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "foreach", "(", "$", "name", "as", "$", "n", "=>", "$", "helper", ")", "{", "$", "this", "->", "registerHelper", "(", "$", "n", ",", "$", "helper", ")", ";", "}", "}", "elseif", "(", "is_object", "(", "$", "name", ")", ")", "{", "$", "this", "->", "registerJavascriptObject", "(", "'helper'", ",", "$", "this", "->", "wrapHelperObject", "(", "$", "name", ")", ")", ";", "}", "elseif", "(", "$", "helper", "===", "false", ")", "{", "$", "this", "->", "registerJavascriptObject", "(", "'helper'", ",", "$", "name", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "helper", ")", ")", "{", "$", "this", "->", "registerJavascriptFunction", "(", "'helper'", ",", "$", "name", ",", "$", "this", "->", "wrapHelperCallable", "(", "$", "name", ",", "$", "helper", ")", ")", ";", "}", "else", "{", "$", "this", "->", "registerJavascriptFunction", "(", "'helper'", ",", "$", "name", ",", "$", "helper", ")", ";", "}", "}" ]
Registers helpers accessible by any template in the environment @param string|array|object $name @param string|callable|bool $helper
[ "Registers", "helpers", "accessible", "by", "any", "template", "in", "the", "environment" ]
8e450d930efbcd56eb12ba36516831d8e1407a24
https://github.com/kynx/v8js-handlebars/blob/8e450d930efbcd56eb12ba36516831d8e1407a24/src/Handlebars.php#L190-L205
train
kynx/v8js-handlebars
src/Handlebars.php
Handlebars.registerDecorator
public function registerDecorator($name, $decorator) { if (is_object($name)) { $this->registerJavascriptObject('decorator', $this->wrapDecoratorObject($name)); } elseif ($decorator === false) { $this->registerJavascriptObject('decorator', $name); } elseif (is_callable($decorator)) { $this->registerJavascriptFunction('decorator', $name, $this->wrapDecoratorCallable($name, $decorator)); } else { $this->registerJavascriptFunction('decorator', $name, $decorator); } }
php
public function registerDecorator($name, $decorator) { if (is_object($name)) { $this->registerJavascriptObject('decorator', $this->wrapDecoratorObject($name)); } elseif ($decorator === false) { $this->registerJavascriptObject('decorator', $name); } elseif (is_callable($decorator)) { $this->registerJavascriptFunction('decorator', $name, $this->wrapDecoratorCallable($name, $decorator)); } else { $this->registerJavascriptFunction('decorator', $name, $decorator); } }
[ "public", "function", "registerDecorator", "(", "$", "name", ",", "$", "decorator", ")", "{", "if", "(", "is_object", "(", "$", "name", ")", ")", "{", "$", "this", "->", "registerJavascriptObject", "(", "'decorator'", ",", "$", "this", "->", "wrapDecoratorObject", "(", "$", "name", ")", ")", ";", "}", "elseif", "(", "$", "decorator", "===", "false", ")", "{", "$", "this", "->", "registerJavascriptObject", "(", "'decorator'", ",", "$", "name", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "decorator", ")", ")", "{", "$", "this", "->", "registerJavascriptFunction", "(", "'decorator'", ",", "$", "name", ",", "$", "this", "->", "wrapDecoratorCallable", "(", "$", "name", ",", "$", "decorator", ")", ")", ";", "}", "else", "{", "$", "this", "->", "registerJavascriptFunction", "(", "'decorator'", ",", "$", "name", ",", "$", "decorator", ")", ";", "}", "}" ]
Registers a decorator accessible by any template in the environment @param string|object $name @param string|callable|bool $decorator
[ "Registers", "a", "decorator", "accessible", "by", "any", "template", "in", "the", "environment" ]
8e450d930efbcd56eb12ba36516831d8e1407a24
https://github.com/kynx/v8js-handlebars/blob/8e450d930efbcd56eb12ba36516831d8e1407a24/src/Handlebars.php#L221-L232
train
Wedeto/Util
src/Functions.php
Functions.is_int_val
public static function is_int_val($val) { if (is_int($val)) return true; if (is_bool($val)) return false; if (!is_string($val)) return false; return (string)((int)$val) === $val; }
php
public static function is_int_val($val) { if (is_int($val)) return true; if (is_bool($val)) return false; if (!is_string($val)) return false; return (string)((int)$val) === $val; }
[ "public", "static", "function", "is_int_val", "(", "$", "val", ")", "{", "if", "(", "is_int", "(", "$", "val", ")", ")", "return", "true", ";", "if", "(", "is_bool", "(", "$", "val", ")", ")", "return", "false", ";", "if", "(", "!", "is_string", "(", "$", "val", ")", ")", "return", "false", ";", "return", "(", "string", ")", "(", "(", "int", ")", "$", "val", ")", "===", "$", "val", ";", "}" ]
Check if the provided value contains an integer value. The value may be an int, or anything convertable to an int. After conversion, the string representation of the value before and after conversion are compared, and if they are equal, the value is considered a proper integral value. @param mixed $val The value to test @return boolean True when $val is considered an integral value, false otherwise
[ "Check", "if", "the", "provided", "value", "contains", "an", "integer", "value", ".", "The", "value", "may", "be", "an", "int", "or", "anything", "convertable", "to", "an", "int", ".", "After", "conversion", "the", "string", "representation", "of", "the", "value", "before", "and", "after", "conversion", "are", "compared", "and", "if", "they", "are", "equal", "the", "value", "is", "considered", "a", "proper", "integral", "value", "." ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Functions.php#L58-L65
train
Wedeto/Util
src/Functions.php
Functions.str
public static function str($obj, $html = false, $depth = 0) { if (is_null($obj)) return "NULL"; if (is_bool($obj)) return $obj ? "TRUE" : "FALSE"; if (is_scalar($obj)) return (string)$obj; $str = ""; if ($obj instanceof Throwable) { $str = self::exceptionToString($obj); } else if (is_object($obj) && method_exists($obj, '__toString')) { $str = (string)$obj; } else if (is_object($obj) && $obj instanceof \JsonSerializable) { $obj = $obj->jsonSerialize(); } if (empty($str) && is_array($obj)) { if ($depth > 1) return '[...]'; $vals = []; foreach ($obj as $k => $v) { $repr = ""; if (!is_int($k)) $repr = "'$k' => "; $repr .= self::str($v, $html, $depth + 1); $vals[] = $repr; } return '[' . implode(', ', $vals) . ']'; } elseif (empty($str)) { $str = self::sprint_r($obj); } if ($html) { $str = nl2br($str); $str = str_replace(' ', '  ', $str); } return $str; }
php
public static function str($obj, $html = false, $depth = 0) { if (is_null($obj)) return "NULL"; if (is_bool($obj)) return $obj ? "TRUE" : "FALSE"; if (is_scalar($obj)) return (string)$obj; $str = ""; if ($obj instanceof Throwable) { $str = self::exceptionToString($obj); } else if (is_object($obj) && method_exists($obj, '__toString')) { $str = (string)$obj; } else if (is_object($obj) && $obj instanceof \JsonSerializable) { $obj = $obj->jsonSerialize(); } if (empty($str) && is_array($obj)) { if ($depth > 1) return '[...]'; $vals = []; foreach ($obj as $k => $v) { $repr = ""; if (!is_int($k)) $repr = "'$k' => "; $repr .= self::str($v, $html, $depth + 1); $vals[] = $repr; } return '[' . implode(', ', $vals) . ']'; } elseif (empty($str)) { $str = self::sprint_r($obj); } if ($html) { $str = nl2br($str); $str = str_replace(' ', '  ', $str); } return $str; }
[ "public", "static", "function", "str", "(", "$", "obj", ",", "$", "html", "=", "false", ",", "$", "depth", "=", "0", ")", "{", "if", "(", "is_null", "(", "$", "obj", ")", ")", "return", "\"NULL\"", ";", "if", "(", "is_bool", "(", "$", "obj", ")", ")", "return", "$", "obj", "?", "\"TRUE\"", ":", "\"FALSE\"", ";", "if", "(", "is_scalar", "(", "$", "obj", ")", ")", "return", "(", "string", ")", "$", "obj", ";", "$", "str", "=", "\"\"", ";", "if", "(", "$", "obj", "instanceof", "Throwable", ")", "{", "$", "str", "=", "self", "::", "exceptionToString", "(", "$", "obj", ")", ";", "}", "else", "if", "(", "is_object", "(", "$", "obj", ")", "&&", "method_exists", "(", "$", "obj", ",", "'__toString'", ")", ")", "{", "$", "str", "=", "(", "string", ")", "$", "obj", ";", "}", "else", "if", "(", "is_object", "(", "$", "obj", ")", "&&", "$", "obj", "instanceof", "\\", "JsonSerializable", ")", "{", "$", "obj", "=", "$", "obj", "->", "jsonSerialize", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "str", ")", "&&", "is_array", "(", "$", "obj", ")", ")", "{", "if", "(", "$", "depth", ">", "1", ")", "return", "'[...]'", ";", "$", "vals", "=", "[", "]", ";", "foreach", "(", "$", "obj", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "repr", "=", "\"\"", ";", "if", "(", "!", "is_int", "(", "$", "k", ")", ")", "$", "repr", "=", "\"'$k' => \"", ";", "$", "repr", ".=", "self", "::", "str", "(", "$", "v", ",", "$", "html", ",", "$", "depth", "+", "1", ")", ";", "$", "vals", "[", "]", "=", "$", "repr", ";", "}", "return", "'['", ".", "implode", "(", "', '", ",", "$", "vals", ")", ".", "']'", ";", "}", "elseif", "(", "empty", "(", "$", "str", ")", ")", "{", "$", "str", "=", "self", "::", "sprint_r", "(", "$", "obj", ")", ";", "}", "if", "(", "$", "html", ")", "{", "$", "str", "=", "nl2br", "(", "$", "str", ")", ";", "$", "str", "=", "str_replace", "(", "' '", ",", "'  '", ",", "$", "str", ")", ";", "}", "return", "$", "str", ";", "}" ]
Convert any object to a string representation. @param mixed $obj The variable to convert to a string @param bool $html True to add line breaks as <br>, false to add them as \n @param int $depth The recursion counter. When this increases above 1, '...' is returned @return string The value converted to a string
[ "Convert", "any", "object", "to", "a", "string", "representation", "." ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Functions.php#L285-L339
train
Wedeto/Util
src/Functions.php
Functions.sprint_r
public static function sprint_r($obj) { ob_start(); print_r($obj); $str = ob_get_contents(); ob_end_clean(); $str = preg_replace("/\s+\\(\s+/", " ( ", $str); $str = preg_replace("/\n\s+/", ", ", $str); $str = preg_replace("/\n\s*\\)/", " )", $str); return $str; }
php
public static function sprint_r($obj) { ob_start(); print_r($obj); $str = ob_get_contents(); ob_end_clean(); $str = preg_replace("/\s+\\(\s+/", " ( ", $str); $str = preg_replace("/\n\s+/", ", ", $str); $str = preg_replace("/\n\s*\\)/", " )", $str); return $str; }
[ "public", "static", "function", "sprint_r", "(", "$", "obj", ")", "{", "ob_start", "(", ")", ";", "print_r", "(", "$", "obj", ")", ";", "$", "str", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "str", "=", "preg_replace", "(", "\"/\\s+\\\\(\\s+/\"", ",", "\" ( \"", ",", "$", "str", ")", ";", "$", "str", "=", "preg_replace", "(", "\"/\\n\\s+/\"", ",", "\", \"", ",", "$", "str", ")", ";", "$", "str", "=", "preg_replace", "(", "\"/\\n\\s*\\\\)/\"", ",", "\" )\"", ",", "$", "str", ")", ";", "return", "$", "str", ";", "}" ]
Format an object using print_r, formatting to a singe line object notation
[ "Format", "an", "object", "using", "print_r", "formatting", "to", "a", "singe", "line", "object", "notation" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Functions.php#L349-L360
train
Wedeto/Util
src/Functions.php
Functions.debug
public static function debug(string $format) { if (!is_resource(self::$debug_stream)) self::$debug_stream = fopen('php://output', 'w'); $args = func_get_args(); foreach ($args as $idx => &$arg) { if ($idx === 0) $arg .= PHP_SAPI === 'cli' ? "\n" : "<br>\n"; if (!is_scalar($arg)) $arg = static::str($arg); } array_unshift($args, self::$debug_stream); call_user_func_array('fprintf', $args); }
php
public static function debug(string $format) { if (!is_resource(self::$debug_stream)) self::$debug_stream = fopen('php://output', 'w'); $args = func_get_args(); foreach ($args as $idx => &$arg) { if ($idx === 0) $arg .= PHP_SAPI === 'cli' ? "\n" : "<br>\n"; if (!is_scalar($arg)) $arg = static::str($arg); } array_unshift($args, self::$debug_stream); call_user_func_array('fprintf', $args); }
[ "public", "static", "function", "debug", "(", "string", "$", "format", ")", "{", "if", "(", "!", "is_resource", "(", "self", "::", "$", "debug_stream", ")", ")", "self", "::", "$", "debug_stream", "=", "fopen", "(", "'php://output'", ",", "'w'", ")", ";", "$", "args", "=", "func_get_args", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "idx", "=>", "&", "$", "arg", ")", "{", "if", "(", "$", "idx", "===", "0", ")", "$", "arg", ".=", "PHP_SAPI", "===", "'cli'", "?", "\"\\n\"", ":", "\"<br>\\n\"", ";", "if", "(", "!", "is_scalar", "(", "$", "arg", ")", ")", "$", "arg", "=", "static", "::", "str", "(", "$", "arg", ")", ";", "}", "array_unshift", "(", "$", "args", ",", "self", "::", "$", "debug_stream", ")", ";", "call_user_func_array", "(", "'fprintf'", ",", "$", "args", ")", ";", "}" ]
Log an output message to a specified stream @param string $format The formatting string @param ... Arguments to fprintf. Non-scalar arguments will be converted to a string using WF::str
[ "Log", "an", "output", "message", "to", "a", "specified", "stream" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Functions.php#L410-L427
train
Wedeto/Util
src/Functions.php
Functions.fillPlaceholders
public static function fillPlaceholders(string $msg, array $values) { foreach ($values as $key => $value) $msg = str_replace('{' . $key . '}', self::str($value), $msg); return $msg; }
php
public static function fillPlaceholders(string $msg, array $values) { foreach ($values as $key => $value) $msg = str_replace('{' . $key . '}', self::str($value), $msg); return $msg; }
[ "public", "static", "function", "fillPlaceholders", "(", "string", "$", "msg", ",", "array", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "$", "msg", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "self", "::", "str", "(", "$", "value", ")", ",", "$", "msg", ")", ";", "return", "$", "msg", ";", "}" ]
Fill a placeholder string @param string $msg The message to replace placeholder in @param array $values The assocative array containing the placeholders @return string The filled string
[ "Fill", "a", "placeholder", "string" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Functions.php#L444-L449
train
Wedeto/Util
src/Functions.php
Functions.clamp
public static function clamp(int $value, int $min, int $max) { return $value < $min ? $min : ($value > $max ? $max : $value); }
php
public static function clamp(int $value, int $min, int $max) { return $value < $min ? $min : ($value > $max ? $max : $value); }
[ "public", "static", "function", "clamp", "(", "int", "$", "value", ",", "int", "$", "min", ",", "int", "$", "max", ")", "{", "return", "$", "value", "<", "$", "min", "?", "$", "min", ":", "(", "$", "value", ">", "$", "max", "?", "$", "max", ":", "$", "value", ")", ";", "}" ]
Restrict the value to a specific valid range. @param int $value The value to clamp @param int $min THe minimum allowable value @param int $max The maximum allowable value @return int The value, $min when $value is less than $min, or $max when $value is more than max.
[ "Restrict", "the", "value", "to", "a", "specific", "valid", "range", "." ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Functions.php#L459-L462
train
mvccore/ext-tool-locale
src/MvcCore/Ext/Tools/Locale.php
Locale.translateParsedLocaleToAppValue
protected static function translateParsedLocaleToAppValue (\stdClass $parsedLocale) { if (!static::$windowsPlatform) { $result = $parsedLocale; } else { $result = (object) array_merge([], (array) $parsedLocale); if (!static::$LANGS) static::prepareWinConfigOppositeArrays(); $langAndLocale = $parsedLocale->lang . ($parsedLocale->locale !== NULL ? $parsedLocale->locale : ''); if (isset(static::$EXCEPTIONS[$langAndLocale])) { $exception = static::$EXCEPTIONS[$langAndLocale]; $result->lang = $exception[0]; $result->locale = $exception[1]; if ($result->locale === NULL && isset($exception[5])) $result->locale = ($exception[5] ? $exception[6] : static::$exceptionsLocales[$exception[6]]); $result->script = $exception[2]; } else { $result->system = $result->lang; $langNameUpper = strtoupper($result->lang); $result->lang = (isset(static::$LANGS[$langNameUpper]) ? static::$LANGS[$langNameUpper] : $result->lang); if ($result->script !== NULL) { $result->system .= '_' . $result->script; $scriptNameUpper = strtoupper($result->script); $result->script = (isset(static::$SCRIPTS[$scriptNameUpper]) ? static::$SCRIPTS[$scriptNameUpper] : $result->script); } if ($result->locale !== NULL) { $result->system .= '_' . $result->locale; $localeNameUpper = strtoupper($result->locale); $result->locale = (isset(static::$LOCALES[$localeNameUpper]) ? static::$LOCALES[$localeNameUpper] : $result->locale ); } } if ($result->encoding !== NULL) { $encodingOpposite = static::$encodings[$result->encoding]; if ($encodingOpposite) { $result->system .= '.' . $result->encoding; $result->encoding = $encodingOpposite; } else { $result->system .= '.' . $result->encoding; } } } return $result; }
php
protected static function translateParsedLocaleToAppValue (\stdClass $parsedLocale) { if (!static::$windowsPlatform) { $result = $parsedLocale; } else { $result = (object) array_merge([], (array) $parsedLocale); if (!static::$LANGS) static::prepareWinConfigOppositeArrays(); $langAndLocale = $parsedLocale->lang . ($parsedLocale->locale !== NULL ? $parsedLocale->locale : ''); if (isset(static::$EXCEPTIONS[$langAndLocale])) { $exception = static::$EXCEPTIONS[$langAndLocale]; $result->lang = $exception[0]; $result->locale = $exception[1]; if ($result->locale === NULL && isset($exception[5])) $result->locale = ($exception[5] ? $exception[6] : static::$exceptionsLocales[$exception[6]]); $result->script = $exception[2]; } else { $result->system = $result->lang; $langNameUpper = strtoupper($result->lang); $result->lang = (isset(static::$LANGS[$langNameUpper]) ? static::$LANGS[$langNameUpper] : $result->lang); if ($result->script !== NULL) { $result->system .= '_' . $result->script; $scriptNameUpper = strtoupper($result->script); $result->script = (isset(static::$SCRIPTS[$scriptNameUpper]) ? static::$SCRIPTS[$scriptNameUpper] : $result->script); } if ($result->locale !== NULL) { $result->system .= '_' . $result->locale; $localeNameUpper = strtoupper($result->locale); $result->locale = (isset(static::$LOCALES[$localeNameUpper]) ? static::$LOCALES[$localeNameUpper] : $result->locale ); } } if ($result->encoding !== NULL) { $encodingOpposite = static::$encodings[$result->encoding]; if ($encodingOpposite) { $result->system .= '.' . $result->encoding; $result->encoding = $encodingOpposite; } else { $result->system .= '.' . $result->encoding; } } } return $result; }
[ "protected", "static", "function", "translateParsedLocaleToAppValue", "(", "\\", "stdClass", "$", "parsedLocale", ")", "{", "if", "(", "!", "static", "::", "$", "windowsPlatform", ")", "{", "$", "result", "=", "$", "parsedLocale", ";", "}", "else", "{", "$", "result", "=", "(", "object", ")", "array_merge", "(", "[", "]", ",", "(", "array", ")", "$", "parsedLocale", ")", ";", "if", "(", "!", "static", "::", "$", "LANGS", ")", "static", "::", "prepareWinConfigOppositeArrays", "(", ")", ";", "$", "langAndLocale", "=", "$", "parsedLocale", "->", "lang", ".", "(", "$", "parsedLocale", "->", "locale", "!==", "NULL", "?", "$", "parsedLocale", "->", "locale", ":", "''", ")", ";", "if", "(", "isset", "(", "static", "::", "$", "EXCEPTIONS", "[", "$", "langAndLocale", "]", ")", ")", "{", "$", "exception", "=", "static", "::", "$", "EXCEPTIONS", "[", "$", "langAndLocale", "]", ";", "$", "result", "->", "lang", "=", "$", "exception", "[", "0", "]", ";", "$", "result", "->", "locale", "=", "$", "exception", "[", "1", "]", ";", "if", "(", "$", "result", "->", "locale", "===", "NULL", "&&", "isset", "(", "$", "exception", "[", "5", "]", ")", ")", "$", "result", "->", "locale", "=", "(", "$", "exception", "[", "5", "]", "?", "$", "exception", "[", "6", "]", ":", "static", "::", "$", "exceptionsLocales", "[", "$", "exception", "[", "6", "]", "]", ")", ";", "$", "result", "->", "script", "=", "$", "exception", "[", "2", "]", ";", "}", "else", "{", "$", "result", "->", "system", "=", "$", "result", "->", "lang", ";", "$", "langNameUpper", "=", "strtoupper", "(", "$", "result", "->", "lang", ")", ";", "$", "result", "->", "lang", "=", "(", "isset", "(", "static", "::", "$", "LANGS", "[", "$", "langNameUpper", "]", ")", "?", "static", "::", "$", "LANGS", "[", "$", "langNameUpper", "]", ":", "$", "result", "->", "lang", ")", ";", "if", "(", "$", "result", "->", "script", "!==", "NULL", ")", "{", "$", "result", "->", "system", ".=", "'_'", ".", "$", "result", "->", "script", ";", "$", "scriptNameUpper", "=", "strtoupper", "(", "$", "result", "->", "script", ")", ";", "$", "result", "->", "script", "=", "(", "isset", "(", "static", "::", "$", "SCRIPTS", "[", "$", "scriptNameUpper", "]", ")", "?", "static", "::", "$", "SCRIPTS", "[", "$", "scriptNameUpper", "]", ":", "$", "result", "->", "script", ")", ";", "}", "if", "(", "$", "result", "->", "locale", "!==", "NULL", ")", "{", "$", "result", "->", "system", ".=", "'_'", ".", "$", "result", "->", "locale", ";", "$", "localeNameUpper", "=", "strtoupper", "(", "$", "result", "->", "locale", ")", ";", "$", "result", "->", "locale", "=", "(", "isset", "(", "static", "::", "$", "LOCALES", "[", "$", "localeNameUpper", "]", ")", "?", "static", "::", "$", "LOCALES", "[", "$", "localeNameUpper", "]", ":", "$", "result", "->", "locale", ")", ";", "}", "}", "if", "(", "$", "result", "->", "encoding", "!==", "NULL", ")", "{", "$", "encodingOpposite", "=", "static", "::", "$", "encodings", "[", "$", "result", "->", "encoding", "]", ";", "if", "(", "$", "encodingOpposite", ")", "{", "$", "result", "->", "system", ".=", "'.'", ".", "$", "result", "->", "encoding", ";", "$", "result", "->", "encoding", "=", "$", "encodingOpposite", ";", "}", "else", "{", "$", "result", "->", "system", ".=", "'.'", ".", "$", "result", "->", "encoding", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Translate parsed system locale value into application locale value. Do not translate anything on non-windows plaforms, but translate windows system locale value language, terotiry and encoding combination into standard application values. @param \stdClass $parsedLocale @return \stdClass
[ "Translate", "parsed", "system", "locale", "value", "into", "application", "locale", "value", ".", "Do", "not", "translate", "anything", "on", "non", "-", "windows", "plaforms", "but", "translate", "windows", "system", "locale", "value", "language", "terotiry", "and", "encoding", "combination", "into", "standard", "application", "values", "." ]
bd34466dd9d524f3e3c7b5f34aa358b9e6f49fe9
https://github.com/mvccore/ext-tool-locale/blob/bd34466dd9d524f3e3c7b5f34aa358b9e6f49fe9/src/MvcCore/Ext/Tools/Locale.php#L1015-L1064
train
OpenConext/Stepup-u2f-bundle
src/Service/U2fService.php
U2fService.verifyAuthentication
public function verifyAuthentication(Registration $registration, SignRequest $request, SignResponse $response) { if (!$this->appId->equals(new AppId($request->appId))) { return AuthenticationVerificationResult::appIdMismatch(); } if ($response->errorCode > 0) { return AuthenticationVerificationResult::deviceReportedError($response->errorCode); } $yubicoRegistration = new YubicoRegistration(); $yubicoRegistration->keyHandle = $registration->keyHandle; $yubicoRegistration->publicKey = $registration->publicKey; $yubicoRegistration->counter = $registration->signCounter; $yubicoRequest = new YubicoSignRequest(); $yubicoRequest->version = $request->version; $yubicoRequest->challenge = $request->challenge; $yubicoRequest->appId = $request->appId; $yubicoRequest->keyHandle = $request->keyHandle; $yubicoResponse = new \stdClass; $yubicoResponse->keyHandle = $response->keyHandle; $yubicoResponse->signatureData = $response->signatureData; $yubicoResponse->clientData = $response->clientData; try { $yubicoRegistration = $this->u2fService->doAuthenticate( [$yubicoRequest], [$yubicoRegistration], $yubicoResponse ); } catch (Error $error) { switch ($error->getCode()) { case \u2flib_server\ERR_NO_MATCHING_REQUEST: return AuthenticationVerificationResult::requestResponseMismatch(); case \u2flib_server\ERR_NO_MATCHING_REGISTRATION: return AuthenticationVerificationResult::responseRegistrationMismatch(); case \u2flib_server\ERR_PUBKEY_DECODE: return AuthenticationVerificationResult::publicKeyDecodingFailed(); case \u2flib_server\ERR_AUTHENTICATION_FAILURE: return AuthenticationVerificationResult::responseWasNotSignedByDevice(); case \u2flib_server\ERR_COUNTER_TOO_LOW: return AuthenticationVerificationResult::signCounterTooLow(); default: throw new LogicException( sprintf( 'The Yubico U2F service threw an exception with error code %d that should not occur ("%s")', $error->getCode(), $error->getMessage() ), $error ); } } $registration = new Registration(); $registration->keyHandle = $yubicoRegistration->keyHandle; $registration->publicKey = $yubicoRegistration->publicKey; $registration->signCounter = $yubicoRegistration->counter; return AuthenticationVerificationResult::success($registration); }
php
public function verifyAuthentication(Registration $registration, SignRequest $request, SignResponse $response) { if (!$this->appId->equals(new AppId($request->appId))) { return AuthenticationVerificationResult::appIdMismatch(); } if ($response->errorCode > 0) { return AuthenticationVerificationResult::deviceReportedError($response->errorCode); } $yubicoRegistration = new YubicoRegistration(); $yubicoRegistration->keyHandle = $registration->keyHandle; $yubicoRegistration->publicKey = $registration->publicKey; $yubicoRegistration->counter = $registration->signCounter; $yubicoRequest = new YubicoSignRequest(); $yubicoRequest->version = $request->version; $yubicoRequest->challenge = $request->challenge; $yubicoRequest->appId = $request->appId; $yubicoRequest->keyHandle = $request->keyHandle; $yubicoResponse = new \stdClass; $yubicoResponse->keyHandle = $response->keyHandle; $yubicoResponse->signatureData = $response->signatureData; $yubicoResponse->clientData = $response->clientData; try { $yubicoRegistration = $this->u2fService->doAuthenticate( [$yubicoRequest], [$yubicoRegistration], $yubicoResponse ); } catch (Error $error) { switch ($error->getCode()) { case \u2flib_server\ERR_NO_MATCHING_REQUEST: return AuthenticationVerificationResult::requestResponseMismatch(); case \u2flib_server\ERR_NO_MATCHING_REGISTRATION: return AuthenticationVerificationResult::responseRegistrationMismatch(); case \u2flib_server\ERR_PUBKEY_DECODE: return AuthenticationVerificationResult::publicKeyDecodingFailed(); case \u2flib_server\ERR_AUTHENTICATION_FAILURE: return AuthenticationVerificationResult::responseWasNotSignedByDevice(); case \u2flib_server\ERR_COUNTER_TOO_LOW: return AuthenticationVerificationResult::signCounterTooLow(); default: throw new LogicException( sprintf( 'The Yubico U2F service threw an exception with error code %d that should not occur ("%s")', $error->getCode(), $error->getMessage() ), $error ); } } $registration = new Registration(); $registration->keyHandle = $yubicoRegistration->keyHandle; $registration->publicKey = $yubicoRegistration->publicKey; $registration->signCounter = $yubicoRegistration->counter; return AuthenticationVerificationResult::success($registration); }
[ "public", "function", "verifyAuthentication", "(", "Registration", "$", "registration", ",", "SignRequest", "$", "request", ",", "SignResponse", "$", "response", ")", "{", "if", "(", "!", "$", "this", "->", "appId", "->", "equals", "(", "new", "AppId", "(", "$", "request", "->", "appId", ")", ")", ")", "{", "return", "AuthenticationVerificationResult", "::", "appIdMismatch", "(", ")", ";", "}", "if", "(", "$", "response", "->", "errorCode", ">", "0", ")", "{", "return", "AuthenticationVerificationResult", "::", "deviceReportedError", "(", "$", "response", "->", "errorCode", ")", ";", "}", "$", "yubicoRegistration", "=", "new", "YubicoRegistration", "(", ")", ";", "$", "yubicoRegistration", "->", "keyHandle", "=", "$", "registration", "->", "keyHandle", ";", "$", "yubicoRegistration", "->", "publicKey", "=", "$", "registration", "->", "publicKey", ";", "$", "yubicoRegistration", "->", "counter", "=", "$", "registration", "->", "signCounter", ";", "$", "yubicoRequest", "=", "new", "YubicoSignRequest", "(", ")", ";", "$", "yubicoRequest", "->", "version", "=", "$", "request", "->", "version", ";", "$", "yubicoRequest", "->", "challenge", "=", "$", "request", "->", "challenge", ";", "$", "yubicoRequest", "->", "appId", "=", "$", "request", "->", "appId", ";", "$", "yubicoRequest", "->", "keyHandle", "=", "$", "request", "->", "keyHandle", ";", "$", "yubicoResponse", "=", "new", "\\", "stdClass", ";", "$", "yubicoResponse", "->", "keyHandle", "=", "$", "response", "->", "keyHandle", ";", "$", "yubicoResponse", "->", "signatureData", "=", "$", "response", "->", "signatureData", ";", "$", "yubicoResponse", "->", "clientData", "=", "$", "response", "->", "clientData", ";", "try", "{", "$", "yubicoRegistration", "=", "$", "this", "->", "u2fService", "->", "doAuthenticate", "(", "[", "$", "yubicoRequest", "]", ",", "[", "$", "yubicoRegistration", "]", ",", "$", "yubicoResponse", ")", ";", "}", "catch", "(", "Error", "$", "error", ")", "{", "switch", "(", "$", "error", "->", "getCode", "(", ")", ")", "{", "case", "\\", "u2flib_server", "\\", "ERR_NO_MATCHING_REQUEST", ":", "return", "AuthenticationVerificationResult", "::", "requestResponseMismatch", "(", ")", ";", "case", "\\", "u2flib_server", "\\", "ERR_NO_MATCHING_REGISTRATION", ":", "return", "AuthenticationVerificationResult", "::", "responseRegistrationMismatch", "(", ")", ";", "case", "\\", "u2flib_server", "\\", "ERR_PUBKEY_DECODE", ":", "return", "AuthenticationVerificationResult", "::", "publicKeyDecodingFailed", "(", ")", ";", "case", "\\", "u2flib_server", "\\", "ERR_AUTHENTICATION_FAILURE", ":", "return", "AuthenticationVerificationResult", "::", "responseWasNotSignedByDevice", "(", ")", ";", "case", "\\", "u2flib_server", "\\", "ERR_COUNTER_TOO_LOW", ":", "return", "AuthenticationVerificationResult", "::", "signCounterTooLow", "(", ")", ";", "default", ":", "throw", "new", "LogicException", "(", "sprintf", "(", "'The Yubico U2F service threw an exception with error code %d that should not occur (\"%s\")'", ",", "$", "error", "->", "getCode", "(", ")", ",", "$", "error", "->", "getMessage", "(", ")", ")", ",", "$", "error", ")", ";", "}", "}", "$", "registration", "=", "new", "Registration", "(", ")", ";", "$", "registration", "->", "keyHandle", "=", "$", "yubicoRegistration", "->", "keyHandle", ";", "$", "registration", "->", "publicKey", "=", "$", "yubicoRegistration", "->", "publicKey", ";", "$", "registration", "->", "signCounter", "=", "$", "yubicoRegistration", "->", "counter", ";", "return", "AuthenticationVerificationResult", "::", "success", "(", "$", "registration", ")", ";", "}" ]
Request signing of a sign request. Does not support U2F's sign counter system. @param Registration $registration The registration that is to be signed. @param SignRequest $request The sign request that you requested earlier and was used to query the U2F device. @param SignResponse $response The response that the U2F device gave in response to the sign request. @return AuthenticationVerificationResult
[ "Request", "signing", "of", "a", "sign", "request", ".", "Does", "not", "support", "U2F", "s", "sign", "counter", "system", "." ]
992f91db04afaad98f0d10645d81f4e3ea6742d0
https://github.com/OpenConext/Stepup-u2f-bundle/blob/992f91db04afaad98f0d10645d81f4e3ea6742d0/src/Service/U2fService.php#L160-L222
train
ZhukV/AppleModel
src/Apple/Model/AbstractModel.php
AbstractModel.serialize
public function serialize() { $data = array(); foreach (get_object_vars($this) as $propertyName => $propertyValue) { $data[$propertyName] = $propertyValue; } return serialize($data); }
php
public function serialize() { $data = array(); foreach (get_object_vars($this) as $propertyName => $propertyValue) { $data[$propertyName] = $propertyValue; } return serialize($data); }
[ "public", "function", "serialize", "(", ")", "{", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "get_object_vars", "(", "$", "this", ")", "as", "$", "propertyName", "=>", "$", "propertyValue", ")", "{", "$", "data", "[", "$", "propertyName", "]", "=", "$", "propertyValue", ";", "}", "return", "serialize", "(", "$", "data", ")", ";", "}" ]
Implements of \Serializable
[ "Implements", "of", "\\", "Serializable" ]
3ab06d560b7c442b8ebafdd95d1d2523b40ef903
https://github.com/ZhukV/AppleModel/blob/3ab06d560b7c442b8ebafdd95d1d2523b40ef903/src/Apple/Model/AbstractModel.php#L46-L55
train
ZhukV/AppleModel
src/Apple/Model/AbstractModel.php
AbstractModel.unserialize
public function unserialize($str) { $data = @unserialize($str); if ($data === false) { throw new \RuntimeException(sprintf('Can\'t unserialize model data: %s', $str)); } if (!is_array($data)) { throw new \RuntimeException(sprintf('Unserialized data must be array, "%s" given.', gettype($data))); } foreach ($data as $propertyName => $propertyValue) { if (!property_exists($this, $propertyName)) { throw new \LogicException(sprintf('Undefined property "%s" in model "%s". Allowed properies: "%s".', $propertyName, get_class($this), implode('", "', array_keys(get_object_vars($this))))); } $this->{$propertyName} = $propertyValue; } }
php
public function unserialize($str) { $data = @unserialize($str); if ($data === false) { throw new \RuntimeException(sprintf('Can\'t unserialize model data: %s', $str)); } if (!is_array($data)) { throw new \RuntimeException(sprintf('Unserialized data must be array, "%s" given.', gettype($data))); } foreach ($data as $propertyName => $propertyValue) { if (!property_exists($this, $propertyName)) { throw new \LogicException(sprintf('Undefined property "%s" in model "%s". Allowed properies: "%s".', $propertyName, get_class($this), implode('", "', array_keys(get_object_vars($this))))); } $this->{$propertyName} = $propertyValue; } }
[ "public", "function", "unserialize", "(", "$", "str", ")", "{", "$", "data", "=", "@", "unserialize", "(", "$", "str", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Can\\'t unserialize model data: %s'", ",", "$", "str", ")", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Unserialized data must be array, \"%s\" given.'", ",", "gettype", "(", "$", "data", ")", ")", ")", ";", "}", "foreach", "(", "$", "data", "as", "$", "propertyName", "=>", "$", "propertyValue", ")", "{", "if", "(", "!", "property_exists", "(", "$", "this", ",", "$", "propertyName", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'Undefined property \"%s\" in model \"%s\". Allowed properies: \"%s\".'", ",", "$", "propertyName", ",", "get_class", "(", "$", "this", ")", ",", "implode", "(", "'\", \"'", ",", "array_keys", "(", "get_object_vars", "(", "$", "this", ")", ")", ")", ")", ")", ";", "}", "$", "this", "->", "{", "$", "propertyName", "}", "=", "$", "propertyValue", ";", "}", "}" ]
Implements if \Serializable
[ "Implements", "if", "\\", "Serializable" ]
3ab06d560b7c442b8ebafdd95d1d2523b40ef903
https://github.com/ZhukV/AppleModel/blob/3ab06d560b7c442b8ebafdd95d1d2523b40ef903/src/Apple/Model/AbstractModel.php#L60-L79
train
Hnto/nuki
src/Handlers/Provider/Params.php
Params.get
public function get($key = false, $default = false) { if ($key === false) { return $this->params; } if (!$this->has($key) && $default === false) { return new Param($key, null); } if (!$this->has($key) && $default !== false) { return new Param($key, $default); } return new Param($key, $this->params[$key]); }
php
public function get($key = false, $default = false) { if ($key === false) { return $this->params; } if (!$this->has($key) && $default === false) { return new Param($key, null); } if (!$this->has($key) && $default !== false) { return new Param($key, $default); } return new Param($key, $this->params[$key]); }
[ "public", "function", "get", "(", "$", "key", "=", "false", ",", "$", "default", "=", "false", ")", "{", "if", "(", "$", "key", "===", "false", ")", "{", "return", "$", "this", "->", "params", ";", "}", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", "&&", "$", "default", "===", "false", ")", "{", "return", "new", "Param", "(", "$", "key", ",", "null", ")", ";", "}", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", "&&", "$", "default", "!==", "false", ")", "{", "return", "new", "Param", "(", "$", "key", ",", "$", "default", ")", ";", "}", "return", "new", "Param", "(", "$", "key", ",", "$", "this", "->", "params", "[", "$", "key", "]", ")", ";", "}" ]
Get param value by key or false for all params Optional set default if not found @param bool $key @param bool $default @return Param|array
[ "Get", "param", "value", "by", "key", "or", "false", "for", "all", "params", "Optional", "set", "default", "if", "not", "found" ]
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Provider/Params.php#L52-L66
train
Dhii/iterator-abstract
src/KeyAwareIterableTrait.php
KeyAwareIterableTrait._getCurrentIterableKey
protected function _getCurrentIterableKey(&$iterable) { $current = $this->_getCurrentIterableValue($iterable); return ($current instanceof KeyAwareInterface) ? $current->getKey() : key($iterable); }
php
protected function _getCurrentIterableKey(&$iterable) { $current = $this->_getCurrentIterableValue($iterable); return ($current instanceof KeyAwareInterface) ? $current->getKey() : key($iterable); }
[ "protected", "function", "_getCurrentIterableKey", "(", "&", "$", "iterable", ")", "{", "$", "current", "=", "$", "this", "->", "_getCurrentIterableValue", "(", "$", "iterable", ")", ";", "return", "(", "$", "current", "instanceof", "KeyAwareInterface", ")", "?", "$", "current", "->", "getKey", "(", ")", ":", "key", "(", "$", "iterable", ")", ";", "}" ]
Retrieves the key for the current element of an iterable. @since [*next-version*] @param array|Traversable $iterable The iterable. @return string|int|null The current key.
[ "Retrieves", "the", "key", "for", "the", "current", "element", "of", "an", "iterable", "." ]
576484183865575ffc2a0d586132741329626fb8
https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/KeyAwareIterableTrait.php#L24-L31
train
ARCANESOFT/Auth
src/Providers/ViewComposerServiceProvider.php
ViewComposerServiceProvider.registerOtherComposers
private function registerOtherComposers() { $this->composer( 'auth::admin.roles._partials.permissions-checkbox', 'Arcanesoft\Auth\ViewComposers\PermissionsComposer@composeRolePermissions' ); $this->composer( 'auth::admin.users.index', 'Arcanesoft\Auth\ViewComposers\RolesComposer@composeFilters' ); $this->composer( ViewComposers\PermissionGroupsFilterComposer::VIEW, ViewComposers\PermissionGroupsFilterComposer::class ); }
php
private function registerOtherComposers() { $this->composer( 'auth::admin.roles._partials.permissions-checkbox', 'Arcanesoft\Auth\ViewComposers\PermissionsComposer@composeRolePermissions' ); $this->composer( 'auth::admin.users.index', 'Arcanesoft\Auth\ViewComposers\RolesComposer@composeFilters' ); $this->composer( ViewComposers\PermissionGroupsFilterComposer::VIEW, ViewComposers\PermissionGroupsFilterComposer::class ); }
[ "private", "function", "registerOtherComposers", "(", ")", "{", "$", "this", "->", "composer", "(", "'auth::admin.roles._partials.permissions-checkbox'", ",", "'Arcanesoft\\Auth\\ViewComposers\\PermissionsComposer@composeRolePermissions'", ")", ";", "$", "this", "->", "composer", "(", "'auth::admin.users.index'", ",", "'Arcanesoft\\Auth\\ViewComposers\\RolesComposer@composeFilters'", ")", ";", "$", "this", "->", "composer", "(", "ViewComposers", "\\", "PermissionGroupsFilterComposer", "::", "VIEW", ",", "ViewComposers", "\\", "PermissionGroupsFilterComposer", "::", "class", ")", ";", "}" ]
Register other view composers.
[ "Register", "other", "view", "composers", "." ]
b33ca82597a76b1e395071f71ae3e51f1ec67e62
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Providers/ViewComposerServiceProvider.php#L54-L70
train
vpg/titon.utility
src/Titon/Utility/Validator.php
Validator.addField
public function addField($field, $title, array $rules = array()) { $this->_fields[$field] = $title; /** * 0 => rule * rule => [opt, ...] */ if ($rules) { foreach ($rules as $rule => $options) { if (is_numeric($rule)) { $rule = $options; $options = array(); } $this->addRule($field, $rule, null, $options); } } return $this; }
php
public function addField($field, $title, array $rules = array()) { $this->_fields[$field] = $title; /** * 0 => rule * rule => [opt, ...] */ if ($rules) { foreach ($rules as $rule => $options) { if (is_numeric($rule)) { $rule = $options; $options = array(); } $this->addRule($field, $rule, null, $options); } } return $this; }
[ "public", "function", "addField", "(", "$", "field", ",", "$", "title", ",", "array", "$", "rules", "=", "array", "(", ")", ")", "{", "$", "this", "->", "_fields", "[", "$", "field", "]", "=", "$", "title", ";", "/**\n * 0 => rule\n * rule => [opt, ...]\n */", "if", "(", "$", "rules", ")", "{", "foreach", "(", "$", "rules", "as", "$", "rule", "=>", "$", "options", ")", "{", "if", "(", "is_numeric", "(", "$", "rule", ")", ")", "{", "$", "rule", "=", "$", "options", ";", "$", "options", "=", "array", "(", ")", ";", "}", "$", "this", "->", "addRule", "(", "$", "field", ",", "$", "rule", ",", "null", ",", "$", "options", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add a field to be used in validation. Can optionally apply an array of validation rules. @param string $field @param string $title @param array $rules @return $this
[ "Add", "a", "field", "to", "be", "used", "in", "validation", ".", "Can", "optionally", "apply", "an", "array", "of", "validation", "rules", "." ]
8a77eb9e7b8baacf41cc25487289779d8319cd3a
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validator.php#L85-L104
train
vpg/titon.utility
src/Titon/Utility/Validator.php
Validator.addRule
public function addRule($field, $rule, $message, $options = array()) { if (empty($this->_fields[$field])) { throw new InvalidArgumentException(sprintf('Field %s does not exist', $field)); } if (isset($this->_messages[$rule])) { $message = $message ?: $this->_messages[$rule]; } else { $this->_messages[$rule] = $message; } $this->_rules[$field][$rule] = array( 'message' => $message, 'options' => (array) $options ); return $this; }
php
public function addRule($field, $rule, $message, $options = array()) { if (empty($this->_fields[$field])) { throw new InvalidArgumentException(sprintf('Field %s does not exist', $field)); } if (isset($this->_messages[$rule])) { $message = $message ?: $this->_messages[$rule]; } else { $this->_messages[$rule] = $message; } $this->_rules[$field][$rule] = array( 'message' => $message, 'options' => (array) $options ); return $this; }
[ "public", "function", "addRule", "(", "$", "field", ",", "$", "rule", ",", "$", "message", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_fields", "[", "$", "field", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Field %s does not exist'", ",", "$", "field", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_messages", "[", "$", "rule", "]", ")", ")", "{", "$", "message", "=", "$", "message", "?", ":", "$", "this", "->", "_messages", "[", "$", "rule", "]", ";", "}", "else", "{", "$", "this", "->", "_messages", "[", "$", "rule", "]", "=", "$", "message", ";", "}", "$", "this", "->", "_rules", "[", "$", "field", "]", "[", "$", "rule", "]", "=", "array", "(", "'message'", "=>", "$", "message", ",", "'options'", "=>", "(", "array", ")", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Add a validation rule to a field. Can supply an optional error message and options. @param string $field @param string $rule @param string $message @param array $options @return $this @throws \Titon\Utility\Exception\InvalidArgumentException
[ "Add", "a", "validation", "rule", "to", "a", "field", ".", "Can", "supply", "an", "optional", "error", "message", "and", "options", "." ]
8a77eb9e7b8baacf41cc25487289779d8319cd3a
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validator.php#L128-L145
train
vpg/titon.utility
src/Titon/Utility/Validator.php
Validator.validate
public function validate() { if (!$this->_data) { return false; } $fields = $this->getFields(); $messages = $this->getMessages(); foreach ($this->_data as $field => $value) { if (empty($this->_rules[$field])) { continue; } foreach ($this->_rules[$field] as $rule => $params) { $options = $params['options']; $arguments = $options; array_unshift($arguments, $value); // Use G11n if it is available if (class_exists('Titon\G11n\Utility\Validate')) { $class = 'Titon\G11n\Utility\Validate'; } else { $class = 'Titon\Utility\Validate'; } if (!call_user_func(array($class, 'hasMethod'), $rule)) { throw new InvalidValidationRuleException(sprintf('Validation rule %s does not exist', $rule)); } // Prepare messages $message = $params['message']; if (!$message && isset($messages[$rule])) { $message = $messages[$rule]; } if ($message) { $message = String::insert($message, array_map(function($value) { return is_array($value) ? implode(', ', $value) : $value; }, $options + array( 'field' => $field, 'title' => $fields[$field] ))); } else { throw new InvalidValidationRuleException(sprintf('Error message for rule %s does not exist', $rule)); } if (!call_user_func_array(array($class, $rule), $arguments)) { $this->addError($field, $message); break; } } } return empty($this->_errors); }
php
public function validate() { if (!$this->_data) { return false; } $fields = $this->getFields(); $messages = $this->getMessages(); foreach ($this->_data as $field => $value) { if (empty($this->_rules[$field])) { continue; } foreach ($this->_rules[$field] as $rule => $params) { $options = $params['options']; $arguments = $options; array_unshift($arguments, $value); // Use G11n if it is available if (class_exists('Titon\G11n\Utility\Validate')) { $class = 'Titon\G11n\Utility\Validate'; } else { $class = 'Titon\Utility\Validate'; } if (!call_user_func(array($class, 'hasMethod'), $rule)) { throw new InvalidValidationRuleException(sprintf('Validation rule %s does not exist', $rule)); } // Prepare messages $message = $params['message']; if (!$message && isset($messages[$rule])) { $message = $messages[$rule]; } if ($message) { $message = String::insert($message, array_map(function($value) { return is_array($value) ? implode(', ', $value) : $value; }, $options + array( 'field' => $field, 'title' => $fields[$field] ))); } else { throw new InvalidValidationRuleException(sprintf('Error message for rule %s does not exist', $rule)); } if (!call_user_func_array(array($class, $rule), $arguments)) { $this->addError($field, $message); break; } } } return empty($this->_errors); }
[ "public", "function", "validate", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_data", ")", "{", "return", "false", ";", "}", "$", "fields", "=", "$", "this", "->", "getFields", "(", ")", ";", "$", "messages", "=", "$", "this", "->", "getMessages", "(", ")", ";", "foreach", "(", "$", "this", "->", "_data", "as", "$", "field", "=>", "$", "value", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_rules", "[", "$", "field", "]", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "this", "->", "_rules", "[", "$", "field", "]", "as", "$", "rule", "=>", "$", "params", ")", "{", "$", "options", "=", "$", "params", "[", "'options'", "]", ";", "$", "arguments", "=", "$", "options", ";", "array_unshift", "(", "$", "arguments", ",", "$", "value", ")", ";", "// Use G11n if it is available", "if", "(", "class_exists", "(", "'Titon\\G11n\\Utility\\Validate'", ")", ")", "{", "$", "class", "=", "'Titon\\G11n\\Utility\\Validate'", ";", "}", "else", "{", "$", "class", "=", "'Titon\\Utility\\Validate'", ";", "}", "if", "(", "!", "call_user_func", "(", "array", "(", "$", "class", ",", "'hasMethod'", ")", ",", "$", "rule", ")", ")", "{", "throw", "new", "InvalidValidationRuleException", "(", "sprintf", "(", "'Validation rule %s does not exist'", ",", "$", "rule", ")", ")", ";", "}", "// Prepare messages", "$", "message", "=", "$", "params", "[", "'message'", "]", ";", "if", "(", "!", "$", "message", "&&", "isset", "(", "$", "messages", "[", "$", "rule", "]", ")", ")", "{", "$", "message", "=", "$", "messages", "[", "$", "rule", "]", ";", "}", "if", "(", "$", "message", ")", "{", "$", "message", "=", "String", "::", "insert", "(", "$", "message", ",", "array_map", "(", "function", "(", "$", "value", ")", "{", "return", "is_array", "(", "$", "value", ")", "?", "implode", "(", "', '", ",", "$", "value", ")", ":", "$", "value", ";", "}", ",", "$", "options", "+", "array", "(", "'field'", "=>", "$", "field", ",", "'title'", "=>", "$", "fields", "[", "$", "field", "]", ")", ")", ")", ";", "}", "else", "{", "throw", "new", "InvalidValidationRuleException", "(", "sprintf", "(", "'Error message for rule %s does not exist'", ",", "$", "rule", ")", ")", ";", "}", "if", "(", "!", "call_user_func_array", "(", "array", "(", "$", "class", ",", "$", "rule", ")", ",", "$", "arguments", ")", ")", "{", "$", "this", "->", "addError", "(", "$", "field", ",", "$", "message", ")", ";", "break", ";", "}", "}", "}", "return", "empty", "(", "$", "this", "->", "_errors", ")", ";", "}" ]
Validate the data against the rules schema. Return true if all fields passed validation. @return bool @throws \Titon\Utility\Exception\InvalidValidationRuleException
[ "Validate", "the", "data", "against", "the", "rules", "schema", ".", "Return", "true", "if", "all", "fields", "passed", "validation", "." ]
8a77eb9e7b8baacf41cc25487289779d8319cd3a
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validator.php#L222-L277
train
vpg/titon.utility
src/Titon/Utility/Validator.php
Validator.makeFromShorthand
public static function makeFromShorthand(array $data = array(), array $fields = array()) { /** @type \Titon\Utility\Validator $obj */ $obj = new static($data); foreach ($fields as $field => $data) { $title = $field; // Convert to array if (is_string($data)) { $data = array('rules' => $data); } else if (!is_array($data)) { continue; } else if (Hash::isNumeric(array_keys($data))) { $data = array('rules' => $data); } // Prepare for parsing if (isset($data['title'])) { $title = $data['title']; } if (is_string($data['rules'])) { $data['rules'] = explode('|', $data['rules']); } $obj->addField($field, $title); foreach ($data['rules'] as $ruleOpts) { $shorthand = self::splitShorthand($ruleOpts); $obj->addRule($field, $shorthand['rule'], $shorthand['message'], $shorthand['options']); } } return $obj; }
php
public static function makeFromShorthand(array $data = array(), array $fields = array()) { /** @type \Titon\Utility\Validator $obj */ $obj = new static($data); foreach ($fields as $field => $data) { $title = $field; // Convert to array if (is_string($data)) { $data = array('rules' => $data); } else if (!is_array($data)) { continue; } else if (Hash::isNumeric(array_keys($data))) { $data = array('rules' => $data); } // Prepare for parsing if (isset($data['title'])) { $title = $data['title']; } if (is_string($data['rules'])) { $data['rules'] = explode('|', $data['rules']); } $obj->addField($field, $title); foreach ($data['rules'] as $ruleOpts) { $shorthand = self::splitShorthand($ruleOpts); $obj->addRule($field, $shorthand['rule'], $shorthand['message'], $shorthand['options']); } } return $obj; }
[ "public", "static", "function", "makeFromShorthand", "(", "array", "$", "data", "=", "array", "(", ")", ",", "array", "$", "fields", "=", "array", "(", ")", ")", "{", "/** @type \\Titon\\Utility\\Validator $obj */", "$", "obj", "=", "new", "static", "(", "$", "data", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", "=>", "$", "data", ")", "{", "$", "title", "=", "$", "field", ";", "// Convert to array", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "$", "data", "=", "array", "(", "'rules'", "=>", "$", "data", ")", ";", "}", "else", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "continue", ";", "}", "else", "if", "(", "Hash", "::", "isNumeric", "(", "array_keys", "(", "$", "data", ")", ")", ")", "{", "$", "data", "=", "array", "(", "'rules'", "=>", "$", "data", ")", ";", "}", "// Prepare for parsing", "if", "(", "isset", "(", "$", "data", "[", "'title'", "]", ")", ")", "{", "$", "title", "=", "$", "data", "[", "'title'", "]", ";", "}", "if", "(", "is_string", "(", "$", "data", "[", "'rules'", "]", ")", ")", "{", "$", "data", "[", "'rules'", "]", "=", "explode", "(", "'|'", ",", "$", "data", "[", "'rules'", "]", ")", ";", "}", "$", "obj", "->", "addField", "(", "$", "field", ",", "$", "title", ")", ";", "foreach", "(", "$", "data", "[", "'rules'", "]", "as", "$", "ruleOpts", ")", "{", "$", "shorthand", "=", "self", "::", "splitShorthand", "(", "$", "ruleOpts", ")", ";", "$", "obj", "->", "addRule", "(", "$", "field", ",", "$", "shorthand", "[", "'rule'", "]", ",", "$", "shorthand", "[", "'message'", "]", ",", "$", "shorthand", "[", "'options'", "]", ")", ";", "}", "}", "return", "$", "obj", ";", "}" ]
Create a validator instance from a set of shorthand or expanded rule sets. @param array $data @param array $fields @return $this
[ "Create", "a", "validator", "instance", "from", "a", "set", "of", "shorthand", "or", "expanded", "rule", "sets", "." ]
8a77eb9e7b8baacf41cc25487289779d8319cd3a
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validator.php#L286-L323
train
vpg/titon.utility
src/Titon/Utility/Validator.php
Validator.splitShorthand
public static function splitShorthand($shorthand) { $rule = null; $message = ''; $opts = array(); // rule:o1,o2,o3 // rule:o1,o2:The message here! if (strpos($shorthand, ':') !== false) { $parts = explode(':', $shorthand, 3); $rule = $parts[0]; if (!empty($parts[1])) { $opts = $parts[1]; if (strpos($opts, ',') !== false) { $opts = explode(',', $opts); } else { $opts = array($opts); } } if (!empty($parts[2])) { $message = $parts[2]; } // rule } else { $rule = $shorthand; } return array( 'rule' => $rule, 'message' => $message, 'options' => $opts ); }
php
public static function splitShorthand($shorthand) { $rule = null; $message = ''; $opts = array(); // rule:o1,o2,o3 // rule:o1,o2:The message here! if (strpos($shorthand, ':') !== false) { $parts = explode(':', $shorthand, 3); $rule = $parts[0]; if (!empty($parts[1])) { $opts = $parts[1]; if (strpos($opts, ',') !== false) { $opts = explode(',', $opts); } else { $opts = array($opts); } } if (!empty($parts[2])) { $message = $parts[2]; } // rule } else { $rule = $shorthand; } return array( 'rule' => $rule, 'message' => $message, 'options' => $opts ); }
[ "public", "static", "function", "splitShorthand", "(", "$", "shorthand", ")", "{", "$", "rule", "=", "null", ";", "$", "message", "=", "''", ";", "$", "opts", "=", "array", "(", ")", ";", "// rule:o1,o2,o3", "// rule:o1,o2:The message here!", "if", "(", "strpos", "(", "$", "shorthand", ",", "':'", ")", "!==", "false", ")", "{", "$", "parts", "=", "explode", "(", "':'", ",", "$", "shorthand", ",", "3", ")", ";", "$", "rule", "=", "$", "parts", "[", "0", "]", ";", "if", "(", "!", "empty", "(", "$", "parts", "[", "1", "]", ")", ")", "{", "$", "opts", "=", "$", "parts", "[", "1", "]", ";", "if", "(", "strpos", "(", "$", "opts", ",", "','", ")", "!==", "false", ")", "{", "$", "opts", "=", "explode", "(", "','", ",", "$", "opts", ")", ";", "}", "else", "{", "$", "opts", "=", "array", "(", "$", "opts", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "parts", "[", "2", "]", ")", ")", "{", "$", "message", "=", "$", "parts", "[", "2", "]", ";", "}", "// rule", "}", "else", "{", "$", "rule", "=", "$", "shorthand", ";", "}", "return", "array", "(", "'rule'", "=>", "$", "rule", ",", "'message'", "=>", "$", "message", ",", "'options'", "=>", "$", "opts", ")", ";", "}" ]
Split a shorthand rule into multiple parts. @param string $shorthand @return array
[ "Split", "a", "shorthand", "rule", "into", "multiple", "parts", "." ]
8a77eb9e7b8baacf41cc25487289779d8319cd3a
https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Validator.php#L331-L366
train
OpenConext/Stepup-bundle
src/Http/CookieHelper.php
CookieHelper.write
public function write(Response $response, $value) { $cookie = $this->createCookieWithValue($value); $response->headers->setCookie($cookie); return $cookie; }
php
public function write(Response $response, $value) { $cookie = $this->createCookieWithValue($value); $response->headers->setCookie($cookie); return $cookie; }
[ "public", "function", "write", "(", "Response", "$", "response", ",", "$", "value", ")", "{", "$", "cookie", "=", "$", "this", "->", "createCookieWithValue", "(", "$", "value", ")", ";", "$", "response", "->", "headers", "->", "setCookie", "(", "$", "cookie", ")", ";", "return", "$", "cookie", ";", "}" ]
Write a new value for the current cookie to a given Response. @param string $value @return Cookie
[ "Write", "a", "new", "value", "for", "the", "current", "cookie", "to", "a", "given", "Response", "." ]
94178ddb421889df9e068109293a8da880793ed2
https://github.com/OpenConext/Stepup-bundle/blob/94178ddb421889df9e068109293a8da880793ed2/src/Http/CookieHelper.php#L46-L51
train
OpenConext/Stepup-bundle
src/Http/CookieHelper.php
CookieHelper.read
public function read(Request $request) { if (!$request->cookies->has($this->cookieSettings->getName())) { return null; } return $this->createCookieWithValue( $request->cookies->get($this->cookieSettings->getName()) ); }
php
public function read(Request $request) { if (!$request->cookies->has($this->cookieSettings->getName())) { return null; } return $this->createCookieWithValue( $request->cookies->get($this->cookieSettings->getName()) ); }
[ "public", "function", "read", "(", "Request", "$", "request", ")", "{", "if", "(", "!", "$", "request", "->", "cookies", "->", "has", "(", "$", "this", "->", "cookieSettings", "->", "getName", "(", ")", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "createCookieWithValue", "(", "$", "request", "->", "cookies", "->", "get", "(", "$", "this", "->", "cookieSettings", "->", "getName", "(", ")", ")", ")", ";", "}" ]
Retrieve the current cookie from the Request if it exists. Note that we only read the value, we ignore the other settings. @param Request $request @return null|Cookie
[ "Retrieve", "the", "current", "cookie", "from", "the", "Request", "if", "it", "exists", "." ]
94178ddb421889df9e068109293a8da880793ed2
https://github.com/OpenConext/Stepup-bundle/blob/94178ddb421889df9e068109293a8da880793ed2/src/Http/CookieHelper.php#L61-L70
train
phpffcms/ffcms-core
src/Network/Response.php
Response.redirect
public function redirect($to, $full = false) { $to = trim($to, '/'); if (!$full && !Str::startsWith(App::$Alias->baseUrl, $to)) { $to = App::$Alias->baseUrl . '/' . $to; } $redirect = new FoundationRedirect($to); $redirect->send(); exit('Redirecting to ' . $to . ' ...'); }
php
public function redirect($to, $full = false) { $to = trim($to, '/'); if (!$full && !Str::startsWith(App::$Alias->baseUrl, $to)) { $to = App::$Alias->baseUrl . '/' . $to; } $redirect = new FoundationRedirect($to); $redirect->send(); exit('Redirecting to ' . $to . ' ...'); }
[ "public", "function", "redirect", "(", "$", "to", ",", "$", "full", "=", "false", ")", "{", "$", "to", "=", "trim", "(", "$", "to", ",", "'/'", ")", ";", "if", "(", "!", "$", "full", "&&", "!", "Str", "::", "startsWith", "(", "App", "::", "$", "Alias", "->", "baseUrl", ",", "$", "to", ")", ")", "{", "$", "to", "=", "App", "::", "$", "Alias", "->", "baseUrl", ".", "'/'", ".", "$", "to", ";", "}", "$", "redirect", "=", "new", "FoundationRedirect", "(", "$", "to", ")", ";", "$", "redirect", "->", "send", "(", ")", ";", "exit", "(", "'Redirecting to '", ".", "$", "to", ".", "' ...'", ")", ";", "}" ]
Fast redirect in web environment @param string $to @param bool $full
[ "Fast", "redirect", "in", "web", "environment" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Network/Response.php#L21-L30
train
zapheus/zapheus
src/Routing/Router.php
Router.connect
public function connect($uri, $handler, $middlewares = array()) { return $this->add($this->route('CONNECT', $uri, $handler, $middlewares)); }
php
public function connect($uri, $handler, $middlewares = array()) { return $this->add($this->route('CONNECT', $uri, $handler, $middlewares)); }
[ "public", "function", "connect", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'CONNECT'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in CONNECT HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "CONNECT", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L54-L57
train
zapheus/zapheus
src/Routing/Router.php
Router.delete
public function delete($uri, $handler, $middlewares = array()) { return $this->add($this->route('DELETE', $uri, $handler, $middlewares)); }
php
public function delete($uri, $handler, $middlewares = array()) { return $this->add($this->route('DELETE', $uri, $handler, $middlewares)); }
[ "public", "function", "delete", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'DELETE'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in DELETE HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "DELETE", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L67-L70
train
zapheus/zapheus
src/Routing/Router.php
Router.get
public function get($uri, $handler, $middlewares = array()) { return $this->add($this->route('GET', $uri, $handler, $middlewares)); }
php
public function get($uri, $handler, $middlewares = array()) { return $this->add($this->route('GET', $uri, $handler, $middlewares)); }
[ "public", "function", "get", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'GET'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in GET HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "GET", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L80-L83
train
zapheus/zapheus
src/Routing/Router.php
Router.head
public function head($uri, $handler, $middlewares = array()) { return $this->add($this->route('HEAD', $uri, $handler, $middlewares)); }
php
public function head($uri, $handler, $middlewares = array()) { return $this->add($this->route('HEAD', $uri, $handler, $middlewares)); }
[ "public", "function", "head", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'HEAD'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in HEAD HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "HEAD", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L104-L107
train
zapheus/zapheus
src/Routing/Router.php
Router.options
public function options($uri, $handler, $middlewares = array()) { return $this->add($this->route('OPTIONS', $uri, $handler, $middlewares)); }
php
public function options($uri, $handler, $middlewares = array()) { return $this->add($this->route('OPTIONS', $uri, $handler, $middlewares)); }
[ "public", "function", "options", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'OPTIONS'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in OPTIONS HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "OPTIONS", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L117-L120
train
zapheus/zapheus
src/Routing/Router.php
Router.patch
public function patch($uri, $handler, $middlewares = array()) { return $this->add($this->route('PATCH', $uri, $handler, $middlewares)); }
php
public function patch($uri, $handler, $middlewares = array()) { return $this->add($this->route('PATCH', $uri, $handler, $middlewares)); }
[ "public", "function", "patch", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'PATCH'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in PATCH HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "PATCH", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L130-L133
train
zapheus/zapheus
src/Routing/Router.php
Router.post
public function post($uri, $handler, $middlewares = array()) { return $this->add($this->route('POST', $uri, $handler, $middlewares)); }
php
public function post($uri, $handler, $middlewares = array()) { return $this->add($this->route('POST', $uri, $handler, $middlewares)); }
[ "public", "function", "post", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'POST'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in POST HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "POST", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L143-L146
train
zapheus/zapheus
src/Routing/Router.php
Router.purge
public function purge($uri, $handler, $middlewares = array()) { return $this->add($this->route('PURGE', $uri, $handler, $middlewares)); }
php
public function purge($uri, $handler, $middlewares = array()) { return $this->add($this->route('PURGE', $uri, $handler, $middlewares)); }
[ "public", "function", "purge", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'PURGE'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in PURGE HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "PURGE", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L156-L159
train
zapheus/zapheus
src/Routing/Router.php
Router.put
public function put($uri, $handler, $middlewares = array()) { return $this->add($this->route('PUT', $uri, $handler, $middlewares)); }
php
public function put($uri, $handler, $middlewares = array()) { return $this->add($this->route('PUT', $uri, $handler, $middlewares)); }
[ "public", "function", "put", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'PUT'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in PUT HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "PUT", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L169-L172
train
zapheus/zapheus
src/Routing/Router.php
Router.trace
public function trace($uri, $handler, $middlewares = array()) { return $this->add($this->route('TRACE', $uri, $handler, $middlewares)); }
php
public function trace($uri, $handler, $middlewares = array()) { return $this->add($this->route('TRACE', $uri, $handler, $middlewares)); }
[ "public", "function", "trace", "(", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "add", "(", "$", "this", "->", "route", "(", "'TRACE'", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ")", ";", "}" ]
Adds a new route instance in TRACE HTTP method. @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return self
[ "Adds", "a", "new", "route", "instance", "in", "TRACE", "HTTP", "method", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L192-L195
train
zapheus/zapheus
src/Routing/Router.php
Router.route
protected function route($method, $uri, $handler, $middlewares) { if (is_string($handler) === true) { $namespace = $this->namespace; $namespace !== '' && $namespace .= '\\'; $handler = $namespace . $handler; } return new Route($method, $uri, $handler, $middlewares); }
php
protected function route($method, $uri, $handler, $middlewares) { if (is_string($handler) === true) { $namespace = $this->namespace; $namespace !== '' && $namespace .= '\\'; $handler = $namespace . $handler; } return new Route($method, $uri, $handler, $middlewares); }
[ "protected", "function", "route", "(", "$", "method", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", "{", "if", "(", "is_string", "(", "$", "handler", ")", "===", "true", ")", "{", "$", "namespace", "=", "$", "this", "->", "namespace", ";", "$", "namespace", "!==", "''", "&&", "$", "namespace", ".=", "'\\\\'", ";", "$", "handler", "=", "$", "namespace", ".", "$", "handler", ";", "}", "return", "new", "Route", "(", "$", "method", ",", "$", "uri", ",", "$", "handler", ",", "$", "middlewares", ")", ";", "}" ]
Prepares a new route instance. @param string $method @param string $uri @param callable|string $handler @param array|callable|string $middlewares @return \Zapheus\Routing\Route
[ "Prepares", "a", "new", "route", "instance", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Routing/Router.php#L206-L218
train
frameworkwtf/core
src/Provider.php
Provider.getSentry
protected function getSentry(Container $container): callable { return function ($c) { $config = $c['config']('suit.sentry'); $client = new \Raven_Client($config['dsn'], $config['options'] ?? []); $client->install(); if ($c->has('user')) { $client->user_context((array) $c->get('user')); } return $client; }; }
php
protected function getSentry(Container $container): callable { return function ($c) { $config = $c['config']('suit.sentry'); $client = new \Raven_Client($config['dsn'], $config['options'] ?? []); $client->install(); if ($c->has('user')) { $client->user_context((array) $c->get('user')); } return $client; }; }
[ "protected", "function", "getSentry", "(", "Container", "$", "container", ")", ":", "callable", "{", "return", "function", "(", "$", "c", ")", "{", "$", "config", "=", "$", "c", "[", "'config'", "]", "(", "'suit.sentry'", ")", ";", "$", "client", "=", "new", "\\", "Raven_Client", "(", "$", "config", "[", "'dsn'", "]", ",", "$", "config", "[", "'options'", "]", "??", "[", "]", ")", ";", "$", "client", "->", "install", "(", ")", ";", "if", "(", "$", "c", "->", "has", "(", "'user'", ")", ")", "{", "$", "client", "->", "user_context", "(", "(", "array", ")", "$", "c", "->", "get", "(", "'user'", ")", ")", ";", "}", "return", "$", "client", ";", "}", ";", "}" ]
Add Sentry integration.
[ "Add", "Sentry", "integration", "." ]
8104ca140ec287c26724389780e5e1dba57a030a
https://github.com/frameworkwtf/core/blob/8104ca140ec287c26724389780e5e1dba57a030a/src/Provider.php#L49-L62
train
frameworkwtf/core
src/Provider.php
Provider.setErrorHandler
protected function setErrorHandler(Container $container): callable { return function (Container $container) { return function (ServerRequestInterface $request, ResponseInterface $response, Throwable $e) use ($container) { $container->sentry->captureException($e); if ($container->has('appErrorHandler')) { return $container['appErrorHandler']->error500($request, $response, $e); } return $response->withStatus(500); }; }; }
php
protected function setErrorHandler(Container $container): callable { return function (Container $container) { return function (ServerRequestInterface $request, ResponseInterface $response, Throwable $e) use ($container) { $container->sentry->captureException($e); if ($container->has('appErrorHandler')) { return $container['appErrorHandler']->error500($request, $response, $e); } return $response->withStatus(500); }; }; }
[ "protected", "function", "setErrorHandler", "(", "Container", "$", "container", ")", ":", "callable", "{", "return", "function", "(", "Container", "$", "container", ")", "{", "return", "function", "(", "ServerRequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ",", "Throwable", "$", "e", ")", "use", "(", "$", "container", ")", "{", "$", "container", "->", "sentry", "->", "captureException", "(", "$", "e", ")", ";", "if", "(", "$", "container", "->", "has", "(", "'appErrorHandler'", ")", ")", "{", "return", "$", "container", "[", "'appErrorHandler'", "]", "->", "error500", "(", "$", "request", ",", "$", "response", ",", "$", "e", ")", ";", "}", "return", "$", "response", "->", "withStatus", "(", "500", ")", ";", "}", ";", "}", ";", "}" ]
Set error handler with sentry. @param Container $container @return callable
[ "Set", "error", "handler", "with", "sentry", "." ]
8104ca140ec287c26724389780e5e1dba57a030a
https://github.com/frameworkwtf/core/blob/8104ca140ec287c26724389780e5e1dba57a030a/src/Provider.php#L96-L108
train
gplcart/export
handlers/Export.php
Export.prepare
protected function prepare(array $product) { $data = array(); foreach ($this->job['data']['header'] as $key => $value) { $data[$key] = isset($product[$key]) ? $product[$key] : ''; } $this->prepareImages($data, $product); $this->preparePrice($data, $product); $this->prepareImages($data, $product); return $data; }
php
protected function prepare(array $product) { $data = array(); foreach ($this->job['data']['header'] as $key => $value) { $data[$key] = isset($product[$key]) ? $product[$key] : ''; } $this->prepareImages($data, $product); $this->preparePrice($data, $product); $this->prepareImages($data, $product); return $data; }
[ "protected", "function", "prepare", "(", "array", "$", "product", ")", "{", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "job", "[", "'data'", "]", "[", "'header'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "data", "[", "$", "key", "]", "=", "isset", "(", "$", "product", "[", "$", "key", "]", ")", "?", "$", "product", "[", "$", "key", "]", ":", "''", ";", "}", "$", "this", "->", "prepareImages", "(", "$", "data", ",", "$", "product", ")", ";", "$", "this", "->", "preparePrice", "(", "$", "data", ",", "$", "product", ")", ";", "$", "this", "->", "prepareImages", "(", "$", "data", ",", "$", "product", ")", ";", "return", "$", "data", ";", "}" ]
Prepares export data @param array $product @return array
[ "Prepares", "export", "data" ]
b4d93c7a2bd6653f12231fb30d36601ea00fc926
https://github.com/gplcart/export/blob/b4d93c7a2bd6653f12231fb30d36601ea00fc926/handlers/Export.php#L99-L111
train
ColibriPlatform/base
Migration.php
Migration.up
public function up($limit = 0) { $migrations = $this->getNewMigrations(); if (empty($migrations)) { $this->messages[] = 'No new migration found. Your system is up-to-date.'; return true; } foreach ($migrations as $migration) { if (!$this->migrateUp($migration)) { $this->messages[] = "Migration {$migration} failed. The rest of the migrations are canceled."; return false; } } return true; }
php
public function up($limit = 0) { $migrations = $this->getNewMigrations(); if (empty($migrations)) { $this->messages[] = 'No new migration found. Your system is up-to-date.'; return true; } foreach ($migrations as $migration) { if (!$this->migrateUp($migration)) { $this->messages[] = "Migration {$migration} failed. The rest of the migrations are canceled."; return false; } } return true; }
[ "public", "function", "up", "(", "$", "limit", "=", "0", ")", "{", "$", "migrations", "=", "$", "this", "->", "getNewMigrations", "(", ")", ";", "if", "(", "empty", "(", "$", "migrations", ")", ")", "{", "$", "this", "->", "messages", "[", "]", "=", "'No new migration found. Your system is up-to-date.'", ";", "return", "true", ";", "}", "foreach", "(", "$", "migrations", "as", "$", "migration", ")", "{", "if", "(", "!", "$", "this", "->", "migrateUp", "(", "$", "migration", ")", ")", "{", "$", "this", "->", "messages", "[", "]", "=", "\"Migration {$migration} failed. The rest of the migrations are canceled.\"", ";", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Upgrades the application by applying new migrations. @return integer the status of the action execution. 0 means normal, other values mean abnormal.
[ "Upgrades", "the", "application", "by", "applying", "new", "migrations", "." ]
b45db9c88317e28acc5b024ac98f8428685179aa
https://github.com/ColibriPlatform/base/blob/b45db9c88317e28acc5b024ac98f8428685179aa/Migration.php#L64-L80
train
ColibriPlatform/base
Migration.php
Migration.migrateUp
protected function migrateUp($class) { if ($class === self::BASE_MIGRATION) { return true; } $this->messages[] = "*** applying $class"; $start = microtime(true); $migration = $this->createMigration($class); ob_start(); $result = $migration->up(); $messages = ob_get_contents(); ob_end_clean(); $this->messages[] = $messages; // $this->messages = ArrayHelper::merge($this->messages, explode("\n", $messages)); if ($result !== false) { $this->addMigrationHistory($class); $time = microtime(true) - $start; $this->messages[] = "*** applied $class (time: " . sprintf('%.3f', $time) . 's)'; return true; } else { $time = microtime(true) - $start; $this->messages[] = "*** failed to apply $class (time: " . sprintf('%.3f', $time) . 's)'; return false; } }
php
protected function migrateUp($class) { if ($class === self::BASE_MIGRATION) { return true; } $this->messages[] = "*** applying $class"; $start = microtime(true); $migration = $this->createMigration($class); ob_start(); $result = $migration->up(); $messages = ob_get_contents(); ob_end_clean(); $this->messages[] = $messages; // $this->messages = ArrayHelper::merge($this->messages, explode("\n", $messages)); if ($result !== false) { $this->addMigrationHistory($class); $time = microtime(true) - $start; $this->messages[] = "*** applied $class (time: " . sprintf('%.3f', $time) . 's)'; return true; } else { $time = microtime(true) - $start; $this->messages[] = "*** failed to apply $class (time: " . sprintf('%.3f', $time) . 's)'; return false; } }
[ "protected", "function", "migrateUp", "(", "$", "class", ")", "{", "if", "(", "$", "class", "===", "self", "::", "BASE_MIGRATION", ")", "{", "return", "true", ";", "}", "$", "this", "->", "messages", "[", "]", "=", "\"*** applying $class\"", ";", "$", "start", "=", "microtime", "(", "true", ")", ";", "$", "migration", "=", "$", "this", "->", "createMigration", "(", "$", "class", ")", ";", "ob_start", "(", ")", ";", "$", "result", "=", "$", "migration", "->", "up", "(", ")", ";", "$", "messages", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "this", "->", "messages", "[", "]", "=", "$", "messages", ";", "// $this->messages = ArrayHelper::merge($this->messages, explode(\"\\n\", $messages));", "if", "(", "$", "result", "!==", "false", ")", "{", "$", "this", "->", "addMigrationHistory", "(", "$", "class", ")", ";", "$", "time", "=", "microtime", "(", "true", ")", "-", "$", "start", ";", "$", "this", "->", "messages", "[", "]", "=", "\"*** applied $class (time: \"", ".", "sprintf", "(", "'%.3f'", ",", "$", "time", ")", ".", "'s)'", ";", "return", "true", ";", "}", "else", "{", "$", "time", "=", "microtime", "(", "true", ")", "-", "$", "start", ";", "$", "this", "->", "messages", "[", "]", "=", "\"*** failed to apply $class (time: \"", ".", "sprintf", "(", "'%.3f'", ",", "$", "time", ")", ".", "'s)'", ";", "return", "false", ";", "}", "}" ]
Upgrades with the specified migration class. @param string $class the migration class name @return boolean whether the migration is successful
[ "Upgrades", "with", "the", "specified", "migration", "class", "." ]
b45db9c88317e28acc5b024ac98f8428685179aa
https://github.com/ColibriPlatform/base/blob/b45db9c88317e28acc5b024ac98f8428685179aa/Migration.php#L88-L115
train
ColibriPlatform/base
Migration.php
Migration.getMigrationHistory
protected function getMigrationHistory($limit) { if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) { $this->createMigrationHistoryTable(); } $query = new Query; $rows = $query->select(['version', 'apply_time']) ->from($this->migrationTable) ->orderBy('apply_time DESC, version DESC') ->limit($limit) ->createCommand($this->db) ->queryAll(); $history = ArrayHelper::map($rows, 'version', 'apply_time'); unset($history[self::BASE_MIGRATION]); return $history; }
php
protected function getMigrationHistory($limit) { if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) { $this->createMigrationHistoryTable(); } $query = new Query; $rows = $query->select(['version', 'apply_time']) ->from($this->migrationTable) ->orderBy('apply_time DESC, version DESC') ->limit($limit) ->createCommand($this->db) ->queryAll(); $history = ArrayHelper::map($rows, 'version', 'apply_time'); unset($history[self::BASE_MIGRATION]); return $history; }
[ "protected", "function", "getMigrationHistory", "(", "$", "limit", ")", "{", "if", "(", "$", "this", "->", "db", "->", "schema", "->", "getTableSchema", "(", "$", "this", "->", "migrationTable", ",", "true", ")", "===", "null", ")", "{", "$", "this", "->", "createMigrationHistoryTable", "(", ")", ";", "}", "$", "query", "=", "new", "Query", ";", "$", "rows", "=", "$", "query", "->", "select", "(", "[", "'version'", ",", "'apply_time'", "]", ")", "->", "from", "(", "$", "this", "->", "migrationTable", ")", "->", "orderBy", "(", "'apply_time DESC, version DESC'", ")", "->", "limit", "(", "$", "limit", ")", "->", "createCommand", "(", "$", "this", "->", "db", ")", "->", "queryAll", "(", ")", ";", "$", "history", "=", "ArrayHelper", "::", "map", "(", "$", "rows", ",", "'version'", ",", "'apply_time'", ")", ";", "unset", "(", "$", "history", "[", "self", "::", "BASE_MIGRATION", "]", ")", ";", "return", "$", "history", ";", "}" ]
Returns the migration history. @param integer $limit the maximum number of records in the history to be returned. `null` for "no limit". @return array the migration history
[ "Returns", "the", "migration", "history", "." ]
b45db9c88317e28acc5b024ac98f8428685179aa
https://github.com/ColibriPlatform/base/blob/b45db9c88317e28acc5b024ac98f8428685179aa/Migration.php#L172-L188
train
johnkrovitch/Sam
File/Locator.php
Locator.locate
public function locate($source) { $sources = []; $normalizedSources = []; // if the wildcard is at the end of the string, it means that we look for a directory $endingWithWilCard = substr($source, strlen($source) - 2) === '/*'; if ($endingWithWilCard) { $source = substr($source, 0, strlen($source) - 2); } if (is_dir($source) || $endingWithWilCard) { $finder = new Finder(); $finder ->files() ->in($this->removeLastSlash($source)) ; foreach ($finder as $file) { $sources[] = $file; } } else if (strstr($source, '*') !== false) { // if the source contains a wildcard, we use it with the finder component $sources = $this->getSourcesFromFinder($source); } else { $sources[] = $source; } // each found sources should be normalized foreach ($sources as $source) { $normalizedSources[] = $this ->normalizer ->normalize($source); } return $normalizedSources; }
php
public function locate($source) { $sources = []; $normalizedSources = []; // if the wildcard is at the end of the string, it means that we look for a directory $endingWithWilCard = substr($source, strlen($source) - 2) === '/*'; if ($endingWithWilCard) { $source = substr($source, 0, strlen($source) - 2); } if (is_dir($source) || $endingWithWilCard) { $finder = new Finder(); $finder ->files() ->in($this->removeLastSlash($source)) ; foreach ($finder as $file) { $sources[] = $file; } } else if (strstr($source, '*') !== false) { // if the source contains a wildcard, we use it with the finder component $sources = $this->getSourcesFromFinder($source); } else { $sources[] = $source; } // each found sources should be normalized foreach ($sources as $source) { $normalizedSources[] = $this ->normalizer ->normalize($source); } return $normalizedSources; }
[ "public", "function", "locate", "(", "$", "source", ")", "{", "$", "sources", "=", "[", "]", ";", "$", "normalizedSources", "=", "[", "]", ";", "// if the wildcard is at the end of the string, it means that we look for a directory", "$", "endingWithWilCard", "=", "substr", "(", "$", "source", ",", "strlen", "(", "$", "source", ")", "-", "2", ")", "===", "'/*'", ";", "if", "(", "$", "endingWithWilCard", ")", "{", "$", "source", "=", "substr", "(", "$", "source", ",", "0", ",", "strlen", "(", "$", "source", ")", "-", "2", ")", ";", "}", "if", "(", "is_dir", "(", "$", "source", ")", "||", "$", "endingWithWilCard", ")", "{", "$", "finder", "=", "new", "Finder", "(", ")", ";", "$", "finder", "->", "files", "(", ")", "->", "in", "(", "$", "this", "->", "removeLastSlash", "(", "$", "source", ")", ")", ";", "foreach", "(", "$", "finder", "as", "$", "file", ")", "{", "$", "sources", "[", "]", "=", "$", "file", ";", "}", "}", "else", "if", "(", "strstr", "(", "$", "source", ",", "'*'", ")", "!==", "false", ")", "{", "// if the source contains a wildcard, we use it with the finder component", "$", "sources", "=", "$", "this", "->", "getSourcesFromFinder", "(", "$", "source", ")", ";", "}", "else", "{", "$", "sources", "[", "]", "=", "$", "source", ";", "}", "// each found sources should be normalized", "foreach", "(", "$", "sources", "as", "$", "source", ")", "{", "$", "normalizedSources", "[", "]", "=", "$", "this", "->", "normalizer", "->", "normalize", "(", "$", "source", ")", ";", "}", "return", "$", "normalizedSources", ";", "}" ]
Locate a source either if it a file or a directory and normalize it. Return an array of SplFileInfo. @param mixed $source @return SplFileInfo[] @throws Exception
[ "Locate", "a", "source", "either", "if", "it", "a", "file", "or", "a", "directory", "and", "normalize", "it", ".", "Return", "an", "array", "of", "SplFileInfo", "." ]
fbd3770c11eecc0a6d8070f439f149062316f606
https://github.com/johnkrovitch/Sam/blob/fbd3770c11eecc0a6d8070f439f149062316f606/File/Locator.php#L35-L72
train
johnkrovitch/Sam
File/Locator.php
Locator.getSourcesFromFinder
protected function getSourcesFromFinder($source) { $array = explode(DIRECTORY_SEPARATOR, $source); $filename = array_pop($array); $directory = $source; $pattern = '*'; // if a dot is present, the last part is the filename pattern if (strstr($filename, '.') !== false) { $pattern = $filename; $directory = implode('/', $array); } $finder = new Finder(); $finder ->name($pattern) ->in($directory); $sources = []; foreach ($finder as $source) { $sources[] = $source; } return $sources; }
php
protected function getSourcesFromFinder($source) { $array = explode(DIRECTORY_SEPARATOR, $source); $filename = array_pop($array); $directory = $source; $pattern = '*'; // if a dot is present, the last part is the filename pattern if (strstr($filename, '.') !== false) { $pattern = $filename; $directory = implode('/', $array); } $finder = new Finder(); $finder ->name($pattern) ->in($directory); $sources = []; foreach ($finder as $source) { $sources[] = $source; } return $sources; }
[ "protected", "function", "getSourcesFromFinder", "(", "$", "source", ")", "{", "$", "array", "=", "explode", "(", "DIRECTORY_SEPARATOR", ",", "$", "source", ")", ";", "$", "filename", "=", "array_pop", "(", "$", "array", ")", ";", "$", "directory", "=", "$", "source", ";", "$", "pattern", "=", "'*'", ";", "// if a dot is present, the last part is the filename pattern", "if", "(", "strstr", "(", "$", "filename", ",", "'.'", ")", "!==", "false", ")", "{", "$", "pattern", "=", "$", "filename", ";", "$", "directory", "=", "implode", "(", "'/'", ",", "$", "array", ")", ";", "}", "$", "finder", "=", "new", "Finder", "(", ")", ";", "$", "finder", "->", "name", "(", "$", "pattern", ")", "->", "in", "(", "$", "directory", ")", ";", "$", "sources", "=", "[", "]", ";", "foreach", "(", "$", "finder", "as", "$", "source", ")", "{", "$", "sources", "[", "]", "=", "$", "source", ";", "}", "return", "$", "sources", ";", "}" ]
Return files sources using the finder to allow wild wards. @param $source @return SplFileInfo[]
[ "Return", "files", "sources", "using", "the", "finder", "to", "allow", "wild", "wards", "." ]
fbd3770c11eecc0a6d8070f439f149062316f606
https://github.com/johnkrovitch/Sam/blob/fbd3770c11eecc0a6d8070f439f149062316f606/File/Locator.php#L91-L115
train
johnkrovitch/Sam
File/Locator.php
Locator.removeLastSlash
private function removeLastSlash($string) { if ('/' === substr($string, strlen($string) - 1)) { $string = substr($string, 0, strlen($string) - 1); } return $string; }
php
private function removeLastSlash($string) { if ('/' === substr($string, strlen($string) - 1)) { $string = substr($string, 0, strlen($string) - 1); } return $string; }
[ "private", "function", "removeLastSlash", "(", "$", "string", ")", "{", "if", "(", "'/'", "===", "substr", "(", "$", "string", ",", "strlen", "(", "$", "string", ")", "-", "1", ")", ")", "{", "$", "string", "=", "substr", "(", "$", "string", ",", "0", ",", "strlen", "(", "$", "string", ")", "-", "1", ")", ";", "}", "return", "$", "string", ";", "}" ]
Remove the last slash of the string. @param string $string @return string
[ "Remove", "the", "last", "slash", "of", "the", "string", "." ]
fbd3770c11eecc0a6d8070f439f149062316f606
https://github.com/johnkrovitch/Sam/blob/fbd3770c11eecc0a6d8070f439f149062316f606/File/Locator.php#L124-L131
train
agentmedia/phine-core
src/Core/Logic/Translation/ContentTranslator.php
ContentTranslator.SetContent
public function SetContent(Content $content) { $this->texts = array(); $wordings = ContentWording::Schema()->FetchByContent(false, $content); foreach($wordings as $wording) { $prefix = Str::Replace('-', '.', $content->GetType()); $this->texts[$prefix . '.' . $wording->GetPlaceholder()] = $wording->GetText(); } }
php
public function SetContent(Content $content) { $this->texts = array(); $wordings = ContentWording::Schema()->FetchByContent(false, $content); foreach($wordings as $wording) { $prefix = Str::Replace('-', '.', $content->GetType()); $this->texts[$prefix . '.' . $wording->GetPlaceholder()] = $wording->GetText(); } }
[ "public", "function", "SetContent", "(", "Content", "$", "content", ")", "{", "$", "this", "->", "texts", "=", "array", "(", ")", ";", "$", "wordings", "=", "ContentWording", "::", "Schema", "(", ")", "->", "FetchByContent", "(", "false", ",", "$", "content", ")", ";", "foreach", "(", "$", "wordings", "as", "$", "wording", ")", "{", "$", "prefix", "=", "Str", "::", "Replace", "(", "'-'", ",", "'.'", ",", "$", "content", "->", "GetType", "(", ")", ")", ";", "$", "this", "->", "texts", "[", "$", "prefix", ".", "'.'", ".", "$", "wording", "->", "GetPlaceholder", "(", ")", "]", "=", "$", "wording", "->", "GetText", "(", ")", ";", "}", "}" ]
Set the current content to retrieve customized wording texts @param Content $content The content
[ "Set", "the", "current", "content", "to", "retrieve", "customized", "wording", "texts" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Translation/ContentTranslator.php#L37-L46
train
agentmedia/phine-core
src/Core/Logic/Translation/ContentTranslator.php
ContentTranslator.GetReplacement
public function GetReplacement($placeholder) { if (isset($this->texts[$placeholder])) { return $this->texts[$placeholder]; } return $this->phpTranslator->GetReplacement($placeholder); }
php
public function GetReplacement($placeholder) { if (isset($this->texts[$placeholder])) { return $this->texts[$placeholder]; } return $this->phpTranslator->GetReplacement($placeholder); }
[ "public", "function", "GetReplacement", "(", "$", "placeholder", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "texts", "[", "$", "placeholder", "]", ")", ")", "{", "return", "$", "this", "->", "texts", "[", "$", "placeholder", "]", ";", "}", "return", "$", "this", "->", "phpTranslator", "->", "GetReplacement", "(", "$", "placeholder", ")", ";", "}" ]
Gets the placeholder replacement text @param string $placeholder The placeholder @return string Returns the replacement, without parameters attached, yet
[ "Gets", "the", "placeholder", "replacement", "text" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Translation/ContentTranslator.php#L73-L80
train
sndsgd/http
src/http/data/decoder/QueryStringDecoder.php
QueryStringDecoder.decodePair
public function decodePair(string $keyValuePair): array { # more than a handful of clients like to use '+' characters # when encoding data that is (almost) compliant with rfc 3986 # this is a hack that allows for it if (strpos($keyValuePair, "+") !== false) { $keyValuePair = str_replace("+", " ", $keyValuePair); } $parts = explode("=", $keyValuePair, 2); $key = rawurldecode($parts[0]); # interpret a key with an empty value as `null` $value = (count($parts) === 1) ? null : rawurldecode($parts[1]); return [$key, $value]; }
php
public function decodePair(string $keyValuePair): array { # more than a handful of clients like to use '+' characters # when encoding data that is (almost) compliant with rfc 3986 # this is a hack that allows for it if (strpos($keyValuePair, "+") !== false) { $keyValuePair = str_replace("+", " ", $keyValuePair); } $parts = explode("=", $keyValuePair, 2); $key = rawurldecode($parts[0]); # interpret a key with an empty value as `null` $value = (count($parts) === 1) ? null : rawurldecode($parts[1]); return [$key, $value]; }
[ "public", "function", "decodePair", "(", "string", "$", "keyValuePair", ")", ":", "array", "{", "# more than a handful of clients like to use '+' characters", "# when encoding data that is (almost) compliant with rfc 3986", "# this is a hack that allows for it", "if", "(", "strpos", "(", "$", "keyValuePair", ",", "\"+\"", ")", "!==", "false", ")", "{", "$", "keyValuePair", "=", "str_replace", "(", "\"+\"", ",", "\" \"", ",", "$", "keyValuePair", ")", ";", "}", "$", "parts", "=", "explode", "(", "\"=\"", ",", "$", "keyValuePair", ",", "2", ")", ";", "$", "key", "=", "rawurldecode", "(", "$", "parts", "[", "0", "]", ")", ";", "# interpret a key with an empty value as `null`", "$", "value", "=", "(", "count", "(", "$", "parts", ")", "===", "1", ")", "?", "null", ":", "rawurldecode", "(", "$", "parts", "[", "1", "]", ")", ";", "return", "[", "$", "key", ",", "$", "value", "]", ";", "}" ]
Decode a urlencoded parameter key value pair @param string $keyValuePair @return array<string> The decoded key and value
[ "Decode", "a", "urlencoded", "parameter", "key", "value", "pair" ]
e7f82010a66c6d3241a24ea82baf4593130c723b
https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/data/decoder/QueryStringDecoder.php#L54-L69
train
sndsgd/http
src/http/data/decoder/QueryStringDecoder.php
QueryStringDecoder.decode
public function decode($query): array { foreach (explode("&", $query) as $keyValuePair) { list($key, $value) = $this->decodePair($keyValuePair); $this->values->addValue($key, $value); } return $this->values->getValues(); }
php
public function decode($query): array { foreach (explode("&", $query) as $keyValuePair) { list($key, $value) = $this->decodePair($keyValuePair); $this->values->addValue($key, $value); } return $this->values->getValues(); }
[ "public", "function", "decode", "(", "$", "query", ")", ":", "array", "{", "foreach", "(", "explode", "(", "\"&\"", ",", "$", "query", ")", "as", "$", "keyValuePair", ")", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "$", "this", "->", "decodePair", "(", "$", "keyValuePair", ")", ";", "$", "this", "->", "values", "->", "addValue", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", "->", "values", "->", "getValues", "(", ")", ";", "}" ]
Decode a query string @param string $query @return array
[ "Decode", "a", "query", "string" ]
e7f82010a66c6d3241a24ea82baf4593130c723b
https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/data/decoder/QueryStringDecoder.php#L77-L84
train
PenoaksDev/Milky-Framework
src/Milky/Database/Query/Builder.php
Builder.crossJoin
public function crossJoin( $table, $first = null, $operator = null, $second = null ) { if ( $first ) { return $this->join( $table, $first, $operator, $second, 'cross' ); } $this->joins[] = new JoinClause( 'cross', $table ); return $this; }
php
public function crossJoin( $table, $first = null, $operator = null, $second = null ) { if ( $first ) { return $this->join( $table, $first, $operator, $second, 'cross' ); } $this->joins[] = new JoinClause( 'cross', $table ); return $this; }
[ "public", "function", "crossJoin", "(", "$", "table", ",", "$", "first", "=", "null", ",", "$", "operator", "=", "null", ",", "$", "second", "=", "null", ")", "{", "if", "(", "$", "first", ")", "{", "return", "$", "this", "->", "join", "(", "$", "table", ",", "$", "first", ",", "$", "operator", ",", "$", "second", ",", "'cross'", ")", ";", "}", "$", "this", "->", "joins", "[", "]", "=", "new", "JoinClause", "(", "'cross'", ",", "$", "table", ")", ";", "return", "$", "this", ";", "}" ]
Add a "cross join" clause to the query. @param string $table @param string $first @param string $operator @param string $second @return Builder|static
[ "Add", "a", "cross", "join", "clause", "to", "the", "query", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Query/Builder.php#L476-L486
train
PenoaksDev/Milky-Framework
src/Milky/Database/Query/Builder.php
Builder.lock
public function lock( $value = true ) { $this->lock = $value; if ( $this->lock ) { $this->useWritePdo(); } return $this; }
php
public function lock( $value = true ) { $this->lock = $value; if ( $this->lock ) { $this->useWritePdo(); } return $this; }
[ "public", "function", "lock", "(", "$", "value", "=", "true", ")", "{", "$", "this", "->", "lock", "=", "$", "value", ";", "if", "(", "$", "this", "->", "lock", ")", "{", "$", "this", "->", "useWritePdo", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Lock the selected rows in the table. @param bool $value @return $this
[ "Lock", "the", "selected", "rows", "in", "the", "table", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Query/Builder.php#L1528-L1538
train
cmsgears/module-community
common/models/entities/Group.php
Group.getMemberUsers
public function getMemberUsers() { $memberTable = CmnTables::getTableName( CmnTables::TABLE_GROUP_MEMBER ); return $this->hasMany( User::class, [ 'id' => 'userId' ] ) ->viaTable( $memberTable, [ 'groupId' => 'id' ] ); }
php
public function getMemberUsers() { $memberTable = CmnTables::getTableName( CmnTables::TABLE_GROUP_MEMBER ); return $this->hasMany( User::class, [ 'id' => 'userId' ] ) ->viaTable( $memberTable, [ 'groupId' => 'id' ] ); }
[ "public", "function", "getMemberUsers", "(", ")", "{", "$", "memberTable", "=", "CmnTables", "::", "getTableName", "(", "CmnTables", "::", "TABLE_GROUP_MEMBER", ")", ";", "return", "$", "this", "->", "hasMany", "(", "User", "::", "class", ",", "[", "'id'", "=>", "'userId'", "]", ")", "->", "viaTable", "(", "$", "memberTable", ",", "[", "'groupId'", "=>", "'id'", "]", ")", ";", "}" ]
Return all the group member users. @return \cmsgears\core\common\models\entities\User[]
[ "Return", "all", "the", "group", "member", "users", "." ]
0ca9cf0aa0cee395a4788bd6085f291e10728555
https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/common/models/entities/Group.php#L304-L310
train
cmsgears/module-community
common/models/entities/Group.php
Group.queryWithAuthor
public static function queryWithAuthor( $config = [] ) { $config[ 'relations' ][] = [ 'avatar', 'modelContent', 'modelContent.template', 'modelContent.banner', 'creator' ]; $config[ 'relations' ][] = [ 'creator.avatar' => function ( $query ) { $fileTable = CoreTables::getTableName( CoreTables::TABLE_FILE ); $query->from( "$fileTable aavatar" ); } ]; return parent::queryWithAll( $config ); }
php
public static function queryWithAuthor( $config = [] ) { $config[ 'relations' ][] = [ 'avatar', 'modelContent', 'modelContent.template', 'modelContent.banner', 'creator' ]; $config[ 'relations' ][] = [ 'creator.avatar' => function ( $query ) { $fileTable = CoreTables::getTableName( CoreTables::TABLE_FILE ); $query->from( "$fileTable aavatar" ); } ]; return parent::queryWithAll( $config ); }
[ "public", "static", "function", "queryWithAuthor", "(", "$", "config", "=", "[", "]", ")", "{", "$", "config", "[", "'relations'", "]", "[", "]", "=", "[", "'avatar'", ",", "'modelContent'", ",", "'modelContent.template'", ",", "'modelContent.banner'", ",", "'creator'", "]", ";", "$", "config", "[", "'relations'", "]", "[", "]", "=", "[", "'creator.avatar'", "=>", "function", "(", "$", "query", ")", "{", "$", "fileTable", "=", "CoreTables", "::", "getTableName", "(", "CoreTables", "::", "TABLE_FILE", ")", ";", "$", "query", "->", "from", "(", "\"$fileTable aavatar\"", ")", ";", "}", "]", ";", "return", "parent", "::", "queryWithAll", "(", "$", "config", ")", ";", "}" ]
Return query to find the model with avatar, content, template, banner, author and author avatar. @param array $config @return \yii\db\ActiveQuery to query with avatar, content, template, banner, author and author avatar.
[ "Return", "query", "to", "find", "the", "model", "with", "avatar", "content", "template", "banner", "author", "and", "author", "avatar", "." ]
0ca9cf0aa0cee395a4788bd6085f291e10728555
https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/common/models/entities/Group.php#L391-L401
train
bkstg/resource-bundle
EventSubscriber/ProductionMenuSubscriber.php
ProductionMenuSubscriber.addResourceItem
public function addResourceItem(ProductionMenuCollectionEvent $event): void { $menu = $event->getMenu(); $group = $event->getGroup(); // Create resource menu item. $resources = $this->factory->createItem('menu_item.resources', [ 'route' => 'bkstg_resource_index', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => [ 'icon' => 'file', 'translation_domain' => BkstgResourceBundle::TRANSLATION_DOMAIN, ], ]); $menu->addChild($resources); // If this user is an editor create the post and archive items. if ($this->auth->isGranted('GROUP_ROLE_EDITOR', $group)) { $resources_resources = $this->factory->createItem('menu_item.resources_resources', [ 'route' => 'bkstg_resource_index', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgResourceBundle::TRANSLATION_DOMAIN], ]); $resources->addChild($resources_resources); $archive = $this->factory->createItem('menu_item.resources_archive', [ 'route' => 'bkstg_resource_archive', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgResourceBundle::TRANSLATION_DOMAIN], ]); $resources->addChild($archive); } }
php
public function addResourceItem(ProductionMenuCollectionEvent $event): void { $menu = $event->getMenu(); $group = $event->getGroup(); // Create resource menu item. $resources = $this->factory->createItem('menu_item.resources', [ 'route' => 'bkstg_resource_index', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => [ 'icon' => 'file', 'translation_domain' => BkstgResourceBundle::TRANSLATION_DOMAIN, ], ]); $menu->addChild($resources); // If this user is an editor create the post and archive items. if ($this->auth->isGranted('GROUP_ROLE_EDITOR', $group)) { $resources_resources = $this->factory->createItem('menu_item.resources_resources', [ 'route' => 'bkstg_resource_index', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgResourceBundle::TRANSLATION_DOMAIN], ]); $resources->addChild($resources_resources); $archive = $this->factory->createItem('menu_item.resources_archive', [ 'route' => 'bkstg_resource_archive', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgResourceBundle::TRANSLATION_DOMAIN], ]); $resources->addChild($archive); } }
[ "public", "function", "addResourceItem", "(", "ProductionMenuCollectionEvent", "$", "event", ")", ":", "void", "{", "$", "menu", "=", "$", "event", "->", "getMenu", "(", ")", ";", "$", "group", "=", "$", "event", "->", "getGroup", "(", ")", ";", "// Create resource menu item.", "$", "resources", "=", "$", "this", "->", "factory", "->", "createItem", "(", "'menu_item.resources'", ",", "[", "'route'", "=>", "'bkstg_resource_index'", ",", "'routeParameters'", "=>", "[", "'production_slug'", "=>", "$", "group", "->", "getSlug", "(", ")", "]", ",", "'extras'", "=>", "[", "'icon'", "=>", "'file'", ",", "'translation_domain'", "=>", "BkstgResourceBundle", "::", "TRANSLATION_DOMAIN", ",", "]", ",", "]", ")", ";", "$", "menu", "->", "addChild", "(", "$", "resources", ")", ";", "// If this user is an editor create the post and archive items.", "if", "(", "$", "this", "->", "auth", "->", "isGranted", "(", "'GROUP_ROLE_EDITOR'", ",", "$", "group", ")", ")", "{", "$", "resources_resources", "=", "$", "this", "->", "factory", "->", "createItem", "(", "'menu_item.resources_resources'", ",", "[", "'route'", "=>", "'bkstg_resource_index'", ",", "'routeParameters'", "=>", "[", "'production_slug'", "=>", "$", "group", "->", "getSlug", "(", ")", "]", ",", "'extras'", "=>", "[", "'translation_domain'", "=>", "BkstgResourceBundle", "::", "TRANSLATION_DOMAIN", "]", ",", "]", ")", ";", "$", "resources", "->", "addChild", "(", "$", "resources_resources", ")", ";", "$", "archive", "=", "$", "this", "->", "factory", "->", "createItem", "(", "'menu_item.resources_archive'", ",", "[", "'route'", "=>", "'bkstg_resource_archive'", ",", "'routeParameters'", "=>", "[", "'production_slug'", "=>", "$", "group", "->", "getSlug", "(", ")", "]", ",", "'extras'", "=>", "[", "'translation_domain'", "=>", "BkstgResourceBundle", "::", "TRANSLATION_DOMAIN", "]", ",", "]", ")", ";", "$", "resources", "->", "addChild", "(", "$", "archive", ")", ";", "}", "}" ]
Add the resource menu items. @param ProductionMenuCollectionEvent $event The menu collection event. @return void
[ "Add", "the", "resource", "menu", "items", "." ]
9d094366799a4df117a1dd747af9bb6debe14325
https://github.com/bkstg/resource-bundle/blob/9d094366799a4df117a1dd747af9bb6debe14325/EventSubscriber/ProductionMenuSubscriber.php#L60-L92
train
ZFrapid/zfrapid-library
src/View/Helper/BootstrapFlashMessenger.php
BootstrapFlashMessenger.render
public function render() { // get messages $allMessages = [ 'danger' => array_unique( array_merge( $this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages() ) ), 'success' => array_unique( array_merge( $this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages() ) ), 'warning' => array_unique( array_merge( $this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages() ) ), 'info' => array_unique( array_merge( $this->flashMessenger->getInfoMessages(), $this->flashMessenger->getCurrentInfoMessages() ) ), 'default' => array_unique( array_merge( $this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages() ) ), ]; // clear messages $this->flashMessenger->clearMessagesFromContainer(); $this->flashMessenger->clearCurrentMessagesFromContainer(); // initialize output $output = ''; // loop through messages foreach ($allMessages as $groupKey => $groupMessages) { foreach ($groupMessages as $message) { $addClass = $groupKey == 'default' ? '' : 'alert-' . $groupKey; // setup view model $viewModel = new ViewModel(); $viewModel->setVariable('alertClass', $addClass); $viewModel->setVariable('alertMessage', $message); $viewModel->setTemplate('zfrapid-library/widget/bootstrap-alert'); // add rendered output $output .= $this->getView()->render($viewModel); } } // return output return $output . "\n"; }
php
public function render() { // get messages $allMessages = [ 'danger' => array_unique( array_merge( $this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages() ) ), 'success' => array_unique( array_merge( $this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages() ) ), 'warning' => array_unique( array_merge( $this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages() ) ), 'info' => array_unique( array_merge( $this->flashMessenger->getInfoMessages(), $this->flashMessenger->getCurrentInfoMessages() ) ), 'default' => array_unique( array_merge( $this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages() ) ), ]; // clear messages $this->flashMessenger->clearMessagesFromContainer(); $this->flashMessenger->clearCurrentMessagesFromContainer(); // initialize output $output = ''; // loop through messages foreach ($allMessages as $groupKey => $groupMessages) { foreach ($groupMessages as $message) { $addClass = $groupKey == 'default' ? '' : 'alert-' . $groupKey; // setup view model $viewModel = new ViewModel(); $viewModel->setVariable('alertClass', $addClass); $viewModel->setVariable('alertMessage', $message); $viewModel->setTemplate('zfrapid-library/widget/bootstrap-alert'); // add rendered output $output .= $this->getView()->render($viewModel); } } // return output return $output . "\n"; }
[ "public", "function", "render", "(", ")", "{", "// get messages", "$", "allMessages", "=", "[", "'danger'", "=>", "array_unique", "(", "array_merge", "(", "$", "this", "->", "flashMessenger", "->", "getErrorMessages", "(", ")", ",", "$", "this", "->", "flashMessenger", "->", "getCurrentErrorMessages", "(", ")", ")", ")", ",", "'success'", "=>", "array_unique", "(", "array_merge", "(", "$", "this", "->", "flashMessenger", "->", "getSuccessMessages", "(", ")", ",", "$", "this", "->", "flashMessenger", "->", "getCurrentSuccessMessages", "(", ")", ")", ")", ",", "'warning'", "=>", "array_unique", "(", "array_merge", "(", "$", "this", "->", "flashMessenger", "->", "getWarningMessages", "(", ")", ",", "$", "this", "->", "flashMessenger", "->", "getCurrentWarningMessages", "(", ")", ")", ")", ",", "'info'", "=>", "array_unique", "(", "array_merge", "(", "$", "this", "->", "flashMessenger", "->", "getInfoMessages", "(", ")", ",", "$", "this", "->", "flashMessenger", "->", "getCurrentInfoMessages", "(", ")", ")", ")", ",", "'default'", "=>", "array_unique", "(", "array_merge", "(", "$", "this", "->", "flashMessenger", "->", "getMessages", "(", ")", ",", "$", "this", "->", "flashMessenger", "->", "getCurrentMessages", "(", ")", ")", ")", ",", "]", ";", "// clear messages", "$", "this", "->", "flashMessenger", "->", "clearMessagesFromContainer", "(", ")", ";", "$", "this", "->", "flashMessenger", "->", "clearCurrentMessagesFromContainer", "(", ")", ";", "// initialize output", "$", "output", "=", "''", ";", "// loop through messages", "foreach", "(", "$", "allMessages", "as", "$", "groupKey", "=>", "$", "groupMessages", ")", "{", "foreach", "(", "$", "groupMessages", "as", "$", "message", ")", "{", "$", "addClass", "=", "$", "groupKey", "==", "'default'", "?", "''", ":", "'alert-'", ".", "$", "groupKey", ";", "// setup view model", "$", "viewModel", "=", "new", "ViewModel", "(", ")", ";", "$", "viewModel", "->", "setVariable", "(", "'alertClass'", ",", "$", "addClass", ")", ";", "$", "viewModel", "->", "setVariable", "(", "'alertMessage'", ",", "$", "message", ")", ";", "$", "viewModel", "->", "setTemplate", "(", "'zfrapid-library/widget/bootstrap-alert'", ")", ";", "// add rendered output", "$", "output", ".=", "$", "this", "->", "getView", "(", ")", "->", "render", "(", "$", "viewModel", ")", ";", "}", "}", "// return output", "return", "$", "output", ".", "\"\\n\"", ";", "}" ]
Outputs message depending on flag @return string
[ "Outputs", "message", "depending", "on", "flag" ]
3eca4f465dd1f2dee889532892c5052e830bc03c
https://github.com/ZFrapid/zfrapid-library/blob/3eca4f465dd1f2dee889532892c5052e830bc03c/src/View/Helper/BootstrapFlashMessenger.php#L58-L119
train
mwyatt/core
src/Mail.php
Mail.getInlinedHtml
public function getInlinedHtml($body) { $inliner = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles; $inliner->setHtml($body); $inliner->setUseInlineStylesBlock(); return $inliner->convert(); }
php
public function getInlinedHtml($body) { $inliner = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles; $inliner->setHtml($body); $inliner->setUseInlineStylesBlock(); return $inliner->convert(); }
[ "public", "function", "getInlinedHtml", "(", "$", "body", ")", "{", "$", "inliner", "=", "new", "\\", "TijsVerkoyen", "\\", "CssToInlineStyles", "\\", "CssToInlineStyles", ";", "$", "inliner", "->", "setHtml", "(", "$", "body", ")", ";", "$", "inliner", "->", "setUseInlineStylesBlock", "(", ")", ";", "return", "$", "inliner", "->", "convert", "(", ")", ";", "}" ]
sets body after mashing in inline styles this is the method for doing tagging, simple now! @return string inlined stuffs
[ "sets", "body", "after", "mashing", "in", "inline", "styles", "this", "is", "the", "method", "for", "doing", "tagging", "simple", "now!" ]
8ea9d67cc84fe6aff17a469c703d5492dbcd93ed
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Mail.php#L51-L57
train
shgysk8zer0/core_api
traits/pdostatement.php
PDOStatement.execute
final public function execute($bound_input_params = null) { if (!is_array($bound_input_params) or empty($bound_input_params)) { $success = parent::execute(); } else { $success = parent::execute($this->bindConversion($bound_input_params)); } // Accumulative success of statement execution if (is_null($this->_success)) { // Success is not set, so it is the result of this execution $this->_success = $success; } else { // Success is already set, so it is `&=`d to `$success` // false &= true -> false // true &= false -> false // true &= true -> true $this->_success &= $this->_success; } return $this; }
php
final public function execute($bound_input_params = null) { if (!is_array($bound_input_params) or empty($bound_input_params)) { $success = parent::execute(); } else { $success = parent::execute($this->bindConversion($bound_input_params)); } // Accumulative success of statement execution if (is_null($this->_success)) { // Success is not set, so it is the result of this execution $this->_success = $success; } else { // Success is already set, so it is `&=`d to `$success` // false &= true -> false // true &= false -> false // true &= true -> true $this->_success &= $this->_success; } return $this; }
[ "final", "public", "function", "execute", "(", "$", "bound_input_params", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "bound_input_params", ")", "or", "empty", "(", "$", "bound_input_params", ")", ")", "{", "$", "success", "=", "parent", "::", "execute", "(", ")", ";", "}", "else", "{", "$", "success", "=", "parent", "::", "execute", "(", "$", "this", "->", "bindConversion", "(", "$", "bound_input_params", ")", ")", ";", "}", "// Accumulative success of statement execution", "if", "(", "is_null", "(", "$", "this", "->", "_success", ")", ")", "{", "// Success is not set, so it is the result of this execution", "$", "this", "->", "_success", "=", "$", "success", ";", "}", "else", "{", "// Success is already set, so it is `&=`d to `$success`", "// false &= true -> false", "// true &= false -> false", "// true &= true -> true", "$", "this", "->", "_success", "&=", "$", "this", "->", "_success", ";", "}", "return", "$", "this", ";", "}" ]
Execute the prepared statement @param array $bound_input_params [$key => $value] @return self
[ "Execute", "the", "prepared", "statement" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/pdostatement.php#L54-L74
train
Xsaven/laravel-intelect-admin
src/Addons/LogViewer/LogViewer.php
LogViewer.getLogFiles
public function getLogFiles($count = 20) { $files = glob(storage_path('logs/*')); $files = array_combine($files, array_map("filemtime", $files)); arsort($files); $files = array_map('basename', array_keys($files)); return array_slice($files, 0, $count); }
php
public function getLogFiles($count = 20) { $files = glob(storage_path('logs/*')); $files = array_combine($files, array_map("filemtime", $files)); arsort($files); $files = array_map('basename', array_keys($files)); return array_slice($files, 0, $count); }
[ "public", "function", "getLogFiles", "(", "$", "count", "=", "20", ")", "{", "$", "files", "=", "glob", "(", "storage_path", "(", "'logs/*'", ")", ")", ";", "$", "files", "=", "array_combine", "(", "$", "files", ",", "array_map", "(", "\"filemtime\"", ",", "$", "files", ")", ")", ";", "arsort", "(", "$", "files", ")", ";", "$", "files", "=", "array_map", "(", "'basename'", ",", "array_keys", "(", "$", "files", ")", ")", ";", "return", "array_slice", "(", "$", "files", ",", "0", ",", "$", "count", ")", ";", "}" ]
Get log file list in storage. @param int $count @return array
[ "Get", "log", "file", "list", "in", "storage", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/LogViewer/LogViewer.php#L102-L111
train
Xsaven/laravel-intelect-admin
src/Addons/LogViewer/LogViewer.php
LogViewer.getPrevPageUrl
public function getPrevPageUrl() { if ($this->pageOffset['end'] >= $this->getFilesize() - 1) { return false; } return [ 'file' => $this->file, 'offset' => $this->pageOffset['end'] ]; }
php
public function getPrevPageUrl() { if ($this->pageOffset['end'] >= $this->getFilesize() - 1) { return false; } return [ 'file' => $this->file, 'offset' => $this->pageOffset['end'] ]; }
[ "public", "function", "getPrevPageUrl", "(", ")", "{", "if", "(", "$", "this", "->", "pageOffset", "[", "'end'", "]", ">=", "$", "this", "->", "getFilesize", "(", ")", "-", "1", ")", "{", "return", "false", ";", "}", "return", "[", "'file'", "=>", "$", "this", "->", "file", ",", "'offset'", "=>", "$", "this", "->", "pageOffset", "[", "'end'", "]", "]", ";", "}" ]
Get previous page url. @return bool|string
[ "Get", "previous", "page", "url", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/LogViewer/LogViewer.php#L130-L139
train
Xsaven/laravel-intelect-admin
src/Addons/LogViewer/LogViewer.php
LogViewer.tail
public function tail($seek) { // Open the file $f = fopen($this->filePath, "rb"); if (!$seek) { // Jump to last character fseek($f, -1, SEEK_END); } else { fseek($f, abs($seek)); } $output = ''; while (!feof($f)) { $output .= fread($f, 4096); } $pos = ftell($f); fclose($f); $logs = []; foreach ($this->parseLog(trim($output)) as $log) { $logs[] = $this->renderTableRow($log); } return [$pos, $logs]; }
php
public function tail($seek) { // Open the file $f = fopen($this->filePath, "rb"); if (!$seek) { // Jump to last character fseek($f, -1, SEEK_END); } else { fseek($f, abs($seek)); } $output = ''; while (!feof($f)) { $output .= fread($f, 4096); } $pos = ftell($f); fclose($f); $logs = []; foreach ($this->parseLog(trim($output)) as $log) { $logs[] = $this->renderTableRow($log); } return [$pos, $logs]; }
[ "public", "function", "tail", "(", "$", "seek", ")", "{", "// Open the file", "$", "f", "=", "fopen", "(", "$", "this", "->", "filePath", ",", "\"rb\"", ")", ";", "if", "(", "!", "$", "seek", ")", "{", "// Jump to last character", "fseek", "(", "$", "f", ",", "-", "1", ",", "SEEK_END", ")", ";", "}", "else", "{", "fseek", "(", "$", "f", ",", "abs", "(", "$", "seek", ")", ")", ";", "}", "$", "output", "=", "''", ";", "while", "(", "!", "feof", "(", "$", "f", ")", ")", "{", "$", "output", ".=", "fread", "(", "$", "f", ",", "4096", ")", ";", "}", "$", "pos", "=", "ftell", "(", "$", "f", ")", ";", "fclose", "(", "$", "f", ")", ";", "$", "logs", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "parseLog", "(", "trim", "(", "$", "output", ")", ")", "as", "$", "log", ")", "{", "$", "logs", "[", "]", "=", "$", "this", "->", "renderTableRow", "(", "$", "log", ")", ";", "}", "return", "[", "$", "pos", ",", "$", "logs", "]", ";", "}" ]
Get tail logs in log file. @param integer $seek @return array
[ "Get", "tail", "logs", "in", "log", "file", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/LogViewer/LogViewer.php#L237-L266
train
Xsaven/laravel-intelect-admin
src/Addons/LogViewer/LogViewer.php
LogViewer.renderTableRow
protected function renderTableRow($log) { $color = LogViewer::$levelColors[$log['level']] ?? 'black'; $index = uniqid(); $button = ''; if (!empty($log['trace'])) { $button = "<a class=\"btn btn-primary btn-xs\" data-toggle=\"collapse\" data-target=\".trace-{$index}\"><i class=\"fa fa-info\"></i>&nbsp;&nbsp;Exception</a>"; } $trace = ''; if (!empty($log['trace'])) { $trace = "<tr class=\"collapse trace-{$index}\"> <td colspan=\"5\"><div style=\"white-space: pre-wrap;background: #333;color: #fff; padding: 10px;\">{$log['trace']}</div></td> </tr>"; } return <<<TPL <tr style="background-color: rgb(255, 255, 213);"> <td><span class="label bg-{$color}">{$log['level']}</span></td> <td><strong>{$log['env']}</strong></td> <td style="width:150px;">{$log['time']}</td> <td><code>{$log['info']}</code></td> <td>$button</td> </tr> $trace TPL; }
php
protected function renderTableRow($log) { $color = LogViewer::$levelColors[$log['level']] ?? 'black'; $index = uniqid(); $button = ''; if (!empty($log['trace'])) { $button = "<a class=\"btn btn-primary btn-xs\" data-toggle=\"collapse\" data-target=\".trace-{$index}\"><i class=\"fa fa-info\"></i>&nbsp;&nbsp;Exception</a>"; } $trace = ''; if (!empty($log['trace'])) { $trace = "<tr class=\"collapse trace-{$index}\"> <td colspan=\"5\"><div style=\"white-space: pre-wrap;background: #333;color: #fff; padding: 10px;\">{$log['trace']}</div></td> </tr>"; } return <<<TPL <tr style="background-color: rgb(255, 255, 213);"> <td><span class="label bg-{$color}">{$log['level']}</span></td> <td><strong>{$log['env']}</strong></td> <td style="width:150px;">{$log['time']}</td> <td><code>{$log['info']}</code></td> <td>$button</td> </tr> $trace TPL; }
[ "protected", "function", "renderTableRow", "(", "$", "log", ")", "{", "$", "color", "=", "LogViewer", "::", "$", "levelColors", "[", "$", "log", "[", "'level'", "]", "]", "??", "'black'", ";", "$", "index", "=", "uniqid", "(", ")", ";", "$", "button", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "log", "[", "'trace'", "]", ")", ")", "{", "$", "button", "=", "\"<a class=\\\"btn btn-primary btn-xs\\\" data-toggle=\\\"collapse\\\" data-target=\\\".trace-{$index}\\\"><i class=\\\"fa fa-info\\\"></i>&nbsp;&nbsp;Exception</a>\"", ";", "}", "$", "trace", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "log", "[", "'trace'", "]", ")", ")", "{", "$", "trace", "=", "\"<tr class=\\\"collapse trace-{$index}\\\">\n <td colspan=\\\"5\\\"><div style=\\\"white-space: pre-wrap;background: #333;color: #fff; padding: 10px;\\\">{$log['trace']}</div></td>\n</tr>\"", ";", "}", "return", " <<<TPL\n<tr style=\"background-color: rgb(255, 255, 213);\">\n <td><span class=\"label bg-{$color}\">{$log['level']}</span></td>\n <td><strong>{$log['env']}</strong></td>\n <td style=\"width:150px;\">{$log['time']}</td>\n <td><code>{$log['info']}</code></td>\n <td>$button</td>\n</tr>\n$trace\nTPL", ";", "}" ]
Render table row. @param $log @return string
[ "Render", "table", "row", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/LogViewer/LogViewer.php#L274-L305
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/M2P.php
M2P.setMedia
public function setMedia(ChildMedia $v = null) { if ($v === null) { $this->setMediaId(NULL); } else { $this->setMediaId($v->getId()); } $this->aMedia = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildMedia object, it will not be re-added. if ($v !== null) { $v->addM2P($this); } return $this; }
php
public function setMedia(ChildMedia $v = null) { if ($v === null) { $this->setMediaId(NULL); } else { $this->setMediaId($v->getId()); } $this->aMedia = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildMedia object, it will not be re-added. if ($v !== null) { $v->addM2P($this); } return $this; }
[ "public", "function", "setMedia", "(", "ChildMedia", "$", "v", "=", "null", ")", "{", "if", "(", "$", "v", "===", "null", ")", "{", "$", "this", "->", "setMediaId", "(", "NULL", ")", ";", "}", "else", "{", "$", "this", "->", "setMediaId", "(", "$", "v", "->", "getId", "(", ")", ")", ";", "}", "$", "this", "->", "aMedia", "=", "$", "v", ";", "// Add binding for other direction of this n:n relationship.", "// If this object has already been added to the ChildMedia object, it will not be re-added.", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "->", "addM2P", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}" ]
Declares an association between this object and a ChildMedia object. @param ChildMedia $v @return $this|\Attogram\SharedMedia\Orm\M2P The current object (for fluent API support) @throws PropelException
[ "Declares", "an", "association", "between", "this", "object", "and", "a", "ChildMedia", "object", "." ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/M2P.php#L1080-L1098
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/M2P.php
M2P.getMedia
public function getMedia(ConnectionInterface $con = null) { if ($this->aMedia === null && ($this->media_id != 0)) { $this->aMedia = ChildMediaQuery::create()->findPk($this->media_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aMedia->addM2Ps($this); */ } return $this->aMedia; }
php
public function getMedia(ConnectionInterface $con = null) { if ($this->aMedia === null && ($this->media_id != 0)) { $this->aMedia = ChildMediaQuery::create()->findPk($this->media_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aMedia->addM2Ps($this); */ } return $this->aMedia; }
[ "public", "function", "getMedia", "(", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "$", "this", "->", "aMedia", "===", "null", "&&", "(", "$", "this", "->", "media_id", "!=", "0", ")", ")", "{", "$", "this", "->", "aMedia", "=", "ChildMediaQuery", "::", "create", "(", ")", "->", "findPk", "(", "$", "this", "->", "media_id", ",", "$", "con", ")", ";", "/* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n $this->aMedia->addM2Ps($this);\n */", "}", "return", "$", "this", "->", "aMedia", ";", "}" ]
Get the associated ChildMedia object @param ConnectionInterface $con Optional Connection object. @return ChildMedia The associated ChildMedia object. @throws PropelException
[ "Get", "the", "associated", "ChildMedia", "object" ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/M2P.php#L1108-L1122
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/M2P.php
M2P.setPage
public function setPage(ChildPage $v = null) { if ($v === null) { $this->setPageId(NULL); } else { $this->setPageId($v->getId()); } $this->aPage = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildPage object, it will not be re-added. if ($v !== null) { $v->addM2P($this); } return $this; }
php
public function setPage(ChildPage $v = null) { if ($v === null) { $this->setPageId(NULL); } else { $this->setPageId($v->getId()); } $this->aPage = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildPage object, it will not be re-added. if ($v !== null) { $v->addM2P($this); } return $this; }
[ "public", "function", "setPage", "(", "ChildPage", "$", "v", "=", "null", ")", "{", "if", "(", "$", "v", "===", "null", ")", "{", "$", "this", "->", "setPageId", "(", "NULL", ")", ";", "}", "else", "{", "$", "this", "->", "setPageId", "(", "$", "v", "->", "getId", "(", ")", ")", ";", "}", "$", "this", "->", "aPage", "=", "$", "v", ";", "// Add binding for other direction of this n:n relationship.", "// If this object has already been added to the ChildPage object, it will not be re-added.", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "->", "addM2P", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}" ]
Declares an association between this object and a ChildPage object. @param ChildPage $v @return $this|\Attogram\SharedMedia\Orm\M2P The current object (for fluent API support) @throws PropelException
[ "Declares", "an", "association", "between", "this", "object", "and", "a", "ChildPage", "object", "." ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/M2P.php#L1131-L1149
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/M2P.php
M2P.getPage
public function getPage(ConnectionInterface $con = null) { if ($this->aPage === null && ($this->page_id != 0)) { $this->aPage = ChildPageQuery::create()->findPk($this->page_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPage->addM2Ps($this); */ } return $this->aPage; }
php
public function getPage(ConnectionInterface $con = null) { if ($this->aPage === null && ($this->page_id != 0)) { $this->aPage = ChildPageQuery::create()->findPk($this->page_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPage->addM2Ps($this); */ } return $this->aPage; }
[ "public", "function", "getPage", "(", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "$", "this", "->", "aPage", "===", "null", "&&", "(", "$", "this", "->", "page_id", "!=", "0", ")", ")", "{", "$", "this", "->", "aPage", "=", "ChildPageQuery", "::", "create", "(", ")", "->", "findPk", "(", "$", "this", "->", "page_id", ",", "$", "con", ")", ";", "/* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n $this->aPage->addM2Ps($this);\n */", "}", "return", "$", "this", "->", "aPage", ";", "}" ]
Get the associated ChildPage object @param ConnectionInterface $con Optional Connection object. @return ChildPage The associated ChildPage object. @throws PropelException
[ "Get", "the", "associated", "ChildPage", "object" ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/M2P.php#L1159-L1173
train
SkinnyBot/Plugin-Installer
src/Installer/PluginInstaller.php
PluginInstaller.determinePlugins
public static function determinePlugins($packages, $pluginsDir = 'plugins', $vendorDir = 'vendor') { $plugins = []; foreach ($packages as $package) { if ($package->getType() !== 'skinny-plugin') { continue; } $ns = static::primaryNamespace($package); $path = $vendorDir . DIRECTORY_SEPARATOR . $package->getPrettyName(); $plugins[$ns] = $path; } if (is_dir($pluginsDir)) { $dir = new \DirectoryIterator($pluginsDir); foreach ($dir as $info) { if (!$info->isDir() || $info->isDot()) { continue; } $name = $info->getFilename(); $plugins[$name] = $pluginsDir . DIRECTORY_SEPARATOR . $name; } } ksort($plugins); return $plugins; }
php
public static function determinePlugins($packages, $pluginsDir = 'plugins', $vendorDir = 'vendor') { $plugins = []; foreach ($packages as $package) { if ($package->getType() !== 'skinny-plugin') { continue; } $ns = static::primaryNamespace($package); $path = $vendorDir . DIRECTORY_SEPARATOR . $package->getPrettyName(); $plugins[$ns] = $path; } if (is_dir($pluginsDir)) { $dir = new \DirectoryIterator($pluginsDir); foreach ($dir as $info) { if (!$info->isDir() || $info->isDot()) { continue; } $name = $info->getFilename(); $plugins[$name] = $pluginsDir . DIRECTORY_SEPARATOR . $name; } } ksort($plugins); return $plugins; }
[ "public", "static", "function", "determinePlugins", "(", "$", "packages", ",", "$", "pluginsDir", "=", "'plugins'", ",", "$", "vendorDir", "=", "'vendor'", ")", "{", "$", "plugins", "=", "[", "]", ";", "foreach", "(", "$", "packages", "as", "$", "package", ")", "{", "if", "(", "$", "package", "->", "getType", "(", ")", "!==", "'skinny-plugin'", ")", "{", "continue", ";", "}", "$", "ns", "=", "static", "::", "primaryNamespace", "(", "$", "package", ")", ";", "$", "path", "=", "$", "vendorDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "package", "->", "getPrettyName", "(", ")", ";", "$", "plugins", "[", "$", "ns", "]", "=", "$", "path", ";", "}", "if", "(", "is_dir", "(", "$", "pluginsDir", ")", ")", "{", "$", "dir", "=", "new", "\\", "DirectoryIterator", "(", "$", "pluginsDir", ")", ";", "foreach", "(", "$", "dir", "as", "$", "info", ")", "{", "if", "(", "!", "$", "info", "->", "isDir", "(", ")", "||", "$", "info", "->", "isDot", "(", ")", ")", "{", "continue", ";", "}", "$", "name", "=", "$", "info", "->", "getFilename", "(", ")", ";", "$", "plugins", "[", "$", "name", "]", "=", "$", "pluginsDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "name", ";", "}", "}", "ksort", "(", "$", "plugins", ")", ";", "return", "$", "plugins", ";", "}" ]
Find all plugins available. Add all composer packages of type skinny-plugin, and all plugins located in the plugins directory to a plugin-name indexed array of paths. @param array $packages An array of \Composer\Package\PackageInterface objects. @param string $pluginsDir The path to the plugins dir. @param string $vendorDir The path to the vendor dir. @return array plugin-name Indexed paths to plugins.
[ "Find", "all", "plugins", "available", "." ]
b88c073b2f0a6f687117840036f57d9529d1e877
https://github.com/SkinnyBot/Plugin-Installer/blob/b88c073b2f0a6f687117840036f57d9529d1e877/src/Installer/PluginInstaller.php#L54-L82
train
SkinnyBot/Plugin-Installer
src/Installer/PluginInstaller.php
PluginInstaller.writeConfigFile
public static function writeConfigFile($configFile, $plugins, $root = null) { $root = $root ?: dirname(dirname($configFile)); $data = []; foreach ($plugins as $name => $pluginPath) { // Normalize to *nix paths. $pluginPath = str_replace('\\', '/', $pluginPath); $pluginPath .= '/'; $pluginPath = str_replace( DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $pluginPath ); // Namespaced plugins should use / $name = str_replace('\\', '/', $name); $data[] = sprintf(" '%s' => '%s'", $name, $pluginPath); } $data = implode(",\n", $data); $contents = <<<'PHP' <?php $baseDir = dirname(dirname(__file__)); return [ 'plugins' => [ %s ] ]; PHP; $contents = sprintf($contents, $data); // Gross hacks to work around composer smashing `__FILE__` in this // PHP file when it runs the code through eval() $uppercase = function ($matches) { return strtoupper($matches[0]); }; $contents = preg_replace_callback('/__file__/', $uppercase, $contents); $root = str_replace( DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $root ); // Normalize to *nix paths. $root = str_replace('\\', '/', $root); $contents = str_replace('\'' . $root, '$baseDir . \'', $contents); file_put_contents($configFile, $contents); }
php
public static function writeConfigFile($configFile, $plugins, $root = null) { $root = $root ?: dirname(dirname($configFile)); $data = []; foreach ($plugins as $name => $pluginPath) { // Normalize to *nix paths. $pluginPath = str_replace('\\', '/', $pluginPath); $pluginPath .= '/'; $pluginPath = str_replace( DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $pluginPath ); // Namespaced plugins should use / $name = str_replace('\\', '/', $name); $data[] = sprintf(" '%s' => '%s'", $name, $pluginPath); } $data = implode(",\n", $data); $contents = <<<'PHP' <?php $baseDir = dirname(dirname(__file__)); return [ 'plugins' => [ %s ] ]; PHP; $contents = sprintf($contents, $data); // Gross hacks to work around composer smashing `__FILE__` in this // PHP file when it runs the code through eval() $uppercase = function ($matches) { return strtoupper($matches[0]); }; $contents = preg_replace_callback('/__file__/', $uppercase, $contents); $root = str_replace( DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $root ); // Normalize to *nix paths. $root = str_replace('\\', '/', $root); $contents = str_replace('\'' . $root, '$baseDir . \'', $contents); file_put_contents($configFile, $contents); }
[ "public", "static", "function", "writeConfigFile", "(", "$", "configFile", ",", "$", "plugins", ",", "$", "root", "=", "null", ")", "{", "$", "root", "=", "$", "root", "?", ":", "dirname", "(", "dirname", "(", "$", "configFile", ")", ")", ";", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "plugins", "as", "$", "name", "=>", "$", "pluginPath", ")", "{", "// Normalize to *nix paths.", "$", "pluginPath", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "pluginPath", ")", ";", "$", "pluginPath", ".=", "'/'", ";", "$", "pluginPath", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ".", "DIRECTORY_SEPARATOR", ",", "DIRECTORY_SEPARATOR", ",", "$", "pluginPath", ")", ";", "// Namespaced plugins should use /", "$", "name", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "name", ")", ";", "$", "data", "[", "]", "=", "sprintf", "(", "\" '%s' => '%s'\"", ",", "$", "name", ",", "$", "pluginPath", ")", ";", "}", "$", "data", "=", "implode", "(", "\",\\n\"", ",", "$", "data", ")", ";", "$", "contents", "=", " <<<'PHP'\n<?php\n$baseDir = dirname(dirname(__file__));\nreturn [\n 'plugins' => [\n%s\n ]\n];\nPHP", ";", "$", "contents", "=", "sprintf", "(", "$", "contents", ",", "$", "data", ")", ";", "// Gross hacks to work around composer smashing `__FILE__` in this", "// PHP file when it runs the code through eval()", "$", "uppercase", "=", "function", "(", "$", "matches", ")", "{", "return", "strtoupper", "(", "$", "matches", "[", "0", "]", ")", ";", "}", ";", "$", "contents", "=", "preg_replace_callback", "(", "'/__file__/'", ",", "$", "uppercase", ",", "$", "contents", ")", ";", "$", "root", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ".", "DIRECTORY_SEPARATOR", ",", "DIRECTORY_SEPARATOR", ",", "$", "root", ")", ";", "// Normalize to *nix paths.", "$", "root", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "root", ")", ";", "$", "contents", "=", "str_replace", "(", "'\\''", ".", "$", "root", ",", "'$baseDir . \\''", ",", "$", "contents", ")", ";", "file_put_contents", "(", "$", "configFile", ",", "$", "contents", ")", ";", "}" ]
Rewrite the config file with a complete list of plugins. @param string $configFile The path to the config file. @param array $plugins Of plugins. @param string|null $root The root directory. Defaults to a value generated from $configFile. @return void
[ "Rewrite", "the", "config", "file", "with", "a", "complete", "list", "of", "plugins", "." ]
b88c073b2f0a6f687117840036f57d9529d1e877
https://github.com/SkinnyBot/Plugin-Installer/blob/b88c073b2f0a6f687117840036f57d9529d1e877/src/Installer/PluginInstaller.php#L93-L146
train
SkinnyBot/Plugin-Installer
src/Installer/PluginInstaller.php
PluginInstaller.primaryNamespace
public static function primaryNamespace($package) { $primaryNs = null; $autoLoad = $package->getAutoload(); foreach ($autoLoad as $type => $pathMap) { if ($type !== 'psr-4') { continue; } $count = count($pathMap); if ($count === 1) { $primaryNs = key($pathMap); break; } $matches = preg_grep('#^(\./)?src/?$#', $pathMap); if ($matches) { $primaryNs = key($matches); break; } foreach (['', '.'] as $path) { $key = array_search($path, $pathMap, true); if ($key !== false) { $primaryNs = $key; } } break; } if (!$primaryNs) { throw new RuntimeException( sprintf( "Unable to get primary namespace for package %s." . "\nEnsure you have added proper 'autoload' section to your plugin's config.", $package->getName() ) ); } return trim($primaryNs, '\\'); }
php
public static function primaryNamespace($package) { $primaryNs = null; $autoLoad = $package->getAutoload(); foreach ($autoLoad as $type => $pathMap) { if ($type !== 'psr-4') { continue; } $count = count($pathMap); if ($count === 1) { $primaryNs = key($pathMap); break; } $matches = preg_grep('#^(\./)?src/?$#', $pathMap); if ($matches) { $primaryNs = key($matches); break; } foreach (['', '.'] as $path) { $key = array_search($path, $pathMap, true); if ($key !== false) { $primaryNs = $key; } } break; } if (!$primaryNs) { throw new RuntimeException( sprintf( "Unable to get primary namespace for package %s." . "\nEnsure you have added proper 'autoload' section to your plugin's config.", $package->getName() ) ); } return trim($primaryNs, '\\'); }
[ "public", "static", "function", "primaryNamespace", "(", "$", "package", ")", "{", "$", "primaryNs", "=", "null", ";", "$", "autoLoad", "=", "$", "package", "->", "getAutoload", "(", ")", ";", "foreach", "(", "$", "autoLoad", "as", "$", "type", "=>", "$", "pathMap", ")", "{", "if", "(", "$", "type", "!==", "'psr-4'", ")", "{", "continue", ";", "}", "$", "count", "=", "count", "(", "$", "pathMap", ")", ";", "if", "(", "$", "count", "===", "1", ")", "{", "$", "primaryNs", "=", "key", "(", "$", "pathMap", ")", ";", "break", ";", "}", "$", "matches", "=", "preg_grep", "(", "'#^(\\./)?src/?$#'", ",", "$", "pathMap", ")", ";", "if", "(", "$", "matches", ")", "{", "$", "primaryNs", "=", "key", "(", "$", "matches", ")", ";", "break", ";", "}", "foreach", "(", "[", "''", ",", "'.'", "]", "as", "$", "path", ")", "{", "$", "key", "=", "array_search", "(", "$", "path", ",", "$", "pathMap", ",", "true", ")", ";", "if", "(", "$", "key", "!==", "false", ")", "{", "$", "primaryNs", "=", "$", "key", ";", "}", "}", "break", ";", "}", "if", "(", "!", "$", "primaryNs", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "\"Unable to get primary namespace for package %s.\"", ".", "\"\\nEnsure you have added proper 'autoload' section to your plugin's config.\"", ",", "$", "package", "->", "getName", "(", ")", ")", ")", ";", "}", "return", "trim", "(", "$", "primaryNs", ",", "'\\\\'", ")", ";", "}" ]
Get the primary namespace for a plugin package. @param \Composer\Package\PackageInterface $package composer object. @return string The package's primary namespace. @throws \RuntimeException When the package's primary namespace cannot be determined.
[ "Get", "the", "primary", "namespace", "for", "a", "plugin", "package", "." ]
b88c073b2f0a6f687117840036f57d9529d1e877
https://github.com/SkinnyBot/Plugin-Installer/blob/b88c073b2f0a6f687117840036f57d9529d1e877/src/Installer/PluginInstaller.php#L169-L209
train
SkinnyBot/Plugin-Installer
src/Installer/PluginInstaller.php
PluginInstaller.install
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { parent::install($repo, $package); $path = $this->getInstallPath($package); $ns = static::primaryNamespace($package); $this->updateConfig($ns, $path); }
php
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { parent::install($repo, $package); $path = $this->getInstallPath($package); $ns = static::primaryNamespace($package); $this->updateConfig($ns, $path); }
[ "public", "function", "install", "(", "InstalledRepositoryInterface", "$", "repo", ",", "PackageInterface", "$", "package", ")", "{", "parent", "::", "install", "(", "$", "repo", ",", "$", "package", ")", ";", "$", "path", "=", "$", "this", "->", "getInstallPath", "(", "$", "package", ")", ";", "$", "ns", "=", "static", "::", "primaryNamespace", "(", "$", "package", ")", ";", "$", "this", "->", "updateConfig", "(", "$", "ns", ",", "$", "path", ")", ";", "}" ]
Installs specific plugin. After the plugin is installed, app's `skinny-plugins.php` config file is updated with plugin namespace to path mapping. @param \Composer\Repository\InstalledRepositoryInterface $repo Repository in which to check. @param \Composer\Package\PackageInterface $package Package instance. @deprecated superceeded by the post-autoload-dump hook
[ "Installs", "specific", "plugin", "." ]
b88c073b2f0a6f687117840036f57d9529d1e877
https://github.com/SkinnyBot/Plugin-Installer/blob/b88c073b2f0a6f687117840036f57d9529d1e877/src/Installer/PluginInstaller.php#L234-L240
train
SkinnyBot/Plugin-Installer
src/Installer/PluginInstaller.php
PluginInstaller.update
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { parent::update($repo, $initial, $target); $ns = static::primaryNamespace($initial); $this->updateConfig($ns, null); $path = $this->getInstallPath($target); $ns = static::primaryNamespace($target); $this->updateConfig($ns, $path); }
php
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { parent::update($repo, $initial, $target); $ns = static::primaryNamespace($initial); $this->updateConfig($ns, null); $path = $this->getInstallPath($target); $ns = static::primaryNamespace($target); $this->updateConfig($ns, $path); }
[ "public", "function", "update", "(", "InstalledRepositoryInterface", "$", "repo", ",", "PackageInterface", "$", "initial", ",", "PackageInterface", "$", "target", ")", "{", "parent", "::", "update", "(", "$", "repo", ",", "$", "initial", ",", "$", "target", ")", ";", "$", "ns", "=", "static", "::", "primaryNamespace", "(", "$", "initial", ")", ";", "$", "this", "->", "updateConfig", "(", "$", "ns", ",", "null", ")", ";", "$", "path", "=", "$", "this", "->", "getInstallPath", "(", "$", "target", ")", ";", "$", "ns", "=", "static", "::", "primaryNamespace", "(", "$", "target", ")", ";", "$", "this", "->", "updateConfig", "(", "$", "ns", ",", "$", "path", ")", ";", "}" ]
Updates specific plugin. After the plugin is installed, app's `skinny-plugins.php` config file is updated with plugin namespace to path mapping. @param \Composer\Repository\InstalledRepositoryInterface $repo Repository in which to check. @param \Composer\Package\PackageInterface $initial Already installed package version. @param \Composer\Package\PackageInterface $target Updated version. @deprecated superceeded by the post-autoload-dump hook @throws \InvalidArgumentException If $initial package is not installed.
[ "Updates", "specific", "plugin", "." ]
b88c073b2f0a6f687117840036f57d9529d1e877
https://github.com/SkinnyBot/Plugin-Installer/blob/b88c073b2f0a6f687117840036f57d9529d1e877/src/Installer/PluginInstaller.php#L256-L266
train
SkinnyBot/Plugin-Installer
src/Installer/PluginInstaller.php
PluginInstaller.updateConfig
public function updateConfig($name, $path) { $name = str_replace('\\', '/', $name); $configFile = static::configFile($this->vendorDir); $this->ensureConfigFile($configFile); $return = include $configFile; if (is_array($return) && empty($config)) { $config = $return; } if (!isset($config)) { $this->io->write( 'ERROR - `vendor/skinny-plugins.php` file is invalid. ' . 'Plugin path configuration not updated.' ); return; } if (!isset($config['plugins'])) { $config['plugins'] = []; } if ($path == null) { unset($config['plugins'][$name]); } else { $config['plugins'][$name] = $path; } $root = dirname($this->vendorDir); static::writeConfigFile($configFile, $config['plugins'], $root); }
php
public function updateConfig($name, $path) { $name = str_replace('\\', '/', $name); $configFile = static::configFile($this->vendorDir); $this->ensureConfigFile($configFile); $return = include $configFile; if (is_array($return) && empty($config)) { $config = $return; } if (!isset($config)) { $this->io->write( 'ERROR - `vendor/skinny-plugins.php` file is invalid. ' . 'Plugin path configuration not updated.' ); return; } if (!isset($config['plugins'])) { $config['plugins'] = []; } if ($path == null) { unset($config['plugins'][$name]); } else { $config['plugins'][$name] = $path; } $root = dirname($this->vendorDir); static::writeConfigFile($configFile, $config['plugins'], $root); }
[ "public", "function", "updateConfig", "(", "$", "name", ",", "$", "path", ")", "{", "$", "name", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "name", ")", ";", "$", "configFile", "=", "static", "::", "configFile", "(", "$", "this", "->", "vendorDir", ")", ";", "$", "this", "->", "ensureConfigFile", "(", "$", "configFile", ")", ";", "$", "return", "=", "include", "$", "configFile", ";", "if", "(", "is_array", "(", "$", "return", ")", "&&", "empty", "(", "$", "config", ")", ")", "{", "$", "config", "=", "$", "return", ";", "}", "if", "(", "!", "isset", "(", "$", "config", ")", ")", "{", "$", "this", "->", "io", "->", "write", "(", "'ERROR - `vendor/skinny-plugins.php` file is invalid. '", ".", "'Plugin path configuration not updated.'", ")", ";", "return", ";", "}", "if", "(", "!", "isset", "(", "$", "config", "[", "'plugins'", "]", ")", ")", "{", "$", "config", "[", "'plugins'", "]", "=", "[", "]", ";", "}", "if", "(", "$", "path", "==", "null", ")", "{", "unset", "(", "$", "config", "[", "'plugins'", "]", "[", "$", "name", "]", ")", ";", "}", "else", "{", "$", "config", "[", "'plugins'", "]", "[", "$", "name", "]", "=", "$", "path", ";", "}", "$", "root", "=", "dirname", "(", "$", "this", "->", "vendorDir", ")", ";", "static", "::", "writeConfigFile", "(", "$", "configFile", ",", "$", "config", "[", "'plugins'", "]", ",", "$", "root", ")", ";", "}" ]
Update the plugin path for a given package. @param string $name The plugin name being installed. @param string $path The path, the plugin is being installed into.
[ "Update", "the", "plugin", "path", "for", "a", "given", "package", "." ]
b88c073b2f0a6f687117840036f57d9529d1e877
https://github.com/SkinnyBot/Plugin-Installer/blob/b88c073b2f0a6f687117840036f57d9529d1e877/src/Installer/PluginInstaller.php#L290-L317
train
hschletz/NADA
src/Column/Mysql.php
Mysql._modify
protected function _modify() { $this->_table->alter( 'MODIFY ' . $this->_database->prepareIdentifier($this->_name) . ' ' . $this->getDefinition() ); }
php
protected function _modify() { $this->_table->alter( 'MODIFY ' . $this->_database->prepareIdentifier($this->_name) . ' ' . $this->getDefinition() ); }
[ "protected", "function", "_modify", "(", ")", "{", "$", "this", "->", "_table", "->", "alter", "(", "'MODIFY '", ".", "$", "this", "->", "_database", "->", "prepareIdentifier", "(", "$", "this", "->", "_name", ")", ".", "' '", ".", "$", "this", "->", "getDefinition", "(", ")", ")", ";", "}" ]
Modify column in the database according to current properties @return void
[ "Modify", "column", "in", "the", "database", "according", "to", "current", "properties" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Column/Mysql.php#L167-L175
train
vainproject/vain-user
src/User/Auth/Access/Traits/UserTrait.php
UserTrait.saveRoles
public function saveRoles($inputRoles) { if (!empty($inputRoles)) { $this->roles()->sync($inputRoles); } else { $this->roles()->detach(); } }
php
public function saveRoles($inputRoles) { if (!empty($inputRoles)) { $this->roles()->sync($inputRoles); } else { $this->roles()->detach(); } }
[ "public", "function", "saveRoles", "(", "$", "inputRoles", ")", "{", "if", "(", "!", "empty", "(", "$", "inputRoles", ")", ")", "{", "$", "this", "->", "roles", "(", ")", "->", "sync", "(", "$", "inputRoles", ")", ";", "}", "else", "{", "$", "this", "->", "roles", "(", ")", "->", "detach", "(", ")", ";", "}", "}" ]
Save the inputted roles. @param mixed $inputRoles @return void
[ "Save", "the", "inputted", "roles", "." ]
1c059faa61ebf289fcaea39a90b4523cfc9d6efc
https://github.com/vainproject/vain-user/blob/1c059faa61ebf289fcaea39a90b4523cfc9d6efc/src/User/Auth/Access/Traits/UserTrait.php#L63-L70
train
ekyna/Resource
Doctrine/ORM/Mapping/DiscriminatorMapper.php
DiscriminatorMapper.extractEntry
private function extractEntry($class) { if ($class != $this->baseClass && !is_subclass_of($class, $this->baseClass)) { return false; } if (!preg_match_all('~/?([a-zA-Z0-9]+)~', $class, $namespaces)) { throw new \Exception("Unexpected class {$class}."); } $prefix = $suffix = null; $parts = $namespaces[0]; foreach ($parts as $index => $namespace) { if ($namespace == 'Component') { $prefix = strtolower($parts[$index + 1]); break; } elseif (preg_match('~([a-zA-Z0-9]+)Bundle~', $namespace, $matches)) { $prefix = strtolower($matches[1]); break; } } $suffix = strtolower(end($parts)); if (empty($prefix) || empty($suffix)) { throw new \Exception( "Failed to extract discriminator value from class '{$class}'." ); } $value = $prefix . '_' . $suffix; if (in_array($value, $this->map)) { throw new \Exception("Found duplicate discriminator map entry '{$value}' in {$class}"); } $this->map[$class] = $value; return true; }
php
private function extractEntry($class) { if ($class != $this->baseClass && !is_subclass_of($class, $this->baseClass)) { return false; } if (!preg_match_all('~/?([a-zA-Z0-9]+)~', $class, $namespaces)) { throw new \Exception("Unexpected class {$class}."); } $prefix = $suffix = null; $parts = $namespaces[0]; foreach ($parts as $index => $namespace) { if ($namespace == 'Component') { $prefix = strtolower($parts[$index + 1]); break; } elseif (preg_match('~([a-zA-Z0-9]+)Bundle~', $namespace, $matches)) { $prefix = strtolower($matches[1]); break; } } $suffix = strtolower(end($parts)); if (empty($prefix) || empty($suffix)) { throw new \Exception( "Failed to extract discriminator value from class '{$class}'." ); } $value = $prefix . '_' . $suffix; if (in_array($value, $this->map)) { throw new \Exception("Found duplicate discriminator map entry '{$value}' in {$class}"); } $this->map[$class] = $value; return true; }
[ "private", "function", "extractEntry", "(", "$", "class", ")", "{", "if", "(", "$", "class", "!=", "$", "this", "->", "baseClass", "&&", "!", "is_subclass_of", "(", "$", "class", ",", "$", "this", "->", "baseClass", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "preg_match_all", "(", "'~/?([a-zA-Z0-9]+)~'", ",", "$", "class", ",", "$", "namespaces", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Unexpected class {$class}.\"", ")", ";", "}", "$", "prefix", "=", "$", "suffix", "=", "null", ";", "$", "parts", "=", "$", "namespaces", "[", "0", "]", ";", "foreach", "(", "$", "parts", "as", "$", "index", "=>", "$", "namespace", ")", "{", "if", "(", "$", "namespace", "==", "'Component'", ")", "{", "$", "prefix", "=", "strtolower", "(", "$", "parts", "[", "$", "index", "+", "1", "]", ")", ";", "break", ";", "}", "elseif", "(", "preg_match", "(", "'~([a-zA-Z0-9]+)Bundle~'", ",", "$", "namespace", ",", "$", "matches", ")", ")", "{", "$", "prefix", "=", "strtolower", "(", "$", "matches", "[", "1", "]", ")", ";", "break", ";", "}", "}", "$", "suffix", "=", "strtolower", "(", "end", "(", "$", "parts", ")", ")", ";", "if", "(", "empty", "(", "$", "prefix", ")", "||", "empty", "(", "$", "suffix", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Failed to extract discriminator value from class '{$class}'.\"", ")", ";", "}", "$", "value", "=", "$", "prefix", ".", "'_'", ".", "$", "suffix", ";", "if", "(", "in_array", "(", "$", "value", ",", "$", "this", "->", "map", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Found duplicate discriminator map entry '{$value}' in {$class}\"", ")", ";", "}", "$", "this", "->", "map", "[", "$", "class", "]", "=", "$", "value", ";", "return", "true", ";", "}" ]
Extracts the discriminator name from the given class. @param string $class @return string @return bool @throws \Exception
[ "Extracts", "the", "discriminator", "name", "from", "the", "given", "class", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Mapping/DiscriminatorMapper.php#L190-L230
train
MacGyer/yii2-data-uri-validator
src/DataUriValidator.php
DataUriValidator.validateAttribute
public function validateAttribute($model, $attribute) { $value = $model->$attribute; $result = $this->validateValue($value); if (!empty($result)) { $this->addError($model, $attribute, $this->renderMessage($model, $attribute)); } }
php
public function validateAttribute($model, $attribute) { $value = $model->$attribute; $result = $this->validateValue($value); if (!empty($result)) { $this->addError($model, $attribute, $this->renderMessage($model, $attribute)); } }
[ "public", "function", "validateAttribute", "(", "$", "model", ",", "$", "attribute", ")", "{", "$", "value", "=", "$", "model", "->", "$", "attribute", ";", "$", "result", "=", "$", "this", "->", "validateValue", "(", "$", "value", ")", ";", "if", "(", "!", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "addError", "(", "$", "model", ",", "$", "attribute", ",", "$", "this", "->", "renderMessage", "(", "$", "model", ",", "$", "attribute", ")", ")", ";", "}", "}" ]
Validates a single attribute. @param \yii\base\Model $model the data model to be validated @param string $attribute the name of the attribute to be validated. @uses [[renderMessage()]] @uses [[validateValue()]]
[ "Validates", "a", "single", "attribute", "." ]
d8e9c750cdff1bf7d1bd10bdffac8405e116e47a
https://github.com/MacGyer/yii2-data-uri-validator/blob/d8e9c750cdff1bf7d1bd10bdffac8405e116e47a/src/DataUriValidator.php#L44-L52
train
MacGyer/yii2-data-uri-validator
src/DataUriValidator.php
DataUriValidator.renderMessage
private function renderMessage($model, $attribute) { $attributeLabel = $model->getAttributeLabel($attribute); $message = strtr($this->message, ['{attribute}' => $attributeLabel]); return $message; }
php
private function renderMessage($model, $attribute) { $attributeLabel = $model->getAttributeLabel($attribute); $message = strtr($this->message, ['{attribute}' => $attributeLabel]); return $message; }
[ "private", "function", "renderMessage", "(", "$", "model", ",", "$", "attribute", ")", "{", "$", "attributeLabel", "=", "$", "model", "->", "getAttributeLabel", "(", "$", "attribute", ")", ";", "$", "message", "=", "strtr", "(", "$", "this", "->", "message", ",", "[", "'{attribute}'", "=>", "$", "attributeLabel", "]", ")", ";", "return", "$", "message", ";", "}" ]
Renders the attribute's error message. @param [\yii\base\Model](http://www.yiiframework.com/doc-2.0/yii-base-model.html) $model the data model currently being validated. @param string $attribute the name of the attribute to be validated. @return string the error message.
[ "Renders", "the", "attribute", "s", "error", "message", "." ]
d8e9c750cdff1bf7d1bd10bdffac8405e116e47a
https://github.com/MacGyer/yii2-data-uri-validator/blob/d8e9c750cdff1bf7d1bd10bdffac8405e116e47a/src/DataUriValidator.php#L92-L98
train
MetaModels/phpunit-contao-database
src/Contao/Database/QueryCollection.php
QueryCollection.findQuery
public function findQuery($strQuery) { foreach ($this->queries as $query) { if ($query->matches($strQuery)) { return $query; } } return null; }
php
public function findQuery($strQuery) { foreach ($this->queries as $query) { if ($query->matches($strQuery)) { return $query; } } return null; }
[ "public", "function", "findQuery", "(", "$", "strQuery", ")", "{", "foreach", "(", "$", "this", "->", "queries", "as", "$", "query", ")", "{", "if", "(", "$", "query", "->", "matches", "(", "$", "strQuery", ")", ")", "{", "return", "$", "query", ";", "}", "}", "return", "null", ";", "}" ]
Try to find the query matching the given string. @param string $strQuery The query string. @return FakeQuery|null
[ "Try", "to", "find", "the", "query", "matching", "the", "given", "string", "." ]
aeb2ee10dac532fa73e2deb6457b6a167a1c01c7
https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/QueryCollection.php#L57-L66
train
Kris-Kuiper/sFire-Framework
src/Template/TemplateData.php
TemplateData.register
public static function register($action, $closure) { if(false === is_string($action)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($action)), E_USER_ERROR); } if(false === is_object($closure)) { return trigger_error(sprintf('Argument 2 passed to %s() must be callable object, "%s" given', __METHOD__, gettype($closure)), E_USER_ERROR); } static :: setTemplateFunctions($action, $closure); }
php
public static function register($action, $closure) { if(false === is_string($action)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($action)), E_USER_ERROR); } if(false === is_object($closure)) { return trigger_error(sprintf('Argument 2 passed to %s() must be callable object, "%s" given', __METHOD__, gettype($closure)), E_USER_ERROR); } static :: setTemplateFunctions($action, $closure); }
[ "public", "static", "function", "register", "(", "$", "action", ",", "$", "closure", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "action", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "action", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "is_object", "(", "$", "closure", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 2 passed to %s() must be callable object, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "closure", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "static", "::", "setTemplateFunctions", "(", "$", "action", ",", "$", "closure", ")", ";", "}" ]
Register a new template function @param string $action @param object $closure @return sFire\MVC\Controller
[ "Register", "a", "new", "template", "function" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Template/TemplateData.php#L54-L65
train
railken/lem
src/Concerns/HasExceptions.php
HasExceptions.getException
public function getException($code) { if (!isset($this->exceptions[$code])) { throw new Exceptions\ExceptionNotDefinedException($this, $code); } return $this->exceptions[$code]; }
php
public function getException($code) { if (!isset($this->exceptions[$code])) { throw new Exceptions\ExceptionNotDefinedException($this, $code); } return $this->exceptions[$code]; }
[ "public", "function", "getException", "(", "$", "code", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "exceptions", "[", "$", "code", "]", ")", ")", "{", "throw", "new", "Exceptions", "\\", "ExceptionNotDefinedException", "(", "$", "this", ",", "$", "code", ")", ";", "}", "return", "$", "this", "->", "exceptions", "[", "$", "code", "]", ";", "}" ]
Retrieve an exception class given code. @param string $code @return string
[ "Retrieve", "an", "exception", "class", "given", "code", "." ]
cff1efcd090a9504b2faf5594121885786dea67a
https://github.com/railken/lem/blob/cff1efcd090a9504b2faf5594121885786dea67a/src/Concerns/HasExceptions.php#L23-L30
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.setColors
public function setColors($textColor = null, $fillColor = null) { // set the desired text and fill $this->desiredState->setTextColor($textColor); $this->desiredState->setFillColor($fillColor); // chaining return $this; }
php
public function setColors($textColor = null, $fillColor = null) { // set the desired text and fill $this->desiredState->setTextColor($textColor); $this->desiredState->setFillColor($fillColor); // chaining return $this; }
[ "public", "function", "setColors", "(", "$", "textColor", "=", "null", ",", "$", "fillColor", "=", "null", ")", "{", "// set the desired text and fill", "$", "this", "->", "desiredState", "->", "setTextColor", "(", "$", "textColor", ")", ";", "$", "this", "->", "desiredState", "->", "setFillColor", "(", "$", "fillColor", ")", ";", "// chaining", "return", "$", "this", ";", "}" ]
Set both the fill and text colors @param $textColor int|string|null $color - can be either a Color constant Color::Blue or a string with the same spelling "blue", "Red", "LIGHT CYAN", etc @param $fillColor int|string|null $color - can be either a Color constant Color::Blue or a string with the same spelling "blue", "Red", "LIGHT CYAN", etc @return $this
[ "Set", "both", "the", "fill", "and", "text", "colors" ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L272-L280
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.clear
public function clear($rightAway = false) { // clear the old settings $this->desiredState->clear(); // if it desired to send out the clear sequence right away if ($rightAway) { // send it out $this->output(EscapeSequenceGenerator::generateClearSequence()); // reset the two states to cleared $this->currentState = new TerminalState(); $this->desiredState = new TerminalState(); } // chaining return $this; }
php
public function clear($rightAway = false) { // clear the old settings $this->desiredState->clear(); // if it desired to send out the clear sequence right away if ($rightAway) { // send it out $this->output(EscapeSequenceGenerator::generateClearSequence()); // reset the two states to cleared $this->currentState = new TerminalState(); $this->desiredState = new TerminalState(); } // chaining return $this; }
[ "public", "function", "clear", "(", "$", "rightAway", "=", "false", ")", "{", "// clear the old settings", "$", "this", "->", "desiredState", "->", "clear", "(", ")", ";", "// if it desired to send out the clear sequence right away", "if", "(", "$", "rightAway", ")", "{", "// send it out", "$", "this", "->", "output", "(", "EscapeSequenceGenerator", "::", "generateClearSequence", "(", ")", ")", ";", "// reset the two states to cleared", "$", "this", "->", "currentState", "=", "new", "TerminalState", "(", ")", ";", "$", "this", "->", "desiredState", "=", "new", "TerminalState", "(", ")", ";", "}", "// chaining", "return", "$", "this", ";", "}" ]
Clear away all formatting - bold, underscore, text and fill color @param boolean $rightAway - whether to send out the escape sequence right away or allow the display to do it later @return $this
[ "Clear", "away", "all", "formatting", "-", "bold", "underscore", "text", "and", "fill", "color" ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L294-L313
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.outputEscapeSequence
public function outputEscapeSequence() { // send out any escaping to implement anything sitting in the desired state $this->output($this->generator->generate($this->currentState, $this->desiredState)); // copy the current state to the now achieved desired state $this->currentState = clone $this->desiredState; }
php
public function outputEscapeSequence() { // send out any escaping to implement anything sitting in the desired state $this->output($this->generator->generate($this->currentState, $this->desiredState)); // copy the current state to the now achieved desired state $this->currentState = clone $this->desiredState; }
[ "public", "function", "outputEscapeSequence", "(", ")", "{", "// send out any escaping to implement anything sitting in the desired state", "$", "this", "->", "output", "(", "$", "this", "->", "generator", "->", "generate", "(", "$", "this", "->", "currentState", ",", "$", "this", "->", "desiredState", ")", ")", ";", "// copy the current state to the now achieved desired state", "$", "this", "->", "currentState", "=", "clone", "$", "this", "->", "desiredState", ";", "}" ]
Send out the escape sequence which will accomplish the desired state
[ "Send", "out", "the", "escape", "sequence", "which", "will", "accomplish", "the", "desired", "state" ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L318-L325
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.newLine
public function newLine($count = 1) { // send out any escaping to implement anything sitting in the desired state $this->outputEscapeSequence(); // if the $count is greater than one if (is_int($count) && $count > 1) { // send out the \n $count times for ($i=0; $i<$count; ++$i) { // echo the newline character $this->output("\n"); } } else { // the parameter might be one or something crazy, just output one // echo the new line character $this->output("\n"); } // fire the handler that indicates the cursor is sent to the left margin $this->carriageReturn(); // chaining return $this; }
php
public function newLine($count = 1) { // send out any escaping to implement anything sitting in the desired state $this->outputEscapeSequence(); // if the $count is greater than one if (is_int($count) && $count > 1) { // send out the \n $count times for ($i=0; $i<$count; ++$i) { // echo the newline character $this->output("\n"); } } else { // the parameter might be one or something crazy, just output one // echo the new line character $this->output("\n"); } // fire the handler that indicates the cursor is sent to the left margin $this->carriageReturn(); // chaining return $this; }
[ "public", "function", "newLine", "(", "$", "count", "=", "1", ")", "{", "// send out any escaping to implement anything sitting in the desired state", "$", "this", "->", "outputEscapeSequence", "(", ")", ";", "// if the $count is greater than one", "if", "(", "is_int", "(", "$", "count", ")", "&&", "$", "count", ">", "1", ")", "{", "// send out the \\n $count times", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "++", "$", "i", ")", "{", "// echo the newline character", "$", "this", "->", "output", "(", "\"\\n\"", ")", ";", "}", "}", "else", "{", "// the parameter might be one or something crazy, just output one", "// echo the new line character", "$", "this", "->", "output", "(", "\"\\n\"", ")", ";", "}", "// fire the handler that indicates the cursor is sent to the left margin", "$", "this", "->", "carriageReturn", "(", ")", ";", "// chaining", "return", "$", "this", ";", "}" ]
Move the cursor to the next line This is not an ANSI sequence, but rather the ASCII code 12 or \n @param int $count - the number of newlines to output @return $this
[ "Move", "the", "cursor", "to", "the", "next", "line", "This", "is", "not", "an", "ANSI", "sequence", "but", "rather", "the", "ASCII", "code", "12", "or", "\\", "n" ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L354-L380
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.clearScreen
public function clearScreen() { // send out any escaping to implement anything sitting in the desired state $this->outputEscapeSequence(); // escape sequences to clear screen and move it up $this->output(EscapeSequenceGenerator::generateClearScreenSequence()); // fire the handler that indicates the cursor is sent to the left margin $this->carriageReturn(); // chaining return $this; }
php
public function clearScreen() { // send out any escaping to implement anything sitting in the desired state $this->outputEscapeSequence(); // escape sequences to clear screen and move it up $this->output(EscapeSequenceGenerator::generateClearScreenSequence()); // fire the handler that indicates the cursor is sent to the left margin $this->carriageReturn(); // chaining return $this; }
[ "public", "function", "clearScreen", "(", ")", "{", "// send out any escaping to implement anything sitting in the desired state", "$", "this", "->", "outputEscapeSequence", "(", ")", ";", "// escape sequences to clear screen and move it up", "$", "this", "->", "output", "(", "EscapeSequenceGenerator", "::", "generateClearScreenSequence", "(", ")", ")", ";", "// fire the handler that indicates the cursor is sent to the left margin", "$", "this", "->", "carriageReturn", "(", ")", ";", "// chaining", "return", "$", "this", ";", "}" ]
Clear the screen and move cursor to the top. @return $this
[ "Clear", "the", "screen", "and", "move", "cursor", "to", "the", "top", "." ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L388-L401
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.prompt
public function prompt($text) { // send out any escaping to implement anything sitting in the desired state $this->outputEscapeSequence(); // save off the prompt string $prompt = $text . $this->promptCaret . " "; // prompt and return the answer return $this->readUserInput($prompt); }
php
public function prompt($text) { // send out any escaping to implement anything sitting in the desired state $this->outputEscapeSequence(); // save off the prompt string $prompt = $text . $this->promptCaret . " "; // prompt and return the answer return $this->readUserInput($prompt); }
[ "public", "function", "prompt", "(", "$", "text", ")", "{", "// send out any escaping to implement anything sitting in the desired state", "$", "this", "->", "outputEscapeSequence", "(", ")", ";", "// save off the prompt string", "$", "prompt", "=", "$", "text", ".", "$", "this", "->", "promptCaret", ".", "\" \"", ";", "// prompt and return the answer", "return", "$", "this", "->", "readUserInput", "(", "$", "prompt", ")", ";", "}" ]
Prompt for a value. @param $text - the prompt string @return string
[ "Prompt", "for", "a", "value", "." ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L447-L458
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.getScreenHeight
public static function getScreenHeight() { // set a simple error handler that indicates the exec function was disabled set_error_handler("self::errorHandler", E_WARNING); // initialize the array for the output of the execute $output = []; // execute the bash command tput cols to determine the screen width $height = exec("tput lines 2>&1", $output); // if the height is zero, then something went wrong if ($height == 0 || $height == "" || is_null($height)) { // use the error handler to raise the exception self::errorHandler(null,null ); } // put back the error handler restore_error_handler(); // return the width return intval($height); }
php
public static function getScreenHeight() { // set a simple error handler that indicates the exec function was disabled set_error_handler("self::errorHandler", E_WARNING); // initialize the array for the output of the execute $output = []; // execute the bash command tput cols to determine the screen width $height = exec("tput lines 2>&1", $output); // if the height is zero, then something went wrong if ($height == 0 || $height == "" || is_null($height)) { // use the error handler to raise the exception self::errorHandler(null,null ); } // put back the error handler restore_error_handler(); // return the width return intval($height); }
[ "public", "static", "function", "getScreenHeight", "(", ")", "{", "// set a simple error handler that indicates the exec function was disabled", "set_error_handler", "(", "\"self::errorHandler\"", ",", "E_WARNING", ")", ";", "// initialize the array for the output of the execute", "$", "output", "=", "[", "]", ";", "// execute the bash command tput cols to determine the screen width", "$", "height", "=", "exec", "(", "\"tput lines 2>&1\"", ",", "$", "output", ")", ";", "// if the height is zero, then something went wrong", "if", "(", "$", "height", "==", "0", "||", "$", "height", "==", "\"\"", "||", "is_null", "(", "$", "height", ")", ")", "{", "// use the error handler to raise the exception", "self", "::", "errorHandler", "(", "null", ",", "null", ")", ";", "}", "// put back the error handler", "restore_error_handler", "(", ")", ";", "// return the width", "return", "intval", "(", "$", "height", ")", ";", "}" ]
Get the current screen height @uses errorHandler @return int - the number of lines it holds @throws RuntimeException
[ "Get", "the", "current", "screen", "height" ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L520-L548
train
1HappyPlace/ansi-terminal
src/ANSI/Terminal.php
Terminal.getScreenWidth
public static function getScreenWidth() { // set a simple error handler that indicates the exec function was disabled set_error_handler("self::errorHandler", E_WARNING); // initialize the array for the output of the execute $output = []; // execute the bash command tput cols to determine the screen width $width = exec("tput cols 2>&1", $output); // if the height is zero, then something went wrong if (count($output) == 0 ||$width == 0 || $width == "" || is_null($width)) { // use the error handler to raise the exception self::errorHandler(null,null); } // put back the error handler restore_error_handler(); // return the height return intval($width); }
php
public static function getScreenWidth() { // set a simple error handler that indicates the exec function was disabled set_error_handler("self::errorHandler", E_WARNING); // initialize the array for the output of the execute $output = []; // execute the bash command tput cols to determine the screen width $width = exec("tput cols 2>&1", $output); // if the height is zero, then something went wrong if (count($output) == 0 ||$width == 0 || $width == "" || is_null($width)) { // use the error handler to raise the exception self::errorHandler(null,null); } // put back the error handler restore_error_handler(); // return the height return intval($width); }
[ "public", "static", "function", "getScreenWidth", "(", ")", "{", "// set a simple error handler that indicates the exec function was disabled", "set_error_handler", "(", "\"self::errorHandler\"", ",", "E_WARNING", ")", ";", "// initialize the array for the output of the execute", "$", "output", "=", "[", "]", ";", "// execute the bash command tput cols to determine the screen width", "$", "width", "=", "exec", "(", "\"tput cols 2>&1\"", ",", "$", "output", ")", ";", "// if the height is zero, then something went wrong", "if", "(", "count", "(", "$", "output", ")", "==", "0", "||", "$", "width", "==", "0", "||", "$", "width", "==", "\"\"", "||", "is_null", "(", "$", "width", ")", ")", "{", "// use the error handler to raise the exception", "self", "::", "errorHandler", "(", "null", ",", "null", ")", ";", "}", "// put back the error handler", "restore_error_handler", "(", ")", ";", "// return the height", "return", "intval", "(", "$", "width", ")", ";", "}" ]
Get the current screen width @uses errorHandler @return int - the number of characters that will fit across the screen @throws RuntimeException
[ "Get", "the", "current", "screen", "width" ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Terminal.php#L557-L584
train
timostamm/web-resource
src/ResourceResponse.php
ResourceResponse.sendContent
public function sendContent() { if (! $this->isSuccessful()) { return parent::sendContent(); } if (0 === $this->maxlen) { return $this; } $out = fopen('php://output', 'wb'); $in = $this->resource->getStream(); stream_copy_to_stream($in, $out, $this->maxlen, $this->offset); fclose($out); fclose($in); return $this; }
php
public function sendContent() { if (! $this->isSuccessful()) { return parent::sendContent(); } if (0 === $this->maxlen) { return $this; } $out = fopen('php://output', 'wb'); $in = $this->resource->getStream(); stream_copy_to_stream($in, $out, $this->maxlen, $this->offset); fclose($out); fclose($in); return $this; }
[ "public", "function", "sendContent", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isSuccessful", "(", ")", ")", "{", "return", "parent", "::", "sendContent", "(", ")", ";", "}", "if", "(", "0", "===", "$", "this", "->", "maxlen", ")", "{", "return", "$", "this", ";", "}", "$", "out", "=", "fopen", "(", "'php://output'", ",", "'wb'", ")", ";", "$", "in", "=", "$", "this", "->", "resource", "->", "getStream", "(", ")", ";", "stream_copy_to_stream", "(", "$", "in", ",", "$", "out", ",", "$", "this", "->", "maxlen", ",", "$", "this", "->", "offset", ")", ";", "fclose", "(", "$", "out", ")", ";", "fclose", "(", "$", "in", ")", ";", "return", "$", "this", ";", "}" ]
Sends the resource. {@inheritdoc}
[ "Sends", "the", "resource", "." ]
4c60e679093990585ee2f0a00029ab0a218573b8
https://github.com/timostamm/web-resource/blob/4c60e679093990585ee2f0a00029ab0a218573b8/src/ResourceResponse.php#L195-L214
train
ScaraMVC/Framework
src/Scara/Html/FormBuilder.php
FormBuilder.open
public function open($options = []) { $options['method'] = self::getMethod($options); $options['action'] = self::getAction($options); $options['accept-charset'] = 'UTF-8'; if (isset($options['files']) && $options['files']) { $options['enctype'] = 'multipart/form-data'; } $options = $this->attributes($options); return '<form'.$options.'>'; }
php
public function open($options = []) { $options['method'] = self::getMethod($options); $options['action'] = self::getAction($options); $options['accept-charset'] = 'UTF-8'; if (isset($options['files']) && $options['files']) { $options['enctype'] = 'multipart/form-data'; } $options = $this->attributes($options); return '<form'.$options.'>'; }
[ "public", "function", "open", "(", "$", "options", "=", "[", "]", ")", "{", "$", "options", "[", "'method'", "]", "=", "self", "::", "getMethod", "(", "$", "options", ")", ";", "$", "options", "[", "'action'", "]", "=", "self", "::", "getAction", "(", "$", "options", ")", ";", "$", "options", "[", "'accept-charset'", "]", "=", "'UTF-8'", ";", "if", "(", "isset", "(", "$", "options", "[", "'files'", "]", ")", "&&", "$", "options", "[", "'files'", "]", ")", "{", "$", "options", "[", "'enctype'", "]", "=", "'multipart/form-data'", ";", "}", "$", "options", "=", "$", "this", "->", "attributes", "(", "$", "options", ")", ";", "return", "'<form'", ".", "$", "options", ".", "'>'", ";", "}" ]
Open a new form object. @param array $options - Form options @return string
[ "Open", "a", "new", "form", "object", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Html/FormBuilder.php#L34-L49
train
ScaraMVC/Framework
src/Scara/Html/FormBuilder.php
FormBuilder.input
public function input($type, $name, $value = '', $options = []) { if (!isset($options['id'])) { $options['id'] = $name; } if (!empty($value)) { $options['value'] = $value; } $options['type'] = $type; $options['name'] = $name; return '<input'.$this->attributes($options).'>'; }
php
public function input($type, $name, $value = '', $options = []) { if (!isset($options['id'])) { $options['id'] = $name; } if (!empty($value)) { $options['value'] = $value; } $options['type'] = $type; $options['name'] = $name; return '<input'.$this->attributes($options).'>'; }
[ "public", "function", "input", "(", "$", "type", ",", "$", "name", ",", "$", "value", "=", "''", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'id'", "]", ")", ")", "{", "$", "options", "[", "'id'", "]", "=", "$", "name", ";", "}", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "options", "[", "'value'", "]", "=", "$", "value", ";", "}", "$", "options", "[", "'type'", "]", "=", "$", "type", ";", "$", "options", "[", "'name'", "]", "=", "$", "name", ";", "return", "'<input'", ".", "$", "this", "->", "attributes", "(", "$", "options", ")", ".", "'>'", ";", "}" ]
Creates a form input element. @param string $type - The type of form input @param string $name - The name of the input @param string $value - The value of the input @param array $options - The input's options @return string
[ "Creates", "a", "form", "input", "element", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Html/FormBuilder.php#L75-L89
train
ScaraMVC/Framework
src/Scara/Html/FormBuilder.php
FormBuilder.textarea
public function textarea($name, $value = '', $options = []) { if (!isset($options['id'])) { $options['id'] = $name; } $options['name'] = $name; return '<textarea'.$this->attributes($options).'>'.$value.'</textarea>'; }
php
public function textarea($name, $value = '', $options = []) { if (!isset($options['id'])) { $options['id'] = $name; } $options['name'] = $name; return '<textarea'.$this->attributes($options).'>'.$value.'</textarea>'; }
[ "public", "function", "textarea", "(", "$", "name", ",", "$", "value", "=", "''", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'id'", "]", ")", ")", "{", "$", "options", "[", "'id'", "]", "=", "$", "name", ";", "}", "$", "options", "[", "'name'", "]", "=", "$", "name", ";", "return", "'<textarea'", ".", "$", "this", "->", "attributes", "(", "$", "options", ")", ".", "'>'", ".", "$", "value", ".", "'</textarea>'", ";", "}" ]
Creates a textarea form input box. @param string $name - The textarea's name @param string $value - The textarea's value @param array $options - The textarea's options @return string
[ "Creates", "a", "textarea", "form", "input", "box", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Html/FormBuilder.php#L156-L165
train
ScaraMVC/Framework
src/Scara/Html/FormBuilder.php
FormBuilder.getAction
private function getAction($options) { if (isset($options['action'])) { $action = $this->_generator->to($options['action']); } else { $action = $_SERVER['REQUEST_URI']; } return $action; }
php
private function getAction($options) { if (isset($options['action'])) { $action = $this->_generator->to($options['action']); } else { $action = $_SERVER['REQUEST_URI']; } return $action; }
[ "private", "function", "getAction", "(", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'action'", "]", ")", ")", "{", "$", "action", "=", "$", "this", "->", "_generator", "->", "to", "(", "$", "options", "[", "'action'", "]", ")", ";", "}", "else", "{", "$", "action", "=", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ";", "}", "return", "$", "action", ";", "}" ]
Gets the form action. @param array $options - The form's options @return string
[ "Gets", "the", "form", "action", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Html/FormBuilder.php#L228-L237
train
ScaraMVC/Framework
src/Scara/Html/FormBuilder.php
FormBuilder.getId
private function getId($options) { $id = ''; if (!isset($options['id'])) { $id = $options['name']; } else { $id = $options['id']; } return $id; }
php
private function getId($options) { $id = ''; if (!isset($options['id'])) { $id = $options['name']; } else { $id = $options['id']; } return $id; }
[ "private", "function", "getId", "(", "$", "options", ")", "{", "$", "id", "=", "''", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'id'", "]", ")", ")", "{", "$", "id", "=", "$", "options", "[", "'name'", "]", ";", "}", "else", "{", "$", "id", "=", "$", "options", "[", "'id'", "]", ";", "}", "return", "$", "id", ";", "}" ]
Gets an input's id, or sets it if not supplied. @param array $options - The input's options @deprecated @return string
[ "Gets", "an", "input", "s", "id", "or", "sets", "it", "if", "not", "supplied", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Html/FormBuilder.php#L248-L258
train