2

I am working on an application, where a "meta" namespace has several sub-namespaces, placed in different directories. Take the example below:

$loader = require(__DIR__ . '/vendor/autoload.php');
$loader->set('Foo\Bar', realpath(__DIR__ . "/src/123/Foo/Bar"));
$loader->set('Foo\Baz', realpath(__DIR__ . "/src/abc/Foo/Baz"));

The "meta" namespace is of course Foo, and the sub-namespaces are Bar and Baz.

composer doesn't seem to be happy about it. The second namespace is ignored. Notice that the contents are stored in different folders below src; 123 and abc, respectively.

Is it not possible to assign sub-namespaces this way using composer?

I find it fairly difficult to find information about this corner case.

Kafoso
  • 534
  • 3
  • 20

1 Answers1

1

It is possible - with PSR-4 autoloader (http://www.php-fig.org/psr/psr-4/, What is the difference between PSR-0 and PSR-4?):

$loader = require 'vendor/autoload.php';
$loader->setPsr4('Foo\\Bar\\', realpath(__DIR__ . '/src/123/Foo/Bar'));
$loader->setPsr4('Foo\\Baz\\', realpath(__DIR__ . '/src/abc/Foo/Baz'));

$bar = new Foo\Bar\BarTest();
$baz = new Foo\Baz\BazTest();
Community
  • 1
  • 1
lku
  • 1,732
  • 14
  • 20