Skip to content

Commit 62fbbfd

Browse files
author
Sergey Surkov
committed
version 1.4.0.1
1 parent 7d80594 commit 62fbbfd

9 files changed

Lines changed: 251 additions & 111 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"symbiotic/ui_backend": "1.4.*"
66
},
77
"license": "MIT",
8-
"version": "1.4.0",
8+
"version": "1.4.0.1",
99
"autoload": {
1010
"psr-4": {
1111
"Symbiotic\\Develop\\": "src/"

resources/stubs/src/RoutingDemo.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
namespace DummyPackageNamespace;
55

66

7+
use Symbiotic\Develop\Services\Routing\FakeRoutes;
78
use Symbiotic\Routing\RouterInterface;
89
use Symbiotic\Routing\AppRouting;
910

1011

11-
class DummyClass extends AppRouting
12+
class DummyClass extends FakeRoutes/*AppRouting*/
1213
{
1314

1415
/**
@@ -23,6 +24,7 @@ class DummyClass extends AppRouting
2324
*/
2425
public function backendRoutes(RouterInterface $router): void
2526
{
27+
parent::backendRoutes($router);
2628
/**
2729
* @uri /framework_root/backend/#APP_ID#/ - корневой екшен приложения
2830
* @uses \DummyPackageNamespace\Http\Controllers\Backend\Index::index()
@@ -61,6 +63,8 @@ public function backendRoutes(RouterInterface $router): void
6163
*/
6264
public function frontendRoutes(RouterInterface $router): void
6365
{
66+
parent::frontendRoutes($router);
67+
6468
/**
6569
* @link #FRAMEWORK_ROOT_URI#/#APP_ID#/
6670
* @uri /framework_root/#APP_ID#/ - корневой екшен приложения
@@ -121,6 +125,7 @@ public function frontendRoutes(RouterInterface $router): void
121125
*/
122126
public function defaultRoutes(RouterInterface $router): void
123127
{
128+
parent::defaultRoutes($router);
124129
/**
125130
* @link #FRAMEWORK_ROOT_URI#/default_#APP_ID#/ - md5 кривой, но
126131
* @uri /framework_root/default_#APP_ID#/ роут от корня фреймоворка

src/Bootstrap/DebugBootstrap.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symbiotic\Routing\RouterInterface;
2222
use Symbiotic\Routing\SettlementsInterface;
2323
use Symbiotic\Routing\SettlementsRouter;
24+
2425
use function _S\config;
2526

2627

@@ -29,31 +30,40 @@ class DebugBootstrap implements BootstrapInterface
2930

3031
public function bootstrap(DIContainerInterface $core): void
3132
{
32-
3333
if ($core('config::debug')) {
34-
$core->instance(Timer::class, new Timer());
35-
$core[Timer::class]->start('All');
36-
if (!$core->bound(PackagesRepositoryInterface::class)) {
37-
$core->extend(PackagesRepositoryInterface::class, function (PackagesRepositoryInterface $object) {
38-
return new PackagesRepository($object);
34+
if (!$core->bound(Timer::class)) {
35+
$core->live(Timer::class, function ($app) {
36+
$timer = new Timer();
37+
$timer->start('All');
38+
return $timer;
3939
});
40+
$core[Timer::class];
41+
}
42+
43+
if (!$core->bound(PackagesRepositoryInterface::class)) {
44+
$core->extend(
45+
PackagesRepositoryInterface::class,
46+
function (PackagesRepositoryInterface $object, CoreInterface $core) {
47+
return new PackagesRepository($object, $core);
48+
}
49+
);
4050
}
4151

42-
$core->extend(HttpKernelInterface::class, function (HttpKernelInterface $object) use ($core) {
43-
return new HttpKernel($object, $core[Timer::class]);
52+
$core->extend(HttpKernelInterface::class, function (HttpKernelInterface $object, CoreInterface $core) {
53+
return new HttpKernel($object, $core);
4454
});
45-
$core->extend(SettlementsRouter::class, function (RouterInterface $object) use ($core) {
46-
return new Router($object, $core[Timer::class]);
55+
$core->extend(SettlementsRouter::class, function (RouterInterface $object, CoreInterface $core) {
56+
return new Router($object, $core);
4757
});
48-
$core->extend(SettlementsInterface::class, function (SettlementsInterface $object) use ($core) {
49-
return new Settlements($object, $core[Timer::class]);
58+
$core->extend(SettlementsInterface::class, function (SettlementsInterface $object, CoreInterface $core) {
59+
return new Settlements($object, $core);
5060
});
5161

52-
$core->extend(RoutingHandler::class, function (RequestHandlerInterface $object) use ($core) {
53-
return new RequestHandler($object, $core[Timer::class]);
62+
$core->extend(RoutingHandler::class, function (RequestHandlerInterface $object, CoreInterface $core) {
63+
return new RequestHandler($object, $core);
5464
});
55-
$core->extend(RouteHandler::class, function (RequestHandlerInterface $object) use ($core) {
56-
return new RequestHandler($object, $core[Timer::class]);
65+
$core->extend(RouteHandler::class, function (RequestHandlerInterface $object, CoreInterface $core) {
66+
return new RequestHandler($object, $core);
5767
});
5868
}
5969
}

src/Debug/HttpKernel/HttpKernel.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55

66
use Psr\Container\ContainerInterface;
7+
use Symbiotic\Container\CloningContainer;
8+
use Symbiotic\Core\CoreInterface;
79
use Symbiotic\Core\HttpKernelInterface;
810
use Symbiotic\Develop\Services\Debug\Timer;
911
use Psr\Http\Message\ResponseInterface;
@@ -18,22 +20,22 @@ class HttpKernel implements HttpKernelInterface
1820
protected $object;
1921

2022
/**
21-
* @var Timer
23+
* @var CoreInterface
2224
*/
23-
protected $timer;
25+
protected $container;
2426

2527

26-
public function __construct(HttpKernelInterface $packages, Timer $timer)
28+
public function __construct(HttpKernelInterface $packages, ContainerInterface $core)
2729
{
2830
$this->object = $packages;
29-
$this->timer = $timer;
31+
$this->container = $core;
3032
}
3133

3234
public function bootstrap(): void
3335
{
34-
$this->timer->start('http_kernel_bootstrap');
36+
$this->container[Timer::class]->start('Http Kernel Bootstrap');
3537
$this->call(__FUNCTION__, func_get_args());
36-
$this->timer->end('http_kernel_bootstrap');
38+
$this->container[Timer::class]->end('Http Kernel Bootstrap');
3739
}
3840

3941
public function response(int $code = 200, \Throwable $exception = null): ResponseInterface
@@ -43,26 +45,31 @@ public function response(int $code = 200, \Throwable $exception = null): Respons
4345

4446
public function handle(ServerRequestInterface $request): ResponseInterface
4547
{
46-
$this->timer->start('http_kernel_handle');
48+
$this->container[Timer::class]->start('http_kernel_handle');
4749
$data = $this->call(__FUNCTION__, func_get_args());
48-
$this->timer->end('http_kernel_handle');
50+
$this->container[Timer::class]->end('http_kernel_handle');
51+
4952
return $data;
5053
}
5154

52-
protected function call($method, $parameters)
55+
public function terminate(ServerRequestInterface $request, ResponseInterface $response = null): void
5356
{
54-
return call_user_func_array([$this->object, $method], $parameters);
57+
$this->call(__FUNCTION__, func_get_args());
5558
}
5659

5760
public function cloneInstance(?ContainerInterface $container): ?object
5861
{
59-
$this->object = $this->call(__FUNCTION__, func_get_args());
60-
return $this;
62+
$this->container = $container;
63+
if ($this->object instanceof CloningContainer) {
64+
$this->object = $this->object->cloneInstance($container);
65+
}
66+
return null;
6167
}
6268

63-
public function terminate(ServerRequestInterface $request, ResponseInterface $response = null): void
69+
70+
protected function call($method, $parameters)
6471
{
65-
$this->call(__FUNCTION__, func_get_args());
72+
return call_user_func_array([$this->object, $method], $parameters);
6673
}
6774

6875
}

src/Debug/HttpKernel/RequestHandler.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,24 @@
44
namespace Symbiotic\Develop\Debug\HttpKernel;
55

66

7+
use Psr\Container\ContainerInterface;
8+
use Symbiotic\Container\CloningContainer;
79
use Symbiotic\Develop\Services\Debug\Timer;
810
use Psr\Http\Message\ {ResponseInterface, ServerRequestInterface};
911
use Psr\Http\Server\RequestHandlerInterface;
1012

1113

12-
class RequestHandler implements RequestHandlerInterface
14+
class RequestHandler implements RequestHandlerInterface,CloningContainer
1315
{
14-
/**
15-
* @var RequestHandlerInterface
16-
*/
17-
protected $object;
18-
19-
/**
20-
* @var Timer
21-
*/
22-
protected $timer;
23-
24-
public function __construct(RequestHandlerInterface $object, Timer $timer)
16+
public function __construct(protected RequestHandlerInterface $object, protected ContainerInterface $container)
2517
{
26-
$this->object = $object;
27-
$this->timer = $timer;
2818
}
2919

3020
public function handle(ServerRequestInterface $request): ResponseInterface
3121
{
32-
$name = $this->timer->start(get_class($this->object).'::handle');
22+
$name = $this->container[Timer::class]->start(get_class($this->object).'::handle');
3323
$data = $this->call(__FUNCTION__, func_get_args());
34-
$this->timer->end($name);
24+
$this->container[Timer::class]->end($name);
3525

3626
return $data;
3727
}
@@ -41,5 +31,12 @@ protected function call($method, $parameters)
4131
return call_user_func_array([$this->object, $method], $parameters);
4232
}
4333

34+
public function cloneInstance(?ContainerInterface $container): ?object
35+
{
36+
$new = clone $this;
37+
$new->container = $container;
38+
return $new;
39+
}
40+
4441

4542
}

src/Debug/Packages/PackagesRepository.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,29 @@
22

33
namespace Symbiotic\Develop\Debug\Packages;
44

5-
use Symbiotic\Core\CoreInterface;
5+
use Psr\Container\ContainerInterface;
6+
use Symbiotic\Container\CloningContainer;
67
use Symbiotic\Develop\Services\Debug\Timer;
78
use Symbiotic\Packages\PackageConfig;
89
use Symbiotic\Packages\PackagesLoaderInterface;
910
use Symbiotic\Packages\PackagesRepositoryInterface;
10-
use function _S\core;
1111

12-
class PackagesRepository implements PackagesRepositoryInterface
13-
{
14-
15-
/**
16-
* @var PackagesRepositoryInterface
17-
*/
18-
protected $object;
1912

20-
/**
21-
* @var Timer
22-
*/
23-
protected $timer;
13+
class PackagesRepository implements PackagesRepositoryInterface, CloningContainer
14+
{
2415

2516

26-
public function __construct(PackagesRepositoryInterface $packages)
27-
{
28-
$this->object = $packages;
17+
public function __construct(
18+
protected PackagesRepositoryInterface $object,
19+
protected ContainerInterface $container
20+
) {
2921
}
3022

3123
public function load(): void
3224
{
33-
core(Timer::class)->start('load_packages');
25+
$this->container->get(Timer::class)->start('load_packages');
3426
$this->call(__FUNCTION__, func_get_args());
35-
core(Timer::class)->end('load_packages');
27+
$this->container->get(Timer::class)->end('load_packages');
3628
}
3729

3830
public function has($id): bool
@@ -45,16 +37,16 @@ public function get(string $id): array
4537
return $this->call(__FUNCTION__, func_get_args());
4638
}
4739

48-
public function getPackageConfig(string $id):?PackageConfig
40+
public function getPackageConfig(string $id): ?PackageConfig
4941
{
5042
return $this->call(__FUNCTION__, func_get_args());
5143
}
5244

5345
public function getIds(): array
5446
{
55-
$name = core(Timer::class)->start();
47+
$name = $this->container->get(Timer::class)->start();
5648
$data = $this->call(__FUNCTION__, func_get_args());
57-
core(Timer::class)->end($name);
49+
$this->container->get(Timer::class)->end($name);
5850
return $data;
5951
}
6052

@@ -71,9 +63,9 @@ public function getEventsHandlers(): array
7163

7264
public function all(): array
7365
{
74-
$name = core(Timer::class)->start();
66+
$name = $this->container->get(Timer::class)->start();
7567
$data = $this->call(__FUNCTION__, func_get_args());
76-
core(Timer::class)->end($name);
68+
$this->container->get(Timer::class)->end($name);
7769
return $data;
7870
}
7971

@@ -92,4 +84,13 @@ protected function call($method, $parameters)
9284
return call_user_func_array([$this->object, $method], $parameters);
9385
}
9486

87+
public function cloneInstance(?ContainerInterface $container): ?object
88+
{
89+
$this->container = $container;
90+
if ($this->object instanceof CloningContainer) {
91+
$this->object = $this->object->cloneInstance($container);
92+
}
93+
return null;
94+
}
95+
9596
}

0 commit comments

Comments
 (0)