Skip to content

Commit

Permalink
commit by Simon.Ye
Browse files Browse the repository at this point in the history
  • Loading branch information
samlinye committed Sep 1, 2021
1 parent d4cb2dc commit ffe60c1
Show file tree
Hide file tree
Showing 47 changed files with 1,188 additions and 569 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require": {
"php": ">=7.3.0",
"meiguonet/mgboot-common-php7": "^1.1.0",
"meiguonet/mgboot-common-php7": "^1.0.0",
"nikic/fast-route": "^1.3.0"
}
}
61 changes: 46 additions & 15 deletions src/MgBoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,60 @@

final class MgBoot
{
private static string $controllerDir = '';
private static ?LoggerInterface $runtimeLogger = null;
private static bool $requestLogEnabled = false;
private static ?LoggerInterface $requestLogLogger = null;
private static bool $executeTimeLogEnabled = false;
private static ?LoggerInterface $executeTimeLogLogger = null;
private static ?CorsSettings $corsSettings = null;
/**
* @var string
*/
private static $controllerDir = '';

/**
* @var LoggerInterface|null
*/
private static $runtimeLogger = null;

/**
* @var bool
*/
private static $requestLogEnabled = false;

/**
* @var LoggerInterface|null
*/
private static $requestLogLogger = null;

/**
* @var bool
*/
private static $executeTimeLogEnabled = false;

/**
* @var LoggerInterface|null
*/
private static $executeTimeLogLogger = null;

/**
* @var CorsSettings|null
*/
private static $corsSettings = null;

/**
* @var JwtSettings[]
*/
private static array $jwtSettings = [];
private static bool $gzipOutputEnabled = true;
private static $jwtSettings = [];

/**
* @var bool
*/
private static $gzipOutputEnabled = true;

/**
* @var ExceptionHandler[]
*/
private static array $exceptionHandlers = [];
private static $exceptionHandlers = [];

/**
* @var Middleware[]
*/
private static array $middlewares = [];
private static $middlewares = [];

private function __construct()
{
Expand Down Expand Up @@ -80,7 +112,7 @@ public static function handleRequest(Request $request, Response $response): void
$httpMethod = strtoupper($request->getMethod());
$uri = $request->getRequestUrl();

if (str_contains($uri, '?')) {
if (strpos($uri, '?') !== false) {
$uri = substr($uri, 0, strpos($uri, '?'));
}

Expand Down Expand Up @@ -266,7 +298,7 @@ private static function checkNecessaryExceptionHandlers(): void
$found = false;

foreach (self::$exceptionHandlers as $handler) {
if (str_contains($handler->getExceptionClassName(), $clazz)) {
if (strpos($handler->getExceptionClassName(), $clazz) !== false) {
$found = true;
break;
}
Expand Down Expand Up @@ -313,8 +345,7 @@ private static function setRouteRuleToRequest(Request $request, string $httpMeth
}

if ($matched instanceof RouteRule) {
/** @noinspection PhpUndefinedVariableInspection */
$request->withRouteRule($rule);
$request->withRouteRule($matched);
return true;
}

Expand Down
8 changes: 6 additions & 2 deletions src/annotation/ClientIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace mgboot\core\annotation;

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
use Doctrine\Common\Annotations\Annotation\Target;

/**
* @Annotation
* @Target({"ANNOTATION", "PROPERTY"})
*/
final class ClientIp
{
}
24 changes: 19 additions & 5 deletions src/annotation/DeleteMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

namespace mgboot\core\annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;

#[Attribute(Attribute::TARGET_METHOD)]
/**
* @Annotation
* @Target("METHOD")
*/
final class DeleteMapping
{
private string $value;
/**
* @var string
*/
private $value;

public function __construct(string $arg0)
public function __construct($arg0)
{
$this->value = $arg0;
$value = '';

if (is_string($arg0) && $arg0 !== '') {
$value = $arg0;
} else if (is_array($arg0) && is_string($arg0['value']) && $arg0['value'] !== '') {
$value = $arg0['value'];
}

$this->value = $value;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/annotation/DtoBind.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace mgboot\core\annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;

#[Attribute(Attribute::TARGET_PARAMETER)]
/**
* @Annotation
* @Target("ANNOTATION")
*/
final class DtoBind
{
}
24 changes: 18 additions & 6 deletions src/annotation/GetMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@

namespace mgboot\core\annotation;

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
/**
* @Annotation
* @Target("METHOD")
*/
final class GetMapping
{
private string $value;
/**
* @var string
*/
private $value;

public function __construct(string $arg0)
public function __construct($arg0)
{
$this->value = $arg0;
$value = '';

if (is_string($arg0) && $arg0 !== '') {
$value = $arg0;
} else if (is_array($arg0) && is_string($arg0['value']) && $arg0['value'] !== '') {
$value = $arg0['value'];
}

$this->value = $value;
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/annotation/HttpHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

namespace mgboot\core\annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
/**
* @Annotation
* @Target({"ANNOTATION", "PROPERTY"})
*/
final class HttpHeader
{
private string $name;
/**
* @var string
*/
private $name;

public function __construct(string $arg0)
public function __construct(?string $name = null)
{
$this->name = $arg0;
$this->name = empty($name) ? '' : $name;
}

/**
Expand Down
28 changes: 21 additions & 7 deletions src/annotation/JwtAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@

namespace mgboot\core\annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;

#[Attribute(Attribute::TARGET_METHOD)]
/**
* @Annotation
* @Target("METHOD")
*/
final class JwtAuth
{
private string $settingsKey;
/**
* @var string
*/
private $value;

public function __construct(string $arg0)
public function __construct($arg0)
{
$this->settingsKey = $arg0;
$value = '';

if (is_string($arg0) && $arg0 !== '') {
$value = $arg0;
} else if (is_array($arg0) && is_string($arg0['value']) && $arg0['value'] !== '') {
$value = $arg0['value'];
}

$this->value = $value;
}

/**
* @return string
*/
public function getSettingsKey(): string
public function getValue(): string
{
return $this->settingsKey;
return $this->value;
}
}
17 changes: 12 additions & 5 deletions src/annotation/JwtClaim.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

namespace mgboot\core\annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
use mgboot\Cast;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
/**
* @Annotation
* @Target({"ANNOTATION", "PROPERTY"})
*/
final class JwtClaim
{
private string $name;
/**
* @var string
*/
private $name;

public function __construct(string $arg0 = '')
public function __construct(?string $name = null)
{
$this->name = $arg0;
$this->name = empty($name) ? '' : $name;
}

/**
Expand Down
45 changes: 45 additions & 0 deletions src/annotation/MapBind.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace mgboot\core\annotation;

use Doctrine\Common\Annotations\Annotation\Target;
use mgboot\constant\Regexp;

/**
* @Annotation
* @Target("ANNOTATION")
*/
final class MapBind
{
/**
* @var string[]
*/
private $rules;

public function __construct($arg0 = null)
{
$rules = [];

if (is_string($arg0) && $arg0 !== '') {
$rules = preg_split(Regexp::COMMA_SEP, $arg0);
} else if (is_array($arg0) && !empty($arg0)) {
foreach ($arg0 as $s1) {
if (!is_string($s1) || $s1 === '') {
continue;
}

$rules[] = $s1;
}
}

$this->rules = $rules;
}

/**
* @return string[]
*/
public function getRules(): array
{
return $this->rules;
}
}
30 changes: 30 additions & 0 deletions src/annotation/ParamInject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace mgboot\core\annotation;

use Doctrine\Common\Annotations\Annotation\Target;

/**
* @Annotation
* @Target("METHOD")
*/
final class ParamInject
{
/**
* @var array
*/
private $value;

public function __construct(array $values)
{
$this->value = $values;
}

/**
* @return array
*/
public function getValue(): array
{
return $this->value;
}
}
Loading

0 comments on commit ffe60c1

Please sign in to comment.