repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
MatiasNAmendola/slimpower-slim | src/Libs/Net.php | Net.getBasicPath | public static function getBasicPath() {
$s = &$_SERVER;
$ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false;
$sp = strtolower($s['SERVER_PROTOCOL']);
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
$port = $s['SERVER_PORT'];
$port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port;
$host = isset($s['HTTP_X_FORWARDED_HOST']) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null);
$host = isset($host) ? $host : $s['SERVER_NAME'] . $port;
$uri = $protocol . '://' . $host;
return $uri;
} | php | public static function getBasicPath() {
$s = &$_SERVER;
$ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false;
$sp = strtolower($s['SERVER_PROTOCOL']);
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
$port = $s['SERVER_PORT'];
$port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port;
$host = isset($s['HTTP_X_FORWARDED_HOST']) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null);
$host = isset($host) ? $host : $s['SERVER_NAME'] . $port;
$uri = $protocol . '://' . $host;
return $uri;
} | [
"public",
"static",
"function",
"getBasicPath",
"(",
")",
"{",
"$",
"s",
"=",
"&",
"$",
"_SERVER",
";",
"$",
"ssl",
"=",
"(",
"!",
"empty",
"(",
"$",
"s",
"[",
"'HTTPS'",
"]",
")",
"&&",
"$",
"s",
"[",
"'HTTPS'",
"]",
"==",
"'on'",
")",
"?",
"true",
":",
"false",
";",
"$",
"sp",
"=",
"strtolower",
"(",
"$",
"s",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
";",
"$",
"protocol",
"=",
"substr",
"(",
"$",
"sp",
",",
"0",
",",
"strpos",
"(",
"$",
"sp",
",",
"'/'",
")",
")",
".",
"(",
"(",
"$",
"ssl",
")",
"?",
"'s'",
":",
"''",
")",
";",
"$",
"port",
"=",
"$",
"s",
"[",
"'SERVER_PORT'",
"]",
";",
"$",
"port",
"=",
"(",
"(",
"!",
"$",
"ssl",
"&&",
"$",
"port",
"==",
"'80'",
")",
"||",
"(",
"$",
"ssl",
"&&",
"$",
"port",
"==",
"'443'",
")",
")",
"?",
"''",
":",
"':'",
".",
"$",
"port",
";",
"$",
"host",
"=",
"isset",
"(",
"$",
"s",
"[",
"'HTTP_X_FORWARDED_HOST'",
"]",
")",
"?",
"$",
"s",
"[",
"'HTTP_X_FORWARDED_HOST'",
"]",
":",
"(",
"isset",
"(",
"$",
"s",
"[",
"'HTTP_HOST'",
"]",
")",
"?",
"$",
"s",
"[",
"'HTTP_HOST'",
"]",
":",
"null",
")",
";",
"$",
"host",
"=",
"isset",
"(",
"$",
"host",
")",
"?",
"$",
"host",
":",
"$",
"s",
"[",
"'SERVER_NAME'",
"]",
".",
"$",
"port",
";",
"$",
"uri",
"=",
"$",
"protocol",
".",
"'://'",
".",
"$",
"host",
";",
"return",
"$",
"uri",
";",
"}"
] | Get basic path
@return string URL | [
"Get",
"basic",
"path"
] | train | https://github.com/MatiasNAmendola/slimpower-slim/blob/c78ebbd4124d75ec82fe19b6dd62504da097fd15/src/Libs/Net.php#L104-L115 |
BenGorUser/SymfonyRoutingBridge | src/BenGorUser/SymfonyRoutingBridge/Infrastructure/Routing/SymfonyUserUrlGenerator.php | SymfonyUserUrlGenerator.generate | public function generate($aToken)
{
return $this->urlGenerator->generate(
$this->pathName,
['token' => $aToken],
UrlGeneratorInterface::ABSOLUTE_URL
);
} | php | public function generate($aToken)
{
return $this->urlGenerator->generate(
$this->pathName,
['token' => $aToken],
UrlGeneratorInterface::ABSOLUTE_URL
);
} | [
"public",
"function",
"generate",
"(",
"$",
"aToken",
")",
"{",
"return",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"$",
"this",
"->",
"pathName",
",",
"[",
"'token'",
"=>",
"$",
"aToken",
"]",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/BenGorUser/SymfonyRoutingBridge/blob/fb023ecebb432689e87d9c7e61777fe9d25ee907/src/BenGorUser/SymfonyRoutingBridge/Infrastructure/Routing/SymfonyUserUrlGenerator.php#L54-L61 |
qingbing/php-helper | src/abstracts/SingleTon.php | SingleTon.getInstance | final public static function getInstance()
{
$className = get_called_class();
if (!isset(self::$_instances[$className])) {
$instance = new $className();
/* @var SingleTon $instance */
$instance->init();
self::$_instances[$className] = $instance;
}
return self::$_instances[$className];
} | php | final public static function getInstance()
{
$className = get_called_class();
if (!isset(self::$_instances[$className])) {
$instance = new $className();
/* @var SingleTon $instance */
$instance->init();
self::$_instances[$className] = $instance;
}
return self::$_instances[$className];
} | [
"final",
"public",
"static",
"function",
"getInstance",
"(",
")",
"{",
"$",
"className",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
")",
";",
"/* @var SingleTon $instance */",
"$",
"instance",
"->",
"init",
"(",
")",
";",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
"=",
"$",
"instance",
";",
"}",
"return",
"self",
"::",
"$",
"_instances",
"[",
"$",
"className",
"]",
";",
"}"
] | 获取实例
@return $this | [
"获取实例"
] | train | https://github.com/qingbing/php-helper/blob/112d54ed2377db9f25604877b1a82e464f4ffd14/src/abstracts/SingleTon.php#L28-L38 |
itcreator/custom-cmf | Module/System/src/Cmf/System/Application.php | Application.killWww | public function killWww()
{
$host = $_SERVER['SERVER_NAME'];
if (stripos($host, 'www.') === 0) {
$host = substr_replace($host, '', 0, 4);
$uri = $_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently");
if ('/' == $uri[0]) {
header('Location: http://' . $host . $uri);
} else {
header('Location: http://' . $host . '/' . $uri);
}
die;
}
return $this;
} | php | public function killWww()
{
$host = $_SERVER['SERVER_NAME'];
if (stripos($host, 'www.') === 0) {
$host = substr_replace($host, '', 0, 4);
$uri = $_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently");
if ('/' == $uri[0]) {
header('Location: http://' . $host . $uri);
} else {
header('Location: http://' . $host . '/' . $uri);
}
die;
}
return $this;
} | [
"public",
"function",
"killWww",
"(",
")",
"{",
"$",
"host",
"=",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
";",
"if",
"(",
"stripos",
"(",
"$",
"host",
",",
"'www.'",
")",
"===",
"0",
")",
"{",
"$",
"host",
"=",
"substr_replace",
"(",
"$",
"host",
",",
"''",
",",
"0",
",",
"4",
")",
";",
"$",
"uri",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"header",
"(",
"\"HTTP/1.1 301 Moved Permanently\"",
")",
";",
"if",
"(",
"'/'",
"==",
"$",
"uri",
"[",
"0",
"]",
")",
"{",
"header",
"(",
"'Location: http://'",
".",
"$",
"host",
".",
"$",
"uri",
")",
";",
"}",
"else",
"{",
"header",
"(",
"'Location: http://'",
".",
"$",
"host",
".",
"'/'",
".",
"$",
"uri",
")",
";",
"}",
"die",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Redirect from www.hostname to hostname
@return Application | [
"Redirect",
"from",
"www",
".",
"hostname",
"to",
"hostname"
] | train | https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/System/src/Cmf/System/Application.php#L67-L85 |
PenoaksDev/Milky-Framework | src/Milky/Binding/UniversalBuilder.php | UniversalBuilder.resolve | public static function resolve( $key )
{
if ( strpos( $key, '\\' ) !== false )
return static::resolveClass( $key );
$key = explode( '.', $key );
if ( $resolver = static::getResolver( $key[0] ) )
return $resolver->resolve( $key[0], implode( '.', array_slice( $key, 1 ) ) );
return null;
} | php | public static function resolve( $key )
{
if ( strpos( $key, '\\' ) !== false )
return static::resolveClass( $key );
$key = explode( '.', $key );
if ( $resolver = static::getResolver( $key[0] ) )
return $resolver->resolve( $key[0], implode( '.', array_slice( $key, 1 ) ) );
return null;
} | [
"public",
"static",
"function",
"resolve",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'\\\\'",
")",
"!==",
"false",
")",
"return",
"static",
"::",
"resolveClass",
"(",
"$",
"key",
")",
";",
"$",
"key",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"resolver",
"=",
"static",
"::",
"getResolver",
"(",
"$",
"key",
"[",
"0",
"]",
")",
")",
"return",
"$",
"resolver",
"->",
"resolve",
"(",
"$",
"key",
"[",
"0",
"]",
",",
"implode",
"(",
"'.'",
",",
"array_slice",
"(",
"$",
"key",
",",
"1",
")",
")",
")",
";",
"return",
"null",
";",
"}"
] | Attempts to locate a instance or value from the registered resolvers.
@param $key
@return mixed|null|object | [
"Attempts",
"to",
"locate",
"a",
"instance",
"or",
"value",
"from",
"the",
"registered",
"resolvers",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L132-L143 |
PenoaksDev/Milky-Framework | src/Milky/Binding/UniversalBuilder.php | UniversalBuilder.resolveClass | public static function resolveClass( $class, $buildOnFailure = false, $parameters = [] )
{
if ( !is_string( $class ) )
throw new ResolverException( "Class must be a string" );
if ( $class == Framework::class )
return Framework::fw();
if ( $class == Configuration::class )
return Framework::config();
if ( $class == Logger::class )
return Framework::log();
// TODO Add a few more basic classes
foreach ( static::$resolvers as $resolver )
if ( false !== ( $result = $resolver->resolveClass( $class ) ) )
return $result;
if ( $buildOnFailure )
return static::buildClass( $class, $parameters );
return null;
} | php | public static function resolveClass( $class, $buildOnFailure = false, $parameters = [] )
{
if ( !is_string( $class ) )
throw new ResolverException( "Class must be a string" );
if ( $class == Framework::class )
return Framework::fw();
if ( $class == Configuration::class )
return Framework::config();
if ( $class == Logger::class )
return Framework::log();
// TODO Add a few more basic classes
foreach ( static::$resolvers as $resolver )
if ( false !== ( $result = $resolver->resolveClass( $class ) ) )
return $result;
if ( $buildOnFailure )
return static::buildClass( $class, $parameters );
return null;
} | [
"public",
"static",
"function",
"resolveClass",
"(",
"$",
"class",
",",
"$",
"buildOnFailure",
"=",
"false",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"class",
")",
")",
"throw",
"new",
"ResolverException",
"(",
"\"Class must be a string\"",
")",
";",
"if",
"(",
"$",
"class",
"==",
"Framework",
"::",
"class",
")",
"return",
"Framework",
"::",
"fw",
"(",
")",
";",
"if",
"(",
"$",
"class",
"==",
"Configuration",
"::",
"class",
")",
"return",
"Framework",
"::",
"config",
"(",
")",
";",
"if",
"(",
"$",
"class",
"==",
"Logger",
"::",
"class",
")",
"return",
"Framework",
"::",
"log",
"(",
")",
";",
"// TODO Add a few more basic classes",
"foreach",
"(",
"static",
"::",
"$",
"resolvers",
"as",
"$",
"resolver",
")",
"if",
"(",
"false",
"!==",
"(",
"$",
"result",
"=",
"$",
"resolver",
"->",
"resolveClass",
"(",
"$",
"class",
")",
")",
")",
"return",
"$",
"result",
";",
"if",
"(",
"$",
"buildOnFailure",
")",
"return",
"static",
"::",
"buildClass",
"(",
"$",
"class",
",",
"$",
"parameters",
")",
";",
"return",
"null",
";",
"}"
] | Attempts to locate a class within the registered resolvers.
Optionally will build the class on failure.
@param string $class
@param bool $buildOnFailure
@param array $parameters
@return mixed|null|object | [
"Attempts",
"to",
"locate",
"a",
"class",
"within",
"the",
"registered",
"resolvers",
".",
"Optionally",
"will",
"build",
"the",
"class",
"on",
"failure",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L154-L176 |
PenoaksDev/Milky-Framework | src/Milky/Binding/UniversalBuilder.php | UniversalBuilder.buildClass | public static function buildClass( $class, array $parameters = [] )
{
if ( !is_string( $class ) )
throw new BindingException( "Class must be a string" );
if ( static::building( $class ) )
throw new BindingException( "The class [" . $class . "] is already being built." );
static::$buildStack[] = $class;
try
{
$reflector = new \ReflectionClass( $class );
// If the type is not instantiable, the developer is attempting to resolve
// an abstract type such as an Interface of Abstract Class and there is
// no binding registered for the abstractions so we need to bail out.
if ( !$reflector->isInstantiable() )
throw new BindingException( "Target [$class] is not instantiable." );
$constructor = $reflector->getConstructor();
// If there are no constructors, that means there are no dependencies then
// we can just resolve the instances of the objects right away.
if ( is_null( $constructor ) )
return new $class;
$dependencies = $constructor->getParameters();
// Once we have all the constructor's parameters we can create each of the
// dependency instances and then use the reflection instances to make a
// new instance of this class, injecting the created dependencies in.
$parameters = static::keyParametersByArgument( $dependencies, $parameters );
$instances = static::getDependencies( $dependencies, $parameters, $class );
array_pop( static::$buildStack );
/**/
return $reflector->newInstanceArgs( $instances );
}
catch ( \ReflectionException $e )
{
array_pop( static::$buildStack );
throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() );
}
} | php | public static function buildClass( $class, array $parameters = [] )
{
if ( !is_string( $class ) )
throw new BindingException( "Class must be a string" );
if ( static::building( $class ) )
throw new BindingException( "The class [" . $class . "] is already being built." );
static::$buildStack[] = $class;
try
{
$reflector = new \ReflectionClass( $class );
// If the type is not instantiable, the developer is attempting to resolve
// an abstract type such as an Interface of Abstract Class and there is
// no binding registered for the abstractions so we need to bail out.
if ( !$reflector->isInstantiable() )
throw new BindingException( "Target [$class] is not instantiable." );
$constructor = $reflector->getConstructor();
// If there are no constructors, that means there are no dependencies then
// we can just resolve the instances of the objects right away.
if ( is_null( $constructor ) )
return new $class;
$dependencies = $constructor->getParameters();
// Once we have all the constructor's parameters we can create each of the
// dependency instances and then use the reflection instances to make a
// new instance of this class, injecting the created dependencies in.
$parameters = static::keyParametersByArgument( $dependencies, $parameters );
$instances = static::getDependencies( $dependencies, $parameters, $class );
array_pop( static::$buildStack );
/**/
return $reflector->newInstanceArgs( $instances );
}
catch ( \ReflectionException $e )
{
array_pop( static::$buildStack );
throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() );
}
} | [
"public",
"static",
"function",
"buildClass",
"(",
"$",
"class",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"class",
")",
")",
"throw",
"new",
"BindingException",
"(",
"\"Class must be a string\"",
")",
";",
"if",
"(",
"static",
"::",
"building",
"(",
"$",
"class",
")",
")",
"throw",
"new",
"BindingException",
"(",
"\"The class [\"",
".",
"$",
"class",
".",
"\"] is already being built.\"",
")",
";",
"static",
"::",
"$",
"buildStack",
"[",
"]",
"=",
"$",
"class",
";",
"try",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"// If the type is not instantiable, the developer is attempting to resolve",
"// an abstract type such as an Interface of Abstract Class and there is",
"// no binding registered for the abstractions so we need to bail out.",
"if",
"(",
"!",
"$",
"reflector",
"->",
"isInstantiable",
"(",
")",
")",
"throw",
"new",
"BindingException",
"(",
"\"Target [$class] is not instantiable.\"",
")",
";",
"$",
"constructor",
"=",
"$",
"reflector",
"->",
"getConstructor",
"(",
")",
";",
"// If there are no constructors, that means there are no dependencies then",
"// we can just resolve the instances of the objects right away.",
"if",
"(",
"is_null",
"(",
"$",
"constructor",
")",
")",
"return",
"new",
"$",
"class",
";",
"$",
"dependencies",
"=",
"$",
"constructor",
"->",
"getParameters",
"(",
")",
";",
"// Once we have all the constructor's parameters we can create each of the",
"// dependency instances and then use the reflection instances to make a",
"// new instance of this class, injecting the created dependencies in.",
"$",
"parameters",
"=",
"static",
"::",
"keyParametersByArgument",
"(",
"$",
"dependencies",
",",
"$",
"parameters",
")",
";",
"$",
"instances",
"=",
"static",
"::",
"getDependencies",
"(",
"$",
"dependencies",
",",
"$",
"parameters",
",",
"$",
"class",
")",
";",
"array_pop",
"(",
"static",
"::",
"$",
"buildStack",
")",
";",
"/**/",
"return",
"$",
"reflector",
"->",
"newInstanceArgs",
"(",
"$",
"instances",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"array_pop",
"(",
"static",
"::",
"$",
"buildStack",
")",
";",
"throw",
"new",
"BindingException",
"(",
"\"Failed to build [$class]: \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"\" in \"",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"\" on line \"",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
")",
";",
"}",
"}"
] | Attempts to construct a class
@param string $class
@param array $parameters
@return object
@throws BindingException | [
"Attempts",
"to",
"construct",
"a",
"class"
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L187-L235 |
PenoaksDev/Milky-Framework | src/Milky/Binding/UniversalBuilder.php | UniversalBuilder.call | public static function call( $callback, array $parameters = [], $defaultMethod = null )
{
if ( is_string( $callback ) && strpos( $callback, '@' ) !== false || $defaultMethod )
{
$segments = explode( '@', $callback );
$method = count( $segments ) == 2 ? $segments[1] : $defaultMethod;
if ( is_null( $method ) )
throw new \InvalidArgumentException( 'Method not provided.' );
$callback = [static::resolve( $segments[0] ), $method];
}
$dependencies = static::getMethodDependencies( $callback, $parameters );
return call_user_func_array( $callback, $dependencies );
} | php | public static function call( $callback, array $parameters = [], $defaultMethod = null )
{
if ( is_string( $callback ) && strpos( $callback, '@' ) !== false || $defaultMethod )
{
$segments = explode( '@', $callback );
$method = count( $segments ) == 2 ? $segments[1] : $defaultMethod;
if ( is_null( $method ) )
throw new \InvalidArgumentException( 'Method not provided.' );
$callback = [static::resolve( $segments[0] ), $method];
}
$dependencies = static::getMethodDependencies( $callback, $parameters );
return call_user_func_array( $callback, $dependencies );
} | [
"public",
"static",
"function",
"call",
"(",
"$",
"callback",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"defaultMethod",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"callback",
")",
"&&",
"strpos",
"(",
"$",
"callback",
",",
"'@'",
")",
"!==",
"false",
"||",
"$",
"defaultMethod",
")",
"{",
"$",
"segments",
"=",
"explode",
"(",
"'@'",
",",
"$",
"callback",
")",
";",
"$",
"method",
"=",
"count",
"(",
"$",
"segments",
")",
"==",
"2",
"?",
"$",
"segments",
"[",
"1",
"]",
":",
"$",
"defaultMethod",
";",
"if",
"(",
"is_null",
"(",
"$",
"method",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Method not provided.'",
")",
";",
"$",
"callback",
"=",
"[",
"static",
"::",
"resolve",
"(",
"$",
"segments",
"[",
"0",
"]",
")",
",",
"$",
"method",
"]",
";",
"}",
"$",
"dependencies",
"=",
"static",
"::",
"getMethodDependencies",
"(",
"$",
"callback",
",",
"$",
"parameters",
")",
";",
"return",
"call_user_func_array",
"(",
"$",
"callback",
",",
"$",
"dependencies",
")",
";",
"}"
] | Call the given Closure / class@method and inject its dependencies.
@param callable|string $callback
@param array $parameters
@param string|null $defaultMethod
@return mixed | [
"Call",
"the",
"given",
"Closure",
"/",
"class@method",
"and",
"inject",
"its",
"dependencies",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L265-L281 |
PenoaksDev/Milky-Framework | src/Milky/Binding/UniversalBuilder.php | UniversalBuilder.getMethodDependencies | public static function getMethodDependencies( $callback, array $parameters = [] )
{
$reflector = static::getCallReflector( $callback );
return static::getDependencies( $reflector->getParameters(), $parameters, $reflector->getName() );
} | php | public static function getMethodDependencies( $callback, array $parameters = [] )
{
$reflector = static::getCallReflector( $callback );
return static::getDependencies( $reflector->getParameters(), $parameters, $reflector->getName() );
} | [
"public",
"static",
"function",
"getMethodDependencies",
"(",
"$",
"callback",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"reflector",
"=",
"static",
"::",
"getCallReflector",
"(",
"$",
"callback",
")",
";",
"return",
"static",
"::",
"getDependencies",
"(",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
",",
"$",
"parameters",
",",
"$",
"reflector",
"->",
"getName",
"(",
")",
")",
";",
"}"
] | Get all dependencies for a given method.
@param callable|string $callback
@param array $parameters
@return array | [
"Get",
"all",
"dependencies",
"for",
"a",
"given",
"method",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L291-L296 |
PenoaksDev/Milky-Framework | src/Milky/Binding/UniversalBuilder.php | UniversalBuilder.getDependencies | public static function getDependencies( array $parameters, array $primitives = [], $classAndMethod = null )
{
$dependencies = [];
if ( !array_key_exists( 'fw', $primitives ) )
$primitives['fw'] = Framework::fw();
foreach ( $parameters as $parameter )
{
try
{
/*
* If the class is null, it means the dependency is a string or some other
* primitive type which we can not resolve since it is not a class and
* we will just bomb out with an error since we have no-where to go.
*/
if ( array_key_exists( $parameter->name, $primitives ) )
$dependencies[] = $primitives[$parameter->name];
else if ( is_null( $parameter->getClass() ) )
$dependencies[] = static::resolve( $parameter->name );
else
{
$depend = static::resolveClass( $parameter->getClass()->name );
if ( is_null( $depend ) )
throw new BindingException();
if ( is_array( $depend ) )
{
if ( array_key_exists( $parameter->name, $depend ) )
$depend = $depend[$parameter->name];
else
$depend = $depend[0];
}
$dependencies[] = $depend;
}
}
catch ( BindingException $e )
{
/*
* If we can not resolve the class instance, we will check to see if the value
* is optional, and if it is we will return the optional parameter value as
* the value of the dependency, similarly to how we do this with scalars.
*/
if ( $parameter->isDefaultValueAvailable() )
$dependencies[] = $parameter->getDefaultValue();
else if ( $parameter->isOptional() )
$dependencies[] = null;
else
{
$parameterClass = $parameter->getClass()->name;
foreach ( $primitives as $prim )
if ( $prim instanceof $parameterClass )
{
$dependencies[] = $prim;
continue;
}
$params = [];
foreach ( $parameters as $param )
$params[] = ( !is_null( $param->getClass() ) ? $param->getClass()->getName() . " " : "" ) . ( $param->isPassedByReference() ? "&" : "" ) . "$" . $param->getName() . ( $param->isDefaultValueAvailable() ? " = " . ( is_array( $param->getDefaultValue() ) ? "[" . implode( ', ', $param->getDefaultValue() ) . "]" : $param->getDefaultValue() ) : ( $param->isOptional() ? " = null" : "" ) );
throw new BindingException( "Dependency injection failed for " . $parameter . " on " . $classAndMethod . "( " . implode( ', ', $params ) . " )" );
}
}
}
return $dependencies;
} | php | public static function getDependencies( array $parameters, array $primitives = [], $classAndMethod = null )
{
$dependencies = [];
if ( !array_key_exists( 'fw', $primitives ) )
$primitives['fw'] = Framework::fw();
foreach ( $parameters as $parameter )
{
try
{
/*
* If the class is null, it means the dependency is a string or some other
* primitive type which we can not resolve since it is not a class and
* we will just bomb out with an error since we have no-where to go.
*/
if ( array_key_exists( $parameter->name, $primitives ) )
$dependencies[] = $primitives[$parameter->name];
else if ( is_null( $parameter->getClass() ) )
$dependencies[] = static::resolve( $parameter->name );
else
{
$depend = static::resolveClass( $parameter->getClass()->name );
if ( is_null( $depend ) )
throw new BindingException();
if ( is_array( $depend ) )
{
if ( array_key_exists( $parameter->name, $depend ) )
$depend = $depend[$parameter->name];
else
$depend = $depend[0];
}
$dependencies[] = $depend;
}
}
catch ( BindingException $e )
{
/*
* If we can not resolve the class instance, we will check to see if the value
* is optional, and if it is we will return the optional parameter value as
* the value of the dependency, similarly to how we do this with scalars.
*/
if ( $parameter->isDefaultValueAvailable() )
$dependencies[] = $parameter->getDefaultValue();
else if ( $parameter->isOptional() )
$dependencies[] = null;
else
{
$parameterClass = $parameter->getClass()->name;
foreach ( $primitives as $prim )
if ( $prim instanceof $parameterClass )
{
$dependencies[] = $prim;
continue;
}
$params = [];
foreach ( $parameters as $param )
$params[] = ( !is_null( $param->getClass() ) ? $param->getClass()->getName() . " " : "" ) . ( $param->isPassedByReference() ? "&" : "" ) . "$" . $param->getName() . ( $param->isDefaultValueAvailable() ? " = " . ( is_array( $param->getDefaultValue() ) ? "[" . implode( ', ', $param->getDefaultValue() ) . "]" : $param->getDefaultValue() ) : ( $param->isOptional() ? " = null" : "" ) );
throw new BindingException( "Dependency injection failed for " . $parameter . " on " . $classAndMethod . "( " . implode( ', ', $params ) . " )" );
}
}
}
return $dependencies;
} | [
"public",
"static",
"function",
"getDependencies",
"(",
"array",
"$",
"parameters",
",",
"array",
"$",
"primitives",
"=",
"[",
"]",
",",
"$",
"classAndMethod",
"=",
"null",
")",
"{",
"$",
"dependencies",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'fw'",
",",
"$",
"primitives",
")",
")",
"$",
"primitives",
"[",
"'fw'",
"]",
"=",
"Framework",
"::",
"fw",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"try",
"{",
"/*\n\t\t\t\t * If the class is null, it means the dependency is a string or some other\n\t\t\t\t * primitive type which we can not resolve since it is not a class and\n\t\t\t\t * we will just bomb out with an error since we have no-where to go.\n\t\t\t\t */",
"if",
"(",
"array_key_exists",
"(",
"$",
"parameter",
"->",
"name",
",",
"$",
"primitives",
")",
")",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"primitives",
"[",
"$",
"parameter",
"->",
"name",
"]",
";",
"else",
"if",
"(",
"is_null",
"(",
"$",
"parameter",
"->",
"getClass",
"(",
")",
")",
")",
"$",
"dependencies",
"[",
"]",
"=",
"static",
"::",
"resolve",
"(",
"$",
"parameter",
"->",
"name",
")",
";",
"else",
"{",
"$",
"depend",
"=",
"static",
"::",
"resolveClass",
"(",
"$",
"parameter",
"->",
"getClass",
"(",
")",
"->",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"depend",
")",
")",
"throw",
"new",
"BindingException",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"depend",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"parameter",
"->",
"name",
",",
"$",
"depend",
")",
")",
"$",
"depend",
"=",
"$",
"depend",
"[",
"$",
"parameter",
"->",
"name",
"]",
";",
"else",
"$",
"depend",
"=",
"$",
"depend",
"[",
"0",
"]",
";",
"}",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"depend",
";",
"}",
"}",
"catch",
"(",
"BindingException",
"$",
"e",
")",
"{",
"/*\n\t\t\t\t * If we can not resolve the class instance, we will check to see if the value\n\t\t\t\t * is optional, and if it is we will return the optional parameter value as\n\t\t\t\t * the value of the dependency, similarly to how we do this with scalars.\n\t\t\t\t */",
"if",
"(",
"$",
"parameter",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
";",
"else",
"if",
"(",
"$",
"parameter",
"->",
"isOptional",
"(",
")",
")",
"$",
"dependencies",
"[",
"]",
"=",
"null",
";",
"else",
"{",
"$",
"parameterClass",
"=",
"$",
"parameter",
"->",
"getClass",
"(",
")",
"->",
"name",
";",
"foreach",
"(",
"$",
"primitives",
"as",
"$",
"prim",
")",
"if",
"(",
"$",
"prim",
"instanceof",
"$",
"parameterClass",
")",
"{",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"prim",
";",
"continue",
";",
"}",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"param",
")",
"$",
"params",
"[",
"]",
"=",
"(",
"!",
"is_null",
"(",
"$",
"param",
"->",
"getClass",
"(",
")",
")",
"?",
"$",
"param",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
".",
"\" \"",
":",
"\"\"",
")",
".",
"(",
"$",
"param",
"->",
"isPassedByReference",
"(",
")",
"?",
"\"&\"",
":",
"\"\"",
")",
".",
"\"$\"",
".",
"$",
"param",
"->",
"getName",
"(",
")",
".",
"(",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
"?",
"\" = \"",
".",
"(",
"is_array",
"(",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
")",
"?",
"\"[\"",
".",
"implode",
"(",
"', '",
",",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
")",
".",
"\"]\"",
":",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
")",
":",
"(",
"$",
"param",
"->",
"isOptional",
"(",
")",
"?",
"\" = null\"",
":",
"\"\"",
")",
")",
";",
"throw",
"new",
"BindingException",
"(",
"\"Dependency injection failed for \"",
".",
"$",
"parameter",
".",
"\" on \"",
".",
"$",
"classAndMethod",
".",
"\"( \"",
".",
"implode",
"(",
"', '",
",",
"$",
"params",
")",
".",
"\" )\"",
")",
";",
"}",
"}",
"}",
"return",
"$",
"dependencies",
";",
"}"
] | Resolve all of the dependencies from the ReflectionParameters.
@param \ReflectionParameter[] $parameters
@param array $primitives
@param string $classAndMethod
@return array | [
"Resolve",
"all",
"of",
"the",
"dependencies",
"from",
"the",
"ReflectionParameters",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/UniversalBuilder.php#L325-L390 |
Dhii/callback-abstract | src/NormalizeMethodCallableCapableTrait.php | NormalizeMethodCallableCapableTrait._normalizeMethodCallable | protected function _normalizeMethodCallable($callable)
{
if (is_object($callable) && is_callable($callable)) {
return array($callable, '__invoke');
}
$amtPartsRequired = 2; // Number of parts required for a valid callable
$origCallable = $callable; // Preserving the original value for reporting
// If stringable, try to separate into parts
try {
$callable = $this->_normalizeString($callable);
$callable = explode('::', $callable, $amtPartsRequired);
} catch (InvalidArgumentException $e) {
// Just continue
}
// Normalizing to array
$callable = $this->_normalizeArray($callable);
$callable = array_slice($callable, 0, $amtPartsRequired);
// Array must have exactly 2 parts
if (count($callable) !== $amtPartsRequired) {
throw $this->_createOutOfRangeException($this->__('The callable must have at least %1$s parts', array($amtPartsRequired)), null, null, $origCallable);
}
// First value must be an object or string, because stringable objects should be valid targets
if (!is_string($callable[0]) && !is_object($callable[0])) {
throw $this->_createOutOfRangeException($this->__('The first part must be an object or a string'), null, null, $origCallable);
}
// The second value must be a string or stringable
try {
$callable[1] = $this->_normalizeString($callable[1]);
} catch (InvalidArgumentException $e) {
throw $this->_createOutOfRangeException($this->__('The second part must be a string or stringable'), null, $e, $origCallable);
}
return $callable;
} | php | protected function _normalizeMethodCallable($callable)
{
if (is_object($callable) && is_callable($callable)) {
return array($callable, '__invoke');
}
$amtPartsRequired = 2; // Number of parts required for a valid callable
$origCallable = $callable; // Preserving the original value for reporting
// If stringable, try to separate into parts
try {
$callable = $this->_normalizeString($callable);
$callable = explode('::', $callable, $amtPartsRequired);
} catch (InvalidArgumentException $e) {
// Just continue
}
// Normalizing to array
$callable = $this->_normalizeArray($callable);
$callable = array_slice($callable, 0, $amtPartsRequired);
// Array must have exactly 2 parts
if (count($callable) !== $amtPartsRequired) {
throw $this->_createOutOfRangeException($this->__('The callable must have at least %1$s parts', array($amtPartsRequired)), null, null, $origCallable);
}
// First value must be an object or string, because stringable objects should be valid targets
if (!is_string($callable[0]) && !is_object($callable[0])) {
throw $this->_createOutOfRangeException($this->__('The first part must be an object or a string'), null, null, $origCallable);
}
// The second value must be a string or stringable
try {
$callable[1] = $this->_normalizeString($callable[1]);
} catch (InvalidArgumentException $e) {
throw $this->_createOutOfRangeException($this->__('The second part must be a string or stringable'), null, $e, $origCallable);
}
return $callable;
} | [
"protected",
"function",
"_normalizeMethodCallable",
"(",
"$",
"callable",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"callable",
")",
"&&",
"is_callable",
"(",
"$",
"callable",
")",
")",
"{",
"return",
"array",
"(",
"$",
"callable",
",",
"'__invoke'",
")",
";",
"}",
"$",
"amtPartsRequired",
"=",
"2",
";",
"// Number of parts required for a valid callable",
"$",
"origCallable",
"=",
"$",
"callable",
";",
"// Preserving the original value for reporting",
"// If stringable, try to separate into parts",
"try",
"{",
"$",
"callable",
"=",
"$",
"this",
"->",
"_normalizeString",
"(",
"$",
"callable",
")",
";",
"$",
"callable",
"=",
"explode",
"(",
"'::'",
",",
"$",
"callable",
",",
"$",
"amtPartsRequired",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// Just continue",
"}",
"// Normalizing to array",
"$",
"callable",
"=",
"$",
"this",
"->",
"_normalizeArray",
"(",
"$",
"callable",
")",
";",
"$",
"callable",
"=",
"array_slice",
"(",
"$",
"callable",
",",
"0",
",",
"$",
"amtPartsRequired",
")",
";",
"// Array must have exactly 2 parts",
"if",
"(",
"count",
"(",
"$",
"callable",
")",
"!==",
"$",
"amtPartsRequired",
")",
"{",
"throw",
"$",
"this",
"->",
"_createOutOfRangeException",
"(",
"$",
"this",
"->",
"__",
"(",
"'The callable must have at least %1$s parts'",
",",
"array",
"(",
"$",
"amtPartsRequired",
")",
")",
",",
"null",
",",
"null",
",",
"$",
"origCallable",
")",
";",
"}",
"// First value must be an object or string, because stringable objects should be valid targets",
"if",
"(",
"!",
"is_string",
"(",
"$",
"callable",
"[",
"0",
"]",
")",
"&&",
"!",
"is_object",
"(",
"$",
"callable",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"_createOutOfRangeException",
"(",
"$",
"this",
"->",
"__",
"(",
"'The first part must be an object or a string'",
")",
",",
"null",
",",
"null",
",",
"$",
"origCallable",
")",
";",
"}",
"// The second value must be a string or stringable",
"try",
"{",
"$",
"callable",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"_normalizeString",
"(",
"$",
"callable",
"[",
"1",
"]",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"$",
"this",
"->",
"_createOutOfRangeException",
"(",
"$",
"this",
"->",
"__",
"(",
"'The second part must be a string or stringable'",
")",
",",
"null",
",",
"$",
"e",
",",
"$",
"origCallable",
")",
";",
"}",
"return",
"$",
"callable",
";",
"}"
] | Normalizes a method representation into a format recognizable by PHP as callable.
This does not guarantee that the callable will actually be invocable at this time; only that it looks like
something that can be invoked. See the second argument of {@see is_callable()).
@since [*next-version*]
@param string|Stringable|stdClass|Traversable|array $callable The stringable that identifies a static method,
or a list, where the first element is a class or class name, and the second is the name of the method. If the list has
more than 2 parts, other parts will be removed. The second element may be a Stringable object, and will then
be normalized. The first element MUST be a string or object, and will not be normalized.
@see is_callable()
@throws InvalidArgumentException If the argument is not stringable and not a list.
@throws OutOfRangeException If the argument does not contain enough parts to make a callable, if one of the parts is invalid.
@return array An array, where the first element is an object or a class name, and the second element is the name of a method. | [
"Normalizes",
"a",
"method",
"representation",
"into",
"a",
"format",
"recognizable",
"by",
"PHP",
"as",
"callable",
"."
] | train | https://github.com/Dhii/callback-abstract/blob/43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19/src/NormalizeMethodCallableCapableTrait.php#L34-L73 |
ZendExperts/phpids | lib/IDS/Caching/File.php | IDS_Caching_File.getInstance | public static function getInstance($type, $init)
{
if (!self::$cachingInstance) {
self::$cachingInstance = new IDS_Caching_File($type, $init);
}
return self::$cachingInstance;
} | php | public static function getInstance($type, $init)
{
if (!self::$cachingInstance) {
self::$cachingInstance = new IDS_Caching_File($type, $init);
}
return self::$cachingInstance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
"$",
"type",
",",
"$",
"init",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"cachingInstance",
")",
"{",
"self",
"::",
"$",
"cachingInstance",
"=",
"new",
"IDS_Caching_File",
"(",
"$",
"type",
",",
"$",
"init",
")",
";",
"}",
"return",
"self",
"::",
"$",
"cachingInstance",
";",
"}"
] | Returns an instance of this class
@param string $type caching type
@param object $init the IDS_Init object
@return object $this | [
"Returns",
"an",
"instance",
"of",
"this",
"class"
] | train | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Caching/File.php#L113-L120 |
ZendExperts/phpids | lib/IDS/Caching/File.php | IDS_Caching_File.setCache | public function setCache(array $data)
{
if (!is_writable(preg_replace('/[\/][^\/]+\.[^\/]++$/', null,
$this->path))) {
throw new Exception('Temp directory ' .
htmlspecialchars($this->path, ENT_QUOTES, 'UTF-8') .
' seems not writable');
}
if ((!file_exists($this->path) || (time()-filectime($this->path)) >
$this->config['expiration_time'])) {
$handle = @fopen($this->path, 'w+');
$serialized = @serialize($data);
if (!$handle) {
throw new Exception("Cache file couldn't be created");
}
if (!$serialized) {
throw new Exception("Cache data couldn't be serialized");
}
fwrite($handle, $serialized);
fclose($handle);
}
return $this;
} | php | public function setCache(array $data)
{
if (!is_writable(preg_replace('/[\/][^\/]+\.[^\/]++$/', null,
$this->path))) {
throw new Exception('Temp directory ' .
htmlspecialchars($this->path, ENT_QUOTES, 'UTF-8') .
' seems not writable');
}
if ((!file_exists($this->path) || (time()-filectime($this->path)) >
$this->config['expiration_time'])) {
$handle = @fopen($this->path, 'w+');
$serialized = @serialize($data);
if (!$handle) {
throw new Exception("Cache file couldn't be created");
}
if (!$serialized) {
throw new Exception("Cache data couldn't be serialized");
}
fwrite($handle, $serialized);
fclose($handle);
}
return $this;
} | [
"public",
"function",
"setCache",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"preg_replace",
"(",
"'/[\\/][^\\/]+\\.[^\\/]++$/'",
",",
"null",
",",
"$",
"this",
"->",
"path",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Temp directory '",
".",
"htmlspecialchars",
"(",
"$",
"this",
"->",
"path",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
".",
"' seems not writable'",
")",
";",
"}",
"if",
"(",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"path",
")",
"||",
"(",
"time",
"(",
")",
"-",
"filectime",
"(",
"$",
"this",
"->",
"path",
")",
")",
">",
"$",
"this",
"->",
"config",
"[",
"'expiration_time'",
"]",
")",
")",
"{",
"$",
"handle",
"=",
"@",
"fopen",
"(",
"$",
"this",
"->",
"path",
",",
"'w+'",
")",
";",
"$",
"serialized",
"=",
"@",
"serialize",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"$",
"handle",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Cache file couldn't be created\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"serialized",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Cache data couldn't be serialized\"",
")",
";",
"}",
"fwrite",
"(",
"$",
"handle",
",",
"$",
"serialized",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Writes cache data into the file
@param array $data the cache data
@throws Exception if cache file couldn't be created
@return object $this | [
"Writes",
"cache",
"data",
"into",
"the",
"file"
] | train | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Caching/File.php#L130-L157 |
ZendExperts/phpids | lib/IDS/Caching/File.php | IDS_Caching_File.getCache | public function getCache()
{
// make sure filters are parsed again if cache expired
if (file_exists($this->path) && (time()-filectime($this->path)) <
$this->config['expiration_time']) {
$data = unserialize(file_get_contents($this->path));
return $data;
}
return false;
} | php | public function getCache()
{
// make sure filters are parsed again if cache expired
if (file_exists($this->path) && (time()-filectime($this->path)) <
$this->config['expiration_time']) {
$data = unserialize(file_get_contents($this->path));
return $data;
}
return false;
} | [
"public",
"function",
"getCache",
"(",
")",
"{",
"// make sure filters are parsed again if cache expired",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"path",
")",
"&&",
"(",
"time",
"(",
")",
"-",
"filectime",
"(",
"$",
"this",
"->",
"path",
")",
")",
"<",
"$",
"this",
"->",
"config",
"[",
"'expiration_time'",
"]",
")",
"{",
"$",
"data",
"=",
"unserialize",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"path",
")",
")",
";",
"return",
"$",
"data",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the cached data
Note that this method returns false if either type or file cache is
not set
@return mixed cache data or false | [
"Returns",
"the",
"cached",
"data"
] | train | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Caching/File.php#L167-L178 |
TuumPHP/Web | src/View/ErrorView.php | ErrorView.findView | private function findView($code)
{
return isset($this->error_files[$code]) ? $this->error_files[$code] : $this->default_error_file;
} | php | private function findView($code)
{
return isset($this->error_files[$code]) ? $this->error_files[$code] : $this->default_error_file;
} | [
"private",
"function",
"findView",
"(",
"$",
"code",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"error_files",
"[",
"$",
"code",
"]",
")",
"?",
"$",
"this",
"->",
"error_files",
"[",
"$",
"code",
"]",
":",
"$",
"this",
"->",
"default_error_file",
";",
"}"
] | find error-view file from error code ($code).
@param $code
@return string | [
"find",
"error",
"-",
"view",
"file",
"from",
"error",
"code",
"(",
"$code",
")",
"."
] | train | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/View/ErrorView.php#L103-L106 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.notify | final public function notify($title = null, $body = null, $icon = null, $fallback = false)
{
$this->response['notify'] = [];
if (isset($title)) {
$this->response['notify']['title'] = "$title";
}
if (isset($body)) {
$this->response['notify']['body'] = "$body";
}
if (isset($icon)) {
$this->response['notify']['icon'] = "$icon";
}
$this->response['notify']['fallback'] = $fallback;
return $this;
} | php | final public function notify($title = null, $body = null, $icon = null, $fallback = false)
{
$this->response['notify'] = [];
if (isset($title)) {
$this->response['notify']['title'] = "$title";
}
if (isset($body)) {
$this->response['notify']['body'] = "$body";
}
if (isset($icon)) {
$this->response['notify']['icon'] = "$icon";
}
$this->response['notify']['fallback'] = $fallback;
return $this;
} | [
"final",
"public",
"function",
"notify",
"(",
"$",
"title",
"=",
"null",
",",
"$",
"body",
"=",
"null",
",",
"$",
"icon",
"=",
"null",
",",
"$",
"fallback",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'notify'",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"title",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'notify'",
"]",
"[",
"'title'",
"]",
"=",
"\"$title\"",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"body",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'notify'",
"]",
"[",
"'body'",
"]",
"=",
"\"$body\"",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"icon",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'notify'",
"]",
"[",
"'icon'",
"]",
"=",
"\"$icon\"",
";",
"}",
"$",
"this",
"->",
"response",
"[",
"'notify'",
"]",
"[",
"'fallback'",
"]",
"=",
"$",
"fallback",
";",
"return",
"$",
"this",
";",
"}"
] | Creates a notification (or alert)
@param string $title
@param string $body
@param string $icon
@param bool $fallback Use `alert` as fallback if notifications denied or not supported
@return self
@example $resp->notify('Title', 'Body', 'path/to/icon.png', true); | [
"Creates",
"a",
"notification",
"(",
"or",
"alert",
")"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L58-L75 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.script | final public function script($js = null)
{
(array_key_exists('script', $this->response))
? $this->response['script'] .= ';' . $js
: $this->response['script'] = "$js";
return $this;
} | php | final public function script($js = null)
{
(array_key_exists('script', $this->response))
? $this->response['script'] .= ';' . $js
: $this->response['script'] = "$js";
return $this;
} | [
"final",
"public",
"function",
"script",
"(",
"$",
"js",
"=",
"null",
")",
"{",
"(",
"array_key_exists",
"(",
"'script'",
",",
"$",
"this",
"->",
"response",
")",
")",
"?",
"$",
"this",
"->",
"response",
"[",
"'script'",
"]",
".=",
"';'",
".",
"$",
"js",
":",
"$",
"this",
"->",
"response",
"[",
"'script'",
"]",
"=",
"\"$js\"",
";",
"return",
"$",
"this",
";",
"}"
] | handleJSON in functions.js will eval() $js
Requires 'unsafe-eval' be set on script-src in csp.ini
which is generally a BAD idea.
Including because it is useful.
*USE WITH CAUTION* and watch your quotes
@param string $js (script to execute)
@example $resp->script("alert('Hello world')");
@return self | [
"handleJSON",
"in",
"functions",
".",
"js",
"will",
"eval",
"()",
"$js",
"Requires",
"unsafe",
"-",
"eval",
"be",
"set",
"on",
"script",
"-",
"src",
"in",
"csp",
".",
"ini",
"which",
"is",
"generally",
"a",
"BAD",
"idea",
".",
"Including",
"because",
"it",
"is",
"useful",
".",
"*",
"USE",
"WITH",
"CAUTION",
"*",
"and",
"watch",
"your",
"quotes"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L260-L267 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.table | final public function table()
{
$args = func_get_args();
$this->response['table'] = (count($args) == 1) ? $args[0] : $args;
return $this;
} | php | final public function table()
{
$args = func_get_args();
$this->response['table'] = (count($args) == 1) ? $args[0] : $args;
return $this;
} | [
"final",
"public",
"function",
"table",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"this",
"->",
"response",
"[",
"'table'",
"]",
"=",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"1",
")",
"?",
"$",
"args",
"[",
"0",
"]",
":",
"$",
"args",
";",
"return",
"$",
"this",
";",
"}"
] | Creates a table in browser console in supported browsers. Handler
in JavaScript will revert to log() if not supported
@param mixed function arguments [Any quantity or kind]
@return self | [
"Creates",
"a",
"table",
"in",
"browser",
"console",
"in",
"supported",
"browsers",
".",
"Handler",
"in",
"JavaScript",
"will",
"revert",
"to",
"log",
"()",
"if",
"not",
"supported"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L319-L324 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.triggerEvent | final public function triggerEvent($selector = null, $event = null)
{
if (! array_key_exists('triggerEvent', $this->response)) {
$this->response['triggerEvent'] = [];
}
$this->response['triggerEvent']["$selector"] = "$event";
return $this;
} | php | final public function triggerEvent($selector = null, $event = null)
{
if (! array_key_exists('triggerEvent', $this->response)) {
$this->response['triggerEvent'] = [];
}
$this->response['triggerEvent']["$selector"] = "$event";
return $this;
} | [
"final",
"public",
"function",
"triggerEvent",
"(",
"$",
"selector",
"=",
"null",
",",
"$",
"event",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'triggerEvent'",
",",
"$",
"this",
"->",
"response",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'triggerEvent'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"response",
"[",
"'triggerEvent'",
"]",
"[",
"\"$selector\"",
"]",
"=",
"\"$event\"",
";",
"return",
"$",
"this",
";",
"}"
] | Will trigger an event ($event) on targets ($selector) in handleJSON
handleJSON needs to determine which type of event to trigger
@see https://developer.mozilla.org/en-US/docs/Web/Events
@param string $selector (CSS selector for target(s))
@param string $event (Event to be triggered)
@return self
@example $resp->triggerEvent('button[type=submit]', 'click') | [
"Will",
"trigger",
"an",
"event",
"(",
"$event",
")",
"on",
"targets",
"(",
"$selector",
")",
"in",
"handleJSON"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L455-L463 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.open | final public function open(
$url = null,
array $paramaters = array(),
$replace = false,
$name = '_blank'
)
{
$specs = [
'height' => 500, // The height of the window. Min. value is 100
'width' => 500, // The width of the window. Min. value is 100
'top' => 0, // The top position of the window.
'left' => 0, // The left position of the window.
'resizable' => 1, // Whether or not the window is resizable. IE only
'titlebar' => 0, // Whether or not to display the title bar
'menubar' => 0, // Whether or not to display the menu bar
'toolbar' => 0, // Whether or not to display the browser toolbar. IE and Firefox only
'status' => 0 // Whether or not to add a status bar
];
$specs = array_merge($specs, $paramaters);
$this->response['open'] = [
'url' => $url,
'name' => $name,
'specs' => $specs,
'replace' => $replace
];
return $this;
} | php | final public function open(
$url = null,
array $paramaters = array(),
$replace = false,
$name = '_blank'
)
{
$specs = [
'height' => 500, // The height of the window. Min. value is 100
'width' => 500, // The width of the window. Min. value is 100
'top' => 0, // The top position of the window.
'left' => 0, // The left position of the window.
'resizable' => 1, // Whether or not the window is resizable. IE only
'titlebar' => 0, // Whether or not to display the title bar
'menubar' => 0, // Whether or not to display the menu bar
'toolbar' => 0, // Whether or not to display the browser toolbar. IE and Firefox only
'status' => 0 // Whether or not to add a status bar
];
$specs = array_merge($specs, $paramaters);
$this->response['open'] = [
'url' => $url,
'name' => $name,
'specs' => $specs,
'replace' => $replace
];
return $this;
} | [
"final",
"public",
"function",
"open",
"(",
"$",
"url",
"=",
"null",
",",
"array",
"$",
"paramaters",
"=",
"array",
"(",
")",
",",
"$",
"replace",
"=",
"false",
",",
"$",
"name",
"=",
"'_blank'",
")",
"{",
"$",
"specs",
"=",
"[",
"'height'",
"=>",
"500",
",",
"// The height of the window. Min. value is 100",
"'width'",
"=>",
"500",
",",
"// The width of the window. Min. value is 100",
"'top'",
"=>",
"0",
",",
"// The top position of the window.",
"'left'",
"=>",
"0",
",",
"// The left position of the window.",
"'resizable'",
"=>",
"1",
",",
"// Whether or not the window is resizable. IE only",
"'titlebar'",
"=>",
"0",
",",
"// Whether or not to display the title bar",
"'menubar'",
"=>",
"0",
",",
"// Whether or not to display the menu bar",
"'toolbar'",
"=>",
"0",
",",
"// Whether or not to display the browser toolbar. IE and Firefox only",
"'status'",
"=>",
"0",
"// Whether or not to add a status bar",
"]",
";",
"$",
"specs",
"=",
"array_merge",
"(",
"$",
"specs",
",",
"$",
"paramaters",
")",
";",
"$",
"this",
"->",
"response",
"[",
"'open'",
"]",
"=",
"[",
"'url'",
"=>",
"$",
"url",
",",
"'name'",
"=>",
"$",
"name",
",",
"'specs'",
"=>",
"$",
"specs",
",",
"'replace'",
"=>",
"$",
"replace",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Open a popup using JavaScript
@param string $url Specifies the URL of the page to open
@param array $paramaters See comments on $specs
@param bool $replace Creates a new entry or replaces the current entry in the history list
@param string $name Specifies the target attribute or the name of the window
@return self
@see http://www.w3schools.com/jsref/met_win_open.asp
@example $resp->open('example.com', ['width' => 900], false, '_top') | [
"Open",
"a",
"popup",
"using",
"JavaScript"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L476-L505 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.dataset | final public function dataset($sel = null, $name = null, $value = null)
{
if (!is_array($this->response['dataset'])) {
$this->response['dataset'] = [];
}
$this->response['dataset']["$sel"]["$name"] = "$value";
return $this;
} | php | final public function dataset($sel = null, $name = null, $value = null)
{
if (!is_array($this->response['dataset'])) {
$this->response['dataset'] = [];
}
$this->response['dataset']["$sel"]["$name"] = "$value";
return $this;
} | [
"final",
"public",
"function",
"dataset",
"(",
"$",
"sel",
"=",
"null",
",",
"$",
"name",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"response",
"[",
"'dataset'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'dataset'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"response",
"[",
"'dataset'",
"]",
"[",
"\"$sel\"",
"]",
"[",
"\"$name\"",
"]",
"=",
"\"$value\"",
";",
"return",
"$",
"this",
";",
"}"
] | Sets data-* using $this->attributes.
Makes necessary conversions
@param string $sel (CSS selector)
@param string $name (data-$name)
@param string $value (string or boolean)
@return self
@example $resp->dataset('menuitem[label="Click Me"]', 'request', 'action=test')
@see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.dataset | [
"Sets",
"data",
"-",
"*",
"using",
"$this",
"-",
">",
"attributes",
"."
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L607-L616 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.style | final public function style($sel = null, $property = null, $value = null)
{
if (! is_array($this->response['style'])) {
$this->response['style'] = [];
}
$this->response['style']["$sel"]["$property"] = "$value";
return $this;
} | php | final public function style($sel = null, $property = null, $value = null)
{
if (! is_array($this->response['style'])) {
$this->response['style'] = [];
}
$this->response['style']["$sel"]["$property"] = "$value";
return $this;
} | [
"final",
"public",
"function",
"style",
"(",
"$",
"sel",
"=",
"null",
",",
"$",
"property",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"response",
"[",
"'style'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'style'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"response",
"[",
"'style'",
"]",
"[",
"\"$sel\"",
"]",
"[",
"\"$property\"",
"]",
"=",
"\"$value\"",
";",
"return",
"$",
"this",
";",
"}"
] | Sets inline style on Element matching $sel
@param string $sel [Any valid CSS selector]
@param string $property [Property to set]
@param string $value [Value to set it to]
@return self | [
"Sets",
"inline",
"style",
"on",
"Element",
"matching",
"$sel"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L626-L634 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.animate | final public function animate($sel, Array $keyframes, Array $opts)
{
if (! array_key_exists('animate', $this->response)) {
$this->response['animate'] = [];
}
$this->response['animate'][$sel] = ['keyframes' => $keyframes, 'opts' => $opts];
return $this;
} | php | final public function animate($sel, Array $keyframes, Array $opts)
{
if (! array_key_exists('animate', $this->response)) {
$this->response['animate'] = [];
}
$this->response['animate'][$sel] = ['keyframes' => $keyframes, 'opts' => $opts];
return $this;
} | [
"final",
"public",
"function",
"animate",
"(",
"$",
"sel",
",",
"Array",
"$",
"keyframes",
",",
"Array",
"$",
"opts",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'animate'",
",",
"$",
"this",
"->",
"response",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'animate'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"response",
"[",
"'animate'",
"]",
"[",
"$",
"sel",
"]",
"=",
"[",
"'keyframes'",
"=>",
"$",
"keyframes",
",",
"'opts'",
"=>",
"$",
"opts",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add animations using `Element.animate`
@param String $sel Passed to `document.querySelectorAll`
@param Array $keyframes Array of keyframes / steps in animation
@param array $opts Array of options, such as duration
@return self
@see https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats
@example
$resp->animate('#login-dialog', [
['transform' => 'none'],
['transform' => 'translateX(5em)scale(0.9)'],
['transform' => 'translateX(-5em)scale(1.1)'],
['transform' => 'none']
], [
'duration' => 100,
'iterations' => 5,
]); | [
"Add",
"animations",
"using",
"Element",
".",
"animate"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L653-L660 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.id | final public function id($sel = null, $id = false)
{
if (is_string($id)) {
$id = preg_replace(['/\s/', '/[\W]/'], ['_', null], trim($id));
}
return $this->attributes("$sel", 'id', $id);
} | php | final public function id($sel = null, $id = false)
{
if (is_string($id)) {
$id = preg_replace(['/\s/', '/[\W]/'], ['_', null], trim($id));
}
return $this->attributes("$sel", 'id', $id);
} | [
"final",
"public",
"function",
"id",
"(",
"$",
"sel",
"=",
"null",
",",
"$",
"id",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"id",
")",
")",
"{",
"$",
"id",
"=",
"preg_replace",
"(",
"[",
"'/\\s/'",
",",
"'/[\\W]/'",
"]",
",",
"[",
"'_'",
",",
"null",
"]",
",",
"trim",
"(",
"$",
"id",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"attributes",
"(",
"\"$sel\"",
",",
"'id'",
",",
"$",
"id",
")",
";",
"}"
] | Sets ID on Element matching $sel
@param string $sel [Any valid CSS selector]
@param mixed $id [String, null, or false. False unsets]
@return self | [
"Sets",
"ID",
"on",
"Element",
"matching",
"$sel"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L669-L676 |
shgysk8zer0/core_api | traits/ajax_dom.php | AJAX_DOM.consoleSetter | final protected function consoleSetter(
$method = 'log',
array $value = array()
)
{
if (array_key_exists($method, $this->response)) {
if (! is_array($this->response[$method])) {
$this->response[$method] = [$this->response[$method]];
}
$this->response[$method][] = count($value) === 1 ? current($value) : $value;
} else {
$this->response[$method] = count($value) == 1 ? current($value) : $value;
}
return $this;
} | php | final protected function consoleSetter(
$method = 'log',
array $value = array()
)
{
if (array_key_exists($method, $this->response)) {
if (! is_array($this->response[$method])) {
$this->response[$method] = [$this->response[$method]];
}
$this->response[$method][] = count($value) === 1 ? current($value) : $value;
} else {
$this->response[$method] = count($value) == 1 ? current($value) : $value;
}
return $this;
} | [
"final",
"protected",
"function",
"consoleSetter",
"(",
"$",
"method",
"=",
"'log'",
",",
"array",
"$",
"value",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"response",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"response",
"[",
"$",
"method",
"]",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"$",
"method",
"]",
"=",
"[",
"$",
"this",
"->",
"response",
"[",
"$",
"method",
"]",
"]",
";",
"}",
"$",
"this",
"->",
"response",
"[",
"$",
"method",
"]",
"[",
"]",
"=",
"count",
"(",
"$",
"value",
")",
"===",
"1",
"?",
"current",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"response",
"[",
"$",
"method",
"]",
"=",
"count",
"(",
"$",
"value",
")",
"==",
"1",
"?",
"current",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Private method for setting console values which can contain one or more
values. I.E., log could take a singe argument and then be called again
later. For console methods, set here to make it easier to call multiple
times.
@param string $method Console method to be setting
@param array $value Value to be setting or appending.
@return self | [
"Private",
"method",
"for",
"setting",
"console",
"values",
"which",
"can",
"contain",
"one",
"or",
"more",
"values",
".",
"I",
".",
"E",
".",
"log",
"could",
"take",
"a",
"singe",
"argument",
"and",
"then",
"be",
"called",
"again",
"later",
".",
"For",
"console",
"methods",
"set",
"here",
"to",
"make",
"it",
"easier",
"to",
"call",
"multiple",
"times",
"."
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/ajax_dom.php#L720-L734 |
Revys/revy | src/App/RoutesBase.php | RoutesBase.withLanguage | public static function withLanguage(\Closure $callback, $config = [])
{
if (\App::runningUnitTests()) {
$locale = \App::getLocale();
} else {
$locale = request()->segment(1);
}
if (strlen($locale) <= 2) {
Route::group(['prefix' => $locale, 'middleware' => 'lang'], function () use ($callback) {
$callback();
});
}
} | php | public static function withLanguage(\Closure $callback, $config = [])
{
if (\App::runningUnitTests()) {
$locale = \App::getLocale();
} else {
$locale = request()->segment(1);
}
if (strlen($locale) <= 2) {
Route::group(['prefix' => $locale, 'middleware' => 'lang'], function () use ($callback) {
$callback();
});
}
} | [
"public",
"static",
"function",
"withLanguage",
"(",
"\\",
"Closure",
"$",
"callback",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"\\",
"App",
"::",
"runningUnitTests",
"(",
")",
")",
"{",
"$",
"locale",
"=",
"\\",
"App",
"::",
"getLocale",
"(",
")",
";",
"}",
"else",
"{",
"$",
"locale",
"=",
"request",
"(",
")",
"->",
"segment",
"(",
"1",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"locale",
")",
"<=",
"2",
")",
"{",
"Route",
"::",
"group",
"(",
"[",
"'prefix'",
"=>",
"$",
"locale",
",",
"'middleware'",
"=>",
"'lang'",
"]",
",",
"function",
"(",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"$",
"callback",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] | Wraps routes with language prefix
@param \Closure $callback
@param array $config | [
"Wraps",
"routes",
"with",
"language",
"prefix"
] | train | https://github.com/Revys/revy/blob/b2c13f5f7e88eec2681b4ec8a0385e18c28fbfd1/src/App/RoutesBase.php#L36-L49 |
kapitchi/KapitchiEntity | src/KapitchiEntity/Mapper/EntityDbAdapterMapper.php | EntityDbAdapterMapper.getIdentifier | protected function getIdentifier($object)
{
$property = new ReflectionProperty(get_class($object), $this->getPrimaryKey());
$property->setAccessible(true);
return $property->getValue($object);
} | php | protected function getIdentifier($object)
{
$property = new ReflectionProperty(get_class($object), $this->getPrimaryKey());
$property->setAccessible(true);
return $property->getValue($object);
} | [
"protected",
"function",
"getIdentifier",
"(",
"$",
"object",
")",
"{",
"$",
"property",
"=",
"new",
"ReflectionProperty",
"(",
"get_class",
"(",
"$",
"object",
")",
",",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
")",
";",
"$",
"property",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"property",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"}"
] | check if object has already an identifier
@param object $object
@return mixed | [
"check",
"if",
"object",
"has",
"already",
"an",
"identifier"
] | train | https://github.com/kapitchi/KapitchiEntity/blob/69deaeb41d9133422a20ad6f64f0743d66cea8fd/src/KapitchiEntity/Mapper/EntityDbAdapterMapper.php#L99-L104 |
theopera/framework | src/Component/Mail/Mailer.php | Mailer.send | public function send(MailMessage $message)
{
$this->headers->add(new Header('From', $message->getFrom()));
$this->mailer->send($message, $this->headers);
} | php | public function send(MailMessage $message)
{
$this->headers->add(new Header('From', $message->getFrom()));
$this->mailer->send($message, $this->headers);
} | [
"public",
"function",
"send",
"(",
"MailMessage",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"headers",
"->",
"add",
"(",
"new",
"Header",
"(",
"'From'",
",",
"$",
"message",
"->",
"getFrom",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"mailer",
"->",
"send",
"(",
"$",
"message",
",",
"$",
"this",
"->",
"headers",
")",
";",
"}"
] | Tries to deliver the mail
@param \Opera\Component\Mail\MailMessage $message
@throws MailException | [
"Tries",
"to",
"deliver",
"the",
"mail"
] | train | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Mail/Mailer.php#L52-L57 |
theopera/framework | src/Component/Mail/Mailer.php | Mailer.parseAttachments | private function parseAttachments(array $files, string $message, string $contentType, string $hash) : string
{
$result = [];
// The original message
$result[] = '--body-mixed-' . $hash;
$result[] = new Header('Content-Type', $contentType);
$result[] = '';
$result[] = $message;
// The attachments
foreach ($files as $file) {
$headers = new Headers();
$headers->add(new Header('Content-Transfer-Encoding', 'base64'));
$headers->add(new Header('Content-Disposition', 'attachment'));
$headers->add(new Header('Content-Type', 'application/octet-stream', [
'filename' => $file->getFilename()
]));
$result[] = '--body-mixed-' . $hash;
$result[] = $headers;
$result[] = '';
$result[] = base64_encode($file->fread($file->getSize()));
}
return implode("\r\n", $result);
} | php | private function parseAttachments(array $files, string $message, string $contentType, string $hash) : string
{
$result = [];
// The original message
$result[] = '--body-mixed-' . $hash;
$result[] = new Header('Content-Type', $contentType);
$result[] = '';
$result[] = $message;
// The attachments
foreach ($files as $file) {
$headers = new Headers();
$headers->add(new Header('Content-Transfer-Encoding', 'base64'));
$headers->add(new Header('Content-Disposition', 'attachment'));
$headers->add(new Header('Content-Type', 'application/octet-stream', [
'filename' => $file->getFilename()
]));
$result[] = '--body-mixed-' . $hash;
$result[] = $headers;
$result[] = '';
$result[] = base64_encode($file->fread($file->getSize()));
}
return implode("\r\n", $result);
} | [
"private",
"function",
"parseAttachments",
"(",
"array",
"$",
"files",
",",
"string",
"$",
"message",
",",
"string",
"$",
"contentType",
",",
"string",
"$",
"hash",
")",
":",
"string",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"// The original message",
"$",
"result",
"[",
"]",
"=",
"'--body-mixed-'",
".",
"$",
"hash",
";",
"$",
"result",
"[",
"]",
"=",
"new",
"Header",
"(",
"'Content-Type'",
",",
"$",
"contentType",
")",
";",
"$",
"result",
"[",
"]",
"=",
"''",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"message",
";",
"// The attachments",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"headers",
"=",
"new",
"Headers",
"(",
")",
";",
"$",
"headers",
"->",
"add",
"(",
"new",
"Header",
"(",
"'Content-Transfer-Encoding'",
",",
"'base64'",
")",
")",
";",
"$",
"headers",
"->",
"add",
"(",
"new",
"Header",
"(",
"'Content-Disposition'",
",",
"'attachment'",
")",
")",
";",
"$",
"headers",
"->",
"add",
"(",
"new",
"Header",
"(",
"'Content-Type'",
",",
"'application/octet-stream'",
",",
"[",
"'filename'",
"=>",
"$",
"file",
"->",
"getFilename",
"(",
")",
"]",
")",
")",
";",
"$",
"result",
"[",
"]",
"=",
"'--body-mixed-'",
".",
"$",
"hash",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"headers",
";",
"$",
"result",
"[",
"]",
"=",
"''",
";",
"$",
"result",
"[",
"]",
"=",
"base64_encode",
"(",
"$",
"file",
"->",
"fread",
"(",
"$",
"file",
"->",
"getSize",
"(",
")",
")",
")",
";",
"}",
"return",
"implode",
"(",
"\"\\r\\n\"",
",",
"$",
"result",
")",
";",
"}"
] | This will return a message body with the attachments in
basecode64 encoding also the original message will be included
@param SplFileObject[] $files
@param string $message
@param string $contentType
@param string $hash
@return string | [
"This",
"will",
"return",
"a",
"message",
"body",
"with",
"the",
"attachments",
"in",
"basecode64",
"encoding",
"also",
"the",
"original",
"message",
"will",
"be",
"included"
] | train | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Mail/Mailer.php#L70-L97 |
romm/configuration_object | Classes/Validation/ValidatorResolver.php | ValidatorResolver.addMixedTypeValidators | protected function addMixedTypeValidators($targetClassName, GenericObjectValidator $validator)
{
foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $property) {
/*
* If the property already is already bound to an object validator,
* there is no need to do further checks.
*/
if ($this->propertyHasObjectValidator($validator, $property)) {
continue;
}
if ($this->propertyIsMixedType($targetClassName, $property)) {
/*
* The property is mixed, a validator with the `mixedTypes`
* option is added, to delegate the validator resolving to
* later (when the property is actually filled).
*/
$objectValidator = $this->createValidator(MixedTypeValidator::class);
$validator->addPropertyValidator($property, $objectValidator);
}
}
} | php | protected function addMixedTypeValidators($targetClassName, GenericObjectValidator $validator)
{
foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $property) {
/*
* If the property already is already bound to an object validator,
* there is no need to do further checks.
*/
if ($this->propertyHasObjectValidator($validator, $property)) {
continue;
}
if ($this->propertyIsMixedType($targetClassName, $property)) {
/*
* The property is mixed, a validator with the `mixedTypes`
* option is added, to delegate the validator resolving to
* later (when the property is actually filled).
*/
$objectValidator = $this->createValidator(MixedTypeValidator::class);
$validator->addPropertyValidator($property, $objectValidator);
}
}
} | [
"protected",
"function",
"addMixedTypeValidators",
"(",
"$",
"targetClassName",
",",
"GenericObjectValidator",
"$",
"validator",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"reflectionService",
"->",
"getClassPropertyNames",
"(",
"$",
"targetClassName",
")",
"as",
"$",
"property",
")",
"{",
"/*\n * If the property already is already bound to an object validator,\n * there is no need to do further checks.\n */",
"if",
"(",
"$",
"this",
"->",
"propertyHasObjectValidator",
"(",
"$",
"validator",
",",
"$",
"property",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"propertyIsMixedType",
"(",
"$",
"targetClassName",
",",
"$",
"property",
")",
")",
"{",
"/*\n * The property is mixed, a validator with the `mixedTypes`\n * option is added, to delegate the validator resolving to\n * later (when the property is actually filled).\n */",
"$",
"objectValidator",
"=",
"$",
"this",
"->",
"createValidator",
"(",
"MixedTypeValidator",
"::",
"class",
")",
";",
"$",
"validator",
"->",
"addPropertyValidator",
"(",
"$",
"property",
",",
"$",
"objectValidator",
")",
";",
"}",
"}",
"}"
] | This function will list the properties of the given class, and filter on
the ones that do not have a validator assigned yet.
@param string $targetClassName
@param GenericObjectValidator $validator | [
"This",
"function",
"will",
"list",
"the",
"properties",
"of",
"the",
"given",
"class",
"and",
"filter",
"on",
"the",
"ones",
"that",
"do",
"not",
"have",
"a",
"validator",
"assigned",
"yet",
"."
] | train | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/ValidatorResolver.php#L118-L140 |
romm/configuration_object | Classes/Validation/ValidatorResolver.php | ValidatorResolver.propertyHasObjectValidator | protected function propertyHasObjectValidator(GenericObjectValidator $validator, $property)
{
$propertiesValidators = $validator->getPropertyValidators();
if (isset($propertiesValidators[$property])) {
foreach ($propertiesValidators[$property] as $validator) {
if ($validator instanceof ObjectValidatorInterface) {
return true;
}
}
}
return false;
} | php | protected function propertyHasObjectValidator(GenericObjectValidator $validator, $property)
{
$propertiesValidators = $validator->getPropertyValidators();
if (isset($propertiesValidators[$property])) {
foreach ($propertiesValidators[$property] as $validator) {
if ($validator instanceof ObjectValidatorInterface) {
return true;
}
}
}
return false;
} | [
"protected",
"function",
"propertyHasObjectValidator",
"(",
"GenericObjectValidator",
"$",
"validator",
",",
"$",
"property",
")",
"{",
"$",
"propertiesValidators",
"=",
"$",
"validator",
"->",
"getPropertyValidators",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"propertiesValidators",
"[",
"$",
"property",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"propertiesValidators",
"[",
"$",
"property",
"]",
"as",
"$",
"validator",
")",
"{",
"if",
"(",
"$",
"validator",
"instanceof",
"ObjectValidatorInterface",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks among the existing validators of the given property if it does
already has an object validator (can be several types, like the classes
`ObjectValidator` or `ConjunctionValidator`, as long as they implement
the interface `ObjectValidatorInterface`).
If one is found, `true` is returned.
@param GenericObjectValidator $validator
@param string $property
@return bool | [
"Checks",
"among",
"the",
"existing",
"validators",
"of",
"the",
"given",
"property",
"if",
"it",
"does",
"already",
"has",
"an",
"object",
"validator",
"(",
"can",
"be",
"several",
"types",
"like",
"the",
"classes",
"ObjectValidator",
"or",
"ConjunctionValidator",
"as",
"long",
"as",
"they",
"implement",
"the",
"interface",
"ObjectValidatorInterface",
")",
"."
] | train | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/ValidatorResolver.php#L154-L167 |
romm/configuration_object | Classes/Validation/ValidatorResolver.php | ValidatorResolver.propertyIsMixedType | protected function propertyIsMixedType($className, $property)
{
$mixedType = false;
$propertySchema = $this->reflectionService->getClassSchema($className)->getProperty($property);
if ($this->classIsMixedType($propertySchema['type'])) {
$mixedType = true;
} else {
if ($this->reflectionService->isPropertyTaggedWith($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE)) {
$tags = $this->reflectionService->getPropertyTagValues($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE);
$mixedTypeClassName = reset($tags);
if ($this->classIsMixedType($mixedTypeClassName)) {
$mixedType = true;
}
}
}
return $mixedType;
} | php | protected function propertyIsMixedType($className, $property)
{
$mixedType = false;
$propertySchema = $this->reflectionService->getClassSchema($className)->getProperty($property);
if ($this->classIsMixedType($propertySchema['type'])) {
$mixedType = true;
} else {
if ($this->reflectionService->isPropertyTaggedWith($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE)) {
$tags = $this->reflectionService->getPropertyTagValues($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE);
$mixedTypeClassName = reset($tags);
if ($this->classIsMixedType($mixedTypeClassName)) {
$mixedType = true;
}
}
}
return $mixedType;
} | [
"protected",
"function",
"propertyIsMixedType",
"(",
"$",
"className",
",",
"$",
"property",
")",
"{",
"$",
"mixedType",
"=",
"false",
";",
"$",
"propertySchema",
"=",
"$",
"this",
"->",
"reflectionService",
"->",
"getClassSchema",
"(",
"$",
"className",
")",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"if",
"(",
"$",
"this",
"->",
"classIsMixedType",
"(",
"$",
"propertySchema",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"mixedType",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"reflectionService",
"->",
"isPropertyTaggedWith",
"(",
"$",
"className",
",",
"$",
"property",
",",
"MixedTypesService",
"::",
"PROPERTY_ANNOTATION_MIXED_TYPE",
")",
")",
"{",
"$",
"tags",
"=",
"$",
"this",
"->",
"reflectionService",
"->",
"getPropertyTagValues",
"(",
"$",
"className",
",",
"$",
"property",
",",
"MixedTypesService",
"::",
"PROPERTY_ANNOTATION_MIXED_TYPE",
")",
";",
"$",
"mixedTypeClassName",
"=",
"reset",
"(",
"$",
"tags",
")",
";",
"if",
"(",
"$",
"this",
"->",
"classIsMixedType",
"(",
"$",
"mixedTypeClassName",
")",
")",
"{",
"$",
"mixedType",
"=",
"true",
";",
"}",
"}",
"}",
"return",
"$",
"mixedType",
";",
"}"
] | Checks if the given property is a mixed type.
First, we check if the type of the property is a class that implements
the interface `MixedTypesInterface`.
If not, we check if the property has the annotation `@mixedTypesResolver`
with a class name that implements the interface `MixedTypesInterface`.
If one was found, `true` is returned.
@param string $className
@param string $property
@return bool | [
"Checks",
"if",
"the",
"given",
"property",
"is",
"a",
"mixed",
"type",
"."
] | train | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/ValidatorResolver.php#L184-L204 |
Dhii/validation-base | src/AbstractValidatorBase.php | AbstractValidatorBase.validate | public function validate($value)
{
try {
$this->_validate($value);
} catch (RootException $e) {
if ($e instanceof ValidationFailedExceptionInterface) {
throw $e;
}
$this->_throwValidationException($this->__('Problem validating'), null, $e, true);
}
} | php | public function validate($value)
{
try {
$this->_validate($value);
} catch (RootException $e) {
if ($e instanceof ValidationFailedExceptionInterface) {
throw $e;
}
$this->_throwValidationException($this->__('Problem validating'), null, $e, true);
}
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"_validate",
"(",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"RootException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"ValidationFailedExceptionInterface",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"_throwValidationException",
"(",
"$",
"this",
"->",
"__",
"(",
"'Problem validating'",
")",
",",
"null",
",",
"$",
"e",
",",
"true",
")",
";",
"}",
"}"
] | {@inheritdoc}
@since 0.1 | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/Dhii/validation-base/blob/9e75c5f886a2403c6989c36c2d4ffcfae158172e/src/AbstractValidatorBase.php#L39-L50 |
Dhii/validation-base | src/AbstractValidatorBase.php | AbstractValidatorBase._throwValidationException | protected function _throwValidationException(
$message = null,
$code = null,
RootException $previous = null,
$validator = null
) {
if ($validator === true) {
$validator = $this;
}
throw $this->_createValidationException($message, $code, $previous, $validator);
} | php | protected function _throwValidationException(
$message = null,
$code = null,
RootException $previous = null,
$validator = null
) {
if ($validator === true) {
$validator = $this;
}
throw $this->_createValidationException($message, $code, $previous, $validator);
} | [
"protected",
"function",
"_throwValidationException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"RootException",
"$",
"previous",
"=",
"null",
",",
"$",
"validator",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"validator",
"===",
"true",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
";",
"}",
"throw",
"$",
"this",
"->",
"_createValidationException",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
",",
"$",
"validator",
")",
";",
"}"
] | {inheritdoc}.
@since [*next-version*]
@throws ValidationException | [
"{",
"inheritdoc",
"}",
"."
] | train | https://github.com/Dhii/validation-base/blob/9e75c5f886a2403c6989c36c2d4ffcfae158172e/src/AbstractValidatorBase.php#L59-L70 |
Dhii/validation-base | src/AbstractValidatorBase.php | AbstractValidatorBase._throwValidationFailedException | protected function _throwValidationFailedException(
$message = null,
$code = null,
RootException $previous = null,
$validator = null,
$subject = null,
$validationErrors = null
) {
if ($validator === true) {
$validator = $this;
}
throw $this->_createValidationFailedException($message, $code, $previous, $validator, $subject, $validationErrors);
} | php | protected function _throwValidationFailedException(
$message = null,
$code = null,
RootException $previous = null,
$validator = null,
$subject = null,
$validationErrors = null
) {
if ($validator === true) {
$validator = $this;
}
throw $this->_createValidationFailedException($message, $code, $previous, $validator, $subject, $validationErrors);
} | [
"protected",
"function",
"_throwValidationFailedException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"RootException",
"$",
"previous",
"=",
"null",
",",
"$",
"validator",
"=",
"null",
",",
"$",
"subject",
"=",
"null",
",",
"$",
"validationErrors",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"validator",
"===",
"true",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
";",
"}",
"throw",
"$",
"this",
"->",
"_createValidationFailedException",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
",",
"$",
"validator",
",",
"$",
"subject",
",",
"$",
"validationErrors",
")",
";",
"}"
] | {inheritdoc}.
@since [*next-version*]
@throws ValidationFailedException | [
"{",
"inheritdoc",
"}",
"."
] | train | https://github.com/Dhii/validation-base/blob/9e75c5f886a2403c6989c36c2d4ffcfae158172e/src/AbstractValidatorBase.php#L79-L92 |
dpoposki/blog | src/Poposki/Blog/Persistence/InMemoryPostRepository.php | InMemoryPostRepository.findById | public function findById(PostId $postId)
{
if (isset($this->posts[$postId->getId()])) {
return $this->posts[$postId->getId()];
}
return null;
} | php | public function findById(PostId $postId)
{
if (isset($this->posts[$postId->getId()])) {
return $this->posts[$postId->getId()];
}
return null;
} | [
"public",
"function",
"findById",
"(",
"PostId",
"$",
"postId",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"posts",
"[",
"$",
"postId",
"->",
"getId",
"(",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"posts",
"[",
"$",
"postId",
"->",
"getId",
"(",
")",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dpoposki/blog/blob/656a5903b1c27bcbdd33eb1f40b0448776439fbc/src/Poposki/Blog/Persistence/InMemoryPostRepository.php#L36-L43 |
zhaoxianfang/tools | src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php | BindTrait.bind | final public function bind($nameOrFqcn, $valueOrRef)
{
$valueOrRef = static::processValue($valueOrRef, true);
if (isset($nameOrFqcn[0]) && '$' !== $nameOrFqcn[0] && !$valueOrRef instanceof Reference) {
throw new InvalidArgumentException(sprintf('Invalid binding for service "%s": named arguments must start with a "$", and FQCN must map to references. Neither applies to binding "%s".', $this->id, $nameOrFqcn));
}
$bindings = $this->definition->getBindings();
$bindings[$nameOrFqcn] = $valueOrRef;
$this->definition->setBindings($bindings);
return $this;
} | php | final public function bind($nameOrFqcn, $valueOrRef)
{
$valueOrRef = static::processValue($valueOrRef, true);
if (isset($nameOrFqcn[0]) && '$' !== $nameOrFqcn[0] && !$valueOrRef instanceof Reference) {
throw new InvalidArgumentException(sprintf('Invalid binding for service "%s": named arguments must start with a "$", and FQCN must map to references. Neither applies to binding "%s".', $this->id, $nameOrFqcn));
}
$bindings = $this->definition->getBindings();
$bindings[$nameOrFqcn] = $valueOrRef;
$this->definition->setBindings($bindings);
return $this;
} | [
"final",
"public",
"function",
"bind",
"(",
"$",
"nameOrFqcn",
",",
"$",
"valueOrRef",
")",
"{",
"$",
"valueOrRef",
"=",
"static",
"::",
"processValue",
"(",
"$",
"valueOrRef",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"nameOrFqcn",
"[",
"0",
"]",
")",
"&&",
"'$'",
"!==",
"$",
"nameOrFqcn",
"[",
"0",
"]",
"&&",
"!",
"$",
"valueOrRef",
"instanceof",
"Reference",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid binding for service \"%s\": named arguments must start with a \"$\", and FQCN must map to references. Neither applies to binding \"%s\".'",
",",
"$",
"this",
"->",
"id",
",",
"$",
"nameOrFqcn",
")",
")",
";",
"}",
"$",
"bindings",
"=",
"$",
"this",
"->",
"definition",
"->",
"getBindings",
"(",
")",
";",
"$",
"bindings",
"[",
"$",
"nameOrFqcn",
"]",
"=",
"$",
"valueOrRef",
";",
"$",
"this",
"->",
"definition",
"->",
"setBindings",
"(",
"$",
"bindings",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets bindings.
Bindings map $named or FQCN arguments to values that should be
injected in the matching parameters (of the constructor, of methods
called and of controller actions).
@param string $nameOrFqcn A parameter name with its "$" prefix, or a FQCN
@param mixed $valueOrRef The value or reference to bind
@return $this | [
"Sets",
"bindings",
"."
] | train | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php#L31-L42 |
formapro/BadaBoom | src/BadaBoom/ChainNode/Filter/AbstractFilter.php | AbstractFilter.handle | public final function handle(\Exception $exception, DataHolderInterface $data)
{
if ($this->shouldContinue($exception, $data)) {
$this->handleNextNode($exception, $data);
}
} | php | public final function handle(\Exception $exception, DataHolderInterface $data)
{
if ($this->shouldContinue($exception, $data)) {
$this->handleNextNode($exception, $data);
}
} | [
"public",
"final",
"function",
"handle",
"(",
"\\",
"Exception",
"$",
"exception",
",",
"DataHolderInterface",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldContinue",
"(",
"$",
"exception",
",",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"handleNextNode",
"(",
"$",
"exception",
",",
"$",
"data",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/formapro/BadaBoom/blob/db42dbc4a43f7070586229c0e6075fe3a781e04e/src/BadaBoom/ChainNode/Filter/AbstractFilter.php#L12-L17 |
etiennemarais/converse-api-wrapper | src/Services/Curl/RequestDispatcher.php | RequestDispatcher.execute | public function execute(\Closure $callback = null)
{
$stacks = $this->buildStacks();
foreach ($stacks as $requests) {
foreach ($requests as $request) {
$status = curl_multi_add_handle($this->handle, $request->getHandle());
if ($status !== CURLM_OK) {
throw new \Exception(sprintf(
'Unable to add request to cURL multi handle (code #%u)',
$status
));
}
}
$this->dispatch();
foreach ($requests as $request) {
$request->setRawResponse(curl_multi_getcontent($request->getHandle()));
curl_multi_remove_handle($this->handle, $request->getHandle());
if ($callback !== null) {
$callback($request->getResponse());
}
}
}
} | php | public function execute(\Closure $callback = null)
{
$stacks = $this->buildStacks();
foreach ($stacks as $requests) {
foreach ($requests as $request) {
$status = curl_multi_add_handle($this->handle, $request->getHandle());
if ($status !== CURLM_OK) {
throw new \Exception(sprintf(
'Unable to add request to cURL multi handle (code #%u)',
$status
));
}
}
$this->dispatch();
foreach ($requests as $request) {
$request->setRawResponse(curl_multi_getcontent($request->getHandle()));
curl_multi_remove_handle($this->handle, $request->getHandle());
if ($callback !== null) {
$callback($request->getResponse());
}
}
}
} | [
"public",
"function",
"execute",
"(",
"\\",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"stacks",
"=",
"$",
"this",
"->",
"buildStacks",
"(",
")",
";",
"foreach",
"(",
"$",
"stacks",
"as",
"$",
"requests",
")",
"{",
"foreach",
"(",
"$",
"requests",
"as",
"$",
"request",
")",
"{",
"$",
"status",
"=",
"curl_multi_add_handle",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"request",
"->",
"getHandle",
"(",
")",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"CURLM_OK",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Unable to add request to cURL multi handle (code #%u)'",
",",
"$",
"status",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"dispatch",
"(",
")",
";",
"foreach",
"(",
"$",
"requests",
"as",
"$",
"request",
")",
"{",
"$",
"request",
"->",
"setRawResponse",
"(",
"curl_multi_getcontent",
"(",
"$",
"request",
"->",
"getHandle",
"(",
")",
")",
")",
";",
"curl_multi_remove_handle",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"request",
"->",
"getHandle",
"(",
")",
")",
";",
"if",
"(",
"$",
"callback",
"!==",
"null",
")",
"{",
"$",
"callback",
"(",
"$",
"request",
"->",
"getResponse",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] | @param callable $callback
@throws \Exception | [
"@param",
"callable",
"$callback"
] | train | https://github.com/etiennemarais/converse-api-wrapper/blob/900f726a39697427f17aec1bdee8e8f3de298672/src/Services/Curl/RequestDispatcher.php#L73-L99 |
KDF5000/EasyThink | src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_assign.php | Smarty_Internal_Compile_Assign.compile | public function compile($args, $compiler, $parameter)
{
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
$this->required_attributes = array('var', 'value');
$this->shorttag_order = array('var', 'value');
$this->optional_attributes = array('scope');
$_nocache = 'null';
$_scope = Smarty::SCOPE_LOCAL;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// nocache ?
if ($compiler->tag_nocache || $compiler->nocache) {
$_nocache = 'true';
// create nocache var to make it know for further compiling
$compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true);
}
// scope setup
if (isset($_attr['scope'])) {
$_attr['scope'] = trim($_attr['scope'], "'\"");
if ($_attr['scope'] == 'parent') {
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL;
} else {
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
}
}
// compiled output
if (isset($parameter['smarty_internal_index'])) {
$output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
} else {
$output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);";
}
if ($_scope == Smarty::SCOPE_PARENT) {
$output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
} elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }";
}
if ( $_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
}
$output .= '?>';
return $output;
} | php | public function compile($args, $compiler, $parameter)
{
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
$this->required_attributes = array('var', 'value');
$this->shorttag_order = array('var', 'value');
$this->optional_attributes = array('scope');
$_nocache = 'null';
$_scope = Smarty::SCOPE_LOCAL;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// nocache ?
if ($compiler->tag_nocache || $compiler->nocache) {
$_nocache = 'true';
// create nocache var to make it know for further compiling
$compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true);
}
// scope setup
if (isset($_attr['scope'])) {
$_attr['scope'] = trim($_attr['scope'], "'\"");
if ($_attr['scope'] == 'parent') {
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL;
} else {
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
}
}
// compiled output
if (isset($parameter['smarty_internal_index'])) {
$output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
} else {
$output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);";
}
if ($_scope == Smarty::SCOPE_PARENT) {
$output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
} elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }";
}
if ( $_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
}
$output .= '?>';
return $output;
} | [
"public",
"function",
"compile",
"(",
"$",
"args",
",",
"$",
"compiler",
",",
"$",
"parameter",
")",
"{",
"// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append",
"$",
"this",
"->",
"required_attributes",
"=",
"array",
"(",
"'var'",
",",
"'value'",
")",
";",
"$",
"this",
"->",
"shorttag_order",
"=",
"array",
"(",
"'var'",
",",
"'value'",
")",
";",
"$",
"this",
"->",
"optional_attributes",
"=",
"array",
"(",
"'scope'",
")",
";",
"$",
"_nocache",
"=",
"'null'",
";",
"$",
"_scope",
"=",
"Smarty",
"::",
"SCOPE_LOCAL",
";",
"// check and get attributes",
"$",
"_attr",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"$",
"compiler",
",",
"$",
"args",
")",
";",
"// nocache ?",
"if",
"(",
"$",
"compiler",
"->",
"tag_nocache",
"||",
"$",
"compiler",
"->",
"nocache",
")",
"{",
"$",
"_nocache",
"=",
"'true'",
";",
"// create nocache var to make it know for further compiling",
"$",
"compiler",
"->",
"template",
"->",
"tpl_vars",
"[",
"trim",
"(",
"$",
"_attr",
"[",
"'var'",
"]",
",",
"\"'\"",
")",
"]",
"=",
"new",
"Smarty_variable",
"(",
"null",
",",
"true",
")",
";",
"}",
"// scope setup",
"if",
"(",
"isset",
"(",
"$",
"_attr",
"[",
"'scope'",
"]",
")",
")",
"{",
"$",
"_attr",
"[",
"'scope'",
"]",
"=",
"trim",
"(",
"$",
"_attr",
"[",
"'scope'",
"]",
",",
"\"'\\\"\"",
")",
";",
"if",
"(",
"$",
"_attr",
"[",
"'scope'",
"]",
"==",
"'parent'",
")",
"{",
"$",
"_scope",
"=",
"Smarty",
"::",
"SCOPE_PARENT",
";",
"}",
"elseif",
"(",
"$",
"_attr",
"[",
"'scope'",
"]",
"==",
"'root'",
")",
"{",
"$",
"_scope",
"=",
"Smarty",
"::",
"SCOPE_ROOT",
";",
"}",
"elseif",
"(",
"$",
"_attr",
"[",
"'scope'",
"]",
"==",
"'global'",
")",
"{",
"$",
"_scope",
"=",
"Smarty",
"::",
"SCOPE_GLOBAL",
";",
"}",
"else",
"{",
"$",
"compiler",
"->",
"trigger_template_error",
"(",
"'illegal value for \"scope\" attribute'",
",",
"$",
"compiler",
"->",
"lex",
"->",
"taglineno",
")",
";",
"}",
"}",
"// compiled output",
"if",
"(",
"isset",
"(",
"$",
"parameter",
"[",
"'smarty_internal_index'",
"]",
")",
")",
"{",
"$",
"output",
"=",
"\"<?php \\$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\\n\\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];\"",
";",
"}",
"else",
"{",
"$",
"output",
"=",
"\"<?php \\$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);\"",
";",
"}",
"if",
"(",
"$",
"_scope",
"==",
"Smarty",
"::",
"SCOPE_PARENT",
")",
"{",
"$",
"output",
".=",
"\"\\nif (\\$_smarty_tpl->parent != null) \\$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \\$_smarty_tpl->tpl_vars[$_attr[var]];\"",
";",
"}",
"elseif",
"(",
"$",
"_scope",
"==",
"Smarty",
"::",
"SCOPE_ROOT",
"||",
"$",
"_scope",
"==",
"Smarty",
"::",
"SCOPE_GLOBAL",
")",
"{",
"$",
"output",
".=",
"\"\\n\\$_ptr = \\$_smarty_tpl->parent; while (\\$_ptr != null) {\\$_ptr->tpl_vars[$_attr[var]] = clone \\$_smarty_tpl->tpl_vars[$_attr[var]]; \\$_ptr = \\$_ptr->parent; }\"",
";",
"}",
"if",
"(",
"$",
"_scope",
"==",
"Smarty",
"::",
"SCOPE_GLOBAL",
")",
"{",
"$",
"output",
".=",
"\"\\nSmarty::\\$global_tpl_vars[$_attr[var]] = clone \\$_smarty_tpl->tpl_vars[$_attr[var]];\"",
";",
"}",
"$",
"output",
".=",
"'?>'",
";",
"return",
"$",
"output",
";",
"}"
] | Compiles code for the {assign} tag
@param array $args array with attributes from parser
@param object $compiler compiler object
@param array $parameter array with compilation parameter
@return string compiled code | [
"Compiles",
"code",
"for",
"the",
"{",
"assign",
"}",
"tag"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_assign.php#L28-L73 |
Programie/PHPCurl | src/main/php/com/selfcoders/phpcurl/Curl.php | Curl.getInfo | public function getInfo($option = null)
{
if ($option) {
return curl_getinfo($this->handle, $option);
} else {
return curl_getinfo($this->handle);
}
} | php | public function getInfo($option = null)
{
if ($option) {
return curl_getinfo($this->handle, $option);
} else {
return curl_getinfo($this->handle);
}
} | [
"public",
"function",
"getInfo",
"(",
"$",
"option",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"option",
")",
"{",
"return",
"curl_getinfo",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"option",
")",
";",
"}",
"else",
"{",
"return",
"curl_getinfo",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"}",
"}"
] | Get information regarding a specific transfer.
@param int|null $option The option to get or null to get all information.
@return mixed If $option is given, returns its value as a string. Otherwise, returns an associative array. | [
"Get",
"information",
"regarding",
"a",
"specific",
"transfer",
"."
] | train | https://github.com/Programie/PHPCurl/blob/54ef8bba19e87654906f74b14646c1f322ea7241/src/main/php/com/selfcoders/phpcurl/Curl.php#L132-L139 |
Programie/PHPCurl | src/main/php/com/selfcoders/phpcurl/Curl.php | Curl.getHeaderContent | public function getHeaderContent()
{
if (!$this->headerFileHandle) {
return null;
}
fseek($this->headerFileHandle, 0);
$lines = array();
while ($line = trim(fgets($this->headerFileHandle), "\n\r")) {
$lines[] = $line;
}
return $lines;
} | php | public function getHeaderContent()
{
if (!$this->headerFileHandle) {
return null;
}
fseek($this->headerFileHandle, 0);
$lines = array();
while ($line = trim(fgets($this->headerFileHandle), "\n\r")) {
$lines[] = $line;
}
return $lines;
} | [
"public",
"function",
"getHeaderContent",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"headerFileHandle",
")",
"{",
"return",
"null",
";",
"}",
"fseek",
"(",
"$",
"this",
"->",
"headerFileHandle",
",",
"0",
")",
";",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"line",
"=",
"trim",
"(",
"fgets",
"(",
"$",
"this",
"->",
"headerFileHandle",
")",
",",
"\"\\n\\r\"",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"return",
"$",
"lines",
";",
"}"
] | Get the content of the header output if enabled with enabledHeaderOutput.
@return array|null The header output or null if header output was not enabled | [
"Get",
"the",
"content",
"of",
"the",
"header",
"output",
"if",
"enabled",
"with",
"enabledHeaderOutput",
"."
] | train | https://github.com/Programie/PHPCurl/blob/54ef8bba19e87654906f74b14646c1f322ea7241/src/main/php/com/selfcoders/phpcurl/Curl.php#L146-L160 |
Programie/PHPCurl | src/main/php/com/selfcoders/phpcurl/Curl.php | Curl.getVerboseContent | public function getVerboseContent()
{
if (!$this->verboseFileHandle) {
return null;
}
fseek($this->verboseFileHandle, 0);
$lines = array();
while ($line = trim(fgets($this->verboseFileHandle), "\n\r")) {
$lines[] = $line;
}
return $lines;
} | php | public function getVerboseContent()
{
if (!$this->verboseFileHandle) {
return null;
}
fseek($this->verboseFileHandle, 0);
$lines = array();
while ($line = trim(fgets($this->verboseFileHandle), "\n\r")) {
$lines[] = $line;
}
return $lines;
} | [
"public",
"function",
"getVerboseContent",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"verboseFileHandle",
")",
"{",
"return",
"null",
";",
"}",
"fseek",
"(",
"$",
"this",
"->",
"verboseFileHandle",
",",
"0",
")",
";",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"line",
"=",
"trim",
"(",
"fgets",
"(",
"$",
"this",
"->",
"verboseFileHandle",
")",
",",
"\"\\n\\r\"",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"return",
"$",
"lines",
";",
"}"
] | Get the content of the verbose output if enabled with enableVerboseOutput.
@return array|null The verbose output or null if verbose mode was not enabled | [
"Get",
"the",
"content",
"of",
"the",
"verbose",
"output",
"if",
"enabled",
"with",
"enableVerboseOutput",
"."
] | train | https://github.com/Programie/PHPCurl/blob/54ef8bba19e87654906f74b14646c1f322ea7241/src/main/php/com/selfcoders/phpcurl/Curl.php#L167-L181 |
Programie/PHPCurl | src/main/php/com/selfcoders/phpcurl/Curl.php | Curl.enableVerboseOutput | public function enableVerboseOutput()
{
$this->verboseFileHandle = tmpfile();
$this->setOpt(CURLOPT_VERBOSE, true);
$this->setOpt(CURLOPT_STDERR, $this->verboseFileHandle);
} | php | public function enableVerboseOutput()
{
$this->verboseFileHandle = tmpfile();
$this->setOpt(CURLOPT_VERBOSE, true);
$this->setOpt(CURLOPT_STDERR, $this->verboseFileHandle);
} | [
"public",
"function",
"enableVerboseOutput",
"(",
")",
"{",
"$",
"this",
"->",
"verboseFileHandle",
"=",
"tmpfile",
"(",
")",
";",
"$",
"this",
"->",
"setOpt",
"(",
"CURLOPT_VERBOSE",
",",
"true",
")",
";",
"$",
"this",
"->",
"setOpt",
"(",
"CURLOPT_STDERR",
",",
"$",
"this",
"->",
"verboseFileHandle",
")",
";",
"}"
] | Set all future requests of this instance to verbose mode.
The content of the verbose output can be retrieved later using getVerboseContent. | [
"Set",
"all",
"future",
"requests",
"of",
"this",
"instance",
"to",
"verbose",
"mode",
"."
] | train | https://github.com/Programie/PHPCurl/blob/54ef8bba19e87654906f74b14646c1f322ea7241/src/main/php/com/selfcoders/phpcurl/Curl.php#L278-L283 |
PenoaksDev/Milky-Framework | src/Milky/Account/Passwords/PasswordBrokerManager.php | PasswordBrokerManager.resolve | protected function resolve( $name )
{
$config = $this->getConfig( $name );
if ( is_null( $config ) )
throw new InvalidArgumentException( "Password resetter [{$name}] is not defined." );
// The password broker uses a token repository to validate tokens and send user
// password e-mails, as well as validating that password reset process as an
// aggregate service of sorts providing a convenient interface for resets.
return new PasswordBroker( $this->createTokenRepository( $config ), AccountManager::i()->resolveAuth( $config['provider'] ), Mailer::i(), $config['email'] );
} | php | protected function resolve( $name )
{
$config = $this->getConfig( $name );
if ( is_null( $config ) )
throw new InvalidArgumentException( "Password resetter [{$name}] is not defined." );
// The password broker uses a token repository to validate tokens and send user
// password e-mails, as well as validating that password reset process as an
// aggregate service of sorts providing a convenient interface for resets.
return new PasswordBroker( $this->createTokenRepository( $config ), AccountManager::i()->resolveAuth( $config['provider'] ), Mailer::i(), $config['email'] );
} | [
"protected",
"function",
"resolve",
"(",
"$",
"name",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"config",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Password resetter [{$name}] is not defined.\"",
")",
";",
"// The password broker uses a token repository to validate tokens and send user",
"// password e-mails, as well as validating that password reset process as an",
"// aggregate service of sorts providing a convenient interface for resets.",
"return",
"new",
"PasswordBroker",
"(",
"$",
"this",
"->",
"createTokenRepository",
"(",
"$",
"config",
")",
",",
"AccountManager",
"::",
"i",
"(",
")",
"->",
"resolveAuth",
"(",
"$",
"config",
"[",
"'provider'",
"]",
")",
",",
"Mailer",
"::",
"i",
"(",
")",
",",
"$",
"config",
"[",
"'email'",
"]",
")",
";",
"}"
] | Resolve the given broker.
@param string $name
@return PasswordBroker
@throws \InvalidArgumentException | [
"Resolve",
"the",
"given",
"broker",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Account/Passwords/PasswordBrokerManager.php#L40-L51 |
PenoaksDev/Milky-Framework | src/Milky/Account/Passwords/PasswordBrokerManager.php | PasswordBrokerManager.createTokenRepository | protected function createTokenRepository( array $config )
{
$key = Config::get( 'app.key' );
if ( Str::startsWith( $key, 'base64:' ) )
$key = base64_decode( substr( $key, 7 ) );
$connection = isset( $config['connection'] ) ? $config['connection'] : null;
return new DatabaseTokenRepository( DatabaseManager::i()->connection( $connection ), $config['table'], $key, $config['expire'] );
} | php | protected function createTokenRepository( array $config )
{
$key = Config::get( 'app.key' );
if ( Str::startsWith( $key, 'base64:' ) )
$key = base64_decode( substr( $key, 7 ) );
$connection = isset( $config['connection'] ) ? $config['connection'] : null;
return new DatabaseTokenRepository( DatabaseManager::i()->connection( $connection ), $config['table'], $key, $config['expire'] );
} | [
"protected",
"function",
"createTokenRepository",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"key",
"=",
"Config",
"::",
"get",
"(",
"'app.key'",
")",
";",
"if",
"(",
"Str",
"::",
"startsWith",
"(",
"$",
"key",
",",
"'base64:'",
")",
")",
"$",
"key",
"=",
"base64_decode",
"(",
"substr",
"(",
"$",
"key",
",",
"7",
")",
")",
";",
"$",
"connection",
"=",
"isset",
"(",
"$",
"config",
"[",
"'connection'",
"]",
")",
"?",
"$",
"config",
"[",
"'connection'",
"]",
":",
"null",
";",
"return",
"new",
"DatabaseTokenRepository",
"(",
"DatabaseManager",
"::",
"i",
"(",
")",
"->",
"connection",
"(",
"$",
"connection",
")",
",",
"$",
"config",
"[",
"'table'",
"]",
",",
"$",
"key",
",",
"$",
"config",
"[",
"'expire'",
"]",
")",
";",
"}"
] | Create a token repository instance based on the given configuration.
@param array $config
@return TokenRepositoryInterface | [
"Create",
"a",
"token",
"repository",
"instance",
"based",
"on",
"the",
"given",
"configuration",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Account/Passwords/PasswordBrokerManager.php#L59-L69 |
native5/native5-sdk-client-php | src/Native5/Identity/SecurityUtils.php | SecurityUtils.getSubject | public static function getSubject()
{
$logger = $GLOBALS['logger'];
$app = $GLOBALS['app'];
$subject = $app->getSubject();
$logger->debug('Subject authentication status = '.$subject->isAuthenticated());
if ($subject === null) {
$subject = Subject::createBuilder()->build();
$app->setSubject($subject);
}
return $subject;
} | php | public static function getSubject()
{
$logger = $GLOBALS['logger'];
$app = $GLOBALS['app'];
$subject = $app->getSubject();
$logger->debug('Subject authentication status = '.$subject->isAuthenticated());
if ($subject === null) {
$subject = Subject::createBuilder()->build();
$app->setSubject($subject);
}
return $subject;
} | [
"public",
"static",
"function",
"getSubject",
"(",
")",
"{",
"$",
"logger",
"=",
"$",
"GLOBALS",
"[",
"'logger'",
"]",
";",
"$",
"app",
"=",
"$",
"GLOBALS",
"[",
"'app'",
"]",
";",
"$",
"subject",
"=",
"$",
"app",
"->",
"getSubject",
"(",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"'Subject authentication status = '",
".",
"$",
"subject",
"->",
"isAuthenticated",
"(",
")",
")",
";",
"if",
"(",
"$",
"subject",
"===",
"null",
")",
"{",
"$",
"subject",
"=",
"Subject",
"::",
"createBuilder",
"(",
")",
"->",
"build",
"(",
")",
";",
"$",
"app",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"}",
"return",
"$",
"subject",
";",
"}"
] | getSubject Convienience method to retrieve the subject.
Subject is always retrieved from applicationContext.
If no subject is found, then a new subject is created with default properties.
@static
@access public
@return void | [
"getSubject",
"Convienience",
"method",
"to",
"retrieve",
"the",
"subject",
".",
"Subject",
"is",
"always",
"retrieved",
"from",
"applicationContext",
".",
"If",
"no",
"subject",
"is",
"found",
"then",
"a",
"new",
"subject",
"is",
"created",
"with",
"default",
"properties",
"."
] | train | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Identity/SecurityUtils.php#L83-L96 |
Finesse/QueryScribe | src/Query.php | Query.table | public function table($table, string $alias = null): self
{
$table = $this->checkStringValue('Argument $table', $table);
$this->table = $table;
$this->tableAlias = $alias;
return $this;
} | php | public function table($table, string $alias = null): self
{
$table = $this->checkStringValue('Argument $table', $table);
$this->table = $table;
$this->tableAlias = $alias;
return $this;
} | [
"public",
"function",
"table",
"(",
"$",
"table",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $table'",
",",
"$",
"table",
")",
";",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"$",
"this",
"->",
"tableAlias",
"=",
"$",
"alias",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the target table.
@param string|\Closure|self|StatementInterface $table Not prefixed table name without quotes
@param string|null $alias Table alias. Warning! Alias is not allowed in insert, update and delete queries in some
of the DBMSs.
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Sets",
"the",
"target",
"table",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L81-L88 |
Finesse/QueryScribe | src/Query.php | Query.getTableIdentifier | public function getTableIdentifier()
{
if ($this->tableAlias !== null) {
return $this->tableAlias;
}
if (is_string($this->table)) {
return $this->table;
}
return null;
} | php | public function getTableIdentifier()
{
if ($this->tableAlias !== null) {
return $this->tableAlias;
}
if (is_string($this->table)) {
return $this->table;
}
return null;
} | [
"public",
"function",
"getTableIdentifier",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tableAlias",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"tableAlias",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"table",
")",
")",
"{",
"return",
"$",
"this",
"->",
"table",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the identifier which the target table can be appealed to.
@return string|null Alias or table name. Null if the target table has no string name. | [
"Returns",
"the",
"identifier",
"which",
"the",
"target",
"table",
"can",
"be",
"appealed",
"to",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L95-L104 |
Finesse/QueryScribe | src/Query.php | Query.addUpdate | public function addUpdate(array $values): self
{
foreach ($values as $column => $value) {
if (!is_string($column)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $values indexes',
$column,
['string']
));
}
$value = $this->checkScalarOrNullValue('Argument $values['.$column.']', $value);
$this->update[$column] = $value;
}
return $this;
} | php | public function addUpdate(array $values): self
{
foreach ($values as $column => $value) {
if (!is_string($column)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $values indexes',
$column,
['string']
));
}
$value = $this->checkScalarOrNullValue('Argument $values['.$column.']', $value);
$this->update[$column] = $value;
}
return $this;
} | [
"public",
"function",
"addUpdate",
"(",
"array",
"$",
"values",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"column",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'Argument $values indexes'",
",",
"$",
"column",
",",
"[",
"'string'",
"]",
")",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"checkScalarOrNullValue",
"(",
"'Argument $values['",
".",
"$",
"column",
".",
"']'",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"update",
"[",
"$",
"column",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds values that should be updated
@param mixed[]|\Closure[]|self[]|StatementInterface[] $values Fields to update. The indexes are the columns
names, the values are the values.
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"values",
"that",
"should",
"be",
"updated"
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L115-L131 |
Finesse/QueryScribe | src/Query.php | Query.makeEmptyCopy | public function makeEmptyCopy(): self
{
$query = $this->constructEmptyCopy();
$query->setClosureResolver($this->closureResolver);
return $query;
} | php | public function makeEmptyCopy(): self
{
$query = $this->constructEmptyCopy();
$query->setClosureResolver($this->closureResolver);
return $query;
} | [
"public",
"function",
"makeEmptyCopy",
"(",
")",
":",
"self",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"constructEmptyCopy",
"(",
")",
";",
"$",
"query",
"->",
"setClosureResolver",
"(",
"$",
"this",
"->",
"closureResolver",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Makes an empty self copy with dependencies.
@return static | [
"Makes",
"an",
"empty",
"self",
"copy",
"with",
"dependencies",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L179-L184 |
Finesse/QueryScribe | src/Query.php | Query.makeCopyForCriteriaGroup | public function makeCopyForCriteriaGroup(): self
{
$query = $this->makeEmptyCopy();
$query->table = $this->table;
$query->tableAlias = $this->tableAlias;
return $query;
} | php | public function makeCopyForCriteriaGroup(): self
{
$query = $this->makeEmptyCopy();
$query->table = $this->table;
$query->tableAlias = $this->tableAlias;
return $query;
} | [
"public",
"function",
"makeCopyForCriteriaGroup",
"(",
")",
":",
"self",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"makeEmptyCopy",
"(",
")",
";",
"$",
"query",
"->",
"table",
"=",
"$",
"this",
"->",
"table",
";",
"$",
"query",
"->",
"tableAlias",
"=",
"$",
"this",
"->",
"tableAlias",
";",
"return",
"$",
"query",
";",
"}"
] | Makes a self copy with dependencies for passing to a criteria group callback.
@return static | [
"Makes",
"a",
"self",
"copy",
"with",
"dependencies",
"for",
"passing",
"to",
"a",
"criteria",
"group",
"callback",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L201-L207 |
Finesse/QueryScribe | src/Query.php | Query.apply | public function apply(callable $transform): self
{
$result = $transform($this) ?? $this;
if ($result instanceof self) {
return $result;
}
return $this->handleException(InvalidReturnValueException::create(
'The transform function return value',
$result,
['null', self::class]
));
} | php | public function apply(callable $transform): self
{
$result = $transform($this) ?? $this;
if ($result instanceof self) {
return $result;
}
return $this->handleException(InvalidReturnValueException::create(
'The transform function return value',
$result,
['null', self::class]
));
} | [
"public",
"function",
"apply",
"(",
"callable",
"$",
"transform",
")",
":",
"self",
"{",
"$",
"result",
"=",
"$",
"transform",
"(",
"$",
"this",
")",
"??",
"$",
"this",
";",
"if",
"(",
"$",
"result",
"instanceof",
"self",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidReturnValueException",
"::",
"create",
"(",
"'The transform function return value'",
",",
"$",
"result",
",",
"[",
"'null'",
",",
"self",
"::",
"class",
"]",
")",
")",
";",
"}"
] | Modifies this query by passing it through a transform function.
Warning! In contrast to the other methods, this method can both change this object and return a new object. The
returned query is the only query guaranteed to be a proper result query.
@param callable $transform The function. It recieves this query object as the first argument. It must either
change the given object or return a new query object.
@return static Result query object
@throws InvalidReturnValueException If the callback return value is wrong | [
"Modifies",
"this",
"query",
"by",
"passing",
"it",
"through",
"a",
"transform",
"function",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L220-L233 |
Finesse/QueryScribe | src/Query.php | Query.checkStringValue | protected function checkStringValue(string $name, $value)
{
if (
!is_string($value) &&
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
['string', \Closure::class, self::class, StatementInterface::class]
));
}
if ($value instanceof \Closure) {
return $this->resolveSubQueryClosure($value);
}
return $value;
} | php | protected function checkStringValue(string $name, $value)
{
if (
!is_string($value) &&
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
['string', \Closure::class, self::class, StatementInterface::class]
));
}
if ($value instanceof \Closure) {
return $this->resolveSubQueryClosure($value);
}
return $value;
} | [
"protected",
"function",
"checkStringValue",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"self",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"StatementInterface",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"$",
"name",
",",
"$",
"value",
",",
"[",
"'string'",
",",
"\\",
"Closure",
"::",
"class",
",",
"self",
"::",
"class",
",",
"StatementInterface",
"::",
"class",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"$",
"this",
"->",
"resolveSubQueryClosure",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Check that value is suitable for being a "string or subquery" property of a query. Retrieves the closure
subquery.
@param string $name Value name
@param string|\Closure|self|StatementInterface $value
@return string|self|StatementInterface
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Check",
"that",
"value",
"is",
"suitable",
"for",
"being",
"a",
"string",
"or",
"subquery",
"property",
"of",
"a",
"query",
".",
"Retrieves",
"the",
"closure",
"subquery",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L256-L276 |
Finesse/QueryScribe | src/Query.php | Query.checkIntOrNullValue | protected function checkIntOrNullValue(string $name, $value)
{
if (
$value !== null &&
!is_numeric($value) &&
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
['integer', \Closure::class, self::class, StatementInterface::class, 'null']
));
}
if (is_numeric($value)) {
$value = (int)$value;
} elseif ($value instanceof \Closure) {
return $this->resolveSubQueryClosure($value);
}
return $value;
} | php | protected function checkIntOrNullValue(string $name, $value)
{
if (
$value !== null &&
!is_numeric($value) &&
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
['integer', \Closure::class, self::class, StatementInterface::class, 'null']
));
}
if (is_numeric($value)) {
$value = (int)$value;
} elseif ($value instanceof \Closure) {
return $this->resolveSubQueryClosure($value);
}
return $value;
} | [
"protected",
"function",
"checkIntOrNullValue",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"!",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"self",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"StatementInterface",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"$",
"name",
",",
"$",
"value",
",",
"[",
"'integer'",
",",
"\\",
"Closure",
"::",
"class",
",",
"self",
"::",
"class",
",",
"StatementInterface",
"::",
"class",
",",
"'null'",
"]",
")",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"$",
"this",
"->",
"resolveSubQueryClosure",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Check that value is suitable for being a "int or null or subquery" property of a query. Retrieves the closure
subquery.
@param string $name Value name
@param int|\Closure|self|StatementInterface|null $value
@return int|self|StatementInterface|null
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Check",
"that",
"value",
"is",
"suitable",
"for",
"being",
"a",
"int",
"or",
"null",
"or",
"subquery",
"property",
"of",
"a",
"query",
".",
"Retrieves",
"the",
"closure",
"subquery",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L288-L311 |
Finesse/QueryScribe | src/Query.php | Query.checkScalarOrNullValue | protected function checkScalarOrNullValue(string $name, $value)
{
if (
$value !== null &&
!is_scalar($value) &&
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
['scalar', \Closure::class, self::class, StatementInterface::class, 'null']
));
}
if ($value instanceof \Closure) {
return $this->resolveSubQueryClosure($value);
}
return $value;
} | php | protected function checkScalarOrNullValue(string $name, $value)
{
if (
$value !== null &&
!is_scalar($value) &&
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
['scalar', \Closure::class, self::class, StatementInterface::class, 'null']
));
}
if ($value instanceof \Closure) {
return $this->resolveSubQueryClosure($value);
}
return $value;
} | [
"protected",
"function",
"checkScalarOrNullValue",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"!",
"is_scalar",
"(",
"$",
"value",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"self",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"StatementInterface",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"$",
"name",
",",
"$",
"value",
",",
"[",
"'scalar'",
",",
"\\",
"Closure",
"::",
"class",
",",
"self",
"::",
"class",
",",
"StatementInterface",
"::",
"class",
",",
"'null'",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"$",
"this",
"->",
"resolveSubQueryClosure",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Check that value is suitable for being a "scalar or null or subquery" property of a query. Retrieves the closure
subquery.
@param string $name Value name
@param mixed|\Closure|self|StatementInterface|null $value
@return mixed|self|StatementInterface|null
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Check",
"that",
"value",
"is",
"suitable",
"for",
"being",
"a",
"scalar",
"or",
"null",
"or",
"subquery",
"property",
"of",
"a",
"query",
".",
"Retrieves",
"the",
"closure",
"subquery",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L323-L344 |
Finesse/QueryScribe | src/Query.php | Query.checkSubQueryValue | protected function checkSubQueryValue(string $name, $value)
{
if (
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
[\Closure::class, self::class, StatementInterface::class]
));
}
if ($value instanceof \Closure) {
$value = $this->resolveSubQueryClosure($value);
}
return $value;
} | php | protected function checkSubQueryValue(string $name, $value)
{
if (
!($value instanceof \Closure) &&
!($value instanceof self) &&
!($value instanceof StatementInterface)
) {
return $this->handleException(InvalidArgumentException::create(
$name,
$value,
[\Closure::class, self::class, StatementInterface::class]
));
}
if ($value instanceof \Closure) {
$value = $this->resolveSubQueryClosure($value);
}
return $value;
} | [
"protected",
"function",
"checkSubQueryValue",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"self",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"StatementInterface",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"$",
"name",
",",
"$",
"value",
",",
"[",
"\\",
"Closure",
"::",
"class",
",",
"self",
"::",
"class",
",",
"StatementInterface",
"::",
"class",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"resolveSubQueryClosure",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Check that value is suitable for being a subquery property of a query. Retrieves the closure subquery.
@param string $name Value name
@param \Closure|self|StatementInterface $value
@return self|StatementInterface
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Check",
"that",
"value",
"is",
"suitable",
"for",
"being",
"a",
"subquery",
"property",
"of",
"a",
"query",
".",
"Retrieves",
"the",
"closure",
"subquery",
"."
] | train | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Query.php#L355-L374 |
Dhii/callback-abstract | src/CreateReflectionForCallableCapableTrait.php | CreateReflectionForCallableCapableTrait._createReflectionForCallable | protected function _createReflectionForCallable($callable)
{
$callable = $this->_normalizeCallable($callable);
// String or closure means function
if (is_string($callable) || ($callable instanceof Closure)) {
return $this->_createReflectionFunction($callable);
}
// Otherwise array, which means method
$object = $callable[0];
$class = is_string($object) ? $object : get_class($object);
$method = $callable[1];
return $this->_createReflectionMethod($class, $method);
} | php | protected function _createReflectionForCallable($callable)
{
$callable = $this->_normalizeCallable($callable);
// String or closure means function
if (is_string($callable) || ($callable instanceof Closure)) {
return $this->_createReflectionFunction($callable);
}
// Otherwise array, which means method
$object = $callable[0];
$class = is_string($object) ? $object : get_class($object);
$method = $callable[1];
return $this->_createReflectionMethod($class, $method);
} | [
"protected",
"function",
"_createReflectionForCallable",
"(",
"$",
"callable",
")",
"{",
"$",
"callable",
"=",
"$",
"this",
"->",
"_normalizeCallable",
"(",
"$",
"callable",
")",
";",
"// String or closure means function",
"if",
"(",
"is_string",
"(",
"$",
"callable",
")",
"||",
"(",
"$",
"callable",
"instanceof",
"Closure",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_createReflectionFunction",
"(",
"$",
"callable",
")",
";",
"}",
"// Otherwise array, which means method",
"$",
"object",
"=",
"$",
"callable",
"[",
"0",
"]",
";",
"$",
"class",
"=",
"is_string",
"(",
"$",
"object",
")",
"?",
"$",
"object",
":",
"get_class",
"(",
"$",
"object",
")",
";",
"$",
"method",
"=",
"$",
"callable",
"[",
"1",
"]",
";",
"return",
"$",
"this",
"->",
"_createReflectionMethod",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"}"
] | Creates a reflection for the given callable.
@since [*next-version*]
@param callable|Stringable|array $callable The callable, or an object that represents a function FQN, or a
callable-like array where the method is stringable.
@throws InvalidArgumentException If the callable type is invalid.
@throws OutOfRangeException If the callable format is wrong.
@throws ReflectionException If a reflection could not be created.
@return ReflectionFunction|ReflectionMethod The reflection. | [
"Creates",
"a",
"reflection",
"for",
"the",
"given",
"callable",
"."
] | train | https://github.com/Dhii/callback-abstract/blob/43ed4e99fc6ccdaf46a25d06da482a2fba8d9b19/src/CreateReflectionForCallableCapableTrait.php#L34-L49 |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Subscriber/Mock.php | Mock.addResponse | public function addResponse($response)
{
if (is_string($response)) {
$response = file_exists($response)
? $this->factory->fromMessage(file_get_contents($response))
: $this->factory->fromMessage($response);
} elseif (!($response instanceof ResponseInterface)) {
throw new \InvalidArgumentException('Response must a message '
. 'string, response object, or path to a file');
}
$this->queue[] = $response;
return $this;
} | php | public function addResponse($response)
{
if (is_string($response)) {
$response = file_exists($response)
? $this->factory->fromMessage(file_get_contents($response))
: $this->factory->fromMessage($response);
} elseif (!($response instanceof ResponseInterface)) {
throw new \InvalidArgumentException('Response must a message '
. 'string, response object, or path to a file');
}
$this->queue[] = $response;
return $this;
} | [
"public",
"function",
"addResponse",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"file_exists",
"(",
"$",
"response",
")",
"?",
"$",
"this",
"->",
"factory",
"->",
"fromMessage",
"(",
"file_get_contents",
"(",
"$",
"response",
")",
")",
":",
"$",
"this",
"->",
"factory",
"->",
"fromMessage",
"(",
"$",
"response",
")",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"response",
"instanceof",
"ResponseInterface",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Response must a message '",
".",
"'string, response object, or path to a file'",
")",
";",
"}",
"$",
"this",
"->",
"queue",
"[",
"]",
"=",
"$",
"response",
";",
"return",
"$",
"this",
";",
"}"
] | Add a response to the end of the queue
@param string|ResponseInterface $response Response or path to response file
@return self
@throws \InvalidArgumentException if a string or Response is not passed | [
"Add",
"a",
"response",
"to",
"the",
"end",
"of",
"the",
"queue"
] | train | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Subscriber/Mock.php#L90-L104 |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Subscriber/Mock.php | Mock.addMultiple | public function addMultiple(array $items)
{
foreach ($items as $item) {
if ($item instanceof RequestException) {
$this->addException($item);
} else {
$this->addResponse($item);
}
}
} | php | public function addMultiple(array $items)
{
foreach ($items as $item) {
if ($item instanceof RequestException) {
$this->addException($item);
} else {
$this->addResponse($item);
}
}
} | [
"public",
"function",
"addMultiple",
"(",
"array",
"$",
"items",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"RequestException",
")",
"{",
"$",
"this",
"->",
"addException",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addResponse",
"(",
"$",
"item",
")",
";",
"}",
"}",
"}"
] | Add multiple items to the queue
@param array $items Items to add | [
"Add",
"multiple",
"items",
"to",
"the",
"queue"
] | train | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Subscriber/Mock.php#L125-L134 |
zetta-code/doctrine-util | src/Common/DebugSql.php | DebugSql.getParamsArray | private static function getParamsArray($paramObj)
{
$parameters = array();
foreach ($paramObj as $val) {
/* @var $val \Doctrine\ORM\Query\Parameter */
$parameters[$val->getName()] = $val->getValue();
}
return $parameters;
} | php | private static function getParamsArray($paramObj)
{
$parameters = array();
foreach ($paramObj as $val) {
/* @var $val \Doctrine\ORM\Query\Parameter */
$parameters[$val->getName()] = $val->getValue();
}
return $parameters;
} | [
"private",
"static",
"function",
"getParamsArray",
"(",
"$",
"paramObj",
")",
"{",
"$",
"parameters",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"paramObj",
"as",
"$",
"val",
")",
"{",
"/* @var $val \\Doctrine\\ORM\\Query\\Parameter */",
"$",
"parameters",
"[",
"$",
"val",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"val",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Get query params list
@param ArrayCollection $paramObj
@return array | [
"Get",
"query",
"params",
"list"
] | train | https://github.com/zetta-code/doctrine-util/blob/40cf1d12c89001f85e68c7508d1b86fa1b90f00c/src/Common/DebugSql.php#L26-L35 |
zetta-code/doctrine-util | src/Common/DebugSql.php | DebugSql.getFullSQL | public static function getFullSQL($query)
{
$sql = $query->getSql();
$paramsList = self::getListParamsByDql($query->getDql());
$paramsArr = self::getParamsArray($query->getParameters());
$fullSql = '';
for ($i = 0; $i < strlen($sql); $i++) {
if ($sql[$i] == '?') {
$nameParam = array_shift($paramsList);
if (!isset($paramsArr[$nameParam])) {
$fullSql .= ':' . $nameParam;
} elseif (is_string($paramsArr[$nameParam])) {
$fullSql .= '"' . addslashes($paramsArr[$nameParam]) . '"';
} elseif (is_array($paramsArr[$nameParam])) {
$sqlArr = '';
foreach ($paramsArr[$nameParam] as $var) {
if (!empty($sqlArr))
$sqlArr .= ',';
if (is_string($var)) {
$sqlArr .= '"' . addslashes($var) . '"';
} else
$sqlArr .= $var;
}
$fullSql .= $sqlArr;
} elseif (is_object($paramsArr[$nameParam])) {
switch (get_class($paramsArr[$nameParam])) {
case 'DateTime':
$fullSql .= '\'' . $paramsArr[$nameParam]->format('Y-m-d H:i:s') . '\'';
break;
default:
$fullSql .= $paramsArr[$nameParam]->getId();
}
} else
$fullSql .= $paramsArr[$nameParam];
} else {
$fullSql .= $sql[$i];
}
}
return $fullSql;
} | php | public static function getFullSQL($query)
{
$sql = $query->getSql();
$paramsList = self::getListParamsByDql($query->getDql());
$paramsArr = self::getParamsArray($query->getParameters());
$fullSql = '';
for ($i = 0; $i < strlen($sql); $i++) {
if ($sql[$i] == '?') {
$nameParam = array_shift($paramsList);
if (!isset($paramsArr[$nameParam])) {
$fullSql .= ':' . $nameParam;
} elseif (is_string($paramsArr[$nameParam])) {
$fullSql .= '"' . addslashes($paramsArr[$nameParam]) . '"';
} elseif (is_array($paramsArr[$nameParam])) {
$sqlArr = '';
foreach ($paramsArr[$nameParam] as $var) {
if (!empty($sqlArr))
$sqlArr .= ',';
if (is_string($var)) {
$sqlArr .= '"' . addslashes($var) . '"';
} else
$sqlArr .= $var;
}
$fullSql .= $sqlArr;
} elseif (is_object($paramsArr[$nameParam])) {
switch (get_class($paramsArr[$nameParam])) {
case 'DateTime':
$fullSql .= '\'' . $paramsArr[$nameParam]->format('Y-m-d H:i:s') . '\'';
break;
default:
$fullSql .= $paramsArr[$nameParam]->getId();
}
} else
$fullSql .= $paramsArr[$nameParam];
} else {
$fullSql .= $sql[$i];
}
}
return $fullSql;
} | [
"public",
"static",
"function",
"getFullSQL",
"(",
"$",
"query",
")",
"{",
"$",
"sql",
"=",
"$",
"query",
"->",
"getSql",
"(",
")",
";",
"$",
"paramsList",
"=",
"self",
"::",
"getListParamsByDql",
"(",
"$",
"query",
"->",
"getDql",
"(",
")",
")",
";",
"$",
"paramsArr",
"=",
"self",
"::",
"getParamsArray",
"(",
"$",
"query",
"->",
"getParameters",
"(",
")",
")",
";",
"$",
"fullSql",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"sql",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"sql",
"[",
"$",
"i",
"]",
"==",
"'?'",
")",
"{",
"$",
"nameParam",
"=",
"array_shift",
"(",
"$",
"paramsList",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
")",
")",
"{",
"$",
"fullSql",
".=",
"':'",
".",
"$",
"nameParam",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
")",
")",
"{",
"$",
"fullSql",
".=",
"'\"'",
".",
"addslashes",
"(",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
")",
".",
"'\"'",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
")",
")",
"{",
"$",
"sqlArr",
"=",
"''",
";",
"foreach",
"(",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
"as",
"$",
"var",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sqlArr",
")",
")",
"$",
"sqlArr",
".=",
"','",
";",
"if",
"(",
"is_string",
"(",
"$",
"var",
")",
")",
"{",
"$",
"sqlArr",
".=",
"'\"'",
".",
"addslashes",
"(",
"$",
"var",
")",
".",
"'\"'",
";",
"}",
"else",
"$",
"sqlArr",
".=",
"$",
"var",
";",
"}",
"$",
"fullSql",
".=",
"$",
"sqlArr",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
")",
")",
"{",
"switch",
"(",
"get_class",
"(",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
")",
")",
"{",
"case",
"'DateTime'",
":",
"$",
"fullSql",
".=",
"'\\''",
".",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
".",
"'\\''",
";",
"break",
";",
"default",
":",
"$",
"fullSql",
".=",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
"->",
"getId",
"(",
")",
";",
"}",
"}",
"else",
"$",
"fullSql",
".=",
"$",
"paramsArr",
"[",
"$",
"nameParam",
"]",
";",
"}",
"else",
"{",
"$",
"fullSql",
".=",
"$",
"sql",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"return",
"$",
"fullSql",
";",
"}"
] | Get SQL from query
@param \Doctrine\ORM\Query $query
@return string | [
"Get",
"SQL",
"from",
"query"
] | train | https://github.com/zetta-code/doctrine-util/blob/40cf1d12c89001f85e68c7508d1b86fa1b90f00c/src/Common/DebugSql.php#L43-L86 |
koolkode/config | src/YamlConfigurationLoader.php | YamlConfigurationLoader.load | public function load(\SplFileInfo $source, array $params = [])
{
return (array)Yaml::parse($this->loadSource($source, $params));
} | php | public function load(\SplFileInfo $source, array $params = [])
{
return (array)Yaml::parse($this->loadSource($source, $params));
} | [
"public",
"function",
"load",
"(",
"\\",
"SplFileInfo",
"$",
"source",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"(",
"array",
")",
"Yaml",
"::",
"parse",
"(",
"$",
"this",
"->",
"loadSource",
"(",
"$",
"source",
",",
"$",
"params",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/koolkode/config/blob/ad97d80f6e4ae5f8925839488abf2d9bfcb6d7f6/src/YamlConfigurationLoader.php#L34-L37 |
koolkode/config | src/YamlConfigurationLoader.php | YamlConfigurationLoader.loadSource | protected function loadSource(\SplFileInfo $source, array $params = [])
{
$cfg = @file_get_contents($source->getPathname());
if($cfg === false)
{
throw new \RuntimeException(sprintf('Configuration source not found: "%s"', $source->getPathname()));
}
$replacements = [];
foreach($params as $k => $v)
{
$replacements['%' . $k . '%'] = trim($v);
}
return trim(strtr($cfg, $replacements));
} | php | protected function loadSource(\SplFileInfo $source, array $params = [])
{
$cfg = @file_get_contents($source->getPathname());
if($cfg === false)
{
throw new \RuntimeException(sprintf('Configuration source not found: "%s"', $source->getPathname()));
}
$replacements = [];
foreach($params as $k => $v)
{
$replacements['%' . $k . '%'] = trim($v);
}
return trim(strtr($cfg, $replacements));
} | [
"protected",
"function",
"loadSource",
"(",
"\\",
"SplFileInfo",
"$",
"source",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"cfg",
"=",
"@",
"file_get_contents",
"(",
"$",
"source",
"->",
"getPathname",
"(",
")",
")",
";",
"if",
"(",
"$",
"cfg",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Configuration source not found: \"%s\"'",
",",
"$",
"source",
"->",
"getPathname",
"(",
")",
")",
")",
";",
"}",
"$",
"replacements",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"replacements",
"[",
"'%'",
".",
"$",
"k",
".",
"'%'",
"]",
"=",
"trim",
"(",
"$",
"v",
")",
";",
"}",
"return",
"trim",
"(",
"strtr",
"(",
"$",
"cfg",
",",
"$",
"replacements",
")",
")",
";",
"}"
] | Loads the contents of the given file and replaces %-delimited placeholders
with the given values.
@param \SplFileInfo $source
@param array<string, mixed> $params
@return string
@throws \RuntimeException When the file could not be accessed. | [
"Loads",
"the",
"contents",
"of",
"the",
"given",
"file",
"and",
"replaces",
"%",
"-",
"delimited",
"placeholders",
"with",
"the",
"given",
"values",
"."
] | train | https://github.com/koolkode/config/blob/ad97d80f6e4ae5f8925839488abf2d9bfcb6d7f6/src/YamlConfigurationLoader.php#L49-L66 |
SetBased/php-abc-language-resolver-core | src/CoreLanguageResolver.php | CoreLanguageResolver.resolveLanId | private function resolveLanId(): void
{
$codes = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null);
// If HTTP_ACCEPT_LANGUAGE is not set or empty return the default language.
if (empty($codes)) $this->lanIdDefault;
$map = Abc::$babel->getInternalLanguageMap();
// Try to find the language code. Examples: en, en-US, zh, zh-Hans.
// BTW We assume HTTP_ACCEPT_LANGUAGE is sorted properly.
foreach ($codes as &$code)
{
// The official language code for Dutch in the Netherlands is nl-NL (with hyphen). But in practice we encounter
// nl_NL, nl_nl, nl-nl. Therefore, internal language codes are in lower case and with hyphen.
// Remove sorting weight, replace underscore with dash, and convert to lower case.
$code = strtolower(str_replace('_', '-', strtok($code, ';')));
if (isset($map[$code]))
{
$this->lanId = $map[$code];
return;
}
}
// We did not find the language code. Try without county code. Examples: en, zh.
foreach ($codes as $code)
{
$code = substr($code, 0, 2);
if (isset($map[$code]))
{
$this->lanId = $map[$code];
return;
}
}
// We did not find the language code. Use the ID of the default language.
$this->lanId = $this->lanIdDefault;
} | php | private function resolveLanId(): void
{
$codes = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null);
// If HTTP_ACCEPT_LANGUAGE is not set or empty return the default language.
if (empty($codes)) $this->lanIdDefault;
$map = Abc::$babel->getInternalLanguageMap();
// Try to find the language code. Examples: en, en-US, zh, zh-Hans.
// BTW We assume HTTP_ACCEPT_LANGUAGE is sorted properly.
foreach ($codes as &$code)
{
// The official language code for Dutch in the Netherlands is nl-NL (with hyphen). But in practice we encounter
// nl_NL, nl_nl, nl-nl. Therefore, internal language codes are in lower case and with hyphen.
// Remove sorting weight, replace underscore with dash, and convert to lower case.
$code = strtolower(str_replace('_', '-', strtok($code, ';')));
if (isset($map[$code]))
{
$this->lanId = $map[$code];
return;
}
}
// We did not find the language code. Try without county code. Examples: en, zh.
foreach ($codes as $code)
{
$code = substr($code, 0, 2);
if (isset($map[$code]))
{
$this->lanId = $map[$code];
return;
}
}
// We did not find the language code. Use the ID of the default language.
$this->lanId = $this->lanIdDefault;
} | [
"private",
"function",
"resolveLanId",
"(",
")",
":",
"void",
"{",
"$",
"codes",
"=",
"explode",
"(",
"','",
",",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
"??",
"null",
")",
";",
"// If HTTP_ACCEPT_LANGUAGE is not set or empty return the default language.",
"if",
"(",
"empty",
"(",
"$",
"codes",
")",
")",
"$",
"this",
"->",
"lanIdDefault",
";",
"$",
"map",
"=",
"Abc",
"::",
"$",
"babel",
"->",
"getInternalLanguageMap",
"(",
")",
";",
"// Try to find the language code. Examples: en, en-US, zh, zh-Hans.",
"// BTW We assume HTTP_ACCEPT_LANGUAGE is sorted properly.",
"foreach",
"(",
"$",
"codes",
"as",
"&",
"$",
"code",
")",
"{",
"// The official language code for Dutch in the Netherlands is nl-NL (with hyphen). But in practice we encounter",
"// nl_NL, nl_nl, nl-nl. Therefore, internal language codes are in lower case and with hyphen.",
"// Remove sorting weight, replace underscore with dash, and convert to lower case.",
"$",
"code",
"=",
"strtolower",
"(",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"strtok",
"(",
"$",
"code",
",",
"';'",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"this",
"->",
"lanId",
"=",
"$",
"map",
"[",
"$",
"code",
"]",
";",
"return",
";",
"}",
"}",
"// We did not find the language code. Try without county code. Examples: en, zh.",
"foreach",
"(",
"$",
"codes",
"as",
"$",
"code",
")",
"{",
"$",
"code",
"=",
"substr",
"(",
"$",
"code",
",",
"0",
",",
"2",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"this",
"->",
"lanId",
"=",
"$",
"map",
"[",
"$",
"code",
"]",
";",
"return",
";",
"}",
"}",
"// We did not find the language code. Use the ID of the default language.",
"$",
"this",
"->",
"lanId",
"=",
"$",
"this",
"->",
"lanIdDefault",
";",
"}"
] | Resolves the ID of the language in which the response must be drafted. | [
"Resolves",
"the",
"ID",
"of",
"the",
"language",
"in",
"which",
"the",
"response",
"must",
"be",
"drafted",
"."
] | train | https://github.com/SetBased/php-abc-language-resolver-core/blob/122b76d75c89caa4b6ef2bcbae260eddd5c3d33a/src/CoreLanguageResolver.php#L55-L97 |
praxigento/mobi_mod_downline | Plugin/Magento/Quote/Model/Quote.php | Quote.aroundGetCustomerGroupId | public function aroundGetCustomerGroupId(
\Magento\Quote\Model\Quote $subject,
\Closure $proceed
) {
/* call parent to get group ID and to process other around-plugins */
$result = $proceed();
if ($result == \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID) {
/* check referral code in registry for guest visitors */
$code = $this->hlpReferral->getReferralCode();
if ($code) {
/* return referral group id if code exists */
$result = $this->hlpConfig->getReferralsGroupReferrals();
}
}
return $result;
} | php | public function aroundGetCustomerGroupId(
\Magento\Quote\Model\Quote $subject,
\Closure $proceed
) {
/* call parent to get group ID and to process other around-plugins */
$result = $proceed();
if ($result == \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID) {
/* check referral code in registry for guest visitors */
$code = $this->hlpReferral->getReferralCode();
if ($code) {
/* return referral group id if code exists */
$result = $this->hlpConfig->getReferralsGroupReferrals();
}
}
return $result;
} | [
"public",
"function",
"aroundGetCustomerGroupId",
"(",
"\\",
"Magento",
"\\",
"Quote",
"\\",
"Model",
"\\",
"Quote",
"$",
"subject",
",",
"\\",
"Closure",
"$",
"proceed",
")",
"{",
"/* call parent to get group ID and to process other around-plugins */",
"$",
"result",
"=",
"$",
"proceed",
"(",
")",
";",
"if",
"(",
"$",
"result",
"==",
"\\",
"Magento",
"\\",
"Customer",
"\\",
"Model",
"\\",
"GroupManagement",
"::",
"NOT_LOGGED_IN_ID",
")",
"{",
"/* check referral code in registry for guest visitors */",
"$",
"code",
"=",
"$",
"this",
"->",
"hlpReferral",
"->",
"getReferralCode",
"(",
")",
";",
"if",
"(",
"$",
"code",
")",
"{",
"/* return referral group id if code exists */",
"$",
"result",
"=",
"$",
"this",
"->",
"hlpConfig",
"->",
"getReferralsGroupReferrals",
"(",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Replace NOT_LOGGED_IN group for referral customers.
@param \Magento\Quote\Model\Quote $subject
@param \Closure $proceed
@return int|mixed | [
"Replace",
"NOT_LOGGED_IN",
"group",
"for",
"referral",
"customers",
"."
] | train | https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Plugin/Magento/Quote/Model/Quote.php#L35-L50 |
Mandarin-Medien/MMCmfRoutingBundle | EventListener/AutoNodeRouteUpdateListener.php | AutoNodeRouteUpdateListener.prePersist | public function prePersist(LifecycleEventArgs $args)
{
// update child routes
$entity = $args->getEntity();
if ( $entity instanceof RoutableNodeInterface
&& $entity->hasAutoNodeRouteGeneration()
) {
$routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
$entity->addRoute($routeManager->generateAutoNodeRoute($entity));
}
return;
} | php | public function prePersist(LifecycleEventArgs $args)
{
// update child routes
$entity = $args->getEntity();
if ( $entity instanceof RoutableNodeInterface
&& $entity->hasAutoNodeRouteGeneration()
) {
$routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
$entity->addRoute($routeManager->generateAutoNodeRoute($entity));
}
return;
} | [
"public",
"function",
"prePersist",
"(",
"LifecycleEventArgs",
"$",
"args",
")",
"{",
"// update child routes",
"$",
"entity",
"=",
"$",
"args",
"->",
"getEntity",
"(",
")",
";",
"if",
"(",
"$",
"entity",
"instanceof",
"RoutableNodeInterface",
"&&",
"$",
"entity",
"->",
"hasAutoNodeRouteGeneration",
"(",
")",
")",
"{",
"$",
"routeManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'mm_cmf_routing.node_route_manager'",
")",
";",
"$",
"entity",
"->",
"addRoute",
"(",
"$",
"routeManager",
"->",
"generateAutoNodeRoute",
"(",
"$",
"entity",
")",
")",
";",
"}",
"return",
";",
"}"
] | prePersist Event
whenever a new Node is created, also create automatically a new NodeRoute
@param LifecycleEventArgs $args | [
"prePersist",
"Event",
"whenever",
"a",
"new",
"Node",
"is",
"created",
"also",
"create",
"automatically",
"a",
"new",
"NodeRoute"
] | train | https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/EventListener/AutoNodeRouteUpdateListener.php#L41-L55 |
Mandarin-Medien/MMCmfRoutingBundle | EventListener/AutoNodeRouteUpdateListener.php | AutoNodeRouteUpdateListener.onFlush | public function onFlush(OnFlushEventArgs $args)
{
$unit = $args->getEntityManager()->getUnitOfWork();
$routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
foreach($unit->getScheduledEntityUpdates() as $entity) {
if( $entity instanceof RoutableNodeInterface
&& $entity->hasAutoNodeRouteGeneration()
) {
$hasNodeRoute = false;
$routeGenerated = false;
foreach ($entity->getRoutes() as $route) {
if($route instanceof AutoNodeRoute) {
$hasNodeRoute = true;
break;
}
}
if(!$hasNodeRoute) {
$routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
$entity->addRoute($routeManager->generateAutoNodeRoute($entity));
$routeGenerated = true;
}
// check if Node::name has changed
$changed = $unit->getEntityChangeSet($entity);
if( array_key_exists('name', $changed)
|| array_key_exists('parent', $changed)
|| $routeGenerated
) {
// update all child AutoNodeRoutes
$routeManager->getAutoNodeRoutesRecursive($entity);
$unit->computeChangeSets();
}
}
}
} | php | public function onFlush(OnFlushEventArgs $args)
{
$unit = $args->getEntityManager()->getUnitOfWork();
$routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
foreach($unit->getScheduledEntityUpdates() as $entity) {
if( $entity instanceof RoutableNodeInterface
&& $entity->hasAutoNodeRouteGeneration()
) {
$hasNodeRoute = false;
$routeGenerated = false;
foreach ($entity->getRoutes() as $route) {
if($route instanceof AutoNodeRoute) {
$hasNodeRoute = true;
break;
}
}
if(!$hasNodeRoute) {
$routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
$entity->addRoute($routeManager->generateAutoNodeRoute($entity));
$routeGenerated = true;
}
// check if Node::name has changed
$changed = $unit->getEntityChangeSet($entity);
if( array_key_exists('name', $changed)
|| array_key_exists('parent', $changed)
|| $routeGenerated
) {
// update all child AutoNodeRoutes
$routeManager->getAutoNodeRoutesRecursive($entity);
$unit->computeChangeSets();
}
}
}
} | [
"public",
"function",
"onFlush",
"(",
"OnFlushEventArgs",
"$",
"args",
")",
"{",
"$",
"unit",
"=",
"$",
"args",
"->",
"getEntityManager",
"(",
")",
"->",
"getUnitOfWork",
"(",
")",
";",
"$",
"routeManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'mm_cmf_routing.node_route_manager'",
")",
";",
"foreach",
"(",
"$",
"unit",
"->",
"getScheduledEntityUpdates",
"(",
")",
"as",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"entity",
"instanceof",
"RoutableNodeInterface",
"&&",
"$",
"entity",
"->",
"hasAutoNodeRouteGeneration",
"(",
")",
")",
"{",
"$",
"hasNodeRoute",
"=",
"false",
";",
"$",
"routeGenerated",
"=",
"false",
";",
"foreach",
"(",
"$",
"entity",
"->",
"getRoutes",
"(",
")",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"instanceof",
"AutoNodeRoute",
")",
"{",
"$",
"hasNodeRoute",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"hasNodeRoute",
")",
"{",
"$",
"routeManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'mm_cmf_routing.node_route_manager'",
")",
";",
"$",
"entity",
"->",
"addRoute",
"(",
"$",
"routeManager",
"->",
"generateAutoNodeRoute",
"(",
"$",
"entity",
")",
")",
";",
"$",
"routeGenerated",
"=",
"true",
";",
"}",
"// check if Node::name has changed",
"$",
"changed",
"=",
"$",
"unit",
"->",
"getEntityChangeSet",
"(",
"$",
"entity",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'name'",
",",
"$",
"changed",
")",
"||",
"array_key_exists",
"(",
"'parent'",
",",
"$",
"changed",
")",
"||",
"$",
"routeGenerated",
")",
"{",
"// update all child AutoNodeRoutes",
"$",
"routeManager",
"->",
"getAutoNodeRoutesRecursive",
"(",
"$",
"entity",
")",
";",
"$",
"unit",
"->",
"computeChangeSets",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | onFlush Event for persisting all NodeRoutes that needs an update
@param OnFlushEventArgs $args | [
"onFlush",
"Event",
"for",
"persisting",
"all",
"NodeRoutes",
"that",
"needs",
"an",
"update"
] | train | https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/EventListener/AutoNodeRouteUpdateListener.php#L63-L106 |
TuumPHP/View | src/Renderer.php | Renderer.block | public function block($file, $data = [])
{
$block = clone($this);
$block->layout_file = null;
return $block->doRender($file, $data);
} | php | public function block($file, $data = [])
{
$block = clone($this);
$block->layout_file = null;
return $block->doRender($file, $data);
} | [
"public",
"function",
"block",
"(",
"$",
"file",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"block",
"=",
"clone",
"(",
"$",
"this",
")",
";",
"$",
"block",
"->",
"layout_file",
"=",
"null",
";",
"return",
"$",
"block",
"->",
"doRender",
"(",
"$",
"file",
",",
"$",
"data",
")",
";",
"}"
] | render a block, without default layout.
@param string $file
@param array $data
@return string | [
"render",
"a",
"block",
"without",
"default",
"layout",
"."
] | train | https://github.com/TuumPHP/View/blob/b82b20d7b8ee66b2bdbe4eb0d95fabd9bafe4b21/src/Renderer.php#L157-L162 |
TuumPHP/View | src/Renderer.php | Renderer.doRender | private function doRender($file, $data)
{
$this->view_data = array_merge($this->view_data, $data);
if (is_array($file)) {
foreach($file as $key => $val) {
$this->section->set($key, $val);
}
}
elseif(!$this->view_file = $this->getPath($file)) {
return null;
}
else {
$this->setContent($this->renderViewFile());
}
if (!isset($this->layout_file)) {
return $this->section->get('content');
}
$layout = clone($this);
$layout->layout_file = null;
return $layout->doRender($this->layout_file, $this->view_data);
} | php | private function doRender($file, $data)
{
$this->view_data = array_merge($this->view_data, $data);
if (is_array($file)) {
foreach($file as $key => $val) {
$this->section->set($key, $val);
}
}
elseif(!$this->view_file = $this->getPath($file)) {
return null;
}
else {
$this->setContent($this->renderViewFile());
}
if (!isset($this->layout_file)) {
return $this->section->get('content');
}
$layout = clone($this);
$layout->layout_file = null;
return $layout->doRender($this->layout_file, $this->view_data);
} | [
"private",
"function",
"doRender",
"(",
"$",
"file",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"view_data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"view_data",
",",
"$",
"data",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"file",
")",
")",
"{",
"foreach",
"(",
"$",
"file",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"section",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"val",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"view_file",
"=",
"$",
"this",
"->",
"getPath",
"(",
"$",
"file",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setContent",
"(",
"$",
"this",
"->",
"renderViewFile",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"layout_file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"section",
"->",
"get",
"(",
"'content'",
")",
";",
"}",
"$",
"layout",
"=",
"clone",
"(",
"$",
"this",
")",
";",
"$",
"layout",
"->",
"layout_file",
"=",
"null",
";",
"return",
"$",
"layout",
"->",
"doRender",
"(",
"$",
"this",
"->",
"layout_file",
",",
"$",
"this",
"->",
"view_data",
")",
";",
"}"
] | a simple renderer for a raw PHP file.
@param string|array $file
@param array $data
@return string
@throws \Exception | [
"a",
"simple",
"renderer",
"for",
"a",
"raw",
"PHP",
"file",
"."
] | train | https://github.com/TuumPHP/View/blob/b82b20d7b8ee66b2bdbe4eb0d95fabd9bafe4b21/src/Renderer.php#L197-L217 |
TuumPHP/View | src/Renderer.php | Renderer.renderViewFile | private function renderViewFile()
{
try {
ob_start();
extract($this->view_data);
/** @noinspection PhpIncludeInspection */
include($this->view_file);
return trim(ob_get_clean(), "\n");
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
} | php | private function renderViewFile()
{
try {
ob_start();
extract($this->view_data);
/** @noinspection PhpIncludeInspection */
include($this->view_file);
return trim(ob_get_clean(), "\n");
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
} | [
"private",
"function",
"renderViewFile",
"(",
")",
"{",
"try",
"{",
"ob_start",
"(",
")",
";",
"extract",
"(",
"$",
"this",
"->",
"view_data",
")",
";",
"/** @noinspection PhpIncludeInspection */",
"include",
"(",
"$",
"this",
"->",
"view_file",
")",
";",
"return",
"trim",
"(",
"ob_get_clean",
"(",
")",
",",
"\"\\n\"",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] | a simple renderer for a raw PHP file.
@return string
@throws \Exception | [
"a",
"simple",
"renderer",
"for",
"a",
"raw",
"PHP",
"file",
"."
] | train | https://github.com/TuumPHP/View/blob/b82b20d7b8ee66b2bdbe4eb0d95fabd9bafe4b21/src/Renderer.php#L225-L242 |
OliverMonneke/pennePHP | src/Time/DateTime.php | DateTime.add | public function add($string)
{
$this->timestamp = $this->getTimestamp() + $this->evaluateDateString($string);
return $this;
} | php | public function add($string)
{
$this->timestamp = $this->getTimestamp() + $this->evaluateDateString($string);
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"string",
")",
"{",
"$",
"this",
"->",
"timestamp",
"=",
"$",
"this",
"->",
"getTimestamp",
"(",
")",
"+",
"$",
"this",
"->",
"evaluateDateString",
"(",
"$",
"string",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a specific period
@param string $string The period to add
@return DateTime | [
"Add",
"a",
"specific",
"period"
] | train | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Time/DateTime.php#L94-L99 |
OliverMonneke/pennePHP | src/Time/DateTime.php | DateTime.sub | public function sub($string)
{
$this->timestamp = $this->getTimestamp() - $this->evaluateDateString($string);
return $this;
} | php | public function sub($string)
{
$this->timestamp = $this->getTimestamp() - $this->evaluateDateString($string);
return $this;
} | [
"public",
"function",
"sub",
"(",
"$",
"string",
")",
"{",
"$",
"this",
"->",
"timestamp",
"=",
"$",
"this",
"->",
"getTimestamp",
"(",
")",
"-",
"$",
"this",
"->",
"evaluateDateString",
"(",
"$",
"string",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Subtract a specific period
@param string $string The period
@return DateTime | [
"Subtract",
"a",
"specific",
"period"
] | train | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Time/DateTime.php#L108-L113 |
OliverMonneke/pennePHP | src/Time/DateTime.php | DateTime.evaluateDateString | protected function evaluateDateString($string)
{
$seconds = 1;
$matches = [];
preg_match('/^([0-9]*)([s|M|h|d|m|y])$/', $string, $matches);
switch ($matches[2]) {
case 's':
$seconds = $matches[1];
break;
case 'M':
$seconds = $this->evaluateDateString(60 * $matches[1] . 's');
break;
case 'h':
$seconds = $this->evaluateDateString(60 * $matches[1] . 'M');
break;
case 'd':
$seconds = $this->evaluateDateString(24 * $matches[1] . 'h');
break;
case 'm':
$seconds = $this->evaluateDateString(30 * $matches[1] . 'd');
break;
case 'y':
$seconds = $this->evaluateDateString(12 * $matches[1] . 'm');
break;
}
return $seconds;
} | php | protected function evaluateDateString($string)
{
$seconds = 1;
$matches = [];
preg_match('/^([0-9]*)([s|M|h|d|m|y])$/', $string, $matches);
switch ($matches[2]) {
case 's':
$seconds = $matches[1];
break;
case 'M':
$seconds = $this->evaluateDateString(60 * $matches[1] . 's');
break;
case 'h':
$seconds = $this->evaluateDateString(60 * $matches[1] . 'M');
break;
case 'd':
$seconds = $this->evaluateDateString(24 * $matches[1] . 'h');
break;
case 'm':
$seconds = $this->evaluateDateString(30 * $matches[1] . 'd');
break;
case 'y':
$seconds = $this->evaluateDateString(12 * $matches[1] . 'm');
break;
}
return $seconds;
} | [
"protected",
"function",
"evaluateDateString",
"(",
"$",
"string",
")",
"{",
"$",
"seconds",
"=",
"1",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"preg_match",
"(",
"'/^([0-9]*)([s|M|h|d|m|y])$/'",
",",
"$",
"string",
",",
"$",
"matches",
")",
";",
"switch",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"{",
"case",
"'s'",
":",
"$",
"seconds",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"break",
";",
"case",
"'M'",
":",
"$",
"seconds",
"=",
"$",
"this",
"->",
"evaluateDateString",
"(",
"60",
"*",
"$",
"matches",
"[",
"1",
"]",
".",
"'s'",
")",
";",
"break",
";",
"case",
"'h'",
":",
"$",
"seconds",
"=",
"$",
"this",
"->",
"evaluateDateString",
"(",
"60",
"*",
"$",
"matches",
"[",
"1",
"]",
".",
"'M'",
")",
";",
"break",
";",
"case",
"'d'",
":",
"$",
"seconds",
"=",
"$",
"this",
"->",
"evaluateDateString",
"(",
"24",
"*",
"$",
"matches",
"[",
"1",
"]",
".",
"'h'",
")",
";",
"break",
";",
"case",
"'m'",
":",
"$",
"seconds",
"=",
"$",
"this",
"->",
"evaluateDateString",
"(",
"30",
"*",
"$",
"matches",
"[",
"1",
"]",
".",
"'d'",
")",
";",
"break",
";",
"case",
"'y'",
":",
"$",
"seconds",
"=",
"$",
"this",
"->",
"evaluateDateString",
"(",
"12",
"*",
"$",
"matches",
"[",
"1",
"]",
".",
"'m'",
")",
";",
"break",
";",
"}",
"return",
"$",
"seconds",
";",
"}"
] | Convert string to seconds
@param string $string The string
@return int | [
"Convert",
"string",
"to",
"seconds"
] | train | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Time/DateTime.php#L122-L150 |
eliasis-framework/wp-plugin-rating | src/controller/class-main.php | Main.get_plugin_rating | public function get_plugin_rating( $slug, $ratings = null ) {
$ratings = $ratings ?: [
1 => 0,
2 => 0,
3 => 0,
4 => 0,
5 => 1,
];
$plugins_url = Component::WP_Plugin_Rating()->getOption(
'url',
'wp-plugins'
);
$url = $plugins_url . $slug . '/reviews/#new-post';
$data['plugin-url-review'] = $url;
if ( Plugin::exists( 'WP_Plugin_Info' ) ) {
$info = Plugin::WP_Plugin_Info()->getControllerInstance( 'Main' );
$rating = $info->get( 'ratings', $slug );
$ratings = ( false !== $rating ) ? $rating : $ratings;
}
$total = 0;
$voters = array_sum( $ratings );
foreach ( $ratings as $stars => $votes ) {
$total += $stars * $votes;
}
$rating = $total ? $total / $voters : 0;
$data['stars'] = $this->prepare_stars( $rating );
$this->render( $data );
} | php | public function get_plugin_rating( $slug, $ratings = null ) {
$ratings = $ratings ?: [
1 => 0,
2 => 0,
3 => 0,
4 => 0,
5 => 1,
];
$plugins_url = Component::WP_Plugin_Rating()->getOption(
'url',
'wp-plugins'
);
$url = $plugins_url . $slug . '/reviews/#new-post';
$data['plugin-url-review'] = $url;
if ( Plugin::exists( 'WP_Plugin_Info' ) ) {
$info = Plugin::WP_Plugin_Info()->getControllerInstance( 'Main' );
$rating = $info->get( 'ratings', $slug );
$ratings = ( false !== $rating ) ? $rating : $ratings;
}
$total = 0;
$voters = array_sum( $ratings );
foreach ( $ratings as $stars => $votes ) {
$total += $stars * $votes;
}
$rating = $total ? $total / $voters : 0;
$data['stars'] = $this->prepare_stars( $rating );
$this->render( $data );
} | [
"public",
"function",
"get_plugin_rating",
"(",
"$",
"slug",
",",
"$",
"ratings",
"=",
"null",
")",
"{",
"$",
"ratings",
"=",
"$",
"ratings",
"?",
":",
"[",
"1",
"=>",
"0",
",",
"2",
"=>",
"0",
",",
"3",
"=>",
"0",
",",
"4",
"=>",
"0",
",",
"5",
"=>",
"1",
",",
"]",
";",
"$",
"plugins_url",
"=",
"Component",
"::",
"WP_Plugin_Rating",
"(",
")",
"->",
"getOption",
"(",
"'url'",
",",
"'wp-plugins'",
")",
";",
"$",
"url",
"=",
"$",
"plugins_url",
".",
"$",
"slug",
".",
"'/reviews/#new-post'",
";",
"$",
"data",
"[",
"'plugin-url-review'",
"]",
"=",
"$",
"url",
";",
"if",
"(",
"Plugin",
"::",
"exists",
"(",
"'WP_Plugin_Info'",
")",
")",
"{",
"$",
"info",
"=",
"Plugin",
"::",
"WP_Plugin_Info",
"(",
")",
"->",
"getControllerInstance",
"(",
"'Main'",
")",
";",
"$",
"rating",
"=",
"$",
"info",
"->",
"get",
"(",
"'ratings'",
",",
"$",
"slug",
")",
";",
"$",
"ratings",
"=",
"(",
"false",
"!==",
"$",
"rating",
")",
"?",
"$",
"rating",
":",
"$",
"ratings",
";",
"}",
"$",
"total",
"=",
"0",
";",
"$",
"voters",
"=",
"array_sum",
"(",
"$",
"ratings",
")",
";",
"foreach",
"(",
"$",
"ratings",
"as",
"$",
"stars",
"=>",
"$",
"votes",
")",
"{",
"$",
"total",
"+=",
"$",
"stars",
"*",
"$",
"votes",
";",
"}",
"$",
"rating",
"=",
"$",
"total",
"?",
"$",
"total",
"/",
"$",
"voters",
":",
"0",
";",
"$",
"data",
"[",
"'stars'",
"]",
"=",
"$",
"this",
"->",
"prepare_stars",
"(",
"$",
"rating",
")",
";",
"$",
"this",
"->",
"render",
"(",
"$",
"data",
")",
";",
"}"
] | Get plugin Rating.
@param string $slug → WordPress plugin slug.
@param array $ratings → default ratings if plugin not exists. | [
"Get",
"plugin",
"Rating",
"."
] | train | https://github.com/eliasis-framework/wp-plugin-rating/blob/6fbdb0d5f83357d1de0c6796936c023cbdd33d4e/src/controller/class-main.php#L30-L68 |
eliasis-framework/wp-plugin-rating | src/controller/class-main.php | Main.prepare_stars | protected function prepare_stars( $rating ) {
$stars = [];
$full_star = (int) floor( $rating );
$half_star = ( ( $rating - $full_star ) > 0 ) ? true : false;
for ( $i = 0; $i < $full_star; $i++ ) {
$stars[] = 'filled';
}
if ( $half_star ) {
$stars[] = 'half';
}
for ( $i = 0; $i < ( 5 - $full_star ); $i++ ) {
$stars[] = 'empty';
}
return array_reverse( $stars );
} | php | protected function prepare_stars( $rating ) {
$stars = [];
$full_star = (int) floor( $rating );
$half_star = ( ( $rating - $full_star ) > 0 ) ? true : false;
for ( $i = 0; $i < $full_star; $i++ ) {
$stars[] = 'filled';
}
if ( $half_star ) {
$stars[] = 'half';
}
for ( $i = 0; $i < ( 5 - $full_star ); $i++ ) {
$stars[] = 'empty';
}
return array_reverse( $stars );
} | [
"protected",
"function",
"prepare_stars",
"(",
"$",
"rating",
")",
"{",
"$",
"stars",
"=",
"[",
"]",
";",
"$",
"full_star",
"=",
"(",
"int",
")",
"floor",
"(",
"$",
"rating",
")",
";",
"$",
"half_star",
"=",
"(",
"(",
"$",
"rating",
"-",
"$",
"full_star",
")",
">",
"0",
")",
"?",
"true",
":",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"full_star",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stars",
"[",
"]",
"=",
"'filled'",
";",
"}",
"if",
"(",
"$",
"half_star",
")",
"{",
"$",
"stars",
"[",
"]",
"=",
"'half'",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"(",
"5",
"-",
"$",
"full_star",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stars",
"[",
"]",
"=",
"'empty'",
";",
"}",
"return",
"array_reverse",
"(",
"$",
"stars",
")",
";",
"}"
] | Prepare states for each star.
@param float|int $rating → plugin rating.
@return array $rating → state for the five stars | [
"Prepare",
"states",
"for",
"each",
"star",
"."
] | train | https://github.com/eliasis-framework/wp-plugin-rating/blob/6fbdb0d5f83357d1de0c6796936c023cbdd33d4e/src/controller/class-main.php#L77-L96 |
eliasis-framework/wp-plugin-rating | src/controller/class-main.php | Main.render | protected function render( $data ) {
$template = Component::WP_Plugin_Rating()->getOption( 'path', 'template' );
$this->view->renderizate( $template, 'component', $data );
} | php | protected function render( $data ) {
$template = Component::WP_Plugin_Rating()->getOption( 'path', 'template' );
$this->view->renderizate( $template, 'component', $data );
} | [
"protected",
"function",
"render",
"(",
"$",
"data",
")",
"{",
"$",
"template",
"=",
"Component",
"::",
"WP_Plugin_Rating",
"(",
")",
"->",
"getOption",
"(",
"'path'",
",",
"'template'",
")",
";",
"$",
"this",
"->",
"view",
"->",
"renderizate",
"(",
"$",
"template",
",",
"'component'",
",",
"$",
"data",
")",
";",
"}"
] | Renderizate admin page.
@param array $data → data to render in the view. | [
"Renderizate",
"admin",
"page",
"."
] | train | https://github.com/eliasis-framework/wp-plugin-rating/blob/6fbdb0d5f83357d1de0c6796936c023cbdd33d4e/src/controller/class-main.php#L103-L108 |
ivopetkov/data-object | src/DataListToArrayTrait.php | DataListToArrayTrait.toArray | public function toArray(): array
{
$this->internalDataListUpdate();
// Copied from DataObjectToArrayTrait. Do not modify here !!!
$toArray = function($object) use (&$toArray) {
$result = [];
$vars = get_object_vars($object);
foreach ($vars as $name => $value) {
if ($name !== 'internalDataObjectData') {
$reflectionProperty = new \ReflectionProperty($object, $name);
if ($reflectionProperty->isPublic()) {
$result[$name] = null;
}
}
}
if (isset($object->internalDataObjectData)) {
foreach ($object->internalDataObjectData as $name => $value) {
$result[substr($name, 1)] = null;
}
}
ksort($result);
foreach ($result as $name => $null) {
$value = $object instanceof \ArrayAccess ? $object[$name] : (isset($object->$name) ? $object->$name : null);
if (is_object($value)) {
if (method_exists($value, 'toArray')) {
$result[$name] = $value->toArray();
} else {
if ($value instanceof \DateTime) {
$result[$name] = $value->format('c');
} else {
$propertyVars = $toArray($value);
foreach ($propertyVars as $propertyVarName => $propertyVarValue) {
if (is_object($propertyVarValue)) {
$propertyVars[$propertyVarName] = $toArray($propertyVarValue);
}
}
$result[$name] = $propertyVars;
}
}
} else {
$result[$name] = $value;
}
}
return $result;
};
$result = [];
foreach ($this->internalDataListData as $index => $object) {
$object = $this->internalDataListUpdateValueIfNeeded($this->internalDataListData, $index);
if (method_exists($object, 'toArray')) {
$result[] = $object->toArray();
} else {
$result[] = $toArray($object);
}
}
return $result;
} | php | public function toArray(): array
{
$this->internalDataListUpdate();
// Copied from DataObjectToArrayTrait. Do not modify here !!!
$toArray = function($object) use (&$toArray) {
$result = [];
$vars = get_object_vars($object);
foreach ($vars as $name => $value) {
if ($name !== 'internalDataObjectData') {
$reflectionProperty = new \ReflectionProperty($object, $name);
if ($reflectionProperty->isPublic()) {
$result[$name] = null;
}
}
}
if (isset($object->internalDataObjectData)) {
foreach ($object->internalDataObjectData as $name => $value) {
$result[substr($name, 1)] = null;
}
}
ksort($result);
foreach ($result as $name => $null) {
$value = $object instanceof \ArrayAccess ? $object[$name] : (isset($object->$name) ? $object->$name : null);
if (is_object($value)) {
if (method_exists($value, 'toArray')) {
$result[$name] = $value->toArray();
} else {
if ($value instanceof \DateTime) {
$result[$name] = $value->format('c');
} else {
$propertyVars = $toArray($value);
foreach ($propertyVars as $propertyVarName => $propertyVarValue) {
if (is_object($propertyVarValue)) {
$propertyVars[$propertyVarName] = $toArray($propertyVarValue);
}
}
$result[$name] = $propertyVars;
}
}
} else {
$result[$name] = $value;
}
}
return $result;
};
$result = [];
foreach ($this->internalDataListData as $index => $object) {
$object = $this->internalDataListUpdateValueIfNeeded($this->internalDataListData, $index);
if (method_exists($object, 'toArray')) {
$result[] = $object->toArray();
} else {
$result[] = $toArray($object);
}
}
return $result;
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"this",
"->",
"internalDataListUpdate",
"(",
")",
";",
"// Copied from DataObjectToArrayTrait. Do not modify here !!!",
"$",
"toArray",
"=",
"function",
"(",
"$",
"object",
")",
"use",
"(",
"&",
"$",
"toArray",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"'internalDataObjectData'",
")",
"{",
"$",
"reflectionProperty",
"=",
"new",
"\\",
"ReflectionProperty",
"(",
"$",
"object",
",",
"$",
"name",
")",
";",
"if",
"(",
"$",
"reflectionProperty",
"->",
"isPublic",
"(",
")",
")",
"{",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"null",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"object",
"->",
"internalDataObjectData",
")",
")",
"{",
"foreach",
"(",
"$",
"object",
"->",
"internalDataObjectData",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"result",
"[",
"substr",
"(",
"$",
"name",
",",
"1",
")",
"]",
"=",
"null",
";",
"}",
"}",
"ksort",
"(",
"$",
"result",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"name",
"=>",
"$",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"object",
"instanceof",
"\\",
"ArrayAccess",
"?",
"$",
"object",
"[",
"$",
"name",
"]",
":",
"(",
"isset",
"(",
"$",
"object",
"->",
"$",
"name",
")",
"?",
"$",
"object",
"->",
"$",
"name",
":",
"null",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"value",
",",
"'toArray'",
")",
")",
"{",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
"->",
"toArray",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
"->",
"format",
"(",
"'c'",
")",
";",
"}",
"else",
"{",
"$",
"propertyVars",
"=",
"$",
"toArray",
"(",
"$",
"value",
")",
";",
"foreach",
"(",
"$",
"propertyVars",
"as",
"$",
"propertyVarName",
"=>",
"$",
"propertyVarValue",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"propertyVarValue",
")",
")",
"{",
"$",
"propertyVars",
"[",
"$",
"propertyVarName",
"]",
"=",
"$",
"toArray",
"(",
"$",
"propertyVarValue",
")",
";",
"}",
"}",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"propertyVars",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"internalDataListData",
"as",
"$",
"index",
"=>",
"$",
"object",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"internalDataListUpdateValueIfNeeded",
"(",
"$",
"this",
"->",
"internalDataListData",
",",
"$",
"index",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"object",
",",
"'toArray'",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"object",
"->",
"toArray",
"(",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"toArray",
"(",
"$",
"object",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the list data converted as an array.
@return array The list data converted as an array.
@throws \InvalidArgumentException | [
"Returns",
"the",
"list",
"data",
"converted",
"as",
"an",
"array",
"."
] | train | https://github.com/ivopetkov/data-object/blob/024039017fd9e6e3aca6edbad79aaf45764b8991/src/DataListToArrayTrait.php#L24-L81 |
rrolt/activehelper | src/Digithis/Activehelper/Activehelper.php | Activehelper.link | public function link($routes, $url, $value = '', $attributes = array('class' => 'active'))
{
if(empty($value))
{
$value = $url;
}
$output = '<a href="'.$url.'"';
if($this->is($routes))
{
$output.= $this->putAttributes($attributes);
}
$output.= '>'.$value.'</a>';
return $output;
} | php | public function link($routes, $url, $value = '', $attributes = array('class' => 'active'))
{
if(empty($value))
{
$value = $url;
}
$output = '<a href="'.$url.'"';
if($this->is($routes))
{
$output.= $this->putAttributes($attributes);
}
$output.= '>'.$value.'</a>';
return $output;
} | [
"public",
"function",
"link",
"(",
"$",
"routes",
",",
"$",
"url",
",",
"$",
"value",
"=",
"''",
",",
"$",
"attributes",
"=",
"array",
"(",
"'class'",
"=>",
"'active'",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"url",
";",
"}",
"$",
"output",
"=",
"'<a href=\"'",
".",
"$",
"url",
".",
"'\"'",
";",
"if",
"(",
"$",
"this",
"->",
"is",
"(",
"$",
"routes",
")",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"putAttributes",
"(",
"$",
"attributes",
")",
";",
"}",
"$",
"output",
".=",
"'>'",
".",
"$",
"value",
".",
"'</a>'",
";",
"return",
"$",
"output",
";",
"}"
] | Generate link with active state.
@param array $routes
@param string $url
@param string $value
@param array $attributes
@return string | [
"Generate",
"link",
"with",
"active",
"state",
"."
] | train | https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L38-L55 |
rrolt/activehelper | src/Digithis/Activehelper/Activehelper.php | Activehelper.is | public function is()
{
$this->routes = array();
foreach(func_get_args() as $param)
{
if(!is_array($param))
{
$this->routes[] = $param;
continue;
}
foreach ($param as $p)
{
$this->routes[] = $p;
}
}
$this->request = Request::path();
$this->parseRoutes();
foreach($this->routes as $route)
{
if(!Request::is($route))
{
continue;
}
foreach($this->bad_routes as $bad_route)
{
if(str_is($bad_route, $this->request))
{
return false;
}
}
return true;
}
return false;
} | php | public function is()
{
$this->routes = array();
foreach(func_get_args() as $param)
{
if(!is_array($param))
{
$this->routes[] = $param;
continue;
}
foreach ($param as $p)
{
$this->routes[] = $p;
}
}
$this->request = Request::path();
$this->parseRoutes();
foreach($this->routes as $route)
{
if(!Request::is($route))
{
continue;
}
foreach($this->bad_routes as $bad_route)
{
if(str_is($bad_route, $this->request))
{
return false;
}
}
return true;
}
return false;
} | [
"public",
"function",
"is",
"(",
")",
"{",
"$",
"this",
"->",
"routes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"param",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"[",
"]",
"=",
"$",
"param",
";",
"continue",
";",
"}",
"foreach",
"(",
"$",
"param",
"as",
"$",
"p",
")",
"{",
"$",
"this",
"->",
"routes",
"[",
"]",
"=",
"$",
"p",
";",
"}",
"}",
"$",
"this",
"->",
"request",
"=",
"Request",
"::",
"path",
"(",
")",
";",
"$",
"this",
"->",
"parseRoutes",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"Request",
"::",
"is",
"(",
"$",
"route",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"bad_routes",
"as",
"$",
"bad_route",
")",
"{",
"if",
"(",
"str_is",
"(",
"$",
"bad_route",
",",
"$",
"this",
"->",
"request",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Get current state.
@return boolean | [
"Get",
"current",
"state",
"."
] | train | https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L62-L103 |
rrolt/activehelper | src/Digithis/Activehelper/Activehelper.php | Activehelper.parseRoutes | private function parseRoutes()
{
$this->bad_routes = array();
foreach($this->routes as $r => $route)
{
if (strpos($route, 'not:') !== false)
{
$bad_route = substr($route, strpos($route, "not:")+4);
$this->bad_routes[] = $bad_route;
unset($this->routes[$r]);
}
}
} | php | private function parseRoutes()
{
$this->bad_routes = array();
foreach($this->routes as $r => $route)
{
if (strpos($route, 'not:') !== false)
{
$bad_route = substr($route, strpos($route, "not:")+4);
$this->bad_routes[] = $bad_route;
unset($this->routes[$r]);
}
}
} | [
"private",
"function",
"parseRoutes",
"(",
")",
"{",
"$",
"this",
"->",
"bad_routes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"r",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"route",
",",
"'not:'",
")",
"!==",
"false",
")",
"{",
"$",
"bad_route",
"=",
"substr",
"(",
"$",
"route",
",",
"strpos",
"(",
"$",
"route",
",",
"\"not:\"",
")",
"+",
"4",
")",
";",
"$",
"this",
"->",
"bad_routes",
"[",
"]",
"=",
"$",
"bad_route",
";",
"unset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"r",
"]",
")",
";",
"}",
"}",
"}"
] | Separate routes in clean routes and excluded routes.
@param array $route
@return void | [
"Separate",
"routes",
"in",
"clean",
"routes",
"and",
"excluded",
"routes",
"."
] | train | https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L126-L141 |
rrolt/activehelper | src/Digithis/Activehelper/Activehelper.php | Activehelper.putAttributes | private function putAttributes($attributes)
{
$output = '';
foreach($attributes as $attribute => $value)
{
$output.= ' '.$attribute. '="'.$value.'"';
}
return $output;
} | php | private function putAttributes($attributes)
{
$output = '';
foreach($attributes as $attribute => $value)
{
$output.= ' '.$attribute. '="'.$value.'"';
}
return $output;
} | [
"private",
"function",
"putAttributes",
"(",
"$",
"attributes",
")",
"{",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"output",
".=",
"' '",
".",
"$",
"attribute",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Attributes to string.
@param array $attributes
@return string | [
"Attributes",
"to",
"string",
"."
] | train | https://github.com/rrolt/activehelper/blob/eb29ef0aee8944a391be2b886579effb648e4909/src/Digithis/Activehelper/Activehelper.php#L149-L159 |
fiiSoft/fiisoft-tasks-queue | src/TasksQueue/Worker/QueueWorker.php | QueueWorker.setMinimalLogLevel | public function setMinimalLogLevel($minLevel)
{
$this->logger->setMinLevel($minLevel);
$this->commandHandler->setMinimalLogLevel($minLevel);
$this->commandQueue->setMinimalLogLevel($minLevel);
} | php | public function setMinimalLogLevel($minLevel)
{
$this->logger->setMinLevel($minLevel);
$this->commandHandler->setMinimalLogLevel($minLevel);
$this->commandQueue->setMinimalLogLevel($minLevel);
} | [
"public",
"function",
"setMinimalLogLevel",
"(",
"$",
"minLevel",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"setMinLevel",
"(",
"$",
"minLevel",
")",
";",
"$",
"this",
"->",
"commandHandler",
"->",
"setMinimalLogLevel",
"(",
"$",
"minLevel",
")",
";",
"$",
"this",
"->",
"commandQueue",
"->",
"setMinimalLogLevel",
"(",
"$",
"minLevel",
")",
";",
"}"
] | Set minimal level of messages logged by logger.
@param string $minLevel
@return void | [
"Set",
"minimal",
"level",
"of",
"messages",
"logged",
"by",
"logger",
"."
] | train | https://github.com/fiiSoft/fiisoft-tasks-queue/blob/0c5d03f8e6f0fbe023f45e84d3db469dbea476ae/src/TasksQueue/Worker/QueueWorker.php#L57-L62 |
fiiSoft/fiisoft-tasks-queue | src/TasksQueue/Worker/QueueWorker.php | QueueWorker.runOnce | public function runOnce($wait = true, $exitOnError = null)
{
$command = $this->commandQueue->getNextCommand($wait);
if ($command) {
$this->logActivity('Handle command: '.$command->getName());
try {
$this->commandHandler->handle($command);
} catch (Exception $e) {
$this->logCatchedException($e);
$this->logNotice('Requeue command '.$command->getName().' after error');
$this->commandQueue->requeueCommand($command);
if ($exitOnError === true
|| ($exitOnError === null && $this->exitOnError)
|| $e->getCode() > 0
) {
throw $e;
}
return true;
}
$this->commandQueue->confirmCommandHandled($command);
return true;
}
return false;
} | php | public function runOnce($wait = true, $exitOnError = null)
{
$command = $this->commandQueue->getNextCommand($wait);
if ($command) {
$this->logActivity('Handle command: '.$command->getName());
try {
$this->commandHandler->handle($command);
} catch (Exception $e) {
$this->logCatchedException($e);
$this->logNotice('Requeue command '.$command->getName().' after error');
$this->commandQueue->requeueCommand($command);
if ($exitOnError === true
|| ($exitOnError === null && $this->exitOnError)
|| $e->getCode() > 0
) {
throw $e;
}
return true;
}
$this->commandQueue->confirmCommandHandled($command);
return true;
}
return false;
} | [
"public",
"function",
"runOnce",
"(",
"$",
"wait",
"=",
"true",
",",
"$",
"exitOnError",
"=",
"null",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"commandQueue",
"->",
"getNextCommand",
"(",
"$",
"wait",
")",
";",
"if",
"(",
"$",
"command",
")",
"{",
"$",
"this",
"->",
"logActivity",
"(",
"'Handle command: '",
".",
"$",
"command",
"->",
"getName",
"(",
")",
")",
";",
"try",
"{",
"$",
"this",
"->",
"commandHandler",
"->",
"handle",
"(",
"$",
"command",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"logCatchedException",
"(",
"$",
"e",
")",
";",
"$",
"this",
"->",
"logNotice",
"(",
"'Requeue command '",
".",
"$",
"command",
"->",
"getName",
"(",
")",
".",
"' after error'",
")",
";",
"$",
"this",
"->",
"commandQueue",
"->",
"requeueCommand",
"(",
"$",
"command",
")",
";",
"if",
"(",
"$",
"exitOnError",
"===",
"true",
"||",
"(",
"$",
"exitOnError",
"===",
"null",
"&&",
"$",
"this",
"->",
"exitOnError",
")",
"||",
"$",
"e",
"->",
"getCode",
"(",
")",
">",
"0",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"commandQueue",
"->",
"confirmCommandHandled",
"(",
"$",
"command",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Handle next received command and return.
This is blocking operation when argument $wait is true (because it waits for next available command),
and non-blocking when $wait is false (if there is no command to handle, then simply returns).
@param bool $wait (default true) if true then waits until command is available (blocking mode)
@param bool|null $exitOnError (default null) if true then worker will finish its job on any error
@throws LogicException
@throws RuntimeException
@throws Exception
@return bool true if command has been handled, false if there was no command in queue | [
"Handle",
"next",
"received",
"command",
"and",
"return",
".",
"This",
"is",
"blocking",
"operation",
"when",
"argument",
"$wait",
"is",
"true",
"(",
"because",
"it",
"waits",
"for",
"next",
"available",
"command",
")",
"and",
"non",
"-",
"blocking",
"when",
"$wait",
"is",
"false",
"(",
"if",
"there",
"is",
"no",
"command",
"to",
"handle",
"then",
"simply",
"returns",
")",
"."
] | train | https://github.com/fiiSoft/fiisoft-tasks-queue/blob/0c5d03f8e6f0fbe023f45e84d3db469dbea476ae/src/TasksQueue/Worker/QueueWorker.php#L92-L121 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.getMimetype | public function getMimetype($force = false) {
if(!isset($this->mimetype) || $force) {
$this->mimetype = MimeTypeGetter::get($this->folder->getPath() . $this->filename);
}
return $this->mimetype;
} | php | public function getMimetype($force = false) {
if(!isset($this->mimetype) || $force) {
$this->mimetype = MimeTypeGetter::get($this->folder->getPath() . $this->filename);
}
return $this->mimetype;
} | [
"public",
"function",
"getMimetype",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"mimetype",
")",
"||",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"mimetype",
"=",
"MimeTypeGetter",
"::",
"get",
"(",
"$",
"this",
"->",
"folder",
"->",
"getPath",
"(",
")",
".",
"$",
"this",
"->",
"filename",
")",
";",
"}",
"return",
"$",
"this",
"->",
"mimetype",
";",
"}"
] | retrieve mime type
requires MimeTypeGetter
@param bool $force forces re-read of mime type | [
"retrieve",
"mime",
"type",
"requires",
"MimeTypeGetter"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L102-L109 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.isWebImage | public function isWebImage($force = false) {
if(!isset($this->mimetype) || $force) {
$this->mimetype = MimeTypeGetter::get($this->folder->getPath() . $this->filename);
}
return preg_match('~^image/(p?jpeg|png|gif)$~', $this->mimetype);
} | php | public function isWebImage($force = false) {
if(!isset($this->mimetype) || $force) {
$this->mimetype = MimeTypeGetter::get($this->folder->getPath() . $this->filename);
}
return preg_match('~^image/(p?jpeg|png|gif)$~', $this->mimetype);
} | [
"public",
"function",
"isWebImage",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"mimetype",
")",
"||",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"mimetype",
"=",
"MimeTypeGetter",
"::",
"get",
"(",
"$",
"this",
"->",
"folder",
"->",
"getPath",
"(",
")",
".",
"$",
"this",
"->",
"filename",
")",
";",
"}",
"return",
"preg_match",
"(",
"'~^image/(p?jpeg|png|gif)$~'",
",",
"$",
"this",
"->",
"mimetype",
")",
";",
"}"
] | check whether mime type indicates web image
(i.e. image/jpeg, image/gif, image/png)
@param bool $force forces re-read of mime type | [
"check",
"whether",
"mime",
"type",
"indicates",
"web",
"image",
"(",
"i",
".",
"e",
".",
"image",
"/",
"jpeg",
"image",
"/",
"gif",
"image",
"/",
"png",
")"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L117-L124 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.getRelativePath | public function getRelativePath($force = FALSE) {
if(!is_null($this->folder->getRelativePath())) {
return $this->folder->getRelativePath() . $this->filename;
}
} | php | public function getRelativePath($force = FALSE) {
if(!is_null($this->folder->getRelativePath())) {
return $this->folder->getRelativePath() . $this->filename;
}
} | [
"public",
"function",
"getRelativePath",
"(",
"$",
"force",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"folder",
"->",
"getRelativePath",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"folder",
"->",
"getRelativePath",
"(",
")",
".",
"$",
"this",
"->",
"filename",
";",
"}",
"}"
] | returns path relative to assets path root
@param boolean $force
@return string | [
"returns",
"path",
"relative",
"to",
"assets",
"path",
"root"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L146-L152 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.rename | public function rename($to) {
$from = $this->filename;
// name is unchanged, nothing to do
if($from !== $to) {
$oldpath = $this->folder->getPath() . $from;
$newpath = $this->folder->getPath() . $to;
if(file_exists($newpath)) {
throw new FilesystemFileException("Rename from '$oldpath' to '$newpath' failed. '$newpath' already exists.", FilesystemFileException::FILE_RENAME_FAILED);
}
if(@rename($oldpath, $newpath)) {
$this->renameCacheEntries($to);
// set new filename
$this->filename = $to;
// re-read fileinfo
$this->fileInfo = new \SplFileInfo($newpath);
self::$instances[$newpath] = $this;
unset(self::$instances[$oldpath]);
}
else {
throw new FilesystemFileException(sprintf("Rename from '%s' to '%s' failed.", $oldpath, $newpath), FilesystemFileException::FILE_RENAME_FAILED);
}
}
return $this;
} | php | public function rename($to) {
$from = $this->filename;
// name is unchanged, nothing to do
if($from !== $to) {
$oldpath = $this->folder->getPath() . $from;
$newpath = $this->folder->getPath() . $to;
if(file_exists($newpath)) {
throw new FilesystemFileException("Rename from '$oldpath' to '$newpath' failed. '$newpath' already exists.", FilesystemFileException::FILE_RENAME_FAILED);
}
if(@rename($oldpath, $newpath)) {
$this->renameCacheEntries($to);
// set new filename
$this->filename = $to;
// re-read fileinfo
$this->fileInfo = new \SplFileInfo($newpath);
self::$instances[$newpath] = $this;
unset(self::$instances[$oldpath]);
}
else {
throw new FilesystemFileException(sprintf("Rename from '%s' to '%s' failed.", $oldpath, $newpath), FilesystemFileException::FILE_RENAME_FAILED);
}
}
return $this;
} | [
"public",
"function",
"rename",
"(",
"$",
"to",
")",
"{",
"$",
"from",
"=",
"$",
"this",
"->",
"filename",
";",
"// name is unchanged, nothing to do",
"if",
"(",
"$",
"from",
"!==",
"$",
"to",
")",
"{",
"$",
"oldpath",
"=",
"$",
"this",
"->",
"folder",
"->",
"getPath",
"(",
")",
".",
"$",
"from",
";",
"$",
"newpath",
"=",
"$",
"this",
"->",
"folder",
"->",
"getPath",
"(",
")",
".",
"$",
"to",
";",
"if",
"(",
"file_exists",
"(",
"$",
"newpath",
")",
")",
"{",
"throw",
"new",
"FilesystemFileException",
"(",
"\"Rename from '$oldpath' to '$newpath' failed. '$newpath' already exists.\"",
",",
"FilesystemFileException",
"::",
"FILE_RENAME_FAILED",
")",
";",
"}",
"if",
"(",
"@",
"rename",
"(",
"$",
"oldpath",
",",
"$",
"newpath",
")",
")",
"{",
"$",
"this",
"->",
"renameCacheEntries",
"(",
"$",
"to",
")",
";",
"// set new filename",
"$",
"this",
"->",
"filename",
"=",
"$",
"to",
";",
"// re-read fileinfo",
"$",
"this",
"->",
"fileInfo",
"=",
"new",
"\\",
"SplFileInfo",
"(",
"$",
"newpath",
")",
";",
"self",
"::",
"$",
"instances",
"[",
"$",
"newpath",
"]",
"=",
"$",
"this",
";",
"unset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"oldpath",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"FilesystemFileException",
"(",
"sprintf",
"(",
"\"Rename from '%s' to '%s' failed.\"",
",",
"$",
"oldpath",
",",
"$",
"newpath",
")",
",",
"FilesystemFileException",
"::",
"FILE_RENAME_FAILED",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | rename file
@param string $to new filename
@return \vxPHP\File\FilesystemFile
@throws FilesystemFileException | [
"rename",
"file"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L170-L210 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.move | public function move(FilesystemFolder $destination) {
// already in destination folder, nothing to do
if($destination !== $this->folder) {
$oldpath = $this->folder->getPath() . $this->filename;
$newpath = $destination->getPath() . $this->filename;
if(@rename($oldpath, $newpath)) {
$this->clearCacheEntries();
// set new folder reference
$this->folder = $destination;
// re-read fileinfo
$this->fileInfo = new \SplFileInfo($newpath);
self::$instances[$newpath] = $this;
unset(self::$instances[$oldpath]);
// @todo: check necessity of chmod
@chmod($newpath, 0666 & ~umask());
}
else {
throw new FilesystemFileException("Moving from '$oldpath' to '$newpath' failed.", FilesystemFileException::FILE_RENAME_FAILED);
}
}
return $this;
} | php | public function move(FilesystemFolder $destination) {
// already in destination folder, nothing to do
if($destination !== $this->folder) {
$oldpath = $this->folder->getPath() . $this->filename;
$newpath = $destination->getPath() . $this->filename;
if(@rename($oldpath, $newpath)) {
$this->clearCacheEntries();
// set new folder reference
$this->folder = $destination;
// re-read fileinfo
$this->fileInfo = new \SplFileInfo($newpath);
self::$instances[$newpath] = $this;
unset(self::$instances[$oldpath]);
// @todo: check necessity of chmod
@chmod($newpath, 0666 & ~umask());
}
else {
throw new FilesystemFileException("Moving from '$oldpath' to '$newpath' failed.", FilesystemFileException::FILE_RENAME_FAILED);
}
}
return $this;
} | [
"public",
"function",
"move",
"(",
"FilesystemFolder",
"$",
"destination",
")",
"{",
"// already in destination folder, nothing to do",
"if",
"(",
"$",
"destination",
"!==",
"$",
"this",
"->",
"folder",
")",
"{",
"$",
"oldpath",
"=",
"$",
"this",
"->",
"folder",
"->",
"getPath",
"(",
")",
".",
"$",
"this",
"->",
"filename",
";",
"$",
"newpath",
"=",
"$",
"destination",
"->",
"getPath",
"(",
")",
".",
"$",
"this",
"->",
"filename",
";",
"if",
"(",
"@",
"rename",
"(",
"$",
"oldpath",
",",
"$",
"newpath",
")",
")",
"{",
"$",
"this",
"->",
"clearCacheEntries",
"(",
")",
";",
"// set new folder reference",
"$",
"this",
"->",
"folder",
"=",
"$",
"destination",
";",
"// re-read fileinfo",
"$",
"this",
"->",
"fileInfo",
"=",
"new",
"\\",
"SplFileInfo",
"(",
"$",
"newpath",
")",
";",
"self",
"::",
"$",
"instances",
"[",
"$",
"newpath",
"]",
"=",
"$",
"this",
";",
"unset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"oldpath",
"]",
")",
";",
"// @todo: check necessity of chmod",
"@",
"chmod",
"(",
"$",
"newpath",
",",
"0666",
"&",
"~",
"umask",
"(",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"FilesystemFileException",
"(",
"\"Moving from '$oldpath' to '$newpath' failed.\"",
",",
"FilesystemFileException",
"::",
"FILE_RENAME_FAILED",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | move file into new folder,
orphaned cache entries are deleted, new cache entries are not generated
@param FilesystemFolder $destination
@return \vxPHP\File\FilesystemFile
@throws FilesystemFileException | [
"move",
"file",
"into",
"new",
"folder",
"orphaned",
"cache",
"entries",
"are",
"deleted",
"new",
"cache",
"entries",
"are",
"not",
"generated"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L220-L257 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.renameCacheEntries | protected function renameCacheEntries($to) {
if(($cachePath = $this->folder->getCachePath(TRUE))) {
$di = new \DirectoryIterator($cachePath);
foreach($di as $fileinfo) {
$filename = $fileinfo->getFilename();
if( $fileinfo->isDot() ||
!$fileinfo->isFile() ||
strpos($filename, $this->filename) !== 0
) {
continue;
}
$renamed = substr_replace($filename, $to, 0, strlen($this->filename));
rename($fileinfo->getRealPath(), $fileinfo->getPath() . DIRECTORY_SEPARATOR . $renamed);
}
}
} | php | protected function renameCacheEntries($to) {
if(($cachePath = $this->folder->getCachePath(TRUE))) {
$di = new \DirectoryIterator($cachePath);
foreach($di as $fileinfo) {
$filename = $fileinfo->getFilename();
if( $fileinfo->isDot() ||
!$fileinfo->isFile() ||
strpos($filename, $this->filename) !== 0
) {
continue;
}
$renamed = substr_replace($filename, $to, 0, strlen($this->filename));
rename($fileinfo->getRealPath(), $fileinfo->getPath() . DIRECTORY_SEPARATOR . $renamed);
}
}
} | [
"protected",
"function",
"renameCacheEntries",
"(",
"$",
"to",
")",
"{",
"if",
"(",
"(",
"$",
"cachePath",
"=",
"$",
"this",
"->",
"folder",
"->",
"getCachePath",
"(",
"TRUE",
")",
")",
")",
"{",
"$",
"di",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"cachePath",
")",
";",
"foreach",
"(",
"$",
"di",
"as",
"$",
"fileinfo",
")",
"{",
"$",
"filename",
"=",
"$",
"fileinfo",
"->",
"getFilename",
"(",
")",
";",
"if",
"(",
"$",
"fileinfo",
"->",
"isDot",
"(",
")",
"||",
"!",
"$",
"fileinfo",
"->",
"isFile",
"(",
")",
"||",
"strpos",
"(",
"$",
"filename",
",",
"$",
"this",
"->",
"filename",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"renamed",
"=",
"substr_replace",
"(",
"$",
"filename",
",",
"$",
"to",
",",
"0",
",",
"strlen",
"(",
"$",
"this",
"->",
"filename",
")",
")",
";",
"rename",
"(",
"$",
"fileinfo",
"->",
"getRealPath",
"(",
")",
",",
"$",
"fileinfo",
"->",
"getPath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"renamed",
")",
";",
"}",
"}",
"}"
] | updates names of cache entries
@param string $to new filename | [
"updates",
"names",
"of",
"cache",
"entries"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L264-L285 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.delete | public function delete() {
if(@unlink($this->getPath())) {
$this->deleteCacheEntries();
self::unsetInstance($this->getPath());
}
else {
throw new FilesystemFileException("Delete of file '{$this->getPath()}' failed.", FilesystemFileException::FILE_DELETE_FAILED);
}
} | php | public function delete() {
if(@unlink($this->getPath())) {
$this->deleteCacheEntries();
self::unsetInstance($this->getPath());
}
else {
throw new FilesystemFileException("Delete of file '{$this->getPath()}' failed.", FilesystemFileException::FILE_DELETE_FAILED);
}
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"@",
"unlink",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"deleteCacheEntries",
"(",
")",
";",
"self",
"::",
"unsetInstance",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"FilesystemFileException",
"(",
"\"Delete of file '{$this->getPath()}' failed.\"",
",",
"FilesystemFileException",
"::",
"FILE_DELETE_FAILED",
")",
";",
"}",
"}"
] | deletes file and removes instance from lookup array
@throws FilesystemFileException | [
"deletes",
"file",
"and",
"removes",
"instance",
"from",
"lookup",
"array"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L291-L301 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.deleteCacheEntries | protected function deleteCacheEntries() {
if(($cachePath = $this->folder->getCachePath(TRUE))) {
$di = new \DirectoryIterator($cachePath);
foreach($di as $fileinfo) {
if( $fileinfo->isDot() ||
!$fileinfo->isFile() ||
strpos($fileinfo->getFilename(), $this->filename) !== 0
) {
continue;
}
unlink($fileinfo->getRealPath());
}
}
} | php | protected function deleteCacheEntries() {
if(($cachePath = $this->folder->getCachePath(TRUE))) {
$di = new \DirectoryIterator($cachePath);
foreach($di as $fileinfo) {
if( $fileinfo->isDot() ||
!$fileinfo->isFile() ||
strpos($fileinfo->getFilename(), $this->filename) !== 0
) {
continue;
}
unlink($fileinfo->getRealPath());
}
}
} | [
"protected",
"function",
"deleteCacheEntries",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"cachePath",
"=",
"$",
"this",
"->",
"folder",
"->",
"getCachePath",
"(",
"TRUE",
")",
")",
")",
"{",
"$",
"di",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"cachePath",
")",
";",
"foreach",
"(",
"$",
"di",
"as",
"$",
"fileinfo",
")",
"{",
"if",
"(",
"$",
"fileinfo",
"->",
"isDot",
"(",
")",
"||",
"!",
"$",
"fileinfo",
"->",
"isFile",
"(",
")",
"||",
"strpos",
"(",
"$",
"fileinfo",
"->",
"getFilename",
"(",
")",
",",
"$",
"this",
"->",
"filename",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"unlink",
"(",
"$",
"fileinfo",
"->",
"getRealPath",
"(",
")",
")",
";",
"}",
"}",
"}"
] | cleans up cache entries associated with
"original" file | [
"cleans",
"up",
"cache",
"entries",
"associated",
"with",
"original",
"file"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L307-L324 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.getCacheInfo | public function getCacheInfo() {
if(($cachePath = $this->folder->getCachePath(TRUE))) {
$size = 0;
$count = 0;
$di = new \DirectoryIterator($cachePath);
foreach($di as $fileinfo) {
if( $fileinfo->isDot() ||
!$fileinfo->isFile() ||
strpos($fileinfo->getFilename(), $this->filename) !== 0
) {
continue;
}
++$count;
$size += $fileinfo->getSize();
}
return ['count' => $count, 'totalSize' => $size];
}
return FALSE;
} | php | public function getCacheInfo() {
if(($cachePath = $this->folder->getCachePath(TRUE))) {
$size = 0;
$count = 0;
$di = new \DirectoryIterator($cachePath);
foreach($di as $fileinfo) {
if( $fileinfo->isDot() ||
!$fileinfo->isFile() ||
strpos($fileinfo->getFilename(), $this->filename) !== 0
) {
continue;
}
++$count;
$size += $fileinfo->getSize();
}
return ['count' => $count, 'totalSize' => $size];
}
return FALSE;
} | [
"public",
"function",
"getCacheInfo",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"cachePath",
"=",
"$",
"this",
"->",
"folder",
"->",
"getCachePath",
"(",
"TRUE",
")",
")",
")",
"{",
"$",
"size",
"=",
"0",
";",
"$",
"count",
"=",
"0",
";",
"$",
"di",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"cachePath",
")",
";",
"foreach",
"(",
"$",
"di",
"as",
"$",
"fileinfo",
")",
"{",
"if",
"(",
"$",
"fileinfo",
"->",
"isDot",
"(",
")",
"||",
"!",
"$",
"fileinfo",
"->",
"isFile",
"(",
")",
"||",
"strpos",
"(",
"$",
"fileinfo",
"->",
"getFilename",
"(",
")",
",",
"$",
"this",
"->",
"filename",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"++",
"$",
"count",
";",
"$",
"size",
"+=",
"$",
"fileinfo",
"->",
"getSize",
"(",
")",
";",
"}",
"return",
"[",
"'count'",
"=>",
"$",
"count",
",",
"'totalSize'",
"=>",
"$",
"size",
"]",
";",
"}",
"return",
"FALSE",
";",
"}"
] | retrieve information about cached files
@return array information | [
"retrieve",
"information",
"about",
"cached",
"files"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L339-L360 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.getFilesystemFilesInFolder | public static function getFilesystemFilesInFolder(FilesystemFolder $folder) {
$files = [];
$glob = glob($folder->getPath() . '*', GLOB_NOSORT);
if($glob !== FALSE) {
foreach($glob as $f) {
if(!is_dir($f)) {
if(!isset(self::$instances[$f])) {
self::$instances[$f] = new self(basename($f), $folder);
}
$files[] = self::$instances[$f];
}
}
}
return $files;
} | php | public static function getFilesystemFilesInFolder(FilesystemFolder $folder) {
$files = [];
$glob = glob($folder->getPath() . '*', GLOB_NOSORT);
if($glob !== FALSE) {
foreach($glob as $f) {
if(!is_dir($f)) {
if(!isset(self::$instances[$f])) {
self::$instances[$f] = new self(basename($f), $folder);
}
$files[] = self::$instances[$f];
}
}
}
return $files;
} | [
"public",
"static",
"function",
"getFilesystemFilesInFolder",
"(",
"FilesystemFolder",
"$",
"folder",
")",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"glob",
"=",
"glob",
"(",
"$",
"folder",
"->",
"getPath",
"(",
")",
".",
"'*'",
",",
"GLOB_NOSORT",
")",
";",
"if",
"(",
"$",
"glob",
"!==",
"FALSE",
")",
"{",
"foreach",
"(",
"$",
"glob",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"f",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"f",
"]",
")",
")",
"{",
"self",
"::",
"$",
"instances",
"[",
"$",
"f",
"]",
"=",
"new",
"self",
"(",
"basename",
"(",
"$",
"f",
")",
",",
"$",
"folder",
")",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"self",
"::",
"$",
"instances",
"[",
"$",
"f",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"files",
";",
"}"
] | return all filesystem files instances within a certain folder
@param FilesystemFolder $folder
@return Array filesystem files | [
"return",
"all",
"filesystem",
"files",
"instances",
"within",
"a",
"certain",
"folder"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L368-L389 |
Vectrex/vxPHP | src/File/FilesystemFile.php | FilesystemFile.sanitizeFilename | public static function sanitizeFilename($filename, FilesystemFolder $dir, $ndx = 2) {
// remove any characters which are not allowed in any file system
$filename = preg_replace('~[<>:"/\\|?*\\x00-\\x1F]~', '_', $filename);
if(!file_exists($dir->getPath() . $filename)) {
return $filename;
}
$pathinfo = pathinfo($filename);
$pathinfo['extension'] = !empty($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '';
while(file_exists($dir->getPath() . sprintf('%s(%d)%s', $pathinfo['filename'], $ndx, $pathinfo['extension']))) {
++$ndx;
}
return sprintf('%s(%d)%s', $pathinfo['filename'], $ndx, $pathinfo['extension']);
} | php | public static function sanitizeFilename($filename, FilesystemFolder $dir, $ndx = 2) {
// remove any characters which are not allowed in any file system
$filename = preg_replace('~[<>:"/\\|?*\\x00-\\x1F]~', '_', $filename);
if(!file_exists($dir->getPath() . $filename)) {
return $filename;
}
$pathinfo = pathinfo($filename);
$pathinfo['extension'] = !empty($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '';
while(file_exists($dir->getPath() . sprintf('%s(%d)%s', $pathinfo['filename'], $ndx, $pathinfo['extension']))) {
++$ndx;
}
return sprintf('%s(%d)%s', $pathinfo['filename'], $ndx, $pathinfo['extension']);
} | [
"public",
"static",
"function",
"sanitizeFilename",
"(",
"$",
"filename",
",",
"FilesystemFolder",
"$",
"dir",
",",
"$",
"ndx",
"=",
"2",
")",
"{",
"// remove any characters which are not allowed in any file system",
"$",
"filename",
"=",
"preg_replace",
"(",
"'~[<>:\"/\\\\|?*\\\\x00-\\\\x1F]~'",
",",
"'_'",
",",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
"->",
"getPath",
"(",
")",
".",
"$",
"filename",
")",
")",
"{",
"return",
"$",
"filename",
";",
"}",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"filename",
")",
";",
"$",
"pathinfo",
"[",
"'extension'",
"]",
"=",
"!",
"empty",
"(",
"$",
"pathinfo",
"[",
"'extension'",
"]",
")",
"?",
"'.'",
".",
"$",
"pathinfo",
"[",
"'extension'",
"]",
":",
"''",
";",
"while",
"(",
"file_exists",
"(",
"$",
"dir",
"->",
"getPath",
"(",
")",
".",
"sprintf",
"(",
"'%s(%d)%s'",
",",
"$",
"pathinfo",
"[",
"'filename'",
"]",
",",
"$",
"ndx",
",",
"$",
"pathinfo",
"[",
"'extension'",
"]",
")",
")",
")",
"{",
"++",
"$",
"ndx",
";",
"}",
"return",
"sprintf",
"(",
"'%s(%d)%s'",
",",
"$",
"pathinfo",
"[",
"'filename'",
"]",
",",
"$",
"ndx",
",",
"$",
"pathinfo",
"[",
"'extension'",
"]",
")",
";",
"}"
] | clean up $filename and avoid duplicate filenames within folder $dir
the cleanup is simple and does not take reserved filenames into consideration
(e.g. PRN or CON on Windows systems)
@see https://msdn.microsoft.com/en-us/library/aa365247
@param string $filename
@param FilesystemFolder $dir
@param integer $starting_index used in renamed file
@return string | [
"clean",
"up",
"$filename",
"and",
"avoid",
"duplicate",
"filenames",
"within",
"folder",
"$dir",
"the",
"cleanup",
"is",
"simple",
"and",
"does",
"not",
"take",
"reserved",
"filenames",
"into",
"consideration",
"(",
"e",
".",
"g",
".",
"PRN",
"or",
"CON",
"on",
"Windows",
"systems",
")",
"@see",
"https",
":",
"//",
"msdn",
".",
"microsoft",
".",
"com",
"/",
"en",
"-",
"us",
"/",
"library",
"/",
"aa365247"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/File/FilesystemFile.php#L402-L422 |
tonis-io-legacy/view | src/Strategy/TwigStrategy.php | TwigStrategy.render | public function render(ModelInterface $model)
{
if (!$model instanceof ViewModel) {
return '';
}
return $this->twig->render($model->getTemplate() . $this->suffix, $model->getVariables());
} | php | public function render(ModelInterface $model)
{
if (!$model instanceof ViewModel) {
return '';
}
return $this->twig->render($model->getTemplate() . $this->suffix, $model->getVariables());
} | [
"public",
"function",
"render",
"(",
"ModelInterface",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"instanceof",
"ViewModel",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"$",
"model",
"->",
"getTemplate",
"(",
")",
".",
"$",
"this",
"->",
"suffix",
",",
"$",
"model",
"->",
"getVariables",
"(",
")",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/view/blob/20e703cd3f6243dc08b2eec028a8997c33e9edcc/src/Strategy/TwigStrategy.php#L37-L44 |
tonis-io-legacy/view | src/Strategy/TwigStrategy.php | TwigStrategy.canRender | public function canRender(ModelInterface $model)
{
if (!$model instanceof ViewModel) {
return false;
}
try {
$this->twig->getLoader()->getSource($model->getTemplate() . $this->suffix);
} catch (\Twig_Error_Loader $e) {
return false;
}
return true;
} | php | public function canRender(ModelInterface $model)
{
if (!$model instanceof ViewModel) {
return false;
}
try {
$this->twig->getLoader()->getSource($model->getTemplate() . $this->suffix);
} catch (\Twig_Error_Loader $e) {
return false;
}
return true;
} | [
"public",
"function",
"canRender",
"(",
"ModelInterface",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"instanceof",
"ViewModel",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"twig",
"->",
"getLoader",
"(",
")",
"->",
"getSource",
"(",
"$",
"model",
"->",
"getTemplate",
"(",
")",
".",
"$",
"this",
"->",
"suffix",
")",
";",
"}",
"catch",
"(",
"\\",
"Twig_Error_Loader",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/view/blob/20e703cd3f6243dc08b2eec028a8997c33e9edcc/src/Strategy/TwigStrategy.php#L49-L61 |
prosoftSolutions/Pager | View/TranslatedView.php | TranslatedView.render | public function render(PagerfantaInterface $pagerfanta, $routeGenerator, array $options = array())
{
$optionsWithTranslations = $this->addTranslationOptions($options);
return $this->view->render($pagerfanta, $routeGenerator, $optionsWithTranslations);
} | php | public function render(PagerfantaInterface $pagerfanta, $routeGenerator, array $options = array())
{
$optionsWithTranslations = $this->addTranslationOptions($options);
return $this->view->render($pagerfanta, $routeGenerator, $optionsWithTranslations);
} | [
"public",
"function",
"render",
"(",
"PagerfantaInterface",
"$",
"pagerfanta",
",",
"$",
"routeGenerator",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"optionsWithTranslations",
"=",
"$",
"this",
"->",
"addTranslationOptions",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"$",
"pagerfanta",
",",
"$",
"routeGenerator",
",",
"$",
"optionsWithTranslations",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/prosoftSolutions/Pager/blob/96446ee22caedc0b9bb486d9ffe7a50b6c13177f/View/TranslatedView.php#L43-L48 |
squareproton/Bond | src/Bond/Pg/Result.php | Result.setFetchOptions | public function setFetchOptions( $fetchOptions )
{
// set fetchOptions
if( $fetchOptions === null ) {
return $this->fetchOptions;
}
if( !is_integer($fetchOptions) ) {
throw new BadTypeException( $fetchOptions, 'int' );
}
$fetchOptions += $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC ) ? 0 : self::TYPE_DEFAULT;
$fetchOptions += $fetchOptions & ( self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT ) ? 0 : self::FLATTEN_DEFAULT;
$fetchOptions += $fetchOptions & ( self::STYLE_ASSOC | self::STYLE_NUM ) ? 0 : self::STYLE_DEFAULT;
$fetchOptions += $fetchOptions & ( self::FETCH_SINGLE | self::FETCH_MULTIPLE ) ? 0 : self::FETCH_DEFAULT;
$fetchOptions += $fetchOptions & ( self::CACHE | self::CACHE_NOT ) ? 0 : self::CACHE_DEFAULT;
// flatten
$flatten = (bool) ( $fetchOptions & self::FLATTEN_IF_POSSIBLE ) && ( $this->numFields() === 1 );
$this->buildFetchCallback( $fetchOptions, $flatten );
$this->fetchOptions = $fetchOptions;
return $this;
} | php | public function setFetchOptions( $fetchOptions )
{
// set fetchOptions
if( $fetchOptions === null ) {
return $this->fetchOptions;
}
if( !is_integer($fetchOptions) ) {
throw new BadTypeException( $fetchOptions, 'int' );
}
$fetchOptions += $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC ) ? 0 : self::TYPE_DEFAULT;
$fetchOptions += $fetchOptions & ( self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT ) ? 0 : self::FLATTEN_DEFAULT;
$fetchOptions += $fetchOptions & ( self::STYLE_ASSOC | self::STYLE_NUM ) ? 0 : self::STYLE_DEFAULT;
$fetchOptions += $fetchOptions & ( self::FETCH_SINGLE | self::FETCH_MULTIPLE ) ? 0 : self::FETCH_DEFAULT;
$fetchOptions += $fetchOptions & ( self::CACHE | self::CACHE_NOT ) ? 0 : self::CACHE_DEFAULT;
// flatten
$flatten = (bool) ( $fetchOptions & self::FLATTEN_IF_POSSIBLE ) && ( $this->numFields() === 1 );
$this->buildFetchCallback( $fetchOptions, $flatten );
$this->fetchOptions = $fetchOptions;
return $this;
} | [
"public",
"function",
"setFetchOptions",
"(",
"$",
"fetchOptions",
")",
"{",
"// set fetchOptions",
"if",
"(",
"$",
"fetchOptions",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"fetchOptions",
";",
"}",
"if",
"(",
"!",
"is_integer",
"(",
"$",
"fetchOptions",
")",
")",
"{",
"throw",
"new",
"BadTypeException",
"(",
"$",
"fetchOptions",
",",
"'int'",
")",
";",
"}",
"$",
"fetchOptions",
"+=",
"$",
"fetchOptions",
"&",
"(",
"self",
"::",
"TYPE_DETECT",
"|",
"self",
"::",
"TYPE_AGNOSTIC",
")",
"?",
"0",
":",
"self",
"::",
"TYPE_DEFAULT",
";",
"$",
"fetchOptions",
"+=",
"$",
"fetchOptions",
"&",
"(",
"self",
"::",
"FLATTEN_IF_POSSIBLE",
"|",
"self",
"::",
"FLATTEN_PREVENT",
")",
"?",
"0",
":",
"self",
"::",
"FLATTEN_DEFAULT",
";",
"$",
"fetchOptions",
"+=",
"$",
"fetchOptions",
"&",
"(",
"self",
"::",
"STYLE_ASSOC",
"|",
"self",
"::",
"STYLE_NUM",
")",
"?",
"0",
":",
"self",
"::",
"STYLE_DEFAULT",
";",
"$",
"fetchOptions",
"+=",
"$",
"fetchOptions",
"&",
"(",
"self",
"::",
"FETCH_SINGLE",
"|",
"self",
"::",
"FETCH_MULTIPLE",
")",
"?",
"0",
":",
"self",
"::",
"FETCH_DEFAULT",
";",
"$",
"fetchOptions",
"+=",
"$",
"fetchOptions",
"&",
"(",
"self",
"::",
"CACHE",
"|",
"self",
"::",
"CACHE_NOT",
")",
"?",
"0",
":",
"self",
"::",
"CACHE_DEFAULT",
";",
"// flatten",
"$",
"flatten",
"=",
"(",
"bool",
")",
"(",
"$",
"fetchOptions",
"&",
"self",
"::",
"FLATTEN_IF_POSSIBLE",
")",
"&&",
"(",
"$",
"this",
"->",
"numFields",
"(",
")",
"===",
"1",
")",
";",
"$",
"this",
"->",
"buildFetchCallback",
"(",
"$",
"fetchOptions",
",",
"$",
"flatten",
")",
";",
"$",
"this",
"->",
"fetchOptions",
"=",
"$",
"fetchOptions",
";",
"return",
"$",
"this",
";",
"}"
] | Set the result fetchOptions
@param int Bitmask
@return Bond\Pg\Resource | [
"Set",
"the",
"result",
"fetchOptions"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Result.php#L155-L181 |
squareproton/Bond | src/Bond/Pg/Result.php | Result.buildFetchCallback | private function buildFetchCallback( $fetchOptions, $flatten )
{
$original = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );
$new = $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );
// nothing has changed - don't need to change the callback
if( $original === $new ) {
return false;
}
// only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway)
$this->fetchType = ( $fetchOptions & self::STYLE_ASSOC and !$flatten ) ? PGSQL_ASSOC : PGSQL_NUM;
// types and keys
// determine types - this could be enabled to automatically convert types (to something other than a string)
// off by default as the performance hit has yet to be determined
if( $fetchOptions & self::TYPE_DETECT ) {
$typeCallbacks = $this->getFieldTypeCallbacks();
if( $this->fetchType === PGSQL_ASSOC ) {
$keys = array_keys( $typeCallbacks );
} else {
$keys = range(0, count($typeCallbacks) - 1);
}
// flatten
if( $flatten ) {
$typeCallback = array_pop( $typeCallbacks );
$this->fetchCallback = function( $row ) use ( $keys, $typeCallback ) {
return call_user_func( $typeCallback, $row[0] );
};
} else {
$this->fetchCallback = function( $row ) use ( $keys, $typeCallbacks ) {
return array_combine(
$keys,
array_map( 'call_user_func', $typeCallbacks, $row )
);
};
}
} elseif( $flatten ) {
$this->fetchCallback = function( $row ) {
return array_shift( $row );
};
} else {
$this->fetchCallback = function( $row ) {
return $row;
};
}
return true;
} | php | private function buildFetchCallback( $fetchOptions, $flatten )
{
$original = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );
$new = $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );
// nothing has changed - don't need to change the callback
if( $original === $new ) {
return false;
}
// only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway)
$this->fetchType = ( $fetchOptions & self::STYLE_ASSOC and !$flatten ) ? PGSQL_ASSOC : PGSQL_NUM;
// types and keys
// determine types - this could be enabled to automatically convert types (to something other than a string)
// off by default as the performance hit has yet to be determined
if( $fetchOptions & self::TYPE_DETECT ) {
$typeCallbacks = $this->getFieldTypeCallbacks();
if( $this->fetchType === PGSQL_ASSOC ) {
$keys = array_keys( $typeCallbacks );
} else {
$keys = range(0, count($typeCallbacks) - 1);
}
// flatten
if( $flatten ) {
$typeCallback = array_pop( $typeCallbacks );
$this->fetchCallback = function( $row ) use ( $keys, $typeCallback ) {
return call_user_func( $typeCallback, $row[0] );
};
} else {
$this->fetchCallback = function( $row ) use ( $keys, $typeCallbacks ) {
return array_combine(
$keys,
array_map( 'call_user_func', $typeCallbacks, $row )
);
};
}
} elseif( $flatten ) {
$this->fetchCallback = function( $row ) {
return array_shift( $row );
};
} else {
$this->fetchCallback = function( $row ) {
return $row;
};
}
return true;
} | [
"private",
"function",
"buildFetchCallback",
"(",
"$",
"fetchOptions",
",",
"$",
"flatten",
")",
"{",
"$",
"original",
"=",
"$",
"this",
"->",
"fetchOptions",
"&",
"(",
"self",
"::",
"TYPE_DETECT",
"|",
"self",
"::",
"TYPE_AGNOSTIC",
"|",
"self",
"::",
"FLATTEN_IF_POSSIBLE",
"|",
"self",
"::",
"FLATTEN_PREVENT",
"|",
"self",
"::",
"STYLE_ASSOC",
"|",
"self",
"::",
"STYLE_NUM",
")",
";",
"$",
"new",
"=",
"$",
"fetchOptions",
"&",
"(",
"self",
"::",
"TYPE_DETECT",
"|",
"self",
"::",
"TYPE_AGNOSTIC",
"|",
"self",
"::",
"FLATTEN_IF_POSSIBLE",
"|",
"self",
"::",
"FLATTEN_PREVENT",
"|",
"self",
"::",
"STYLE_ASSOC",
"|",
"self",
"::",
"STYLE_NUM",
")",
";",
"// nothing has changed - don't need to change the callback",
"if",
"(",
"$",
"original",
"===",
"$",
"new",
")",
"{",
"return",
"false",
";",
"}",
"// only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway)",
"$",
"this",
"->",
"fetchType",
"=",
"(",
"$",
"fetchOptions",
"&",
"self",
"::",
"STYLE_ASSOC",
"and",
"!",
"$",
"flatten",
")",
"?",
"PGSQL_ASSOC",
":",
"PGSQL_NUM",
";",
"// types and keys",
"// determine types - this could be enabled to automatically convert types (to something other than a string)",
"// off by default as the performance hit has yet to be determined",
"if",
"(",
"$",
"fetchOptions",
"&",
"self",
"::",
"TYPE_DETECT",
")",
"{",
"$",
"typeCallbacks",
"=",
"$",
"this",
"->",
"getFieldTypeCallbacks",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fetchType",
"===",
"PGSQL_ASSOC",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"typeCallbacks",
")",
";",
"}",
"else",
"{",
"$",
"keys",
"=",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"typeCallbacks",
")",
"-",
"1",
")",
";",
"}",
"// flatten",
"if",
"(",
"$",
"flatten",
")",
"{",
"$",
"typeCallback",
"=",
"array_pop",
"(",
"$",
"typeCallbacks",
")",
";",
"$",
"this",
"->",
"fetchCallback",
"=",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"keys",
",",
"$",
"typeCallback",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"typeCallback",
",",
"$",
"row",
"[",
"0",
"]",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"fetchCallback",
"=",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"keys",
",",
"$",
"typeCallbacks",
")",
"{",
"return",
"array_combine",
"(",
"$",
"keys",
",",
"array_map",
"(",
"'call_user_func'",
",",
"$",
"typeCallbacks",
",",
"$",
"row",
")",
")",
";",
"}",
";",
"}",
"}",
"elseif",
"(",
"$",
"flatten",
")",
"{",
"$",
"this",
"->",
"fetchCallback",
"=",
"function",
"(",
"$",
"row",
")",
"{",
"return",
"array_shift",
"(",
"$",
"row",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"fetchCallback",
"=",
"function",
"(",
"$",
"row",
")",
"{",
"return",
"$",
"row",
";",
"}",
";",
"}",
"return",
"true",
";",
"}"
] | Build a row processing callback based on the TYPE_DETECT and row flattening
@param bool $flatten
@return Callable | [
"Build",
"a",
"row",
"processing",
"callback",
"based",
"on",
"the",
"TYPE_DETECT",
"and",
"row",
"flattening"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Result.php#L188-L249 |
Subsets and Splits