Download the PHP package adeptoas/slim3-init without Composer

On this page you can find all versions of the php package adeptoas/slim3-init. 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 slim3-init

Slim3 Init

This is a very convenient wrapper around the Slim4 framework providing us with some shortcuts and prepopulated concepts.

Installation

Add this to composer.json:

Make sure to merge your require-blocks!

Usage

SlimInit


HandlerCaller

All mocking methods return the text output that would've been sent to the browser. This is a JSON string most of the times.


Handler

To have your API do something, you need to create handlers which extend Adepto\Slim3Init\Handlers\Handler. Each handler must override getRoutes(): array to return an array of routes. Each handler receives a container in the constructor by default.

The actual methods of your handler must have the following signature:


PrivilegedHandler

Same as for Handler, only that this type of handler also has to override actionAllowed(string $action, array $data = []): bool to determine, if a given action is allowed and permitted. A PrivilegedHandler has an authorization client (client used to authenticate, instance of Adepto\Slim3Init\Client\Client) via getClient().

Force a permission. This is basically just an alias for actionAllowed (which you have to override) but throws a Adepto\Slim3Init\Exceptions\AccessDeniedException if the given permission is not allowed.


Route

Defines a route which has to be returned inside an array returned by your handler's getRoutes() function.


Interface: Client

-

Should return the username of the currently logged in user (if `BasicAuth` was used).

-

Should return an array full of `Adepto\Slim3Init\Client\Permission` objects for the currently logged in user (
if `BasicAuth` was used).

-

Should return true when the currently logged in user has a certain permission. You can use `$data` to combine the
permission with more info, i.e. when a resource's information access should be constrained to certain IDs.

Interface: Permission

-

Should return the name of the permission. You are free to define how a name looks like. It is recommended to use
reverse-domain style, i.e. `adepto.api.addKnowledge`.

-

Should return information specific to that permission, i.e. IDs of a resource that can be accessed. Can be an empty
array, if there is no information.

-

Should return true, if the permission is allowed.

Abstract: BasicAuth (Middleware)

-

Should return an array with more information to be added to the container, i.e. an authorized client to be used with a
PrivilegedHandler. If you're going to return a client, make sure to set the key to `PrivilegedHandler::CONTAINER_CLIENT`
. Should throw an `Adepto\Slim3Init\Exceptions\UnauthorizedException` if the user could not be authorized.

Examples

Examples can be found in examples/ of this repository.


Upgrade from SlimInit 1.0 (using Slim3)

While quite a lot has changed under the hood in Slim, the actual effects on SlimInit are as minimal as possible. There are 3 breaking changes and a few minor changes.

Breaking Changes

1. Handlers now must return an instance of Adepto\Slim3Init\Response

Previously, all handlers were defined using only Psr7-compatible interfaces. While you can still define your handler's arguments using Psr7, the return value must definitely be an instance of Adepto\Slim3Init\Response. If you need to convert an existing response, use Response::fromSlimResponse($originalResponse).

2. Middleware handling changes from a callback $next() to a handler

This change comes directly from Slim4, as SlimInit does not change this behavior. Previously, middleware worked like this:

Now, middleware uses a RequestHandlerInterface to process other code:

You no longer have access to the response before other middleware and handlers have run.

3. SlimInit no longer contains handleError, handleNotFound and handleMethodNotAllowed

Instead of overriding these methods in your own application to customize the handling of 500, 404 and 405 respectively, you now implement your own ExceptionHandler and assign it to exceptions. Example:

You can also override already existing default handlers for 404, 405 and 500:

To use the default exception handler and just customize the HTTP status code, you can continue to assign a status code instead of a handler, just like in SlimInit 1.x:

4. SlimInit 4.1 requires PHP 7.4+

SlimInit 4.1 is also the only version targeting PHP 7.4 specifically.

5. SlimInit 4.2 requires PHP 8.1+

Currently in development, this version will require PHP 8.1 or higher.

Minor Changes

1. SlimInit now uses a custom extension of DI\Container

It is still compatible with Psr7 ContainerInterface. If you specify Adepto\Slim3Init\Container as the type, you can make use of ArrayAccess without exceptions, like so:

2. Slim's convenience methods withJSON and write are now a custom implementation on Response

In their pursuit of being the most generic library on earth, getting Slim's convenience methods to work on top of ResponseInterface that doesn't have them and still have IDEs pick that up correctly is a nightmare. So SlimInit contains its own implementation of those.

3. A new abstract class Middleware

You can now also supply middleware that extends Adepto\Slim3Init\Middleware\Middleware. This gives you some convenience like always having access to the container and creating responses.

4. new HandlerCaller(…) is deprecated

Use HandlerCaller::default(string $baseURL, string $handlerClass, $container = null) instead.

to be continued


All versions of slim3-init with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
slim/slim Version ^4.9
php-di/php-di Version ^6.3
ext-mbstring Version *
ext-json Version *
slim/psr7 Version ^1.5
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 adeptoas/slim3-init contains the following files

Loading the files please wait ....