1. Go to this page and download the library: Download hypothesisphp/lens library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hypothesisphp / lens example snippets
use Lens;
// Get a nested value
$city = Lens::path('address.city')->get($user);
// Set (immutable — returns a new copy)
$updated = Lens::path('address.city')->set($user, 'Bandung');
// Update (transform in place)
$updated = Lens::path('price')->update($product, fn($v) => $v * 1.1);
// Batch (single clone, multiple changes)
$updated = Lens::batch($user)
->set('profile.name', 'John')
->update('profile.age', fn($v) => $v + 1)
->set('address.city', 'Bandung')
->apply();
// Returns a NEW object — original unchanged
$updated = Lens::path('name')->set($user, 'Bob');
// $user->name is still 'Alice'
// $updated->name is 'Bob'
// Deep set
$updated = Lens::path('address.city')->set($user, 'Bandung');
use Lens\Contracts\CloneStrategyInterface;
class MyCloneStrategy implements CloneStrategyInterface
{
public function clone(mixed $data): mixed { /* ... */ }
public function supports(mixed $data): bool { /* ... */ }
}
use Lens\Contracts\MetadataProviderInterface;
class DoctrineMetadataProvider implements MetadataProviderInterface
{
// Read types from Doctrine metadata instead of reflection
}