Skip to content

Commit

Permalink
Merge pull request #63 from ofernandezcr92/php-8.1.18
Browse files Browse the repository at this point in the history
Adding support to php 8.1.18
  • Loading branch information
stevevega authored Apr 24, 2023
2 parents 950e17b + a8589d9 commit df2cce2
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 96 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"homepage": "https://github.com/stevevega/kima",
"license": "BSD-3-Clause",
"require": {
"php": ">=7.4",
"mongodb/mongodb": "^1.7.0",
"datadog/dd-trace": ">=0.48.0"
"php": ">=8.1",
"mongodb/mongodb": "^1.15.0",
"datadog/dd-trace": ">=0.86.3"
},
"autoload": {
"psr-0": {
Expand Down
12 changes: 6 additions & 6 deletions library/Kima/Cache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Redis extends PhpRedis implements ICache
*/
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = 6379;
const DEFAULT_TIMEOUT = null;
const DEFAULT_TIMEOUT = 0;

/**
* Connection type
Expand Down Expand Up @@ -191,14 +191,14 @@ public function set($key, $value, $expiration = 0)
/**
* Connects to a redis server
*
* @param string $host
* @param string $port
* @param string $timeout
* @param int|null $retry_interval
* @param string $host
* @param int $port
* @param int $timeout
* @param int $retry_interval
*
* @return bool
*/
public function connect($host, $port = null, $timeout = null, $retry_interval = null)
public function connect($host, $port = 6379, $timeout = 0, $retry_interval = 0)
{
$this->connection_type === self::PERSISTENT
? parent::pconnect($host, $port, $timeout, $retry_interval)
Expand Down
50 changes: 35 additions & 15 deletions library/Kima/L10n.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* Kima L10n
*
* @author Steve Vega
*/
namespace Kima;
Expand All @@ -12,44 +13,49 @@
*/
class L10n
{

/**
* Error messages
*/
const ERROR_INVALID_STRINGS_PATH = 'Cannot access strings path "%s"';

/**
* The strings used on this action
*
* @var array
*/
protected static $strings;

/**
* The cache key
*
* @var string
*/
protected static $cache_key;

/**
* The prefix of the cache key
*
* @var string
*/
protected static $cache_key_prefix;

/**
* Array with the paths of the l10n resources.
*
* @var array
*/
protected static $l10n_paths = [];

/**
* Flag that indicates if store the keys
* @var boolean
*
* @var bool
*/
protected static $store_keys = true;

/**
* Sets the value of store_keys
*
* @param bool $store_keys
*/
public static function set_store_keys($store_keys)
Expand All @@ -59,6 +65,7 @@ public static function set_store_keys($store_keys)

/**
* Sets the value of l10n_paths
*
* @param array $paths
*/
public static function set_l10n_paths(array $paths)
Expand All @@ -68,6 +75,7 @@ public static function set_l10n_paths(array $paths)

/**
* Sets the value of cache key prefix
*
* @param string $prefix
*/
public static function set_cache_key_prefix($prefix)
Expand All @@ -77,9 +85,11 @@ public static function set_cache_key_prefix($prefix)

/**
* Gets the key wanted for translation
* @param string $key
* @param array $args
* @param string $language
*
* @param string $key
* @param array $args
* @param string $language
*
* @return string
*/
public static function t($key, array $args = [], $language = '')
Expand All @@ -91,7 +101,8 @@ public static function t($key, array $args = [], $language = '')

// check if we do have the language strings loaded
if (empty(self::$strings[$language]) || !self::$store_keys) {
$controller = strtolower($app->get_controller());
$app_controller = $app->get_controller() ?? '';
$controller = strtolower($app_controller);
$method = $app->get_method();

// get the string path and sets the cache key
Expand Down Expand Up @@ -125,8 +136,10 @@ public static function t($key, array $args = [], $language = '')
/**
* Validates whether there is any change in data of the files stored cached.
* Using the timestamp of the file and cache.
* @param array $strings_paths
* @return boolean
*
* @param array $strings_paths
*
* @return bool
*/
private static function is_valid_strings_paths_timestamp(array $strings_paths)
{
Expand All @@ -143,7 +156,9 @@ private static function is_valid_strings_paths_timestamp(array $strings_paths)

/**
* Gets the strings paths for the current language
* @param string $language
*
* @param string $language
*
* @return array
*/
private static function get_strings_paths($language)
Expand All @@ -169,9 +184,11 @@ private static function get_strings_paths($language)
/**
* Retrieves and parse the language strings from the l10n string files
* Sets the strings on cache
* @param string $controller
* @param string $method
* @param array $strings_paths
*
* @param string $controller
* @param string $method
* @param array $strings_paths
*
* @return array
*/
private static function get_strings($controller, $method, array $strings_paths)
Expand All @@ -198,7 +215,7 @@ private static function get_strings($controller, $method, array $strings_paths)

$method_strings = array_merge(
$method_strings,
self::get_section_strings($strings_data, $controller . '-'. $method)
self::get_section_strings($strings_data, $controller . '-' . $method)
);
}
}
Expand All @@ -213,8 +230,10 @@ private static function get_strings($controller, $method, array $strings_paths)

/**
* Gets the strings data for a section
* @param array $strings_data
* @param string $section
*
* @param array $strings_data
* @param string $section
*
* @return array
*/
private static function get_section_strings(array $strings_data, $section)
Expand All @@ -228,6 +247,7 @@ private static function get_section_strings(array $strings_data, $section)

/**
* Sets the cache key for the strings
*
* @param string $language
* @param string $controller
* @param string $method
Expand Down
Loading

0 comments on commit df2cce2

Please sign in to comment.