Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of dependencies and make the autoloader self-contained #22

Closed
meglio opened this issue Dec 9, 2020 · 7 comments
Closed

Get rid of dependencies and make the autoloader self-contained #22

meglio opened this issue Dec 9, 2020 · 7 comments

Comments

@meglio
Copy link

meglio commented Dec 9, 2020

It is an ironic situation that in order to use RobotLoader I have to use composer, so that:

  1. Dependencies are fetched (currently there are two of them - nette/finder and nette/utils)
  2. Dependencies can be autoloaded by the composer's autoloading

In your documentation, you're claiming that RobotLoader can replace composer autoloading, but the only easy way to use it in this mode is to ... install it and autoload it with using composer.

My suggestion is to make RobotLoader a self-contained file with zero dependencies. So then the simplest use case becomes possible: download the single RobotLoader.php file manually, throw it into the source folder, and start using it as the autoloader in the user project.

@dg
Copy link
Member

dg commented Dec 9, 2020

Of course, the robot loader can be modified so that it has no dependencies, but its purpose is not to replace a Composer. Composer autoloading is the best way to autoload the contents of the vendor/ folder.

@meglio
Copy link
Author

meglio commented Dec 10, 2020

So, what's the point then - how do I use RobotLoader if I don't use Composer? And why would I use RobotLoader if I do use Composer?

The RobotLoader implies it can be used with or without Composer. But then it turns out that you can't use RobotLoader without composer out of the box. But if I introduce Composer to my project, rarely will it be also the case that I use something else besides the composer itself.

At the end of the day, it is not clear what problem RobotLoader is trying to solve. Could you elaborate a use-case where it will make sense, please?

@JanTvrdik
Copy link
Contributor

It's like a composer classmap autoloader with automatic reindexing, so you don't need to call composer dump-autoload everytime you add new class.

@dg
Copy link
Member

dg commented Dec 10, 2020

This is an over 13-year-old library, so it was created much earlier than Composer and was originally used to autoload all classes. Today, it is standard to install and load libraries by Composer. RobotLoader is used to autoload other classes, such as classes that are part of the application. It can do this better than Composer due to automatic reindexing, see comment above.

RobotLoader can also be used to search for classes in directories without using autoloding feature. https://doc.nette.org/en/3.0/robotloader#toc-php-files-analyzer

It would be possible to get rid of all dependencies, but this is not my priority at the moment, because RobotLoader is not an alternative to the Composer.

@meglio
Copy link
Author

meglio commented Dec 10, 2020

@JanTvrdik , in the development mode, I only ever need to composer dump-autoload after installing a new library - not a big deal since I'd be running composer from command line anyway. If my understanding is wrong, please correct me.

Trying to understand what's the point with "automatic reindexing". Is this for when an authoritative classmap is used in composer, i.e.:

"config": {
    "classmap-authoritative": true
}

... if not, then for what cases?

Without the authoritative classmap loading ON, I only ever have to declare my src application folder once, and then the autoloading happens for whatever folders/subfolders I create after that while developing. In production, if I want to go faster, I'd then dump-autoload, but that's (most of the time) part of the CI/CD anyway (not a manual step).

I'm not trying to be unkind, just can't understand why I would use the library and how it can help me, and I still cannot figure it out. I'm happily using some other libraries from Nette. But this one is confusing, and the documentation does not help. It teaches one how to use it, but has no examples of when it would make sense to add it on top of composer.

Hope my question and investigation makes sense to you, and hope you can see the problem I'm trying to describe.

@JanTvrdik
Copy link
Contributor

classmap autoloader refers to https://getcomposer.org/doc/04-schema.md#classmap (i.e. not PSR-4 and PSR-0)

@dg
Copy link
Member

dg commented Sep 26, 2023

Here is standalone version of RobotLoader https://github.com/nette/robot-loader/tree/standalone/src/RobotLoader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants