Skip to content

Commit

Permalink
Merge pull request #16 from BapCat/master.php71
Browse files Browse the repository at this point in the history
Update to PHP 7.1
  • Loading branch information
LordMonoxide committed Jan 3, 2019
2 parents f41cd2d + 9376cf6 commit 906bf4f
Show file tree
Hide file tree
Showing 19 changed files with 420 additions and 422 deletions.
7 changes: 0 additions & 7 deletions .buildpath

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea/
report/
vendor/
composer.lock
.idea/
34 changes: 0 additions & 34 deletions .project

This file was deleted.

2 changes: 0 additions & 2 deletions .settings/org.eclipse.php.core.prefs

This file was deleted.

2 changes: 0 additions & 2 deletions .settings/org.eclipse.php.ui.prefs

This file was deleted.

7 changes: 0 additions & 7 deletions .settings/org.eclipse.wst.common.project.facet.core.xml

This file was deleted.

2 changes: 0 additions & 2 deletions .settings/org.eclipse.wst.validation.prefs

This file was deleted.

13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
language: php

php:
- 5.6
- 7.0
- hhvm
- 7.1
- 7.2

before_script:
- travis_retry composer self-update
- travis_retry composer install --prefer-source
- composer require satooshi/php-coveralls --prefer-source

script:
- mkdir -p build/logs
- ./test --coverage-clover build/logs/clover.xml
- phpunit --coverage-clover build/logs/clover.xml tests

after_script:
- php vendor/bin/coveralls -v
after_success:
- composer require php-coveralls/php-coveralls --prefer-source
- php vendor/bin/php-coveralls -v
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bapcat/phi",
"description": "A super-minimal inversion-of-control library",
"license": "GPLv3",
"license": "GPL-3.0-or-later",
"homepage": "http://github.com/BapCat/Phi",
"keywords": ["IOC", "Inversion of control", "DI", "Dependency injection"],
"authors": [
Expand All @@ -11,13 +11,13 @@
}
],
"require": {
"php": ">=5.5.0",
"bapcat/interfaces": "^1.1",
"raphhh/trex-reflection": "^0.1.1"
"php": "^7.1",
"raphhh/trex-reflection": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"bapcat/values": "^0.1.4"
"roave/security-advisories": "dev-master",
"phpunit/phpunit": "^7.5",
"bapcat/values": "^0.2"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 4 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>

<exclude>
<directory suffix=".php">vendor</directory>
</exclude>
</whitelist>
<exclude>
<directory suffix=".php">vendor</directory>
</exclude>
</filter>
</phpunit>
93 changes: 93 additions & 0 deletions src/Ioc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php declare(strict_types=1); namespace BapCat\Phi;

/**
* Dependency injection manager
*
* @author Corey Frenette
* @copyright Copyright (c) 2019, BapCat
*/
abstract class Ioc implements Resolver {
/** @var Ioc|null $instance Singleton instance */
private static $instance;

/**
* Accessor for singleton
*
* @return Ioc
*/
public static function instance(): Ioc {
if(self::$instance === null) {
self::$instance = new static();
}

return self::$instance;
}

/**
* @note This function automatically binds Ioc to itself
*/
private function __construct() {
$this->bind(__CLASS__, $this);
}

/**
* Binds a class to an alias
*
* @param string $alias An alias (eg. `db.helper`), or a real class or
* interface name to be replaced by `$binding`
* @param string|callable|object $binding May be one of the following:
* <ul>
* <li>The fully-qualified name of a class</li>
* <li>An instance of a class (creates a singleton)</li>
* <li>A callable that returns an instance of a class</li>
* </ul>
*
* @return void
*/
public abstract function bind(string $alias, $binding): void;

/**
* Binds a class to an alias as a lazy-loaded singleton
*
* @param string $alias An alias (eg. `db.helper`), or a real class or
* interface name to be replaced by `$binding`
* @param string|callable|object $binding May be one of the following:
* <ul>
* <li>The fully-qualified name of a class</li>
* <li>An instance of a class (creates a singleton)</li>
* <li>A callable that returns an instance of a class</li>
* </ul>
* @param array $arguments The arguments to pass to the binding when it is constructed
*
* @return void
*/
public abstract function singleton(string $alias, $binding, array $arguments = []): void;

/**
* Resolves an alias to a concrete class name
*
* @param string $alias An alias (eg. `db.helper`) to resolve back to a real class
*
* @return string|callable|object The concrete class registered to alias, or `$alias` if there is no binding
*/
public abstract function resolve(string $alias);

/**
* Adds a custom resolver to the IoC container
*
* @param Resolver $resolver The resolver to add
*
* @return void
*/
public abstract function addResolver(Resolver $resolver): void;

/**
* Executes a callable using dependency injection
*
* @param callable $call A callable to execute using dependency injection
* @param mixed[] $arguments The arguments to pass to the callable
*
* @return mixed The return value of the callable
*/
public abstract function call(callable $call, array $arguments = []);
}

0 comments on commit 906bf4f

Please sign in to comment.