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

DI config from PHP using anonymous functions

Hi guys,

Please refer to: Class Phalcon\Di Toward the bottom there is "public loadFromPhp (mixed $filePath)"

I would like to use anonymouse functions for both shared and non-shared services, but I do not know the array key name, does anyone know how this can be done?

<?php
return [
    'myComponent' => [
        '?????' => function() { reutrn new CustomerServiceClass(); },
        'shared' => true,
    ],
    'group' => [
        '?????' => function( $type, $service ) {  return new CustomerServiceClass(); },
        'arguments' => [
            [
                'type' => 'service',
                'service' => 'myComponent',
            ],
        ],
    ]
];

Thanks, Dave

Hi @DaveGoodchild you try with

    return [
        'myComponent' => [
            function() { reutrn new CustomerServiceClass(); },
            'shared' => true,
     ],

I check loadFromPHP and probably works