Commit 72734e7e by 叶明星
parents 49b3aa3d b54eb5f1
Showing with 3574 additions and 52 deletions
...@@ -2,6 +2,7 @@ APP_ENV=local ...@@ -2,6 +2,7 @@ APP_ENV=local
APP_DEBUG=true APP_DEBUG=true
APP_KEY= APP_KEY=
APP_TIMEZONE=PRC APP_TIMEZONE=PRC
DB_TIMEZONE=+08:00
//系统编码,用于生成错误码 //系统编码,用于生成错误码
SYSTEM_CODE=01 SYSTEM_CODE=01
...@@ -34,3 +35,8 @@ REDIS_READ_PORT=6379 ...@@ -34,3 +35,8 @@ REDIS_READ_PORT=6379
CACHE_DRIVER=file CACHE_DRIVER=file
QUEUE_DRIVER=sync QUEUE_DRIVER=sync
RABBIT_IP=192.168.1.237
RABBIT_PORT=5672
RABBIT_USER=huntadmin
RABBIT_PASS=jy2y2900
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
*/ */
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Model\Logic\CommonLogic;
use App\Http\Model\Logic\PackCheckLogic;
use App\Http\Model\Logic\PalletLogic; use App\Http\Model\Logic\PalletLogic;
use App\Http\Model\Logic\PickTaskLogic; use App\Http\Model\Logic\PickTaskLogic;
use App\Http\Model\OutStoreDetailModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class AdminOutstoreController extends Controller class AdminOutstoreController extends Controller
...@@ -40,6 +43,13 @@ class AdminOutstoreController extends Controller ...@@ -40,6 +43,13 @@ class AdminOutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
//获取需要修改的货品
if ($data['out_store_detail_id'] == 'all'){
$data['out_store_detail_id_arr'] = OutStoreDetailModel::where('out_store_id',$data['out_store_id'])->pluck('out_store_detail_id');
}else{
$data['out_store_detail_id_arr'] = [$data['out_store_detail_id']];
}
$returnData = (new PickTaskLogic())->confirmPick($data); $returnData = (new PickTaskLogic())->confirmPick($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data)); return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data));
...@@ -53,6 +63,12 @@ class AdminOutstoreController extends Controller ...@@ -53,6 +63,12 @@ class AdminOutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
//获取需要修改的货品
if ($data['out_store_detail_id'] == 'all'){
$data['out_store_detail_id_arr'] = OutStoreDetailModel::where('out_store_id',$data['out_store_id'])->pluck('out_store_detail_id');
}else{
$data['out_store_detail_id_arr'] = [$data['out_store_detail_id']];
}
$returnData = (new PickTaskLogic())->cancelPick($data); $returnData = (new PickTaskLogic())->cancelPick($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data)); return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data));
...@@ -65,6 +81,13 @@ class AdminOutstoreController extends Controller ...@@ -65,6 +81,13 @@ class AdminOutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
//获取需要修改的货品
if ($data['out_store_detail_id'] == 'all'){
$data['out_store_detail_id_arr'] = OutStoreDetailModel::where('out_store_id',$data['out_store_id'])->pluck('out_store_detail_id');
}else{
$data['out_store_detail_id_arr'] = [$data['out_store_detail_id']];
}
$returnData = (new PalletLogic())->confirmOutStore($data); $returnData = (new PalletLogic())->confirmOutStore($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data)); return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data));
...@@ -78,6 +101,13 @@ class AdminOutstoreController extends Controller ...@@ -78,6 +101,13 @@ class AdminOutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
//获取需要修改的货品
if ($data['out_store_detail_id'] == 'all'){
$data['out_store_detail_id_arr'] = OutStoreDetailModel::where('out_store_id',$data['out_store_id'])->pluck('out_store_detail_id');
}else{
$data['out_store_detail_id_arr'] = [$data['out_store_detail_id']];
}
$returnData = (new PalletLogic())->cancelOutStore($data); $returnData = (new PalletLogic())->cancelOutStore($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data)); return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data));
...@@ -111,6 +141,68 @@ class AdminOutstoreController extends Controller ...@@ -111,6 +141,68 @@ class AdminOutstoreController extends Controller
return $this->apiReturn($returnData); return $this->apiReturn($returnData);
} }
//装箱
public function right_pack_check($request)
{
$data = $request->all();
try{
$returnData = (new PackCheckLogic())->right_pack_check($data);
}catch (\Exception $exception){
return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data));
}
return $this->apiReturn($returnData);
}
//装卡板
public function palletActive($request)
{
$data = $request->all();
try{
$returnData = (new PalletLogic())->palletActive($data);
}catch (\Exception $exception){
return $this->apiReturn($exception->getMessage().'|jsondata='.json_encode($data));
}
return $this->apiReturn($returnData);
}
//获取箱子信息
public function get_box_info($request)
{
$data = $request->all();
try{
$returnData = (new PalletLogic())->getBoxInfo($data);
}catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101;
return $this->apiReturn($exception->getMessage());
}
return $this->apiReturn($returnData);
}
//获取卡板打印信息
public function print_pallet_info($request)
{
$data = $request->all();
try{
$returnData = (new PalletLogic())->print_pallet_info($data);
}catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101;
return $this->apiReturn($exception->getMessage());
}
return $this->apiReturn($returnData);
}
//获取拣货任务打印信息
public function print_pick_task_info($request)
{
$data = $request->all();
try{
$returnData = (new PalletLogic())->print_pick_task_info($data);
}catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101;
return $this->apiReturn($exception->getMessage());
}
return $this->apiReturn($returnData);
}
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ namespace App\Http\Controllers; ...@@ -10,6 +10,7 @@ namespace App\Http\Controllers;
use App\Http\Model\Logic\PalletLogic; use App\Http\Model\Logic\PalletLogic;
use App\Http\Model\Logic\PickTaskLogic; use App\Http\Model\Logic\PickTaskLogic;
use App\Http\Model\PickTaskDetailModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Model\Logic\OutStoreLogic; use App\Http\Model\Logic\OutStoreLogic;
class OutstoreController extends Controller class OutstoreController extends Controller
...@@ -69,6 +70,8 @@ class OutstoreController extends Controller ...@@ -69,6 +70,8 @@ class OutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
$outStoreDetailIdArr = PickTaskDetailModel::where('pick_task_detail_id',$data['pick_task_detail_id'])->pluck('out_store_detail_id');
$data['out_store_detail_id_arr'] = $outStoreDetailIdArr;
$returnData = (new PalletLogic())->confirmOutStore($data); $returnData = (new PalletLogic())->confirmOutStore($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101; if (empty(self::$errCode))self::$errCode=101;
...@@ -82,6 +85,9 @@ class OutstoreController extends Controller ...@@ -82,6 +85,9 @@ class OutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
//获取所有的out_store_detail_id
$outStoreDetailIdArr = PickTaskDetailModel::where('pick_task_detail_id',$data['pick_task_detail_id'])->pluck('out_store_detail_id');
$data['out_store_detail_id_arr'] = $outStoreDetailIdArr;
$returnData = (new PalletLogic())->cancelOutStore($data); $returnData = (new PalletLogic())->cancelOutStore($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101; if (empty(self::$errCode))self::$errCode=101;
...@@ -95,6 +101,7 @@ class OutstoreController extends Controller ...@@ -95,6 +101,7 @@ class OutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
$data['pick_task_detail_id_str'] = implode(',',$data['pick_task_detail_id']);
$returnData = (new PalletLogic())->deliverGoods($data); $returnData = (new PalletLogic())->deliverGoods($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101; if (empty(self::$errCode))self::$errCode=101;
...@@ -121,15 +128,20 @@ class OutstoreController extends Controller ...@@ -121,15 +128,20 @@ class OutstoreController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
$returnData = [ $returnData = (new PalletLogic())->getBoxInfo($data);
'box_sn'=>'XB12313', }catch (\Exception $exception){
'box_status'=>1, if (empty(self::$errCode))self::$errCode=101;
'detail'=>[ return $this->apiReturn($exception->getMessage());
['goods_name'=>'2131','number'=>1], }
['goods_name'=>'2131','number'=>1], return $this->apiReturn($returnData);
['goods_name'=>'2131','number'=>1], }
]
]; //获取箱子信息
public function get_pallet_info($request)
{
$data = $request->all();
try{
$returnData = (new PalletLogic())->getPalletInfo($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101; if (empty(self::$errCode))self::$errCode=101;
return $this->apiReturn($exception->getMessage()); return $this->apiReturn($exception->getMessage());
......
...@@ -7,8 +7,14 @@ ...@@ -7,8 +7,14 @@
*/ */
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Model\BoxModel;
use App\Http\Model\GoodsModel;
use App\Http\Model\Logic\CommonLogic; use App\Http\Model\Logic\CommonLogic;
use App\Http\Model\Logic\PickTaskLogic; use App\Http\Model\Logic\PickTaskLogic;
use App\Http\Model\OutStoreDetailModel;
use App\Http\Model\PalletModel;
use App\Http\Model\PickTaskDetailModel;
use App\Http\Model\PickTaskModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
...@@ -57,6 +63,28 @@ class PicktaskController extends Controller ...@@ -57,6 +63,28 @@ class PicktaskController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
//获取所有的out_store_detail_id
$goodsType = substr($data['goods_sn'],0,2);
$pickTaskId = PickTaskModel::where('pick_task_sn',$data['pick_task_sn'])->value('pick_task_id');
switch ($goodsType){
case 'KB':
$outStoreDetailIdArr = PalletModel::getWhereObj([])->where('pallet_sn',$data['goods_sn'])->value('pallet_id');
$outStoreDetailIdArr = OutStoreDetailModel::where('pick_task_id',$pickTaskId)->where('pallet_id',$outStoreDetailIdArr)->pluck('out_store_detail_id');
break;
case 'XB':
$outStoreDetailIdArr = BoxModel::where('box_sn',$data['goods_sn'])->value('box_id');
$outStoreDetailIdArr = OutStoreDetailModel::where('pick_task_id',$pickTaskId)->where('box_id',$outStoreDetailIdArr)->pluck('out_store_detail_id');
break;
default:
$outStoreDetailIdArr = GoodsModel::where('goods_name',$data['goods_sn'])->value('goods_id');
$outStoreDetailIdArr = OutStoreDetailModel::where('pick_task_id',$pickTaskId)->where('goods_id',$outStoreDetailIdArr)->pluck('out_store_detail_id');
break;
}
if (empty($outStoreDetailIdArr)){
throw new \Exception('该任务下没有这个型号');
}
$data['out_store_detail_id_arr'] = $outStoreDetailIdArr;
$returnData = (new PickTaskLogic())->confirmPick($data); $returnData = (new PickTaskLogic())->confirmPick($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101; if (empty(self::$errCode))self::$errCode=101;
...@@ -71,6 +99,15 @@ class PicktaskController extends Controller ...@@ -71,6 +99,15 @@ class PicktaskController extends Controller
{ {
$data = $request->all(); $data = $request->all();
try{ try{
//获取所有的out_store_detail_id
$outStoreDetailIdArr = PickTaskDetailModel::where('pick_task_detail_id',$data['pick_task_detail_id'])->pluck('out_store_detail_id');
if (empty($outStoreDetailIdArr)){
throw new \Exception('该任务下没有这个型号');
}
$data['out_store_detail_id_arr'] = $outStoreDetailIdArr;
$returnData = (new PickTaskLogic())->cancelPick($data); $returnData = (new PickTaskLogic())->cancelPick($data);
}catch (\Exception $exception){ }catch (\Exception $exception){
if (empty(self::$errCode))self::$errCode=101; if (empty(self::$errCode))self::$errCode=101;
......
<?php
/**
* Created by 2020/5/8.
* User: Joneq
* Info: 2020/5/8
* Time: 下午6:34
*/
namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
class BoxModel extends Model
{
protected $connection = 'mysql';
protected $table = 'box';
protected $primaryKey = 'box_id';
public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
}
\ No newline at end of file
...@@ -16,4 +16,9 @@ class GoodsModel extends Model ...@@ -16,4 +16,9 @@ class GoodsModel extends Model
protected $table = 'goods'; protected $table = 'goods';
protected $primaryKey = 'goods_id'; protected $primaryKey = 'goods_id';
public $timestamps = false; public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
} }
\ No newline at end of file
<?php
/**
* Created by 2020/5/9.
* User: Joneq
* Info: 2020/5/9
* Time: 上午11:15
*/
namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
class LocationModel extends Model
{
protected $connection = 'mysql';
protected $table = 'location';
protected $primaryKey = 'location_id';
public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
}
\ No newline at end of file
...@@ -10,9 +10,15 @@ namespace App\Http\Model\Logic; ...@@ -10,9 +10,15 @@ namespace App\Http\Model\Logic;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Model\OutStoreDetailModel;
use App\Http\Model\OutStoreModel;
use App\Http\Model\StoreModel;
use Bschmitt\Amqp\Facades\Amqp;
use Illuminate\Support\Facades\DB;
class CommonLogic class CommonLogic
{ {
static public $deliverType = [1=>'送货',2=>'自提',3=>'快递',4=>'陆运',5=>'空运',6=>'提货',7=>'转仓',8=>'海运'];
//检测值是否为空 //检测值是否为空
static public function checkEmpty($key,$data) static public function checkEmpty($key,$data)
...@@ -39,8 +45,7 @@ class CommonLogic ...@@ -39,8 +45,7 @@ class CommonLogic
static public function getHaveKeyCn($value) static public function getHaveKeyCn($value)
{ {
foreach ($value as $key=>$keyId){ foreach ($value as $key=>$keyId){
$cn = self::getSqlKeyCn($key,$keyId); if ( ($cn = self::getSqlKeyCn($key,$keyId)) !== false){
if (is_string($cn)){
$value[$key."_cn"] = $cn; $value[$key."_cn"] = $cn;
} }
} }
...@@ -50,17 +55,14 @@ class CommonLogic ...@@ -50,17 +55,14 @@ class CommonLogic
//获取sqlid的中文 //获取sqlid的中文
static public function getSqlKeyCn($key,$value) static public function getSqlKeyCn($key,$value)
{ {
$title = '';
switch ($key){ switch ($key){
case 'delivery_id'://发货人员 case 'delivery_id'://发货人员
case 'admin_id'://根据id获取人员姓名 case 'admin_id'://根据id获取人员姓名
case 'pick_user_id'://拣货人 case 'pick_user_id'://拣货人
case 'confirm_user_id'://确认人 case 'confirm_user_id'://确认人
$title='该人暂未录入'; $value = '暂未录入';break;
$value = 0;break;
case 'store_id'://根据仓库IDid获取名称 case 'store_id'://根据仓库IDid获取名称
$title='该仓库暂未录入'; $value = StoreModel::where('store_id',$value)->value("store_name");break;
$value = 0;break;
case 'out_store_status': case 'out_store_status':
$value = OutStoreLogic::getOutStoreStatus($value);break; $value = OutStoreLogic::getOutStoreStatus($value);break;
case 'receive_status': case 'receive_status':
...@@ -70,26 +72,21 @@ class CommonLogic ...@@ -70,26 +72,21 @@ class CommonLogic
case 'pack_status': case 'pack_status':
$value = PackCheckLogic::getStatus($value);break; $value = PackCheckLogic::getStatus($value);break;
case 'goods_id'://根据物料id获取物料编码 case 'goods_id'://根据物料id获取物料编码
$title='该物料暂未录入'; $value = DB::table('goods')->where('goods_id',$value)->value('goods_name');break;
$value = 0;break;
case 'delivery_type'://根据发货方式ID获取名称 case 'delivery_type'://根据发货方式ID获取名称
$title='该发货方式暂未录入'; $value = array_get(self::$deliverType,$value,'暂无该种发货方式');break;
$value = 0;break; case 'customer_id':
case 'goods_name'://获取型号方式 $value = DB::table('customer')->where('customer_id',$value)->value('customer_name');break;
$title='该型号暂未录入'; case 'brand_id'://根据品牌IDid获取名称
$value = 0;break; $value = DB::table('brand')->where('brand_id',$value)->value('brand_name');;break;
case 'brand_name'://根据品牌IDid获取名称
$title='该品牌暂未录入';
$value = 0;break;
case 'pallet_id'://根据卡板IDid获取名称box_id case 'pallet_id'://根据卡板IDid获取名称box_id
$title='该卡板暂未录入'; $value = DB::table('pallet')->where('pallet_id',$value)->value('pallet_sn');break;
$value = 0;break;
case 'box_id'://根据卡板IDid获取名称 case 'box_id'://根据卡板IDid获取名称
$title='该箱号暂未录入'; $value = DB::table('box')->where('box_id',$value)->value('box_sn');break;
$value = 0;break;
case 'location_id'://根据货位id获取名称 case 'location_id'://根据货位id获取名称
$title='该货位暂未录入'; $value = DB::table('location')->where('location_id',$value)->value('location_sn');break;
$value = 0;break; case 'country_code'://国家编码
$value = DB::table('country')->where('country_id',$value)->value('country');break;
case 'add_time': case 'add_time':
case 'last_update_time': case 'last_update_time':
case 'delivery_time': case 'delivery_time':
...@@ -98,16 +95,56 @@ class CommonLogic ...@@ -98,16 +95,56 @@ class CommonLogic
$value = self::getDataTime($value);break; $value = self::getDataTime($value);break;
case 'is_apply_customs': case 'is_apply_customs':
case 'is_need_pallet': case 'is_need_pallet':
case 'is_insp':
$value = $value?'是':'否';break; $value = $value?'是':'否';break;
case 'is_confirm': case 'is_confirm':
$value = $value?'已确认':'未确认';break; $value = $value?'已确认':'未确认';break;
default: default:
$value = false;
break; break;
} }
if ($title){
return $title;
}
return $value; return $value;
} }
static public function sendRabbitMq($outStoreDetailIdArr)
{
$outStoreArr = OutStoreDetailModel::whereIn('out_store_detail_id',$outStoreDetailIdArr)->pluck('out_store_id')->toArray();
foreach (array_filter($outStoreArr) as $key=>$value){
$outStoreInfo = OutStoreModel::getWhereObj([])->where('out_store_id',$value)->first()->toArray();
$outStoreDetailData = OutStoreDetailModel::getWhereObj([])
->where('out_store_id',$value)
->select('erp_entry_sn','number','box_id','pallet_id')
->get()
->toArray();
$json = [
'SyncName'=>'out_store',
'Data'=>[
'erp_store_id'=>$outStoreInfo['erp_out_store_id'],
'box_number'=>count(array_filter(array_column($outStoreDetailData,'box_id'))),
'pallet_number'=>count(array_filter(array_column($outStoreDetailData,'pallet_id'))),
'detail'=>$outStoreDetailData,
]
];
return Amqp::publish('store_audit_status', json_encode($json),[ 'queue' => 'store_audit_status', 'exchange' => 'store', 'exchange_type' => 'direct']);
}
}
static public function getAdminInfo()
{
$data = app('request')->all();
if (!isset($data['admin_id']) || !isset($data['store_id'])){
throw new \Exception('admin_id 或者 store_id 信息丢失');
}
return $data;
}
} }
\ No newline at end of file
...@@ -62,7 +62,7 @@ class OutStoreLogic ...@@ -62,7 +62,7 @@ class OutStoreLogic
if(!isset($data['out_store_detail']) || empty($data['out_store_detail'])){ if(!isset($data['out_store_detail']) || empty($data['out_store_detail'])){
Controller::$level = 5; Controller::$level = 5;
Controller::$errCode = 3; Controller::$errCode = 3;
throw new \Exception('库详情为空'); throw new \Exception('库详情为空');
} }
if (empty($data['customer_id'] = CustomerModel::where('erp_client_sn',$data['erp_client_sn'])->value('customer_id'))){ if (empty($data['customer_id'] = CustomerModel::where('erp_client_sn',$data['erp_client_sn'])->value('customer_id'))){
...@@ -99,19 +99,21 @@ class OutStoreLogic ...@@ -99,19 +99,21 @@ class OutStoreLogic
//获取erp的goodsid //获取erp的goodsid
if (empty($stockInfo = StockModel::where('goods_id',$goodsInfo->goods_id)->orderBy('stock_id','desc')->first())){ if (empty($stockInfo = StockModel::where('goods_id',$goodsInfo->goods_id)->where('warehousing_sn',$outStoreData['warehousing_sn'])->orderBy('stock_id','desc')->first())){
Controller::$level = 5; Controller::$level = 5;
Controller::$errCode = 4; Controller::$errCode = 4;
throw new \Exception('goods_id查询不到商品库存信息'.$goodsInfo->goods_id); throw new \Exception('goods_id查询不到商品库存信息'.$goodsInfo->goods_id);
} }
$value['goods_id'] = $goodsInfo->goods_id; $value['goods_id'] = $goodsInfo->goods_id;
$value['goods_name'] = $goodsInfo->goods_name;
$value['brand_id'] = $goodsInfo->brand_id; $value['brand_id'] = $goodsInfo->brand_id;
//TODO 定位数据获取 //TODO 定位数据获取
$value['box_id'] = $stockInfo->box_id; $value['box_id'] = $stockInfo->box_id;
$value['pallet_id'] = $stockInfo->pallet_id; $value['pallet_id'] = $stockInfo->pallet_id;
$value['location_id'] = $stockInfo->location_id;
$value['country_code'] = $stockInfo->country_id; $value['country_code'] = $stockInfo->country_id;
$value['batch'] = $stockInfo->batch; $value['batch'] = $stockInfo->batch;
...@@ -124,6 +126,7 @@ class OutStoreLogic ...@@ -124,6 +126,7 @@ class OutStoreLogic
$value['warehousing_sn'] = $outStoreData['warehousing_sn']; $value['warehousing_sn'] = $outStoreData['warehousing_sn'];
$value['out_store_sn'] = $outStoreData['out_store_sn']; $value['out_store_sn'] = $outStoreData['out_store_sn'];
$value['is_apply_customs'] = $outStoreData['is_apply_customs']; $value['is_apply_customs'] = $outStoreData['is_apply_customs'];
$value['store_id'] = $outStoreData['store_id'];
unset($value['brand_name']); unset($value['brand_name']);
return $value; return $value;
...@@ -146,11 +149,18 @@ class OutStoreLogic ...@@ -146,11 +149,18 @@ class OutStoreLogic
//新增出库单 //新增出库单
$outStoreId = $insertData['out_store_id'] = OutStoreModel::insertGetId($insertData); $outStoreId = $insertData['out_store_id'] = OutStoreModel::insertGetId($insertData);
//新增出库任务 //新增出库任务
$pickTaskId = PickTaskModel::insertGetId([
'pick_task_sn'=>PickTaskLogic::getPickTaskSn(),'warehousing_sn'=>$insertData['warehousing_sn'], //判断是否是报关单,是报关单就不生成
'out_store_id'=>$outStoreId,'store_id'=>$insertData['store_id'],//TODO if (empty($insertData['is_apply_customs'])){
'add_time'=>$insertData['add_time'] $pickTaskId = PickTaskModel::insertGetId([
]); 'pick_task_sn'=>PickTaskLogic::getPickTaskSn(),'warehousing_sn'=>$insertData['warehousing_sn'],
'out_store_id'=>$outStoreId,'store_id'=>$insertData['store_id'],
'add_time'=>$insertData['add_time']
]);
}else{
$pickTaskId = 0;
}
//判断是否商检,只要一个是就就是 //判断是否商检,只要一个是就就是
...@@ -168,7 +178,7 @@ class OutStoreLogic ...@@ -168,7 +178,7 @@ class OutStoreLogic
//is_apply_customs报关任务默认隐藏 //is_apply_customs报关任务默认隐藏
PickTaskDetailModel::insertGetId(PickTaskLogic::handleInsertData([ PickTaskDetailModel::insertGetId(PickTaskLogic::handleInsertData([
'out_store_id'=>$outStoreId,'out_store_detail_id'=>$outStoreDetailId, 'out_store_id'=>$outStoreId,'out_store_detail_id'=>$outStoreDetailId,'store_id'=>$insertData['store_id'],
'pick_task_id'=>$pickTaskId,'is_show'=>empty($insertData['is_apply_customs'])?1:0 'pick_task_id'=>$pickTaskId,'is_show'=>empty($insertData['is_apply_customs'])?1:0
])); ]));
} }
......
...@@ -9,6 +9,14 @@ ...@@ -9,6 +9,14 @@
namespace App\Http\Model\Logic; namespace App\Http\Model\Logic;
use App\Http\Model\BoxModel;
use App\Http\Model\GoodsModel;
use App\Http\Model\OutStoreDetailModel;
use App\Http\Model\OutStoreModel;
use App\Http\Model\PalletModel;
use App\Http\Model\PickTaskDetailModel;
use App\Http\Model\PickTaskModel;
class PackCheckLogic class PackCheckLogic
{ {
static public $statusCn = [ static public $statusCn = [
...@@ -23,4 +31,56 @@ class PackCheckLogic ...@@ -23,4 +31,56 @@ class PackCheckLogic
} }
return array_get(self::$statusCn,$status,'状态异常!!'); return array_get(self::$statusCn,$status,'状态异常!!');
} }
//获取出库仓号
static public function getPackCheckSn()
{
//CK+年后两位+月两位+日两位+10000
$beginTime = strtotime(date('Y-m-d'));
$endTime = $beginTime +86400;
$todayNum = $outStoreSn = OutStoreModel::where('add_time','>=',$beginTime)->where('add_time','<=',$endTime)->count('out_store_id');
if (empty($todayNum)){
$todayNum = 10000;
}else{
$todayNum += 100001;
}
return 'DB'.substr(date('Ymd'),2,6).$todayNum;
}
public function right_pack_check($data)
{
//获取所有的out_store_detail_id
$goodsType = substr($data['goods_name_box_id'],0,2);
$pickTaskId = PickTaskModel::where('pick_task_sn',$data['pick_task_sn'])->value('pick_task_id');
switch ($goodsType){
case 'KB':
$outStoreDetailIdArr = PalletModel::getWhereObj([])->where('pallet_sn',$data['goods_name_box_id'])->value('pallet_id');
$outStoreDetailIdArr = OutStoreDetailModel::where('pick_task_id',$pickTaskId)->where('pallet_id',$outStoreDetailIdArr)->pluck('out_store_detail_id');
break;
case 'XB':
$outStoreDetailIdArr = BoxModel::where('box_sn',$data['goods_name_box_id'])->value('box_id');
$outStoreDetailIdArr = OutStoreDetailModel::where('pick_task_id',$pickTaskId)->where('box_id',$outStoreDetailIdArr)->pluck('out_store_detail_id');
break;
default:
$outStoreDetailIdArr = GoodsModel::where('goods_name',$data['goods_name_box_id'])->value('goods_id');
$outStoreDetailIdArr = OutStoreDetailModel::where('pick_task_id',$pickTaskId)->where('goods_id',$outStoreDetailIdArr)->pluck('out_store_detail_id');
break;
}
if (empty($outStoreDetailIdArr)){
throw new \Exception('该拣货任务下没找到该型号');
}
//判断是否是未复核状态
$packStatus = PickTaskDetailModel::whereIn('out_store_detail_id',$outStoreDetailIdArr)->value('pack_status');
if ($packStatus !== 1 ){
throw new \Exception('该型号没有在未复核状态中');
}
PickTaskDetailModel::whereIn('out_store_detail_id',$outStoreDetailIdArr)->update(['pack_status'=>2]);
return [];
}
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ class OutStoreDetailModel extends Model ...@@ -20,7 +20,7 @@ class OutStoreDetailModel extends Model
static public function getWhereObj($data) static public function getWhereObj($data)
{ {
$obj = self::where('add_time','>=',0); $obj = self::where('store_id',app('request')->store_id);
foreach ($data as $key=>$value){ foreach ($data as $key=>$value){
if (empty($value))continue; if (empty($value))continue;
......
...@@ -16,4 +16,9 @@ class OutStoreModel extends Model ...@@ -16,4 +16,9 @@ class OutStoreModel extends Model
protected $table = 'out_store'; protected $table = 'out_store';
protected $primaryKey = 'out_store_id'; protected $primaryKey = 'out_store_id';
public $timestamps = false; public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
} }
\ No newline at end of file
<?php
/**
* Created by 2020/5/8.
* User: Joneq
* Info: 2020/5/8
* Time: 下午4:47
*/
namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
class PackCheckModel extends Model
{
protected $connection = 'mysql';
protected $table = 'pack_check';
protected $primaryKey = 'pack_check_id';
public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
}
\ No newline at end of file
...@@ -16,4 +16,9 @@ class PalletModel extends Model ...@@ -16,4 +16,9 @@ class PalletModel extends Model
protected $table = 'pallet'; protected $table = 'pallet';
protected $primaryKey = 'pallet_id'; protected $primaryKey = 'pallet_id';
public $timestamps = false; public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
} }
\ No newline at end of file
...@@ -20,8 +20,7 @@ class PickTaskDetailModel extends Model ...@@ -20,8 +20,7 @@ class PickTaskDetailModel extends Model
static public function getWhereObj($data) static public function getWhereObj($data)
{ {
$obj = self::where('add_time','>=',0)->where('is_del',0); $obj = self::where('store_id','=',app('request')->store_id)->where('is_del',0);
foreach ($data as $key=>$value){ foreach ($data as $key=>$value){
if (empty($value))continue; if (empty($value))continue;
......
...@@ -17,4 +17,9 @@ class PickTaskModel extends Model ...@@ -17,4 +17,9 @@ class PickTaskModel extends Model
protected $primaryKey = 'pick_task_id'; protected $primaryKey = 'pick_task_id';
public $timestamps = false; public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
} }
\ No newline at end of file
<?php
/**
* Created by 2020/4/26.
* User: Joneq
* Info: 2020/4/26
* Time: 下午5:47
*/
namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
class StockFrozenModel extends Model
{
protected $connection = 'mysql';
protected $table = 'stock_frozen';
protected $primaryKey = 'stock_frozen_id';
public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
}
\ No newline at end of file
...@@ -17,4 +17,9 @@ class StockModel extends Model ...@@ -17,4 +17,9 @@ class StockModel extends Model
protected $primaryKey = 'stock_id'; protected $primaryKey = 'stock_id';
public $timestamps = false; public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
} }
\ No newline at end of file
...@@ -16,4 +16,9 @@ class StoreModel extends Model ...@@ -16,4 +16,9 @@ class StoreModel extends Model
protected $table = 'store'; protected $table = 'store';
protected $primaryKey = 'store_id'; protected $primaryKey = 'store_id';
public $timestamps = false; public $timestamps = false;
static public function getWhereObj($data)
{
return $obj = self::where('store_id','=',app('request')->store_id);
}
} }
\ No newline at end of file
...@@ -85,6 +85,7 @@ $app->middleware([ ...@@ -85,6 +85,7 @@ $app->middleware([
// $app->register(App\Providers\EventServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class);
$app->register(Illuminate\Redis\RedisServiceProvider::class); $app->register(Illuminate\Redis\RedisServiceProvider::class);
$app->register(Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class); $app->register(Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class);
$app->register(Bschmitt\Amqp\LumenServiceProvider::class);
$app->withEloquent(); $app->withEloquent();
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -99,6 +100,9 @@ $app->withEloquent(); ...@@ -99,6 +100,9 @@ $app->withEloquent();
$app->configure('website'); $app->configure('website');
$app->configure('database'); $app->configure('database');
$app->configure('errmsg'); $app->configure('errmsg');
$app->configure('amqp');
LogReport::$suffix = '_'.env('LARAVELS_LISTEN_PORT', ''); LogReport::$suffix = '_'.env('LARAVELS_LISTEN_PORT', '');
LogReport::$app_name = env('ELK_NAME',''); LogReport::$app_name = env('ELK_NAME','');
LogReport::$log_path = realpath(__DIR__ . '/../').'/storage/logs/LogReport/'; LogReport::$log_path = realpath(__DIR__ . '/../').'/storage/logs/LogReport/';
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
"vlucas/phpdotenv": "~2.2", "vlucas/phpdotenv": "~2.2",
"predis/predis": "^1.1", "predis/predis": "^1.1",
"illuminate/redis": "^5.5", "illuminate/redis": "^5.5",
"hhxsv5/laravel-s": "~3.4.0" "hhxsv5/laravel-s": "~3.4.0",
"bschmitt/laravel-amqp": "^2.0"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "~1.4", "fzaninotto/faker": "~1.4",
......
...@@ -4,9 +4,81 @@ ...@@ -4,9 +4,81 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "24ecf32eb4f7ae70431c9f0bc833bed1", "content-hash": "494c777571a6f30c0a000f63b9861a38",
"packages": [ "packages": [
{ {
"name": "bschmitt/laravel-amqp",
"version": "2.0.8",
"source": {
"type": "git",
"url": "https://github.com/bschmitt/laravel-amqp.git",
"reference": "66a3db685913093cb7e4fd39020ffc8c2db1e767"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bschmitt/laravel-amqp/zipball/66a3db685913093cb7e4fd39020ffc8c2db1e767",
"reference": "66a3db685913093cb7e4fd39020ffc8c2db1e767",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"illuminate/support": ">=v5.5.28",
"php": ">=7.0",
"php-amqplib/php-amqplib": ">=2.9"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "^3.0@dev"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Bschmitt\\Amqp\\AmqpServiceProvider"
],
"aliases": {
"Amqp": "Bschmitt\\Amqp\\Facades\\Amqp"
}
}
},
"autoload": {
"psr-4": {
"Bschmitt\\Amqp\\": "src/",
"Bschmitt\\Amqp\\Test\\": "test/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Björn Schmitt",
"email": "code@bjoern.io"
}
],
"description": "AMQP wrapper for Laravel and Lumen to publish and consume messages",
"keywords": [
"AMQP",
"Björn Schmitt",
"bschmitt",
"laravel",
"laravel5",
"lumen",
"message queue",
"package",
"queue",
"rabbitmq"
],
"time": "2019-08-29T16:11:19+00:00"
},
{
"name": "doctrine/inflector", "name": "doctrine/inflector",
"version": "1.3.1", "version": "1.3.1",
"source": { "source": {
...@@ -1847,6 +1919,187 @@ ...@@ -1847,6 +1919,187 @@
"time": "2018-07-02T15:55:56+00:00" "time": "2018-07-02T15:55:56+00:00"
}, },
{ {
"name": "php-amqplib/php-amqplib",
"version": "v2.11.2",
"source": {
"type": "git",
"url": "https://github.com/php-amqplib/php-amqplib.git",
"reference": "bd1c7b976d1ec19a542ad89d9a3d155a8f9f7687"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/bd1c7b976d1ec19a542ad89d9a3d155a8f9f7687",
"reference": "bd1c7b976d1ec19a542ad89d9a3d155a8f9f7687",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"ext-mbstring": "*",
"ext-sockets": "*",
"php": ">=5.6.3",
"phpseclib/phpseclib": "^2.0.0"
},
"conflict": {
"php": "7.4.0 - 7.4.1"
},
"replace": {
"videlalvaro/php-amqplib": "self.version"
},
"require-dev": {
"ext-curl": "*",
"nategood/httpful": "^0.2.20",
"phpunit/phpunit": "^5.7|^6.5|^7.0",
"squizlabs/php_codesniffer": "^2.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.11-dev"
}
},
"autoload": {
"psr-4": {
"PhpAmqpLib\\": "PhpAmqpLib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-or-later"
],
"authors": [
{
"name": "Alvaro Videla",
"role": "Original Maintainer"
},
{
"name": "John Kelly",
"email": "johnmkelly86@gmail.com",
"role": "Maintainer"
},
{
"name": "Raúl Araya",
"email": "nubeiro@gmail.com",
"role": "Maintainer"
},
{
"name": "Luke Bakken",
"email": "luke@bakken.io",
"role": "Maintainer"
}
],
"description": "Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.",
"homepage": "https://github.com/php-amqplib/php-amqplib/",
"keywords": [
"message",
"queue",
"rabbitmq"
],
"time": "2020-04-30T13:18:50+00:00"
},
{
"name": "phpseclib/phpseclib",
"version": "2.0.27",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc",
"reference": "34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phing/phing": "~2.7",
"phpunit/phpunit": "^4.8.35|^5.7|^6.0",
"sami/sami": "~2.0",
"squizlabs/php_codesniffer": "~2.0"
},
"suggest": {
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"type": "library",
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib\\": "phpseclib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Wigginton",
"email": "terrafrost@php.net",
"role": "Lead Developer"
},
{
"name": "Patrick Monnerat",
"email": "pm@datasphere.ch",
"role": "Developer"
},
{
"name": "Andreas Fischer",
"email": "bantu@phpbb.com",
"role": "Developer"
},
{
"name": "Hans-Jürgen Petrich",
"email": "petrich@tronic-media.com",
"role": "Developer"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
}
],
"description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
"homepage": "http://phpseclib.sourceforge.net",
"keywords": [
"BigInteger",
"aes",
"asn.1",
"asn1",
"blowfish",
"crypto",
"cryptography",
"encryption",
"rsa",
"security",
"sftp",
"signature",
"signing",
"ssh",
"twofish",
"x.509",
"x509"
],
"time": "2020-04-04T23:17:33+00:00"
},
{
"name": "predis/predis", "name": "predis/predis",
"version": "v1.1.1", "version": "v1.1.1",
"source": { "source": {
......
<?php
return [
'use' => 'production',
'properties' => [
'production' => [
'host' => env('RABBIT_IP'),
'port' => 5672,
'username' => env('RABBIT_USER'),
'password' => env('RABBIT_PASS'),
'vhost' => '/',
'connect_options' => [],
'ssl_options' => [],
'exchange' => 'amq.topic',
'exchange_type' => 'topic',
'exchange_passive' => false,
'exchange_durable' => true,
'exchange_auto_delete' => false,
'exchange_internal' => false,
'exchange_nowait' => false,
'exchange_properties' => [],
'queue_force_declare' => false,
'queue_passive' => false,
'queue_durable' => true,
'queue_exclusive' => false,
'queue_auto_delete' => false,
'queue_nowait' => false,
'queue_properties' => [],
'consumer_tag' => '',
'consumer_no_local' => false,
'consumer_no_ack' => false,
'consumer_exclusive' => false,
'consumer_nowait' => false,
'timeout' => 0,
'persistent' => false,
'qos' => false,
'qos_prefetch_size' => 0,
'qos_prefetch_count' => 1,
'qos_a_global' => false
],
],
];
\ No newline at end of file
{"server":{"listen_ip":"0.0.0.0","listen_port":"40003","socket_type":1,"enable_coroutine_runtime":false,"server":"LaravelS","handle_static":false,"laravel_base_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service","inotify_reload":{"enable":false,"watch_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service","file_types":[".php"],"excluded_dirs":[],"log":true},"event_handlers":[],"websocket":{"enable":false},"sockets":[],"processes":[],"timer":{"enable":false,"jobs":[],"pid_file":"/usr/local/var/www/ichunt/scm_wms_outstore_service/storage/laravels-timer.pid","max_wait_time":5},"events":[],"swoole_tables":[],"register_providers":[],"cleaners":[],"swoole":{"daemonize":false,"dispatch_mode":2,"reactor_num":4,"worker_num":"3","task_ipc_mode":1,"task_max_request":8000,"task_tmpdir":"/tmp","max_request":8000,"open_tcp_nodelay":true,"pid_file":"/usr/local/var/www/ichunt/scm_wms_outstore_service/storage/laravels.pid","log_file":"/usr/local/var/www/ichunt/scm_wms_outstore_service/storage/logs/swoole-2020-05.log","log_level":4,"document_root":"/usr/local/var/www/ichunt/scm_wms_outstore_service/public","buffer_output_size":2097152,"socket_buffer_size":134217728,"package_max_length":4194304,"reload_async":true,"max_wait_time":60,"enable_reuse_port":true,"enable_coroutine":false,"http_compression":false},"enable_gzip":false,"process_prefix":"/usr/local/var/www/ichunt/scm_wms_outstore_service","ignore_check_pid":false},"laravel":{"root_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service","static_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service/public","cleaners":[],"register_providers":[],"is_lumen":true,"_SERVER":{"SHELL":"/bin/bash","TERM":"xterm-256color","HOMEBREW_BOTTLE_DOMAIN":"https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles","TMPDIR":"/var/folders/vd/95yw3kdx65n1qw9ggmkkkp7c0000gn/T/","Apple_PubSub_Socket_Render":"/private/tmp/com.apple.launchd.y4PHUvRYlF/Render","USER":"gongyang","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.MXRCxiKd63/Listeners","__CF_USER_TEXT_ENCODING":"0x1F5:0x19:0x34","PATH":"/usr/local/opt/mysql@5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin","_":"/usr/bin/php","PWD":"/usr/local/var/www/ichunt/scm_wms_outstore_service","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"0","HOME":"/Users/gongyang","SHLVL":"2","LOGNAME":"gongyang","LC_CTYPE":"zh_CN.UTF-8","PHP_SELF":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","SCRIPT_NAME":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","SCRIPT_FILENAME":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","PATH_TRANSLATED":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","DOCUMENT_ROOT":"","REQUEST_TIME_FLOAT":1588906010.009845,"REQUEST_TIME":1588906010,"argv":["/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","laravels","config"],"argc":3,"APP_ENV":"local","APP_DEBUG":"true","APP_KEY":"","APP_TIMEZONE":"PRC","SYSTEM_CODE":"01","SYSTEM_NAME":"服务初始服务(开发环境)","LARAVELS_LISTEN_IP":"0.0.0.0","LARAVELS_LISTEN_PORT":"40003","worker_num":"3","DB_CONNECTION":"mysql","DB_HOST":"192.168.2.232","DB_USERNAME":"liexin_scm_wms","DB_PASSWORD":"liexin_scm_wms#zsyM","DB_PORT":"3306","DB_DATABASE":"liexin_scm_wms","DB_PREFIX":"lie_","REDIS_HOST":"192.168.1.235","REDIS_PASSWORD":"icDb29mLy2s","REDIS_PORT":"6379","REDIS_READ_HOST":"192.168.1.237","REDIS_READ_PASSWORD":"icDb29mLy2s","REDIS_READ_PORT":"6379","CACHE_DRIVER":"file","QUEUE_DRIVER":"sync","SHELL_VERBOSITY":0},"_ENV":{"APP_ENV":"local","APP_DEBUG":"true","APP_KEY":"","APP_TIMEZONE":"PRC","SYSTEM_CODE":"01","SYSTEM_NAME":"服务初始服务(开发环境)","LARAVELS_LISTEN_IP":"0.0.0.0","LARAVELS_LISTEN_PORT":"40003","worker_num":"3","DB_CONNECTION":"mysql","DB_HOST":"192.168.2.232","DB_USERNAME":"liexin_scm_wms","DB_PASSWORD":"liexin_scm_wms#zsyM","DB_PORT":"3306","DB_DATABASE":"liexin_scm_wms","DB_PREFIX":"lie_","REDIS_HOST":"192.168.1.235","REDIS_PASSWORD":"icDb29mLy2s","REDIS_PORT":"6379","REDIS_READ_HOST":"192.168.1.237","REDIS_READ_PASSWORD":"icDb29mLy2s","REDIS_READ_PORT":"6379","CACHE_DRIVER":"file","QUEUE_DRIVER":"sync","SHELL_VERBOSITY":0}}} {"server":{"listen_ip":"0.0.0.0","listen_port":"40003","socket_type":1,"enable_coroutine_runtime":false,"server":"LaravelS","handle_static":false,"laravel_base_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service","inotify_reload":{"enable":false,"watch_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service","file_types":[".php"],"excluded_dirs":[],"log":true},"event_handlers":[],"websocket":{"enable":false},"sockets":[],"processes":[],"timer":{"enable":false,"jobs":[],"pid_file":"/usr/local/var/www/ichunt/scm_wms_outstore_service/storage/laravels-timer.pid","max_wait_time":5},"events":[],"swoole_tables":[],"register_providers":[],"cleaners":[],"swoole":{"daemonize":false,"dispatch_mode":2,"reactor_num":4,"worker_num":"3","task_ipc_mode":1,"task_max_request":8000,"task_tmpdir":"/tmp","max_request":8000,"open_tcp_nodelay":true,"pid_file":"/usr/local/var/www/ichunt/scm_wms_outstore_service/storage/laravels.pid","log_file":"/usr/local/var/www/ichunt/scm_wms_outstore_service/storage/logs/swoole-2020-05.log","log_level":4,"document_root":"/usr/local/var/www/ichunt/scm_wms_outstore_service/public","buffer_output_size":2097152,"socket_buffer_size":134217728,"package_max_length":4194304,"reload_async":true,"max_wait_time":60,"enable_reuse_port":true,"enable_coroutine":false,"http_compression":false},"enable_gzip":false,"process_prefix":"/usr/local/var/www/ichunt/scm_wms_outstore_service","ignore_check_pid":false},"laravel":{"root_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service","static_path":"/usr/local/var/www/ichunt/scm_wms_outstore_service/public","cleaners":[],"register_providers":[],"is_lumen":true,"_SERVER":{"SHELL":"/bin/bash","TERM":"xterm-256color","HOMEBREW_BOTTLE_DOMAIN":"https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles","TMPDIR":"/var/folders/vd/95yw3kdx65n1qw9ggmkkkp7c0000gn/T/","Apple_PubSub_Socket_Render":"/private/tmp/com.apple.launchd.wWtj0v7Agw/Render","USER":"gongyang","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.tXmktxiIKD/Listeners","__CF_USER_TEXT_ENCODING":"0x1F5:0x19:0x34","PATH":"/usr/local/opt/mysql@5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin","_":"/usr/bin/php","PWD":"/usr/local/var/www/ichunt/scm_wms_outstore_service","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"0","HOME":"/Users/gongyang","SHLVL":"2","LOGNAME":"gongyang","LC_CTYPE":"zh_CN.UTF-8","PHP_SELF":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","SCRIPT_NAME":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","SCRIPT_FILENAME":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","PATH_TRANSLATED":"/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","DOCUMENT_ROOT":"","REQUEST_TIME_FLOAT":1589425564.966995,"REQUEST_TIME":1589425564,"argv":["/usr/local/var/www/ichunt/scm_wms_outstore_service/artisan","laravels","config"],"argc":3,"APP_ENV":"local","APP_DEBUG":"true","APP_KEY":"","APP_TIMEZONE":"PRC","DB_TIMEZONE":"+08:00","SYSTEM_CODE":"01","SYSTEM_NAME":"服务初始服务(开发环境)","LARAVELS_LISTEN_IP":"0.0.0.0","LARAVELS_LISTEN_PORT":"40003","worker_num":"3","DB_CONNECTION":"mysql","DB_HOST":"192.168.2.232","DB_USERNAME":"liexin_scm_wms","DB_PASSWORD":"liexin_scm_wms#zsyM","DB_PORT":"3306","DB_DATABASE":"liexin_scm_wms","DB_PREFIX":"lie_","REDIS_HOST":"192.168.1.235","REDIS_PASSWORD":"icDb29mLy2s","REDIS_PORT":"6379","REDIS_READ_HOST":"192.168.1.237","REDIS_READ_PASSWORD":"icDb29mLy2s","REDIS_READ_PORT":"6379","CACHE_DRIVER":"file","QUEUE_DRIVER":"sync","RABBIT_IP":"192.168.1.237","RABBIT_PORT":"5672","RABBIT_USER":"huntadmin","RABBIT_PASS":"jy2y2900","SHELL_VERBOSITY":0},"_ENV":{"APP_ENV":"local","APP_DEBUG":"true","APP_KEY":"","APP_TIMEZONE":"PRC","DB_TIMEZONE":"+08:00","SYSTEM_CODE":"01","SYSTEM_NAME":"服务初始服务(开发环境)","LARAVELS_LISTEN_IP":"0.0.0.0","LARAVELS_LISTEN_PORT":"40003","worker_num":"3","DB_CONNECTION":"mysql","DB_HOST":"192.168.2.232","DB_USERNAME":"liexin_scm_wms","DB_PASSWORD":"liexin_scm_wms#zsyM","DB_PORT":"3306","DB_DATABASE":"liexin_scm_wms","DB_PREFIX":"lie_","REDIS_HOST":"192.168.1.235","REDIS_PASSWORD":"icDb29mLy2s","REDIS_PORT":"6379","REDIS_READ_HOST":"192.168.1.237","REDIS_READ_PASSWORD":"icDb29mLy2s","REDIS_READ_PORT":"6379","CACHE_DRIVER":"file","QUEUE_DRIVER":"sync","RABBIT_IP":"192.168.1.237","RABBIT_PORT":"5672","RABBIT_USER":"huntadmin","RABBIT_PASS":"jy2y2900","SHELL_VERBOSITY":0}}}
\ No newline at end of file \ No newline at end of file
16100 74392
\ No newline at end of file \ No newline at end of file
/.idea
/vendor
composer.lock
\ No newline at end of file
language: php
php:
- 7.0
- 7.1
before_script:
- composer self-update
- composer install --prefer-source --no-interaction --dev
# script: build.sh
# script: phpunit --configuration phpunit.xml --coverage-text
The MIT License (MIT)
Copyright (c) 2015 Björn Schmitt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# bschmitt/laravel-amqp
AMQP wrapper for Laravel and Lumen to publish and consume messages especially from RabbitMQ
[![Build Status](https://travis-ci.org/bschmitt/laravel-amqp.svg?branch=master)](https://travis-ci.org/bschmitt/laravel-amqp)
[![Latest Stable Version](https://poser.pugx.org/bschmitt/laravel-amqp/v/stable.svg)](https://packagist.org/packages/bschmitt/laravel-amqp)
[![License](https://poser.pugx.org/bschmitt/laravel-amqp/license.svg)](https://packagist.org/packages/bschmitt/laravel-amqp)
## Features
- Advanced queue configuration
- Add message to queues easily
- Listen queues with useful options
## Installation
### Composer
Add the following to your require part within the composer.json:
```js
"bschmitt/laravel-amqp": "2.*" (Laravel >= 5.5)
"bschmitt/laravel-amqp": "1.*" (Laravel < 5.5)
```
```batch
$ php composer update
```
or
```
$ php composer require bschmitt/laravel-amqp
```
## Integration
### Lumen
Create a **config** folder in the root directory of your Lumen application and copy the content
from **vendor/bschmitt/laravel-amqp/config/amqp.php** to **config/amqp.php**.
Adjust the properties to your needs.
```php
return [
'use' => 'production',
'properties' => [
'production' => [
'host' => 'localhost',
'port' => 5672,
'username' => 'username',
'password' => 'password',
'vhost' => '/',
'exchange' => 'amq.topic',
'exchange_type' => 'topic',
'consumer_tag' => 'consumer',
'ssl_options' => [], // See https://secure.php.net/manual/en/context.ssl.php
'connect_options' => [], // See https://github.com/php-amqplib/php-amqplib/blob/master/PhpAmqpLib/Connection/AMQPSSLConnection.php
'queue_properties' => ['x-ha-policy' => ['S', 'all']],
'exchange_properties' => [],
'timeout' => 0
],
],
];
```
Register the Lumen Service Provider in **bootstrap/app.php**:
```php
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
*/
//...
$app->configure('amqp');
$app->register(Bschmitt\Amqp\LumenServiceProvider::class);
//...
```
Add Facade Support for Lumen 5.2+
```php
//...
$app->withFacades();
class_alias(\Illuminate\Support\Facades\App::class, 'App');
//...
```
### Laravel
Open **config/app.php** and add the service provider and alias:
```php
'Bschmitt\Amqp\AmqpServiceProvider',
```
```php
'Amqp' => 'Bschmitt\Amqp\Facades\Amqp',
```
## Publishing a message
### Push message with routing key
```php
Amqp::publish('routing-key', 'message');
```
### Push message with routing key and create queue
```php
Amqp::publish('routing-key', 'message' , ['queue' => 'queue-name']);
```
### Push message with routing key and overwrite properties
```php
Amqp::publish('routing-key', 'message' , ['exchange' => 'amq.direct']);
```
## Consuming messages
### Consume messages, acknowledge and stop when no message is left
```php
Amqp::consume('queue-name', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
$resolver->stopWhenProcessed();
});
```
### Consume messages forever
```php
Amqp::consume('queue-name', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
});
```
### Consume messages, with custom settings
```php
Amqp::consume('queue-name', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
}, [
'timeout' => 2,
'vhost' => 'vhost3'
]);
```
## Fanout example
### Publishing a message
```php
\Amqp::publish('', 'message' , [
'exchange_type' => 'fanout',
'exchange' => 'amq.fanout',
]);
```
### Consuming messages
```php
\Amqp::consume('', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
}, [
'exchange' => 'amq.fanout',
'exchange_type' => 'fanout',
'queue_force_declare' => true,
'queue_exclusive' => true,
'persistent' => true// required if you want to listen forever
]);
```
## Credits
* Some concepts were used from https://github.com/mookofe/tail
## License
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
{
"name": "bschmitt/laravel-amqp",
"description": "AMQP wrapper for Laravel and Lumen to publish and consume messages",
"keywords": [
"laravel",
"lumen",
"laravel5",
"rabbitmq",
"amqp",
"queue",
"package",
"message queue",
"Björn Schmitt",
"bschmitt"
],
"license": "MIT",
"support": {
"issues": "https://github.com/bschmitt/laravel-amqp/issues",
"source": "https://github.com/bschmitt/laravel-amqp"
},
"authors": [
{
"name": "Björn Schmitt",
"email": "code@bjoern.io"
}
],
"require": {
"php": ">=7.0",
"php-amqplib/php-amqplib": ">=2.9",
"illuminate/support": ">=v5.5.28"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9",
"squizlabs/php_codesniffer": "^3.0@dev"
},
"autoload": {
"psr-4": {
"Bschmitt\\Amqp\\": "src/",
"Bschmitt\\Amqp\\Test\\": "test/"
}
},
"extra": {
"laravel": {
"providers": [
"Bschmitt\\Amqp\\AmqpServiceProvider"
],
"aliases": {
"Amqp": "Bschmitt\\Amqp\\Facades\\Amqp"
}
}
},
"minimum-stability": "dev"
}
<?php
return [
/*
|--------------------------------------------------------------------------
| Define which configuration should be used
|--------------------------------------------------------------------------
*/
'use' => 'production',
/*
|--------------------------------------------------------------------------
| AMQP properties separated by key
|--------------------------------------------------------------------------
*/
'properties' => [
'production' => [
'host' => 'localhost',
'port' => 5672,
'username' => '',
'password' => '',
'vhost' => '/',
'connect_options' => [],
'ssl_options' => [],
'exchange' => 'amq.topic',
'exchange_type' => 'topic',
'exchange_passive' => false,
'exchange_durable' => true,
'exchange_auto_delete' => false,
'exchange_internal' => false,
'exchange_nowait' => false,
'exchange_properties' => [],
'queue_force_declare' => false,
'queue_passive' => false,
'queue_durable' => true,
'queue_exclusive' => false,
'queue_auto_delete' => false,
'queue_nowait' => false,
'queue_properties' => ['x-ha-policy' => ['S', 'all']],
'consumer_tag' => '',
'consumer_no_local' => false,
'consumer_no_ack' => false,
'consumer_exclusive' => false,
'consumer_nowait' => false,
'timeout' => 0,
'persistent' => false,
'qos' => false,
'qos_prefetch_size' => 0,
'qos_prefetch_count' => 1,
'qos_a_global' => false
],
],
];
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
\ No newline at end of file
<?php
namespace Bschmitt\Amqp;
use Closure;
use Bschmitt\Amqp\Request;
use Bschmitt\Amqp\Message;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class Amqp
{
/**
* @param string $routing
* @param mixed $message
* @param array $properties
*/
public function publish($routing, $message, array $properties = [])
{
$properties['routing'] = $routing;
/* @var Publisher $publisher */
$publisher = app()->make('Bschmitt\Amqp\Publisher');
$publisher
->mergeProperties($properties)
->setup();
if (is_string($message)) {
$message = new Message($message, ['content_type' => 'text/plain', 'delivery_mode' => 2]);
}
$publisher->publish($routing, $message);
Request::shutdown($publisher->getChannel(), $publisher->getConnection());
}
/**
* @param string $queue
* @param Closure $callback
* @param array $properties
* @throws Exception\Configuration
*/
public function consume($queue, Closure $callback, $properties = [])
{
$properties['queue'] = $queue;
/* @var Consumer $consumer */
$consumer = app()->make('Bschmitt\Amqp\Consumer');
$consumer
->mergeProperties($properties)
->setup();
$consumer->consume($queue, $callback);
Request::shutdown($consumer->getChannel(), $consumer->getConnection());
}
/**
* @param string $body
* @param array $properties
* @return \Bschmitt\Amqp\Message
*/
public function message($body, $properties = [])
{
return new Message($body, $properties);
}
}
<?php
namespace Bschmitt\Amqp;
use Bschmitt\Amqp\Consumer;
use Bschmitt\Amqp\Publisher;
use Illuminate\Support\ServiceProvider;
class AmqpServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->app->bind('Amqp', 'Bschmitt\Amqp\Amqp');
if (!class_exists('Amqp')) {
class_alias('Bschmitt\Amqp\Facades\Amqp', 'Amqp');
}
$this->publishes([
__DIR__.'/../config/amqp.php' => config_path('amqp.php'),
]);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('Bschmitt\Amqp\Publisher', function ($app) {
return new Publisher(config());
});
$this->app->singleton('Bschmitt\Amqp\Consumer', function ($app) {
return new Consumer(config());
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['Amqp', 'Bschmitt\Amqp\Publisher', 'Bschmitt\Amqp\Consumer'];
}
}
<?php
namespace Bschmitt\Amqp;
use Illuminate\Config\Repository;
use Closure;
use PhpAmqpLib\Exception\AMQPTimeoutException;
use PhpAmqpLib\Message\AMQPMessage;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class Consumer extends Request
{
/**
* @var int
*/
protected $messageCount = 0;
/**
* @param string $queue
* @param Closure $closure
* @return bool
* @throws \Exception
*/
public function consume($queue, Closure $closure)
{
try {
$this->messageCount = $this->getQueueMessageCount();
if (!$this->getProperty('persistent') && $this->messageCount == 0) {
throw new Exception\Stop();
}
/*
queue: Queue from where to get the messages
consumer_tag: Consumer identifier
no_local: Don't receive messages published by this consumer.
no_ack: Tells the server if the consumer will acknowledge the messages.
exclusive: Request exclusive consumer access, meaning only this consumer can access the queue
nowait:
qos: The consumer-prefetch make it possible to limit the number of unacknowledged messages on a channel (or connection) when consuming.
Or, in other words, don't dispatch a new message to a worker
until it has processed and acknowledged the previous one
callback: A PHP Callback
*/
$object = $this;
if ($this->getProperty('qos')) {
$this->getChannel()->basic_qos(
$this->getProperty('qos_prefetch_size'),
$this->getProperty('qos_prefetch_count'),
$this->getProperty('qos_a_global')
);
}
$this->getChannel()->basic_consume(
$queue,
$this->getProperty('consumer_tag'),
$this->getProperty('consumer_no_local'),
$this->getProperty('consumer_no_ack'),
$this->getProperty('consumer_exclusive'),
$this->getProperty('consumer_nowait'),
function ($message) use ($closure, $object) {
$closure($message, $object);
}
);
// consume
while (count($this->getChannel()->callbacks)) {
$this->getChannel()->wait(null, false,
$this->getProperty('timeout') ? $this->getProperty('timeout') : 0
);
}
} catch (\Exception $e) {
if ($e instanceof Exception\Stop) {
return true;
}
if ($e instanceof AMQPTimeoutException) {
return true;
}
throw $e;
}
return true;
}
/**
* Acknowledges a message
*
* @param AMQPMessage $message
*/
public function acknowledge(AMQPMessage $message)
{
$message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
if ($message->body === 'quit') {
$message->delivery_info['channel']->basic_cancel($message->delivery_info['consumer_tag']);
}
}
/**
* Rejects a message and requeues it if wanted (default: false)
*
* @param AMQPMessage $message
* @param bool $requeue
*/
public function reject(AMQPMessage $message, $requeue = false)
{
$message->delivery_info['channel']->basic_reject($message->delivery_info['delivery_tag'], $requeue);
}
/**
* Stops consumer when no message is left
*
* @throws Exception\Stop
*/
public function stopWhenProcessed()
{
if (--$this->messageCount <= 0) {
throw new Exception\Stop();
}
}
}
<?php
namespace Bschmitt\Amqp;
use Illuminate\Config\Repository;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
abstract class Context
{
const REPOSITORY_KEY = 'amqp';
/**
* @var array
*/
protected $properties = [];
/**
* Context constructor.
*
* @param Repository $config
*/
public function __construct(Repository $config)
{
$this->extractProperties($config);
}
/**
* @param Repository $config
*/
protected function extractProperties(Repository $config)
{
if ($config->has(self::REPOSITORY_KEY)) {
$data = $config->get(self::REPOSITORY_KEY);
$this->properties = $data['properties'][$data['use']];
}
}
/**
* @param array $properties
* @return $this
*/
public function mergeProperties(array $properties)
{
$this->properties = array_merge($this->properties, $properties);
return $this;
}
/**
* @return array
*/
public function getProperties()
{
return $this->properties;
}
/**
* @param string $key
* @return mixed
*/
public function getProperty($key)
{
return array_key_exists($key, $this->properties) ? $this->properties[$key] : null;
}
/**
* @param string $key
* @param mixed $default
* @return mixed
*/
public function getConnectOption($key, $default = null)
{
$options = $this->getProperty('connect_options');
if (!is_array($options)) {
return $default;
}
return array_key_exists($key, $options) ? $options[$key] : $default;
}
/**
* @return mixed
*/
abstract public function setup();
}
<?php
namespace Bschmitt\Amqp\Exception;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class Configuration extends \Exception
{
}
<?php
namespace Bschmitt\Amqp\Exception;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class Stop extends \Exception
{
}
<?php
namespace Bschmitt\Amqp\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @author Björn Schmitt <code@bjoern.io>
* @see Bschmitt\Amqp\Amqp
*/
class Amqp extends Facade
{
/**
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Amqp';
}
}
<?php
namespace Bschmitt\Amqp;
use Illuminate\Support\ServiceProvider;
/**
* Lumen Service Provider
*
* @author Björn Schmitt <code@bjoern.io>
*/
class LumenServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
}
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
$this->app->bind('Bschmitt\Amqp\Publisher', function ($app) {
return new Publisher($app->config);
});
$this->app->bind('Bschmitt\Amqp\Consumer', function ($app) {
return new Consumer($app->config);
});
$this->app->bind('Amqp', 'Bschmitt\Amqp\Amqp');
if (!class_exists('Amqp')) {
class_alias('Bschmitt\Amqp\Facades\Amqp', 'Amqp');
}
}
}
<?php
namespace Bschmitt\Amqp;
use PhpAmqpLib\Message\AMQPMessage;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class Message extends AMQPMessage
{
}
<?php
namespace Bschmitt\Amqp;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class Publisher extends Request
{
/**
* @param string $routing
* @param Message $message
* @throws Exception\Configuration
*/
public function publish($routing, $message)
{
$this->getChannel()->basic_publish($message, $this->getProperty('exchange'), $routing);
}
}
<?php
namespace Bschmitt\Amqp;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Connection\AMQPSSLConnection;
use PhpAmqpLib\Channel\AMQPChannel;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class Request extends Context
{
/**
* @var AMQPStreamConnection
*/
protected $connection;
/**
* @var AMQPChannel
*/
protected $channel;
/**
* @var array
*/
protected $queueInfo;
/**
*
*/
public function connect()
{
if ($this->getProperty('ssl_options')) {
$this->connection = new AMQPSSLConnection(
$this->getProperty('host'),
$this->getProperty('port'),
$this->getProperty('username'),
$this->getProperty('password'),
$this->getProperty('vhost'),
$this->getProperty('ssl_options'),
$this->getProperty('connect_options')
);
} else {
$this->connection = new AMQPStreamConnection(
$this->getProperty('host'),
$this->getProperty('port'),
$this->getProperty('username'),
$this->getProperty('password'),
$this->getProperty('vhost'),
$this->getConnectOption('insist', false),
$this->getConnectOption('login_method', 'AMQPLAIN'),
$this->getConnectOption('login_response', null),
$this->getConnectOption('locale', 3),
$this->getConnectOption('connection_timeout', 3.0),
$this->getConnectOption('read_write_timeout', 130),
$this->getConnectOption('context', null),
$this->getConnectOption('keepalive', false),
$this->getConnectOption('heartbeat', 60),
$this->getConnectOption('channel_rpc_timeout', 0.0),
$this->getConnectOption('ssl_protocol', null)
);
}
$this->channel = $this->connection->channel();
}
/**
* @throws Exception\Configuration
*/
public function setup()
{
$this->connect();
$exchange = $this->getProperty('exchange');
if (empty($exchange)) {
throw new Exception\Configuration('Please check your settings, exchange is not defined.');
}
/*
name: $exchange
type: topic
passive: false
durable: true // the exchange will survive server restarts
auto_delete: false //the exchange won't be deleted once the channel is closed.
*/
$this->channel->exchange_declare(
$exchange,
$this->getProperty('exchange_type'),
$this->getProperty('exchange_passive'),
$this->getProperty('exchange_durable'),
$this->getProperty('exchange_auto_delete'),
$this->getProperty('exchange_internal'),
$this->getProperty('exchange_nowait'),
$this->getProperty('exchange_properties')
);
$queue = $this->getProperty('queue');
if (!empty($queue) || $this->getProperty('queue_force_declare')) {
/*
name: $queue
passive: false
durable: true // the queue will survive server restarts
exclusive: false // queue is deleted when connection closes
auto_delete: false //the queue won't be deleted once the channel is closed.
nowait: false // Doesn't wait on replies for certain things.
parameters: array // Extra data, like high availability params
*/
/** @var ['queue name', 'message count',] queueInfo */
$this->queueInfo = $this->channel->queue_declare(
$queue,
$this->getProperty('queue_passive'),
$this->getProperty('queue_durable'),
$this->getProperty('queue_exclusive'),
$this->getProperty('queue_auto_delete'),
$this->getProperty('queue_nowait'),
$this->getProperty('queue_properties')
);
$this->channel->queue_bind(
$queue ?: $this->queueInfo[0],
$exchange,
$this->getProperty('routing')
);
}
// clear at shutdown
$this->connection->set_close_on_destruct(true);
}
/**
* @return \PhpAmqpLib\Channel\AMQPChannel
*/
public function getChannel()
{
return $this->channel;
}
/**
* @return AMQPStreamConnection
*/
public function getConnection()
{
return $this->connection;
}
/**
* @return int
*/
public function getQueueMessageCount()
{
if (is_array($this->queueInfo)) {
return $this->queueInfo[1];
}
return 0;
}
/**
* @param AMQPChannel $channel
* @param AMQPStreamConnection $connection
*/
public static function shutdown(AMQPChannel $channel, AMQPStreamConnection $connection)
{
$channel->close();
$connection->close();
}
}
<?php
namespace Bschmitt\Amqp\Test;
use \Mockery;
use Illuminate\Config\Repository;
class BaseTestCase extends \PHPUnit_Framework_TestCase
{
const REPOSITORY_KEY = 'amqp';
protected $configRepository;
protected $defaultConfig;
protected function setUp()
{
$amqpConfig = include dirname(__FILE__).'/../config/amqp.php';
$this->defaultConfig = $amqpConfig['properties'][$amqpConfig['use']];
$config = Mockery::mock('\Illuminate\Config\Repository');
$config->shouldReceive('has')->with(self::REPOSITORY_KEY)->andReturn(true);
$config->shouldReceive('get')->with(self::REPOSITORY_KEY)->andReturn($amqpConfig);
$this->configRepository = $config;
}
protected function tearDown()
{
// necessary for Mockery to check if methods were called and with what arguments
Mockery::close();
}
protected function setProtectedProperty($class, $mock, $propertyName, $value)
{
$reflectionClass = new \ReflectionClass($class);
$channelProperty = $reflectionClass->getProperty($propertyName);
$channelProperty->setAccessible(true);
$channelProperty->setValue($mock, $value);
$channelProperty->setAccessible(false);
}
}
<?php
namespace Bschmitt\Amqp\Test;
use \Mockery;
use Bschmitt\Amqp\Publisher;
use Illuminate\Config\Repository;
/**
* @author Björn Schmitt <code@bjoern.io>
*/
class PublisherTest extends BaseTestCase
{
private $publisherMock;
private $connectionMock;
private $channelMock;
protected function setUp()
{
parent::setUp();
// partial mock of \Bschmitt\Amqp\Publisher
// we want all methods except [connect] to be real
$this->publisherMock = Mockery::mock('\Bschmitt\Amqp\Publisher[connect]', [$this->configRepository]);
// set connection and channel properties
$this->channelMock = Mockery::mock('\PhpAmqpLib\Channel\AMQPChannel');
$this->connectionMock = Mockery::mock('\PhpAmqpLib\Connection\AMQPSSLConnection');
// channel and connection are both protected and without changing the source this was the only way to mock them
$this->setProtectedProperty('\Bschmitt\Amqp\Publisher', $this->publisherMock, 'channel', $this->channelMock);
$this->setProtectedProperty('\Bschmitt\Amqp\Publisher', $this->publisherMock, 'connection', $this->connectionMock);
}
public function testSetupPublisher()
{
$this->connectionMock->shouldReceive('set_close_on_destruct')->with(true)->times(1);
$this->channelMock->shouldReceive('exchange_declare')->with(
$this->defaultConfig['exchange'],
$this->defaultConfig['exchange_type'],
$this->defaultConfig['exchange_passive'],
$this->defaultConfig['exchange_durable'],
$this->defaultConfig['exchange_auto_delete'],
$this->defaultConfig['exchange_internal'],
$this->defaultConfig['exchange_nowait'],
$this->defaultConfig['exchange_properties']
)->times(1);
$this->publisherMock->shouldReceive('connect')->times(1);
$this->publisherMock->setup();
}
public function testPublishShouldAChannelMethodWithProperParams()
{
$routing = 'routing-key';
$message = 'sample-message';
$this->channelMock->shouldReceive('basic_publish')
->with(
$message,
$this->defaultConfig['exchange'],
$routing
)->times(1);
$this->publisherMock->publish($routing, $message);
}
public function testPublishShouldCallAChannelMethodWithCustomExchangeValue()
{
$routing = 'routing-key';
$message = 'sample-message';
$exchange = 'custom-exchange';
$this->publisherMock->mergeProperties(['exchange' => $exchange]);
$this->channelMock->shouldReceive('basic_publish')
->with(
$message,
$exchange,
$routing
)->times(1);
$this->publisherMock->publish($routing, $message);
}
}
<?php
namespace Bschmitt\Amqp\Test;
use \Mockery;
use Bschmitt\Amqp\Request;
use Bschmitt\Amqp\Context;
class RequestTest extends BaseTestCase
{
private $connectionMock;
private $channelMock;
private $requestMock;
protected function setUp()
{
parent::setUp();
$this->channelMock = Mockery::mock('\PhpAmqpLib\Channel\AMQPChannel');
$this->connectionMock = Mockery::mock('\PhpAmqpLib\Connection\AMQPSSLConnection');
// partial mock of \Bschmitt\Amqp\Publisher
// we want all methods except [connect,getChannel] to be real
$this->requestMock = Mockery::mock('\Bschmitt\Amqp\Request[connect,getChannel]', [$this->configRepository]);
// channel and connection are both protected and without changing the source this was the only way to mock them
$this->setProtectedProperty('\Bschmitt\Amqp\Request', $this->requestMock, 'channel', $this->channelMock);
$this->setProtectedProperty('\Bschmitt\Amqp\Request', $this->requestMock, 'connection', $this->connectionMock);
}
/**
* @expectedException Bschmitt\Amqp\Exception\Configuration
*/
public function testIfEmptyExchangeThrowsAnException()
{
$this->requestMock->mergeProperties(['exchange' => '']);
$this->requestMock->shouldReceive('connect');
$this->requestMock->setup();
}
public function testIfQueueGetsDeclaredAndBoundIfInConfig()
{
$queueName = 'amqp-test';
$routing = 'routing-test';
$this->requestMock->mergeProperties([
'queue' => $queueName,
'queue_force_declare' => true,
'routing' => $routing
]);
$this->channelMock->shouldReceive('exchange_declare');
$this->requestMock->shouldReceive('connect');
$this->channelMock->shouldReceive('queue_declare')
->with(
$queueName,
$this->defaultConfig['queue_passive'],
$this->defaultConfig['queue_durable'],
$this->defaultConfig['queue_exclusive'],
$this->defaultConfig['queue_auto_delete'],
$this->defaultConfig['queue_nowait'],
$this->defaultConfig['queue_properties']
)
->andReturn([$queueName, 4])
->times(1);
$this->channelMock->shouldReceive('queue_bind')
->with(
$queueName,
$this->defaultConfig['exchange'],
$routing
)
->times(1);
$this->connectionMock->shouldReceive('set_close_on_destruct')->with(true)->times(1);
$this->requestMock->setup();
}
public function testQueueMessageCountShouldBeZeroIfQueueinfoIsNotSet()
{
$this->assertEquals($this->requestMock->getQueueMessageCount(), 0);
}
public function testQueueMessageCountShouldReturnMessageCount()
{
$messageCount = 4;
$queueInfo = ['queue-name', $messageCount];
$this->setProtectedProperty('\Bschmitt\Amqp\Request', $this->requestMock, 'queueInfo', $queueInfo);
$this->assertEquals($this->requestMock->getQueueMessageCount(), $messageCount);
}
public function testIfChannelAndConnectionAreClosedWhenShutdownIsInvoked()
{
$this->channelMock->shouldReceive('close')->times(1);
$this->connectionMock->shouldReceive('close')->times(1);
$this->requestMock::shutDown($this->channelMock, $this->connectionMock);
}
}
...@@ -12,6 +12,7 @@ return array( ...@@ -12,6 +12,7 @@ return array(
'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php', 'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php',
'72579e7bd17821bb1321b87411366eae' => $vendorDir . '/illuminate/support/helpers.php', '72579e7bd17821bb1321b87411366eae' => $vendorDir . '/illuminate/support/helpers.php',
'1d1b89d124cc9cb8219922c9d5569199' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php', '1d1b89d124cc9cb8219922c9d5569199' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php',
'decc78cc4436b1292c6c0d151b19445c' => $vendorDir . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php', '6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'253c157292f75eb38082b5acb06f3f01' => $vendorDir . '/nikic/fast-route/src/functions.php', '253c157292f75eb38082b5acb06f3f01' => $vendorDir . '/nikic/fast-route/src/functions.php',
'bee9632da3ca00a99623b9c35d0c4f8b' => $vendorDir . '/laravel/lumen-framework/src/helpers.php', 'bee9632da3ca00a99623b9c35d0c4f8b' => $vendorDir . '/laravel/lumen-framework/src/helpers.php',
......
...@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__)); ...@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
'phpDocumentor\\Reflection\\' => array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/reflection-docblock/src', $vendorDir . '/phpdocumentor/type-resolver/src'), 'phpDocumentor\\Reflection\\' => array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/reflection-docblock/src', $vendorDir . '/phpdocumentor/type-resolver/src'),
'Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'), 'Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'),
'Symfony\\Polyfill\\Util\\' => array($vendorDir . '/symfony/polyfill-util'), 'Symfony\\Polyfill\\Util\\' => array($vendorDir . '/symfony/polyfill-util'),
...@@ -28,6 +29,7 @@ return array( ...@@ -28,6 +29,7 @@ return array(
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'), 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'Prophecy\\' => array($vendorDir . '/phpspec/prophecy/src/Prophecy'), 'Prophecy\\' => array($vendorDir . '/phpspec/prophecy/src/Prophecy'),
'Predis\\' => array($vendorDir . '/predis/predis/src'), 'Predis\\' => array($vendorDir . '/predis/predis/src'),
'PhpAmqpLib\\' => array($vendorDir . '/php-amqplib/php-amqplib/PhpAmqpLib'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'), 'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
'Laravel\\Lumen\\' => array($vendorDir . '/laravel/lumen-framework/src'), 'Laravel\\Lumen\\' => array($vendorDir . '/laravel/lumen-framework/src'),
'Illuminate\\View\\' => array($vendorDir . '/illuminate/view'), 'Illuminate\\View\\' => array($vendorDir . '/illuminate/view'),
...@@ -62,6 +64,8 @@ return array( ...@@ -62,6 +64,8 @@ return array(
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'), 'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
'Cron\\' => array($vendorDir . '/mtdowling/cron-expression/src/Cron'), 'Cron\\' => array($vendorDir . '/mtdowling/cron-expression/src/Cron'),
'Common\\' => array($baseDir . '/common'), 'Common\\' => array($baseDir . '/common'),
'Bschmitt\\Amqp\\Test\\' => array($vendorDir . '/bschmitt/laravel-amqp/test'),
'Bschmitt\\Amqp\\' => array($vendorDir . '/bschmitt/laravel-amqp/src'),
'App\\' => array($baseDir . '/app'), 'App\\' => array($baseDir . '/app'),
'' => array($vendorDir . '/nesbot/carbon/src'), '' => array($vendorDir . '/nesbot/carbon/src'),
); );
...@@ -13,6 +13,7 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f ...@@ -13,6 +13,7 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f
'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php', 'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php',
'72579e7bd17821bb1321b87411366eae' => __DIR__ . '/..' . '/illuminate/support/helpers.php', '72579e7bd17821bb1321b87411366eae' => __DIR__ . '/..' . '/illuminate/support/helpers.php',
'1d1b89d124cc9cb8219922c9d5569199' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php', '1d1b89d124cc9cb8219922c9d5569199' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php',
'decc78cc4436b1292c6c0d151b19445c' => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
'6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php', '6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'253c157292f75eb38082b5acb06f3f01' => __DIR__ . '/..' . '/nikic/fast-route/src/functions.php', '253c157292f75eb38082b5acb06f3f01' => __DIR__ . '/..' . '/nikic/fast-route/src/functions.php',
'bee9632da3ca00a99623b9c35d0c4f8b' => __DIR__ . '/..' . '/laravel/lumen-framework/src/helpers.php', 'bee9632da3ca00a99623b9c35d0c4f8b' => __DIR__ . '/..' . '/laravel/lumen-framework/src/helpers.php',
...@@ -23,6 +24,7 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f ...@@ -23,6 +24,7 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f
public static $prefixLengthsPsr4 = array ( public static $prefixLengthsPsr4 = array (
'p' => 'p' =>
array ( array (
'phpseclib\\' => 10,
'phpDocumentor\\Reflection\\' => 25, 'phpDocumentor\\Reflection\\' => 25,
), ),
'W' => 'W' =>
...@@ -54,6 +56,7 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f ...@@ -54,6 +56,7 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f
'Psr\\Container\\' => 14, 'Psr\\Container\\' => 14,
'Prophecy\\' => 9, 'Prophecy\\' => 9,
'Predis\\' => 7, 'Predis\\' => 7,
'PhpAmqpLib\\' => 11,
), ),
'M' => 'M' =>
array ( array (
...@@ -110,6 +113,11 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f ...@@ -110,6 +113,11 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f
'Cron\\' => 5, 'Cron\\' => 5,
'Common\\' => 7, 'Common\\' => 7,
), ),
'B' =>
array (
'Bschmitt\\Amqp\\Test\\' => 19,
'Bschmitt\\Amqp\\' => 14,
),
'A' => 'A' =>
array ( array (
'App\\' => 4, 'App\\' => 4,
...@@ -117,6 +125,10 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f ...@@ -117,6 +125,10 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f
); );
public static $prefixDirsPsr4 = array ( public static $prefixDirsPsr4 = array (
'phpseclib\\' =>
array (
0 => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib',
),
'phpDocumentor\\Reflection\\' => 'phpDocumentor\\Reflection\\' =>
array ( array (
0 => __DIR__ . '/..' . '/phpdocumentor/reflection-common/src', 0 => __DIR__ . '/..' . '/phpdocumentor/reflection-common/src',
...@@ -207,6 +219,10 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f ...@@ -207,6 +219,10 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f
array ( array (
0 => __DIR__ . '/..' . '/predis/predis/src', 0 => __DIR__ . '/..' . '/predis/predis/src',
), ),
'PhpAmqpLib\\' =>
array (
0 => __DIR__ . '/..' . '/php-amqplib/php-amqplib/PhpAmqpLib',
),
'Monolog\\' => 'Monolog\\' =>
array ( array (
0 => __DIR__ . '/..' . '/monolog/monolog/src/Monolog', 0 => __DIR__ . '/..' . '/monolog/monolog/src/Monolog',
...@@ -343,6 +359,14 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f ...@@ -343,6 +359,14 @@ class ComposerStaticInit5c9707cde9ea4e3942300fe24293f04f
array ( array (
0 => __DIR__ . '/../..' . '/common', 0 => __DIR__ . '/../..' . '/common',
), ),
'Bschmitt\\Amqp\\Test\\' =>
array (
0 => __DIR__ . '/..' . '/bschmitt/laravel-amqp/test',
),
'Bschmitt\\Amqp\\' =>
array (
0 => __DIR__ . '/..' . '/bschmitt/laravel-amqp/src',
),
'App\\' => 'App\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/app', 0 => __DIR__ . '/../..' . '/app',
......
[ [
{ {
"name": "bschmitt/laravel-amqp",
"version": "2.0.8",
"version_normalized": "2.0.8.0",
"source": {
"type": "git",
"url": "https://github.com/bschmitt/laravel-amqp.git",
"reference": "66a3db685913093cb7e4fd39020ffc8c2db1e767"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bschmitt/laravel-amqp/zipball/66a3db685913093cb7e4fd39020ffc8c2db1e767",
"reference": "66a3db685913093cb7e4fd39020ffc8c2db1e767",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"illuminate/support": ">=v5.5.28",
"php": ">=7.0",
"php-amqplib/php-amqplib": ">=2.9"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "^3.0@dev"
},
"time": "2019-08-29T16:11:19+00:00",
"type": "library",
"extra": {
"laravel": {
"providers": [
"Bschmitt\\Amqp\\AmqpServiceProvider"
],
"aliases": {
"Amqp": "Bschmitt\\Amqp\\Facades\\Amqp"
}
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Bschmitt\\Amqp\\": "src/",
"Bschmitt\\Amqp\\Test\\": "test/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Björn Schmitt",
"email": "code@bjoern.io"
}
],
"description": "AMQP wrapper for Laravel and Lumen to publish and consume messages",
"keywords": [
"AMQP",
"Björn Schmitt",
"bschmitt",
"laravel",
"laravel5",
"lumen",
"message queue",
"package",
"queue",
"rabbitmq"
]
},
{
"name": "doctrine/inflector", "name": "doctrine/inflector",
"version": "1.3.1", "version": "1.3.1",
"version_normalized": "1.3.1.0", "version_normalized": "1.3.1.0",
...@@ -2326,6 +2400,91 @@ ...@@ -2326,6 +2400,91 @@
"description": "Library for handling version information and constraints" "description": "Library for handling version information and constraints"
}, },
{ {
"name": "php-amqplib/php-amqplib",
"version": "v2.11.2",
"version_normalized": "2.11.2.0",
"source": {
"type": "git",
"url": "https://github.com/php-amqplib/php-amqplib.git",
"reference": "bd1c7b976d1ec19a542ad89d9a3d155a8f9f7687"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/bd1c7b976d1ec19a542ad89d9a3d155a8f9f7687",
"reference": "bd1c7b976d1ec19a542ad89d9a3d155a8f9f7687",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"ext-mbstring": "*",
"ext-sockets": "*",
"php": ">=5.6.3",
"phpseclib/phpseclib": "^2.0.0"
},
"conflict": {
"php": "7.4.0 - 7.4.1"
},
"replace": {
"videlalvaro/php-amqplib": "self.version"
},
"require-dev": {
"ext-curl": "*",
"nategood/httpful": "^0.2.20",
"phpunit/phpunit": "^5.7|^6.5|^7.0",
"squizlabs/php_codesniffer": "^2.5"
},
"time": "2020-04-30T13:18:50+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.11-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"PhpAmqpLib\\": "PhpAmqpLib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-or-later"
],
"authors": [
{
"name": "Alvaro Videla",
"role": "Original Maintainer"
},
{
"name": "John Kelly",
"email": "johnmkelly86@gmail.com",
"role": "Maintainer"
},
{
"name": "Raúl Araya",
"email": "nubeiro@gmail.com",
"role": "Maintainer"
},
{
"name": "Luke Bakken",
"email": "luke@bakken.io",
"role": "Maintainer"
}
],
"description": "Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.",
"homepage": "https://github.com/php-amqplib/php-amqplib/",
"keywords": [
"message",
"queue",
"rabbitmq"
]
},
{
"name": "phpdocumentor/reflection-common", "name": "phpdocumentor/reflection-common",
"version": "2.0.0", "version": "2.0.0",
"version_normalized": "2.0.0.0", "version_normalized": "2.0.0.0",
...@@ -2501,6 +2660,106 @@ ...@@ -2501,6 +2660,106 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names" "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names"
}, },
{ {
"name": "phpseclib/phpseclib",
"version": "2.0.27",
"version_normalized": "2.0.27.0",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc",
"reference": "34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phing/phing": "~2.7",
"phpunit/phpunit": "^4.8.35|^5.7|^6.0",
"sami/sami": "~2.0",
"squizlabs/php_codesniffer": "~2.0"
},
"suggest": {
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"time": "2020-04-04T23:17:33+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib\\": "phpseclib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Wigginton",
"email": "terrafrost@php.net",
"role": "Lead Developer"
},
{
"name": "Patrick Monnerat",
"email": "pm@datasphere.ch",
"role": "Developer"
},
{
"name": "Andreas Fischer",
"email": "bantu@phpbb.com",
"role": "Developer"
},
{
"name": "Hans-Jürgen Petrich",
"email": "petrich@tronic-media.com",
"role": "Developer"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
}
],
"description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
"homepage": "http://phpseclib.sourceforge.net",
"keywords": [
"BigInteger",
"aes",
"asn.1",
"asn1",
"blowfish",
"crypto",
"cryptography",
"encryption",
"rsa",
"security",
"sftp",
"signature",
"signing",
"ssh",
"twofish",
"x.509",
"x509"
]
},
{
"name": "phpspec/prophecy", "name": "phpspec/prophecy",
"version": "v1.10.3", "version": "v1.10.3",
"version_normalized": "1.10.3.0", "version_normalized": "1.10.3.0",
......
# Contributor Code of Conduct
As contributors and maintainers of this project, and in the interest of
fostering an open and welcoming community, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating
documentation, submitting pull requests or patches, and other activities.
We are committed to making participation in this project a harassment-free
experience for everyone, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal appearance,
body size, race, ethnicity, age, religion, or nationality.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic
addresses, without explicit permission
* Other unethical or unprofessional conduct
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
By adopting this Code of Conduct, project maintainers commit themselves to
fairly and consistently applying these principles to every aspect of managing
this project. Project maintainers who do not follow or enforce the Code of
Conduct may be permanently removed from the project team.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting a project maintainer. All complaints will be reviewed
and investigated and will result in a response that is deemed necessary and
appropriate to the circumstances. Maintainers are obligated to maintain
confidentiality with regard to the reporter of an incident.
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.3.0, available at
[http://contributor-covenant.org/version/1/3/0/][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/3/0/
---
name: 🐛 Bug Report
about: Report errors and problems
---
**Version(s) affected**: x.y.z
**Description**
<!-- A clear and concise description of the problem. -->
**How to reproduce**
<!-- Code and/or config needed to reproduce the problem. -->
**Possible Solution**
<!--- Optional: only if you have suggestions on a fix/reason for the bug -->
**Additional context**
<!-- Required: php tests/phpinfo.php output from same SAPI as bug occurred -->
<!-- Optional: any other context about the problem: log messages, screenshots, etc. -->
---
name: 🚀 Feature Request
about: RFC and ideas for new features and improvements
---
**Description**
<!-- A clear and concise description of the new feature. -->
**Example**
<!-- A simple example of the new feature in action (include PHP code, YAML config, etc.)
If the new feature changes an existing feature, include a simple before/after comparison. -->
---
name: ⛔ Support Question
about: Questions about using library
---
[submodule "docs"]
path = docs
url = https://github.com/php-amqplib/php-amqplib.git
branch = gh-pages
# Changelog
All Notable changes to `php-amqplib` will be documented in this file
## 2.11.2 - 2020-04-30
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/15?closed=1
## 2.11.1 - 2020-02-24
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/13?closed=1
## 2.11.0 - 2019-11-19
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/12?closed=1
## 2.10.1 - 2019-10-10
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/11?closed=1
## 2.10.0 - 2019-08-09
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/10?closed=1)
- Heartbeats are disabled by default. This reverts the following changes: [Issue](https://github.com/php-amqplib/php-amqplib/issues/563) / [PR](https://github.com/php-amqplib/php-amqplib/pull/648)
## 2.9.2 - 2019-04-24
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/9?closed=1)
## 2.9.1 - 2019-03-26
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/8?closed=1)
## 2.9.0 - 2019-03-23
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/7?closed=1)
- heartbeats are now enabled by default [Issue](https://github.com/php-amqplib/php-amqplib/issues/563) / [PR](https://github.com/php-amqplib/php-amqplib/pull/648)
## 2.8.1 - 2018-11-13
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/6?closed=1)
- `ext-sockets` is now required: [PR](https://github.com/php-amqplib/php-amqplib/pull/610)
- Fix `errno=11 Resource temporarily unavailable` error: [Issue](https://github.com/php-amqplib/php-amqplib/issues/613) / [PR](https://github.com/php-amqplib/php-amqplib/pull/615)
## 2.8.0 - 2018-10-23
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/3?closed=1)
- Drop testing and support for PHP 5.3
- Use specific exceptions instead of general `AMQPRuntimeException`: [PR](https://github.com/php-amqplib/php-amqplib/pull/600)
- Allow overriding of `LIBRARY_PROPERTIES` - [PR](https://github.com/php-amqplib/php-amqplib/pull/606)
## 2.7.2 - 2018-02-11
[GitHub Milestone](https://github.com/php-amqplib/php-amqplib/milestone/5?closed=1)
- PHP `5.3` compatibility [PR](https://github.com/php-amqplib/php-amqplib/issues/539)
## 2.7.1 - 2018-02-01
- Support PHPUnit 6 [PR](https://github.com/php-amqplib/php-amqplib/pull/530)
- Use `tcp_nodelay` for `StreamIO` [PR](https://github.com/php-amqplib/php-amqplib/pull/517)
- Pass connection timeout to `wait` method [PR](https://github.com/php-amqplib/php-amqplib/pull/512)
- Fix possible indefinite waiting for data in StreamIO [PR](https://github.com/php-amqplib/php-amqplib/pull/423), [PR](https://github.com/php-amqplib/php-amqplib/pull/534)
- Change protected method check_heartbeat to public [PR](https://github.com/php-amqplib/php-amqplib/pull/520)
- Ensure access levels are consistent for calling `check_heartbeat` [PR](https://github.com/php-amqplib/php-amqplib/pull/535)
## 2.7.0 - 2017-09-20
### Added
- Increased overall test coverage
- Bring heartbeat support to socket connection
- Add message delivery tag for publisher confirms
- Add support for serializing DateTimeImmutable objects
### Fixed
- Fixed infinite loop on reconnect - check_heartbeat
- Fixed signal handling exit example
- Fixed exchange_unbind arguments
- Fixed invalid annotation for channel_id
- Fixed socket null error on php 5.3 version
- Fixed timeout parameters on HHVM before calling stream_select
### Changed
- declare(ticks=1) no longer needed after PHP5.3 / amqplib 2.4.1
- Minor DebugHelper improvements
### Enhancements
- Add extensions requirements to README.md
- Add PHP 7.1 to Travis build
- Reduce memory usage in StreamIO::write()
- Re-enable heartbeats after reconnection
## 2.6.3 - 2016-04-11
### Added
- Added the ability to set timeout as float
### Fixed
- Fixed restoring of error_handler on connection error
### Enhancements
- Verify read_write_timeout is at least 2x the heartbeat (if set)
- Many PHPDoc fixes
- Throw exception when trying to create an exchange on a closed connection
## 2.6.2 - 2016-03-02
### Added
- Added AMQPLazySocketConnection
- AbstractConnection::getServerProperties method to retrieve server properties.
- AMQPReader::wait() will throw IOWaitException on stream_select failure
- Add PHPDocs to Auto-generated Protocol Classes
### Fixed
- Disable heartbeat when closing connection
- Fix for when the default error handler is not restored in StreamIO
### Enhancements
- Cleanup tests and improve testing performance
- Confirm received valid frame type on wait_frame in AbstractConnection
- Update DEMO files closer to PSR-2 standards
## 2.6.1 - 2016-02-12
### Added
- Add constants for delivery modes to AMQPMessage
### Fixed
- Fix some PHPDoc problems
- AbstractCollection value de/encoding on PHP7
- StreamIO: fix "bad write retry" in SSL mode
### Enhancements
- Update PHPUnit configuration
- Add scrutinizer-ci configuration
- Organizational changes from videlalvaro to php-amqplib org
- Minor complexity optimizations, code organization, and code cleanup
## 2.6.0 - 2015-09-23
### BC Breaking Changes
- The `AMQPStreamConnection` class now throws `ErrorExceptions` when errors happen while reading/writing to the network.
### Added
- Heartbeat frames will decrease the timeout used when calling wait_channel - heartbeat frames do not reset the timeout
### Fixed
- Declared the class AbstractChannel as being an abstract class
- Reads, writes and signals respond immediately instead of waiting for a timeout
- Fatal error in some cases on Channel.wait with timeout when RabbitMQ restarted
- Remove warning when trying to push a deferred frame
# Contributing
Contributions are **welcome** and will be fully **credited**.
We accept contributions via Pull Requests on [Github](https://github.com/php-amqplib/php-amqplib).
## Pull Requests
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the README and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow semver. Randomly breaking public APIs is not an option.
- **Create topic branches** - Don't ask us to pull from your master branch.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
## Running Tests
To successfully run the tests you need to first have a stock RabbitMQ broker running locally. Then, run tests like this:
``` bash
$ vendor/bin/phpunit
```
or
``` bash
$ make test
```
**Happy coding**!
Following people contributed to this project:
Barry Pederson <bp@barryp.org> - author of original Python lib
Vadim Zaliva <lord@crocodile.org> - PHP paort
taavi013@gmail.com patches - patches
Sean Murphy http://code.google.com/u/sgmurphy/ - patches
spiderbill http://code.google.com/u/spiderbill/ - patches
<?php
namespace PhpAmqpLib\Connection;
/**
* Class AMQPConnection
*
* Kept for BC
*
* @deprecated
*/
class AMQPConnection extends AMQPStreamConnection
{
}
<?php
namespace PhpAmqpLib\Connection;
class AMQPLazyConnection extends AMQPStreamConnection
{
/**
* Gets socket from current connection
*
* @deprecated
*/
public function getSocket()
{
$this->connect();
return parent::getSocket();
}
/**
* {@inheritdoc}
*/
public function channel($channel_id = null)
{
$this->connect();
return parent::channel($channel_id);
}
/**
* @return null|\PhpAmqpLib\Wire\IO\AbstractIO
*/
public function getIO()
{
if (empty($this->io)) {
$this->connect();
}
return $this->io;
}
/**
* Should the connection be attempted during construction?
*
* @return bool
*/
public function connectOnConstruct()
{
return false;
}
}
<?php
namespace PhpAmqpLib\Connection;
/**
* Yet another lazy connection. This time using sockets. Current architecture doesn't allow to wrap existing connections
*/
class AMQPLazySocketConnection extends AMQPSocketConnection
{
/**
* Gets socket from current connection
*
* @deprecated
*/
public function getSocket()
{
$this->connect();
return parent::getSocket();
}
/**
* {@inheritdoc}
*/
public function channel($channel_id = null)
{
$this->connect();
return parent::channel($channel_id);
}
/**
* @return null|\PhpAmqpLib\Wire\IO\AbstractIO
*/
public function getIO()
{
if (empty($this->io)) {
$this->connect();
}
return $this->io;
}
/**
* Should the connection be attempted during construction?
*
* @return bool
*/
public function connectOnConstruct()
{
return false;
}
}
<?php
namespace PhpAmqpLib\Connection;
class AMQPSSLConnection extends AMQPStreamConnection
{
/**
* @param string $host
* @param int $port
* @param string $user
* @param string $password
* @param string $vhost
* @param array $ssl_options
* @param array $options
* @param string $ssl_protocol
*/
public function __construct(
$host,
$port,
$user,
$password,
$vhost = '/',
$ssl_options = array(),
$options = array(),
$ssl_protocol = 'ssl'
) {
$ssl_context = empty($ssl_options) ? null : $this->create_ssl_context($ssl_options);
parent::__construct(
$host,
$port,
$user,
$password,
$vhost,
isset($options['insist']) ? $options['insist'] : false,
isset($options['login_method']) ? $options['login_method'] : 'AMQPLAIN',
isset($options['login_response']) ? $options['login_response'] : null,
isset($options['locale']) ? $options['locale'] : 'en_US',
isset($options['connection_timeout']) ? $options['connection_timeout'] : 3,
isset($options['read_write_timeout']) ? $options['read_write_timeout'] : 130,
$ssl_context,
isset($options['keepalive']) ? $options['keepalive'] : false,
isset($options['heartbeat']) ? $options['heartbeat'] : 0,
isset($options['channel_rpc_timeout']) ? $options['channel_rpc_timeout'] : 0.0,
$ssl_protocol
);
}
public static function try_create_connection($host, $port, $user, $password, $vhost, $options) {
$ssl_options = isset($options['ssl_options']) ? $options['ssl_options'] : [];
return new static($host, $port, $user, $password, $vhost, $ssl_options, $options);
}
/**
* @param array $options
* @return resource
*/
private function create_ssl_context($options)
{
$ssl_context = stream_context_create();
foreach ($options as $k => $v) {
stream_context_set_option($ssl_context, 'ssl', $k, $v);
}
return $ssl_context;
}
}
<?php
namespace PhpAmqpLib\Connection;
use PhpAmqpLib\Wire\IO\SocketIO;
class AMQPSocketConnection extends AbstractConnection
{
/**
* @param string $host
* @param int $port
* @param string $user
* @param string $password
* @param string $vhost
* @param bool $insist
* @param string $login_method
* @param null $login_response @deprecated
* @param string $locale
* @param int|float $read_timeout
* @param bool $keepalive
* @param int $write_timeout
* @param int $heartbeat
* @param float $channel_rpc_timeout
* @throws \Exception
*/
public function __construct(
$host,
$port,
$user,
$password,
$vhost = '/',
$insist = false,
$login_method = 'AMQPLAIN',
$login_response = null,
$locale = 'en_US',
$read_timeout = 3,
$keepalive = false,
$write_timeout = 3,
$heartbeat = 0,
$channel_rpc_timeout = 0.0
) {
if ($channel_rpc_timeout > $read_timeout) {
throw new \InvalidArgumentException('channel RPC timeout must not be greater than I/O read timeout');
}
$io = new SocketIO($host, $port, $read_timeout, $keepalive, $write_timeout, $heartbeat);
parent::__construct(
$user,
$password,
$vhost,
$insist,
$login_method,
$login_response,
$locale,
$io,
$heartbeat,
max($read_timeout, $write_timeout),
$channel_rpc_timeout
);
}
protected static function try_create_connection($host, $port, $user, $password, $vhost, $options){
$insist = isset($options['insist']) ?
$options['insist'] : false;
$login_method = isset($options['login_method']) ?
$options['login_method'] :'AMQPLAIN';
$login_response = isset($options['login_response']) ?
$options['login_response'] : null;
$locale = isset($options['locale']) ?
$options['locale'] : 'en_US';
$read_timeout = isset($options['read_timeout']) ?
$options['read_timeout'] : 3;
$keepalive = isset($options['keepalive']) ?
$options['keepalive'] : false;
$write_timeout = isset($options['write_timeout']) ?
$options['write_timeout'] : 3;
$heartbeat = isset($options['heartbeat']) ?
$options['heartbeat'] : 0;
return new static($host,
$port,
$user,
$password,
$vhost,
$insist,
$login_method,
$login_response,
$locale,
$read_timeout,
$keepalive,
$write_timeout,
$heartbeat);
}
}
<?php
namespace PhpAmqpLib\Connection;
use PhpAmqpLib\Wire\IO\StreamIO;
class AMQPStreamConnection extends AbstractConnection
{
/**
* @param string $host
* @param string $port
* @param string $user
* @param string $password
* @param string $vhost
* @param bool $insist
* @param string $login_method
* @param null $login_response @deprecated
* @param string $locale
* @param float $connection_timeout
* @param float $read_write_timeout
* @param null $context
* @param bool $keepalive
* @param int $heartbeat
* @param float $channel_rpc_timeout
* @param string|null $ssl_protocol
*/
public function __construct(
$host,
$port,
$user,
$password,
$vhost = '/',
$insist = false,
$login_method = 'AMQPLAIN',
$login_response = null,
$locale = 'en_US',
$connection_timeout = 3.0,
$read_write_timeout = 3.0,
$context = null,
$keepalive = false,
$heartbeat = 0,
$channel_rpc_timeout = 0.0,
$ssl_protocol = null
) {
if ($channel_rpc_timeout > $read_write_timeout) {
throw new \InvalidArgumentException('channel RPC timeout must not be greater than I/O read-write timeout');
}
$io = new StreamIO(
$host,
$port,
$connection_timeout,
$read_write_timeout,
$context,
$keepalive,
$heartbeat,
$ssl_protocol
);
parent::__construct(
$user,
$password,
$vhost,
$insist,
$login_method,
$login_response,
$locale,
$io,
$heartbeat,
$connection_timeout,
$channel_rpc_timeout
);
// save the params for the use of __clone, this will overwrite the parent
$this->construct_params = func_get_args();
}
protected static function try_create_connection($host, $port, $user, $password, $vhost, $options){
$insist = isset($options['insist']) ?
$options['insist'] : false;
$login_method = isset($options['login_method']) ?
$options['login_method'] :'AMQPLAIN';
$login_response = isset($options['login_response']) ?
$options['login_response'] : null;
$locale = isset($options['locale']) ?
$options['locale'] : 'en_US';
$connection_timeout = isset($options['connection_timeout']) ?
$options['connection_timeout'] : 3.0;
$read_write_timeout = isset($options['read_write_timeout']) ?
$options['read_write_timeout'] : 130.0;
$context = isset($options['context']) ?
$options['context'] : null;
$keepalive = isset($options['keepalive']) ?
$options['keepalive'] : false;
$heartbeat = isset($options['heartbeat']) ?
$options['heartbeat'] : 60;
return new static($host,
$port,
$user,
$password,
$vhost,
$insist,
$login_method,
$login_response,
$locale,
$connection_timeout,
$read_write_timeout,
$context,
$keepalive,
$heartbeat);
}
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPBasicCancelException extends \Exception implements AMQPExceptionInterface
{
/**
* @var string
* @internal Use getter getConsumerTag()
*/
public $consumerTag;
/**
* @param string $consumerTag
*/
public function __construct($consumerTag)
{
parent::__construct('Channel was canceled');
$this->consumerTag = $consumerTag;
}
/**
* @return string
*/
public function getConsumerTag()
{
return $this->consumerTag;
}
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPChannelClosedException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
/**
* @deprecated use AMQPProtocolChannelException instead
*/
class AMQPChannelException extends AMQPException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPConnectionBlockedException extends AMQPRuntimeException
{
public function __construct($message = '', $code = 0, $previous = null)
{
if (empty($message)) {
$message = 'Connection is blocked due to low resources';
}
parent::__construct($message, $code, $previous);
}
}
<?php
namespace PhpAmqpLib\Exception;
/**
* When connection was closed by server, proxy or some tunnel due to timeout or network issue.
*/
class AMQPConnectionClosedException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
/**
* @deprecated use AMQPProtocolConnectionException instead
*/
class AMQPConnectionException extends AMQPException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPDataReadException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPEmptyDeliveryTagException extends AMQPRuntimeException
{
}
\ No newline at end of file
<?php
namespace PhpAmqpLib\Exception;
/**
* @deprecated use AMQPProtocolException instead
*/
class AMQPException extends \Exception
{
/** @var string */
public $amqp_reply_code;
/** @var int */
public $amqp_reply_text;
/** @var int[] */
public $amqp_method_sig;
/** @var array */
public $args;
/**
* @param string $reply_code
* @param int $reply_text
* @param array $method_sig
*/
public function __construct($reply_code, $reply_text, $method_sig)
{
parent::__construct($reply_text, $reply_code);
$this->amqp_reply_code = $reply_code; // redundant, but kept for BC
$this->amqp_reply_text = $reply_text; // redundant, but kept for BC
$this->amqp_method_sig = $method_sig;
$this->args = array($reply_code, $reply_text, $method_sig, '');
}
}
<?php
namespace PhpAmqpLib\Exception;
interface AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPHeartbeatMissedException extends AMQPConnectionClosedException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPIOException extends \Exception implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPIOWaitException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPInvalidArgumentException extends \RuntimeException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPInvalidFrameException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPLogicException extends \LogicException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
/**
* Used mostly in non-blocking methods when no data is ready for processing.
*/
class AMQPNoDataException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPNotImplementedException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPOutOfBoundsException extends \OutOfBoundsException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPOutOfRangeException extends \OutOfRangeException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPProtocolChannelException extends AMQPProtocolException
{
}
<?php
namespace PhpAmqpLib\Exception;
/**
* @deprecated
*/
class AMQPProtocolConnectionException extends AMQPProtocolException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPProtocolException extends \Exception implements AMQPExceptionInterface
{
/** @var string */
public $amqp_reply_code;
/** @var int */
public $amqp_reply_text;
/** @var int[] */
public $amqp_method_sig;
/** @var array */
public $args;
/**
* @param string $reply_code
* @param int $reply_text
* @param array $method_sig
*/
public function __construct($reply_code, $reply_text, $method_sig)
{
parent::__construct($reply_text, $reply_code);
$this->amqp_reply_code = $reply_code; // redundant, but kept for BC
$this->amqp_reply_text = $reply_text; // redundant, but kept for BC
$this->amqp_method_sig = $method_sig;
$this->args = array($reply_code, $reply_text, $method_sig);
}
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPRuntimeException extends \RuntimeException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPSocketException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPTimeoutException extends \RuntimeException implements AMQPExceptionInterface
{
/**
* @var int|float|null
*/
private $timeout;
public function __construct($message = '', $timeout = 0, $code = 0, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);
$this->timeout = $timeout;
}
/**
* @param int|float|null $timeout
* @param int $code
* @return self
*/
public static function writeTimeout($timeout, $code = 0)
{
return new self('Error sending data. Connection timed out.', $timeout, $code);
}
/**
* @return int|float|null
*/
public function getTimeout()
{
return $this->timeout;
}
}
<?php
namespace PhpAmqpLib\Exchange;
final class AMQPExchangeType
{
const DIRECT = 'direct';
const FANOUT = 'fanout';
const TOPIC = 'topic';
const HEADERS = 'headers';
}
<?php
namespace PhpAmqpLib\Helper;
use InvalidArgumentException;
class Assert
{
/**
* @param mixed $argument
* @throws \InvalidArgumentException
*/
public static function isCallable($argument)
{
if (!is_callable($argument)) {
throw new InvalidArgumentException(sprintf(
'Given argument "%s" should be callable. %s type was given.',
$argument,
gettype($argument)
));
}
}
}
<?php
namespace PhpAmqpLib\Helper;
use PhpAmqpLib\Wire\Constants;
class DebugHelper
{
/**
* @var bool
*/
protected $debug;
/**
* @var resource
*/
protected $debug_output;
/**
* @var Constants
*/
protected $constants;
/**
* @param Constants $constants
*/
public function __construct(Constants $constants)
{
if(!defined('STDOUT')) {
define('STDOUT', fopen('php://stdout', 'w'));
}
$this->debug = defined('AMQP_DEBUG') ? AMQP_DEBUG : false;
$this->debug_output = defined('AMQP_DEBUG_OUTPUT') ? AMQP_DEBUG_OUTPUT : STDOUT;
$this->constants = $constants;
}
/**
* @param string $msg
*/
public function debug_msg($msg) {
if ($this->debug) {
$this->print_msg($msg);
}
}
/**
* @param array $allowed_methods
*/
public function debug_allowed_methods($allowed_methods) {
if ($allowed_methods) {
$msg = 'waiting for ' . implode(', ', $allowed_methods);
} else {
$msg = 'waiting for any method';
}
$this->debug_msg($msg);
}
/**
* @param string $method_sig
*/
public function debug_method_signature1($method_sig) {
$this->debug_method_signature('< %s:', $method_sig);
}
/**
* @param string $msg
* @param string $method_sig
*/
public function debug_method_signature($msg, $method_sig) {
if ($this->debug) {
$constants = $this->constants;
$methods = $constants::$GLOBAL_METHOD_NAMES;
$key = MiscHelper::methodSig($method_sig);
$this->debug_msg(sprintf($msg . ': %s', $key, $methods[$key]));
}
}
/**
* @param string $data
*/
public function debug_hexdump($data) {
if ($this->debug) {
$this->debug_msg(sprintf(
'< [hex]: %s%s',
PHP_EOL,
MiscHelper::hexdump($data, $htmloutput = false, $uppercase = true, $return = true)
));
}
}
/**
* @param int $version_major
* @param int $version_minor
* @param array $server_properties
* @param array $mechanisms
* @param array $locales
*/
public function debug_connection_start($version_major, $version_minor, $server_properties, $mechanisms, $locales) {
if ($this->debug) {
$this->debug_msg(sprintf(
'Start from server, version: %d.%d, properties: %s, mechanisms: %s, locales: %s',
$version_major,
$version_minor,
MiscHelper::dump_table($server_properties),
implode(', ', $mechanisms),
implode(', ', $locales)
));
}
}
/**
* @param string $s
*/
protected function print_msg($s) {
fwrite($this->debug_output, $s . PHP_EOL);
}
}
<?php
namespace PhpAmqpLib\Helper;
class MiscHelper
{
/**
* @param string|array $a
* @return string
*/
public static function methodSig($a)
{
if (is_string($a)) {
return $a;
}
return sprintf('%d,%d', $a[0], $a[1]);
}
/**
* Gets a number (either int or float) and returns an array containing its integer part as first element and its
* decimal part mutliplied by 10^6. Useful for some PHP stream functions that need seconds and microseconds as
* different arguments
*
* @param int|float $number
* @return int[]
*/
public static function splitSecondsMicroseconds($number)
{
return array((int)floor($number), (int)(fmod($number, 1) * 1000000));
}
/**
* View any string as a hexdump.
*
* This is most commonly used to view binary data from streams
* or sockets while debugging, but can be used to view any string
* with non-viewable characters.
*
* @version 1.3.2
* @author Aidan Lister <aidan@php.net>
* @author Peter Waller <iridum@php.net>
* @link http://aidanlister.com/repos/v/function.hexdump.php
*
* @param string $data The string to be dumped
* @param bool $htmloutput Set to false for non-HTML output
* @param bool $uppercase Set to true for uppercase hex
* @param bool $return Set to true to return the dump
* @return string|null
*/
public static function hexdump($data, $htmloutput = true, $uppercase = false, $return = false)
{
// Init
$hexi = '';
$ascii = '';
$dump = $htmloutput ? '<pre>' : '';
$offset = 0;
$len = mb_strlen($data, 'ASCII');
// Upper or lower case hexidecimal
$hexFormat = $uppercase ? 'X' : 'x';
// Iterate string
for ($i = $j = 0; $i < $len; $i++) {
// Convert to hexidecimal
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$hexi .= sprintf('%02' . $hexFormat . ' ', ord($data[$i]));
// Replace non-viewable bytes with '.'
if (ord($data[$i]) >= 32) {
$ascii .= $htmloutput ? htmlentities($data[$i]) : $data[$i];
} else {
$ascii .= '.';
}
// Add extra column spacing
if ($j === 7) {
$hexi .= ' ';
$ascii .= ' ';
}
// Add row
if (++$j === 16 || $i === $len - 1) {
// Join the hexi / ascii output
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$dump .= sprintf('%04' . $hexFormat . ' %-49s %s', $offset, $hexi, $ascii);
// Reset vars
$hexi = $ascii = '';
$offset += 16;
$j = 0;
// Add newline
if ($i !== $len - 1) {
$dump .= PHP_EOL;
}
}
}
// Finish dump
$dump .= $htmloutput ? '</pre>' : '';
$dump .= PHP_EOL;
if ($return) {
return $dump;
}
echo $dump;
return null;
}
/**
* @param array $table
* @return string
*/
public static function dump_table($table)
{
$tokens = array();
foreach ($table as $name => $value) {
switch ($value[0]) {
case 'D':
$val = $value[1]->n . 'E' . $value[1]->e;
break;
case 'F':
$val = '(' . self::dump_table($value[1]) . ')';
break;
case 'T':
$val = date('Y-m-d H:i:s', $value[1]);
break;
default:
$val = $value[1];
}
$tokens[] = $name . '=' . $val;
}
return implode(', ', $tokens);
}
}
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment