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
|
---|---|---|---|---|---|---|---|---|---|---|
ezra-obiwale/dSCore | src/Core/Engine.php | Engine.getDefaultAction | public static function getDefaultAction($module = null, $exception = false) {
$module = ($module === null) ? static::getDefaultModule() : $module;
return static::getConfig('modules', $module, 'defaults', 'action', $exception);
} | php | public static function getDefaultAction($module = null, $exception = false) {
$module = ($module === null) ? static::getDefaultModule() : $module;
return static::getConfig('modules', $module, 'defaults', 'action', $exception);
} | [
"public",
"static",
"function",
"getDefaultAction",
"(",
"$",
"module",
"=",
"null",
",",
"$",
"exception",
"=",
"false",
")",
"{",
"$",
"module",
"=",
"(",
"$",
"module",
"===",
"null",
")",
"?",
"static",
"::",
"getDefaultModule",
"(",
")",
":",
"$",
"module",
";",
"return",
"static",
"::",
"getConfig",
"(",
"'modules'",
",",
"$",
"module",
",",
"'defaults'",
",",
"'action'",
",",
"$",
"exception",
")",
";",
"}"
] | Fetches the default action from the config
@param string $module
@param boolean $exception Indicates whether to throw an exception if not found
@return string | [
"Fetches",
"the",
"default",
"action",
"from",
"the",
"config"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L301-L305 |
ezra-obiwale/dSCore | src/Core/Engine.php | Engine.getControllerClass | protected static function getControllerClass($live = true) {
$class = static::getModule() . '\Controllers\\' . static::getController() .
'Controller';
if (!class_exists($class))
ControllerException::notFound($class);
if (!in_array('DScribe\Core\AController', class_parents($class)))
throw new \Exception('Controller Exception: Controller "' . $class . '" does not extend "DScribe\Core\AController"');
return ($live) ? new $class() : $class;
} | php | protected static function getControllerClass($live = true) {
$class = static::getModule() . '\Controllers\\' . static::getController() .
'Controller';
if (!class_exists($class))
ControllerException::notFound($class);
if (!in_array('DScribe\Core\AController', class_parents($class)))
throw new \Exception('Controller Exception: Controller "' . $class . '" does not extend "DScribe\Core\AController"');
return ($live) ? new $class() : $class;
} | [
"protected",
"static",
"function",
"getControllerClass",
"(",
"$",
"live",
"=",
"true",
")",
"{",
"$",
"class",
"=",
"static",
"::",
"getModule",
"(",
")",
".",
"'\\Controllers\\\\'",
".",
"static",
"::",
"getController",
"(",
")",
".",
"'Controller'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"ControllerException",
"::",
"notFound",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"'DScribe\\Core\\AController'",
",",
"class_parents",
"(",
"$",
"class",
")",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"'Controller Exception: Controller \"'",
".",
"$",
"class",
".",
"'\" does not extend \"DScribe\\Core\\AController\"'",
")",
";",
"return",
"(",
"$",
"live",
")",
"?",
"new",
"$",
"class",
"(",
")",
":",
"$",
"class",
";",
"}"
] | Creates an instance of the current controller class
@return AController
@throws Exception | [
"Creates",
"an",
"instance",
"of",
"the",
"current",
"controller",
"class"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L340-L351 |
ezra-obiwale/dSCore | src/Core/Engine.php | Engine.authenticate | protected static function authenticate($controller, $action, $params) {
$auth = new Authenticate(static::$userId, $controller, $action);
if (!$auth->execute()) {
$controller->accessDenied($action, $params);
exit;
}
} | php | protected static function authenticate($controller, $action, $params) {
$auth = new Authenticate(static::$userId, $controller, $action);
if (!$auth->execute()) {
$controller->accessDenied($action, $params);
exit;
}
} | [
"protected",
"static",
"function",
"authenticate",
"(",
"$",
"controller",
",",
"$",
"action",
",",
"$",
"params",
")",
"{",
"$",
"auth",
"=",
"new",
"Authenticate",
"(",
"static",
"::",
"$",
"userId",
",",
"$",
"controller",
",",
"$",
"action",
")",
";",
"if",
"(",
"!",
"$",
"auth",
"->",
"execute",
"(",
")",
")",
"{",
"$",
"controller",
"->",
"accessDenied",
"(",
"$",
"action",
",",
"$",
"params",
")",
";",
"exit",
";",
"}",
"}"
] | Authenticates the current user against the controller and action
@param string $controller
@param string $action | [
"Authenticates",
"the",
"current",
"user",
"against",
"the",
"controller",
"and",
"action"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L358-L364 |
ezra-obiwale/dSCore | src/Core/Engine.php | Engine.resetUserIdentity | public static function resetUserIdentity(AUser $user = NULL, $duration = null) {
static::$userId = new UserIdentity($user, $duration);
if (!$user)
Session::reset();
static::saveSession();
} | php | public static function resetUserIdentity(AUser $user = NULL, $duration = null) {
static::$userId = new UserIdentity($user, $duration);
if (!$user)
Session::reset();
static::saveSession();
} | [
"public",
"static",
"function",
"resetUserIdentity",
"(",
"AUser",
"$",
"user",
"=",
"NULL",
",",
"$",
"duration",
"=",
"null",
")",
"{",
"static",
"::",
"$",
"userId",
"=",
"new",
"UserIdentity",
"(",
"$",
"user",
",",
"$",
"duration",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"Session",
"::",
"reset",
"(",
")",
";",
"static",
"::",
"saveSession",
"(",
")",
";",
"}"
] | Resets the user to guest
@param AUser $user
@param int $duration Duration for which the identity should be valid | [
"Resets",
"the",
"user",
"to",
"guest"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L371-L376 |
ezra-obiwale/dSCore | src/Core/Engine.php | Engine.init | public static function init(array $config) {
static::$config = $config;
static::checkConfig($config);
static::fetchSession();
if (static::$userId === null)
static::$userId = new UserIdentity();
static::$inject = include CONFIG . 'inject.php';
} | php | public static function init(array $config) {
static::$config = $config;
static::checkConfig($config);
static::fetchSession();
if (static::$userId === null)
static::$userId = new UserIdentity();
static::$inject = include CONFIG . 'inject.php';
} | [
"public",
"static",
"function",
"init",
"(",
"array",
"$",
"config",
")",
"{",
"static",
"::",
"$",
"config",
"=",
"$",
"config",
";",
"static",
"::",
"checkConfig",
"(",
"$",
"config",
")",
";",
"static",
"::",
"fetchSession",
"(",
")",
";",
"if",
"(",
"static",
"::",
"$",
"userId",
"===",
"null",
")",
"static",
"::",
"$",
"userId",
"=",
"new",
"UserIdentity",
"(",
")",
";",
"static",
"::",
"$",
"inject",
"=",
"include",
"CONFIG",
".",
"'inject.php'",
";",
"}"
] | Initializes the engine
@param array $config | [
"Initializes",
"the",
"engine"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L415-L425 |
ezra-obiwale/dSCore | src/Core/Engine.php | Engine.run | public static function run(array $config) {
static::init($config);
static::moduleIsActivated();
$cache = static::canCache();
$name = join('/', static::getUrls());
if ($cache && $out = $cache->fetch($name)) {
echo $out;
}
else {
$view = new View();
$controller = static::getControllerClass();
$controller->setView($view);
$action = static::getAction();
if (!in_array($action, $controller->getActions())) {
ControllerException::invalidAction($action);
}
$params = static::getParams();
static::authenticate($controller, $action, $params);
$view->setController($controller)
->setAction($action);
$refMethod = new ReflectionMethod($controller, $action . 'Action');
if (count($params) < $refMethod->getNumberOfRequiredParameters()) {
ControllerException::invalidParamCount();
}
$actionRet = call_user_func_array(array($controller, $action . 'Action'), $params);
if ($actionRet !== null && !is_array($actionRet) &&
(is_object($actionRet) && get_class($actionRet) !== 'DScribe\View\View')) {
ControllerException::invalidActionResult();
}
if (is_array($actionRet))
$view->variables($actionRet);
elseif (is_object($actionRet))
$view = $actionRet;
ob_start();
$view->render();
$data = ob_get_clean();
if ($cache && !Session::fetch('noCache'))
$cache->save($name, $data);
echo $data;
static::terminate();
}
} | php | public static function run(array $config) {
static::init($config);
static::moduleIsActivated();
$cache = static::canCache();
$name = join('/', static::getUrls());
if ($cache && $out = $cache->fetch($name)) {
echo $out;
}
else {
$view = new View();
$controller = static::getControllerClass();
$controller->setView($view);
$action = static::getAction();
if (!in_array($action, $controller->getActions())) {
ControllerException::invalidAction($action);
}
$params = static::getParams();
static::authenticate($controller, $action, $params);
$view->setController($controller)
->setAction($action);
$refMethod = new ReflectionMethod($controller, $action . 'Action');
if (count($params) < $refMethod->getNumberOfRequiredParameters()) {
ControllerException::invalidParamCount();
}
$actionRet = call_user_func_array(array($controller, $action . 'Action'), $params);
if ($actionRet !== null && !is_array($actionRet) &&
(is_object($actionRet) && get_class($actionRet) !== 'DScribe\View\View')) {
ControllerException::invalidActionResult();
}
if (is_array($actionRet))
$view->variables($actionRet);
elseif (is_object($actionRet))
$view = $actionRet;
ob_start();
$view->render();
$data = ob_get_clean();
if ($cache && !Session::fetch('noCache'))
$cache->save($name, $data);
echo $data;
static::terminate();
}
} | [
"public",
"static",
"function",
"run",
"(",
"array",
"$",
"config",
")",
"{",
"static",
"::",
"init",
"(",
"$",
"config",
")",
";",
"static",
"::",
"moduleIsActivated",
"(",
")",
";",
"$",
"cache",
"=",
"static",
"::",
"canCache",
"(",
")",
";",
"$",
"name",
"=",
"join",
"(",
"'/'",
",",
"static",
"::",
"getUrls",
"(",
")",
")",
";",
"if",
"(",
"$",
"cache",
"&&",
"$",
"out",
"=",
"$",
"cache",
"->",
"fetch",
"(",
"$",
"name",
")",
")",
"{",
"echo",
"$",
"out",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"new",
"View",
"(",
")",
";",
"$",
"controller",
"=",
"static",
"::",
"getControllerClass",
"(",
")",
";",
"$",
"controller",
"->",
"setView",
"(",
"$",
"view",
")",
";",
"$",
"action",
"=",
"static",
"::",
"getAction",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"action",
",",
"$",
"controller",
"->",
"getActions",
"(",
")",
")",
")",
"{",
"ControllerException",
"::",
"invalidAction",
"(",
"$",
"action",
")",
";",
"}",
"$",
"params",
"=",
"static",
"::",
"getParams",
"(",
")",
";",
"static",
"::",
"authenticate",
"(",
"$",
"controller",
",",
"$",
"action",
",",
"$",
"params",
")",
";",
"$",
"view",
"->",
"setController",
"(",
"$",
"controller",
")",
"->",
"setAction",
"(",
"$",
"action",
")",
";",
"$",
"refMethod",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"controller",
",",
"$",
"action",
".",
"'Action'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"<",
"$",
"refMethod",
"->",
"getNumberOfRequiredParameters",
"(",
")",
")",
"{",
"ControllerException",
"::",
"invalidParamCount",
"(",
")",
";",
"}",
"$",
"actionRet",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"controller",
",",
"$",
"action",
".",
"'Action'",
")",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"actionRet",
"!==",
"null",
"&&",
"!",
"is_array",
"(",
"$",
"actionRet",
")",
"&&",
"(",
"is_object",
"(",
"$",
"actionRet",
")",
"&&",
"get_class",
"(",
"$",
"actionRet",
")",
"!==",
"'DScribe\\View\\View'",
")",
")",
"{",
"ControllerException",
"::",
"invalidActionResult",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"actionRet",
")",
")",
"$",
"view",
"->",
"variables",
"(",
"$",
"actionRet",
")",
";",
"elseif",
"(",
"is_object",
"(",
"$",
"actionRet",
")",
")",
"$",
"view",
"=",
"$",
"actionRet",
";",
"ob_start",
"(",
")",
";",
"$",
"view",
"->",
"render",
"(",
")",
";",
"$",
"data",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"$",
"cache",
"&&",
"!",
"Session",
"::",
"fetch",
"(",
"'noCache'",
")",
")",
"$",
"cache",
"->",
"save",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"echo",
"$",
"data",
";",
"static",
"::",
"terminate",
"(",
")",
";",
"}",
"}"
] | Starts the engine
@param array $config
@todo Check caching controller actions | [
"Starts",
"the",
"engine"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L476-L525 |
miaoxing/file | src/Service/Cdn.php | Cdn.download | public function download($remoteFile)
{
// 获取文件内容
$http = wei()->http([
'url' => $remoteFile,
'timeout' => 10000,
'referer' => true,
'throwException' => false,
]);
if (!$http->isSuccess()) {
return false;
}
// 保存到本地
$dir = wei()->upload->getDir() . '/' . $this->app->getId() . '/' . date('Ymd');
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$file = $dir . time() . rand(1, 10000) . '.' . wei()->file->getExt($remoteFile);
file_put_contents($file, $http->getResponse());
return $file;
} | php | public function download($remoteFile)
{
// 获取文件内容
$http = wei()->http([
'url' => $remoteFile,
'timeout' => 10000,
'referer' => true,
'throwException' => false,
]);
if (!$http->isSuccess()) {
return false;
}
// 保存到本地
$dir = wei()->upload->getDir() . '/' . $this->app->getId() . '/' . date('Ymd');
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$file = $dir . time() . rand(1, 10000) . '.' . wei()->file->getExt($remoteFile);
file_put_contents($file, $http->getResponse());
return $file;
} | [
"public",
"function",
"download",
"(",
"$",
"remoteFile",
")",
"{",
"// 获取文件内容",
"$",
"http",
"=",
"wei",
"(",
")",
"->",
"http",
"(",
"[",
"'url'",
"=>",
"$",
"remoteFile",
",",
"'timeout'",
"=>",
"10000",
",",
"'referer'",
"=>",
"true",
",",
"'throwException'",
"=>",
"false",
",",
"]",
")",
";",
"if",
"(",
"!",
"$",
"http",
"->",
"isSuccess",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// 保存到本地",
"$",
"dir",
"=",
"wei",
"(",
")",
"->",
"upload",
"->",
"getDir",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"app",
"->",
"getId",
"(",
")",
".",
"'/'",
".",
"date",
"(",
"'Ymd'",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"mkdir",
"(",
"$",
"dir",
",",
"0777",
",",
"true",
")",
";",
"}",
"$",
"file",
"=",
"$",
"dir",
".",
"time",
"(",
")",
".",
"rand",
"(",
"1",
",",
"10000",
")",
".",
"'.'",
".",
"wei",
"(",
")",
"->",
"file",
"->",
"getExt",
"(",
"$",
"remoteFile",
")",
";",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"http",
"->",
"getResponse",
"(",
")",
")",
";",
"return",
"$",
"file",
";",
"}"
] | 下载文件到本地
@param string $remoteFile
@return bool|string | [
"下载文件到本地"
] | train | https://github.com/miaoxing/file/blob/5855a7e83992c1ba465943f1ed5ad09dd4536192/src/Service/Cdn.php#L121-L143 |
miaoxing/file | src/Service/Cdn.php | Cdn.upload | public function upload($remoteFile)
{
// 调用ueditor接口下载图片,确保图片只在一台服务器中
$app = wei()->app->getNamespace();
$url = wei()->ueditor->getOption('imageUrl') . $this->url->append('/ueditor/get-remote-image', ['app' => $app]);
$http = wei()->http([
'url' => $url,
'dataType' => 'json',
'throwException' => false,
'method' => 'post',
'data' => [
'upfile' => $remoteFile,
],
]);
if (!$http->isSuccess()) {
return false;
}
if (!isset($http['urls'][0])) {
$this->logger->alert('下载远程图片失败', [
'url' => $remoteFile,
'response' => $http->getResponse(),
]);
return false;
}
return $http['urls'][0];
} | php | public function upload($remoteFile)
{
// 调用ueditor接口下载图片,确保图片只在一台服务器中
$app = wei()->app->getNamespace();
$url = wei()->ueditor->getOption('imageUrl') . $this->url->append('/ueditor/get-remote-image', ['app' => $app]);
$http = wei()->http([
'url' => $url,
'dataType' => 'json',
'throwException' => false,
'method' => 'post',
'data' => [
'upfile' => $remoteFile,
],
]);
if (!$http->isSuccess()) {
return false;
}
if (!isset($http['urls'][0])) {
$this->logger->alert('下载远程图片失败', [
'url' => $remoteFile,
'response' => $http->getResponse(),
]);
return false;
}
return $http['urls'][0];
} | [
"public",
"function",
"upload",
"(",
"$",
"remoteFile",
")",
"{",
"// 调用ueditor接口下载图片,确保图片只在一台服务器中",
"$",
"app",
"=",
"wei",
"(",
")",
"->",
"app",
"->",
"getNamespace",
"(",
")",
";",
"$",
"url",
"=",
"wei",
"(",
")",
"->",
"ueditor",
"->",
"getOption",
"(",
"'imageUrl'",
")",
".",
"$",
"this",
"->",
"url",
"->",
"append",
"(",
"'/ueditor/get-remote-image'",
",",
"[",
"'app'",
"=>",
"$",
"app",
"]",
")",
";",
"$",
"http",
"=",
"wei",
"(",
")",
"->",
"http",
"(",
"[",
"'url'",
"=>",
"$",
"url",
",",
"'dataType'",
"=>",
"'json'",
",",
"'throwException'",
"=>",
"false",
",",
"'method'",
"=>",
"'post'",
",",
"'data'",
"=>",
"[",
"'upfile'",
"=>",
"$",
"remoteFile",
",",
"]",
",",
"]",
")",
";",
"if",
"(",
"!",
"$",
"http",
"->",
"isSuccess",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"http",
"[",
"'urls'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"alert",
"(",
"'下载远程图片失败', [",
"",
"",
"'url'",
"=>",
"$",
"remoteFile",
",",
"'response'",
"=>",
"$",
"http",
"->",
"getResponse",
"(",
")",
",",
"]",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"http",
"[",
"'urls'",
"]",
"[",
"0",
"]",
";",
"}"
] | 上传图片到CDN
@param string $remoteFile
@return bool|string
@todo 独立为服务 | [
"上传图片到CDN"
] | train | https://github.com/miaoxing/file/blob/5855a7e83992c1ba465943f1ed5ad09dd4536192/src/Service/Cdn.php#L152-L181 |
miaoxing/file | src/Service/Cdn.php | Cdn.convertToVirtualUrl | public function convertToVirtualUrl($content)
{
// 如果替换的key为空,strtr会返回false
if (!$this->realUrl) {
return $content;
}
if (is_array($content)) {
return array_map([$this, __METHOD__], $content);
}
return strtr($content, [$this->realUrl => $this->virtualUrl]);
} | php | public function convertToVirtualUrl($content)
{
// 如果替换的key为空,strtr会返回false
if (!$this->realUrl) {
return $content;
}
if (is_array($content)) {
return array_map([$this, __METHOD__], $content);
}
return strtr($content, [$this->realUrl => $this->virtualUrl]);
} | [
"public",
"function",
"convertToVirtualUrl",
"(",
"$",
"content",
")",
"{",
"// 如果替换的key为空,strtr会返回false",
"if",
"(",
"!",
"$",
"this",
"->",
"realUrl",
")",
"{",
"return",
"$",
"content",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"return",
"array_map",
"(",
"[",
"$",
"this",
",",
"__METHOD__",
"]",
",",
"$",
"content",
")",
";",
"}",
"return",
"strtr",
"(",
"$",
"content",
",",
"[",
"$",
"this",
"->",
"realUrl",
"=>",
"$",
"this",
"->",
"virtualUrl",
"]",
")",
";",
"}"
] | 更新内容中的地址为虚拟地址,用于存储
@param string|array $content
@return string|array | [
"更新内容中的地址为虚拟地址",
"用于存储"
] | train | https://github.com/miaoxing/file/blob/5855a7e83992c1ba465943f1ed5ad09dd4536192/src/Service/Cdn.php#L189-L200 |
miaoxing/file | src/Service/Cdn.php | Cdn.convertToRealUrl | public function convertToRealUrl($content)
{
if (is_array($content)) {
return array_map([$this, __METHOD__], $content);
}
// 构造替换的数据,允许没有旧地址的情况
$replaces = [$this->virtualUrl => $this->realUrl];
if ($this->oldUrl) {
$replaces[$this->oldUrl] = $this->realUrl;
}
return strtr($content, $replaces);
} | php | public function convertToRealUrl($content)
{
if (is_array($content)) {
return array_map([$this, __METHOD__], $content);
}
// 构造替换的数据,允许没有旧地址的情况
$replaces = [$this->virtualUrl => $this->realUrl];
if ($this->oldUrl) {
$replaces[$this->oldUrl] = $this->realUrl;
}
return strtr($content, $replaces);
} | [
"public",
"function",
"convertToRealUrl",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"return",
"array_map",
"(",
"[",
"$",
"this",
",",
"__METHOD__",
"]",
",",
"$",
"content",
")",
";",
"}",
"// 构造替换的数据,允许没有旧地址的情况",
"$",
"replaces",
"=",
"[",
"$",
"this",
"->",
"virtualUrl",
"=>",
"$",
"this",
"->",
"realUrl",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"oldUrl",
")",
"{",
"$",
"replaces",
"[",
"$",
"this",
"->",
"oldUrl",
"]",
"=",
"$",
"this",
"->",
"realUrl",
";",
"}",
"return",
"strtr",
"(",
"$",
"content",
",",
"$",
"replaces",
")",
";",
"}"
] | 更新内容中的地址为真实地址(如CDN地址),用于展示
@param string|array $content
@return string|array | [
"更新内容中的地址为真实地址",
"(",
"如CDN地址",
")",
"用于展示"
] | train | https://github.com/miaoxing/file/blob/5855a7e83992c1ba465943f1ed5ad09dd4536192/src/Service/Cdn.php#L208-L221 |
togucms/AnnotationBundle | Metadata/PropertyMetadata.php | PropertyMetadata.getValue | public function getValue($object) {
if(null === $this->reflectionClass) {
$this->reflectionClass = new \ReflectionClass($this->class);
}
$method = $this->reflectionClass->getMethod($this->getter);
return $method->invoke($object);
} | php | public function getValue($object) {
if(null === $this->reflectionClass) {
$this->reflectionClass = new \ReflectionClass($this->class);
}
$method = $this->reflectionClass->getMethod($this->getter);
return $method->invoke($object);
} | [
"public",
"function",
"getValue",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"reflectionClass",
")",
"{",
"$",
"this",
"->",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"class",
")",
";",
"}",
"$",
"method",
"=",
"$",
"this",
"->",
"reflectionClass",
"->",
"getMethod",
"(",
"$",
"this",
"->",
"getter",
")",
";",
"return",
"$",
"method",
"->",
"invoke",
"(",
"$",
"object",
")",
";",
"}"
] | @param object $obj
@return mixed | [
"@param",
"object",
"$obj"
] | train | https://github.com/togucms/AnnotationBundle/blob/386141ea9c6e220fdf2e012ada2b5b081ec34d61/Metadata/PropertyMetadata.php#L64-L70 |
zhaoxianfang/tools | src/Qqlogin/Oauth.php | Oauth.qq_login | public function qq_login()
{
//-------生成唯一随机串防CSRF攻击
$state = md5(uniqid(rand(), true));
session('state', $state);
//-------构造请求参数列表
$keysArr = array(
"response_type" => "code",
"client_id" => $this->appid,
"redirect_uri" => $this->callback,
"state" => $state,
"scope" => $this->scope,
);
$login_url = $this->urlUtils->combineURL(self::GET_AUTH_CODE_URL, $keysArr);
return $login_url;
// header("Location:$login_url");
} | php | public function qq_login()
{
//-------生成唯一随机串防CSRF攻击
$state = md5(uniqid(rand(), true));
session('state', $state);
//-------构造请求参数列表
$keysArr = array(
"response_type" => "code",
"client_id" => $this->appid,
"redirect_uri" => $this->callback,
"state" => $state,
"scope" => $this->scope,
);
$login_url = $this->urlUtils->combineURL(self::GET_AUTH_CODE_URL, $keysArr);
return $login_url;
// header("Location:$login_url");
} | [
"public",
"function",
"qq_login",
"(",
")",
"{",
"//-------生成唯一随机串防CSRF攻击",
"$",
"state",
"=",
"md5",
"(",
"uniqid",
"(",
"rand",
"(",
")",
",",
"true",
")",
")",
";",
"session",
"(",
"'state'",
",",
"$",
"state",
")",
";",
"//-------构造请求参数列表",
"$",
"keysArr",
"=",
"array",
"(",
"\"response_type\"",
"=>",
"\"code\"",
",",
"\"client_id\"",
"=>",
"$",
"this",
"->",
"appid",
",",
"\"redirect_uri\"",
"=>",
"$",
"this",
"->",
"callback",
",",
"\"state\"",
"=>",
"$",
"state",
",",
"\"scope\"",
"=>",
"$",
"this",
"->",
"scope",
",",
")",
";",
"$",
"login_url",
"=",
"$",
"this",
"->",
"urlUtils",
"->",
"combineURL",
"(",
"self",
"::",
"GET_AUTH_CODE_URL",
",",
"$",
"keysArr",
")",
";",
"return",
"$",
"login_url",
";",
"// header(\"Location:$login_url\");",
"}"
] | QQ登录
@Author ZhaoXianFang
@DateTime 2018-05-31
@param string $jump [跳转地址]
@return [type] [description] | [
"QQ登录"
] | train | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Qqlogin/Oauth.php#L64-L83 |
Linkvalue-Interne/MajoraOAuthServerBundle | src/Majora/Component/OAuth/Server/Server.php | Server.createLoginAttempt | protected function createLoginAttempt(array $data, array $headers, array $query)
{
// validate grant_type manually (needed to guess specialized option resolver)
if (empty($data['grant_type'])) {
throw new \InvalidArgumentException('Any grant_type given.');
}
$grantType = $data['grant_type'];
if (!$this->grantExtensions->containsKey($grantType)) {
throw new \InvalidArgumentException('Given grant_type is invalid.');
}
// create option resolver
$requestResolver = new OptionsResolver();
$requestResolver->setRequired(array(
'client_secret',
'client_api_key',
'grant_type',
));
$this->grantExtensions->get($grantType)
->configureRequestParameters($requestResolver)
;
return new LoginAttempt(
$query,
$requestResolver->resolve($data),
$headers
);
} | php | protected function createLoginAttempt(array $data, array $headers, array $query)
{
// validate grant_type manually (needed to guess specialized option resolver)
if (empty($data['grant_type'])) {
throw new \InvalidArgumentException('Any grant_type given.');
}
$grantType = $data['grant_type'];
if (!$this->grantExtensions->containsKey($grantType)) {
throw new \InvalidArgumentException('Given grant_type is invalid.');
}
// create option resolver
$requestResolver = new OptionsResolver();
$requestResolver->setRequired(array(
'client_secret',
'client_api_key',
'grant_type',
));
$this->grantExtensions->get($grantType)
->configureRequestParameters($requestResolver)
;
return new LoginAttempt(
$query,
$requestResolver->resolve($data),
$headers
);
} | [
"protected",
"function",
"createLoginAttempt",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"headers",
",",
"array",
"$",
"query",
")",
"{",
"// validate grant_type manually (needed to guess specialized option resolver)",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'grant_type'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Any grant_type given.'",
")",
";",
"}",
"$",
"grantType",
"=",
"$",
"data",
"[",
"'grant_type'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"grantExtensions",
"->",
"containsKey",
"(",
"$",
"grantType",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Given grant_type is invalid.'",
")",
";",
"}",
"// create option resolver",
"$",
"requestResolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"requestResolver",
"->",
"setRequired",
"(",
"array",
"(",
"'client_secret'",
",",
"'client_api_key'",
",",
"'grant_type'",
",",
")",
")",
";",
"$",
"this",
"->",
"grantExtensions",
"->",
"get",
"(",
"$",
"grantType",
")",
"->",
"configureRequestParameters",
"(",
"$",
"requestResolver",
")",
";",
"return",
"new",
"LoginAttempt",
"(",
"$",
"query",
",",
"$",
"requestResolver",
"->",
"resolve",
"(",
"$",
"data",
")",
",",
"$",
"headers",
")",
";",
"}"
] | Validate given request parameters and build a
LoginAttempt object with it.
@param array $data
@param array $headers
@param array $query
@return LoginAttempt | [
"Validate",
"given",
"request",
"parameters",
"and",
"build",
"a",
"LoginAttempt",
"object",
"with",
"it",
"."
] | train | https://github.com/Linkvalue-Interne/MajoraOAuthServerBundle/blob/3e84e2494c947d1bd5d5c16221a3b9e343ebff92/src/Majora/Component/OAuth/Server/Server.php#L119-L146 |
Linkvalue-Interne/MajoraOAuthServerBundle | src/Majora/Component/OAuth/Server/Server.php | Server.loadApplication | protected function loadApplication(LoginAttempt $loginAttempt)
{
// retrieve Application
if (!$application = $this->applicationLoader->retrieveByApiKeyAndSecret(
$loginAttempt->getData('client_api_key'),
$loginAttempt->getData('client_secret')
)) {
throw new InvalidGrantException(
$loginAttempt,
'Any application found for given api_key / secret.'
);
}
return $application;
} | php | protected function loadApplication(LoginAttempt $loginAttempt)
{
// retrieve Application
if (!$application = $this->applicationLoader->retrieveByApiKeyAndSecret(
$loginAttempt->getData('client_api_key'),
$loginAttempt->getData('client_secret')
)) {
throw new InvalidGrantException(
$loginAttempt,
'Any application found for given api_key / secret.'
);
}
return $application;
} | [
"protected",
"function",
"loadApplication",
"(",
"LoginAttempt",
"$",
"loginAttempt",
")",
"{",
"// retrieve Application",
"if",
"(",
"!",
"$",
"application",
"=",
"$",
"this",
"->",
"applicationLoader",
"->",
"retrieveByApiKeyAndSecret",
"(",
"$",
"loginAttempt",
"->",
"getData",
"(",
"'client_api_key'",
")",
",",
"$",
"loginAttempt",
"->",
"getData",
"(",
"'client_secret'",
")",
")",
")",
"{",
"throw",
"new",
"InvalidGrantException",
"(",
"$",
"loginAttempt",
",",
"'Any application found for given api_key / secret.'",
")",
";",
"}",
"return",
"$",
"application",
";",
"}"
] | Loads application for given login attempt.
@param LoginAttempt $loginAttempt
@return ApplicationInterface
@throws InvalidGrantException | [
"Loads",
"application",
"for",
"given",
"login",
"attempt",
"."
] | train | https://github.com/Linkvalue-Interne/MajoraOAuthServerBundle/blob/3e84e2494c947d1bd5d5c16221a3b9e343ebff92/src/Majora/Component/OAuth/Server/Server.php#L157-L171 |
Linkvalue-Interne/MajoraOAuthServerBundle | src/Majora/Component/OAuth/Server/Server.php | Server.loadAccount | protected function loadAccount(
ApplicationInterface $application,
LoginAttempt $loginAttempt
) {
// run grant extension result
return $this->grantExtensions
->get($loginAttempt->getData('grant_type'))
->grant($application, $loginAttempt)
;
} | php | protected function loadAccount(
ApplicationInterface $application,
LoginAttempt $loginAttempt
) {
// run grant extension result
return $this->grantExtensions
->get($loginAttempt->getData('grant_type'))
->grant($application, $loginAttempt)
;
} | [
"protected",
"function",
"loadAccount",
"(",
"ApplicationInterface",
"$",
"application",
",",
"LoginAttempt",
"$",
"loginAttempt",
")",
"{",
"// run grant extension result",
"return",
"$",
"this",
"->",
"grantExtensions",
"->",
"get",
"(",
"$",
"loginAttempt",
"->",
"getData",
"(",
"'grant_type'",
")",
")",
"->",
"grant",
"(",
"$",
"application",
",",
"$",
"loginAttempt",
")",
";",
"}"
] | Runs grant extension to load accounts.
@param ApplicationInterface $application
@param LoginAttempt $loginAttempt
@return AccountInterface
@throws \InvalidArgumentException
@throws UnknownGrantTypeException | [
"Runs",
"grant",
"extension",
"to",
"load",
"accounts",
"."
] | train | https://github.com/Linkvalue-Interne/MajoraOAuthServerBundle/blob/3e84e2494c947d1bd5d5c16221a3b9e343ebff92/src/Majora/Component/OAuth/Server/Server.php#L184-L193 |
Linkvalue-Interne/MajoraOAuthServerBundle | src/Majora/Component/OAuth/Server/Server.php | Server.grant | public function grant(array $data, array $headers = array(), array $query = array())
{
// create and validate login attempt from given data
$loginAttempt = $this->createLoginAttempt(
$data, $headers, $query
);
// load application / account
$account = $this->loadAccount(
$application = $this->loadApplication($loginAttempt),
$loginAttempt
);
// event call
$this->eventDispatcher->dispatch(
AccessTokenEvents::MAJORA_ACCESS_TOKEN_CREATED,
new AccessTokenEvent(
// access token generation
$accessToken = new $this->tokenOptions['access_token_class'](
$application,
$account,
$this->tokenOptions['access_token_ttl'],
null, // for now, we let the expiration date calculate itself
$this->randomTokenGenerator->generate('access_token'),
// refresh token generation only if necessary
in_array('refresh_token', $application->getAllowedGrantTypes())
&& $this->grantExtensions->containsKey('refresh_token') ?
new $this->tokenOptions['refresh_token_class'](
$application,
$account,
$this->tokenOptions['refresh_token_ttl'],
null, // same
$this->randomTokenGenerator->generate('refresh_token')
) :
null
)
)
);
return $accessToken;
} | php | public function grant(array $data, array $headers = array(), array $query = array())
{
// create and validate login attempt from given data
$loginAttempt = $this->createLoginAttempt(
$data, $headers, $query
);
// load application / account
$account = $this->loadAccount(
$application = $this->loadApplication($loginAttempt),
$loginAttempt
);
// event call
$this->eventDispatcher->dispatch(
AccessTokenEvents::MAJORA_ACCESS_TOKEN_CREATED,
new AccessTokenEvent(
// access token generation
$accessToken = new $this->tokenOptions['access_token_class'](
$application,
$account,
$this->tokenOptions['access_token_ttl'],
null, // for now, we let the expiration date calculate itself
$this->randomTokenGenerator->generate('access_token'),
// refresh token generation only if necessary
in_array('refresh_token', $application->getAllowedGrantTypes())
&& $this->grantExtensions->containsKey('refresh_token') ?
new $this->tokenOptions['refresh_token_class'](
$application,
$account,
$this->tokenOptions['refresh_token_ttl'],
null, // same
$this->randomTokenGenerator->generate('refresh_token')
) :
null
)
)
);
return $accessToken;
} | [
"public",
"function",
"grant",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"array",
"$",
"query",
"=",
"array",
"(",
")",
")",
"{",
"// create and validate login attempt from given data",
"$",
"loginAttempt",
"=",
"$",
"this",
"->",
"createLoginAttempt",
"(",
"$",
"data",
",",
"$",
"headers",
",",
"$",
"query",
")",
";",
"// load application / account",
"$",
"account",
"=",
"$",
"this",
"->",
"loadAccount",
"(",
"$",
"application",
"=",
"$",
"this",
"->",
"loadApplication",
"(",
"$",
"loginAttempt",
")",
",",
"$",
"loginAttempt",
")",
";",
"// event call",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"AccessTokenEvents",
"::",
"MAJORA_ACCESS_TOKEN_CREATED",
",",
"new",
"AccessTokenEvent",
"(",
"// access token generation",
"$",
"accessToken",
"=",
"new",
"$",
"this",
"->",
"tokenOptions",
"[",
"'access_token_class'",
"]",
"(",
"$",
"application",
",",
"$",
"account",
",",
"$",
"this",
"->",
"tokenOptions",
"[",
"'access_token_ttl'",
"]",
",",
"null",
",",
"// for now, we let the expiration date calculate itself",
"$",
"this",
"->",
"randomTokenGenerator",
"->",
"generate",
"(",
"'access_token'",
")",
",",
"// refresh token generation only if necessary",
"in_array",
"(",
"'refresh_token'",
",",
"$",
"application",
"->",
"getAllowedGrantTypes",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"grantExtensions",
"->",
"containsKey",
"(",
"'refresh_token'",
")",
"?",
"new",
"$",
"this",
"->",
"tokenOptions",
"[",
"'refresh_token_class'",
"]",
"(",
"$",
"application",
",",
"$",
"account",
",",
"$",
"this",
"->",
"tokenOptions",
"[",
"'refresh_token_ttl'",
"]",
",",
"null",
",",
"// same",
"$",
"this",
"->",
"randomTokenGenerator",
"->",
"generate",
"(",
"'refresh_token'",
")",
")",
":",
"null",
")",
")",
")",
";",
"return",
"$",
"accessToken",
";",
"}"
] | Grant given credentials, or throws an exception if invalid
credentials for application or account.
@param array $data login request data
@param array $headers optionnal login request headers
@param array $query optionnal login request query
@return AccessTokenInterface | [
"Grant",
"given",
"credentials",
"or",
"throws",
"an",
"exception",
"if",
"invalid",
"credentials",
"for",
"application",
"or",
"account",
"."
] | train | https://github.com/Linkvalue-Interne/MajoraOAuthServerBundle/blob/3e84e2494c947d1bd5d5c16221a3b9e343ebff92/src/Majora/Component/OAuth/Server/Server.php#L205-L247 |
yuncms/yuncms-composer | ManifestManager.php | ManifestManager.build | public function build()
{
$packages = [];
if (file_exists($installed = $this->vendorPath . '/composer/installed.json')) {
$packages = json_decode(file_get_contents($installed), true);
}
$frontendManifest = [];
$backendManifest = [];
$translateManifest = [];
$migrationManifest = [];
$eventManifest = [];
$taskManifest = [];
foreach ($packages as $package) {
if ($package['type'] === self::PACKAGE_TYPE && isset($package['extra'][self::EXTRA_FIELD]) && isset($package['extra'][self::EXTRA_FIELD]['id'])) {
$extra = $package['extra'][self::EXTRA_FIELD];
if (isset($extra['frontend']['class'])) {//处理前端模块
$frontendManifest[$extra['id']] = $extra['frontend'];
}
if (isset($extra['backend']['class'])) {//处理后端模块
$backendManifest[$extra['id']] = $extra['backend'];
}
if (isset($extra['translate'])) {//处理语言包
$translateManifest[$extra['id'] . '*'] = $extra['translate'];
}
if (isset($extra['migrationNamespace'])) {//迁移
$migrationManifest[] = $extra['migrationNamespace'];
}
if (isset($extra['events'])) {
foreach ($extra['events'] as $event) {
$eventManifest[] = $event;
}
}
if (isset($extra['tasks'])) {
foreach ($extra['tasks'] as $task) {
$taskManifest[] = $task;
}
}
}
}
//写清单文件
$this->write(self::FRONTEND_MODULE_FILE, $frontendManifest);
$this->write(self::BACKEND_MODULE_FILE, $backendManifest);
$this->write(self::TRANSLATE_FILE, $translateManifest);
$this->write(self::MIGRATION_FILE, $migrationManifest);
$this->write(self::EVENT_FILE, $eventManifest);
$this->write(self::TASK_FILE, $taskManifest);
} | php | public function build()
{
$packages = [];
if (file_exists($installed = $this->vendorPath . '/composer/installed.json')) {
$packages = json_decode(file_get_contents($installed), true);
}
$frontendManifest = [];
$backendManifest = [];
$translateManifest = [];
$migrationManifest = [];
$eventManifest = [];
$taskManifest = [];
foreach ($packages as $package) {
if ($package['type'] === self::PACKAGE_TYPE && isset($package['extra'][self::EXTRA_FIELD]) && isset($package['extra'][self::EXTRA_FIELD]['id'])) {
$extra = $package['extra'][self::EXTRA_FIELD];
if (isset($extra['frontend']['class'])) {//处理前端模块
$frontendManifest[$extra['id']] = $extra['frontend'];
}
if (isset($extra['backend']['class'])) {//处理后端模块
$backendManifest[$extra['id']] = $extra['backend'];
}
if (isset($extra['translate'])) {//处理语言包
$translateManifest[$extra['id'] . '*'] = $extra['translate'];
}
if (isset($extra['migrationNamespace'])) {//迁移
$migrationManifest[] = $extra['migrationNamespace'];
}
if (isset($extra['events'])) {
foreach ($extra['events'] as $event) {
$eventManifest[] = $event;
}
}
if (isset($extra['tasks'])) {
foreach ($extra['tasks'] as $task) {
$taskManifest[] = $task;
}
}
}
}
//写清单文件
$this->write(self::FRONTEND_MODULE_FILE, $frontendManifest);
$this->write(self::BACKEND_MODULE_FILE, $backendManifest);
$this->write(self::TRANSLATE_FILE, $translateManifest);
$this->write(self::MIGRATION_FILE, $migrationManifest);
$this->write(self::EVENT_FILE, $eventManifest);
$this->write(self::TASK_FILE, $taskManifest);
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"packages",
"=",
"[",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"installed",
"=",
"$",
"this",
"->",
"vendorPath",
".",
"'/composer/installed.json'",
")",
")",
"{",
"$",
"packages",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"installed",
")",
",",
"true",
")",
";",
"}",
"$",
"frontendManifest",
"=",
"[",
"]",
";",
"$",
"backendManifest",
"=",
"[",
"]",
";",
"$",
"translateManifest",
"=",
"[",
"]",
";",
"$",
"migrationManifest",
"=",
"[",
"]",
";",
"$",
"eventManifest",
"=",
"[",
"]",
";",
"$",
"taskManifest",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"$",
"package",
"[",
"'type'",
"]",
"===",
"self",
"::",
"PACKAGE_TYPE",
"&&",
"isset",
"(",
"$",
"package",
"[",
"'extra'",
"]",
"[",
"self",
"::",
"EXTRA_FIELD",
"]",
")",
"&&",
"isset",
"(",
"$",
"package",
"[",
"'extra'",
"]",
"[",
"self",
"::",
"EXTRA_FIELD",
"]",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"extra",
"=",
"$",
"package",
"[",
"'extra'",
"]",
"[",
"self",
"::",
"EXTRA_FIELD",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'frontend'",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"//处理前端模块",
"$",
"frontendManifest",
"[",
"$",
"extra",
"[",
"'id'",
"]",
"]",
"=",
"$",
"extra",
"[",
"'frontend'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'backend'",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"//处理后端模块",
"$",
"backendManifest",
"[",
"$",
"extra",
"[",
"'id'",
"]",
"]",
"=",
"$",
"extra",
"[",
"'backend'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'translate'",
"]",
")",
")",
"{",
"//处理语言包",
"$",
"translateManifest",
"[",
"$",
"extra",
"[",
"'id'",
"]",
".",
"'*'",
"]",
"=",
"$",
"extra",
"[",
"'translate'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'migrationNamespace'",
"]",
")",
")",
"{",
"//迁移",
"$",
"migrationManifest",
"[",
"]",
"=",
"$",
"extra",
"[",
"'migrationNamespace'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'events'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"extra",
"[",
"'events'",
"]",
"as",
"$",
"event",
")",
"{",
"$",
"eventManifest",
"[",
"]",
"=",
"$",
"event",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"'tasks'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"extra",
"[",
"'tasks'",
"]",
"as",
"$",
"task",
")",
"{",
"$",
"taskManifest",
"[",
"]",
"=",
"$",
"task",
";",
"}",
"}",
"}",
"}",
"//写清单文件",
"$",
"this",
"->",
"write",
"(",
"self",
"::",
"FRONTEND_MODULE_FILE",
",",
"$",
"frontendManifest",
")",
";",
"$",
"this",
"->",
"write",
"(",
"self",
"::",
"BACKEND_MODULE_FILE",
",",
"$",
"backendManifest",
")",
";",
"$",
"this",
"->",
"write",
"(",
"self",
"::",
"TRANSLATE_FILE",
",",
"$",
"translateManifest",
")",
";",
"$",
"this",
"->",
"write",
"(",
"self",
"::",
"MIGRATION_FILE",
",",
"$",
"migrationManifest",
")",
";",
"$",
"this",
"->",
"write",
"(",
"self",
"::",
"EVENT_FILE",
",",
"$",
"eventManifest",
")",
";",
"$",
"this",
"->",
"write",
"(",
"self",
"::",
"TASK_FILE",
",",
"$",
"taskManifest",
")",
";",
"}"
] | Build the manifest file. | [
"Build",
"the",
"manifest",
"file",
"."
] | train | https://github.com/yuncms/yuncms-composer/blob/ba2aa1e7b7e25bb30b991d315b8036c454e8f324/ManifestManager.php#L44-L91 |
yuncms/yuncms-composer | ManifestManager.php | ManifestManager.write | public function write($file, array $manifest)
{
$file = $this->vendorPath . '/' . $file;
$array = var_export($manifest, true);
file_put_contents($file, "<?php\n\nreturn $array;\n");
$this->opcacheInvalidate($file);
} | php | public function write($file, array $manifest)
{
$file = $this->vendorPath . '/' . $file;
$array = var_export($manifest, true);
file_put_contents($file, "<?php\n\nreturn $array;\n");
$this->opcacheInvalidate($file);
} | [
"public",
"function",
"write",
"(",
"$",
"file",
",",
"array",
"$",
"manifest",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"vendorPath",
".",
"'/'",
".",
"$",
"file",
";",
"$",
"array",
"=",
"var_export",
"(",
"$",
"manifest",
",",
"true",
")",
";",
"file_put_contents",
"(",
"$",
"file",
",",
"\"<?php\\n\\nreturn $array;\\n\"",
")",
";",
"$",
"this",
"->",
"opcacheInvalidate",
"(",
"$",
"file",
")",
";",
"}"
] | Write the manifest array to a file.
@param string $file
@param array $manifest | [
"Write",
"the",
"manifest",
"array",
"to",
"a",
"file",
"."
] | train | https://github.com/yuncms/yuncms-composer/blob/ba2aa1e7b7e25bb30b991d315b8036c454e8f324/ManifestManager.php#L98-L104 |
MatiasNAmendola/slimpower-auth-core | src/Callables/LoginNullAuthenticator.php | LoginNullAuthenticator.authenticate | public function authenticate($username, $password) {
$enc = hash(self::DEFAULT_ALG, $username . $password);
$ret = array("user" => $username, "id" => $enc);
return $ret;
} | php | public function authenticate($username, $password) {
$enc = hash(self::DEFAULT_ALG, $username . $password);
$ret = array("user" => $username, "id" => $enc);
return $ret;
} | [
"public",
"function",
"authenticate",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"enc",
"=",
"hash",
"(",
"self",
"::",
"DEFAULT_ALG",
",",
"$",
"username",
".",
"$",
"password",
")",
";",
"$",
"ret",
"=",
"array",
"(",
"\"user\"",
"=>",
"$",
"username",
",",
"\"id\"",
"=>",
"$",
"enc",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Authenticate
@param string $username Username
@param string $password Password
@return array|null User data or null | [
"Authenticate"
] | train | https://github.com/MatiasNAmendola/slimpower-auth-core/blob/550ab85d871de8451cb242eaa17f4041ff320b7c/src/Callables/LoginNullAuthenticator.php#L55-L59 |
judus/minimal-config | src/Config.php | Config.exists | public function exists($name, $else = null, $literal = false)
{
$literal || $item = $this->find($name, $this->items);
isset($item) || $item = isset($this->items[$name]) ?
$this->items[$name] : $else;
return $item;
} | php | public function exists($name, $else = null, $literal = false)
{
$literal || $item = $this->find($name, $this->items);
isset($item) || $item = isset($this->items[$name]) ?
$this->items[$name] : $else;
return $item;
} | [
"public",
"function",
"exists",
"(",
"$",
"name",
",",
"$",
"else",
"=",
"null",
",",
"$",
"literal",
"=",
"false",
")",
"{",
"$",
"literal",
"||",
"$",
"item",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
";",
"isset",
"(",
"$",
"item",
")",
"||",
"$",
"item",
"=",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
":",
"$",
"else",
";",
"return",
"$",
"item",
";",
"}"
] | @param $name
@param null $else
@param bool $literal
@return mixed|null
@throws KeyDoesNotExistException | [
"@param",
"$name",
"@param",
"null",
"$else",
"@param",
"bool",
"$literal"
] | train | https://github.com/judus/minimal-config/blob/bd72c1a6bf46f3a17da4c6ac38e43c271be679ca/src/Config.php#L71-L79 |
judus/minimal-config | src/Config.php | Config.item | public function item($name, $value = null, $literal = null)
{
$literal = is_null($literal) ? $this->isLiteral() : $literal;
func_num_args() < 2 || $this->items[$name] = $value;
if (!$literal) {
return $this->find($name, $this->items);
}
isset($this->items[$name]) || $this->throwKeyDoesNotExist($name);
return $this->items[$name];
} | php | public function item($name, $value = null, $literal = null)
{
$literal = is_null($literal) ? $this->isLiteral() : $literal;
func_num_args() < 2 || $this->items[$name] = $value;
if (!$literal) {
return $this->find($name, $this->items);
}
isset($this->items[$name]) || $this->throwKeyDoesNotExist($name);
return $this->items[$name];
} | [
"public",
"function",
"item",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"literal",
"=",
"null",
")",
"{",
"$",
"literal",
"=",
"is_null",
"(",
"$",
"literal",
")",
"?",
"$",
"this",
"->",
"isLiteral",
"(",
")",
":",
"$",
"literal",
";",
"func_num_args",
"(",
")",
"<",
"2",
"||",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"!",
"$",
"literal",
")",
"{",
"return",
"$",
"this",
"->",
"find",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
";",
"}",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
"||",
"$",
"this",
"->",
"throwKeyDoesNotExist",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
";",
"}"
] | @param $name
@param null $value
@param null|bool $literal
@return mixed
@throws KeyDoesNotExistException | [
"@param",
"$name",
"@param",
"null",
"$value",
"@param",
"null|bool",
"$literal"
] | train | https://github.com/judus/minimal-config/blob/bd72c1a6bf46f3a17da4c6ac38e43c271be679ca/src/Config.php#L89-L102 |
judus/minimal-config | src/Config.php | Config.find | public function find($name, $array, $throw = false, $parent = null)
{
list($key, $child) = array_pad(explode('.', $name, 2), 2, null);
if (!isset($array[$key]) && !$throw) {
return null;
}
isset($array[$key]) || $this->throwKeyDoesNotExist($name);
return $child ? $this->find($child, $array[$key], $name) : $array[$key];
} | php | public function find($name, $array, $throw = false, $parent = null)
{
list($key, $child) = array_pad(explode('.', $name, 2), 2, null);
if (!isset($array[$key]) && !$throw) {
return null;
}
isset($array[$key]) || $this->throwKeyDoesNotExist($name);
return $child ? $this->find($child, $array[$key], $name) : $array[$key];
} | [
"public",
"function",
"find",
"(",
"$",
"name",
",",
"$",
"array",
",",
"$",
"throw",
"=",
"false",
",",
"$",
"parent",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"child",
")",
"=",
"array_pad",
"(",
"explode",
"(",
"'.'",
",",
"$",
"name",
",",
"2",
")",
",",
"2",
",",
"null",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"$",
"throw",
")",
"{",
"return",
"null",
";",
"}",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"this",
"->",
"throwKeyDoesNotExist",
"(",
"$",
"name",
")",
";",
"return",
"$",
"child",
"?",
"$",
"this",
"->",
"find",
"(",
"$",
"child",
",",
"$",
"array",
"[",
"$",
"key",
"]",
",",
"$",
"name",
")",
":",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}"
] | @param $name
@param $array
@param null $parent
@param bool $throw
@return mixed
@throws KeyDoesNotExistException | [
"@param",
"$name",
"@param",
"$array",
"@param",
"null",
"$parent",
"@param",
"bool",
"$throw"
] | train | https://github.com/judus/minimal-config/blob/bd72c1a6bf46f3a17da4c6ac38e43c271be679ca/src/Config.php#L164-L175 |
goncalomb/asbestos | src/classes/Page.php | Page.start | public static function start()
{
if (self::$_page) {
return null;
}
self::$_page = new Html\Document();
self::$_zones['head'] = self::$_page->head();
self::$_zones['body'] = self::$_page->body();
ob_start();
return self::$_page;
} | php | public static function start()
{
if (self::$_page) {
return null;
}
self::$_page = new Html\Document();
self::$_zones['head'] = self::$_page->head();
self::$_zones['body'] = self::$_page->body();
ob_start();
return self::$_page;
} | [
"public",
"static",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_page",
")",
"{",
"return",
"null",
";",
"}",
"self",
"::",
"$",
"_page",
"=",
"new",
"Html",
"\\",
"Document",
"(",
")",
";",
"self",
"::",
"$",
"_zones",
"[",
"'head'",
"]",
"=",
"self",
"::",
"$",
"_page",
"->",
"head",
"(",
")",
";",
"self",
"::",
"$",
"_zones",
"[",
"'body'",
"]",
"=",
"self",
"::",
"$",
"_page",
"->",
"body",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"return",
"self",
"::",
"$",
"_page",
";",
"}"
] | Initialize page.
@return \Asbestos\Html\Document | [
"Initialize",
"page",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L56-L66 |
goncalomb/asbestos | src/classes/Page.php | Page.createZone | public static function createZone($zoneName, $tag='div')
{
if (self::$_page && !isset(self::$_zones[$zoneName])) {
$element = new Html\Element($tag);
self::$_zones[$zoneName] = $element;
self::append(self::$_outputZone, $element);
return $element;
}
return null;
} | php | public static function createZone($zoneName, $tag='div')
{
if (self::$_page && !isset(self::$_zones[$zoneName])) {
$element = new Html\Element($tag);
self::$_zones[$zoneName] = $element;
self::append(self::$_outputZone, $element);
return $element;
}
return null;
} | [
"public",
"static",
"function",
"createZone",
"(",
"$",
"zoneName",
",",
"$",
"tag",
"=",
"'div'",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_page",
"&&",
"!",
"isset",
"(",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
")",
")",
"{",
"$",
"element",
"=",
"new",
"Html",
"\\",
"Element",
"(",
"$",
"tag",
")",
";",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
"=",
"$",
"element",
";",
"self",
"::",
"append",
"(",
"self",
"::",
"$",
"_outputZone",
",",
"$",
"element",
")",
";",
"return",
"$",
"element",
";",
"}",
"return",
"null",
";",
"}"
] | Create a new page zone.
@param string $zoneName Zone name.
@param string $tag Tag name (defaults to div).
@return \Asbestos\Html\Element | [
"Create",
"a",
"new",
"page",
"zone",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L75-L84 |
goncalomb/asbestos | src/classes/Page.php | Page.getZone | public static function getZone($zoneName=null)
{
if ($zoneName === null) {
$zoneName = self::$_outputZone;
}
return (isset(self::$_zones[$zoneName]) ? self::$_zones[$zoneName] : null);
} | php | public static function getZone($zoneName=null)
{
if ($zoneName === null) {
$zoneName = self::$_outputZone;
}
return (isset(self::$_zones[$zoneName]) ? self::$_zones[$zoneName] : null);
} | [
"public",
"static",
"function",
"getZone",
"(",
"$",
"zoneName",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"zoneName",
"===",
"null",
")",
"{",
"$",
"zoneName",
"=",
"self",
"::",
"$",
"_outputZone",
";",
"}",
"return",
"(",
"isset",
"(",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
")",
"?",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
":",
"null",
")",
";",
"}"
] | Get zone element.
@param string $zoneName Zone name (defaults to current zone).
@return \Asbestos\Html\Element | [
"Get",
"zone",
"element",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L92-L98 |
goncalomb/asbestos | src/classes/Page.php | Page.startZone | public static function startZone($zoneName)
{
if (isset(self::$_zones[$zoneName])) {
self::flushBuffer();
self::$_zoneStack[] = self::$_outputZone;
self::$_outputZone = $zoneName;
return true;
}
return false;
} | php | public static function startZone($zoneName)
{
if (isset(self::$_zones[$zoneName])) {
self::flushBuffer();
self::$_zoneStack[] = self::$_outputZone;
self::$_outputZone = $zoneName;
return true;
}
return false;
} | [
"public",
"static",
"function",
"startZone",
"(",
"$",
"zoneName",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
")",
")",
"{",
"self",
"::",
"flushBuffer",
"(",
")",
";",
"self",
"::",
"$",
"_zoneStack",
"[",
"]",
"=",
"self",
"::",
"$",
"_outputZone",
";",
"self",
"::",
"$",
"_outputZone",
"=",
"$",
"zoneName",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Set the current output zone (pushes last to stack).
@param string $zoneName Zone name.
@return boolean | [
"Set",
"the",
"current",
"output",
"zone",
"(",
"pushes",
"last",
"to",
"stack",
")",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L117-L126 |
goncalomb/asbestos | src/classes/Page.php | Page.endZone | public static function endZone()
{
$zoneName = array_pop(self::$_zoneStack);
if ($zoneName !== null && isset(self::$_zones[$zoneName])) {
self::flushBuffer();
self::$_outputZone = $zoneName;
return true;
}
return false;
} | php | public static function endZone()
{
$zoneName = array_pop(self::$_zoneStack);
if ($zoneName !== null && isset(self::$_zones[$zoneName])) {
self::flushBuffer();
self::$_outputZone = $zoneName;
return true;
}
return false;
} | [
"public",
"static",
"function",
"endZone",
"(",
")",
"{",
"$",
"zoneName",
"=",
"array_pop",
"(",
"self",
"::",
"$",
"_zoneStack",
")",
";",
"if",
"(",
"$",
"zoneName",
"!==",
"null",
"&&",
"isset",
"(",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
")",
")",
"{",
"self",
"::",
"flushBuffer",
"(",
")",
";",
"self",
"::",
"$",
"_outputZone",
"=",
"$",
"zoneName",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Resets current output zone (removes last from stack).
@return boolean | [
"Resets",
"current",
"output",
"zone",
"(",
"removes",
"last",
"from",
"stack",
")",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L133-L142 |
goncalomb/asbestos | src/classes/Page.php | Page.append | public static function append($zoneName, ...$data)
{
if (isset(self::$_zones[$zoneName])) {
self::flushBuffer();
call_user_func_array(array(self::$_zones[$zoneName], 'append'), $data);
return true;
}
return false;
} | php | public static function append($zoneName, ...$data)
{
if (isset(self::$_zones[$zoneName])) {
self::flushBuffer();
call_user_func_array(array(self::$_zones[$zoneName], 'append'), $data);
return true;
}
return false;
} | [
"public",
"static",
"function",
"append",
"(",
"$",
"zoneName",
",",
"...",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
")",
")",
"{",
"self",
"::",
"flushBuffer",
"(",
")",
";",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"_zones",
"[",
"$",
"zoneName",
"]",
",",
"'append'",
")",
",",
"$",
"data",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Append data to to zone.
@param string $zoneName Zone name.
@param mixed $data Data to be appended.
@return boolean | [
"Append",
"data",
"to",
"to",
"zone",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L151-L159 |
goncalomb/asbestos | src/classes/Page.php | Page.flushBuffer | public static function flushBuffer()
{
if (self::$_page && ob_get_length()) {
self::$_zones[self::$_outputZone]->append(ob_get_clean());
ob_start();
return true;
}
return false;
} | php | public static function flushBuffer()
{
if (self::$_page && ob_get_length()) {
self::$_zones[self::$_outputZone]->append(ob_get_clean());
ob_start();
return true;
}
return false;
} | [
"public",
"static",
"function",
"flushBuffer",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_page",
"&&",
"ob_get_length",
"(",
")",
")",
"{",
"self",
"::",
"$",
"_zones",
"[",
"self",
"::",
"$",
"_outputZone",
"]",
"->",
"append",
"(",
"ob_get_clean",
"(",
")",
")",
";",
"ob_start",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Flushes the output buffer to the current zone element.
@return boolean | [
"Flushes",
"the",
"output",
"buffer",
"to",
"the",
"current",
"zone",
"element",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L166-L174 |
goncalomb/asbestos | src/classes/Page.php | Page.metaTag | public static function metaTag($name, $content)
{
if (self::$_page) {
self::$_page->metaTag($name, $content);
}
} | php | public static function metaTag($name, $content)
{
if (self::$_page) {
self::$_page->metaTag($name, $content);
}
} | [
"public",
"static",
"function",
"metaTag",
"(",
"$",
"name",
",",
"$",
"content",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_page",
")",
"{",
"self",
"::",
"$",
"_page",
"->",
"metaTag",
"(",
"$",
"name",
",",
"$",
"content",
")",
";",
"}",
"}"
] | Set meta tag.
@param string $name Meta tag name.
@param string $content Meta tag content. | [
"Set",
"meta",
"tag",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L194-L199 |
goncalomb/asbestos | src/classes/Page.php | Page.ogTags | public static function ogTags($data, $merge=true, $prefix='og')
{
if (self::$_page) {
self::$_page->ogTags($data, $merge, $prefix);
}
} | php | public static function ogTags($data, $merge=true, $prefix='og')
{
if (self::$_page) {
self::$_page->ogTags($data, $merge, $prefix);
}
} | [
"public",
"static",
"function",
"ogTags",
"(",
"$",
"data",
",",
"$",
"merge",
"=",
"true",
",",
"$",
"prefix",
"=",
"'og'",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_page",
")",
"{",
"self",
"::",
"$",
"_page",
"->",
"ogTags",
"(",
"$",
"data",
",",
"$",
"merge",
",",
"$",
"prefix",
")",
";",
"}",
"}"
] | Set Open Graph tags.
@param array $data Tag names and values.
@param bool $merge Merge with current tags.
@param string $prefix Tag name prefix. | [
"Set",
"Open",
"Graph",
"tags",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L208-L213 |
goncalomb/asbestos | src/classes/Page.php | Page.scriptFile | public static function scriptFile($src, $end=false)
{
if (self::$_page) {
self::$_page->scriptFile($src, $end);
}
} | php | public static function scriptFile($src, $end=false)
{
if (self::$_page) {
self::$_page->scriptFile($src, $end);
}
} | [
"public",
"static",
"function",
"scriptFile",
"(",
"$",
"src",
",",
"$",
"end",
"=",
"false",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_page",
")",
"{",
"self",
"::",
"$",
"_page",
"->",
"scriptFile",
"(",
"$",
"src",
",",
"$",
"end",
")",
";",
"}",
"}"
] | Add script file.
@param string $src The script location.
@param bool $end Add script to end of body instead of head. | [
"Add",
"script",
"file",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L221-L226 |
goncalomb/asbestos | src/classes/Page.php | Page.setMetadata | public static function setMetadata($title=null, $data=[], $merge=true)
{
if (self::$_page) {
// format the title
$simple_title = $title;
if ($title) {
$title = str_replace('{}', $title, Config::get('site.title-format', '{}'));
} else {
$simple_title = $title = Config::get('site.title', '');
}
self::$_page->title($title);
// merge data with the global configuration
if ($merge) {
if ($config_data = Config::get('site.metadata', [])) {
$data = array_merge($config_data, $data);
}
}
// set basic meta tags
foreach (['description', 'keywords', 'author'] as $name) {
if (!empty($data[$name])) {
self::$_page->metaTag($name, $data[$name]);
}
}
// set tags for Twitter Cards
if (isset($data['twitter']) && is_array($data['twitter'])) {
self::$_page->ogTags($data['twitter'], false, 'twitter');
} else {
self::$_page->ogTags([], false, 'twitter');
}
// set Open Graph tags
if (isset($data['og']) && is_array($data['og'])) {
$og_tags = [
'title' => $simple_title,
'url' => Asbestos::request()->getUrl()
];
if (!empty($data['description'])) {
$og_tags['description'] = $data['description'];
}
self::$_page->ogTags(array_merge($og_tags, $data['og']), false);
} else {
self::$_page->ogTags([], false);
}
}
} | php | public static function setMetadata($title=null, $data=[], $merge=true)
{
if (self::$_page) {
// format the title
$simple_title = $title;
if ($title) {
$title = str_replace('{}', $title, Config::get('site.title-format', '{}'));
} else {
$simple_title = $title = Config::get('site.title', '');
}
self::$_page->title($title);
// merge data with the global configuration
if ($merge) {
if ($config_data = Config::get('site.metadata', [])) {
$data = array_merge($config_data, $data);
}
}
// set basic meta tags
foreach (['description', 'keywords', 'author'] as $name) {
if (!empty($data[$name])) {
self::$_page->metaTag($name, $data[$name]);
}
}
// set tags for Twitter Cards
if (isset($data['twitter']) && is_array($data['twitter'])) {
self::$_page->ogTags($data['twitter'], false, 'twitter');
} else {
self::$_page->ogTags([], false, 'twitter');
}
// set Open Graph tags
if (isset($data['og']) && is_array($data['og'])) {
$og_tags = [
'title' => $simple_title,
'url' => Asbestos::request()->getUrl()
];
if (!empty($data['description'])) {
$og_tags['description'] = $data['description'];
}
self::$_page->ogTags(array_merge($og_tags, $data['og']), false);
} else {
self::$_page->ogTags([], false);
}
}
} | [
"public",
"static",
"function",
"setMetadata",
"(",
"$",
"title",
"=",
"null",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_page",
")",
"{",
"// format the title",
"$",
"simple_title",
"=",
"$",
"title",
";",
"if",
"(",
"$",
"title",
")",
"{",
"$",
"title",
"=",
"str_replace",
"(",
"'{}'",
",",
"$",
"title",
",",
"Config",
"::",
"get",
"(",
"'site.title-format'",
",",
"'{}'",
")",
")",
";",
"}",
"else",
"{",
"$",
"simple_title",
"=",
"$",
"title",
"=",
"Config",
"::",
"get",
"(",
"'site.title'",
",",
"''",
")",
";",
"}",
"self",
"::",
"$",
"_page",
"->",
"title",
"(",
"$",
"title",
")",
";",
"// merge data with the global configuration",
"if",
"(",
"$",
"merge",
")",
"{",
"if",
"(",
"$",
"config_data",
"=",
"Config",
"::",
"get",
"(",
"'site.metadata'",
",",
"[",
"]",
")",
")",
"{",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"config_data",
",",
"$",
"data",
")",
";",
"}",
"}",
"// set basic meta tags",
"foreach",
"(",
"[",
"'description'",
",",
"'keywords'",
",",
"'author'",
"]",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_page",
"->",
"metaTag",
"(",
"$",
"name",
",",
"$",
"data",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"// set tags for Twitter Cards",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'twitter'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"'twitter'",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_page",
"->",
"ogTags",
"(",
"$",
"data",
"[",
"'twitter'",
"]",
",",
"false",
",",
"'twitter'",
")",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"_page",
"->",
"ogTags",
"(",
"[",
"]",
",",
"false",
",",
"'twitter'",
")",
";",
"}",
"// set Open Graph tags",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'og'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"'og'",
"]",
")",
")",
"{",
"$",
"og_tags",
"=",
"[",
"'title'",
"=>",
"$",
"simple_title",
",",
"'url'",
"=>",
"Asbestos",
"::",
"request",
"(",
")",
"->",
"getUrl",
"(",
")",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"og_tags",
"[",
"'description'",
"]",
"=",
"$",
"data",
"[",
"'description'",
"]",
";",
"}",
"self",
"::",
"$",
"_page",
"->",
"ogTags",
"(",
"array_merge",
"(",
"$",
"og_tags",
",",
"$",
"data",
"[",
"'og'",
"]",
")",
",",
"false",
")",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"_page",
"->",
"ogTags",
"(",
"[",
"]",
",",
"false",
")",
";",
"}",
"}",
"}"
] | Set page title and metadata using the config (see site.metadata config).
@param string $title The document title.
@param array $data The metadata array.
@param bool $merge Merge with current tags. | [
"Set",
"page",
"title",
"and",
"metadata",
"using",
"the",
"config",
"(",
"see",
"site",
".",
"metadata",
"config",
")",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L248-L291 |
goncalomb/asbestos | src/classes/Page.php | Page.end | public static function end()
{
if (!self::$_page || ErrorHandling::lastError()) {
return;
}
self::$_zones[self::$_outputZone]->append(ob_get_clean());
self::$_page->output();
// reset class
self::$_page = null;
self::$_zones = array();
self::$_zoneStack = array();
self::$_outputZone = 'body';
echo '<!-- ';
echo '~', Asbestos::executionTime();
echo " -->\n";
} | php | public static function end()
{
if (!self::$_page || ErrorHandling::lastError()) {
return;
}
self::$_zones[self::$_outputZone]->append(ob_get_clean());
self::$_page->output();
// reset class
self::$_page = null;
self::$_zones = array();
self::$_zoneStack = array();
self::$_outputZone = 'body';
echo '<!-- ';
echo '~', Asbestos::executionTime();
echo " -->\n";
} | [
"public",
"static",
"function",
"end",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"_page",
"||",
"ErrorHandling",
"::",
"lastError",
"(",
")",
")",
"{",
"return",
";",
"}",
"self",
"::",
"$",
"_zones",
"[",
"self",
"::",
"$",
"_outputZone",
"]",
"->",
"append",
"(",
"ob_get_clean",
"(",
")",
")",
";",
"self",
"::",
"$",
"_page",
"->",
"output",
"(",
")",
";",
"// reset class",
"self",
"::",
"$",
"_page",
"=",
"null",
";",
"self",
"::",
"$",
"_zones",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"_zoneStack",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"_outputZone",
"=",
"'body'",
";",
"echo",
"'<!-- '",
";",
"echo",
"'~'",
",",
"Asbestos",
"::",
"executionTime",
"(",
")",
";",
"echo",
"\" -->\\n\"",
";",
"}"
] | Finalize and output page. | [
"Finalize",
"and",
"output",
"page",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Page.php#L326-L343 |
Innmind/Compose | src/Definition/Argument.php | Argument.validate | public function validate($value): void
{
if (!$this->type->accepts($value)) {
throw new InvalidArgument((string) $this->name);
}
} | php | public function validate($value): void
{
if (!$this->type->accepts($value)) {
throw new InvalidArgument((string) $this->name);
}
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"type",
"->",
"accepts",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidArgument",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"name",
")",
";",
"}",
"}"
] | @param mixed $value
@throws InvalidArgument | [
"@param",
"mixed",
"$value"
] | train | https://github.com/Innmind/Compose/blob/1a833d7ba2f6248e9c472c00cd7aca041c1a2ba9/src/Definition/Argument.php#L71-L76 |
yuncms/yii2-article | frontend/models/ManageSearch.php | ManageSearch.search | public function search($params)
{
$query = Article::find()->where(['user_id' => Yii::$app->user->id]);
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'status' => $this->status,
'comments' => $this->comments,
'supports' => $this->supports,
'collections' => $this->collections,
'views' => $this->views,
'is_top' => $this->is_top,
'is_best' => $this->is_best,
]);
$query->andFilterWhere(['like', 'uuid', $this->uuid])
->andFilterWhere(['like', 'category_id', $this->category_id])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'sub_title', $this->sub_title]);
return $dataProvider;
} | php | public function search($params)
{
$query = Article::find()->where(['user_id' => Yii::$app->user->id]);
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'status' => $this->status,
'comments' => $this->comments,
'supports' => $this->supports,
'collections' => $this->collections,
'views' => $this->views,
'is_top' => $this->is_top,
'is_best' => $this->is_best,
]);
$query->andFilterWhere(['like', 'uuid', $this->uuid])
->andFilterWhere(['like', 'category_id', $this->category_id])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'sub_title', $this->sub_title]);
return $dataProvider;
} | [
"public",
"function",
"search",
"(",
"$",
"params",
")",
"{",
"$",
"query",
"=",
"Article",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
"]",
")",
";",
"// add conditions that should always apply here",
"$",
"dataProvider",
"=",
"new",
"ActiveDataProvider",
"(",
"[",
"'query'",
"=>",
"$",
"query",
",",
"]",
")",
";",
"$",
"this",
"->",
"load",
"(",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"// uncomment the following line if you do not want to return any records when validation fails",
"// $query->where('0=1');",
"return",
"$",
"dataProvider",
";",
"}",
"// grid filtering conditions",
"$",
"query",
"->",
"andFilterWhere",
"(",
"[",
"'status'",
"=>",
"$",
"this",
"->",
"status",
",",
"'comments'",
"=>",
"$",
"this",
"->",
"comments",
",",
"'supports'",
"=>",
"$",
"this",
"->",
"supports",
",",
"'collections'",
"=>",
"$",
"this",
"->",
"collections",
",",
"'views'",
"=>",
"$",
"this",
"->",
"views",
",",
"'is_top'",
"=>",
"$",
"this",
"->",
"is_top",
",",
"'is_best'",
"=>",
"$",
"this",
"->",
"is_best",
",",
"]",
")",
";",
"$",
"query",
"->",
"andFilterWhere",
"(",
"[",
"'like'",
",",
"'uuid'",
",",
"$",
"this",
"->",
"uuid",
"]",
")",
"->",
"andFilterWhere",
"(",
"[",
"'like'",
",",
"'category_id'",
",",
"$",
"this",
"->",
"category_id",
"]",
")",
"->",
"andFilterWhere",
"(",
"[",
"'like'",
",",
"'title'",
",",
"$",
"this",
"->",
"title",
"]",
")",
"->",
"andFilterWhere",
"(",
"[",
"'like'",
",",
"'sub_title'",
",",
"$",
"this",
"->",
"sub_title",
"]",
")",
";",
"return",
"$",
"dataProvider",
";",
"}"
] | Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider | [
"Creates",
"data",
"provider",
"instance",
"with",
"search",
"query",
"applied"
] | train | https://github.com/yuncms/yii2-article/blob/177ec4d3d143b2f2a69bce760e873485cf3df192/frontend/models/ManageSearch.php#L42-L78 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Type/TypeFactory.php | TypeFactory.getType | public static function getType($type)
{
if (!isset(self::$typesMap[$type])) {
throw new \InvalidArgumentException(sprintf('Invalid type specified "%s".', $type));
}
if (!isset(self::$typeObjects[$type])) {
$className = self::$typesMap[$type];
self::$typeObjects[$type] = new $className;
}
return self::$typeObjects[$type];
} | php | public static function getType($type)
{
if (!isset(self::$typesMap[$type])) {
throw new \InvalidArgumentException(sprintf('Invalid type specified "%s".', $type));
}
if (!isset(self::$typeObjects[$type])) {
$className = self::$typesMap[$type];
self::$typeObjects[$type] = new $className;
}
return self::$typeObjects[$type];
} | [
"public",
"static",
"function",
"getType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"typesMap",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid type specified \"%s\".'",
",",
"$",
"type",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"typeObjects",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"className",
"=",
"self",
"::",
"$",
"typesMap",
"[",
"$",
"type",
"]",
";",
"self",
"::",
"$",
"typeObjects",
"[",
"$",
"type",
"]",
"=",
"new",
"$",
"className",
";",
"}",
"return",
"self",
"::",
"$",
"typeObjects",
"[",
"$",
"type",
"]",
";",
"}"
] | Get a Type instance.
@param string $type The type name.
@return Type $type
@throws \InvalidArgumentException | [
"Get",
"a",
"Type",
"instance",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Type/TypeFactory.php#L78-L89 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Type/TypeFactory.php | TypeFactory.getTypeFromPHPVariable | public static function getTypeFromPHPVariable($variable)
{
if ($variable === null) {
throw ODMException::cannotInferTypeFromNullValue();
}
$phpType = gettype($variable);
if ($phpType === 'string') {
if ($variable === '') {
throw new \InvalidArgumentException;
}
return self::getType(Type::STRING);
}
if ($phpType instanceof NumberValue) {
//use type coercion to determine the actual php type
$phpType = gettype((string)$variable + 0);
}
if ($phpType === 'integer') {
return self::getType(Type::INT);
}
if ($phpType === 'double') {
return self::getType(Type::FLOAT);
}
if (is_resource($variable) || $variable instanceof StreamInterface || $variable instanceof BinaryValue) {
return self::getType(Type::BIN);
}
if ($phpType === 'object') {
if ($variable instanceof SetValue) {
return self::getType(Type::SET);
}
if (!$variable instanceof \Traversable && !$variable instanceof \stdClass) {
throw ODMException::unmappedObjectSerializationNotSupported();
}
//Traversable objects fall through to the array case
$phpType = 'array';
}
if ($phpType === 'array') {
$i = 0;
foreach ($variable as $k => $v) {
if (!is_int($k) || $k != $i++) {
return self::getType(Type::MAP);
}
}
return self::getType(Type::LIST_);
}
if ($phpType === 'boolean') {
return self::getType(Type::BOOL);
}
//NULL, closed resource or unknown type
throw new \InvalidArgumentException;
} | php | public static function getTypeFromPHPVariable($variable)
{
if ($variable === null) {
throw ODMException::cannotInferTypeFromNullValue();
}
$phpType = gettype($variable);
if ($phpType === 'string') {
if ($variable === '') {
throw new \InvalidArgumentException;
}
return self::getType(Type::STRING);
}
if ($phpType instanceof NumberValue) {
//use type coercion to determine the actual php type
$phpType = gettype((string)$variable + 0);
}
if ($phpType === 'integer') {
return self::getType(Type::INT);
}
if ($phpType === 'double') {
return self::getType(Type::FLOAT);
}
if (is_resource($variable) || $variable instanceof StreamInterface || $variable instanceof BinaryValue) {
return self::getType(Type::BIN);
}
if ($phpType === 'object') {
if ($variable instanceof SetValue) {
return self::getType(Type::SET);
}
if (!$variable instanceof \Traversable && !$variable instanceof \stdClass) {
throw ODMException::unmappedObjectSerializationNotSupported();
}
//Traversable objects fall through to the array case
$phpType = 'array';
}
if ($phpType === 'array') {
$i = 0;
foreach ($variable as $k => $v) {
if (!is_int($k) || $k != $i++) {
return self::getType(Type::MAP);
}
}
return self::getType(Type::LIST_);
}
if ($phpType === 'boolean') {
return self::getType(Type::BOOL);
}
//NULL, closed resource or unknown type
throw new \InvalidArgumentException;
} | [
"public",
"static",
"function",
"getTypeFromPHPVariable",
"(",
"$",
"variable",
")",
"{",
"if",
"(",
"$",
"variable",
"===",
"null",
")",
"{",
"throw",
"ODMException",
"::",
"cannotInferTypeFromNullValue",
"(",
")",
";",
"}",
"$",
"phpType",
"=",
"gettype",
"(",
"$",
"variable",
")",
";",
"if",
"(",
"$",
"phpType",
"===",
"'string'",
")",
"{",
"if",
"(",
"$",
"variable",
"===",
"''",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
";",
"}",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"STRING",
")",
";",
"}",
"if",
"(",
"$",
"phpType",
"instanceof",
"NumberValue",
")",
"{",
"//use type coercion to determine the actual php type",
"$",
"phpType",
"=",
"gettype",
"(",
"(",
"string",
")",
"$",
"variable",
"+",
"0",
")",
";",
"}",
"if",
"(",
"$",
"phpType",
"===",
"'integer'",
")",
"{",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"INT",
")",
";",
"}",
"if",
"(",
"$",
"phpType",
"===",
"'double'",
")",
"{",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"FLOAT",
")",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"variable",
")",
"||",
"$",
"variable",
"instanceof",
"StreamInterface",
"||",
"$",
"variable",
"instanceof",
"BinaryValue",
")",
"{",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"BIN",
")",
";",
"}",
"if",
"(",
"$",
"phpType",
"===",
"'object'",
")",
"{",
"if",
"(",
"$",
"variable",
"instanceof",
"SetValue",
")",
"{",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"SET",
")",
";",
"}",
"if",
"(",
"!",
"$",
"variable",
"instanceof",
"\\",
"Traversable",
"&&",
"!",
"$",
"variable",
"instanceof",
"\\",
"stdClass",
")",
"{",
"throw",
"ODMException",
"::",
"unmappedObjectSerializationNotSupported",
"(",
")",
";",
"}",
"//Traversable objects fall through to the array case",
"$",
"phpType",
"=",
"'array'",
";",
"}",
"if",
"(",
"$",
"phpType",
"===",
"'array'",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"variable",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"k",
")",
"||",
"$",
"k",
"!=",
"$",
"i",
"++",
")",
"{",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"MAP",
")",
";",
"}",
"}",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"LIST_",
")",
";",
"}",
"if",
"(",
"$",
"phpType",
"===",
"'boolean'",
")",
"{",
"return",
"self",
"::",
"getType",
"(",
"Type",
"::",
"BOOL",
")",
";",
"}",
"//NULL, closed resource or unknown type",
"throw",
"new",
"\\",
"InvalidArgumentException",
";",
"}"
] | Get a Type instance based on the type of the passed php variable.
Adapted from {@see \Aws\DynamoDb\Marshaler}
@param mixed $variable
@return Type $type
@throws ODMException | [
"Get",
"a",
"Type",
"instance",
"based",
"on",
"the",
"type",
"of",
"the",
"passed",
"php",
"variable",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Type/TypeFactory.php#L102-L165 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Type/TypeFactory.php | TypeFactory.overrideType | public static function overrideType($name, $className)
{
if (!isset(self::$typesMap[$name])) {
throw MappingException::typeNotFound($name);
}
self::$typesMap[$name] = $className;
} | php | public static function overrideType($name, $className)
{
if (!isset(self::$typesMap[$name])) {
throw MappingException::typeNotFound($name);
}
self::$typesMap[$name] = $className;
} | [
"public",
"static",
"function",
"overrideType",
"(",
"$",
"name",
",",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"typesMap",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"typeNotFound",
"(",
"$",
"name",
")",
";",
"}",
"self",
"::",
"$",
"typesMap",
"[",
"$",
"name",
"]",
"=",
"$",
"className",
";",
"}"
] | Overrides an already defined type to use a different implementation.
@param string $name
@param string $className
@throws MappingException | [
"Overrides",
"an",
"already",
"defined",
"type",
"to",
"use",
"a",
"different",
"implementation",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Type/TypeFactory.php#L198-L205 |
pluf/discount | src/Discount/Service.php | Discount_Service.discountIsValid | public static function discountIsValid($code)
{
$discount = Discount_Shortcuts_GetDiscountByCodeOrNull($code);
if ($discount == null)
return false;
$engine = Discount_Shortcuts_GetEngineOrNull($discount->get_type());
if ($engine == null)
return false;
return $engine->isValid($discount);
} | php | public static function discountIsValid($code)
{
$discount = Discount_Shortcuts_GetDiscountByCodeOrNull($code);
if ($discount == null)
return false;
$engine = Discount_Shortcuts_GetEngineOrNull($discount->get_type());
if ($engine == null)
return false;
return $engine->isValid($discount);
} | [
"public",
"static",
"function",
"discountIsValid",
"(",
"$",
"code",
")",
"{",
"$",
"discount",
"=",
"Discount_Shortcuts_GetDiscountByCodeOrNull",
"(",
"$",
"code",
")",
";",
"if",
"(",
"$",
"discount",
"==",
"null",
")",
"return",
"false",
";",
"$",
"engine",
"=",
"Discount_Shortcuts_GetEngineOrNull",
"(",
"$",
"discount",
"->",
"get_type",
"(",
")",
")",
";",
"if",
"(",
"$",
"engine",
"==",
"null",
")",
"return",
"false",
";",
"return",
"$",
"engine",
"->",
"isValid",
"(",
"$",
"discount",
")",
";",
"}"
] | Checks if discount with given code is valid.
@param string $code
@return boolean | [
"Checks",
"if",
"discount",
"with",
"given",
"code",
"is",
"valid",
"."
] | train | https://github.com/pluf/discount/blob/b0006d6b25dd61241f51b5b098d7d546b470de26/src/Discount/Service.php#L49-L58 |
pluf/discount | src/Discount/Service.php | Discount_Service.getPrice | public static function getPrice($originPrice, $discountCode, $request)
{
$discount = Discount_Shortcuts_GetDiscountByCodeOr404($discountCode);
$engine = $discount->get_engine();
return $engine->getPrice($originPrice, $discount, $request);
} | php | public static function getPrice($originPrice, $discountCode, $request)
{
$discount = Discount_Shortcuts_GetDiscountByCodeOr404($discountCode);
$engine = $discount->get_engine();
return $engine->getPrice($originPrice, $discount, $request);
} | [
"public",
"static",
"function",
"getPrice",
"(",
"$",
"originPrice",
",",
"$",
"discountCode",
",",
"$",
"request",
")",
"{",
"$",
"discount",
"=",
"Discount_Shortcuts_GetDiscountByCodeOr404",
"(",
"$",
"discountCode",
")",
";",
"$",
"engine",
"=",
"$",
"discount",
"->",
"get_engine",
"(",
")",
";",
"return",
"$",
"engine",
"->",
"getPrice",
"(",
"$",
"originPrice",
",",
"$",
"discount",
",",
"$",
"request",
")",
";",
"}"
] | Computes and returns new price after using given discount
@param integer $originPrice
@param string $discountCode
@param Pluf_HTTP_Request $request
@return integer | [
"Computes",
"and",
"returns",
"new",
"price",
"after",
"using",
"given",
"discount"
] | train | https://github.com/pluf/discount/blob/b0006d6b25dd61241f51b5b098d7d546b470de26/src/Discount/Service.php#L68-L73 |
pluf/discount | src/Discount/Service.php | Discount_Service.consumeDiscount | public static function consumeDiscount($discountCode)
{
$discount = Discount_Shortcuts_GetDiscountByCodeOr404($discountCode);
$engine = $discount->get_engine();
$engine->consumeDiscount($discount);
return $discount;
} | php | public static function consumeDiscount($discountCode)
{
$discount = Discount_Shortcuts_GetDiscountByCodeOr404($discountCode);
$engine = $discount->get_engine();
$engine->consumeDiscount($discount);
return $discount;
} | [
"public",
"static",
"function",
"consumeDiscount",
"(",
"$",
"discountCode",
")",
"{",
"$",
"discount",
"=",
"Discount_Shortcuts_GetDiscountByCodeOr404",
"(",
"$",
"discountCode",
")",
";",
"$",
"engine",
"=",
"$",
"discount",
"->",
"get_engine",
"(",
")",
";",
"$",
"engine",
"->",
"consumeDiscount",
"(",
"$",
"discount",
")",
";",
"return",
"$",
"discount",
";",
"}"
] | Decrease one unit of given discount.
If discount is one-time-use it will be invalid after this function.
@param string $discountCode
@return Discount_Discount | [
"Decrease",
"one",
"unit",
"of",
"given",
"discount",
".",
"If",
"discount",
"is",
"one",
"-",
"time",
"-",
"use",
"it",
"will",
"be",
"invalid",
"after",
"this",
"function",
"."
] | train | https://github.com/pluf/discount/blob/b0006d6b25dd61241f51b5b098d7d546b470de26/src/Discount/Service.php#L82-L88 |
nhlm/pipechain | src/InvokerProcessors/Traits/StackProcessingTrait.php | StackProcessingTrait.processStack | public function processStack($payload, PipeChainCollectionInterface $pipeChainCollection)
{
foreach ( $pipeChainCollection as $stage => $fallback ) {
$payload = $this->process($payload, $stage, $fallback);
}
return $payload;
} | php | public function processStack($payload, PipeChainCollectionInterface $pipeChainCollection)
{
foreach ( $pipeChainCollection as $stage => $fallback ) {
$payload = $this->process($payload, $stage, $fallback);
}
return $payload;
} | [
"public",
"function",
"processStack",
"(",
"$",
"payload",
",",
"PipeChainCollectionInterface",
"$",
"pipeChainCollection",
")",
"{",
"foreach",
"(",
"$",
"pipeChainCollection",
"as",
"$",
"stage",
"=>",
"$",
"fallback",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"process",
"(",
"$",
"payload",
",",
"$",
"stage",
",",
"$",
"fallback",
")",
";",
"}",
"return",
"$",
"payload",
";",
"}"
] | processes a PipeChainCollection with the provided payload.
@param mixed $payload
@param PipeChainCollectionInterface $pipeChainCollection
@return mixed payload | [
"processes",
"a",
"PipeChainCollection",
"with",
"the",
"provided",
"payload",
"."
] | train | https://github.com/nhlm/pipechain/blob/7f67b54372415a66c42ce074bc359c55fda218a5/src/InvokerProcessors/Traits/StackProcessingTrait.php#L25-L32 |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/http/HttpRequest.php | HttpRequest.fetchJSON | public function fetchJSON($url, $followRedirects = true, $username = null, $password = null, $headers = array())
{
$contents = $this->fetchURL($url, $followRedirects, $username, $password, $headers);
return JSONUtils::decode($contents,true);
} | php | public function fetchJSON($url, $followRedirects = true, $username = null, $password = null, $headers = array())
{
$contents = $this->fetchURL($url, $followRedirects, $username, $password, $headers);
return JSONUtils::decode($contents,true);
} | [
"public",
"function",
"fetchJSON",
"(",
"$",
"url",
",",
"$",
"followRedirects",
"=",
"true",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"headers",
"=",
"array",
"(",
")",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"fetchURL",
"(",
"$",
"url",
",",
"$",
"followRedirects",
",",
"$",
"username",
",",
"$",
"password",
",",
"$",
"headers",
")",
";",
"return",
"JSONUtils",
"::",
"decode",
"(",
"$",
"contents",
",",
"true",
")",
";",
"}"
] | Fetch the contents of a URL as a JSON array
@param string $url Fully-qualified URL to request
@param bool $followRedirects If true, follow redirects to default max of 5
@param string $username Username to use in http authentication header
@param string $password Password to use in http authentication header
@param array $headers Array of http headers to append to the existing headers list
@return array PHP array version of JSON contents
@throws HttpRequestException If contents cannot be fetched | [
"Fetch",
"the",
"contents",
"of",
"a",
"URL",
"as",
"a",
"JSON",
"array"
] | train | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/http/HttpRequest.php#L63-L67 |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/http/HttpRequest.php | HttpRequest.headURL | public function headURL($url, $followRedirects = true, $username = null, $password = null, $headers = array())
{
if (function_exists('curl_init')) {
$contents = $this->curlRequest($url, true, $followRedirects, $username, $password, $headers);
return $contents;
} else {
throw new HttpRequestException('headURL not supported without curl');
}
} | php | public function headURL($url, $followRedirects = true, $username = null, $password = null, $headers = array())
{
if (function_exists('curl_init')) {
$contents = $this->curlRequest($url, true, $followRedirects, $username, $password, $headers);
return $contents;
} else {
throw new HttpRequestException('headURL not supported without curl');
}
} | [
"public",
"function",
"headURL",
"(",
"$",
"url",
",",
"$",
"followRedirects",
"=",
"true",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"headers",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'curl_init'",
")",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"curlRequest",
"(",
"$",
"url",
",",
"true",
",",
"$",
"followRedirects",
",",
"$",
"username",
",",
"$",
"password",
",",
"$",
"headers",
")",
";",
"return",
"$",
"contents",
";",
"}",
"else",
"{",
"throw",
"new",
"HttpRequestException",
"(",
"'headURL not supported without curl'",
")",
";",
"}",
"}"
] | Fetch the headers of a URL
@param string $url Fully-qualified URL to request
@param bool $followRedirects If true, follow redirects to default max of 5
@param string $username Username to use in http authentication header
@param string $password Password to use in http authentication header
@param array $headers Array of http headers to append to the existing headers list
@return string Contents of the HTTP headers
@throws HttpRequestException If contents cannot be fetched | [
"Fetch",
"the",
"headers",
"of",
"a",
"URL"
] | train | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/http/HttpRequest.php#L81-L94 |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/http/HttpRequest.php | HttpRequest.postURL | public function postURL($url, $postData, $username = null, $password = null, $headers = array(), &$responseHeaders = false)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
if ($this->timeout != null) {
curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, $this->timeout);
}
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
if ($username && $password) {
curl_setopt($c, CURLOPT_USERPWD, "$username:$password");
}
if (!empty($headers)) {
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
}
if ($responseHeaders !== false) {
curl_setopt($c, CURLOPT_HEADER, true);
}
curl_setopt($c, CURLOPT_REFERER, $url);
if ($this->userAgent != null)
curl_setopt($c, CURLOPT_USERAGENT, $this->userAgent);
$rawContents = curl_exec($c);
$error = curl_error($c);
$responseCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
if ($rawContents && $responseHeaders !== false) {
list($headerBlock, $contents) = explode("\\r\\n\\r\\n", $rawContents, 2);
$responseHeaders = array();
foreach(explode("\\r\\n", $headerBlock) as $headerString) {
@list($headerName, $headerValue) = explode(':', $headerString, 2);
$responseHeaders[trim($headerName)] = trim($headerValue);
}
} else {
$contents = $rawContents;
}
// errors
switch (true) {
case $contents === false:
throw new HttpRequestTransferException("Error posting to URL '".$url."': ".$error);
case $responseCode >= 500:
$e = new HttpRequestServerException("Request to URL '$url' returned server error $responseCode. Body: '$contents'", $responseCode);
$e->responseBody = $contents;
$e->responseHeaders = $headers;
throw $e;
case $responseCode >= 400:
$e = new HttpRequestServerException("Request to URL '$url' returned client error $responseCode. Body: '$contents'", $responseCode);
$e->responseBody = $contents;
$e->responseHeaders = $headers;
throw $e;
default:
}
unset($error);
unset($responseCode);
unset($curl);
unset($url);
unset($c);
return $contents;
} | php | public function postURL($url, $postData, $username = null, $password = null, $headers = array(), &$responseHeaders = false)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
if ($this->timeout != null) {
curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, $this->timeout);
}
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
if ($username && $password) {
curl_setopt($c, CURLOPT_USERPWD, "$username:$password");
}
if (!empty($headers)) {
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
}
if ($responseHeaders !== false) {
curl_setopt($c, CURLOPT_HEADER, true);
}
curl_setopt($c, CURLOPT_REFERER, $url);
if ($this->userAgent != null)
curl_setopt($c, CURLOPT_USERAGENT, $this->userAgent);
$rawContents = curl_exec($c);
$error = curl_error($c);
$responseCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
if ($rawContents && $responseHeaders !== false) {
list($headerBlock, $contents) = explode("\\r\\n\\r\\n", $rawContents, 2);
$responseHeaders = array();
foreach(explode("\\r\\n", $headerBlock) as $headerString) {
@list($headerName, $headerValue) = explode(':', $headerString, 2);
$responseHeaders[trim($headerName)] = trim($headerValue);
}
} else {
$contents = $rawContents;
}
// errors
switch (true) {
case $contents === false:
throw new HttpRequestTransferException("Error posting to URL '".$url."': ".$error);
case $responseCode >= 500:
$e = new HttpRequestServerException("Request to URL '$url' returned server error $responseCode. Body: '$contents'", $responseCode);
$e->responseBody = $contents;
$e->responseHeaders = $headers;
throw $e;
case $responseCode >= 400:
$e = new HttpRequestServerException("Request to URL '$url' returned client error $responseCode. Body: '$contents'", $responseCode);
$e->responseBody = $contents;
$e->responseHeaders = $headers;
throw $e;
default:
}
unset($error);
unset($responseCode);
unset($curl);
unset($url);
unset($c);
return $contents;
} | [
"public",
"function",
"postURL",
"(",
"$",
"url",
",",
"$",
"postData",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"&",
"$",
"responseHeaders",
"=",
"false",
")",
"{",
"$",
"c",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"if",
"(",
"$",
"this",
"->",
"timeout",
"!=",
"null",
")",
"{",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_TIMEOUT",
",",
"$",
"this",
"->",
"timeout",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_CONNECTTIMEOUT",
",",
"$",
"this",
"->",
"timeout",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"2",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"postData",
")",
";",
"if",
"(",
"$",
"username",
"&&",
"$",
"password",
")",
"{",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_USERPWD",
",",
"\"$username:$password\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"headers",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"}",
"if",
"(",
"$",
"responseHeaders",
"!==",
"false",
")",
"{",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_REFERER",
",",
"$",
"url",
")",
";",
"if",
"(",
"$",
"this",
"->",
"userAgent",
"!=",
"null",
")",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_USERAGENT",
",",
"$",
"this",
"->",
"userAgent",
")",
";",
"$",
"rawContents",
"=",
"curl_exec",
"(",
"$",
"c",
")",
";",
"$",
"error",
"=",
"curl_error",
"(",
"$",
"c",
")",
";",
"$",
"responseCode",
"=",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"c",
")",
";",
"if",
"(",
"$",
"rawContents",
"&&",
"$",
"responseHeaders",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"headerBlock",
",",
"$",
"contents",
")",
"=",
"explode",
"(",
"\"\\\\r\\\\n\\\\r\\\\n\"",
",",
"$",
"rawContents",
",",
"2",
")",
";",
"$",
"responseHeaders",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"\"\\\\r\\\\n\"",
",",
"$",
"headerBlock",
")",
"as",
"$",
"headerString",
")",
"{",
"@",
"list",
"(",
"$",
"headerName",
",",
"$",
"headerValue",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"headerString",
",",
"2",
")",
";",
"$",
"responseHeaders",
"[",
"trim",
"(",
"$",
"headerName",
")",
"]",
"=",
"trim",
"(",
"$",
"headerValue",
")",
";",
"}",
"}",
"else",
"{",
"$",
"contents",
"=",
"$",
"rawContents",
";",
"}",
"// errors",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"contents",
"===",
"false",
":",
"throw",
"new",
"HttpRequestTransferException",
"(",
"\"Error posting to URL '\"",
".",
"$",
"url",
".",
"\"': \"",
".",
"$",
"error",
")",
";",
"case",
"$",
"responseCode",
">=",
"500",
":",
"$",
"e",
"=",
"new",
"HttpRequestServerException",
"(",
"\"Request to URL '$url' returned server error $responseCode. Body: '$contents'\"",
",",
"$",
"responseCode",
")",
";",
"$",
"e",
"->",
"responseBody",
"=",
"$",
"contents",
";",
"$",
"e",
"->",
"responseHeaders",
"=",
"$",
"headers",
";",
"throw",
"$",
"e",
";",
"case",
"$",
"responseCode",
">=",
"400",
":",
"$",
"e",
"=",
"new",
"HttpRequestServerException",
"(",
"\"Request to URL '$url' returned client error $responseCode. Body: '$contents'\"",
",",
"$",
"responseCode",
")",
";",
"$",
"e",
"->",
"responseBody",
"=",
"$",
"contents",
";",
"$",
"e",
"->",
"responseHeaders",
"=",
"$",
"headers",
";",
"throw",
"$",
"e",
";",
"default",
":",
"}",
"unset",
"(",
"$",
"error",
")",
";",
"unset",
"(",
"$",
"responseCode",
")",
";",
"unset",
"(",
"$",
"curl",
")",
";",
"unset",
"(",
"$",
"url",
")",
";",
"unset",
"(",
"$",
"c",
")",
";",
"return",
"$",
"contents",
";",
"}"
] | Posts the data to the given URL
@param string $url Fully-qualified URL to request
@param mixed $postData The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with
@ and use the full path. This can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as
an array with the field name as key and field data as value.
@param string $username Username to use in http authentication header
@param string $password Password to use in http authentication header
@param array $headers Array of http headers to append to the existing headers list
@return string Contents of the HTTP response body
@throws HttpRequestException | [
"Posts",
"the",
"data",
"to",
"the",
"given",
"URL"
] | train | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/http/HttpRequest.php#L183-L258 |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/http/HttpRequest.php | HttpRequest.fetchURL | public function fetchURL($url, $followRedirects = true, $username = null, $password = null, $headers = array())
{
if (function_exists('curl_init')) {
$contents = $this->curlRequest($url, false, $followRedirects, $username, $password, $headers);
return $contents;
} else {
if ($this->userAgent != null) {
$opts = array(
'http'=> array(
'user_agent'=> $this->userAgent,
'max_redirects' => $this->redirects, // stop after 10 redirects
)
);
}
if ($username && $password) {
$opts = ($opts) ? $opts : array('http' => array());
$opts['http']['header'] =
array('Authorization: Basic '
. base64_encode("$username:$password"));
}
if ($headers) {
$opts['http']['header'] =$headers;
}
$context = ($opts) ? stream_context_create($opts) : null;
unset($opts);
$contents = @file_get_contents($url, false, $context);
if ($contents === false)
throw new HttpRequestException("Unknown error fetching URL '".$url."'");
unset($context);
unset($url);
return $contents;
}
} | php | public function fetchURL($url, $followRedirects = true, $username = null, $password = null, $headers = array())
{
if (function_exists('curl_init')) {
$contents = $this->curlRequest($url, false, $followRedirects, $username, $password, $headers);
return $contents;
} else {
if ($this->userAgent != null) {
$opts = array(
'http'=> array(
'user_agent'=> $this->userAgent,
'max_redirects' => $this->redirects, // stop after 10 redirects
)
);
}
if ($username && $password) {
$opts = ($opts) ? $opts : array('http' => array());
$opts['http']['header'] =
array('Authorization: Basic '
. base64_encode("$username:$password"));
}
if ($headers) {
$opts['http']['header'] =$headers;
}
$context = ($opts) ? stream_context_create($opts) : null;
unset($opts);
$contents = @file_get_contents($url, false, $context);
if ($contents === false)
throw new HttpRequestException("Unknown error fetching URL '".$url."'");
unset($context);
unset($url);
return $contents;
}
} | [
"public",
"function",
"fetchURL",
"(",
"$",
"url",
",",
"$",
"followRedirects",
"=",
"true",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"headers",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'curl_init'",
")",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"curlRequest",
"(",
"$",
"url",
",",
"false",
",",
"$",
"followRedirects",
",",
"$",
"username",
",",
"$",
"password",
",",
"$",
"headers",
")",
";",
"return",
"$",
"contents",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"userAgent",
"!=",
"null",
")",
"{",
"$",
"opts",
"=",
"array",
"(",
"'http'",
"=>",
"array",
"(",
"'user_agent'",
"=>",
"$",
"this",
"->",
"userAgent",
",",
"'max_redirects'",
"=>",
"$",
"this",
"->",
"redirects",
",",
"// stop after 10 redirects",
")",
")",
";",
"}",
"if",
"(",
"$",
"username",
"&&",
"$",
"password",
")",
"{",
"$",
"opts",
"=",
"(",
"$",
"opts",
")",
"?",
"$",
"opts",
":",
"array",
"(",
"'http'",
"=>",
"array",
"(",
")",
")",
";",
"$",
"opts",
"[",
"'http'",
"]",
"[",
"'header'",
"]",
"=",
"array",
"(",
"'Authorization: Basic '",
".",
"base64_encode",
"(",
"\"$username:$password\"",
")",
")",
";",
"}",
"if",
"(",
"$",
"headers",
")",
"{",
"$",
"opts",
"[",
"'http'",
"]",
"[",
"'header'",
"]",
"=",
"$",
"headers",
";",
"}",
"$",
"context",
"=",
"(",
"$",
"opts",
")",
"?",
"stream_context_create",
"(",
"$",
"opts",
")",
":",
"null",
";",
"unset",
"(",
"$",
"opts",
")",
";",
"$",
"contents",
"=",
"@",
"file_get_contents",
"(",
"$",
"url",
",",
"false",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"contents",
"===",
"false",
")",
"throw",
"new",
"HttpRequestException",
"(",
"\"Unknown error fetching URL '\"",
".",
"$",
"url",
".",
"\"'\"",
")",
";",
"unset",
"(",
"$",
"context",
")",
";",
"unset",
"(",
"$",
"url",
")",
";",
"return",
"$",
"contents",
";",
"}",
"}"
] | Fetch the contents of a URL
@param string $url Fully-qualified URL to request
@param bool $followRedirects If true, follow redirects to default max of 5
@param string $username Username to use in http authentication header
@param string $password Password to use in http authentication header
@param array $headers Array of http headers to append to the existing headers list
@return string Contents of the HTTP response body
@throws HttpRequestException If contents cannot be fetched | [
"Fetch",
"the",
"contents",
"of",
"a",
"URL"
] | train | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/http/HttpRequest.php#L274-L320 |
sil-project/SeedBatchBundle | src/CodeGenerator/SeedBatchCodeGenerator.php | SeedBatchCodeGenerator.generate | public static function generate($seedBatch)
{
if (!$seedFarm = $seedBatch->getSeedFarm()) {
throw new InvalidEntityCodeException('librinfo.error.missing_seed_farm');
}
if (!$seedFarmCode = $seedFarm->getCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_seed_farm_code');
}
$variety = $seedBatch->getVariety();
if (!$variety) {
throw new InvalidEntityCodeException('librinfo.error.missing_variety');
}
if (!$varietyCode = $variety->getCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_variety_code');
}
$species = $variety->getSpecies();
if (!$species) {
throw new InvalidEntityCodeException('librinfo.error.missing_species');
}
if (!$speciesCode = $species->getCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_species_code');
}
$producer = $seedBatch->getProducer();
if (!$producer) {
throw new InvalidEntityCodeException('librinfo.error.missing_producer');
}
if (!$producerCode = $producer->getSeedProducerCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_producer_code');
}
$productionYear = (int) $seedBatch->getProductionYear();
if (!$productionYear) {
throw new InvalidEntityCodeException('librinfo.error.missing_production_year');
}
// if ($productionYear < 2000 || $productionYear > 2099) {
if ($productionYear < 1) {
throw new InvalidEntityCodeException('librinfo.error.invalid_production_year');
}
// TODO: test if year is too far in the future ?
$batchNumber = $seedBatch->getBatchNumber();
if (!$batchNumber) {
throw new InvalidEntityCodeException('librinfo.error.missing_batch_number');
}
// if ($batchNumber < 1 || $batchNumber > 99) {
if ($batchNumber < 1) {
throw new InvalidEntityCodeException('librinfo.error.invalid_batch_number');
}
return sprintf(
'%s-%s%s-%s-%02d-%02d',
$seedFarmCode,
$speciesCode,
$varietyCode,
$producerCode,
$productionYear % 100, // - 2000,
$batchNumber % 100
);
} | php | public static function generate($seedBatch)
{
if (!$seedFarm = $seedBatch->getSeedFarm()) {
throw new InvalidEntityCodeException('librinfo.error.missing_seed_farm');
}
if (!$seedFarmCode = $seedFarm->getCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_seed_farm_code');
}
$variety = $seedBatch->getVariety();
if (!$variety) {
throw new InvalidEntityCodeException('librinfo.error.missing_variety');
}
if (!$varietyCode = $variety->getCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_variety_code');
}
$species = $variety->getSpecies();
if (!$species) {
throw new InvalidEntityCodeException('librinfo.error.missing_species');
}
if (!$speciesCode = $species->getCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_species_code');
}
$producer = $seedBatch->getProducer();
if (!$producer) {
throw new InvalidEntityCodeException('librinfo.error.missing_producer');
}
if (!$producerCode = $producer->getSeedProducerCode()) {
throw new InvalidEntityCodeException('librinfo.error.missing_producer_code');
}
$productionYear = (int) $seedBatch->getProductionYear();
if (!$productionYear) {
throw new InvalidEntityCodeException('librinfo.error.missing_production_year');
}
// if ($productionYear < 2000 || $productionYear > 2099) {
if ($productionYear < 1) {
throw new InvalidEntityCodeException('librinfo.error.invalid_production_year');
}
// TODO: test if year is too far in the future ?
$batchNumber = $seedBatch->getBatchNumber();
if (!$batchNumber) {
throw new InvalidEntityCodeException('librinfo.error.missing_batch_number');
}
// if ($batchNumber < 1 || $batchNumber > 99) {
if ($batchNumber < 1) {
throw new InvalidEntityCodeException('librinfo.error.invalid_batch_number');
}
return sprintf(
'%s-%s%s-%s-%02d-%02d',
$seedFarmCode,
$speciesCode,
$varietyCode,
$producerCode,
$productionYear % 100, // - 2000,
$batchNumber % 100
);
} | [
"public",
"static",
"function",
"generate",
"(",
"$",
"seedBatch",
")",
"{",
"if",
"(",
"!",
"$",
"seedFarm",
"=",
"$",
"seedBatch",
"->",
"getSeedFarm",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_seed_farm'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"seedFarmCode",
"=",
"$",
"seedFarm",
"->",
"getCode",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_seed_farm_code'",
")",
";",
"}",
"$",
"variety",
"=",
"$",
"seedBatch",
"->",
"getVariety",
"(",
")",
";",
"if",
"(",
"!",
"$",
"variety",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_variety'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"varietyCode",
"=",
"$",
"variety",
"->",
"getCode",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_variety_code'",
")",
";",
"}",
"$",
"species",
"=",
"$",
"variety",
"->",
"getSpecies",
"(",
")",
";",
"if",
"(",
"!",
"$",
"species",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_species'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"speciesCode",
"=",
"$",
"species",
"->",
"getCode",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_species_code'",
")",
";",
"}",
"$",
"producer",
"=",
"$",
"seedBatch",
"->",
"getProducer",
"(",
")",
";",
"if",
"(",
"!",
"$",
"producer",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_producer'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"producerCode",
"=",
"$",
"producer",
"->",
"getSeedProducerCode",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_producer_code'",
")",
";",
"}",
"$",
"productionYear",
"=",
"(",
"int",
")",
"$",
"seedBatch",
"->",
"getProductionYear",
"(",
")",
";",
"if",
"(",
"!",
"$",
"productionYear",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_production_year'",
")",
";",
"}",
"// if ($productionYear < 2000 || $productionYear > 2099) {",
"if",
"(",
"$",
"productionYear",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.invalid_production_year'",
")",
";",
"}",
"// TODO: test if year is too far in the future ?",
"$",
"batchNumber",
"=",
"$",
"seedBatch",
"->",
"getBatchNumber",
"(",
")",
";",
"if",
"(",
"!",
"$",
"batchNumber",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.missing_batch_number'",
")",
";",
"}",
"// if ($batchNumber < 1 || $batchNumber > 99) {",
"if",
"(",
"$",
"batchNumber",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidEntityCodeException",
"(",
"'librinfo.error.invalid_batch_number'",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s-%s%s-%s-%02d-%02d'",
",",
"$",
"seedFarmCode",
",",
"$",
"speciesCode",
",",
"$",
"varietyCode",
",",
"$",
"producerCode",
",",
"$",
"productionYear",
"%",
"100",
",",
"// - 2000,",
"$",
"batchNumber",
"%",
"100",
")",
";",
"}"
] | @param SeedBatch $seedBatch
@return string
@throws InvalidEntityCodeException | [
"@param",
"SeedBatch",
"$seedBatch"
] | train | https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/CodeGenerator/SeedBatchCodeGenerator.php#L44-L101 |
kambalabs/KmbBase | src/KmbBase/Widget/AbstractWidgetAction.php | AbstractWidgetAction.setPluginManager | public function setPluginManager(PluginManager $plugins)
{
$this->plugins = $plugins;
$this->plugins->setController($this->controller);
return $this;
} | php | public function setPluginManager(PluginManager $plugins)
{
$this->plugins = $plugins;
$this->plugins->setController($this->controller);
return $this;
} | [
"public",
"function",
"setPluginManager",
"(",
"PluginManager",
"$",
"plugins",
")",
"{",
"$",
"this",
"->",
"plugins",
"=",
"$",
"plugins",
";",
"$",
"this",
"->",
"plugins",
"->",
"setController",
"(",
"$",
"this",
"->",
"controller",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set plugin manager
@param PluginManager $plugins
@return AbstractWidgetAction | [
"Set",
"plugin",
"manager"
] | train | https://github.com/kambalabs/KmbBase/blob/ca420f247e9e4063266005e30afc4c8af492a33b/src/KmbBase/Widget/AbstractWidgetAction.php#L80-L86 |
OxfordInfoLabs/kinikit-core | src/Util/Annotation/Annotation.php | Annotation.getValues | public function getValues() {
$exploded = explode(",", $this->getValue());
$values = array();
foreach ($exploded as $entry){
$values[] = trim($entry);
}
return $values;
} | php | public function getValues() {
$exploded = explode(",", $this->getValue());
$values = array();
foreach ($exploded as $entry){
$values[] = trim($entry);
}
return $values;
} | [
"public",
"function",
"getValues",
"(",
")",
"{",
"$",
"exploded",
"=",
"explode",
"(",
"\",\"",
",",
"$",
"this",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"exploded",
"as",
"$",
"entry",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"trim",
"(",
"$",
"entry",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Return value as an array split by "," | [
"Return",
"value",
"as",
"an",
"array",
"split",
"by"
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Annotation/Annotation.php#L62-L70 |
davewwww/Ispec | src/Dwo/Ispec/Cache/FindAllManager.php | FindAllManager.findAllByIp | public function findAllByIp($ip)
{
$ip = ip2long($ip);
$ipInfos = [];
foreach($this->ipInfosLong as $data) {
if($ip >= $data[0] && $ip <= $data[1]) {
$ipInfos[] = $data[2];
}
}
return $ipInfos;
} | php | public function findAllByIp($ip)
{
$ip = ip2long($ip);
$ipInfos = [];
foreach($this->ipInfosLong as $data) {
if($ip >= $data[0] && $ip <= $data[1]) {
$ipInfos[] = $data[2];
}
}
return $ipInfos;
} | [
"public",
"function",
"findAllByIp",
"(",
"$",
"ip",
")",
"{",
"$",
"ip",
"=",
"ip2long",
"(",
"$",
"ip",
")",
";",
"$",
"ipInfos",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"ipInfosLong",
"as",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"ip",
">=",
"$",
"data",
"[",
"0",
"]",
"&&",
"$",
"ip",
"<=",
"$",
"data",
"[",
"1",
"]",
")",
"{",
"$",
"ipInfos",
"[",
"]",
"=",
"$",
"data",
"[",
"2",
"]",
";",
"}",
"}",
"return",
"$",
"ipInfos",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/davewwww/Ispec/blob/06e40344eaad27715c87c8f6830ab4894e89736d/src/Dwo/Ispec/Cache/FindAllManager.php#L44-L56 |
goncalomb/asbestos | src/classes/Http/Request.php | Request.fromGlobals | public static function fromGlobals()
{
$request = new self();
foreach ([
'Accept', 'Accept-Charset', 'Accept-Encoding', 'Accept-Language',
'Connection', 'Host', 'Referer', 'User-Agent'
] as $name) {
$key = 'HTTP_' . str_replace('-', '_', strtoupper($name));
if (isset($_SERVER[$key])) {
$request->setHeader($name, $_SERVER[$key], false);
}
}
$request->_isSecure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off');
$request->_method = $_SERVER['REQUEST_METHOD'];
$request->_uri = $_SERVER['REQUEST_URI'];
$request->_path = strstr($_SERVER['REQUEST_URI'], '?', true);
if ($request->_path == false) {
$request->_path = $_SERVER['REQUEST_URI'];
}
$request->_query = strstr($_SERVER['REQUEST_URI'], '?');
if ($request->_query == false) {
$request->_query = '';
}
return $request;
} | php | public static function fromGlobals()
{
$request = new self();
foreach ([
'Accept', 'Accept-Charset', 'Accept-Encoding', 'Accept-Language',
'Connection', 'Host', 'Referer', 'User-Agent'
] as $name) {
$key = 'HTTP_' . str_replace('-', '_', strtoupper($name));
if (isset($_SERVER[$key])) {
$request->setHeader($name, $_SERVER[$key], false);
}
}
$request->_isSecure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off');
$request->_method = $_SERVER['REQUEST_METHOD'];
$request->_uri = $_SERVER['REQUEST_URI'];
$request->_path = strstr($_SERVER['REQUEST_URI'], '?', true);
if ($request->_path == false) {
$request->_path = $_SERVER['REQUEST_URI'];
}
$request->_query = strstr($_SERVER['REQUEST_URI'], '?');
if ($request->_query == false) {
$request->_query = '';
}
return $request;
} | [
"public",
"static",
"function",
"fromGlobals",
"(",
")",
"{",
"$",
"request",
"=",
"new",
"self",
"(",
")",
";",
"foreach",
"(",
"[",
"'Accept'",
",",
"'Accept-Charset'",
",",
"'Accept-Encoding'",
",",
"'Accept-Language'",
",",
"'Connection'",
",",
"'Host'",
",",
"'Referer'",
",",
"'User-Agent'",
"]",
"as",
"$",
"name",
")",
"{",
"$",
"key",
"=",
"'HTTP_'",
".",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"strtoupper",
"(",
"$",
"name",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"request",
"->",
"setHeader",
"(",
"$",
"name",
",",
"$",
"_SERVER",
"[",
"$",
"key",
"]",
",",
"false",
")",
";",
"}",
"}",
"$",
"request",
"->",
"_isSecure",
"=",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"&&",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
"!=",
"'off'",
")",
";",
"$",
"request",
"->",
"_method",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
";",
"$",
"request",
"->",
"_uri",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"$",
"request",
"->",
"_path",
"=",
"strstr",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"'?'",
",",
"true",
")",
";",
"if",
"(",
"$",
"request",
"->",
"_path",
"==",
"false",
")",
"{",
"$",
"request",
"->",
"_path",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"}",
"$",
"request",
"->",
"_query",
"=",
"strstr",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"'?'",
")",
";",
"if",
"(",
"$",
"request",
"->",
"_query",
"==",
"false",
")",
"{",
"$",
"request",
"->",
"_query",
"=",
"''",
";",
"}",
"return",
"$",
"request",
";",
"}"
] | Create request from PHP globals. | [
"Create",
"request",
"from",
"PHP",
"globals",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Http/Request.php#L61-L90 |
offworks/laraquent | src/Support/Exedra/Wizard.php | Wizard.executeMigrate | public function executeMigrate()
{
$this->app->eloquent->getConnection()->useDefaultSchemaGrammar();
$file = $this->app->path['app']->file($this->app->config->get('db.schema_path', 'database/schema.php'));
if(!$file->isExists())
throw new \Exception('['.$file.'] does not exists.');
$file->load(array(
'schema' => new \Laraquent\Schema($this->app->eloquent->getConnection())
));
} | php | public function executeMigrate()
{
$this->app->eloquent->getConnection()->useDefaultSchemaGrammar();
$file = $this->app->path['app']->file($this->app->config->get('db.schema_path', 'database/schema.php'));
if(!$file->isExists())
throw new \Exception('['.$file.'] does not exists.');
$file->load(array(
'schema' => new \Laraquent\Schema($this->app->eloquent->getConnection())
));
} | [
"public",
"function",
"executeMigrate",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"eloquent",
"->",
"getConnection",
"(",
")",
"->",
"useDefaultSchemaGrammar",
"(",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"app",
"->",
"path",
"[",
"'app'",
"]",
"->",
"file",
"(",
"$",
"this",
"->",
"app",
"->",
"config",
"->",
"get",
"(",
"'db.schema_path'",
",",
"'database/schema.php'",
")",
")",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"isExists",
"(",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"'['",
".",
"$",
"file",
".",
"'] does not exists.'",
")",
";",
"$",
"file",
"->",
"load",
"(",
"array",
"(",
"'schema'",
"=>",
"new",
"\\",
"Laraquent",
"\\",
"Schema",
"(",
"$",
"this",
"->",
"app",
"->",
"eloquent",
"->",
"getConnection",
"(",
")",
")",
")",
")",
";",
"}"
] | Migrate eloquent schema
Use db.schema_path config if configured
@description Migrate eloquent schema | [
"Migrate",
"eloquent",
"schema",
"Use",
"db",
".",
"schema_path",
"config",
"if",
"configured"
] | train | https://github.com/offworks/laraquent/blob/74cbc6258acfda8f7213c701887a7b223aff954f/src/Support/Exedra/Wizard.php#L13-L25 |
staticka/staticka | src/Filter/InlineMinifier.php | InlineMinifier.filter | public function filter($code)
{
$elements = (array) $this->elements($code);
foreach ((array) $elements as $element)
{
$original = (string) $element->nodeValue;
$minified = $this->minify($original);
$minified = preg_replace('/\s+/', ' ', $minified);
$minified = $this->minify($minified);
$code = str_replace($original, $minified, $code);
}
return $code;
} | php | public function filter($code)
{
$elements = (array) $this->elements($code);
foreach ((array) $elements as $element)
{
$original = (string) $element->nodeValue;
$minified = $this->minify($original);
$minified = preg_replace('/\s+/', ' ', $minified);
$minified = $this->minify($minified);
$code = str_replace($original, $minified, $code);
}
return $code;
} | [
"public",
"function",
"filter",
"(",
"$",
"code",
")",
"{",
"$",
"elements",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"elements",
"(",
"$",
"code",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"original",
"=",
"(",
"string",
")",
"$",
"element",
"->",
"nodeValue",
";",
"$",
"minified",
"=",
"$",
"this",
"->",
"minify",
"(",
"$",
"original",
")",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"$",
"minified",
")",
";",
"$",
"minified",
"=",
"$",
"this",
"->",
"minify",
"(",
"$",
"minified",
")",
";",
"$",
"code",
"=",
"str_replace",
"(",
"$",
"original",
",",
"$",
"minified",
",",
"$",
"code",
")",
";",
"}",
"return",
"$",
"code",
";",
"}"
] | Filters the specified code.
@param string $code
@return string | [
"Filters",
"the",
"specified",
"code",
"."
] | train | https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Filter/InlineMinifier.php#L34-L52 |
staticka/staticka | src/Filter/InlineMinifier.php | InlineMinifier.elements | protected function elements($code)
{
libxml_use_internal_errors(true);
$doc = new \DOMDocument;
$doc->loadHTML((string) $code);
$tag = (string) $this->tagname;
$items = $doc->getElementsByTagName($tag);
$items = iterator_to_array($items);
return count($items) > 0 ? $items : array();
} | php | protected function elements($code)
{
libxml_use_internal_errors(true);
$doc = new \DOMDocument;
$doc->loadHTML((string) $code);
$tag = (string) $this->tagname;
$items = $doc->getElementsByTagName($tag);
$items = iterator_to_array($items);
return count($items) > 0 ? $items : array();
} | [
"protected",
"function",
"elements",
"(",
"$",
"code",
")",
"{",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"doc",
"=",
"new",
"\\",
"DOMDocument",
";",
"$",
"doc",
"->",
"loadHTML",
"(",
"(",
"string",
")",
"$",
"code",
")",
";",
"$",
"tag",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"tagname",
";",
"$",
"items",
"=",
"$",
"doc",
"->",
"getElementsByTagName",
"(",
"$",
"tag",
")",
";",
"$",
"items",
"=",
"iterator_to_array",
"(",
"$",
"items",
")",
";",
"return",
"count",
"(",
"$",
"items",
")",
">",
"0",
"?",
"$",
"items",
":",
"array",
"(",
")",
";",
"}"
] | Returns elements by a tag name.
@param string $code
@return \DOMNodeList | [
"Returns",
"elements",
"by",
"a",
"tag",
"name",
"."
] | train | https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Filter/InlineMinifier.php#L60-L75 |
staticka/staticka | src/Filter/InlineMinifier.php | InlineMinifier.minify | protected function minify($code)
{
$pattern = (string) '!/\*[^*]*\*+([^/][^*]*\*+)*/!';
$minified = preg_replace('/^\\s+/m', '', $code);
$minified = preg_replace($pattern, '', $minified);
$minified = preg_replace('/( )?}( )?/', '}', $minified);
$minified = preg_replace('/( )?{( )?/', '{', $minified);
$minified = preg_replace('/( )?:( )?/', ':', $minified);
$minified = preg_replace('/( )?;( )?/', ';', $minified);
$minified = preg_replace('/( )?,( )?/', ',', $minified);
return $minified;
} | php | protected function minify($code)
{
$pattern = (string) '!/\*[^*]*\*+([^/][^*]*\*+)*/!';
$minified = preg_replace('/^\\s+/m', '', $code);
$minified = preg_replace($pattern, '', $minified);
$minified = preg_replace('/( )?}( )?/', '}', $minified);
$minified = preg_replace('/( )?{( )?/', '{', $minified);
$minified = preg_replace('/( )?:( )?/', ':', $minified);
$minified = preg_replace('/( )?;( )?/', ';', $minified);
$minified = preg_replace('/( )?,( )?/', ',', $minified);
return $minified;
} | [
"protected",
"function",
"minify",
"(",
"$",
"code",
")",
"{",
"$",
"pattern",
"=",
"(",
"string",
")",
"'!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!'",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"'/^\\\\s+/m'",
",",
"''",
",",
"$",
"code",
")",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"$",
"pattern",
",",
"''",
",",
"$",
"minified",
")",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"'/( )?}( )?/'",
",",
"'}'",
",",
"$",
"minified",
")",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"'/( )?{( )?/'",
",",
"'{'",
",",
"$",
"minified",
")",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"'/( )?:( )?/'",
",",
"':'",
",",
"$",
"minified",
")",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"'/( )?;( )?/'",
",",
"';'",
",",
"$",
"minified",
")",
";",
"$",
"minified",
"=",
"preg_replace",
"(",
"'/( )?,( )?/'",
",",
"','",
",",
"$",
"minified",
")",
";",
"return",
"$",
"minified",
";",
"}"
] | Minifies the specified code.
@param string $code
@return string | [
"Minifies",
"the",
"specified",
"code",
"."
] | train | https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Filter/InlineMinifier.php#L83-L102 |
phpactor/completion-rpc-extension | lib/CompletionRpcExtension.php | CompletionRpcExtension.load | public function load(ContainerBuilder $container)
{
$container->register('completion_rpc.handler', function (Container $container) {
return new CompleteHandler($container->get(CompletionExtension::SERVICE_REGISTRY));
}, [ RpcExtension::TAG_RPC_HANDLER => ['name' => CompleteHandler::NAME] ]);
} | php | public function load(ContainerBuilder $container)
{
$container->register('completion_rpc.handler', function (Container $container) {
return new CompleteHandler($container->get(CompletionExtension::SERVICE_REGISTRY));
}, [ RpcExtension::TAG_RPC_HANDLER => ['name' => CompleteHandler::NAME] ]);
} | [
"public",
"function",
"load",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"container",
"->",
"register",
"(",
"'completion_rpc.handler'",
",",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"CompleteHandler",
"(",
"$",
"container",
"->",
"get",
"(",
"CompletionExtension",
"::",
"SERVICE_REGISTRY",
")",
")",
";",
"}",
",",
"[",
"RpcExtension",
"::",
"TAG_RPC_HANDLER",
"=>",
"[",
"'name'",
"=>",
"CompleteHandler",
"::",
"NAME",
"]",
"]",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/phpactor/completion-rpc-extension/blob/0968cd63d4408905e4a4df646986de5a6822343e/lib/CompletionRpcExtension.php#L25-L30 |
lightwerk/SurfTasks | Classes/Lightwerk/SurfTasks/Task/Transfer/AssureConnectionTask.php | AssureConnectionTask.execute | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
if ($node->isLocalhost()) {
$deployment->getLogger()->log('node seems not to be a remote node', LOG_DEBUG);
} else {
$username = $node->hasOption('username') ? $node->getOption('username') : null;
if (!empty($username)) {
$username = $username.'@';
}
$hostname = $node->getHostname();
$sshOptions = ['-A', '-q', '-o BatchMode=yes'];
if ($node->hasOption('port')) {
$sshOptions[] = '-p '.escapeshellarg($node->getOption('port'));
}
$command = 'ssh '.implode(' ', $sshOptions).' '.escapeshellarg($username.$hostname).' exit;';
$this->shell->execute($command, $deployment->getNode('localhost'), $deployment);
$deployment->getLogger()->log('SSH connection successfully established', LOG_DEBUG);
}
} | php | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
if ($node->isLocalhost()) {
$deployment->getLogger()->log('node seems not to be a remote node', LOG_DEBUG);
} else {
$username = $node->hasOption('username') ? $node->getOption('username') : null;
if (!empty($username)) {
$username = $username.'@';
}
$hostname = $node->getHostname();
$sshOptions = ['-A', '-q', '-o BatchMode=yes'];
if ($node->hasOption('port')) {
$sshOptions[] = '-p '.escapeshellarg($node->getOption('port'));
}
$command = 'ssh '.implode(' ', $sshOptions).' '.escapeshellarg($username.$hostname).' exit;';
$this->shell->execute($command, $deployment->getNode('localhost'), $deployment);
$deployment->getLogger()->log('SSH connection successfully established', LOG_DEBUG);
}
} | [
"public",
"function",
"execute",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"isLocalhost",
"(",
")",
")",
"{",
"$",
"deployment",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"'node seems not to be a remote node'",
",",
"LOG_DEBUG",
")",
";",
"}",
"else",
"{",
"$",
"username",
"=",
"$",
"node",
"->",
"hasOption",
"(",
"'username'",
")",
"?",
"$",
"node",
"->",
"getOption",
"(",
"'username'",
")",
":",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"username",
")",
")",
"{",
"$",
"username",
"=",
"$",
"username",
".",
"'@'",
";",
"}",
"$",
"hostname",
"=",
"$",
"node",
"->",
"getHostname",
"(",
")",
";",
"$",
"sshOptions",
"=",
"[",
"'-A'",
",",
"'-q'",
",",
"'-o BatchMode=yes'",
"]",
";",
"if",
"(",
"$",
"node",
"->",
"hasOption",
"(",
"'port'",
")",
")",
"{",
"$",
"sshOptions",
"[",
"]",
"=",
"'-p '",
".",
"escapeshellarg",
"(",
"$",
"node",
"->",
"getOption",
"(",
"'port'",
")",
")",
";",
"}",
"$",
"command",
"=",
"'ssh '",
".",
"implode",
"(",
"' '",
",",
"$",
"sshOptions",
")",
".",
"' '",
".",
"escapeshellarg",
"(",
"$",
"username",
".",
"$",
"hostname",
")",
".",
"' exit;'",
";",
"$",
"this",
"->",
"shell",
"->",
"execute",
"(",
"$",
"command",
",",
"$",
"deployment",
"->",
"getNode",
"(",
"'localhost'",
")",
",",
"$",
"deployment",
")",
";",
"$",
"deployment",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"'SSH connection successfully established'",
",",
"LOG_DEBUG",
")",
";",
"}",
"}"
] | Executes this task.
@param Node $node
@param Application $application
@param Deployment $deployment
@param array $options
@throws TaskExecutionException | [
"Executes",
"this",
"task",
"."
] | train | https://github.com/lightwerk/SurfTasks/blob/8a6e4c85e42c762ad6515778c3fc7e19052cd9d1/Classes/Lightwerk/SurfTasks/Task/Transfer/AssureConnectionTask.php#L52-L74 |
Nicklas766/Comment | src/Comment/Modules/Vote.php | Vote.getVote | public function getVote($sql, $params)
{
$likes = $this->findAllWhere("$sql", $params);
// Return users of the ones who have upvoted.
$score = array_reduce($likes, function ($carry, $item) {
$carry += $item->upVote - $item->downVote;
return $carry;
});
$this->likes = $likes;
$this->score = $score;
return $this;
} | php | public function getVote($sql, $params)
{
$likes = $this->findAllWhere("$sql", $params);
// Return users of the ones who have upvoted.
$score = array_reduce($likes, function ($carry, $item) {
$carry += $item->upVote - $item->downVote;
return $carry;
});
$this->likes = $likes;
$this->score = $score;
return $this;
} | [
"public",
"function",
"getVote",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"{",
"$",
"likes",
"=",
"$",
"this",
"->",
"findAllWhere",
"(",
"\"$sql\"",
",",
"$",
"params",
")",
";",
"// Return users of the ones who have upvoted.",
"$",
"score",
"=",
"array_reduce",
"(",
"$",
"likes",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"item",
")",
"{",
"$",
"carry",
"+=",
"$",
"item",
"->",
"upVote",
"-",
"$",
"item",
"->",
"downVote",
";",
"return",
"$",
"carry",
";",
"}",
")",
";",
"$",
"this",
"->",
"likes",
"=",
"$",
"likes",
";",
"$",
"this",
"->",
"score",
"=",
"$",
"score",
";",
"return",
"$",
"this",
";",
"}"
] | Return a vote
@param string $sql
@param array $params
@return object | [
"Return",
"a",
"vote",
"@param",
"string",
"$sql",
"@param",
"array",
"$params"
] | train | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/Modules/Vote.php#L36-L49 |
Nicklas766/Comment | src/Comment/Modules/Vote.php | Vote.saveVote | public function saveVote($user, $parentId, $parentType, $voteType = "like")
{
$vote = $this->findAllWhere("parentId = ? AND parentType = ? AND user = ?", [$parentId, $parentType, $user])[0];
if ($vote != null) {
$vote->setDb($this->db);
}
if ($vote == null) {
$vote = $this;
}
$vote->user = $user;
$vote->parentId = $parentId;
$vote->parentType = $parentType;
$vote->upVote = 1;
$vote->downVote = null;
if ($voteType == "downVote") {
$vote->upVote = null;
$vote->downVote = 1;
}
$vote->save();
return true;
} | php | public function saveVote($user, $parentId, $parentType, $voteType = "like")
{
$vote = $this->findAllWhere("parentId = ? AND parentType = ? AND user = ?", [$parentId, $parentType, $user])[0];
if ($vote != null) {
$vote->setDb($this->db);
}
if ($vote == null) {
$vote = $this;
}
$vote->user = $user;
$vote->parentId = $parentId;
$vote->parentType = $parentType;
$vote->upVote = 1;
$vote->downVote = null;
if ($voteType == "downVote") {
$vote->upVote = null;
$vote->downVote = 1;
}
$vote->save();
return true;
} | [
"public",
"function",
"saveVote",
"(",
"$",
"user",
",",
"$",
"parentId",
",",
"$",
"parentType",
",",
"$",
"voteType",
"=",
"\"like\"",
")",
"{",
"$",
"vote",
"=",
"$",
"this",
"->",
"findAllWhere",
"(",
"\"parentId = ? AND parentType = ? AND user = ?\"",
",",
"[",
"$",
"parentId",
",",
"$",
"parentType",
",",
"$",
"user",
"]",
")",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"vote",
"!=",
"null",
")",
"{",
"$",
"vote",
"->",
"setDb",
"(",
"$",
"this",
"->",
"db",
")",
";",
"}",
"if",
"(",
"$",
"vote",
"==",
"null",
")",
"{",
"$",
"vote",
"=",
"$",
"this",
";",
"}",
"$",
"vote",
"->",
"user",
"=",
"$",
"user",
";",
"$",
"vote",
"->",
"parentId",
"=",
"$",
"parentId",
";",
"$",
"vote",
"->",
"parentType",
"=",
"$",
"parentType",
";",
"$",
"vote",
"->",
"upVote",
"=",
"1",
";",
"$",
"vote",
"->",
"downVote",
"=",
"null",
";",
"if",
"(",
"$",
"voteType",
"==",
"\"downVote\"",
")",
"{",
"$",
"vote",
"->",
"upVote",
"=",
"null",
";",
"$",
"vote",
"->",
"downVote",
"=",
"1",
";",
"}",
"$",
"vote",
"->",
"save",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Checks if vote already exists, then either create new or update
@param array $params
@return bool | [
"Checks",
"if",
"vote",
"already",
"exists",
"then",
"either",
"create",
"new",
"or",
"update",
"@param",
"array",
"$params"
] | train | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/Modules/Vote.php#L57-L84 |
Nicklas766/Comment | src/Comment/Modules/Vote.php | Vote.like | public function like($user, $parentId, $parentType)
{
$likes = $this->findAllWhere("parentId = ? AND parentType = ?", [$parentId, $parentType]);
// Return users of the ones who have upvoted.
$users = array_map(function ($like) {
return $like->upVote != null ? $like->user : "";
}, $likes);
if (in_array($user, $users)) {
return false;
}
$this->saveVote($user, $parentId, $parentType);
return true;
} | php | public function like($user, $parentId, $parentType)
{
$likes = $this->findAllWhere("parentId = ? AND parentType = ?", [$parentId, $parentType]);
// Return users of the ones who have upvoted.
$users = array_map(function ($like) {
return $like->upVote != null ? $like->user : "";
}, $likes);
if (in_array($user, $users)) {
return false;
}
$this->saveVote($user, $parentId, $parentType);
return true;
} | [
"public",
"function",
"like",
"(",
"$",
"user",
",",
"$",
"parentId",
",",
"$",
"parentType",
")",
"{",
"$",
"likes",
"=",
"$",
"this",
"->",
"findAllWhere",
"(",
"\"parentId = ? AND parentType = ?\"",
",",
"[",
"$",
"parentId",
",",
"$",
"parentType",
"]",
")",
";",
"// Return users of the ones who have upvoted.",
"$",
"users",
"=",
"array_map",
"(",
"function",
"(",
"$",
"like",
")",
"{",
"return",
"$",
"like",
"->",
"upVote",
"!=",
"null",
"?",
"$",
"like",
"->",
"user",
":",
"\"\"",
";",
"}",
",",
"$",
"likes",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"user",
",",
"$",
"users",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"saveVote",
"(",
"$",
"user",
",",
"$",
"parentId",
",",
"$",
"parentType",
")",
";",
"return",
"true",
";",
"}"
] | Control if user has already liked or not
@param string $user
@param array $params
@return bool | [
"Control",
"if",
"user",
"has",
"already",
"liked",
"or",
"not",
"@param",
"string",
"$user",
"@param",
"array",
"$params"
] | train | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/Modules/Vote.php#L93-L106 |
phossa/phossa-config | src/Phossa/Config/Loader/JsonLoader.php | JsonLoader.load | public static function load(/*# string */ $path)/*# : array */
{
if (!is_readable($path)) {
throw new LogicException(
Message::get(Message::CONFIG_LOAD_ERROR, $path),
Message::CONFIG_LOAD_ERROR
);
}
$data = @json_decode(file_get_contents($path), true);
if (json_last_error() !== \JSON_ERROR_NONE) {
if (function_exists('json_last_error_msg')) {
$message = json_last_error_msg();
} else {
$message = Message::get(Message::CONFIG_FORMAT_ERROR);
}
throw new LogicException(
$message,
Message::CONFIG_FORMAT_ERROR
);
}
return $data;
} | php | public static function load(/*# string */ $path)/*# : array */
{
if (!is_readable($path)) {
throw new LogicException(
Message::get(Message::CONFIG_LOAD_ERROR, $path),
Message::CONFIG_LOAD_ERROR
);
}
$data = @json_decode(file_get_contents($path), true);
if (json_last_error() !== \JSON_ERROR_NONE) {
if (function_exists('json_last_error_msg')) {
$message = json_last_error_msg();
} else {
$message = Message::get(Message::CONFIG_FORMAT_ERROR);
}
throw new LogicException(
$message,
Message::CONFIG_FORMAT_ERROR
);
}
return $data;
} | [
"public",
"static",
"function",
"load",
"(",
"/*# string */",
"$",
"path",
")",
"/*# : array */",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CONFIG_LOAD_ERROR",
",",
"$",
"path",
")",
",",
"Message",
"::",
"CONFIG_LOAD_ERROR",
")",
";",
"}",
"$",
"data",
"=",
"@",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"path",
")",
",",
"true",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"\\",
"JSON_ERROR_NONE",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'json_last_error_msg'",
")",
")",
"{",
"$",
"message",
"=",
"json_last_error_msg",
"(",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CONFIG_FORMAT_ERROR",
")",
";",
"}",
"throw",
"new",
"LogicException",
"(",
"$",
"message",
",",
"Message",
"::",
"CONFIG_FORMAT_ERROR",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Loader/JsonLoader.php#L34-L58 |
ZFrapid/zfrapid-library | src/View/Helper/H1.php | H1.toString | public function toString($indent = null)
{
$output = parent::toString($indent);
$output = str_replace(
['<title>', '</title>'], ['<h1>', '</h1>'], $output
);
return $output;
} | php | public function toString($indent = null)
{
$output = parent::toString($indent);
$output = str_replace(
['<title>', '</title>'], ['<h1>', '</h1>'], $output
);
return $output;
} | [
"public",
"function",
"toString",
"(",
"$",
"indent",
"=",
"null",
")",
"{",
"$",
"output",
"=",
"parent",
"::",
"toString",
"(",
"$",
"indent",
")",
";",
"$",
"output",
"=",
"str_replace",
"(",
"[",
"'<title>'",
",",
"'</title>'",
"]",
",",
"[",
"'<h1>'",
",",
"'</h1>'",
"]",
",",
"$",
"output",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Turn helper into string
@param string|null $indent
@return string | [
"Turn",
"helper",
"into",
"string"
] | train | https://github.com/ZFrapid/zfrapid-library/blob/3eca4f465dd1f2dee889532892c5052e830bc03c/src/View/Helper/H1.php#L51-L59 |
Vectrex/vxPHP | src/Application/Config.php | Config.dumpXmlErrors | private function dumpXmlErrors($xmlFile) {
$severity = [LIBXML_ERR_WARNING => 'Warning', LIBXML_ERR_ERROR => 'Error', LIBXML_ERR_FATAL => 'Fatal'];
$errors = [];
foreach(libxml_get_errors() as $error) {
$errors[] = sprintf("Row %d, column %d: %s (%d) %s", $error->line, $error->column, $severity[$error->level], $error->code, $error->message);
}
throw new ConfigException(sprintf("Could not parse XML configuration in '%s'.\n\n%s", $xmlFile, implode("\n", $errors)));
} | php | private function dumpXmlErrors($xmlFile) {
$severity = [LIBXML_ERR_WARNING => 'Warning', LIBXML_ERR_ERROR => 'Error', LIBXML_ERR_FATAL => 'Fatal'];
$errors = [];
foreach(libxml_get_errors() as $error) {
$errors[] = sprintf("Row %d, column %d: %s (%d) %s", $error->line, $error->column, $severity[$error->level], $error->code, $error->message);
}
throw new ConfigException(sprintf("Could not parse XML configuration in '%s'.\n\n%s", $xmlFile, implode("\n", $errors)));
} | [
"private",
"function",
"dumpXmlErrors",
"(",
"$",
"xmlFile",
")",
"{",
"$",
"severity",
"=",
"[",
"LIBXML_ERR_WARNING",
"=>",
"'Warning'",
",",
"LIBXML_ERR_ERROR",
"=>",
"'Error'",
",",
"LIBXML_ERR_FATAL",
"=>",
"'Fatal'",
"]",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"libxml_get_errors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"sprintf",
"(",
"\"Row %d, column %d: %s (%d) %s\"",
",",
"$",
"error",
"->",
"line",
",",
"$",
"error",
"->",
"column",
",",
"$",
"severity",
"[",
"$",
"error",
"->",
"level",
"]",
",",
"$",
"error",
"->",
"code",
",",
"$",
"error",
"->",
"message",
")",
";",
"}",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Could not parse XML configuration in '%s'.\\n\\n%s\"",
",",
"$",
"xmlFile",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"errors",
")",
")",
")",
";",
"}"
] | Create formatted output of XML errors
@param string $xmlFile
@throws ConfigException | [
"Create",
"formatted",
"output",
"of",
"XML",
"errors"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L173-L184 |
Vectrex/vxPHP | src/Application/Config.php | Config.includeIncludes | private function includeIncludes(\DOMDocument $doc, $filepath) {
$path = rtrim(dirname(realpath($filepath)), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if(in_array($filepath, $this->parsedXmlFiles)) {
throw new ConfigException(sprintf("File %s has already been used.", $filepath));
}
$this->parsedXmlFiles[] = $filepath;
$includes = (new \DOMXPath($doc))->query('//include');
foreach($includes as $node) {
if(!empty($node->nodeValue)) {
// load file
$include = new \DOMDocument();
if(!$include->load($path . $node->nodeValue, LIBXML_NOCDATA)) {
$this->dumpXmlErrors($path . $node->nodeValue);
exit();
}
// recursively insert includes
$this->includeIncludes($include, $path . $node->nodeValue);
// import root node and descendants of include
foreach($include->childNodes as $childNode) {
if($childNode instanceOf \DOMComment) {
continue;
}
$importedNode = $doc->importNode($childNode, true);
break;
}
// check whether included file groups several elements under a config element
if('config' !== $importedNode->nodeName) {
// replace include element with imported root element
$node->parentNode->replaceChild($importedNode, $node);
}
else {
// append all child elements of imported root element
while($importedNode->firstChild) {
$node->parentNode->insertBefore($importedNode->firstChild, $node);
}
// delete include element
$node->parentNode->removeChild($node);
}
}
}
} | php | private function includeIncludes(\DOMDocument $doc, $filepath) {
$path = rtrim(dirname(realpath($filepath)), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if(in_array($filepath, $this->parsedXmlFiles)) {
throw new ConfigException(sprintf("File %s has already been used.", $filepath));
}
$this->parsedXmlFiles[] = $filepath;
$includes = (new \DOMXPath($doc))->query('//include');
foreach($includes as $node) {
if(!empty($node->nodeValue)) {
// load file
$include = new \DOMDocument();
if(!$include->load($path . $node->nodeValue, LIBXML_NOCDATA)) {
$this->dumpXmlErrors($path . $node->nodeValue);
exit();
}
// recursively insert includes
$this->includeIncludes($include, $path . $node->nodeValue);
// import root node and descendants of include
foreach($include->childNodes as $childNode) {
if($childNode instanceOf \DOMComment) {
continue;
}
$importedNode = $doc->importNode($childNode, true);
break;
}
// check whether included file groups several elements under a config element
if('config' !== $importedNode->nodeName) {
// replace include element with imported root element
$node->parentNode->replaceChild($importedNode, $node);
}
else {
// append all child elements of imported root element
while($importedNode->firstChild) {
$node->parentNode->insertBefore($importedNode->firstChild, $node);
}
// delete include element
$node->parentNode->removeChild($node);
}
}
}
} | [
"private",
"function",
"includeIncludes",
"(",
"\\",
"DOMDocument",
"$",
"doc",
",",
"$",
"filepath",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"dirname",
"(",
"realpath",
"(",
"$",
"filepath",
")",
")",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"in_array",
"(",
"$",
"filepath",
",",
"$",
"this",
"->",
"parsedXmlFiles",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"File %s has already been used.\"",
",",
"$",
"filepath",
")",
")",
";",
"}",
"$",
"this",
"->",
"parsedXmlFiles",
"[",
"]",
"=",
"$",
"filepath",
";",
"$",
"includes",
"=",
"(",
"new",
"\\",
"DOMXPath",
"(",
"$",
"doc",
")",
")",
"->",
"query",
"(",
"'//include'",
")",
";",
"foreach",
"(",
"$",
"includes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"node",
"->",
"nodeValue",
")",
")",
"{",
"// load file",
"$",
"include",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"include",
"->",
"load",
"(",
"$",
"path",
".",
"$",
"node",
"->",
"nodeValue",
",",
"LIBXML_NOCDATA",
")",
")",
"{",
"$",
"this",
"->",
"dumpXmlErrors",
"(",
"$",
"path",
".",
"$",
"node",
"->",
"nodeValue",
")",
";",
"exit",
"(",
")",
";",
"}",
"// recursively insert includes",
"$",
"this",
"->",
"includeIncludes",
"(",
"$",
"include",
",",
"$",
"path",
".",
"$",
"node",
"->",
"nodeValue",
")",
";",
"// import root node and descendants of include",
"foreach",
"(",
"$",
"include",
"->",
"childNodes",
"as",
"$",
"childNode",
")",
"{",
"if",
"(",
"$",
"childNode",
"instanceOf",
"\\",
"DOMComment",
")",
"{",
"continue",
";",
"}",
"$",
"importedNode",
"=",
"$",
"doc",
"->",
"importNode",
"(",
"$",
"childNode",
",",
"true",
")",
";",
"break",
";",
"}",
"// check whether included file groups several elements under a config element",
"if",
"(",
"'config'",
"!==",
"$",
"importedNode",
"->",
"nodeName",
")",
"{",
"// replace include element with imported root element",
"$",
"node",
"->",
"parentNode",
"->",
"replaceChild",
"(",
"$",
"importedNode",
",",
"$",
"node",
")",
";",
"}",
"else",
"{",
"// append all child elements of imported root element",
"while",
"(",
"$",
"importedNode",
"->",
"firstChild",
")",
"{",
"$",
"node",
"->",
"parentNode",
"->",
"insertBefore",
"(",
"$",
"importedNode",
"->",
"firstChild",
",",
"$",
"node",
")",
";",
"}",
"// delete include element",
"$",
"node",
"->",
"parentNode",
"->",
"removeChild",
"(",
"$",
"node",
")",
";",
"}",
"}",
"}",
"}"
] | recursively include XML files in include tags
to avoid circular references any file can only be included once
@param \DOMDocument $doc
@param string $filepath
@throws ConfigException | [
"recursively",
"include",
"XML",
"files",
"in",
"include",
"tags",
"to",
"avoid",
"circular",
"references",
"any",
"file",
"can",
"only",
"be",
"included",
"once"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L194-L267 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseConfig | private function parseConfig(\DOMDocument $config) {
try {
// determine server context, missing SERVER_ADDR assumes localhost/CLI
$this->isLocalhost = !isset($_SERVER['SERVER_ADDR']) || !!preg_match('/^(?:127|192|1|0)(?:\.\d{1,3}){3}$/', $_SERVER['SERVER_ADDR']);
$rootNode = $config->firstChild;
// allow parsing of specific sections
foreach($rootNode->childNodes as $section) {
if($section->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$sectionName = $section->nodeName;
if(empty($this->sections) || in_array($sectionName, $this->sections)) {
$methodName =
'parse' .
ucfirst(preg_replace_callback('/_([a-z])/', function($match) { return strtoupper($match[1]); }, $sectionName)) .
'Settings'
;
if(method_exists($this, $methodName)) {
call_user_func([$this, $methodName], $section);
}
}
}
}
catch(ConfigException $e) {
throw $e;
}
} | php | private function parseConfig(\DOMDocument $config) {
try {
// determine server context, missing SERVER_ADDR assumes localhost/CLI
$this->isLocalhost = !isset($_SERVER['SERVER_ADDR']) || !!preg_match('/^(?:127|192|1|0)(?:\.\d{1,3}){3}$/', $_SERVER['SERVER_ADDR']);
$rootNode = $config->firstChild;
// allow parsing of specific sections
foreach($rootNode->childNodes as $section) {
if($section->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$sectionName = $section->nodeName;
if(empty($this->sections) || in_array($sectionName, $this->sections)) {
$methodName =
'parse' .
ucfirst(preg_replace_callback('/_([a-z])/', function($match) { return strtoupper($match[1]); }, $sectionName)) .
'Settings'
;
if(method_exists($this, $methodName)) {
call_user_func([$this, $methodName], $section);
}
}
}
}
catch(ConfigException $e) {
throw $e;
}
} | [
"private",
"function",
"parseConfig",
"(",
"\\",
"DOMDocument",
"$",
"config",
")",
"{",
"try",
"{",
"// determine server context, missing SERVER_ADDR assumes localhost/CLI",
"$",
"this",
"->",
"isLocalhost",
"=",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_ADDR'",
"]",
")",
"||",
"!",
"!",
"preg_match",
"(",
"'/^(?:127|192|1|0)(?:\\.\\d{1,3}){3}$/'",
",",
"$",
"_SERVER",
"[",
"'SERVER_ADDR'",
"]",
")",
";",
"$",
"rootNode",
"=",
"$",
"config",
"->",
"firstChild",
";",
"// allow parsing of specific sections",
"foreach",
"(",
"$",
"rootNode",
"->",
"childNodes",
"as",
"$",
"section",
")",
"{",
"if",
"(",
"$",
"section",
"->",
"nodeType",
"!==",
"XML_ELEMENT_NODE",
")",
"{",
"continue",
";",
"}",
"$",
"sectionName",
"=",
"$",
"section",
"->",
"nodeName",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"sections",
")",
"||",
"in_array",
"(",
"$",
"sectionName",
",",
"$",
"this",
"->",
"sections",
")",
")",
"{",
"$",
"methodName",
"=",
"'parse'",
".",
"ucfirst",
"(",
"preg_replace_callback",
"(",
"'/_([a-z])/'",
",",
"function",
"(",
"$",
"match",
")",
"{",
"return",
"strtoupper",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"}",
",",
"$",
"sectionName",
")",
")",
".",
"'Settings'",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
")",
"{",
"call_user_func",
"(",
"[",
"$",
"this",
",",
"$",
"methodName",
"]",
",",
"$",
"section",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"ConfigException",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}"
] | iterates through the top level nodes (sections) of the config
file; if a method matching the section name is found this method
is called to parse the section
@param \DOMDocument $config
@throws ConfigException
@return void | [
"iterates",
"through",
"the",
"top",
"level",
"nodes",
"(",
"sections",
")",
"of",
"the",
"config",
"file",
";",
"if",
"a",
"method",
"matching",
"the",
"section",
"name",
"is",
"found",
"this",
"method",
"is",
"called",
"to",
"parse",
"the",
"section"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L278-L324 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseDbSettings | private function parseDbSettings(\DOMNode $db) {
$context = $this->isLocalhost ? 'local' : 'remote';
$xpath = new \DOMXPath($db->ownerDocument);
$d = $xpath->query("db_connection[@context='$context']", $db);
if(!$d->length) {
$d = $db->getElementsByTagName('db_connection');
}
if($d->length) {
$this->db = new \stdClass();
foreach($d->item(0)->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$v = trim($node->nodeValue);
$k = $node->nodeName;
$this->db->$k = $v;
}
}
} | php | private function parseDbSettings(\DOMNode $db) {
$context = $this->isLocalhost ? 'local' : 'remote';
$xpath = new \DOMXPath($db->ownerDocument);
$d = $xpath->query("db_connection[@context='$context']", $db);
if(!$d->length) {
$d = $db->getElementsByTagName('db_connection');
}
if($d->length) {
$this->db = new \stdClass();
foreach($d->item(0)->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$v = trim($node->nodeValue);
$k = $node->nodeName;
$this->db->$k = $v;
}
}
} | [
"private",
"function",
"parseDbSettings",
"(",
"\\",
"DOMNode",
"$",
"db",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"isLocalhost",
"?",
"'local'",
":",
"'remote'",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"db",
"->",
"ownerDocument",
")",
";",
"$",
"d",
"=",
"$",
"xpath",
"->",
"query",
"(",
"\"db_connection[@context='$context']\"",
",",
"$",
"db",
")",
";",
"if",
"(",
"!",
"$",
"d",
"->",
"length",
")",
"{",
"$",
"d",
"=",
"$",
"db",
"->",
"getElementsByTagName",
"(",
"'db_connection'",
")",
";",
"}",
"if",
"(",
"$",
"d",
"->",
"length",
")",
"{",
"$",
"this",
"->",
"db",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"d",
"->",
"item",
"(",
"0",
")",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"nodeType",
"!==",
"XML_ELEMENT_NODE",
")",
"{",
"continue",
";",
"}",
"$",
"v",
"=",
"trim",
"(",
"$",
"node",
"->",
"nodeValue",
")",
";",
"$",
"k",
"=",
"$",
"node",
"->",
"nodeName",
";",
"$",
"this",
"->",
"db",
"->",
"$",
"k",
"=",
"$",
"v",
";",
"}",
"}",
"}"
] | parse db settings
@deprecated will be replaced by datasource settings
@param DOMNode $db | [
"parse",
"db",
"settings"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L335-L363 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseVxpdoSettings | private function parseVxpdoSettings(\DOMNode $vxpdo) {
if(is_null($this->vxpdo)) {
$this->vxpdo = [];
}
foreach($vxpdo->getElementsByTagName('datasource') as $datasource) {
$name = $datasource->getAttribute('name') ?: 'default';
if(array_key_exists($name, $this->vxpdo)) {
throw new ConfigException(sprintf("Datasource '%s' declared twice.", $name));
}
$config = [
'driver' => null,
'dsn' => null,
'host' => null,
'port' => null,
'user' => null,
'password' => null,
'dbname' => null,
];
foreach($datasource->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
if(array_key_exists($node->nodeName, $config)) {
$config[$node->nodeName] = trim($node->nodeValue);
}
}
$this->vxpdo[$name] = (object) $config;
}
} | php | private function parseVxpdoSettings(\DOMNode $vxpdo) {
if(is_null($this->vxpdo)) {
$this->vxpdo = [];
}
foreach($vxpdo->getElementsByTagName('datasource') as $datasource) {
$name = $datasource->getAttribute('name') ?: 'default';
if(array_key_exists($name, $this->vxpdo)) {
throw new ConfigException(sprintf("Datasource '%s' declared twice.", $name));
}
$config = [
'driver' => null,
'dsn' => null,
'host' => null,
'port' => null,
'user' => null,
'password' => null,
'dbname' => null,
];
foreach($datasource->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
if(array_key_exists($node->nodeName, $config)) {
$config[$node->nodeName] = trim($node->nodeValue);
}
}
$this->vxpdo[$name] = (object) $config;
}
} | [
"private",
"function",
"parseVxpdoSettings",
"(",
"\\",
"DOMNode",
"$",
"vxpdo",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"vxpdo",
")",
")",
"{",
"$",
"this",
"->",
"vxpdo",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"vxpdo",
"->",
"getElementsByTagName",
"(",
"'datasource'",
")",
"as",
"$",
"datasource",
")",
"{",
"$",
"name",
"=",
"$",
"datasource",
"->",
"getAttribute",
"(",
"'name'",
")",
"?",
":",
"'default'",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"vxpdo",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Datasource '%s' declared twice.\"",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"config",
"=",
"[",
"'driver'",
"=>",
"null",
",",
"'dsn'",
"=>",
"null",
",",
"'host'",
"=>",
"null",
",",
"'port'",
"=>",
"null",
",",
"'user'",
"=>",
"null",
",",
"'password'",
"=>",
"null",
",",
"'dbname'",
"=>",
"null",
",",
"]",
";",
"foreach",
"(",
"$",
"datasource",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"nodeType",
"!==",
"XML_ELEMENT_NODE",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"node",
"->",
"nodeName",
",",
"$",
"config",
")",
")",
"{",
"$",
"config",
"[",
"$",
"node",
"->",
"nodeName",
"]",
"=",
"trim",
"(",
"$",
"node",
"->",
"nodeValue",
")",
";",
"}",
"}",
"$",
"this",
"->",
"vxpdo",
"[",
"$",
"name",
"]",
"=",
"(",
"object",
")",
"$",
"config",
";",
"}",
"}"
] | parse datasource settings
@param \DOMNode $datasources
@throws ConfigException | [
"parse",
"datasource",
"settings"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L371-L410 |
Vectrex/vxPHP | src/Application/Config.php | Config.parsePropelSettings | private function parsePropelSettings(\DOMNode $propel) {
if(!class_exists('\\PropelConfiguration')) {
throw new ConfigException("Class 'PropelConfiguration' not found.");
}
var_dump(json_decode(json_encode((array) $propel)), true);
} | php | private function parsePropelSettings(\DOMNode $propel) {
if(!class_exists('\\PropelConfiguration')) {
throw new ConfigException("Class 'PropelConfiguration' not found.");
}
var_dump(json_decode(json_encode((array) $propel)), true);
} | [
"private",
"function",
"parsePropelSettings",
"(",
"\\",
"DOMNode",
"$",
"propel",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'\\\\PropelConfiguration'",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"Class 'PropelConfiguration' not found.\"",
")",
";",
"}",
"var_dump",
"(",
"json_decode",
"(",
"json_encode",
"(",
"(",
"array",
")",
"$",
"propel",
")",
")",
",",
"true",
")",
";",
"}"
] | @todo
@param \DOMNode $propel
@throws ConfigException | [
"@todo"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L418-L426 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseMailSettings | private function parseMailSettings(\DOMNode $mail) {
if(($mailer = $mail->getElementsByTagName('mailer')->item(0))) {
if(is_null($this->mail)) {
$this->mail = new \stdClass();
$this->mail->mailer = new \stdClass();
}
if(!($class = $mailer->getAttribute('class'))) {
throw new ConfigException('No mailer class specified.');
}
$this->mail->mailer->class = $class;
foreach($mailer->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$this->mail->mailer->{$node->nodeName} = trim($node->nodeValue);
}
}
} | php | private function parseMailSettings(\DOMNode $mail) {
if(($mailer = $mail->getElementsByTagName('mailer')->item(0))) {
if(is_null($this->mail)) {
$this->mail = new \stdClass();
$this->mail->mailer = new \stdClass();
}
if(!($class = $mailer->getAttribute('class'))) {
throw new ConfigException('No mailer class specified.');
}
$this->mail->mailer->class = $class;
foreach($mailer->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$this->mail->mailer->{$node->nodeName} = trim($node->nodeValue);
}
}
} | [
"private",
"function",
"parseMailSettings",
"(",
"\\",
"DOMNode",
"$",
"mail",
")",
"{",
"if",
"(",
"(",
"$",
"mailer",
"=",
"$",
"mail",
"->",
"getElementsByTagName",
"(",
"'mailer'",
")",
"->",
"item",
"(",
"0",
")",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"mail",
")",
")",
"{",
"$",
"this",
"->",
"mail",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"this",
"->",
"mail",
"->",
"mailer",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"class",
"=",
"$",
"mailer",
"->",
"getAttribute",
"(",
"'class'",
")",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'No mailer class specified.'",
")",
";",
"}",
"$",
"this",
"->",
"mail",
"->",
"mailer",
"->",
"class",
"=",
"$",
"class",
";",
"foreach",
"(",
"$",
"mailer",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"nodeType",
"!==",
"XML_ELEMENT_NODE",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"mail",
"->",
"mailer",
"->",
"{",
"$",
"node",
"->",
"nodeName",
"}",
"=",
"trim",
"(",
"$",
"node",
"->",
"nodeValue",
")",
";",
"}",
"}",
"}"
] | parses all (optional) mail settings
@param \DOMNode $mail
@throws ConfigException | [
"parses",
"all",
"(",
"optional",
")",
"mail",
"settings"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L434-L460 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseBinariesSettings | private function parseBinariesSettings(\DOMNode $binaries) {
$context = $this->isLocalhost ? 'local' : 'remote';
$xpath = new \DOMXPath($binaries->ownerDocument);
$e = $xpath->query("db_connection[@context='$context']", $binaries);
if(!$e->length) {
$e = $xpath->query('executables');
}
if($e->length) {
$p = $e->item(0)->getElementsByTagName('path');
if(empty($p)) {
throw new ConfigException('Malformed "site.ini.xml"! Missing path for binaries.');
}
$this->binaries = new \stdClass;
$this->binaries->path = rtrim($p->item(0)->nodeValue, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
foreach($e->item(0)->getElementsByTagName('executable') as $v) {
if(!($id = $v->getAttribute('id'))) {
throw new ConfigException('Binary without id found.');
}
foreach($v->attributes as $attr) {
$this->binaries->executables[$id][$attr->nodeName] = $attr->nodeValue;
}
}
}
} | php | private function parseBinariesSettings(\DOMNode $binaries) {
$context = $this->isLocalhost ? 'local' : 'remote';
$xpath = new \DOMXPath($binaries->ownerDocument);
$e = $xpath->query("db_connection[@context='$context']", $binaries);
if(!$e->length) {
$e = $xpath->query('executables');
}
if($e->length) {
$p = $e->item(0)->getElementsByTagName('path');
if(empty($p)) {
throw new ConfigException('Malformed "site.ini.xml"! Missing path for binaries.');
}
$this->binaries = new \stdClass;
$this->binaries->path = rtrim($p->item(0)->nodeValue, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
foreach($e->item(0)->getElementsByTagName('executable') as $v) {
if(!($id = $v->getAttribute('id'))) {
throw new ConfigException('Binary without id found.');
}
foreach($v->attributes as $attr) {
$this->binaries->executables[$id][$attr->nodeName] = $attr->nodeValue;
}
}
}
} | [
"private",
"function",
"parseBinariesSettings",
"(",
"\\",
"DOMNode",
"$",
"binaries",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"isLocalhost",
"?",
"'local'",
":",
"'remote'",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"binaries",
"->",
"ownerDocument",
")",
";",
"$",
"e",
"=",
"$",
"xpath",
"->",
"query",
"(",
"\"db_connection[@context='$context']\"",
",",
"$",
"binaries",
")",
";",
"if",
"(",
"!",
"$",
"e",
"->",
"length",
")",
"{",
"$",
"e",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'executables'",
")",
";",
"}",
"if",
"(",
"$",
"e",
"->",
"length",
")",
"{",
"$",
"p",
"=",
"$",
"e",
"->",
"item",
"(",
"0",
")",
"->",
"getElementsByTagName",
"(",
"'path'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"p",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Malformed \"site.ini.xml\"! Missing path for binaries.'",
")",
";",
"}",
"$",
"this",
"->",
"binaries",
"=",
"new",
"\\",
"stdClass",
";",
"$",
"this",
"->",
"binaries",
"->",
"path",
"=",
"rtrim",
"(",
"$",
"p",
"->",
"item",
"(",
"0",
")",
"->",
"nodeValue",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"foreach",
"(",
"$",
"e",
"->",
"item",
"(",
"0",
")",
"->",
"getElementsByTagName",
"(",
"'executable'",
")",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"id",
"=",
"$",
"v",
"->",
"getAttribute",
"(",
"'id'",
")",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Binary without id found.'",
")",
";",
"}",
"foreach",
"(",
"$",
"v",
"->",
"attributes",
"as",
"$",
"attr",
")",
"{",
"$",
"this",
"->",
"binaries",
"->",
"executables",
"[",
"$",
"id",
"]",
"[",
"$",
"attr",
"->",
"nodeName",
"]",
"=",
"$",
"attr",
"->",
"nodeValue",
";",
"}",
"}",
"}",
"}"
] | parse settings for binaries
@todo clean up code
@param \DOMNode $binaries
@throws ConfigException | [
"parse",
"settings",
"for",
"binaries",
"@todo",
"clean",
"up",
"code"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L469-L504 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseSiteSettings | private function parseSiteSettings(\DOMNode $site) {
if(is_null($this->site)) {
$this->site = new \stdClass;
$this->site->use_nice_uris = FALSE;
}
foreach($site->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$v = trim($node->nodeValue);
$k = $node->nodeName;
switch ($k) {
case 'locales':
if(!isset($this->site->locales)) {
$this->site->locales = [];
}
foreach($node->getElementsByTagName('locale') as $locale) {
$loc = $locale->getAttribute('value');
if($loc && !in_array($loc, $this->site->locales)) {
$this->site->locales[] = $loc;
}
if($loc && $locale->getAttribute('default') === '1') {
$this->site->default_locale = $loc;
}
}
break;
case 'site->use_nice_uris':
if($v === '1') {
$this->site->use_nice_uris = TRUE;
}
break;
default:
$this->site->$k = $v;
}
}
} | php | private function parseSiteSettings(\DOMNode $site) {
if(is_null($this->site)) {
$this->site = new \stdClass;
$this->site->use_nice_uris = FALSE;
}
foreach($site->childNodes as $node) {
if($node->nodeType !== XML_ELEMENT_NODE) {
continue;
}
$v = trim($node->nodeValue);
$k = $node->nodeName;
switch ($k) {
case 'locales':
if(!isset($this->site->locales)) {
$this->site->locales = [];
}
foreach($node->getElementsByTagName('locale') as $locale) {
$loc = $locale->getAttribute('value');
if($loc && !in_array($loc, $this->site->locales)) {
$this->site->locales[] = $loc;
}
if($loc && $locale->getAttribute('default') === '1') {
$this->site->default_locale = $loc;
}
}
break;
case 'site->use_nice_uris':
if($v === '1') {
$this->site->use_nice_uris = TRUE;
}
break;
default:
$this->site->$k = $v;
}
}
} | [
"private",
"function",
"parseSiteSettings",
"(",
"\\",
"DOMNode",
"$",
"site",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"site",
")",
")",
"{",
"$",
"this",
"->",
"site",
"=",
"new",
"\\",
"stdClass",
";",
"$",
"this",
"->",
"site",
"->",
"use_nice_uris",
"=",
"FALSE",
";",
"}",
"foreach",
"(",
"$",
"site",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"nodeType",
"!==",
"XML_ELEMENT_NODE",
")",
"{",
"continue",
";",
"}",
"$",
"v",
"=",
"trim",
"(",
"$",
"node",
"->",
"nodeValue",
")",
";",
"$",
"k",
"=",
"$",
"node",
"->",
"nodeName",
";",
"switch",
"(",
"$",
"k",
")",
"{",
"case",
"'locales'",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"site",
"->",
"locales",
")",
")",
"{",
"$",
"this",
"->",
"site",
"->",
"locales",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"node",
"->",
"getElementsByTagName",
"(",
"'locale'",
")",
"as",
"$",
"locale",
")",
"{",
"$",
"loc",
"=",
"$",
"locale",
"->",
"getAttribute",
"(",
"'value'",
")",
";",
"if",
"(",
"$",
"loc",
"&&",
"!",
"in_array",
"(",
"$",
"loc",
",",
"$",
"this",
"->",
"site",
"->",
"locales",
")",
")",
"{",
"$",
"this",
"->",
"site",
"->",
"locales",
"[",
"]",
"=",
"$",
"loc",
";",
"}",
"if",
"(",
"$",
"loc",
"&&",
"$",
"locale",
"->",
"getAttribute",
"(",
"'default'",
")",
"===",
"'1'",
")",
"{",
"$",
"this",
"->",
"site",
"->",
"default_locale",
"=",
"$",
"loc",
";",
"}",
"}",
"break",
";",
"case",
"'site->use_nice_uris'",
":",
"if",
"(",
"$",
"v",
"===",
"'1'",
")",
"{",
"$",
"this",
"->",
"site",
"->",
"use_nice_uris",
"=",
"TRUE",
";",
"}",
"break",
";",
"default",
":",
"$",
"this",
"->",
"site",
"->",
"$",
"k",
"=",
"$",
"v",
";",
"}",
"}",
"}"
] | parse general website settings
@param \DOMNode $site | [
"parse",
"general",
"website",
"settings"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L511-L560 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseTemplatingSettings | private function parseTemplatingSettings(\DOMNode $templating) {
if(is_null($this->templating)) {
$this->templating = new \stdClass;
$this->templating->filters = [];
}
$xpath = new \DOMXPath($templating->ownerDocument);
foreach($xpath->query("filters/filter", $templating) as $filter) {
$id = $filter->getAttribute('id');
$class = $filter->getAttribute('class');
if(!$id) {
throw new ConfigException('Templating filter without id found.');
}
if(!$class) {
throw new ConfigException(sprintf("No class for templating filter '%s' configured.", $id));
}
if(isset($this->templating->filters[$id])) {
throw new ConfigException(sprintf("Templating filter '%s' has already been defined.", $id));
}
// clean path delimiters, prepend leading backslash, and replace slashes with backslashes
$class = '\\' . ltrim(str_replace('/', '\\', $class), '/\\');
// store parsed information
$this->templating->filters[$id] = [
'class' => $class,
'parameters' => $filter->getAttribute('parameters')
];
}
} | php | private function parseTemplatingSettings(\DOMNode $templating) {
if(is_null($this->templating)) {
$this->templating = new \stdClass;
$this->templating->filters = [];
}
$xpath = new \DOMXPath($templating->ownerDocument);
foreach($xpath->query("filters/filter", $templating) as $filter) {
$id = $filter->getAttribute('id');
$class = $filter->getAttribute('class');
if(!$id) {
throw new ConfigException('Templating filter without id found.');
}
if(!$class) {
throw new ConfigException(sprintf("No class for templating filter '%s' configured.", $id));
}
if(isset($this->templating->filters[$id])) {
throw new ConfigException(sprintf("Templating filter '%s' has already been defined.", $id));
}
// clean path delimiters, prepend leading backslash, and replace slashes with backslashes
$class = '\\' . ltrim(str_replace('/', '\\', $class), '/\\');
// store parsed information
$this->templating->filters[$id] = [
'class' => $class,
'parameters' => $filter->getAttribute('parameters')
];
}
} | [
"private",
"function",
"parseTemplatingSettings",
"(",
"\\",
"DOMNode",
"$",
"templating",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"templating",
")",
")",
"{",
"$",
"this",
"->",
"templating",
"=",
"new",
"\\",
"stdClass",
";",
"$",
"this",
"->",
"templating",
"->",
"filters",
"=",
"[",
"]",
";",
"}",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"templating",
"->",
"ownerDocument",
")",
";",
"foreach",
"(",
"$",
"xpath",
"->",
"query",
"(",
"\"filters/filter\"",
",",
"$",
"templating",
")",
"as",
"$",
"filter",
")",
"{",
"$",
"id",
"=",
"$",
"filter",
"->",
"getAttribute",
"(",
"'id'",
")",
";",
"$",
"class",
"=",
"$",
"filter",
"->",
"getAttribute",
"(",
"'class'",
")",
";",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Templating filter without id found.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"No class for templating filter '%s' configured.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"templating",
"->",
"filters",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Templating filter '%s' has already been defined.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"// clean path delimiters, prepend leading backslash, and replace slashes with backslashes",
"$",
"class",
"=",
"'\\\\'",
".",
"ltrim",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"class",
")",
",",
"'/\\\\'",
")",
";",
"// store parsed information",
"$",
"this",
"->",
"templating",
"->",
"filters",
"[",
"$",
"id",
"]",
"=",
"[",
"'class'",
"=>",
"$",
"class",
",",
"'parameters'",
"=>",
"$",
"filter",
"->",
"getAttribute",
"(",
"'parameters'",
")",
"]",
";",
"}",
"}"
] | parse templating configuration
currently only filters for SimpleTemplate templates and their configuration are parsed
@param \DOMNode $templating | [
"parse",
"templating",
"configuration",
"currently",
"only",
"filters",
"for",
"SimpleTemplate",
"templates",
"and",
"their",
"configuration",
"are",
"parsed"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L568-L607 |
Vectrex/vxPHP | src/Application/Config.php | Config.parsePathsSettings | private function parsePathsSettings(\DOMNode $paths) {
if(is_null($this->paths)) {
$this->paths = [];
}
foreach($paths->getElementsByTagName('path') as $path) {
$id = $path->getAttribute('id');
$subdir = $path->getAttribute('subdir') ?: '';
if(!$id || !$subdir) {
continue;
}
$subdir = '/' . trim($subdir, '/') . '/';
// additional attributes are currently ignored
$this->paths[$id] = ['subdir' => $subdir];
}
} | php | private function parsePathsSettings(\DOMNode $paths) {
if(is_null($this->paths)) {
$this->paths = [];
}
foreach($paths->getElementsByTagName('path') as $path) {
$id = $path->getAttribute('id');
$subdir = $path->getAttribute('subdir') ?: '';
if(!$id || !$subdir) {
continue;
}
$subdir = '/' . trim($subdir, '/') . '/';
// additional attributes are currently ignored
$this->paths[$id] = ['subdir' => $subdir];
}
} | [
"private",
"function",
"parsePathsSettings",
"(",
"\\",
"DOMNode",
"$",
"paths",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"paths",
")",
")",
"{",
"$",
"this",
"->",
"paths",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"paths",
"->",
"getElementsByTagName",
"(",
"'path'",
")",
"as",
"$",
"path",
")",
"{",
"$",
"id",
"=",
"$",
"path",
"->",
"getAttribute",
"(",
"'id'",
")",
";",
"$",
"subdir",
"=",
"$",
"path",
"->",
"getAttribute",
"(",
"'subdir'",
")",
"?",
":",
"''",
";",
"if",
"(",
"!",
"$",
"id",
"||",
"!",
"$",
"subdir",
")",
"{",
"continue",
";",
"}",
"$",
"subdir",
"=",
"'/'",
".",
"trim",
"(",
"$",
"subdir",
",",
"'/'",
")",
".",
"'/'",
";",
"// additional attributes are currently ignored",
"$",
"this",
"->",
"paths",
"[",
"$",
"id",
"]",
"=",
"[",
"'subdir'",
"=>",
"$",
"subdir",
"]",
";",
"}",
"}"
] | parse various path setting
@param \DOMNode $paths | [
"parse",
"various",
"path",
"setting"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L614-L637 |
Vectrex/vxPHP | src/Application/Config.php | Config.parsePagesSettings | private function parsePagesSettings(\DOMNode $pages) {
$scriptName = $pages->getAttribute('script');
if(!$scriptName) {
if($this->site) {
$scriptName = $this->site->root_document ?: 'index.php';
}
else {
$scriptName = 'index.php';
}
}
$redirect = $pages->getAttribute('default_redirect');
if(is_null($this->routes)) {
$this->routes = [];
}
if(!array_key_exists($scriptName, $this->routes)) {
$this->routes[$scriptName] = [];
}
foreach($pages->getElementsByTagName('page') as $page) {
$parameters = [
'redirect' => $redirect
];
// get route id
$pageId = $page->getAttribute('id');
if(is_null($pageId) || trim($pageId) === '') {
throw new ConfigException('Route with missing or invalid id found.');
}
// read optional controller
if(($controller = $page->getAttribute('controller'))) {
// clean path delimiters, prepend leading backslash, replace slashes with backslashes, apply ucfirst to all namespaces
$namespaces = explode('\\', ltrim(str_replace('/', '\\', $controller), '/\\'));
if(count($namespaces) && $namespaces[0]) {
$parameters['controller'] = '\\Controller\\'. implode('\\', array_map('ucfirst', $namespaces)) . 'Controller';
}
else {
throw new ConfigException(sprintf("Controller string '%s' cannot be parsed.", (string) $controller));
}
}
// read optional controller method
if(($method = $page->getAttribute('method'))) {
$parameters['method'] = $method;
}
// read optional allowed request methods
if(($requestMethods = $page->getAttribute('request_methods'))) {
$allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
$requestMethods = preg_split('~\s*,\s*~', strtoupper($requestMethods));
foreach($requestMethods as $requestMethod) {
if(!in_array($requestMethod, $allowedMethods)) {
throw new ConfigException(sprintf("Invalid request method '%s' for route '%s'.", $requestMethod, $pageId));
}
}
$parameters['requestMethods'] = $requestMethods;
}
// when no path is defined page id will be used for route lookup
if(($path = $page->getAttribute('path'))) {
// initialize lookup expression
$rex = $path;
// extract route parameters and default values
if(preg_match_all('~\{(.*?)(=.*?)?\}~', $path, $matches)) {
$placeholders = [];
if(!empty($matches[1])) {
foreach($matches[1] as $ndx => $name) {
$name = strtolower($name);
if(!empty($matches[2][$ndx])) {
$placeholders[$name] = [
'name' => $name,
'default' => substr($matches[2][$ndx], 1)
];
// turn this path parameter into regexp and make it optional
$rex = preg_replace('~\{.*?\}~', '(?:([^/]+))?', $rex, 1);
}
else {
$placeholders[$name] = [
'name' => $name
];
// turn this path parameter into regexp
$rex = preg_replace('~\{.*?\}~', '([^/]+)', $rex, 1);
}
}
}
$parameters['placeholders'] = $placeholders;
}
$parameters['path'] = $path;
}
else {
$rex = $pageId;
}
$parameters['match'] = $rex;
// extract optional authentication requirements
if(($auth = $page->getAttribute('auth'))) {
$auth = strtolower(trim($auth));
if($auth && ($authParameters = $page->getAttribute('auth_parameters'))) {
$parameters['authParameters'] = trim($authParameters);
}
$parameters['auth'] = $auth;
}
if(isset($this->routes[$scriptName][$pageId])) {
throw new ConfigException(sprintf("Route '%s' for script '%s' found more than once.", $pageId, $scriptName));
}
$route = new Route($pageId, $scriptName, $parameters);
$this->routes[$scriptName][$route->getRouteId()] = $route;
}
} | php | private function parsePagesSettings(\DOMNode $pages) {
$scriptName = $pages->getAttribute('script');
if(!$scriptName) {
if($this->site) {
$scriptName = $this->site->root_document ?: 'index.php';
}
else {
$scriptName = 'index.php';
}
}
$redirect = $pages->getAttribute('default_redirect');
if(is_null($this->routes)) {
$this->routes = [];
}
if(!array_key_exists($scriptName, $this->routes)) {
$this->routes[$scriptName] = [];
}
foreach($pages->getElementsByTagName('page') as $page) {
$parameters = [
'redirect' => $redirect
];
// get route id
$pageId = $page->getAttribute('id');
if(is_null($pageId) || trim($pageId) === '') {
throw new ConfigException('Route with missing or invalid id found.');
}
// read optional controller
if(($controller = $page->getAttribute('controller'))) {
// clean path delimiters, prepend leading backslash, replace slashes with backslashes, apply ucfirst to all namespaces
$namespaces = explode('\\', ltrim(str_replace('/', '\\', $controller), '/\\'));
if(count($namespaces) && $namespaces[0]) {
$parameters['controller'] = '\\Controller\\'. implode('\\', array_map('ucfirst', $namespaces)) . 'Controller';
}
else {
throw new ConfigException(sprintf("Controller string '%s' cannot be parsed.", (string) $controller));
}
}
// read optional controller method
if(($method = $page->getAttribute('method'))) {
$parameters['method'] = $method;
}
// read optional allowed request methods
if(($requestMethods = $page->getAttribute('request_methods'))) {
$allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
$requestMethods = preg_split('~\s*,\s*~', strtoupper($requestMethods));
foreach($requestMethods as $requestMethod) {
if(!in_array($requestMethod, $allowedMethods)) {
throw new ConfigException(sprintf("Invalid request method '%s' for route '%s'.", $requestMethod, $pageId));
}
}
$parameters['requestMethods'] = $requestMethods;
}
// when no path is defined page id will be used for route lookup
if(($path = $page->getAttribute('path'))) {
// initialize lookup expression
$rex = $path;
// extract route parameters and default values
if(preg_match_all('~\{(.*?)(=.*?)?\}~', $path, $matches)) {
$placeholders = [];
if(!empty($matches[1])) {
foreach($matches[1] as $ndx => $name) {
$name = strtolower($name);
if(!empty($matches[2][$ndx])) {
$placeholders[$name] = [
'name' => $name,
'default' => substr($matches[2][$ndx], 1)
];
// turn this path parameter into regexp and make it optional
$rex = preg_replace('~\{.*?\}~', '(?:([^/]+))?', $rex, 1);
}
else {
$placeholders[$name] = [
'name' => $name
];
// turn this path parameter into regexp
$rex = preg_replace('~\{.*?\}~', '([^/]+)', $rex, 1);
}
}
}
$parameters['placeholders'] = $placeholders;
}
$parameters['path'] = $path;
}
else {
$rex = $pageId;
}
$parameters['match'] = $rex;
// extract optional authentication requirements
if(($auth = $page->getAttribute('auth'))) {
$auth = strtolower(trim($auth));
if($auth && ($authParameters = $page->getAttribute('auth_parameters'))) {
$parameters['authParameters'] = trim($authParameters);
}
$parameters['auth'] = $auth;
}
if(isset($this->routes[$scriptName][$pageId])) {
throw new ConfigException(sprintf("Route '%s' for script '%s' found more than once.", $pageId, $scriptName));
}
$route = new Route($pageId, $scriptName, $parameters);
$this->routes[$scriptName][$route->getRouteId()] = $route;
}
} | [
"private",
"function",
"parsePagesSettings",
"(",
"\\",
"DOMNode",
"$",
"pages",
")",
"{",
"$",
"scriptName",
"=",
"$",
"pages",
"->",
"getAttribute",
"(",
"'script'",
")",
";",
"if",
"(",
"!",
"$",
"scriptName",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"site",
")",
"{",
"$",
"scriptName",
"=",
"$",
"this",
"->",
"site",
"->",
"root_document",
"?",
":",
"'index.php'",
";",
"}",
"else",
"{",
"$",
"scriptName",
"=",
"'index.php'",
";",
"}",
"}",
"$",
"redirect",
"=",
"$",
"pages",
"->",
"getAttribute",
"(",
"'default_redirect'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"scriptName",
",",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"[",
"$",
"scriptName",
"]",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"pages",
"->",
"getElementsByTagName",
"(",
"'page'",
")",
"as",
"$",
"page",
")",
"{",
"$",
"parameters",
"=",
"[",
"'redirect'",
"=>",
"$",
"redirect",
"]",
";",
"// get route id",
"$",
"pageId",
"=",
"$",
"page",
"->",
"getAttribute",
"(",
"'id'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"pageId",
")",
"||",
"trim",
"(",
"$",
"pageId",
")",
"===",
"''",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Route with missing or invalid id found.'",
")",
";",
"}",
"// read optional controller",
"if",
"(",
"(",
"$",
"controller",
"=",
"$",
"page",
"->",
"getAttribute",
"(",
"'controller'",
")",
")",
")",
"{",
"// clean path delimiters, prepend leading backslash, replace slashes with backslashes, apply ucfirst to all namespaces",
"$",
"namespaces",
"=",
"explode",
"(",
"'\\\\'",
",",
"ltrim",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"controller",
")",
",",
"'/\\\\'",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"namespaces",
")",
"&&",
"$",
"namespaces",
"[",
"0",
"]",
")",
"{",
"$",
"parameters",
"[",
"'controller'",
"]",
"=",
"'\\\\Controller\\\\'",
".",
"implode",
"(",
"'\\\\'",
",",
"array_map",
"(",
"'ucfirst'",
",",
"$",
"namespaces",
")",
")",
".",
"'Controller'",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Controller string '%s' cannot be parsed.\"",
",",
"(",
"string",
")",
"$",
"controller",
")",
")",
";",
"}",
"}",
"// read optional controller method",
"if",
"(",
"(",
"$",
"method",
"=",
"$",
"page",
"->",
"getAttribute",
"(",
"'method'",
")",
")",
")",
"{",
"$",
"parameters",
"[",
"'method'",
"]",
"=",
"$",
"method",
";",
"}",
"// read optional allowed request methods",
"if",
"(",
"(",
"$",
"requestMethods",
"=",
"$",
"page",
"->",
"getAttribute",
"(",
"'request_methods'",
")",
")",
")",
"{",
"$",
"allowedMethods",
"=",
"[",
"'GET'",
",",
"'POST'",
",",
"'PUT'",
",",
"'DELETE'",
",",
"'PATCH'",
"]",
";",
"$",
"requestMethods",
"=",
"preg_split",
"(",
"'~\\s*,\\s*~'",
",",
"strtoupper",
"(",
"$",
"requestMethods",
")",
")",
";",
"foreach",
"(",
"$",
"requestMethods",
"as",
"$",
"requestMethod",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"requestMethod",
",",
"$",
"allowedMethods",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Invalid request method '%s' for route '%s'.\"",
",",
"$",
"requestMethod",
",",
"$",
"pageId",
")",
")",
";",
"}",
"}",
"$",
"parameters",
"[",
"'requestMethods'",
"]",
"=",
"$",
"requestMethods",
";",
"}",
"// when no path is defined page id will be used for route lookup",
"if",
"(",
"(",
"$",
"path",
"=",
"$",
"page",
"->",
"getAttribute",
"(",
"'path'",
")",
")",
")",
"{",
"// initialize lookup expression",
"$",
"rex",
"=",
"$",
"path",
";",
"// extract route parameters and default values",
"if",
"(",
"preg_match_all",
"(",
"'~\\{(.*?)(=.*?)?\\}~'",
",",
"$",
"path",
",",
"$",
"matches",
")",
")",
"{",
"$",
"placeholders",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"1",
"]",
"as",
"$",
"ndx",
"=>",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"ndx",
"]",
")",
")",
"{",
"$",
"placeholders",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'default'",
"=>",
"substr",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"ndx",
"]",
",",
"1",
")",
"]",
";",
"// turn this path parameter into regexp and make it optional",
"$",
"rex",
"=",
"preg_replace",
"(",
"'~\\{.*?\\}~'",
",",
"'(?:([^/]+))?'",
",",
"$",
"rex",
",",
"1",
")",
";",
"}",
"else",
"{",
"$",
"placeholders",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
"]",
";",
"// turn this path parameter into regexp",
"$",
"rex",
"=",
"preg_replace",
"(",
"'~\\{.*?\\}~'",
",",
"'([^/]+)'",
",",
"$",
"rex",
",",
"1",
")",
";",
"}",
"}",
"}",
"$",
"parameters",
"[",
"'placeholders'",
"]",
"=",
"$",
"placeholders",
";",
"}",
"$",
"parameters",
"[",
"'path'",
"]",
"=",
"$",
"path",
";",
"}",
"else",
"{",
"$",
"rex",
"=",
"$",
"pageId",
";",
"}",
"$",
"parameters",
"[",
"'match'",
"]",
"=",
"$",
"rex",
";",
"// extract optional authentication requirements",
"if",
"(",
"(",
"$",
"auth",
"=",
"$",
"page",
"->",
"getAttribute",
"(",
"'auth'",
")",
")",
")",
"{",
"$",
"auth",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"auth",
")",
")",
";",
"if",
"(",
"$",
"auth",
"&&",
"(",
"$",
"authParameters",
"=",
"$",
"page",
"->",
"getAttribute",
"(",
"'auth_parameters'",
")",
")",
")",
"{",
"$",
"parameters",
"[",
"'authParameters'",
"]",
"=",
"trim",
"(",
"$",
"authParameters",
")",
";",
"}",
"$",
"parameters",
"[",
"'auth'",
"]",
"=",
"$",
"auth",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"scriptName",
"]",
"[",
"$",
"pageId",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Route '%s' for script '%s' found more than once.\"",
",",
"$",
"pageId",
",",
"$",
"scriptName",
")",
")",
";",
"}",
"$",
"route",
"=",
"new",
"Route",
"(",
"$",
"pageId",
",",
"$",
"scriptName",
",",
"$",
"parameters",
")",
";",
"$",
"this",
"->",
"routes",
"[",
"$",
"scriptName",
"]",
"[",
"$",
"route",
"->",
"getRouteId",
"(",
")",
"]",
"=",
"$",
"route",
";",
"}",
"}"
] | parse page routes
called seperately for differing script attributes
@param \DOMNode $pages
@throws ConfigException | [
"parse",
"page",
"routes",
"called",
"seperately",
"for",
"differing",
"script",
"attributes"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L646-L803 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseMenusSettings | private function parseMenusSettings(\DOMNode $menus) {
foreach ((new \DOMXPath($menus->ownerDocument))->query('menu', $menus) as $menu) {
$id = $menu->getAttribute('id') ?: Menu::DEFAULT_ID;
if(isset($this->menus[$id])) {
$this->appendMenuEntries($menu->childNodes, $this->menus[$id]);
}
else {
$this->menus[$id] = $this->parseMenu($menu);
}
}
} | php | private function parseMenusSettings(\DOMNode $menus) {
foreach ((new \DOMXPath($menus->ownerDocument))->query('menu', $menus) as $menu) {
$id = $menu->getAttribute('id') ?: Menu::DEFAULT_ID;
if(isset($this->menus[$id])) {
$this->appendMenuEntries($menu->childNodes, $this->menus[$id]);
}
else {
$this->menus[$id] = $this->parseMenu($menu);
}
}
} | [
"private",
"function",
"parseMenusSettings",
"(",
"\\",
"DOMNode",
"$",
"menus",
")",
"{",
"foreach",
"(",
"(",
"new",
"\\",
"DOMXPath",
"(",
"$",
"menus",
"->",
"ownerDocument",
")",
")",
"->",
"query",
"(",
"'menu'",
",",
"$",
"menus",
")",
"as",
"$",
"menu",
")",
"{",
"$",
"id",
"=",
"$",
"menu",
"->",
"getAttribute",
"(",
"'id'",
")",
"?",
":",
"Menu",
"::",
"DEFAULT_ID",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"menus",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"appendMenuEntries",
"(",
"$",
"menu",
"->",
"childNodes",
",",
"$",
"this",
"->",
"menus",
"[",
"$",
"id",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"menus",
"[",
"$",
"id",
"]",
"=",
"$",
"this",
"->",
"parseMenu",
"(",
"$",
"menu",
")",
";",
"}",
"}",
"}"
] | parse menu tree
if menus share the same id entries of later menus are appended
to the first; other menu attributes are left unchanged
@param \DOMNode $menus
@throws ConfigException | [
"parse",
"menu",
"tree",
"if",
"menus",
"share",
"the",
"same",
"id",
"entries",
"of",
"later",
"menus",
"are",
"appended",
"to",
"the",
"first",
";",
"other",
"menu",
"attributes",
"are",
"left",
"unchanged"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L814-L829 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseServicesSettings | private function parseServicesSettings(\DOMNode $services) {
if(is_null($this->services)) {
$this->services = [];
}
foreach($services->getElementsByTagName('service') as $service) {
if(!($id = $service->getAttribute('id'))) {
throw new ConfigException('Service without id found.');
}
if(isset($this->services[$id])) {
throw new ConfigException(sprintf("Service '%s' has already been defined.", $id));
}
if(!($class = $service->getAttribute('class'))) {
throw new ConfigException(sprintf("No class for service '%s' configured.", $id));
}
// clean path delimiters, prepend leading backslash, and replace slashes with backslashes
$class = '\\' . ltrim(str_replace('/', '\\', $class), '/\\');
// store parsed information
$this->services[$id] = [
'class' => $class,
'parameters' => []
];
foreach($service->getElementsByTagName('parameter') as $parameter) {
$name = $parameter->getAttribute('name');
$value = $parameter->getAttribute('value');
if(!$name) {
throw new ConfigException(sprintf("A parameter for service '%s' has no name.", $id));
}
$this->services[$id]['parameters'][$name] = $value;
}
}
} | php | private function parseServicesSettings(\DOMNode $services) {
if(is_null($this->services)) {
$this->services = [];
}
foreach($services->getElementsByTagName('service') as $service) {
if(!($id = $service->getAttribute('id'))) {
throw new ConfigException('Service without id found.');
}
if(isset($this->services[$id])) {
throw new ConfigException(sprintf("Service '%s' has already been defined.", $id));
}
if(!($class = $service->getAttribute('class'))) {
throw new ConfigException(sprintf("No class for service '%s' configured.", $id));
}
// clean path delimiters, prepend leading backslash, and replace slashes with backslashes
$class = '\\' . ltrim(str_replace('/', '\\', $class), '/\\');
// store parsed information
$this->services[$id] = [
'class' => $class,
'parameters' => []
];
foreach($service->getElementsByTagName('parameter') as $parameter) {
$name = $parameter->getAttribute('name');
$value = $parameter->getAttribute('value');
if(!$name) {
throw new ConfigException(sprintf("A parameter for service '%s' has no name.", $id));
}
$this->services[$id]['parameters'][$name] = $value;
}
}
} | [
"private",
"function",
"parseServicesSettings",
"(",
"\\",
"DOMNode",
"$",
"services",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"services",
")",
")",
"{",
"$",
"this",
"->",
"services",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"services",
"->",
"getElementsByTagName",
"(",
"'service'",
")",
"as",
"$",
"service",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"id",
"=",
"$",
"service",
"->",
"getAttribute",
"(",
"'id'",
")",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Service without id found.'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"services",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Service '%s' has already been defined.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"class",
"=",
"$",
"service",
"->",
"getAttribute",
"(",
"'class'",
")",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"No class for service '%s' configured.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"// clean path delimiters, prepend leading backslash, and replace slashes with backslashes",
"$",
"class",
"=",
"'\\\\'",
".",
"ltrim",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"class",
")",
",",
"'/\\\\'",
")",
";",
"// store parsed information",
"$",
"this",
"->",
"services",
"[",
"$",
"id",
"]",
"=",
"[",
"'class'",
"=>",
"$",
"class",
",",
"'parameters'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"service",
"->",
"getElementsByTagName",
"(",
"'parameter'",
")",
"as",
"$",
"parameter",
")",
"{",
"$",
"name",
"=",
"$",
"parameter",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"$",
"value",
"=",
"$",
"parameter",
"->",
"getAttribute",
"(",
"'value'",
")",
";",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"A parameter for service '%s' has no name.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"services",
"[",
"$",
"id",
"]",
"[",
"'parameters'",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | parse settings for services
only service id, class and parameters are parsed
lazy initialization is handled by Application instance
@param \DOMNode $services
@throws ConfigException | [
"parse",
"settings",
"for",
"services",
"only",
"service",
"id",
"class",
"and",
"parameters",
"are",
"parsed",
"lazy",
"initialization",
"is",
"handled",
"by",
"Application",
"instance"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L839-L885 |
Vectrex/vxPHP | src/Application/Config.php | Config.parsePluginsSettings | private function parsePluginsSettings(\DOMNode $plugins) {
if(is_null($this->services)) {
$this->services = [];
}
foreach($plugins->getElementsByTagName('plugin') as $plugin) {
if(!($id = $plugin->getAttribute('id'))) {
throw new ConfigException('Plugin without id found.');
}
if(isset($this->plugins[$id])) {
throw new ConfigException(sprintf("Plugin '%s' has already been defined.", $id));
}
if(!($class = $plugin->getAttribute('class'))) {
throw new ConfigException(sprintf("No class for plugin '%s' configured.", $id));
}
// clean path delimiters, prepend leading backslash, and replace slashes with backslashes
$class = '\\' . ltrim(str_replace('/', '\\', $class), '/\\');
// store parsed information
$this->plugins[$id] = [
'class' => $class,
'parameters' => []
];
foreach($plugin->getElementsByTagName('parameter') as $parameter) {
$name = $parameter->getAttribute('name');
$value = $parameter->getAttribute('value');
if(!$name) {
throw new ConfigException(sprintf("A parameter for plugin '%s' has no name.", $id));
}
$this->plugins[$id]['parameters'][$name] = $value;
}
}
} | php | private function parsePluginsSettings(\DOMNode $plugins) {
if(is_null($this->services)) {
$this->services = [];
}
foreach($plugins->getElementsByTagName('plugin') as $plugin) {
if(!($id = $plugin->getAttribute('id'))) {
throw new ConfigException('Plugin without id found.');
}
if(isset($this->plugins[$id])) {
throw new ConfigException(sprintf("Plugin '%s' has already been defined.", $id));
}
if(!($class = $plugin->getAttribute('class'))) {
throw new ConfigException(sprintf("No class for plugin '%s' configured.", $id));
}
// clean path delimiters, prepend leading backslash, and replace slashes with backslashes
$class = '\\' . ltrim(str_replace('/', '\\', $class), '/\\');
// store parsed information
$this->plugins[$id] = [
'class' => $class,
'parameters' => []
];
foreach($plugin->getElementsByTagName('parameter') as $parameter) {
$name = $parameter->getAttribute('name');
$value = $parameter->getAttribute('value');
if(!$name) {
throw new ConfigException(sprintf("A parameter for plugin '%s' has no name.", $id));
}
$this->plugins[$id]['parameters'][$name] = $value;
}
}
} | [
"private",
"function",
"parsePluginsSettings",
"(",
"\\",
"DOMNode",
"$",
"plugins",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"services",
")",
")",
"{",
"$",
"this",
"->",
"services",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"plugins",
"->",
"getElementsByTagName",
"(",
"'plugin'",
")",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"id",
"=",
"$",
"plugin",
"->",
"getAttribute",
"(",
"'id'",
")",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Plugin without id found.'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"plugins",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Plugin '%s' has already been defined.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"class",
"=",
"$",
"plugin",
"->",
"getAttribute",
"(",
"'class'",
")",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"No class for plugin '%s' configured.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"// clean path delimiters, prepend leading backslash, and replace slashes with backslashes",
"$",
"class",
"=",
"'\\\\'",
".",
"ltrim",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"class",
")",
",",
"'/\\\\'",
")",
";",
"// store parsed information",
"$",
"this",
"->",
"plugins",
"[",
"$",
"id",
"]",
"=",
"[",
"'class'",
"=>",
"$",
"class",
",",
"'parameters'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"plugin",
"->",
"getElementsByTagName",
"(",
"'parameter'",
")",
"as",
"$",
"parameter",
")",
"{",
"$",
"name",
"=",
"$",
"parameter",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"$",
"value",
"=",
"$",
"parameter",
"->",
"getAttribute",
"(",
"'value'",
")",
";",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"A parameter for plugin '%s' has no name.\"",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"plugins",
"[",
"$",
"id",
"]",
"[",
"'parameters'",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | parses settings for plugins
plugin id, class, events and parameters are parsed
initialization (not lazy) is handled by Application instance
@param \DOMNode $plugins
@throws ConfigException | [
"parses",
"settings",
"for",
"plugins",
"plugin",
"id",
"class",
"events",
"and",
"parameters",
"are",
"parsed",
"initialization",
"(",
"not",
"lazy",
")",
"is",
"handled",
"by",
"Application",
"instance"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L895-L941 |
Vectrex/vxPHP | src/Application/Config.php | Config.parseMenu | private function parseMenu(\DOMNode $menu) {
$root = $menu->getAttribute('script');
if(!$root) {
if($this->site) {
$root= $this->site->root_document ?: 'index.php';
}
else {
$root= 'index.php';
}
}
$type = $menu->getAttribute('type') === 'dynamic' ? 'dynamic' : 'static';
$service = $menu->getAttribute('service') ?: NULL;
$id = $menu->getAttribute('id') ?: NULL;
if($type === 'dynamic' && !$service) {
throw new ConfigException("A dynamic menu requires a configured service.");
}
$m = new Menu(
$root,
$id,
$type,
$service
);
if(($menuAuth = strtolower(trim($menu->getAttribute('auth'))))) {
$m->setAuth($menuAuth);
// if an auth level is defined, additional authentication parameters can be set
if(($authParameters = $menu->getAttribute('auth_parameters'))) {
$m->setAuthParameters($authParameters);
}
}
$this->appendMenuEntries($menu->childNodes, $m);
return $m;
} | php | private function parseMenu(\DOMNode $menu) {
$root = $menu->getAttribute('script');
if(!$root) {
if($this->site) {
$root= $this->site->root_document ?: 'index.php';
}
else {
$root= 'index.php';
}
}
$type = $menu->getAttribute('type') === 'dynamic' ? 'dynamic' : 'static';
$service = $menu->getAttribute('service') ?: NULL;
$id = $menu->getAttribute('id') ?: NULL;
if($type === 'dynamic' && !$service) {
throw new ConfigException("A dynamic menu requires a configured service.");
}
$m = new Menu(
$root,
$id,
$type,
$service
);
if(($menuAuth = strtolower(trim($menu->getAttribute('auth'))))) {
$m->setAuth($menuAuth);
// if an auth level is defined, additional authentication parameters can be set
if(($authParameters = $menu->getAttribute('auth_parameters'))) {
$m->setAuthParameters($authParameters);
}
}
$this->appendMenuEntries($menu->childNodes, $m);
return $m;
} | [
"private",
"function",
"parseMenu",
"(",
"\\",
"DOMNode",
"$",
"menu",
")",
"{",
"$",
"root",
"=",
"$",
"menu",
"->",
"getAttribute",
"(",
"'script'",
")",
";",
"if",
"(",
"!",
"$",
"root",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"site",
")",
"{",
"$",
"root",
"=",
"$",
"this",
"->",
"site",
"->",
"root_document",
"?",
":",
"'index.php'",
";",
"}",
"else",
"{",
"$",
"root",
"=",
"'index.php'",
";",
"}",
"}",
"$",
"type",
"=",
"$",
"menu",
"->",
"getAttribute",
"(",
"'type'",
")",
"===",
"'dynamic'",
"?",
"'dynamic'",
":",
"'static'",
";",
"$",
"service",
"=",
"$",
"menu",
"->",
"getAttribute",
"(",
"'service'",
")",
"?",
":",
"NULL",
";",
"$",
"id",
"=",
"$",
"menu",
"->",
"getAttribute",
"(",
"'id'",
")",
"?",
":",
"NULL",
";",
"if",
"(",
"$",
"type",
"===",
"'dynamic'",
"&&",
"!",
"$",
"service",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"A dynamic menu requires a configured service.\"",
")",
";",
"}",
"$",
"m",
"=",
"new",
"Menu",
"(",
"$",
"root",
",",
"$",
"id",
",",
"$",
"type",
",",
"$",
"service",
")",
";",
"if",
"(",
"(",
"$",
"menuAuth",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"menu",
"->",
"getAttribute",
"(",
"'auth'",
")",
")",
")",
")",
")",
"{",
"$",
"m",
"->",
"setAuth",
"(",
"$",
"menuAuth",
")",
";",
"// if an auth level is defined, additional authentication parameters can be set",
"if",
"(",
"(",
"$",
"authParameters",
"=",
"$",
"menu",
"->",
"getAttribute",
"(",
"'auth_parameters'",
")",
")",
")",
"{",
"$",
"m",
"->",
"setAuthParameters",
"(",
"$",
"authParameters",
")",
";",
"}",
"}",
"$",
"this",
"->",
"appendMenuEntries",
"(",
"$",
"menu",
"->",
"childNodes",
",",
"$",
"m",
")",
";",
"return",
"$",
"m",
";",
"}"
] | Parse XML menu entries and creates menu instance
@param \DOMNode $menu
@return Menu
@throws ConfigException | [
"Parse",
"XML",
"menu",
"entries",
"and",
"creates",
"menu",
"instance"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L950-L994 |
Vectrex/vxPHP | src/Application/Config.php | Config.appendMenuEntries | private function appendMenuEntries(\DOMNodeList $entries, Menu $menu) {
foreach($entries as $entry) {
if($entry->nodeType !== XML_ELEMENT_NODE || 'menuentry' !== $entry->nodeName) {
continue;
}
// read additional attributes which are passed to menu entry constructor
$attributes = [];
foreach($entry->attributes as $attr) {
$nodeName = $attr->nodeName;
if(!in_array($nodeName, ['page', 'path', 'auth', 'auth_parameters'])) {
$attributes[$attr->nodeName] = $attr->nodeValue;
}
}
if('menuentry' === $entry->nodeName) {
$page = $entry->getAttribute('page');
$path = $entry->getAttribute('path');
if($page && $path) {
throw new ConfigException(sprintf("Menu entry with both page ('%s') and path ('%s') attribute found.", $page, $path));
}
// menu entry comes with a path attribute (which can also link an external resource)
if($path) {
$local = strpos($path, '/') !== 0 && !preg_match('~^[a-z]+://~', $path);
$e = new MenuEntry($path, $attributes, $local);
}
// menu entry comes with a page attribute, in this case the route path is used
else if($page) {
if(!isset($this->routes[$menu->getScript()][$page])) {
throw new ConfigException(sprintf(
"No route for menu entry ('%s') found. Available routes for script '%s' are '%s'.",
$page,
$menu->getScript(),
empty($this->routes[$menu->getScript()]) ? 'none' : implode("', '", array_keys($this->routes[$menu->getScript()]))
));
}
$e = new MenuEntry((string) $this->routes[$menu->getScript()][$page]->getPath(), $attributes, true);
}
// handle authentication settings of menu entry
if(($auth = strtolower(trim($entry->getAttribute('auth'))))) {
// set optional authentication level
$e->setAuth($auth);
// if auth level is defined, additional authentication parameters can be set
if(($authParameters = $entry->getAttribute('auth_parameters'))) {
$e->setAuthParameters($authParameters);
}
}
$menu->appendEntry($e);
$submenu = (new \DOMXPath($entry->ownerDocument))->query('menu', $entry);
if($submenu->length) {
$e->appendMenu($this->parseMenu($submenu->item(0)));
}
}
else if($entry->nodeName === 'menuentry_placeholder') {
$e = new DynamicMenuEntry(null, $attributes);
$menu->appendEntry($e);
}
}
} | php | private function appendMenuEntries(\DOMNodeList $entries, Menu $menu) {
foreach($entries as $entry) {
if($entry->nodeType !== XML_ELEMENT_NODE || 'menuentry' !== $entry->nodeName) {
continue;
}
// read additional attributes which are passed to menu entry constructor
$attributes = [];
foreach($entry->attributes as $attr) {
$nodeName = $attr->nodeName;
if(!in_array($nodeName, ['page', 'path', 'auth', 'auth_parameters'])) {
$attributes[$attr->nodeName] = $attr->nodeValue;
}
}
if('menuentry' === $entry->nodeName) {
$page = $entry->getAttribute('page');
$path = $entry->getAttribute('path');
if($page && $path) {
throw new ConfigException(sprintf("Menu entry with both page ('%s') and path ('%s') attribute found.", $page, $path));
}
// menu entry comes with a path attribute (which can also link an external resource)
if($path) {
$local = strpos($path, '/') !== 0 && !preg_match('~^[a-z]+://~', $path);
$e = new MenuEntry($path, $attributes, $local);
}
// menu entry comes with a page attribute, in this case the route path is used
else if($page) {
if(!isset($this->routes[$menu->getScript()][$page])) {
throw new ConfigException(sprintf(
"No route for menu entry ('%s') found. Available routes for script '%s' are '%s'.",
$page,
$menu->getScript(),
empty($this->routes[$menu->getScript()]) ? 'none' : implode("', '", array_keys($this->routes[$menu->getScript()]))
));
}
$e = new MenuEntry((string) $this->routes[$menu->getScript()][$page]->getPath(), $attributes, true);
}
// handle authentication settings of menu entry
if(($auth = strtolower(trim($entry->getAttribute('auth'))))) {
// set optional authentication level
$e->setAuth($auth);
// if auth level is defined, additional authentication parameters can be set
if(($authParameters = $entry->getAttribute('auth_parameters'))) {
$e->setAuthParameters($authParameters);
}
}
$menu->appendEntry($e);
$submenu = (new \DOMXPath($entry->ownerDocument))->query('menu', $entry);
if($submenu->length) {
$e->appendMenu($this->parseMenu($submenu->item(0)));
}
}
else if($entry->nodeName === 'menuentry_placeholder') {
$e = new DynamicMenuEntry(null, $attributes);
$menu->appendEntry($e);
}
}
} | [
"private",
"function",
"appendMenuEntries",
"(",
"\\",
"DOMNodeList",
"$",
"entries",
",",
"Menu",
"$",
"menu",
")",
"{",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"entry",
"->",
"nodeType",
"!==",
"XML_ELEMENT_NODE",
"||",
"'menuentry'",
"!==",
"$",
"entry",
"->",
"nodeName",
")",
"{",
"continue",
";",
"}",
"// read additional attributes which are passed to menu entry constructor",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entry",
"->",
"attributes",
"as",
"$",
"attr",
")",
"{",
"$",
"nodeName",
"=",
"$",
"attr",
"->",
"nodeName",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"nodeName",
",",
"[",
"'page'",
",",
"'path'",
",",
"'auth'",
",",
"'auth_parameters'",
"]",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"attr",
"->",
"nodeName",
"]",
"=",
"$",
"attr",
"->",
"nodeValue",
";",
"}",
"}",
"if",
"(",
"'menuentry'",
"===",
"$",
"entry",
"->",
"nodeName",
")",
"{",
"$",
"page",
"=",
"$",
"entry",
"->",
"getAttribute",
"(",
"'page'",
")",
";",
"$",
"path",
"=",
"$",
"entry",
"->",
"getAttribute",
"(",
"'path'",
")",
";",
"if",
"(",
"$",
"page",
"&&",
"$",
"path",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"Menu entry with both page ('%s') and path ('%s') attribute found.\"",
",",
"$",
"page",
",",
"$",
"path",
")",
")",
";",
"}",
"// menu entry comes with a path attribute (which can also link an external resource)",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"local",
"=",
"strpos",
"(",
"$",
"path",
",",
"'/'",
")",
"!==",
"0",
"&&",
"!",
"preg_match",
"(",
"'~^[a-z]+://~'",
",",
"$",
"path",
")",
";",
"$",
"e",
"=",
"new",
"MenuEntry",
"(",
"$",
"path",
",",
"$",
"attributes",
",",
"$",
"local",
")",
";",
"}",
"// menu entry comes with a page attribute, in this case the route path is used",
"else",
"if",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"menu",
"->",
"getScript",
"(",
")",
"]",
"[",
"$",
"page",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"sprintf",
"(",
"\"No route for menu entry ('%s') found. Available routes for script '%s' are '%s'.\"",
",",
"$",
"page",
",",
"$",
"menu",
"->",
"getScript",
"(",
")",
",",
"empty",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"menu",
"->",
"getScript",
"(",
")",
"]",
")",
"?",
"'none'",
":",
"implode",
"(",
"\"', '\"",
",",
"array_keys",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"menu",
"->",
"getScript",
"(",
")",
"]",
")",
")",
")",
")",
";",
"}",
"$",
"e",
"=",
"new",
"MenuEntry",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"routes",
"[",
"$",
"menu",
"->",
"getScript",
"(",
")",
"]",
"[",
"$",
"page",
"]",
"->",
"getPath",
"(",
")",
",",
"$",
"attributes",
",",
"true",
")",
";",
"}",
"// handle authentication settings of menu entry",
"if",
"(",
"(",
"$",
"auth",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"entry",
"->",
"getAttribute",
"(",
"'auth'",
")",
")",
")",
")",
")",
"{",
"// set optional authentication level",
"$",
"e",
"->",
"setAuth",
"(",
"$",
"auth",
")",
";",
"// if auth level is defined, additional authentication parameters can be set",
"if",
"(",
"(",
"$",
"authParameters",
"=",
"$",
"entry",
"->",
"getAttribute",
"(",
"'auth_parameters'",
")",
")",
")",
"{",
"$",
"e",
"->",
"setAuthParameters",
"(",
"$",
"authParameters",
")",
";",
"}",
"}",
"$",
"menu",
"->",
"appendEntry",
"(",
"$",
"e",
")",
";",
"$",
"submenu",
"=",
"(",
"new",
"\\",
"DOMXPath",
"(",
"$",
"entry",
"->",
"ownerDocument",
")",
")",
"->",
"query",
"(",
"'menu'",
",",
"$",
"entry",
")",
";",
"if",
"(",
"$",
"submenu",
"->",
"length",
")",
"{",
"$",
"e",
"->",
"appendMenu",
"(",
"$",
"this",
"->",
"parseMenu",
"(",
"$",
"submenu",
"->",
"item",
"(",
"0",
")",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"entry",
"->",
"nodeName",
"===",
"'menuentry_placeholder'",
")",
"{",
"$",
"e",
"=",
"new",
"DynamicMenuEntry",
"(",
"null",
",",
"$",
"attributes",
")",
";",
"$",
"menu",
"->",
"appendEntry",
"(",
"$",
"e",
")",
";",
"}",
"}",
"}"
] | append menu entries of configuration to a
previously created Menu instance
@param \DOMNodeList $entries
@param Menu $menu
@throws ConfigException | [
"append",
"menu",
"entries",
"of",
"configuration",
"to",
"a",
"previously",
"created",
"Menu",
"instance"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L1004-L1099 |
Vectrex/vxPHP | src/Application/Config.php | Config.createConst | public function createConst() {
$properties = get_object_vars($this);
if(isset($properties['db'])) {
foreach($properties['db'] as $k => $v) {
if(is_scalar($v)) {
$k = strtoupper($k);
if(!defined("DB$k")) { define("DB$k", $v); }
}
}
}
if(isset($properties['site'])) {
foreach($properties['site'] as $k => $v) {
if(is_scalar($v)) {
$k = strtoupper($k);
if(!defined($k)) { define($k, $v); }
}
}
}
if(isset($properties['paths'])) {
foreach($properties['paths'] as $k => $v) {
$k = strtoupper($k);
if(!defined($k)) { define($k, $v['subdir']); }
}
}
$locale = localeconv();
foreach($locale as $k => $v) {
$k = strtoupper($k);
if(!defined($k) && !is_array($v)) { define($k, $v); }
}
} | php | public function createConst() {
$properties = get_object_vars($this);
if(isset($properties['db'])) {
foreach($properties['db'] as $k => $v) {
if(is_scalar($v)) {
$k = strtoupper($k);
if(!defined("DB$k")) { define("DB$k", $v); }
}
}
}
if(isset($properties['site'])) {
foreach($properties['site'] as $k => $v) {
if(is_scalar($v)) {
$k = strtoupper($k);
if(!defined($k)) { define($k, $v); }
}
}
}
if(isset($properties['paths'])) {
foreach($properties['paths'] as $k => $v) {
$k = strtoupper($k);
if(!defined($k)) { define($k, $v['subdir']); }
}
}
$locale = localeconv();
foreach($locale as $k => $v) {
$k = strtoupper($k);
if(!defined($k) && !is_array($v)) { define($k, $v); }
}
} | [
"public",
"function",
"createConst",
"(",
")",
"{",
"$",
"properties",
"=",
"get_object_vars",
"(",
"$",
"this",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"'db'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"properties",
"[",
"'db'",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"v",
")",
")",
"{",
"$",
"k",
"=",
"strtoupper",
"(",
"$",
"k",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"\"DB$k\"",
")",
")",
"{",
"define",
"(",
"\"DB$k\"",
",",
"$",
"v",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"'site'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"properties",
"[",
"'site'",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"v",
")",
")",
"{",
"$",
"k",
"=",
"strtoupper",
"(",
"$",
"k",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"$",
"k",
")",
")",
"{",
"define",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"'paths'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"properties",
"[",
"'paths'",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"k",
"=",
"strtoupper",
"(",
"$",
"k",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"$",
"k",
")",
")",
"{",
"define",
"(",
"$",
"k",
",",
"$",
"v",
"[",
"'subdir'",
"]",
")",
";",
"}",
"}",
"}",
"$",
"locale",
"=",
"localeconv",
"(",
")",
";",
"foreach",
"(",
"$",
"locale",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"k",
"=",
"strtoupper",
"(",
"$",
"k",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"$",
"k",
")",
"&&",
"!",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"define",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"}",
"}"
] | create constants for simple access to certain configuration settings | [
"create",
"constants",
"for",
"simple",
"access",
"to",
"certain",
"configuration",
"settings"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L1105-L1140 |
Vectrex/vxPHP | src/Application/Config.php | Config.getPaths | public function getPaths($access = 'rw') {
$paths = [];
foreach($this->paths as $p) {
if($p['access'] === $access) {
array_push($paths, $p);
}
}
return $paths;
} | php | public function getPaths($access = 'rw') {
$paths = [];
foreach($this->paths as $p) {
if($p['access'] === $access) {
array_push($paths, $p);
}
}
return $paths;
} | [
"public",
"function",
"getPaths",
"(",
"$",
"access",
"=",
"'rw'",
")",
"{",
"$",
"paths",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"paths",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"$",
"p",
"[",
"'access'",
"]",
"===",
"$",
"access",
")",
"{",
"array_push",
"(",
"$",
"paths",
",",
"$",
"p",
")",
";",
"}",
"}",
"return",
"$",
"paths",
";",
"}"
] | returns all paths matching access criteria
@param string $access
@return paths | [
"returns",
"all",
"paths",
"matching",
"access",
"criteria"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L1148-L1156 |
Vectrex/vxPHP | src/Application/Config.php | Config.getServerConfig | private function getServerConfig() {
$this->server['apc_on'] = extension_loaded('apc') && function_exists('apc_add') && ini_get('apc.enabled') && ini_get('apc.rfc1867');
$fs = ini_get('upload_max_filesize');
$suffix = strtoupper(substr($fs, -1));
switch($suffix) {
case 'K':
$mult = 1024; break;
case 'M':
$mult = 1024*1024; break;
case 'G':
$mult = 1024*1024*1024; break;
default:
$mult = 0;
}
$this->server['max_upload_filesize'] = $mult ? (float) (substr($fs, 0, -1)) * $mult : (int) $fs;
} | php | private function getServerConfig() {
$this->server['apc_on'] = extension_loaded('apc') && function_exists('apc_add') && ini_get('apc.enabled') && ini_get('apc.rfc1867');
$fs = ini_get('upload_max_filesize');
$suffix = strtoupper(substr($fs, -1));
switch($suffix) {
case 'K':
$mult = 1024; break;
case 'M':
$mult = 1024*1024; break;
case 'G':
$mult = 1024*1024*1024; break;
default:
$mult = 0;
}
$this->server['max_upload_filesize'] = $mult ? (float) (substr($fs, 0, -1)) * $mult : (int) $fs;
} | [
"private",
"function",
"getServerConfig",
"(",
")",
"{",
"$",
"this",
"->",
"server",
"[",
"'apc_on'",
"]",
"=",
"extension_loaded",
"(",
"'apc'",
")",
"&&",
"function_exists",
"(",
"'apc_add'",
")",
"&&",
"ini_get",
"(",
"'apc.enabled'",
")",
"&&",
"ini_get",
"(",
"'apc.rfc1867'",
")",
";",
"$",
"fs",
"=",
"ini_get",
"(",
"'upload_max_filesize'",
")",
";",
"$",
"suffix",
"=",
"strtoupper",
"(",
"substr",
"(",
"$",
"fs",
",",
"-",
"1",
")",
")",
";",
"switch",
"(",
"$",
"suffix",
")",
"{",
"case",
"'K'",
":",
"$",
"mult",
"=",
"1024",
";",
"break",
";",
"case",
"'M'",
":",
"$",
"mult",
"=",
"1024",
"*",
"1024",
";",
"break",
";",
"case",
"'G'",
":",
"$",
"mult",
"=",
"1024",
"*",
"1024",
"*",
"1024",
";",
"break",
";",
"default",
":",
"$",
"mult",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"server",
"[",
"'max_upload_filesize'",
"]",
"=",
"$",
"mult",
"?",
"(",
"float",
")",
"(",
"substr",
"(",
"$",
"fs",
",",
"0",
",",
"-",
"1",
")",
")",
"*",
"$",
"mult",
":",
"(",
"int",
")",
"$",
"fs",
";",
"}"
] | add particular information regarding server configuration, like PHP extensions | [
"add",
"particular",
"information",
"regarding",
"server",
"configuration",
"like",
"PHP",
"extensions"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Application/Config.php#L1161-L1180 |
Raphhh/puppy-application | src/Application.php | Application.run | public function run()
{
$request = $this->getService('requestStack')->getMasterRequest();
$this->getPreProcesses()->execute($request);
$response = $this->getFrontController()->call($request);
$this->getPostProcesses()->execute($response);
$response->send();
} | php | public function run()
{
$request = $this->getService('requestStack')->getMasterRequest();
$this->getPreProcesses()->execute($request);
$response = $this->getFrontController()->call($request);
$this->getPostProcesses()->execute($response);
$response->send();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getService",
"(",
"'requestStack'",
")",
"->",
"getMasterRequest",
"(",
")",
";",
"$",
"this",
"->",
"getPreProcesses",
"(",
")",
"->",
"execute",
"(",
"$",
"request",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getFrontController",
"(",
")",
"->",
"call",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"getPostProcesses",
"(",
")",
"->",
"execute",
"(",
"$",
"response",
")",
";",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}"
] | Sends the http response | [
"Sends",
"the",
"http",
"response"
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L62-L69 |
Raphhh/puppy-application | src/Application.php | Application.initModules | public function initModules(IModulesLoader $modulesLoader)
{
foreach ($modulesLoader->getModules() as $module) {
$this->addModule($module);
}
} | php | public function initModules(IModulesLoader $modulesLoader)
{
foreach ($modulesLoader->getModules() as $module) {
$this->addModule($module);
}
} | [
"public",
"function",
"initModules",
"(",
"IModulesLoader",
"$",
"modulesLoader",
")",
"{",
"foreach",
"(",
"$",
"modulesLoader",
"->",
"getModules",
"(",
")",
"as",
"$",
"module",
")",
"{",
"$",
"this",
"->",
"addModule",
"(",
"$",
"module",
")",
";",
"}",
"}"
] | Init the modules of the current project.
@param IModulesLoader $modulesLoader | [
"Init",
"the",
"modules",
"of",
"the",
"current",
"project",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L76-L81 |
Raphhh/puppy-application | src/Application.php | Application.get | public function get($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller, 'get')->getPattern()
);
} | php | public function get($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller, 'get')->getPattern()
);
} | [
"public",
"function",
"get",
"(",
"$",
"uriPattern",
",",
"callable",
"$",
"controller",
")",
"{",
"return",
"new",
"IRoutePatternSetterAdapter",
"(",
"$",
"this",
"->",
"getFrontController",
"(",
")",
"->",
"addController",
"(",
"$",
"uriPattern",
",",
"$",
"controller",
",",
"'get'",
")",
"->",
"getPattern",
"(",
")",
")",
";",
"}"
] | Adds a controller called by http GET method.
@param string $uriPattern
@param callable $controller
@return IRoutePatternSetter | [
"Adds",
"a",
"controller",
"called",
"by",
"http",
"GET",
"method",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L101-L106 |
Raphhh/puppy-application | src/Application.php | Application.post | public function post($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller, 'post')->getPattern()
);
} | php | public function post($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller, 'post')->getPattern()
);
} | [
"public",
"function",
"post",
"(",
"$",
"uriPattern",
",",
"callable",
"$",
"controller",
")",
"{",
"return",
"new",
"IRoutePatternSetterAdapter",
"(",
"$",
"this",
"->",
"getFrontController",
"(",
")",
"->",
"addController",
"(",
"$",
"uriPattern",
",",
"$",
"controller",
",",
"'post'",
")",
"->",
"getPattern",
"(",
")",
")",
";",
"}"
] | Adds a controller called by http POST method.
@param string $uriPattern
@param callable $controller
@return IRoutePatternSetter | [
"Adds",
"a",
"controller",
"called",
"by",
"http",
"POST",
"method",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L115-L120 |
Raphhh/puppy-application | src/Application.php | Application.json | public function json($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller, '', 'application/json')->getPattern()
);
} | php | public function json($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller, '', 'application/json')->getPattern()
);
} | [
"public",
"function",
"json",
"(",
"$",
"uriPattern",
",",
"callable",
"$",
"controller",
")",
"{",
"return",
"new",
"IRoutePatternSetterAdapter",
"(",
"$",
"this",
"->",
"getFrontController",
"(",
")",
"->",
"addController",
"(",
"$",
"uriPattern",
",",
"$",
"controller",
",",
"''",
",",
"'application/json'",
")",
"->",
"getPattern",
"(",
")",
")",
";",
"}"
] | Adds a controller with a json format.
@param string $uriPattern
@param callable $controller
@return IRoutePatternSetter | [
"Adds",
"a",
"controller",
"with",
"a",
"json",
"format",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L129-L134 |
Raphhh/puppy-application | src/Application.php | Application.any | public function any($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller)->getPattern()
);
} | php | public function any($uriPattern, callable $controller)
{
return new IRoutePatternSetterAdapter(
$this->getFrontController()->addController($uriPattern, $controller)->getPattern()
);
} | [
"public",
"function",
"any",
"(",
"$",
"uriPattern",
",",
"callable",
"$",
"controller",
")",
"{",
"return",
"new",
"IRoutePatternSetterAdapter",
"(",
"$",
"this",
"->",
"getFrontController",
"(",
")",
"->",
"addController",
"(",
"$",
"uriPattern",
",",
"$",
"controller",
")",
"->",
"getPattern",
"(",
")",
")",
";",
"}"
] | Adds a controller called by any http method or format.
@param string $uriPattern
@param callable $controller
@return IRoutePatternSetter | [
"Adds",
"a",
"controller",
"called",
"by",
"any",
"http",
"method",
"or",
"format",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L143-L148 |
Raphhh/puppy-application | src/Application.php | Application.filter | public function filter(callable $filter, callable $controller)
{
$pattern = $this->getFrontController()->addController(':all', $controller)->getPattern();
$pattern->addFilter($filter);
return new IRoutePatternSetterAdapter($pattern);
} | php | public function filter(callable $filter, callable $controller)
{
$pattern = $this->getFrontController()->addController(':all', $controller)->getPattern();
$pattern->addFilter($filter);
return new IRoutePatternSetterAdapter($pattern);
} | [
"public",
"function",
"filter",
"(",
"callable",
"$",
"filter",
",",
"callable",
"$",
"controller",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"getFrontController",
"(",
")",
"->",
"addController",
"(",
"':all'",
",",
"$",
"controller",
")",
"->",
"getPattern",
"(",
")",
";",
"$",
"pattern",
"->",
"addFilter",
"(",
"$",
"filter",
")",
";",
"return",
"new",
"IRoutePatternSetterAdapter",
"(",
"$",
"pattern",
")",
";",
"}"
] | Adds a controller with a special filter.
This filter receive the current Request as first param.
@param callable $filter
@param callable $controller
@return IRoutePatternSetter | [
"Adds",
"a",
"controller",
"with",
"a",
"special",
"filter",
".",
"This",
"filter",
"receive",
"the",
"current",
"Request",
"as",
"first",
"param",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L158-L163 |
Raphhh/puppy-application | src/Application.php | Application.mirror | public function mirror($uriPattern, $mirror)
{
return $this->any(
$uriPattern,
function (AppController $appController, array $args) use ($mirror) {
return $appController->call($mirror, $args);
}
);
} | php | public function mirror($uriPattern, $mirror)
{
return $this->any(
$uriPattern,
function (AppController $appController, array $args) use ($mirror) {
return $appController->call($mirror, $args);
}
);
} | [
"public",
"function",
"mirror",
"(",
"$",
"uriPattern",
",",
"$",
"mirror",
")",
"{",
"return",
"$",
"this",
"->",
"any",
"(",
"$",
"uriPattern",
",",
"function",
"(",
"AppController",
"$",
"appController",
",",
"array",
"$",
"args",
")",
"use",
"(",
"$",
"mirror",
")",
"{",
"return",
"$",
"appController",
"->",
"call",
"(",
"$",
"mirror",
",",
"$",
"args",
")",
";",
"}",
")",
";",
"}"
] | Adds a mirror of a route.
@param string $uriPattern
@param string $mirror
@return IRoutePatternSetterAdapter | [
"Adds",
"a",
"mirror",
"of",
"a",
"route",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L183-L191 |
Raphhh/puppy-application | src/Application.php | Application.before | public function before(callable $process)
{
if ($process instanceof \Closure) {
$process = \Closure::bind($process, $this);
}
$this->preProcesses[] = $process;
} | php | public function before(callable $process)
{
if ($process instanceof \Closure) {
$process = \Closure::bind($process, $this);
}
$this->preProcesses[] = $process;
} | [
"public",
"function",
"before",
"(",
"callable",
"$",
"process",
")",
"{",
"if",
"(",
"$",
"process",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"process",
"=",
"\\",
"Closure",
"::",
"bind",
"(",
"$",
"process",
",",
"$",
"this",
")",
";",
"}",
"$",
"this",
"->",
"preProcesses",
"[",
"]",
"=",
"$",
"process",
";",
"}"
] | adds a process before the call stack.
$process will receive the master request as first arg.
@param callable $process | [
"adds",
"a",
"process",
"before",
"the",
"call",
"stack",
".",
"$process",
"will",
"receive",
"the",
"master",
"request",
"as",
"first",
"arg",
"."
] | train | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Application.php#L199-L205 |
AnonymPHP/Anonym-Database | Mode/ModeManager.php | ModeManager.getQuery | public function getQuery()
{
$strings = $this->string;
$query = $this->buildQuery($this->getPattern($this->getChieldPattern()), $strings);
return $query;
} | php | public function getQuery()
{
$strings = $this->string;
$query = $this->buildQuery($this->getPattern($this->getChieldPattern()), $strings);
return $query;
} | [
"public",
"function",
"getQuery",
"(",
")",
"{",
"$",
"strings",
"=",
"$",
"this",
"->",
"string",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"buildQuery",
"(",
"$",
"this",
"->",
"getPattern",
"(",
"$",
"this",
"->",
"getChieldPattern",
"(",
")",
")",
",",
"$",
"strings",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Yeni bir query Sorgusu olu�turur
@return \Anonym\Components\Database\Builders\BuildManager | [
"Yeni",
"bir",
"query",
"Sorgusu",
"olu�turur"
] | train | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Mode/ModeManager.php#L126-L133 |
AnonymPHP/Anonym-Database | Mode/ModeManager.php | ModeManager.build | public function build()
{
$query = $this->getQuery();
$manager = new BuildManager($this->getBase()->getConnection());
$manager->setPage($this->page);
$manager->setQuery($query);
$manager->setParams($this->string['parameters']);
return $manager;
} | php | public function build()
{
$query = $this->getQuery();
$manager = new BuildManager($this->getBase()->getConnection());
$manager->setPage($this->page);
$manager->setQuery($query);
$manager->setParams($this->string['parameters']);
return $manager;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getQuery",
"(",
")",
";",
"$",
"manager",
"=",
"new",
"BuildManager",
"(",
"$",
"this",
"->",
"getBase",
"(",
")",
"->",
"getConnection",
"(",
")",
")",
";",
"$",
"manager",
"->",
"setPage",
"(",
"$",
"this",
"->",
"page",
")",
";",
"$",
"manager",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"$",
"manager",
"->",
"setParams",
"(",
"$",
"this",
"->",
"string",
"[",
"'parameters'",
"]",
")",
";",
"return",
"$",
"manager",
";",
"}"
] | Sorguyu buildManager ��ine atar
@return \Anonym\Components\Database\Builders\BuildManager | [
"Sorguyu",
"buildManager",
"��ine",
"atar"
] | train | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Mode/ModeManager.php#L140-L150 |
AnonymPHP/Anonym-Database | Mode/ModeManager.php | ModeManager.doWhere | private function doWhere($where, $type)
{
switch ($type) {
case 'and':
$where = $this->useBuilder('where')
->where($where, $this->getCield());
break;
case 'or':
$where = $this->useBuilder('where')
->orWhere($where, $this->getCield());
break;
}
$this->string['where'] = $where['content'];
$this->string['parameters'] = array_merge($this->string['parameters'], $where['array']);
} | php | private function doWhere($where, $type)
{
switch ($type) {
case 'and':
$where = $this->useBuilder('where')
->where($where, $this->getCield());
break;
case 'or':
$where = $this->useBuilder('where')
->orWhere($where, $this->getCield());
break;
}
$this->string['where'] = $where['content'];
$this->string['parameters'] = array_merge($this->string['parameters'], $where['array']);
} | [
"private",
"function",
"doWhere",
"(",
"$",
"where",
",",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'and'",
":",
"$",
"where",
"=",
"$",
"this",
"->",
"useBuilder",
"(",
"'where'",
")",
"->",
"where",
"(",
"$",
"where",
",",
"$",
"this",
"->",
"getCield",
"(",
")",
")",
";",
"break",
";",
"case",
"'or'",
":",
"$",
"where",
"=",
"$",
"this",
"->",
"useBuilder",
"(",
"'where'",
")",
"->",
"orWhere",
"(",
"$",
"where",
",",
"$",
"this",
"->",
"getCield",
"(",
")",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"string",
"[",
"'where'",
"]",
"=",
"$",
"where",
"[",
"'content'",
"]",
";",
"$",
"this",
"->",
"string",
"[",
"'parameters'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"string",
"[",
"'parameters'",
"]",
",",
"$",
"where",
"[",
"'array'",
"]",
")",
";",
"}"
] | Where tetiklenir
@param mixed $args
@param string $type | [
"Where",
"tetiklenir"
] | train | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Mode/ModeManager.php#L245-L267 |
AnonymPHP/Anonym-Database | Mode/ModeManager.php | ModeManager.where | public function where($where, $controll = null)
{
if (!is_array($where) && !is_null($controll)) {
$where = [
[$where, '=', $controll]
];
} elseif (is_array($where) && isset($where[0]) && isset($where[1])) {
if (is_string($where[1])) {
$where = [
[$where[0], $where[1], $where[2]]
];
}
}
$this->doWhere($where, 'and');
return $this;
} | php | public function where($where, $controll = null)
{
if (!is_array($where) && !is_null($controll)) {
$where = [
[$where, '=', $controll]
];
} elseif (is_array($where) && isset($where[0]) && isset($where[1])) {
if (is_string($where[1])) {
$where = [
[$where[0], $where[1], $where[2]]
];
}
}
$this->doWhere($where, 'and');
return $this;
} | [
"public",
"function",
"where",
"(",
"$",
"where",
",",
"$",
"controll",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"where",
")",
"&&",
"!",
"is_null",
"(",
"$",
"controll",
")",
")",
"{",
"$",
"where",
"=",
"[",
"[",
"$",
"where",
",",
"'='",
",",
"$",
"controll",
"]",
"]",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"where",
")",
"&&",
"isset",
"(",
"$",
"where",
"[",
"0",
"]",
")",
"&&",
"isset",
"(",
"$",
"where",
"[",
"1",
"]",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"where",
"[",
"1",
"]",
")",
")",
"{",
"$",
"where",
"=",
"[",
"[",
"$",
"where",
"[",
"0",
"]",
",",
"$",
"where",
"[",
"1",
"]",
",",
"$",
"where",
"[",
"2",
"]",
"]",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"doWhere",
"(",
"$",
"where",
",",
"'and'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Where sorgusu
@param mixed $where
@param null controll
@return $this | [
"Where",
"sorgusu"
] | train | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Mode/ModeManager.php#L276-L297 |
AnonymPHP/Anonym-Database | Mode/ModeManager.php | ModeManager.pagination | public function pagination($perPage = 15)
{
$currentPageFinder = Paginator::getCurrentPageFinder();
$pathFinder = Paginator::getRequestPathFinder();
$pagination = new Paginator($perPage, call_user_func($currentPageFinder), [
'pageName' => 'page',
'path' => call_user_func($pathFinder),
]);
$pagination->setMode(Paginator::MODE_STANDART);
$count = $this->build()->rowCount();
$pagination->count($count);
return $pagination;
} | php | public function pagination($perPage = 15)
{
$currentPageFinder = Paginator::getCurrentPageFinder();
$pathFinder = Paginator::getRequestPathFinder();
$pagination = new Paginator($perPage, call_user_func($currentPageFinder), [
'pageName' => 'page',
'path' => call_user_func($pathFinder),
]);
$pagination->setMode(Paginator::MODE_STANDART);
$count = $this->build()->rowCount();
$pagination->count($count);
return $pagination;
} | [
"public",
"function",
"pagination",
"(",
"$",
"perPage",
"=",
"15",
")",
"{",
"$",
"currentPageFinder",
"=",
"Paginator",
"::",
"getCurrentPageFinder",
"(",
")",
";",
"$",
"pathFinder",
"=",
"Paginator",
"::",
"getRequestPathFinder",
"(",
")",
";",
"$",
"pagination",
"=",
"new",
"Paginator",
"(",
"$",
"perPage",
",",
"call_user_func",
"(",
"$",
"currentPageFinder",
")",
",",
"[",
"'pageName'",
"=>",
"'page'",
",",
"'path'",
"=>",
"call_user_func",
"(",
"$",
"pathFinder",
")",
",",
"]",
")",
";",
"$",
"pagination",
"->",
"setMode",
"(",
"Paginator",
"::",
"MODE_STANDART",
")",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"build",
"(",
")",
"->",
"rowCount",
"(",
")",
";",
"$",
"pagination",
"->",
"count",
"(",
"$",
"count",
")",
";",
"return",
"$",
"pagination",
";",
"}"
] | create a instance for standart pagination
@param int $perPage
@return Paginator | [
"create",
"a",
"instance",
"for",
"standart",
"pagination"
] | train | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Mode/ModeManager.php#L305-L323 |
AnonymPHP/Anonym-Database | Mode/ModeManager.php | ModeManager.simplePagination | public function simplePagination($perPage = 15){
$pegination = $this->pagination($perPage);
$pegination->setMode(Paginator::MODE_SIMPLE);
return $pegination;
} | php | public function simplePagination($perPage = 15){
$pegination = $this->pagination($perPage);
$pegination->setMode(Paginator::MODE_SIMPLE);
return $pegination;
} | [
"public",
"function",
"simplePagination",
"(",
"$",
"perPage",
"=",
"15",
")",
"{",
"$",
"pegination",
"=",
"$",
"this",
"->",
"pagination",
"(",
"$",
"perPage",
")",
";",
"$",
"pegination",
"->",
"setMode",
"(",
"Paginator",
"::",
"MODE_SIMPLE",
")",
";",
"return",
"$",
"pegination",
";",
"}"
] | create a paginaton instance and return it
@param int $perPage
@return Paginator | [
"create",
"a",
"paginaton",
"instance",
"and",
"return",
"it"
] | train | https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Mode/ModeManager.php#L332-L337 |
zineinc/floppy-client | src/Floppy/Client/FileTypeGuesser.php | FileTypeGuesser.guessFileType | public function guessFileType(FileId $fileId)
{
$extension = strtolower(\pathinfo($fileId->id(), PATHINFO_EXTENSION));
foreach($this->fileTypeExtensions as $fileType => $extensions) {
if(in_array($extension, $extensions)) {
return $fileType;
}
}
return 'file';
} | php | public function guessFileType(FileId $fileId)
{
$extension = strtolower(\pathinfo($fileId->id(), PATHINFO_EXTENSION));
foreach($this->fileTypeExtensions as $fileType => $extensions) {
if(in_array($extension, $extensions)) {
return $fileType;
}
}
return 'file';
} | [
"public",
"function",
"guessFileType",
"(",
"FileId",
"$",
"fileId",
")",
"{",
"$",
"extension",
"=",
"strtolower",
"(",
"\\",
"pathinfo",
"(",
"$",
"fileId",
"->",
"id",
"(",
")",
",",
"PATHINFO_EXTENSION",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fileTypeExtensions",
"as",
"$",
"fileType",
"=>",
"$",
"extensions",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"extension",
",",
"$",
"extensions",
")",
")",
"{",
"return",
"$",
"fileType",
";",
"}",
"}",
"return",
"'file'",
";",
"}"
] | Guess file type code
@param FileId $fileId
@return string | [
"Guess",
"file",
"type",
"code"
] | train | https://github.com/zineinc/floppy-client/blob/24a4e72756ef88de561d08d71090bcf4c00be845/src/Floppy/Client/FileTypeGuesser.php#L23-L34 |
werx/core | src/Input.php | Input.post | public function post($key = null, $default = null, $deep = true)
{
if (!empty($key)) {
return $this->request->request->get($key, $default, $deep);
} else {
return $this->request->request->all();
}
} | php | public function post($key = null, $default = null, $deep = true)
{
if (!empty($key)) {
return $this->request->request->get($key, $default, $deep);
} else {
return $this->request->request->all();
}
} | [
"public",
"function",
"post",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
",",
"$",
"deep",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"request",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"default",
",",
"$",
"deep",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"}",
"}"
] | Fetch items from the $_POST array.
@param null $key
@param null $default
@param bool $deep
@return array|mixed | [
"Fetch",
"items",
"from",
"the",
"$_POST",
"array",
"."
] | train | https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Input.php#L31-L38 |
Subsets and Splits