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

Rename binding types to "contracts" #201

Open
webmozart opened this issue Aug 16, 2016 · 4 comments
Open

Rename binding types to "contracts" #201

webmozart opened this issue Aug 16, 2016 · 4 comments

Comments

@webmozart
Copy link
Member

webmozart commented Aug 16, 2016

We currently use the term "binding type" for specifying the common denominator between modules providing "things" (resources, classes, user-defined) and modules consuming (or using) those things. That term unfortunately is quite abstract and not intuitive to grasp.

To borrow a term from software architecture, I would like to propose changing that term to "contract". Modules can define contracts and use any "thing" that satisfies that contract. Other modules can provide things satisfying the contract.

A contract is made up of three properties:

  • its globally unique name
  • the type of the things the contract expects ("resource", "class", user-defined)
  • optional: named parameters

The definition of contracts would look like this:

{
    "contracts": {
        "Vendor\\PluginInterface": {
            "require": "class",
            "parameters": {
                "foo": {
                    "default": "bar"
                }
            }
        },
        "vendor/translations-yml": "resource"
    }
}

When a module provides "things" satisfying the contract, that looks like this:

{
    "provide": {
        "Acme\\PluginA": "Vendor\\PluginInterface",
        "Acme\\PluginB": {
            "contract": "Vendor\\PluginInterface",
            "parameters": {
                "foo": "baz"
            }
        },
        "/acme/module/trans/*.yml": "vendor/translations-yml"
    }
}

I quite like that changed naming and think it is much easier to understand without explaining as much as we currently have to explain. If there are no major concerns, I'd like to tackle this change with beta12.

@webmozart webmozart added this to the 1.0-beta12 milestone Aug 16, 2016
@tgalopin
Copy link
Contributor

After seeing it written, it's really a good name :) .

@webmozart
Copy link
Member Author

webmozart commented Aug 16, 2016

In a later step, we can also add "constraints" to those contracts that can be defined for each "type". Example constraint for the "resource" type:

{
    "contracts": {
        "vendor/translations-yml": {
            "type": "resource",
            "constraints": {
                "extension": ".yml"
            }
        }
    }
}

The goal here is to document and enforce the specific constraints that the provided "things" must fulfill.

@tgalopin
Copy link
Contributor

What about an array of globs for constraints? It seems more powerful than a specific "extension" key.

@webmozart
Copy link
Member Author

Sure :) we can discuss this when we get there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants