mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 15:16:33 +02:00
Simplify QFN
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use Closure;
|
||||
use Grav\Common\Assets\Pipeline;
|
||||
use Grav\Common\Assets\Traits\LegacyAssetsTrait;
|
||||
use Grav\Common\Assets\Traits\TestingAssetsTrait;
|
||||
@@ -81,7 +82,7 @@ class Assets extends PropertyObject
|
||||
/** @var array */
|
||||
protected $pipeline_options = [];
|
||||
|
||||
/** @var \Closure|string */
|
||||
/** @var Closure|string */
|
||||
protected $fetch_command;
|
||||
/** @var string */
|
||||
protected $autoload;
|
||||
|
||||
@@ -15,6 +15,8 @@ use Grav\Common\Grav;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\Object\PropertyObject;
|
||||
use MatthiasMullie\Minify\CSS;
|
||||
use MatthiasMullie\Minify\JS;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use function array_key_exists;
|
||||
|
||||
@@ -131,7 +133,7 @@ class Pipeline extends PropertyObject
|
||||
|
||||
// Minify if required
|
||||
if ($this->shouldMinify('css')) {
|
||||
$minifier = new \MatthiasMullie\Minify\CSS();
|
||||
$minifier = new CSS();
|
||||
$minifier->add($buffer);
|
||||
$buffer = $minifier->minify();
|
||||
}
|
||||
@@ -194,7 +196,7 @@ class Pipeline extends PropertyObject
|
||||
|
||||
// Minify if required
|
||||
if ($this->shouldMinify('js')) {
|
||||
$minifier = new \MatthiasMullie\Minify\JS();
|
||||
$minifier = new JS();
|
||||
$minifier->add($buffer);
|
||||
$buffer = $minifier->minify();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Grav\Common\Assets\Traits;
|
||||
use Closure;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use function dirname;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
|
||||
@@ -80,7 +81,7 @@ trait AssetUtilsTrait
|
||||
if (0 === strpos($link, '//')) {
|
||||
$link = 'http:' . $link;
|
||||
}
|
||||
$relative_dir = \dirname($relative_path);
|
||||
$relative_dir = dirname($relative_path);
|
||||
} else {
|
||||
// Fix to remove relative dir if grav is in one
|
||||
if (($this->base_url !== '/') && Utils::startsWith($relative_path, $this->base_url)) {
|
||||
@@ -88,7 +89,7 @@ trait AssetUtilsTrait
|
||||
$relative_path = ltrim(preg_replace($base_url, '/', $link, 1), '/');
|
||||
}
|
||||
|
||||
$relative_dir = \dirname($relative_path);
|
||||
$relative_dir = dirname($relative_path);
|
||||
$link = ROOT_DIR . $relative_path;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use function donatj\UserAgent\parse_user_agent;
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,7 @@ class Browser
|
||||
{
|
||||
try {
|
||||
$this->useragent = parse_user_agent();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->useragent = parse_user_agent("Mozilla/5.0 (compatible; Unknown;)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace Grav\Common\Config;
|
||||
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use function is_callable;
|
||||
|
||||
/**
|
||||
* Class CompiledConfig
|
||||
@@ -68,7 +69,7 @@ class CompiledConfig extends CompiledBase
|
||||
*/
|
||||
protected function createObject(array $data = [])
|
||||
{
|
||||
if ($this->withDefaults && empty($data) && \is_callable($this->callable)) {
|
||||
if ($this->withDefaults && empty($data) && is_callable($this->callable)) {
|
||||
$blueprints = $this->callable;
|
||||
$data = $blueprints()->getDefaults();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Grav\Common\Grav;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Service\ConfigServiceProvider;
|
||||
use Grav\Common\Utils;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* Class Config
|
||||
@@ -130,7 +131,7 @@ class Config extends Data
|
||||
{
|
||||
$setup = Grav::instance()['setup']->toArray();
|
||||
foreach ($setup as $key => $value) {
|
||||
if ($key === 'streams' || !\is_array($value)) {
|
||||
if ($key === 'streams' || !is_array($value)) {
|
||||
// Optimized as streams and simple values are fully defined in setup.
|
||||
$this->items[$key] = $value;
|
||||
} else {
|
||||
|
||||
@@ -23,6 +23,7 @@ use function is_array;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Class Blueprint
|
||||
@@ -387,7 +388,7 @@ class Blueprint extends BlueprintForm
|
||||
$context = $this->context;
|
||||
}
|
||||
|
||||
if ($context && $context[\strlen($context)-1] !== '/') {
|
||||
if ($context && $context[strlen($context)-1] !== '/') {
|
||||
$context .= '/';
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
namespace Grav\Common\Data;
|
||||
|
||||
use ArrayAccess;
|
||||
use Exception;
|
||||
use JsonSerializable;
|
||||
use RocketTheme\Toolbox\ArrayTraits\Countable;
|
||||
use RocketTheme\Toolbox\ArrayTraits\Export;
|
||||
use RocketTheme\Toolbox\ArrayTraits\ExportInterface;
|
||||
@@ -25,7 +27,7 @@ use function is_object;
|
||||
* Class Data
|
||||
* @package Grav\Common\Data
|
||||
*/
|
||||
class Data implements DataInterface, \ArrayAccess, \Countable, \JsonSerializable, ExportInterface
|
||||
class Data implements DataInterface, ArrayAccess, \Countable, JsonSerializable, ExportInterface
|
||||
{
|
||||
use NestedArrayAccessWithGetters, Countable, Export;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ use function is_bool;
|
||||
use function is_float;
|
||||
use function is_int;
|
||||
use function is_string;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Class Validation
|
||||
@@ -238,16 +239,16 @@ class Validation
|
||||
$value = trim($value);
|
||||
}
|
||||
|
||||
if (isset($params['min']) && \strlen($value) < $params['min']) {
|
||||
if (isset($params['min']) && strlen($value) < $params['min']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($params['max']) && \strlen($value) > $params['max']) {
|
||||
if (isset($params['max']) && strlen($value) > $params['max']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$min = $params['min'] ?? 0;
|
||||
if (isset($params['step']) && (\strlen($value) - $min) % $params['step'] === 0) {
|
||||
if (isset($params['step']) && (strlen($value) - $min) % $params['step'] === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
namespace Grav\Common\Data;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class ValidationException
|
||||
* @package Grav\Common\Data
|
||||
*/
|
||||
class ValidationException extends \RuntimeException
|
||||
class ValidationException extends RuntimeException
|
||||
{
|
||||
/** @var array */
|
||||
protected $messages = [];
|
||||
|
||||
@@ -36,12 +36,14 @@ use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use ReflectionObject;
|
||||
use SplFileInfo;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Throwable;
|
||||
use Twig\Environment;
|
||||
use Twig\Template;
|
||||
use Twig\TemplateWrapper;
|
||||
use function array_slice;
|
||||
use function call_user_func;
|
||||
use function count;
|
||||
use function define;
|
||||
use function defined;
|
||||
@@ -837,7 +839,7 @@ class Debugger
|
||||
{
|
||||
if ($errno !== E_USER_DEPRECATED && $errno !== E_DEPRECATED) {
|
||||
if ($this->errorHandler) {
|
||||
return \call_user_func($this->errorHandler, $errno, $errstr, $errfile, $errline);
|
||||
return call_user_func($this->errorHandler, $errno, $errstr, $errfile, $errline);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -870,7 +872,7 @@ class Debugger
|
||||
foreach ($backtrace as $current) {
|
||||
if (isset($current['args'])) {
|
||||
foreach ($current['args'] as $arg) {
|
||||
if ($arg instanceof \SplFileInfo) {
|
||||
if ($arg instanceof SplFileInfo) {
|
||||
$arg = $arg->getPathname();
|
||||
}
|
||||
if (is_string($arg) && preg_match('/.+\.(yaml|md)$/i', $arg)) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common\Errors;
|
||||
|
||||
use ErrorException;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Whoops\Handler\Handler;
|
||||
@@ -49,7 +50,7 @@ class SimplePageHandler extends Handler
|
||||
}
|
||||
$message = $inspector->getException()->getMessage();
|
||||
|
||||
if ($inspector->getException() instanceof \ErrorException) {
|
||||
if ($inspector->getException() instanceof ErrorException) {
|
||||
$code = Misc::translateErrorCode($code);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Common\Flex\Types\Pages;
|
||||
|
||||
use Exception;
|
||||
use Grav\Common\Flex\Traits\FlexCollectionTrait;
|
||||
use Grav\Common\Flex\Traits\FlexGravTrait;
|
||||
use Grav\Common\Grav;
|
||||
@@ -432,7 +433,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
* @param string|false $endDate
|
||||
* @param string|null $field
|
||||
* @return static
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dateRange($startDate, $endDate = false, $field = null)
|
||||
{
|
||||
@@ -771,7 +772,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
* Get the extended version of this Collection with each page keyed by route
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function toExtendedArray(): array
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ use Grav\Framework\Flex\FlexDirectory;
|
||||
use Grav\Framework\Flex\Interfaces\FlexCollectionInterface;
|
||||
use Grav\Framework\Flex\Interfaces\FlexStorageInterface;
|
||||
use Grav\Framework\Flex\Pages\FlexPageIndex;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
@@ -652,7 +653,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
|
||||
* @param PageInterface|string|null $key
|
||||
*
|
||||
* @return $this
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function remove($key = null)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ use Grav\Common\Language\Language;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Utils;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use SplFileInfo;
|
||||
|
||||
/**
|
||||
* Implements PageTranslateInterface
|
||||
@@ -75,7 +76,7 @@ trait PageTranslateTrait
|
||||
|
||||
// FIXME: use flex, also rawRoute() does not fully work?
|
||||
$aPage = new Page();
|
||||
$aPage->init(new \SplFileInfo($path), $languageExtension);
|
||||
$aPage->init(new SplFileInfo($path), $languageExtension);
|
||||
if ($onlyPublished && !$aPage->published()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Grav\Common\Flex\Types\Users\Traits;
|
||||
|
||||
use Grav\Common\Page\Medium\ImageMedium;
|
||||
use Grav\Common\Page\Medium\StaticImageMedium;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Trait UserObjectLegacyTrait
|
||||
@@ -87,6 +88,6 @@ trait UserObjectLegacyTrait
|
||||
{
|
||||
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6', E_USER_DEPRECATED);
|
||||
|
||||
return \count($this->jsonSerialize());
|
||||
return count($this->jsonSerialize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Common\Flex\Types\Users;
|
||||
|
||||
use Countable;
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Flex\Traits\FlexGravTrait;
|
||||
@@ -65,7 +66,7 @@ use function is_object;
|
||||
* @property bool $authenticated
|
||||
* @property bool $authorized
|
||||
*/
|
||||
class UserObject extends FlexObject implements UserInterface, \Countable
|
||||
class UserObject extends FlexObject implements UserInterface, Countable
|
||||
{
|
||||
use FlexGravTrait;
|
||||
use FlexObjectTrait;
|
||||
|
||||
@@ -17,6 +17,7 @@ use Grav\Common\Iterator;
|
||||
use Grav\Common\Utils;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
use function in_array;
|
||||
@@ -728,7 +729,7 @@ class GPM extends Iterator
|
||||
$type = 'plugins';
|
||||
}
|
||||
|
||||
$not_found = new \stdClass();
|
||||
$not_found = new stdClass();
|
||||
$not_found->name = $inflector::camelize($search);
|
||||
$not_found->slug = $search;
|
||||
$not_found->package_type = $type;
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Grav\Common\GPM;
|
||||
use DirectoryIterator;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\Grav;
|
||||
use RuntimeException;
|
||||
use ZipArchive;
|
||||
use function count;
|
||||
use function in_array;
|
||||
@@ -274,7 +275,7 @@ class Installer
|
||||
public static function copyInstall($source_path, $install_path)
|
||||
{
|
||||
if (empty($source_path)) {
|
||||
throw new \RuntimeException("Directory $source_path is missing");
|
||||
throw new RuntimeException("Directory $source_path is missing");
|
||||
}
|
||||
|
||||
Folder::rcopy($source_path, $install_path);
|
||||
|
||||
@@ -17,7 +17,9 @@ use Symfony\Component\HttpClient\Exception\TransportException;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Component\HttpClient\HttpOptions;
|
||||
use Symfony\Component\HttpClient\NativeHttpClient;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use function call_user_func;
|
||||
use function defined;
|
||||
use function function_exists;
|
||||
|
||||
/**
|
||||
@@ -40,7 +42,7 @@ class Response
|
||||
* @param array $overrides An array of parameters for both `curl` and `fopen`
|
||||
* @param callable|null $callback Either a function or callback in array notation
|
||||
* @return string The response of the request
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public static function get($uri = '', $overrides = [], $callback = null)
|
||||
{
|
||||
@@ -57,7 +59,7 @@ class Response
|
||||
}
|
||||
|
||||
$config = Grav::instance()['config'];
|
||||
$referer = \defined('GRAV_CLI') ? 'grav_cli' : Grav::instance()['uri']->rootUrl(true);
|
||||
$referer = defined('GRAV_CLI') ? 'grav_cli' : Grav::instance()['uri']->rootUrl(true);
|
||||
$options = new HttpOptions();
|
||||
|
||||
// Set default Headers
|
||||
|
||||
@@ -29,6 +29,21 @@ use Grav\Common\Processors\TasksProcessor;
|
||||
use Grav\Common\Processors\ThemesProcessor;
|
||||
use Grav\Common\Processors\TwigProcessor;
|
||||
use Grav\Common\Scheduler\Scheduler;
|
||||
use Grav\Common\Service\AccountsServiceProvider;
|
||||
use Grav\Common\Service\AssetsServiceProvider;
|
||||
use Grav\Common\Service\BackupsServiceProvider;
|
||||
use Grav\Common\Service\ConfigServiceProvider;
|
||||
use Grav\Common\Service\ErrorServiceProvider;
|
||||
use Grav\Common\Service\FilesystemServiceProvider;
|
||||
use Grav\Common\Service\FlexServiceProvider;
|
||||
use Grav\Common\Service\InflectorServiceProvider;
|
||||
use Grav\Common\Service\LoggerServiceProvider;
|
||||
use Grav\Common\Service\OutputServiceProvider;
|
||||
use Grav\Common\Service\PagesServiceProvider;
|
||||
use Grav\Common\Service\RequestServiceProvider;
|
||||
use Grav\Common\Service\SessionServiceProvider;
|
||||
use Grav\Common\Service\StreamsServiceProvider;
|
||||
use Grav\Common\Service\TaskServiceProvider;
|
||||
use Grav\Common\Twig\Twig;
|
||||
use Grav\Framework\DI\Container;
|
||||
use Grav\Framework\Psr7\Response;
|
||||
@@ -41,6 +56,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use function array_key_exists;
|
||||
use function call_user_func_array;
|
||||
use function function_exists;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
use function is_callable;
|
||||
@@ -65,21 +81,21 @@ class Grav extends Container
|
||||
* to the dependency injection container.
|
||||
*/
|
||||
protected static $diMap = [
|
||||
'Grav\Common\Service\AccountsServiceProvider',
|
||||
'Grav\Common\Service\AssetsServiceProvider',
|
||||
'Grav\Common\Service\BackupsServiceProvider',
|
||||
'Grav\Common\Service\ConfigServiceProvider',
|
||||
'Grav\Common\Service\ErrorServiceProvider',
|
||||
'Grav\Common\Service\FilesystemServiceProvider',
|
||||
'Grav\Common\Service\FlexServiceProvider',
|
||||
'Grav\Common\Service\InflectorServiceProvider',
|
||||
'Grav\Common\Service\LoggerServiceProvider',
|
||||
'Grav\Common\Service\OutputServiceProvider',
|
||||
'Grav\Common\Service\PagesServiceProvider',
|
||||
'Grav\Common\Service\RequestServiceProvider',
|
||||
'Grav\Common\Service\SessionServiceProvider',
|
||||
'Grav\Common\Service\StreamsServiceProvider',
|
||||
'Grav\Common\Service\TaskServiceProvider',
|
||||
AccountsServiceProvider::class,
|
||||
AssetsServiceProvider::class,
|
||||
BackupsServiceProvider::class,
|
||||
ConfigServiceProvider::class,
|
||||
ErrorServiceProvider::class,
|
||||
FilesystemServiceProvider::class,
|
||||
FlexServiceProvider::class,
|
||||
InflectorServiceProvider::class,
|
||||
LoggerServiceProvider::class,
|
||||
OutputServiceProvider::class,
|
||||
PagesServiceProvider::class,
|
||||
RequestServiceProvider::class,
|
||||
SessionServiceProvider::class,
|
||||
StreamsServiceProvider::class,
|
||||
TaskServiceProvider::class,
|
||||
'browser' => Browser::class,
|
||||
'cache' => Cache::class,
|
||||
'events' => EventDispatcher::class,
|
||||
@@ -530,7 +546,7 @@ class Grav extends Container
|
||||
public function shutdown()
|
||||
{
|
||||
// Prevent user abort allowing onShutdown event to run without interruptions.
|
||||
if (\function_exists('ignore_user_abort')) {
|
||||
if (function_exists('ignore_user_abort')) {
|
||||
@ignore_user_abort(true);
|
||||
}
|
||||
|
||||
@@ -546,7 +562,7 @@ class Grav extends Container
|
||||
// the connection to the client open. This will make page loads to feel much faster.
|
||||
|
||||
// FastCGI allows us to flush all response data to the client and finish the request.
|
||||
$success = \function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false;
|
||||
$success = function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false;
|
||||
if (!$success) {
|
||||
// Unfortunately without FastCGI there is no way to force close the connection.
|
||||
// We need to ask browser to close the connection for us.
|
||||
|
||||
@@ -139,7 +139,7 @@ class LogViewer
|
||||
}
|
||||
|
||||
return array(
|
||||
'date' => \DateTime::createFromFormat('Y-m-d H:i:s', $data['date']),
|
||||
'date' => DateTime::createFromFormat('Y-m-d H:i:s', $data['date']),
|
||||
'logger' => $data['logger'],
|
||||
'level' => $data['level'],
|
||||
'message' => $data['message'],
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common\Helpers;
|
||||
|
||||
use Exception;
|
||||
use Grav\Common\Grav;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
@@ -93,7 +94,7 @@ class YamlLinter
|
||||
foreach ($iterator as $filepath => $file) {
|
||||
try {
|
||||
Yaml::parse(static::extractYaml($filepath));
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$lint_errors[str_replace(GRAV_ROOT, '', $filepath)] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common\Media\Interfaces;
|
||||
|
||||
use ArrayAccess;
|
||||
use Grav\Common\Data\Data;
|
||||
|
||||
/**
|
||||
@@ -16,7 +17,7 @@ use Grav\Common\Data\Data;
|
||||
*
|
||||
* @property string $type
|
||||
*/
|
||||
interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObjectInterface, \ArrayAccess
|
||||
interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObjectInterface, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Create a copy of this media object
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Grav\Common\Page\Interfaces;
|
||||
use ArrayAccess;
|
||||
use Countable;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Serializable;
|
||||
use Traversable;
|
||||
|
||||
@@ -91,7 +92,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
|
||||
*
|
||||
* @param PageInterface|string|null $key
|
||||
* @return PageCollectionInterface
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
//public function remove($key = null);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ use Grav\Common\Yaml;
|
||||
use InvalidArgumentException;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\File\MarkdownFile;
|
||||
use RuntimeException;
|
||||
use SplFileInfo;
|
||||
use function dirname;
|
||||
use function in_array;
|
||||
@@ -1104,10 +1105,10 @@ class Page implements PageInterface
|
||||
$this->_action = 'move';
|
||||
|
||||
if ($this->route() === $parent->route()) {
|
||||
throw new \RuntimeException('Failed: Cannot set page parent to self');
|
||||
throw new RuntimeException('Failed: Cannot set page parent to self');
|
||||
}
|
||||
if (Utils::startsWith($parent->rawRoute(), $this->rawRoute())) {
|
||||
throw new \RuntimeException('Failed: Cannot set page parent to a child of current page');
|
||||
throw new RuntimeException('Failed: Cannot set page parent to a child of current page');
|
||||
}
|
||||
|
||||
$this->parent($parent);
|
||||
|
||||
@@ -34,6 +34,7 @@ use Grav\Plugin\Admin;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use SplFileInfo;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Whoops\Exception\ErrorException;
|
||||
use Collator;
|
||||
@@ -1344,7 +1345,7 @@ class Pages
|
||||
|
||||
/** @var PageInterface $page */
|
||||
$page = $event['page'];
|
||||
$page->init(new \SplFileInfo('plugin://admin/pages/admin/error.md'));
|
||||
$page->init(new SplFileInfo('plugin://admin/pages/admin/error.md'));
|
||||
$page->routable(true);
|
||||
$header = $page->header();
|
||||
$header->title = 'Please install missing plugin';
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use ArrayAccess;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Page\Interfaces\PageInterface;
|
||||
@@ -25,7 +26,7 @@ use function is_string;
|
||||
* Class Plugin
|
||||
* @package Grav\Common
|
||||
*/
|
||||
class Plugin implements EventSubscriberInterface, \ArrayAccess
|
||||
class Plugin implements EventSubscriberInterface, ArrayAccess
|
||||
{
|
||||
/** @var string */
|
||||
public $name;
|
||||
|
||||
@@ -30,6 +30,7 @@ class Plugins extends Iterator
|
||||
/** @var array */
|
||||
public $formFieldTypes;
|
||||
|
||||
/** @var bool */
|
||||
private $plugins_initialized = false;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,7 @@ use RocketTheme\Toolbox\Event\Event;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class PagesProcessor
|
||||
@@ -55,7 +56,7 @@ class PagesProcessor extends ProcessorBase
|
||||
unset($this->container['page']);
|
||||
$this->container['page'] = $page = $event->page;
|
||||
} else {
|
||||
throw new \RuntimeException('Page Not Found', 404);
|
||||
throw new RuntimeException('Page Not Found', 404);
|
||||
}
|
||||
|
||||
$this->addMessage("Routed to page {$page->rawRoute()} (type: {$page->template()}) [Not Found fallback]");
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace Grav\Common\Scheduler;
|
||||
* // bool(true)
|
||||
*/
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use RuntimeException;
|
||||
use function count;
|
||||
@@ -473,9 +474,9 @@ class Cron
|
||||
}
|
||||
|
||||
$date = $this->parseDate($date, $min, $hour, $day, $month, $weekday);
|
||||
$interval = new \DateInterval('PT1M'); // 1 min
|
||||
$interval = new DateInterval('PT1M'); // 1 min
|
||||
if ($minuteBefore !== 0) {
|
||||
$date->sub(new \DateInterval('PT' . abs($minuteBefore) . 'M'));
|
||||
$date->sub(new DateInterval('PT' . abs($minuteBefore) . 'M'));
|
||||
}
|
||||
$n = $minuteAfter - $minuteBefore + 1;
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common\Scheduler;
|
||||
|
||||
use Closure;
|
||||
use Cron\CronExpression;
|
||||
use DateTime;
|
||||
use Grav\Common\Grav;
|
||||
@@ -109,7 +110,7 @@ class Job
|
||||
/**
|
||||
* Get the command
|
||||
*
|
||||
* @return \Closure|string
|
||||
* @return Closure|string
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
@@ -336,7 +337,7 @@ class Job
|
||||
if (is_callable($this->command)) {
|
||||
$this->output = $this->exec();
|
||||
} else {
|
||||
$args = \is_string($this->args) ? explode(' ', $this->args) : $this->args;
|
||||
$args = is_string($this->args) ? explode(' ', $this->args) : $this->args;
|
||||
$command = array_merge([$this->command], $args);
|
||||
$process = new Process($command);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use DateTime;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
@@ -247,7 +248,7 @@ class Scheduler
|
||||
case 'array':
|
||||
return $this->output_schedule;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid output type');
|
||||
throw new InvalidArgumentException('Invalid output type');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common\Service;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Grav\Common\Config\CompiledBlueprints;
|
||||
use Grav\Common\Config\CompiledConfig;
|
||||
use Grav\Common\Config\CompiledLanguages;
|
||||
@@ -169,9 +170,9 @@ class ConfigServiceProvider implements ServiceProviderInterface
|
||||
$paths = [];
|
||||
|
||||
foreach ($plugins as $path) {
|
||||
$iterator = new \DirectoryIterator($path);
|
||||
$iterator = new DirectoryIterator($path);
|
||||
|
||||
/** @var \DirectoryIterator $directory */
|
||||
/** @var DirectoryIterator $directory */
|
||||
foreach ($iterator as $directory) {
|
||||
if (!$directory->isDir() || $directory->isDot()) {
|
||||
continue;
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Grav\Common;
|
||||
|
||||
use Grav\Common\Form\FormFlash;
|
||||
use Grav\Events\SessionStartEvent;
|
||||
use Grav\Plugin\Form\Forms;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
@@ -126,7 +127,7 @@ class Session extends \Grav\Framework\Session\Session
|
||||
|
||||
/** @var Uri $uri */
|
||||
$uri = $grav['uri'];
|
||||
/** @var Grav\Plugin\Form\Forms|null $form */
|
||||
/** @var Forms|null $form */
|
||||
$form = $grav['forms']->getActiveForm();
|
||||
|
||||
$sessionField = base64_encode($uri->url);
|
||||
|
||||
@@ -130,12 +130,12 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface
|
||||
new TwigFilter('pad', [$this, 'padFilter']),
|
||||
new TwigFilter('regex_replace', [$this, 'regexReplace']),
|
||||
new TwigFilter('safe_email', [$this, 'safeEmailFilter'], ['is_safe' => ['html']]),
|
||||
new TwigFilter('safe_truncate', ['\Grav\Common\Utils', 'safeTruncate']),
|
||||
new TwigFilter('safe_truncate_html', ['\Grav\Common\Utils', 'safeTruncateHTML']),
|
||||
new TwigFilter('safe_truncate', [Utils::class, 'safeTruncate']),
|
||||
new TwigFilter('safe_truncate_html', [Utils::class, 'safeTruncateHTML']),
|
||||
new TwigFilter('sort_by_key', [$this, 'sortByKeyFilter']),
|
||||
new TwigFilter('starts_with', [$this, 'startsWithFilter']),
|
||||
new TwigFilter('truncate', ['\Grav\Common\Utils', 'truncate']),
|
||||
new TwigFilter('truncate_html', ['\Grav\Common\Utils', 'truncateHTML']),
|
||||
new TwigFilter('truncate', [Utils::class, 'truncate']),
|
||||
new TwigFilter('truncate_html', [Utils::class, 'truncateHTML']),
|
||||
new TwigFilter('json_decode', [$this, 'jsonDecodeFilter']),
|
||||
new TwigFilter('array_unique', 'array_unique'),
|
||||
new TwigFilter('basename', 'basename'),
|
||||
|
||||
@@ -22,6 +22,7 @@ use Grav\Common\User\Authentication;
|
||||
use Grav\Common\User\Interfaces\UserInterface;
|
||||
use Grav\Common\User\Traits\UserTrait;
|
||||
use Grav\Framework\Flex\Flex;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* Class User
|
||||
@@ -303,7 +304,7 @@ class User extends Data implements UserInterface
|
||||
protected function getAvatarFile(): ?string
|
||||
{
|
||||
$avatars = $this->get('avatar');
|
||||
if (\is_array($avatars) && $avatars) {
|
||||
if (is_array($avatars) && $avatars) {
|
||||
$avatar = array_shift($avatars);
|
||||
return $avatar['path'] ?? null;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use Grav\Common\User\Interfaces\UserInterface;
|
||||
use Grav\Common\Utils;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function is_string;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ use function extension_loaded;
|
||||
use function function_exists;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
use function is_string;
|
||||
use function strlen;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use ZipArchive;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
@@ -62,7 +63,7 @@ class BackupCommand extends ConsoleCommand
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
$io->title('Grav Backup');
|
||||
|
||||
if (!class_exists(\ZipArchive::class)) {
|
||||
if (!class_exists(ZipArchive::class)) {
|
||||
$io->error('php-zip extension needs to be enabled!');
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use ZipArchive;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
|
||||
@@ -72,7 +73,7 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
*/
|
||||
protected function serve(): int
|
||||
{
|
||||
if (!class_exists(\ZipArchive::class)) {
|
||||
if (!class_exists(ZipArchive::class)) {
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
$io->title('Direct Install');
|
||||
$io->error('php-zip extension needs to be enabled!');
|
||||
|
||||
@@ -14,6 +14,7 @@ use Grav\Console\ConsoleCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Class InfoCommand
|
||||
@@ -84,7 +85,7 @@ class InfoCommand extends ConsoleCommand
|
||||
$this->output->writeln("Found package <cyan>'{$this->input->getArgument('package')}'</cyan> under the '<green>" . ucfirst($foundPackage->package_type) . "</green>' section");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("<cyan>{$foundPackage->name}</cyan> [{$foundPackage->slug}]");
|
||||
$this->output->writeln(str_repeat('-', \strlen($foundPackage->name) + \strlen($foundPackage->slug) + 3));
|
||||
$this->output->writeln(str_repeat('-', strlen($foundPackage->name) + strlen($foundPackage->slug) + 3));
|
||||
$this->output->writeln('<white>' . strip_tags($foundPackage->description_plain) . '</white>');
|
||||
$this->output->writeln('');
|
||||
|
||||
@@ -160,7 +161,7 @@ class InfoCommand extends ConsoleCommand
|
||||
}, $log['content']);
|
||||
|
||||
$this->output->writeln("<cyan>{$title}</cyan>");
|
||||
$this->output->writeln(str_repeat('-', \strlen($title)));
|
||||
$this->output->writeln(str_repeat('-', strlen($title)));
|
||||
$this->output->writeln($content);
|
||||
$this->output->writeln('');
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use ZipArchive;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
@@ -108,7 +109,7 @@ class InstallCommand extends ConsoleCommand
|
||||
*/
|
||||
protected function serve(): int
|
||||
{
|
||||
if (!class_exists(\ZipArchive::class)) {
|
||||
if (!class_exists(ZipArchive::class)) {
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
$io->title('GPM Install');
|
||||
$io->error('php-zip extension needs to be enabled!');
|
||||
|
||||
@@ -21,6 +21,7 @@ use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use ZipArchive;
|
||||
use function is_callable;
|
||||
use function strlen;
|
||||
|
||||
@@ -96,7 +97,7 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
*/
|
||||
protected function serve(): int
|
||||
{
|
||||
if (!class_exists(\ZipArchive::class)) {
|
||||
if (!class_exists(ZipArchive::class)) {
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
$io->title('GPM Self Upgrade');
|
||||
$io->error('php-zip extension needs to be enabled!');
|
||||
|
||||
@@ -18,6 +18,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use ZipArchive;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
@@ -109,7 +110,7 @@ class UpdateCommand extends ConsoleCommand
|
||||
*/
|
||||
protected function serve(): int
|
||||
{
|
||||
if (!class_exists(\ZipArchive::class)) {
|
||||
if (!class_exists(ZipArchive::class)) {
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
$io->title('GPM Update');
|
||||
$io->error('php-zip extension needs to be enabled!');
|
||||
|
||||
@@ -9,13 +9,24 @@
|
||||
|
||||
namespace Grav\Framework\Acl;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Grav\Common\Utils;
|
||||
use IteratorAggregate;
|
||||
use JsonSerializable;
|
||||
use RuntimeException;
|
||||
use Traversable;
|
||||
use function count;
|
||||
use function is_array;
|
||||
use function is_bool;
|
||||
use function is_string;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Class Access
|
||||
* @package Grav\Framework\Acl
|
||||
*/
|
||||
class Access implements \JsonSerializable, \IteratorAggregate, \Countable
|
||||
class Access implements JsonSerializable, IteratorAggregate, Countable
|
||||
{
|
||||
/** @var string */
|
||||
private $name;
|
||||
@@ -69,7 +80,7 @@ class Access implements \JsonSerializable, \IteratorAggregate, \Countable
|
||||
$this->inherited += $parent->inherited + array_fill_keys(array_keys($inherited), $name ?? $parent->getName());
|
||||
$acl = array_replace($acl, $inherited);
|
||||
if (null === $acl) {
|
||||
throw new \RuntimeException('Internal error');
|
||||
throw new RuntimeException('Internal error');
|
||||
}
|
||||
|
||||
$this->acl = $acl;
|
||||
@@ -155,11 +166,11 @@ class Access implements \JsonSerializable, \IteratorAggregate, \Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Traversable
|
||||
* @return Traversable
|
||||
*/
|
||||
public function getIterator(): \Traversable
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new \ArrayIterator($this->acl);
|
||||
return new ArrayIterator($this->acl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,13 +9,20 @@
|
||||
|
||||
namespace Grav\Framework\Acl;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Grav\Common\Inflector;
|
||||
use IteratorAggregate;
|
||||
use RuntimeException;
|
||||
use Traversable;
|
||||
use function count;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Class Action
|
||||
* @package Grav\Framework\Acl
|
||||
*/
|
||||
class Action implements \IteratorAggregate, \Countable
|
||||
class Action implements IteratorAggregate, Countable
|
||||
{
|
||||
/** @var string */
|
||||
public $name;
|
||||
@@ -155,7 +162,7 @@ class Action implements \IteratorAggregate, \Countable
|
||||
public function addChild(Action $child): void
|
||||
{
|
||||
if (strpos($child->name, "{$this->name}.") !== 0) {
|
||||
throw new \RuntimeException('Bad child');
|
||||
throw new RuntimeException('Bad child');
|
||||
}
|
||||
|
||||
$child->setParent($this);
|
||||
@@ -165,11 +172,11 @@ class Action implements \IteratorAggregate, \Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Traversable
|
||||
* @return Traversable
|
||||
*/
|
||||
public function getIterator(): \Traversable
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new \ArrayIterator($this->children);
|
||||
return new ArrayIterator($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
namespace Grav\Framework\Acl;
|
||||
|
||||
use ArrayIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use RuntimeException;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Class Permissions
|
||||
* @package Grav\Framework\Acl
|
||||
@@ -30,7 +35,7 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
public function getInstances(): array
|
||||
{
|
||||
$iterator = new RecursiveActionIterator($this->actions);
|
||||
$recursive = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$recursive = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
return iterator_to_array($recursive);
|
||||
}
|
||||
@@ -138,7 +143,7 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
{
|
||||
$types = array_replace($this->types, $types);
|
||||
if (null === $types) {
|
||||
throw new \RuntimeException('Internal error');
|
||||
throw new RuntimeException('Internal error');
|
||||
}
|
||||
|
||||
$this->types = $types;
|
||||
@@ -178,7 +183,7 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
*/
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
throw new \RuntimeException(__METHOD__ . '(): Not Supported');
|
||||
throw new RuntimeException(__METHOD__ . '(): Not Supported');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +192,7 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
*/
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
throw new \RuntimeException(__METHOD__ . '(): Not Supported');
|
||||
throw new RuntimeException(__METHOD__ . '(): Not Supported');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,11 +204,11 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \ArrayIterator|\Traversable
|
||||
* @return ArrayIterator|Traversable
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->actions);
|
||||
return new ArrayIterator($this->actions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
namespace Grav\Framework\Acl;
|
||||
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* Class PermissionsReader
|
||||
@@ -102,7 +105,7 @@ class PermissionsReader
|
||||
foreach ($dependencies as $type => $dep) {
|
||||
foreach (get_object_vars($dep) as $k => &$val) {
|
||||
if (null === $val) {
|
||||
$val = $dependencies[$k] ?? new \stdClass();
|
||||
$val = $dependencies[$k] ?? new stdClass();
|
||||
}
|
||||
}
|
||||
unset($val);
|
||||
@@ -110,7 +113,7 @@ class PermissionsReader
|
||||
|
||||
$encoded = json_encode($dependencies);
|
||||
if ($encoded === false) {
|
||||
throw new \RuntimeException('json_encode(): failed to encode dependencies');
|
||||
throw new RuntimeException('json_encode(): failed to encode dependencies');
|
||||
}
|
||||
$dependencies = json_decode($encoded, true);
|
||||
|
||||
@@ -170,7 +173,7 @@ class PermissionsReader
|
||||
|
||||
$action = array_replace_recursive(...$scopes);
|
||||
if (null === $action) {
|
||||
throw new \RuntimeException('Internal error');
|
||||
throw new RuntimeException('Internal error');
|
||||
}
|
||||
|
||||
$newType = $defaults['type'] ?? null;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Framework\Acl;
|
||||
|
||||
use RecursiveIterator;
|
||||
use RocketTheme\Toolbox\ArrayTraits\Constructor;
|
||||
use RocketTheme\Toolbox\ArrayTraits\Countable;
|
||||
use RocketTheme\Toolbox\ArrayTraits\Iterator;
|
||||
@@ -17,7 +18,7 @@ use RocketTheme\Toolbox\ArrayTraits\Iterator;
|
||||
* Class Action
|
||||
* @package Grav\Framework\Acl
|
||||
*/
|
||||
class RecursiveActionIterator implements \RecursiveIterator, \Countable
|
||||
class RecursiveActionIterator implements RecursiveIterator, \Countable
|
||||
{
|
||||
use Constructor, Iterator, Countable;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Framework\Cache;
|
||||
|
||||
use DateInterval;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
@@ -21,7 +22,7 @@ abstract class AbstractCache implements CacheInterface
|
||||
|
||||
/**
|
||||
* @param string $namespace
|
||||
* @param null|int|\DateInterval $defaultLifetime
|
||||
* @param null|int|DateInterval $defaultLifetime
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct($namespace = '', $defaultLifetime = null)
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
|
||||
namespace Grav\Framework\Cache\Adapter;
|
||||
|
||||
use DateInterval;
|
||||
use Grav\Framework\Cache\AbstractCache;
|
||||
use Grav\Framework\Cache\CacheInterface;
|
||||
use Grav\Framework\Cache\Exception\InvalidArgumentException;
|
||||
use function count;
|
||||
use function get_class;
|
||||
|
||||
/**
|
||||
* Cache class for PSR-16 compatible "Simple Cache" implementation using chained cache adapters.
|
||||
@@ -29,7 +32,7 @@ class ChainCache extends AbstractCache
|
||||
/**
|
||||
* Chain Cache constructor.
|
||||
* @param array $caches
|
||||
* @param null|int|\DateInterval $defaultLifetime
|
||||
* @param null|int|DateInterval $defaultLifetime
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException|InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $caches, $defaultLifetime = null)
|
||||
@@ -45,7 +48,7 @@ class ChainCache extends AbstractCache
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
"The class '%s' does not implement the '%s' interface",
|
||||
\get_class($cache),
|
||||
get_class($cache),
|
||||
CacheInterface::class
|
||||
)
|
||||
);
|
||||
@@ -53,7 +56,7 @@ class ChainCache extends AbstractCache
|
||||
}
|
||||
|
||||
$this->caches = array_values($caches);
|
||||
$this->count = \count($caches);
|
||||
$this->count = count($caches);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Framework\Cache\Adapter;
|
||||
|
||||
use DateInterval;
|
||||
use Doctrine\Common\Cache\CacheProvider;
|
||||
use Grav\Framework\Cache\AbstractCache;
|
||||
use Grav\Framework\Cache\Exception\InvalidArgumentException;
|
||||
@@ -27,7 +28,7 @@ class DoctrineCache extends AbstractCache
|
||||
*
|
||||
* @param CacheProvider $doctrineCache
|
||||
* @param string $namespace
|
||||
* @param null|int|\DateInterval $defaultLifetime
|
||||
* @param null|int|DateInterval $defaultLifetime
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException|InvalidArgumentException
|
||||
*/
|
||||
public function __construct(CacheProvider $doctrineCache, $namespace = '', $defaultLifetime = null)
|
||||
|
||||
@@ -9,9 +9,15 @@
|
||||
|
||||
namespace Grav\Framework\Cache\Adapter;
|
||||
|
||||
use ErrorException;
|
||||
use FilesystemIterator;
|
||||
use Grav\Framework\Cache\AbstractCache;
|
||||
use Grav\Framework\Cache\Exception\CacheException;
|
||||
use Grav\Framework\Cache\Exception\InvalidArgumentException;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use RuntimeException;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Cache class for PSR-16 compatible "Simple Cache" implementation using file backend.
|
||||
@@ -32,7 +38,7 @@ class FileCache extends AbstractCache
|
||||
* @param string $namespace
|
||||
* @param int|null $defaultLifetime
|
||||
* @param string|null $folder
|
||||
* @throws InvalidArgumentException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException|InvalidArgumentException
|
||||
*/
|
||||
public function __construct($namespace = '', $defaultLifetime = null, $folder = null)
|
||||
{
|
||||
@@ -106,7 +112,7 @@ class FileCache extends AbstractCache
|
||||
public function doClear()
|
||||
{
|
||||
$result = true;
|
||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS));
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->directory, FilesystemIterator::SKIP_DOTS));
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
$result = ($file->isDir() || @unlink($file) || !file_exists($file)) && $result;
|
||||
@@ -203,7 +209,7 @@ class FileCache extends AbstractCache
|
||||
/**
|
||||
* @param string $dir
|
||||
* @return void
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function mkdir($dir)
|
||||
{
|
||||
@@ -218,7 +224,7 @@ class FileCache extends AbstractCache
|
||||
// Take yet another look, make sure that the folder doesn't exist.
|
||||
clearstatcache(true, $dir);
|
||||
if (!@is_dir($dir)) {
|
||||
throw new \RuntimeException(sprintf('Unable to create directory: %s', $dir));
|
||||
throw new RuntimeException(sprintf('Unable to create directory: %s', $dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,11 +236,11 @@ class FileCache extends AbstractCache
|
||||
* @param int $line
|
||||
* @return bool
|
||||
* @internal
|
||||
* @throws \ErrorException
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public static function throwError($type, $message, $file, $line)
|
||||
{
|
||||
throw new \ErrorException($message, 0, $type, $file, $line);
|
||||
throw new ErrorException($message, 0, $type, $file, $line);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace Grav\Framework\Cache\Adapter;
|
||||
|
||||
use Grav\Framework\Cache\AbstractCache;
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* Cache class for PSR-16 compatible "Simple Cache" implementation using in memory backend.
|
||||
|
||||
@@ -9,7 +9,19 @@
|
||||
|
||||
namespace Grav\Framework\Cache;
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Grav\Framework\Cache\Exception\InvalidArgumentException;
|
||||
use stdClass;
|
||||
use Traversable;
|
||||
use function array_key_exists;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_array;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Cache trait for PSR-16 compatible "Simple Cache" implementation
|
||||
@@ -21,7 +33,7 @@ trait CacheTrait
|
||||
private $namespace = '';
|
||||
/** @var int|null */
|
||||
private $defaultLifetime = null;
|
||||
/** @var \stdClass */
|
||||
/** @var stdClass */
|
||||
private $miss;
|
||||
/** @var bool */
|
||||
private $validation = true;
|
||||
@@ -30,7 +42,7 @@ trait CacheTrait
|
||||
* Always call from constructor.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param null|int|\DateInterval $defaultLifetime
|
||||
* @param null|int|DateInterval $defaultLifetime
|
||||
* @return void
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@@ -38,7 +50,7 @@ trait CacheTrait
|
||||
{
|
||||
$this->namespace = (string) $namespace;
|
||||
$this->defaultLifetime = $this->convertTtl($defaultLifetime);
|
||||
$this->miss = new \stdClass;
|
||||
$this->miss = new stdClass;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +96,7 @@ trait CacheTrait
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param null|int|\DateInterval $ttl
|
||||
* @param null|int|DateInterval $ttl
|
||||
* @return bool
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@@ -126,14 +138,14 @@ trait CacheTrait
|
||||
*/
|
||||
public function getMultiple($keys, $default = null)
|
||||
{
|
||||
if ($keys instanceof \Traversable) {
|
||||
if ($keys instanceof Traversable) {
|
||||
$keys = iterator_to_array($keys, false);
|
||||
} elseif (!\is_array($keys)) {
|
||||
$isObject = \is_object($keys);
|
||||
} elseif (!is_array($keys)) {
|
||||
$isObject = is_object($keys);
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Cache keys must be array or Traversable, "%s" given',
|
||||
$isObject ? \get_class($keys) : \gettype($keys)
|
||||
$isObject ? get_class($keys) : gettype($keys)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -166,20 +178,20 @@ trait CacheTrait
|
||||
|
||||
/**
|
||||
* @param iterable $values
|
||||
* @param null|int|\DateInterval $ttl
|
||||
* @param null|int|DateInterval $ttl
|
||||
* @return bool
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setMultiple($values, $ttl = null)
|
||||
{
|
||||
if ($values instanceof \Traversable) {
|
||||
if ($values instanceof Traversable) {
|
||||
$values = iterator_to_array($values, true);
|
||||
} elseif (!is_array($values)) {
|
||||
$isObject = \is_object($values);
|
||||
$isObject = is_object($values);
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Cache values must be array or Traversable, "%s" given',
|
||||
$isObject ? \get_class($values) : \gettype($values)
|
||||
$isObject ? get_class($values) : gettype($values)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -205,14 +217,14 @@ trait CacheTrait
|
||||
*/
|
||||
public function deleteMultiple($keys)
|
||||
{
|
||||
if ($keys instanceof \Traversable) {
|
||||
if ($keys instanceof Traversable) {
|
||||
$keys = iterator_to_array($keys, false);
|
||||
} elseif (!is_array($keys)) {
|
||||
$isObject = \is_object($keys);
|
||||
$isObject = is_object($keys);
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Cache keys must be array or Traversable, "%s" given',
|
||||
$isObject ? \get_class($keys) : \gettype($keys)
|
||||
$isObject ? get_class($keys) : gettype($keys)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -295,20 +307,20 @@ trait CacheTrait
|
||||
*/
|
||||
protected function validateKey($key)
|
||||
{
|
||||
if (!\is_string($key)) {
|
||||
if (!is_string($key)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Cache key must be string, "%s" given',
|
||||
\is_object($key) ? \get_class($key) : \gettype($key)
|
||||
is_object($key) ? get_class($key) : gettype($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (!isset($key[0])) {
|
||||
throw new InvalidArgumentException('Cache key length must be greater than zero');
|
||||
}
|
||||
if (\strlen($key) > 64) {
|
||||
if (strlen($key) > 64) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cache key length must be less than 65 characters, key had %d characters', \strlen($key))
|
||||
sprintf('Cache key length must be less than 65 characters, key had %d characters', strlen($key))
|
||||
);
|
||||
}
|
||||
if (strpbrk($key, '{}()/\@:') !== false) {
|
||||
@@ -335,7 +347,7 @@ trait CacheTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int|\DateInterval $ttl
|
||||
* @param null|int|DateInterval $ttl
|
||||
* @return int|null
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@@ -345,19 +357,19 @@ trait CacheTrait
|
||||
return $this->getDefaultLifetime();
|
||||
}
|
||||
|
||||
if (\is_int($ttl)) {
|
||||
if (is_int($ttl)) {
|
||||
return $ttl;
|
||||
}
|
||||
|
||||
if ($ttl instanceof \DateInterval) {
|
||||
$date = \DateTime::createFromFormat('U', '0');
|
||||
if ($ttl instanceof DateInterval) {
|
||||
$date = DateTime::createFromFormat('U', '0');
|
||||
$ttl = $date ? (int)$date->add($ttl)->format('U') : 0;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Expiration date must be an integer, a DateInterval or null, "%s" given',
|
||||
\is_object($ttl) ? \get_class($ttl) : \gettype($ttl)
|
||||
is_object($ttl) ? get_class($ttl) : gettype($ttl)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
|
||||
namespace Grav\Framework\Cache\Exception;
|
||||
|
||||
use Exception;
|
||||
use Psr\SimpleCache\CacheException as SimpleCacheException;
|
||||
|
||||
/**
|
||||
* CacheException class for PSR-16 compatible "Simple Cache" implementation.
|
||||
* @package Grav\Framework\Cache\Exception
|
||||
*/
|
||||
class CacheException extends \Exception implements SimpleCacheException
|
||||
class CacheException extends Exception implements SimpleCacheException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -11,9 +11,14 @@ namespace Grav\Framework\Collection;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
|
||||
use FilesystemIterator;
|
||||
use Grav\Common\Grav;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RocketTheme\Toolbox\ResourceLocator\RecursiveUniformResourceIterator;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use SeekableIterator;
|
||||
use function array_slice;
|
||||
|
||||
/**
|
||||
* Collection of objects stored into a filesystem.
|
||||
@@ -28,7 +33,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
|
||||
{
|
||||
/** @var string */
|
||||
protected $path;
|
||||
/** @var \RecursiveDirectoryIterator|RecursiveUniformResourceIterator */
|
||||
/** @var RecursiveDirectoryIterator|RecursiveUniformResourceIterator */
|
||||
protected $iterator;
|
||||
/** @var callable */
|
||||
protected $createObjectFunction;
|
||||
@@ -89,7 +94,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
|
||||
$next = ClosureExpressionVisitor::sortByField($field, $ordering === Criteria::DESC ? -1 : 1, $next);
|
||||
}
|
||||
if (null === $next) {
|
||||
throw new \RuntimeException('Criteria is missing orderings');
|
||||
throw new RuntimeException('Criteria is missing orderings');
|
||||
}
|
||||
|
||||
uasort($filtered, $next);
|
||||
@@ -101,7 +106,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
|
||||
$length = $criteria->getMaxResults();
|
||||
|
||||
if ($offset || $length) {
|
||||
$filtered = \array_slice($filtered, (int)$offset, $length);
|
||||
$filtered = array_slice($filtered, (int)$offset, $length);
|
||||
}
|
||||
|
||||
return new ArrayCollection($filtered);
|
||||
@@ -112,15 +117,15 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
|
||||
*/
|
||||
protected function setIterator()
|
||||
{
|
||||
$iteratorFlags = \RecursiveDirectoryIterator::SKIP_DOTS + \FilesystemIterator::UNIX_PATHS
|
||||
+ \FilesystemIterator::CURRENT_AS_SELF + \FilesystemIterator::FOLLOW_SYMLINKS;
|
||||
$iteratorFlags = RecursiveDirectoryIterator::SKIP_DOTS + FilesystemIterator::UNIX_PATHS
|
||||
+ FilesystemIterator::CURRENT_AS_SELF + FilesystemIterator::FOLLOW_SYMLINKS;
|
||||
|
||||
if (strpos($this->path, '://')) {
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = Grav::instance()['locator'];
|
||||
$this->iterator = $locator->getRecursiveIterator($this->path, $iteratorFlags);
|
||||
} else {
|
||||
$this->iterator = new \RecursiveDirectoryIterator($this->path, $iteratorFlags);
|
||||
$this->iterator = new RecursiveDirectoryIterator($this->path, $iteratorFlags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,18 +159,18 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \SeekableIterator $iterator
|
||||
* @param SeekableIterator $iterator
|
||||
* @param int $nestingLimit
|
||||
* @return array
|
||||
*/
|
||||
protected function doInitializeByIterator(\SeekableIterator $iterator, $nestingLimit)
|
||||
protected function doInitializeByIterator(SeekableIterator $iterator, $nestingLimit)
|
||||
{
|
||||
$children = [];
|
||||
$objects = [];
|
||||
$filter = $this->filterFunction;
|
||||
$objectFunction = $this->createObjectFunction;
|
||||
|
||||
/** @var \RecursiveDirectoryIterator $file */
|
||||
/** @var RecursiveDirectoryIterator $file */
|
||||
foreach ($iterator as $file) {
|
||||
// Skip files if they shouldn't be included.
|
||||
if (!($this->flags & static::INCLUDE_FILES) && $file->isFile()) {
|
||||
@@ -215,7 +220,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RecursiveDirectoryIterator $file
|
||||
* @param RecursiveDirectoryIterator $file
|
||||
* @return object
|
||||
*/
|
||||
protected function createObject($file)
|
||||
|
||||
@@ -13,6 +13,10 @@ use ArrayIterator;
|
||||
use Closure;
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
|
||||
use InvalidArgumentException;
|
||||
use function array_key_exists;
|
||||
use function array_slice;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Abstract Index Collection.
|
||||
@@ -248,7 +252,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return \count($this->entries);
|
||||
return count($this->entries);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +261,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
|
||||
public function set($key, $value)
|
||||
{
|
||||
if (!$this->isAllowedElement($value)) {
|
||||
throw new \InvalidArgumentException('Invalid argument $value');
|
||||
throw new InvalidArgumentException('Invalid argument $value');
|
||||
}
|
||||
|
||||
$this->entries[$key] = $this->getElementMeta($value);
|
||||
@@ -269,7 +273,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
|
||||
public function add($element)
|
||||
{
|
||||
if (!$this->isAllowedElement($element)) {
|
||||
throw new \InvalidArgumentException('Invalid argument $element');
|
||||
throw new InvalidArgumentException('Invalid argument $element');
|
||||
}
|
||||
|
||||
$this->entries[$this->getCurrentKey($element)] = $this->getElementMeta($element);
|
||||
@@ -350,7 +354,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
|
||||
*/
|
||||
public function slice($offset, $length = null)
|
||||
{
|
||||
return $this->loadElements(\array_slice($this->entries, $offset, $length, true));
|
||||
return $this->loadElements(array_slice($this->entries, $offset, $length, true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,7 +364,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
|
||||
*/
|
||||
public function limit($start, $limit = null)
|
||||
{
|
||||
return $this->createFrom(\array_slice($this->entries, $start, $limit, true));
|
||||
return $this->createFrom(array_slice($this->entries, $start, $limit, true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
|
||||
namespace Grav\Framework\ContentBlock;
|
||||
|
||||
use Exception;
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use function get_class;
|
||||
|
||||
/**
|
||||
* Class to create nested blocks of content.
|
||||
@@ -54,7 +58,7 @@ class ContentBlock implements ContentBlockInterface
|
||||
/**
|
||||
* @param array $serialized
|
||||
* @return ContentBlockInterface
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function fromArray(array $serialized)
|
||||
{
|
||||
@@ -63,14 +67,14 @@ class ContentBlock implements ContentBlockInterface
|
||||
$id = $serialized['id'] ?? null;
|
||||
|
||||
if (!$type || !$id || !is_a($type, ContentBlockInterface::class, true)) {
|
||||
throw new \InvalidArgumentException('Bad data');
|
||||
throw new InvalidArgumentException('Bad data');
|
||||
}
|
||||
|
||||
/** @var ContentBlockInterface $instance */
|
||||
$instance = new $type($id);
|
||||
$instance->build($serialized);
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf('Cannot unserialize Block: %s', $e->getMessage()), $e->getCode(), $e);
|
||||
} catch (Exception $e) {
|
||||
throw new InvalidArgumentException(sprintf('Cannot unserialize Block: %s', $e->getMessage()), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
@@ -114,7 +118,7 @@ class ContentBlock implements ContentBlockInterface
|
||||
}
|
||||
|
||||
$array = [
|
||||
'_type' => \get_class($this),
|
||||
'_type' => get_class($this),
|
||||
'_version' => $this->version,
|
||||
'id' => $this->id,
|
||||
'cached' => $this->cached
|
||||
@@ -161,7 +165,7 @@ class ContentBlock implements ContentBlockInterface
|
||||
{
|
||||
try {
|
||||
return $this->toString();
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return sprintf('Error while rendering block: %s', $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -169,7 +173,7 @@ class ContentBlock implements ContentBlockInterface
|
||||
/**
|
||||
* @param array $serialized
|
||||
* @return void
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function build(array $serialized)
|
||||
{
|
||||
@@ -286,13 +290,13 @@ class ContentBlock implements ContentBlockInterface
|
||||
/**
|
||||
* @param array $serialized
|
||||
* @return void
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function checkVersion(array $serialized)
|
||||
{
|
||||
$version = isset($serialized['_version']) ? (int) $serialized['_version'] : 1;
|
||||
if ($version !== $this->version) {
|
||||
throw new \RuntimeException(sprintf('Unsupported version %s', $version));
|
||||
throw new RuntimeException(sprintf('Unsupported version %s', $version));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
namespace Grav\Framework\ContentBlock;
|
||||
|
||||
use Serializable;
|
||||
|
||||
/**
|
||||
* ContentBlock Interface
|
||||
* @package Grav\Framework\ContentBlock
|
||||
*/
|
||||
interface ContentBlockInterface extends \Serializable
|
||||
interface ContentBlockInterface extends Serializable
|
||||
{
|
||||
/**
|
||||
* @param string|null $id
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
namespace Grav\Framework\ContentBlock;
|
||||
|
||||
use RuntimeException;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* HtmlBlock
|
||||
*
|
||||
@@ -104,7 +108,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
|
||||
/**
|
||||
* @param array $serialized
|
||||
* @return void
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function build(array $serialized)
|
||||
{
|
||||
@@ -138,7 +142,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
|
||||
*/
|
||||
public function addStyle($element, $priority = 0, $location = 'head')
|
||||
{
|
||||
if (!\is_array($element)) {
|
||||
if (!is_array($element)) {
|
||||
$element = ['href' => (string) $element];
|
||||
}
|
||||
if (empty($element['href'])) {
|
||||
@@ -182,7 +186,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
|
||||
*/
|
||||
public function addInlineStyle($element, $priority = 0, $location = 'head')
|
||||
{
|
||||
if (!\is_array($element)) {
|
||||
if (!is_array($element)) {
|
||||
$element = ['content' => (string) $element];
|
||||
}
|
||||
if (empty($element['content'])) {
|
||||
@@ -213,7 +217,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
|
||||
*/
|
||||
public function addScript($element, $priority = 0, $location = 'head')
|
||||
{
|
||||
if (!\is_array($element)) {
|
||||
if (!is_array($element)) {
|
||||
$element = ['src' => (string) $element];
|
||||
}
|
||||
if (empty($element['src'])) {
|
||||
@@ -225,8 +229,8 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
|
||||
|
||||
$src = $element['src'];
|
||||
$type = !empty($element['type']) ? (string) $element['type'] : 'text/javascript';
|
||||
$defer = isset($element['defer']) ? true : false;
|
||||
$async = isset($element['async']) ? true : false;
|
||||
$defer = isset($element['defer']);
|
||||
$async = isset($element['async']);
|
||||
$handle = !empty($element['handle']) ? (string) $element['handle'] : '';
|
||||
|
||||
$this->scripts[$location][md5($src) . sha1($src)] = [
|
||||
@@ -250,7 +254,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
|
||||
*/
|
||||
public function addInlineScript($element, $priority = 0, $location = 'head')
|
||||
{
|
||||
if (!\is_array($element)) {
|
||||
if (!is_array($element)) {
|
||||
$element = ['content' => (string) $element];
|
||||
}
|
||||
if (empty($element['content'])) {
|
||||
@@ -281,7 +285,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
|
||||
*/
|
||||
public function addHtml($html, $priority = 0, $location = 'bottom')
|
||||
{
|
||||
if (empty($html) || !\is_string($html)) {
|
||||
if (empty($html) || !is_string($html)) {
|
||||
return false;
|
||||
}
|
||||
if (!isset($this->html[$location])) {
|
||||
|
||||
@@ -19,6 +19,9 @@ use Grav\Framework\RequestHandler\Exception\RequestException;
|
||||
use Grav\Framework\Route\Route;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Throwable;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Trait ControllerResponseTrait
|
||||
@@ -94,10 +97,10 @@ trait ControllerResponseTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $e
|
||||
* @param Throwable $e
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function createErrorResponse(\Throwable $e): ResponseInterface
|
||||
protected function createErrorResponse(Throwable $e): ResponseInterface
|
||||
{
|
||||
$response = $this->getErrorJson($e);
|
||||
$message = $response['message'];
|
||||
@@ -130,10 +133,10 @@ trait ControllerResponseTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $e
|
||||
* @param Throwable $e
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function createJsonErrorResponse(\Throwable $e): ResponseInterface
|
||||
protected function createJsonErrorResponse(Throwable $e): ResponseInterface
|
||||
{
|
||||
$response = $this->getErrorJson($e);
|
||||
$reason = $e instanceof RequestException ? $e->getHttpReason() : null;
|
||||
@@ -142,10 +145,10 @@ trait ControllerResponseTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $e
|
||||
* @param Throwable $e
|
||||
* @return array
|
||||
*/
|
||||
protected function getErrorJson(\Throwable $e): array
|
||||
protected function getErrorJson(Throwable $e): array
|
||||
{
|
||||
$code = $this->getErrorCode($e instanceof RequestException ? $e->getHttpCode() : $e->getCode());
|
||||
$message = $e->getMessage();
|
||||
@@ -163,7 +166,7 @@ trait ControllerResponseTrait
|
||||
$debugger = Grav::instance()['debugger'];
|
||||
if ($debugger->enabled()) {
|
||||
$response['error'] += [
|
||||
'type' => \get_class($e),
|
||||
'type' => get_class($e),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'trace' => explode("\n", $e->getTraceAsString())
|
||||
|
||||
@@ -11,9 +11,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Framework\File;
|
||||
|
||||
use Exception;
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use Grav\Framework\File\Interfaces\FileInterface;
|
||||
use Grav\Framework\Filesystem\Filesystem;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class AbstractFile
|
||||
@@ -184,13 +186,13 @@ class AbstractFile implements FileInterface
|
||||
{
|
||||
if (!$this->handle) {
|
||||
if (!$this->mkdir($this->getPath())) {
|
||||
throw new \RuntimeException('Creating directory failed for ' . $this->filepath);
|
||||
throw new RuntimeException('Creating directory failed for ' . $this->filepath);
|
||||
}
|
||||
$this->handle = @fopen($this->filepath, 'cb+') ?: null;
|
||||
if (!$this->handle) {
|
||||
$error = error_get_last();
|
||||
|
||||
throw new \RuntimeException("Opening file for writing failed on error {$error['message']}");
|
||||
throw new RuntimeException("Opening file for writing failed on error {$error['message']}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +275,7 @@ class AbstractFile implements FileInterface
|
||||
$dir = $this->getPath();
|
||||
|
||||
if (!$this->mkdir($dir)) {
|
||||
throw new \RuntimeException('Creating directory failed for ' . $filepath);
|
||||
throw new RuntimeException('Creating directory failed for ' . $filepath);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -288,7 +290,7 @@ class AbstractFile implements FileInterface
|
||||
// Support for symlinks.
|
||||
$realpath = is_link($filepath) ? realpath($filepath) : $filepath;
|
||||
if ($realpath === false) {
|
||||
throw new \RuntimeException('Failed to save file ' . $filepath);
|
||||
throw new RuntimeException('Failed to save file ' . $filepath);
|
||||
}
|
||||
|
||||
// Create file with a temporary name and rename it to make the save action atomic.
|
||||
@@ -300,12 +302,12 @@ class AbstractFile implements FileInterface
|
||||
$tmp = false;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$tmp = false;
|
||||
}
|
||||
|
||||
if ($tmp === false) {
|
||||
throw new \RuntimeException('Failed to save file ' . $filepath);
|
||||
throw new RuntimeException('Failed to save file ' . $filepath);
|
||||
}
|
||||
|
||||
// Touch the directory as well, thus marking it modified.
|
||||
@@ -339,7 +341,7 @@ class AbstractFile implements FileInterface
|
||||
/**
|
||||
* @param string $dir
|
||||
* @return bool
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
* @internal
|
||||
*/
|
||||
protected function mkdir(string $dir): bool
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Grav\Framework\File;
|
||||
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use RuntimeException;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* Class DataFile
|
||||
@@ -60,7 +61,7 @@ class DataFile extends AbstractFile
|
||||
*/
|
||||
public function save($data): void
|
||||
{
|
||||
if (\is_string($data)) {
|
||||
if (is_string($data)) {
|
||||
// Make sure that the string is valid data.
|
||||
try {
|
||||
$this->formatter->decode($data);
|
||||
|
||||
@@ -11,6 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Framework\File;
|
||||
|
||||
use RuntimeException;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* Class File
|
||||
* @package Grav\Framework\File
|
||||
@@ -32,8 +35,8 @@ class File extends AbstractFile
|
||||
*/
|
||||
public function save($data): void
|
||||
{
|
||||
if (!\is_string($data)) {
|
||||
throw new \RuntimeException('Cannot save data, string required');
|
||||
if (!is_string($data)) {
|
||||
throw new RuntimeException('Cannot save data, string required');
|
||||
}
|
||||
|
||||
parent::save($data);
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* Abstract file formatter.
|
||||
@@ -42,7 +43,7 @@ abstract class AbstractFormatter implements FileFormatterInterface
|
||||
{
|
||||
$mime = $this->getConfig('mime');
|
||||
|
||||
return \is_string($mime) ? $mime : 'application/octet-stream';
|
||||
return is_string($mime) ? $mime : 'application/octet-stream';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +67,7 @@ abstract class AbstractFormatter implements FileFormatterInterface
|
||||
$extensions = $this->getConfig('file_extension');
|
||||
|
||||
// Call fails on bad configuration.
|
||||
return \is_string($extensions) ? [$extensions] : $extensions;
|
||||
return is_string($extensions) ? [$extensions] : $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Exception;
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use JsonSerializable;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function is_scalar;
|
||||
|
||||
/**
|
||||
* Class CsvFormatter
|
||||
@@ -81,13 +88,13 @@ class CsvFormatter extends AbstractFormatter
|
||||
$delimiter = $delimiter ?? $this->getDelimiter();
|
||||
$lines = preg_split('/\r\n|\r|\n/', $data);
|
||||
if ($lines === false) {
|
||||
throw new \RuntimeException('Decoding CSV failed');
|
||||
throw new RuntimeException('Decoding CSV failed');
|
||||
}
|
||||
|
||||
// Get the field names
|
||||
$headerStr = array_shift($lines);
|
||||
if (!$headerStr) {
|
||||
throw new \RuntimeException('CSV header missing');
|
||||
throw new RuntimeException('CSV header missing');
|
||||
}
|
||||
|
||||
$header = str_getcsv($headerStr, $delimiter);
|
||||
@@ -112,8 +119,8 @@ class CsvFormatter extends AbstractFormatter
|
||||
$list[] = array_combine($header, $csv_line);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Badly formatted CSV line: ' . $line);
|
||||
} catch (Exception $e) {
|
||||
throw new RuntimeException('Badly formatted CSV line: ' . $line);
|
||||
}
|
||||
|
||||
return $list;
|
||||
@@ -128,8 +135,8 @@ class CsvFormatter extends AbstractFormatter
|
||||
{
|
||||
foreach ($line as $key => &$value) {
|
||||
// Oops, we need to convert the line to a string.
|
||||
if (!\is_scalar($value)) {
|
||||
if (is_array($value) || $value instanceof \JsonSerializable || $value instanceof \stdClass) {
|
||||
if (!is_scalar($value)) {
|
||||
if (is_array($value) || $value instanceof JsonSerializable || $value instanceof stdClass) {
|
||||
$value = json_encode($value);
|
||||
} elseif (is_object($value)) {
|
||||
if (method_exists($value, 'toJson')) {
|
||||
|
||||
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use RuntimeException;
|
||||
use function is_int;
|
||||
use function is_string;
|
||||
|
||||
@@ -141,7 +142,7 @@ class JsonFormatter extends AbstractFormatter
|
||||
$encoded = @json_encode($data, $this->getEncodeOptions());
|
||||
|
||||
if ($encoded === false && json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \RuntimeException('Encoding JSON failed: ' . json_last_error_msg());
|
||||
throw new RuntimeException('Encoding JSON failed: ' . json_last_error_msg());
|
||||
}
|
||||
|
||||
return $encoded ?: '';
|
||||
@@ -156,7 +157,7 @@ class JsonFormatter extends AbstractFormatter
|
||||
$decoded = @json_decode($data, $this->getDecodeAssoc(), $this->getDecodeDepth(), $this->getDecodeOptions());
|
||||
|
||||
if (null === $decoded && json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \RuntimeException('Decoding JSON failed: ' . json_last_error_msg());
|
||||
throw new RuntimeException('Decoding JSON failed: ' . json_last_error_msg());
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
|
||||
@@ -12,6 +12,10 @@ declare(strict_types=1);
|
||||
namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* Class SerializeFormatter
|
||||
@@ -27,7 +31,7 @@ class SerializeFormatter extends AbstractFormatter
|
||||
{
|
||||
$config += [
|
||||
'file_extension' => '.ser',
|
||||
'decode_options' => ['allowed_classes' => [\stdClass::class]]
|
||||
'decode_options' => ['allowed_classes' => [stdClass::class]]
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
@@ -64,7 +68,7 @@ class SerializeFormatter extends AbstractFormatter
|
||||
$decoded = @unserialize($data, ['allowed_classes' => $classes]);
|
||||
|
||||
if ($decoded === false && $data !== serialize(false)) {
|
||||
throw new \RuntimeException('Decoding serialized data failed');
|
||||
throw new RuntimeException('Decoding serialized data failed');
|
||||
}
|
||||
|
||||
return $this->preserveLines($decoded, ['\\n', '\\r'], ["\n", "\r"]);
|
||||
@@ -80,9 +84,9 @@ class SerializeFormatter extends AbstractFormatter
|
||||
*/
|
||||
protected function preserveLines($data, array $search, array $replace)
|
||||
{
|
||||
if (\is_string($data)) {
|
||||
if (is_string($data)) {
|
||||
$data = str_replace($search, $replace, $data);
|
||||
} elseif (\is_array($data)) {
|
||||
} elseif (is_array($data)) {
|
||||
foreach ($data as &$value) {
|
||||
$value = $this->preserveLines($value, $search, $replace);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,12 @@ declare(strict_types=1);
|
||||
namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Yaml\Exception\DumpException;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml as YamlParser;
|
||||
use RocketTheme\Toolbox\Compat\Yaml\Yaml as FallbackYamlParser;
|
||||
use function function_exists;
|
||||
|
||||
/**
|
||||
* Class YamlFormatter
|
||||
@@ -89,7 +91,7 @@ class YamlFormatter extends AbstractFormatter
|
||||
YamlParser::DUMP_EXCEPTION_ON_INVALID_TYPE
|
||||
);
|
||||
} catch (DumpException $e) {
|
||||
throw new \RuntimeException('Encoding YAML failed: ' . $e->getMessage(), 0, $e);
|
||||
throw new RuntimeException('Encoding YAML failed: ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +102,7 @@ class YamlFormatter extends AbstractFormatter
|
||||
public function decode($data): array
|
||||
{
|
||||
// Try native PECL YAML PHP extension first if available.
|
||||
if (\function_exists('yaml_parse') && $this->useNativeDecoder()) {
|
||||
if (function_exists('yaml_parse') && $this->useNativeDecoder()) {
|
||||
// Safely decode YAML.
|
||||
$saved = @ini_get('yaml.decode_php');
|
||||
@ini_set('yaml.decode_php', '0');
|
||||
@@ -119,7 +121,7 @@ class YamlFormatter extends AbstractFormatter
|
||||
return (array) FallbackYamlParser::parse($data);
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Decoding YAML failed: ' . $e->getMessage(), 0, $e);
|
||||
throw new RuntimeException('Decoding YAML failed: ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Framework\File\Interfaces;
|
||||
|
||||
use Serializable;
|
||||
|
||||
/**
|
||||
* Defines common interface for all file formatters.
|
||||
*
|
||||
@@ -24,7 +26,7 @@ namespace Grav\Framework\File\Interfaces;
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
interface FileFormatterInterface extends \Serializable
|
||||
interface FileFormatterInterface extends Serializable
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
|
||||
@@ -11,6 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Framework\File\Interfaces;
|
||||
|
||||
use RuntimeException;
|
||||
use Serializable;
|
||||
|
||||
/**
|
||||
* Defines common interface for all file readers.
|
||||
*
|
||||
@@ -24,7 +27,7 @@ namespace Grav\Framework\File\Interfaces;
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
interface FileInterface extends \Serializable
|
||||
interface FileInterface extends Serializable
|
||||
{
|
||||
/**
|
||||
* Get both path and filename of the file.
|
||||
@@ -98,7 +101,7 @@ interface FileInterface extends \Serializable
|
||||
* @param bool $block For non-blocking lock, set the parameter to `false`.
|
||||
*
|
||||
* @return bool Returns `true` if the file was successfully locked, `false` otherwise.
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
* @api
|
||||
*/
|
||||
public function lock(bool $block = true): bool;
|
||||
@@ -150,7 +153,7 @@ interface FileInterface extends \Serializable
|
||||
*
|
||||
* @param mixed $data Data to be saved.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
* @api
|
||||
*/
|
||||
public function save($data): void;
|
||||
|
||||
@@ -12,6 +12,10 @@ declare(strict_types=1);
|
||||
namespace Grav\Framework\Filesystem;
|
||||
|
||||
use Grav\Framework\Filesystem\Interfaces\FilesystemInterface;
|
||||
use RuntimeException;
|
||||
use function count;
|
||||
use function dirname;
|
||||
use function pathinfo;
|
||||
|
||||
/**
|
||||
* Class Filesystem
|
||||
@@ -203,7 +207,7 @@ class Filesystem implements FilesystemInterface
|
||||
*/
|
||||
protected function dirnameInternal(?string $scheme, string $path, int $levels = 1): array
|
||||
{
|
||||
$path = \dirname($path, $levels);
|
||||
$path = dirname($path, $levels);
|
||||
|
||||
if (null !== $scheme && $path === '.') {
|
||||
return [$scheme, ''];
|
||||
@@ -226,10 +230,10 @@ class Filesystem implements FilesystemInterface
|
||||
protected function pathinfoInternal(?string $scheme, string $path, ?int $options = null)
|
||||
{
|
||||
if ($options) {
|
||||
return \pathinfo($path, $options);
|
||||
return pathinfo($path, $options);
|
||||
}
|
||||
|
||||
$info = \pathinfo($path);
|
||||
$info = pathinfo($path);
|
||||
|
||||
if (null !== $scheme) {
|
||||
$info['scheme'] = $scheme;
|
||||
@@ -260,7 +264,7 @@ class Filesystem implements FilesystemInterface
|
||||
{
|
||||
$components = explode('://', $filename, 2);
|
||||
|
||||
return 2 === \count($components) ? $components : [null, $components[0]];
|
||||
return 2 === count($components) ? $components : [null, $components[0]];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +284,7 @@ class Filesystem implements FilesystemInterface
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function normalizePathPart(string $path): string
|
||||
{
|
||||
@@ -323,7 +327,7 @@ class Filesystem implements FilesystemInterface
|
||||
$test = array_pop($list);
|
||||
if ($test === null) {
|
||||
// Oops, user tried to access something outside of our root folder.
|
||||
throw new \RuntimeException("Bad path {$path}");
|
||||
throw new RuntimeException("Bad path {$path}");
|
||||
}
|
||||
} else {
|
||||
$list[] = $part;
|
||||
|
||||
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Grav\Framework\Filesystem\Interfaces;
|
||||
|
||||
use Grav\Framework\Filesystem\Filesystem;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Defines several stream-save filesystem actions.
|
||||
@@ -29,7 +30,7 @@ interface FilesystemInterface
|
||||
* @param string $path A filename or path, does not need to exist as a file.
|
||||
* @param int $levels The number of parent directories to go up (>= 1).
|
||||
* @return string Returns parent path.
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
* @api
|
||||
*/
|
||||
public function parent(string $path, int $levels = 1): string;
|
||||
@@ -39,7 +40,7 @@ interface FilesystemInterface
|
||||
*
|
||||
* @param string $path A filename or path, does not need to exist as a file.
|
||||
* @return string Returns normalized path.
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
* @api
|
||||
*/
|
||||
public function normalize(string $path): string;
|
||||
@@ -62,7 +63,7 @@ interface FilesystemInterface
|
||||
* @param string $path A filename or path, does not need to exist as a file.
|
||||
* @param int $levels The number of parent directories to go up (>= 1).
|
||||
* @return string Returns path to the directory.
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
* @api
|
||||
*/
|
||||
public function dirname(string $path, int $levels = 1): string;
|
||||
|
||||
@@ -18,6 +18,7 @@ use Grav\Framework\Flex\Interfaces\FlexInterface;
|
||||
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
|
||||
use Grav\Framework\Object\ObjectCollection;
|
||||
use RuntimeException;
|
||||
use function count;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
@@ -292,7 +293,7 @@ class Flex implements FlexInterface
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return \count($this->types);
|
||||
return count($this->types);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ use function array_filter;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_scalar;
|
||||
|
||||
/**
|
||||
* Class FlexCollection
|
||||
@@ -370,7 +371,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
|
||||
|
||||
$key = null;
|
||||
foreach ($context as $value) {
|
||||
if (!\is_scalar($value)) {
|
||||
if (!is_scalar($value)) {
|
||||
$key = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace Grav\Framework\Flex;
|
||||
|
||||
use ArrayAccess;
|
||||
use Exception;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Grav;
|
||||
@@ -19,6 +20,7 @@ use Grav\Framework\Flex\Interfaces\FlexFormInterface;
|
||||
use Grav\Framework\Form\Interfaces\FormFlashInterface;
|
||||
use Grav\Framework\Form\Traits\FormTrait;
|
||||
use Grav\Framework\Route\Route;
|
||||
use JsonSerializable;
|
||||
use RocketTheme\Toolbox\ArrayTraits\NestedArrayAccessWithGetters;
|
||||
use RuntimeException;
|
||||
use Twig\Error\LoaderError;
|
||||
@@ -30,7 +32,7 @@ use Twig\TemplateWrapper;
|
||||
* Class FlexForm
|
||||
* @package Grav\Framework\Flex
|
||||
*/
|
||||
class FlexDirectoryForm implements FlexDirectoryFormInterface, \JsonSerializable
|
||||
class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
|
||||
{
|
||||
use NestedArrayAccessWithGetters {
|
||||
NestedArrayAccessWithGetters::get as private traitGet;
|
||||
@@ -436,7 +438,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, \JsonSerializable
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function doSubmit(array $data, array $files)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace Grav\Framework\Flex;
|
||||
|
||||
use ArrayAccess;
|
||||
use Exception;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Grav;
|
||||
@@ -19,6 +21,7 @@ use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
|
||||
use Grav\Framework\Form\Interfaces\FormFlashInterface;
|
||||
use Grav\Framework\Form\Traits\FormTrait;
|
||||
use Grav\Framework\Route\Route;
|
||||
use JsonSerializable;
|
||||
use RocketTheme\Toolbox\ArrayTraits\NestedArrayAccessWithGetters;
|
||||
use RuntimeException;
|
||||
use Twig\Error\LoaderError;
|
||||
@@ -30,7 +33,7 @@ use Twig\TemplateWrapper;
|
||||
* Class FlexForm
|
||||
* @package Grav\Framework\Flex
|
||||
*/
|
||||
class FlexForm implements FlexObjectFormInterface, \JsonSerializable
|
||||
class FlexForm implements FlexObjectFormInterface, JsonSerializable
|
||||
{
|
||||
use NestedArrayAccessWithGetters {
|
||||
NestedArrayAccessWithGetters::get as private traitGet;
|
||||
@@ -494,7 +497,7 @@ class FlexForm implements FlexObjectFormInterface, \JsonSerializable
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function doSubmit(array $data, array $files)
|
||||
{
|
||||
@@ -532,7 +535,7 @@ class FlexForm implements FlexObjectFormInterface, \JsonSerializable
|
||||
/**
|
||||
* Filter validated data.
|
||||
*
|
||||
* @param \ArrayAccess|Data|null $data
|
||||
* @param ArrayAccess|Data|null $data
|
||||
* @return void
|
||||
*/
|
||||
protected function filterData($data = null): void
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Grav\Framework\Flex\Interfaces;
|
||||
|
||||
use Grav\Framework\Form\Interfaces\FormInterface;
|
||||
use Grav\Framework\Route\Route;
|
||||
use Serializable;
|
||||
|
||||
/**
|
||||
* Defines Forms for Flex Objects.
|
||||
@@ -18,7 +19,7 @@ use Grav\Framework\Route\Route;
|
||||
* @used-by \Grav\Framework\Flex\FlexForm
|
||||
* @since 1.6
|
||||
*/
|
||||
interface FlexFormInterface extends \Serializable, FormInterface
|
||||
interface FlexFormInterface extends Serializable, FormInterface
|
||||
{
|
||||
/**
|
||||
* Get media task route.
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Grav\Framework\Flex\Interfaces;
|
||||
|
||||
use Countable;
|
||||
use Grav\Framework\Flex\FlexDirectory;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Interface FlexInterface
|
||||
@@ -66,7 +67,7 @@ interface FlexInterface extends Countable
|
||||
* @param array $options In addition to the options in getObjects(), following options can be passed:
|
||||
* collection_class: Class to be used to create the collection. Defaults to ObjectCollection.
|
||||
* @return FlexCollectionInterface
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getMixedCollection(array $keys, array $options = []): FlexCollectionInterface;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Framework\Flex\Interfaces;
|
||||
|
||||
use ArrayAccess;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Framework\Flex\Flex;
|
||||
use Grav\Framework\Object\Interfaces\NestedObjectInterface;
|
||||
@@ -25,7 +26,7 @@ use RuntimeException;
|
||||
* @used-by \Grav\Framework\Flex\FlexObject
|
||||
* @since 1.6
|
||||
*/
|
||||
interface FlexObjectInterface extends FlexCommonInterface, NestedObjectInterface, \ArrayAccess
|
||||
interface FlexObjectInterface extends FlexCommonInterface, NestedObjectInterface, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Construct a new Flex Object instance.
|
||||
|
||||
@@ -169,7 +169,7 @@ class FlexPageCollection extends FlexCollection
|
||||
*/
|
||||
public function currentPosition($path): ?int
|
||||
{
|
||||
$pos = \array_search($path, $this->getKeys(), true);
|
||||
$pos = array_search($path, $this->getKeys(), true);
|
||||
|
||||
return $pos !== false ? $pos : null;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use Grav\Framework\Flex\Pages\Traits\PageTranslateTrait;
|
||||
use Grav\Framework\Flex\Traits\FlexMediaTrait;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use function array_key_exists;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@ use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Framework\Filesystem\Filesystem;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
@@ -228,7 +229,7 @@ trait PageRoutableTrait
|
||||
public function unsetRouteSlug(): void
|
||||
{
|
||||
// TODO:
|
||||
throw new \RuntimeException(__METHOD__ . '(): Not Implemented');
|
||||
throw new RuntimeException(__METHOD__ . '(): Not Implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +242,7 @@ trait PageRoutableTrait
|
||||
{
|
||||
if (null !== $var) {
|
||||
// TODO:
|
||||
throw new \RuntimeException(__METHOD__ . '(string): Not Implemented');
|
||||
throw new RuntimeException(__METHOD__ . '(string): Not Implemented');
|
||||
}
|
||||
|
||||
if ($this->root()) {
|
||||
@@ -337,7 +338,7 @@ trait PageRoutableTrait
|
||||
{
|
||||
if (null !== $var) {
|
||||
// TODO:
|
||||
throw new \RuntimeException(__METHOD__ . '(string): Not Implemented');
|
||||
throw new RuntimeException(__METHOD__ . '(string): Not Implemented');
|
||||
}
|
||||
|
||||
$path = $this->_path;
|
||||
@@ -414,7 +415,7 @@ trait PageRoutableTrait
|
||||
{
|
||||
if (null !== $var) {
|
||||
// TODO:
|
||||
throw new \RuntimeException(__METHOD__ . '(PageInterface): Not Implemented');
|
||||
throw new RuntimeException(__METHOD__ . '(PageInterface): Not Implemented');
|
||||
}
|
||||
|
||||
if ($this->root()) {
|
||||
|
||||
@@ -23,6 +23,7 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use SplFileInfo;
|
||||
use function array_key_exists;
|
||||
use function basename;
|
||||
use function count;
|
||||
use function is_scalar;
|
||||
use function is_string;
|
||||
@@ -670,7 +671,7 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
$pattern .= '/{FILE}{EXT}';
|
||||
} else {
|
||||
$filesystem = Filesystem::getInstance(true);
|
||||
$this->dataFile = \basename($pattern, $extension);
|
||||
$this->dataFile = basename($pattern, $extension);
|
||||
$pattern = $filesystem->dirname($pattern) . '/{FILE}{EXT}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use Grav\Framework\Filesystem\Filesystem;
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use RuntimeException;
|
||||
use function is_scalar;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
@@ -154,7 +155,7 @@ class SimpleStorage extends AbstractFilesystemStorage
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $key => $row) {
|
||||
if (null === $row || \is_scalar($row)) {
|
||||
if (null === $row || is_scalar($row)) {
|
||||
// Only load rows which haven't been loaded before.
|
||||
$key = (string)$key;
|
||||
$list[$key] = $this->hasKey($key) ? $this->loadRow($key) : null;
|
||||
|
||||
@@ -23,9 +23,11 @@ use Grav\Framework\Form\FormFlashFile;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function strpos;
|
||||
|
||||
/**
|
||||
* Implements Grav Page content and header manipulation methods.
|
||||
@@ -81,10 +83,10 @@ trait FlexMediaTrait
|
||||
$schema = $this->getBlueprint()->schema();
|
||||
$settings = $field && is_object($schema) ? (array)$schema->getProperty($field) : null;
|
||||
|
||||
if (isset($settings['type']) && (\in_array($settings['type'], ['avatar', 'file', 'pagemedia']) || !empty($settings['destination']))) {
|
||||
if (isset($settings['type']) && (in_array($settings['type'], ['avatar', 'file', 'pagemedia']) || !empty($settings['destination']))) {
|
||||
// Set destination folder.
|
||||
$settings['media_field'] = true;
|
||||
if (empty($settings['destination']) || \in_array($settings['destination'], ['@self', 'self@', '@self@'], true)) {
|
||||
if (empty($settings['destination']) || in_array($settings['destination'], ['@self', 'self@', '@self@'], true)) {
|
||||
$settings['destination'] = $this->getMediaFolder();
|
||||
$settings['self'] = true;
|
||||
} else {
|
||||
@@ -187,7 +189,7 @@ trait FlexMediaTrait
|
||||
foreach ($files as $field => $group) {
|
||||
$field = (string)$field;
|
||||
// Ignore files without a field and resized images.
|
||||
if ($field === '' || \strpos($field, '/')) {
|
||||
if ($field === '' || strpos($field, '/')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Framework\Form;
|
||||
|
||||
use Exception;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\User\Interfaces\UserInterface;
|
||||
@@ -17,6 +18,9 @@ use Grav\Framework\Form\Interfaces\FormFlashInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use function func_get_args;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* Class FormFlash
|
||||
@@ -122,7 +126,7 @@ class FormFlash implements FormFlashInterface
|
||||
if ($exists) {
|
||||
try {
|
||||
$data = (array)$file->content();
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +311,7 @@ class FormFlash implements FormFlashInterface
|
||||
$tmp_name = Utils::generateRandomString(12);
|
||||
$name = $upload->getClientFilename();
|
||||
if (!$name) {
|
||||
throw new \RuntimeException('Uploaded file has no filename');
|
||||
throw new RuntimeException('Uploaded file has no filename');
|
||||
}
|
||||
|
||||
// Prepare upload data for later save
|
||||
@@ -332,7 +336,7 @@ class FormFlash implements FormFlashInterface
|
||||
public function addFile(string $filename, string $field, array $crop = null): bool
|
||||
{
|
||||
if (!file_exists($filename)) {
|
||||
throw new \RuntimeException("File not found: {$filename}");
|
||||
throw new RuntimeException("File not found: {$filename}");
|
||||
}
|
||||
|
||||
// Prepare upload data for later save
|
||||
@@ -517,7 +521,7 @@ class FormFlash implements FormFlashInterface
|
||||
protected function addFileInternal(?string $field, string $name, array $data, array $crop = null): void
|
||||
{
|
||||
if (!($this->folder && $this->uniqueId)) {
|
||||
throw new \RuntimeException('Cannot upload files: form flash folder not defined');
|
||||
throw new RuntimeException('Cannot upload files: form flash folder not defined');
|
||||
}
|
||||
|
||||
$field = $field ?: 'undefined';
|
||||
|
||||
@@ -10,8 +10,14 @@
|
||||
namespace Grav\Framework\Form;
|
||||
|
||||
use Grav\Framework\Psr7\Stream;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RuntimeException;
|
||||
use function copy;
|
||||
use function fopen;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Class FormFlashFile
|
||||
@@ -59,12 +65,12 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
|
||||
|
||||
$tmpFile = $this->getTmpFile();
|
||||
if (null === $tmpFile) {
|
||||
throw new \RuntimeException('No temporary file');
|
||||
throw new RuntimeException('No temporary file');
|
||||
}
|
||||
|
||||
$resource = \fopen($tmpFile, 'rb');
|
||||
$resource = fopen($tmpFile, 'rb');
|
||||
if (false === $resource) {
|
||||
throw new \RuntimeException('No temporary file');
|
||||
throw new RuntimeException('No temporary file');
|
||||
}
|
||||
|
||||
return Stream::create($resource);
|
||||
@@ -78,18 +84,18 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
|
||||
{
|
||||
$this->validateActive();
|
||||
|
||||
if (!\is_string($targetPath) || empty($targetPath)) {
|
||||
throw new \InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
|
||||
if (!is_string($targetPath) || empty($targetPath)) {
|
||||
throw new InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
|
||||
}
|
||||
$tmpFile = $this->getTmpFile();
|
||||
if (null === $tmpFile) {
|
||||
throw new \RuntimeException('No temporary file');
|
||||
throw new RuntimeException('No temporary file');
|
||||
}
|
||||
|
||||
$this->moved = \copy($tmpFile, $targetPath);
|
||||
$this->moved = copy($tmpFile, $targetPath);
|
||||
|
||||
if (false === $this->moved) {
|
||||
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath));
|
||||
throw new RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath));
|
||||
}
|
||||
|
||||
$filename = $this->getClientFilename();
|
||||
@@ -204,20 +210,20 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \RuntimeException if is moved or not ok
|
||||
* @throws RuntimeException if is moved or not ok
|
||||
*/
|
||||
private function validateActive(): void
|
||||
{
|
||||
if (!$this->isOk()) {
|
||||
throw new \RuntimeException('Cannot retrieve stream due to upload error');
|
||||
throw new RuntimeException('Cannot retrieve stream due to upload error');
|
||||
}
|
||||
|
||||
if ($this->moved) {
|
||||
throw new \RuntimeException('Cannot retrieve stream after it has already been moved');
|
||||
throw new RuntimeException('Cannot retrieve stream after it has already been moved');
|
||||
}
|
||||
|
||||
if (!$this->getTmpFile()) {
|
||||
throw new \RuntimeException('Cannot retrieve stream as the file is missing');
|
||||
throw new RuntimeException('Cannot retrieve stream as the file is missing');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
|
||||
namespace Grav\Framework\Form\Traits;
|
||||
|
||||
use ArrayAccess;
|
||||
use Exception;
|
||||
use FilesystemIterator;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Data\ValidationException;
|
||||
@@ -25,10 +28,15 @@ use Grav\Framework\Form\Interfaces\FormInterface;
|
||||
use Grav\Framework\Session\SessionInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RuntimeException;
|
||||
use SplFileInfo;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Template;
|
||||
use Twig\TemplateWrapper;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
|
||||
/**
|
||||
* Trait FormTrait
|
||||
@@ -55,7 +63,7 @@ trait FormTrait
|
||||
private $sessionid;
|
||||
/** @var bool */
|
||||
private $submitted;
|
||||
/** @var \ArrayAccess|Data|null */
|
||||
/** @var ArrayAccess|Data|null */
|
||||
private $data;
|
||||
/** @var array|UploadedFileInterface[] */
|
||||
private $files;
|
||||
@@ -201,9 +209,9 @@ trait FormTrait
|
||||
while ($path) {
|
||||
$offset = array_shift($path);
|
||||
|
||||
if ((\is_array($current) || $current instanceof \ArrayAccess) && isset($current[$offset])) {
|
||||
if ((is_array($current) || $current instanceof ArrayAccess) && isset($current[$offset])) {
|
||||
$current = $current[$offset];
|
||||
} elseif (\is_object($current) && isset($current->{$offset})) {
|
||||
} elseif (is_object($current) && isset($current->{$offset})) {
|
||||
$current = $current->{$offset};
|
||||
} else {
|
||||
return null;
|
||||
@@ -242,7 +250,7 @@ trait FormTrait
|
||||
[$data, $files] = $this->parseRequest($request);
|
||||
|
||||
$this->submit($data, $files);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = $grav['debugger'];
|
||||
$debugger->addException($e);
|
||||
@@ -313,7 +321,7 @@ trait FormTrait
|
||||
$this->validateUploads($this->getFiles());
|
||||
} catch (ValidationException $e) {
|
||||
$this->setErrors($e->getMessages());
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = Grav::instance()['debugger'];
|
||||
$debugger->addException($e);
|
||||
@@ -335,7 +343,7 @@ trait FormTrait
|
||||
{
|
||||
try {
|
||||
if ($this->isSubmitted()) {
|
||||
throw new \RuntimeException('Form has already been submitted');
|
||||
throw new RuntimeException('Form has already been submitted');
|
||||
}
|
||||
|
||||
$this->data = new Data($data, $this->getBlueprint());
|
||||
@@ -348,7 +356,7 @@ trait FormTrait
|
||||
$this->doSubmit($this->data->toArray(), $this->files);
|
||||
|
||||
$this->submitted = true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = Grav::instance()['debugger'];
|
||||
$debugger->addException($e);
|
||||
@@ -444,8 +452,8 @@ trait FormTrait
|
||||
$name = $this->getName();
|
||||
|
||||
$list = [];
|
||||
/** @var \SplFileInfo $file */
|
||||
foreach (new \FilesystemIterator($folder) as $file) {
|
||||
/** @var SplFileInfo $file */
|
||||
foreach (new FilesystemIterator($folder) as $file) {
|
||||
$uniqueId = $file->getFilename();
|
||||
$config = [
|
||||
'session_id' => $this->getSessionId(),
|
||||
@@ -654,8 +662,8 @@ trait FormTrait
|
||||
protected function parseRequest(ServerRequestInterface $request): array
|
||||
{
|
||||
$method = $request->getMethod();
|
||||
if (!\in_array($method, ['PUT', 'POST', 'PATCH'])) {
|
||||
throw new \RuntimeException(sprintf('FlexForm: Bad HTTP method %s', $method));
|
||||
if (!in_array($method, ['PUT', 'POST', 'PATCH'])) {
|
||||
throw new RuntimeException(sprintf('FlexForm: Bad HTTP method %s', $method));
|
||||
}
|
||||
|
||||
$body = $request->getParsedBody();
|
||||
@@ -684,10 +692,10 @@ trait FormTrait
|
||||
/**
|
||||
* Validate data and throw validation exceptions if validation fails.
|
||||
*
|
||||
* @param \ArrayAccess|Data|null $data
|
||||
* @param ArrayAccess|Data|null $data
|
||||
* @return void
|
||||
* @throws ValidationException
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function validateData($data = null): void
|
||||
{
|
||||
@@ -699,7 +707,7 @@ trait FormTrait
|
||||
/**
|
||||
* Filter validated data.
|
||||
*
|
||||
* @param \ArrayAccess|Data|null $data
|
||||
* @param ArrayAccess|Data|null $data
|
||||
* @return void
|
||||
*/
|
||||
protected function filterData($data = null): void
|
||||
@@ -742,7 +750,7 @@ trait FormTrait
|
||||
|
||||
if ($filename && !Utils::checkFilename($filename)) {
|
||||
$grav = Grav::instance();
|
||||
throw new \RuntimeException(
|
||||
throw new RuntimeException(
|
||||
sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_UPLOAD', null, true), $filename, 'Bad filename')
|
||||
);
|
||||
}
|
||||
@@ -756,7 +764,7 @@ trait FormTrait
|
||||
*/
|
||||
protected function decodeData($data): array
|
||||
{
|
||||
if (!\is_array($data)) {
|
||||
if (!is_array($data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -764,7 +772,7 @@ trait FormTrait
|
||||
if (isset($data['_json'])) {
|
||||
$data = array_replace_recursive($data, $this->jsonDecode($data['_json']));
|
||||
if (null === $data) {
|
||||
throw new \RuntimeException(__METHOD__ . '(): Unexpected error');
|
||||
throw new RuntimeException(__METHOD__ . '(): Unexpected error');
|
||||
}
|
||||
unset($data['_json']);
|
||||
}
|
||||
@@ -781,7 +789,7 @@ trait FormTrait
|
||||
protected function jsonDecode(array $data): array
|
||||
{
|
||||
foreach ($data as $key => &$value) {
|
||||
if (\is_array($value)) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->jsonDecode($value);
|
||||
} elseif (trim($value) === '') {
|
||||
unset($data[$key]);
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
namespace Grav\Framework\Object\Access;
|
||||
|
||||
use Grav\Framework\Object\Interfaces\ObjectInterface;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
|
||||
/**
|
||||
* Nested Property Object Trait
|
||||
@@ -24,7 +28,7 @@ trait NestedPropertyTrait
|
||||
*/
|
||||
public function hasNestedProperty($property, $separator = null)
|
||||
{
|
||||
$test = new \stdClass;
|
||||
$test = new stdClass;
|
||||
|
||||
return $this->getNestedProperty($property, $test, $separator) !== $test;
|
||||
}
|
||||
@@ -58,9 +62,9 @@ trait NestedPropertyTrait
|
||||
|
||||
$offset = array_shift($path);
|
||||
|
||||
if ((\is_array($current) || is_a($current, 'ArrayAccess')) && isset($current[$offset])) {
|
||||
if ((is_array($current) || is_a($current, 'ArrayAccess')) && isset($current[$offset])) {
|
||||
$current = $current[$offset];
|
||||
} elseif (\is_object($current) && isset($current->{$offset})) {
|
||||
} elseif (is_object($current) && isset($current->{$offset})) {
|
||||
$current = $current->{$offset};
|
||||
} else {
|
||||
return $default;
|
||||
@@ -76,7 +80,7 @@ trait NestedPropertyTrait
|
||||
* @param mixed $value New value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setNestedProperty($property, $value, $separator = null)
|
||||
{
|
||||
@@ -98,12 +102,12 @@ trait NestedPropertyTrait
|
||||
// Handle arrays and scalars.
|
||||
if ($current === null) {
|
||||
$current = [$offset => []];
|
||||
} elseif (\is_array($current)) {
|
||||
} elseif (is_array($current)) {
|
||||
if (!isset($current[$offset])) {
|
||||
$current[$offset] = [];
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Cannot set nested property {$property} on non-array value");
|
||||
throw new RuntimeException("Cannot set nested property {$property} on non-array value");
|
||||
}
|
||||
|
||||
$current = &$current[$offset];
|
||||
@@ -118,7 +122,7 @@ trait NestedPropertyTrait
|
||||
* @param string $property Object property to be updated.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function unsetNestedProperty($property, $separator = null)
|
||||
{
|
||||
@@ -142,12 +146,12 @@ trait NestedPropertyTrait
|
||||
if ($current === null) {
|
||||
return $this;
|
||||
}
|
||||
if (\is_array($current)) {
|
||||
if (is_array($current)) {
|
||||
if (!isset($current[$offset])) {
|
||||
return $this;
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Cannot unset nested property {$property} on non-array value");
|
||||
throw new RuntimeException("Cannot unset nested property {$property} on non-array value");
|
||||
}
|
||||
|
||||
$current = &$current[$offset];
|
||||
@@ -163,7 +167,7 @@ trait NestedPropertyTrait
|
||||
* @param mixed $default Default value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function defNestedProperty($property, $default, $separator = null)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Framework\Object;
|
||||
|
||||
use ArrayAccess;
|
||||
use Grav\Framework\Object\Access\NestedArrayAccessTrait;
|
||||
use Grav\Framework\Object\Access\NestedPropertyTrait;
|
||||
use Grav\Framework\Object\Access\OverloadedPropertyTrait;
|
||||
@@ -19,7 +20,7 @@ use Grav\Framework\Object\Property\ArrayPropertyTrait;
|
||||
/**
|
||||
* Array Objects keep the data in private array property.
|
||||
*/
|
||||
class ArrayObject implements NestedObjectInterface, \ArrayAccess
|
||||
class ArrayObject implements NestedObjectInterface, ArrayAccess
|
||||
{
|
||||
use ObjectTrait;
|
||||
use ArrayPropertyTrait;
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace Grav\Framework\Object\Base;
|
||||
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use Grav\Framework\Object\Interfaces\ObjectInterface;
|
||||
use function call_user_func_array;
|
||||
use function get_class;
|
||||
use function is_callable;
|
||||
use function is_object;
|
||||
|
||||
/**
|
||||
* ObjectCollection Trait
|
||||
@@ -46,7 +50,7 @@ trait ObjectCollectionTrait
|
||||
return $type . static::$type;
|
||||
}
|
||||
|
||||
$class = \get_class($this);
|
||||
$class = get_class($this);
|
||||
return $type . strtolower(substr($class, strrpos($class, '\\') + 1));
|
||||
}
|
||||
|
||||
@@ -210,7 +214,7 @@ trait ObjectCollectionTrait
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->getIterator() as $key => $value) {
|
||||
$list[$key] = \is_object($value) ? clone $value : $value;
|
||||
$list[$key] = is_object($value) ? clone $value : $value;
|
||||
}
|
||||
|
||||
return $this->createFrom($list);
|
||||
@@ -317,7 +321,7 @@ trait ObjectCollectionTrait
|
||||
*/
|
||||
foreach ($this->getIterator() as $id => $element) {
|
||||
$callable = [$element, $method];
|
||||
$list[$id] = is_callable($callable) ? \call_user_func_array($callable, $arguments) : null;
|
||||
$list[$id] = is_callable($callable) ? call_user_func_array($callable, $arguments) : null;
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
namespace Grav\Framework\Object\Base;
|
||||
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use InvalidArgumentException;
|
||||
use function get_class;
|
||||
|
||||
/**
|
||||
* Object trait.
|
||||
@@ -46,7 +48,7 @@ trait ObjectTrait
|
||||
return $type . static::$type;
|
||||
}
|
||||
|
||||
$class = \get_class($this);
|
||||
$class = get_class($this);
|
||||
return $type . strtolower(substr($class, strrpos($class, '\\') + 1));
|
||||
}
|
||||
|
||||
@@ -158,7 +160,7 @@ trait ObjectTrait
|
||||
protected function doUnserialize(array $serialized)
|
||||
{
|
||||
if (!isset($serialized['key'], $serialized['type'], $serialized['elements']) || $serialized['type'] !== $this->getType()) {
|
||||
throw new \InvalidArgumentException("Cannot unserialize '{$this->getType()}': Bad data");
|
||||
throw new InvalidArgumentException("Cannot unserialize '{$this->getType()}': Bad data");
|
||||
}
|
||||
|
||||
$this->setKey($serialized['key']);
|
||||
|
||||
@@ -9,9 +9,15 @@
|
||||
|
||||
namespace Grav\Framework\Object\Collection;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use RuntimeException;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
use function is_string;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Class ObjectExpressionVisitor
|
||||
@@ -124,11 +130,11 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $orientation
|
||||
* @param \Closure|null $next
|
||||
* @param Closure|null $next
|
||||
*
|
||||
* @return \Closure
|
||||
* @return Closure
|
||||
*/
|
||||
public static function sortByField($name, $orientation = 1, \Closure $next = null)
|
||||
public static function sortByField($name, $orientation = 1, Closure $next = null)
|
||||
{
|
||||
if (!$next) {
|
||||
$next = function ($a, $b) {
|
||||
@@ -145,7 +151,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
|
||||
}
|
||||
|
||||
// For strings we use natural case insensitive sorting.
|
||||
if (\is_string($aValue) && \is_string($bValue)) {
|
||||
if (is_string($aValue) && is_string($bValue)) {
|
||||
return strnatcasecmp($aValue, $bValue) * $orientation;
|
||||
}
|
||||
|
||||
@@ -194,12 +200,12 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
|
||||
|
||||
case Comparison::IN:
|
||||
return function ($object) use ($field, $value) {
|
||||
return \in_array(static::getObjectFieldValue($object, $field), $value, true);
|
||||
return in_array(static::getObjectFieldValue($object, $field), $value, true);
|
||||
};
|
||||
|
||||
case Comparison::NIN:
|
||||
return function ($object) use ($field, $value) {
|
||||
return !\in_array(static::getObjectFieldValue($object, $field), $value, true);
|
||||
return !in_array(static::getObjectFieldValue($object, $field), $value, true);
|
||||
};
|
||||
|
||||
case Comparison::CONTAINS:
|
||||
@@ -210,10 +216,10 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
|
||||
case Comparison::MEMBER_OF:
|
||||
return function ($object) use ($field, $value) {
|
||||
$fieldValues = static::getObjectFieldValue($object, $field);
|
||||
if (!\is_array($fieldValues)) {
|
||||
if (!is_array($fieldValues)) {
|
||||
$fieldValues = iterator_to_array($fieldValues);
|
||||
}
|
||||
return \in_array($value, $fieldValues, true);
|
||||
return in_array($value, $fieldValues, true);
|
||||
};
|
||||
|
||||
case Comparison::STARTS_WITH:
|
||||
@@ -227,7 +233,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
|
||||
};
|
||||
|
||||
default:
|
||||
throw new \RuntimeException("Unknown comparison operator: " . $comparison->getOperator());
|
||||
throw new RuntimeException("Unknown comparison operator: " . $comparison->getOperator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace Grav\Framework\Object\Interfaces;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Common Interface for both Objects and Collections
|
||||
* @package Grav\Framework\Object
|
||||
@@ -39,7 +41,7 @@ interface NestedObjectCollectionInterface extends ObjectCollectionInterface
|
||||
* @param mixed $value New value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setNestedProperty($property, $value, $separator = null);
|
||||
|
||||
@@ -48,7 +50,7 @@ interface NestedObjectCollectionInterface extends ObjectCollectionInterface
|
||||
* @param mixed $default Default value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function defNestedProperty($property, $default, $separator = null);
|
||||
|
||||
@@ -56,7 +58,7 @@ interface NestedObjectCollectionInterface extends ObjectCollectionInterface
|
||||
* @param string $property Object property to be unset.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function unsetNestedProperty($property, $separator = null);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace Grav\Framework\Object\Interfaces;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Common Interface for both Objects and Collections
|
||||
* @package Grav\Framework\Object
|
||||
@@ -35,7 +37,7 @@ interface NestedObjectInterface extends ObjectInterface
|
||||
* @param mixed $value New value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setNestedProperty($property, $value, $separator = null);
|
||||
|
||||
@@ -44,7 +46,7 @@ interface NestedObjectInterface extends ObjectInterface
|
||||
* @param mixed $default Default value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function defNestedProperty($property, $default, $separator = null);
|
||||
|
||||
@@ -52,7 +54,7 @@ interface NestedObjectInterface extends ObjectInterface
|
||||
* @param string $property Object property to be unset.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function unsetNestedProperty($property, $separator = null);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Grav\Framework\Object\Interfaces;
|
||||
|
||||
use Doctrine\Common\Collections\Selectable;
|
||||
use Grav\Framework\Collection\CollectionInterface;
|
||||
use Serializable;
|
||||
|
||||
/**
|
||||
* ObjectCollection Interface
|
||||
@@ -20,7 +21,7 @@ use Grav\Framework\Collection\CollectionInterface;
|
||||
* @extends CollectionInterface<TKey,T>
|
||||
* @extends Selectable<TKey,T>
|
||||
*/
|
||||
interface ObjectCollectionInterface extends CollectionInterface, Selectable, \Serializable
|
||||
interface ObjectCollectionInterface extends CollectionInterface, Selectable, Serializable
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
|
||||
@@ -9,11 +9,14 @@
|
||||
|
||||
namespace Grav\Framework\Object\Interfaces;
|
||||
|
||||
use JsonSerializable;
|
||||
use Serializable;
|
||||
|
||||
/**
|
||||
* Object Interface
|
||||
* @package Grav\Framework\Object
|
||||
*/
|
||||
interface ObjectInterface extends \Serializable, \JsonSerializable
|
||||
interface ObjectInterface extends Serializable, JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user