Skip to content

Commit

Permalink
Merge pull request #9 from ytake/fixed/hhvm3.26-unbound-name-patch
Browse files Browse the repository at this point in the history
fixed unbound names
  • Loading branch information
ytake authored May 7, 2018
2 parents 12a2bdf + 6a68306 commit 8a94eb7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
9 changes: 9 additions & 0 deletions .travis.sh
Original file line number Diff line number Diff line change
@@ -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
23 changes: 15 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
27 changes: 10 additions & 17 deletions src/FactoryContainer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,41 +83,34 @@ 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;
}
}
return $reflectionClass->newInstanceArgs($arguments);
}
} 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<mixed> {
return $this->resolveConstructorParameters($id, $constructor);
throw new ContainerException(\sprintf('Error retrieving "%s"', $id));
}

<<__Memoize>>
Expand Down Expand Up @@ -174,16 +167,16 @@ class FactoryContainer implements ContainerInterface {
protected function resolveConstructorParameters(
string $id,
\ReflectionMethod $constructor,
): array<mixed> {
$r = [];
): Vector<mixed> {
$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,
);
));
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/ServiceModule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace Ytake\HHContainer;

<<__ConsistentConstruct>>
abstract class ServiceModule {
/**
* @param ContainerInterface $container
*/

abstract public function provide(FactoryContainer $container): void;
}
13 changes: 7 additions & 6 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?hh // strict

use Ytake\HHContainer\FactoryContainer;
use Ytake\HHContainer\ServiceModule;

final class ContainerTest extends \PHPUnit\Framework\TestCase
{
public function testShouldReturnPrimitiveTypes(): void
Expand Down Expand Up @@ -91,7 +94,7 @@ public function testShouldResolveConstructorPromotionInstance(): void

public function testShouldResolveDependencyInjectionWithLocation(): void
{
$container = new \Ytake\HHContainer\FactoryContainer();
$container = new FactoryContainer();
$container->set('message.class', $container ==> new MockMessageClass('testing'));
$container->parameters(MessageClient::class, 'message', $container ==> $container->get('message.class'));
$instance = $container->get(MessageClient::class);
Expand All @@ -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());
}
}

Expand Down

0 comments on commit 8a94eb7

Please sign in to comment.