Giter Club home page Giter Club logo

Comments (14)

aydot avatar aydot commented on June 27, 2024

Also, the Injecting Dependencies in Controllers example code you have doesn't work for me. When I use the Piping::get('Classname'), it works. but when i inject the dependency, and put the annotation, it doesn't.

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

I'll take a look at this soon.

from piping-bag.

aydot avatar aydot commented on June 27, 2024

Had a chance to look at this yet ?

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

I can confirm the bug...

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

@aydot due to some changes I made earlier for performance, I had to change the way the plugin is installed. Check the new instructions https://github.com/lorenzo/piping-bag#configuration

In particular, you need to change

DispatcherFactory::add('ControllerFactory');

With the following:

use PipingBag\Di\PipingBag;
DispatcherFactory::add(PipingBag::get('PipingBag\Routing\Filter\ControllerFactoryFilter'));

from piping-bag.

aydot avatar aydot commented on June 27, 2024

the controller action injection still doesn't work for me

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

Tell me what you did, it works for me fine

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

@aydot actually you are right, it does not work. I need to investigate further.

from piping-bag.

aydot avatar aydot commented on June 27, 2024

have an idea when you'd be able to look into this? quick question, will this work for a Controller constructor injection just like Laravel does?

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

Hey, I'm sorry about this issue. I'm currently sorting it out with Ray.Di creator, since I need a feature that is not currently supported in the library.

CakePHP already reserves the constructor of the controller, so adding more parameters to it will only feel awkward. Instead you can use use any other method to get your dependencies injected:

/**
 * @Inject
 */
public function postConstruct(Dep1 $dep, Dep2 $dep2 ....) {
}

I'll try to solve this issue as soon as possible. If you need any workaround please let me know. There are way to workaround this, but need some changes in Ray.Di to make this work in a generic way.

from piping-bag.

aydot avatar aydot commented on June 27, 2024

How do I write test for the dependencies? Will I have to swap out the instance in the container?
I tried this code here but didn't work.

$container = new Container;
$browser = $this->getMock('Ikimea\Browser\Browser');
(new Bind($container, 'Ikimea\Browser\Browser'))->toInstance($browser);

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

The best way is to create a new container with extra modules that you can use in the test. In general, this technique is used for integration testing and makes no much sense for unit testing since you should be passing the dependencies manually:

PipingBag::container($anotherInjectorInstance);

You can create the injector instance manually or by passing the result of calling PipingBag::create($allModulesNeededForTest)

from piping-bag.

aydot avatar aydot commented on June 27, 2024

How would you test a code like this?

<?php
namespace App\View\Cell;

use Cake\View\Cell;
use PipingBag\Di\PipingBag as Di;
use Ikimea\Browser\Browser;

class BrowserCompatibilityCell extends Cell
{
    protected $_validCellOptions = [];

    public function display()
    {
        $browser = Di::get('Ikimea\Browser\Browser');
        $this->set('browser', $browser->getBrowser().' '.$browser->getVersion());
    }
}

Since I can't inject it's dependency via the constructor

from piping-bag.

lorenzo avatar lorenzo commented on June 27, 2024

Closing this as it is working now

from piping-bag.

Related Issues (13)

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.