{"id":29270215,"url":"https://github.com/kolyunya/string-processor","last_synced_at":"2025-07-04T22:11:22.574Z","repository":{"id":57008207,"uuid":"55162117","full_name":"Kolyunya/string-processor","owner":"Kolyunya","description":"PHP string processing library.","archived":false,"fork":false,"pushed_at":"2017-04-21T11:35:28.000Z","size":74,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T17:02:07.009Z","etag":null,"topics":["camel-case","kebab-case","snake-case","string","string-manipulation","string-parsing","string-processing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kolyunya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-31T15:35:26.000Z","updated_at":"2017-04-20T14:54:37.000Z","dependencies_parsed_at":"2022-08-21T14:31:30.826Z","dependency_job_id":null,"html_url":"https://github.com/Kolyunya/string-processor","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Kolyunya/string-processor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kolyunya%2Fstring-processor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kolyunya%2Fstring-processor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kolyunya%2Fstring-processor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kolyunya%2Fstring-processor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kolyunya","download_url":"https://codeload.github.com/Kolyunya/string-processor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kolyunya%2Fstring-processor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263626326,"owners_count":23490624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camel-case","kebab-case","snake-case","string","string-manipulation","string-parsing","string-processing"],"created_at":"2025-07-04T22:11:20.167Z","updated_at":"2025-07-04T22:11:22.564Z","avatar_url":"https://github.com/Kolyunya.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP string processing library\n\n## Status\n[![Build Status](https://travis-ci.org/Kolyunya/string-processor.svg?branch=master)](https://travis-ci.org/Kolyunya/string-processor)\n[![Code Climate](https://codeclimate.com/github/Kolyunya/string-processor/badges/gpa.svg)](https://codeclimate.com/github/Kolyunya/string-processor)\n[![Latest Stable Version](https://poser.pugx.org/kolyunya/string-processor/v/stable)](https://packagist.org/packages/kolyunya/string-processor)\n\n## Description\nThis library provides a collection of string processors.\n\n## Installation\nThis library is [composer-enabled](https://packagist.org/packages/kolyunya/string-processor). The recommended way of using it in your project is to require it via `composer`.\n~~~\ncomposer require kolyunya/string-processor\n~~~\n\n## Single processor usage\n\n### Basic usage\nEach processor implements the [ProcessorInterface](https://github.com/Kolyunya/string-processor/blob/master/sources/ProcessorInterface.php) which contains the `process` method:\n~~~php\n/**\n * Processes a string and returns a processed version of the original string.\n * @param string $string A string to process.\n * @return string A processed version of the original string.\n */\npublic function process($string);\n~~~\n\nConstruct a processor and run `process($string)` on it:\n~~~php\n$processor = new Processor();\necho $processor-\u003eprocess($string);\n~~~\n\n### Shorthand usage\nYou can also use a processor without even instantiating it. Each processor has a static `run` method.\n~~~php\n/**\n * Processes a string and returns a processed version of the original string.\n * @param string $string A string to process.\n * @param object|array $parameters Parameters passed to the processor's constructor.\n * @return string A processed version of the original string.\n */\npublic static function run($string, $parameters = array());\n~~~\nYou can pass parameters to the processor's constructor in the `$parameters` array. You can also pass a single parameter without wrapping it into an array.\n~~~php\necho KebabCaseFormatter::run('snake_case'); // Output: \"snake-case\"\necho Translator::run(\n    'Лорем ипсум долор сит амет',\n    new RuEnDictionary()\n); // Output: \"Lorem ipsum dolor sit amet\"\n~~~\n\n## Processors combination\n\n### `Multiprocessor` usage\nThere is a special processor ([`Multiprocessor`](https://github.com/Kolyunya/string-processor/blob/master/sources/Multiprocessor.php)) which allows you to combine multiple processors in one. Suppose you want to convert a string to an `UPPER-KEBAB` case. You can combine two processors using `Multiprocessor` to solve this problem.\n~~~php\n$processor = new Multiprocessor([\n    new KebabCaseFormatter(),\n    new UpperCaseFormatter(),\n]);\necho $processor-\u003eprocess('snake_case'); // Output: \"SNAKE-CASE\"\necho $processor-\u003eprocess('CamelCase'); // Output: \"CAMEL-CASE\"\n~~~\nThe `UpperCaseFormatter` will be applied after the `KebabCaseFormatter`. Note that either the processors order does not matter in the first example, it actually matters in the second one.\n\nAnother common problem example is to generate URL slugs. A string should be purified from punctuation characters, converted to the `kebab-case` and transliterated. Combine the `PunctuationStripper`, the `KebabCaseFormatter` and the `Translator` using `Multiprocessor`.\n~~~php\n$processor = new Multiprocessor([\n    new RuEnTranslator(),\n    new AlphabeticalPurifier(),\n    new KebabCaseFormatter(),\n]);\necho $processor-\u003eprocess('Лорем ипсум долор сит амет'); // Output: \"lorem-ipsum-dolor-sit-amet\"\necho $processor-\u003eprocess('Привет, Мир!'); // Output: \"privet-mir\"\n~~~\n\n### Processors decoration\nEach processor is a [decorator](https://en.wikipedia.org/wiki/Decorator_pattern). The [ProcessorInterface](https://github.com/Kolyunya/string-processor/blob/master/sources/ProcessorInterface.php) contains the `decorate` method:\n~~~php\n/**\n * Decorates supplied processor with the current processor.\n * @param ProcessorInterface $processor Processor to decorate.\n * @return ProcessorInterface Current processor.\n */\npublic function decorate(ProcessorInterface $processor);\n~~~\nThat means that the above example can be implemented using processors decoration. The `Multiprocessor` usage is somewhat more readable though.\n~~~php\n$processor =\n(new RuEnTranslator())-\u003edecorate(\n    (new KebabCaseFormatter())-\u003edecorate(\n        (new PunctuationStripper())\n    )\n);\necho $processor-\u003eprocess('Лорем ипсум долор сит амет'); // Output: \"lorem-ipsum-dolor-sit-amet\"\necho $processor-\u003eprocess('Привет, Мир!'); // Output: \"privet-mir\"\n~~~\n\n## Available processors\nCurrently the following processors are implemented:\n* [Case switchers](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/CaseSwitcher.php) - format strings to arbitrary formats.\n    * [CamelCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/CamelCaseFormatter.php) - formats a string to the `CamelCase`.\n    * [KebabCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/KebabCaseFormatter.php) - formats a string to the `kebab-case`.\n    * [SnakeCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/SnakeCaseFormatter.php) - formats a string to the `snake_case`.\n    * [UpperCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/UpperCaseFormatter.php) - formats a string to the `UPPER CASE`.\n    * [LowerCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/LowerCaseFormatter.php) - formats a string to the `lower case`.\n* [Translators](https://github.com/Kolyunya/string-processor/blob/master/sources/Translit/Translator.php) - transliterate strings from one language to another.\n    * [RuEnTranslator](https://github.com/Kolyunya/string-processor/blob/master/sources/Translit/RuEnTranslator.php) - transliterates strings from Russian to English and the other way around.\n* [Purifiers](https://github.com/Kolyunya/string-processor/blob/master/sources/Purify/BasePurifier.php) - purify strings.\n    * [PunctuationStripper](https://github.com/Kolyunya/string-processor/blob/master/sources/Purify/PunctuationStripper.php) - Strips punctuation characters.\n    * [AlphabeticalPurifier](https://github.com/Kolyunya/string-processor/blob/master/sources/Purify/AlphabeticalPurifier.php) - Strips non-alphabetical characters.\n* [Multiprocessor](https://github.com/Kolyunya/string-processor/blob/master/sources/Multiprocessor.php) - combines multiple processors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkolyunya%2Fstring-processor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkolyunya%2Fstring-processor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkolyunya%2Fstring-processor/lists"}