Skip to content

Commit

Permalink
Merge pull request #12 from ytake/feature/patch-1
Browse files Browse the repository at this point in the history
oops
  • Loading branch information
ytake authored Aug 23, 2018
2 parents 17ad184 + a53adb4 commit cfdffd4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/FactoryContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use type Psr\Container\ContainerInterface;

enum Scope : int {
Prototype = 0;
Singleton = 1;
PROTOTYPE = 0;
SINGLETON = 1;
}

type TServiceModule = classname<ServiceModule>;
Expand Down Expand Up @@ -51,7 +51,7 @@ class FactoryContainer implements ContainerInterface {
public function set(
string $id,
TCallable $callback,
Scope $scope = Scope::Prototype,
Scope $scope = Scope::PROTOTYPE,
): void {
if (!$this->locked) {
$this->mapper->add(Pair {$id, Map{$scope => $callback}});
Expand All @@ -72,7 +72,7 @@ public function get($id): mixed {
if ($this->has($id)) {
$resolved = $this->mapper->get($id);
if (!is_null($resolved)) {
if ($resolved->firstKey() === Scope::Singleton) {
if ($resolved->firstKey() === Scope::SINGLETON) {
return $this->shared($id);
}
$callable = $resolved->firstValue();
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function registerFactory(FactoryInterface $factory): void {
public function create(string $factoryName): FactoryInterface::T {
$resolve = $this->factories->get($factoryName);
if (!is_null($resolve)) {
if ($resolve->scope() === Scope::Singleton) {
if ($resolve->scope() === Scope::SINGLETON) {
return $this->createShared($factoryName);
}
return $resolve->provide($this->container);
Expand Down
6 changes: 3 additions & 3 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testShouldReturnSingletonObject(): void
$container->set(
'testing:testing',
$container ==> new \stdClass(),
\Ytake\HHContainer\Scope::Singleton
\Ytake\HHContainer\Scope::SINGLETON
);
$this->assertInstanceOf(\stdClass::class, $container->get('testing:testing'));
$this->assertSame($container->get('testing:testing'), $container->get('testing:testing'));
Expand All @@ -36,7 +36,7 @@ public function testShouldReturnSingletonObject(): void
public function testShouldReturnPrototypeObject(): void
{
$container = new \Ytake\HHContainer\FactoryContainer();
$container->set('testing:testing', $container ==> new \stdClass(), \Ytake\HHContainer\Scope::Prototype);
$container->set('testing:testing', $container ==> new \stdClass(), \Ytake\HHContainer\Scope::PROTOTYPE);
$this->assertInstanceOf(\stdClass::class, $container->get('testing:testing'));
$this->assertNotSame($container->get('testing:testing'), $container->get('testing:testing'));
}
Expand All @@ -48,7 +48,7 @@ public function testShouldReturunResolveInstance(): void
$container->set(
'testing:testing',
$container ==> $container->get('testing'),
\Ytake\HHContainer\Scope::Prototype
\Ytake\HHContainer\Scope::PROTOTYPE
);
$this->assertSame(1, $container->get('testing:testing'));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function name(): string {
return 'testing';
}
public function scope(): Scope {
return Scope::Singleton;
return Scope::SINGLETON;
}
}

Expand All @@ -49,7 +49,7 @@ public function provide(FactoryContainer $_container): this::T {
}

public function scope(): Scope {
return Scope::Singleton;
return Scope::SINGLETON;
}

public function name(): string {
Expand Down

0 comments on commit cfdffd4

Please sign in to comment.