add encoding service

This commit is contained in:
Jaeger 2017-09-21 13:12:20 +08:00
parent 43d8f71678
commit ad9b493fc0
5 changed files with 57 additions and 8 deletions

View File

@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: Jaeger <JaegerCode@gmail.com>
* Date: 2017/9/21
*/
namespace QL\Exceptions;
use Exception;
class ServiceNotFoundException extends Exception
{
}

View File

@ -8,8 +8,9 @@
namespace QL;
use QL\Contracts\ServiceProviderContract;
use QL\Exceptions\ServiceNotFoundException;
use QL\Providers\EncodeServiceProvider;
use Closure;
class Kernel
{
@ -17,12 +18,22 @@ class Kernel
EncodeServiceProvider::class
];
protected $binds = [];
protected $binds;
protected $ql;
/**
* Kernel constructor.
* @param $ql
*/
public function __construct(QueryList $ql)
{
$this->ql = $ql;
$this->binds = collect();
}
public function bootstrap()
{
$this->registerProviders();
return $this;
}
@ -33,9 +44,17 @@ class Kernel
}
}
public function bind($name, $provider)
public function bind(string $name,Closure $provider)
{
$this->binds[$name] = value($provider);
$this->binds[$name] = $provider;
}
public function getBind(string $name)
{
if(!$this->binds->offsetExists($name)){
throw new ServiceNotFoundException("Service: {$name} not found!");
}
return $this->binds[$name];
}
private function register(ServiceProviderContract $instance)

View File

@ -15,8 +15,8 @@ class EncodeServiceProvider implements ServiceProviderContract
{
public function register(Kernel $kernel)
{
$kernel->bind('encoder',function (){
return new EncodeService();
$kernel->bind('encoding',function (string $outputEncoding,string $inputEncoding = null){
return EncodeService::convert($this,$outputEncoding,$inputEncoding);
});
}
}

View File

@ -28,9 +28,15 @@ class QueryList
*/
public function __construct()
{
$this->kernel = (new Kernel())->bootstrap();
$this->kernel = (new Kernel($this))->bootstrap();
}
public function __call($name, $arguments)
{
return $this->kernel->getBind($name)->call($this,...$arguments);
}
/**
* @return mixed
*/

View File

@ -8,6 +8,15 @@
namespace QL\Services;
class EncodeService
{
public static function convert($ql,string $outputEncoding,string $inputEncoding = null)
{
dump($outputEncoding,$inputEncoding);
return $ql;
}
public static function detect()
{
}
}