2017 © Pedro Peláez
 

library byname

PHP trait for bynaming (nicknaming) classes/objects

image

gregoriohc/byname

PHP trait for bynaming (nicknaming) classes/objects

  • Monday, April 30, 2018
  • by gregoriohc
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

byname

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

PHP trait for bynaming (nicknaming) classes/objects., (*2)

Install

Via Composer, (*3)

``` bash $ composer require gregoriohc/byname, (*4)


## Usage By default, the class byname is the class basename (without namespace). ``` php 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., (*5)

``` php class MyClass { use HasByname; protected static function bynamePrefix() { return 'My'; } }, (*6)

echo MyClass::byname(); // Class, (*7)


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

A more complex example, mixing this with inheritance:, (*8)

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

class UserController extends BaseController { ... }, (*10)

echo UserController::byname(); // User, (*11)

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


### Custom byname You can set a custom byname overriding the `bynameValue` method. ``` php 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:, (*13)

``` php class MyClass { use HasByname; }, (*14)

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


## Testing ``` bash $ composer test

Change log

Please see CHANGELOG for more information on what has changed recently., (*16)

Contributing

Please see CONTRIBUTING for details., (*17)

Security

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

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., (*19)

Credits

License

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

The Versions

30/04 2018

dev-master

9999999-dev https://github.com/gregoriohc/byname

PHP trait for bynaming (nicknaming) classes/objects

  Sources   Download

MIT

The Requires

 

The Development Requires

gregoriohc byname

30/04 2018

v1.0.1

1.0.1.0 https://github.com/gregoriohc/byname

PHP trait for bynaming (nicknaming) classes/objects

  Sources   Download

MIT

The Requires

 

The Development Requires

gregoriohc byname

05/02 2018

v1.0.0

1.0.0.0 https://github.com/gregoriohc/byname

PHP trait for bynaming (nicknaming) classes/objects

  Sources   Download

MIT

The Requires

 

The Development Requires

gregoriohc byname