1. Go to this page and download the library: Download neunerlei/inflection 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/ */
neunerlei / inflection example snippets
use Neunerlei\Inflection\Inflector;
Inflector::toSingular("trees"); // "tree"
use Neunerlei\Inflection\Inflector;
Inflector::toPlural("tree"); // "trees"
use Neunerlei\Inflection\Inflector;
Inflector::toSlug("Given string"); // "given-string"
use Neunerlei\Inflection\Inflector;
Inflector::toFile("Given string.jpg"); // "given-string.jpg"
// With and without path handling
Inflector::toFile("/path/with/Given string.jpg", true);
// "/path/with/given-string.jpg"
Inflector::toFile("/path/with/Given string.jpg");
// "path-with-given-string.jpg"
use Neunerlei\Inflection\Inflector;
// Sanitization in action
Inflector::toGetter("myProperty"); // "getMyProperty"
Inflector::toGetter("hasMyProperty"); // "getMyProperty"
Inflector::toGetter("my-Property"); // "getMyProperty"
Inflector::toGetter("isMyProperty"); // "getMyProperty"
Inflector::toGetter("issetProperty"); // "getIssetProperty" this works, too!
// Disable sanitization
Inflector::toGetter("isMyProperty", null, ["noSanitization"]); // "getIsMyProperty"
Inflector::toGetter("hasMyProperty", null, ["ns"]); // "getHasMyProperty"
// Change the prefix
Inflector::toGetter("myProperty", "is"); // "isMyProperty"
Inflector::toGetter("getMyProperty", "has"); // "hasMyProperty"
// Intelligent splitting works here to
Inflector::toGetter("FAQ", "is", ["intelligentSplitting"]); // "isFaq";
use Neunerlei\Inflection\Inflector;
Inflector::toSetter("Given string"); // "setGivenString"
use Neunerlei\Inflection\Inflector;
Inflector::toSetter("hasMyProperty"); // "myProperty"
use Neunerlei\Inflection\Inflector;
Inflector::toComparable("max mustermann"); // "max1 mustermann1"
Inflector::toComparable("Mustermann, Max "); // "max1 mustermann1"
Inflector::toComparable("first name last name"); // "first1 last1 name2"
use Neunerlei\Inflection\Inflector;
Inflector::toUuid("max mustermann"); // "c47276d9-be31-5329-40d9-25fc290609ec"
Inflector::toUuid("Mustermann, Max "); // "c47276d9-be31-5329-40d9-25fc290609ec"
Inflector::toUuid("first name last name"); // "7f9f995d-6b94-460e-0158-edd97a8b016a"
namespace YourVendor\YourNamespace;
use Neunerlei\Inflection\Adapter\InflectorAdapterInterface;
class MyInflectorAdapter implements InflectorAdapterInterface{
public function toSingular(string $pluralWord) : string{
// Your fancy inflector does it's job here...
}
public function toPlural(string $singularWord) : string{
// Your fancy inflector does it's job here...
}
}
namespace YourVendor\YourNamespace;
use Neunerlei\Inflection\Inflector;
// If your adapter does not need any dependencies
Inflector::$inflectorAdapterClass = MyInflectorAdapter::class;
// If you have to instantiate your adapter first
Inflector::setInflectorAdapter(new MyInflectorAdapter());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.