auraphp / Aura.Di

Dependency Injection System
MIT License
349 stars 63 forks source link

Simple instantiate a new container: More to it than whats in the readme? #51

Closed isimmons closed 10 years ago

isimmons commented 10 years ago
<?php namespace Foo;

use Aura\Di\Container;
use Aura\Di\Factory;

class Bar {
    protected $container;

    public function __construct()
    {
        $this->container = new Container(new Factory());
    }
   ...
}

Results in error Argument 1 passed to Aura\Di\Factory::__construct() must be an instance of Aura\Di\ForgeInterface, none given

Can't just pass in a new Forge() because it has dependencies and then there is a second parameter to Factory.

What am I missing?

isimmons commented 10 years ago

Based on the errors I changed to this and it seems to be working

use Aura\Di\Container;
use Aura\Di\Forge;
use Aura\Di\Config as DiConfig;

class Foo {

 protected $container;

    public function __construct()
    {
        $this->container = new Container(new Forge(new DiConfig));
    }
}

Am able to set and get objects in the container now.

isimmons commented 10 years ago

Just realized I'm on the develope-2 branch. Shouldn't the default branch at the main url be master? Anyway, I see the instructions there are different.

pmjones commented 10 years ago

Develop-2 is the way to fly. Develop is v1, and master is the most-recent v1 release. (I am considering reminding master entirely in favor of tags and the develop-* branches only.)

harikt commented 10 years ago

seems you downloaded a different version and played with readme of different version. Checkout the downloaded readme , and let us know if things still persists.

@pmjones this is why I am thinking to keep a v2 or v2 flag in readme .

Thank you.

pmjones commented 10 years ago

@isimmons Is this still an issue for you? If so we can continue working it; if not I'd like to close it.

isimmons commented 10 years ago

Oh sorry, no issue. I was just confused. I used packagist and installed v1.1.2 thinking I should use a stable version since I'm new to Aura. Then when I clicked on the link to github from packagist I didn't realize it took me to the develop-2 branch. Guess I should have looked around more before posting the issue and I would have seen this. Will go ahead and close. Thanks