Download the PHP package kynx/code-utils without Composer

On this page you can find all versions of the php package kynx/code-utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package code-utils

kynx/code-utils

Build Status

Utilities for generating PHP code.

Normalizers

The normalizers generate readable PHP labels (class names, namespaces, property names, etc) from valid UTF-8 strings, transliterating them to ASCII and spelling out any invalid characters.

Usage

The following code (forgive the Japanese - a certain translation tool tells me it means "Pet Store"):

outputs:

and:

outputs:

See the tests for more examples.

Why?

You must never run code generated from untrusted user input. But there are a few cases where you do want to output code generated from (mostly) trusted input.

In my case, I need to generate classes and properties from an OpenAPI specification. There are no hard-and-fast rules on the characters present, just a vague "it is RECOMMENDED to follow common programming naming conventions". Whatever they are.

How?

Each normalizer uses ext-intl's Transliterator to turn the UTF-8 string into Latin-ASCII. Where a character has no equivalent in ASCII (the "€" symbol is a good example), it uses the Unicode name of the character to spell it out (to Euro, after some minor clean-up). For ASCII characters that are not valid in a PHP label, it provides its own spell outs. For instance, a backtick "`" becomes Backtick.

Initial digits are also spelt out: "123foo" becomes OneTwoThreeFoo. Finally reserved words are suffixed with a user-supplied string so they don't mess things up. In the first usage example above, if we normalized "class" it would become ClassController.

The results may not be pretty. If for some mad reason your input contains ͖ - put your glasses on! - the label will contain CombiningRightArrowheadAndUpArrowheadBelow. But it is valid PHP, and stands a chance of being as unique as the original. Which brings me to...

Unique labelers

The normalization process reduces around a million Unicode code points down to just 162 ASCII characters. Then it mangles the label further by stripping separators, reducing whitespace and turning it into camelCase, snake_case or whatever your programming preference. It's gonna be lossy - nothing we can do about that.

The unique labelers' job is to add back lost uniqueness, using a UniqueStrategyInterface to decorate any non-unique class names in the list it is given.

To guarantee uniqueness within a set of class name labels, use the UniqueClassLabeller:

outputs:

There are labelers for each of the normalizers: UniqueClassLabeler, UniqueConstantLabeler, UniquePropertyLabeler and UniqueVariableLabeler. Along with the NumberSuffix implementation of UniqueStrategyInterface, we provide a SpellOutOrdinalPrefix strategy. Using that instead of NumberSuffix above would output:

Kinda cute, but a bit verbose for my taste.


All versions of code-utils with dependencies

PHP Build Version
Package Version
Requires php Version ~8.3.0 || ~8.4.0
ext-intl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kynx/code-utils contains the following files

Loading the files please wait ....