add encoding service
This commit is contained in:
parent
43d8f71678
commit
ad9b493fc0
15
src/Exceptions/ServiceNotFoundException.php
Normal file
15
src/Exceptions/ServiceNotFoundException.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
@ -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)
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
@ -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
|
||||
*/
|
||||
|
@ -9,5 +9,14 @@ namespace QL\Services;
|
||||
|
||||
class EncodeService
|
||||
{
|
||||
public static function convert($ql,string $outputEncoding,string $inputEncoding = null)
|
||||
{
|
||||
dump($outputEncoding,$inputEncoding);
|
||||
return $ql;
|
||||
}
|
||||
|
||||
public static function detect()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user