Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Alias package classes to somewhere other than global namespace
  • Is there any way of aliasing package classes into another namespace in order to allow them to be overridden in the app bootstrap (in a similar way to how core does). I don't want to alias them into the global namespace, just from say Ecommerce\Core to Ecommerce. I know that you can use Autoloader::alias_to_namespace() to achieve the change of namespace, but since this calls class_alias() the package class is already loaded by the point at which you're trying to override it. Thanks.
  • I know this is quite old, but just curious. Does this accomplish the same thing?
    Autoloader:;add_classes(array(
    'Ecommerce\\Model_Customer' => __DIR__.'/classes/model/customer.php',
    ));
  • For anyone that's interested I've found a way to do it but it seems a bit dirty, alternatives are welcome.
    $ecommerce_classes = array(
     'Ecommerce\\Core\\Model_Customer'   => __DIR__ . '/classes/model/customer.php',
    );
    
    \Autoloader::add_classes($ecommerce_classes);
    
    // Alias all of the ecommerce core classes into the ecommerce
    // namespace to give app classes a chance to override them
    array_map(function($class){
     
     $parts = explode('\\', $class);
     $class_name = array_pop($parts);
     
     if( ! class_exists('\Ecommerce\\'.$class_name)) {
      \Autoloader::alias_to_namespace($class, 'Ecommerce');
     }
     
    }, array_keys($ecommerce_classes));
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion