fuel / helpers

FuelPHP Framework - Generic helpers library
MIT License
17 stars 7 forks source link

Class 'Arr' not found #3

Open sagikazarmark opened 10 years ago

sagikazarmark commented 10 years ago

call_user_func_array() expects parameter 1 to be a valid callback, class 'Arr' not found

I get this message related to this line.

WanWizard commented 10 years ago

Arr is expected to be present in the global namespace. This is done in the Framework via the Facade classes. If you use this repo on it's own, outside the framework, you need to make sure Arr is available like it is done in phpunit:

// make Arr available in the global namespace
class_alias('Fuel\Common\Arr', 'Arr');

The correct solution is to have a DiC extension definition (like "getArrInstance') that can be attached to a class that needs Arr, so it can fetch an instance itself. This is how v2 handles it for all other dependencies.

sagikazarmark commented 10 years ago

Does that mean that I can do this in my package and use this package later with Fuel's DiC? You talked about extensibility, doesn't this break it?

What about this?

if( ! class_exists('Arr'))
{
    // make Arr available in the global namespace
    class_alias('Fuel\Common\Arr', 'Arr');
}
emlynwest commented 10 years ago

Personally I feel this should not be the case. It should be possible to use as much of the common package without having to set up little bits and pieces like this. It should be possible to inject an instance of Arr or to have the class constructed for you if one is not passed.

sagikazarmark commented 10 years ago

@stevewest The actual problem is that DataContainer uses Arr, and it assumes it exists in the root namespace. So it is OK to inject it in YOUR class, but in the actual case, it does not matter.

emlynwest commented 10 years ago

Yes, I know that. What I propose is a solution to that. You should not have to alias a class to set up the data container like that.

WanWizard commented 10 years ago

Which is what I wrote as "the correct solution" ;)

sagikazarmark commented 9 years ago

First step to the correct solution:

https://github.com/fuelphp/common/blob/master/src/Providers/FuelServiceProvider.php#L45

Arr Proxy uses an instance of Arr class resolved from the container.