定制 gregoriohc/byname 二次开发

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

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

gregoriohc/byname

最新稳定版本:v1.0.2

Composer 安装命令:

composer require gregoriohc/byname

包简介

PHP trait for bynaming (nicknaming) classes/objects

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

PHP trait for bynaming (nicknaming) classes/objects.

Install

Via Composer

$ composer require gregoriohc/byname

Usage

By default, the class byname is the class basename (without namespace).

class MyClass {
    use HasByname;
}

echo MyClass::byname();
// MyClass

Removing prefix and/or suffix

You can remove some characters from the beginning (prefix) or the end (suffix) of the byname overriding the bynamePrefix and bynameSuffix methods and returning the string to remove or the number of characters.

class MyClass {
    use HasByname;
    protected static function bynamePrefix()
    {
        return 'My';
    }
}

echo MyClass::byname();
// Class
class MyClass {
    use HasByname;
    protected static function bynameSuffix()
    {
        return 5;
    }
}

echo MyClass::byname();
// My

A more complex example, mixing this with inheritance:

abstract class BaseController {
    use HasByname;
    protected static function bynameSuffix()
    {
        return 'Controller';
    }
    public function model()
    {
        $class = '\\App\\' . $this->byname();
        return new $class();
    }
}

class UserController extends BaseController {
    ...
}

echo UserController::byname();
// User

$user = (new UserController)->model();
print_r($user);
// App\User Object (...)

Custom byname

You can set a custom byname overriding the bynameValue method.

class MyClass {
    use HasByname;
    protected static function bynameValue()
    {
        return 'Cool';
    }
}

echo MyClass::byname();
// Cool

Case

Yu can also get the name in three diferent cases:

class MyClass {
    use HasByname;
}

echo MyClass::bynameSnake();
// my_class
echo MyClass::bynameCamel();
// myClass
echo MyClass::bynameStudly();
// MyClass

Testing

$ composer test

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker.

Socialware

You're free to use this package, but if it makes it to your production environment I highly appreciate you sharing it on any social network.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-05