Download the PHP package monospice/spicy-identifier-tools without Composer
On this page you can find all versions of the php package monospice/spicy-identifier-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download monospice/spicy-identifier-tools
More information about monospice/spicy-identifier-tools
Files in monospice/spicy-identifier-tools
Package spicy-identifier-tools
Short Description An easy way to parse, convert, and format identifier names.
License MIT
Informations about the package spicy-identifier-tools
Spicy Identifier Tools
An easy way to parse, convert, and format identifier names.
These tools are helpful when working with dynamic identifier names such as dynamic methods or when working between different programming languages.
Simple Example
Or just:
Installation
If you're autoloading classes (hopefully):
Basic Usage
The package comes with three tools:
Parser
: Converts identifier strings into arrays of partsFormatter
: Comverts an array of identifier parts into a formatted stringConverter
: Parses and formats an identifier string in one step
Parser
Note: Although PHP doesn't support hyphens in identifier names, the hyphen methods may be useful when working between other languages that do, like HTML/CSS or Lisp (gasp!).
Formatter
Converter
At this time, the Converter
class only provides a generic method:
Case Formats
The CaseFormat
class contains constants that represent each case.
This package supports the following "cases" for identifiers:
Case Format | Constant Name | Example |
---|---|---|
Uppercase | UPPERCASE | ANIDENTIFIER |
Lowercase | LOWERCASE | anidentifier |
Camel Case | CAMEL_CASE | anIdentifier |
Upper Camel Case | UPPER_CAMEL_CASE or STUDLY_CAPS | AnIdentifier |
Camel Case with Acronyms | CAMEL_CASE_WITH_ACRONYMS | anIdentifierACRNM |
Upper CC with Acronyms | UPPER_CAMEL_CASE_WITH_ACRONYMS | AnIdentifierACRNM |
Underscore (snake case) | UNDERSCORE or SNAKE_CASE | an_identifier |
Upper Underscore | UPPER_UNDERSCORE | An_Identifier |
Capitalized Underscore | CAPS_UNDERSCORE | AN_IDENTIFIER |
Underscore with Acronyms | UNDERSCORE_WITH_ACRONYMS | an_identifier_ACRNM |
Upper US with Acronyms | UPPER_UNDERSCORE_WITH_ACRONYMS | An_Identifier_ACRNM |
Hyphenated | HYPHEN | an-identifier |
Upper Hyphenated | UPPER_HYPHEN | An-Identifier |
Capitalized Hyphenated | CAPS_HYPHEN | AN-IDENTIFIER |
Hyphenated Acronyms | HYPHEN_WITH_ACRONYMS | an-identifier-ACRNM |
Upper Hy. with Acronyms | UPPER_HYPHEN_WITH_ACRONYMS | An-Identifier-ACRNM |
Note: Because the Parser
class does not perform formatting, when using the
::parse()
method, one must choose a "base" case to parse from, such as
CAMEL_CASE
, not UPPER_CAMEL_CASE
or CAMEL_CASE_WITH_ACRONYMS
.
Acronyms in Identifier Names
Sometimes identifier names contain acronyms, such as JavaScript's
XMLHttpRequest
. The Parser
class preserves these acronyms:
However, the Formatter
and Converter
classes will not preserve these
acronyms unless one chooses an output format with acronyms:
This behavior provides flexibility when converting or normalizing identifier names.
Identifiers with Mixed Case
Although mixed case identifiers are not recommended in practice, one may use
the Parser
to parse identifiers that contain multiple cases:
The package does not provide support to output identifiers in a mixed format.
Extended ASCII Identifiers (Experimental)
PHP supports extended ASCII characters in identifier names. For example, the
character ä
in:
When parsing identifiers by underscore or hyphen, these characters have no
effect. However, camel case identifiers may include words that are delimited
by extended ASCII characters, such as änÏdentifierNáme
.
The Spicy Identifier Tools package provides an experimental method to parse these identifiers:
The consistency of this method depends on the character encoding of the source files and the environment language and encoding settings. As a best practice, one should avoid using extended ASCII characters in identifier names.
For more information, visit the PHP Manual: http://php.net/manual/en/language.variables.basics.php
Testing
The Spicy Identifier Tools package uses PHPUnit to test input variations and PHPSpec for object behavior.
License
The MIT License (MIT). Please see the LICENSE File for more information.