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

Map Laravel Package

aimeos/map

High-performance e-commerce framework for Laravel/Lumen (and other PHP apps). Provides products, catalog, basket, checkout, customers, orders and admin UI. Extensible via plugins, supports multiple shops/sites, currencies and languages, and scales well.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing via Composer:

composer require aimeos/map  

The package provides a fluent, immutable Map class that extends ArrayObject for easy array manipulation. Your first use case: transforming data. Instead of nested array_map() and array_filter() calls, chain methods:

use Aimeos\Map\Map;  

$users = new Map([  
    ['id' => 1, 'name' => 'Alice', 'active' => true],  
    ['id' => 2, 'name' => 'Bob', 'active' => false],  
]);  

$result = $users  
    ->filter(fn($u) => $u['active'])  
    ->map(fn($u) => $u['name'])  
    ->toArray(); // ['Alice']  

Check the examples/ directory in the repo for quick starter snippets—though the package is lightweight, it lacks extensive official docs.

Implementation Patterns

  • Immutable Operations: All mutating methods (e.g., map(), filter()) return a new Map instance. Use ->apply() to mutate in-place when safe (e.g., internal state).
  • Lazy Evaluation: Chain operations freely; processing happens only on toArray(), toJson(), or iteration. Ideal for API responses or data pipelines:
    $pipeline = (new Map($largeDataset))  
        ->filter expensiveFilter()  
        ->map expensiveTransform()  
        ->sort();  
    $output = $pipeline->toArray(); // triggers processing  
    
  • Type Coercion: Convert numeric keys to associative arrays automatically:
    new Map([1, 2, 3])->keyBy(fn($v) => "item_{$v}");  
    
  • Interoperability: Works natively with Laravel Collections via ->map()Map::fromArray($laravelCollection->all()).

Gotchas and Tips

  • Key Preservation: map() preserves numeric keys by default. Use ->keyBy(fn($v) => $v['id']) if keys must reset.
  • Performance: Avoid repeated count() or toArray() calls inside loops—cache the Map instance.
  • No Recursive Operations: map() doesn’t recurse into nested arrays. For deep transforms, use custom recursion or forEachDeep() (if available in newer versions).
  • Debugging: print_r() on a Map shows internal ArrayObject structure. Use ->debug() (if added) or cast to array: (array)$map.
  • Extension: Extend Map to add domain-specific methods (e.g., validate(), toDto()) without breaking immutability:
    class UserMap extends Map {  
        public function active(): self {  
            return $this->filter(fn($u) => $u['active']);  
        }  
    }  
    
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
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
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation