PHPackages                             acfunpro/afcloudstorage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. acfunpro/afcloudstorage

ActiveLibrary[File &amp; Storage](/categories/file-storage)

acfunpro/afcloudstorage
=======================

cloud storage by Acfun, Inc.

1.1.7(7y ago)01111proprietaryPHPPHP &gt;=5.3.0

Since Nov 18Pushed 7y agoCompare

[ Source](https://github.com/acfunpro/afcloudstorage)[ Packagist](https://packagist.org/packages/acfunpro/afcloudstorage)[ RSS](/packages/acfunpro-afcloudstorage/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (3)Versions (19)Used By (0)

\####安装方法

```
github 地址
	https://github.com/acfunpro/afcloudstorage.git

composer require acfunpro/afcloudstorage

在/config/app.php文件中加入
	'afcloud' => array(
		'form'=>'admin',
		'take' => 10
	),
	form值用来与url中_afForm参数对比，如果相等则为后台请求,若不设置默认为admin
	take值为限制返回条数，默认为20条
	在providers中加入
		Jenssegers\Mongodb\MongodbServiceProvider::class,
		Mews\Purifier\PurifierServiceProvider::class,
	在aliases加入
		'Mongo'     => Jenssegers\Mongodb\MongodbServiceProvider::class,
		'Purifier' => Mews\Purifier\Facades\Purifier::class,

在/app/Http/routes.php加入
Route::group( [ 'prefix' => 'api', 'middleware' => 'AfCloud' ] , function(){
	Route::resource( "auto" , "AfCloudController" );
});

执行 $ php artisan make:middleware AfCloudMiddleware
生成/app/Http/Middleware/目录下生成AfCloudMiddleware.php
修改handle方法为 因为_afClass是必须存在的，加入中间件判断
public function handle($request, Closure $next)
{
	$arrInputData = Input::all();
	if( !empty( $arrInputData[ '_afClass' ] ) && ! preg_match( '/[^\w\-]/' , $arrInputData[ '_afClass' ] ) && !empty( $arrInputData[ '_afForm' ] ) && Config::get('app.afcloud.form') == $arrInputData[ '_afForm' ] )
	{
		return $next($request);
	}
	else
	{
		return response('Unauthorized.', 401);
	}
}
在加入/app/Http/Kernel.php加入
	'AfCloud' => \App\Http\Middleware\AfCloudMiddleware::class,

在/app/Http/Middleware/VerifyCsrfToken.php文件$except中加入
	'/api*'

在文件中使用
	use acfunpro\afcloudstorage\AfCloudStorage;

// 如果使用vdate
	在App\Http\Controllers.php 文件中加入
	use dekuan\vdata\CRemote;
	function __construct()
	{
		$this->m_sAcceptedVersion = CRemote::GetAcceptedVersionEx();
	}

部署完毕后在根目录执行
		php artisan optimize

```

\####说明 采用mongodb存储数据 保留表名：\_SetupTables (对所有表的列设置信息) \_LogTables (接口请求日志) 请求示例： {url}?\_afClass=test&amp;\_afWhere={"name":\["lk","test%"\],"id":\["gt":"3"\]}&amp;\_afOther={"order":\["sort","asc"\]}

\####提供方法 基于RESTful设计原则

```
$arrOutPutData 接收返回数据
$sErroeMsg     返回错误信息
$nCall         错误码 0为正常

获取全部对象
	$AfCloud = AfCloudStorage::GetInstance();
	$nCall  = $AfCloud->GetIndex( $arrOutPutData, $sErroeMsg );

获取一个对象
	$nCall  = $AfCloud->GetShow( $arrOutPutData, $sErroeMsg, $id );

创建对象
	$nCall  = $AfCloud->PostStore( $arrOutPutData, $sErroeMsg );

修改对象
	$nCall  = $AfCloud->PostStore( $arrOutPutData, $sErroeMsg, $id );

删除对象
	$nCall  = $AfCloud->GetDestroy( $arrOutPutData, $sErroeMsg, $id );

获取对应表的设置数据   $vFlag为false 返回所有数据 / true 只返回相关的字段
	$nCall  = $AfCloud->GetTablesColumn( $vFlag = false );

设置参数
	参数： $arrMData 键名接受 _afDBTableName，_afArrInputData
	          _afDBTableName  操作的表名
	          _afArrInputData 条件设置 _afForm，_afWhere，_afOther
	      $bFlag false将_afArrInputData的参数覆盖url的参数
	              true将_afArrInputData的参数追加到url的参数
	$nCall  = $AfCloud->SetVar( $arrMData = [], $bFlag = false );

获取参数
		_afRequestForm  返回值 Index为前台请求 ／ Admin为后台请求
		_afDBTableName  返回值 操作的表名
		_afArrInputData 返回值 查询条件
	$nCall  = $AfCloud->GetVar();

获取对_afid
	定义为主键id生成规则：substr(md5(microtime().rand(0,9999).rand(0,9999)),8,16);
	$nCall  = $AfCloud->GetAfid();

```

\####前台请求URL get {url}?\_afClass=test 获取全部对象 实现方法 GetIndex( array &amp; $arrOutputData = \[\], &amp; $sErroeMsg = '' )

```
get     {url}/1?_afClass=test  获取一个对象 默认字段为id
			若字段名为mid则写成
			{url}/mid.1
		实现方法  GetShow( array & $arrOutputData = [], & $sErroeMsg = '', $id )

post    {url}?_afClass=test   创建对象
		实现方法  PostStore( array & $arrOutputData = [], & $sErroeMsg = '')

put     {url}/1?_afClass=test  修改一个对象 默认字段为id
			若字段名为mid则写成
			{url}/mid.1
		实现方法	PostStore( array & $arrOutputData = [], & $sErroeMsg = '', $id = '' )

delete  {url}/1?_afClass=test  删除对象 默认字段为id
			若字段名为mid则写成
			{url}/mid.1
		实现方法	GetDestroy( &$arrOutputData, &$sErroeMsg, $id = '' )

```

\####前台参数 带\*为必填 \*\_afClass = test // 表名 \_afForm = admin // 标明来源

```
	_afWhere = {"name":"abc"}   // 返回name值为abc的数据
	_afWhere = {"id",["gt","5"]} // 返回id大于5的数据
		// gt处可选参数
		[
			'gt' => '>' ,
			'ge' => '>=',
			'lt' => '
