Added functional-php library

This commit is contained in:
Alejandro Celaya
2018-11-02 10:54:42 +01:00
parent 6986d03c53
commit 521f6f2b18
8 changed files with 17 additions and 21 deletions

View File

@@ -6,8 +6,8 @@ namespace Shlinkio\Shlink\Common;
use const ARRAY_FILTER_USE_KEY;
use const JSON_ERROR_NONE;
use function array_filter;
use function Functional\contains;
use function getenv;
use function in_array;
use function json_decode as spl_json_decode;
use function json_last_error;
use function json_last_error_msg;
@@ -49,11 +49,6 @@ function env($key, $default = null)
return trim($value);
}
function contains($needle, array $haystack): bool
{
return in_array($needle, $haystack, true);
}
/**
* Returns only the keys in keysToPick from provided array
*
@@ -63,7 +58,7 @@ function contains($needle, array $haystack): bool
function pick(array $array, array $keysToPick): array
{
return array_filter($array, function (string $key) use ($keysToPick) {
return contains($key, $keysToPick);
return contains($keysToPick, $key);
}, ARRAY_FILTER_USE_KEY);
}

View File

@@ -11,7 +11,7 @@ use Shlinkio\Shlink\Core\Options\AppOptions;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\Factory\FactoryInterface;
use function Shlinkio\Shlink\Common\contains;
use function Functional\contains;
use function Shlinkio\Shlink\Common\env;
class CacheFactory implements FactoryInterface
@@ -53,7 +53,7 @@ class CacheFactory implements FactoryInterface
{
// Try to get the adapter from config
$config = $container->get('config');
if (isset($config['cache']['adapter']) && contains($config['cache']['adapter'], self::VALID_CACHE_ADAPTERS)) {
if (isset($config['cache']['adapter']) && contains(self::VALID_CACHE_ADAPTERS, $config['cache']['adapter'])) {
return $this->resolveCacheAdapter($config['cache']);
}