PHP code example of keepondream / laravel-service

1. Go to this page and download the library: Download keepondream/laravel-service 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/ */

    

keepondream / laravel-service example snippets

 
# 项目目录执行命令:
php artisan make:service {模型名称或者自定义名称(user)}
 
app
    - Services
        - UserService.php
        - AdminService.php
        - ...
 

/**
 * Description: UserService service
 * Author: WangSx
 * DateTime: 2019-11-28 13:22
 */
namespace App\Services;
use Keepondream\serviceSingleInstance\Service as BaseService;

/**
 * Author: WangSx
 * DateTime: 2019-11-28 13:22
 * Class UserService
 * @package App\Services
 * @method static string echo() echo 
 */
class UserService extends BaseService
{
    /**
     * Description: echo 
     * Author: WangSx
     * DateTime: 2019-11-28 21:23
     * @return string
     */
    public function _echo()
    {
        return "echo";
    }
    
}
 
  # 方法一: 直接静态调用,应为做了'_'方法名映射
  UserService::echo();  // 返回 字符串 'echo'
        
  # 方法二: 通过静态调用获取实例,进行链式操作
  UserService::getInstance()->_echo(); // 返回 字符串 'echo'