Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/php.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
name: php
on:
pull_request:
push:
jobs:
phptests:
runs-on: ${{ matrix.operating-system }}
environment: OCR
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['8.1', '8.2']
php-versions: ['8.1', '8.2', '8.3', '8.4']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -42,7 +41,7 @@ jobs:
fail-fast: false
matrix:
php-version:
- 8.2
- 8.1
dependencies:
- highest
steps:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"php": ">=8.1",
"guzzlehttp/guzzle": "^7.2",
"monolog/monolog": "^3.0",
"psr/log": "^2.0 || ^3.0",
"godruoyi/easy-container": "^2.0 || ^3.0",
"psr/simple-cache": "^2.0 || ^3.0",
"psr/log": "^3.0",
"godruoyi/easy-container": "^3.0",
"psr/simple-cache": "^3.0",
"symfony/cache": "^6.1",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^10.1",
"mockery/mockery": "^1.6",
"laravel/pint": "^1.10",
"laravel/pint": "^1.19",
"ext-gd": "*"
},
"autoload": {
Expand All @@ -36,7 +36,7 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"pint": "vendor/bin/pint"
"test": "vendor/bin/phpunit --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings",
"pint": "vendor/bin/pint --config=pint.json"
}
}
31 changes: 11 additions & 20 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,18 @@ class Application extends Manager
{
/**
* The container instance,.
*
* @var Container
*/
protected $container;
protected Container $container;

/**
* OCR configurage.
*
* @var array
* OCR configure.
*/
protected $config;
protected array|Config $config;

/**
* The default service providers.
*
* @var array
*/
protected $defaultProviders = [
protected array $defaultProviders = [
Providers\HttpServiceProvider::class,
Providers\LogServiceProvider::class,
Providers\CacheServiceProvider::class,
Expand All @@ -52,7 +46,7 @@ class Application extends Manager
*/
public function __construct(array $config = [])
{
$this->container = new Container();
$this->container = new Container;
$this->config = new Config($config);

$this->boot();
Expand All @@ -73,20 +67,19 @@ public function getContainer(): Container
*
* @throws Exception
*/
protected function boot()
protected function boot(): void
{
$this->registerCore();
$this->registerDefaultProvider();
}

/**
* Registe core alias and service.
* Register core alias and service.
*
* @return void
*
* @throws Exception
*/
protected function registerCore()
protected function registerCore(): void
{
$this->container->singleton('app', function ($app) {
return $app;
Expand All @@ -104,10 +97,8 @@ protected function registerCore()

/**
* Register default service provider.
*
* @return void
*/
protected function registerDefaultProvider()
protected function registerDefaultProvider(): void
{
foreach ($this->defaultProviders as $p) {
$this->register($p);
Expand All @@ -117,9 +108,9 @@ protected function registerDefaultProvider()
/**
* Register a service to container.
*
* @param mixed $service
* @throws Exception
*/
public function register($service)
public function register(mixed $service): void
{
if (is_string($service) && class_exists($service)) {
$service = $this->container->make($service);
Expand Down
82 changes: 41 additions & 41 deletions src/Clients/AliyunClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function __construct(AliyunRequest $request)
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* side N string 默认face,身份证正反面类型:face/back
* 参数 是否可选 类型 可选范围/说明
* side N string 默认face,身份证正反面类型:face/back
* @return array
*/
public function idcard($images, array $options = [])
Expand All @@ -96,7 +96,7 @@ public function idcard($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* side N string 默认face,行驶证正反面类型:face/back
* side N string 默认face,行驶证正反面类型:face/back
* @return array
*/
public function vehicle($images, array $options = [])
Expand All @@ -113,8 +113,8 @@ public function vehicle($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* side N string 默认face,驾驶证首页/副页:face/back
* 参数 是否可选 类型 可选范围/说明
* side N string 默认face,驾驶证首页/副页:face/back
* @return array
*/
public function driverLicense($images, array $options = [])
Expand All @@ -131,7 +131,7 @@ public function driverLicense($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* null
* null
* @return array
*/
public function businessLicense($images, array $options = [])
Expand All @@ -146,7 +146,7 @@ public function businessLicense($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* null
* null
* @return array
*/
public function bankCard($images, array $options = [])
Expand All @@ -161,7 +161,7 @@ public function bankCard($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* null
* null
* @return array
*/
public function businessCard($images, array $options = [])
Expand All @@ -176,7 +176,7 @@ public function businessCard($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* null
* null
* @return array
*/
public function passport($images, array $options = [])
Expand All @@ -191,11 +191,11 @@ public function passport($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* format N string format 输出格式html/json/xlsx
* dir_assure N bool 图片方向是否确定是正向的: true(确定)/false(不确定)
* line_less N bool 是否无线条: true(无线条,或者只有横线没有竖线)/false(有线条)
* skip_detection N bool 是否跳过检测,如果没有检测到表格,可以设置"skip_detection":true
* 参数 是否可选 类型 可选范围/说明
* format N string format 输出格式html/json/xlsx
* dir_assure N bool 图片方向是否确定是正向的: true(确定)/false(不确定)
* line_less N bool 是否无线条: true(无线条,或者只有横线没有竖线)/false(有线条)
* skip_detection N bool 是否跳过检测,如果没有检测到表格,可以设置"skip_detection":true
* @return array
*/
public function tableParse($images, array $options = [])
Expand All @@ -212,7 +212,7 @@ public function tableParse($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* 参数 是否可选 类型 可选范围/说明
* @return array
*/
public function vin($images, array $options = [])
Expand All @@ -227,7 +227,7 @@ public function vin($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* null
* null
* @return array
*/
public function trainTicket($images, array $options = [])
Expand All @@ -244,9 +244,9 @@ public function trainTicket($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* multi_crop N boolean 当设成true时,会做多crop预测,只有当多crop返回的结果一致,
* 并且置信度>0.9时,才返回结果
* 参数 是否可选 类型 可选范围/说明
* multi_crop N boolean 当设成true时,会做多crop预测,只有当多crop返回的结果一致,
* 并且置信度>0.9时,才返回结果
* @return array
*/
public function vehiclePlate($images, array $options = [])
Expand All @@ -263,12 +263,12 @@ public function vehiclePlate($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* min_size 16, 图片中文字的最小高度,单位像素
* output_prob true, 是否输出文字框的概率
* output_keypoints false, 是否输出文字框角点
* skip_detection false 是否跳过文字检测步骤直接进行文字识别
* without_predicting_direction false 是否关闭文字行方向预测
* 参数 是否可选 类型 可选范围/说明
* min_size 16, 图片中文字的最小高度,单位像素
* output_prob true, 是否输出文字框的概率
* output_keypoints false, 是否输出文字框角点
* skip_detection false 是否跳过文字检测步骤直接进行文字识别
* without_predicting_direction false 是否关闭文字行方向预测
* @return array
*/
public function general($images, array $options = [])
Expand All @@ -286,12 +286,12 @@ public function general($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* charInfo N bool 是否需要单字识别功能,默认不需要。 true:需要 false:不需要
* rotate N bool 是否需要自动旋转功能,默认不需要。 true:需要 false:不需要
* table N bool 是否需要表格识别功能,默认不需要。 true:需要 false:不需要
* sortPage N bool 字块返回顺序,false表示从左往右,从上到下的顺序,true表示从上到下,从左往右的顺序,默认false
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* charInfo N bool 是否需要单字识别功能,默认不需要。 true:需要 false:不需要
* rotate N bool 是否需要自动旋转功能,默认不需要。 true:需要 false:不需要
* table N bool 是否需要表格识别功能,默认不需要。 true:需要 false:不需要
* sortPage N bool 字块返回顺序,false表示从左往右,从上到下的顺序,true表示从上到下,从左往右的顺序,默认false
* @return array
*/
public function generalAdvanced($images, array $options = [])
Expand All @@ -316,7 +316,7 @@ public function generalAdvanced($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* 参数 是否可选 类型 可选范围/说明
* @return array
*/
public function invoice($images, array $options = [])
Expand All @@ -333,7 +333,7 @@ public function invoice($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* 参数 是否可选 类型 可选范围/说明
* @return array
*/
public function houseCert($images, array $options = [])
Expand All @@ -350,8 +350,8 @@ public function houseCert($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* @return array
*/
public function document($images, array $options = [])
Expand All @@ -368,8 +368,8 @@ public function document($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* @return array
*/
public function ugc($images, array $options = [])
Expand All @@ -386,8 +386,8 @@ public function ugc($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* @return array
*/
public function custom($images, array $options = [])
Expand All @@ -404,8 +404,8 @@ public function custom($images, array $options = [])
*
* @param string|SplFIleInfo $images
* @param array $options
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* 参数 是否可选 类型 可选范围/说明
* prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要
* @return array
*/
public function ecommerce($images, array $options = [])
Expand Down
6 changes: 3 additions & 3 deletions src/Clients/BaiduClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ public function asynTable($images, array $options = [])
* @see https://ai.baidu.com/ai-doc/OCR/Ik3h7y238
*
* @param string|\SplFileInfo $requestId
* @param array $requestType 期望获取结果的类型,取值为 “excel” 时返回 xls 文件的地址,
* 取值为 “json” 时返回 json 格式的字符串,默认为 ”excel”
* @param array $requestType 期望获取结果的类型,取值为 “excel” 时返回 xls 文件的地址,
* 取值为 “json” 时返回 json 格式的字符串,默认为 ”excel”
* @return array
*
* @throws \RuntimeException
*/
public function asynTableInfo(string $requestId, string $requestType = null)
public function asynTableInfo(string $requestId, ?string $requestType = null)
{
$uri = 'https://aip.baidubce.com/rest/2.0/solution/v1/form_ocr/get_request_result';

Expand Down
2 changes: 1 addition & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract public function getDefaultDriver();
/**
* Get a driver instance.
*/
public function driver(string $driver = null): Client
public function driver(?string $driver = null): Client
{
$driver = $driver ?: $this->getDefaultDriver();

Expand Down
2 changes: 1 addition & 1 deletion src/Providers/HttpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HttpServiceProvider implements ServiceProviderInterface
public function register(ContainerInterface $container)
{
$container->singleton('http', function ($app) {
$http = new Http();
$http = new Http;

$http->customHttpHandler($this->processHttpError());

Expand Down
Loading
Loading