hiqdev/yii2-collection
Yii2 extension that integrates hiqdev/php-collection, providing collection data structures and helpers for Yii2 apps. Install via Composer and use a consistent, reusable collection API within your Yii2 project.
php-collection library, this package is tightly coupled to Yii2 (e.g., leverages Yii2 traits, components, and conventions). If the Laravel project is not Yii2-based, integration would require significant abstraction or a rewrite of core logic.Illuminate\Support\Collection class, which provides similar (and often more feature-rich) functionality. This package offers no unique value for Laravel unless:
ActiveRecord, QueryBuilder, or Behavior system) are required.php-collection: The package wraps hiqdev/php-collection, which is a generic PHP collection library. If Laravel’s native Collection is insufficient, evaluating php-collection directly (without Yii2 shims) may be preferable.yii\base\BaseObject, while Laravel uses Illuminate\Support\Manager. Mixing these would require custom wrappers.yii\base\Event) differs from Laravel’s (Illuminate\Events\Dispatcher), which could complicate integration.Yii2CollectionProxy).php-collection: Use the underlying hiqdev/php-collection directly, bypassing Yii2-specific code.rawItems()) and reimplement them in Laravel’s Collection macro system.Collection evolves rapidly (e.g., new methods like when(), unless(), or pipe()). Backporting or maintaining parity would be error-prone.php-collection (which itself may not be optimized) could introduce unnecessary abstraction.pcntl_fork or a message queue).php-collection features are missing in Laravel’s Collection and prioritize backporting those via macros or custom classes.Why Laravel?
ArrayHelper) that Laravel’s Collection lacks?Alternatives Evaluation
Collection (with macros)?php-collection directly?league/collection)?Maintenance Commitment
Collection evolves to include missing features?Testing and Compatibility
Illuminate\Support\Collection already provides:
map, filter, reduce, pluck).Collection via macros or custom traits before adopting this package.BaseObject (for traits like ManagerTrait).Component and Behavior systems.| Approach | Feasibility | Effort | Risk | Notes |
|---|---|---|---|---|
Use Laravel Collection + Macros |
High | Low | Low | Best for most use cases. |
Direct php-collection Integration |
Medium | Medium | Medium | Requires namespace/dependency isolation. |
| Yii2 Adapter Layer | Low | High | High | Rewrite traits for Laravel’s DI. |
| Micro-Service Isolation | Medium | High | Medium | Run Yii2 collection logic in a separate service. |
Recommended Path:
hiqdev/yii2-collection missing in Laravel’s Collection.// In a service provider:
\Illuminate\Support\Collection::macro('yiiRawItems', function () {
return $this->all(); // or custom logic
});
php-collection: If Yii2-specific behaviors are critical, use the underlying library with a facade:
use HiQDev\Collection\Collection as YiiCollection;
$yiiCollection = new YiiCollection([1, 2, 3]);
Collection differences.yii/yii2 (for traits/components).yiisoft/yii2-composer (autoloader).yii2-collection methods are missing in Laravel’s Collection.rawItems(), ManagerTrait behaviors).Collection macros.Collection::macro('yiiGetItem', function ($offset, $default = null) {
return $this->get($offset, $default);
});
Collection evolves independently (e.g., new methods, optimizations).Collection.How can I help you explore Laravel packages today?