Skip to content

Commit

Permalink
fix: namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX committed Apr 9, 2020
1 parent 8c1c441 commit 78bef4b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/CorsService.php → src/CorsCore.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
declare(strict_types=1);

namespace app\Service\Cors;
namespace HZEX\Think\Cors;

use think\Request;
use think\Response;
use function HZEX\Think\Cors\str_starts_with;

class CorsService
class CorsCore
{
/**
* 允许访问的来源
Expand Down
6 changes: 3 additions & 3 deletions src/CorsMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace app\Service\Cors;
namespace HZEX\Think\Cors;

use Closure;
use think\Config;
Expand All @@ -11,15 +11,15 @@
class CorsMiddleware
{
/**
* @var CorsService
* @var CorsCore
*/
protected $cors;

public function __construct(Config $config)
{
$conf = $config->get('cros', []);

$this->cors = new CorsService(
$this->cors = new CorsCore(
$conf['allowed_origins'] ?? [],
$conf['allowed_origins_patterns'] ?? [],
$conf['allowed_methods'] ?? [],
Expand Down
8 changes: 2 additions & 6 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

namespace HZEX\Think\Cors;

use app\Service\Cors\CorsMiddleware;

class Service extends \think\Service
{
public function register()
{
if (!defined('CORS_NOT_AUTO_REGISTER')) {
// 注册跨域中间件
$this->app->middleware->unshift(CorsMiddleware::class, 'route');
}
// 注册跨域中间件
$this->app->middleware->unshift(CorsMiddleware::class, 'route');
}
}

0 comments on commit 78bef4b

Please sign in to comment.