https://github.com/organiseyou/nameservice
PHP library for converting internal names
https://github.com/organiseyou/nameservice
hacktoberfest library php
Last synced: 6 months ago
JSON representation
PHP library for converting internal names
- Host: GitHub
- URL: https://github.com/organiseyou/nameservice
- Owner: OrganiseYou
- License: mit
- Created: 2023-02-19T11:51:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-10-22T09:23:25.000Z (9 months ago)
- Last Synced: 2025-11-22T11:19:56.204Z (8 months ago)
- Topics: hacktoberfest, library, php
- Language: PHP
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Name service
This is a library that convert the names that are used in projects.
## Add service to an project
```
composer req organiseyou/name-service
```
## Usage
### Use it the service
```php
$service = new Service('organise_you');
$capitals = $service->toDatabase();
//where $value is ORGANISE_YOU
$capitals = $service->toSlug();
//where $value is organise-you
$capitals = $service->toPascalCase();
//where $value is OrganiseYou
$capitals = $service->toCamelCase();
//where $value is organiseYou
```
#### Overwrite the default transformer
Sometimes we need to overwrite the default transformer
```php
$service = new Service(
'organise-you',
fn (string $slug) => ConvertService::urlToName($slug)
);
$value = $service->toDatabase()
// where $value is ORGANISE_YOU
```
### Use the static functions
#### Convert an name from url to an internal name
```
$internalName = Organiseyou\NameService\ConvertService::urlToName($name);
```
#### Convert an friendly written name to an internal name
```
$internalName = Organiseyou\NameService\ConvertService::saveConvert($name);
```
### Convert an internal name to an url friendly name
```
$urlFriendlyName = ConvertService::convertNameToId($internalName);
```
### Convert an internal name to a camelcase name
```
$camelCase = ConvertService::toCamelCase($internalName);
```
## Run tests
To run the tests, first clone the project to an repository
```
git clone git@github.com:OrganiseYou/NameService.git
```
And go to the directory
```
cd NameService
```
Run composer install
```
php ./vendor/bin/phpunit tests
```
## Upgrade v1 to v2
I did changed the class name, change the use case from
```php
use Organiseyou\NameService\ConvertService;
```
to
```php
use Organiseyou\NameService\Convert as ConvertService;
```
And remove ``Organiseyou\NameService`` and it is backwards compatible.