Download the PHP package uuf6429/php-cs-fixer-blockstring without Composer

On this page you can find all versions of the php package uuf6429/php-cs-fixer-blockstring. 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 php-cs-fixer-blockstring

๐Ÿงน PHP-CS-Fixer Heredoc/Nowdoc Content Formatter

CI codecov Minimum PHP Version License Latest Stable Version Latest Unstable Version

This project extends PHP-CS-Fixer to be able to format the contents of PHP Heredoc and Nowdoc strings (aka Block Strings).

Note that no language-specific formatters are provided by design โ€“ this project instead provides the ability to integrate any type of formatters with minimal code (mainly in your PHP-CS-Fixer configuration file).

While this might sound like a weakness, it in fact makes it possible to integrate virtually any formatter for any language.

๐Ÿ”Œ Installation

Install via Composer:

Finally, register a custom fixer in your .php-cs-fixer.php config file (1๏ธโƒฃ) and then set up formatters (2๏ธโƒฃ):

[!WARNING] If PHP CS Fixer is installed via php-cs-fixer/shim package, you may have to require the bootstrap file:

๐Ÿ’ก Before You Start

1. What does the configuration look like? The configuration is made up of a map of block string delimiters and formatter pairs. A default formatter can be configured to run for any Block Strings that have other not been configured. For example: In that (fictitious) example, `LineFormatter` is applied to all block strings except `<<
2. What's the deal with formatter versions? You might have noticed that the base formatter class requires having a version. Most formatters require a way for providing such a version. The reason is that by supplying an up-to-date version, the PHP-CS-Fixer cache can be skipped - which is important if the recently updated external fixer is behaving differently - otherwise fixes become outdated because of an outdated cache. Note that the actual value of the version does not matter. Some formatters might be able to figure out the version by themselves.
3. What about variable interpolation in Heredoc? They provide an interesting challenge, which this project solves with the concept of an [`InterpolationCodec`]. It works by replacing interpolation 'segments' with tokens โ€“ ensuring that the content is valid during the formatting stage โ€“ and then they're rolled back to the original value. The codec can be configured for most of the formatters โ€“ you should probably apply such configuration diligently if you plan on having Heredoc strings. Here's an example illustration of the whole flow: That JSON cannot be formatted properly because `$users` is not valid syntax. The [`GeneratedTokenCodec`] codec can be used; it will automatically replace the `$users` part with a token temporarily. By default, it will replace it with `__PHP_VAR_1__` in this specific case โ€“ which, however, is still not valid(!) So instead, we configure it with a different token pattern: `new GeneratedTokenCodec('"__PHP_VAR_%d__"')`. The double quotes ensure that the replaced token is valid JSON: Given that, the formatter will do its job without problems, and then the codec will transform that token back to the original interpolation.
4. What about complex variable interpolation in Heredoc? The `GeneratedTokenCodec` codec additionally allows handling interpolations on a case-by-case basis by providing a callback that acts as a token generation factory. If this callback returns null instead of a string token, the default functionality will be used instead. Additionally, you can always build your own codec simply by having a class implement [`CodecInterface`].
5. The 3d-party/external formatter complains that the string has bad syntax. This is not at all unlikely โ€“ that's one reason why the interpolation codec concept exists โ€“ string interpolation often causes broken syntax. Unfortunately, the codec concept won't help you if you're using some other sort of templating system, such as replacing placeholders with `str_replace()`, `preg_replace()`, `strtr()` or `sprintf()` or similar. You can, however, implement a "formatter" that replaces such placeholders temporarily during formatting and then reverses them back, but since this seems like an uncommon usecase, there aren't any supporting implementations yet (you're welcome to suggest it though).

๐Ÿš€ Usage Example

1. Given the following PHP-CS-Fixer configuration:
2. ...and the following source code file (whitespace has been replaced for better display):
3. ...PHP-CS-Fixer will format everything, resulting in (whitespace also substituted):

[!TIP] More example configurations ("recipes") can be found in uuf6429/php-cs-fixer-blockstring-recipes.

โญ๏ธ Formatters

AbstractFormatter

This is the base class of all formatters. In most cases you don't really want to extend this class, since it does not handle string interpolation at all โ€“ check out AbstractStringFormatter instead.

Extending this class makes sense in two situations:

  1. If your class is infrastructural, and you don't really need to handle string interpolation - just like ChainFormatter
  2. Or if, for whatever reason, the CodecInterface concept does not work for you and you want to write something from scratch.

AbstractStringFormatter

This formatter base class is aware of string interpolation โ€“ it passes content through a codec before and after formatting (to properly handle string interpolation).

Additionally, it keeps an in-memory cache of formatted content to avoid unnecessary work within the same process.

It can be used to embed any kind of formatter, including (native) PHP-based ones.

Example with your own custom class:

ChainFormatter

This formatter allows multiple formatters to be applied sequentially โ€“ the output of each formatter becomes the input of the next one.

Example:

CliPipeFormatter

It's no secret that the best formatting tools are not directly available in PHP. This formatter off-loads formatting to such external executables.

Example:

The command definition (for version detection or formatting) is an array with the following structure:

  • cmd array/string: The command line e.g. 'jfmt --format' or ['jfmt', '--format'].
  • cwd (optional) string: The current working directory of the command.
  • env (optional) array of string keys and values: Environment variables to pass to the command.

DockerPipeFormatter

The minimal setup, stable repeatability, and a rich ecosystem make Docker images an ideal source of formatting tools. This formatter exists to take advantage of that.

Example:

SimpleLineFormatter

A formatter that normalizes indentation and removes any trailing whitespace at the end of lines.

Example:

WslPipeFormatter

A formatter making use of Windows Subsystem for Linux (WSL). Of course, you will need to be running on Windows, and WSL needs to be enabled and set up. Configuration is otherwise almost identical to CliPipeFormatter.


All versions of php-cs-fixer-blockstring with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
ext-json Version *
symfony/process Version ^5 || ^6 || ^7 || ^8
friendsofphp/php-cs-fixer Version ^3
symfony/deprecation-contracts Version ^2 || ^3
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 uuf6429/php-cs-fixer-blockstring contains the following files

Loading the files please wait ...