use Linker\Link; $linker = new Link(); $linker->register('db', function () { return new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password'); }); $linker->register('users', function ($linker) { return new UserProvider($linker->get('db')); }); $user = $linker->get('users')->findByEmail('user@example.com');
use Linker\Link; $linker = new Link(); $linker->register('mailer', function () { return new Mailer('smtp.example.com', 'username', 'password'); }); $linker->register('orderProcessor', function ($linker) { return new OrderProcessor($linker->get('mailer')); }); $linker->get('orderProcessor')->processOrder($order);In this example, we are registering a mailer class and an order processor class that depends on the mailer using Linker. Then we are using the order processor to process an order. Overall, Linker is a powerful PHP package library that helps in structuring and managing dependencies in a structured way. It is useful in building modular and maintainable applications.