When creating a service provider, you must implement two methods: provides and register.
provides(string $id): bool: This method tells the container which service IDs or class names this provider is responsible for. If the $id is not returned as true here, the container will ignore any registration attempts for that ID in the register method.register(): void: This method is used to define the actual services within the container using the container instance obtained via $this->getContainer().
namespace WeDevs\Dokan\DependencyManagement\Providers;
use WeDevs\Dokan\BaseServiceProvider;
class SomeServiceProvider extends BaseServiceProvider
{
public function provides(string $id): bool
{
$services = [
'key',
Some\Controller::class,
Some\Model::class,
Some\Request::class,
];
return in_array($id, $services);
}
public function register(): void
{
$this->getContainer()->add('key', 'value');
$this->getContainer()
->add(Some\Controller::class)
->addArgument(Some\Request::class)
->addArgument(Some\Model::class);
$this->getContainer()->add(Some\Request::class);
$this->getContainer()->add(Some\Model::class);
}
}