Skip to content
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

Convert hardcoded strings in demos to hintable fields #1559

Merged
merged 10 commits into from
Jan 20, 2021
Merged

Conversation

mvorisek
Copy link
Member

@mvorisek mvorisek commented Dec 4, 2020

Preface

The hintable support is another major game changer in sense of cleaness and maintainability. For now, adding it to demos only and it is up too every user to use it or not.

Description

Annotate model fields and used them magically as a real properties.

Usage

  1. add Model class phpdoc
  2. use the properties either as standard value property or supermagically for field names itself (see below)

standard ("value") property

$model->is_folder === $model->get('is_folder')
$model->is_folder = false === $model->set('is_folder', false)

  • shorter to type
  • refactorable
  • typed for static analysis

"name" property

$model->fieldName()->is_folder === 'is_folder'

  • refactorable name

@mvorisek mvorisek force-pushed the to_hintable branch 8 times, most recently from 7ff7e3e to 6eb73ae Compare December 4, 2020 22:20
@mvorisek
Copy link
Member Author

mvorisek commented Dec 7, 2020

@DarkSide666 @georgehristov @ibelar please review, very powerfull lib I released for atk4. For now, I am adding it as a dev dependency ie. for demos only

I will then adjust everything in demos to make it analyseable/typehintable/refactorable.

@romaninsh
Copy link
Member

romaninsh commented Dec 9, 2020

As pointed by others:
Screenshot 2020-12-09 at 10 06 42

Checking if we'll need to bundle it into our ZIP distribution....

Edit: looks like it is unspecified.

@romaninsh
Copy link
Member

romaninsh commented Dec 9, 2020

@mvorisek - I think this is fine but would be nice to have a bit more info in the readme file there just to understand what is that library doing and why is it needed:

https://github.com/mvorisek/atk4-hintable-mirror

Edit: found notes here, reading: https://github.com/mvorisek/atk4-hintable-mirror/blob/develop/src/Data/HintableModel.php#L14

@romaninsh
Copy link
Member

@mvorisek - why not bring magic properties natively into ATK Model ?

@georgehristov
Copy link
Collaborator

@mvorisek I would also suggest adding native trait \Atk4\Data\Model\HintableTrait

@mvorisek
Copy link
Member Author

mvorisek commented Dec 9, 2020

I think this is fine but would be nice to have a bit more info in the readme file there just to understand what is that library doing and why is it needed:

Edit: found notes here, reading: https://github.com/mvorisek/atk4-hintable-mirror/blob/develop/src/Data/HintableModel.php#L14

updated PR title

@mvorisek - why not bring magic properties natively into ATK Model ?

I need more control over this than waiting days until someone merge something. This is why I also removed the PRs for it a few months ago.

@mvorisek I would also suggest adding native trait \Atk4\Data\Model\HintableTrait

There are two issues with trait:

  • HintableModel can not be then specified as a type
    • I checked now, very minor issue as super well written and specifying this type does not bring any benefict for end user ;-)
  • Model::init method must be overrided
    • trait can NOT enforce it, see https://3v4l.org/MX9pm
    • user can alias a init method from trait or we can offer aliased method from trait directly
    • we can check if init() method from trait was called or not later, thus this should not be issue as well

So I can change the functionality to trait and offer it also under \Atk4\Data\Model\HintableTrait name.

If welcomed, I can add it also as atk4/data dep (so it does not have to be required in any other project) and possibly annotate Model id field in Model class phpdoc directly.

Copy link
Member

@DarkSide666 DarkSide666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mvorisek mvorisek force-pushed the to_hintable branch 5 times, most recently from cd8ff34 to f2cce7c Compare January 16, 2021 22:57
@ibelar
Copy link
Contributor

ibelar commented Jan 18, 2021

Is there a specific reason to prefix table field name using 'xxx' or 'yyy'? Why not using the table name instead like 'country_name', 'stats_name' etd?

@mvorisek
Copy link
Member Author

mvorisek commented Jan 18, 2021

Is there a specific reason to prefix table field name using 'xxx' or 'yyy'? Why not using the table name instead like 'country_name', 'stats_name' etd?

The reason I added is solely to identify direct usage of original/actual DB field names.

I have choosen xxx_ to be able to easily find it. I would merge and revert later once everything is replaced (I replaced only for classes in init-db.php).

Beatifulness addressed in atk4/data#831

@@ -234,7 +234,7 @@ protected function getPathWithAppVars(string $path): string

public function demoFilesProvider(): array
{
$excludeDirs = ['_demo-data', '_includes', '_unit-test', 'special'];
$excludeDirs = ['_demo-data', '_includes'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibelar FYI do not add anything else here, this is why #1586 was not caught by tests before

@@ -84,7 +84,7 @@ public function getQuery()
public function setModelCondition(Model $model): Model
{
if ($q = $this->getQuery()) {
$model->addCondition('name', 'like', '%' . $q . '%');
$model->addCondition($model->title_field, 'like', '%' . $q . '%');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was a bug

@mvorisek mvorisek merged commit 48e8190 into develop Jan 20, 2021
@mvorisek mvorisek deleted the to_hintable branch January 20, 2021 11:57
@mvorisek mvorisek restored the to_hintable branch January 20, 2021 13:30
@mvorisek mvorisek deleted the to_hintable branch January 20, 2021 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants