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

Add Module bindings to Provider #320

Merged
merged 3 commits into from
Aug 19, 2024
Merged

Conversation

Chemaclass
Copy link
Member

📚 Description

Inspired by Laravel Provider bindings, you can also define global bindings on each module Provider

🔖 Changes

  • Enable defining custom bindings on module Provider level

For example:

final class Provider extends AbstractProvider
{
    /** @var array<class-string,class-string> */
    public array $bindings = [
        GreeterGeneratorInterface::class => CompanyGenerator::class,
    ];

    public function provideModuleDependencies(Container $container): void
    {
    }
}

See test BindingsInsideProvider for a full working example

@Chemaclass Chemaclass added the enhancement New feature or request label Aug 18, 2024
@Chemaclass Chemaclass self-assigned this Aug 18, 2024
@Chemaclass Chemaclass changed the title Add module bindings to setup Add Module bindings to Provider Aug 18, 2024
@Chemaclass Chemaclass merged commit 8155a45 into main Aug 19, 2024
13 checks passed
@Chemaclass Chemaclass deleted the feat/add-provider-bindings branch August 19, 2024 18:05
Comment on lines 21 to +26
use Gacela\Framework\Exception\GacelaNotBootstrappedException;

use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

use SplFileInfo;
Copy link
Member

Choose a reason for hiding this comment

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

There are some extra new lines on this file.

foreach ($iterator as $file) {
if ($file->getExtension() === 'php') {
$fileContents = (string)file_get_contents($file->getPathname());
if (preg_match('/namespace\s+([a-zA-Z0-9_\\\\]+)\s*;/', $fileContents, $matches) !== false) {
Copy link
Member

Choose a reason for hiding this comment

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

What if the file has no namespace on top BUT has some var (varName or varValue) that contains the keyword "namespace"?
Have you checked this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants