Download the PHP package affinity4/slimphp-support without Composer

On this page you can find all versions of the php package affinity4/slimphp-support. 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 slimphp-support

SlimPHP Support

Add Laravel style facades, traits and helper functions to any SlimPHP app

Installation

Usage

Setting up Facades in your Application

To use SlimPHP Facades, you first need to create your Slim app as normal, with either Slim\App\AppFactory or DI\Container\Slim\Bridge. Then you'll need to call Affinity4\SlimSupport\Support\Facade::setFacadeApplication($app):

You will now have access to all Facades, as well as the helper function (e.g. response())

App Facade

Facade for Slim\App:

Container

Response

JSON Response

Pipeline Facade

NOTE: See Pipeline Support Class section for a detailed example.

Helper functions

response()

Standard application/text Response

Standard JSON Response

tap()

Traits

Tappable

Macroable

Macros allow you to add methods to classes dynamically (without having to modify their code).

Let's say you are tired of having to do this:

Instead you just want to call a write method directly from the $response instance. First, we need to extend the Response class so we can use the Macroable trait, but still have all of our base Response methods.

Then we need to add MacroableResponse to our container, so we are always dealing with the same instance (not all instances will have the "macroed" methods).

Then we can get our MacroableResponse instance from the container however you want, and just call write!

Conditionable

Allows to conditionally chain functionality.

For example, let's imagine we have a standard PSR-11 Container, which has a the bare minimum PSR-11 compliant methods, set, get and has. The set method adds a service to the container, get returns the service and has checks an service is in the container.

We have a Logger we want to add to the container, but it requires a FileDriver to be in the container already, or else we need to also add the FileDriver class to the container first.

We might then have some bootstrapping logic like so:

However, if we extends our Container class and add the Conditionable trait, we can instead use the unless method to do this check with a fluent interface:

NOTE: To check the opposite, there is also when.

You're probably thinking this is still quite bit verbose, so to clean this up you could create invokable ServiceFactory classes for all of your $container->set logic.__

Dumpable

Adds dump and dd methods to any class

Would result in:

NOTE: You can also pass ...$args to the dd and dump methods as normal if you want to append additional dump data.

ForwardsCalls

Proxy calls to missing methods in current class, to another target class. Useful when you cannot inherit or modify a class but you want to add some functionality to it (other than overloading any of it's methods of course).

Here's an example where we have a base App class, but it is a final class so we cannot inherit it. So instead, we create an AppProxy class which allows us to say that "any method that gets called on AppProxy which doesn't exist in AppProxy, we use App instead"

Then we can use getContainer (or any other public methods/properties) from App by calling out AppProxy

Pipeline Support class

Pipelines allow for a middleware-like interface to chain processing of tasks.

A pipeline processes each task, passed the returned value to the next process in the chain.

They are useful for multi-step data processing, http middleware, database querying and validation tasks.

Here's an example of how to use it to validation, filter, transform and save an incoming get request.

This way our controller stays clean, and readable, and each responsibility is separated to it's own class to make maintainance easier in the long run. This would also make testing easier, as you could test the individual classes, and also the overall pipeline result, without needing to test the controller itself.

Hub

A Hub class, is a way to store a similar group of pipelines so they can be retrieved and executed from the same object.


All versions of slimphp-support with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
psr/http-factory Version ^1.0
symfony/var-dumper Version ^6.4
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 affinity4/slimphp-support contains the following files

Loading the files please wait ....