diff --git a/.travis.sh b/.travis.sh new file mode 100755 index 0000000..5b1af47 --- /dev/null +++ b/.travis.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -ex +hhvm --version +curl https://getcomposer.org/installer | hhvm -d hhvm.jit=0 --php -- /dev/stdin --install-dir=/usr/local/bin --filename=composer + +cd /var/source +hhvm -d hhvm.php7.all=1 -d hhvm.jit=0 -d hhvm.hack.lang.auto_typecheck=0 /usr/local/bin/composer install + +hhvm -d hhvm.php7.all=1 -d hhvm.jit=0 -d hhvm.hack.lang.auto_typecheck=0 vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml index 47ed2e2..c75f8a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,17 @@ -language: php sudo: required -dist: trusty -php: - - hhvm - - hhvm-3.18 -install: composer install +language: generic +services: + - docker +env: + matrix: + - HHVM_VERSION=3.24-lts-latest + - HHVM_VERSION=3.25.3 + - HHVM_VERSION=3.26.0 + - HHVM_VERSION=latest + - HHVM_VERSION=nightly +install: + - docker pull hhvm/hhvm:$HHVM_VERSION script: - - hh_client - - hhvm vendor/bin/phpunit + - env | egrep '^(HHVM_VERSION|GITHUB_API_KEY|TRAVIS_EVENT_TYPE)=' > ./env-list + - docker run --env-file ./env-list -v $(pwd):/var/source hhvm/hhvm:$HHVM_VERSION /var/source/.travis.sh + \ No newline at end of file diff --git a/README.md b/README.md index 98c1f3d..701d73f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ simple light weight service location / dependency injection container ## Installation ```bash -$ hhvm --php $(which composer) require ytake/hh-container +$ hhvm $(which composer) require ytake/hh-container ``` ```json diff --git a/composer.json b/composer.json index 667f401..7627468 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ "container" ], "require": { - "hhvm": ">=3.12", - "hhvm/hhvm-autoload": "^1.5", + "hhvm": ">=3.24", + "hhvm/hhvm-autoload": "^1.6", "ytake/psr-container-hhi": "^1.0" }, "require-dev": { diff --git a/src/FactoryContainer.hh b/src/FactoryContainer.hh index 12cac1e..a45ea94 100644 --- a/src/FactoryContainer.hh +++ b/src/FactoryContainer.hh @@ -83,23 +83,23 @@ class FactoryContainer implements ContainerInterface { public function get($id): mixed { if ($this->has($id)) { $resolved = $this->bindings->get($id); - if (!is_null($resolved)) { + if (!\is_null($resolved)) { if ($this->scopes->get($id) === Scope::SINGLETON) { return $this->shared($id); } - return call_user_func($resolved, $this); + return \call_user_func($resolved, $this); } } try { $reflectionClass = new \ReflectionClass($id); if ($reflectionClass->isInstantiable()) { - $arguments = []; + $arguments = Vector{}; $constructor = $reflectionClass->getConstructor(); if ($constructor instanceof \ReflectionMethod) { $resolvedParameters = $this->resolveConstructorParameters($id, $constructor); - if (count($resolvedParameters)) { + if ($resolvedParameters->count()) { $arguments = $resolvedParameters; } } @@ -107,17 +107,10 @@ class FactoryContainer implements ContainerInterface { } } catch (\ReflectionException $e) { throw new NotFoundException( - sprintf('Identifier "%s" is not binding.', $id), + \sprintf('Identifier "%s" is not binding.', $id), ); } - throw new ContainerException(sprintf('Error retrieving "%s"', $id)); - } - - protected function resolveParameters( - string $id, - \ReflectionMethod $constructor, - ) : array { - return $this->resolveConstructorParameters($id, $constructor); + throw new ContainerException(\sprintf('Error retrieving "%s"', $id)); } <<__Memoize>> @@ -174,16 +167,16 @@ class FactoryContainer implements ContainerInterface { protected function resolveConstructorParameters( string $id, \ReflectionMethod $constructor, - ): array { - $r = []; + ): Vector { + $r = Vector{}; if ($parameters = $constructor->getParameters()) { foreach ($parameters as $parameter) { if (isset($this->parameters[$id])) { if (isset($this->parameters[$id][$parameter->getName()])) { - $r[] = call_user_func( + $r->add(call_user_func( $this->parameters[$id][$parameter->getName()], $this, - ); + )); } } } diff --git a/src/ServiceModule.hh b/src/ServiceModule.hh index db12c07..b61fc51 100644 --- a/src/ServiceModule.hh +++ b/src/ServiceModule.hh @@ -19,8 +19,6 @@ namespace Ytake\HHContainer; <<__ConsistentConstruct>> abstract class ServiceModule { - /** - * @param ContainerInterface $container - */ + abstract public function provide(FactoryContainer $container): void; } diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index 278fa5d..4727008 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -1,5 +1,8 @@ set('message.class', $container ==> new MockMessageClass('testing')); $container->parameters(MessageClient::class, 'message', $container ==> $container->get('message.class')); $instance = $container->get(MessageClient::class); @@ -101,11 +104,9 @@ public function testShouldResolveDependencyInjectionWithLocation(): void } } -class StubModule extends \Ytake\HHContainer\ServiceModule -{ - public function provide(\Ytake\HHContainer\FactoryContainer $container): void - { - $container->set('provide:sample', $container ==> new \stdClass()); +class StubModule extends ServiceModule { + public function provide(FactoryContainer $container): void { + $container->set(\stdClass::class, $container ==> new \stdClass()); } }