PHP code example of stormmore / method-overloader

1. Go to this page and download the library: Download stormmore/method-overloader 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/ */

    

stormmore / method-overloader example snippets


$userRepository = new UserRepository();
$userRepository->add('Michael','Jordan', 23);
$userRepository->add('Michael Jordan', 23);
$userRepository->add(new User("Michael", "Jordan", 23));
$userRepository->add(new Player("Michael", "Jordan", 23));
$userRepository->add(['fist_name' => 'Michael', 'last_name' => 'Jordan', 'number' => 23]);

composer 

use \Storm\MethodOverload\MethodOverloader;

class UserRepository  
{

    public function add(mixed ...$args): void
    {
            $addMethodOverloader = MethodOverloader::create($this)
            ->register($this->addByFirstNameLastNameAndNumber(...),'string', 'string', 'int')
            ->register($this->adddByUser(...), User::Class)
            ->register($this->addByPlayer(...), Player::class)
            ->register($this->addByArray(...), 'array')
            ->register($this->addNyNameAndNumber(...), 'string', 'int')
            ->onFailure(function() {
                throw new MyCustomException();
            });
                  
        $addMethodOverloader->invoke($args);
    }
    
    private function addByFirstNameLastNameAndNumber(): void
    {
    }
    
    private function addNyNameAndNumber(string name, int number): void
    {
    }
    
    private function addByUser(User $user): void
    {
    }
    
    private function addByPlayer(Player $player): void
    {
    }
    
    private function addByArray($array): void
    {
    }
}

$callable = $object->methodName(...);