- How do I install marvin255/value-object in a Laravel project?
- Install it with Composer using composer require marvin255/value-object. Laravel's package discovery will handle any service provider the package registers, though this library may not require one. After installation, import the value object classes you need and start using them in your domain code.
- What value objects are included in marvin255/value-object?
- The package provides value objects for email addresses, URIs, integers, strings, and files. These cover common domain concerns where you want typed, validated data instead of raw scalars. Check the repository for the exact class names and available methods.
- Why should I use immutable value objects instead of plain strings or integers?
- Immutable value objects prevent accidental changes after creation, which keeps domain data consistent across your application. They also centralize validation and make method signatures more expressive than raw scalars. This reduces bugs when the same concept, such as an email or URI, is passed through multiple layers.
- How does validation work in this value object library?
- Each value object is self-validating, so invalid input is rejected when the object is created rather than later in your business logic. That means you can trust an instance to represent a valid email, URI, integer, string, or file path according to the class rules. For exact validation rules and exception behavior, consult the package source or README.
- How do I convert a value object to an array or JSON?
- The package is designed with simple array and JSON conversion, so value objects can be serialized for APIs, storage, or debugging. Use the provided conversion methods on the value object rather than manually extracting properties. Confirm the exact method names in the README because they may vary by value object type.
- Can I use marvin255/value-object outside of Laravel?
- Yes, it is a PHP value objects library and does not fundamentally depend on the Laravel framework. You can install it via Composer in any compatible PHP project. Laravel users benefit from the same classes, but the package is not limited to Laravel applications.
- How do I create a custom value object with this package?
- The library is intended for building immutable, self-validating value objects, so you can define your own class with typed properties and validation logic. Reuse the package's conventions for construction and array/JSON conversion where possible. Check the README for the recommended base class or interface to extend.
- Does marvin255/value-object integrate with Eloquent casts?
- The package focuses on value objects and array/JSON conversion rather than database mapping. If you need to persist a value object in Eloquent, use a custom cast or map it to a scalar or JSON column. Check the repository for any built-in cast support before writing your own.
- Which PHP and Laravel versions are supported?
- Version support is defined in the package's composer.json and README on GitHub. Because it is a PHP library, it can be used with any Laravel release that satisfies those constraints. Always verify the current requirements before adding it to an existing application.
- How should I test code that uses these value objects?
- Test that valid input creates the expected object and that invalid input is rejected according to your rules. Because the objects are immutable, you can assert on their exported array or JSON values without worrying about hidden mutation. Use PHPUnit or Pest as you normally would in a Laravel project.