Upgrade to 3.2.5

This commit is contained in:
Bastian Allgeier
2019-09-24 11:00:59 +02:00
parent ff9b5b1861
commit 447a9dd266
234 changed files with 1990 additions and 1224 deletions

View File

@@ -4,14 +4,13 @@ namespace Kirby\Api;
use Closure;
use Exception;
use Throwable;
use Kirby\Exception\NotFoundException;
use Kirby\Http\Router;
use Kirby\Http\Response;
use Kirby\Http\Router;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Properties;
use Kirby\Toolkit\Str;
use Throwable;
/**
* The API class is a generic container
@@ -169,12 +168,41 @@ class Api
$auth = $this->route->attributes()['auth'] ?? true;
if ($auth !== false) {
$this->authenticate();
$user = $this->authenticate();
// set PHP locales based on *user* language
// so that e.g. strftime() gets formatted correctly
if (is_a($user, 'Kirby\Cms\User') === true) {
$locale = $language = $user->language();
// if it's not already a full locale, "fake" one
// and assume that the country equals the language
if (Str::contains($locale, '_') !== true) {
$locale .= '_' . strtoupper($locale);
}
// provide some variants as fallbacks to be
// compatible with as many systems as possible
$locales = [
$locale,
$locale . '.UTF-8',
$locale . '.UTF8',
$locale . '.ISO8859-1',
$language,
setlocale(LC_ALL, 0) // fall back to the previously defined locale
];
// set the locales that are relevant for string formatting
// *don't* set LC_CTYPE to avoid breaking other parts of the system
setlocale(LC_MONETARY, $locales);
setlocale(LC_NUMERIC, $locales);
setlocale(LC_TIME, $locales);
}
}
$output = $this->route->action()->call($this, ...$this->route->arguments());
if (is_object($output) === true) {
if (is_object($output) === true && is_a($output, 'Kirby\\Http\\Response') !== true) {
return $this->resolve($output)->toResponse();
}
@@ -186,7 +214,7 @@ class Api
*
* @param string $name
* @param array|null $collection
* @return Kirby\Api\Collection
* @return \Kirby\Api\Collection
*
* @throws NotFoundException If no collection for `$name` exists
*/
@@ -263,7 +291,7 @@ class Api
*
* @param string $name
* @param mixed $object
* @return Kirby\Api\Model
* @return \Kirby\Api\Model
*
* @throws NotFoundException If no model for `$name` exists
*/
@@ -375,7 +403,7 @@ class Api
* API model or collection representation
*
* @param mixed $object
* @return Kirby\Api\Model|Kirby\Api\Collection
* @return \Kirby\Api\Model|\Kirby\Api\Collection
*
* @throws NotFoundException If `$object` cannot be resolved
*/
@@ -540,50 +568,15 @@ class Api
try {
$result = $this->call($path, $method, $requestData);
} catch (Throwable $e) {
if (is_a($e, 'Kirby\Exception\Exception') === true) {
$result = [
'status' => 'error',
'route' => ($this->route)? $this->route->pattern() : null
] + $e->toArray();
} else {
// remove the document root from the file path
$file = $e->getFile();
if (empty($_SERVER['DOCUMENT_ROOT']) === false) {
$file = ltrim(Str::after($file, $_SERVER['DOCUMENT_ROOT']), '/');
}
$result = [
'status' => 'error',
'exception' => get_class($e),
'message' => $e->getMessage(),
'file' => $file,
'line' => $e->getLine(),
'code' => empty($e->getCode()) === false ? $e->getCode() : 500,
'route' => $this->route ? $this->route->pattern() : null
];
}
$result = $this->responseForException($e);
}
if ($result === null) {
$result = [
'status' => 'error',
'message' => 'not found',
'code' => 404,
];
}
if ($result === true) {
$result = [
'status' => 'ok',
];
}
if ($result === false) {
$result = [
'status' => 'error',
'message' => 'bad request',
'code' => 400,
];
$result = $this->responseFor404();
} elseif ($result === false) {
$result = $this->responseFor400();
} elseif ($result === true) {
$result = $this->responseFor200();
}
if (is_array($result) === false) {
@@ -593,17 +586,6 @@ class Api
// pretty print json data
$pretty = (bool)($requestData['query']['pretty'] ?? false) === true;
// remove critical info from the result set if
// debug mode is switched off
if ($this->debug !== true) {
unset(
$result['file'],
$result['exception'],
$result['line'],
$result['route']
);
}
if (($result['status'] ?? 'ok') === 'error') {
$code = $result['code'] ?? 400;
@@ -618,6 +600,95 @@ class Api
return Response::json($result, 200, $pretty);
}
/**
* Returns a 200 - ok
* response array.
*
* @return array
*/
public function responseFor200(): array
{
return [
'status' => 'ok',
'message' => 'ok',
'code' => 200
];
}
/**
* Returns a 400 - bad request
* response array.
*
* @return array
*/
public function responseFor400(): array
{
return [
'status' => 'error',
'message' => 'bad request',
'code' => 400,
];
}
/**
* Returns a 404 - not found
* response array.
*
* @return array
*/
public function responseFor404(): array
{
return [
'status' => 'error',
'message' => 'not found',
'code' => 404,
];
}
/**
* Creates the response array for
* an exception. Kirby exceptions will
* have more information
*
* @param Exception $e
* @return array
*/
public function responseForException($e): array
{
// prepare the result array for all exception types
$result = [
'status' => 'error',
'message' => $e->getMessage(),
'code' => empty($e->getCode()) === true ? 500 : $e->getCode(),
'exception' => get_class($e),
'key' => null,
'file' => F::relativepath($e->getFile(), $_SERVER['DOCUMENT_ROOT'] ?? null),
'line' => $e->getLine(),
'details' => [],
'route' => $this->route ? $this->route->pattern() : null
];
// extend the information for Kirby Exceptions
if (is_a($e, 'Kirby\Exception\Exception') === true) {
$result['key'] = $e->getKey();
$result['details'] = $e->getDetails();
$result['code'] = $e->getHttpCode();
}
// remove critical info from the result set if
// debug mode is switched off
if ($this->debug !== true) {
unset(
$result['file'],
$result['exception'],
$result['line'],
$result['route']
);
}
return $result;
}
/**
* Upload helper method
*
@@ -635,8 +706,26 @@ class Api
$errors = [];
$files = $this->requestFiles();
// get error messages from translation
$errorMessages = [
UPLOAD_ERR_INI_SIZE => t('upload.error.iniSize'),
UPLOAD_ERR_FORM_SIZE => t('upload.error.formSize'),
UPLOAD_ERR_PARTIAL => t('upload.error.partial'),
UPLOAD_ERR_NO_FILE => t('upload.error.noFile'),
UPLOAD_ERR_NO_TMP_DIR => t('upload.error.tmpDir'),
UPLOAD_ERR_CANT_WRITE => t('upload.error.cantWrite'),
UPLOAD_ERR_EXTENSION => t('upload.error.extension')
];
if (empty($files) === true) {
throw new Exception('No uploaded files');
$postMaxSize = Str::toBytes(ini_get('post_max_size'));
$uploadMaxFileSize = Str::toBytes(ini_get('upload_max_filesize'));
if ($postMaxSize < $uploadMaxFileSize) {
throw new Exception(t('upload.error.iniPostSize'));
} else {
throw new Exception(t('upload.error.noFiles'));
}
}
foreach ($files as $upload) {
@@ -648,7 +737,8 @@ class Api
try {
if ($upload['error'] !== 0) {
throw new Exception('Upload error');
$errorMessage = $errorMessages[$upload['error']] ?? t('upload.error.default');
throw new Exception($errorMessage);
}
// get the extension of the uploaded file
@@ -659,7 +749,7 @@ class Api
if (empty($extension) === true || in_array($extension, ['tmp', 'temp'])) {
$mime = F::mime($upload['tmp_name']);
$extension = F::mimeToExtension($mime);
$filename = F::name($upload['name']) . '.' .$extension;
$filename = F::name($upload['name']) . '.' . $extension;
} else {
$filename = basename($upload['name']);
}
@@ -669,7 +759,7 @@ class Api
// move the file to a location including the extension,
// for better mime detection
if (move_uploaded_file($upload['tmp_name'], $source) === false) {
throw new Exception('The uploaded file could not be moved');
throw new Exception(t('upload.error.cantMove'));
}
$data = $callback($source, $filename);

View File

@@ -15,7 +15,6 @@ use APCUIterator;
*/
class ApcuCache extends Cache
{
/**
* Determines if an item exists in the cache
*
@@ -59,7 +58,7 @@ class ApcuCache extends Cache
* needs to return a Value object or null if not found
*
* @param string $key
* @return Kirby\Cache\Value|null
* @return \Kirby\Cache\Value|null
*/
public function retrieve(string $key)
{

View File

@@ -16,7 +16,6 @@ namespace Kirby\Cache;
*/
abstract class Cache
{
/**
* Stores all options for the driver
* @var array
@@ -71,7 +70,7 @@ abstract class Cache
* this needs to be defined by the driver
*
* @param string $key
* @return Kirby\Cache\Value|null
* @return \Kirby\Cache\Value|null
*/
abstract public function retrieve(string $key);
@@ -96,7 +95,7 @@ abstract class Cache
$value = $this->retrieve($key);
// check for a valid cache value
if (!is_a($value, Value::class)) {
if (!is_a($value, 'Kirby\Cache\Value')) {
return $default;
}
@@ -141,7 +140,7 @@ abstract class Cache
$value = $this->retrieve($key);
// check for a valid Value object
if (!is_a($value, Value::class)) {
if (!is_a($value, 'Kirby\Cache\Value')) {
return false;
}
@@ -182,7 +181,7 @@ abstract class Cache
$value = $this->retrieve($key);
// check for a valid Value object
if (!is_a($value, Value::class)) {
if (!is_a($value, 'Kirby\Cache\Value')) {
return false;
}

View File

@@ -16,7 +16,6 @@ use Kirby\Toolkit\F;
*/
class FileCache extends Cache
{
/**
* Full root including prefix
* @var string
@@ -93,7 +92,7 @@ class FileCache extends Cache
* needs to return a Value object or null if not found
*
* @param string $key
* @return Kirby\Cache\Value|null
* @return \Kirby\Cache\Value|null
*/
public function retrieve(string $key)
{

View File

@@ -13,7 +13,6 @@ namespace Kirby\Cache;
*/
class MemCached extends Cache
{
/**
* store for the memache connection
* @var Memcached
@@ -65,7 +64,7 @@ class MemCached extends Cache
* needs to return a Value object or null if not found
*
* @param string $key
* @return Kirby\Cache\Value|null
* @return \Kirby\Cache\Value|null
*/
public function retrieve(string $key)
{

View File

@@ -13,7 +13,6 @@ namespace Kirby\Cache;
*/
class MemoryCache extends Cache
{
/**
* Cache data
* @var array
@@ -45,7 +44,7 @@ class MemoryCache extends Cache
* needs to return a Value object or null if not found
*
* @param string $key
* @return Kirby\Cache\Value|null
* @return \Kirby\Cache\Value|null
*/
public function retrieve(string $key)
{

View File

@@ -13,7 +13,6 @@ namespace Kirby\Cache;
*/
class NullCache extends Cache
{
/**
* Writes an item to the cache for a given number of minutes and
* returns whether the operation was successful
@@ -38,7 +37,7 @@ class NullCache extends Cache
* needs to return a Value object or null if not found
*
* @param string $key
* @return Kirby\Cache\Value|null
* @return \Kirby\Cache\Value|null
*/
public function retrieve(string $key)
{

View File

@@ -17,7 +17,6 @@ use Throwable;
*/
class Value
{
/**
* Cached value
* @var mixed

View File

@@ -92,7 +92,7 @@ class Api extends BaseApi
*
* @param string $path Path to file's parent model
* @param string $filename Filename
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function file(string $path = null, string $filename)
{
@@ -114,7 +114,7 @@ class Api extends BaseApi
* Returns the model's object for the given path
*
* @param string $path Path to parent model
* @return Kirby\Cms\Model|null
* @return \Kirby\Cms\Model|null
*/
public function parent(string $path)
{
@@ -166,7 +166,7 @@ class Api extends BaseApi
/**
* Returns the Kirby instance
*
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
public function kirby()
{
@@ -184,11 +184,11 @@ class Api extends BaseApi
}
/**
* Returns the page object for the given id
*
* @param string $id Page's id
* @return Kirby\Cms\Page|null
*/
* Returns the page object for the given id
*
* @param string $id Page's id
* @return \Kirby\Cms\Page|null
*/
public function page(string $id)
{
$id = str_replace('+', '/', $id);
@@ -214,7 +214,7 @@ class Api extends BaseApi
}
/**
* @param Kirby\Cms\App $kirby
* @param \Kirby\Cms\App $kirby
*/
protected function setKirby(App $kirby)
{
@@ -225,7 +225,7 @@ class Api extends BaseApi
/**
* Returns the site object
*
* @return Kirby\Cms\Site
* @return \Kirby\Cms\Site
*/
public function site()
{
@@ -238,7 +238,7 @@ class Api extends BaseApi
* id is passed
*
* @param string $id User's id
* @return Kirby\Cms\User|null
* @return \Kirby\Cms\User|null
*/
public function user(string $id = null)
{
@@ -263,7 +263,7 @@ class Api extends BaseApi
/**
* Returns the users collection
*
* @return Kirby\Cms\Users
* @return \Kirby\Cms\Users
*/
public function users()
{

View File

@@ -6,8 +6,8 @@ use Kirby\Data\Data;
use Kirby\Email\PHPMailer as Emailer;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Http\Router;
use Kirby\Http\Request;
use Kirby\Http\Router;
use Kirby\Http\Server;
use Kirby\Http\Visitor;
use Kirby\Session\AutoSession;
@@ -15,8 +15,8 @@ use Kirby\Text\KirbyTag;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Config;
use Kirby\Toolkit\Controller;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Dir;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Properties;
/**
@@ -132,7 +132,7 @@ class App
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return [
'languages' => $this->languages(),
@@ -149,7 +149,7 @@ class App
* Returns the Api instance
*
* @internal
* @return Kirby\Cms\Api
* @return \Kirby\Cms\Api
*/
public function api()
{
@@ -181,7 +181,7 @@ class App
*
* @internal
* @param string $name Hook name
* @param mixed $args Arguments to pass to the hooks
* @param mixed ...$args Arguments to pass to the hooks
* @return mixed Resulting value as modified by the hooks
*/
public function apply(string $name, ...$args)
@@ -294,7 +294,7 @@ class App
* automatically injected
*
* @param string $name
* @return Kirby\Cms\Collection|null
* @return \Kirby\Cms\Collection|null
*/
public function collection(string $name)
{
@@ -309,11 +309,11 @@ class App
/**
* Returns all user-defined collections
*
* @return Kirby\Cms\Collections
* @return \Kirby\Cms\Collections
*/
public function collections()
{
return $this->collections = $this->collections ?? new Collections;
return $this->collections = $this->collections ?? new Collections();
}
/**
@@ -357,6 +357,7 @@ class App
* @internal
* @param string $name
* @param array $arguments
* @param string $contentType
* @return array
*/
public function controller(string $name, array $arguments = [], string $contentType = 'html'): array
@@ -388,7 +389,8 @@ class App
* Try to find a controller by name
*
* @param string $name
* @return Kirby\Toolkit\Controller|null
* @param string $contentType
* @return \Kirby\Toolkit\Controller|null
*/
protected function controllerLookup(string $name, string $contentType = 'html')
{
@@ -403,7 +405,7 @@ class App
// registry controller
if ($controller = $this->extension('controllers', $name)) {
return is_a($controller, Controller::class) ? $controller : new Controller($controller);
return is_a($controller, 'Kirby\Toolkit\Controller') ? $controller : new Controller($controller);
}
return null;
@@ -412,7 +414,7 @@ class App
/**
* Returns the default language object
*
* @return Kirby\Cms\Language|null
* @return \Kirby\Cms\Language|null
*/
public function defaultLanguage()
{
@@ -434,7 +436,7 @@ class App
/**
* Detect the prefered language from the visitor object
*
* @return Kirby\Cms\Language
* @return \Kirby\Cms\Language
*/
public function detectedLanguage()
{
@@ -459,7 +461,9 @@ class App
/**
* Returns the Email singleton
*
* @return Kirby\Email\PHPMailer
* @param mixed $preset
* @param array $props
* @return \Kirby\Email\PHPMailer
*/
public function email($preset = [], array $props = [])
{
@@ -470,8 +474,9 @@ class App
* Finds any file in the content directory
*
* @param string $path
* @param mixed $parent
* @param boolean $drafts
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function file(string $path, $parent = null, bool $drafts = true)
{
@@ -479,11 +484,11 @@ class App
$id = dirname($path);
$filename = basename($path);
if (is_a($parent, User::class) === true) {
if (is_a($parent, 'Kirby\Cms\User') === true) {
return $parent->file($filename);
}
if (is_a($parent, File::class) === true) {
if (is_a($parent, 'Kirby\Cms\File') === true) {
$parent = $parent->parent();
}
@@ -511,13 +516,13 @@ class App
/**
* Returns the current App instance
*
* @param Kirby\Cms\App $instance
* @param \Kirby\Cms\App $instance
* @return self
*/
public static function instance(self $instance = null)
{
if ($instance === null) {
return static::$instance ?? new static;
return static::$instance ?? new static();
}
return static::$instance = $instance;
@@ -529,7 +534,7 @@ class App
*
* @internal
* @param mixed $input
* @return Kirby\Http\Response
* @return \Kirby\Http\Response
*/
public function io($input)
{
@@ -652,6 +657,7 @@ class App
* @internal
* @param string $text
* @param array $data
* @param bool $inline
* @return string
*/
public function kirbytext(string $text = null, array $data = [], bool $inline = false): string
@@ -673,7 +679,7 @@ class App
* Returns the current language
*
* @param string|null $code
* @return Kirby\Cms\Language|null
* @return \Kirby\Cms\Language|null
*/
public function language(string $code = null)
{
@@ -696,6 +702,7 @@ class App
* Returns the current language code
*
* @internal
* @param string|null $languageCode
* @return string|null
*/
public function languageCode(string $languageCode = null): ?string
@@ -710,7 +717,7 @@ class App
/**
* Returns all available site languages
*
* @return Kirby\Cms\Languages
* @return \Kirby\Cms\Languages
*/
public function languages()
{
@@ -724,7 +731,7 @@ class App
/**
* Returns the app's locks object
*
* @return Kirby\Cms\ContentLocks
* @return \Kirby\Cms\ContentLocks
*/
public function locks(): ContentLocks
{
@@ -732,7 +739,7 @@ class App
return $this->locks;
}
return $this->locks = new ContentLocks;
return $this->locks = new ContentLocks();
}
/**
@@ -787,6 +794,7 @@ class App
/**
* Inject options from Kirby instance props
*
* @param array $options
* @return array
*/
protected function optionsFromProps(array $options = []): array
@@ -819,9 +827,9 @@ class App
* Returns any page from the content folder
*
* @param string $id
* @param Kirby\Cms\Page|Kirby\Cms\Site|null $parent
* @param \Kirby\Cms\Page|\Kirby\Cms\Site|null $parent
* @param bool $drafts
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function page(string $id, $parent = null, bool $drafts = true)
{
@@ -863,7 +871,9 @@ class App
* Returns the Response object for the
* current request
*
* @return Kirby\Http\Response
* @param string|null $path
* @param string|null $method
* @return \Kirby\Http\Response
*/
public function render(string $path = null, string $method = null)
{
@@ -873,11 +883,11 @@ class App
/**
* Returns the Request singleton
*
* @return Kirby\Http\Request
* @return \Kirby\Http\Request
*/
public function request()
{
return $this->request = $this->request ?? new Request;
return $this->request = $this->request ?? new Request();
}
/**
@@ -954,17 +964,17 @@ class App
/**
* Response configuration
*
* @return Kirby\Cms\Responder
* @return \Kirby\Cms\Responder
*/
public function response()
{
return $this->response = $this->response ?? new Responder;
return $this->response = $this->response ?? new Responder();
}
/**
* Returns all user roles
*
* @return Kirby\Cms\Roles
* @return \Kirby\Cms\Roles
*/
public function roles()
{
@@ -985,7 +995,7 @@ class App
/**
* Returns the directory structure
*
* @return Kirby\Cms\Ingredients
* @return \Kirby\Cms\Ingredients
*/
public function roots()
{
@@ -995,7 +1005,7 @@ class App
/**
* Returns the currently active route
*
* @return Kirby\Http\Route|null
* @return \Kirby\Http\Route|null
*/
public function route()
{
@@ -1006,7 +1016,7 @@ class App
* Returns the Router singleton
*
* @internal
* @return Kirby\Http\Router
* @return \Kirby\Http\Router
*/
public function router()
{
@@ -1046,7 +1056,7 @@ class App
* Returns the current session object
*
* @param array $options Additional options, see the session component
* @return Kirby\Session\Session
* @return \Kirby\Session\Session
*/
public function session(array $options = [])
{
@@ -1123,7 +1133,7 @@ class App
/**
* Sets a custom Site object
*
* @param Kirby\Cms\Site|array $site
* @param \Kirby\Cms\Site|array $site
* @return self
*/
protected function setSite($site = null)
@@ -1141,17 +1151,17 @@ class App
/**
* Returns the Server object
*
* @return Kirby\Http\Server
* @return \Kirby\Http\Server
*/
public function server()
{
return $this->server = $this->server ?? new Server;
return $this->server = $this->server ?? new Server();
}
/**
* Initializes and returns the Site object
*
* @return Kirby\Cms\Site
* @return \Kirby\Cms\Site
*/
public function site()
{
@@ -1186,7 +1196,9 @@ class App
* and return a template snippet
*
* @internal
* @return string
* @param mixed $name
* @param array $data
* @return string|null
*/
public function snippet($name, array $data = []): ?string
{
@@ -1196,7 +1208,7 @@ class App
/**
* System check class
*
* @return Kirby\Cms\System
* @return \Kirby\Cms\System
*/
public function system()
{
@@ -1208,7 +1220,10 @@ class App
* and return the Template object
*
* @internal
* @return Kirby\Cms\Template
* @return \Kirby\Cms\Template
* @param string $name
* @param string $type
* @param string $defaultType
*/
public function template(string $name, string $type = 'html', string $defaultType = 'html')
{
@@ -1277,7 +1292,7 @@ class App
/**
* Returns the url structure
*
* @return Kirby\Cms\Ingredients
* @return \Kirby\Cms\Ingredients
*/
public function urls()
{
@@ -1308,7 +1323,7 @@ class App
/**
* Returns the visitor object
*
* @return Kirby\Cms\Visitor
* @return \Kirby\Cms\Visitor
*/
public function visitor()
{

View File

@@ -23,7 +23,7 @@ trait AppCaches
* Returns a cache instance by key
*
* @param string $key
* @return Kirby\Cache\Cache
* @return \Kirby\Cache\Cache
*/
public function cache(string $key)
{
@@ -36,7 +36,7 @@ trait AppCaches
if ($options['active'] === false) {
// use a dummy cache that does nothing
return $this->caches[$key] = new NullCache;
return $this->caches[$key] = new NullCache();
}
$type = strtolower($options['type']);
@@ -55,7 +55,7 @@ trait AppCaches
$cache = new $className($options);
// check if it is a useable cache object
if (is_a($cache, Cache::class) !== true) {
if (is_a($cache, 'Kirby\Cache\Cache') !== true) {
throw new InvalidArgumentException([
'key' => 'app.invalid.cacheType',
'data' => ['type' => $type]

View File

@@ -3,11 +3,11 @@
namespace Kirby\Cms;
use Kirby\Http\Response;
use Whoops\Run as Whoops;
use Whoops\Handler\Handler;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Handler\PlainTextHandler;
use Whoops\Handler\CallbackHandler;
use Whoops\Handler\Handler;
use Whoops\Handler\PlainTextHandler;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run as Whoops;
/**
* AppErrors
@@ -22,8 +22,8 @@ trait AppErrors
{
protected function handleCliErrors(): void
{
$whoops = new Whoops;
$whoops->pushHandler(new PlainTextHandler);
$whoops = new Whoops();
$whoops->pushHandler(new PlainTextHandler());
$whoops->register();
}
@@ -45,11 +45,11 @@ trait AppErrors
protected function handleHtmlErrors()
{
$whoops = new Whoops;
$whoops = new Whoops();
if ($this->option('debug') === true) {
if ($this->option('whoops', true) === true) {
$handler = new PrettyPageHandler;
$handler = new PrettyPageHandler();
$handler->setPageTitle('Kirby CMS Debugger');
if ($editor = $this->option('editor')) {
@@ -79,7 +79,7 @@ trait AppErrors
protected function handleJsonErrors()
{
$whoops = new Whoops;
$whoops = new Whoops();
$handler = new CallbackHandler(function ($exception, $inspector, $run) {
if (is_a($exception, 'Kirby\Exception\Exception') === true) {
$httpCode = $exception->getHttpCode();

View File

@@ -23,7 +23,6 @@ use Kirby\Toolkit\V;
*/
trait AppPlugins
{
/**
* A list of all registered plugins
*
@@ -83,7 +82,7 @@ trait AppPlugins
*
* @internal
* @param array $extensions
* @param Kirby\Cms\Plugin $plugin The plugin which defined those extensions
* @param \Kirby\Cms\Plugin $plugin The plugin which defined those extensions
* @return array
*/
public function extend(array $extensions, Plugin $plugin = null): array
@@ -106,7 +105,7 @@ trait AppPlugins
protected function extendApi($api): array
{
if (is_array($api) === true) {
if (is_a($api['routes'] ?? [], Closure::class) === true) {
if (is_a($api['routes'] ?? [], 'Closure') === true) {
$api['routes'] = $api['routes']($this);
}
@@ -254,7 +253,7 @@ trait AppPlugins
/**
* Registers markdown component
*
* @param Closure $blueprints
* @param Closure $markdown
* @return Closure
*/
protected function extendMarkdown(Closure $markdown)
@@ -266,7 +265,7 @@ trait AppPlugins
* Registers additional options
*
* @param array $options
* @param Kirby\Cms\Plugin|null $plugin
* @param \Kirby\Cms\Plugin|null $plugin
* @return array
*/
protected function extendOptions(array $options, Plugin $plugin = null): array
@@ -336,7 +335,7 @@ trait AppPlugins
*/
protected function extendRoutes($routes): array
{
if (is_a($routes, Closure::class) === true) {
if (is_a($routes, 'Closure') === true) {
$routes = $routes($this);
}
@@ -480,7 +479,7 @@ trait AppPlugins
/**
* Returns the extensions registry
*
* @internal
* @param string|null $type
* @return array
@@ -556,6 +555,7 @@ trait AppPlugins
/**
* Apply all passed extensions
*
* @param array $props
* @return void
*/
protected function extensionsFromProps(array $props)
@@ -643,7 +643,7 @@ trait AppPlugins
*
* @param string $name
* @param array|null $extends If null is passed it will be used as getter. Otherwise as factory.
* @return Kirby\Cms\Plugin|null
* @return \Kirby\Cms\Plugin|null
*/
public static function plugin(string $name, array $extends = null)
{
@@ -658,7 +658,7 @@ trait AppPlugins
$name = $plugin->name();
if (isset(static::$plugins[$name]) === true) {
throw new DuplicateException('The plugin "'. $name . '" has already been registered');
throw new DuplicateException('The plugin "' . $name . '" has already been registered');
}
return static::$plugins[$name] = $plugin;

View File

@@ -85,7 +85,7 @@ trait AppTranslations
*
* @internal
* @param string $languageCode
* @return Kirby\Cms\Language|null
* @return \Kirby\Cms\Language|null
*/
public function setCurrentLanguage(string $languageCode = null)
{
@@ -140,7 +140,7 @@ trait AppTranslations
* Load a specific translation by locale
*
* @param string|null $locale
* @return Kirby\Cms\Translation|null
* @return \Kirby\Cms\Translation|null
*/
public function translation(string $locale = null)
{
@@ -164,7 +164,7 @@ trait AppTranslations
/**
* Returns all available translations
*
* @return Kirby\Cms\Translations
* @return \Kirby\Cms\Translations
*/
public function translations()
{

View File

@@ -15,7 +15,6 @@ use Throwable;
*/
trait AppUsers
{
/**
* Cache for the auth auth layer
*
@@ -27,7 +26,7 @@ trait AppUsers
* Returns the Authentication layer class
*
* @internal
* @return Kirby\Cms\Auth
* @return \Kirby\Cms\Auth
*/
public function auth()
{
@@ -38,7 +37,7 @@ trait AppUsers
* Become any existing user
*
* @param string|null $who
* @return Kirby\Cms\User|null
* @return \Kirby\Cms\User|null
*/
public function impersonate(string $who = null)
{
@@ -48,8 +47,8 @@ trait AppUsers
/**
* Set the currently active user id
*
* @param Kirby\Cms\User|string $user
* @return Kirby\Cms\App
* @param \Kirby\Cms\User|string $user
* @return \Kirby\Cms\App
*/
protected function setUser($user = null)
{
@@ -61,7 +60,7 @@ trait AppUsers
* Create your own set of app users
*
* @param array $users
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
protected function setUsers(array $users = null)
{
@@ -79,7 +78,7 @@ trait AppUsers
* or the current user if no id is given
*
* @param string $id
* @return Kirby\Cms\User|null
* @return \Kirby\Cms\User|null
*/
public function user(string $id = null)
{
@@ -101,7 +100,7 @@ trait AppUsers
/**
* Returns all users
*
* @return Kirby\Cms\Users
* @return \Kirby\Cms\Users
*/
public function users()
{

View File

@@ -31,6 +31,8 @@ class Asset
/**
* Creates a new Asset object
* for the given path.
*
* @param string $path
*/
public function __construct(string $path)
{

View File

@@ -3,9 +3,9 @@
namespace Kirby\Cms;
use Kirby\Data\Data;
use Kirby\Exception\PermissionException;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Exception\PermissionException;
use Kirby\Http\Request\Auth\BasicAuth;
use Kirby\Toolkit\F;
use Throwable;
@@ -27,7 +27,7 @@ class Auth
protected $userException;
/**
* @param Kirby\Cms\App $kirby
* @param \Kirby\Cms\App $kirby
* @codeCoverageIgnore
*/
public function __construct(App $kirby)
@@ -61,8 +61,8 @@ class Auth
* for a basic authentication header with
* valid credentials
*
* @param Kirby\Http\Request\Auth\BasicAuth|null $auth
* @return Kirby\Cms\User|null
* @param \Kirby\Http\Request\Auth\BasicAuth|null $auth
* @return \Kirby\Cms\User|null
*/
public function currentUserFromBasicAuth(BasicAuth $auth = null)
{
@@ -90,8 +90,8 @@ class Auth
* the current session and finding a valid
* valid user id in there
*
* @param Kirby\Cms\Session|array|null $session
* @return Kirby\Cms\User|null
* @param \Kirby\Session\Session|array|null $session
* @return \Kirby\Cms\User|null
*/
public function currentUserFromSession($session = null)
{
@@ -125,7 +125,7 @@ class Auth
* Become any existing user
*
* @param string|null $who
* @return Kirby\Cms\User|null
* @return \Kirby\Cms\User|null
*/
public function impersonate(string $who = null)
{
@@ -196,7 +196,7 @@ class Auth
* @param string $email
* @param string $password
* @param boolean $long
* @return Kirby\Cms\User
* @return \Kirby\Cms\User
*
* @throws PermissionException If the rate limit was exceeded or if any other error occured with debug mode off
* @throws NotFoundException If the email was invalid
@@ -226,7 +226,7 @@ class Auth
*
* @param string $email
* @param string $password
* @return Kirby\Cms\User
* @return \Kirby\Cms\User
*
* @throws PermissionException If the rate limit was exceeded or if any other error occured with debug mode off
* @throws NotFoundException If the email was invalid
@@ -413,8 +413,8 @@ class Auth
/**
* Validates the currently logged in user
*
* @param Kirby\Session\Session|array|null $session
* @return Kirby\Cms\User
* @param \Kirby\Session\Session|array|null $session
* @return \Kirby\Cms\User
* @throws
*/
public function user($session = null)

View File

@@ -3,9 +3,9 @@
namespace Kirby\Cms;
use Exception;
use Kirby\Data\Data;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Data\Data;
use Kirby\Form\Field;
use Kirby\Toolkit\A;
use Kirby\Toolkit\F;
@@ -90,7 +90,7 @@ class Blueprint
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->props ?? [];
}
@@ -222,7 +222,7 @@ class Blueprint
*
* @param string $name
* @param string $fallback
* @param Kirby\Cms\Model $model
* @param \Kirby\Cms\Model $model
* @return self
*/
public static function factory(string $name, string $fallback = null, Model $model)
@@ -352,7 +352,7 @@ class Blueprint
/**
* Returns the parent model
*
* @return Kirby\Cms\Model
* @return \Kirby\Cms\Model
*/
public function model()
{
@@ -603,7 +603,14 @@ class Blueprint
'type' => $type = $sectionProps['type'] ?? null
]);
if (isset(Section::$types[$type]) === false) {
if (empty($type) === true || is_string($type) === false) {
$sections[$sectionName] = [
'name' => $sectionName,
'headline' => 'Invalid section type for section "' . $sectionName . '"',
'type' => 'info',
'text' => 'The following section types are available: ' . $this->helpList(array_keys(Section::$types))
];
} elseif (isset(Section::$types[$type]) === false) {
$sections[$sectionName] = [
'name' => $sectionName,
'headline' => 'Invalid section type ("' . $type . '")',
@@ -712,7 +719,7 @@ class Blueprint
* Returns a single section by name
*
* @param string $name
* @return Kirby\Cms\Section|null
* @return \Kirby\Cms\Section|null
*/
public function section(string $name)
{

View File

@@ -101,23 +101,22 @@ class Collection extends BaseCollection
/**
* Appends an element to the data array
*
* @param mixed $key
* @param mixed $key Optional collection key, will be determined from the item if not given
* @param mixed $item
* @return Kirby\Cms\Collection
* @return \Kirby\Cms\Collection
*/
public function append(...$args)
{
if (count($args) === 1) {
if (is_object($args[0]) === true) {
$this->data[$args[0]->id()] = $args[0];
// try to determine the key from the provided item
if (is_object($args[0]) === true && is_callable([$args[0], 'id']) === true) {
return parent::append($args[0]->id(), $args[0]);
} else {
$this->data[] = $args[0];
return parent::append($args[0]);
}
} elseif (count($args) === 2) {
$this->set($args[0], $args[1]);
}
return $this;
return parent::append(...$args);
}
/**
@@ -126,7 +125,7 @@ class Collection extends BaseCollection
*
* @param string $field
* @param bool $i Ignore upper/lowercase for group names
* @return Kirby\Cms\Collection
* @return \Kirby\Cms\Collection
*/
public function groupBy($field, bool $i = true)
{
@@ -165,7 +164,7 @@ class Collection extends BaseCollection
* Checks if the given object or id
* is in the collection
*
* @param string|object
* @param string|object $id
* @return boolean
*/
public function has($id): bool
@@ -197,8 +196,8 @@ class Collection extends BaseCollection
/**
* Returns a Collection without the given element(s)
*
* @param mixed[] $keys any number of keys, passed as individual arguments
* @return Kirby\Cms\Collection
* @param mixed ...$keys any number of keys, passed as individual arguments
* @return \Kirby\Cms\Collection
*/
public function not(...$keys)
{
@@ -217,7 +216,8 @@ class Collection extends BaseCollection
/**
* Add pagination and return a sliced set of data.
*
* @return Kirby\Cms\Collection
* @param mixed ...$arguments
* @return \Kirby\Cms\Collection
*/
public function paginate(...$arguments)
{
@@ -230,13 +230,34 @@ class Collection extends BaseCollection
/**
* Returns the parent model
*
* @return Kirby\Cms\Model
* @return \Kirby\Cms\Model
*/
public function parent()
{
return $this->parent;
}
/**
* Prepends an element to the data array
*
* @param mixed $key Optional collection key, will be determined from the item if not given
* @param mixed $item
* @return Kirby\Cms\Collection
*/
public function prepend(...$args)
{
if (count($args) === 1) {
// try to determine the key from the provided item
if (is_object($args[0]) === true && is_callable([$args[0], 'id']) === true) {
return parent::prepend($args[0]->id(), $args[0]);
} else {
return parent::prepend($args[0]);
}
}
return parent::prepend(...$args);
}
/**
* Runs a combination of filterBy, sortBy, not
* offset, limit, search and paginate on the collection.

View File

@@ -21,7 +21,6 @@ use Kirby\Toolkit\Controller;
*/
class Collections
{
/**
* Each collection is cached once it
* has been called, to avoid further
@@ -45,7 +44,7 @@ class Collections
*
* @param string $name
* @param array $arguments
* @return Kirby\Cms\Collection|null
* @return \Kirby\Cms\Collection|null
*/
public function __call(string $name, array $arguments = [])
{
@@ -57,7 +56,7 @@ class Collections
*
* @param string $name
* @param array $data
* @return Kirby\Cms\Collection|null
* @return \Kirby\Cms\Collection|null
*/
public function get(string $name, array $data = [])
{

View File

@@ -14,7 +14,6 @@ namespace Kirby\Cms;
*/
class Content
{
/**
* The raw data array
*
@@ -47,7 +46,7 @@ class Content
*
* @param string $name
* @param array $arguments
* @return Kirby\Cms\Field
* @return \Kirby\Cms\Field
*/
public function __call(string $name, array $arguments = [])
{
@@ -73,7 +72,7 @@ class Content
* @see self::data()
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->toArray();
}
@@ -147,8 +146,8 @@ class Content
* Returns either a single field object
* or all registered fields
*
* @param string $key
* @return Kirby\Cms\Field|array
* @param string $key
* @return \Kirby\Cms\Field|array
*/
public function get(string $key = null)
{
@@ -217,7 +216,7 @@ class Content
* Returns the parent
* Site, Page, File or User object
*
* @return Kirby\Cms\Model
* @return \Kirby\Cms\Model
*/
public function parent()
{
@@ -227,7 +226,7 @@ class Content
/**
* Set the parent model
*
* @param Kirby\Cms\Model $parent
* @param \Kirby\Cms\Model $parent
* @return self
*/
public function setParent(Model $parent)

View File

@@ -17,7 +17,6 @@ use Kirby\Exception\PermissionException;
*/
class ContentLock
{
/**
* Lock data
*
@@ -33,7 +32,7 @@ class ContentLock
protected $model;
/**
* @param Kirby\Cms\ModelWithContent $model
* @param \Kirby\Cms\ModelWithContent $model
*/
public function __construct(ModelWithContent $model)
{
@@ -80,13 +79,13 @@ class ContentLock
$data['user'] !== $this->user()->id() &&
$user = $this->kirby()->user($data['user'])
) {
$time = intval($data['time']);
$time = (int)($data['time']);
return [
'user' => $user->id(),
'email' => $user->email(),
'time' => $time,
'unlockable' => $time + $this->kirby()->option('lock.duration', 60 * 2) <= time()
'unlockable' => ($time + 200) <= time()
];
}
@@ -124,7 +123,7 @@ class ContentLock
/**
* Returns the app instance
*
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
protected function kirby(): App
{
@@ -201,7 +200,7 @@ class ContentLock
* Returns currently authenticated user;
* throws exception if none is authenticated
*
* @return Kirby\Cms\User
* @return \Kirby\Cms\User
*/
protected function user(): User
{

View File

@@ -18,7 +18,6 @@ use Kirby\Toolkit\F;
*/
class ContentLocks
{
/**
* Data from the `.lock` files
* that have been read so far
@@ -73,7 +72,7 @@ class ContentLocks
/**
* Returns the path to a model's lock file
*
* @param Kirby\Cms\ModelWithContent $model
* @param \Kirby\Cms\ModelWithContent $model
* @return string
*/
public static function file(ModelWithContent $model): string
@@ -84,7 +83,7 @@ class ContentLocks
/**
* Returns the lock/unlock data for the specified model
*
* @param Kirby\Cms\ModelWithContent $model
* @param \Kirby\Cms\ModelWithContent $model
* @return array
*/
public function get(ModelWithContent $model): array
@@ -155,7 +154,7 @@ class ContentLocks
* Returns model ID used as the key for the data array;
* prepended with a slash because the $site otherwise won't have an ID
*
* @param Kirby\Cms\ModelWithContent $model
* @param \Kirby\Cms\ModelWithContent $model
* @return string
*/
public static function id(ModelWithContent $model): string
@@ -166,7 +165,7 @@ class ContentLocks
/**
* Sets and writes the lock/unlock data for the specified model
*
* @param Kirby\Cms\ModelWithContent $model
* @param \Kirby\Cms\ModelWithContent $model
* @param array $data
* @return boolean
*/

View File

@@ -60,7 +60,7 @@ class ContentTranslation
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->toArray();
}
@@ -154,7 +154,7 @@ class ContentTranslation
/**
* Returns the parent page, file or site object
*
* @return Kirby\Cms\Model
* @return \Kirby\Cms\Model
*/
public function parent()
{
@@ -182,7 +182,7 @@ class ContentTranslation
}
/**
* @param Kirby\Cms\Model $parent
* @param \Kirby\Cms\Model $parent
* @return self
*/
protected function setParent(Model $parent)

View File

@@ -109,7 +109,7 @@ class Email
*
* @param string $name
* @param string|null $type
* @return Kirby\Cms\Template
* @return \Kirby\Cms\Template
*/
protected function getTemplate(string $name, string $type = null)
{

View File

@@ -27,7 +27,6 @@ use Kirby\Exception\InvalidArgumentException;
*/
class Field
{
/**
* Field method aliases
*
@@ -111,7 +110,7 @@ class Field
* @see Field::toArray
* @return void
*/
public function __debuginfo()
public function __debugInfo()
{
return $this->toArray();
}
@@ -170,7 +169,7 @@ class Field
/**
* @see Field::parent()
* @return Kirby\Cms\Model|null
* @return \Kirby\Cms\Model|null
*/
public function model()
{
@@ -201,7 +200,7 @@ class Field
/**
* Returns the parent object of the field
*
* @return Kirby\Cms\Model|null
* @return \Kirby\Cms\Model|null
*/
public function parent()
{

View File

@@ -5,7 +5,6 @@ namespace Kirby\Cms;
use Kirby\Image\Image;
use Kirby\Toolkit\A;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Str;
/**
* The `$file` object provides a set
@@ -42,14 +41,14 @@ class File extends ModelWithContent
* This is used to do actual file
* method calls, like size, mime, etc.
*
* @var Kirby\Image\Image
* @var \Kirby\Image\Image
*/
protected $asset;
/**
* Cache for the initialized blueprint object
*
* @var Kirby\Cms\FileBlueprint
* @var \Kirby\Cms\FileBlueprint
*/
protected $blueprint;
@@ -73,7 +72,7 @@ class File extends ModelWithContent
/**
* The parent object
*
* @var Kirby\Cms\Model
* @var \Kirby\Cms\Model
*/
protected $parent;
@@ -141,7 +140,7 @@ class File extends ModelWithContent
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return array_merge($this->toArray(), [
'content' => $this->content(),
@@ -165,7 +164,7 @@ class File extends ModelWithContent
* Returns the Image object
*
* @internal
* @return Kirby\Image\Image
* @return \Kirby\Image\Image
*/
public function asset()
{
@@ -175,7 +174,7 @@ class File extends ModelWithContent
/**
* Returns the FileBlueprint object for the file
*
* @return Kirby\Cms\FileBlueprint
* @return \Kirby\Cms\FileBlueprint
*/
public function blueprint()
{
@@ -189,7 +188,7 @@ class File extends ModelWithContent
/**
* Store the template in addition to the
* other content.
*
* @internal
* @param array $data
* @param string|null $languageCode
@@ -232,28 +231,32 @@ class File extends ModelWithContent
* gets dragged onto a textarea
*
* @internal
* @param string $type
* @param string $type (auto|kirbytext|markdown)
* @param bool $absolute
* @return string
*/
public function dragText($type = 'kirbytext', bool $absolute = false): string
public function dragText($type = 'auto', bool $absolute = false): string
{
if ($type === 'auto') {
$type = option('panel.kirbytext', true) ? 'kirbytext' : 'markdown';
}
$url = $absolute ? $this->id() : $this->filename();
switch ($type) {
case 'kirbytext':
if ($this->type() === 'image') {
return '(image: ' . $url . ')';
} else {
return '(file: ' . $url . ')';
}
// no break
case 'markdown':
if ($this->type() === 'image') {
return '![' . $this->alt() . '](' . $url . ')';
} else {
return '[' . $this->filename() . '](' . $url . ')';
}
// no break
default:
if ($this->type() === 'image') {
return '(image: ' . $url . ')';
} else {
return '(file: ' . $url . ')';
}
}
}
@@ -261,6 +264,7 @@ class File extends ModelWithContent
* Constructs a File object
*
* @internal
* @param mixed $props
* @return self
*/
public static function factory($props)
@@ -281,7 +285,7 @@ class File extends ModelWithContent
/**
* Returns the parent Files collection
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function files()
{
@@ -311,7 +315,7 @@ class File extends ModelWithContent
/**
* Compares the current object with the given file object
*
* @param Kirby\Cms\File $file
* @param \Kirby\Cms\File $file
* @return bool
*/
public function is(File $file): bool
@@ -355,7 +359,7 @@ class File extends ModelWithContent
/**
* @deprecated 3.0.0 Use `File::content()` instead
*
* @return Kirby\Cms\Content
* @return \Kirby\Cms\Content
*/
public function meta()
{
@@ -409,7 +413,7 @@ class File extends ModelWithContent
/**
* Returns the parent Page object
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function page()
{
@@ -468,7 +472,7 @@ class File extends ModelWithContent
*
* @internal
* @param string|null $query
* @return Kirby\Cms\File|Kirby\Cms\Asset|null
* @return \Kirby\Cms\File|\Kirby\Cms\Asset|null
*/
protected function panelImageSource(string $query = null)
{
@@ -538,7 +542,7 @@ class File extends ModelWithContent
/**
* Returns the parent Model object
*
* @return Kirby\Cms\Model
* @return \Kirby\Cms\Model
*/
public function parent()
{
@@ -563,7 +567,7 @@ class File extends ModelWithContent
/**
* Returns a collection of all parent pages
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function parents()
{
@@ -571,13 +575,13 @@ class File extends ModelWithContent
return $this->parent()->parents()->prepend($this->parent()->id(), $this->parent());
}
return new Pages;
return new Pages();
}
/**
* Returns the permissions object for this file
*
* @return Kirby\Cms\FilePermissions
* @return \Kirby\Cms\FilePermissions
*/
public function permissions()
{
@@ -598,7 +602,7 @@ class File extends ModelWithContent
* Returns the FileRules class to
* validate any important action.
*
* @return Kirby\Cms\FileRules
* @return \Kirby\Cms\FileRules
*/
protected function rules()
{
@@ -636,7 +640,7 @@ class File extends ModelWithContent
/**
* Sets the parent model object
*
* @param Kirby\Cms\Model $parent
* @param \Kirby\Cms\Model $parent
* @return self
*/
protected function setParent(Model $parent = null)
@@ -684,7 +688,7 @@ class File extends ModelWithContent
* Returns the parent Files collection
* @internal
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
protected function siblingsCollection()
{
@@ -694,7 +698,7 @@ class File extends ModelWithContent
/**
* Returns the parent Site object
*
* @return Kirby\Cms\Site
* @return \Kirby\Cms\Site
*/
public function site()
{
@@ -715,7 +719,7 @@ class File extends ModelWithContent
* Returns siblings with the same template
*
* @param bool $self
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function templateSiblings(bool $self = true)
{

View File

@@ -19,7 +19,6 @@ use Kirby\Toolkit\F;
*/
trait FileActions
{
/**
* Renames the file without touching the extension
* The store is used to actually execute this.
@@ -53,7 +52,9 @@ trait FileActions
}
// remove the lock of the old file
$oldFile->lock()->remove();
if ($lock = $oldFile->lock()) {
$lock->remove();
}
// remove all public versions
$oldFile->unpublish();
@@ -121,8 +122,8 @@ trait FileActions
/**
* Copy the file to the given page
*
* @param Kirby\Cms\Page $page
* @return Kirby\Cms\File
* @param \Kirby\Cms\Page $page
* @return \Kirby\Cms\File
*/
public function copy(Page $page)
{
@@ -216,7 +217,9 @@ trait FileActions
$file->unpublish();
// remove the lock of the old file
$file->lock()->remove();
if ($lock = $file->lock()) {
$lock->remove();
}
if ($file->kirby()->multilang() === true) {
foreach ($file->translations() as $translation) {

View File

@@ -44,6 +44,7 @@ class FileBlueprint extends Blueprint
}
/**
* @param mixed $accept
* @return array
*/
protected function normalizeAccept($accept = null): array

View File

@@ -72,7 +72,7 @@ trait FileFoundation
/**
* Returns the Image object
*
* @return Kirby\Image\Image
* @return \Kirby\Image\Image
*/
public function asset()
{
@@ -155,7 +155,7 @@ trait FileFoundation
/**
* Returns the app instance
*
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
public function kirby()
{

View File

@@ -15,12 +15,11 @@ use Kirby\Exception\InvalidArgumentException;
*/
trait FileModifications
{
/**
* Blurs the image by the given amount of pixels
*
* @param boolean $pixels
* @return Kirby\Cms\FileVersion|Kirby\Cms\File
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
*/
public function blur($pixels = true)
{
@@ -30,7 +29,7 @@ trait FileModifications
/**
* Converts the image to black and white
*
* @return Kirby\Cms\FileVersion|Kirby\Cms\File
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
*/
public function bw()
{
@@ -43,7 +42,7 @@ trait FileModifications
* @param integer $width
* @param integer $height
* @param string|array $options
* @return Kirby\Cms\FileVersion|Kirby\Cms\File
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
*/
public function crop(int $width, int $height = null, $options = null)
{
@@ -73,7 +72,7 @@ trait FileModifications
* Sets the JPEG compression quality
*
* @param integer $quality
* @return Kirby\Cms\FileVersion|Kirby\Cms\File
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
*/
public function quality(int $quality)
{
@@ -87,7 +86,7 @@ trait FileModifications
* @param integer $width
* @param integer $height
* @param integer $quality
* @return Kirby\Cms\FileVersion|Kirby\Cms\File
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
*/
public function resize(int $width = null, int $height = null, int $quality = null)
{
@@ -155,7 +154,7 @@ trait FileModifications
* place.
*
* @param array|null|string $options
* @return Kirby\Cms\FileVersion|Kirby\Cms\File
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
*/
public function thumb($options = null)
{
@@ -172,7 +171,7 @@ trait FileModifications
$result = $this->kirby()->component('file::version')($this->kirby(), $this, $options);
if (is_a($result, FileVersion::class) === false && is_a($result, File::class) === false) {
if (is_a($result, 'Kirby\Cms\FileVersion') === false && is_a($result, 'Kirby\Cms\File') === false) {
throw new InvalidArgumentException('The file::version component must return a File or FileVersion object');
}

View File

@@ -37,7 +37,7 @@ class FileVersion
return $this->asset()->$method(...$arguments);
}
if (is_a($this->original(), File::class) === true) {
if (is_a($this->original(), 'Kirby\Cms\File') === true) {
// content fields
return $this->original()->content()->get($method, $arguments);
}
@@ -49,7 +49,7 @@ class FileVersion
}
/**
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
public function kirby()
{

View File

@@ -28,7 +28,6 @@ use Kirby\Toolkit\Str;
*/
class Filename
{
/**
* List of all applicable attributes
*
@@ -167,7 +166,7 @@ class Filename
return false;
}
return intval($value);
return (int)$value;
}
/**
@@ -257,7 +256,7 @@ class Filename
return false;
}
return intval($value);
return (int)$value;
}
/**

View File

@@ -18,7 +18,6 @@ namespace Kirby\Cms;
*/
class Files extends Collection
{
/**
* All registered files methods
*
@@ -31,7 +30,7 @@ class Files extends Collection
* an entire second collection to the
* current collection
*
* @param mixed $item
* @param mixed $object
* @return self
*/
public function add($object)
@@ -45,7 +44,7 @@ class Files extends Collection
$this->__set($file->id(), $file);
// add a file object
} elseif (is_a($object, File::class) === true) {
} elseif (is_a($object, 'Kirby\Cms\File') === true) {
$this->__set($object->id(), $object);
}
@@ -76,7 +75,7 @@ class Files extends Collection
* Creates a files collection from an array of props
*
* @param array $files
* @param Kirby\Cms\Model $parent
* @param \Kirby\Cms\Model $parent
* @param array $inject
* @return self
*/
@@ -102,7 +101,7 @@ class Files extends Collection
* Tries to find a file by id/filename
*
* @param string $id
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function findById(string $id)
{
@@ -115,7 +114,7 @@ class Files extends Collection
* map the get method correctly.
*
* @param string $key
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function findByKey(string $key)
{

View File

@@ -45,7 +45,7 @@ class Form extends BaseForm
}
/**
* @param Kirby\Cms\Model $model
* @param \Kirby\Cms\Model $model
* @param array $props
* @return self
*/

View File

@@ -15,25 +15,24 @@ use Kirby\Toolkit\Str;
*/
trait HasChildren
{
/**
* The Pages collection
*
* @var Kirby\Cms\Pages
* @var \Kirby\Cms\Pages
*/
public $children;
/**
* The list of available drafts
*
* @var Kirby\Cms\Pages
* @var \Kirby\Cms\Pages
*/
public $drafts;
/**
* Returns the Pages collection
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function children()
{
@@ -47,7 +46,7 @@ trait HasChildren
/**
* Returns all children and drafts at the same time
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function childrenAndDrafts()
{
@@ -69,7 +68,7 @@ trait HasChildren
* Searches for a child draft by id
*
* @param string $path
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function draft(string $path)
{
@@ -102,7 +101,7 @@ trait HasChildren
/**
* Return all drafts of the model
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function drafts()
{
@@ -127,7 +126,7 @@ trait HasChildren
* Finds one or multiple children by id
*
* @param string ...$arguments
* @return Kirby\Cms\Page|Kirby\Cms\Pages
* @return \Kirby\Cms\Page|\Kirby\Cms\Pages
*/
public function find(...$arguments)
{
@@ -137,7 +136,8 @@ trait HasChildren
/**
* Finds a single page or draft
*
* @return Kirby\Cms\Page|null
* @param string $path
* @return \Kirby\Cms\Page|null
*/
public function findPageOrDraft(string $path)
{
@@ -147,7 +147,7 @@ trait HasChildren
/**
* Returns a collection of all children of children
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function grandChildren()
{
@@ -216,7 +216,7 @@ trait HasChildren
* Creates a flat child index
*
* @param bool $drafts
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function index(bool $drafts = false)
{

View File

@@ -13,18 +13,17 @@ namespace Kirby\Cms;
*/
trait HasFiles
{
/**
* The Files collection
*
* @var Kirby\Cms\Files
* @var \Kirby\Cms\Files
*/
protected $files;
/**
* Filters the Files collection by type audio
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function audio()
{
@@ -34,7 +33,7 @@ trait HasFiles
/**
* Filters the Files collection by type code
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function code()
{
@@ -56,7 +55,7 @@ trait HasFiles
* Creates a new file
*
* @param array $props
* @return Kirby\Cms\File
* @return \Kirby\Cms\File
*/
public function createFile(array $props)
{
@@ -71,7 +70,7 @@ trait HasFiles
/**
* Filters the Files collection by type documents
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function documents()
{
@@ -83,7 +82,7 @@ trait HasFiles
*
* @param string $filename
* @param string $in
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function file(string $filename = null, string $in = 'files')
{
@@ -108,7 +107,7 @@ trait HasFiles
/**
* Returns the Files collection
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function files()
{
@@ -183,7 +182,7 @@ trait HasFiles
* Returns a specific image by filename or the first one
*
* @param string $filename
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function image(string $filename = null)
{
@@ -193,7 +192,7 @@ trait HasFiles
/**
* Filters the Files collection by type image
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function images()
{
@@ -203,7 +202,7 @@ trait HasFiles
/**
* Sets the Files collection
*
* @param Kirby\Cms\Files|null $files
* @param \Kirby\Cms\Files|null $files
* @return self
*/
protected function setFiles(array $files = null)
@@ -218,7 +217,7 @@ trait HasFiles
/**
* Filters the Files collection by type videos
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function videos()
{

View File

@@ -13,7 +13,6 @@ namespace Kirby\Cms;
*/
trait HasMethods
{
/**
* All registered methods
*

View File

@@ -14,7 +14,6 @@ namespace Kirby\Cms;
*/
trait HasSiblings
{
/**
* Returns the position / index in the collection
*
@@ -28,7 +27,7 @@ trait HasSiblings
/**
* Returns the next item in the collection if available
*
* @return Kirby\Cms\Model|null
* @return \Kirby\Cms\Model|null
*/
public function next()
{
@@ -38,7 +37,7 @@ trait HasSiblings
/**
* Returns the end of the collection starting after the current item
*
* @return Kirby\Cms\Collection
* @return \Kirby\Cms\Collection
*/
public function nextAll()
{
@@ -48,7 +47,7 @@ trait HasSiblings
/**
* Returns the previous item in the collection if available
*
* @return Kirby\Cms\Model|null
* @return \Kirby\Cms\Model|null
*/
public function prev()
{
@@ -58,7 +57,7 @@ trait HasSiblings
/**
* Returns the beginning of the collection before the current item
*
* @return Kirby\Cms\Collection
* @return \Kirby\Cms\Collection
*/
public function prevAll()
{
@@ -69,7 +68,7 @@ trait HasSiblings
* Returns all sibling elements
*
* @param bool $self
* @return Kirby\Cms\Collection
* @return \Kirby\Cms\Collection
*/
public function siblings(bool $self = true)
{
@@ -125,6 +124,7 @@ trait HasSiblings
/**
* Checks if the item is at a certain position
*
* @param int $n
* @return bool
*/
public function isNth(int $n): bool

View File

@@ -16,7 +16,6 @@ namespace Kirby\Cms;
*/
class Ingredients
{
/**
* @var array
*/
@@ -49,7 +48,7 @@ class Ingredients
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->ingredients;
}

View File

@@ -14,7 +14,6 @@ namespace Kirby\Cms;
*/
class KirbyTag extends \Kirby\Text\KirbyTag
{
/**
* Finds a file for the given path.
* The method first searches the file
@@ -22,7 +21,7 @@ class KirbyTag extends \Kirby\Text\KirbyTag
* Afterwards it uses Kirby's global file finder.
*
* @param string $path
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function file(string $path)
{
@@ -32,7 +31,7 @@ class KirbyTag extends \Kirby\Text\KirbyTag
return $file;
}
if (is_a($parent, File::class) === true && $file = $parent->page()->file($path)) {
if (is_a($parent, 'Kirby\Cms\File') === true && $file = $parent->page()->file($path)) {
return $file;
}
@@ -42,7 +41,7 @@ class KirbyTag extends \Kirby\Text\KirbyTag
/**
* Returns the current Kirby instance
*
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
public function kirby()
{
@@ -52,7 +51,7 @@ class KirbyTag extends \Kirby\Text\KirbyTag
/**
* Returns the parent model
*
* @return Kirby\Cms\Model|null
* @return \Kirby\Cms\Model|null
*/
public function parent()
{

View File

@@ -14,13 +14,12 @@ namespace Kirby\Cms;
*/
class KirbyTags extends \Kirby\Text\KirbyTags
{
/**
* The KirbyTag rendering class
*
* @var string
*/
protected static $tagClass = KirbyTag::class;
protected static $tagClass = 'Kirby\Cms\KirbyTag';
/**
* @param string $text

View File

@@ -3,7 +3,6 @@
namespace Kirby\Cms;
use Kirby\Data\Data;
use Kirby\Exception\DuplicateException;
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\PermissionException;
@@ -29,7 +28,6 @@ use Throwable;
*/
class Language extends Model
{
/**
* @var string
*/
@@ -97,7 +95,7 @@ class Language extends Model
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->toArray();
}
@@ -230,6 +228,7 @@ class Language extends Model
* When the language is deleted, all content files with
* the language code must be removed as well.
*
* @param mixed $code
* @return bool
*/
protected function deleteContentFiles($code): bool
@@ -355,7 +354,7 @@ class Language extends Model
* which is used to handle language specific
* routes.
*
* @return Kirby\Cms\LanguageRouter
* @return \Kirby\Cms\LanguageRouter
*/
public function router()
{
@@ -480,7 +479,7 @@ class Language extends Model
}
/**
* @param array $slug
* @param array $slugs
* @return self
*/
protected function setSlugs(array $slugs = null)

View File

@@ -20,7 +20,6 @@ use Kirby\Toolkit\Str;
*/
class LanguageRouter
{
/**
* The parent language
*
@@ -39,7 +38,7 @@ class LanguageRouter
* Creates a new language router instance
* for the given language
*
* @param Kirby\Cms\Language $language
* @param \Kirby\Cms\Language $language
*/
public function __construct(Language $language)
{

View File

@@ -4,8 +4,6 @@ namespace Kirby\Cms;
use Kirby\Exception\DuplicateException;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\LogicException;
use Kirby\Exception\PermissionException;
use Kirby\Toolkit\Str;
/**

View File

@@ -16,7 +16,6 @@ use Kirby\Toolkit\F;
*/
class Languages extends Collection
{
/**
* Creates a new collection with the given language objects
*
@@ -51,7 +50,7 @@ class Languages extends Collection
*
* @internal
* @param array $props
* @return Kirby\Cms\Language
* @return \Kirby\Cms\Language
*/
public function create(array $props)
{
@@ -61,7 +60,7 @@ class Languages extends Collection
/**
* Returns the default language
*
* @return Kirby\Cms\Language|null
* @return \Kirby\Cms\Language|null
*/
public function default()
{
@@ -74,7 +73,7 @@ class Languages extends Collection
/**
* @deprecated 3.0.0 Use `Languages::default()`instead
* @return Kirby\Cms\Language|null
* @return \Kirby\Cms\Language|null
*/
public function findDefault()
{

View File

@@ -19,15 +19,14 @@ use Throwable;
*/
class Media
{
/**
* Tries to find a file by model and filename
* and to copy it to the media folder.
*
* @param Kirby\Cms\Model $model
* @param \Kirby\Cms\Model $model
* @param string $hash
* @param string $filename
* @return Kirby\Cms\Response|false
* @return \Kirby\Cms\Response|false
*/
public static function link(Model $model = null, string $hash, string $filename)
{
@@ -80,10 +79,10 @@ class Media
* given filename and then calls the thumb
* component to create a thumbnail accordingly
*
* @param Kirby\Cms\Model $model
* @param \Kirby\Cms\Model $model
* @param string $hash
* @param string $filename
* @return Kirby\Cms\Response|false
* @return \Kirby\Cms\Response|false
*/
public static function thumb($model, string $hash, string $filename)
{

View File

@@ -20,14 +20,14 @@ abstract class Model
/**
* The parent Kirby instance
*
* @var Kirby\Cms\App
* @var \Kirby\Cms\App
*/
public static $kirby;
/**
* The parent site instance
*
* @var Kirby\Cms\Site
* @var \Kirby\Cms\Site
*/
protected $site;
@@ -55,7 +55,7 @@ abstract class Model
/**
* Returns the parent Kirby instance
*
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
public function kirby()
{
@@ -65,7 +65,7 @@ abstract class Model
/**
* Returns the parent Site instance
*
* @return Kirby\Cms\Site
* @return \Kirby\Cms\Site
*/
public function site()
{
@@ -75,7 +75,7 @@ abstract class Model
/**
* Setter for the parent Kirby object
*
* @param Kirby\Cms\App|null $kirby
* @param \Kirby\Cms\App|null $kirby
* @return self
*/
protected function setKirby(App $kirby = null)
@@ -88,7 +88,7 @@ abstract class Model
* Setter for the parent site object
*
* @internal
* @param Kirby\Cms\Site|null $site
* @param \Kirby\Cms\Site|null $site
* @return self
*/
public function setSite(Site $site = null)

View File

@@ -39,7 +39,7 @@ abstract class ModelPermissions
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->toArray();
}

View File

@@ -19,23 +19,22 @@ use Throwable;
*/
abstract class ModelWithContent extends Model
{
/**
* The content
*
* @var Kirby\Cms\Content
* @var \Kirby\Cms\Content
*/
public $content;
/**
* @var Kirby\Cms\Translations
* @var \Kirby\Cms\Translations
*/
public $translations;
/**
* Returns the blueprint of the model
*
* @return Kirby\Cms\Blueprint
* @return \Kirby\Cms\Blueprint
*/
abstract public function blueprint();
@@ -53,7 +52,7 @@ abstract class ModelWithContent extends Model
* Returns the content
*
* @param string $languageCode
* @return Kirby\Cms\Content
* @return \Kirby\Cms\Content
*/
public function content(string $languageCode = null)
{
@@ -263,13 +262,17 @@ abstract class ModelWithContent extends Model
* Only if a content directory exists,
* virtual pages will need to overwrite this method
*
* @return Kirby\Cms\ContentLock|null
* @return \Kirby\Cms\ContentLock|null
*/
public function lock()
{
$dir = $this->contentFileDirectory();
if (is_string($dir) === true && file_exists($dir) === true) {
if (
$this->kirby()->option('content.locking', true) &&
is_string($dir) === true &&
file_exists($dir) === true
) {
return new ContentLock($this);
}
}
@@ -360,19 +363,19 @@ abstract class ModelWithContent extends Model
*
* @internal
* @param string|null $query
* @return Kirby\Cms\File|Kirby\Cms\Asset|null
* @return \Kirby\Cms\File|\Kirby\Cms\Asset|null
*/
protected function panelImageSource(string $query = null)
{
$image = $this->query($query ?? null);
// validate the query result
if (is_a($image, File::class) === false && is_a($image, Asset::class) === false) {
if (is_a($image, 'Kirby\Cms\File') === false && is_a($image, 'Kirby\Cms\Asset') === false) {
$image = null;
}
// fallback for files
if ($image === null && is_a($this, File::class) === true && $this->isViewable() === true) {
if ($image === null && is_a($this, 'Kirby\Cms\File') === true && $this->isViewable() === true) {
$image = $this;
}
@@ -395,7 +398,7 @@ abstract class ModelWithContent extends Model
$result = Str::query($query, [
'kirby' => $this->kirby(),
'site' => is_a($this, Site::class) ? $this : $this->site(),
'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(),
static::CLASS_ALIAS => $this
]);
@@ -488,8 +491,22 @@ abstract class ModelWithContent extends Model
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
}
// merge the translation with the new data
$translation->update($data, $overwrite);
// get the content to store
$content = $translation->update($data, $overwrite)->content();
$kirby = $this->kirby();
$languageCode = $kirby->languageCode($languageCode);
// remove all untranslatable fields
if ($languageCode !== $kirby->defaultLanguage()->code()) {
foreach ($this->blueprint()->fields() as $field) {
if (($field['translate'] ?? true) === false) {
$content[$field['name']] = null;
}
}
// merge the translation with the new data
$translation->update($content, true);
}
// send the full translation array to the writer
$clone->writeContent($translation->content(), $languageCode);
@@ -526,7 +543,7 @@ abstract class ModelWithContent extends Model
protected function setTranslations(array $translations = null)
{
if ($translations !== null) {
$this->translations = new Collection;
$this->translations = new Collection();
foreach ($translations as $props) {
$props['parent'] = $this;
@@ -552,7 +569,7 @@ abstract class ModelWithContent extends Model
$result = Str::template($template, [
'kirby' => $this->kirby(),
'site' => is_a($this, Site::class) ? $this : $this->site(),
'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(),
static::CLASS_ALIAS => $this
]);
@@ -564,7 +581,7 @@ abstract class ModelWithContent extends Model
* If no code is specified the current translation is returned
*
* @param string|null $languageCode
* @return Kirby\Cms\ContentTranslation|null
* @return \Kirby\Cms\ContentTranslation|null
*/
public function translation(string $languageCode = null)
{
@@ -574,7 +591,7 @@ abstract class ModelWithContent extends Model
/**
* Returns the translations collection
*
* @return Kirby\Cms\Collection
* @return \Kirby\Cms\Collection
*/
public function translations()
{
@@ -582,7 +599,7 @@ abstract class ModelWithContent extends Model
return $this->translations;
}
$this->translations = new Collection;
$this->translations = new Collection();
foreach ($this->kirby()->languages() as $language) {
$translation = new ContentTranslation([
@@ -623,7 +640,13 @@ abstract class ModelWithContent extends Model
}
return $this->commit('update', [$this, $form->data(), $form->strings(), $languageCode], function ($model, $values, $strings, $languageCode) {
return $model->save($strings, $languageCode, true);
// save updated values
$model = $model->save($strings, $languageCode, true);
// update model in siblings collection
$model->siblings()->add($model);
return $model;
});
}

View File

@@ -16,7 +16,6 @@ use Kirby\Toolkit\Collection as BaseCollection;
*/
class NestCollection extends BaseCollection
{
/**
* Converts all objects in the collection
* to an array. This can also take a callback

View File

@@ -15,7 +15,6 @@ use Kirby\Toolkit\Obj;
*/
class NestObject extends Obj
{
/**
* Converts the object to an array
*

View File

@@ -49,7 +49,7 @@ class Page extends ModelWithContent
/**
* The PageBlueprint object
*
* @var Kirby\Cms\PageBlueprint
* @var \Kirby\Cms\PageBlueprint
*/
protected $blueprint;
@@ -92,7 +92,7 @@ class Page extends ModelWithContent
* The template, that should be loaded
* if it exists
*
* @var Kirby\Cms\Template
* @var \Kirby\Cms\Template
*/
protected $intendedTemplate;
@@ -111,7 +111,7 @@ class Page extends ModelWithContent
/**
* The parent page
*
* @var Kirby\Cms\Page|null
* @var \Kirby\Cms\Page|null
*/
protected $parent;
@@ -125,7 +125,7 @@ class Page extends ModelWithContent
/**
* The parent Site object
*
* @var Kirby\Cms\Site|null
* @var \Kirby\Cms\Site|null
*/
protected $site;
@@ -154,7 +154,7 @@ class Page extends ModelWithContent
* Magic caller
*
* @param string $method
* @param array $args
* @param array $arguments
* @return mixed
*/
public function __call(string $method, array $arguments = [])
@@ -192,7 +192,7 @@ class Page extends ModelWithContent
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return array_merge($this->toArray(), [
'content' => $this->content(),
@@ -222,7 +222,7 @@ class Page extends ModelWithContent
/**
* Returns the blueprint object
*
* @return Kirby\Cms\PageBlueprint
* @return \Kirby\Cms\PageBlueprint
*/
public function blueprint()
{
@@ -236,6 +236,7 @@ class Page extends ModelWithContent
/**
* Returns an array with all blueprints that are available for the page
*
* @param string $inSection
* @return array
*/
public function blueprints(string $inSection = null): array
@@ -300,6 +301,8 @@ class Page extends ModelWithContent
* Prepares the content for the write method
*
* @internal
* @param array $data
* @param string $languageCode
* @return array
*/
public function contentFileData(array $data, string $languageCode = null): array
@@ -405,15 +408,20 @@ class Page extends ModelWithContent
* gets dragged onto a textarea
*
* @internal
* @param string $type (auto|kirbytext|markdown)
* @return string
*/
public function dragText($type = 'kirbytext'): string
public function dragText(string $type = 'auto'): string
{
if ($type === 'auto') {
$type = option('panel.kirbytext', true) ? 'kirbytext' : 'markdown';
}
switch ($type) {
case 'kirbytext':
return '(link: ' . $this->id() . ' text: ' . $this->title() . ')';
case 'markdown':
return '[' . $this->title() . '](' . $this->url() . ')';
default:
return '(link: ' . $this->id() . ' text: ' . $this->title() . ')';
}
}
@@ -432,6 +440,7 @@ class Page extends ModelWithContent
* takes page models into account.
*
* @internal
* @param mixed $props
* @return self
*/
public static function factory($props)
@@ -477,7 +486,7 @@ class Page extends ModelWithContent
* Returns the template that should be
* loaded if it exists.
*
* @return Kirby\Cms\Template
* @return \Kirby\Cms\Template
*/
public function intendedTemplate()
{
@@ -514,12 +523,12 @@ class Page extends ModelWithContent
/**
* Compares the current object with the given page object
*
* @param Kirby\Cms\Page|string $page
* @param \Kirby\Cms\Page|string $page
* @return bool
*/
public function is($page): bool
{
if (is_a($page, Page::class) === false) {
if (is_a($page, 'Kirby\Cms\Page') === false) {
if (is_string($page) === false) {
return false;
}
@@ -527,7 +536,7 @@ class Page extends ModelWithContent
$page = $this->kirby()->page($page);
}
if (is_a($page, Page::class) === false) {
if (is_a($page, 'Kirby\Cms\Page') === false) {
return false;
}
@@ -553,6 +562,7 @@ class Page extends ModelWithContent
/**
* Checks if the page is a direct or indirect ancestor of the given $page object
*
* @param Page $child
* @return boolean
*/
public function isAncestorOf(Page $child): bool
@@ -617,7 +627,7 @@ class Page extends ModelWithContent
/**
* Checks if the page is a child of the given page
*
* @param Kirby\Cms\Page|string $parent
* @param \Kirby\Cms\Page|string $parent
* @return boolean
*/
public function isChildOf($parent): bool
@@ -632,7 +642,7 @@ class Page extends ModelWithContent
/**
* Checks if the page is a descendant of the given page
*
* @param Kirby\Cms\Page|string $parent
* @param \Kirby\Cms\Page|string $parent
* @return boolean
*/
public function isDescendantOf($parent): bool
@@ -920,7 +930,7 @@ class Page extends ModelWithContent
*
* @internal
* @param string|null $query
* @return Kirby\Cms\File|Kirby\Cms\Asset|null
* @return \Kirby\Cms\File|\Kirby\Cms\Asset|null
*/
protected function panelImageSource(string $query = null)
{
@@ -972,6 +982,7 @@ class Page extends ModelWithContent
* in the panel
*
* @internal
* @param bool $relative
* @return string
*/
public function panelUrl(bool $relative = false): string
@@ -986,7 +997,7 @@ class Page extends ModelWithContent
/**
* Returns the parent Page object
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function parent()
{
@@ -1014,7 +1025,7 @@ class Page extends ModelWithContent
* or the Site
*
* @internal
* @return Kirby\Cms\Page|Kirby\Cms\Site
* @return \Kirby\Cms\Page|\Kirby\Cms\Site
*/
public function parentModel()
{
@@ -1024,11 +1035,11 @@ class Page extends ModelWithContent
/**
* Returns a list of all parents and their parents recursively
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function parents()
{
$parents = new Pages;
$parents = new Pages();
$page = $this->parent();
while ($page !== null) {
@@ -1042,7 +1053,7 @@ class Page extends ModelWithContent
/**
* Returns the permissions object for this page
*
* @return Kirby\Cms\PagePermissions
* @return \Kirby\Cms\PagePermissions
*/
public function permissions()
{
@@ -1146,7 +1157,8 @@ class Page extends ModelWithContent
/**
* @internal
* @return Kirby\Cms\Template
* @param mixed $type
* @return \Kirby\Cms\Template
*/
public function representation($type)
{
@@ -1177,7 +1189,7 @@ class Page extends ModelWithContent
* which is being used in various methods
* to check for valid actions and input.
*
* @return Kirby\Cms\PageRules
* @return \Kirby\Cms\PageRules
*/
protected function rules()
{
@@ -1189,7 +1201,7 @@ class Page extends ModelWithContent
*
* @param string $query
* @param array $params
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function search(string $query = null, $params = [])
{
@@ -1246,14 +1258,14 @@ class Page extends ModelWithContent
*/
protected function setNum(int $num = null)
{
$this->num = $num === null ? $num : intval($num);
$this->num = $num === null ? $num : (int)$num;
return $this;
}
/**
* Sets the parent page object
*
* @param Kirby\Cms\Page|null $parent
* @param \Kirby\Cms\Page|null $parent
* @return self
*/
protected function setParent(Page $parent = null)
@@ -1360,7 +1372,7 @@ class Page extends ModelWithContent
/**
* Returns the final template
*
* @return Kirby\Cms\Template
* @return \Kirby\Cms\Template
*/
public function template()
{
@@ -1380,7 +1392,7 @@ class Page extends ModelWithContent
/**
* Returns the title field or the slug as fallback
*
* @return Kirby\Cms\Field
* @return \Kirby\Cms\Field
*/
public function title()
{

View File

@@ -23,7 +23,6 @@ use Kirby\Toolkit\Str;
*/
trait PageActions
{
/**
* Changes the sorting number
* The sorting number must already be correct
@@ -69,7 +68,7 @@ trait PageActions
* Changes the slug/uid of the page
*
* @param string $slug
* @param string $language
* @param string $languageCode
* @return self
*/
public function changeSlug(string $slug, string $languageCode = null)
@@ -101,13 +100,18 @@ trait PageActions
if ($oldPage->exists() === true) {
// remove the lock of the old page
$oldPage->lock()->remove();
if ($lock = $oldPage->lock()) {
$lock->remove();
}
// actually move stuff on disk
if (Dir::move($oldPage->root(), $newPage->root()) !== true) {
throw new LogicException('The page directory cannot be moved');
}
// remove from the siblings
$oldPage->parentModel()->children()->remove($oldPage);
Dir::remove($oldPage->mediaRoot());
}
@@ -126,7 +130,7 @@ trait PageActions
* Change the slug for a specific language
*
* @param string $slug
* @param string $language
* @param string $languageCode
* @return self
*/
protected function changeSlugForLanguage(string $slug, string $languageCode = null)
@@ -175,7 +179,7 @@ trait PageActions
protected function changeStatusToDraft()
{
$page = $this->commit('changeStatus', [$this, 'draft'], function ($page) {
$page = $this->commit('changeStatus', [$this, 'draft', null], function ($page) {
return $page->unpublish();
});
@@ -216,7 +220,7 @@ trait PageActions
return $this;
}
$page = $this->commit('changeStatus', [$this, 'unlisted'], function ($page) {
$page = $this->commit('changeStatus', [$this, 'unlisted', null], function ($page) {
return $page->publish()->changeNum(null);
});
@@ -295,7 +299,8 @@ trait PageActions
* 5. returns the result
*
* @param string $action
* @param mixed ...$arguments
* @param array $arguments
* @param Closure $callback
* @return mixed
*/
protected function commit(string $action, array $arguments, Closure $callback)
@@ -314,7 +319,7 @@ trait PageActions
* Copies the page to a new parent
*
* @param array $options
* @return Kirby\Cms\Page
* @return \Kirby\Cms\Page
*/
public function copy(array $options = [])
{
@@ -370,6 +375,13 @@ trait PageActions
}
}
// add copy to siblings
if ($isDraft === true) {
$parentModel->drafts()->append($copy->id(), $copy);
} else {
$parentModel->children()->append($copy->id(), $copy);
}
return $copy;
}
@@ -500,7 +512,7 @@ trait PageActions
'site' => $this->site(),
]);
return intval($template);
return (int)$template;
}
}
@@ -561,7 +573,7 @@ trait PageActions
*
* @param string $slug
* @param array $options
* @return Kirby\Cms\Page
* @return \Kirby\Cms\Page
*/
public function duplicate(string $slug = null, array $options = [])
{

View File

@@ -13,7 +13,6 @@ namespace Kirby\Cms;
*/
class PageBlueprint extends Blueprint
{
/**
* Creates a new page blueprint object
* with the given props

View File

@@ -13,7 +13,6 @@ namespace Kirby\Cms;
*/
trait PageSiblings
{
/**
* @deprecated 3.0.0 Use `Page::hasNextUnlisted` instead
* @return boolean
@@ -106,7 +105,7 @@ trait PageSiblings
/**
* Returns the next listed page if it exists
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function nextListed()
{
@@ -116,7 +115,7 @@ trait PageSiblings
/**
* Returns the next unlisted page if it exists
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function nextUnlisted()
{
@@ -144,7 +143,7 @@ trait PageSiblings
/**
* Returns the previous listed page
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function prevListed()
{
@@ -154,7 +153,7 @@ trait PageSiblings
/**
* Returns the previous unlisted page
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function prevUnlisted()
{
@@ -173,7 +172,7 @@ trait PageSiblings
/**
* Private siblings collector
*
* @return Kirby\Cms\Collection
* @return \Kirby\Cms\Collection
*/
protected function siblingsCollection()
{
@@ -188,7 +187,7 @@ trait PageSiblings
* Returns siblings with the same template
*
* @param bool $self
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function templateSiblings(bool $self = true)
{

View File

@@ -20,11 +20,10 @@ namespace Kirby\Cms;
*/
class Pages extends Collection
{
/**
* Cache for the index
*
* @var Kirby\Cms\Pages|null
* @var \Kirby\Cms\Pages|null
*/
protected $index = null;
@@ -40,7 +39,7 @@ class Pages extends Collection
* an entire second collection to the
* current collection
*
* @param mixed $item
* @param mixed $object
* @return self
*/
public function add($object)
@@ -54,7 +53,7 @@ class Pages extends Collection
$this->__set($page->id(), $page);
// add a page object
} elseif (is_a($object, Page::class) === true) {
} elseif (is_a($object, 'Kirby\Cms\Page') === true) {
$this->__set($object->id(), $object);
}
@@ -64,17 +63,17 @@ class Pages extends Collection
/**
* Returns all audio files of all children
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function audio()
{
return $this->files()->filterBy("type", "audio");
return $this->files()->filterBy('type', 'audio');
}
/**
* Returns all children for each page in the array
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function children()
{
@@ -92,27 +91,27 @@ class Pages extends Collection
/**
* Returns all code files of all children
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function code()
{
return $this->files()->filterBy("type", "code");
return $this->files()->filterBy('type', 'code');
}
/**
* Returns all documents of all children
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function documents()
{
return $this->files()->filterBy("type", "document");
return $this->files()->filterBy('type', 'document');
}
/**
* Fetch all drafts for all pages in the collection
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function drafts()
{
@@ -131,8 +130,7 @@ class Pages extends Collection
* Creates a pages collection from an array of props
*
* @param array $pages
* @param Kirby\Cms\Model $parent
* @param array $inject
* @param \Kirby\Cms\Model $model
* @param bool $draft
* @return self
*/
@@ -167,7 +165,7 @@ class Pages extends Collection
/**
* Returns all files of all children
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function files()
{
@@ -271,7 +269,7 @@ class Pages extends Collection
* Alias for Pages::findById
*
* @param string $id
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function findByUri(string $id)
{
@@ -281,7 +279,7 @@ class Pages extends Collection
/**
* Finds the currently open page
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function findOpen()
{
@@ -293,7 +291,8 @@ class Pages extends Collection
* extension pages
*
* @param string $key
* @return Kirby\Cms\Page|null
* @param mixed $default
* @return \Kirby\Cms\Page|null
*/
public function get($key, $default = null)
{
@@ -311,11 +310,11 @@ class Pages extends Collection
/**
* Returns all images of all children
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function images()
{
return $this->files()->filterBy("type", "image");
return $this->files()->filterBy('type', 'image');
}
/**
@@ -323,7 +322,7 @@ class Pages extends Collection
* pages and subpages, etc.
*
* @param bool $drafts
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function index(bool $drafts = false)
{
@@ -357,7 +356,7 @@ class Pages extends Collection
/**
* Returns all listed pages in the collection
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function listed()
{
@@ -367,7 +366,7 @@ class Pages extends Collection
/**
* Returns all unlisted pages in the collection
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function unlisted()
{
@@ -377,6 +376,7 @@ class Pages extends Collection
/**
* Include all given items in the collection
*
* @param mixed ...$args
* @return self
*/
public function merge(...$args)
@@ -441,7 +441,7 @@ class Pages extends Collection
/*
* Returns all listed and unlisted pages in the collection
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function published()
{
@@ -452,7 +452,7 @@ class Pages extends Collection
* Filter all pages by the given template
*
* @param string|array $templates
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function template($templates)
{
@@ -472,17 +472,17 @@ class Pages extends Collection
/**
* Returns all video files of all children
*
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public function videos()
{
return $this->files()->filterBy("type", "video");
return $this->files()->filterBy('type', 'video');
}
/**
* Deprecated alias for Pages::listed()
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function visible()
{

View File

@@ -22,7 +22,6 @@ use Kirby\Toolkit\Pagination as BasePagination;
*/
class Pagination extends BasePagination
{
/**
* Pagination method (param or query)
*

View File

@@ -24,12 +24,29 @@ use Throwable;
*/
class Panel
{
public static function customCss(App $kirby)
{
if ($css = $kirby->option('panel.css')) {
$asset = asset($css);
if ($asset->exists() === true) {
return $asset->url() . '?' . $asset->modified();
}
}
return false;
}
public static function icons(App $kirby): string
{
return F::read($kirby->root('kirby') . '/panel/dist/img/icons.svg');
}
/**
* Links all dist files in the media folder
* and returns the link to the requested asset
*
* @param Kirby\Cms\App $kirby
* @param \Kirby\Cms\App $kirby
* @return bool
*/
public static function link(App $kirby): bool
@@ -61,8 +78,8 @@ class Panel
/**
* Renders the main panel view
*
* @param Kirby\Cms\App $kirby
* @return Kirby\Cms\Response
* @param \Kirby\Cms\App $kirby
* @return \Kirby\Cms\Response
*/
public static function render(App $kirby)
{
@@ -85,19 +102,20 @@ class Panel
'kirby' => $kirby,
'config' => $kirby->option('panel'),
'assetUrl' => $kirby->url('media') . '/panel/' . $kirby->versionHash(),
'customCss' => static::customCss($kirby),
'icons' => static::icons($kirby),
'pluginCss' => $plugins->url('css'),
'pluginJs' => $plugins->url('js'),
'icons' => F::read($kirby->root('panel') . '/dist/img/icons.svg'),
'panelUrl' => $uri->path()->toString(true) . '/',
'options' => [
'url' => $url,
'site' => $kirby->url('index'),
'api' => $kirby->url('api'),
'csrf' => $kirby->option('api')['csrf'] ?? csrf(),
'csrf' => $kirby->option('api.csrf') ?? csrf(),
'translation' => 'en',
'debug' => $kirby->option('debug', false),
'search' => [
'limit' => $kirby->option('panel')['search']['limit'] ?? 10
'limit' => $kirby->option('panel.search.limit') ?? 10
]
]
]);

View File

@@ -2,7 +2,6 @@
namespace Kirby\Cms;
use Kirby\Toolkit\Dir;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Str;
@@ -19,7 +18,6 @@ use Kirby\Toolkit\Str;
*/
class PanelPlugins
{
/**
* Cache of all collected plugin files
*

View File

@@ -54,7 +54,7 @@ class PluginAssets
*
* @param string $pluginName
* @param string $filename
* @return Kirby\Cms\Response|null
* @return \Kirby\Cms\Response|null
*/
public static function resolve(string $pluginName, string $filename)
{

View File

@@ -2,7 +2,6 @@
namespace Kirby\Cms;
use Kirby\Http\Request;
use Kirby\Toolkit\Facade;
/**
@@ -17,7 +16,7 @@ use Kirby\Toolkit\Facade;
class R extends Facade
{
/**
* @return Kirby\Cms\Request
* @return \Kirby\Http\Request
*/
public static function instance()
{

View File

@@ -16,7 +16,6 @@ use Kirby\Toolkit\Str;
*/
class Responder
{
/**
* HTTP status code
*
@@ -174,7 +173,7 @@ class Responder
* Creates and returns the response object from the config
*
* @param string|null $body
* @return Kirby\Cms\Response
* @return \Kirby\Cms\Response
*/
public function send(string $body = null)
{

View File

@@ -14,7 +14,6 @@ namespace Kirby\Cms;
*/
class Response extends \Kirby\Http\Response
{
/**
* Adjusted redirect creation which
* parses locations with the Url::to method

View File

@@ -34,7 +34,7 @@ class Role extends Model
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->toArray();
}
@@ -133,7 +133,7 @@ class Role extends Model
}
/**
* @return Kirby\Cms\Permissions
* @return \Kirby\Cms\Permissions
*/
public function permissions()
{

View File

@@ -20,6 +20,51 @@ use Kirby\Toolkit\Dir;
*/
class Roles extends Collection
{
/**
* Returns a filtered list of all
* roles that can be created by the
* current user
*
* @return self
*/
public function canBeChanged()
{
if ($user = App::instance()->user()) {
return $this->filter(function ($role) use ($user) {
$newUser = new User([
'email' => 'test@getkirby.com',
'role' => $role->id()
]);
return $newUser->permissions()->can('changeRole');
});
}
return $this;
}
/**
* Returns a filtered list of all
* roles that can be created by the
* current user
*
* @return self
*/
public function canBeCreated()
{
if ($user = App::instance()->user()) {
return $this->filter(function ($role) use ($user) {
$newUser = new User([
'email' => 'test@getkirby.com',
'role' => $role->id()
]);
return $newUser->permissions()->can('create');
});
}
return $this;
}
/**
* @param array $roles
@@ -28,7 +73,7 @@ class Roles extends Collection
*/
public static function factory(array $roles, array $inject = [])
{
$collection = new static;
$collection = new static();
// read all user blueprints
foreach ($roles as $props) {
@@ -52,7 +97,7 @@ class Roles extends Collection
*/
public static function load(string $root = null, array $inject = [])
{
$roles = new static;
$roles = new static();
// load roles from plugins
foreach (App::instance()->extensions('blueprints') as $blueprintName => $blueprint) {

View File

@@ -17,7 +17,7 @@ use Kirby\Toolkit\Facade;
class S extends Facade
{
/**
* @return Kirby\Session\Session
* @return \Kirby\Session\Session
*/
public static function instance()
{

View File

@@ -18,11 +18,10 @@ use Kirby\Toolkit\Str;
*/
class Search
{
/**
* @param string $query
* @param array $params
* @return Kirby\Cms\Files
* @return \Kirby\Cms\Files
*/
public static function files(string $query = null, $params = [])
{
@@ -31,6 +30,10 @@ class Search
/**
* Native search method to search for anything within the collection
*
* @param Collection $collection
* @param string $query
* @param mixed $params
*/
public static function collection(Collection $collection, string $query = null, $params = [])
{
@@ -69,10 +72,10 @@ class Search
$keys = array_keys($data);
$keys[] = 'id';
if (is_a($item, User::class) === true) {
if (is_a($item, 'Kirby\Cms\User') === true) {
$keys[] = 'email';
$keys[] = 'role';
} elseif (is_a($item, Page::class) === true) {
} elseif (is_a($item, 'Kirby\Cms\Page') === true) {
// apply the default score for pages
$options['score'] = array_merge([
'id' => 64,
@@ -126,7 +129,7 @@ class Search
/**
* @param string $query
* @param array $params
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public static function pages(string $query = null, $params = [])
{
@@ -136,7 +139,7 @@ class Search
/**
* @param string $query
* @param array $params
* @return Kirby\Cms\Users
* @return \Kirby\Cms\Users
*/
public static function users(string $query = null, $params = [])
{

View File

@@ -16,7 +16,6 @@ use Kirby\Toolkit\Component;
*/
class Section extends Component
{
/**
* Registry for all component mixins
*
@@ -46,7 +45,7 @@ class Section extends Component
}
/**
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
public function kirby()
{
@@ -54,7 +53,7 @@ class Section extends Component
}
/**
* @return Kirby\Cms\Model
* @return \Kirby\Cms\Model
*/
public function model()
{

View File

@@ -5,7 +5,6 @@ namespace Kirby\Cms;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\LogicException;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Str;
/**
* The `$site` object is the root element
@@ -132,7 +131,7 @@ class Site extends ModelWithContent
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return array_merge($this->toArray(), [
'content' => $this->content(),
@@ -160,7 +159,7 @@ class Site extends ModelWithContent
/**
* Returns the blueprint object
*
* @return Kirby\Cms\SiteBlueprint
* @return \Kirby\Cms\SiteBlueprint
*/
public function blueprint()
{
@@ -175,7 +174,7 @@ class Site extends ModelWithContent
* Returns an array with all blueprints that are available
* as subpages of the site
*
* @params string $inSection
* @param string $inSection
* @return array
*/
public function blueprints(string $inSection = null): array
@@ -200,7 +199,7 @@ class Site extends ModelWithContent
/**
* Builds a breadcrumb collection
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function breadcrumb()
{
@@ -220,6 +219,8 @@ class Site extends ModelWithContent
* Prepares the content for the write method
*
* @internal
* @param array $data
* @param string $languageCode
* @return array
*/
public function contentFileData(array $data, string $languageCode = null): array
@@ -243,7 +244,7 @@ class Site extends ModelWithContent
/**
* Returns the error page object
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function errorPage()
{
@@ -282,7 +283,7 @@ class Site extends ModelWithContent
/**
* Returns the home page object
*
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function homePage()
{
@@ -339,7 +340,7 @@ class Site extends ModelWithContent
*/
public function is($site): bool
{
if (is_a($site, Site::class) === false) {
if (is_a($site, 'Kirby\Cms\Site') === false) {
return false;
}
@@ -391,7 +392,7 @@ class Site extends ModelWithContent
* it can be found. (see `Site::homePage()`)
*
* @param string $path
* @return Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|null
*/
public function page(string $path = null)
{
@@ -413,7 +414,7 @@ class Site extends ModelWithContent
/**
* Alias for `Site::children()`
*
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function pages()
{
@@ -451,7 +452,7 @@ class Site extends ModelWithContent
/**
* Returns the permissions object for this site
*
* @return Kirby\Cms\SitePermissions
* @return \Kirby\Cms\SitePermissions
*/
public function permissions()
{
@@ -496,7 +497,7 @@ class Site extends ModelWithContent
* which is being used in various methods
* to check for valid actions and input.
*
* @return Kirby\Cms\SiteRules
* @return \Kirby\Cms\SiteRules
*/
protected function rules()
{
@@ -508,7 +509,7 @@ class Site extends ModelWithContent
*
* @param string $query
* @param array $params
* @return Kirby\Cms\Pages
* @return \Kirby\Cms\Pages
*/
public function search(string $query = null, $params = [])
{
@@ -565,7 +566,7 @@ class Site extends ModelWithContent
* Sets the current page object
*
* @internal
* @param Kirby\Cms\Page|null $page
* @param \Kirby\Cms\Page|null $page
* @return self
*/
public function setPage(Page $page = null)
@@ -644,9 +645,9 @@ class Site extends ModelWithContent
* returns the current page
*
* @internal
* @param string|Kirby\Cms\Page $page
* @param string|\Kirby\Cms\Page $page
* @param string|null $languageCode
* @return Kirby\Cms\Page
* @return \Kirby\Cms\Page
*/
public function visit($page, string $languageCode = null)
{
@@ -677,6 +678,7 @@ class Site extends ModelWithContent
* modified after the given unix timestamp
* This is mainly used to auto-update the cache
*
* @param mixed $time
* @return bool
*/
public function wasModifiedAfter($time): bool

View File

@@ -15,7 +15,6 @@ use Closure;
*/
trait SiteActions
{
/**
* Commits a site action, by following these steps
*
@@ -27,6 +26,7 @@ trait SiteActions
*
* @param string $action
* @param mixed ...$arguments
* @param Closure $callback
* @return mixed
*/
protected function commit(string $action, array $arguments, Closure $callback)
@@ -60,7 +60,7 @@ trait SiteActions
* Creates a main page
*
* @param array $props
* @return Kirby\Cms\Page
* @return \Kirby\Cms\Page
*/
public function createChild(array $props)
{

View File

@@ -2,6 +2,8 @@
namespace Kirby\Cms;
use Kirby\Exception\InvalidArgumentException;
/**
* The Structure class wraps
* array data into a nicely chainable
@@ -18,7 +20,6 @@ namespace Kirby\Cms;
*/
class Structure extends Collection
{
/**
* Creates a new Collection with the given objects
*
@@ -38,13 +39,17 @@ class Structure extends Collection
* StructureObjects
*
* @param string $id
* @param array|StructureObject $object
* @param array|StructureObject $props
*/
public function __set(string $id, $props)
{
if (is_a($props, StructureObject::class) === true) {
if (is_a($props, 'Kirby\Cms\StructureObject') === true) {
$object = $props;
} else {
if (is_array($props) === false) {
throw new InvalidArgumentException('Invalid structure data');
}
$object = new StructureObject([
'content' => $props,
'id' => $props['id'] ?? $id,

View File

@@ -77,7 +77,7 @@ class StructureObject extends Model
/**
* Returns the content
*
* @return Kirby\Cms\Content
* @return \Kirby\Cms\Content
*/
public function content()
{
@@ -110,7 +110,7 @@ class StructureObject extends Model
*/
public function is($structure): bool
{
if (is_a($structure, StructureObject::class) === false) {
if (is_a($structure, 'Kirby\Cms\StructureObject') === false) {
return false;
}
@@ -120,7 +120,7 @@ class StructureObject extends Model
/**
* Returns the parent Model object
*
* @return Kirby\Cms\Model
* @return \Kirby\Cms\Model
*/
public function parent()
{
@@ -158,7 +158,7 @@ class StructureObject extends Model
* Sets the parent Model. This can either be a
* Page, Site, File or User object
*
* @param Kirby\Cms\Model|null $parent
* @param \Kirby\Cms\Model|null $parent
* @return self
*/
protected function setParent(Model $parent = null)
@@ -170,7 +170,7 @@ class StructureObject extends Model
/**
* Sets the parent Structure collection
*
* @param Kirby\Cms\Structure $structure
* @param \Kirby\Cms\Structure $structure
* @return self
*/
protected function setStructure(Structure $structure = null)
@@ -182,7 +182,7 @@ class StructureObject extends Model
/**
* Returns the parent Structure collection as siblings
*
* @return Kirby\Cms\Structure
* @return \Kirby\Cms\Structure
*/
protected function siblingsCollection()
{

View File

@@ -2,7 +2,6 @@
namespace Kirby\Cms;
use Throwable;
use Kirby\Data\Json;
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
@@ -14,6 +13,7 @@ use Kirby\Toolkit\Dir;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Str;
use Kirby\Toolkit\V;
use Throwable;
/**
* The System class gathers all information
@@ -31,14 +31,13 @@ use Kirby\Toolkit\V;
*/
class System
{
/**
* @var App
*/
protected $app;
/**
* @param Kirby\Cms\App $app
* @param \Kirby\Cms\App $app
*/
public function __construct(App $app)
{
@@ -53,7 +52,7 @@ class System
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->toArray();
}
@@ -138,20 +137,21 @@ class System
*/
public function init()
{
/* /site/accounts */
// init /site/accounts
try {
Dir::make($this->app->root('accounts'));
} catch (Throwable $e) {
throw new PermissionException('The accounts directory could not be created');
}
/* /content */
// init /content
try {
Dir::make($this->app->root('content'));
} catch (Throwable $e) {
throw new PermissionException('The content directory could not be created');
}
// init /media
try {
Dir::make($this->app->root('media'));
} catch (Throwable $e) {

View File

@@ -18,7 +18,6 @@ use Kirby\Toolkit\Tpl;
*/
class Template
{
/**
* Global template data
*
@@ -126,7 +125,7 @@ class Template
// Try the default template in the default template directory.
return F::realpath($this->root() . '/' . $this->name() . '.' . $this->extension(), $this->root());
} catch (Exception $e) {
//
// ignore errors, continue searching
}
// Look for the default template provided by an extension.

View File

@@ -42,7 +42,7 @@ class Translation
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return $this->toArray();
}

View File

@@ -35,7 +35,7 @@ class Translations extends Collection
*/
public static function factory(array $translations)
{
$collection = new static;
$collection = new static();
foreach ($translations as $code => $props) {
$translation = new Translation($code, $props);
@@ -52,7 +52,7 @@ class Translations extends Collection
*/
public static function load(string $root, array $inject = [])
{
$collection = new static;
$collection = new static();
foreach (Dir::read($root) as $filename) {
if (F::extension($filename) !== 'json') {

View File

@@ -140,7 +140,7 @@ class User extends ModelWithContent
*
* @return array
*/
public function __debuginfo(): array
public function __debugInfo(): array
{
return array_merge($this->toArray(), [
'avatar' => $this->avatar(),
@@ -168,7 +168,7 @@ class User extends ModelWithContent
/**
* Returns the File object for the avatar or null
*
* @return Kirby\Cms\File|null
* @return \Kirby\Cms\File|null
*/
public function avatar()
{
@@ -178,7 +178,7 @@ class User extends ModelWithContent
/**
* Returns the UserBlueprint object
*
* @return Kirby\Cms\UserBlueprint
* @return \Kirby\Cms\UserBlueprint
*/
public function blueprint()
{
@@ -260,6 +260,7 @@ class User extends ModelWithContent
* takes User models into account.
*
* @internal
* @param mixed $props
* @return self
*/
public static function factory($props)
@@ -326,7 +327,7 @@ class User extends ModelWithContent
/**
* Compares the current object with the given user object
*
* @param Kirby\Cms\User|null $user
* @param \Kirby\Cms\User|null $user
* @return bool
*/
public function is(User $user = null): bool
@@ -404,7 +405,7 @@ class User extends ModelWithContent
* Logs the user in
*
* @param string $password
* @param Kirby\Session\Session|array $session Session options or session object to set the user in
* @param \Kirby\Session\Session|array $session Session options or session object to set the user in
* @return bool
*
* @throws PermissionException If the password is not valid
@@ -420,7 +421,7 @@ class User extends ModelWithContent
/**
* Logs the user in without checking the password
*
* @param Kirby\Session\Session|array $session Session options or session object to set the user in
* @param \Kirby\Session\Session|array $session Session options or session object to set the user in
* @return void
*/
public function loginPasswordless($session = null): void
@@ -434,7 +435,7 @@ class User extends ModelWithContent
/**
* Logs the user out
*
* @param Kirby\Session\Session|array $session Session options or session object to unset the user in
* @param \Kirby\Session\Session|array $session Session options or session object to unset the user in
* @return void
*/
public function logout($session = null): void
@@ -480,7 +481,7 @@ class User extends ModelWithContent
* @internal
* @param string $name
* @param array $props
* @return Kirby\Cms\User
* @return \Kirby\Cms\User
*/
public static function model(string $name, array $props = [])
{
@@ -515,7 +516,7 @@ class User extends ModelWithContent
/**
* Returns the user's name
*
* @return Kirby\Cms\Field
* @return \Kirby\Cms\Field
*/
public function name()
{
@@ -563,7 +564,7 @@ class User extends ModelWithContent
*
* @internal
* @param string|null $query
* @return Kirby\Cms\File|Kirby\Cms\Asset|null
* @return \Kirby\Cms\File|\Kirby\Cms\Asset|null
*/
protected function panelImageSource(string $query = null)
{
@@ -640,7 +641,7 @@ class User extends ModelWithContent
}
/**
* @return Kirby\Cms\UserPermissions
* @return \Kirby\Cms\UserPermissions
*/
public function permissions()
{
@@ -650,7 +651,7 @@ class User extends ModelWithContent
/**
* Returns the user role
*
* @return Kirby\Cms\Role
* @return \Kirby\Cms\Role
*/
public function role()
{
@@ -681,7 +682,7 @@ class User extends ModelWithContent
* Returns the UserRules class to
* validate any important action.
*
* @return Kirby\Cms\UserRules
* @return \Kirby\Cms\UserRules
*/
protected function rules()
{
@@ -781,8 +782,8 @@ class User extends ModelWithContent
/**
* Converts session options into a session object
*
* @param Kirby\Session\Session|array $session Session options or session object to unset the user in
* @return Kirby\Session\Session
* @param \Kirby\Session\Session|array $session Session options or session object to unset the user in
* @return \Kirby\Session\Session
*/
protected function sessionFromOptions($session)
{
@@ -799,7 +800,7 @@ class User extends ModelWithContent
/**
* Returns the parent Users collection
*
* @return Kirby\Cms\Users
* @return \Kirby\Cms\Users
*/
protected function siblingsCollection()
{

View File

@@ -21,7 +21,6 @@ use Kirby\Toolkit\Str;
*/
trait UserActions
{
/**
* Changes the user email address
*
@@ -158,7 +157,7 @@ trait UserActions
/**
* Creates a new User from the given props and returns a new User object
*
* @param array $input
* @param array $props
* @return self
*/
public static function create(array $props = null)
@@ -199,6 +198,9 @@ trait UserActions
$languageCode = null;
}
// add the user to users collection
$user->kirby()->users()->add($user);
// write the user data
return $user->save($user->content()->toArray(), $languageCode);
});
@@ -242,6 +244,9 @@ trait UserActions
throw new LogicException('The user directory for "' . $user->email() . '" could not be deleted');
}
// remove the user from users collection
$user->kirby()->users()->remove($user);
return true;
});
}
@@ -287,6 +292,7 @@ trait UserActions
/**
* Writes the account information to disk
*
* @param array $credentials
* @return boolean
*/
protected function writeCredentials(array $credentials): bool

View File

@@ -25,6 +25,11 @@ class UserPermissions extends ModelPermissions
protected function canChangeRole(): bool
{
// only one role, makes no sense to change it
if ($this->user->kirby()->roles()->count() < 2) {
return false;
}
// users who are not admins cannot change their own role
if ($this->user->is($this->model) === true && $this->user->isAdmin() === false) {
return false;
@@ -33,6 +38,21 @@ class UserPermissions extends ModelPermissions
return $this->model->isLastAdmin() !== true;
}
protected function canCreate(): bool
{
// the admin can always create new users
if ($this->user->isAdmin() === true) {
return true;
}
// users who are not admins cannot create admins
if ($this->model->isAdmin() === true) {
return false;
}
return true;
}
protected function canDelete(): bool
{
return $this->model->isLastAdmin() !== true;

View File

@@ -70,13 +70,27 @@ class UserRules
public static function changeRole(User $user, string $role): bool
{
if ($user->kirby()->user()->isAdmin() === false) {
// protect admin from role changes by non-admin
if (
$user->kirby()->user()->isAdmin() === false &&
$user->isAdmin() === true
) {
throw new PermissionException([
'key' => 'user.changeRole.permission',
'data' => ['name' => $user->username()]
]);
}
// prevent non-admins making a user to admin
if (
$user->kirby()->user()->isAdmin() === false &&
$role === 'admin'
) {
throw new PermissionException([
'key' => 'user.changeRole.toAdmin'
]);
}
static::validRole($user, $role);
if ($role !== 'admin' && $user->isLastAdmin() === true) {
@@ -101,23 +115,29 @@ class UserRules
static::validId($user, $user->id());
static::validEmail($user, $user->email(), true);
static::validLanguage($user, $user->language());
// only admins are allowed to add admins
$role = $props['role'] ?? null;
if (empty($props['password']) === false) {
static::validPassword($user, $props['password']);
}
// get the current user if it exists
$currentUser = $user->kirby()->user();
// admins are allowed everything
if ($currentUser && $currentUser->isAdmin() === true) {
return true;
}
// only admins are allowed to add admins
$role = $props['role'] ?? null;
if ($role === 'admin' && $currentUser && $currentUser->isAdmin() === false) {
throw new PermissionException([
'key' => 'user.create.permission'
]);
}
if (empty($props['password']) === false) {
static::validPassword($user, $props['password']);
}
// check user permissions (if not on install)
if ($user->kirby()->users()->count() > 0) {
if ($user->permissions()->create() !== true) {
throw new PermissionException([

View File

@@ -19,7 +19,6 @@ use Kirby\Toolkit\Str;
*/
class Users extends Collection
{
/**
* All registered users methods
*
@@ -37,7 +36,7 @@ class Users extends Collection
* an entire second collection to the
* current collection
*
* @param mixed $item
* @param mixed $object
* @return self
*/
public function add($object)
@@ -51,7 +50,7 @@ class Users extends Collection
$this->__set($user->id(), $user);
// add a user object
} elseif (is_a($object, User::class) === true) {
} elseif (is_a($object, 'Kirby\Cms\User') === true) {
$this->__set($object->id(), $object);
}
@@ -67,7 +66,7 @@ class Users extends Collection
*/
public static function factory(array $users, array $inject = [])
{
$collection = new static;
$collection = new static();
// read all user blueprints
foreach ($users as $props) {
@@ -82,7 +81,7 @@ class Users extends Collection
* Finds a user in the collection by id or email address
*
* @param string $key
* @return Kirby\Cms\User|null
* @return \Kirby\Cms\User|null
*/
public function findByKey(string $key)
{
@@ -102,7 +101,7 @@ class Users extends Collection
*/
public static function load(string $root, array $inject = [])
{
$users = new static;
$users = new static();
foreach (Dir::read($root) as $userDirectory) {
if (is_dir($root . '/' . $userDirectory) === false) {

View File

@@ -16,7 +16,7 @@ use Kirby\Toolkit\Facade;
class Visitor extends Facade
{
/**
* @return Kirby\Http\Visitor
* @return \Kirby\Http\Visitor
*/
public static function instance()
{

View File

@@ -24,7 +24,6 @@ use Kirby\Toolkit\F;
*/
class Data
{
/**
* Handler Type Aliases
*
@@ -52,7 +51,7 @@ class Data
* Handler getter
*
* @param string $type
* @return Kirby\Data\Handler
* @return \Kirby\Data\Handler
*/
public static function handler(string $type)
{
@@ -65,7 +64,7 @@ class Data
null;
if (class_exists($handler)) {
return new $handler;
return new $handler();
}
throw new Exception('Missing handler for type: "' . $type . '"');

View File

@@ -18,7 +18,6 @@ use Kirby\Toolkit\F;
*/
abstract class Handler
{
/**
* Parses an encoded string and returns a multi-dimensional array
*
@@ -55,6 +54,7 @@ abstract class Handler
/**
* Writes data to a file
*
* @param string $file
* @param array $data
* @return boolean
*/

View File

@@ -15,7 +15,6 @@ use Exception;
*/
class Json extends Handler
{
/**
* Converts an array to an encoded JSON string
*
@@ -24,13 +23,13 @@ class Json extends Handler
*/
public static function encode($data): string
{
return json_encode($data);
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
/**
* Parses an encoded JSON string and returns a multi-dimensional array
*
* @param string $string
* @param string $json
* @return array
*/
public static function decode($json): array

View File

@@ -16,7 +16,6 @@ use Kirby\Toolkit\F;
*/
class PHP extends Handler
{
/**
* Converts an array to PHP file content
*
@@ -35,7 +34,7 @@ class PHP extends Handler
$array[] = "$indent " . ($indexed ? '' : static::encode($key) . ' => ') . static::encode($value, "$indent ");
}
return "[\n" . implode(",\n", $array) . "\n" . $indent . "]";
return "[\n" . implode(",\n", $array) . "\n" . $indent . ']';
case 'boolean':
return $data ? 'true' : 'false';
case 'int':
@@ -75,6 +74,7 @@ class PHP extends Handler
/**
* Creates a PHP file with the given data
*
* @param string $file
* @param array $data
* @return boolean
*/

View File

@@ -15,7 +15,6 @@ use Kirby\Toolkit\Str;
*/
class Txt extends Handler
{
/**
* Converts an array to an encoded Kirby txt string
*

View File

@@ -16,7 +16,6 @@ use Spyc;
*/
class Yaml extends Handler
{
/**
* Converts an array to an encoded YAML string
*
@@ -43,7 +42,7 @@ class Yaml extends Handler
/**
* Parses an encoded YAML string and returns a multi-dimensional array
*
* @param string $string
* @param string $yaml
* @return array
*/
public static function decode($yaml): array

View File

@@ -21,7 +21,6 @@ use Throwable;
*/
class Database
{
/**
* The number of affected rows for the last query
*
@@ -180,7 +179,7 @@ class Database
* Connects to a database
*
* @param array|null $params This can either be a config key or an array of parameters for the connection
* @return Kirby\Database\Database
* @return \Kirby\Database\Database
*/
public function connect(array $params = null)
{
@@ -223,7 +222,7 @@ class Database
/**
* Returns the currently active connection
*
* @return Kirby\Database\Database|null
* @return \Kirby\Database\Database|null
*/
public function connection()
{
@@ -234,7 +233,7 @@ class Database
* Sets the exception mode for the next query
*
* @param boolean $fail
* @return Kirby\Database\Database
* @return \Kirby\Database\Database
*/
public function fail(bool $fail = true)
{
@@ -467,7 +466,7 @@ class Database
* Returns the correct Sql generator instance
* for the type of database
*
* @return Kirby\Database\Sql
* @return \Kirby\Database\Sql
*/
public function sql()
{
@@ -481,7 +480,7 @@ class Database
* for that table
*
* @param string $table
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function table(string $table)
{
@@ -579,6 +578,9 @@ class Database
* Magic way to start queries for tables by
* using a method named like the table.
* I.e. $db->users()->all()
*
* @param mixed $method
* @param mixed $arguments
*/
public function __call($method, $arguments = null)
{

View File

@@ -36,7 +36,7 @@ class Db
* (Re)connect the database
*
* @param array $params Pass [] to use the default params from the config
* @return Kirby\Database\Database
* @return \Kirby\Database\Database
*/
public static function connect(array $params = null)
{
@@ -61,7 +61,7 @@ class Db
/**
* Returns the current database connection
*
* @return Kirby\Database\Database
* @return \Kirby\Database\Database
*/
public static function connection()
{
@@ -74,7 +74,7 @@ class Db
* that table.
*
* @param string $table
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public static function table($table)
{
@@ -177,12 +177,12 @@ Db::$queries['column'] = function (string $table, string $column, $where = null,
};
/**
* Shortcut for inserting a new row into a table
*
* @param string $table The name of the table, which should be queried
* @param array $values An array of values, which should be inserted
* @return boolean
*/
* Shortcut for inserting a new row into a table
*
* @param string $table The name of the table, which should be queried
* @param array $values An array of values, which should be inserted
* @return bool
*/
Db::$queries['insert'] = function (string $table, array $values) {
return Db::table($table)->insert($values);
};
@@ -193,7 +193,7 @@ Db::$queries['insert'] = function (string $table, array $values) {
* @param string $table The name of the table, which should be queried
* @param array $values An array of values, which should be inserted
* @param mixed $where An optional where clause
* @return boolean
* @return bool
*/
Db::$queries['update'] = function (string $table, array $values, $where = null) {
return Db::table($table)->where($where)->update($values);
@@ -204,7 +204,7 @@ Db::$queries['update'] = function (string $table, array $values, $where = null)
*
* @param string $table The name of the table, which should be queried
* @param mixed $where An optional where clause
* @return boolean
* @return bool
*/
Db::$queries['delete'] = function (string $table, $where = null) {
return Db::table($table)->where($where)->delete();

View File

@@ -150,7 +150,7 @@ class Query
/**
* Constructor
*
* @param Kirby\Database\Database $database Database object
* @param \Kirby\Database\Database $database Database object
* @param string $table Optional name of the table, which should be queried
*/
public function __construct(Database $database, string $table)
@@ -185,7 +185,7 @@ class Query
* the query instead of actually executing the query and returning results
*
* @param boolean $debug
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function debug(bool $debug = true)
{
@@ -197,7 +197,7 @@ class Query
* Enables distinct select clauses.
*
* @param boolean $distinct
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function distinct(bool $distinct = true)
{
@@ -210,7 +210,7 @@ class Query
* If enabled queries will no longer fail silently but throw an exception
*
* @param boolean $fail
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function fail(bool $fail = true)
{
@@ -223,7 +223,7 @@ class Query
* Set this to array to get a simple array instead of an object
*
* @param string $fetch
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function fetch(string $fetch)
{
@@ -236,7 +236,7 @@ class Query
* Set this to array to get a simple array instead of an iterator object
*
* @param string $iterator
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function iterator(string $iterator)
{
@@ -245,11 +245,11 @@ class Query
}
/**
* Sets the name of the table, which should be queried
*
* @param string $table
* @return Kirby\Database\Query
*/
* Sets the name of the table, which should be queried
*
* @param string $table
* @return \Kirby\Database\Query
*/
public function table(string $table)
{
if ($this->database->validateTable($table) === false) {
@@ -264,7 +264,7 @@ class Query
* Sets the name of the primary key column
*
* @param string $primaryKeyName
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function primaryKeyName(string $primaryKeyName)
{
@@ -277,7 +277,7 @@ class Query
* By default all columns will be selected
*
* @param mixed $select Pass either a string of columns or an array
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function select($select)
{
@@ -310,7 +310,7 @@ class Query
*
* @param string $table Name of the table, which should be joined
* @param string $on The on clause for this join
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function leftJoin(string $table, string $on)
{
@@ -322,7 +322,7 @@ class Query
*
* @param string $table Name of the table, which should be joined
* @param string $on The on clause for this join
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function rightJoin(string $table, string $on)
{
@@ -334,7 +334,7 @@ class Query
*
* @param string $table Name of the table, which should be joined
* @param string $on The on clause for this join
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function innerJoin($table, $on)
{
@@ -345,7 +345,7 @@ class Query
* Sets the values which should be used for the update or insert clause
*
* @param mixed $values Can either be a string or an array of values
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function values($values = [])
{
@@ -383,8 +383,8 @@ class Query
* ->where('username like ?', 'myuser') (args: 2)
* ->where('username', 'like', 'myuser'); (args: 3)
*
* @param list
* @return Kirby\Database\Query
* @param mixed ...$args
* @return \Kirby\Database\Query
*/
public function where(...$args)
{
@@ -396,8 +396,8 @@ class Query
* Shortcut to attach a where clause with an OR operator.
* Check out the where() method docs for additional info.
*
* @param list
* @return Kirby\Database\Query
* @param mixed ...$args
* @return \Kirby\Database\Query
*/
public function orWhere(...$args)
{
@@ -420,8 +420,8 @@ class Query
* Shortcut to attach a where clause with an AND operator.
* Check out the where() method docs for additional info.
*
* @param list
* @return Kirby\Database\Query
* @param mixed ...$args
* @return \Kirby\Database\Query
*/
public function andWhere(...$args)
{
@@ -441,11 +441,11 @@ class Query
}
/**
* Attaches a group by clause
*
* @param string $group
* @return Kirby\Database\Query
*/
* Attaches a group by clause
*
* @param string $group
* @return \Kirby\Database\Query
*/
public function group(string $group = null)
{
$this->group = $group;
@@ -463,8 +463,8 @@ class Query
* ->having('username like ?', 'myuser') (args: 2)
* ->having('username', 'like', 'myuser'); (args: 3)
*
* @param list
* @return Kirby\Database\Query
* @param mixed ...$args
* @return \Kirby\Database\Query
*/
public function having(...$args)
{
@@ -476,7 +476,7 @@ class Query
* Attaches an order clause
*
* @param string $order
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function order(string $order = null)
{
@@ -488,7 +488,7 @@ class Query
* Sets the offset for select clauses
*
* @param int $offset
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function offset(int $offset = null)
{
@@ -500,7 +500,7 @@ class Query
* Sets the limit for select clauses
*
* @param int $limit
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function limit(int $limit = null)
{
@@ -559,7 +559,7 @@ class Query
/**
* Builds a count query
*
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function count()
{
@@ -570,7 +570,7 @@ class Query
* Builds a max query
*
* @param string $column
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function max(string $column)
{
@@ -581,7 +581,7 @@ class Query
* Builds a min query
*
* @param string $column
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function min(string $column)
{
@@ -592,7 +592,7 @@ class Query
* Builds a sum query
*
* @param string $column
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function sum(string $column)
{
@@ -603,7 +603,7 @@ class Query
* Builds an average query
*
* @param string $column
* @return Kirby\Database\Query
* @return \Kirby\Database\Query
*/
public function avg(string $column)
{
@@ -815,7 +815,7 @@ class Query
$sql = $this->database->sql();
$primaryKey = $sql->combineIdentifier($this->table, $this->primaryKeyName);
$results = $this->query($this->select(array($column))->order($primaryKey . ' ASC')->build('select'), [
$results = $this->query($this->select([$column])->order($primaryKey . ' ASC')->build('select'), [
'iterator' => 'array',
'fetch' => 'array',
]);

View File

@@ -2,7 +2,6 @@
namespace Kirby\Database;
use Closure;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Str;
@@ -18,7 +17,6 @@ use Kirby\Toolkit\Str;
*/
class Sql
{
/**
* List of literals which should not be escaped in queries
*
@@ -36,7 +34,7 @@ class Sql
/**
* Constructor
*
* @param Kirby\Database\Database $database
* @param \Kirby\Database\Database $database
*/
public function __construct($database)
{
@@ -464,7 +462,7 @@ class Sql
/**
* Create the syntax for multiple joins
*
* @params array $joins
* @param array $joins
* @return array
*/
public function joins(array $joins = null): array
@@ -677,11 +675,11 @@ class Sql
switch (count($parts)) {
// non-qualified identifier
case 1:
return array($table, $this->unquoteIdentifier($parts[0]));
return [$table, $this->unquoteIdentifier($parts[0])];
// qualified identifier
case 2:
return array($this->unquoteIdentifier($parts[0]), $this->unquoteIdentifier($parts[1]));
return [$this->unquoteIdentifier($parts[0]), $this->unquoteIdentifier($parts[1])];
// every other number is an error
default:

View File

@@ -15,7 +15,6 @@ use Kirby\Database\Sql;
*/
class Sqlite extends Sql
{
/**
* Returns a list of columns for a specified table
* SQLite version

View File

@@ -14,7 +14,7 @@ use Kirby\Toolkit\Properties;
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
*/
class Body
{
use Properties;

View File

@@ -2,11 +2,10 @@
namespace Kirby\Email;
use Exception;
use Kirby\Toolkit\Properties;
use Kirby\Toolkit\V;
use Exception;
/**
* Wrapper for email libraries
*
@@ -16,7 +15,7 @@ use Exception;
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
*/
class Email
{
use Properties;
@@ -47,7 +46,7 @@ class Email
}
/**
* @return Kirby\Email\Body
* @return \Kirby\Email\Body
*/
public function body()
{

View File

@@ -13,7 +13,7 @@ use PHPMailer\PHPMailer\PHPMailer as Mailer;
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
*/
class PHPMailer extends Email
{
public function send(bool $debug = false): bool

View File

@@ -2,7 +2,6 @@
namespace Kirby\Exception;
use Kirby\Cms\App;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;

View File

@@ -3,7 +3,6 @@
namespace Kirby\Form;
use Exception;
use Kirby\Cms\App;
use Kirby\Cms\Model;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\Component;
@@ -23,7 +22,6 @@ use Kirby\Toolkit\V;
*/
class Field extends Component
{
/**
* Registry for all component mixins
*
@@ -51,6 +49,10 @@ class Field extends Component
throw new InvalidArgumentException('The field type "' . $type . '" does not exist');
}
if (isset($attrs['model']) === false) {
throw new InvalidArgumentException('Field requires a model');
}
// use the type as fallback for the name
$attrs['name'] = $attrs['name'] ?? $type;
$attrs['type'] = $type;
@@ -71,6 +73,7 @@ class Field extends Component
}
/**
* @param mixed $default
* @return mixed
*/
public function data($default = false)
@@ -177,6 +180,39 @@ class Field extends Component
'value' => function ($value = null) {
return $value;
}
],
'computed' => [
'after' => function () {
if ($this->after !== null) {
return $this->model()->toString($this->after);
}
},
'before' => function () {
if ($this->before !== null) {
return $this->model()->toString($this->before);
}
},
'default' => function () {
if ($this->default === null) {
return;
}
if (is_string($this->default) === false) {
return $this->default;
}
return $this->model()->toString($this->default);
},
'label' => function () {
if ($this->label !== null) {
return $this->model()->toString($this->label);
}
},
'placeholder' => function () {
if ($this->placeholder !== null) {
return $this->model()->toString($this->placeholder);
}
}
]
];
}
@@ -217,7 +253,7 @@ class Field extends Component
}
/**
* @return Kirby\Cms\App
* @return \Kirby\Cms\App
*/
public function kirby()
{

View File

@@ -16,14 +16,13 @@ use Kirby\Toolkit\Collection;
*/
class Fields extends Collection
{
/**
* Internal setter for each object in the Collection.
* This takes care of validation and of setting
* the collection prop on each object correctly.
*
* @param string $id
* @param object $object
* @param string $name
* @param object $field
*/
public function __set(string $name, $field)
{

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