-
-
Notifications
You must be signed in to change notification settings - Fork 178
refactor!: Move field methods to Content\Field
#7082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v6/develop
Are you sure you want to change the base?
Conversation
55012fa
to
d02ec9c
Compare
Not relevant, comment was based on incorrect assumptionOne behavior change not listed in the TODO section for this PR: Currently, method access with
This means that currently it's possible to write A way to keep this backwards-compatible would be to have a mapping of public methods, then in class Field
{
private static $builtinMethods = [
'isvalid' => 'isValid',
'kirbytext' => 'kirbytext',
// …
];
public function __call(string $method, array $arguments = []): mixed
{
$method = strtolower($method);
if ($this->hasMethod($method) === true) {
return $this->callMethod($method, [clone $this, ...$arguments]);
} else if (isset(static::$builtinMethods[$method])) {
return $this->{static::$builtinMethods[$method]}(...$arguments);
} else {
// TODO: throw deprecation, then exception
// when unknown method is called
}
return $this;
}
} (Alternatively, some of that logic — or something a bit more elaborate — could move to the |
@fvsch this is not needed. PHP Methods are case insensitive by default. |
@bastianallgeier Ha! I did not know that. 😅 |
52f516b
to
500a8c8
Compare
f38c393
to
dd5605f
Compare
Content\Field
classContent\Field
Resolves #7078 BREAKING CHANGE: Removed `Kirby\Content\Field::$aliases`. BREAKING CHANGE: Removed `Kirby\Cms\Core::fieldMethods()` and `Kirby\Cms\Core::fieldMethodsAliases()`.
dd5605f
to
f62882f
Compare
Description
Todo
replace
method even though this is in the core. Change?Summary of changes
config/methods.php
intoKirby\Content\Field
classKirby\Content\Field::$aliases
array and instead added aliases as actual methods that call the main methodsField::value($value)
is now bound to the cloned new field objectCore::fieldMethods()
andCore::fieldMethodsAliases()
Reasoning
Allows IDEs etc. to actually "understand" field methods, their parameter and return type hints etc.
Changelog
Refactoring
Kirby\Content\Field
Breaking changes
Kirby\Exception\BadMethodCallException
Kirby\Content\Field::$aliases
Kirby\Cms\Core::fieldMethods()
andKirby\Cms\Core::fieldMethodsAliases()
Ready?
For review team