Giter Club home page Giter Club logo

Comments (8)

philipobenito avatar philipobenito commented on July 28, 2024 1

Hmm, I dunno, let me think on it for a day or so (a little busy today), my initial thoughts are that it's not a major change over my example above. Having reminded myself of the codebase, it would be fine as an addition to AbstractDefinition, we'd just need to add it to the interface on the next major version bump. I'm just not 100% sure on the semantics yet.

from container.

philipobenito avatar philipobenito commented on July 28, 2024

If I understand what you're trying to do then extend should already be able to do this?

from container.

nebulousGirl avatar nebulousGirl commented on July 28, 2024

No, because in the case of a factory closure, extend returns a CallableDefinition and it does not have any method that allows me to add another closure to extend it like in ClassDefinition with withMethodCall.

To resolve this problem, I can add a withCallback method to AbstractDefinition, I just want your opinion before I start working on it.

from container.

philipobenito avatar philipobenito commented on July 28, 2024

@nebulousGirl ah, I see what you mean. You could do this, seems a little like a work around but I think safer overall than enabling withMethodCall.

$container
    ->add('something', function ($methods = []) {
        $service = new Service;

        foreach ($methods as $method => $args) {
            call_user_func_array([$service, $method], $args);
            // you could even go a little further here and have the container resolve $args
        }

        return $service;
    })
;

$container->get('something'); // no methods invoked as none passed to the callable

$container
    ->extend('something')
    ->withArgument(new RawArgument([
        'methodName' => [/* args */],
        'anotherMethod' => [/* args */]
    ])
;

$container->get('something'); // methodName and anotherMethod both invoked

from container.

philipobenito avatar philipobenito commented on July 28, 2024

@nebulousGirl the problem with adding a method to AbstractDefinition is that it's flirting with a BC break if we want to keep interfaces up to date.

from container.

nebulousGirl avatar nebulousGirl commented on July 28, 2024

Would you prefer that I create a trait that is used both by CallableDefinition and ClassDefinition?

from container.

Anahkiasen avatar Anahkiasen commented on July 28, 2024

Any news on this one? Trying to make a decorator to support service-providers but I'm being blocked by the same issue :/

from container.

philipobenito avatar philipobenito commented on July 28, 2024

This is handled by 421d774 for release in 3.0.0.

You can now add method calls to any definition and it will attempt to invoke those methods if the end concrete is an object.

from container.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.