Download the PHP package vkr/controller-delegation-bundle without Composer

On this page you can find all versions of the php package vkr/controller-delegation-bundle. 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 controller-delegation-bundle

About

This small bundle enables usage of the Delegation pattern in Symfony controllers. Its main use-case is when you create a reusable component that requires some controller logic but does not require to define complete controllers and templates. It can be said that the goal of this bundle is to provide a system of bundle inheritance that is more lightweight and hassle-free than default Symfony bundle inheritance.

This bundle consists just of three classes - two abstract and one concrete. It does not do anything by itself, and is designed to be used as a dependency in other reusable bundles.

This bundle has no dependencies other than Symfony itself.

Philosophy

Suppose you have some reusable code that involves a lot of manipulation with the container and invoking other useful controller methods such as . Of course, you can put these into an actual controller, but then you also have to define a view. Both controller actions and views can be overridden by bundle inheritance, but that involves following a naming convention, and that can be inconvenient. For example, customizing is not the easiest thing in the world.

The philosophy behind this bundle states that it will be easier for a client coder to invoke a delegate method inside each controller action that would accept the same arguments as the actual controller but might return something other than HTTP response. The controller then parses the results of delegate's work in whatever way it deems necessary.

Thus, it can be said that the actual controller acts as a decorator for the delegate class.

Usage

Create a delegate class that should extend . This class is container-aware and has access to all controller methods via . It should return the same instance of class that was created in its parent constructor under the name of .

Use it in the following way:

All setter methods of return its instance. You could also write

Then it is expected that the client coder will create a controller that will extend and write the following method in it:

is a shortcut for getting template variables. It is generally recommended that both controller method and delegate method have same signatures.

Dealing with redirects

If there are any redirects that you wish to return, things become more tricky. The concept is that the delegate class creator should not hardcode any route names. These are replaced with special markers, such as 'success' or 'failure'. Then you do something like this in your delegate class:

For these markers to be parsed, they must be first declared as class property:

Note that required routes list can be neither declared nor redefined in action methods.

Then, this should be added to your controller:

If your delegate can return both redirect and non-redirect values, the controller will look as follows:

If the object contains both redirect and non-redirect values, redirect will take precedence.

If your route comes with parameters, you can modify your controller as follows:

Finally, if you want to skip some of required parameters, you can use key:

Sometimes, you will want to use external links for redirect, e.g. an API call. Here is how you do it:

Dealing with additional render calls

Suppose that inside your controller logic you need to render something that is not going to be returned by the controller. The best example here is sending emails. In this case, you just need to pass an extra argument to the delegate action, and then parse it somehow in your delegate:

Inside your delegate you can use

Note that template name and template variables should not be hardcoded inside the delegate class.

Best practices


All versions of controller-delegation-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
symfony/symfony Version ~2.8|~3.0
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 vkr/controller-delegation-bundle contains the following files

Loading the files please wait ....