PHP code example of talesoft / tale-inflector

1. Go to this page and download the library: Download talesoft/tale-inflector library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

talesoft / tale-inflector example snippets


use Tale\Inflector;

$inflector = new Inflector();

//Table generation
$inflector->inflect('ProductAttribute', ['tableize', 'pluralize']); //product_attributes
$inflector->inflect('someProperty', ['tableize']); //some_property

//Canonicalization / slugs
$inflector->inflect('Some title I inserted', ['canonicalize']); //some-title-i-inserted
$inflector->inflect('Was höre ich da?', ['canonicalize']); //was-hore-ich-da

//Or just use the static methods for quick access
Inflector::canonicalize('Some random title'); //some-random-title

use Tale\Inflector\StrategyInterface;

class MyInflectionStrategy implements StrategyInterface
{
    public function inflect(string $string): string
    {
        return "!! {$string} !!";
    }
}
 
$inflector->inflect('Test', [MyInflectionStrategy::class]); //!! Test !!
 

use Tale\Inflector\StrategyInterface;

class MyInflectionStrategy implements StrategyInterface
{
    public function inflect(string $string): string
    {
        return "!! {$string} !!";
    }
}

$inflector->addNamedStrategy('exlamize', MyInflectionStrategy::class);
$inflector->inflect('House', ['pluralize', 'exclamize']); //!! Houses !!