Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Stdlib Laravel Package

laminas/laminas-stdlib

Utility components for PHP from the Laminas project: data structures, array and string helpers, hydrators, validators, option objects, and more. A shared toolbox used across Laminas and usable standalone in any PHP application.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer: composer require laminas/laminas-stdlib. It’s intentionally lightweight and dependency-light—ideal for use in standalone scripts, custom frameworks, or alongside Laravel. Your first use case will likely be hydrating objects from request data. For example, use Hydrator\ClassMethodsHydrator to convert a request payload (e.g., from an API controller) into a domain object:

use Laminas\Hydrator\ClassMethodsHydrator;

$hydrator = new ClassMethodsHydrator();
$user = $hydrator->hydrate($requestPayload, new User());

Check the official docs for quick reference; the library is well-documented with clear, minimal examples for each component.

Implementation Patterns

  • Hydration Strategy Injection: Use hydrators in services where object population from external data occurs (e.g., DTO mapping, API payloads, ORM hydration). Combine with custom strategies (GetSetStrategy, StrategyInterface) for nested objects or enum handling.
  • Safe Parameter Access: Replace raw $_GET/$_POST access with Filter\InputFilter or Request\Parameters to validate and cast inputs—especially useful in CLI tools or micro-frameworks.
  • Collection Abstraction: Use ArrayObject subclasses (e.g., GenericArrayObject) for type-safe collections in domain models—no need to reinvent “has this key?” or “pluck all values” logic.
  • Message Routing: In console or queue jobs, use Message + Result classes to build structured, serializable event payloads (e.g., for event-sourcing or audit trails).
  • Standalone Helpers: Leverage Utils\ArrayUtilities::dot() for flattening nested arrays (e.g., for config merging or Laravel’s cache tagging), or Utils\StringUtilities::isJson() in middleware for content-type decisions.

Gotchas and Tips

  • Hydrator Naming: ClassMethodsHydrator uses method names (getFoo()foo), not property names—ensure your DTOs follow PSR-1 conventions or extend ArraySerializable.
  • Null Handling: Some hydrator strategies silently drop nulls; override StrategyInterface if you need to preserve null vs. omit keys.
  • PHP 8+ Enum Support: Use Hydrator\Strategy\EnumStrategy (if available in your version) to hydrate backed enums cleanly—otherwise, write a custom strategy.
  • Performance Tip: Hydrators are lightweight, but instantiate them once per context (e.g., singleton service)—don’t create them inside tight loops.
  • Debugging Tip: The ArraySerializable trait’s toArray() often trips developers when hydrating from DB arrays—use ClassMethodsHydrator with exposeMethods(false) to hydrate only via __set() or properties.
  • Laravel Integration: Use laminas/laminas-stdlib in command handlers or jobs where Laminas’ InputFilter or hydration patterns improve data integrity over raw validated() arrays.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport