Coder Social home page Coder Social logo

Comments (8)

dg avatar dg commented on June 10, 2024 1

@Gappa I'm not sure yet, I'll let you know

from di.

dg avatar dg commented on June 10, 2024

It looks like the TestExtensionConfigDTO object can't be simply created, so it is created in the container using Dumper::createObject(), i.e. using serialization+unserialization, which is a pretty dirty way.

https://github.com/nette/php-generator/blob/08ab9bff22ae34fe4e1d2fe8ba16b3770ea2459f/src/PhpGenerator/Dumper.php#L290-L297

But I understand why you use it that way, let's try to find a solution.

The solution I can think of is that TestExtensionConfigDTO will have a constructor (and all properties will be promoted parameters), so such an object can be easily created. But that's not enough, some information will still have to be added for the DI compiler to use that constructor…

from di.

mabar avatar mabar commented on June 10, 2024

I am confused what does it have to do with DI compiler. Isn't config schema used just to access config values of the extension? They are not passed to generated DIC

For objects that are passed to generated DIC, I am using explicit serialization, which is fine as long as changing the object forces DIC to regenerate (can be done by adding object to compiler dependencies) https://github.com/orisai/localization/blob/ae99720c58b10408b099e68c9692f75a45c4b627/src/Bridge/NetteDI/LocalizationExtension.php#L131-L136

from di.

dg avatar dg commented on June 10, 2024

@mabar I suppose @Gappa will then pass the $this->config to some service. Right?

from di.

Gappa avatar Gappa commented on June 10, 2024

@mabar I suppose @Gappa will then pass the $this->config to some service. Right?

Yes, that is correct.

from di.

janfejtek avatar janfejtek commented on June 10, 2024

I think having some better decision making when triggering error would be fine? Plus some changes in Dumper::createObject logic to avoid unserialization. Maybe some similar logic to form values? https://github.com/nette/forms/blob/d42a22b451fcdf267e7c485309370506a8731d56/src/Forms/Container.php#L137

If I have simple class like this

class Data {
   public string $url;
   public string $query;
}

I would say it is really close to \stdClass, but it is not accepted
c257fa9#diff-b01fda112fb0df465a70dd098f3843dd90fc3a0ce514c37ef38d620e7f7cc718R184

from di.

dg avatar dg commented on June 10, 2024

I don't know how to dump this object:

class Data {
   public string $url;
   public string $query;
}

but I can dump this one:

class Data {
  function __construct(
   public string $url,
   public string $query,
  ) {}
}

from di.

Gappa avatar Gappa commented on June 10, 2024

Tried it with 6b9910cece1e074ad1d1babc6a62c48dfa9ea870 and it works now - thanks. 👍

However, would it be better if I changed those DTOs to classes with private properties and a constructor?

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.