定制 andrei930/tinx 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

andrei930/tinx

Composer 安装命令:

composer require andrei930/tinx

包简介

Reload your Laravel Tinker session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!

README 文档

README

Updated version of Furey/Tinx

Link to the original package

Looking for a reloadable version of Laravel Tinker?

Save the following script as tinx.sh to your project root directory:

#!/bin/sh
while true; do php artisan tinker; done

Run the script to launch a reloadable version of Tinker:

$ . tinx.sh

While your Tinker session is running, press:

  • Ctrl + D from an empty prompt to reload your session
  • Ctrl + C to exit your session

Can't see newly created classes in Tinker?

Exit your Tinker session and run:

$ composer dump -o

Thanks for loving Laravel, and thanks for digging Tinx.

Happy coding!

🤓👋

Laravel Tinx

Laravel Tinker, re()loaded.

Reload your session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!

Contents

Installation

To install Tinx, simply require it via Composer:

composer require --dev andrei930/tinx

If using Laravel <=5.4, register Tinx's service provider in config/app.php (Laravel >=5.5 does this automatically):

<?php

// 'config/app.php'

return [
    // etc…
    'providers' => [
        // etc…
        Ajthinking\Tinx\TinxServiceProvider::class,
        // etc…
    ],
    // etc…
];

Usage

From the command line, instead of running php artisan tinker, run:

php artisan tinx

Reload your Tinker session

To reboot your current session, simply call:

re()

This will allow you to immediately test out your application's code changes.

Aliases: reboot(), reload(), restart().

To regenerate Composer's optimized autoload files before rebooting your current session, call:

reo()

Calling reo() simply runs composer dump -o before re(), ensuring any new classes added to your codebase since starting Tinx are automatically aliasable/resolvable by Laravel Tinker.

Magic models

Tinx sniffs your models and prepares the following shortcuts:

Example Shortcut Equals
$u App\User::first()
$u_ App\User::latest()->first()
$c App\Models\Car::first()
u(3) App\User::find(3)
u("gmail") Where "%gmail%" is found in any column.
u("mail", "jon@snow.com") App\User::where("mail", "jon@snow.com")->get()
u("id", ">", 0) App\User::where("id", ">", 0)->get()
u() "App\User"
u()::whereRaw(...) App\User::whereRaw(...) // Note: >= PHP 7.0 only

Naming strategy

Tinx calculates shortcut names via the implementation defined by your strategy config value.

Lets say you have two models: Car and Crocodile.

If your naming strategy was set to pascal (default), Tinx would define the following shortcuts in your session:

  • Car: $c, $c_, c()
  • Crocodile: $cr, $cr_, cr()

Names

The shortcuts defined for your session will display when Tinx loads and on subsequent reloads.

To see your shortcuts at any time during your session, run:

names()

Your shortcuts will initially display only if your session satisfies the names_table_limit config value.

To filter the shortcuts returned by names(), simply pass your filter terms like so:

names('car', 'user')

Fast factories

Shortcut methods are a great way to create factory models fast.

// Instead of this…
factory(App\User::class)->create()

// …try substituting a shortcut method, like this:
factory(u())->create()

When tinkering, every keystroke counts!

Configuration

Tinx contains a number of helpful configuration options.

To personalise your Tinx installation, publish its config file by running:

php artisan vendor:publish --provider=Ajthinking\\Tinx\\TinxServiceProvider --force

Once published, edit config/tinx.php where appropriate to suit your needs:

<?php

// 'config/tinx.php'

return [

    /**
     * Base paths to search for models (paths ending in '*' search recursively).
     * */
    'model_paths' => [
        '/app',
        '/app/Models/*',
        // '/also/search/this/directory',
        // '/also/search/this/directory/recursively/*',
    ],

    /**
     * Only define these models (all other models will be ignored).
     * */
    'only' => [
        // 'App\OnlyThisModel',
        // 'App\AlsoOnlyThisModel',
    ],

    /**
     * Ignore these models.
     * */
    'except' => [
        // 'App\IgnoreThisModel',
        // 'App\AlsoIgnoreThisModel',
    ],

    /**
     * Model shortcut naming strategy (e.g. 'App\User' = '$u', '$u_', 'u()').
     * Supported values: 'pascal', 'shortestUnique'
     * */
    'strategy' => 'pascal',
    /**
     * Alternatively, you may pass a resolvable fully qualified class name
     * implementing 'Ajthinking\Tinx\Naming\Strategy'.
     * */
    // 'strategy' => App\CustomNamingStrategy::class,

    /**
     * Column name (e.g. 'id', 'created_at') used to determine last model shortcut (i.e. '$u_').
     * */
    'latest_column' => 'created_at',

    /**
     * If true, models without database tables will also have shortcuts defined.
     * */
    'tableless_models' => false,

    /**
     * Include these file(s) before starting tinker.
     * */
    'include' => [
        // '/include/this/file.php',
        // '/also/include/this/file.php',
    ],

    /**
     * Show the console 'Class/Shortcuts' table for up to this many model names, otherwise, hide it.
     * To always view the 'Class/Shortcuts' table regardless of the model name count,
     * pass a 'verbose' flag when booting Tinx (e.g. "php artisan tinx -v"),
     * or set this value to '-1'.
     * */
    'names_table_limit' => 10,

];

Contributing

Please post issues and send PRs.

License

MIT

andrei930/tinx 适用场景与选型建议

andrei930/tinx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.36k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 andrei930/tinx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 andrei930/tinx 我们能提供哪些服务?
定制开发 / 二次开发

基于 andrei930/tinx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-24