Skip to content

Commit

Permalink
Merge pull request #474 from bluzphp/develop
Browse files Browse the repository at this point in the history
Migrate to Symfony/Cache
  • Loading branch information
Anton authored Jul 5, 2021
2 parents e47c194 + ddb31d2 commit 3aaaf2c
Show file tree
Hide file tree
Showing 64 changed files with 363 additions and 358 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"ext-json": "*",
"ext-ctype": "*",
"bluzphp/collection": "~1.0",
"cache/cache": "~1.0",
"psr/log": "~1.1",
"laminas/laminas-diactoros": "~2.6",
"laminas/laminas-httphandlerrunner": "~1.4"
"laminas/laminas-httphandlerrunner": "~1.4",
"symfony/cache": "^5.3"
},
"require-dev": {
"codeception/codeception": "~4.1",
Expand All @@ -27,7 +27,7 @@
"ext-redis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)",
"ext-memcached": "required by Memcached adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)",
"phpmailer/phpmailer": "required by Bluz\\Mailer (https://github.com/bluzphp/framework/wiki/Mailer)",
"predis/predis": "required by Cache\\Adapter\\Predis (https://github.com/bluzphp/framework/wiki/Cache)"
"predis/predis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function getEnvironment(): string
* Get path to Application
*
* @return string
* @throws ReflectionException
*/
public function getPath(): string
{
Expand Down Expand Up @@ -180,7 +179,6 @@ public function init(string $environment = 'production'): void
*
* @return void
* @throws ConfigException
* @throws ReflectionException
*/
protected function initConfig(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ trait Options
/**
* @var array options store
*/
protected $options;
protected $options = [];

/**
* Get option by key
Expand Down Expand Up @@ -105,7 +105,7 @@ public function getOptions(): array
*
* @return void
*/
public function setOptions(array $options = null): void
public function setOptions(?array $options = null): void
{
// store options by default
$this->options = (array)$options;
Expand Down
5 changes: 4 additions & 1 deletion src/Db/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ public static function findWhere(...$where): array
$whereAndTerms[] = $self->name . '.' . $keyName . ' IN (' . $keyValue . ')';
} elseif (null === $keyValue) {
$whereAndTerms[] = $self->name . '.' . $keyName . ' IS NULL';
} elseif (is_string($keyValue) && ('%' === $keyValue{0} || '%' === $keyValue{-1})) {
} elseif (
is_string($keyValue)
&& ('%' === substr($keyValue, 0, 1) || '%' === substr($keyValue, -1, 1))
) {
$whereAndTerms[] = $self->name . '.' . $keyName . ' LIKE ?';
$whereParams[] = $keyValue;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/EventManager/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ public function getParam($name, $default = null)
/**
* Set the event name
*
* @param string $name
* @param string $name
*
* @return void
*/
public function setName($name): void
public function setName(string $name): void
{
$this->name = (string)$name;
$this->name = $name;
}

/**
Expand Down
28 changes: 14 additions & 14 deletions src/Http/CacheControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CacheControl
*
* @param Response $response
*/
public function __construct($response)
public function __construct(Response $response)
{
$this->response = $response;
}
Expand Down Expand Up @@ -135,11 +135,11 @@ public function getMaxAge(): ?int
*
* This methods sets the Cache-Control max-age directive.
*
* @param integer $value Number of seconds
* @param integer $value Number of seconds
*
* @return void
*/
public function setMaxAge($value): void
public function setMaxAge(int $value): void
{
$this->doSetContainer('max-age', $value);
$this->updateCacheControlHeader();
Expand All @@ -150,11 +150,11 @@ public function setMaxAge($value): void
*
* This methods sets the Cache-Control s-maxage directive.
*
* @param integer $value Number of seconds
* @param integer $value Number of seconds
*
* @return void
*/
public function setSharedMaxAge($value): void
public function setSharedMaxAge(int $value): void
{
$this->setPublic();
$this->doSetContainer('s-maxage', $value);
Expand Down Expand Up @@ -183,11 +183,11 @@ public function getTtl(): ?int
*
* This method adjusts the Cache-Control/s-maxage directive.
*
* @param integer $seconds Number of seconds
* @param integer $seconds Number of seconds
*
* @return void
*/
public function setTtl($seconds): void
public function setTtl(int $seconds): void
{
$this->setSharedMaxAge($this->getAge() + $seconds);
}
Expand All @@ -197,11 +197,11 @@ public function setTtl($seconds): void
*
* This method adjusts the Cache-Control/max-age directive.
*
* @param integer $seconds Number of seconds
* @param integer $seconds Number of seconds
*
* @return void
*/
public function setClientTtl($seconds): void
public function setClientTtl(int $seconds): void
{
$this->setMaxAge($this->getAge() + $seconds);
}
Expand All @@ -219,12 +219,12 @@ public function getEtag(): string
/**
* Sets the ETag value
*
* @param string $etag The ETag unique identifier
* @param bool $weak Whether you want a weak ETag or not
* @param string $etag The ETag unique identifier
* @param bool $weak Whether you want a weak ETag or not
*
* @return void
*/
public function setEtag($etag, $weak = false): void
public function setEtag(string $etag, bool $weak = false): void
{
$etag = trim($etag, '"');
$this->response->setHeader('ETag', (true === $weak ? 'W/' : '') . '"' . $etag . '"');
Expand All @@ -246,11 +246,11 @@ public function getAge(): int
/**
* Set the age of the response
*
* @param integer $age
* @param integer $age
*
* @return void
*/
public function setAge($age): void
public function setAge(int $age): void
{
$this->response->setHeader('Age', $age);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Layout/Helper/HeadScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* Set or generate <script> code for <head>
*
* @param string $src
* @param array $attributes
* @param string|null $src
* @param array $attributes
*
* @return null|string
*/
return
function ($src = null, array $attributes = []) {
function (?string $src = null, array $attributes = []) {
/**
* @var Layout $this
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Layout/Helper/HeadStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* Set or generate <style> code for <head>
*
* @param string $href
* @param string $media
* @param string|null $href
* @param string $media
*
* @return string|null
*/
return
function ($href = null, $media = 'all') {
function (?string $href = null, string $media = 'all') {
/**
* @var Layout $this
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Layout/Helper/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
/**
* Set or generate <link> code for <head>
*
* @param array $link
* @param array|null $link
*
* @return string|null
*/
return
function (array $link = null) {
function (?array $link = null) {
/**
* @var Layout $this
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Layout/Helper/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
/**
* Set or generate <meta> code for <head>
*
* @param string|array|null $name
* @param string|null $content
* @param string|array|null $name
* @param string|null $content
*
* @return string|null
*/
return
function ($name = null, $content = null) {
function ($name = null, ?string $content = null) {
// it's stack for <head>
$meta = Registry::get('layout:meta') ?: [];

Expand Down
4 changes: 2 additions & 2 deletions src/Layout/Helper/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
/**
* Set or generate <title> code for <head>
*
* @param string $title
* @param string|null $title
*
* @return string
*/
return
function ($title = null) {
function (?string $title = null) {
// it's stack for <title> tag
if (null === $title) {
return Registry::get('layout:title');
Expand Down
6 changes: 3 additions & 3 deletions src/Layout/Helper/TitleAppend.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* Set or generate <title> code for <head>
*
* @param string $title
* @param string $separator
* @param string $title
* @param string $separator
*
* @return string
*/
return
function ($title, $separator = ' :: ') {
function (string $title, string $separator = ' :: ') {
// it's stack for <title> tag
$oldTitle = Registry::get('layout:title');
$result = (!$oldTitle ?: $oldTitle . $separator) . $title;
Expand Down
6 changes: 3 additions & 3 deletions src/Layout/Helper/TitlePrepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* Set or generate <title> code for <head>
*
* @param string $title
* @param string $separator
* @param string $title
* @param string $separator
*
* @return string
*/
return
function ($title, $separator = ' :: ') {
function (string $title, string $separator = ' :: ') {
// it's stack for <title> tag
$oldTitle = Registry::get('layout:title');
$result = $title . (!$oldTitle ?: $separator . $oldTitle);
Expand Down
2 changes: 1 addition & 1 deletion src/Logger/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Logger extends AbstractLogger
*
* @return string
*/
protected function interpolate($message, array $context = []): string
protected function interpolate(string $message, array $context = []): string
{
// build a replacement array with braces around the context keys
$replace = [];
Expand Down
24 changes: 12 additions & 12 deletions src/Messages/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,67 +44,67 @@ class Messages
/**
* Add notice
*
* @param string $message
* @param string $message
* @param string[] $text
*
* @return void
* @since 1.0.0 added $text
*/
public function addNotice($message, ...$text): void
public function addNotice(string $message, ...$text): void
{
$this->add(self::TYPE_NOTICE, $message, ...$text);
}

/**
* Add success
*
* @param string $message
* @param string $message
* @param string[] $text
*
* @return void
* @since 1.0.0 added $text
*/
public function addSuccess($message, ...$text): void
public function addSuccess(string $message, ...$text): void
{
$this->add(self::TYPE_SUCCESS, $message, ...$text);
}

/**
* Add error
*
* @param string $message
* @param string $message
* @param string[] $text
*
* @return void
* @since 1.0.0 added $text
*/
public function addError($message, ...$text): void
public function addError(string $message, ...$text): void
{
$this->add(self::TYPE_ERROR, $message, ...$text);
}

/**
* Add message to container
*
* @param string $type One of error, notice or success
* @param string $message
* @param string $type One of error, notice or success
* @param string $message
* @param string[] $text
*
* @return void
*/
protected function add($type, $message, ...$text): void
protected function add(string $type, string $message, ...$text): void
{
$this->getMessagesStore()[$type][] = Translator::translate($message, ...$text);
}

/**
* Pop a message by type
*
* @param string $type
* @param string $type
*
* @return stdClass|null
*/
public function pop($type): ?stdClass
public function pop(string $type): ?stdClass
{
$text = array_shift($this->getMessagesStore()[$type]);
if ($text) {
Expand All @@ -119,7 +119,7 @@ public function pop($type): ?stdClass
/**
* Pop all messages
*
* @return ArrayObject|array
* @return array
*/
public function popAll()
{
Expand Down
Loading

0 comments on commit 3aaaf2c

Please sign in to comment.