Git Product home page Git Product logo

Comments (9)

lookyman avatar lookyman commented on May 12, 2024 1

@TomasVotruba https://github.com/lookyman/nette-auto-factory I need to stress that it has massive limitations (constructor arguments) and is basically just an exercise in using PhpGenerator.

from di.

lookyman avatar lookyman commented on May 12, 2024

The anonymous class solution would actually solve a problem I encountered just last week, where I tried to auto generate the interface itself. It works, but if you put it somewhere where the autoloading you already have doesn't see it, you are screwed. You have to either extend the PSR-4 autoload in composer.json, or register new path in RobotLoader in bootstrap. Neither of which you can do in runtime from an extension.

But, PHP 7 :/

Relevant https://github.com/lookyman/di/commit/6674d280d9f2911b63309903df20556315a2b2e2

from di.

dg avatar dg commented on May 12, 2024

👍

from di.

TomasVotruba avatar TomasVotruba commented on May 12, 2024

@lookyman How exactly in your case? And what was your issue? I didn't get that from referenced method.

from di.

lookyman avatar lookyman commented on May 12, 2024

@TomasVotruba

I had an extension, gave it some path, it scanned it for all classes of some type, generated a factory interface for each of them (and wrote it to some file in another path), and registered that interface as a service in container. But if that path with generated interfaces was not under autoload, the container couldn't be instantiated (though it could be built).

Kdyby/Doctrine, for example, runs into similar issue for generated entity proxies. But the proxies are loaded when the application is already running, so you have time to register an autoloader in Container::initialize(). In my case, you don't.

I have since abandoned that idea, but the commit I referenced could be used to solve this issue. Although I would much rather use the already existing afterCompile() for this and pass it a reference to all generated classes, but that would be a big BC break.

from di.

TomasVotruba avatar TomasVotruba commented on May 12, 2024

@lookyman Pretty neat usage :) thanks for explaining.

Do you have this extension somewhere on Github? Would love to see that.

from di.

TomasVotruba avatar TomasVotruba commented on May 12, 2024

@lookyman I was wondering... how far from your package is to create same service lazy loader (using proxy) that has Symfony?
https://symfony.com/doc/current/service_container/lazy_services.html

That would be awesome extension :)

from di.

dg avatar dg commented on May 12, 2024

The problem with autogenerated intefaces is that is then you use in the code interfaces that actually don't exist. It will break code completing in IDE or API documentation generators.

Proxies don't have these problems, but they have another.

from di.

lookyman avatar lookyman commented on May 12, 2024

@dg I know, as I've said, that whole extension was just an excercise. Not really that useful, except perhaps in very specific circumstances.

Anyway, I LOVE the anonymous class thingy you've made here. Thanks.

from di.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.