PHPackages                             andrewbreksa/unicorn - 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. andrewbreksa/unicorn

Abandoned → [slim/slim](/?search=slim%2Fslim)ArchivedLibrary[Framework](/categories/framework)

andrewbreksa/unicorn
====================

A tiny single class RAD PSR-7 web application "framework"

3831PHP

Since Mar 29Pushed 9y ago1 watchersCompare

[ Source](https://github.com/abreksa4/Unicorn)[ Packagist](https://packagist.org/packages/andrewbreksa/unicorn)[ RSS](/packages/andrewbreksa-unicorn/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

[Unicorn](https://github.com/abreksa4/Unicorn)
==============================================

[](#unicorn)

*A tiny single class RAD PSR-7 web application "framework"*

[![Travis](https://camo.githubusercontent.com/40d0c818aecc4ab13a6ae6fbcd10e9bd13c282cc6e57b37bb5b22bc7273d2c36/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616272656b7361342f556e69636f726e2e737667)](https://travis-ci.org/abreksa4/Unicorn)[![Waffle.io](https://camo.githubusercontent.com/1c881219fd425fab6681df07fbae2fac0d6b53011f123ddda8bab3cbaab10881/68747470733a2f2f696d672e736869656c64732e696f2f776166666c652f6c6162656c2f616272656b7361342f556e69636f726e2f696e25323070726f67726573732e737667)](https://waffle.io/abreksa4/Unicorn)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Packagist](https://camo.githubusercontent.com/aef9d0d92b165f99c7027310578c82341e5f3a520da382c937bfd3f4134ee3d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647265776272656b73612f756e69636f726e2e737667)](https://packagist.org/packages/andrewbreksa/unicorn)[![Dependency Status](https://camo.githubusercontent.com/10286d9ae374e24e791341153f7026a6d7f231ca9f84ea182c90009f847b4763/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3538643836653535363839336664303033623363343336662f62616467652e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/user/projects/58d86e556893fd003b3c436f)[![PHP Eye](https://camo.githubusercontent.com/2488dcab0ce8b1719d40cba1f2d3a6d9cd220f3957fce21d92fb215b3e40930c/68747470733a2f2f7068702d6579652e636f6d2f62616467652f616e647265776272656b73612f756e69636f726e2f7465737465642e737667)](https://php-eye.com/package/andrewbreksa/unicorn)

Unicorn is essentially a wrapper around [zendframework/zend-diactoros](https://github.com/zendframework/zend-diactoros) and a couple of [The PHP League](https://thephpleague.com/) packages: [league/event](http://event.thephpleague.com/2.0/), [league/container](http://container.thephpleague.com/), and [league/route](http://route.thephpleague.com/) that provides support for the entire application lifecycle.

Still in it's infancy, Unicorn was born from my frustrations of wanting a framework to handle the plumbing for me, but not force a specific architecture or style, as applications tend to get very domain specific (as they should be).

- Want to build a closure application? Easy.
- Want to build a PSR-7 middleware app? Use your own pipeline implementation. (I recommend [league/pipeline](http://pipeline.thephpleague.com/) or [zend-framework/stratigility](https://zendframework.github.io/zend-stratigility/). Remember, the `Application` object adds itself to the service container so your class constructor dependencies are auto-wired if created via the container. I would include support for middleware by default, but I feel this is not always required by a PSR-7 application, and therefore outside of the Unicorn mission statement)
- Want to use a "full", controller-based MVC framework? Just specify the class and method via routing.
- Want to use all of the above in the same app? Go ahead.

Unicorn attempts to do only the minimum, providing a service container, a router, a few event hooks for the various stages of the application lifecycle, and a PSR-7 implementation. And if you'd like, consider it an anti-framework framework. **You might have to write some code...** ;)

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

[](#installation)

`composer require andrewbreksa/unicorn`

Usage
-----

[](#usage)

Check out the example [index.php](https://github.com/abreksa4/Unicorn/blob/master/public/index.php) to see how to setup a basic app. (And I mean basic).

Application lifecycle/events
----------------------------

[](#application-lifecycleevents)

*As defined in \\Unicorn\\App\\Application*

```
	const EVENT_BOOTSTRAP = 'app.bootstrap';
	const EVENT_DISPATCH = 'app.dispatch';
	const EVENT_ROUTE_EXCEPTION = 'app.route.exception';
	const EVENT_DISPATCH_EXCEPTION = 'app.dispatch.exception';
	const EVENT_RENDER = 'app.render';
	const EVENT_EMIT_EXCEPTION = 'app.emit.exception';
	const EVENT_FINISH = 'app.finish';

```

Each event is emitted before the action takes place (if any, `Application::EVENT_RENDER` doesn't do anything), and the event manager is accessible via `Application::getInstance()->getEventEmitter()`. Fairly simple, see the [league/event](http://event.thephpleague.com/2.0/) documentation.

Routing
-------

[](#routing)

You can access the router via `Application::getInstance()->getRouteCollection()`. From there check out the [league/route](http://route.thephpleague.com/) docs for more info.

A note on the return values of methods/closures/etc called on dispatch: If `NULL` is returned (or nothing at all, implied) then `Application->$response` is not updated, but the emitting process is carried out. However, if you return `FALSE`, the emitting process is not carried out and `Application::EVENT_RENDER` (needless to say, `Application::EVENT_EMIT_EXCEPTION`) is not emitted either. This can be used to run other, "non-Unicorn", code or frameworks on specific routes.

PSR-7
-----

[](#psr-7)

Really? Ok, well checkout [php-fig.org](http://www.php-fig.org/psr/psr-7/) for more info.

Configuration
-------------

[](#configuration)

Configuration is (can be) stored in `./config/autoload`. Any `*.php` or `*.json` file here will either be `include`d or parsed and added to `Application::getInstance()->getConfig()`. And as always, feel free to completely ignore this convention and do whatever you please.

Regardless of how the configuration is set, on `Application->bootstrap()` (after `EVENT_BOOTSTRAP`), if there is any of `services`, `routes`, or `eventListeners` in `Application->getConfig()`, the values of these keys are passed to `Application->bootstrapServices()`, `Application->bootstrapRoutes()` and `Application->bootstrapEventListeners()` respectively.

Dependency container
--------------------

[](#dependency-container)

Unicorn uses [league/container](http://container.thephpleague.com/), which follows the [container-interop](https://github.com/container-interop/container-interop) standard. All of the `Application::getInstance()->get*()` objects are also available via the container (`Application::getInstance()->getContainer()`) as Unicorn registers itself as a delegate (except the container itself, `baseDir`, and `data`. The dependency container is also set to use the `League\Container\ReflectionContainer` as a delegate, so constructor dependencies should be automatically set if available [more on auto-wiring](http://container.thephpleague.com/auto-wiring/).

Notes
-----

[](#notes)

As the architecture and use cases of Unicorn are still being fleshed out, I've yet to put together thorough documentation. It's more of a pet project really that I'm using for RAD on a couple of personal projects.

Event listeners attached to the various `Application::EVENT_*` events are passed a `\League\Event\Event` and the Application instance by default. `EVENT_*_EXCEPTION` events are passed an additional `\Exception` parameter.

Conclusion
----------

[](#conclusion)

Unicorn is supposed to do just about nothing, or in short, everything you should need for any PHP web application. If you're tired of fitting your domain requirements to a framework or needing to write hacky workarounds to problems caused by lack of control, you just might enjoy working with Unicorn.

Feel free to fork and open pull requests against this repo. I don't claim to know what I'm doing, and I feel Unicorn would best serve the community evolving as a project defined by common project requirements instead of a specific set of design patterns and 'full-featured' mentality.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/881e86700b490ed77a8be2ab32ba3179ca7188a2e6bd94a0f2115eb2ed2c1ca2?d=identicon)[abreksa4](/maintainers/abreksa4)

---

Top Contributors

[![abreksa4](https://avatars.githubusercontent.com/u/6120041?v=4)](https://github.com/abreksa4 "abreksa4 (107 commits)")

---

Tags

psr-7rad

### Embed Badge

![Health badge](/badges/andrewbreksa-unicorn/health.svg)

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

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k104.3M836](/packages/laravel-socialite)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k38.6M289](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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