Comments (14)
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.
I'll take a look at this soon.
from piping-bag.
Had a chance to look at this yet ?
from piping-bag.
I can confirm the bug...
from piping-bag.
@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.
the controller action injection still doesn't work for me
from piping-bag.
Tell me what you did, it works for me fine
from piping-bag.
@aydot actually you are right, it does not work. I need to investigate further.
from piping-bag.
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.
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.
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.
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.
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.
Closing this as it is working now
from piping-bag.
Related Issues (13)
- Ray.Di v2 HOT 2
- Pipingbag\Routing\Filter\ControllerFactoryFilter::beforeDispatch missing? HOT 4
- PipingBag ControllerFactoryFilter invalidates template paths HOT 11
- Bad type hinting on PipingBag::get() HOT 2
- 3.1 viewPath is deprectared HOT 1
- Dependency error HOT 4
- Fatal error on Cake 3.3 HOT 2
- Modules with Configure::readOrFail() in them HOT 1
- Example for constructor injection in Controller class HOT 2
- PHP 8 Attributes support
- Fatal Error when I try to create a module HOT 1
- lorenzo/piping-bag dev-master requires ray/di dev-compiler HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from piping-bag.