Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Container/ItemsContainerTrait.php
  • Loading branch information
Sergey Surkov committed Aug 28, 2021
2 parents 1c05c25 + dd138ca commit 9280f20
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 77 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dissonance/full",
"description": "Полная сборка пакетов фреймворка Dissonance.",
"license": "BSD-3-Clause",
"version": "1.1.0",
"version": "1.1.1",
"authors": [{
"name": "Surkov Sergey",
"role": "creator"
Expand Down
10 changes: 5 additions & 5 deletions src/Container/ItemsContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait ItemsContainerTrait /*implements \Dissonance\Container\BaseContainerInterf
*
* @return mixed|null
*/
public function get($key)
public function get(string|int $key)
{
$items = &$this->items;
return $this->hasBy($key,$items) ? $items[$key] :
Expand All @@ -38,7 +38,7 @@ public function get($key)
* @info
* @return bool
*/
public function has($key): bool
public function has(string|int $key): bool
{
return $this->hasBy($key,$this->items);
}
Expand All @@ -49,7 +49,7 @@ public function has($key): bool
* @return bool
* @info
*/
private function hasBy($key, &$items): bool
private function hasBy(string|int $key, array &$items): bool
{
return isset($items[$key]) // isset в 4 раза быстрее array_key_exists
|| (is_array($items) && array_key_exists($key, $items))
Expand All @@ -60,7 +60,7 @@ private function hasBy($key, &$items): bool
* @param int|string $key
* @param $value
*/
public function set($key, $value): void
public function set(string|int $key, $value): void
{
$this->items[$key] = $value;
}
Expand All @@ -70,7 +70,7 @@ public function set($key, $value): void
* @param int|string $key
* @return bool
*/
public function delete($key): bool
public function delete(string|int $key): bool
{
unset($this->items[$key]);

Expand Down
24 changes: 20 additions & 4 deletions src/Container/SubContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public function bind(string $abstract, $concrete = null, bool $shared = false):
// If the abstract type was already resolved in this container we'll fire the
// rebound listener so that any objects which have already gotten resolved
// can have their copy of the object updated via the listener callbacks.
if ($this->resolved($abstract)) {
$alias = $this->getAlias($abstract);
if (isset($this->resolved[$alias]) || isset($this->instances[$alias])) {
$this->rebound($abstract);
}

Expand All @@ -184,6 +185,16 @@ public function rebinding(string $abstract, Closure $callback)
public function resolve(string $abstract, array $parameters = [], bool $raiseEvents = true)
{
$alias = $this->getAlias($abstract);
/// сначала получаем по ключу у нас
/// иначе вернет из ядра по алиасу
/// проблема одноименнных сервисов с алиасами
if (!$parameters && isset($this->instances[$abstract])) {
return $this->instances[$abstract];
}
if (isset($this->bindings[$abstract])) {
return $this->app->build($this->bindings[$abstract]['concrete']);
}
// передаем родителю
if (!$parameters && isset($this->instances[$alias])) {
return $this->instances[$alias];
}
Expand Down Expand Up @@ -363,8 +374,10 @@ public function resolving($abstract, callable $callback = null)
if (is_string($abstract)) {
$abstract = $this->getAlias($abstract);
}

$this->app->resolving($abstract, $callback);
// нам не нужен чужой контейнер, ставим текущий
$this->app->resolving($abstract, function (object $object, $app) use ($callback) {
return $callback($object, $this);
});
}

/**
Expand All @@ -380,7 +393,10 @@ public function afterResolving($abstract, callable $callback = null)
$abstract = $this->getAlias($abstract);
}

$this->app->afterResolving($abstract, $callback);
// нам не нужен чужой контейнер, ставим текущий
$this->app->afterResolving($abstract, function (object $object, $app) use ($callback) {
return $callback($object, $this);
});
}


Expand Down
1 change: 0 additions & 1 deletion src/Core/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public static function registerNamespaces()
protected static function loadPackages($dir)
{
/*foreach(new \DirectoryIterator($dir) as $fileInfo) {*/

$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_SELF));
$iterator->setMaxDepth(2);
foreach ($iterator as $fileInfo) {
Expand Down
9 changes: 1 addition & 8 deletions src/Core/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,7 @@ public function fetch($content)

protected function getTemplate()
{
return
'use function ' . __NAMESPACE__ . '\\app;
use function ' . __NAMESPACE__ . '\\asset;
use function ' . __NAMESPACE__ . '\\route;
use function ' . __NAMESPACE__ . '\\css;
use function ' . __NAMESPACE__ . '\\js;
?>' . $this->template;
return 'use function ' . __NAMESPACE__ . '\\app,asset,route,css,js,adminRoute,apiRoute;'.PHP_EOL.' ?>' . $this->template;
}

public function __toString()
Expand Down
38 changes: 34 additions & 4 deletions src/Http/Kernel/HttpRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function run(): void
* @var CoreInterface $app
*/
$app = $this->app;
$symbiosis = \_DS\config('symbiosis',false);
try {
$request_interface = ServerRequestInterface::class;
$request = $app[PsrHttpFactory::class]->createServerRequestFromGlobals();
Expand Down Expand Up @@ -54,25 +55,49 @@ public function run(): void
})
);
$response = $handler->handle($request);

// Определяем нужно ли отдавать ответ
if (!$app('destroy_response', false) || !\_DS\config('symbiosis')) {
if (!$app('destroy_response', false) || !$symbiosis) {
$this->sendResponse($response);
// при режиме симбиоза не даем другим скриптам продолжить работу, т.к. отдали наш ответ
if (\_DS\config('symbiosis')) {
if ($symbiosis) {
exit;// завершаем работу
}
} else {
// Открываем проксирование буфера через нас
}

} catch (\Throwable $e) {
// при режиме симбиоза не отдаем ответ с ошибкой, запишем выше в лог
if (!\_DS\config('symbiosis')) {
if (!$symbiosis) {
$this->sendResponse($app[HttpKernelInterface::class]->response(500, $e));
} else {
// TODO:
// TODO:log
}
}
}


/**
* Laravel close buffers
* @param int $targetLevel
* @param bool $flush
*/
public static function closeOutputBuffers(int $targetLevel, bool $flush): void
{
$status = ob_get_status(true);
$level = \count($status);
$flags = \PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? \PHP_OUTPUT_HANDLER_FLUSHABLE : \PHP_OUTPUT_HANDLER_CLEANABLE);

while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) {
if ($flush) {
ob_end_flush();
} else {
ob_end_clean();
}
}
}

protected function prepareBaseUrl(ServerRequestInterface $request): string
{
$server = $request->getServerParams();
Expand Down Expand Up @@ -106,6 +131,11 @@ public function sendResponse(ResponseInterface $response)
{
$sender = new ResponseSender($response);
$sender->render();
if (\function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
} elseif (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
static::closeOutputBuffers(0, true);
}
}

}
2 changes: 1 addition & 1 deletion src/SimpleCacheFilesystem/SimpleCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(string $cache_directory, int $default_ttl = 600)
{
if (!is_dir($cache_directory)) {
$uMask = umask(0);
mkdir($cache_directory, 0755, true);
@mkdir($cache_directory, 0755, true);
umask($uMask);
}
if (!is_dir($cache_directory) || !is_writable($cache_directory)) {
Expand Down
1 change: 0 additions & 1 deletion src/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'storage_path' => $basePath . '/storage', // Если убрать то кеш отключится
'packages_paths' => [
$basePath . '/vendor', // Папка для приложений
$basePath . '/modules', // Папка для приложений
],
'bootstrappers' => [
\Dissonance\Develop\Bootstrap\DebugBootstrap::class,/// debug only
Expand Down
Loading

0 comments on commit 9280f20

Please sign in to comment.