Skip to content
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
88 changes: 46 additions & 42 deletions docs.md

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@

class Container implements ContainerInterface
{
/**
* @param array $data
*/
public function __construct(protected array $data = []) {}

/**
* @param string $id
* @return mixed
*/
#[\Override]
public function get(string $id): mixed
{
Expand All @@ -33,27 +26,16 @@ public function get(string $id): mixed
: throw new NotFoundException("Identifier \"$id\" is not found.");
}

/**
* @return array
*/
public function all(): array
{
return $this->data;
}

/**
* @param array $data
* @return void
*/
public function set(array $data): void
{
$this->data = array_merge($this->data, $data);
}

/**
* @param string $id
* @return boolean
*/
#[\Override]
public function has(string $id): bool
{
Expand Down
45 changes: 3 additions & 42 deletions src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

class Cookie
{
/**
* Возвращает значение куки по ключу.
*
* @param string $id
* @return mixed
* @throws NotFoundException
*/
public function get(string $id): mixed
{
if (!array_key_exists($id, $_COOKIE)) {
Expand All @@ -30,57 +23,25 @@ public function get(string $id): mixed
return $_COOKIE[$id];
}

/**
* Проверяет, существует ли куки.
*
* @param string $id
* @return bool
*/
public function has(string $id): bool
{
return array_key_exists($id, $_COOKIE);
}

/**
* Удаляет куки.
*
* @param string $id
* @return void
* @throws NotFoundException
*/
public function remove(string $id): void // Переименовано с unset
public function remove(string $id): void
{
if (!array_key_exists($id, $_COOKIE)) {
throw new NotFoundException("Куки с идентификатором \"$id\" не найдено.");
}
$this->deleteCookie($id);
}

/**
* Удаляет куки из суперглобального массива и отправляет заголовок для удаления в браузере.
*
* @param string $id
* @return void
*/
private function deleteCookie(string $id): void
{
unset($_COOKIE[$id]);
setcookie($id, '', time() - 3600, '/'); // Установить время в прошлое
setcookie($id, '', time() - 3600, '/');
}

/**
* Устанавливает куки.
*
* @param string $key Имя куки.
* @param string $value Значение куки.
* @param int $expire Время жизни (timestamp). По умолчанию 0 (до закрытия браузера).
* @param string $path Путь на сервере. По умолчанию '/'.
* @param string|null $domain Домен. По умолчанию null (текущий хост).
* @param bool $secure Использовать HTTPS. По умолчанию false.
* @param bool $httponly Запретить доступ через JS. По умолчанию false.
* @param string $samesite Значение SameSite. По умолчанию 'Lax'.
* @return void
*/
public function set(
string $key,
string $value,
Expand All @@ -93,7 +54,7 @@ public function set(
): void {
$_COOKIE[$key] = $value;

// Используем setcookie с полным набором параметров для безопасности
// We use setcookie with a full set of parameters for security
setcookie($key, $value, [
'expires' => $expire,
'path' => $path,
Expand Down
3 changes: 0 additions & 3 deletions src/Interfaces/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@

interface FactoryInterface
{
/**
* @return object
*/
public function create(): object;
}
27 changes: 0 additions & 27 deletions src/Interfaces/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,11 @@

interface RequestInterface
{
/**
* @return ContainerInterface
*/
public function get(): ContainerInterface;

/**
* @return ContainerInterface
*/
public function post(): ContainerInterface;

/**
* @return ContainerInterface
*/
public function put(): ContainerInterface;

/**
* @return ContainerInterface
*/
public function patch(): ContainerInterface;

/**
* @return ContainerInterface
*/
public function delete(): ContainerInterface;

/**
* @return ContainerInterface
*/
public function server(): ContainerInterface;

/**
* @return ContainerInterface
*/
public function files(): ContainerInterface;
}
4 changes: 0 additions & 4 deletions src/Interfaces/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@

interface ResponseInterface
{
/**
* @param array $data
* @return void
*/
public function json(array $data): void;
}
9 changes: 0 additions & 9 deletions src/Interfaces/RudraInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,5 @@

interface RudraInterface
{
/**
* Implements the Singleton pattern to ensure only one instance of the class is created.
* If the instance does not exist, it creates and stores it. Otherwise, it returns the existing instance.
* -------------------------
* Реализует паттерн Singleton, чтобы гарантировать создание только одного экземпляра класса.
* Если экземпляр не существует, он создаётся и сохраняется. В противном случае возвращается существующий экземпляр.
*
* @return RudraInterface
*/
public static function run(): RudraInterface;
}
29 changes: 3 additions & 26 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,51 @@

namespace Rudra\Container;

use Rudra\Container\{
Container,
Traits\InstantiationsTrait,
Interfaces\RequestInterface,
};
use Rudra\Container\Container;
use Rudra\Container\Traits\InstantiationsTrait;
use Rudra\Container\Interfaces\RequestInterface;
use Psr\Container\ContainerInterface;

class Request implements RequestInterface
{
use InstantiationsTrait;

/**
* @return ContainerInterface
*/
#[\Override]
public function get(): ContainerInterface
{
return $this->containerize("get", Container::class, $_GET);
}

/**
* @return ContainerInterface
*/
#[\Override]
public function post(): ContainerInterface
{
return $this->containerize("post", Container::class, $_POST);
}

/**
* @return ContainerInterface
*/
#[\Override]
public function put(): ContainerInterface
{
return $this->containerize("put", Container::class);
}

/**
* @return ContainerInterface
*/
#[\Override]
public function patch(): ContainerInterface
{
return $this->containerize("patch", Container::class);
}

/**
* @return ContainerInterface
*/
#[\Override]
public function delete(): ContainerInterface
{
return $this->containerize("delete", Container::class);
}

/**
* @return ContainerInterface
*/
#[\Override]
public function server(): ContainerInterface
{
return $this->containerize("server", Container::class, $_SERVER);
}

/**
* @return ContainerInterface
*/
#[\Override]
public function files(): ContainerInterface
{
Expand Down
8 changes: 0 additions & 8 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

class Response implements ResponseInterface
{
/**
* @param array $data
* @return void
*/
#[\Override]
public function json(array $data, int $code = 200): void
{
Expand All @@ -30,10 +26,6 @@ public function json(array $data, int $code = 200): void
print $this->getJson($data);
}

/**
* @param array $data
* @return string
*/
private function getJson(array $data): string
{
return json_encode($data, JSON_UNESCAPED_UNICODE);
Expand Down
Loading
Loading