Skip to content

Commit

Permalink
Updating container code
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Eelen committed Apr 22, 2024
1 parent f646ba8 commit cdae80e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class BaseServiceProvider extends AbstractServiceProvider
*/
protected function add(string $serviceName, callable $function, ?string $tag = null): void
{
$definition = $this->getLeagueContainer()
$definition = $this->getContainer()
->add($serviceName, $function);

if ($tag !== null) {
Expand All @@ -25,8 +25,8 @@ protected function add(string $serviceName, callable $function, ?string $tag = n
*/
protected function addShared(string $serviceName, callable $function, ?string $tag = null): void
{
$definition = $this->getLeagueContainer()
->share($serviceName, $function);
$definition = $this->getContainer()
->addShared($serviceName, $function);

if ($tag !== null) {
$definition->addTag($tag);
Expand Down
7 changes: 6 additions & 1 deletion app/CommandServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@

class CommandServiceProvider extends BaseServiceProvider
{
protected $provides = [
protected array $provides = [
Application::class,
];

public function provides(string $id): bool
{
return in_array($id, $this->provides, true);
}

public function register(): void
{
$this->add(
Expand Down
7 changes: 6 additions & 1 deletion app/CultureFeed/CultureFeedServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@

class CultureFeedServiceProvider extends BaseServiceProvider
{
protected $provides = [
protected array $provides = [
ConsumerCredentials::class,
CultureFeedFactoryInterface::class,
UserServiceInterface::class,
];

public function provides(string $id): bool
{
return in_array($id, $this->provides, true);
}

public function register(): void
{
$this->addShared(
Expand Down
13 changes: 6 additions & 7 deletions app/Factory/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ class ContainerFactory
public static function forCli(Config $config): Container
{
$container = self::build($config);
$container->addServiceProvider(CommandServiceProvider::class);
$container->addServiceProvider(new CommandServiceProvider);
return $container;
}

public static function forWeb(Config $config): Container
{
$container = self::build($config);
$container->addServiceProvider(RoutingServiceProvider::class);
$container->addServiceProvider(new RoutingServiceProvider);
return $container;
}

Expand All @@ -37,10 +36,10 @@ private static function build(Config $config): Container
$config
);

$container->addServiceProvider(CultureFeedServiceProvider::class);
$container->addServiceProvider(JwtServiceProvider::class);
$container->addServiceProvider(OAuthServiceProvider::class);
$container->addServiceProvider(RequestTokenStorageServiceProvider::class);
$container->addServiceProvider(new CultureFeedServiceProvider);
$container->addServiceProvider(new JwtServiceProvider);
$container->addServiceProvider(new OAuthServiceProvider);
$container->addServiceProvider(new RequestTokenStorageServiceProvider);

return $container;
}
Expand Down
7 changes: 6 additions & 1 deletion app/Jwt/JwtServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class JwtServiceProvider extends BaseServiceProvider
{
protected $provides = [
protected array $provides = [
Builder::class,
Signer::class,
'jwt.keys.private',
Expand All @@ -29,6 +29,11 @@ class JwtServiceProvider extends BaseServiceProvider
JwtDecoderServiceInterface::class,
];

public function provides(string $id): bool
{
return in_array($id, $this->provides, true);
}

public function register(): void
{
$this->addShared(
Expand Down
7 changes: 6 additions & 1 deletion app/OAuth/OAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@

class OAuthServiceProvider extends BaseServiceProvider
{
protected $provides = [
protected array $provides = [
OAuthService::class,
OAuthCallbackHandlerInterface::class,
OAuthUrlHelper::class,
];

public function provides(string $id): bool
{
return in_array($id, $this->provides, true);
}

public function register(): void
{
$this->addShared(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

class RequestTokenStorageServiceProvider extends BaseServiceProvider
{
protected $provides = [
protected array $provides = [
RequestTokenStorageInterface::class,
];

public function provides(string $id): bool
{
return in_array($id, $this->provides, true);
}

public function register(): void
{
$this->addShared(
Expand Down
7 changes: 6 additions & 1 deletion app/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ class RoutingServiceProvider extends BaseServiceProvider
{
public const AUTHORIZATION_PATH = '/authorize';

protected $provides = [
protected array $provides = [
Router::class,
];

public function provides(string $id): bool
{
return in_array($id, $this->provides, true);
}

public function register(): void
{
$this->add(
Expand Down

0 comments on commit cdae80e

Please sign in to comment.