Skip to content

Commit

Permalink
Merge pull request #4 from charonlab/feature/service_provider
Browse files Browse the repository at this point in the history
Implement service provider system
  • Loading branch information
nulxrd committed Feb 11, 2024
2 parents fb79fab + 74c2b3c commit 1da7c72
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ public function factory(string $id, object $service): void {
$this->keys[$id] = true;
$this->factories[$id] = $service;
}

/**
* @inheritDoc
*/
public function register(ServiceProviderInterface $serviceProvider): void {
$serviceProvider->register($this);
}
}
10 changes: 10 additions & 0 deletions src/ContainerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ public function set(string $id, string|int|float|object $value): void;
* @throws \Charon\Container\Exception\NotInvokableException
*/
public function factory(string $id, object $service): void;

/**
* Registers a service provider.
*
* @param \Charon\Container\ServiceProviderInterface $serviceProvider
* The service provider to be registered.
*
* @return void
*/
public function register(ServiceProviderInterface $serviceProvider): void;
}
25 changes: 25 additions & 0 deletions src/ServiceProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the charonlab/charon-container.
*
* Copyright (C) 2023-2024 Charon Lab Development Team
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE.md file for details.
*/

namespace Charon\Container;

interface ServiceProviderInterface
{
/**
* Registers a services into the container.
*
* @param \Charon\Container\ContainerInterface $container
* The container to register the services into.
*
* @return void
*/
public function register(ContainerInterface $container): void;
}

0 comments on commit 1da7c72

Please sign in to comment.