Download the PHP package pixelkarma/pkrouter without Composer

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

PkRouter

PkRouter is a fast and robust modern PHP router intended to be used for API creation. It has no dependencies, and encourages an object oriented approach.

Please see the Example to see in in action.

Features

Installation

Usage

Functions

Controller Methods

See Controller Method Callbacks

Router (PkRouter)

If no options are passed when creating the router, the default classes are used and an empty Route Config is created. You will then need to add routes individually.

Finding a match

There are two ways to find a match and execute its callback.

or

Responding

This is a shortcut to $router->response->sendJson();

Dynamic Properties

In PkRouter, you have the ability to set dynamic properties on the $router instance. These properties can be used to store data that needs to be accessed or modified at different stages of the request lifecycle, such as during the before middleware, the route callback, and the after middleware.

Route Creation

Route Callback

The callback is executed when a matching route is found. This value can either be a function, or a string representing your own controller method. Both should accept one parameter, an instance of PkRouter

Functional Callbacks

Controller Method Callbacks

Your Contoller will need to accept the $router on construct, not the method.

Route Meta

Meta is an array of values used to provide additional data on a route level. This information is accessible from Middleware and Callbacks

Before and After Middleware

See Middleware

URL Parameters

Path: /user/[s:username]/

In this example s, is the type and username is the param name accessible with:

See PkRoute Methods for more information about getParam()

Type Description
i Integer
f Float
a Alpha
n Alphanumeric
s String (URL acceptable characters)
e Email
b Binary: 1, 0, true, false
ip IPV4 Address
ipv6 IPV6 Address
uu UUID String
uu4 UUID Version 4 String
ymd Date: YYYY-MM-DD
hms Time: H:i:s
* Wildcard — Be careful.

Add additional match patterns

By calling the static function addMatchPattern, you can add additional param types. This can be used at any point prior to matching a route.

A common place to put this is in a Route Config file, as shown below

Route Methods

Methods that allow the $key parameter will return $default (default: null) if the key is not found. This is useful when validating a payload when you might want a value other than null.

Route Config

PkRoutesConfig is an extensible class for setting up multiple Routes, and adding Middleware.

Request (PkRequest)

PkRequest contains all of the information about the request being made.

Request Methods

Methods that allow the $key parameter will return $default (default: null) if there is no data. This is useful when validating a payload when you might want a value other than null.

Response (PkResponse)

Headers and response code do not send until the payload sends.

Extending PkResponse

PkRouter only supports JSON out of the box, but you can extend it to do more.

Middleware

Middleware are instances of PkMiddlewareInterface that can be run before your route code and after the payload has sent.

Note: Middleware is executed in the order you place it in the array.

Creating your own Middleware

Note: If your handle() function returns false, it will not continue to the next middleware. The routing will end and run() will return false. If you need to pass data between middleware, consider returning an array or an object.

Passing information between Middleware

Note: Middleware returns are not passed to the callback. See Dynamic Properties.

License

MIT License, see LICENSE.md

Copyright (c) 2024 Pixel Karma, LLC [email protected]


All versions of pkrouter with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1
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 pixelkarma/pkrouter contains the following files

Loading the files please wait ....