Comments (6)
First let me ask. By the value objects you mentioned you mean something like WebConfiguration
class with properties $projectDir
, $tempDir
, $publicDir
and so on? And then wherever you need any of these parameters you would inject this class instead? Or did you mean something else?
from di.
Exactly. I mean for example MailConfig
.
final class MailConfig
{
/** @var string */
private $from;
public function getFrom(): string
{
return $this->from;
}
public function setFrom(string $from): void
{
$this->from = $from;
}
}
With @value
injection.
final class MailConfig
{
/** @var string @value(%mail.from%) */
private $from;
}
from di.
I don't quite see the benefit. These value objects are there to remove the need of manually injecting all the properties. You just inject them to this value object. But whether you do that in config or in the class itself doesn't make much of a difference - it's still about the same amount of writing. The downside here is that you're referencing the container parameters in your source code which is the same thing as $this->container->getParameter('whatever')
. Imo the container parameter names should stay in config - same as all the service names which we're eliminating from source code by using DI instead of service locator.
And if you're doing it because you want to addsome validation for the properties as someone mentioned on twitter then I'm against that as well. I want to perform such validaiton at compile-time to both prevent doing useless things every time in runtime and to see the errors for things that are rarely used and I could miss them.
from di.
Hmmm, I get it.
There's a hidden purpose for the whole thing and to simplify configuration.
Consider you have a modular system and many configurations, you don't want to setup all neon files and their calls. You just want to share this value object and use it.
/** @var string @value(%mail.from%) */
private $from;
/** @var string @value(value="%mail.from%", type="email") */
private $from;
/** @var string @value(value="%mail.from%", type="email", prefix="no-replay@") */
private $from;
The last example is very futuristic, but I hope you know what I mean.
from di.
I'm closing it now, we can still discuss it. :-) Thanks anyway.
from di.
I missed your previous answer here, sorry.
Well I understand a bit better what is your intention but I still don't think it's a good idea and I would not personally use it. When you have a modular system it's more than likely that you'll need to let the user configure most of the parameters in admin interface in which case you probably won't have them as container parameters anyway.
from di.
Related Issues (9)
- Kickoff HOT 1
- Autoload: Support wildcards in namespace and excludes HOT 3
- Autoload - improvements
- Automatic controllers registration doesn't work with Apitte HOT 9
- ContainerAwareInterface
- When I reach 488 definitions i get error HOT 1
- ContainerBuilder - helpers/factories
- Call to undefined method Nette\Loaders\RobotLoader::setCacheStorage() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from di.