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

3.x - Add locator #290

Merged
merged 11 commits into from
Jul 12, 2022
Merged

3.x - Add locator #290

merged 11 commits into from
Jul 12, 2022

Conversation

markstory
Copy link
Member

@markstory markstory commented Jul 10, 2022

Implement the LocatorInterface for this plugin. This has lead to IndexRegisty being deprecated as we can use the locator internally instead.

I've backported the docker-compose environment because I needed it for these changes too.

Fixes #288

$options += ['name' => Inflector::underscore($classAlias)];

if (empty($options['className'])) {
$options['className'] = Inflector::camelize($alias);
Copy link
Member

Choose a reason for hiding this comment

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

Why not add this to the += line above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! this is mostly copy/paste from the ORM locator.

[, $name] = pluginSplit($options['className']);
$options['name'] = Inflector::underscore($name);
}
$options['className'] = $this->fallbackClassName;
Copy link
Member

Choose a reason for hiding this comment

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

if className is being overwritten here, why do we use it in the if statement above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we only want to generate a fallback class if the inflected one does not exist. On line 86 we attempt to resolve the inflected/provided classname. If that class doesn't exist we end up here so we can use the fallbackClassName.

One potential design flaw is that allowFallbackClass isn't used at all in this logic. Should I add that behavior or remove the ability to disable fallbackClasses? I guess we could provide a fallback class that throws an error on construction if we wanted to provide a 'strict mode'.

I could be misunderstanding the question though.

Copy link
Member

Choose a reason for hiding this comment

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

Yea I was referring to the lack of the fallback in that logic

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll get that fixed up.

}

if (empty($options['connection'])) {
$connectionName = $options['className']::defaultConnectionName();
Copy link
Member

Choose a reason for hiding this comment

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

This is using a class name to call a static function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. This is also how the OrmLocator works as well.

@othercorey othercorey added this to the 3.x milestone Jul 10, 2022
@markstory markstory merged commit 76444aa into 3.x Jul 12, 2022
@markstory markstory deleted the add-locator branch July 12, 2022 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use LocatorInterface
2 participants