PHP code example of alicfeng / laravel-helper
1. Go to this page and download the library: Download alicfeng/laravel-helper library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alicfeng / laravel-helper example snippets
[
'providers' => [
AlicFeng\Helper\ServiceProvider\HelperServiceProvider::class,
]
];
// about package setting
return [
'package' => [
/*Response Package Structure*/
'structure' => [
'code' => 'code',
'message' => 'message',
'data' => 'data',
],
// Default Header simple:Content-Type => application/json
'header' => [
],
/*Package encrypt Setting*/
'crypt' => [
'instance' => \AlicFeng\Helper\Crypt\HelperCryptService::class,
'method' => 'aes-128-ecb',
'password' => '1234qwer',
],
/*Package format (json | xml)*/
'format' => 'json',
/*Log*/
'log' => [
'log' => true,
'level' => 'notice',
],
],
// about log setting
'log' => [
'extra_field' => [
'runtime_file' => true,
'memory_message' => false,
'web_message' => false,
'process_id' => false,
],
],
// translate
'translate' => [
'model' => true,
'instance' => \AlicFeng\Helper\Translate\Translation::class,
],
// runtime model
'runtime' => [
'trace' => [
'request' => true,
'response' => false,
'filter_uri' => [
]
],
],
// debug model setting
'debug' => false
];
class HelloService extends HelperServiceAbstract {
public function __construct()
{
parent::__construct();
}
public function package(string $name = '')
{
$codeEnum = [1000, 'success']; // this should define in app/Enum/CodeEnum.php
$result = [
'name' => $name,
'age' => 24,
];
// return $this->rspHelper->transform(DemoTransform::class)->result($codeEnum, $result);
return $this->rspHelper->result($codeEnum, $result);
}
}
protected $routeMiddleware = [
'package.encrypt'=>\AlicFeng\Helper\Middleware\EncryptMiddleware::class
];
Route::middleware('package.encrypt')->get('/package', 'HelloController@package');
/**
*@return \Symfony\Component\HttpFoundation\Response
*/
$response = CurlHelper::get(...);
$response = CurlHelper::post(...);
$response = CurlHelper::put(...);
$response = CurlHelper::delete(...);
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'permission' => 0777,
'tap' => [\AlicFeng\Helper\Component\Log\LogEnhancer::class],
'days' => 7,
'formatter' => \Monolog\Formatter\LineFormatter::class,
'formatter_with' => [
'dateFormat' => 'Y-m-d H:i:s.u',
'allowInlineLineBreaks' => true,
'ignoreEmptyContextAndExtra' => true,
'format' => "[%datetime%] %channel%.%level_name%: %message% %context%\n%extra%\n"
]
]
Log::info('push cash', ['user_id' => 9510, 'cash' => '52.00']);
Log::debug('source data come from cache');
Log::notice('sync article successful', ['user_id' => 9510]);
Log::warning('logout failed', ['user_id' => 8888]);
// or
LogHelper::info('push cash', ['user_id' => 9510, 'cash' => '52.00']);
LogHelper::debug('source data come from cache');
LogHelper::notice('sync article successful', ['user_id' => 9510]);
LogHelper::warning('logout failed', ['user_id' => 8888]);
DateTimeHelper::msectime()
shell
php artisan vendor:publish --provider="AlicFeng\Helper\ServiceProvider\HelperServiceProvider"
[2019-08-20 23:36:37.310839] local.INFO: push cash {"user_id":9510,"cash":"52.00"}
{"memory_usage":"14 MB","memory_peak_usage":"14 MB","runtime_file":{"file":"/Users/alicfeng/tutorial/github/tmp/demo/app/Console/Commands/AlicFeng.php:69","function":"App\\Console\\Commands\\AlicFeng->handle"}}
[2019-08-20 23:36:37.311712] local.DEBUG: source data come from cache
{"memory_usage":"14 MB","memory_peak_usage":"14 MB","runtime_file":{"file":"/Users/alicfeng/tutorial/github/tmp/demo/app/Console/Commands/AlicFeng.php:71","function":"App\\Console\\Commands\\AlicFeng->handle"}}
[2019-08-20 23:36:37.311834] local.NOTICE: sync article successful {"user_id":9510}
{"memory_usage":"14 MB","memory_peak_usage":"14 MB","runtime_file":{"file":"/Users/alicfeng/tutorial/github/tmp/demo/app/Console/Commands/AlicFeng.php:73","function":"App\\Console\\Commands\\AlicFeng->handle"}}
[2019-08-20 23:36:37.311935] local.WARNING: logout failed {"user_id":8888}
{"memory_usage":"14 MB","memory_peak_usage":"14 MB","runtime_file":{"file":"/Users/alicfeng/tutorial/github/tmp/demo/app/Console/Commands/AlicFeng.php:75","function":"App\\Console\\Commands\\AlicFeng->handle"}}
shell
php artisan samego:framework