Grav 1.6 copyright updates and cleanup (PHP files only) (#2351)

* Framework: update copyrights to 2019

* Some code cleanup (Assets, Backup, Config, Session)

* Continue code cleanup, update copyrights

* Fixed exception issues in scheduler, code cleanup

* Remove apc and xcache support, make apc alias of apcu

* Fixed Getters::count() method not returning anything

* More code cleanup, copyright updates

* Copyright updates for Grav\Console
This commit is contained in:
Matias Griese 2019-01-30 22:44:19 +02:00 committed by Andy Miller
parent 604361045b
commit 0566185c4f
289 changed files with 1616 additions and 1331 deletions

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets
* @package Grav\Common\Assets
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -13,17 +14,16 @@ use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Utils;
use Grav\Framework\Object\PropertyObject;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
abstract class BaseAsset extends PropertyObject
{
use AssetUtilsTrait;
const CSS_ASSET = true;
const JS_ASSET = false;
protected const CSS_ASSET = true;
protected const JS_ASSET = false;
/** @const Regex to match CSS import content */
const CSS_IMPORT_REGEX = '{@import(.*?);}';
protected const CSS_IMPORT_REGEX = '{@import(.*?);}';
protected $asset;
@ -81,7 +81,7 @@ abstract class BaseAsset extends PropertyObject
// Do some special stuff for CSS/JS (not inline)
if (!Utils::startsWith($this->getType(), 'inline')) {
$this->base_url = rtrim($uri->rootUrl($config->get('system.absolute_urls')), '/') . '/';
$this->remote = $this->isRemoteLink($asset);
$this->remote = static::isRemoteLink($asset);
// Move this to render?
if (!$this->remote) {

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets
* @package Grav\Common\Assets
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -12,7 +13,6 @@ use Grav\Common\Utils;
class Css extends BaseAsset
{
public function __construct(array $elements = [], $key = null)
{
$base_options = [

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets
* @package Grav\Common\Assets
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets
* @package Grav\Common\Assets
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets
* @package Grav\Common\Assets
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets
* @package Grav\Common\Assets
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -20,17 +21,17 @@ class Pipeline extends PropertyObject
{
use AssetUtilsTrait;
const CSS_ASSET = true;
const JS_ASSET = false;
protected const CSS_ASSET = true;
protected const JS_ASSET = false;
/** @const Regex to match CSS urls */
const CSS_URL_REGEX = '{url\(([\'\"]?)(.*?)\1\)}';
protected const CSS_URL_REGEX = '{url\(([\'\"]?)(.*?)\1\)}';
/** @const Regex to match CSS sourcemap comments */
const CSS_SOURCEMAP_REGEX = '{\/\*# (.*?) \*\/}';
protected const CSS_SOURCEMAP_REGEX = '{\/\*# (.*?) \*\/}';
/** @const Regex to match CSS import content */
const CSS_IMPORT_REGEX = '{@import(.*?);}';
protected const CSS_IMPORT_REGEX = '{@import(.*?);}';
protected $css_minify;
protected $css_minify_windows;
@ -140,7 +141,7 @@ class Pipeline extends PropertyObject
}
// Write file
if (\strlen(trim($buffer)) > 0) {
if (trim($buffer) !== '') {
file_put_contents($this->assets_dir . $file, $buffer);
}
}
@ -213,16 +214,16 @@ class Pipeline extends PropertyObject
}
// Write file
if (\strlen(trim($buffer)) > 0) {
if (trim($buffer) !== '') {
file_put_contents($this->assets_dir . $file, $buffer);
}
}
if ($inline_group) {
$output = "<script" . $this->renderAttributes(). ">\n" . $buffer . "\n</script>\n";
$output = '<script' . $this->renderAttributes(). ">\n" . $buffer . "\n</script>\n";
} else {
$this->asset = $relative_path;
$output = "<script src=\"" . $relative_path . $this->renderQueryString() . "\"" . $this->renderAttributes() . "></script>\n";
$output = '<script src="' . $relative_path . $this->renderQueryString() . '"' . $this->renderAttributes() . "></script>\n";
}
return $output;
@ -249,7 +250,7 @@ class Pipeline extends PropertyObject
$old_url = $matches[2];
// Ensure link is not rooted to webserver, a data URL, or to a remote host
// Ensure link is not rooted to web server, a data URL, or to a remote host
if (Utils::startsWith($old_url, '/') || Utils::startsWith($old_url, 'data:') || $this->isRemoteLink($old_url)) {
return $matches[0];
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets.Traits
* @package Grav\Common\Assets\Traits
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -24,7 +25,7 @@ trait AssetUtilsTrait
{
$base = Grav::instance()['uri']->rootUrl(true);
// sanity check for local URLs with absolute URL's enabled
// Sanity check for local URLs with absolute URL's enabled
if (Utils::startsWith($link, $base)) {
return false;
}
@ -52,12 +53,12 @@ trait AssetUtilsTrait
$link = $asset->getAsset();
$relative_path = $link;
if ($this->isRemoteLink($link)) {
if (static::isRemoteLink($link)) {
$local = false;
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)) {
@ -65,7 +66,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;
}
@ -73,7 +74,7 @@ trait AssetUtilsTrait
// No file found, skip it...
if ($file === false) {
if (!$local) { // Assume we coudln't download this file for some reason assume it's not pipeline compatible
if (!$local) { // Assume we couldn't download this file for some reason assume it's not pipeline compatible
$no_pipeline[$id] = $asset;
}
continue;
@ -125,8 +126,6 @@ trait AssetUtilsTrait
*
* Build an HTML attribute string from an array.
*
* @param array $attributes
*
* @return string
*/
protected function renderAttributes()
@ -157,6 +156,7 @@ trait AssetUtilsTrait
/**
* Render Querystring
*
* @param string $asset
* @return string
*/
protected function renderQueryString($asset = null)

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets.Traits
* @package Grav\Common\Assets\Traits
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Assets.Traits
* @package Grav\Common\Assets\Traits
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -44,6 +45,7 @@ trait TestingAssetsTrait
public function setCollection($collections)
{
$this->collections = $collections;
return $this;
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Backup
* @package Grav\Common\Backup
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -21,9 +22,9 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
class Backups
{
const BACKUP_FILENAME_REGEXZ = "#(.*)--(\d*).zip#";
protected const BACKUP_FILENAME_REGEXZ = "#(.*)--(\d*).zip#";
const BACKUP_DATE_FORMAT = 'YmdHis';
protected const BACKUP_DATE_FORMAT = 'YmdHis';
protected static $backup_dir;
@ -39,7 +40,7 @@ class Backups
public function setup()
{
if (is_null(static::$backup_dir)) {
if (null === static::$backup_dir) {
static::$backup_dir = Grav::instance()['locator']->findResource('backup://', true, true);
Folder::create(static::$backup_dir);
}
@ -53,9 +54,9 @@ class Backups
/** @var Inflector $inflector */
$inflector = Grav::instance()['inflector'];
foreach ($this->getBackupProfiles() as $id => $profile) {
foreach (static::getBackupProfiles() as $id => $profile) {
$at = $profile['schedule_at'];
$name = $inflector->hyphenize($profile['name']);
$name = $inflector::hyphenize($profile['name']);
$logs = 'logs/backup-' . $name . '.out';
/** @var Job $job */
$job = $scheduler->addFunction('Grav\Common\Backup\Backups::backup', [$id], $name );
@ -86,7 +87,7 @@ class Backups
public function getBackupNames()
{
return array_column($this->getBackupProfiles(), 'name');
return array_column(static::getBackupProfiles(), 'name');
}
public static function getTotalBackupsSize()
@ -99,7 +100,7 @@ class Backups
public static function getAvailableBackups($force = false)
{
if ($force || is_null(static::$backups)) {
if ($force || null === static::$backups) {
static::$backups = [];
$backups_itr = new \GlobIterator(static::$backup_dir . '/*.zip', \FilesystemIterator::KEY_AS_FILENAME);
$inflector = Grav::instance()['inflector'];
@ -165,7 +166,7 @@ class Backups
}
if (!file_exists($backup_root)) {
throw new \RuntimeException("Backup location: " . $backup_root . ' does not exist...');
throw new \RuntimeException("Backup location: {$backup_root} does not exist...");
}
$options = [
@ -245,6 +246,6 @@ class Backups
protected static function convertExclude($exclude)
{
$lines = preg_split("/[\s,]+/", $exclude);
return array_map('trim', $lines, array_fill(0,count($lines),'/'));
return array_map('trim', $lines, array_fill(0, \count($lines), '/'));
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -113,7 +114,7 @@ class Browser
{
$version = explode('.', $this->getLongVersion());
return intval($version[0]);
return (int)$version[0];
}
/**
@ -143,10 +144,6 @@ class Browser
*/
public function isTrackable(): bool
{
if (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] === '1') {
return false;
}
return true;
return !(isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] === '1');
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -11,7 +12,9 @@ namespace Grav\Common;
use \Doctrine\Common\Cache as DoctrineCache;
use Grav\Common\Config\Config;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Scheduler\Scheduler;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\Event\EventDispatcher;
/**
* The GravCache object is used throughout Grav to store and retrieve cached data.
@ -117,7 +120,7 @@ class Cache extends Getters
$this->config = $grav['config'];
$this->now = time();
if (is_null($this->enabled)) {
if (null === $this->enabled) {
$this->enabled = (bool)$this->config->get('system.cache.enabled');
}
@ -147,7 +150,7 @@ class Cache extends Getters
foreach (new \DirectoryIterator($cache_dir) as $file) {
$dir = $file->getBasename();
if ($file->isDot() || $file->isFile() || $dir === $current) {
if ($dir === $current || $file->isDot() || $file->isFile()) {
continue;
}
@ -165,7 +168,7 @@ class Cache extends Getters
*/
public function setEnabled($enabled)
{
$this->enabled = (bool) $enabled;
$this->enabled = (bool)$enabled;
}
/**
@ -202,19 +205,15 @@ class Cache extends Getters
// CLI compatibility requires a non-volatile cache driver
if ($this->config->get('system.cache.cli_compatibility') && (
$setting == 'auto' || $this->isVolatileDriver($setting))) {
$setting === 'auto' || $this->isVolatileDriver($setting))) {
$setting = $driver_name;
}
if (!$setting || $setting == 'auto') {
if (!$setting || $setting === 'auto') {
if (extension_loaded('apcu')) {
$driver_name = 'apcu';
} elseif (extension_loaded('apc')) {
$driver_name = 'apc';
} elseif (extension_loaded('wincache')) {
$driver_name = 'wincache';
} elseif (extension_loaded('xcache')) {
$driver_name = 'xcache';
}
} else {
$driver_name = $setting;
@ -224,9 +223,6 @@ class Cache extends Getters
switch ($driver_name) {
case 'apc':
$driver = new DoctrineCache\ApcCache();
break;
case 'apcu':
$driver = new DoctrineCache\ApcuCache();
break;
@ -235,10 +231,6 @@ class Cache extends Getters
$driver = new DoctrineCache\WinCacheCache();
break;
case 'xcache':
$driver = new DoctrineCache\XcacheCache();
break;
case 'memcache':
$memcache = new \Memcache();
$memcache->connect($this->config->get('system.cache.memcache.server', 'localhost'),
@ -295,9 +287,9 @@ class Cache extends Getters
{
if ($this->enabled) {
return $this->driver->fetch($id);
} else {
return false;
}
return false;
}
/**
@ -328,6 +320,7 @@ class Cache extends Getters
if ($this->enabled) {
return $this->driver->delete($id);
}
return false;
}
@ -341,6 +334,7 @@ class Cache extends Getters
if ($this->enabled) {
return $this->driver->deleteAll();
}
return false;
}
@ -355,6 +349,7 @@ class Cache extends Getters
if ($this->enabled) {
return $this->driver->contains(($id));
}
return false;
}
@ -459,7 +454,7 @@ class Cache extends Getters
$output[] = '';
if (($remove == 'all' || $remove == 'standard') && file_exists($user_config)) {
if (($remove === 'all' || $remove === 'standard') && file_exists($user_config)) {
touch($user_config);
$output[] = '<red>Touched: </red>' . $user_config;
@ -540,17 +535,17 @@ class Cache extends Getters
{
if (in_array($setting, ['apc', 'apcu', 'xcache', 'wincache'])) {
return true;
} else {
return false;
}
return false;
}
public static function purgeJob()
{
$cache = Grav::instance()['cache'];
$deleted_folders = $cache->purgeOldCache();
$msg = 'Purged ' . $deleted_folders . ' old cache folders...';
return $msg;
return 'Purged ' . $deleted_folders . ' old cache folders...';
}
public function onSchedulerInitialized(Event $event)

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -46,7 +47,7 @@ class Composer
$composer = static::getComposerLocation();
if ($composer !== static::DEFAULT_PATH && is_executable($composer)) {
$file = fopen($composer, 'r');
$file = fopen($composer, 'rb');
$firstLine = fgets($file);
fclose($file);

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -198,9 +199,7 @@ abstract class CompiledBase
$cache = include $filename;
if (
!\is_array($cache)
|| !isset($cache['checksum'])
|| !isset($cache['data'])
|| !isset($cache['@class'])
|| !isset($cache['checksum'], $cache['data'], $cache['@class'])
|| $cache['@class'] !== \get_class($this)
) {
return false;

View File

@ -1,27 +1,30 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Config;
use Grav\Common\Data\Blueprint;
use Grav\Common\Data\BlueprintSchema;
use Grav\Common\Grav;
/**
* Class CompiledBlueprints
* @package Grav\Common\Config
*/
class CompiledBlueprints extends CompiledBase
{
/**
* @var int Version number for the compiled file.
*/
public $version = 2;
public function __construct($cacheFolder, array $files, $path)
{
parent::__construct($cacheFolder, $files, $path);
/**
* @var BlueprintSchema Blueprints object.
*/
protected $object;
$this->version = 2;
}
/**
* Returns checksum from the configuration files.

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -12,16 +13,6 @@ use Grav\Common\File\CompiledYamlFile;
class CompiledConfig extends CompiledBase
{
/**
* @var int Version number for the compiled file.
*/
public $version = 1;
/**
* @var Config Configuration object.
*/
protected $object;
/**
* @var callable Blueprints loader.
*/
@ -32,6 +23,13 @@ class CompiledConfig extends CompiledBase
*/
protected $withDefaults;
public function __construct($cacheFolder, array $files, $path)
{
parent::__construct($cacheFolder, $files, $path);
$this->version = 1;
}
/**
* Set blueprints for the configuration.
*

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -12,15 +13,12 @@ use Grav\Common\File\CompiledYamlFile;
class CompiledLanguages extends CompiledBase
{
/**
* @var int Version number for the compiled file.
*/
public $version = 1;
public function __construct($cacheFolder, array $files, $path)
{
parent::__construct($cacheFolder, $files, $path);
/**
* @var Languages Configuration object.
*/
protected $object;
$this->version = 1;
}
/**
* Create configuration object.

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Config
* @package Grav\Common\Config
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -11,8 +12,8 @@ namespace Grav\Common\Config;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\Data\Data;
use Grav\Common\Utils;
use Grav\Framework\Psr7\ServerRequest;
use Pimple\Container;
use Psr\Http\Message\ServerRequestInterface;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
class Setup extends Data
@ -157,7 +158,7 @@ class Setup extends Data
if (\defined('GRAV_CLI')) {
static::$environment = 'cli';
} else {
/** @var ServerRequest $request */
/** @var ServerRequestInterface $request */
$request = $container['request'];
$host = $request->getUri()->getHost();

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Data
* @package Grav\Common\Data
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Data
* @package Grav\Common\Data
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Data
* @package Grav\Common\Data
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Data
* @package Grav\Common\Data
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Data
* @package Grav\Common\Data
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Data
* @package Grav\Common\Data
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -11,7 +12,6 @@ namespace Grav\Common\Data;
use Grav\Common\Grav;
use Grav\Common\Utils;
use Grav\Common\Yaml;
use RocketTheme\Toolbox\Compat\Yaml\Yaml as FallbackYaml;
class Validation
{
@ -24,21 +24,18 @@ class Validation
*/
public static function validate($value, array $field)
{
$messages = [];
$validate = isset($field['validate']) ? (array) $field['validate'] : [];
// Validate type with fallback type text.
$type = (string) isset($validate['type']) ? $validate['type'] : $field['type'];
$method = 'type' . str_replace('-', '_', $type);
// If value isn't required, we will stop validation if empty value is given.
if ((empty($validate['required']) || (isset($validate['required']) && $validate['required'] !== true)) && ($value === null || $value === '' || (($field['type'] === 'checkbox' || $field['type'] === 'switch') && $value == false))) {
return $messages;
}
if (!isset($field['type'])) {
$field['type'] = 'text';
}
$type = $validate['type'] ?? $field['type'];
$validate = (array)($field['validate'] ?? null);
$required = $validate['required'] ?? false;
// If value isn't required, we will stop validation if empty value is given.
if ($required !== true && ($value === null || $value === '' || (($field['type'] === 'checkbox' || $field['type'] === 'switch') && $value == false))
) {
return [];
}
// Get language class.
$language = Grav::instance()['language'];
@ -49,17 +46,17 @@ class Validation
: $language->translate('GRAV.FORM.INVALID_INPUT', null, true) . ' "' . $language->translate($name) . '"';
// Validate type with fallback type text.
$method = 'type' . str_replace('-', '_', $type);
// If this is a YAML field validate/filter as such
if ($type !== 'yaml' && isset($field['yaml']) && $field['yaml'] === true) {
if (isset($field['yaml']) && $field['yaml'] === true) {
$method = 'typeYaml';
}
if (method_exists(__CLASS__, $method)) {
$success = self::$method($value, $validate, $field);
} else {
$success = true;
}
$messages = [];
$success = method_exists(__CLASS__, $method) ? self::$method($value, $validate, $field) : true;
if (!$success) {
$messages[$field['name']][] = $message;
}
@ -89,7 +86,7 @@ class Validation
*/
public static function filter($value, array $field)
{
$validate = isset($field['validate']) ? (array) $field['validate'] : [];
$validate = (array)($field['validate'] ?? null);
// If value isn't required, we will return null if empty value is given.
if (($value === null || $value === '') && empty($validate['required'])) {
@ -99,14 +96,12 @@ class Validation
if (!isset($field['type'])) {
$field['type'] = 'text';
}
$type = $field['validate']['type'] ?? $field['type'];
// Validate type with fallback type text.
$type = (string) isset($field['validate']['type']) ? $field['validate']['type'] : $field['type'];
$method = 'filter' . ucfirst(str_replace('-', '_', $type));
// If this is a YAML field validate/filter as such
if ($type !== 'yaml' && isset($field['yaml']) && $field['yaml'] === true) {
if (isset($field['yaml']) && $field['yaml'] === true) {
$method = 'filterYaml';
}
@ -261,8 +256,8 @@ class Validation
*/
public static function typeCheckbox($value, array $params, array $field)
{
$value = (string) $value;
$field_value = (string) ($field['value'] ?? '1');
$value = (string)$value;
$field_value = (string)($field['value'] ?? '1');
return $value === $field_value;
}
@ -303,12 +298,12 @@ class Validation
*/
public static function typeFile($value, array $params, array $field)
{
return self::typeArray((array) $value, $params, $field);
return self::typeArray((array)$value, $params, $field);
}
protected static function filterFile($value, array $params, array $field)
{
return (array) $value;
return (array)$value;
}
/**
@ -758,7 +753,7 @@ class Validation
public static function validateInt($value, $params)
{
return is_numeric($value) && (int) $value == $value;
return is_numeric($value) && (int)$value == $value;
}
protected static function filterInt($value, $params)

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Data
* @package Grav\Common\Data
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -269,7 +270,7 @@ class Debugger
*/
public function startTimer($name, $description = null)
{
if ($name[0] === '_' || $this->enabled()) {
if (strpos($name, '_') === 0 || $this->enabled()) {
$this->debugbar['time']->startMeasure($name, $description);
$this->timers[] = $name;
}
@ -286,7 +287,7 @@ class Debugger
*/
public function stopTimer($name)
{
if (\in_array($name, $this->timers, true) && ($name[0] === '_' || $this->enabled())) {
if (\in_array($name, $this->timers, true) && (strpos($name, '_') === 0 || $this->enabled())) {
$this->debugbar['time']->stopMeasure($name);
}
@ -319,7 +320,7 @@ class Debugger
*/
public function addException(\Exception $e)
{
if ($this->enabled() && $this->initialized) {
if ($this->initialized && $this->enabled()) {
$this->debugbar['exceptions']->addException($e);
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Errors
* @package Grav\Common\Errors
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Errors
* @package Grav\Common\Errors
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -17,11 +18,11 @@ class Errors
{
$grav = Grav::instance();
$config = $grav['config']->get('system.errors');
$jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json';
$jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] === 'application/json';
// Setup Whoops-based error handler
$system = new SystemFacade;
$whoops = new \Whoops\Run($system);
$whoops = new Whoops\Run($system);
$verbosity = 1;
@ -49,17 +50,8 @@ class Errors
break;
}
if (method_exists('Whoops\Util\Misc', 'isAjaxRequest')) { //Whoops 2.0
if (Whoops\Util\Misc::isAjaxRequest() || $jsonRequest) {
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler);
}
} elseif (function_exists('Whoops\isAjaxRequest')) { //Whoops 2.0.0-alpha
if (Whoops\isAjaxRequest() || $jsonRequest) {
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler);
}
} else { //Whoops 1.x
$json_page = new Whoops\Handler\JsonResponseHandler;
$json_page->onlyForAjaxRequests(true);
if (Whoops\Util\Misc::isAjaxRequest() || $jsonRequest) {
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler);
}
if (isset($config['log']) && $config['log']) {

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Errors
* @package Grav\Common\Errors
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -20,7 +21,7 @@ class SimplePageHandler extends Handler
public function __construct()
{
// Add the default, local resource search path:
$this->searchPaths[] = __DIR__ . "/Resources";
$this->searchPaths[] = __DIR__ . '/Resources';
}
/**
@ -31,8 +32,8 @@ class SimplePageHandler extends Handler
$inspector = $this->getInspector();
$helper = new TemplateHelper();
$templateFile = $this->getResource("layout.html.php");
$cssFile = $this->getResource("error.css");
$templateFile = $this->getResource('layout.html.php');
$cssFile = $this->getResource('error.css');
$code = $inspector->getException()->getCode();
if ( ($code >= 400) && ($code < 600) )
@ -46,9 +47,9 @@ class SimplePageHandler extends Handler
}
$vars = array(
"stylesheet" => file_get_contents($cssFile),
"code" => $code,
"message" => filter_var(rawurldecode($message), FILTER_SANITIZE_STRING),
'stylesheet' => file_get_contents($cssFile),
'code' => $code,
'message' => filter_var(rawurldecode($message), FILTER_SANITIZE_STRING),
);
$helper->setVariables($vars);
@ -74,7 +75,7 @@ class SimplePageHandler extends Handler
// Search through available search paths, until we find the
// resource we're after:
foreach ($this->searchPaths as $path) {
$fullPath = $path . "/$resource";
$fullPath = "{$path}/{$resource}";
if (is_file($fullPath)) {
// Cache the result:

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Errors
* @package Grav\Common\Errors
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.File
* @package Grav\Common\File
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.File
* @package Grav\Common\File
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -23,6 +24,6 @@ class CompiledJsonFile extends JsonFile
*/
protected function decode($var, $assoc = true)
{
return (array) json_decode($var, $assoc);
return (array)json_decode($var, $assoc);
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.File
* @package Grav\Common\File
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.File
* @package Grav\Common\File
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.FileSystem
* @package Grav\Common\Filesystem
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -19,11 +20,11 @@ abstract class Archiver
public static function create($compression)
{
if ($compression == 'zip') {
return new ZipArchiver();
} else {
if ($compression === 'zip') {
return new ZipArchiver();
}
return new ZipArchiver();
}
public function setArchive($archive_file)

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.FileSystem
* @package Grav\Common\Filesystem
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -141,6 +142,7 @@ abstract class Folder
*/
public static function getRelativePathDotDot($path, $base)
{
// Normalize paths.
$base = preg_replace('![\\\/]+!', '/', $base);
$path = preg_replace('![\\\/]+!', '/', $path);
@ -148,8 +150,8 @@ abstract class Folder
return '';
}
$baseParts = explode('/', isset($base[0]) && '/' === $base[0] ? substr($base, 1) : $base);
$pathParts = explode('/', isset($path[0]) && '/' === $path[0] ? substr($path, 1) : $path);
$baseParts = explode('/', ltrim($base, '/'));
$pathParts = explode('/', ltrim($path, '/'));
array_pop($baseParts);
$lastPart = array_pop($pathParts);
@ -164,7 +166,7 @@ abstract class Folder
$path = str_repeat('../', count($baseParts)) . implode('/', $pathParts);
return '' === $path
|| '/' === $path[0]
|| strpos($path, '/') === 0
|| false !== ($colonPos = strpos($path, ':')) && ($colonPos < ($slashPos = strpos($path, '/')) || false === $slashPos)
? "./$path" : $path;
}
@ -199,14 +201,14 @@ abstract class Folder
}
$compare = isset($params['compare']) ? 'get' . $params['compare'] : null;
$pattern = isset($params['pattern']) ? $params['pattern'] : null;
$filters = isset($params['filters']) ? $params['filters'] : null;
$recursive = isset($params['recursive']) ? $params['recursive'] : true;
$levels = isset($params['levels']) ? $params['levels'] : -1;
$pattern = $params['pattern'] ?? null;
$filters = $params['filters'] ?? null;
$recursive = $params['recursive'] ?? true;
$levels = $params['levels'] ?? -1;
$key = isset($params['key']) ? 'get' . $params['key'] : null;
$value = isset($params['value']) ? 'get' . $params['value'] : ($recursive ? 'getSubPathname' : 'getFilename');
$folders = isset($params['folders']) ? $params['folders'] : true;
$files = isset($params['files']) ? $params['files'] : true;
$value = 'get' . ($params['value'] ?? ($recursive ? 'SubPathname' : 'Filename'));
$folders = $params['folders'] ?? true;
$files = $params['files'] ?? true;
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
@ -233,7 +235,7 @@ abstract class Folder
/** @var \RecursiveDirectoryIterator $file */
foreach ($iterator as $file) {
// Ignore hidden files.
if ($file->getFilename()[0] === '.') {
if (strpos($file->getFilename(), '.') === 0) {
continue;
}
if (!$folders && $file->isDir()) {
@ -255,7 +257,7 @@ abstract class Folder
if (isset($filters['value'])) {
$filter = $filters['value'];
if (is_callable($filter)) {
$filePath = call_user_func($filter, $file);
$filePath = $filter($file);
} else {
$filePath = preg_replace($filter, '', $filePath);
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.FileSystem
* @package Grav\Common\Filesystem
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.FileSystem
* @package Grav\Common\Filesystem
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -41,9 +42,6 @@ class RecursiveFolderFilterIterator extends \RecursiveFilterIterator
/** @var $current \SplFileInfo */
$current = $this->current();
if ($current->isDir() && !in_array($current->getFilename(), $this::$ignore_folders, true)) {
return true;
}
return false;
return $current->isDir() && !in_array($current->getFilename(), $this::$ignore_folders, true);
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.FileSystem
* @package Grav\Common\Filesystem
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,9 +1,9 @@
<?php
/**
* @package Grav\Framework\Common
* @package Grav\Common\Form
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -14,13 +15,7 @@ abstract class AbstractCollection extends Iterator
{
public function toJson()
{
$items = [];
foreach ($this->items as $name => $package) {
$items[$name] = $package->toArray();
}
return json_encode($items);
return json_encode($this->toArray());
}
public function toArray()

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -17,11 +18,11 @@ class CachedCollection extends Iterator {
public function __construct($items)
{
// local cache to speed things up
if (!isset(self::$cache[get_called_class().__METHOD__])) {
self::$cache[get_called_class().__METHOD__] = $items;
if (!isset(self::$cache[get_called_class() . __METHOD__])) {
self::$cache[get_called_class() . __METHOD__] = $items;
}
foreach (self::$cache[get_called_class().__METHOD__] as $name => $item) {
foreach (self::$cache[get_called_class() . __METHOD__] as $name => $item) {
$this->append([$name => $item]);
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -14,7 +15,8 @@ class Package {
protected $data;
public function __construct(Data $package, $type = null) {
public function __construct(Data $package, $type = null)
{
$this->data = $package;
if ($type) {
@ -22,28 +24,38 @@ class Package {
}
}
public function getData() {
public function getData()
{
return $this->data;
}
public function __get($key) {
public function __get($key)
{
return $this->data->get($key);
}
public function __isset($key) {
return isset($this->data->$key);
public function __set($key, $value)
{
throw new $this->data->set($key, $value);
}
public function __toString() {
public function __isset($key)
{
return isset($this->data->{$key});
}
public function __toString()
{
return $this->toJson();
}
public function toJson() {
public function toJson()
{
return $this->data->toJson();
}
public function toArray() {
public function toArray()
{
return $this->data->toArray();
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -248,7 +249,6 @@ class GPM extends Iterator
if (version_compare($local_version, $remote_version) < 0) {
$repository[$slug]->available = $remote_version;
$repository[$slug]->version = $local_version;
$repository[$slug]->name = $repository[$slug]->name;
$repository[$slug]->type = $repository[$slug]->release_type;
$items[$slug] = $repository[$slug];
}
@ -322,7 +322,7 @@ class GPM extends Iterator
continue;
}
$local_version = $plugin->version ? $plugin->version : 'Unknown';
$local_version = $plugin->version ?: 'Unknown';
$remote_version = $repository[$slug]->version;
if (version_compare($local_version, $remote_version) < 0) {
@ -564,31 +564,33 @@ class GPM extends Iterator
file_exists($source . 'system/config/system.yaml')
) {
return 'grav';
} else {
// must have a blueprint
if (!file_exists($source . 'blueprints.yaml')) {
return false;
}
}
// either theme or plugin
$name = basename($source);
if (Utils::contains($name, 'theme')) {
return 'theme';
} elseif (Utils::contains($name, 'plugin')) {
return 'plugin';
}
foreach (glob($source . "*.php") as $filename) {
$contents = file_get_contents($filename);
if (preg_match($theme_regex, $contents)) {
return 'theme';
} elseif (preg_match($plugin_regex, $contents)) {
return 'plugin';
}
}
// must have a blueprint
if (!file_exists($source . 'blueprints.yaml')) {
return false;
}
// Assume it's a theme
// either theme or plugin
$name = basename($source);
if (Utils::contains($name, 'theme')) {
return 'theme';
}
if (Utils::contains($name, 'plugin')) {
return 'plugin';
}
foreach (glob($source . '*.php') as $filename) {
$contents = file_get_contents($filename);
if (preg_match($theme_regex, $contents)) {
return 'theme';
}
if (preg_match($plugin_regex, $contents)) {
return 'plugin';
}
}
// Assume it's a theme
return 'theme';
}
/**
@ -601,7 +603,7 @@ class GPM extends Iterator
{
$ignore_yaml_files = ['blueprints', 'languages'];
foreach (glob($source . "*.yaml") as $filename) {
foreach (glob($source . '*.yaml') as $filename) {
$name = strtolower(basename($filename, '.yaml'));
if (in_array($name, $ignore_yaml_files)) {
continue;
@ -642,7 +644,7 @@ class GPM extends Iterator
{
$locator = Grav::instance()['locator'];
if ($type == 'theme') {
if ($type === 'theme') {
$install_path = $locator->findResource('themes://', false) . DS . $name;
} else {
$install_path = $locator->findResource('plugins://', false) . DS . $name;
@ -692,7 +694,7 @@ class GPM extends Iterator
}
$not_found = new \stdClass();
$not_found->name = $inflector->camelize($search);
$not_found->name = $inflector::camelize($search);
$not_found->slug = $search;
$not_found->package_type = $type;
$not_found->install_path = str_replace('%name%', $search, $this->install_paths[$type]);
@ -726,7 +728,7 @@ class GPM extends Iterator
$dependency = $dependency['name'];
}
if ($dependency == $slug) {
if ($dependency === $slug) {
$dependent_packages[] = $package_name;
}
}
@ -833,19 +835,19 @@ class GPM extends Iterator
{
$dependencies = $this->calculateMergedDependenciesOfPackages($packages);
foreach ($dependencies as $dependency_slug => $dependencyVersionWithOperator) {
if (in_array($dependency_slug, $packages)) {
if (\in_array($dependency_slug, $packages, true)) {
unset($dependencies[$dependency_slug]);
continue;
}
// Check PHP version
if ($dependency_slug == 'php') {
if ($dependency_slug === 'php') {
$current_php_version = phpversion();
if (version_compare($this->calculateVersionNumberFromDependencyVersion($dependencyVersionWithOperator),
$current_php_version) === 1
) {
//Needs a Grav update first
throw new \Exception("<red>One of the packages require PHP " . $dependencies['php'] . ". Please update PHP to resolve this");
throw new \RuntimeException("<red>One of the packages require PHP {$dependencies['php']}. Please update PHP to resolve this");
} else {
unset($dependencies[$dependency_slug]);
continue;
@ -853,12 +855,12 @@ class GPM extends Iterator
}
//First, check for Grav dependency. If a dependency requires Grav > the current version, abort and tell.
if ($dependency_slug == 'grav') {
if ($dependency_slug === 'grav') {
if (version_compare($this->calculateVersionNumberFromDependencyVersion($dependencyVersionWithOperator),
GRAV_VERSION) === 1
) {
//Needs a Grav update first
throw new \Exception("<red>One of the packages require Grav " . $dependencies['grav'] . ". Please update Grav to the latest release.");
throw new \RuntimeException("<red>One of the packages require Grav {$dependencies['grav']}. Please update Grav to the latest release.");
} else {
unset($dependencies[$dependency_slug]);
continue;
@ -888,7 +890,7 @@ class GPM extends Iterator
$currentlyInstalledVersion);
if (!$compatible) {
throw new \Exception('Dependency <cyan>' . $dependency_slug . '</cyan> is required in an older version than the one installed. This package must be updated. Please get in touch with its developer.',
throw new \RuntimeException('Dependency <cyan>' . $dependency_slug . '</cyan> is required in an older version than the one installed. This package must be updated. Please get in touch with its developer.',
2);
}
}
@ -899,7 +901,7 @@ class GPM extends Iterator
if ($this->firstVersionIsLower($latestRelease, $dependencyVersion)) {
//throw an exception if a required version cannot be found in the GPM yet
throw new \Exception('Dependency <cyan>' . $package_yaml['name'] . '</cyan> is required in version <cyan>' . $dependencyVersion . '</cyan> which is higher than the latest release, <cyan>' . $latestRelease . '</cyan>. Try running `bin/gpm -f index` to force a refresh of the GPM cache',
throw new \RuntimeException('Dependency <cyan>' . $package_yaml['name'] . '</cyan> is required in version <cyan>' . $dependencyVersion . '</cyan> which is higher than the latest release, <cyan>' . $latestRelease . '</cyan>. Try running `bin/gpm -f index` to force a refresh of the GPM cache',
1);
}
@ -950,7 +952,7 @@ class GPM extends Iterator
private function firstVersionIsLower($firstVersion, $secondVersion)
{
return version_compare($firstVersion, $secondVersion) == -1;
return version_compare($firstVersion, $secondVersion) === -1;
}
/**
@ -1005,7 +1007,7 @@ class GPM extends Iterator
$current_package_version_number = $this->calculateVersionNumberFromDependencyVersion($current_package_version_information);
if (!$current_package_version_number) {
throw new \Exception('Bad format for version of dependency ' . $current_package_name . ' for package ' . $packageName,
throw new \RuntimeException('Bad format for version of dependency ' . $current_package_name . ' for package ' . $packageName,
1);
}
@ -1021,7 +1023,7 @@ class GPM extends Iterator
if (!$currently_stored_version_is_in_next_significant_release_format && !$current_package_version_is_in_next_significant_release_format) {
//Comparing versions equals or higher, a simple version_compare is enough
if (version_compare($currently_stored_version_number,
$current_package_version_number) == -1
$current_package_version_number) === -1
) { //Current package version is higher
$dependencies[$current_package_name] = $current_package_version_information;
}
@ -1029,7 +1031,7 @@ class GPM extends Iterator
$compatible = $this->checkNextSignificantReleasesAreCompatible($currently_stored_version_number,
$current_package_version_number);
if (!$compatible) {
throw new \Exception('Dependency ' . $current_package_name . ' is required in two incompatible versions',
throw new \RuntimeException('Dependency ' . $current_package_name . ' is required in two incompatible versions',
2);
}
}
@ -1076,17 +1078,19 @@ class GPM extends Iterator
*/
public function calculateVersionNumberFromDependencyVersion($version)
{
if ($version == '*') {
if ($version === '*') {
return null;
} elseif ($version == '') {
return null;
} elseif ($this->versionFormatIsNextSignificantRelease($version)) {
return trim(substr($version, 1));
} elseif ($this->versionFormatIsEqualOrHigher($version)) {
return trim(substr($version, 2));
} else {
return $version;
}
if ($version === '') {
return null;
}
if ($this->versionFormatIsNextSignificantRelease($version)) {
return trim(substr($version, 1));
}
if ($this->versionFormatIsEqualOrHigher($version)) {
return trim(substr($version, 2));
}
return $version;
}
/**
@ -1100,7 +1104,7 @@ class GPM extends Iterator
*/
public function versionFormatIsNextSignificantRelease($version)
{
return substr($version, 0, 1) == '~';
return strpos($version, '~') === 0;
}
/**
@ -1114,7 +1118,7 @@ class GPM extends Iterator
*/
public function versionFormatIsEqualOrHigher($version)
{
return substr($version, 0, 2) == '>=';
return strpos($version, '>=') === 0;
}
/**
@ -1135,12 +1139,12 @@ class GPM extends Iterator
$version1array = explode('.', $version1);
$version2array = explode('.', $version2);
if (count($version1array) > count($version2array)) {
if (\count($version1array) > \count($version2array)) {
list($version1array, $version2array) = [$version2array, $version1array];
}
$i = 0;
while ($i < count($version1array) - 1) {
while ($i < \count($version1array) - 1) {
if ($version1array[$i] != $version2array[$i]) {
return false;
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -14,23 +15,23 @@ use Grav\Common\Grav;
class Installer
{
/** @const No error */
const OK = 0;
public const OK = 0;
/** @const Target already exists */
const EXISTS = 1;
public const EXISTS = 1;
/** @const Target is a symbolic link */
const IS_LINK = 2;
public const IS_LINK = 2;
/** @const Target doesn't exist */
const NOT_FOUND = 4;
public const NOT_FOUND = 4;
/** @const Target is not a directory */
const NOT_DIRECTORY = 8;
public const NOT_DIRECTORY = 8;
/** @const Target is not a Grav instance */
const NOT_GRAV_ROOT = 16;
public const NOT_GRAV_ROOT = 16;
/** @const Error while trying to open the ZIP package */
const ZIP_OPEN_ERROR = 32;
public const ZIP_OPEN_ERROR = 32;
/** @const Error while trying to extract the ZIP package */
const ZIP_EXTRACT_ERROR = 64;
public const ZIP_EXTRACT_ERROR = 64;
/** @const Invalid source file */
const INVALID_SOURCE = 128;
public const INVALID_SOURCE = 128;
/**
* Destination folder on which validation checks are applied
@ -88,8 +89,8 @@ class Installer
return false;
}
if (self::lastErrorCode() == self::IS_LINK && $options['ignore_symlinks'] ||
self::lastErrorCode() == self::EXISTS && !$options['overwrite']
if ((self::lastErrorCode() === self::IS_LINK && $options['ignore_symlinks']) ||
(self::lastErrorCode() === self::EXISTS && !$options['overwrite'])
) {
return false;
}
@ -189,9 +190,8 @@ class Installer
$package_folder_name = preg_replace('#\./$#', '', $zip->getNameIndex(0));
$zip->close();
$extracted_folder = $destination . '/' . $package_folder_name;
return $extracted_folder;
return $destination . '/' . $package_folder_name;
}
self::$error = self::ZIP_EXTRACT_ERROR;
@ -216,7 +216,7 @@ class Installer
$install_file = $installer_file_folder . DS . 'install.php';
if (file_exists($install_file)) {
require_once($install_file);
require_once $install_file;
} else {
return null;
}
@ -279,10 +279,10 @@ class Installer
{
if (empty($source_path)) {
throw new \RuntimeException("Directory $source_path is missing");
} else {
Folder::rcopy($source_path, $install_path);
}
Folder::rcopy($source_path, $install_path);
return true;
}
@ -296,7 +296,7 @@ class Installer
{
foreach (new \DirectoryIterator($source_path) as $file) {
if ($file->isLink() || $file->isDot() || in_array($file->getFilename(), $ignores)) {
if ($file->isLink() || $file->isDot() || \in_array($file->getFilename(), $ignores, true)) {
continue;
}
@ -385,11 +385,11 @@ class Installer
self::$error = self::NOT_DIRECTORY;
}
if (count($exclude) && in_array(self::$error, $exclude)) {
if (\count($exclude) && \in_array(self::$error, $exclude, true)) {
return true;
}
return !(self::$error);
return !self::$error;
}
/**
@ -469,23 +469,23 @@ class Installer
if (self::$error_zip) {
switch(self::$error_zip) {
case \ZipArchive::ER_EXISTS:
$msg .= "File already exists.";
$msg .= 'File already exists.';
break;
case \ZipArchive::ER_INCONS:
$msg .= "Zip archive inconsistent.";
$msg .= 'Zip archive inconsistent.';
break;
case \ZipArchive::ER_MEMORY:
$msg .= "Malloc failure.";
$msg .= 'Memory allocation failure.';
break;
case \ZipArchive::ER_NOENT:
$msg .= "No such file.";
$msg .= 'No such file.';
break;
case \ZipArchive::ER_NOZIP:
$msg .= "Not a zip archive.";
$msg .= 'Not a zip archive.';
break;
case \ZipArchive::ER_OPEN:
@ -493,11 +493,11 @@ class Installer
break;
case \ZipArchive::ER_READ:
$msg .= "Read error.";
$msg .= 'Read error.';
break;
case \ZipArchive::ER_SEEK:
$msg .= "Seek error.";
$msg .= 'Seek error.';
break;
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -40,14 +41,14 @@ class Licenses
public static function set($slug, $license)
{
$licenses = self::getLicenseFile();
$data = $licenses->content();
$data = (array)$licenses->content();
$slug = strtolower($slug);
if ($license && !self::validate($license)) {
return false;
}
if (!is_string($license)) {
if (!\is_string($license)) {
if (isset($data['licenses'][$slug])) {
unset($data['licenses'][$slug]);
} else {
@ -68,24 +69,20 @@ class Licenses
*
* @param $slug
*
* @return string
* @return array|string
*/
public static function get($slug = null)
{
$licenses = self::getLicenseFile();
$data = $licenses->content();
$data = (array)$licenses->content();
$licenses->free();
$slug = strtolower($slug);
if (!$slug) {
return isset($data['licenses']) ? $data['licenses'] : [];
return $data['licenses'] ?? [];
}
if (!isset($data['licenses']) || !isset($data['licenses'][$slug])) {
return '';
}
return $data['licenses'][$slug];
return $data['licenses'][$slug] ?? '';
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -122,7 +123,7 @@ class GravCore extends AbstractPackageCollection
public function getMinPHPVersion()
{
// If non min set, assume current PHP version
if (is_null($this->min_php)) {
if (null === $this->min_php) {
$this->min_php = phpversion();
}
return $this->min_php;

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -11,8 +12,10 @@ namespace Grav\Common\GPM\Remote;
use Grav\Common\Data\Data;
use Grav\Common\GPM\Common\Package as BasePackage;
class Package extends BasePackage {
public function __construct($package, $package_type = null) {
class Package extends BasePackage
{
public function __construct($package, $package_type = null)
{
$data = new Data($package);
parent::__construct($data, $package_type);
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -77,7 +78,7 @@ class Response
*/
public static function setMethod($method = 'auto')
{
if (!in_array($method, ['auto', 'curl', 'fopen'])) {
if (!\in_array($method, ['auto', 'curl', 'fopen'], true)) {
$method = 'auto';
}
@ -103,7 +104,7 @@ class Response
// check if this function is available, if so use it to stop any timeouts
try {
if (!Utils::isFunctionDisabled('set_time_limit') && !ini_get('safe_mode') && function_exists('set_time_limit')) {
if (function_exists('set_time_limit') && !Utils::isFunctionDisabled('set_time_limit')) {
set_time_limit(0);
}
} catch (\Exception $e) {
@ -165,7 +166,7 @@ class Response
$overrides['curl'][CURLOPT_PROXYPORT] = $proxy['port'];
}
if (isset($proxy['user']) && isset($proxy['pass'])) {
if (isset($proxy['user'], $proxy['pass'])) {
$fopen_auth = $auth = base64_encode($proxy['user'] . ':' . $proxy['pass']);
$overrides['curl'][CURLOPT_PROXYUSERPWD] = $proxy['user'] . ':' . $proxy['pass'];
$overrides['fopen']['header'] = "Proxy-Authorization: Basic $fopen_auth";
@ -219,7 +220,7 @@ class Response
static $filesize = null;
$args = func_get_args();
$isCurlResource = is_resource($args[0]) && get_resource_type($args[0]) == 'curl';
$isCurlResource = is_resource($args[0]) && get_resource_type($args[0]) === 'curl';
$notification_code = !$isCurlResource ? $args[0] : false;
$bytes_transferred = $isCurlResource ? $args[2] : $args[4];
@ -241,7 +242,7 @@ class Response
];
if (self::$callback !== null) {
call_user_func_array(self::$callback, [$progress]);
call_user_func(self::$callback, $progress);
}
}
}
@ -272,13 +273,13 @@ class Response
*/
private static function getFopen()
{
if (count($args = func_get_args()) == 1) {
if (\count($args = func_get_args()) === 1) {
$args = $args[0];
}
$uri = $args[0];
$options = $args[1];
$callback = $args[2];
$options = $args[1] ?? [];
$callback = $args[2] ?? null;
if ($callback) {
$options['fopen']['notification'] = ['self', 'progress'];
@ -307,11 +308,11 @@ class Response
switch ($code) {
case '404':
throw new \RuntimeException("Page not found");
throw new \RuntimeException('Page not found');
case '401':
throw new \RuntimeException("Invalid LICENSE");
throw new \RuntimeException('Invalid LICENSE');
default:
throw new \RuntimeException("Error while trying to download (code: $code): $uri \n");
throw new \RuntimeException("Error while trying to download (code: {$code}): {$uri}\n");
}
}
@ -329,8 +330,8 @@ class Response
$args = count($args) > 1 ? $args : array_shift($args);
$uri = $args[0];
$options = $args[1];
$callback = $args[2];
$options = $args[1] ?? [];
$callback = $args[2] ?? null;
$ch = curl_init($uri);
@ -381,7 +382,7 @@ class Response
return curl_exec($ch);
}
$max_redirects = isset($options['curl'][CURLOPT_MAXREDIRS]) ? $options['curl'][CURLOPT_MAXREDIRS] : 5;
$max_redirects = $options['curl'][CURLOPT_MAXREDIRS] ?? 5;
$options['curl'][CURLOPT_FOLLOWLOCATION] = false;
// open_basedir set but no redirects to follow, we can disable followlocation and proceed normally
@ -405,8 +406,8 @@ class Response
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302 || $code == 303) {
$code = (int)curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code === 301 || $code === 302 || $code === 303) {
preg_match('/Location:(.*?)\n/', $header, $matches);
$uri = trim(array_pop($matches));
} else {

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.GPM
* @package Grav\Common\GPM
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -112,7 +113,7 @@ class Upgrader
*/
public function minPHPVersion()
{
if (is_null($this->min_php)) {
if (null === $this->min_php) {
$this->min_php = $this->remote->getMinPHPVersion();
}
return $this->min_php;
@ -125,7 +126,7 @@ class Upgrader
*/
public function isUpgradable()
{
return version_compare($this->getLocalVersion(), $this->getRemoteVersion(), "<");
return version_compare($this->getLocalVersion(), $this->getRemoteVersion(), '<');
}
/**

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -73,9 +74,9 @@ abstract class Getters implements \ArrayAccess, \Countable
$var = $this->gettersVariable;
return isset($this->{$var}[$offset]);
} else {
return isset($this->{$offset});
}
return isset($this->{$offset});
}
/**
@ -88,10 +89,10 @@ abstract class Getters implements \ArrayAccess, \Countable
if ($this->gettersVariable) {
$var = $this->gettersVariable;
return isset($this->{$var}[$offset]) ? $this->{$var}[$offset] : null;
} else {
return isset($this->{$offset}) ? $this->{$offset} : null;
return $this->{$var}[$offset] ?? null;
}
return $this->{$offset} ?? null;
}
/**
@ -128,10 +129,10 @@ abstract class Getters implements \ArrayAccess, \Countable
{
if ($this->gettersVariable) {
$var = $this->gettersVariable;
count($this->{$var});
} else {
count($this->toArray());
return \count($this->{$var});
}
return \count($this->toArray());
}
/**
@ -145,16 +146,16 @@ abstract class Getters implements \ArrayAccess, \Countable
$var = $this->gettersVariable;
return $this->{$var};
} else {
$properties = (array)$this;
$list = [];
foreach ($properties as $property => $value) {
if ($property[0] != "\0") {
$list[$property] = $value;
}
}
return $list;
}
$properties = (array)$this;
$list = [];
foreach ($properties as $property => $value) {
if ($property[0] !== "\0") {
$list[$property] = $value;
}
}
return $list;
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Helpers
* @package Grav\Common\Helpers
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -32,7 +33,7 @@ class Base32
*/
public static function encode($bytes)
{
$i = 0; $index = 0; $digit = 0;
$i = 0; $index = 0;
$base32 = '';
$bytesLen = \strlen($bytes);

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Helpers
* @package Grav\Common\Helpers
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -203,7 +204,7 @@ class Excerpts
$filename = null;
if (!empty($url_parts['stream'])) {
$filename = $url_parts['scheme'] . '://' . (isset($url_parts['path']) ? $url_parts['path'] : '');
$filename = $url_parts['scheme'] . '://' . ($url_parts['path'] ?? '');
$media = $page->media();
@ -247,10 +248,10 @@ class Excerpts
$medium = static::processMediaActions($medium, $url_parts);
$element_excerpt = $excerpt['element']['attributes'];
$alt = isset($element_excerpt['alt']) ? $element_excerpt['alt'] : '';
$title = isset($element_excerpt['title']) ? $element_excerpt['title'] : '';
$class = isset($element_excerpt['class']) ? $element_excerpt['class'] : '';
$id = isset($element_excerpt['id']) ? $element_excerpt['id'] : '';
$alt = $element_excerpt['alt'] ?? '';
$title = $element_excerpt['title'] ?? '';
$class = $element_excerpt['class'] ?? '';
$id = $element_excerpt['id'] ?? '';
$excerpt['element'] = $medium->parsedownElement($title, $alt, $class, $id, true);
@ -283,7 +284,7 @@ class Excerpts
if (isset($url_parts['query'])) {
$actions = array_reduce(explode('&', $url_parts['query']), function ($carry, $item) {
$parts = explode('=', $item, 2);
$value = isset($parts[1]) ? $parts[1] : null;
$value = $parts[1] ?? null;
$carry[] = ['method' => $parts[0], 'params' => $value];
return $carry;
@ -357,6 +358,10 @@ class Excerpts
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
return $locator->isStream($url) ? ($locator->findResource($url, false) ?: $locator->findResource($url, false, true)) : $url;
if ($locator->isStream($url)) {
return $locator->findResource($url, false) ?: $locator->findResource($url, false, true);
}
return $url;
}
}

View File

@ -1,15 +1,15 @@
<?php
/**
* @package Grav.Common.Helpers
* @package Grav\Common\Helpers
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Helpers;
use Grav\Common\Grav;
use SebastianBergmann\GlobalState\RuntimeException;
class Exif
{
@ -17,7 +17,7 @@ class Exif
/**
* Exif constructor.
* @throws RuntimeException
* @throws \RuntimeException
*/
public function __construct()
{

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Helpers
* @package Grav\Common\Helpers
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -43,7 +44,7 @@ class Truncator {
$dom = self::htmlToDomDocument($html);
// Grab the body of our DOM.
$body = $dom->getElementsByTagName("body")->item(0);
$body = $dom->getElementsByTagName('body')->item(0);
// Iterate over words.
$words = new DOMWordsIterator($body);
@ -81,9 +82,9 @@ class Truncator {
// Return original HTML if not truncated.
if ($truncated) {
return self::innerHTML($body);
} else {
return $html;
}
return $html;
}
/**
@ -93,7 +94,7 @@ class Truncator {
* @param string $ellipsis String to use as ellipsis (if any).
* @return string Safe truncated HTML.
*/
public static function truncateLetters($html, $limit = 0, $ellipsis = "")
public static function truncateLetters($html, $limit = 0, $ellipsis = '')
{
if ($limit <= 0) {
return $html;
@ -129,9 +130,9 @@ class Truncator {
// Return original HTML if not truncated.
if ($truncated) {
return self::innerHTML($body);
} else {
return $html;
}
return $html;
}
/**

View File

@ -1,15 +1,14 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common;
use Grav\Common\Grav;
/**
* This file was originally part of the Akelos Framework
*/
@ -46,14 +45,14 @@ class Inflector
{
static::init();
if ($count == 1) {
if ((int)$count === 1) {
return $word;
}
$lowercased_word = strtolower($word);
foreach (static::$uncountable as $_uncountable) {
if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
if (substr($lowercased_word, -1 * strlen($_uncountable)) === $_uncountable) {
return $word;
}
}
@ -86,13 +85,13 @@ class Inflector
{
static::init();
if ($count != 1) {
if ((int)$count !== 1) {
return $word;
}
$lowercased_word = strtolower($word);
foreach (static::$uncountable as $_uncountable) {
if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
if (substr($lowercased_word, -1 * strlen($_uncountable)) === $_uncountable) {
return $word;
}
}
@ -131,7 +130,7 @@ class Inflector
*/
public static function titleize($word, $uppercase = '')
{
$uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords';
$uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
return $uppercase(static::humanize(static::underscorize($word)));
}
@ -215,7 +214,7 @@ class Inflector
*/
public static function humanize($word, $uppercase = '')
{
$uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst';
$uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
}
@ -287,23 +286,19 @@ class Inflector
{
static::init();
if (in_array(($number % 100), range(11, 13))) {
if (\in_array($number % 100, range(11, 13), true)) {
return $number . static::$ordinals['default'];
} else {
switch (($number % 10)) {
case 1:
return $number . static::$ordinals['first'];
break;
case 2:
return $number . static::$ordinals['second'];
break;
case 3:
return $number . static::$ordinals['third'];
break;
default:
return $number . static::$ordinals['default'];
break;
}
}
switch ($number % 10) {
case 1:
return $number . static::$ordinals['first'];
case 2:
return $number . static::$ordinals['second'];
case 3:
return $number . static::$ordinals['third'];
default:
return $number . static::$ordinals['default'];
}
}
@ -325,7 +320,7 @@ class Inflector
// handle years
if ($diff->y > 0) {
$diff->m = $diff->m + 12 * $diff->y;
$diff->m += 12 * $diff->y;
}
return $diff->m;

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Language
* @package Grav\Common\Language
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -105,7 +106,7 @@ class Language
*/
public function getLanguage()
{
return $this->active ? $this->active : $this->default;
return $this->active ?: $this->default;
}
/**
@ -314,7 +315,8 @@ class Language
* $this->grav['pages']->init();
* ```
*/
public function resetFallbackPageExtensions() {
public function resetFallbackPageExtensions()
{
$this->page_extensions = null;
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Language
* @package Grav\Common\Language
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -179,10 +180,7 @@ class LanguageCodes
public static function isRtl($code)
{
if (static::getOrientation($code) === 'rtl') {
return true;
}
return false;
return static::getOrientation($code) === 'rtl';
}
public static function getNames(array $keys)

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Markdown
* @package Grav\Common\Markdown
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Markdown
* @package Grav\Common\Markdown
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Markdown
* @package Grav\Common\Markdown
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Common\Media
*
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Media\Interfaces;
/**

View File

@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Common\Media
*
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Media\Interfaces;
/**

View File

@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Common\Media
*
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Media\Interfaces;
/**

View File

@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Common\Media
*
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Media\Traits;
use Grav\Common\Cache;

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -100,6 +101,7 @@ class Collection extends Iterator
foreach($collection as $page) {
$this->addPage($page);
}
return $this;
}
@ -117,6 +119,7 @@ class Collection extends Iterator
$this->items = array_uintersect($array1, $array2, function($val1, $val2) {
return strcmp($val1['slug'], $val2['slug']);
});
return $this;
}
@ -130,6 +133,7 @@ class Collection extends Iterator
public function setParams(array $params)
{
$this->params = array_merge($this->params, $params);
return $this;
}
@ -166,7 +170,7 @@ class Collection extends Iterator
*/
public function offsetGet($offset)
{
return !empty($this->items[$offset]) ? $this->pages->get($offset) : null;
return $this->pages->get($offset) ?: null;
}
/**
@ -200,7 +204,7 @@ class Collection extends Iterator
if ($key instanceof Page) {
$key = $key->path();
} elseif (null === $key) {
$key = key($this->items);
$key = (string)key($this->items);
}
if (!\is_string($key)) {
throw new \InvalidArgumentException('Invalid argument $key.');
@ -342,6 +346,7 @@ class Collection extends Iterator
}
$this->items = $date_range;
return $this;
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Page\Interfaces;
/**

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -88,21 +89,21 @@ class Media extends AbstractMedia
/** @var \DirectoryIterator $info */
foreach ($iterator as $path => $info) {
// Ignore folders and Markdown files.
if (!$info->isFile() || $info->getExtension() === 'md' || $info->getFilename()[0] === '.') {
if (!$info->isFile() || $info->getExtension() === 'md' || strpos($info->getFilename(), '.') === 0) {
continue;
}
// Find out what type we're dealing with
list($basename, $ext, $type, $extra) = $this->getFileParts($info->getFilename());
if (!in_array(strtolower($ext), $media_types)) {
if (!\in_array(strtolower($ext), $media_types, true)) {
continue;
}
if ($type === 'alternative') {
$media["{$basename}.{$ext}"][$type][$extra] = [ 'file' => $path, 'size' => $info->getSize() ];
$media["{$basename}.{$ext}"][$type][$extra] = ['file' => $path, 'size' => $info->getSize()];
} else {
$media["{$basename}.{$ext}"][$type] = [ 'file' => $path, 'size' => $info->getSize() ];
$media["{$basename}.{$ext}"][$type] = ['file' => $path, 'size' => $info->getSize()];
}
}
@ -147,7 +148,7 @@ class Media extends AbstractMedia
if (file_exists($meta_path)) {
$types['meta']['file'] = $meta_path;
} elseif ($file_path && $medium->get('mime') === 'image/jpeg' && empty($types['meta']) && $config->get('system.media.auto_metadata_exif') && $exif_reader) {
} elseif ($file_path && $exif_reader && $medium->get('mime') === 'image/jpeg' && empty($types['meta']) && $config->get('system.media.auto_metadata_exif')) {
$meta = $exif_reader->read($file_path);

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -38,14 +39,12 @@ class AudioMedium extends Medium
*/
public function controls($display = true)
{
if($display)
{
if($display) {
$this->attributes['controls'] = true;
}
else
{
} else {
unset($this->attributes['controls']);
}
return $this;
}
@ -57,12 +56,12 @@ class AudioMedium extends Medium
*/
public function preload($preload)
{
$validPreloadAttrs = array('auto','metadata','none');
$validPreloadAttrs = ['auto', 'metadata', 'none'];
if (in_array($preload, $validPreloadAttrs))
{
if (\in_array($preload, $validPreloadAttrs, true)) {
$this->attributes['preload'] = $preload;
}
return $this;
}
@ -77,6 +76,7 @@ class AudioMedium extends Medium
{
$controlsList = str_replace('-', ' ', $controlsList);
$this->attributes['controlsList'] = $controlsList;
return $this;
}
@ -88,14 +88,12 @@ class AudioMedium extends Medium
*/
public function muted($status = false)
{
if($status)
{
if($status) {
$this->attributes['muted'] = true;
}
else
{
} else {
unset($this->attributes['muted']);
}
return $this;
}
@ -107,14 +105,12 @@ class AudioMedium extends Medium
*/
public function loop($status = false)
{
if($status)
{
if($status) {
$this->attributes['loop'] = true;
}
else
{
} else {
unset($this->attributes['loop']);
}
return $this;
}
@ -126,14 +122,12 @@ class AudioMedium extends Medium
*/
public function autoplay($status = false)
{
if($status)
{
if($status) {
$this->attributes['autoplay'] = true;
}
else
{
} else {
unset($this->attributes['autoplay']);
}
return $this;
}
@ -148,6 +142,7 @@ class AudioMedium extends Medium
parent::reset();
$this->attributes['controls'] = true;
return $this;
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -266,7 +267,8 @@ class ImageMedium extends Medium
* @param int [$step=200]
* @return $this
*/
public function derivatives($min_width, $max_width = 2500, $step = 200) {
public function derivatives($min_width, $max_width = 2500, $step = 200)
{
if (!empty($this->alternatives)) {
$max = max(array_keys($this->alternatives));
$base = $this->alternatives[$max];
@ -346,7 +348,7 @@ class ImageMedium extends Medium
$attributes['sizes'] = $this->sizes();
}
return [ 'name' => 'img', 'attributes' => $attributes ];
return ['name' => 'img', 'attributes' => $attributes];
}
/**
@ -426,6 +428,7 @@ class ImageMedium extends Medium
}
$this->quality = $quality;
return $this;
}
@ -445,6 +448,7 @@ class ImageMedium extends Medium
}
$this->format = $format;
return $this;
}
@ -459,6 +463,7 @@ class ImageMedium extends Medium
if ($sizes) {
$this->sizes = $sizes;
return $this;
}
@ -479,10 +484,12 @@ class ImageMedium extends Medium
*/
public function width($value = 'auto')
{
if (!$value || $value === 'auto')
if (!$value || $value === 'auto') {
$this->attributes['width'] = $this->get('width');
else
} else {
$this->attributes['width'] = $value;
}
return $this;
}
@ -500,10 +507,12 @@ class ImageMedium extends Medium
*/
public function height($value = 'auto')
{
if (!$value || $value === 'auto')
if (!$value || $value === 'auto') {
$this->attributes['height'] = $this->get('height');
else
} else {
$this->attributes['height'] = $value;
}
return $this;
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -32,7 +33,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
/**
* @var array
*/
protected $thumbnailTypes = [ 'page', 'default' ];
protected $thumbnailTypes = ['page', 'default'];
protected $thumbnailType = null;
@ -266,7 +267,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
*/
public function querystring($querystring = null, $withQuestionmark = true)
{
if (!is_null($querystring)) {
if (null !== $querystring) {
$this->medium_querystring[] = ltrim($querystring, '?&');
foreach ($this->alternatives as $alt) {
$alt->querystring($querystring, $withQuestionmark);
@ -278,11 +279,11 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
}
// join the strings
$querystring = implode("&", $this->medium_querystring);
$querystring = implode('&', $this->medium_querystring);
// explode all strings
$query_parts = explode("&", $querystring);
$query_parts = explode('&', $querystring);
// Join them again now ensure the elements are unique
$querystring = implode("&", array_unique($query_parts));
$querystring = implode('&', array_unique($query_parts));
return $withQuestionmark ? ('?' . $querystring) : $querystring;
}
@ -494,7 +495,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
*/
public function thumbnail($type = 'auto')
{
if ($type !== 'auto' && !in_array($type, $this->thumbnailTypes)) {
if ($type !== 'auto' && !\in_array($type, $this->thumbnailTypes, true)) {
return $this;
}
@ -560,7 +561,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
{
$classes = func_get_args();
if (!empty($classes)) {
$this->attributes['class'] = implode(',', (array)$classes);
$this->attributes['class'] = implode(',', $classes);
}
return $this;
@ -605,7 +606,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
public function __call($method, $args)
{
$qs = $method;
if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) {
if (\count($args) > 1 || (\count($args) === 1 && !empty($args[0]))) {
$qs .= '=' . implode(',', array_map(function ($a) {
if (is_array($a)) {
$a = '[' . implode(',', $a) . ']';

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -131,23 +132,17 @@ class MediumFactory
switch ($type) {
case 'image':
return new ImageMedium($items, $blueprint);
break;
case 'thumbnail':
return new ThumbnailImageMedium($items, $blueprint);
break;
case 'animated':
case 'vector':
return new StaticImageMedium($items, $blueprint);
break;
case 'video':
return new VideoMedium($items, $blueprint);
break;
case 'audio':
return new AudioMedium($items, $blueprint);
break;
default:
return new Medium($items, $blueprint);
break;
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -15,7 +16,7 @@ trait ParsedownHtmlTrait
/**
* @var \Grav\Common\Markdown\Parsedown
*/
protected $parsedown = null;
protected $parsedown;
/**
* Return HTML markup from the medium.

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -23,6 +24,6 @@ class StaticImageMedium extends Medium
{
empty($attributes['src']) && $attributes['src'] = $this->url($reset);
return [ 'name' => 'img', 'attributes' => $attributes ];
return ['name' => 'img', 'attributes' => $attributes];
}
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@ -83,6 +84,7 @@ class ThumbnailImageMedium extends ImageMedium
public function thumbnail($type = 'auto')
{
$this->bubble('thumbnail', [$type], false);
return $this->bubble('getThumbnail', [], false);
}

View File

@ -1,8 +1,9 @@
<?php
/**
* @package Grav.Common.Page
* @package Grav\Common\Page
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

Some files were not shown because too many files have changed in this diff Show More