We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how can I use "di:beforeServiceResolve" to change parameters


line 215 to 230

    if typeof eventsManager == "object" {
        eventsManager->fire("di:beforeServiceResolve", this, ["name": name, "parameters": parameters]);

    if fetch service, this->_services[name] {
         * The service is registered in the DI
        let instance = service->resolve(parameters, this);
    } else {
         * The DI also acts as builder for any class even if it isn't defined in the DI
        if !class_exists(name) {
            throw new Exception("Service '" . name . "' wasn't found in the dependency injection container");

I want to use "di:beforeServiceResolve" change the parameters .

What should I do?

edited Jun '16
$di = new Phalcon\Di();
$eventsManager = new Phalcon\Events\Manager();
$eventsManager->attach('di:beforeServiceResolve', function(Event $event, Di $di, $data) {
// your logic


But im not sure you can change parameters "on the fly" using event manager. It's possible that you just need to extend phalcon di and override get method and do something with parameters and then call parent get.


Thany you.