Comments (3)
The objects are immutable, but not in the constructor.
If you try to assign the value manually, it will throw an exception:
$test = new Text('value1');
$test->value = 'new value'; // ... Exception
I've considered making constructors final
, but this way developers are limited in extending/overriding the constructor logic, e.g. Name
extends Text
and adds sanitization logic. With construct being final
we'll be unable to do that.
from laravel-value-objects.
Came up with a non-breaking solution, and also to keep extendability in #14
This will be shipped as a minor release in a while.
from laravel-value-objects.
I would have simply put the constructor in protected so that the developers cannot use it without passing a static method which will act as a factory.
protected function __construct(string|Stringable $value)
{
// ....
}
public static function make(mixed ...$values): static
{
return new static(...$values);
}
from laravel-value-objects.
Related Issues (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 laravel-value-objects.