-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Adjust array definition format (+ some new features) #60
Comments
I like the general idea. But I have a question to the |
I've never heard "fluent call" before but from Wikipedia, a Fluent interface is more about method chaining, right? This does not necessarily imply immutability. But the use case here is for immutable objects that return a new instance of itself when a method is called. Would As a sidenote: all this new immutable stuff really needs good explanation (when to use it, when not, why ...) |
Yes, that's the point. |
Bootstrapping is not a scope of the container. |
Instead of list decorators it's better to set decorated service. The use case is decorating third party service and in this case it's definition not available. FYI, |
@xepozz I like the idea in general.
We already have this feature. Any method that returns the instance of the object is assumed to be a fluent interface call. It works well and I don't think we need a separate section for it. It fits pretty well into
Again, we already have such feature.
Currently it's done via separate container entry such as: MyInteface::class => ...,
'my-interface' => Reference::to(MyInterface::class), I'm not sure we need another syntax.
As @yiiliveext mentioned, bootstrapping isn't the job of the container. See yiisoft/app#76 |
@viktorprogger Yes. We do not control what's stored in the container and should not limit these object to be of a certain code style. |
@BoShurik I assume that's for the feature of automatically generating a lazy proxy class. Something similar to what we do in debug proxies: |
MyClass::class => [
'class' => MyClass::class,
'tags' => ['tag1', 'tag2'],
'construct' => [
'argument1',
'argument2',
'host' => 'host',
'...variadic' => ['val1', 'val2', 'val3'],
],
'call' => [
'method1' => 'val1',
'method2' => 'val2',
'method3' => 'val3',
// no need to differentiate fluent calls, we know how to detect these
'method4' => 'val4',
'method5' => 'val5',
'method6' => 'val6',
],
'properties' => [
'property1' => 'val1',
'property3' => 'val2',
],
'reset' => fn() => true,
'aliases' => ['aliased_name1', 'aliased_name2'],
'decorators' => [
Decorator1::class,
Decorator2::class,
Decorator3::class,
],
'lazy' => false,
] |
Also, consider having this complex definition as object: MyClass::class => ComplexDefinition::as([
'class' => MyClass::class,
'tags' => ['tag1', 'tag2'],
...
]); OR MyClass::class => ComplexDefinition::for(MyClass::class)
->tags(['tag1', 'tag2'])
->construct([...])
...
]); This will allow to develop and try it without breaking BC. |
BC is not a concern yet. There's no release. |
@samdark, about your proposal:
|
No, nothing changed. |
Your example with the |
|
properties are to be mentioned in the guide and also it could be useful if https://wiki.php.net/rfc/property_accessors will be accepted. The the comments about |
PR is mentioned above doesn't solve this issue. |
It did solve the issue. We have discussed many variants and came up with a good extendable syntax. |
Main mind
I suggest to group definition keys into by section:
class
(rename from__class
)constructor
tags
([RFC] Tags support di#125)calls
fluentCalls
(new feature)properties
(new feature)aliases
(new feature)decorators
([RFC] Support decorators di#149)lazy
([RFC] Support lazy services via ocramius/proxy-manager di#197)reset
(Ability to reset some definitions di#121)Constructor
,calls
andclass
already existing, but I don't the style of configuration.Now it looks like the following:
What's bad:
__class
key__construct()
key()
What's will:
class
keyconstructor
(orconstruct
, orarguments
)()
won't neededWhat's new:
fluentCalls
: new feature that means that methods will calls in fluent-like style:$newObject = $object->withProp($val)
properties
: new feature that means that any public (or any, need to think) properties also can be configured just as usual method callsaliases
: new feature that means that you can add alias to this definition to use short aliased name instead of full qualified class name (e.g.doctrine.em
instead of\Doctrine\Common\EntityManagerInterface
)lazy
: new feature that means that definition must be resolved even when the class is not used in an application (a.k.a. eager definition resolving). For example, it can be used when you need to make the bootstrapping an applicationFinal resullt
After all adjustments the definition can be looks like this:
The text was updated successfully, but these errors were encountered: