├── README.md ├── src ├── command │ ├── stubs │ │ └── controller.stub │ ├── Clear.php │ └── Build.php ├── Service.php ├── MultiApp.php └── Url.php ├── composer.json └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # think-multi-app 2 | 3 | 用于ThinkPHP6+的多应用支持 4 | 5 | ## 安装 6 | 7 | ~~~ 8 | composer require topthink/think-multi-app 9 | ~~~ 10 | 11 | ## 使用 12 | 13 | 用法参考ThinkPHP6完全开发手册[多应用模式](https://www.kancloud.cn/manual/thinkphp6_0/1297876)章节。 14 | 15 | -------------------------------------------------------------------------------- /src/command/stubs/controller.stub: -------------------------------------------------------------------------------- 1 | =7.1.0", 13 | "topthink/framework": "^6.0|^8.0" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "think\\app\\": "src" 18 | } 19 | }, 20 | "extra": { 21 | "think":{ 22 | "services":[ 23 | "think\\app\\Service" 24 | ] 25 | } 26 | }, 27 | "minimum-stability": "dev" 28 | } 29 | -------------------------------------------------------------------------------- /src/Service.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\app; 12 | 13 | use think\Service as BaseService; 14 | 15 | class Service extends BaseService 16 | { 17 | public function boot() 18 | { 19 | $this->app->event->listen('HttpRun', function () { 20 | $this->app->middleware->add(MultiApp::class); 21 | }); 22 | 23 | $this->commands([ 24 | 'build' => command\Build::class, 25 | 'clear' => command\Clear::class, 26 | ]); 27 | 28 | $this->app->bind([ 29 | 'think\route\Url' => Url::class, 30 | ]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/command/Clear.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\app\command; 12 | 13 | use think\console\Command; 14 | use think\console\Input; 15 | use think\console\input\Argument; 16 | use think\console\input\Option; 17 | use think\console\Output; 18 | 19 | class Clear extends Command 20 | { 21 | protected function configure() 22 | { 23 | // 指令配置 24 | $this->setName('clear') 25 | ->addArgument('app', Argument::OPTIONAL, 'app name .') 26 | ->addOption('cache', 'c', Option::VALUE_NONE, 'clear cache file') 27 | ->addOption('log', 'l', Option::VALUE_NONE, 'clear log file') 28 | ->addOption('dir', 'r', Option::VALUE_NONE, 'clear empty dir') 29 | ->setDescription('Clear runtime file'); 30 | } 31 | 32 | protected function execute(Input $input, Output $output) 33 | { 34 | $app = $input->getArgument('app') ?: ''; 35 | $runtimePath = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . ($app ? $app . DIRECTORY_SEPARATOR : ''); 36 | 37 | if ($input->getOption('cache')) { 38 | $path = $runtimePath . 'cache'; 39 | } elseif ($input->getOption('log')) { 40 | $path = $runtimePath . 'log'; 41 | } else { 42 | $path = $runtimePath; 43 | } 44 | 45 | $rmdir = $input->getOption('dir') ? true : false; 46 | $this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir); 47 | 48 | $output->writeln("Clear Successed"); 49 | } 50 | 51 | protected function clear(string $path, bool $rmdir): void 52 | { 53 | $files = is_dir($path) ? scandir($path) : []; 54 | 55 | foreach ($files as $file) { 56 | if ('.' != $file && '..' != $file && is_dir($path . $file)) { 57 | array_map('unlink', glob($path . $file . DIRECTORY_SEPARATOR . '*.*')); 58 | if ($rmdir) { 59 | rmdir($path . $file); 60 | } 61 | } elseif ('.gitignore' != $file && is_file($path . $file)) { 62 | unlink($path . $file); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/command/Build.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\app\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Argument; 17 | use think\console\Output; 18 | 19 | class Build extends Command 20 | { 21 | /** 22 | * 应用基础目录 23 | * @var string 24 | */ 25 | protected $basePath; 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | protected function configure() 31 | { 32 | $this->setName('build') 33 | ->addArgument('app', Argument::OPTIONAL, 'app name .') 34 | ->setDescription('Build App Dirs'); 35 | } 36 | 37 | protected function execute(Input $input, Output $output) 38 | { 39 | $this->basePath = $this->app->getBasePath(); 40 | $app = $input->getArgument('app') ?: ''; 41 | 42 | if (is_file($this->basePath . 'build.php')) { 43 | $list = include $this->basePath . 'build.php'; 44 | } else { 45 | $list = [ 46 | '__dir__' => ['controller', 'model', 'view'], 47 | ]; 48 | } 49 | 50 | $this->buildApp($app, $list); 51 | $output->writeln("Successed"); 52 | 53 | } 54 | 55 | /** 56 | * 创建应用 57 | * @access protected 58 | * @param string $app 应用名 59 | * @param array $list 目录结构 60 | * @return void 61 | */ 62 | protected function buildApp(string $app, array $list = []): void 63 | { 64 | if (!is_dir($this->basePath . $app)) { 65 | // 创建应用目录 66 | mkdir($this->basePath . $app); 67 | } 68 | 69 | $appPath = $this->basePath . ($app ? $app . DIRECTORY_SEPARATOR : ''); 70 | $namespace = 'app' . ($app ? '\\' . $app : ''); 71 | 72 | // 创建配置文件和公共文件 73 | $this->buildCommon($app); 74 | // 创建模块的默认页面 75 | $this->buildHello($app, $namespace); 76 | 77 | foreach ($list as $path => $file) { 78 | if ('__dir__' == $path) { 79 | // 生成子目录 80 | foreach ($file as $dir) { 81 | $this->checkDirBuild($appPath . $dir); 82 | } 83 | } elseif ('__file__' == $path) { 84 | // 生成(空白)文件 85 | foreach ($file as $name) { 86 | if (!is_file($appPath . $name)) { 87 | file_put_contents($appPath . $name, 'php' == pathinfo($name, PATHINFO_EXTENSION) ? 'app->config->get('route.controller_suffix')) { 100 | $filename = $appPath . $path . DIRECTORY_SEPARATOR . $val . 'Controller.php'; 101 | $class = $val . 'Controller'; 102 | } 103 | $content = "checkDirBuild(dirname($filename)); 111 | $content = ''; 112 | break; 113 | default: 114 | // 其他文件 115 | $content = "app->config->get('route.controller_suffix') ? 'Controller' : ''; 136 | $filename = $this->basePath . ($app ? $app . DIRECTORY_SEPARATOR : '') . 'controller' . DIRECTORY_SEPARATOR . 'Index' . $suffix . '.php'; 137 | 138 | if (!is_file($filename)) { 139 | $content = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'controller.stub'); 140 | $content = str_replace(['{%name%}', '{%app%}', '{%layer%}', '{%suffix%}'], [$app, $namespace, 'controller', $suffix], $content); 141 | $this->checkDirBuild(dirname($filename)); 142 | 143 | file_put_contents($filename, $content); 144 | } 145 | } 146 | 147 | /** 148 | * 创建应用的公共文件 149 | * @access protected 150 | * @param string $app 目录 151 | * @return void 152 | */ 153 | protected function buildCommon(string $app): void 154 | { 155 | $appPath = $this->basePath . ($app ? $app . DIRECTORY_SEPARATOR : ''); 156 | 157 | if (!is_file($appPath . 'common.php')) { 158 | file_put_contents($appPath . 'common.php', " 10 | // +---------------------------------------------------------------------- 11 | declare (strict_types = 1); 12 | 13 | namespace think\app; 14 | 15 | use Closure; 16 | use think\App; 17 | use think\exception\HttpException; 18 | use think\Request; 19 | use think\Response; 20 | 21 | /** 22 | * 多应用模式支持 23 | */ 24 | class MultiApp 25 | { 26 | 27 | /** @var App */ 28 | protected $app; 29 | 30 | public function __construct(App $app) 31 | { 32 | $this->app = $app; 33 | } 34 | 35 | /** 36 | * 多应用解析 37 | * @access public 38 | * @param Request $request 39 | * @param Closure $next 40 | * @return Response 41 | */ 42 | public function handle($request, Closure $next) 43 | { 44 | if (!$this->parseMultiApp()) { 45 | return $next($request); 46 | } 47 | 48 | return $this->app->middleware->pipeline('app') 49 | ->send($request) 50 | ->then(function ($request) use ($next) { 51 | return $next($request); 52 | }); 53 | } 54 | 55 | /** 56 | * 获取路由目录 57 | * @access protected 58 | * @return string 59 | */ 60 | protected function getRoutePath(): string 61 | { 62 | return $this->app->getAppPath() . 'route' . DIRECTORY_SEPARATOR; 63 | } 64 | 65 | /** 66 | * 解析多应用 67 | * @return bool 68 | */ 69 | protected function parseMultiApp(): bool 70 | { 71 | $scriptName = $this->getScriptName(); 72 | $defaultApp = $this->app->config->get('app.default_app') ?: 'index'; 73 | $appName = $this->app->http->getName(); 74 | 75 | if ($appName || ($scriptName && !in_array($scriptName, ['index', 'router', 'think']))) { 76 | $appName = $appName ?: $scriptName; 77 | $this->app->http->setBind(); 78 | } else { 79 | // 自动多应用识别 80 | $this->app->http->setBind(false); 81 | $appName = null; 82 | 83 | $bind = $this->app->config->get('app.domain_bind', []); 84 | 85 | if (!empty($bind)) { 86 | // 获取当前子域名 87 | $subDomain = $this->app->request->subDomain(); 88 | $domain = $this->app->request->host(true); 89 | 90 | if (isset($bind[$domain])) { 91 | $appName = $bind[$domain]; 92 | $this->app->http->setBind(); 93 | } elseif (isset($bind[$subDomain])) { 94 | $appName = $bind[$subDomain]; 95 | $this->app->http->setBind(); 96 | } elseif (isset($bind['*'])) { 97 | $appName = $bind['*']; 98 | $this->app->http->setBind(); 99 | } 100 | } 101 | 102 | if (!$this->app->http->isBind()) { 103 | $path = $this->app->request->pathinfo(); 104 | $map = $this->app->config->get('app.app_map', []); 105 | $deny = $this->app->config->get('app.deny_app_list', []); 106 | $name = current(explode('/', $path)); 107 | 108 | if (strpos($name, '.')) { 109 | $name = strstr($name, '.', true); 110 | } 111 | 112 | if (isset($map[$name])) { 113 | if ($map[$name] instanceof Closure) { 114 | $result = call_user_func_array($map[$name], [$this->app]); 115 | $appName = $result ?: $name; 116 | } else { 117 | $appName = $map[$name]; 118 | } 119 | } elseif ($name && (false !== array_search($name, $map) || in_array($name, $deny))) { 120 | throw new HttpException(404, 'app not exists:' . $name); 121 | } elseif ($name && isset($map['*'])) { 122 | $appName = $map['*']; 123 | } else { 124 | $appName = $name ?: $defaultApp; 125 | $appPath = $this->app->http->getPath() ?: $this->app->getBasePath() . $appName . DIRECTORY_SEPARATOR; 126 | 127 | if (!is_dir($appPath)) { 128 | $express = $this->app->config->get('app.app_express', false); 129 | if ($express) { 130 | $this->setApp($defaultApp); 131 | return true; 132 | } else { 133 | return false; 134 | } 135 | } 136 | } 137 | 138 | if ($name) { 139 | $this->app->request->setRoot('/' . $name); 140 | $this->app->request->setPathinfo(strpos($path, '/') ? ltrim(strstr($path, '/'), '/') : ''); 141 | } 142 | } 143 | } 144 | 145 | $this->setApp($appName ?: $defaultApp); 146 | return true; 147 | } 148 | 149 | /** 150 | * 获取当前运行入口名称 151 | * @access protected 152 | * @codeCoverageIgnore 153 | * @return string 154 | */ 155 | protected function getScriptName(): string 156 | { 157 | if (isset($_SERVER['SCRIPT_FILENAME'])) { 158 | $file = $_SERVER['SCRIPT_FILENAME']; 159 | } elseif (isset($_SERVER['argv'][0])) { 160 | $file = realpath($_SERVER['argv'][0]); 161 | } 162 | 163 | return isset($file) ? pathinfo($file, PATHINFO_FILENAME) : ''; 164 | } 165 | 166 | /** 167 | * 设置应用 168 | * @param string $appName 169 | */ 170 | protected function setApp(string $appName): void 171 | { 172 | $this->app->http->name($appName); 173 | 174 | $appPath = $this->app->http->getPath() ?: $this->app->getBasePath() . $appName . DIRECTORY_SEPARATOR; 175 | 176 | $this->app->setAppPath($appPath); 177 | // 设置应用命名空间 178 | $this->app->setNamespace($this->app->config->get('app.app_namespace') ?: 'app\\' . $appName); 179 | 180 | if (is_dir($appPath)) { 181 | $this->app->setRuntimePath($this->app->getRuntimePath() . $appName . DIRECTORY_SEPARATOR); 182 | $this->app->http->setRoutePath($this->getRoutePath()); 183 | 184 | //加载应用 185 | $this->loadApp($appName, $appPath); 186 | } 187 | } 188 | 189 | /** 190 | * 加载应用文件 191 | * @param string $appName 应用名 192 | * @return void 193 | */ 194 | protected function loadApp(string $appName, string $appPath): void 195 | { 196 | if (is_file($appPath . 'common.php')) { 197 | include_once $appPath . 'common.php'; 198 | } 199 | 200 | $files = []; 201 | 202 | $files = array_merge($files, glob($appPath . 'config' . DIRECTORY_SEPARATOR . '*' . $this->app->getConfigExt())); 203 | 204 | foreach ($files as $file) { 205 | $this->app->config->load($file, pathinfo($file, PATHINFO_FILENAME)); 206 | } 207 | 208 | if (is_file($appPath . 'event.php')) { 209 | $this->app->loadEvent(include $appPath . 'event.php'); 210 | } 211 | 212 | if (is_file($appPath . 'middleware.php')) { 213 | $this->app->middleware->import(include $appPath . 'middleware.php', 'app'); 214 | } 215 | 216 | if (is_file($appPath . 'provider.php')) { 217 | $this->app->bind(include $appPath . 'provider.php'); 218 | } 219 | // 加载应用语言包 220 | $this->app->loadLangPack($this->app->lang->defaultLangSet()); 221 | } 222 | 223 | } 224 | -------------------------------------------------------------------------------- /src/Url.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | declare (strict_types = 1); 12 | 13 | namespace think\app; 14 | 15 | use think\App; 16 | use think\Route; 17 | use think\route\Url as UrlBuild; 18 | 19 | /** 20 | * 路由地址生成 21 | */ 22 | class Url extends UrlBuild 23 | { 24 | /** 25 | * 直接解析URL地址 26 | * @access protected 27 | * @param string $url URL 28 | * @param string|bool $domain Domain 29 | * @return string 30 | */ 31 | protected function parseUrl(string $url, &$domain): string 32 | { 33 | $request = $this->app->request; 34 | 35 | if (0 === strpos($url, '/')) { 36 | // 直接作为路由地址解析 37 | $url = substr($url, 1); 38 | } elseif (false !== strpos($url, '\\')) { 39 | // 解析到类 40 | $url = ltrim(str_replace('\\', '/', $url), '/'); 41 | } elseif (0 === strpos($url, '@')) { 42 | // 解析到控制器 43 | $url = substr($url, 1); 44 | } elseif ('' === $url) { 45 | $url = $request->controller() . '/' . $request->action(); 46 | if (!$this->app->http->isBind()) { 47 | $url = $this->getAppName() . '/' . $url; 48 | } 49 | } else { 50 | // 解析到 应用/控制器/操作 51 | $controller = $request->controller(); 52 | $path = explode('/', $url); 53 | $action = array_pop($path); 54 | $controller = empty($path) ? $controller : array_pop($path); 55 | $app = empty($path) ? $this->getAppName() : array_pop($path); 56 | $url = $controller . '/' . $action; 57 | $bind = $this->app->config->get('app.domain_bind', []); 58 | 59 | if ($key = array_search($this->app->http->getName(), $bind)) { 60 | isset($bind[$_SERVER['SERVER_NAME']]) && $domain = $_SERVER['SERVER_NAME']; 61 | 62 | $domain = is_bool($domain) ? $key : $domain; 63 | } elseif (!$this->app->http->isBind()) { 64 | $map = $this->app->config->get('app.app_map', []); 65 | if ($key = array_search($app, $map)) { 66 | $url = $key . '/' . $url; 67 | } else { 68 | $url = $app . '/' . $url; 69 | } 70 | } 71 | } 72 | 73 | return $url; 74 | } 75 | 76 | public function build(): string 77 | { 78 | // 解析URL 79 | $url = $this->url; 80 | $suffix = $this->suffix; 81 | $domain = $this->domain; 82 | $request = $this->app->request; 83 | $vars = $this->vars; 84 | 85 | if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { 86 | // [name] 表示使用路由命名标识生成URL 87 | $name = substr($url, 1, $pos - 1); 88 | $url = 'name' . substr($url, $pos + 1); 89 | } 90 | 91 | if (false === strpos($url, '://') && 0 !== strpos($url, '/')) { 92 | $info = parse_url($url); 93 | $url = !empty($info['path']) ? $info['path'] : ''; 94 | 95 | if (isset($info['fragment'])) { 96 | // 解析锚点 97 | $anchor = $info['fragment']; 98 | 99 | if (false !== strpos($anchor, '?')) { 100 | // 解析参数 101 | list($anchor, $info['query']) = explode('?', $anchor, 2); 102 | } 103 | 104 | if (false !== strpos($anchor, '@')) { 105 | // 解析域名 106 | list($anchor, $domain) = explode('@', $anchor, 2); 107 | } 108 | } elseif (strpos($url, '@') && false === strpos($url, '\\')) { 109 | // 解析域名 110 | list($url, $domain) = explode('@', $url, 2); 111 | } 112 | } 113 | 114 | if ($url) { 115 | $checkName = isset($name) ? $name : $url . (isset($info['query']) ? '?' . $info['query'] : ''); 116 | $checkDomain = $domain && is_string($domain) ? $domain : null; 117 | 118 | $rule = $this->route->getName($checkName, $checkDomain); 119 | 120 | if (empty($rule) && isset($info['query'])) { 121 | $rule = $this->route->getName($url, $checkDomain); 122 | // 解析地址里面参数 合并到vars 123 | parse_str($info['query'], $params); 124 | $vars = array_merge($params, $vars); 125 | unset($info['query']); 126 | } 127 | } 128 | 129 | if (!empty($rule) && $match = $this->getRuleUrl($rule, $vars, $domain)) { 130 | // 匹配路由命名标识 131 | $url = $match[0]; 132 | 133 | if ($domain && !empty($match[1])) { 134 | $domain = $match[1]; 135 | } 136 | 137 | if (!is_null($match[2])) { 138 | $suffix = $match[2]; 139 | } 140 | 141 | if (!$this->app->http->isBind()) { 142 | $app = $this->getAppName(); 143 | $url = $app . '/' . $url; 144 | } 145 | } elseif (!empty($rule) && isset($name)) { 146 | throw new \InvalidArgumentException('route name not exists:' . $name); 147 | } else { 148 | // 检测URL绑定 149 | $bind = (string) $this->route->getDomainBind($domain && is_string($domain) ? $domain : null); 150 | 151 | if ($bind && 0 === strpos($url, $bind)) { 152 | $url = substr($url, strlen($bind) + 1); 153 | } 154 | 155 | // 路由标识不存在 直接解析 156 | $url = $this->parseUrl($url, $domain); 157 | 158 | if (isset($info['query'])) { 159 | // 解析地址里面参数 合并到vars 160 | parse_str($info['query'], $params); 161 | $vars = array_merge($params, $vars); 162 | } 163 | } 164 | 165 | // 还原URL分隔符 166 | $depr = $this->route->config('pathinfo_depr'); 167 | $url = str_replace('/', $depr, $url); 168 | 169 | $file = $request->baseFile(); 170 | if ($file && 0 !== strpos($request->url(), $file)) { 171 | $file = str_replace('\\', '/', dirname($file)); 172 | } 173 | 174 | $url = rtrim($file, '/') . '/' . ltrim($url, '/'); 175 | 176 | // URL后缀 177 | if ('/' == substr($url, -1) || '' == $url) { 178 | $suffix = ''; 179 | } else { 180 | $suffix = $this->parseSuffix($suffix); 181 | } 182 | 183 | // 锚点 184 | $anchor = !empty($anchor) ? '#' . $anchor : ''; 185 | 186 | // 参数组装 187 | if (!empty($vars)) { 188 | // 添加参数 189 | if ($this->route->config('url_common_param')) { 190 | $vars = http_build_query($vars); 191 | $url .= $suffix . '?' . $vars . $anchor; 192 | } else { 193 | foreach ($vars as $var => $val) { 194 | $val = (string) $val; 195 | if ('' !== $val) { 196 | $url .= $depr . $var . $depr . urlencode($val); 197 | } 198 | } 199 | 200 | $url .= $suffix . $anchor; 201 | } 202 | } else { 203 | $url .= $suffix . $anchor; 204 | } 205 | 206 | // 检测域名 207 | $domain = $this->parseDomain($url, $domain); 208 | 209 | // URL组装 210 | return $domain . rtrim($this->root, '/') . '/' . ltrim($url, '/'); 211 | } 212 | 213 | /** 214 | * 获取URL的应用名 215 | * @access protected 216 | * @return string 217 | */ 218 | protected function getAppName() 219 | { 220 | $app = $this->app->http->getName(); 221 | $map = $this->app->config->get('app.app_map', []); 222 | 223 | if ($key = array_search($app, $map)) { 224 | $app = $key; 225 | } 226 | 227 | return $app; 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------