S
S
Sergey Fedotov2017-05-17 19:50:49
PHP
Sergey Fedotov, 2017-05-17 19:50:49

Is it possible to use composer in this case?

Until now, I wrote my own code without using someone else's. Of course, this is time consuming, but it was enough for my needs. Decided to try using composer. Previously, to ensure autoloading of classes, I used a file in the root of the project, which contained the following code:

set_include_path(__DIR__.'/../classes/');
spl_autoload_extensions('.php');
spl_autoload_register();

In essence, it allows you to load classes from the classes folder, which is located one level lower than the folder accessible through the web server.
File naming is slightly different from PSR - only lowercase letters are used in file names, i.e. for example, if I have an OAuth2/Facebook class, then it is located in the classes/oauth2/facebook.php file.
The download method is very fast. it doesn't even use PHP code for autoloading.
Now I’m confused about similar classes that I use on several sites, arrange them in the form of composer packages (closed for a start, I want to open the successful ones later). Question: is it possible to arrange such structures as composer packages (one namespace - one package)? Or do you still have to redo everything under PSR-4 and load classes through PHP code, and not directly through setting up inlcude paths?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question