PHPackages                             pklink/hahns - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. pklink/hahns

AbandonedArchivedLibrary[Framework](/categories/framework)

pklink/hahns
============

micro framework for PHP 5.4+

0.7.4(12y ago)438MITPHPPHP &gt;=5.4.0

Since Dec 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/pklink/Hahns)[ Packagist](https://packagist.org/packages/pklink/hahns)[ RSS](/packages/pklink-hahns/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (26)Used By (0)

[![No Maintenance Intended](https://camo.githubusercontent.com/d904056147052e22d8e1c7f46bb50293ed2aeb4c43ead9a2d0cf7a48b46d0562/687474703a2f2f756e6d61696e7461696e65642e746563682f62616467652e737667)](http://unmaintained.tech/)

Hahns [![Build Status](https://camo.githubusercontent.com/67d3e8c1e71cea20ebb41bc4c131c95613cc7280e81dedacb7aa0f898bad3205/68747470733a2f2f7472617669732d63692e6f72672f706b6c696e6b2f4861686e732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/pklink/Hahns) [![Dependency Status](https://camo.githubusercontent.com/6193ed97efd9a7c2f4e199681002a15b94c44de348ccb4ac1ddc135eb8b6f900/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3532623839343430656331333735633366353030303031622f62616467652e706e67)](https://www.versioneye.com/user/projects/52b89440ec1375c3f500001b) [![Scrutinizer Quality Score](https://camo.githubusercontent.com/70702f86c55b996998c1e6336cfc5f7cf492ce7c47ad5ebc5d11c6ab68cc70c6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f706b6c696e6b2f4861686e732f6261646765732f7175616c6974792d73636f72652e706e673f733d61636166613861623835323266376466343865393365663866323462373936336564376132363463)](https://scrutinizer-ci.com/g/pklink/Hahns/)
==========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#hahns---)

Hahns is a micro framework for PHP 5.4 and higher.

- [Detailed documentation in English](https://github.com/pklink/Hahns/tree/documentation/en) (work in progess)
- [Detailed documentation in German](https://github.com/pklink/Hahns/tree/documentation/de) (work in progess)

Installation
------------

[](#installation)

To install using [composer](http://getcomposer.org/), have the following lines in your `composer.json` file.

```
{
  "require": {
    "pklink/hahns": "*",
  }
}
```

Usage
-----

[](#usage)

Create application

```
$app = new \Hahns\Hahns();
```

```
$app->get('/', function () {
    return "hello world!";
});

$app->delete('/', function () {
    return "1";
});
```

Every GET-request to `/` will respond

```
hello world!

```

Every DELETE-request to `/` will respond

```
1

```

### Debug mode

[](#debug-mode)

For enable debugging set `debug` in the configuration to `true`

```
$app = new \Hahns\Hahns(['debug' => true]);
```

### Parameters for routing callback

[](#parameters-for-routing-callback)

Hahns will set parameters based on the required type automatically

The following types are built-in:

- `\Hahns\Hahns`
- `\Hahns\Request`
- `\Hahns\Response\Html`
- `\Hahns\Response\Json`
- `\Hahns\Response\Text`

```
$app->get('/', function (\Hahns\Request $request) {
    // ...
});

$app->patch('/', function (\Hahns\Response\Json $response) {
    // ...
});

$app->get('/cars', function (\Hahns\Response\Json $response, \Hahns\Request $request) {
    // ...
});
```

#### Add your own parameter

[](#add-your-own-parameter)

```
$app->parameter('\\stdClass', function() {
    $obj = new stdClass();
    $obj->test = 'yup';
    return $obj;
});

$app->get('/own/parameter', function (\stdClass $obj) {
    return $obj->test;
});

$app->parameter('\Package\MyOwnClass', function(\Hahns\Hahns $app) {
    // ...
});

```

The callback for `parameter()` must be return an instance of the given type.

### Named Parameters

[](#named-parameters)

Based on [regular expressions](http://en.wikipedia.org/wiki/Regular_expression)

```
$app->get('/hello/[.+:name]', function (\Hahns\Response\Json $response, \Hahns\Request $request) {
	return $response->send([
		'message' => sprintf('hello %s %s', $request->get('first'), $request->get('last'))
});

$app->get('/hello/[.+:first]/[.+:last]', function (\Hahns\Request $request, \Hahns\Response\Json $response) {
	return $response->send([
		'message' => sprintf('hello %s %s', $request->get('first'), $request->get('last'))
	]);
});

$app->delete('/cars/id-[\d+:id]/now', function (\Hahns\Response\Json $response, \Hahns\Request $request) {
    return $response->send([
        'message' => sprintf('removed card with id `%d`', $request->get('id'))
    ]);
});
```

### Named Routes

[](#named-routes)

```
$app->get('/route1', function () {
    return 'hello world';
}, 'route1');
$app->get('/route2', 'route1', 'route2');
$app->get('/route3', 'route2');
```

All GET\_request to `/route1`, `/route2` or `/route3` respond

```
hello world

```

### Services

[](#services)

```
$app->service('myservice', function(\Hahns\Hahns $app) {
	$service = new \stdClass();
	$service->test    = 'hello';
	$service->appName = $app->config('name');
	return $service;
});

$app->get('/service-test', function (\Hahns\Hahns $app) {
	echo $app->service->test;
});
```

Every GET-request to `/service-test` will respond

```
hello

```

Built-in services are:

- `html-response` returns instance of `\Hahns\Response\Html`
- `json-response` returns instance of `\Hahns\Response\Json`
- `text-response` returns instance of `\Hahns\Response\Text`

### Events

[](#events)

Hahns trigger various events. Use the `on`-method to add your own handler.

#### Not Found (404)

[](#not-found-404)

Arguments are:

- `string $usedRoute`
- `\Hahns\Hahns $app`
- `\Hahns\Exception\NotFoundException $e`

```
$app->on(\Hahns\Hahns::EVENT_NOT_FOUND, function ($usedRoute, \Hahns\Hahns $app, \Hahns\Exception\NotFoundException $e) {
    // do something
});
```

Per default Hahns sends status code 404

##### Trigger a "Not Found" event

[](#trigger-a-not-found-event)

Simply throw a `\Hahns\Exception\NotFoundException`

```
$app->get('/not-found', function () {
    throw new \Hahns\Exception\NotFoundException();
});
```

#### Error

[](#error)

Arguments are:

- `\Exception $e`
- `\Hahns\Hahns $app`

```
$app->on(\Hahns\Hahns::EVENT_ERROR, function (\Exception $e, \Hahns\Hahns $app) {
    // do something
});
```

Per default Hahns sends status code 500

##### Trigger an "Error" event

[](#trigger-an-error-event)

Simply throw a `\Hahns\Exception\ErrorException`

```
$app->get('/not-found', function () {
    throw new \Hahns\Exception\NotFoundException();
});
```

#### Before Running

[](#before-running)

Arguments are:

- `string $givenRoute`
- `\Hahns\Hahns $app`

```
$app->on(\Hahns\Hahns::EVENT_BEFORE_RUNNING, function ($givenRoute, \Hahns\Hahns $app) {
    // do something
});
```

#### After Running

[](#after-running)

Arguments are:

- `string $usedRoute`
- `\Hahns\Hahns $app`

```
$app->on(\Hahns\Hahns::EVENT_AFTER_RUNNING, function ($usedRoute, \Hahns\Hahns $app) {
    // do something
});
```

#### Before Routing

[](#before-routing)

Arguments are:

- `string $usedRoute`
- `\Hahns\Hahns $app`

```
$app->on(\Hahns\Hahns::EVENT_BEFORE_ROUTING, function ($usedRoute, \Hahns\Hahns $app) {
    // do something
});
```

#### After Routing

[](#after-routing)

Arguments are:

- `string $usedRoute`
- `\Hahns\Hahns $app`

```
$app->on(\Hahns\Hahns::EVENT_AFTER_ROUTING, function ($usedRoute, \Hahns\Hahns $app) {
    // do something
});
```

#### Before execute matched route

[](#before-execute-matched-route)

Arguments are:

- `string $usedRoute`
- `\Closure $routeCallback`
- `array $argsForCallback`
- `\Hahns\Hahns $app`

```
$app->on(\Hahns\Hahns::EVENT_BEFORE_EXECUTING_ROUTE, function ($usedRoute, \Closure $routeCallback, $argsForCallback, \Hahns\Hahns $app)
    // do something
});
```

#### After execute matched route

[](#after-execute-matched-route)

Arguments are:

- `string $usedRoute`
- `\Closure $routeCallback`
- `array $argsForCallback`
- `\Hahns\Hahns $app`

```
$app->on(\Hahns\Hahns::EVENT_AFTER_EXECUTING_ROUTE, function ($usedRoute, \Closure $routeCallback, $argsForCallback, \Hahns\Hahns $app)
    // do something
});
```

Reference
---------

[](#reference)

### `\Hahns\Hahns`

[](#hahnshahns)

```
void            any(string $route, \Closure $callback)	                        // register route for all verbs
void            any(string $route, string $namedRoute)	                        // register route for all verbs using the previous route named $namedRoute
void            any(string $route, \Closure $callback, string $name)	        // register routes for all verbs route with name $name
void            any(string $route, string $namedRoute, string $name)	        // register route for all verbs with name $name using the previous route named $namedRoute
mixed           config(string $name)	                                        // get value $name from config
void            delete(string $route, \Closure $callback)	                    // register DELETE-route
void            delete(string $route, string $namedRoute)	                    // register DELETE-route using the previous route $namedRoute
void            delete(string $route, \Closure $callback, string $name)	        // register DELETE-route with name $name
void            delete(string $route, string $namedRoute, string $name)	        // register DELETE-route with name $name using the previous route named $namedRoute
void            get(string $route, \Closure $callback)		                    // register GET-route
void            get(string $route, string $namedRoute)	                        // register GET-route using the previous route $namedRoute
void            get(string $route, \Closure $callback, string $name)	        // register GET-route with name $name
void            get(string $route, string $namedRoute, string $name)	        // register GET-route with name $name using the previous route named $namedRoute
void            on(int $event, \Closure $callback)                              // add handler $callback for event $event
void            parameter(string type, \Closure $callback)                      // register parameter for route callback as singleton
void            parameter(string type, \Closure $callback, bool $asSingleton)   // register parameter for route callback
void            patch(string $route, \Closure $callback)	                    // register PATCH-route
void            patch(string $route, string $namedRoute)	                    // register PATCH-route using the previous route $namedRoute
void            patch(string $route, \Closure $callback, string $name)	        // register PATCH-route with name $name
void            patch(string $route, string $namedRoute, string $name)	        // register PATCH-route with name $name using the previous route named $namedRoute
void            post(string $route, \Closure $callback)	                        // register POST-route
void            post(string $route, string $namedRoute)	                        // register POST-route using the previous route $namedRoute
void            post(string $route, \Closure $callback, string $name)	        // register POST-route with name $name
void            post(string $route, string $namedRoute, string $name)	        // register POST-route with name $name using the previous route named $namedRoute
void            put(string $route, \Closure $callback)		                    // register PUT-route
void            put(string $route, string $namedRoute)	                        // register PUT-route using the previous route $namedRoute
void            put(string $route, \Closure $callback, string $name)		    // register PUT-route with name $name
void            put(string $route, string $namedRoute, string $name)	        // register PUT-route with name $name using the previous route named $namedRoute
void            run()										                    // start routing
void            run(string $route)                                              // start routing with the given route $route
void            run(string $route, string $requestMethod)                       // start routing with the given route $route and the request method $requestMethod (useful for simulating request)
object          service(string $name)	                                        // get service with name $name
void            service(string $name, \Closure $callback)	                    // register service

```

### `\Hahns\Request`

[](#hahnsrequest)

```
mixed get(string $name)		                    // get GET-param $name or null
mixed get(string $name, mixed $default)		    // get GET-param $name or $default
mixed header(string $name)	                    // get param $name from request header or null
mixed header(string $name, mixed $default)	    // get param $name from request header or $default
mixed payload(string $name)	                    // get param $name from payload (DELETE, PATCH, PUT) or null
mixed payload(string $name, mixed $default)     // get param $name from payload (DELETE, PATCH, PUT) or $default
mixed post(string $name)		                // get POST-param $name or null
mixed post(string $name, mixed $default)		// get POST-param $name or $default

```

### `\Hahns\Response\Html`

[](#hahnsresponsehtml)

```
void   header(string $name, string $value)		                // send header $name with value $value
void   redirect(string $location)                               // send location header with status code 301
void   redirect(string $location, int $status)                  // send location header with status code $code
string send(string $data)	                                    // get $data as html
string send(string $data, int $status)	                        // get $data as html and send status code $status to client
void   status(int code)                                         // send status code $code with HTTP version 1.1 to client
void   status(int code, string $message)                        // send status code $code with message $message to client
void   status(int code, string $message, string $httpVersion)   // send status code $code with message $message and HTTP version $version to client

```

### `\Hahns\Response\Json`

[](#hahnsresponsejson)

```
void   header(string $name, string $value)		                // send header $name with value $value
void   redirect(string $location)                               // send location header with status code 301
void   redirect(string $location, int $status)                  // send location header with status code $code
string send(string $data)	                                    // get $data as json-decoded string
string send(string $data, int $status)	                        // get $data as json-decoded string and send status code $status to client
void   status(int code)                                         // send status code $code with HTTP version 1.1 to client
void   status(int code, string $message)                        // send status code $code with message $message to client
void   status(int code, string $message, string $httpVersion)   // send status code $code with message $message and HTTP version $version to client

```

### `\Hahns\Response\Text`

[](#hahnsresponsetext)

```
void   header(string $name, string $value)		                // send header $name with value $value
void   redirect(string $location)                               // send location header with status code 301
void   redirect(string $location, int $status)                  // send location header with status code $code
string send(string $data)	                                    // get $data as text
string send(string $data, int $status)	                        // get $data as text and send status code $status to client
void   status(int code)                                         // send status code $code with HTTP version 1.1 to client
void   status(int code, string $message)                        // send status code $code with message $message to client
void   status(int code, string $message, string $httpVersion)   // send status code $code with message $message and HTTP version $version to client

```

[![Bitdeli Badge](https://camo.githubusercontent.com/726fb86ec58668fc51ebf366610651c7a396591cfa294fb26a1a5b01f33a232a/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f706b6c696e6b2f6861686e732f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Recently: every ~13 days

Total

24

Last Release

4469d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c8c5e958e572c9805a2746a44c66ffd72fdfb22f1f5c7f0723a40afee9ec176?d=identicon)[pklink](/maintainers/pklink)

---

Top Contributors

[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![pklink](https://avatars.githubusercontent.com/u/753350?v=4)](https://github.com/pklink "pklink (1 commits)")

---

Tags

frameworkrestroutermicroframework

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/pklink-hahns/health.svg)

```
[![Health](https://phpackages.com/badges/pklink-hahns/health.svg)](https://phpackages.com/packages/pklink-hahns)
```

###  Alternatives

[leafs/leaf

Elegant PHP for modern developers

1.3k44.3k9](/packages/leafs-leaf)[slim/slim-skeleton

A Slim Framework skeleton application for rapid development

1.6k458.7k6](/packages/slim-slim-skeleton)[vlucas/bulletphp

A heierarchical resource-oriented micro-framework built on nested closures instead of route-based callbacks

41949.9k1](/packages/vlucas-bulletphp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
