N
N
Ninazu2016-02-20 00:22:47
PHP
Ninazu, 2016-02-20 00:22:47

How to correctly specify autoload for classes without namespace in composer?

- vendor
  - author
    - package
      - path1
        - Class2.php (namespace path1;)
      - path2
        - Class2.php (namespace path2;)
      - BaseClass.php (without namespace)
      - composer.json <--  autoloader

It turns out somewhere
$baseClass = new BaseClass();
$class2 = new \path1\Class2();
$class2 = new \path2\Class2();

composer.json, now I have one.
"autoload": {
  "classmap": [
    "path1",
    "path2",
  ],
  "files": [
    "BaseClass.php",
  ]
}

Everything is working. But the inconvenience is that it is necessary to list all base classes and all folders ((. I feel that there is an easier way that will be solved with one or two lines in "autoload", through psr-4 or psr-0 it can be somehow. But I don’t understand , what needs to be written so that the classes are loaded as they are now.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OnYourLips, 2016-02-20
@OnYourLips

But I don’t understand what needs to be written so that the classes are loaded as they are now.
Namespaces.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question