Download the PHP package mediagone/symfony-powerpack without Composer

On this page you can find all versions of the php package mediagone/symfony-powerpack. 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 symfony-powerpack

Symfony Powerpack

⚠️ This project is in experimental phase, it might be subject to changes.

Latest Version on Packagist Total Downloads

This package provides efficiency and code-quality helpers for Symfony:

  1. Generic param converters
  2. Primitive types parameters

Installation

This package requires PHP 7.4+

Add it as Composer dependency:

In order to use primitive type parameters in your controllers, you must register the converters in your services.yaml by adding the following service declaration:

1) Generic param converter

Param Converters are the best way to convert URL or route parameters into entity or Value Object instances. They allow to extract retrieval or conversion logic, preventing code duplication and keeping your controllers clean.

For more details, see Symfony's documentation.

Custom converters are very powerful, but doing Clean Code implies writing a lot of these converters. This package provides a base class that handles boilerplate code for you: you only have to define resolvers that will convert the request's parameter into the desired value.

Value Object converter

Let's take this very basic ValueObject:

You can use it in your controller by typehinting an argument:

The associated param converter only needs a single resolver to transform the value:

The array key acts as suffix for controller's argument name, thus an empty string means that the converter will look for a request parameter with the exact same name than the controller's argument ("searched").

Note: the converters is using $request->get() internally, so it will look successively in all request data available (Route attributes, GET and POST parameters).

Entity converter

Entity converters work the exact same way, but generally imply more complexity in data retrieval. For example, you can define multiple way of getting back an User, by registering multiple resolvers in the converter:

This way, the converter will be able to fetch the user by Id if an userId parameter is supplied to the controller, or by its Name if the given parameter is userName. In other words, the request parameter name is the concatenation of the controller's argument name and the resolver's array key.

Again, it works the same for GET, POST or route's attributes.

Optional parameters

If you need to allow a nullable argument, just make the argument nullable and handle it in your code (eg. to return a custom response):

Exception handling

Exceptions can be thrown in your resolvers, for example if the supplied value is not valid. In some cases, you don't need to handle those errors and you can just consider them as missing values.

You can either:

Example of @ParamConverter usage:

Note: don't forget to make your method's argument nullable!

2) Primitive types parameters

The only drawback of ParamConverters is they only work with classes but not with primitive PHP types (int, string, float...) so this package also provides a set of classes that can be used to enforce type-safety for primitive types.

Class name Parameter value example Converted PHP value
BoolParam 1 or 0 true or false
FloatParam 3.14159 3.14159
IntParam 42 42
StringParam hello 'hello'
JsonParam ["1","2","3"] ['1', '2', '3']

It also provides parameters to extract serialized arrays from the query, built from comma-separated values string :

Class name Parameter value example Converted PHP value
BoolArrayParam 1,0,1 [true, false, true]
FloatArrayParam 1.1,2.2,3.3 [1.1, 2.2, 3.3]
IntArrayParam 1,2,3 [1, 2, 3]
StringArrayParam one,two,three ['one', 'two', 'three']

Again, you only have to typehint arguments in your controller to get the request's values:

License

Symfony Powerpack is licensed under MIT license. See LICENSE file.


All versions of symfony-powerpack with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-json Version *
symfony/http-kernel Version ^6.2
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 mediagone/symfony-powerpack contains the following files

Loading the files please wait ....