mirror of
https://github.com/getgrav/grav.git
synced 2026-07-10 09:13:47 +02:00
Add some better type checks
This commit is contained in:
@@ -55,20 +55,6 @@ class Pipeline extends PropertyObject
|
||||
/** @var string */
|
||||
protected $asset;
|
||||
|
||||
/**
|
||||
* Closure used by the pipeline to fetch assets.
|
||||
*
|
||||
* Useful when file_get_contents() function is not available in your PHP
|
||||
* installation or when you want to apply any kind of preprocessing to
|
||||
* your assets before they get pipelined.
|
||||
*
|
||||
* The closure will receive as the only parameter a string with the path/URL of the asset and
|
||||
* it should return the content of the asset file as a string.
|
||||
*
|
||||
* @var \Closure|null
|
||||
*/
|
||||
protected $fetch_command;
|
||||
|
||||
public function __construct(array $elements = [], ?string $key = null)
|
||||
{
|
||||
parent::__construct($elements, $key);
|
||||
@@ -249,9 +235,7 @@ class Pipeline extends PropertyObject
|
||||
|
||||
$new_url = ($local ? $this->base_url: '') . $old_url;
|
||||
|
||||
$fixed = str_replace($matches[2], $new_url, $matches[0]);
|
||||
|
||||
return $fixed;
|
||||
return str_replace($matches[2], $new_url, $matches[0]);
|
||||
}, $file);
|
||||
|
||||
return $file;
|
||||
|
||||
@@ -55,8 +55,8 @@ class PageStorage extends FolderStorage
|
||||
$this->ignore_hidden = (bool)$config->get('system.pages.ignore_hidden');
|
||||
$this->ignore_files = (array)$config->get('system.pages.ignore_files');
|
||||
$this->ignore_folders = (array)$config->get('system.pages.ignore_folders');
|
||||
$this->include_default_lang_file_extension = $config->get('system.languages.include_default_lang_file_extension', true);
|
||||
$this->recurse = $options['recurse'] ?? true;
|
||||
$this->include_default_lang_file_extension = (bool)$config->get('system.languages.include_default_lang_file_extension', true);
|
||||
$this->recurse = (bool)($options['recurse'] ?? true);
|
||||
$this->regex = '/(\.([\w\d_-]+))?\.md$/D';
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,6 @@ class Package extends BasePackage
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->settings['enabled'];
|
||||
return (bool)$this->settings['enabled'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ trait GravTrait
|
||||
{
|
||||
user_error(__TRAIT__ . ' is deprecated since Grav 1.4, use Grav::instance() instead', E_USER_DEPRECATED);
|
||||
|
||||
if (!self::$grav) {
|
||||
if (null === self::$grav) {
|
||||
self::$grav = Grav::instance();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ class Exif
|
||||
public function __construct()
|
||||
{
|
||||
if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
|
||||
if (function_exists('exif_read_data') && class_exists('\PHPExif\Reader\Reader')) {
|
||||
$this->reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_NATIVE);
|
||||
if (function_exists('exif_read_data') && class_exists(Reader::class)) {
|
||||
$this->reader = Reader::factory(Reader::TYPE_NATIVE);
|
||||
} else {
|
||||
throw new \RuntimeException('Please enable the Exif extension for PHP or disable Exif support in Grav system configuration');
|
||||
}
|
||||
@@ -37,10 +37,6 @@ class Exif
|
||||
*/
|
||||
public function getReader()
|
||||
{
|
||||
if ($this->reader) {
|
||||
return $this->reader;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->reader;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable
|
||||
throw new \InvalidArgumentException('First parameter must be URI');
|
||||
}
|
||||
|
||||
if (!$this->systemBlueprints) {
|
||||
if (null === $this->systemBlueprints) {
|
||||
$this->systemBlueprints = $this->findBlueprints('blueprints://pages');
|
||||
|
||||
// Register default by default.
|
||||
|
||||
@@ -191,8 +191,8 @@ class Twig
|
||||
$this->twig->addExtension(new DeferredExtension());
|
||||
$this->twig->addExtension(new StringLoaderExtension());
|
||||
|
||||
$this->profile = new \Twig\Profiler\Profile();
|
||||
$this->twig->addExtension(new \Twig\Extension\ProfilerExtension($this->profile));
|
||||
$this->profile = new Profile();
|
||||
$this->twig->addExtension(new ProfilerExtension($this->profile));
|
||||
|
||||
|
||||
$this->grav->fireEvent('onTwigExtensions');
|
||||
|
||||
@@ -156,6 +156,9 @@ class Uri
|
||||
|
||||
if ($custom_base) {
|
||||
$custom_parts = parse_url($custom_base);
|
||||
if ($custom_parts === false) {
|
||||
throw new \RuntimeException('Bad configuration: system.custom_base_url');
|
||||
}
|
||||
$orig_root_path = $this->root_path;
|
||||
$this->root_path = isset($custom_parts['path']) ? rtrim($custom_parts['path'], '/') : '';
|
||||
if (isset($custom_parts['scheme'])) {
|
||||
|
||||
@@ -78,7 +78,12 @@ class SandboxCommand extends ConsoleCommand
|
||||
'Symlink the base grav system'
|
||||
)
|
||||
->setHelp("The <info>sandbox</info> command help create a development environment that can optionally use symbolic links to link the core of grav to the git cloned repository.\nGood for development, playing around or starting fresh");
|
||||
$this->source = getcwd();
|
||||
|
||||
$source = getcwd();
|
||||
if ($source === false) {
|
||||
throw new \RuntimeException('Internal Error');
|
||||
}
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
protected function serve()
|
||||
|
||||
Reference in New Issue
Block a user