Aura\Di error I can't figure out

22 views
Skip to first unread message

Chris Johnson

unread,
Jan 26, 2017, 4:49:59 PM1/26/17
to The Aura Project for PHP
I'm getting this error message:

Aura\Di\Exception\MissingParam: Param missing: \Clx\Api\X12ApiAction::$log


Yet I cannot tell how the parameter is missing.  What am I missing here?

Here's my container configuration:

public function define(Container $di)
{
$di->params[X12ApiAction::class] = [
'log' => $di->lazyNew(ClxMsg::class),
];
}

And here's my class constructor:

class X12ApiAction extends Action
{
/**
* @var ClxMsg
*/
protected $log;

/**
* @param ClxMsg $log
*/
public function __construct(ClxMsg $log)
{

Hari K T

unread,
Jan 26, 2017, 7:08:54 PM1/26/17
to aur...@googlegroups.com
Looks like the problem with namespace.

Can you explicitly add 

$di->params['Clx\Api\X12ApiAction'] = [ 
    'log' => $di->lazyNew('Clx\Api\ClxMsg'), 
];

I have came across something when your namespace is using `use` and without use.


Eg :

$di->params[X12ApiAction::class] = [ 
    'log' => $di->lazyNew(ClxMsg::class), 
];

class X12ApiAction extends Action
{
/**
* @var ClxMsg
*/
protected $log;

/**
* @param ClxMsg $log
*/
    public function __construct(\Clx\Api\ClxMsg $log)
{

The `\Clx\Api\ClxMsg` and `Clx\Api\ClxMsg` are interpreted differently in params.

Hope that helps.

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt

--
You received this message because you are subscribed to the Google Groups "The Aura Project for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Johnson

unread,
Jan 26, 2017, 8:30:00 PM1/26/17
to The Aura Project for PHP
Hello Hari,

Thanks much for the reply.  I've tried many combinations of explicitly providing the namespaces, and I still get the same error.  The correct, full namespaces are actually:
\Clx\Api\X12ApiAction
\Clx\ClxMsg

I've got use statements in all involved files to alias them to just the class names.  But even when I spell out the full namespace, it fails.  I feel like I am overlooking some very simple and basic, but just cannot find it.

Regards,
..chris

Chris Johnson

unread,
Jan 26, 2017, 8:58:54 PM1/26/17
to The Aura Project for PHP
Ah, it was a namespace resolution problem.  PHP is unpredictable this way.  Maybe Aura\Di should have some fuzzy logic built to handle these kinds of cases?

This works:
$di->params['\Clx\Api\X12ApiAction'] = [
    'log' => $di->lazyNew(\Clx\ClxMsg::class),
];

This does not work, even though it should be equivalent:
$di->params['Clx\Api\X12ApiAction'] = [
    'log' => $di->lazyNew(\Clx\ClxMsg::class),
];

This also fails, which is also the same as above:
$di->params[\Clx\Api\X12ApiAction::class] = [
'log' => $di->lazyNew(\Clx\ClxMsg::class),
];

Look at this small test program:
<?php
namespace bar;
class Baz {}


echo
\bar\Baz::class . PHP_EOL;
?>
This outputs:  bar\Baz with no leading \.



On Thursday, January 26, 2017 at 3:49:59 PM UTC-6, Chris Johnson wrote:

Hamza Kubba

unread,
Jan 26, 2017, 10:02:30 PM1/26/17
to aur...@googlegroups.com
Based on your tests (and not on anything else, since I haven't used Aura yet), this should work too btw:
$di->params['\' . \Clx\Api\X12ApiAction::class] = [

'log' => $di->lazyNew(\Clx\ClxMsg::class),
];

--

Hari K T

unread,
Jan 26, 2017, 10:25:02 PM1/26/17
to aur...@googlegroups.com
Happy to know this works for you :-) .
Reply all
Reply to author
Forward
0 new messages