承接 shomisha/stubless 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shomisha/stubless

最新稳定版本:1.5.1

Composer 安装命令:

composer require shomisha/stubless

包简介

A package for generating PHP files without stubs.

README 文档

README

Latest Stable Version Software License

Stubless is a package for generating PHP source code using a readable, fluent, object-oriented API, and without the usage of any stubs. It is ideal for generator commands and takes away the need for manipulating strings when programmatically generating PHP code.

Here is an example of what Stubless can do:

<?php

require_once 'vendor/autoload.php';

use App\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Shomisha\Stubless\Templates\Argument;
use Shomisha\Stubless\Templates\ClassMethod;
use Shomisha\Stubless\Templates\ClassTemplate;
use Shomisha\Stubless\Utilities\Importable;

$class = ClassTemplate::name('UsersController')->extends(new Importable(Controller::class))->setNamespace('App\Http\Controllers');

$requestArgument = Argument::name('request')->type(new Importable(Request::class));
$userArgument = Argument::name('user')->type(new Importable(User::class));
$userRequestArgument = Argument::name('request')->type(new Importable(UserRequest::class));

$class->withMethods([
	ClassMethod::name('index')->addArgument($requestArgument),
	ClassMethod::name('show')->withArguments([
		$requestArgument,
		$userArgument,
	]),
	ClassMethod::name('store')->addArgument($userRequestArgument),
	ClassMethod::name('update')->withArguments([
		$userRequestArgument,
		$userArgument,
	]),
	ClassMethod::name('destroy')->addArgument($userArgument),
]);

echo $class->print();

The following code would generate this PHP source code:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Models\User;
use Illuminate\Http\Request;

class UsersController extends Controller
{
    public function index(Request $request)
    {
    }

    public function show(Request $request, User $user)
    {
    }

    public function store(UserRequest $request)
    {
    }

    public function update(UserRequest $request, User $user)
    {
    }

    public function destroy(User $user)
    {
    }
}

DISCLAIMER: Stubless has been developed and optimised with class generation in mind and will be upgraded with the same mindset in the near future. At some point I might devote more attention into addressing non-object-oriented PHP generation, but that's further down the road and is not planned for right now.

To learn more about how to use Stubless and all of its features check the wiki pages.

统计信息

  • 总下载量: 7.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 39
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 39
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固