Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Request 解析器 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
blankqwq merged 7 commits into master from dev
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitattributes
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* text=auto

*.md diff=markdown
*.php diff=php

/.github export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php-cs-fixer.php export-ignore
phpunit.xml.dist export-ignore
5 changes: 3 additions & 2 deletions .gitignore
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/vendor
composer.phar
composer.lock
.DS_Store
Thumbs.db
/.idea
/.vscode
/.git
.php-cs-fixer.cache
.php-cs-fixer.cache
*.lock
*.cache
3 changes: 2 additions & 1 deletion composer.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"predis/predis": "^1.1",
"ext-curl": "*",
"monolog/monolog": "^2.3",
"ext-pdo": "*"
"ext-pdo": "*",
"psr/http-message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.2 | ^7 | ^8 | ^9",
Expand Down
23 changes: 9 additions & 14 deletions phpunit.xml.dist
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false"
bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false"
stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Container Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
10 changes: 7 additions & 3 deletions src/blankphp/Application.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
use BlankPhp\Database\Grammar\MysqlGrammar;
use BlankPhp\Kernel\ConsoleKernel;
use BlankPhp\Log\Log;
use BlankPhp\Request\Parse;
use BlankPhp\Request\Request;
use BlankPhp\Response\Response;
use BlankPhp\Route\Route;
use BlankPhp\Route\RouteCollection;
use BlankPhp\Route\Router;
use BlankPhp\Scheme\Scheme;
use BlankPhp\Session\Session;
Expand All @@ -33,8 +35,7 @@ class Application extends Container
private $version = '0.2.3-dev';

/**
* @var
* 存储单例
* @var Application
*/
protected static $instance;

Expand All @@ -45,6 +46,7 @@ public static function init()

protected function __construct()
{
parent::__construct();
$this->registerDirName();
$this->registerBaseService();
$this->registerBase();
Expand All @@ -59,7 +61,7 @@ public static function getInstance()
{
//Unsafe usage of new static()
if (empty(static::$instance)) {
new self();
new static();
}

return static::$instance;
Expand All @@ -80,7 +82,9 @@ public function registerBaseService()
foreach ([
'console' => ConsoleKernel::class,
'request' => [\BlankPhp\Contract\Request::class, Request::class],
'request.parse' => [Parse::class],
'route' => [\BlankPhp\Contract\Route::class, Route::class],
'route.collection' => [RouteCollection::class],
'router' => [Router::class],
'app' => [\BlankPhp\Contract\Container::class, __CLASS__],
'db' => Database::class,
Expand Down
28 changes: 28 additions & 0 deletions src/blankphp/Base/Traits/ContainerBindMake.php
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the /blankphp/framework.
*
* (c) 沉迷 <1136589038@qq.com>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace BlankPhp\Base\Traits;

trait ContainerBindMake
{
private $bindThisObj = [];

public function useThis($instance)
{
$this->bindThisObj[] = $instance;
}

public function cleanThem()
{
foreach ($this->bindThisObj as $item) {
app()->cleanInstance($item);
}
}
}
4 changes: 1 addition & 3 deletions src/blankphp/Cache/Cache.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function set($key, $value, $ttl = null)

/**
* @param $key
* @param null $default
* @param $default
*
* @return mixed
*/
Expand All @@ -118,8 +118,6 @@ public function get($key, $default = null)
}

/**
* @param $key
*
* @return mixed
*/
public function remember(string $key, \Closure $closure)
Expand Down
9 changes: 7 additions & 2 deletions src/blankphp/Collection/Collection.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public function item($obj)
return $this->item[] = empty($obj) ? null : $obj;
}

public function merg($value): void
public function items(): array
{
return $this->item;
}

public function merge($value): void
{
$this->item = array_merge($this->item, $value);
}
Expand Down Expand Up @@ -102,7 +107,7 @@ public function __call($name, $arguments)
{
}

public function __toArray()
public function __toArray(): array
{
$data = [];
foreach ($this->item as $item) {
Expand Down
66 changes: 27 additions & 39 deletions src/blankphp/Container.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace BlankPhp;

use BlankPhp\Container\InteractiveBind;
use BlankPhp\Contract\Container as ContainerContract;
use BlankPhp\Contract\Event;
use BlankPhp\Exception\ParameterLoopException;
Expand Down Expand Up @@ -45,9 +46,9 @@ class Container implements \ArrayAccess, ContainerContract, Event
/**
* 别名.
*
* @var array
* @var InteractiveBind
*/
protected $alice = [];
protected $alice = null;

/**
* @var array
Expand All @@ -62,6 +63,11 @@ class Container implements \ArrayAccess, ContainerContract, Event
*/
protected $parameterStatus = [];

protected function __construct()
{
$this->alice = new InteractiveBind();
}

protected function getShareObj($abstract)
{
return $this->classes[$abstract] ?? null;
Expand All @@ -73,13 +79,12 @@ protected function getShareObj($abstract)
*/
public function make($abstract, $parameters = [])
{
// 判断共享对象中是否有
if ($res = $this->getShareObj($abstract)) {
return $res;
}
if ($res = $this->getInstances($abstract)) {
return $res;
}
if ($class = $this->alice->getValue($abstract)) {
$abstract = $class;
}
// 是否为绑定
if ($class = $this->getBinds($abstract)) {
$abstract = $class;
Expand All @@ -95,22 +100,21 @@ private function getInstances($abstract)

private function getBinds($binds)
{
return $this->binds[$binds]['concert'] ?? null;
return $this->binds[$binds] ?? null;
}

public function has($abstract)
{
return isset($this->instances[$abstract]) || isset($this->alice[$abstract]) || isset($this->binds[$abstract]) || isset($this->classes[$abstract]);
return isset($this->instances[$abstract]) || $this->alice->verifyValue($abstract) || isset($this->binds[$abstract]);
}

/**
* @param $instance
* @param $abstract
* @param $share
*
* @return mixed|void
*/
public function bind($abstract, $instance, $share = false)
public function bind($abstract, $instance)
{
//清理老数据
if (null === $instance) {
Expand All @@ -122,48 +126,34 @@ public function bind($abstract, $instance, $share = false)
$concert = $instance;
}
}
$this->binds[$abstract] = compact('concert', 'share');
$this->bindAlice(is_array($instance) ? $instance : [$instance], $abstract);
$this->binds[$abstract] = $concert;
$this->bindAlice($abstract, $instance);
}

/**
* @param $abstract
* @param $instance
*
* @return void
*/
public function bindAlice(array $classes, $abstract)
public function bindAlice($abstract, $instance)
{
$this->alice[$abstract] = array_merge($classes, $this->alice[$abstract] ?? []);
}

/**
* @param $abstract
*
* @return mixed|null
*/
public function getAlice($abstract)
{
return $this->alice[$abstract] ?? [];
$this->alice->binds($abstract, $instance);
}

/**
* @param $abstract
* @param $instance
* @param $share
*
* @return mixed|void
* 实例注册
*/
public function instance($abstract, $instance, $share = false)
public function instance($abstract, $instance)
{
// 是否有别名
if ($share) {
$this->classes[$abstract] = $instance;
}
$this->instances[$abstract] = $instance;
foreach ($this->getAlice($abstract) as $item) {
foreach ($this->alice->getByKey($abstract) as $item) {
$this->instances[$item] = $instance;
}
$this->instances[$abstract] = $instance;
unset($this->binds[$abstract]);

return $instance;
Expand Down Expand Up @@ -224,19 +214,18 @@ public function build($concrete, int $count = 0)
}
}

/**
* @param ReflectionParameter[] $params
/***
* @param array $params
* @param $count
*
* @throws \ReflectionException
* @return array
* @throws ParameterLoopException
* @throws \ReflectionException
*/
public function resolveDepends(array $params, $count): array
{
// 判断参数类型
++$count;
/**
* @var string $key
* @var ReflectionParameter $param
*/
foreach ($params as $param) {
Expand All @@ -253,8 +242,7 @@ public function resolveDepends(array $params, $count): array
}
if ($this->has($paramClassName)) {
$args = $this->make($paramClassName);
} // 共享内存获取
else {
} else {
$args = $this->build($paramClassName, $count);
}
}
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /