Library::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
// +----------------------------------------------------------------------
4
// | ThinkLibrary 6.0 for ThinkPhP 6.0
5
// +----------------------------------------------------------------------
6
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
7
// +----------------------------------------------------------------------
8
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
9
// +----------------------------------------------------------------------
10
// | 开源协议 ( https://mit-license.org )
11
// +----------------------------------------------------------------------
12
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
13
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
14
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
15
// +----------------------------------------------------------------------
16
17
namespace DtApp\ThinkLibrary;
18
19
use think\admin\service\AdminService;
0 ignored issues
show
Bug introduced by
The type think\admin\service\AdminService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use think\Request;
21
use think\Service;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DtApp\ThinkLibrary\Service. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
22
23
/**
24
 * 模块注册服务
25
 * Class Library
26
 * @package DtApp\ThinkLibrary
27
 */
28
class Library extends Service
29
{
30
    /**
31
     * 定义当前版本
32
     */
33
    const VERSION = '6.0.131';
34
35
    /**
36
     * 启动服务
37
     */
38
    public function boot()
39
    {
40
41
    }
42
43
    /**
44
     * 初始化服务
45
     */
46
    public function register()
47
    {
48
        // 输入默认过滤
49
        $this->app->request->filter(['trim']);
50
        // 判断访问模式,兼容 CLI 访问控制器
51
        if (!$this->app->request->isCli()) {
52
            // 注册访问处理中间键
53
            $this->app->middleware->add(function (Request $request) {
54
                $header = [];
55
                if (($origin = $request->header('origin', '*')) !== '*') {
56
                    $header['Access-Control-Allow-Origin'] = $origin;
57
                    $header['Access-Control-Allow-Methods'] = 'GET,PUT,POST,PATCH,DELETE';
58
                    $header['Access-Control-Allow-Headers'] = 'Authorization,Content-Type,If-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,X-Requested-With,User-Form-Token,User-Token,Token';
59
                    $header['Access-Control-Expose-Headers'] = 'User-Form-Token,User-Token,Token';
60
                    $header['Access-Control-Allow-Credentials'] = 'true';
61
                }
62
                // 访问模式及访问权限检查
63
                if ($request->isOptions()) {
64
                    return response()->code(204)->header($header);
65
                }
66
            }, 'route');
67
        }
68
    }
69
}
70