Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ToroPHP and dependency injection #90

@Ecaz

Description

@Ecaz

Hello! I just picked up ToroPHP and I normally use DI when I do any kind of database interaction.

Rough example

$db = new PDO("mysql:host=myhost;dbname=myname", "username", "password");
$object = new Object($db);

class Object {
    private $db;

    function __construct($dbConn) {
        $this->db = $dbConn;
    }

    function get($string) {
        $sql = $this->db->prepare("statement GOES here");
    }
}

But ToroPHP doesn't allow you to do this, is there any way to get around this? I don't wanna use a global variable.

Toro::serve(array(
    "/" => "Object",
    "/get/:string" => "Object" //would be injected somewhere so you could get :string from the db.
));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions